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

Last change on this file since 601 was 598, checked in by alain, 6 years ago

1) Modify the devfs_user_move() function to support large user buffer transfer to/from TXT device.
2) Cosmetic: Improve debug.

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