Loading...
Searching...
No Matches
backend
// vi:set ft=cpp: -*- Mode: C++ -*-
/*
* (c) 2010 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
* Alexander Warg <warg@os.inf.tu-dresden.de>
* economic rights: Technische Universität Dresden (Germany)
*
* License: see LICENSE.spdx (in this directory or the directories above)
*/
#pragma once
#include <l4/l4re_vfs/vfs.h>
#include <l4/crtn/initpriorities.h>
extern "C" void l4re_vfs_select_poll_notify(void);
namespace L4Re { namespace Vfs {
extern L4Re::Vfs::Ops *vfs_ops asm ("l4re_env_posix_vfs_ops");
class Mount_tree;
class Be_file : public File
{
public:
void *operator new (size_t size) noexcept
{ return vfs_ops->malloc(size); }
void *operator new (size_t, void *m) noexcept
{ return m; }
void operator delete (void *m)
{ vfs_ops->free(m); }
// used in close, to unlock all locks of a file (as POSIX says)
int unlock_all_locks() noexcept override
{ return 0; }
// for mmap
L4::Cap<L4Re::Dataspace> data_space() noexcept override
{ return L4::Cap<L4Re::Dataspace>::Invalid; }
ssize_t readv(const struct iovec*, int) noexcept override
{ return -EINVAL; }
ssize_t writev(const struct iovec*, int) noexcept override
{ return -EINVAL; }
ssize_t pwritev(const struct iovec*, int, off64_t) noexcept override
{ return -EINVAL; }
ssize_t preadv(const struct iovec*, int, off64_t) noexcept override
{ return -EINVAL; }
off64_t lseek(off64_t, int) noexcept override
{ return -ESPIPE; }
int ftruncate(off64_t) noexcept override
{ return -EINVAL; }
int fsync() const noexcept override
{ return -EINVAL; }
int fdatasync() const noexcept override
{ return -EINVAL; }
int ioctl(unsigned long, va_list) noexcept override
{ return -EINVAL; }
int fstat(struct stat64 *) const noexcept override
{ return -EINVAL; }
int fchmod(mode_t) noexcept override
{ return -EINVAL; }
int get_status_flags() const noexcept override
{ return 0; }
int set_status_flags(long) noexcept override
{ return 0; }
int get_lock(struct flock64 *) noexcept override
{ return -ENOLCK; }
int set_lock(struct flock64 *, bool) noexcept override
{ return -ENOLCK; }
int faccessat(const char *, int, int) noexcept override
{ return -ENOTDIR; }
int fchmodat(const char *, mode_t, int) noexcept override
{ return -ENOTDIR; }
int utime(const struct utimbuf *) noexcept override
{ return -EROFS; }
int utimes(const struct timeval [2]) noexcept override
{ return -EROFS; }
int utimensat(const char *, const struct timespec [2], int) noexcept override
{ return -EROFS; }
int mkdir(const char *, mode_t) noexcept override
{ return -ENOTDIR; }
int unlink(const char *) noexcept override
{ return -ENOTDIR; }
int rename(const char *, const char *) noexcept override
{ return -ENOTDIR; }
int link(const char *, const char *) noexcept override
{ return -ENOTDIR; }
int symlink(const char *, const char *) noexcept override
{ return -EPERM; }
int rmdir(const char *) noexcept override
{ return -ENOTDIR; }
ssize_t readlink(char *, size_t) override
{ return -EINVAL; }
ssize_t getdents(char *, size_t) noexcept override
{ return -ENOTDIR; }
// Socket interface
int bind(sockaddr const *, socklen_t) noexcept override
{ return -ENOTSOCK; }
int connect(sockaddr const *, socklen_t) noexcept override
{ return -ENOTSOCK; }
ssize_t send(void const *, size_t, int) noexcept override
{ return -ENOTSOCK; }
ssize_t recv(void *, size_t, int) noexcept override
{ return -ENOTSOCK; }
ssize_t sendto(void const *, size_t, int, sockaddr const *, socklen_t) noexcept
override
{ return -ENOTSOCK; }
ssize_t recvfrom(void *, size_t, int, sockaddr *, socklen_t *) noexcept override
{ return -ENOTSOCK; }
ssize_t sendmsg(msghdr const *, int) noexcept override
{ return -ENOTSOCK; }
ssize_t recvmsg(msghdr *, int) noexcept override
{ return -ENOTSOCK; }
int getsockopt(int, int, void *, socklen_t *) noexcept override
{ return -ENOTSOCK; }
int setsockopt(int, int, void const *, socklen_t) noexcept override
{ return -ENOTSOCK; }
int listen(int) noexcept override
{ return -ENOTSOCK; }
int accept(sockaddr *, socklen_t *) noexcept override
{ return -ENOTSOCK; }
int shutdown(int) noexcept override
{ return -ENOTSOCK; }
int getsockname(sockaddr *, socklen_t *) noexcept override
{ return -ENOTSOCK; }
int getpeername(sockaddr *, socklen_t *) noexcept override
{ return -ENOTSOCK; }
bool check_ready(Ready_type) noexcept override
{ return false; }
~Be_file() noexcept = 0;
private:
int get_entry(const char *, int, mode_t, cxx::Ref_ptr<File> *) noexcept override
{ return -ENOTDIR; }
protected:
const char *get_mount(const char *path, cxx::Ref_ptr<File> *dir) noexcept;
};
inline
Be_file::~Be_file() noexcept {}
class Be_file_pos : public Be_file
{
public:
Be_file_pos() noexcept : Be_file(), _pos(0) {}
virtual off64_t size() const noexcept = 0;
ssize_t readv(const struct iovec *v, int iovcnt) noexcept override
{
ssize_t r = preadv(v, iovcnt, _pos);
if (r > 0)
_pos += r;
return r;
}
ssize_t writev(const struct iovec *v, int iovcnt) noexcept override
{
ssize_t r = pwritev(v, iovcnt, _pos);
if (r > 0)
_pos += r;
return r;
}
ssize_t preadv(const struct iovec *v, int iovcnt, off64_t offset) noexcept override = 0;
ssize_t pwritev(const struct iovec *v, int iovcnt, off64_t offset) noexcept override = 0;
off64_t lseek(off64_t offset, int whence) noexcept override
{
off64_t r;
switch (whence)
{
case SEEK_SET: r = offset; break;
case SEEK_CUR: r = _pos + offset; break;
case SEEK_END: r = size() + offset; break;
default: return -EINVAL;
};
if (r < 0)
return -EINVAL;
_pos = r;
return _pos;
}
~Be_file_pos() noexcept = 0;
protected:
off64_t pos() const noexcept { return _pos; }
private:
off64_t _pos;
};
inline Be_file_pos::~Be_file_pos() noexcept {}
class Be_file_stream : public Be_file
{
public:
ssize_t preadv(const struct iovec *v, int iovcnt, off64_t) noexcept override
{ return readv(v, iovcnt); }
ssize_t pwritev(const struct iovec *v, int iovcnt, off64_t) noexcept override
{ return writev(v, iovcnt); }
~Be_file_stream() noexcept = 0;
};
inline Be_file_stream::~Be_file_stream() noexcept {}
class Be_file_system : public File_system
{
private:
char const *const _fstype;
public:
explicit Be_file_system(char const *fstype) noexcept
: File_system(), _fstype(fstype)
{
vfs_ops->register_file_system(this);
}
~Be_file_system() noexcept
{
vfs_ops->unregister_file_system(this);
}
char const *type() const noexcept override { return _fstype; }
};
/* Make sure filesystems can register before the constructor of libmount
* runs */
#define L4RE_VFS_FILE_SYSTEM_ATTRIBUTE \
__attribute__((init_priority(INIT_PRIO_LATE)))
}}
L4Re::Vfs::Be_file_system::~Be_file_system
~Be_file_system() noexcept
Destroy a file-system object.
Definition backend:336
L4Re::Vfs::Be_file_system::type
char const * type() const noexcept override
Return the file-system type.
Definition backend:346
L4Re::Vfs::Be_file_system::Be_file_system
Be_file_system(char const *fstype) noexcept
Create a file-system object for the given fstype.
Definition backend:324
L4Re::Vfs::Be_file
Boiler plate class for implementing an open file for L4Re::Vfs.
Definition backend:31
L4Re::Vfs::Be_file::faccessat
int faccessat(const char *, int, int) noexcept override
Default backend for POSIX access and faccessat functions.
Definition backend:110
L4Re::Vfs::Be_file::writev
ssize_t writev(const struct iovec *, int) noexcept override
Default backend for POSIX write and writev functions.
Definition backend:55
L4Re::Vfs::Be_file::unlink
int unlink(const char *) noexcept override
Default backend for POSIX unlink, unlinkat.
Definition backend:134
L4Re::Vfs::Be_file::fchmodat
int fchmodat(const char *, mode_t, int) noexcept override
Default backend for POSIX fchmodat function.
Definition backend:114
L4Re::Vfs::Be_file::ioctl
int ioctl(unsigned long, va_list) noexcept override
Default backend for POSIX ioctl.
Definition backend:83
L4Re::Vfs::Be_file::utimensat
int utimensat(const char *, const struct timespec[2], int) noexcept override
Default backend for POSIX utimensat.
Definition backend:126
L4Re::Vfs::Be_file::unlock_all_locks
int unlock_all_locks() noexcept override
Unlock all locks on the file.
Definition backend:43
L4Re::Vfs::Be_file::check_ready
bool check_ready(Ready_type) noexcept override
Default implementation of a readiness check.
Definition backend:217
L4Re::Vfs::Be_file::preadv
ssize_t preadv(const struct iovec *, int, off64_t) noexcept override
Default backend for POSIX pread and preadv functions.
Definition backend:63
L4Re::Vfs::Be_file::rmdir
int rmdir(const char *) noexcept override
Default backend for POSIX rmdir, rmdirat.
Definition backend:150
L4Re::Vfs::Be_file::utimes
int utimes(const struct timeval[2]) noexcept override
Default backend for POSIX utimes.
Definition backend:122
L4Re::Vfs::Be_file::set_status_flags
int set_status_flags(long) noexcept override
Default backend for POSIX fcntl subfunctions.
Definition backend:98
L4Re::Vfs::Be_file::pwritev
ssize_t pwritev(const struct iovec *, int, off64_t) noexcept override
Default backend for POSIX pwrite and pwritev functions.
Definition backend:59
L4Re::Vfs::Be_file::readv
ssize_t readv(const struct iovec *, int) noexcept override
Default backend for POSIX read and readv functions.
Definition backend:51
L4Re::Vfs::Be_file::fsync
int fsync() const noexcept override
Default backend for POSIX fsync.
Definition backend:75
L4Re::Vfs::Be_file::mkdir
int mkdir(const char *, mode_t) noexcept override
Default backend for POSIX mkdir and mkdirat.
Definition backend:130
L4Re::Vfs::Be_file::fchmod
int fchmod(mode_t) noexcept override
Default backend for POSIX chmod and fchmod.
Definition backend:90
L4Re::Vfs::Be_file::set_lock
int set_lock(struct flock64 *, bool) noexcept override
Default backend for POSIX fcntl subfunctions.
Definition backend:106
L4Re::Vfs::Be_file::lseek
off64_t lseek(off64_t, int) noexcept override
Default backend for POSIX seek and lseek functions.
Definition backend:67
L4Re::Vfs::Be_file::get_status_flags
int get_status_flags() const noexcept override
Default backend for POSIX fcntl subfunctions.
Definition backend:94
L4Re::Vfs::Be_file::ftruncate
int ftruncate(off64_t) noexcept override
Default backend for the POSIX truncate, ftruncate and similar functions.
Definition backend:71
L4Re::Vfs::Be_file::fdatasync
int fdatasync() const noexcept override
Default backend for POSIX fdatasync.
Definition backend:79
L4Re::Vfs::Be_file::symlink
int symlink(const char *, const char *) noexcept override
Default backend for POSIX symlink, symlinkat.
Definition backend:146
L4Re::Vfs::Be_file::data_space
L4::Cap< L4Re::Dataspace > data_space() noexcept override
Get an L4Re::Dataspace object for the file.
Definition backend:47
L4Re::Vfs::Be_file::utime
int utime(const struct utimbuf *) noexcept override
Default backend for POSIX utime.
Definition backend:118
L4Re::Vfs::Be_file::rename
int rename(const char *, const char *) noexcept override
Default backend for POSIX rename, renameat.
Definition backend:138
L4Re::Vfs::Be_file::get_lock
int get_lock(struct flock64 *) noexcept override
Default backend for POSIX fcntl subfunctions.
Definition backend:102
L4Re::Vfs::Be_file::fstat
int fstat(struct stat64 *) const noexcept override
Get status information for the file.
Definition backend:86
L4Re::Vfs::Be_file::link
int link(const char *, const char *) noexcept override
Default backend for POSIX link, linkat.
Definition backend:142
L4Re::Vfs::Be_file::readlink
ssize_t readlink(char *, size_t) override
Default backend for POSIX readlink, readlinkat.
Definition backend:154
L4Re::Vfs::File
The basic interface for an open POSIX file.
Definition vfs.h:461
L4Re::Vfs::Generic_file::Ready_type
Ready_type
Type of I/O operation/condition a file can indicate readiness.
Definition vfs.h:61
L4Re::Vfs::Ops
Interface for the POSIX backends of an application.
Definition vfs.h:1110
L4::Cap_base::Invalid
@ Invalid
Invalid capability selector.
Definition capability.h:42
L4::Cap
C++ interface for capabilities.
Definition capability.h:224
cxx::Ref_ptr
A reference-counting pointer with automatic cleanup.
Definition ref_ptr:71
L4Re::Vfs
Virtual file system for interfaces in POSIX libc.
Definition backend:16
L4Re
L4Re C++ Interfaces.
Definition cmd_control:14
cxx
Our C++ library.
Definition arith:11