1 | /* |
---|
2 | * vfs.h - Virtual File System definition. |
---|
3 | * |
---|
4 | * Author Mohamed Lamine Karaoui (2014,2015) |
---|
5 | * Alain Greiner (2016,2017,2018) |
---|
6 | * |
---|
7 | * Copyright (c) UPMC Sorbonne Universites |
---|
8 | * |
---|
9 | * This file is part of ALMOS-MKH. |
---|
10 | * |
---|
11 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
12 | * under the terms of the GNU General Public License as published by |
---|
13 | * the Free Software Foundation; version 2.0 of the License. |
---|
14 | * |
---|
15 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
18 | * General Public License for more details. |
---|
19 | * |
---|
20 | * You should have received a copy of the GNU General Public License |
---|
21 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
22 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
23 | */ |
---|
24 | |
---|
25 | #ifndef _VFS_H_ |
---|
26 | #define _VFS_H_ |
---|
27 | |
---|
28 | #include <kernel_config.h> |
---|
29 | #include <hal_kernel_types.h> |
---|
30 | #include <hal_atomic.h> |
---|
31 | #include <remote_rwlock.h> |
---|
32 | #include <remote_busylock.h> |
---|
33 | #include <busylock.h> |
---|
34 | #include <list.h> |
---|
35 | #include <xlist.h> |
---|
36 | #include <bits.h> |
---|
37 | #include <xhtab.h> |
---|
38 | #include <errno.h> |
---|
39 | #include <shared_syscalls.h> |
---|
40 | #include <fatfs.h> |
---|
41 | #include <ramfs.h> |
---|
42 | #include <devfs.h> |
---|
43 | |
---|
44 | /**** Forward declarations ***/ |
---|
45 | |
---|
46 | struct vfs_inode_s; |
---|
47 | struct vfs_dentry_t; |
---|
48 | struct vfs_ctx_t; |
---|
49 | struct vfs_file_ref_s; |
---|
50 | struct vfs_file_s; |
---|
51 | |
---|
52 | struct vfs_inode_op_s; |
---|
53 | struct vfs_dentry_op_s; |
---|
54 | struct vfs_file_op_s; |
---|
55 | struct vfs_ctx_op_s; |
---|
56 | |
---|
57 | struct vfs_lookup_cmd_s; |
---|
58 | struct vfs_lookup_rsp_s; |
---|
59 | |
---|
60 | struct mapper_s; |
---|
61 | struct process_s; |
---|
62 | struct device_s; |
---|
63 | struct vseg_s; |
---|
64 | struct page_s; |
---|
65 | |
---|
66 | |
---|
67 | /****************************************************************************************** |
---|
68 | * These flags are used to define the working mode of the vfs_lookup() function. |
---|
69 | *****************************************************************************************/ |
---|
70 | |
---|
71 | #define VFS_LOOKUP_DIR 0x01 /* the searched inode is a directory */ |
---|
72 | #define VFS_LOOKUP_OPEN 0x02 /* the search is for an open/opendir */ |
---|
73 | #define VFS_LOOKUP_PARENT 0x04 /* return the parent inode (not the inode itself) */ |
---|
74 | #define VFS_LOOKUP_CREATE 0x10 /* file must be created if missing */ |
---|
75 | #define VFS_LOOKUP_EXCL 0x20 /* file cannot previously exist */ |
---|
76 | |
---|
77 | /****************************************************************************************** |
---|
78 | * This structure defines a VFS context, that contains informations common to all inodes |
---|
79 | * and dentries for a given file system. As it is declared as a global variable in the |
---|
80 | * kdata segment, it is handled as private by each OS intance in a given cluster. |
---|
81 | *****************************************************************************************/ |
---|
82 | |
---|
83 | typedef enum |
---|
84 | { |
---|
85 | FS_TYPE_DEVFS = 0, |
---|
86 | FS_TYPE_FATFS = 1, |
---|
87 | FS_TYPE_RAMFS = 2, |
---|
88 | |
---|
89 | FS_TYPES_NR = 3, |
---|
90 | } |
---|
91 | vfs_fs_type_t; |
---|
92 | |
---|
93 | typedef enum |
---|
94 | { |
---|
95 | CTX_ATTR_READ_ONLY = 0x01, /*! write access prohibited */ |
---|
96 | CTX_ATTR_SYNC = 0x10, /*! synchronise FS on each write */ |
---|
97 | } |
---|
98 | vfs_ctx_attr_t; |
---|
99 | |
---|
100 | typedef struct vfs_ctx_s |
---|
101 | { |
---|
102 | vfs_fs_type_t type; /*! File System type */ |
---|
103 | uint32_t attr; /*! global attributes for all files in FS */ |
---|
104 | uint32_t total_clusters; /*! total number of clusters on device */ |
---|
105 | uint32_t cluster_size; /*! cluster size on device (bytes) */ |
---|
106 | xptr_t vfs_root_xp; /*! extended pointer on VFS root inode */ |
---|
107 | busylock_t lock; /*! lock protecting inum allocator */ |
---|
108 | uint32_t bitmap[BITMAP_SIZE(CONFIG_VFS_MAX_INODES)]; /* inum allocator */ |
---|
109 | void * extend; /*! FS specific context extension */ |
---|
110 | } |
---|
111 | vfs_ctx_t; |
---|
112 | |
---|
113 | /****************************************************************************************** |
---|
114 | * This structure define a VFS inode. |
---|
115 | * It contains an extended pointer on the parent dentry, and (for directory only) |
---|
116 | * an hash table (xhtab) registering all children dentries. |
---|
117 | * The <parent> inode is unique for a directory (no hard links for directories). |
---|
118 | * For a file, the parent field points to the first dentry who created this inode. |
---|
119 | * Synchronisation: |
---|
120 | * - the main_lock (remote_busylock) is used during the inode tree traversal, |
---|
121 | * or for inode modification (add/remove children). |
---|
122 | * - the data_lock (remote_rwlock) is used during read/write accesses to the data |
---|
123 | * stored in the mapper. |
---|
124 | * - the mapper lock (remote rwlock) is only used during the radix tree traversal |
---|
125 | * to return the relevant page for read/write. |
---|
126 | *****************************************************************************************/ |
---|
127 | |
---|
128 | /* this enum define the VFS inode types values */ |
---|
129 | /* WARNING : this enum must be kept consistent with macros in <shared_stat.h> file */ |
---|
130 | |
---|
131 | typedef enum |
---|
132 | { |
---|
133 | INODE_TYPE_FILE = 0, /*! regular file */ |
---|
134 | INODE_TYPE_DIR = 1, /*! directory */ |
---|
135 | INODE_TYPE_FIFO = 2, /*! POSIX named pipe */ |
---|
136 | INODE_TYPE_PIPE = 3, /*! POSIX anonymous pipe */ |
---|
137 | INODE_TYPE_SOCK = 4, /*! POSIX socket */ |
---|
138 | INODE_TYPE_DEV = 5, /*! character device */ |
---|
139 | INODE_TYPE_SYML = 6, /*! symbolic link */ |
---|
140 | } |
---|
141 | vfs_inode_type_t; |
---|
142 | |
---|
143 | /* this enum define the VFS inode attributes values */ |
---|
144 | |
---|
145 | typedef enum |
---|
146 | { |
---|
147 | INODE_ATTR_DIRTY = 0x01, /* modified versus the value on device */ |
---|
148 | INODE_ATTR_INLOAD = 0x04, /* loading from device in progress */ |
---|
149 | INODE_ATTR_NEW = 0x08, /* not saved on device yet */ |
---|
150 | } |
---|
151 | vfs_inode_attr_t; |
---|
152 | |
---|
153 | typedef struct vfs_inode_s |
---|
154 | { |
---|
155 | struct vfs_ctx_s * ctx; /*! local pointer on FS context */ |
---|
156 | uint32_t gc; /*! generation counter */ |
---|
157 | uint32_t inum; /*! inode identifier (unique in file system) */ |
---|
158 | uint32_t attr; /*! inode attributes (see above) */ |
---|
159 | vfs_inode_type_t type; /*! inode type (see above) */ |
---|
160 | uint32_t size; /*! number of bytes */ |
---|
161 | uint32_t links; /*! number of alias dentry */ |
---|
162 | uint32_t uid; /*! user owner identifier */ |
---|
163 | uint32_t gid; /*! group owner identifier */ |
---|
164 | uint32_t rights; /*! access rights */ |
---|
165 | uint32_t refcount; /*! reference counter (all pointers) */ |
---|
166 | xptr_t parent_xp; /*! extended pointer on parent dentry */ |
---|
167 | xhtab_t children; /*! embedded xhtab of children dentries */ |
---|
168 | remote_rwlock_t data_lock; /*! protect read/write to data and to size */ |
---|
169 | remote_busylock_t main_lock; /*! protect inode tree traversal and modifs */ |
---|
170 | list_entry_t list; /*! member of set of inodes in same cluster */ |
---|
171 | xlist_entry_t wait_root; /*! root of threads waiting on this inode */ |
---|
172 | struct mapper_s * mapper; /*! associated file cache */ |
---|
173 | void * extend; /*! fs_type_specific inode extension */ |
---|
174 | } |
---|
175 | vfs_inode_t; |
---|
176 | |
---|
177 | /* This define the masks for the inode <rights> field */ |
---|
178 | |
---|
179 | #define VFS_ISUID 0x0004000 |
---|
180 | #define VFS_ISGID 0x0002000 |
---|
181 | #define VFS_ISVTX 0x0001000 |
---|
182 | |
---|
183 | #define VFS_IRWXU 0x0000700 |
---|
184 | #define VFS_IRUSR 0x0000400 |
---|
185 | #define VFS_IWUSR 0x0000200 |
---|
186 | #define VFS_IXUSR 0x0000100 |
---|
187 | |
---|
188 | #define VFS_IRWXG 0x0000070 |
---|
189 | #define VFS_IRGRP 0x0000040 |
---|
190 | #define VFS_IWGRP 0x0000020 |
---|
191 | #define VFS_IXGRP 0x0000010 |
---|
192 | |
---|
193 | #define VFS_IRWXO 0x0000007 |
---|
194 | #define VFS_IROTH 0x0000004 |
---|
195 | #define VFS_IWOTH 0x0000002 |
---|
196 | #define VFS_IXOTH 0x0000001 |
---|
197 | |
---|
198 | /****************************************************************************************** |
---|
199 | * This structure defines a directory entry. |
---|
200 | * A dentry contains the name of a remote file/dir, an extended pointer on the |
---|
201 | * inode representing this file/dir, and a local pointer on the inode representing |
---|
202 | * the parent directory. |
---|
203 | *****************************************************************************************/ |
---|
204 | |
---|
205 | typedef struct vfs_dentry_s |
---|
206 | { |
---|
207 | struct vfs_ctx_s * ctx; /*! local pointer on FS context */ |
---|
208 | char name[CONFIG_VFS_MAX_NAME_LENGTH]; |
---|
209 | uint32_t length; /*! name length (bytes) */ |
---|
210 | uint32_t refcount; /*! reference counter (all pointers) */ |
---|
211 | struct vfs_inode_s * parent; /*! local pointer on parent inode */ |
---|
212 | xptr_t child_xp; /*! extended pointer on child inode */ |
---|
213 | xlist_entry_t list; /*! member of list of dentries with same key */ |
---|
214 | void * extend; /*! FS specific extension */ |
---|
215 | } |
---|
216 | vfs_dentry_t; |
---|
217 | |
---|
218 | /****************************************************************************************** |
---|
219 | * This file structure describes an open file/directory for a given process. |
---|
220 | * It is not replicated, and is dynamically allocated in the cluster that contains |
---|
221 | * the inode, when a thread makes an open() or opendir() system call. |
---|
222 | * It cannot exist a file structure without an inode structure in same cluster. |
---|
223 | * As the fd_array (containing extended pointers on the open file descriptors) |
---|
224 | * is replicated in all process descriptors, we need a references counter. |
---|
225 | *****************************************************************************************/ |
---|
226 | |
---|
227 | typedef enum |
---|
228 | { |
---|
229 | FD_ATTR_READ_ENABLE = 0x01, /*! read access possible */ |
---|
230 | FD_ATTR_WRITE_ENABLE = 0x02, /*! write access possible */ |
---|
231 | FD_ATTR_APPEND = 0x04, /*! append on each write */ |
---|
232 | FD_ATTR_CLOSE_EXEC = 0x08, /*! close file on exec */ |
---|
233 | FD_ATTR_SYNC = 0x10, /*! synchronise FS on each write */ |
---|
234 | FD_ATTR_IS_DIR = 0x20, /*! this is a directory */ |
---|
235 | } |
---|
236 | vfs_file_attr_t; |
---|
237 | |
---|
238 | typedef struct vfs_file_s |
---|
239 | { |
---|
240 | struct vfs_ctx_s * ctx; /*! local pointer on FS context. */ |
---|
241 | uint32_t gc; /*! generation counter */ |
---|
242 | vfs_file_attr_t attr; /*! file attributes bit vector (see above) */ |
---|
243 | vfs_inode_type_t type; /*! same type as inode */ |
---|
244 | uint32_t offset; /*! seek position in file */ |
---|
245 | uint32_t refcount; /*! all pointers on this file descriptor */ |
---|
246 | remote_rwlock_t lock; /*! protect offset modifications */ |
---|
247 | struct mapper_s * mapper; /*! associated file cache */ |
---|
248 | struct vfs_inode_s * inode; /*! local pointer on associated inode */ |
---|
249 | void * extend; /*! FS specific extension */ |
---|
250 | } |
---|
251 | vfs_file_t; |
---|
252 | |
---|
253 | |
---|
254 | /*****************************************************************************************/ |
---|
255 | /******************** VFS global functions ***********************************************/ |
---|
256 | /*****************************************************************************************/ |
---|
257 | |
---|
258 | |
---|
259 | /****************************************************************************************** |
---|
260 | * This function mount a given file system type for a given process TODO. |
---|
261 | *****************************************************************************************/ |
---|
262 | error_t vfs_mount_fs_root( struct device_s * device, |
---|
263 | uint32_t fs_type, |
---|
264 | struct process_s * process ); |
---|
265 | |
---|
266 | |
---|
267 | /*****************************************************************************************/ |
---|
268 | /******************* VFS Context related functions ****************************************/ |
---|
269 | /*****************************************************************************************/ |
---|
270 | |
---|
271 | /****************************************************************************************** |
---|
272 | * This function initialise a (statically allocated) VFS context in local cluster. |
---|
273 | ****************************************************************************************** |
---|
274 | * @ fs_type : file system type. |
---|
275 | * @ attr : global attributes (for all files in FS. |
---|
276 | * @ total_clusters : total number of clusters on device. |
---|
277 | * @ cluster_size : cluster size on device (bytes). |
---|
278 | * @ vfs_root_xp : extended pointer on VFS root inode. |
---|
279 | * @ extend : fs_type_specific extension. |
---|
280 | *****************************************************************************************/ |
---|
281 | void vfs_ctx_init( vfs_fs_type_t type, |
---|
282 | uint32_t attr, |
---|
283 | uint32_t total_clusters, |
---|
284 | uint32_t cluster_size, |
---|
285 | xptr_t vfs_root_xp, |
---|
286 | void * extend ); |
---|
287 | |
---|
288 | /****************************************************************************************** |
---|
289 | * This function allocates an inode identifier from the local cluster inum allocator. |
---|
290 | * The inum respects a fixed format: |
---|
291 | * - the 16 MSB bits contain the cluster identifier : cxy |
---|
292 | * - the 16 LSB bits contains the local inode identifier : lid |
---|
293 | ****************************************************************************************** |
---|
294 | * @ ctx : local pointer on file system context. |
---|
295 | * @ inum : [ou] buffer for allocated inode identifier. |
---|
296 | * @ return 0 if success / return non-zero if error. |
---|
297 | *****************************************************************************************/ |
---|
298 | error_t vfs_ctx_inum_alloc( vfs_ctx_t * ctx, |
---|
299 | uint32_t * inum ); |
---|
300 | |
---|
301 | /****************************************************************************************** |
---|
302 | * This function release an inode identifier. |
---|
303 | ****************************************************************************************** |
---|
304 | * @ ctx : local pointer on file system context. |
---|
305 | * @ inum : released inode identifier. |
---|
306 | *****************************************************************************************/ |
---|
307 | void vfs_ctx_inum_release( vfs_ctx_t * ctx, |
---|
308 | uint32_t inum ); |
---|
309 | |
---|
310 | |
---|
311 | |
---|
312 | |
---|
313 | /*****************************************************************************************/ |
---|
314 | /********************* Inode related functions *******************************************/ |
---|
315 | /*****************************************************************************************/ |
---|
316 | |
---|
317 | /****************************************************************************************** |
---|
318 | * This function allocates memory from local cluster for an inode descriptor and the |
---|
319 | * associated mapper. It initialise these descriptors from arguments values. |
---|
320 | * The parent dentry must have been previously created. |
---|
321 | * If the client thread is not running in the cluster containing this inode, |
---|
322 | * it must use the rpc_vfs_inode_create_client() function. |
---|
323 | ****************************************************************************************** |
---|
324 | * @ dentry_xp : extended pointer on associated dentry (in parent inode cluster). |
---|
325 | * @ fs_type : file system type. |
---|
326 | * @ inode_type : inode type. |
---|
327 | * @ extend : local pointer on vs_type_specific extension. |
---|
328 | * @ attr : inode attributes. |
---|
329 | * @ rights : inode access rights. |
---|
330 | * @ uid : user owner ID. |
---|
331 | * @ gid : group owner ID. |
---|
332 | * @ inode_xp : [out] buffer for extended pointer on created inode. |
---|
333 | * @ return 0 if success / return ENOMEM or EINVAL if error. |
---|
334 | *****************************************************************************************/ |
---|
335 | error_t vfs_inode_create( xptr_t dentry_xp, |
---|
336 | vfs_fs_type_t fs_type, |
---|
337 | vfs_inode_type_t inode_type, |
---|
338 | void * extend, |
---|
339 | uint32_t attr, |
---|
340 | uint32_t rights, |
---|
341 | uid_t uid, |
---|
342 | gid_t gid, |
---|
343 | xptr_t * inode_xp ); |
---|
344 | |
---|
345 | /****************************************************************************************** |
---|
346 | * This function releases memory allocated to an inode descriptor. |
---|
347 | * It must be executed by a thread running in the cluster containing the inode, |
---|
348 | * and the inode refcount must be zero. If the client thread is not running in the owner |
---|
349 | * cluster, you must use the rpc_vfs_inode_destroy_client() function. |
---|
350 | ****************************************************************************************** |
---|
351 | * @ inode : local pointer on inode descriptor. |
---|
352 | * @ return 0 if success / return EINVAL if error. |
---|
353 | *****************************************************************************************/ |
---|
354 | error_t vfs_inode_destroy( vfs_inode_t * inode ); |
---|
355 | |
---|
356 | /****************************************************************************************** |
---|
357 | * This function scan an existing parent inode directory, identified by the <parent> |
---|
358 | * argument to find a directory entry identified by the <name> argument, and update |
---|
359 | * the remote child inode, identified by the <child_xp> argument. |
---|
360 | * Depending on the file system type, it calls the relevant, FS specific function, |
---|
361 | * to scan the directory, and set the "type", "size", and "extend" fields. |
---|
362 | * It must be called by a thread running in the cluster containing the parent inode. |
---|
363 | ****************************************************************************************** |
---|
364 | * @ parent : local pointer on parent inode (directory). |
---|
365 | * @ name : child name. |
---|
366 | * @ child_xp : extended pointer on remote child inode (file or directory) |
---|
367 | * @ return 0 if success / return ENOENT if not found. |
---|
368 | *****************************************************************************************/ |
---|
369 | error_t vfs_inode_load( vfs_inode_t * parent, |
---|
370 | char * name, |
---|
371 | xptr_t child_xp ); |
---|
372 | |
---|
373 | /****************************************************************************************** |
---|
374 | * This function atomically increment/decrement the inode refcount. |
---|
375 | * It can be called by any thread running in any cluster. |
---|
376 | *****************************************************************************************/ |
---|
377 | void vfs_inode_remote_up( xptr_t inode_xp ); |
---|
378 | void vfs_inode_remote_down( xptr_t inode_xp ); |
---|
379 | |
---|
380 | /****************************************************************************************** |
---|
381 | * This function returns the <size> of a file/dir from a remote inode, |
---|
382 | * taking the remote_rwlock protecting <size> in READ_MODE. |
---|
383 | ***************************************************************************************** |
---|
384 | * @ inode_xp : extended pointer on the remote inode. |
---|
385 | * @ return the current size. |
---|
386 | *****************************************************************************************/ |
---|
387 | uint32_t vfs_inode_get_size( xptr_t inode_xp ); |
---|
388 | |
---|
389 | /****************************************************************************************** |
---|
390 | * This function set the <size> of a file/dir to a remote inode, |
---|
391 | * taking the remote_rwlock protecting <size> in WRITE_MODE. |
---|
392 | ***************************************************************************************** |
---|
393 | * @ inode_xp : extended pointer on the remote inode. |
---|
394 | * @ size : value to be written. |
---|
395 | *****************************************************************************************/ |
---|
396 | void vfs_inode_set_size( xptr_t inode_xp, |
---|
397 | uint32_t size ); |
---|
398 | |
---|
399 | /****************************************************************************************** |
---|
400 | * This function takes the main lock of a remote inode. |
---|
401 | * This lock protect all inode fiels, including the children dentries. |
---|
402 | ***************************************************************************************** |
---|
403 | * @ inode_xp : extended pointer on the remote inode. |
---|
404 | *****************************************************************************************/ |
---|
405 | void vfs_inode_lock( xptr_t inode_xp ); |
---|
406 | |
---|
407 | /****************************************************************************************** |
---|
408 | * This function releases the main lock of a remote inode. |
---|
409 | * This lock protect all inode fiels, including the children dentries. |
---|
410 | ***************************************************************************************** |
---|
411 | * @ inode_xp : extended pointer on the remote inode. |
---|
412 | *****************************************************************************************/ |
---|
413 | void vfs_inode_unlock( xptr_t inode_xp ); |
---|
414 | |
---|
415 | /****************************************************************************************** |
---|
416 | * This debug function copies the name of a remote inode identified by the <inode_xp> |
---|
417 | * argument to a local buffer identified by the <name> argument. |
---|
418 | * The local buffer size must be at least CONFIG_VFS_MAX_NAME_LENGTH. |
---|
419 | ***************************************************************************************** |
---|
420 | * @ inode_xp : extended pointer on the remote inode. |
---|
421 | * @ name : local buffer pointer. |
---|
422 | *****************************************************************************************/ |
---|
423 | void vfs_inode_get_name( xptr_t inode_xp, |
---|
424 | char * name ); |
---|
425 | |
---|
426 | |
---|
427 | /*****************************************************************************************/ |
---|
428 | /***************** Dentry related functions **********************************************/ |
---|
429 | /*****************************************************************************************/ |
---|
430 | |
---|
431 | /****************************************************************************************** |
---|
432 | * This function allocates memory from local cluster for a dentry descriptor, |
---|
433 | * initialises it from arguments values, and returns the extended pointer on dentry. |
---|
434 | * The inode field is not initialized, because the inode does not exist yet. |
---|
435 | * If the client thread is not running in the target cluster for this inode, |
---|
436 | * it must use the rpc_dentry_create_client() function. |
---|
437 | ****************************************************************************************** |
---|
438 | * @ fs_type : file system type. |
---|
439 | * @ name : directory entry file/dir name. |
---|
440 | * @ parent : local pointer on parent inode. |
---|
441 | * @ dentry_xp : [out] buffer for extended pointer on created dentry. |
---|
442 | * @ return 0 if success / return ENOMEM or EINVAL if error. |
---|
443 | *****************************************************************************************/ |
---|
444 | error_t vfs_dentry_create( vfs_fs_type_t fs_type, |
---|
445 | char * name, |
---|
446 | vfs_inode_t * parent, |
---|
447 | xptr_t * dentry_xp ); |
---|
448 | |
---|
449 | /****************************************************************************************** |
---|
450 | * This function releases memory allocated to a dentry descriptor. |
---|
451 | * It must be executed by a thread running in the cluster containing the dentry, |
---|
452 | * and the dentry refcount must be zero. If the client thread is not running in the owner |
---|
453 | * cluster, you must use the rpc_dentry_destroy_client() function. |
---|
454 | ****************************************************************************************** |
---|
455 | * @ dentry : local pointer on dentry descriptor. |
---|
456 | * @ return 0 if success / return EINVAL if error. |
---|
457 | *****************************************************************************************/ |
---|
458 | error_t vfs_dentry_destroy( vfs_dentry_t * dentry ); |
---|
459 | |
---|
460 | /****************************************************************************************** |
---|
461 | * These functions atomically increment/decrement the dentry refcount. |
---|
462 | * It can be called by any thread running in any cluster. |
---|
463 | *****************************************************************************************/ |
---|
464 | void vfs_dentry_remote_up( xptr_t dentry_xp ); |
---|
465 | void vfs_dentry_remote_down( xptr_t dentry_xp ); |
---|
466 | |
---|
467 | |
---|
468 | /*****************************************************************************************/ |
---|
469 | /************************ File descriptor related functions ******************************/ |
---|
470 | /*****************************************************************************************/ |
---|
471 | |
---|
472 | /****************************************************************************************** |
---|
473 | * This function allocates memory and initializes a new local file descriptor. |
---|
474 | * It must be executed in the cluster containing the inode. |
---|
475 | * If the client thread is not running in the owner cluster, it must use the |
---|
476 | * rpc_vfs_file_create_client() function. |
---|
477 | ****************************************************************************************** |
---|
478 | * @ inode : local pointer on associated inode. |
---|
479 | * @ attr : file descriptor attributes. |
---|
480 | * @ file_xp : [out] buffer for extended pointer on created file descriptor. |
---|
481 | * @ return 0 if success / return ENOMEM if error. |
---|
482 | *****************************************************************************************/ |
---|
483 | error_t vfs_file_create( vfs_inode_t * inode, |
---|
484 | uint32_t attr, |
---|
485 | xptr_t * file_xp ); |
---|
486 | |
---|
487 | /****************************************************************************************** |
---|
488 | * This function releases memory allocated to a local file descriptor. |
---|
489 | * It must be executed by a thread running in the cluster containing the inode, |
---|
490 | * and the file refcount must be zero. |
---|
491 | * If the client thread is not running in the owner cluster, it must use the |
---|
492 | * rpc_vfs_file_destroy_client() function. |
---|
493 | ****************************************************************************************** |
---|
494 | * @ file : local pointer on file descriptor. |
---|
495 | *****************************************************************************************/ |
---|
496 | void vfs_file_destroy( vfs_file_t * file ); |
---|
497 | |
---|
498 | /****************************************************************************************** |
---|
499 | * These functions increment (resp. decrement) the count field in a remote file |
---|
500 | * descriptor, using a remote_atomic access. |
---|
501 | *****************************************************************************************/ |
---|
502 | void vfs_file_count_up ( xptr_t file_xp ); |
---|
503 | void vfs_file_count_down( xptr_t file_xp ); |
---|
504 | |
---|
505 | |
---|
506 | |
---|
507 | /*****************************************************************************************/ |
---|
508 | /******************* Inode-Tree related functions ****************************************/ |
---|
509 | /*****************************************************************************************/ |
---|
510 | |
---|
511 | /****************************************************************************************** |
---|
512 | * This function returns a printable string for the inode type. |
---|
513 | *****************************************************************************************/ |
---|
514 | const char * vfs_inode_type_str( vfs_inode_type_t type ); |
---|
515 | |
---|
516 | /****************************************************************************************** |
---|
517 | * This function returns in a kernel buffer allocated by the caller function, |
---|
518 | * the pathname of a file/dir identified by an extended pointer on the inode. |
---|
519 | * It traverse the Inode Tree from the target node to the root. |
---|
520 | * It can be called by any thread running in any cluster. |
---|
521 | ****************************************************************************************** |
---|
522 | * @ inode_xp : pointer on inode descriptor. |
---|
523 | * @ buffer : kernel buffer for pathname (must be allocated by caller). |
---|
524 | * @ size : max number of characters in buffer. |
---|
525 | * @ return 0 if success / return EINVAL if buffer too small. |
---|
526 | *****************************************************************************************/ |
---|
527 | error_t vfs_get_path( xptr_t inode_xp, |
---|
528 | char * buffer, |
---|
529 | uint32_t max_size ); |
---|
530 | |
---|
531 | /****************************************************************************************** |
---|
532 | * This function takes a pathname (absolute or relative to cwd) and returns an extended |
---|
533 | * pointer on the associated inode. |
---|
534 | * - If a given directory name in the path is not found in the inode tree, it try to load |
---|
535 | * the missing dentry/inode couple, from informations found in the parent directory. |
---|
536 | * - If this directory entry does not exist on device, it returns an error. |
---|
537 | * - If the the file identified by the pathname does not exist on device but the |
---|
538 | * flag CREATE is set, the inode is created. |
---|
539 | * - If the the file identified by the pathname exist on device but both flags EXCL |
---|
540 | * and CREATE are set, an error is returned. |
---|
541 | ****************************************************************************************** |
---|
542 | * @ cwd_xp : extended pointer on current directory (for relative path). |
---|
543 | * @ pathname : path in kernel space (can be relative or absolute). |
---|
544 | * @ lookup_mode : flags defining the working mode (defined above in this file). |
---|
545 | * @ inode_xp : [out] buffer for extended pointer on searched inode. |
---|
546 | * @ return 0 if success / ENOENT if inode not found , EACCES if permisson denied, |
---|
547 | * EAGAIN if a new complete lookup must be made |
---|
548 | *****************************************************************************************/ |
---|
549 | error_t vfs_lookup( xptr_t cwd_xp, |
---|
550 | char * pathname, |
---|
551 | uint32_t lookup_mode, |
---|
552 | xptr_t * inode_xp ); |
---|
553 | |
---|
554 | /****************************************************************************************** |
---|
555 | * This function creates a new couple dentry/inode, and insert it in the Inode-Tree. |
---|
556 | * It can be executed by any thread running in any cluster (can be different from both |
---|
557 | * the child cluster and the parent cluster), as it uses the rpc_dentry_create_client() |
---|
558 | * and rpc_inode_create client() if required. This is done in three steps: |
---|
559 | * 1) The dentry is created in the cluster containing the existing <parent_xp> inode. |
---|
560 | * The new dentry name is defined by the <name> argument. |
---|
561 | * 2) The inode and its associated mapper are created in cluster identified by <child_cxy>. |
---|
562 | * The new inode and the parent inode can have different FS types. |
---|
563 | * 3) The "child_xp" field in created dentry (pointing on the created inode) is updated. |
---|
564 | ****************************************************************************************** |
---|
565 | * @ child_cxy : target cluster for child inode. |
---|
566 | * @ inode_type : new inode type |
---|
567 | * @ fs_type : new inode FS type. |
---|
568 | * @ parent_xp : extended pointer on parent inode. |
---|
569 | * @ name : new directory entry name. |
---|
570 | * @ extend : fs_type_specific inode extension. |
---|
571 | * @ child_xp : [out] buffer for extended pointer on child inode. |
---|
572 | * @ return 0 if success / ENOMEM if dentry or inode cannot be created. |
---|
573 | *****************************************************************************************/ |
---|
574 | error_t vfs_add_child_in_parent( cxy_t child_cxy, |
---|
575 | vfs_inode_type_t inode_type, |
---|
576 | vfs_fs_type_t fs_type, |
---|
577 | xptr_t parent_xp, |
---|
578 | char * name, |
---|
579 | void * extend, |
---|
580 | xptr_t * child_xp ); |
---|
581 | |
---|
582 | /****************************************************************************************** |
---|
583 | * This function removes a couple dentry/inode from the Inode-Tree, and remove it from |
---|
584 | * the external device. |
---|
585 | ****************************************************************************************** |
---|
586 | * @ child_xp : extended pointer on removed inode. |
---|
587 | *****************************************************************************************/ |
---|
588 | error_t vfs_remove_child_from_parent( xptr_t inode_xp ); |
---|
589 | |
---|
590 | /****************************************************************************************** |
---|
591 | * This recursive function diplays a complete inode/dentry sub-tree. |
---|
592 | * Any inode can be selected as the sub-tree root. |
---|
593 | * TODO this function is not protected against a concurrent inode/dentry removal... |
---|
594 | ****************************************************************************************** |
---|
595 | * @ inode_xp : extended pointer on sub-tree root inode. |
---|
596 | *****************************************************************************************/ |
---|
597 | void vfs_display( xptr_t inode_xp ); |
---|
598 | |
---|
599 | |
---|
600 | |
---|
601 | |
---|
602 | |
---|
603 | /*****************************************************************************************/ |
---|
604 | /****************** File access API ******************************************************/ |
---|
605 | /*****************************************************************************************/ |
---|
606 | |
---|
607 | /****************************************************************************************** |
---|
608 | * This function allocates a vfs_file_t structure in the cluster containing the inode |
---|
609 | * associated to the file identified by the <cwd_xp> & <path> arguments. |
---|
610 | * It initializes it, register it in the reference process fd_array identified by the |
---|
611 | * <process> argument, and returns both the extended pointer on the file descriptor, |
---|
612 | * and the allocated index in the fd_array. |
---|
613 | * The pathname can be relative to current directory or absolute. |
---|
614 | * If the inode does not exist in the inode cache, it try to find the file on the mounted |
---|
615 | * device, and creates an inode on a pseudo randomly selected cluster if found. |
---|
616 | * It the requested file does not exist on device, it creates a new inode if the |
---|
617 | * O_CREAT flag is set, and return an error otherwise. |
---|
618 | ****************************************************************************************** |
---|
619 | * @ process : local pointer on local process descriptor copy. |
---|
620 | * @ path : file pathname (absolute or relative to current directory). |
---|
621 | * @ flags : defined above. |
---|
622 | * @ mode : access rights (as defined by chmod) |
---|
623 | * @ file_xp : [out] buffer for extended pointer on created remote file descriptor. |
---|
624 | * @ file_id : [out] buffer for created file descriptor index in reference fd_array. |
---|
625 | * @ return 0 if success / return non-zero if error. |
---|
626 | *****************************************************************************************/ |
---|
627 | error_t vfs_open( struct process_s * process, |
---|
628 | char * path, |
---|
629 | uint32_t flags, |
---|
630 | uint32_t mode, |
---|
631 | xptr_t * file_xp, |
---|
632 | uint32_t * file_id ); |
---|
633 | |
---|
634 | /****************************************************************************************** |
---|
635 | * This function moves <size> bytes between a remote file mapper, identified by the |
---|
636 | * <file_xp> argument, and a - possibly distributed - user space <buffer>, taken into |
---|
637 | * account the offset in <file_xp>. The transfer direction is defined by <to_buffer>. |
---|
638 | * It is called by the sys_read() and sys_write() functions. |
---|
639 | ****************************************************************************************** |
---|
640 | * @ to_buffer : mapper -> buffer if true / buffer -> mapper if false. |
---|
641 | * @ file_xp : extended pointer on the remote file descriptor. |
---|
642 | * @ buffer : user space pointer on buffer (can be physically distributed). |
---|
643 | * @ size : requested number of bytes from offset. |
---|
644 | * @ returns number of bytes actually moved if success / -1 if error. |
---|
645 | *****************************************************************************************/ |
---|
646 | int vfs_user_move( bool_t to_buffer, |
---|
647 | xptr_t file_xp, |
---|
648 | void * buffer, |
---|
649 | uint32_t size ); |
---|
650 | |
---|
651 | /****************************************************************************************** |
---|
652 | * This function moves <size> bytes between a remote file mapper, identified by the |
---|
653 | * <file_xp> argument, and a - possibly remote - kernel <buffer_xp>, taken into |
---|
654 | * account the offset in <file_xp>. The transfer direction is defined by <to_buffer>. |
---|
655 | * It is called by the elf_load_process() function. |
---|
656 | ****************************************************************************************** |
---|
657 | * @ to_buffer : mapper -> buffer if true / buffer -> mapper if false. |
---|
658 | * @ file_xp : extended pointer on the remote file descriptor. |
---|
659 | * @ buffer_xp : user space pointer on buffer (can be physically distributed). |
---|
660 | * @ size : requested number of bytes from offset. |
---|
661 | * @ returns 0 if success / -1 if error. |
---|
662 | *****************************************************************************************/ |
---|
663 | error_t vfs_kernel_move( bool_t to_buffer, |
---|
664 | xptr_t file_xp, |
---|
665 | xptr_t buffer_xp, |
---|
666 | uint32_t size ); |
---|
667 | |
---|
668 | /****************************************************************************************** |
---|
669 | * This function set a new value in the offset of the open file descriptor <file_xp>. |
---|
670 | * This value depends on the <whence> argument: |
---|
671 | * - if VFS_SEEK_SET, new value is <offset> |
---|
672 | * - if VFS_SEEK_CUR, new value is current_offset + <offset> |
---|
673 | * - if VFS_SEEK_END, new value is file_size + <offset> |
---|
674 | ****************************************************************************************** |
---|
675 | * @ file_xp : extended pointer on the remote open file descriptor. |
---|
676 | * @ offset : local pointer on source kernel buffer. |
---|
677 | * @ whence : VFS_SEEK_SET / VFS_SEEK_CUR / VFS_SEEK_END. |
---|
678 | * @ new_offset : [out] buffer for new offset value. |
---|
679 | * @ returns 0 if success / -1 if error. |
---|
680 | *****************************************************************************************/ |
---|
681 | error_t vfs_lseek( xptr_t file_xp, |
---|
682 | uint32_t offset, |
---|
683 | uint32_t whence, |
---|
684 | uint32_t * new_offset ); |
---|
685 | |
---|
686 | /****************************************************************************************** |
---|
687 | * This function close the -non-replicated- file descriptor identified by the <file_xp> |
---|
688 | * and <file_id> arguments. |
---|
689 | * 1) All entries in the fd_array copies are directly reset by the calling thread, |
---|
690 | * using remote accesses. |
---|
691 | * 2) The memory allocated to file descriptor in cluster containing the inode is released. |
---|
692 | * It requires a RPC if cluster containing the file descriptor is remote. |
---|
693 | ****************************************************************************************** |
---|
694 | * @ file_xp : extended pointer on the file descriptor in owner cluster. |
---|
695 | * @ file_id : file descriptor index in fd_array. |
---|
696 | * @ returns 0 if success / -1 if error. |
---|
697 | *****************************************************************************************/ |
---|
698 | error_t vfs_close( xptr_t file_xp, |
---|
699 | uint32_t file_id ); |
---|
700 | |
---|
701 | /****************************************************************************************** |
---|
702 | * This function remove from the file system a directory entry identified by the |
---|
703 | * <cwd_xp> & <path> arguments. |
---|
704 | ****************************************************************************************** |
---|
705 | * @ cwd_xp : extended pointer on the current working directory file descriptor. |
---|
706 | * @ path : pathname (absolute or relative to current directory). |
---|
707 | * @ returns 0 if success / -1 if error. |
---|
708 | *****************************************************************************************/ |
---|
709 | error_t vfs_unlink( xptr_t cwd_xp, |
---|
710 | char * path ); |
---|
711 | |
---|
712 | /****************************************************************************************** |
---|
713 | * This function returns, in the structure pointed by the <st> pointer, |
---|
714 | * various informations on the inode identified by the <inode_xp> argument. |
---|
715 | * TODO : only partially implemented yet... |
---|
716 | ****************************************************************************************** |
---|
717 | * @ inode_xp : extended pointer on the remote inode. |
---|
718 | * @ st : local pointer on the stat structure in kernel space. |
---|
719 | * @ returns 0 if success / -1 if error. |
---|
720 | *****************************************************************************************/ |
---|
721 | error_t vfs_stat( xptr_t inode_xp, |
---|
722 | struct stat * st ); |
---|
723 | |
---|
724 | /****************************************************************************************** |
---|
725 | * This function returns, in the structure pointed by the <k_dirent> kernel pointer, |
---|
726 | * various infos on the directory entry currently pointed by the <file_xp> file descriptor. |
---|
727 | * TODO not implemented yet... |
---|
728 | ****************************************************************************************** |
---|
729 | * @ file_xp : extended pointer on the file descriptor of the searched directory . |
---|
730 | * @ k_dirent : local pointer on the dirent structure in kernel space. |
---|
731 | * @ returns 0 if success / -1 if error. |
---|
732 | *****************************************************************************************/ |
---|
733 | error_t vfs_readdir( xptr_t file_xp, |
---|
734 | struct dirent * k_dirent ); |
---|
735 | |
---|
736 | /****************************************************************************************** |
---|
737 | * This function creates a new inode and associated dentry for the directory defined |
---|
738 | * by the <cwd_xp> & <path> arguments. |
---|
739 | * TODO not implemented yet... |
---|
740 | ****************************************************************************************** |
---|
741 | * @ cwd_xp : extended pointer on the current working directory file descriptor. |
---|
742 | * @ path : pathname (absolute or relative to current directory). |
---|
743 | * @ mode : access rights (as defined by chmod) |
---|
744 | * @ returns 0 if success / -1 if error. |
---|
745 | *****************************************************************************************/ |
---|
746 | error_t vfs_mkdir( xptr_t cwd_xp, |
---|
747 | char * path, |
---|
748 | uint32_t mode ); |
---|
749 | |
---|
750 | /****************************************************************************************** |
---|
751 | * This function remove a directory identified by the <cwd_xp / path> arguments |
---|
752 | * from the file system. |
---|
753 | * TODO not implemented yet... |
---|
754 | ****************************************************************************************** |
---|
755 | * @ cwd_xp : extended pointer on the current working directory file descriptor. |
---|
756 | * @ path : pathname (absolute or relative to current directory). |
---|
757 | * @ returns 0 if success / -1 if error. |
---|
758 | *****************************************************************************************/ |
---|
759 | error_t vfs_rmdir( xptr_t cwd_xp, |
---|
760 | char * path ); |
---|
761 | |
---|
762 | /****************************************************************************************** |
---|
763 | * This function makes the directory identified by <cwd_xp / path> arguments to become |
---|
764 | * the working directory for the calling process. |
---|
765 | ****************************************************************************************** |
---|
766 | * @ cwd_xp : extended pointer on current directory file descriptor (relative path). |
---|
767 | * @ path : file pathname (absolute or relative to current directory). |
---|
768 | * return 0 if success / -1 if error. |
---|
769 | *****************************************************************************************/ |
---|
770 | error_t vfs_chdir( xptr_t cwd_xp, |
---|
771 | char * path ); |
---|
772 | |
---|
773 | /****************************************************************************************** |
---|
774 | * This function change the access rigths for the file identified by the <cwd_xp / path> |
---|
775 | * arguments. The new access rights are defined by the <mode> argument value. |
---|
776 | ****************************************************************************************** |
---|
777 | * @ cwd_xp : extended pointer on current directory file descriptor (relative path). |
---|
778 | * @ path : file pathname (absolute or relative to current directory). |
---|
779 | * @ mode : access rights new value. |
---|
780 | * return 0 if success / -1 if error. |
---|
781 | *****************************************************************************************/ |
---|
782 | error_t vfs_chmod( xptr_t cwd_xp, |
---|
783 | char * path, |
---|
784 | uint32_t mode ); |
---|
785 | |
---|
786 | /****************************************************************************************** |
---|
787 | * This function creates a named FIFO file. |
---|
788 | * TODO not implemented yet |
---|
789 | ****************************************************************************************** |
---|
790 | * @ path : FIFO pathname (absolute or relative to current directory). |
---|
791 | * @ cwd_xp : extended pointer on the current working directory file descriptor. |
---|
792 | * @ mode : access rights new value. |
---|
793 | *****************************************************************************************/ |
---|
794 | error_t vfs_mkfifo( xptr_t cwd_xp, |
---|
795 | char * path, |
---|
796 | uint32_t mode ); |
---|
797 | |
---|
798 | |
---|
799 | /*****************************************************************************************/ |
---|
800 | /****************** Mapper access API ****************************************************/ |
---|
801 | /*****************************************************************************************/ |
---|
802 | |
---|
803 | /****************************************************************************************** |
---|
804 | * This function makes an I/O operation to move one page to/from device from/to the mapper. |
---|
805 | * It is used in case of MISS on the mapper, or when a dirty page in the mapper must |
---|
806 | * be updated in the File System. |
---|
807 | * Depending on the file system type, it calls the proper, FS specific function. |
---|
808 | * It must be executed by a thread running in the cluster containing the mapper. |
---|
809 | * The mapper pointer is obtained from the page descriptor. |
---|
810 | * It takes the mapper lock before launching the IO operation. |
---|
811 | ****************************************************************************************** |
---|
812 | * @ page : local pointer on the page descriptor. |
---|
813 | * @ to_mapper : transfer direction. |
---|
814 | * @ returns 0 if success / return EINVAL if it cannot access the external device. |
---|
815 | *****************************************************************************************/ |
---|
816 | error_t vfs_mapper_move_page( struct page_s * page, |
---|
817 | bool_t to_mapper ); |
---|
818 | |
---|
819 | /****************************************************************************************** |
---|
820 | * This function makes the I/O operations required to move, from device to mapper, |
---|
821 | * all pages covering a given inode, identified by the <inode> argument. The target |
---|
822 | * inode can be a directory or a file, but this function is mainly used to load (prefetch) |
---|
823 | * a complete directory to the mapper. |
---|
824 | * Depending on the file system type, it calls the proper, FS specific function. |
---|
825 | * It must be executed by a thread running in the cluster containing the mapper. |
---|
826 | * The mapper pointer is obtained from the inode descriptor. |
---|
827 | * It takes the mapper lock before launching the IO operation. |
---|
828 | ****************************************************************************************** |
---|
829 | * @ inode : local pointer on inode. |
---|
830 | * @ return 0 if success / return EIO if device access failure. |
---|
831 | *****************************************************************************************/ |
---|
832 | error_t vfs_mapper_load_all( vfs_inode_t * inode ); |
---|
833 | |
---|
834 | |
---|
835 | #endif /* _VFS_H_ */ |
---|