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(const struct iovec *vec) throw()
75 off64_t l = vec->iov_len;
76 if (_size - _f_pos < l)
81 Vfs_config::memcpy(vec->iov_base, _addr + _f_pos, l);
90 Ro_file::readv(const struct iovec *vec, int cnt) throw()
94 void const *file = (void*)L4_PAGESIZE;
95 long err = L4Re::Env::env()->rm()->attach(&file, _size,
96 Rm::Search_addr | Rm::Read_only, _ds, 0);
101 _addr = (char const *)file;
108 ssize_t r = read(vec);
111 if ((size_t)r < vec->iov_len)
121 Ro_file::writev(const struct iovec*, int iovcnt) throw()
128 Ro_file::lseek64(off64_t offset, int whence) throw()
133 case SEEK_SET: r = offset; break;
134 case SEEK_CUR: r = _f_pos + offset; break;
135 case SEEK_END: r = _size + offset; break;
136 default: return -EINVAL;
148 Ro_file::ioctl(unsigned long v, va_list args) throw()
152 case FIONREAD: // return amount of data still available
153 int *available = va_arg(args, int *);
154 *available = _size - _f_pos;