28#include <sys/socket.h>
42#include <l4/cxx/ref_ptr>
87 virtual
int fstat64(struct stat64 *buf) const noexcept = 0;
94 virtual
int fchmod(mode_t) noexcept = 0;
124 virtual
int utime(const struct utimbuf *) noexcept = 0;
125 virtual
int utimes(const struct timeval [2]) noexcept = 0;
126 virtual ssize_t readlink(
char *,
size_t) = 0;
158 virtual int faccessat(
const char *path,
int mode,
int flags)
noexcept = 0;
172 virtual int mkdir(
const char *path, mode_t mode)
noexcept = 0;
184 virtual int unlink(
const char *path)
noexcept = 0;
199 virtual int rename(
const char *src_path,
const char *dst_path)
noexcept = 0;
214 virtual int link(
const char *src_path,
const char *dst_path)
noexcept = 0;
228 virtual int symlink(
const char *src_path,
const char *dst_path)
noexcept = 0;
240 virtual int rmdir(
const char *path)
noexcept = 0;
241 virtual int openat(
const char *path,
int flags, mode_t mode,
244 virtual ssize_t getdents(
char *buf,
size_t sizebytes)
noexcept = 0;
246 virtual int fchmodat(
const char *pathname,
247 mode_t mode,
int flags)
noexcept = 0;
249 virtual int utimensat(
const char *pathname,
250 const struct timespec times[2],
int flags)
noexcept = 0;
259Directory::~Directory() noexcept
293 virtual ssize_t readv(const struct iovec*,
int iovcnt) noexcept = 0;
305 virtual ssize_t writev(const struct iovec*,
int iovcnt) noexcept = 0;
307 virtual ssize_t preadv(const struct iovec *iov,
int iovcnt, off64_t offset) noexcept = 0;
308 virtual ssize_t pwritev(const struct iovec *iov,
int iovcnt, off64_t offset) noexcept = 0;
317 virtual off64_t lseek64(off64_t,
int) noexcept = 0;
327 virtual
int ftruncate64(off64_t pos) noexcept = 0;
334 virtual
int fsync() const noexcept = 0;
341 virtual
int fdatasync() const noexcept = 0;
352 virtual
int get_lock(struct flock64 *lock) noexcept = 0;
362 virtual
int set_lock(struct flock64 *lock,
bool wait) noexcept = 0;
372 virtual ~Socket() noexcept = 0;
373 virtual
int bind(sockaddr const *, socklen_t) noexcept = 0;
374 virtual
int connect(sockaddr const *, socklen_t) noexcept = 0;
375 virtual ssize_t send(
void const *,
size_t,
int) noexcept = 0;
376 virtual ssize_t recv(
void *,
size_t,
int) noexcept = 0;
377 virtual ssize_t sendto(
void const *,
size_t,
int, sockaddr const *, socklen_t) noexcept = 0;
378 virtual ssize_t recvfrom(
void *,
size_t,
int, sockaddr *, socklen_t *) noexcept = 0;
379 virtual ssize_t sendmsg(msghdr const *,
int) noexcept = 0;
380 virtual ssize_t recvmsg(msghdr *,
int) noexcept = 0;
381 virtual
int getsockopt(
int level,
int opt,
void *, socklen_t *) noexcept = 0;
382 virtual
int setsockopt(
int level,
int opt,
void const *, socklen_t) noexcept = 0;
383 virtual
int listen(
int) noexcept = 0;
384 virtual
int accept(sockaddr *addr, socklen_t *) noexcept = 0;
385 virtual
int shutdown(
int) noexcept = 0;
387 virtual
int getsockname(sockaddr *, socklen_t *) noexcept = 0;
388 virtual
int getpeername(sockaddr *, socklen_t *) noexcept = 0;
392Socket::~Socket() noexcept
415 virtual int ioctl(
unsigned long cmd, va_list args)
noexcept = 0;
419Special_file::~Special_file() noexcept
442 friend class Mount_tree;
445 void operator = (
File const &);
448 File() noexcept : _ref_cnt(0) {}
458 int openat(
const char *path,
int flags, mode_t mode,
461 void add_ref()
noexcept { ++_ref_cnt; }
462 int remove_ref()
noexcept {
return --_ref_cnt; }
464 virtual ~File()
noexcept = 0;
467 {
return _mount_tree; }
469 virtual int select(
int nfds, fd_set *readfds, fd_set *writefds,
470 fd_set *exceptfds,
struct timeval *timeout)
throw() = 0;
479File::~File() noexcept
489 Path() noexcept : _p(0), _l(0) {}
491 explicit Path(
char const *p) noexcept : _p(p)
492 {
for (_l = 0; *p; ++p, ++_l) ; }
494 Path(
char const *p,
unsigned l) noexcept : _p(p), _l(l)
497 static bool __is_sep(
char s)
noexcept;
499 Path cmp_path(
char const *prefix)
const noexcept;
502 operator Invalid_ptr
const * ()
const
503 {
return reinterpret_cast<Invalid_ptr
const *
>(_p); }
505 unsigned length()
const {
return _l; }
506 char const *path()
const {
return _p; }
508 bool empty()
const {
return _l == 0; }
510 bool is_sep(
unsigned offset)
const {
return __is_sep(_p[offset]); }
515 for (; __is_sep(*_p) && _l; ++_p, --_l)
523 for (i = 0; i < _l && !is_sep(i); ++i)
551 explicit Mount_tree(
char *n)
noexcept;
556 Path find(Path const &p,
cxx::Ref_ptr<Mount_tree> *t) noexcept;
558 cxx::Ref_ptr<File> mount()
const
563 m->_mount_tree = cxx::ref_ptr(
this);
573 virtual ~Mount_tree() noexcept = 0;
575 void add_ref() noexcept { ++_ref_cnt; }
576 int remove_ref() noexcept {
return --_ref_cnt; }
579 friend class Real_mount_tree;
589Mount_tree::~Mount_tree() noexcept
593Path::__is_sep(
char s)
noexcept
597Path::cmp_path(
char const *n)
const noexcept
600 for (; *p && !__is_sep(*p) && *n; ++p, ++n)
604 if (*n || (*p && !__is_sep(*p)))
607 return Path(p, _l - (p - _p));
611Mount_tree::Mount_tree(
char *n) noexcept
612: _ref_cnt(0), _name(n)
623 Path
const r = p.cmp_path(x->_name);
641 if (p.first().cmp_path(
"."))
651 Path r = x->find(p, &x);
702 *dir = cxx::ref_ptr(
this);
707 Path p = _mount_tree->lookup(Path(path), mt, &mp);
715 *dir = cxx::ref_ptr(
this);
721File::openat(
const char *path,
int flags, mode_t mode,
726 path = get_mount(path, &dir, &mt);
728 int res = dir->get_entry(path, flags, mode, f);
733 if (!(*f)->_mount_tree && mt)
734 (*f)->_mount_tree = mt;
751 virtual int mmap2(
void *start,
size_t len,
int prot,
int flags,
int fd,
752 off_t offset,
void **ptr)
noexcept = 0;
755 virtual int munmap(
void *start,
size_t len)
noexcept = 0;
758 virtual int mremap(
void *old,
size_t old_sz,
size_t new_sz,
int flags,
759 void **new_addr)
noexcept = 0;
762 virtual int mprotect(
const void *a,
size_t sz,
int prot)
noexcept = 0;
765 virtual int msync(
void *addr,
size_t len,
int flags)
noexcept = 0;
768 virtual int madvise(
void *addr,
size_t len,
int advice)
noexcept = 0;
770 virtual ~Mman() noexcept = 0;
781 char const *_proto_name = 0;
783 template<
typename T>
friend struct cxx::Default_ref_counter;
784 void add_ref() noexcept { ++_ref_cnt; }
785 int remove_ref() noexcept {
return --_ref_cnt; }
788 explicit File_factory(
int proto) : _proto(proto) {}
789 explicit File_factory(
char const *proto_name) : _proto_name(proto_name) {}
790 File_factory(
int proto,
char const *proto_name)
791 : _proto(proto), _proto_name(proto_name)
794 File_factory(File_factory
const &) =
delete;
795 File_factory &operator = (File_factory
const &) =
delete;
797 char const *proto_name()
const {
return _proto_name; }
798 int proto()
const {
return _proto; }
800 virtual ~File_factory() noexcept = 0;
801 virtual
cxx::Ref_ptr<File> create(
L4::Cap<
void> file) = 0;
804inline File_factory::~File_factory() noexcept {}
806template<
typename IFACE,
typename IMPL>
807class File_factory_t :
public File_factory
815 {
return cxx::make_ref_obj<IMPL>(L4::cap_cast<IFACE>(file)); }
843 virtual char const *
type() const noexcept = 0;
861 virtual
int mount(
char const *source,
unsigned long mountflags,
862 void const *data,
cxx::Ref_ptr<
File> *dir) noexcept = 0;
870 File_system *next() const noexcept {
return _next; }
872 void next(File_system *n)
noexcept { _next = n; }
876File_system::~File_system() noexcept
879class File_system_list
885 explicit constexpr Iterator(File_system *c =
nullptr) : _c(c) {}
887 Iterator &operator++()
894 bool operator==(Iterator
const &other)
const {
return _c == other._c; }
895 bool operator!=(Iterator
const &other)
const {
return _c != other._c; }
896 File_system *operator*()
const {
return _c; }
897 File_system *operator->()
const {
return _c; }
903 File_system_list(File_system *head) : _head(head) {}
905 constexpr Iterator begin()
const
906 {
return Iterator(_head); }
908 constexpr Iterator end()
const
909 {
return Iterator(); }
934 virtual
cxx::Ref_ptr<
File> get_cwd() noexcept {
return get_root(); }
982 virtual int register_file_system(
File_system *f)
noexcept = 0;
991 virtual int unregister_file_system(
File_system *f)
noexcept = 0;
1000 virtual File_system *get_file_system(
char const *fstype)
noexcept = 0;
1010 virtual File_system_list file_system_list() noexcept = 0;
1015 int mount(
char const *source,
char const *target,
1016 char const *fstype,
unsigned long mountflags,
1017 void const *data) noexcept;
1019 virtual
int register_file_factory(
cxx::Ref_ptr<File_factory> f) noexcept = 0;
1020 virtual
int unregister_file_factory(
cxx::Ref_ptr<File_factory> f) noexcept = 0;
1021 virtual
cxx::Ref_ptr<File_factory> get_file_factory(
int proto) noexcept = 0;
1022 virtual
cxx::Ref_ptr<File_factory> get_file_factory(
char const *proto_name) noexcept = 0;
1027 int mount_one(
char const *source,
char const *target,
1029 void const *data) noexcept;
1033Fs::mount_one(
char const *source,
char const *target,
1035 void const *data) noexcept
1038 int res = fs->mount(source, mountflags, data, &dir);
1043 return mount(target, dir);
1047Fs::mount(
char const *source,
char const *target,
1048 char const *fstype,
unsigned long mountflags,
1049 void const *data)
noexcept
1051 if ( fstype[0] ==
'a'
1057 File_system_list fsl = file_system_list();
1058 for (File_system_list::Iterator c = fsl.begin(); c != fsl.end(); ++c)
1059 if (mount_one(source, target, *c, mountflags, data) == 0)
1070 return mount_one(source, target, fs, mountflags, data);
1086 virtual void *malloc(
size_t bytes)
noexcept = 0;
1087 virtual void free(
void *mem)
noexcept = 0;
1088 virtual ~Ops()
noexcept = 0;
1090 char *strndup(
char const *str,
unsigned l)
noexcept
1093 for (len = 0; str[len] && len < l; ++len)
1101 char *b =
static_cast<char *
>(this->malloc(len));
1106 for (; len - 1 > 0 && *str; --len, ++b, ++str)
Abstract capability-allocator interface.
L4::Cap related definitions.
Interface for a POSIX file that is a directory.
virtual int mkdir(const char *path, mode_t mode) noexcept=0
Create a new subdirectory.
virtual int link(const char *src_path, const char *dst_path) noexcept=0
Create a hard link (second name) for the given file.
virtual int unlink(const char *path) noexcept=0
Unlink the given file from that directory.
virtual int symlink(const char *src_path, const char *dst_path) noexcept=0
Create a symbolic link for the given file.
virtual int rmdir(const char *path) noexcept=0
Delete an empty directory.
virtual int rename(const char *src_path, const char *dst_path) noexcept=0
Rename the given file.
virtual int faccessat(const char *path, int mode, int flags) noexcept=0
Check access permissions on the given file.
Basic interface for an L4Re::Vfs file system.
virtual char const * type() const noexcept=0
Returns the type of the file system used in mount as fstype argument.
The basic interface for an open POSIX file.
POSIX File-system related functionality.
virtual void set_cwd(cxx::Ref_ptr< File > const &) noexcept
Set the current working directory for the application.
virtual int mount(char const *path, cxx::Ref_ptr< File > const &dir) noexcept=0
Mount a given file object at the given global path in the VFS.
virtual cxx::Ref_ptr< File > get_file(int fd) noexcept=0
Get the L4Re::Vfs::File for the file descriptor fd.
virtual cxx::Ref_ptr< File > free_fd(int fd) noexcept=0
Free the file descriptor fd.
virtual cxx::Pair< cxx::Ref_ptr< File >, int > set_fd(int fd, cxx::Ref_ptr< File > const &f=cxx::Ref_ptr<>::Nil) noexcept=0
Set the file object referenced by the file descriptor fd.
virtual int alloc_fd(cxx::Ref_ptr< File > const &f=cxx::Ref_ptr<>::Nil) noexcept=0
Allocate the next free file descriptor.
virtual cxx::Ref_ptr< File > get_root() noexcept=0
Get the directory object for the application's root directory.
The common interface for an open POSIX file.
virtual int unlock_all_locks() noexcept=0
Unlock all locks on the file.
virtual int fchmod(mode_t) noexcept=0
Change POSIX access rights on the file.
virtual int fstat64(struct stat64 *buf) const noexcept=0
Get status information for the file.
virtual int set_status_flags(long flags) noexcept=0
Set file status flags (fcntl F_SETFL).
virtual int get_status_flags() const noexcept=0
Get file status flags (fcntl F_GETFL).
Interface for POSIX memory management.
virtual int mmap2(void *start, size_t len, int prot, int flags, int fd, off_t offset, void **ptr) noexcept=0
Backend for the mmap2 system call.
virtual int msync(void *addr, size_t len, int flags) noexcept=0
Backend for the msync system call.
virtual int munmap(void *start, size_t len) noexcept=0
Backend for the munmap system call.
virtual int mremap(void *old, size_t old_sz, size_t new_sz, int flags, void **new_addr) noexcept=0
Backend for the mremap system call.
virtual int madvise(void *addr, size_t len, int advice) noexcept=0
Backend for the madvice system call.
virtual int mprotect(const void *a, size_t sz, int prot) noexcept=0
Backend for the mprotect system call.
Interface for the POSIX backends of an application.
Interface for a POSIX file that provides regular file semantics.
virtual L4::Cap< L4Re::Dataspace > data_space() noexcept=0
Get an L4Re::Dataspace object for the file.
Interface for a POSIX file that provides special file semantics.
virtual int ioctl(unsigned long cmd, va_list args) noexcept=0
The famous IO control.
C++ interface for capabilities.
A reference-counting pointer with automatic cleanup.
L4 compiler related defines.
Type_info const * kobject_typeid() noexcept
Get the L4::Type_info for the L4Re interface given in T.
L4 low-level kernel interface.