28 #include <sys/socket.h> 33 # define AT_FDCWD -100 41 #include <l4/cxx/ref_ptr> 86 virtual int fstat64(
struct stat64 *buf)
const throw() = 0;
93 virtual int fchmod(mode_t)
throw() = 0;
123 virtual int utime(
const struct utimbuf *)
throw() = 0;
124 virtual int utimes(
const struct timeval [2])
throw() = 0;
125 virtual ssize_t readlink(
char *,
size_t) = 0;
129 Generic_file::~Generic_file()
throw()
157 virtual int faccessat(
const char *path,
int mode,
int flags)
throw() = 0;
171 virtual int mkdir(
const char *path, mode_t mode)
throw() = 0;
183 virtual int unlink(
const char *path)
throw() = 0;
198 virtual int rename(
const char *src_path,
const char *dst_path)
throw() = 0;
213 virtual int link(
const char *src_path,
const char *dst_path)
throw() = 0;
227 virtual int symlink(
const char *src_path,
const char *dst_path)
throw() = 0;
239 virtual int rmdir(
const char *path)
throw() = 0;
240 virtual int openat(
const char *path,
int flags, mode_t mode,
243 virtual ssize_t getdents(
char *buf,
size_t sizebytes)
throw() = 0;
245 virtual int fchmodat(
const char *pathname,
246 mode_t mode,
int flags)
throw() = 0;
248 virtual int utimensat(
const char *pathname,
249 const struct timespec times[2],
int flags)
throw() = 0;
258 Directory::~Directory()
throw()
292 virtual ssize_t readv(
const struct iovec*,
int iovcnt)
throw() = 0;
304 virtual ssize_t writev(
const struct iovec*,
int iovcnt)
throw() = 0;
306 virtual ssize_t preadv(
const struct iovec *iov,
int iovcnt, off64_t offset)
throw() = 0;
307 virtual ssize_t pwritev(
const struct iovec *iov,
int iovcnt, off64_t offset)
throw() = 0;
316 virtual off64_t lseek64(off64_t,
int)
throw() = 0;
326 virtual int ftruncate64(off64_t pos)
throw() = 0;
333 virtual int fsync()
const throw() = 0;
340 virtual int fdatasync()
const throw() = 0;
351 virtual int get_lock(
struct flock64 *lock)
throw() = 0;
361 virtual int set_lock(
struct flock64 *lock,
bool wait)
throw() = 0;
365 Regular_file::~Regular_file()
throw()
371 virtual ~Socket()
throw() = 0;
372 virtual int bind(sockaddr
const *, socklen_t)
throw() = 0;
373 virtual int connect(sockaddr
const *, socklen_t)
throw() = 0;
374 virtual ssize_t send(
void const *,
size_t,
int)
throw() = 0;
375 virtual ssize_t recv(
void *,
size_t,
int)
throw() = 0;
376 virtual ssize_t sendto(
void const *,
size_t,
int, sockaddr
const *, socklen_t)
throw() = 0;
377 virtual ssize_t recvfrom(
void *,
size_t,
int, sockaddr *, socklen_t *)
throw() = 0;
378 virtual ssize_t sendmsg(msghdr
const *,
int)
throw() = 0;
379 virtual ssize_t recvmsg(msghdr *,
int)
throw() = 0;
380 virtual int getsockopt(
int level,
int opt,
void *, socklen_t *)
throw() = 0;
381 virtual int setsockopt(
int level,
int opt,
void const *, socklen_t)
throw() = 0;
382 virtual int listen(
int)
throw() = 0;
383 virtual int accept(sockaddr *addr, socklen_t *)
throw() = 0;
384 virtual int shutdown(
int)
throw() = 0;
386 virtual int getsockname(sockaddr *, socklen_t *)
throw() = 0;
387 virtual int getpeername(sockaddr *, socklen_t *)
throw() = 0;
391 Socket::~Socket()
throw()
414 virtual int ioctl(
unsigned long cmd, va_list args)
throw() = 0;
418 Special_file::~Special_file()
throw()
441 friend class Mount_tree;
444 void operator = (
File const &);
447 File()
throw() : _ref_cnt(0) {}
457 int openat(
const char *path,
int flags, mode_t mode,
460 void add_ref()
throw() { ++_ref_cnt; }
461 int remove_ref()
throw() {
return --_ref_cnt; }
463 virtual ~
File()
throw() = 0;
466 {
return _mount_tree; }
475 File::~File()
throw()
485 Path()
throw() : _p(0), _l(0) {}
487 explicit Path(
char const *p)
throw() : _p(p)
488 {
for (_l = 0; *p; ++p, ++_l) ; }
490 Path(
char const *p,
unsigned l)
throw() : _p(p), _l(l)
493 static bool __is_sep(
char s)
throw();
495 Path cmp_path(
char const *prefix)
const throw();
498 operator Invalid_ptr
const * ()
const 499 {
return reinterpret_cast<Invalid_ptr
const *
>(_p); }
501 unsigned length()
const {
return _l; }
502 char const *path()
const {
return _p; }
504 bool empty()
const {
return _l == 0; }
506 bool is_sep(
unsigned offset)
const {
return __is_sep(_p[offset]); }
511 for (; __is_sep(*_p) && _l; ++_p, --_l)
519 for (i = 0; i < _l && !is_sep(i); ++i)
547 explicit Mount_tree(
char *n)
throw();
559 m->_mount_tree = cxx::ref_ptr(
this);
569 virtual ~Mount_tree()
throw() = 0;
571 void add_ref()
throw() { ++_ref_cnt; }
572 int remove_ref()
throw() {
return --_ref_cnt; }
575 friend class Real_mount_tree;
585 Mount_tree::~Mount_tree()
throw()
589 Path::__is_sep(
char s)
throw()
593 Path::cmp_path(
char const *n)
const throw()
596 for (; *p && !__is_sep(*p) && *n; ++p, ++n)
600 if (*n || (*p && !__is_sep(*p)))
603 return Path(p, _l - (p - _p));
607 Mount_tree::Mount_tree(
char *n)
throw()
608 : _ref_cnt(0), _name(n)
619 Path
const r = p.cmp_path(x->_name);
637 if (p.first().cmp_path(
"."))
647 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);
718 File::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)
throw() = 0;
752 virtual int munmap(
void *start,
size_t len)
throw() = 0;
755 virtual int mremap(
void *old,
size_t old_sz,
size_t new_sz,
int flags,
756 void **new_addr)
throw() = 0;
759 virtual int mprotect(
const void *a,
size_t sz,
int prot)
throw() = 0;
762 virtual int msync(
void *addr,
size_t len,
int flags)
throw() = 0;
765 virtual int madvise(
void *addr,
size_t len,
int advice)
throw() = 0;
767 virtual ~
Mman()
throw() = 0;
771 Mman::~Mman()
throw() {}
778 char const *_proto_name = 0;
780 template<
typename T>
friend struct cxx::Default_ref_counter;
781 void add_ref()
throw() { ++_ref_cnt; }
782 int remove_ref()
throw() {
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(File_factory
const &) =
delete;
788 File_factory &operator = (File_factory
const &) =
delete;
790 char const *proto_name()
const {
return _proto_name; }
791 int proto()
const {
return _proto; }
793 virtual ~File_factory()
throw() = 0;
797 inline File_factory::~File_factory()
throw() {}
799 template<
typename IFACE,
typename IMPL>
800 class File_factory_t :
public File_factory
803 File_factory_t() : File_factory(IFACE::Protocol) {}
805 {
return cxx::ref_ptr(
new IMPL(L4::cap_cast<IFACE>(file))); }
833 virtual char const *type()
const throw() = 0;
850 virtual int mount(
char const *source,
unsigned long mountflags,
859 File_system *next()
const throw() {
return _next; }
865 File_system::~File_system()
throw()
930 virtual int register_file_system(
File_system *f)
throw() = 0;
939 virtual int unregister_file_system(
File_system *f)
throw() = 0;
948 virtual File_system *get_file_system(
char const *fstype)
throw() = 0;
953 int mount(
char const *source,
char const *target,
954 char const *fstype,
unsigned long mountflags,
955 void const *data)
throw();
967 char const *fstype,
unsigned long mountflags,
968 void const *data)
throw()
976 int res = fs->
mount(source, mountflags, data, &dir);
981 return mount(target, dir);
997 virtual void *malloc(
size_t bytes) noexcept = 0;
998 virtual void free(
void *mem) noexcept = 0;
999 virtual ~
Ops()
throw() = 0;
1001 char *strndup(
char const *str,
unsigned l) noexcept
1004 for (len = 0; str[len] && len < l; ++len)
1012 char *b = (
char *)this->malloc(len);
1017 for (; len - 1 > 0 && *str; --len, ++b, ++str)
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.
The basic interface for an open POSIX file.
L4::Cap related definitions.
L4 compiler related defines.
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).
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 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 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.