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; }
476File::~File() noexcept
486 Path() noexcept : _p(0), _l(0) {}
488 explicit Path(
char const *p) noexcept : _p(p)
489 {
for (_l = 0; *p; ++p, ++_l) ; }
491 Path(
char const *p,
unsigned l) noexcept : _p(p), _l(l)
494 static bool __is_sep(
char s)
noexcept;
496 Path cmp_path(
char const *prefix)
const noexcept;
499 operator Invalid_ptr
const * ()
const
500 {
return reinterpret_cast<Invalid_ptr
const *
>(_p); }
502 unsigned length()
const {
return _l; }
503 char const *path()
const {
return _p; }
505 bool empty()
const {
return _l == 0; }
507 bool is_sep(
unsigned offset)
const {
return __is_sep(_p[offset]); }
512 for (; __is_sep(*_p) && _l; ++_p, --_l)
520 for (i = 0; i < _l && !is_sep(i); ++i)
548 explicit Mount_tree(
char *n)
noexcept;
553 Path find(Path const &p,
cxx::Ref_ptr<Mount_tree> *t) noexcept;
555 cxx::Ref_ptr<File> mount()
const
560 m->_mount_tree = cxx::ref_ptr(
this);
570 virtual ~Mount_tree() noexcept = 0;
572 void add_ref() noexcept { ++_ref_cnt; }
573 int remove_ref() noexcept {
return --_ref_cnt; }
576 friend class Real_mount_tree;
586Mount_tree::~Mount_tree() noexcept
590Path::__is_sep(
char s)
noexcept
594Path::cmp_path(
char const *n)
const noexcept
597 for (; *p && !__is_sep(*p) && *n; ++p, ++n)
601 if (*n || (*p && !__is_sep(*p)))
604 return Path(p, _l - (p - _p));
608Mount_tree::Mount_tree(
char *n) noexcept
609: _ref_cnt(0), _name(n)
620 Path
const r = p.cmp_path(x->_name);
638 if (p.first().cmp_path(
"."))
648 Path r = x->find(p, &x);
699 *dir = cxx::ref_ptr(
this);
704 Path p = _mount_tree->lookup(Path(path), mt, &mp);
712 *dir = cxx::ref_ptr(
this);
718File::openat(
const char *path,
int flags, mode_t mode,
723 path = get_mount(path, &dir, &mt);
725 int res = dir->get_entry(path, flags, mode, f);
730 if (!(*f)->_mount_tree && mt)
731 (*f)->_mount_tree = mt;
748 virtual int mmap2(
void *start,
size_t len,
int prot,
int flags,
int fd,
749 off_t offset,
void **ptr)
noexcept = 0;
752 virtual int munmap(
void *start,
size_t len)
noexcept = 0;
755 virtual int mremap(
void *old,
size_t old_sz,
size_t new_sz,
int flags,
756 void **new_addr)
noexcept = 0;
759 virtual int mprotect(
const void *a,
size_t sz,
int prot)
noexcept = 0;
762 virtual int msync(
void *addr,
size_t len,
int flags)
noexcept = 0;
765 virtual int madvise(
void *addr,
size_t len,
int advice)
noexcept = 0;
767 virtual ~Mman() noexcept = 0;
778 char const *_proto_name = 0;
780 template<
typename T>
friend struct cxx::Default_ref_counter;
781 void add_ref() noexcept { ++_ref_cnt; }
782 int remove_ref() noexcept {
return --_ref_cnt; }
785 explicit File_factory(
int proto) : _proto(proto) {}
786 explicit File_factory(
char const *proto_name) : _proto_name(proto_name) {}
787 File_factory(
int proto,
char const *proto_name)
788 : _proto(proto), _proto_name(proto_name)
791 File_factory(File_factory
const &) =
delete;
792 File_factory &operator = (File_factory
const &) =
delete;
794 char const *proto_name()
const {
return _proto_name; }
795 int proto()
const {
return _proto; }
797 virtual ~File_factory() noexcept = 0;
798 virtual
cxx::Ref_ptr<File> create(
L4::Cap<
void> file) = 0;
801inline File_factory::~File_factory() noexcept {}
803template<
typename IFACE,
typename IMPL>
804class File_factory_t :
public File_factory
812 {
return cxx::ref_ptr(
new IMPL(L4::cap_cast<IFACE>(file))); }
840 virtual char const *
type() const noexcept = 0;
858 virtual
int mount(
char const *source,
unsigned long mountflags,
859 void const *data,
cxx::Ref_ptr<
File> *dir) noexcept = 0;
867 File_system *next() const noexcept {
return _next; }
869 void next(File_system *n)
noexcept { _next = n; }
873File_system::~File_system() noexcept
895 virtual
cxx::Ref_ptr<
File> get_cwd() noexcept {
return get_root(); }
943 virtual int register_file_system(
File_system *f)
noexcept = 0;
952 virtual int unregister_file_system(
File_system *f)
noexcept = 0;
961 virtual File_system *get_file_system(
char const *fstype)
noexcept = 0;
966 int mount(
char const *source,
char const *target,
967 char const *fstype,
unsigned long mountflags,
968 void const *data)
noexcept;
979Fs::mount(
char const *source,
char const *target,
980 char const *fstype,
unsigned long mountflags,
981 void const *data)
noexcept
989 int res = fs->
mount(source, mountflags, data, &dir);
994 return mount(target, dir);
1010 virtual void *malloc(
size_t bytes)
noexcept = 0;
1011 virtual void free(
void *mem)
noexcept = 0;
1012 virtual ~Ops()
noexcept = 0;
1014 char *strndup(
char const *str,
unsigned l)
noexcept
1017 for (len = 0; str[len] && len < l; ++len)
1025 char *b = (
char *)this->malloc(len);
1030 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.
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() const 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.