source: trunk/kernel/vfs/vfs.h @ 12

Last change on this file since 12 was 10, checked in by alain, 8 years ago

Merge all FS related files in one single directory.

File size: 47.4 KB
RevLine 
[1]1/*
2 * vfs.h - Virtual File System definition.
3 *
4 * Author  Mohamed Lamine Karaoui (2015)
5 *         Alain Greiner (2016)
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 <almos_config.h>
29#include <hal_types.h>
30#include <hal_atomic.h>
31#include <remote_rwlock.h>
32#include <remote_spinlock.h>
33#include <spinlock.h>
34#include <list.h>
35#include <xlist.h>
36#include <slist.h>
37#include <bits.h>
38#include <xhtab.h>
39#include <errno.h>
40#include <metafs.h>
41
42#include <fatfs.h>
43#include <ramfs.h>
44
45/****  Forward declarations  ***/
46
47struct vfs_inode_s;
48struct vfs_dentry_t;
49struct vfs_ctx_t;
50struct vfs_file_ref_s;
51struct vfs_file_s;
52
53struct vfs_inode_op_s;
54struct vfs_dentry_op_s;
55struct vfs_file_op_s;
56struct vfs_ctx_op_s;
57
58struct vfs_lookup_cmd_s;
59struct vfs_lookup_rsp_s;
60
61struct mapper_s;
62struct process_s;
63struct device_s;
64struct vseg_s;
65
66/*********************************************************************************************
67 * This defines the various Flags arguments for an open() or opendir() system call.
68 ********************************************************************************************/
69
70#define VFS_O_APPEND         0x00080000
71#define VFS_O_RDONLY         0x00100000
72#define VFS_O_WRONLY         0x00200000
73#define VFS_O_RDWR           0x00300000
74#define VFS_O_CREATE         0x00400000
75#define VFS_O_EXCL           0x00800000
76#define VFS_O_TRUNC          0x01000000
77#define VFS_O_SYNC               0x08000000
78
79/*********************************************************************************************
80 * This defines the various types of command for an lseek() system call.
81 ********************************************************************************************/
82
83#define VFS_SEEK_SET         0
84#define VFS_SEEK_CUR         1
85#define VFS_SEEK_END         2
86
87/*********************************************************************************************
88 * TODO : the following flags were defined in the vfs-params.h file...
89 *        ... and must be documented. [AG]
90 ********************************************************************************************/
91
92
93//////////////////////////////////////
94///    keep these flags compact    ///
95//////////////////////////////////////
96#define VFS_REGFILE          0x0000000
97#define VFS_DIR              0x0000001
98#define VFS_FIFO             0x0000002
99#define VFS_DEV_CHR          0x0000004
100#define VFS_DEV_BLK          0x0000008
101#define VFS_DEV              0x000000C
102#define VFS_SOCK             0x0000010
103#define VFS_SYMLNK           0x0000020
104//////////////////////////////////////
105
106#define VFS_RD_ONLY          0x0000040
107#define VFS_SYS              0x0000080
108#define VFS_ARCHIVE          0x0000100
109#define VFS_PIPE             0x0000200
110
111#define VFS_IFMT             0x0170000
112#define VFS_IFSOCK           0x0140000
113#define VFS_IFLNK            0x0120000
114#define VFS_IFREG            0x0100000
115#define VFS_IFBLK            0x0060000
116#define VFS_IFDIR            0x0040000
117#define VFS_IFCHR            0x0020000
118#define VFS_IFIFO            0x0010000
119
120#define VFS_ISUID            0x0004000
121#define VFS_ISGID            0x0002000
122#define VFS_ISVTX            0x0001000
123
124#define VFS_IRWXU            0x0000700
125#define VFS_IRUSR            0x0000400
126#define VFS_IWUSR            0x0000200
127#define VFS_IXUSR            0x0000100
128#define VFS_IRWXG            0x0000070
129#define VFS_IRGRP            0x0000040
130#define VFS_IWGRP            0x0000020
131#define VFS_IXGRP            0x0000010
132#define VFS_IRWXO            0x0000007
133#define VFS_IROTH            0x0000004
134#define VFS_IWOTH            0x0000002
135#define VFS_IXOTH            0x0000001
136
137#define VFS_IREAD            VFS_IRUSR
138#define VFS_IWRITE           VFS_IWUSR
139#define VFS_IEXEC            VFS_IXUSR
140
141#define VFS_SET(state,flag)    (state) |= (flag)
142#define VFS_IS(state,flag)     (state) & (flag)
143#define VFS_CLEAR(state,flag)  (state) &= ~(flag)
144
145
146/* Lookup flags */
147#define VFS_LOOKUP_FILE         0x1
148#define VFS_LOOKUP_LAST         0x2
149#define VFS_LOOKUP_OPEN         0x4
150#define VFS_LOOKUP_RESTART      0x8
151#define VFS_LOOKUP_RETRY        0x10
152#define VFS_LOOKUP_PARENT       0x20
153#define VFS_LOOKUP_HELD         0x40
154
155/* Context flags*/
156#define VFS_FS_LOCAL            0x1
157#define VFS_FS_USE_MAPPER       0x2
158
159
160
161
162/******************************************************************************************
163 * This structure define a VFS inode.
164 * It contains an extended pointer on the parent dentry, and (for directory only)
165 * an hash table xhtab refering all children dentries.
166 * The <parent> inode is unique for a directory (not hard links for directories).
167 * For a file, the parent field points to the first dentry who created this inode.
[10]168 * Syncronisation:
169 * - the main_lock (spinlock) is used during the inode tree traversal or for inode
170 *   modification (add/remove children).
171 * - the data_lock (rwlock) is used during read/write accesses to the data stored
172 *   in the mapper.
173 * - the mapper lock (rwlock) is only used during the radix tree traversal to return
174 *   to return the relevant page for red/write.
[1]175 *****************************************************************************************/
176
[10]177typedef enum   
178{
179    INODE_TYPE_NORMAL,                 /*! file or directory                            */
180    INODE_TYPE_PIPE,                   /*! POSIX pipe                                   */
181    INODE_TYPE_SOCKET,                 /*! POSIX socket                                 */
182    INODE_TYPE_DEV,                    /*! peripheral channel                           */
183}
184vfs_inode_type_t;
185
[1]186typedef enum 
187{
188    INODE_ATTR_DIRTY  = 0x01,
189    INODE_ATTR_DIR    = 0x02,
190    INODE_ATTR_INLOAD = 0x04,
191    INODE_ATTR_NEW    = 0x08,
192}
[10]193vfs_inode_attr_t;
[1]194
195typedef struct vfs_inode_s
196{
197        struct vfs_ctx_s      * ctx;         /*! Rlocal pointer on FS context                */
198    uint32_t                gc;          /*! generation counter                          */
199        uint32_t                inum;        /*! inode identifier (unique in file system)    */
200        uint32_t                attr;        /*! inode attributes (see above)                */
[10]201        uint32_t                type;        /*! inode type (see above)                      */
[1]202        uint32_t                size;        /*! number of bytes                             */
203        uint32_t                links;       /*! number of alias dentry                      */
204        uid_t                   uid;         /*! user owner identifier                       */
205        gid_t                   gid;         /*! group owner identifier                      */
206    uint32_t                mode;        /*! access mode                                 */
207        uint32_t                    refcount;    /*! reference counter (all pointers)            */
208        xptr_t                  parent_xp;   /*! extended pointer on parent dentry           */
209        xhtab_t                 children;    /*! embedded htab of dir entries (for dir type) */
[10]210        remote_rwlock_t         data_lock;   /*! protect read/write to data and to size      */
211        remote_spinlock_t       main_lock;   /*! protect inode tree traversal and modifs     */
[1]212        xlist_entry_t           xlist;       /*! member of set of inodes in same cluster     */
213        xlist_entry_t           wait_root;   /*! root of threads waiting on this inode       */
214        struct vfs_inode_op_s * op;          /*! TODO ???                                    */
215        struct mapper_s       * mapper;      /*! associated file cache                       */
216        void                  * extend;      /*! FS specific inode extension                 */
217}
218vfs_inode_t;
219
220/******************************************************************************************
221 * This structure defines a directory entry.
222 * A dentry contains the name of a remote file/dir, an extended pointer on the
223 * inode representing this file/dir, and a local pointer on the inode representing
224 * the parent directory.
225 *****************************************************************************************/
226
227typedef struct vfs_dentry_s
228{
229    struct vfs_ctx_s       * ctx;        /*! local pointer on FS context                 */
230        char                     name[CONFIG_VFS_MAX_NAME_LENGTH];
231        uint32_t                 length;     /*! name length (bytes)                         */
232        uint32_t                 refcount;   /*! reference counter (all pointers)            */
233    struct vfs_inode_s     * parent;     /*! local pointer on parent inode               */
234    xptr_t                   child_xp;   /*! extended pointer on child inode             */
235    xlist_entry_t            xlist;      /*! member of xlist of dentries with same key   */
236        struct vfs_dentry_op_s * op;         /*! TODO                                        */
237        void                   * extend;     /*! FS specific extension                       */
238}
239vfs_dentry_t;
240
241/******************************************************************************************
242 * This structure describes an open file/directory for a given process.
243 * It is not replicated, and is dynamically allocated in the cluster that contains
244 * the inode, when a thread makes an open() or opendir() system call.
245 *****************************************************************************************/
246
247
248typedef enum
249{
[10]250    FD_ATTR_READ_ENABLE  = 0x01,       /*! read access possible                         */
251    FD_ATTR_WRITE_ENABLE = 0x02,       /*! write access possible                        */
252    FD_ATTR_APPEND       = 0x04,       /*! append on each write                         */
253    FD_ATTR_CLOSE_EXEC   = 0x08,       /*! close file on exec                           */
254    FD_ATTR_SYNC         = 0x10,       /*! synchronise FS on each write                 */
255    FD_ATTR_IS_DIR       = 0x20,       /*! this is a directory                          */
[1]256}
257vfs_fd_attr_t;
258
259typedef struct vfs_file_s
260{
261        uint32_t                gc;         /*! generation counter                           */
262        uint32_t                type;       /*! see above                                    */
263        uint32_t                attr;       /*! see above                                    */
264        uint32_t                offset;     /*! seek position in file                        */
265        uint32_t                refcount;   /*! all pointers on this file                    */
266        remote_rwlock_t       lock;       /*! protect offset modifications                 */
267        struct mapper_s       * mapper;     /*! associated file cache                        */
268        struct vfs_inode_s    * inode;      /*! local pointer on associated inode            */
269        struct vfs_ctx_s      * ctx;        /*! file system features                         */
270        struct vfs_file_op_s  * op;         /*! local set of function pointers               */
271}
272vfs_file_t;
273
274/******************************************************************************************
275 * This structure defines informations common to all inodes and dentries
276 * of a given file system. As it is declared a global variable in the kdata segment,
277 * it is replicated in all clusters and handled as private by each OS intance.
278 *****************************************************************************************/
279
280typedef enum
281{
282        FS_TYPE_SYSFS = 0,
283        FS_TYPE_DEVFS = 1,
284        FS_TYPE_FATFS = 2,
285        FS_TYPE_RAMFS = 3,
286 
287        FS_TYPES_NR   = 4,
288}
289vfs_types_t;
290
[10]291typedef enum
292{
293    CTX_ATTR_READ_ONLY    = 0x01,       /*! read access possible                         */
294    CTX_ATTR_SYNC         = 0x10,       /*! synchronise FS on each write                 */
295}
296vfs_ctx_attr_t;
297
[1]298typedef struct vfs_ctx_s
299{
300        uint32_t                      type;          /*! File System type                        */
[10]301        uint32_t                      attr;          /*! global attributes for all files in FS   */
[1]302        uint32_t                  count;         /*! number of clusters                      */
303        uint32_t                  blksize;       /*! cluster size                            */
304    xptr_t                    ioc_xp;        /*! extended pointer on IOC device          */
305        xptr_t                    root_xp;       /*! extended pointer on root inode          */
306
307    spinlock_t                lock;          /*! lock protecting inum allocator          */
308        BITMAP( inum , CONFIG_VFS_MAX_INODES );  /*! inum allocator                          */ 
309
310    void                    * extend;        /*! FS specific context extension           */
311}
312vfs_ctx_t;
313
314/******************************************************************************************
315 * This structure define the informations associated to a given file descriptor,
316 * that are returned by the vfs_stat() function.
317 *****************************************************************************************/
318
319typedef struct vfs_stat_s
320{
321        uint32_t    dev;        /*! ID of device containing file                             */
322        uint32_t    ino;        /*! inode number                                             */
323        uint32_t    mode;       /*! protection                                               */
324        uint32_t    nlink;      /*! number of hard links                                     */
325        uint32_t    uid;        /*! user ID of owner                                         */
326        uint32_t    gid;        /*! group ID of owner                                        */
327        uint32_t    rdev;       /*! device ID (if special file)                              */
328        uint64_t    size;       /*! total size, in bytes                                     */
329        uint32_t    blksize;    /*! blocksize for file system I/O                            */
330        uint32_t    blocks;     /*! number of 512B blocks allocated                          */
331        uint64_t    atime;      /*! time of last access                                      */
332        uint64_t    mtime;      /*! time of last modification                                */
333        uint64_t    ctime;      /*! time of last status change                               */
334}
335vfs_stat_t;
336
337
338
339
340
341
342/******************************************************************************************
343 * This structure defines the set of operations that can be done on a VFS context.
344 * TODO A quoi cela sert-il ? [AG]
345 *****************************************************************************************/
346
347typedef error_t (vfs_create_context_t)  ( vfs_ctx_t * context );
348typedef error_t (vfs_destroy_context_t) ( vfs_ctx_t * context );
349typedef error_t (vfs_read_root_t)       ( vfs_ctx_t * context , vfs_inode_t * root );
350typedef error_t (vfs_reply_root_t)      ( vfs_ctx_t * context , vfs_inode_t * root );
351typedef error_t (vfs_write_root_t)      ( vfs_ctx_t * context , vfs_inode_t * root );
352
353struct vfs_ctx_op_s
354{
355        vfs_create_context_t  * create;      /*! allocate memory and initialize a context   */
356        vfs_destroy_context_t * destroy;     /*! release memory allocated to a context      */
357        vfs_read_root_t       * read_root;   /*! TODO                                       */
358        vfs_reply_root_t      * repli_root;  /*! TODO                                       */
359        vfs_write_root_t      * write_root;  /*! TODO                                       */
360}
361vfs_ctx_op_t;
362
363/******************************************************************************************
364 * This structure defines the set of operations that can be done on a VFS inode.
365 * TODO A quoi cela sert-il ? [AG]
366 *****************************************************************************************/
367
368typedef error_t (vfs_init_inode_t)    ( vfs_inode_t * inode );
369typedef error_t (vfs_create_inode_t)  ( vfs_inode_t * parent , vfs_dentry_t  * dentry );
370typedef error_t (vfs_lookup_inode_t)  ( vfs_inode_t * parent , vfs_dentry_t  * dentry );
371typedef error_t (vfs_write_inode_t)   ( vfs_inode_t * inode );
372typedef error_t (vfs_release_inode_t) ( vfs_inode_t * inode );
373typedef error_t (vfs_unlink_inode_t)  ( vfs_inode_t * parent , vfs_dentry_t  * dentry , uint32_t flags );
374typedef error_t (vfs_stat_inode_t)    ( vfs_inode_t * inode );
375typedef error_t (vfs_trunc_inode_t)   ( vfs_inode_t * inode );
376typedef error_t (vfs_delete_inode_t)  ( vfs_inode_t * inode );
377
378typedef struct vfs_inode_op_s
379{
380        vfs_init_inode_t    * init;     /*! initialise inode from scratch                    */
381        vfs_create_inode_t  * create;   /*! allocate memory for one inode                    */
382        vfs_lookup_inode_t  * lookup;   /*! get one directory entry by name                  */ 
383        vfs_write_inode_t   * write;    /*! update the device from the inode                 */
384        vfs_release_inode_t * release;  /*! reset one inode and release associated objects   */
385        vfs_unlink_inode_t  * unlink;   /*! unlink a directory entry from parent inode       */
386        vfs_delete_inode_t  * delete;   /*! release memory allocated to inode when count = 0 */
387        vfs_stat_inode_t    * stat;     /*! TODO                                             */
388        vfs_trunc_inode_t   * trunc;    /*! change the size of a file                        */
389}
390vfs_inode_op_t;
391
392/******************************************************************************************
393 * This structure defines the set of operations that can be done on a VFS dentry.
394 * TODO A quoi cela sert-il ? [AG]
395 *****************************************************************************************/
396
397typedef error_t (vfs_compare_dentry_t) ( char * first , char * second );
398
399typedef struct vfs_dentry_op_s
400{
401        vfs_compare_dentry_t * compare;
402}
403vfs_dentry_op_t;
404
405/******************************************************************************************
406 * This structure defines the set of operations that can be done on a VFS file. 
407 * TODO A quoi cela sert-il ? [AG]
408 *****************************************************************************************/
409
410typedef error_t (vfs_open_file_t)    ( vfs_file_t * file , void * priv );
411typedef error_t (vfs_read_file_t)    ( vfs_file_t * file , char * buffer );
412typedef error_t (vfs_write_file_t)   ( vfs_file_t * file , char * buffer );
413typedef error_t (vfs_lseek_file_t)   ( vfs_file_t * file );
414typedef error_t (vfs_close_file_t)   ( vfs_file_t * file );
415typedef error_t (vfs_release_file_t) ( vfs_file_t * file );
416typedef error_t (vfs_read_dir_t)     ( vfs_file_t * file );
417typedef error_t (vfs_mmap_file_t)    ( vfs_file_t * file , struct vseg_s * vseg );
418typedef error_t (vfs_munmap_file_t)  ( vfs_file_t * file , struct vseg_s * vseg );
419
420typedef struct vfs_file_op_s
421{
422        vfs_open_file_t    * open;
423        vfs_read_file_t    * read;
424        vfs_write_file_t   * write;
425        vfs_lseek_file_t   * lseek;
426        vfs_read_dir_t     * readdir;
427        vfs_close_file_t   * close;
428        vfs_release_file_t * release;
429        vfs_mmap_file_t    * mmap;
430        vfs_munmap_file_t  * munmap;
431}
432vfs_file_op_t;
433
434
435
436
437
438
439/*****************************************************************************************/
440/******************** VFS global functions ***********************************************/
441/*****************************************************************************************/ 
442
443/******************************************************************************************
444 * This function initializes the Virtual File System.     
445 *****************************************************************************************/
446void vfs_init();
447
448/******************************************************************************************
449 * This function mount a given file system type for a given process.     
450 *****************************************************************************************/
451error_t vfs_mount_fs_root( struct device_s  * device,
452                                       uint32_t           fs_type,
453                                       struct process_s * process );
454
455
456/*****************************************************************************************/
457/******************* FS Context related functions ****************************************/
458/*****************************************************************************************/
459
460/******************************************************************************************
461 * This function allocates an inode identifier from the local cluster inum allocator.
462 * The inum respects a fixed format:
463 * - the 16 MSB bits contain the cluster identifier : cxy
464 * - the 16 LSB bits contains the local inode identifier  : lid
465 ******************************************************************************************
466 * @ ctx      : local pointer on file system context.
467 * @ inum     : [ou] buffer for allocated inode identifier.
468 * @ return 0 if success / return non-zero if error.
469 *****************************************************************************************/
470error_t vfs_ctx_inum_alloc( vfs_ctx_t * ctx,
471                            uint32_t  * inum );
472
473/******************************************************************************************
474 * This function release an inode identifier.                                 
475 ******************************************************************************************
476 * @ ctx      : local pointer on file system context.
477 * @ inum     : released inode identifier.
478 *****************************************************************************************/
479void vfs_ctx_inum_release( vfs_ctx_t * ctx,
480                           uint32_t    inum );
481
482
483
484/*****************************************************************************************/
485/************************ File Descriptor related functions ******************************/
486/*****************************************************************************************/
487
488/******************************************************************************************
489 * This function allocates memory and initializes a new local file descriptor.
490 * It must be executed in the owner cluster containing the inode.
491 * If the client thread is not running in the owner cluster, it must use the
492 * rpc_vfs_file_create_client() function.
493 ******************************************************************************************
494 * @ inode_xp : extended pointer on associated inode.
495 * @ type     : file descriptor type.
496 * @ attr     : file descriptor attributes.
497 * @ file_xp  : [out] buffer for extended pointer on created file descriptor.
498 * @ return 0 if success / return ENOMEM if error.
499 *****************************************************************************************/
500error_t vfs_file_create( xptr_t     inode_xp,
501                         uint32_t   type,
502                         uint32_t   attr,
503                         xptr_t   * file_xp ); 
504
505/******************************************************************************************
506 * This function releases memory allocated to a local file descriptor.
507 * It must be executed by a thread running in the cluster containing the inode,
508 * and the file refcount must be zero.
509 * If the client thread is not running in the owner cluster, it must use the
510 * rpc_vfs_file_destroy_client() function.
511 ******************************************************************************************
512 * @ file_xp  : extended pointer on file descriptor.
513 *****************************************************************************************/
514void vfs_file_destroy( xptr_t  file_xp ); 
515
516
517/******************************************************************************************
518 * These functions increment (resp. decrement) the count field in a remote file
519 * descriptor, using a remote_atomic access.
520 *****************************************************************************************/
521void vfs_file_count_up  ( xptr_t   file_xp );
522void vfs_file_count_down( xptr_t   file_xp );
523
524
525
526/*****************************************************************************************/
527/********************* Inode related functions *******************************************/
528/*****************************************************************************************/
529
530/******************************************************************************************
531 * This function allocates memory from local cluster for an inode descriptor and the
532 * associated mapper. It initialise these descriptors from arguments values.
533 * The parent dentry must have been previously created.
534 * If the client thread is not running in the cluster containing this inode,
535 * it must use the rpc_vfs_inode_create_client() function.
536 ******************************************************************************************
537 * @ dentry_xp  : extended pointer on associated dentry (in parent inode cluster).
538 * @ type       : file system type.
539 * @ attr       : inode attributes.
540 * @ mode       : inode access mode.
541 * @ uid        : user owner ID.
542 * @ gid        : group owner ID.
543 * @ inode_xp   : [out] buffer for extended pointer on created inode.
544 * # return 0 if success / return ENOMEM or EINVAL if error.
545 *****************************************************************************************/
546error_t vfs_inode_create( xptr_t      dentry_xp,
547                          uint32_t    type,
548                          uint32_t    attr,
549                          uint32_t    mode,
550                          uid_t       uid,
551                          gid_t       gid,
552                          xptr_t    * inode_xp );
553
554/******************************************************************************************
555 * This function releases memory allocated to an inode descriptor.
556 * It must be executed by a thread running in the cluster containing the inode,
557 * and the inode refcount must be zero.
558 * If the client thread is not running in the owner cluster, it must use the
559 * rpc_vfs_inode_destroy_client() function.
560 ******************************************************************************************
561 * @ inode  : local pointer on inode descriptor.
562 *****************************************************************************************/
563void vfs_inode_destroy( vfs_inode_t *  inode ); 
564
565/******************************************************************************************
566 * This function atomically increment the inode refcount.
567 * It can be called by any thread running in any cluster.
568 *****************************************************************************************/
569void vfs_inode_remote_up( xptr_t  inode_xp );
570
571/******************************************************************************************
572 * This function atomically decrement the inode refcount.
573 * It can be called by any thread running in any cluster.
574 *****************************************************************************************/
575void vfs_inode_remote_down( xptr_t  inode_xp );
576
577/******************************************************************************************
578 * This function returns the <size> of a file/dir from a remote inode,
579 * taking the remote_rwlock protecting <size> in READ_MODE.
580 *****************************************************************************************
581 * @ inode_xp  : extended pointer on the remote inode.
582 * @ return the current size.
583 *****************************************************************************************/
584uint32_t vfs_inode_get_size( xptr_t inode_xp );
585
586/******************************************************************************************
587 * This function set the <size> of a file/dir to a remote inode,
588 * taking the remote_rwlock protecting <size> in WRITE_MODE.
589 *****************************************************************************************
590 * @ inode_xp  : extended pointer on the remote inode.
591 * @ size      : value to be written.
592 *****************************************************************************************/
593void vfs_inode_set_size( xptr_t   inode_xp,
594                         uint32_t size );
595
596/******************************************************************************************
597 * This function takes the main lock of a remote inode.
598 * This lock protect all inode fiels, including the children dentries.
599 *****************************************************************************************
600 * @ inode_xp  : extended pointer on the remote inode.
601 *****************************************************************************************/
602void vfs_inode_remote_lock( xptr_t inode_xp );
603
604/******************************************************************************************
605 * This function releases the main lock of a remote inode.
606 * This lock protect all inode fiels, including the children dentries.
607 *****************************************************************************************
608 * @ inode_xp  : extended pointer on the remote inode.
609 *****************************************************************************************/
610void vfs_inode_remote_unlock( xptr_t inode_xp );
611
612
613
614
615/******************************************************************************************
616 * This function TODO                                                         
617 *****************************************************************************************/
618error_t vfs_inode_hold( vfs_inode_t * inode,
619                        uint32_t      gc );
620
621/******************************************************************************************
622 * This function TODO                                                         
623 *****************************************************************************************/
624error_t vfs_inode_trunc( vfs_inode_t * inode );
625
626/******************************************************************************************
627 * This function TODO                                                         
628 *****************************************************************************************/
629error_t vfs_inode_link( vfs_inode_t * inode,
630                        uint32_t      igc );
631
632/******************************************************************************************
633 * This function TODO                                                         
634 *****************************************************************************************/
635error_t vfs_inode_unlink( vfs_inode_t * inode );
636
637/******************************************************************************************
638 * This function TODO                                                         
639 *****************************************************************************************/
640error_t vfs_inode_stat( vfs_inode_t * inode,
641                        uint32_t      inum );
642
643/******************************************************************************************
644 * This function TODO                                                         
645 *****************************************************************************************/
646error_t vfs_icache_del( vfs_inode_t * inode );
647
648
649/******************************************************************************************
650 * This function TODO  Pourquoi 2 arguments ?
651 *****************************************************************************************/
652error_t vfs_stat_inode( vfs_inode_t * inode,
653                        uint32_t      inum );
654
655
656/*****************************************************************************************/
657/***************** Dentry related functions **********************************************/
658/*****************************************************************************************/
659
660/******************************************************************************************
661 * This function allocates memory from local cluster for a dentry descriptor,
662 * initialises it from  arguments values, and returns the extended pointer on dentry.
663 * The inode field is not initialized, because the inode does not exist yet.
664 * If the client thread is not running in the target cluster for this inode,
665 * it must use the rpc_dentry_create_client() function.
666 ******************************************************************************************
667 * @ type       : file system type.
668 * @ name       : directory entry file/dir name.
669 * @ parent     : local pointer on parent inode.
670 * @ dentry_xp  : [out] buffer for extended pointer on created inode.
671 * @ return 0 if success / return ENOMEM or EINVAL if error.
672 *****************************************************************************************/
673error_t vfs_dentry_create( uint32_t      type,
674                           char        * name,
675                           vfs_inode_t * parent,
676                           xptr_t      * dentry_xp );
677 
678/******************************************************************************************
679 * This function releases memory allocated to a dentry descriptor.
680 * It must be executed by a thread running in the cluster containing the dentry,
681 * and the dentry refcount must be zero.
682 * If the client thread is not running in the owner cluster, it must use the
683 * rpc_dentry_destroy_client() function.
684 ******************************************************************************************
685 * @ dentry  : local pointer on dentry descriptor.
686 *****************************************************************************************/
687void vfs_dentry_destroy( vfs_dentry_t *  dentry ); 
688
689/******************************************************************************************
690 * This function atomically increment the dentry refcount.                               
691 * It can be called by any thread running in any cluster.
692 *****************************************************************************************/
693void vfs_dentry_remote_up( xptr_t dentry_xp );
694
695/******************************************************************************************
696 * This function atomically decrement the dentry refcount.                               
697 * It can be called by any thread running in any cluster.
698 *****************************************************************************************/
699void vfs_dentry_remote_down( xptr_t dentry_xp );
700
701
702/*****************************************************************************************/
703/*                 Inode-Tree related functions                                          */ 
704/*****************************************************************************************/ 
705
706/******************************************************************************************
707 * This function returns in a kernel buffer allocated by the caller function,
708 * the pathname of a file/dir identified by an extended pointer on the inode.
709 * It traverse the Inode Tree from the target node to the root.
710 * It can be called by any thread running in any cluster.
711 ******************************************************************************************
712 * @ inode_xp    : pointer on inode descriptor.
713 * @ buffer      : kernel buffer for pathname (must be allocated by caller).
714 * @ size        : max number of characters in buffer.
715 * @ return 0 if success / return EINVAL if buffer too small.
716 *****************************************************************************************/
717error_t vfs_get_path( xptr_t    inode_xp,
718                      char    * buffer,
719                      uint32_t  max_size );
720
721/******************************************************************************************
722 * This function takes a pathname (absolute or relative to cwd) and returns an extended
723 * pointer on the associated inode, and an extended pointer on the inode context.
724 * If a given name in the path is not found in the inode tree, it try to load the missing
725 * dentry/inode couple, from informations found in the parent directory.
726 * If this directory entry does not exist on device, it returns an error.
727 ******************************************************************************************
728 * @ cwd_xp     : extended pointer on current directory (for relative path).
729 * @ pathname   : path in kernel space (can be relative or absolute).
730 * @ client_uid : client thread user ID (for checking).
731 * @ client_gid : client thread group ID (for checking).
732 * @ inode_xp   : [out] buffer for extended pointer on inode.
733 * @ ctx_xp     : [out] buffer for extended pointer on inode context.
734 * @ return 0 if success / ENOENT if inode not found / EACCES if permissopn denied
735 *****************************************************************************************/
736error_t vfs_lookup( xptr_t       cwd_xp,
737                    char       * pathname,
738                    uint32_t     client_uid,
739                    uint32_t     client_gid,
740                                        xptr_t     * inode_xp,
741                    xptr_t     * ctx_xp );
742
743/******************************************************************************************
744 * This function creates a new couple dentry/inode, and insert it in the Inode-Tree.
745 * It can be executed by any thread running in any cluster, as this function
746 * uses the rpc_dentry_create_client() and rpc_inode_create client() if required.
747 * - The dentry is created in the cluster containing the existing <parent_xp> inode.
748 * - the child inode and its associated mapper are created in a randomly selected cluster.
749 * - The dentry name is defined by the <name> argument.
750 ******************************************************************************************
751 * @ type       : new inode type
752 * @ parent_xp  : extended pointer on parent inode.
753 * @ name       : new directory entry name.
754 * @ child_xp   : [out] buffer for extended pointer on child inode.
755 * @ return 0 if success / ENOENT if entry not found in parent directory
756 *****************************************************************************************/
757error_t vfs_add_child_in_parent( uint32_t type,
758                                 xptr_t   parent_xp,
759                                 char   * name,   
760                                 xptr_t * child_xp );
761
762/******************************************************************************************
763 * TODO
764 ******************************************************************************************
765 * @ child_xp   : extended pointer on removed inode.
766 *****************************************************************************************/
767error_t vfs_remove_child_from_parent( xptr_t child_xp );
768
769/*****************************************************************************************/
770/************************ File related functions *****************************************/
771/*****************************************************************************************/
772
773/******************************************************************************************
774 * This function allocates a vfs_file_t structure in the cluster containing the inode
775 * associated to the requested file, initializes it, and returns an extended pointer
776 * on this remote open file descriptor.
777 * The pathname can be relative to current directory or absolute.
778 * If the inode does not exist in the inode cache, it try to find file on the mounted
779 * device, and creates an inode on a pseudo randomly selected cluster if found.
780 * It the requested file does not exist on device, it creates a new inode if the
781 * O_CREAT flag is set and return an error otherwise.
782 ******************************************************************************************
783 * @ cwd_xp    : extended pointer on current directory file descriptor (for relative path).
784 * @ path      : file pathname (absolute or relative to current directory).
785 * @ flags     : O_RDONLY, O_WRONLY, O_CREATE etc...
786 * @ file_xp   : [out] buffer for extended pointer on created remote file descriptor.
787 * @ return 0 if success / return non-zero if error.
788 *****************************************************************************************/
789error_t vfs_open( xptr_t     cwd_xp,
790                          char     * path,
791                          uint32_t   flags,
792                          xptr_t   * file_xp );
793
794/******************************************************************************************
795 * This function moves <size> bytes from the file identified by the open file descriptor
796 * <file_xp> to the local kernel <buffer> , taken into account the offset in <file_xp>.
797 ******************************************************************************************
798 * @ file_xp   : extended pointer on the remote open file descriptor.
799 * @ buffer    : local pointer on destination kernel buffer.
800 * @ size      : requested number of bytes from offset.
801 * @ returns number of bytes actually transfered / 0 if EOF / -1 if error.
802 *****************************************************************************************/
803uint32_t vfs_read( xptr_t   file_xp, 
804                   void   * buffer,
805                   uint32_t size );
806
807/******************************************************************************************
808 * This function moves <size> bytes from the local kernel <buffer> to the open file
809 * descriptor <file_xp>, taken into account the offset defined in <file_xp>.
810 ******************************************************************************************
811 * @ file_xp   : extended pointer on the remote open file descriptor.
812 * @ buffer    : local pointer on source kernel buffer.
813 * @ size      : requested number of bytes to be written from offset.
814 * @ returns number of bytes actually transfered / -1 if error.
815 *****************************************************************************************/
816uint32_t vfs_write( xptr_t   file_xp,
817                    void   * buffer,
818                    uint32_t size );
819
820/******************************************************************************************
821 * This function set a new value in the offset of the open file descriptor <file_xp>.
822 * This value depends on the <whence> argument:
823 * - if VFS_SEEK_SET, new value is <offset>
824 * - if VFS_SEEK_CUR, new value is current_offset + <offset>
825 * - if VFS_SEEK_END, new value is file_size + <offset>
826 ******************************************************************************************
827 * @ file_xp   : extended pointer on the remote open file descriptor.
828 * @ offset    : local pointer on source kernel buffer.
829 * @ whence    : VFS_SEEK_SET / VFS_SEEK_CUR / VFS_SEEK_END.
830 * @ new_offset : [out] buffer for new offset value.
831 * @ returns 0 if success / -1 if error.
832 *****************************************************************************************/
833error_t vfs_lseek( xptr_t     file_xp,
834                   uint32_t   offset,
835                   uint32_t   whence, 
836                   uint32_t * new_offset );
837
838/******************************************************************************************
839 * This function close an open file descriptor.                             
840 ******************************************************************************************
841 * @ file_xp     : extended pointer on the file descriptor.
842 * @ refcount    : number of references after close.
843 * @ return 0 if success / return -1 if error
844 *****************************************************************************************/
845error_t vfs_close( xptr_t     file_xp, 
846                   uint32_t * refcount );
847
848/******************************************************************************************
849 * This function remove from the file system a directory entry identified by its pathname.
850 * The pathname can be relative to current directory or absolute.
851 ******************************************************************************************
852 * @ cwd_xp   : extended pointer on the current directory file descriptor.
853 * @ path     : pathname (absolute or relative to current directory).
854 *****************************************************************************************/
855error_t vfs_unlink( xptr_t   cwd_xp,
856                    char   * path );
857
858/******************************************************************************************
859 * This function returns in the <ustat> structure various informations on the file TODO
860 *****************************************************************************************/
861error_t vfs_stat( xptr_t       file_xp,
862                  vfs_stat_t * ustat );
863
864
865
866
867/*****************************************************************************************/
868/************************ Directory related functions ************************************/
869/*****************************************************************************************/
870
871/******************************************************************************************
872 * This function TODO                                                         
873 *****************************************************************************************/
874error_t vfs_opendir( xptr_t      cwd_xp,
875                     char      * path,
876                     uint32_t    flags,
877                     xptr_t      file_xp );
878
879/******************************************************************************************
880 * This function TODO                                                         
881 *    fat32_readdir need cleaning
882 *****************************************************************************************/
883error_t vfs_readdir( xptr_t            file_xp,
884                     char            * path );
885
886/******************************************************************************************
887 * This function TODO                                                         
888 *****************************************************************************************/
889error_t vfs_mkdir( xptr_t            file_xp,
890                   char            * path,
891                   uint32_t          mode );
892
893/******************************************************************************************
894 * This function remove a directory from the file system.
895 *****************************************************************************************/
896error_t vfs_rmdir( xptr_t            file_xp,
897                   char            * path );
898
899/******************************************************************************************
900 * This function TODO                                                         
901 *****************************************************************************************/
902error_t vfs_chdir( char            * pathname,
903                   xptr_t            cwd_xp );
904
905/******************************************************************************************
906 * This function TODO                                                         
907 *****************************************************************************************/
908error_t vfs_chmod( char            * pathname,
909                   vfs_file_t      * cwd,
910                   uint32_t          mode );
911
912/******************************************************************************************
913 * This function TODO                                                         
914 *****************************************************************************************/
915error_t vfs_closedir( xptr_t       file_xp,
916                      uint32_t   * refcount );
917
918
919
920
921/*****************************************************************************************/
922/*******************  Pipe related functions *********************************************/
923/*****************************************************************************************/
924
925/******************************************************************************************
926 * This function TODO ???                                                         
927 *****************************************************************************************/
928error_t vfs_pipe( xptr_t pipefd[2] );
929
930/******************************************************************************************
931 * This function TODO                                                         
932 *****************************************************************************************/
933error_t vfs_mkfifo( xptr_t            cwd_xp,
934                    char            * path,
935                    uint32_t          mode );
936
937
938
939
940#endif  /* _VFS_H_ */
Note: See TracBrowser for help on using the repository browser.