28 #include <sys/socket.h>
33 # define AT_FDCWD -100
42 #include <l4/cxx/ref_ptr>
87 virtual
int fstat64(struct stat64 *buf) const throw() = 0;
94 virtual
int fchmod(mode_t) throw() = 0;
124 virtual
int utime(const struct utimbuf *) throw() = 0;
125 virtual
int utimes(const struct timeval [2]) throw() = 0;
126 virtual ssize_t readlink(
char *,
size_t) = 0;
158 virtual int faccessat(
const char *path,
int mode,
int flags)
throw() = 0;
172 virtual int mkdir(
const char *path, mode_t mode)
throw() = 0;
184 virtual int unlink(
const char *path)
throw() = 0;
199 virtual int rename(
const char *src_path,
const char *dst_path)
throw() = 0;
214 virtual int link(
const char *src_path,
const char *dst_path)
throw() = 0;
228 virtual int symlink(
const char *src_path,
const char *dst_path)
throw() = 0;
240 virtual int rmdir(
const char *path)
throw() = 0;
241 virtual int openat(
const char *path,
int flags, mode_t mode,
244 virtual ssize_t getdents(
char *buf,
size_t sizebytes)
throw() = 0;
246 virtual int fchmodat(
const char *pathname,
247 mode_t mode,
int flags)
throw() = 0;
249 virtual int utimensat(
const char *pathname,
250 const struct timespec times[2],
int flags)
throw() = 0;
259 Directory::~Directory() throw()
293 virtual ssize_t readv(const struct iovec*,
int iovcnt) throw() = 0;
305 virtual ssize_t writev(const struct iovec*,
int iovcnt) throw() = 0;
307 virtual ssize_t preadv(const struct iovec *iov,
int iovcnt, off64_t offset) throw() = 0;
308 virtual ssize_t pwritev(const struct iovec *iov,
int iovcnt, off64_t offset) throw() = 0;
317 virtual off64_t lseek64(off64_t,
int) throw() = 0;
327 virtual
int ftruncate64(off64_t pos) throw() = 0;
334 virtual
int fsync() const throw() = 0;
341 virtual
int fdatasync() const throw() = 0;
352 virtual
int get_lock(struct flock64 *lock) throw() = 0;
362 virtual
int set_lock(struct flock64 *lock,
bool wait) throw() = 0;
372 virtual ~Socket() throw() = 0;
373 virtual
int bind(sockaddr const *, socklen_t) throw() = 0;
374 virtual
int connect(sockaddr const *, socklen_t) throw() = 0;
375 virtual ssize_t send(
void const *,
size_t,
int) throw() = 0;
376 virtual ssize_t recv(
void *,
size_t,
int) throw() = 0;
377 virtual ssize_t sendto(
void const *,
size_t,
int, sockaddr const *, socklen_t) throw() = 0;
378 virtual ssize_t recvfrom(
void *,
size_t,
int, sockaddr *, socklen_t *) throw() = 0;
379 virtual ssize_t sendmsg(msghdr const *,
int) throw() = 0;
380 virtual ssize_t recvmsg(msghdr *,
int) throw() = 0;
381 virtual
int getsockopt(
int level,
int opt,
void *, socklen_t *) throw() = 0;
382 virtual
int setsockopt(
int level,
int opt,
void const *, socklen_t) throw() = 0;
383 virtual
int listen(
int) throw() = 0;
384 virtual
int accept(sockaddr *addr, socklen_t *) throw() = 0;
385 virtual
int shutdown(
int) throw() = 0;
387 virtual
int getsockname(sockaddr *, socklen_t *) throw() = 0;
388 virtual
int getpeername(sockaddr *, socklen_t *) throw() = 0;
392 Socket::~Socket() throw()
415 virtual int ioctl(
unsigned long cmd, va_list args)
throw() = 0;
419 Special_file::~Special_file() throw()
442 friend class Mount_tree;
445 void operator = (
File const &);
448 File()
throw() : _ref_cnt(0) {}
458 int openat(
const char *path,
int flags, mode_t mode,
461 void add_ref()
throw() { ++_ref_cnt; }
462 int remove_ref()
throw() {
return --_ref_cnt; }
464 virtual ~
File()
throw() = 0;
467 {
return _mount_tree; }
476 File::~File() throw()
486 Path() throw() : _p(0), _l(0) {}
488 explicit Path(
char const *p)
throw() : _p(p)
489 {
for (_l = 0; *p; ++p, ++_l) ; }
491 Path(
char const *p,
unsigned l)
throw() : _p(p), _l(l)
494 static bool __is_sep(
char s)
throw();
496 Path cmp_path(
char const *prefix)
const throw();
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)
throw();
553 Path find(Path const &p,
cxx::Ref_ptr<Mount_tree> *t) throw();
555 cxx::Ref_ptr<File> mount()
const
560 m->_mount_tree = cxx::ref_ptr(
this);
570 virtual ~Mount_tree() throw() = 0;
572 void add_ref() throw() { ++_ref_cnt; }
573 int remove_ref() throw() {
return --_ref_cnt; }
576 friend class Real_mount_tree;
586 Mount_tree::~Mount_tree() throw()
590 Path::__is_sep(
char s)
throw()
594 Path::cmp_path(
char const *n)
const throw()
597 for (; *p && !__is_sep(*p) && *n; ++p, ++n)
601 if (*n || (*p && !__is_sep(*p)))
604 return Path(p, _l - (p - _p));
608 Mount_tree::Mount_tree(
char *n)
throw()
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);
700 *dir = cxx::ref_ptr(
this);
705 Path p = _mount_tree->lookup(Path(path), mt, &mp);
713 *dir = cxx::ref_ptr(
this);
719 File::openat(
const char *path,
int flags, mode_t mode,
724 path = get_mount(path, &dir, &mt);
726 int res = dir->get_entry(path, flags, mode, f);
731 if (!(*f)->_mount_tree && mt)
732 (*f)->_mount_tree = mt;
749 virtual int mmap2(
void *start,
size_t len,
int prot,
int flags,
int fd,
750 off_t offset,
void **ptr)
throw() = 0;
753 virtual int munmap(
void *start,
size_t len)
throw() = 0;
756 virtual int mremap(
void *old,
size_t old_sz,
size_t new_sz,
int flags,
757 void **new_addr)
throw() = 0;
760 virtual int mprotect(
const void *a,
size_t sz,
int prot)
throw() = 0;
763 virtual int msync(
void *addr,
size_t len,
int flags)
throw() = 0;
766 virtual int madvise(
void *addr,
size_t len,
int advice)
throw() = 0;
768 virtual ~
Mman() throw() = 0;
779 char const *_proto_name = 0;
781 template<
typename T>
friend struct cxx::Default_ref_counter;
782 void add_ref() throw() { ++_ref_cnt; }
783 int remove_ref() throw() {
return --_ref_cnt; }
786 explicit File_factory(
int proto) : _proto(proto) {}
787 explicit File_factory(
char const *proto_name) : _proto_name(proto_name) {}
788 File_factory(
int proto,
char const *proto_name)
789 : _proto(proto), _proto_name(proto_name)
792 File_factory(File_factory
const &) =
delete;
793 File_factory &operator = (File_factory
const &) =
delete;
795 char const *proto_name()
const {
return _proto_name; }
796 int proto()
const {
return _proto; }
798 virtual ~File_factory() throw() = 0;
799 virtual
cxx::Ref_ptr<File> create(
L4::Cap<
void> file) = 0;
802 inline File_factory::~File_factory() throw() {}
804 template<
typename IFACE,
typename IMPL>
805 class File_factory_t :
public File_factory
813 {
return cxx::ref_ptr(
new IMPL(L4::cap_cast<IFACE>(file))); }
841 virtual char const *
type()
const throw() = 0;
858 virtual
int mount(
char const *source,
unsigned long mountflags,
859 void const *data,
cxx::Ref_ptr<
File> *dir) throw() = 0;
867 File_system *next() const throw() {
return _next; }
869 void next(File_system *n)
throw() { _next = n; }
873 File_system::~File_system() throw()
895 virtual
cxx::Ref_ptr<
File> get_cwd() throw() {
return get_root(); }
943 virtual int register_file_system(
File_system *f)
throw() = 0;
952 virtual int unregister_file_system(
File_system *f)
throw() = 0;
961 virtual File_system *get_file_system(
char const *fstype)
throw() = 0;
966 int mount(
char const *source,
char const *target,
967 char const *fstype,
unsigned long mountflags,
968 void const *data)
throw();
980 char const *fstype,
unsigned long mountflags,
981 void const *data)
throw()
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()
throw() = 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 link(const char *src_path, const char *dst_path)=0
Create a hard link (second name) for the given file.
virtual int rename(const char *src_path, const char *dst_path)=0
Rename the given file.
virtual int rmdir(const char *path)=0
Delete an empty directory.
virtual int unlink(const char *path)=0
Unlink the given file from that directory.
virtual int faccessat(const char *path, int mode, int flags)=0
Check access permissions on the given file.
virtual int symlink(const char *src_path, const char *dst_path)=0
Create a symbolic link for the given file.
virtual int mkdir(const char *path, mode_t mode)=0
Create a new subdirectory.
Basic interface for an L4Re::Vfs file system.
virtual int mount(char const *source, unsigned long mountflags, void const *data, cxx::Ref_ptr< File > *dir)=0
Create a directory object dir representing source mounted with this file system.
virtual char const * type() const =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 &)
Set the current working directory for the application.
virtual int mount(char const *path, cxx::Ref_ptr< File > const &dir)=0
Mount a given file object at the given global path in the VFS.
virtual cxx::Ref_ptr< File > free_fd(int fd)=0
Free the file descriptor fd.
virtual cxx::Ref_ptr< File > get_file(int fd)=0
Get the L4Re::Vfs::File for the file descriptor fd.
virtual int alloc_fd(cxx::Ref_ptr< File > const &f=cxx::Ref_ptr<>::Nil)=0
Allocate the next free file descriptor.
virtual cxx::Ref_ptr< File > get_root()=0
Get the directory object for the applications root directory.
virtual cxx::Pair< cxx::Ref_ptr< File >, int > set_fd(int fd, cxx::Ref_ptr< File > const &f=cxx::Ref_ptr<>::Nil)=0
Set the file object referenced by the file descriptor fd.
The common interface for an open POSIX file.
virtual int set_status_flags(long flags)=0
Set file status flags (fcntl F_SETFL).
virtual int fstat64(struct stat64 *buf) const =0
Get status information for the file.
virtual int unlock_all_locks()=0
Unlock all locks on the file.
virtual int get_status_flags() const =0
Get file status flags (fcntl F_GETFL).
virtual int fchmod(mode_t)=0
Change POSIX access rights on that file.
Interface for the POSIX memory management.
virtual int mmap2(void *start, size_t len, int prot, int flags, int fd, off_t offset, void **ptr)=0
Backend for the mmap2 system call.
virtual int madvise(void *addr, size_t len, int advice)=0
Backend for the madvice system call.
virtual int msync(void *addr, size_t len, int flags)=0
Backend for the msync system call.
virtual int mprotect(const void *a, size_t sz, int prot)=0
Backend for the mprotect system call.
virtual int munmap(void *start, size_t len)=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)=0
Backend for the mremap system call.
Interface for the POSIX backends for an application.
Interface for a POSIX file that provides regular file semantics.
virtual L4::Cap< L4Re::Dataspace > data_space() const =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)=0
The famous IO control.
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.