28 #include <sys/socket.h> 33 # define AT_FDCWD -100 41 #include <l4/cxx/ref_ptr> 88 virtual int fstat64(
struct stat64 *buf)
const throw() = 0;
95 virtual int fchmod(mode_t)
throw() = 0;
125 virtual int utime(
const struct utimbuf *)
throw() = 0;
126 virtual int utimes(
const struct timeval [2])
throw() = 0;
127 virtual ssize_t readlink(
char *,
size_t) = 0;
131 Generic_file::~Generic_file()
throw()
159 virtual int faccessat(
const char *path,
int mode,
int flags)
throw() = 0;
173 virtual int mkdir(
const char *path, mode_t mode)
throw() = 0;
185 virtual int unlink(
const char *path)
throw() = 0;
200 virtual int rename(
const char *src_path,
const char *dst_path)
throw() = 0;
215 virtual int link(
const char *src_path,
const char *dst_path)
throw() = 0;
229 virtual int symlink(
const char *src_path,
const char *dst_path)
throw() = 0;
241 virtual int rmdir(
const char *path)
throw() = 0;
242 virtual int openat(
const char *path,
int flags, mode_t mode,
245 virtual ssize_t getdents(
char *buf,
size_t sizebytes)
throw() = 0;
254 Directory::~Directory()
throw()
288 virtual ssize_t readv(
const struct iovec*,
int iovcnt)
throw() = 0;
300 virtual ssize_t writev(
const struct iovec*,
int iovcnt)
throw() = 0;
302 virtual ssize_t preadv(
const struct iovec *iov,
int iovcnt, off64_t offset)
throw() = 0;
303 virtual ssize_t pwritev(
const struct iovec *iov,
int iovcnt, off64_t offset)
throw() = 0;
312 virtual off64_t lseek64(off64_t,
int)
throw() = 0;
322 virtual int ftruncate64(off64_t pos)
throw() = 0;
329 virtual int fsync()
const throw() = 0;
336 virtual int fdatasync()
const throw() = 0;
347 virtual int get_lock(
struct flock64 *lock)
throw() = 0;
357 virtual int set_lock(
struct flock64 *lock,
bool wait)
throw() = 0;
361 Regular_file::~Regular_file()
throw()
367 virtual ~Socket()
throw() = 0;
368 virtual int bind(sockaddr
const *, socklen_t)
throw() = 0;
369 virtual int connect(sockaddr
const *, socklen_t)
throw() = 0;
370 virtual ssize_t send(
void const *,
size_t,
int)
throw() = 0;
371 virtual ssize_t recv(
void *,
size_t,
int)
throw() = 0;
372 virtual ssize_t sendto(
void const *,
size_t,
int, sockaddr
const *, socklen_t)
throw() = 0;
373 virtual ssize_t recvfrom(
void *,
size_t,
int, sockaddr *, socklen_t *)
throw() = 0;
374 virtual ssize_t sendmsg(msghdr
const *,
int)
throw() = 0;
375 virtual ssize_t recvmsg(msghdr *,
int)
throw() = 0;
376 virtual int getsockopt(
int level,
int opt,
void *, socklen_t *)
throw() = 0;
377 virtual int setsockopt(
int level,
int opt,
void const *, socklen_t)
throw() = 0;
378 virtual int listen(
int)
throw() = 0;
379 virtual int accept(sockaddr *addr, socklen_t *)
throw() = 0;
380 virtual int shutdown(
int)
throw() = 0;
382 virtual int getsockname(sockaddr *, socklen_t *)
throw() = 0;
383 virtual int getpeername(sockaddr *, socklen_t *)
throw() = 0;
387 Socket::~Socket()
throw()
410 virtual int ioctl(
unsigned long cmd, va_list args)
throw() = 0;
414 Special_file::~Special_file()
throw()
437 friend class Mount_tree;
440 void operator = (
File const &);
443 File()
throw() : _ref_cnt(0) {}
453 int openat(
const char *path,
int flags, mode_t mode,
456 void add_ref()
throw() { ++_ref_cnt; }
457 int remove_ref()
throw() {
return --_ref_cnt; }
459 virtual ~
File()
throw() = 0;
462 {
return _mount_tree; }
471 File::~File()
throw()
481 Path()
throw() : _p(0), _l(0) {}
483 explicit Path(
char const *p)
throw() : _p(p)
484 {
for (_l = 0; *p; ++p, ++_l) ; }
486 Path(
char const *p,
unsigned l)
throw() : _p(p), _l(l)
489 static bool __is_sep(
char s)
throw();
491 Path cmp_path(
char const *prefix)
const throw();
494 operator Invalid_ptr
const * ()
const 495 {
return reinterpret_cast<Invalid_ptr
const *
>(_p); }
497 unsigned length()
const {
return _l; }
498 char const *path()
const {
return _p; }
500 bool empty()
const {
return _l == 0; }
502 bool is_sep(
unsigned offset)
const {
return __is_sep(_p[offset]); }
507 for (; __is_sep(*_p) && _l; ++_p, --_l)
515 for (i = 0; i < _l && !is_sep(i); ++i)
543 explicit Mount_tree(
char *n)
throw();
555 m->_mount_tree = cxx::ref_ptr(
this);
565 virtual ~Mount_tree()
throw() = 0;
567 void add_ref()
throw() { ++_ref_cnt; }
568 int remove_ref()
throw() {
return --_ref_cnt; }
571 friend class Real_mount_tree;
581 Mount_tree::~Mount_tree()
throw()
585 Path::__is_sep(
char s)
throw()
589 Path::cmp_path(
char const *n)
const throw()
592 for (; *p && !__is_sep(*p) && *n; ++p, ++n)
596 if (*n || (*p && !__is_sep(*p)))
599 return Path(p, _l - (p - _p));
603 Mount_tree::Mount_tree(
char *n)
throw()
604 : _ref_cnt(0), _name(n)
615 Path
const r = p.cmp_path(x->_name);
633 if (p.first().cmp_path(
"."))
643 Path r = x->find(p, &x);
691 class Real_mount_tree :
public Mount_tree
694 explicit Real_mount_tree(
char *n) : Mount_tree(n) {}
702 Path p = root->lookup(Path(path), &base);
706 Path f = p.strip_first();
711 char *name = strndup(f.path(), f.length());
722 nt->_sib = base->_cld;
744 *dir = cxx::ref_ptr(
this);
749 Path p = _mount_tree->lookup(Path(path), mt, &mp);
757 *dir = cxx::ref_ptr(
this);
763 File::openat(
const char *path,
int flags, mode_t mode,
768 path = get_mount(path, &dir, &mt);
770 int res = dir->get_entry(path, flags, mode, f);
775 if (!(*f)->_mount_tree && mt)
776 (*f)->_mount_tree = mt;
793 virtual int mmap2(
void *start,
size_t len,
int prot,
int flags,
int fd,
794 off_t offset,
void **ptr)
throw() = 0;
797 virtual int munmap(
void *start,
size_t len)
throw() = 0;
800 virtual int mremap(
void *old,
size_t old_sz,
size_t new_sz,
int flags,
801 void **new_addr)
throw() = 0;
804 virtual int mprotect(
const void *a,
size_t sz,
int prot)
throw() = 0;
807 virtual int msync(
void *addr,
size_t len,
int flags)
throw() = 0;
810 virtual int madvise(
void *addr,
size_t len,
int advice)
throw() = 0;
812 virtual ~
Mman()
throw() = 0;
816 Mman::~Mman()
throw() {}
823 char const *_proto_name = 0;
825 template<
typename T>
friend struct cxx::Default_ref_counter;
826 void add_ref()
throw() { ++_ref_cnt; }
827 int remove_ref()
throw() {
return --_ref_cnt; }
830 explicit File_factory(
int proto) : _proto(proto) {}
831 explicit File_factory(
char const *proto_name) : _proto_name(proto_name) {}
832 File_factory(File_factory
const &) =
delete;
833 File_factory &operator = (File_factory
const &) =
delete;
835 char const *proto_name()
const {
return _proto_name; }
836 int proto()
const {
return _proto; }
838 virtual ~File_factory()
throw() = 0;
842 inline File_factory::~File_factory()
throw() {}
844 template<
typename IFACE,
typename IMPL>
845 class File_factory_t :
public File_factory
848 File_factory_t() : File_factory(IFACE::Protocol) {}
849 void operator delete (
void *) {}
851 {
return cxx::ref_ptr(
new IMPL(L4::cap_cast<IFACE>(file))); }
879 virtual char const *type()
const throw() = 0;
896 virtual int mount(
char const *source,
unsigned long mountflags,
905 File_system *next()
const throw() {
return _next; }
911 File_system::~File_system()
throw()
976 virtual int register_file_system(
File_system *f)
throw() = 0;
985 virtual int unregister_file_system(
File_system *f)
throw() = 0;
994 virtual File_system *get_file_system(
char const *fstype)
throw() = 0;
999 int mount(
char const *source,
char const *target,
1000 char const *fstype,
unsigned long mountflags,
1001 void const *data)
throw();
1016 return Mount_tree::create_tree(root, path, dir);
1023 char const *fstype,
unsigned long mountflags,
1024 void const *data)
throw()
1032 int res = fs->
mount(source, mountflags, data, &dir);
1037 return mount(target, dir);
1048 virtual void *malloc(
size_t) noexcept = 0;
1049 virtual void free(
void *m) noexcept = 0;
1050 virtual ~App_api() = 0;
1066 virtual ~
Ops()
throw() = 0;
POSIX File-system related functionality.
A reference-counting pointer with automatic cleanup.
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.
Interface for the POSIX backends for an application.
Interface for the POSIX memory management.
virtual int unlock_all_locks()=0
Unlock all locks on the file.
Abstract capability-allocator interface.
virtual cxx::Ref_ptr< File > get_cwd()
Get the directory object for the applications current working directory.
Capability allocator interface.
The basic interface for an open POSIX file.
L4::Cap related definitions.
L4 compiler related defines.
int mount(char const *path, cxx::Ref_ptr< File > const &dir)
Mount a given file object at the given global path in the VFS.
virtual void set_cwd(cxx::Ref_ptr< File > const &)
Set the current working directory for the application.
virtual int set_status_flags(long flags)=0
Set file status flags (fcntl F_SETFL).
_Cap_alloc & cap_alloc
Capability allocator.
The common interface for an open POSIX file.
Interface for a POSIX file that provides special file semantics.
Interface for a POSIX file that provides regular file semantics.
Interface for a POSIX file that is a directory.
virtual int fchmod(mode_t)=0
Change POSIX access rights on that file.
virtual int get_status_flags() const =0
Get file status flags (fcntl F_GETFL).
virtual int fstat64(struct stat64 *buf) const =0
Get status information for the file.
Basic interface for an L4Re::Vfs file system.