3 * (c) 2010 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
4 * Alexander Warg <warg@os.inf.tu-dresden.de>
5 * economic rights: Technische Universität Dresden (Germany)
7 * This file is part of TUD:OS and distributed under the terms of the
8 * GNU General Public License 2.
9 * Please see the COPYING-GPL-2 file for details.
11 * As a special exception, you may use this file as part of a free software
12 * library without restriction. Specifically, if other files instantiate
13 * templates or use macros or inline functions from this file, or you compile
14 * this file and link it with other files to produce an executable, this
15 * file does not by itself cause the resulting executable to be covered by
16 * the GNU General Public License. This exception does not however
17 * invalidate any other reasons why the executable file might be covered by
18 * the GNU General Public License.
22 #include <l4/l4re_vfs/vfs.h>
24 namespace L4Re { namespace Vfs {
26 /// Reference to the applications L4Re::Vfs::Ops singleton.
27 extern L4Re::Vfs::Ops *vfs_ops asm ("l4re_env_posix_vfs_ops");
32 * \brief Boiler plate class for implementing an open file for L4Re::Vfs.
34 * This class may be used as a base class for everything that a POSIX
35 * file descriptor may point to. This are things such as regular files,
36 * directories, special device files, streams, pipes, and so on.
38 class Be_file : public File
41 // used in close, to unlock all locks of a file (as POSIX says)
42 int unlock_all_locks() throw()
46 L4::Cap<L4Re::Dataspace> data_space() const throw()
47 { return L4::Cap<L4Re::Dataspace>::Invalid; }
49 /// Default backend for POSIX read and readv functions.
50 ssize_t readv(const struct iovec*, int) throw()
53 /// Default backend for POSIX write and writev functions.
54 ssize_t writev(const struct iovec*, int) throw()
57 /// Default backend for POSIX seek and lseek functions.
58 virtual off64_t lseek64(off64_t, int) throw()
61 /// Default backend for the POSIX truncate, ftruncate and similar functions.
62 int ftruncate64(off64_t) throw()
65 /// Default backend for POSIX fsync.
66 int fsync() const throw()
69 /// Default backend for POSIX fdatasync.
70 int fdatasync() const throw()
73 /// Default backend for POSIX ioctl.
74 int ioctl(unsigned long, va_list) throw()
77 /// Default backend for POSIX chmod and fchmod.
78 int fchmod(mode_t) throw()
81 /// Default backend for POSIX fcntl subfunctions.
82 int get_status_flags() const throw()
85 /// Default backend for POSIX fcntl subfunctions.
86 int set_status_flags(long) throw()
89 /// Default backend for POSIX fcntl subfunctions.
90 int get_lock(struct flock64 *) throw()
93 /// Default backend for POSIX fcntl subfunctions.
94 int set_lock(struct flock64 *, bool) throw()
97 /// Default backend for POSIX access and faccessat functions.
98 int faccessat(const char *, int, int) throw()
101 /// Default backend for POSIX utime.
102 int utime(const struct utimbuf *) throw()
105 /// Default backend for POSIX utimes.
106 int utimes(const struct utimbuf [2]) throw()
109 /// Default backend for POSIX mkdir and mkdirat.
110 int mkdir(const char *, mode_t) throw()
113 /// Default backend for POSIX unlink, unlinkat.
114 int unlink(const char *) throw()
117 /// Default backend for POSIX rename, renameat.
118 int rename(const char *, const char *) throw()
121 /// Default backend for POSIX link, linkat.
122 int link(const char *, const char *) throw()
125 /// Default backend for POSIX symlink, symlinkat.
126 int symlink(const char *, const char *) throw()
129 /// Default backend for POSIX rmdir, rmdirat.
130 int rmdir(const char *) throw()
133 /// Default backend for POSIX readlink, readlinkat.
134 ssize_t readlink(char *, size_t)
137 ssize_t getdents(char *, size_t) throw()
141 ~Be_file() throw() = 0;
144 /// Default backend for POSIX openat, open.
145 int get_entry(const char *, int, mode_t, cxx::Ref_ptr<File> *) throw()
149 const char *get_mount(const char *path, cxx::Ref_ptr<File> *dir) throw();
153 Be_file::~Be_file() throw() {}
156 * \brief Boilerplate class for implementing a L4Re::Vfs::File_system.
158 * This class already takes care of registering and unregistering the
159 * file system in the global registry and implements the type() method.
161 class Be_file_system : public File_system
164 char const *const _fstype;
169 * \brief Create a file-system object for the given \a fstype.
170 * \param fstype The type that type() shall return.
172 * This constructor takes care of registering the file system
173 * in the registry of L4Re::Vfs::vfs_ops.
175 explicit Be_file_system(char const *fstype) throw()
176 : File_system(), _fstype(fstype)
178 vfs_ops->register_file_system(this);
182 * \brief Destroy a file-system object.
184 * This destructor takes care of removing this file system
185 * from the registry of L4Re::Vfs::vfs_ops.
187 ~Be_file_system() throw()
189 vfs_ops->unregister_file_system(this);
193 * \brief Return the file-system type.
195 * Returns the file-system type given as \a fstype in the constructor.
197 char const *type() const throw() { return _fstype; }