]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4re_vfs/include/backend
ee449b3634d37dedf27ca97683f07e4bea49a8b8
[l4.git] / l4 / pkg / l4re_vfs / include / backend
1 // vi:ft=cpp
2 /*
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)
6  *
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.
10  *
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.
19  */
20 #pragma once
21
22 #include <l4/l4re_vfs/vfs.h>
23
24 namespace L4Re { namespace Vfs {
25
26 /// Reference to the applications L4Re::Vfs::Ops singleton.
27 extern L4Re::Vfs::Ops *vfs_ops asm ("l4re_env_posix_vfs_ops");
28
29 class Mount_tree;
30
31 /**
32  * \brief Boiler plate class for implementing an open file for L4Re::Vfs.
33  *
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.
37  */
38 class Be_file : public File
39 {
40 public:
41   // used in close, to unlock all locks of a file (as POSIX says)
42   int unlock_all_locks() throw()
43   { return 0; }
44
45   // for mmap
46   L4::Cap<L4Re::Dataspace> data_space() const throw()
47   { return L4::Cap<L4Re::Dataspace>::Invalid; }
48
49   /// Default backend for POSIX read and readv functions.
50   ssize_t readv(const struct iovec*, int) throw()
51   { return -EINVAL; }
52
53   /// Default backend for POSIX write and writev functions.
54   ssize_t writev(const struct iovec*, int) throw()
55   { return -EINVAL; }
56
57   /// Default backend for POSIX seek and lseek functions.
58   virtual off64_t lseek64(off64_t, int) throw()
59   { return -ESPIPE; }
60
61   /// Default backend for the POSIX truncate, ftruncate and similar functions.
62   int ftruncate64(off64_t) throw()
63   { return -EINVAL; }
64
65   /// Default backend for POSIX fsync.
66   int fsync() const throw()
67   { return -EINVAL; }
68
69   /// Default backend for POSIX fdatasync.
70   int fdatasync() const throw()
71   { return -EINVAL; }
72
73   /// Default backend for POSIX ioctl.
74   int ioctl(unsigned long, va_list) throw()
75   { return -EINVAL; }
76
77   /// Default backend for POSIX chmod and fchmod.
78   int fchmod(mode_t) throw()
79   { return -EINVAL; }
80
81   /// Default backend for POSIX fcntl subfunctions.
82   int get_status_flags() const throw()
83   { return 0; }
84
85   /// Default backend for POSIX fcntl subfunctions.
86   int set_status_flags(long) throw()
87   { return 0; }
88
89   /// Default backend for POSIX fcntl subfunctions.
90   int get_lock(struct flock64 *) throw()
91   { return -ENOLCK; }
92
93   /// Default backend for POSIX fcntl subfunctions.
94   int set_lock(struct flock64 *, bool) throw()
95   { return -ENOLCK; }
96
97   /// Default backend for POSIX access and faccessat functions.
98   int faccessat(const char *, int, int) throw()
99   { return -ENOTDIR; }
100
101   /// Default backend for POSIX utime.
102   int utime(const struct utimbuf *) throw()
103   { return -EROFS; }
104
105   /// Default backend for POSIX utimes.
106   int utimes(const struct utimbuf [2]) throw()
107   { return -EROFS; }
108
109   /// Default backend for POSIX mkdir and mkdirat.
110   int mkdir(const char *, mode_t) throw()
111   { return -ENOTDIR; }
112
113   /// Default backend for POSIX unlink, unlinkat.
114   int unlink(const char *) throw()
115   { return -ENOTDIR; }
116
117   /// Default backend for POSIX rename, renameat.
118   int rename(const char *, const char *) throw()
119   { return -ENOTDIR; }
120
121   /// Default backend for POSIX link, linkat.
122   int link(const char *, const char *) throw()
123   { return -ENOTDIR; }
124
125   /// Default backend for POSIX symlink, symlinkat.
126   int symlink(const char *, const char *) throw()
127   { return -EPERM; }
128
129   /// Default backend for POSIX rmdir, rmdirat.
130   int rmdir(const char *) throw()
131   { return -ENOTDIR; }
132
133   /// Default backend for POSIX readlink, readlinkat.
134   ssize_t readlink(char *, size_t)
135   { return -EINVAL; }
136
137   ssize_t getdents(char *, size_t) throw()
138   { return -ENOTDIR; }
139
140
141   ~Be_file() throw() = 0;
142
143 private:
144   /// Default backend for POSIX openat, open.
145   int get_entry(const char *, int, mode_t, cxx::Ref_ptr<File> *) throw()
146   { return -ENOTDIR; }
147
148 protected:
149   const char *get_mount(const char *path, cxx::Ref_ptr<File> *dir) throw();
150 };
151
152 inline
153 Be_file::~Be_file() throw() {}
154
155 /**
156  * \brief Boilerplate class for implementing a L4Re::Vfs::File_system.
157  *
158  * This class already takes care of registering and unregistering the
159  * file system in the global registry and implements the type() method.
160  */
161 class Be_file_system : public File_system
162 {
163 private:
164   char const *const _fstype;
165
166 public:
167
168   /**
169    * \brief Create a file-system object for the given \a fstype.
170    * \param fstype The type that type() shall return.
171    *
172    * This constructor takes care of registering the file system
173    * in the registry of L4Re::Vfs::vfs_ops.
174    */
175   explicit Be_file_system(char const *fstype) throw()
176   : File_system(), _fstype(fstype)
177   {
178     vfs_ops->register_file_system(this);
179   }
180
181   /**
182    * \brief Destroy a file-system object.
183    *
184    * This destructor takes care of removing this file system
185    * from the registry of L4Re::Vfs::vfs_ops.
186    */
187   ~Be_file_system() throw() 
188   {
189     vfs_ops->unregister_file_system(this);
190   }
191
192   /**
193    * \brief Return the file-system type.
194    *
195    * Returns the file-system type given as \a fstype in the constructor.
196    */
197   char const *type() const throw() { return _fstype; }
198 };
199
200
201 }}