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.
20 #include <sys/ioctl.h>
24 namespace L4Re { namespace Core {
27 Simple_store<Ro_file> Ro_file::store;
31 Ro_file::operator new(size_t s) throw()
33 if (s != sizeof(Ro_file))
40 Ro_file::operator delete(void *b) throw()
46 Ro_file::~Ro_file() throw()
49 L4Re::Env::env()->rm()->detach(l4_addr_t(_addr), 0);
55 Ro_file::fstat64(struct stat64 *buf) const throw()
59 memset(buf, 0, sizeof(*buf));
61 buf->st_mode = S_IFREG | 0644;
62 buf->st_dev = _ds.cap();
64 buf->st_blksize = L4_PAGESIZE;
65 buf->st_blocks = l4_round_page(_size);
70 Ro_file::read(const struct iovec *vec) throw()
72 off64_t l = vec->iov_len;
73 if (_size - _f_pos < l)
78 Vfs_config::memcpy(vec->iov_base, _addr + _f_pos, l);
87 Ro_file::readv(const struct iovec *vec, int cnt) throw()
91 void const *file = (void*)L4_PAGESIZE;
92 long err = L4Re::Env::env()->rm()->attach(&file, _size,
93 Rm::Search_addr | Rm::Read_only, _ds, 0);
98 _addr = (char const *)file;
105 ssize_t r = read(vec);
108 if ((size_t)r < vec->iov_len)
118 Ro_file::writev(const struct iovec*, int iovcnt) throw()
125 Ro_file::lseek64(off64_t offset, int whence) throw()
130 case SEEK_SET: r = offset; break;
131 case SEEK_CUR: r = _f_pos + offset; break;
132 case SEEK_END: r = _size + offset; break;
133 default: return -EINVAL;
145 Ro_file::ioctl(unsigned long v, va_list args) throw()
149 case FIONREAD: // return amount of data still available
150 int *available = va_arg(args, int *);
151 *available = _size - _f_pos;