source: trunk/kernel/fs/vfs.h @ 588

Last change on this file since 588 was 568, checked in by alain, 6 years ago

omplete restructuration of kernel locks.

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