2 * (c) 2010 Technische Universität Dresden
3 * This file is part of TUD:OS and distributed under the terms of the
4 * GNU General Public License 2.
5 * Please see the COPYING-GPL-2 file for details.
7 * As a special exception, you may use this file as part of a free software
8 * library without restriction. Specifically, if other files instantiate
9 * templates or use macros or inline functions from this file, or you compile
10 * this file and link it with other files to produce an executable, this
11 * file does not by itself cause the resulting executable to be covered by
12 * the GNU General Public License. This exception does not however
13 * invalidate any other reasons why the executable file might be covered by
14 * the GNU General Public License.
22 namespace L4Re { namespace Core {
25 Simple_store<Ro_file> Ro_file::store;
29 Ro_file::operator new(size_t s) throw()
31 if (s != sizeof(Ro_file))
38 Ro_file::operator delete(void *b) throw()
44 Ro_file::~Ro_file() throw()
47 L4Re::Env::env()->rm()->detach(l4_addr_t(_addr), 0);
53 Ro_file::fstat64(struct stat64 *buf) const throw()
57 memset(buf, 0, sizeof(*buf));
59 buf->st_mode = S_IFREG | 0644;
60 buf->st_dev = _ds.cap();
62 buf->st_blksize = L4_PAGESIZE;
63 buf->st_blocks = l4_round_page(_size);
68 Ro_file::read(const struct iovec *vec) throw()
70 off64_t l = vec->iov_len;
71 if (_size - _f_pos < l)
76 Vfs_config::memcpy(vec->iov_base, _addr + _f_pos, l);
85 Ro_file::readv(const struct iovec *vec, int cnt) throw()
89 void const *file = (void*)L4_PAGESIZE;
90 long err = L4Re::Env::env()->rm()->attach(&file, _size,
91 Rm::Search_addr | Rm::Read_only, _ds, 0);
96 _addr = (char const *)file;
103 ssize_t r = read(vec);
106 if ((size_t)r < vec->iov_len)
116 Ro_file::writev(const struct iovec*, int iovcnt) throw()
123 Ro_file::lseek64(off64_t offset, int whence) throw()
128 case SEEK_SET: r = offset; break;
129 case SEEK_CUR: r = _f_pos + offset; break;
130 case SEEK_END: r = _size + offset; break;
131 default: return -EINVAL;