L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
backend
1// vi:set ft=cpp: -*- Mode: C++ -*-
2/*
3 * (c) 2010 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
4 * Alexander Warg <warg@os.inf.tu-dresden.de>
5 * economic rights: Technische Universität Dresden (Germany)
6 *
7 * This file is part of TUD:OS and distributed under the terms of the
8 * GNU General Public License 2.
9 * Please see the COPYING-GPL-2 file for details.
10 *
11 * As a special exception, you may use this file as part of a free software
12 * library without restriction. Specifically, if other files instantiate
13 * templates or use macros or inline functions from this file, or you compile
14 * this file and link it with other files to produce an executable, this
15 * file does not by itself cause the resulting executable to be covered by
16 * the GNU General Public License. This exception does not however
17 * invalidate any other reasons why the executable file might be covered by
18 * the GNU General Public License.
19 */
20#pragma once
21
22#include <l4/l4re_vfs/vfs.h>
23#include <l4/crtn/initpriorities.h>
24
25namespace L4Re { namespace Vfs {
26
28extern L4Re::Vfs::Ops *vfs_ops asm ("l4re_env_posix_vfs_ops");
29
30class Mount_tree;
31
39class Be_file : public File
40{
41public:
42 void *operator new (size_t size) noexcept
43 { return vfs_ops->malloc(size); }
44
45 void *operator new (size_t, void *m) noexcept
46 { return m; }
47
48 void operator delete (void *m)
49 { vfs_ops->free(m); }
50
51 // used in close, to unlock all locks of a file (as POSIX says)
52 int unlock_all_locks() noexcept override
53 { return 0; }
54
55 // for mmap
58
60 ssize_t readv(const struct iovec*, int) noexcept override
61 { return -EINVAL; }
62
64 ssize_t writev(const struct iovec*, int) noexcept override
65 { return -EINVAL; }
66
68 ssize_t pwritev(const struct iovec*, int, off64_t) noexcept override
69 { return -EINVAL; }
70
72 ssize_t preadv(const struct iovec*, int, off64_t) noexcept override
73 { return -EINVAL; }
74
76 off64_t lseek64(off64_t, int) noexcept override
77 { return -ESPIPE; }
78
80 int ftruncate64(off64_t) noexcept override
81 { return -EINVAL; }
82
84 int fsync() const noexcept override
85 { return -EINVAL; }
86
88 int fdatasync() const noexcept override
89 { return -EINVAL; }
90
92 int ioctl(unsigned long, va_list) noexcept override
93 { return -EINVAL; }
94
95 int fstat64(struct stat64 *) const noexcept override
96 { return -EINVAL; }
97
99 int fchmod(mode_t) noexcept override
100 { return -EINVAL; }
101
103 int get_status_flags() const noexcept override
104 { return 0; }
105
107 int set_status_flags(long) noexcept override
108 { return 0; }
109
111 int get_lock(struct flock64 *) noexcept override
112 { return -ENOLCK; }
113
115 int set_lock(struct flock64 *, bool) noexcept override
116 { return -ENOLCK; }
117
119 int faccessat(const char *, int, int) noexcept override
120 { return -ENOTDIR; }
121
123 int fchmodat(const char *, mode_t, int) noexcept override
124 { return -ENOTDIR; }
125
127 int utime(const struct utimbuf *) noexcept override
128 { return -EROFS; }
129
131 int utimes(const struct timeval [2]) noexcept override
132 { return -EROFS; }
133
135 int utimensat(const char *, const struct timespec [2], int) noexcept override
136 { return -EROFS; }
137
139 int mkdir(const char *, mode_t) noexcept override
140 { return -ENOTDIR; }
141
143 int unlink(const char *) noexcept override
144 { return -ENOTDIR; }
145
147 int rename(const char *, const char *) noexcept override
148 { return -ENOTDIR; }
149
151 int link(const char *, const char *) noexcept override
152 { return -ENOTDIR; }
153
155 int symlink(const char *, const char *) noexcept override
156 { return -EPERM; }
157
159 int rmdir(const char *) noexcept override
160 { return -ENOTDIR; }
161
163 ssize_t readlink(char *, size_t) override
164 { return -EINVAL; }
165
166 ssize_t getdents(char *, size_t) noexcept override
167 { return -ENOTDIR; }
168
169
170
171 // Socket interface
172 int bind(sockaddr const *, socklen_t) noexcept override
173 { return -ENOTSOCK; }
174
175 int connect(sockaddr const *, socklen_t) noexcept override
176 { return -ENOTSOCK; }
177
178 ssize_t send(void const *, size_t, int) noexcept override
179 { return -ENOTSOCK; }
180
181 ssize_t recv(void *, size_t, int) noexcept override
182 { return -ENOTSOCK; }
183
184 ssize_t sendto(void const *, size_t, int, sockaddr const *, socklen_t) noexcept
185 override
186 { return -ENOTSOCK; }
187
188 ssize_t recvfrom(void *, size_t, int, sockaddr *, socklen_t *) noexcept override
189 { return -ENOTSOCK; }
190
191 ssize_t sendmsg(msghdr const *, int) noexcept override
192 { return -ENOTSOCK; }
193
194 ssize_t recvmsg(msghdr *, int) noexcept override
195 { return -ENOTSOCK; }
196
197 int getsockopt(int, int, void *, socklen_t *) noexcept override
198 { return -ENOTSOCK; }
199
200 int setsockopt(int, int, void const *, socklen_t) noexcept override
201 { return -ENOTSOCK; }
202
203 int listen(int) noexcept override
204 { return -ENOTSOCK; }
205
206 int accept(sockaddr *, socklen_t *) noexcept override
207 { return -ENOTSOCK; }
208
209 int shutdown(int) noexcept override
210 { return -ENOTSOCK; }
211
212 int getsockname(sockaddr *, socklen_t *) noexcept override
213 { return -ENOTSOCK; }
214
215 int getpeername(sockaddr *, socklen_t *) noexcept override
216 { return -ENOTSOCK; }
217
218 ~Be_file() noexcept = 0;
219
220 int select(int, fd_set *, fd_set *, fd_set *, struct timeval *) throw()
221 { return -EOPNOTSUPP; }
222
223private:
225 int get_entry(const char *, int, mode_t, cxx::Ref_ptr<File> *) noexcept override
226 { return -ENOTDIR; }
227
228protected:
229 const char *get_mount(const char *path, cxx::Ref_ptr<File> *dir) noexcept;
230};
231
232inline
233Be_file::~Be_file() noexcept {}
234
235class Be_file_pos : public Be_file
236{
237public:
238 Be_file_pos() noexcept : Be_file(), _pos(0) {}
239
240 virtual off64_t size() const noexcept = 0;
241
242 ssize_t readv(const struct iovec *v, int iovcnt) noexcept override
243 {
244 ssize_t r = preadv(v, iovcnt, _pos);
245 if (r > 0)
246 _pos += r;
247 return r;
248 }
249
250 ssize_t writev(const struct iovec *v, int iovcnt) noexcept override
251 {
252 ssize_t r = pwritev(v, iovcnt, _pos);
253 if (r > 0)
254 _pos += r;
255 return r;
256 }
257
258 ssize_t preadv(const struct iovec *v, int iovcnt, off64_t offset) noexcept override = 0;
259 ssize_t pwritev(const struct iovec *v, int iovcnt, off64_t offset) noexcept override = 0;
260
261 off64_t lseek64(off64_t offset, int whence) noexcept override
262 {
263 off64_t r;
264 switch (whence)
265 {
266 case SEEK_SET: r = offset; break;
267 case SEEK_CUR: r = _pos + offset; break;
268 case SEEK_END: r = size() + offset; break;
269 default: return -EINVAL;
270 };
271
272 if (r < 0)
273 return -EINVAL;
274
275 _pos = r;
276 return _pos;
277 }
278
279 ~Be_file_pos() noexcept = 0;
280
281protected:
282 off64_t pos() const noexcept { return _pos; }
283
284private:
285 off64_t _pos;
286};
287
288inline Be_file_pos::~Be_file_pos() noexcept {}
289
290class Be_file_stream : public Be_file
291{
292public:
293 ssize_t preadv(const struct iovec *v, int iovcnt, off64_t) noexcept override
294 { return readv(v, iovcnt); }
295
296 ssize_t pwritev(const struct iovec *v, int iovcnt, off64_t) noexcept override
297 { return writev(v, iovcnt); }
298
299 ~Be_file_stream() noexcept = 0;
300
301};
302
303inline Be_file_stream::~Be_file_stream() noexcept {}
304
312{
313private:
314 char const *const _fstype;
315
316public:
317
325 explicit Be_file_system(char const *fstype) noexcept
326 : File_system(), _fstype(fstype)
327 {
328 vfs_ops->register_file_system(this);
329 }
330
338 {
339 vfs_ops->unregister_file_system(this);
340 }
341
347 char const *type() const noexcept override { return _fstype; }
348};
349
350/* Make sure filesystems can register before the constructor of libmount
351 * runs */
352#define L4RE_VFS_FILE_SYSTEM_ATTRIBUTE \
353 __attribute__((init_priority(INIT_PRIO_LATE)))
354
355}}
Boilerplate class for implementing a L4Re::Vfs::File_system.
Definition backend:312
~Be_file_system() noexcept
Destroy a file-system object.
Definition backend:337
char const * type() const noexcept override
Return the file-system type.
Definition backend:347
Be_file_system(char const *fstype) noexcept
Create a file-system object for the given fstype.
Definition backend:325
Boiler plate class for implementing an open file for L4Re::Vfs.
Definition backend:40
int faccessat(const char *, int, int) noexcept override
Default backend for POSIX access and faccessat functions.
Definition backend:119
ssize_t writev(const struct iovec *, int) noexcept override
Default backend for POSIX write and writev functions.
Definition backend:64
int unlink(const char *) noexcept override
Default backend for POSIX unlink, unlinkat.
Definition backend:143
int fchmodat(const char *, mode_t, int) noexcept override
Default backend for POSIX fchmodat function.
Definition backend:123
int ioctl(unsigned long, va_list) noexcept override
Default backend for POSIX ioctl.
Definition backend:92
int utimensat(const char *, const struct timespec[2], int) noexcept override
Default backend for POSIX utimensat.
Definition backend:135
int unlock_all_locks() noexcept override
Unlock all locks on the file.
Definition backend:52
ssize_t preadv(const struct iovec *, int, off64_t) noexcept override
Default backend for POSIX pread and preadv functions.
Definition backend:72
int rmdir(const char *) noexcept override
Default backend for POSIX rmdir, rmdirat.
Definition backend:159
int utimes(const struct timeval[2]) noexcept override
Default backend for POSIX utimes.
Definition backend:131
int set_status_flags(long) noexcept override
Default backend for POSIX fcntl subfunctions.
Definition backend:107
ssize_t pwritev(const struct iovec *, int, off64_t) noexcept override
Default backend for POSIX pwrite and pwritev functions.
Definition backend:68
ssize_t readv(const struct iovec *, int) noexcept override
Default backend for POSIX read and readv functions.
Definition backend:60
int fsync() const noexcept override
Default backend for POSIX fsync.
Definition backend:84
int mkdir(const char *, mode_t) noexcept override
Default backend for POSIX mkdir and mkdirat.
Definition backend:139
int ftruncate64(off64_t) noexcept override
Default backend for the POSIX truncate, ftruncate and similar functions.
Definition backend:80
int fchmod(mode_t) noexcept override
Default backend for POSIX chmod and fchmod.
Definition backend:99
int set_lock(struct flock64 *, bool) noexcept override
Default backend for POSIX fcntl subfunctions.
Definition backend:115
int get_status_flags() const noexcept override
Default backend for POSIX fcntl subfunctions.
Definition backend:103
int fstat64(struct stat64 *) const noexcept override
Get status information for the file.
Definition backend:95
off64_t lseek64(off64_t, int) noexcept override
Default backend for POSIX seek and lseek functions.
Definition backend:76
int fdatasync() const noexcept override
Default backend for POSIX fdatasync.
Definition backend:88
int symlink(const char *, const char *) noexcept override
Default backend for POSIX symlink, symlinkat.
Definition backend:155
L4::Cap< L4Re::Dataspace > data_space() noexcept override
Get an L4Re::Dataspace object for the file.
Definition backend:56
int utime(const struct utimbuf *) noexcept override
Default backend for POSIX utime.
Definition backend:127
int rename(const char *, const char *) noexcept override
Default backend for POSIX rename, renameat.
Definition backend:147
int get_lock(struct flock64 *) noexcept override
Default backend for POSIX fcntl subfunctions.
Definition backend:111
int link(const char *, const char *) noexcept override
Default backend for POSIX link, linkat.
Definition backend:151
ssize_t readlink(char *, size_t) override
Default backend for POSIX readlink, readlinkat.
Definition backend:163
Basic interface for an L4Re::Vfs file system.
Definition vfs.h:832
The basic interface for an open POSIX file.
Definition vfs.h:441
Interface for the POSIX backends of an application.
Definition vfs.h:1084
C++ interface for capabilities.
Definition capability.h:219
A reference-counting pointer with automatic cleanup.
Definition ref_ptr:82
L4Re C++ Interfaces.
Definition l4re.dox:17