2 * (c) 2010 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3 * Alexander Warg <warg@os.inf.tu-dresden.de>
4 * economic rights: Technische Universität Dresden (Germany)
6 * This file is part of TUD:OS and distributed under the terms of the
7 * GNU General Public License 2.
8 * Please see the COPYING-GPL-2 file for details.
10 * As a special exception, you may use this file as part of a free software
11 * library without restriction. Specifically, if other files instantiate
12 * templates or use macros or inline functions from this file, or you compile
13 * this file and link it with other files to produce an executable, this
14 * file does not by itself cause the resulting executable to be covered by
15 * the GNU General Public License. This exception does not however
16 * invalidate any other reasons why the executable file might be covered by
17 * the GNU General Public License.
23 #include <sys/ioctl.h>
27 namespace L4Re { namespace Core {
30 Simple_store<Ro_file> Ro_file::store __attribute__((init_priority(1000)));
34 Ro_file::operator new(size_t s) throw()
36 if (s != sizeof(Ro_file))
43 Ro_file::operator delete(void *b) throw()
49 Ro_file::~Ro_file() throw()
52 L4Re::Env::env()->rm()->detach(l4_addr_t(_addr), 0);
58 Ro_file::fstat64(struct stat64 *buf) const throw()
62 memset(buf, 0, sizeof(*buf));
64 buf->st_mode = S_IFREG | 0644;
65 buf->st_dev = _ds.cap();
67 buf->st_blksize = L4_PAGESIZE;
68 buf->st_blocks = l4_round_page(_size);
73 Ro_file::read_single(const struct iovec *vec, off64_t pos) throw()
75 off64_t l = vec->iov_len;
81 Vfs_config::memcpy(vec->iov_base, _addr + pos, l);
89 Ro_file::preadv(const struct iovec *vec, int cnt, off64_t offset) throw()
93 void const *file = (void*)L4_PAGESIZE;
94 long err = L4Re::Env::env()->rm()->attach(&file, _size,
95 Rm::Search_addr | Rm::Read_only,
101 _addr = (char const *)file;
108 ssize_t r = read_single(vec, offset);
112 if ((size_t)r < vec->iov_len)
122 Ro_file::pwritev(const struct iovec *, int, off64_t) throw()
128 Ro_file::ioctl(unsigned long v, va_list args) throw()
132 case FIONREAD: // return amount of data still available
133 int *available = va_arg(args, int *);
134 *available = _size - pos();