18#include <sys/socket.h> 
   32#include <l4/cxx/ref_ptr> 
   90  virtual 
int fstat(struct stat64 *buf) const noexcept = 0;
 
   97  virtual 
int fchmod(mode_t) noexcept = 0;
 
  127  virtual 
int utime(const struct utimbuf *) noexcept = 0;
 
  128  virtual 
int utimes(const struct timeval [2]) noexcept = 0;
 
  129  virtual ssize_t readlink(
char *, 
size_t) = 0;
 
 
  178  virtual int faccessat(
const char *path, 
int mode, 
int flags) 
noexcept = 0;
 
  192  virtual int mkdir(
const char *path, mode_t mode) 
noexcept = 0;
 
  204  virtual int unlink(
const char *path) 
noexcept = 0;
 
  219  virtual int rename(
const char *src_path, 
const char *dst_path) 
noexcept = 0;
 
  234  virtual int link(
const char *src_path, 
const char *dst_path) 
noexcept = 0;
 
  248  virtual int symlink(
const char *src_path, 
const char *dst_path) 
noexcept = 0;
 
  260  virtual int rmdir(
const char *path) 
noexcept = 0;
 
  261  virtual int openat(
const char *path, 
int flags, mode_t mode,
 
  264  virtual ssize_t getdents(
char *buf, 
size_t sizebytes) 
noexcept = 0;
 
  266  virtual int fchmodat(
const char *pathname,
 
  267                       mode_t mode, 
int flags) 
noexcept = 0;
 
  269  virtual int utimensat(
const char *pathname,
 
  270                        const struct timespec times[2], 
int flags) 
noexcept = 0;
 
 
  279Directory::~Directory() noexcept
 
  313  virtual ssize_t 
readv(const struct iovec*, 
int iovcnt) noexcept = 0;
 
  325  virtual ssize_t 
writev(const struct iovec*, 
int iovcnt) noexcept = 0;
 
  327  virtual ssize_t preadv(const struct iovec *iov, 
int iovcnt, off64_t offset) noexcept = 0;
 
  328  virtual ssize_t pwritev(const struct iovec *iov, 
int iovcnt, off64_t offset) noexcept = 0;
 
  337  virtual off64_t 
lseek(off64_t, 
int) noexcept = 0;
 
  354  virtual 
int fsync() const noexcept = 0;
 
  372  virtual 
int get_lock(struct flock64 *lock) noexcept = 0;
 
  382  virtual 
int set_lock(struct flock64 *lock, 
bool wait) noexcept = 0;
 
 
  392  virtual ~Socket() noexcept = 0;
 
  393  virtual 
int bind(sockaddr const *, socklen_t) noexcept = 0;
 
  394  virtual 
int connect(sockaddr const *, socklen_t) noexcept = 0;
 
  395  virtual ssize_t send(
void const *, 
size_t, 
int) noexcept = 0;
 
  396  virtual ssize_t recv(
void *, 
size_t, 
int) noexcept = 0;
 
  397  virtual ssize_t sendto(
void const *, 
size_t, 
int, sockaddr const *, socklen_t) noexcept = 0;
 
  398  virtual ssize_t recvfrom(
void *, 
size_t, 
int, sockaddr *, socklen_t *) noexcept = 0;
 
  399  virtual ssize_t sendmsg(msghdr const *, 
int) noexcept = 0;
 
  400  virtual ssize_t recvmsg(msghdr *, 
int) noexcept = 0;
 
  401  virtual 
int getsockopt(
int level, 
int opt, 
void *, socklen_t *) noexcept = 0;
 
  402  virtual 
int setsockopt(
int level, 
int opt, 
void const *, socklen_t) noexcept = 0;
 
  403  virtual 
int listen(
int) noexcept = 0;
 
  404  virtual 
int accept(sockaddr *addr, socklen_t *) noexcept = 0;
 
  405  virtual 
int shutdown(
int) noexcept = 0;
 
  407  virtual 
int getsockname(sockaddr *, socklen_t *) noexcept = 0;
 
  408  virtual 
int getpeername(sockaddr *, socklen_t *) noexcept = 0;
 
  412Socket::~Socket() noexcept
 
  435  virtual int ioctl(
unsigned long cmd, va_list args) 
noexcept = 0;
 
 
  439Special_file::~Special_file() noexcept
 
  462  friend class Mount_tree;
 
  465  void operator = (File 
const &);
 
  468  File() noexcept : _ref_cnt(0) {}
 
  478  int openat(
const char *path, 
int flags, mode_t mode,
 
  481  void add_ref() 
noexcept { ++_ref_cnt; }
 
  482  int remove_ref() 
noexcept { 
return --_ref_cnt; }
 
  484  virtual ~File() 
noexcept = 0;
 
  487  { 
return _mount_tree; }
 
  489  char const *path() 
const noexcept { 
return _path; }
 
 
  498File::~File() noexcept
 
  508  Path() noexcept : _p(0), _l(0) {}
 
  510  explicit Path(
char const *p) noexcept : _p(p)
 
  511  { 
for (_l = 0; *p; ++p, ++_l) ; }
 
  513  Path(
char const *p, 
unsigned l) noexcept : _p(p), _l(l)
 
  516  static bool __is_sep(
char s) 
noexcept;
 
  518  Path cmp_path(
char const *prefix) 
const noexcept;
 
  521  operator Invalid_ptr 
const * () 
const 
  522  { 
return reinterpret_cast<Invalid_ptr 
const *
>(_p); }
 
  524  unsigned length()
 const { 
return _l; }
 
  525  char const *path()
 const { 
return _p; }
 
  527  bool empty()
 const { 
return _l == 0; }
 
  529  bool is_sep(
unsigned offset)
 const { 
return __is_sep(_p[offset]); }
 
  534    for (; __is_sep(*_p) && _l; ++_p, --_l)
 
  542    for (i = 0; i < _l && !is_sep(i); ++i)
 
  570  explicit Mount_tree(
char *n) 
noexcept;
 
  572  Path lookup(Path 
const &path, cxx::Ref_ptr<Mount_tree> *mt,
 
  573              cxx::Ref_ptr<Mount_tree> *mp = 0) noexcept;
 
  575  Path find(Path const &p, cxx::Ref_ptr<Mount_tree> *t) noexcept;
 
  577  cxx::Ref_ptr<File> mount()
 const 
  580  void mount(cxx::Ref_ptr<File> 
const &m)
 
  582    m->_mount_tree = cxx::ref_ptr(
this);
 
  586  static int create_tree(cxx::Ref_ptr<Mount_tree> 
const &root,
 
  588                         cxx::Ref_ptr<File> 
const &dir) 
noexcept;
 
  590  void add_child_node(cxx::Ref_ptr<Mount_tree> 
const &cld);
 
  592  virtual ~Mount_tree() noexcept  = 0;
 
  594  void add_ref() noexcept { ++_ref_cnt; }
 
  595  int remove_ref() noexcept { 
return --_ref_cnt; }
 
  598  friend class Real_mount_tree;
 
  602  cxx::Ref_ptr<Mount_tree> _cld;
 
  603  cxx::Ref_ptr<Mount_tree> _sib;
 
  604  cxx::Ref_ptr<File> _mount;
 
  608Mount_tree::~Mount_tree() noexcept
 
  612Path::__is_sep(
char s) 
noexcept 
  616Path::cmp_path(
char const *n) 
const noexcept 
  619  for (; *p && !__is_sep(*p) && *n; ++p, ++n)
 
  623  if (*n || (*p && !__is_sep(*p)))
 
  626  return Path(p, _l - (p - _p));
 
  630Mount_tree::Mount_tree(
char *n) noexcept
 
  631: _ref_cnt(0), _name(n)
 
  635Mount_tree::find(Path 
const &p, cxx::Ref_ptr<Mount_tree> *t) 
noexcept 
  640  for (cxx::Ref_ptr<Mount_tree> x = _cld; x; x = x->_sib)
 
  642      Path 
const r = p.cmp_path(x->_name);
 
  654Mount_tree::lookup(Path 
const &path, cxx::Ref_ptr<Mount_tree> *mt,
 
  655                   cxx::Ref_ptr<Mount_tree> *mp) 
noexcept 
  657  cxx::Ref_ptr<Mount_tree> x(
this);
 
  660  if (p.first().cmp_path(
"."))
 
  670      Path r = x->find(p, &x);
 
  708Mount_tree::add_child_node(cxx::Ref_ptr<Mount_tree> 
const &cld)
 
  716File::get_mount(
const char *path, cxx::Ref_ptr<File> *dir,
 
  717                cxx::Ref_ptr<Mount_tree> *mt) 
noexcept 
  721      *dir = cxx::ref_ptr(
this);
 
  725  cxx::Ref_ptr<Mount_tree> mp;
 
  726  Path p = _mount_tree->lookup(Path(path), mt, &mp);
 
  734      *dir = cxx::ref_ptr(
this);
 
  740File::openat(
const char *path, 
int flags, mode_t mode,
 
  741             cxx::Ref_ptr<File> *f) 
noexcept 
  743  cxx::Ref_ptr<File> dir;
 
  744  cxx::Ref_ptr<Mount_tree> mt;
 
  745  char const *m_path = get_mount(path, &dir, &mt);
 
  747  int res = dir->get_entry(m_path, flags, mode, f);
 
  752  if (!(*f)->_mount_tree && mt)
 
  753    (*f)->_mount_tree = mt;
 
  757  for (; i < 
sizeof((*f)->_path) - 1 && path[i]; ++i)
 
  758    (*f)->_path[i] = path[i];
 
  759  (*f)->_path[i] = 
'\0';
 
  777  virtual int mmap2(
void *start, 
size_t len, 
int prot, 
int flags, 
int fd,
 
  778                    off_t offset, 
void **ptr) 
noexcept = 0;
 
  781  virtual int munmap(
void *start, 
size_t len) 
noexcept = 0;
 
  784  virtual int mremap(
void *old, 
size_t old_sz, 
size_t new_sz, 
int flags,
 
  785                     void **new_addr) 
noexcept = 0;
 
  788  virtual int mprotect(
const void *a, 
size_t sz, 
int prot) 
noexcept = 0;
 
  791  virtual int msync(
void *addr, 
size_t len, 
int flags) 
noexcept = 0;
 
  794  virtual int madvise(
void *addr, 
size_t len, 
int advice) 
noexcept = 0;
 
  796  virtual ~Mman() noexcept = 0;
 
 
  807  char const *_proto_name = 0;
 
  809  template<
typename T> 
friend struct cxx::Default_ref_counter;
 
  810  void add_ref() noexcept { ++_ref_cnt; }
 
  811  int remove_ref() noexcept { 
return --_ref_cnt; }
 
  814  explicit File_factory(
int proto) : _proto(proto) {}
 
  815  explicit File_factory(
char const *proto_name) : _proto_name(proto_name) {}
 
  816  File_factory(
int proto, 
char const *proto_name)
 
  817  : _proto(proto), _proto_name(proto_name)
 
  820  File_factory(File_factory 
const &) = 
delete;
 
  821  File_factory &operator = (File_factory 
const &) = 
delete;
 
  823  char const *proto_name()
 const { 
return _proto_name; }
 
  824  int proto()
 const { 
return _proto; }
 
  826  virtual ~File_factory() noexcept = 0;
 
  827  virtual cxx::Ref_ptr<File> create(L4::Cap<
void> file) = 0;
 
  830inline File_factory::~File_factory() noexcept {}
 
  832template<
typename IFACE, 
typename IMPL>
 
  833class File_factory_t : 
public File_factory
 
  837  : File_factory(IFACE::Protocol, L4::
kobject_typeid<IFACE>()->name())
 
  840  cxx::Ref_ptr<File> create(L4::Cap<void> file)
 override 
  863  File_system() noexcept : _next(0) {}
 
  869  virtual char const *
type() const noexcept = 0;
 
  887  virtual 
int mount(
char const *source, 
unsigned long mountflags,
 
  888                    void const *data, 
cxx::Ref_ptr<
File> *dir) noexcept = 0;
 
  890  virtual ~File_system() noexcept = 0;
 
  896  File_system *next() const noexcept { 
return _next; }
 
  898  void next(File_system *n) 
noexcept { _next = n; }
 
 
  902File_system::~File_system() noexcept
 
  905class File_system_list
 
  911    explicit constexpr Iterator(File_system *c = 
nullptr) : _c(c) {}
 
  913    Iterator &operator++()
 
  920    bool operator==(Iterator 
const &other)
 const { 
return _c == other._c; }
 
  921    bool operator!=(Iterator 
const &other)
 const { 
return _c != other._c; }
 
  922    File_system *operator*()
 const { 
return _c; }
 
  923    File_system *operator->()
 const { 
return _c; }
 
  929  File_system_list(File_system *head) : _head(head) {}
 
  931  constexpr Iterator begin()
 const 
  932  { 
return Iterator(_head); }
 
  934  constexpr Iterator end()
 const 
  935  { 
return Iterator(); }
 
 1008  virtual int register_file_system(
File_system *f) 
noexcept = 0;
 
 1017  virtual int unregister_file_system(
File_system *f) 
noexcept = 0;
 
 1026  virtual File_system *get_file_system(
char const *fstype) 
noexcept = 0;
 
 1036  virtual File_system_list file_system_list() noexcept = 0;
 
 1041  int mount(
char const *source, 
char const *target,
 
 1042            char const *fstype, 
unsigned long mountflags,
 
 1043            void const *data) noexcept;
 
 1045  virtual 
int register_file_factory(
cxx::Ref_ptr<File_factory> f) noexcept = 0;
 
 1046  virtual 
int unregister_file_factory(
cxx::Ref_ptr<File_factory> f) noexcept = 0;
 
 1047  virtual 
cxx::Ref_ptr<File_factory> get_file_factory(
int proto) noexcept = 0;
 
 1048  virtual 
cxx::Ref_ptr<File_factory> get_file_factory(
char const *proto_name) noexcept = 0;
 
 1053  int mount_one(
char const *source, 
char const *target,
 
 1055                void const *data) noexcept;
 
 
 1059Fs::mount_one(
char const *source, 
char const *target,
 
 1061              void const *data) noexcept
 
 1064  int res = fs->mount(source, mountflags, data, &dir);
 
 1069  return mount(target, dir);
 
 1074          char const *fstype, 
unsigned long mountflags,
 
 1075          void const *data) 
noexcept 
 1077  if (   fstype[0] == 
'a' 
 1083      File_system_list fsl = file_system_list();
 
 1084      for (File_system_list::Iterator c = fsl.begin(); c != fsl.end(); ++c)
 
 1085        if (mount_one(source, target, *c, mountflags, data) == 0)
 
 1096  return mount_one(source, target, fs, mountflags, data);
 
 
 1112  virtual void *malloc(
size_t bytes) 
noexcept = 0;
 
 1113  virtual void free(
void *mem) 
noexcept = 0;
 
 1114  virtual ~Ops() 
noexcept = 0;
 
 1116  char *strndup(
char const *str, 
unsigned l) 
noexcept 
 1119    for (len = 0; str[len] && len < l; ++len)
 
 1127    char *b = 
static_cast<char *
>(this->malloc(len));
 
 1132    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.
 
virtual int mount(char const *source, unsigned long mountflags, void const *data, cxx::Ref_ptr< File > *dir) noexcept=0
Create a directory object dir representing source mounted with this file system.
 
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.
 
virtual cxx::Ref_ptr< File > get_cwd() noexcept
Get the directory object for the application's current working 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 fstat(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).
 
Ready_type
Type of I/O operation/condition a file can indicate readiness.
 
virtual bool check_ready(Ready_type rt) noexcept=0
Check whether the file is ready for an I/O operation/condition.
 
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 ssize_t writev(const struct iovec *, int iovcnt) noexcept=0
Write one or more blocks of data to the file.
 
virtual L4::Cap< L4Re::Dataspace > data_space() noexcept=0
Get an L4Re::Dataspace object for the file.
 
virtual ssize_t readv(const struct iovec *, int iovcnt) noexcept=0
Read one or more blocks of data from the file.
 
virtual int fdatasync() const noexcept=0
Sync the data to persistent storage.
 
virtual int fsync() const noexcept=0
Sync the data and meta data to persistent storage.
 
virtual off64_t lseek(off64_t, int) noexcept=0
Change the file pointer.
 
virtual int get_lock(struct flock64 *lock) noexcept=0
Test if the given lock can be placed in the file.
 
virtual int ftruncate(off64_t pos) noexcept=0
Truncate the file at the given position.
 
virtual int set_lock(struct flock64 *lock, bool wait) noexcept=0
Acquire or release the given lock on 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.
 
Virtual file system for interfaces in POSIX libc.
 
Cap< T > cap_cast(Cap< F > const &c) noexcept
static_cast for capabilities.