22#include <l4/l4re_vfs/vfs.h>
23#include <l4/crtn/initpriorities.h>
25namespace L4Re {
namespace Vfs {
42 void *
operator new (
size_t size)
noexcept
43 {
return vfs_ops->malloc(size); }
45 void *
operator new (size_t,
void *m)
noexcept
48 void operator delete (
void *m)
60 ssize_t
readv(
const struct iovec*,
int)
noexcept override
64 ssize_t
writev(
const struct iovec*,
int)
noexcept override
68 ssize_t
pwritev(
const struct iovec*,
int, off64_t)
noexcept override
72 ssize_t
preadv(
const struct iovec*,
int, off64_t)
noexcept override
76 off64_t
lseek64(off64_t,
int)
noexcept override
84 int fsync() const noexcept
override
92 int ioctl(
unsigned long, va_list)
noexcept override
95 int fstat64(
struct stat64 *)
const noexcept override
115 int set_lock(
struct flock64 *,
bool)
noexcept override
123 int fchmodat(
const char *, mode_t,
int)
noexcept override
127 int utime(
const struct utimbuf *)
noexcept override
131 int utimes(
const struct timeval [2])
noexcept override
135 int utimensat(
const char *,
const struct timespec [2],
int)
noexcept override
139 int mkdir(
const char *, mode_t)
noexcept override
143 int unlink(
const char *)
noexcept override
147 int rename(
const char *,
const char *)
noexcept override
151 int link(
const char *,
const char *)
noexcept override
155 int symlink(
const char *,
const char *)
noexcept override
159 int rmdir(
const char *)
noexcept override
166 ssize_t getdents(
char *,
size_t)
noexcept override
172 int bind(sockaddr
const *, socklen_t)
noexcept override
173 {
return -ENOTSOCK; }
175 int connect(sockaddr
const *, socklen_t)
noexcept override
176 {
return -ENOTSOCK; }
178 ssize_t send(
void const *,
size_t,
int)
noexcept override
179 {
return -ENOTSOCK; }
181 ssize_t recv(
void *,
size_t,
int)
noexcept override
182 {
return -ENOTSOCK; }
184 ssize_t sendto(
void const *,
size_t,
int, sockaddr
const *, socklen_t)
noexcept
186 {
return -ENOTSOCK; }
188 ssize_t recvfrom(
void *,
size_t,
int, sockaddr *, socklen_t *)
noexcept override
189 {
return -ENOTSOCK; }
191 ssize_t sendmsg(msghdr
const *,
int)
noexcept override
192 {
return -ENOTSOCK; }
194 ssize_t recvmsg(msghdr *,
int)
noexcept override
195 {
return -ENOTSOCK; }
197 int getsockopt(
int,
int,
void *, socklen_t *)
noexcept override
198 {
return -ENOTSOCK; }
200 int setsockopt(
int,
int,
void const *, socklen_t)
noexcept override
201 {
return -ENOTSOCK; }
203 int listen(
int)
noexcept override
204 {
return -ENOTSOCK; }
206 int accept(sockaddr *, socklen_t *)
noexcept override
207 {
return -ENOTSOCK; }
209 int shutdown(
int)
noexcept override
210 {
return -ENOTSOCK; }
212 int getsockname(sockaddr *, socklen_t *)
noexcept override
213 {
return -ENOTSOCK; }
215 int getpeername(sockaddr *, socklen_t *)
noexcept override
216 {
return -ENOTSOCK; }
218 ~Be_file() noexcept = 0;
220 int select(
int, fd_set *, fd_set *, fd_set *, struct timeval *) throw()
221 {
return -EOPNOTSUPP; }
233Be_file::~Be_file() noexcept {}
235class Be_file_pos :
public Be_file
238 Be_file_pos() noexcept : Be_file(), _pos(0) {}
240 virtual off64_t size() const noexcept = 0;
242 ssize_t readv(const struct iovec *v,
int iovcnt) noexcept
override
244 ssize_t r = preadv(v, iovcnt, _pos);
250 ssize_t writev(
const struct iovec *v,
int iovcnt)
noexcept override
252 ssize_t r = pwritev(v, iovcnt, _pos);
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;
261 off64_t lseek64(off64_t offset,
int whence)
noexcept override
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;
279 ~Be_file_pos() noexcept = 0;
282 off64_t pos() const noexcept {
return _pos; }
288inline Be_file_pos::~Be_file_pos() noexcept {}
290class Be_file_stream :
public Be_file
293 ssize_t preadv(
const struct iovec *v,
int iovcnt, off64_t)
noexcept override
294 {
return readv(v, iovcnt); }
296 ssize_t pwritev(
const struct iovec *v,
int iovcnt, off64_t)
noexcept override
297 {
return writev(v, iovcnt); }
299 ~Be_file_stream() noexcept = 0;
303inline Be_file_stream::~Be_file_stream() noexcept {}
314 char const *
const _fstype;
328 vfs_ops->register_file_system(
this);
339 vfs_ops->unregister_file_system(
this);
347 char const *
type() const noexcept
override {
return _fstype; }
352#define L4RE_VFS_FILE_SYSTEM_ATTRIBUTE \
353 __attribute__((init_priority(INIT_PRIO_LATE)))
Boilerplate class for implementing a L4Re::Vfs::File_system.
~Be_file_system() noexcept
Destroy a file-system object.
char const * type() const noexcept override
Return the file-system type.
Be_file_system(char const *fstype) noexcept
Create a file-system object for the given fstype.
Boiler plate class for implementing an open file for L4Re::Vfs.
int faccessat(const char *, int, int) noexcept override
Default backend for POSIX access and faccessat functions.
ssize_t writev(const struct iovec *, int) noexcept override
Default backend for POSIX write and writev functions.
int unlink(const char *) noexcept override
Default backend for POSIX unlink, unlinkat.
int fchmodat(const char *, mode_t, int) noexcept override
Default backend for POSIX fchmodat function.
int ioctl(unsigned long, va_list) noexcept override
Default backend for POSIX ioctl.
int utimensat(const char *, const struct timespec[2], int) noexcept override
Default backend for POSIX utimensat.
int unlock_all_locks() noexcept override
Unlock all locks on the file.
ssize_t preadv(const struct iovec *, int, off64_t) noexcept override
Default backend for POSIX pread and preadv functions.
int rmdir(const char *) noexcept override
Default backend for POSIX rmdir, rmdirat.
int utimes(const struct timeval[2]) noexcept override
Default backend for POSIX utimes.
int set_status_flags(long) noexcept override
Default backend for POSIX fcntl subfunctions.
ssize_t pwritev(const struct iovec *, int, off64_t) noexcept override
Default backend for POSIX pwrite and pwritev functions.
ssize_t readv(const struct iovec *, int) noexcept override
Default backend for POSIX read and readv functions.
int fsync() const noexcept override
Default backend for POSIX fsync.
int mkdir(const char *, mode_t) noexcept override
Default backend for POSIX mkdir and mkdirat.
int ftruncate64(off64_t) noexcept override
Default backend for the POSIX truncate, ftruncate and similar functions.
int fchmod(mode_t) noexcept override
Default backend for POSIX chmod and fchmod.
int set_lock(struct flock64 *, bool) noexcept override
Default backend for POSIX fcntl subfunctions.
int get_status_flags() const noexcept override
Default backend for POSIX fcntl subfunctions.
int fstat64(struct stat64 *) const noexcept override
Get status information for the file.
off64_t lseek64(off64_t, int) noexcept override
Default backend for POSIX seek and lseek functions.
int fdatasync() const noexcept override
Default backend for POSIX fdatasync.
int symlink(const char *, const char *) noexcept override
Default backend for POSIX symlink, symlinkat.
L4::Cap< L4Re::Dataspace > data_space() noexcept override
Get an L4Re::Dataspace object for the file.
int utime(const struct utimbuf *) noexcept override
Default backend for POSIX utime.
int rename(const char *, const char *) noexcept override
Default backend for POSIX rename, renameat.
int get_lock(struct flock64 *) noexcept override
Default backend for POSIX fcntl subfunctions.
int link(const char *, const char *) noexcept override
Default backend for POSIX link, linkat.
ssize_t readlink(char *, size_t) override
Default backend for POSIX readlink, readlinkat.
Basic interface for an L4Re::Vfs file system.
The basic interface for an open POSIX file.
Interface for the POSIX backends of an application.
C++ interface for capabilities.
A reference-counting pointer with automatic cleanup.