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

Last change on this file since 145 was 101, checked in by alain, 7 years ago

euh...

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