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

Last change on this file since 355 was 317, checked in by alain, 7 years ago

1) Introduce the TSAR hal_cpu_context_switch() function.
2) Introduce the generic vfs_kernel_move() function.

File size: 53.6 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   */
[188]134        uint32_t       total_clusters;           /*! total number of clusters on device      */
135        uint32_t       cluster_size;             /*! cluster size on device (bytes)          */
136        xptr_t         vfs_root_xp;              /*! extended pointer on VFS root inode      */
[23]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{
[188]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_SOCK  =     0x010,      /*! POSIX socket                                  */
167    INODE_TYPE_DEV   =     0x020,      /*! device 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{
[188]184        struct vfs_ctx_s * ctx;              /*! local pointer on FS context                 */
185    uint32_t           gc;               /*! generation counter                          */
186        uint32_t           inum;             /*! inode identifier (unique in file system)    */
187        uint32_t           attr;             /*! inode attributes (see above)                */
188        vfs_inode_type_t   type;             /*! inode type (see above)                      */
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                      */
193    uint32_t           rights;           /*! access rights                               */
194        uint32_t               refcount;         /*! reference counter (all pointers)            */
195        xptr_t             parent_xp;        /*! extended pointer on parent dentry           */
196        xhtab_t            children;         /*! embedded xhtab of children dentries         */
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     */
199        list_entry_t       list;             /*! member of set of inodes in same cluster     */
200        xlist_entry_t      wait_root;        /*! root of threads waiting on this inode       */
201        struct mapper_s  * mapper;           /*! associated file cache                       */
202        void             * extend;           /*! fs_type_specific inode extension            */
[1]203}
204vfs_inode_t;
205
206/******************************************************************************************
207 * This structure defines a directory entry.
208 * A dentry contains the name of a remote file/dir, an extended pointer on the
209 * inode representing this file/dir, and a local pointer on the inode representing
210 * the parent directory.
211 *****************************************************************************************/
212
213typedef struct vfs_dentry_s
214{
[188]215    struct vfs_ctx_s   * ctx;            /*! local pointer on FS context                 */
216        char                 name[CONFIG_VFS_MAX_NAME_LENGTH];
217        uint32_t             length;         /*! name length (bytes)                         */
218        uint32_t             refcount;       /*! reference counter (all pointers)            */
219    struct vfs_inode_s * parent;         /*! local pointer on parent inode               */
220    xptr_t               child_xp;       /*! extended pointer on child inode             */
221    xlist_entry_t        list;           /*! member of list of dentries with same key    */
222        void               * extend;         /*! FS specific extension                       */
[1]223}
224vfs_dentry_t;
225
226/******************************************************************************************
[23]227 * This file structure describes an open file/directory for a given process.
[1]228 * It is not replicated, and is dynamically allocated in the cluster that contains
229 * the inode, when a thread makes an open() or opendir() system call.
[23]230 * It cannot exist a file structure without an inode structure.
[266]231 * As the fd_array (containing extended pointers on the open file descriptors)
[23]232 * is replicated in all process descriptors, we need a references counter.
[1]233 *****************************************************************************************/
234
235typedef enum
236{
[266]237    VFS_SEEK_SET,
238    VFS_SEEK_CUR,
239    VFS_SEEK_END,
240}
241vfs_lseek_cmd_t;
242
243typedef enum
244{
[23]245    FD_ATTR_READ_ENABLE    = 0x01,     /*! read access possible                         */
246    FD_ATTR_WRITE_ENABLE   = 0x02,     /*! write access possible                        */
247    FD_ATTR_APPEND         = 0x04,     /*! append on each write                         */
248    FD_ATTR_CLOSE_EXEC     = 0x08,     /*! close file on exec                           */
249    FD_ATTR_SYNC           = 0x10,     /*! synchronise FS on each write                 */
250    FD_ATTR_IS_DIR         = 0x20,     /*! this is a directory                          */
[1]251}
[23]252vfs_file_attr_t;
[1]253
254typedef struct vfs_file_s
255{
[23]256        struct vfs_ctx_s      * ctx;        /*! local pointer on FS context.                 */
[1]257        uint32_t                gc;         /*! generation counter                           */
[23]258        vfs_file_attr_t         attr;       /*! file attributes bit vector (see above)       */
259        vfs_inode_type_t        type;       /*! same type as inode                           */
[1]260        uint32_t                offset;     /*! seek position in file                        */
[23]261        uint32_t                refcount;   /*! all pointers on this file descriptor         */
262        remote_rwlock_t         lock;       /*! protect offset modifications                 */
[1]263        struct mapper_s       * mapper;     /*! associated file cache                        */
264        struct vfs_inode_s    * inode;      /*! local pointer on associated inode            */
[23]265        void                  * extend;     /*! FS specific extension                        */
[1]266}
267vfs_file_t;
268
269/******************************************************************************************
[23]270 * This structure define the informations associated to a file descriptor,
271 * returned to user space by the stat() system call.
[1]272 *****************************************************************************************/
273
274typedef struct vfs_stat_s
275{
276        uint32_t    dev;        /*! ID of device containing file                             */
277        uint32_t    ino;        /*! inode number                                             */
278        uint32_t    mode;       /*! protection                                               */
279        uint32_t    nlink;      /*! number of hard links                                     */
280        uint32_t    uid;        /*! user ID of owner                                         */
281        uint32_t    gid;        /*! group ID of owner                                        */
282        uint32_t    rdev;       /*! device ID (if special file)                              */
283        uint64_t    size;       /*! total size, in bytes                                     */
284        uint32_t    blksize;    /*! blocksize for file system I/O                            */
285        uint32_t    blocks;     /*! number of 512B blocks allocated                          */
286        uint64_t    atime;      /*! time of last access                                      */
287        uint64_t    mtime;      /*! time of last modification                                */
288        uint64_t    ctime;      /*! time of last status change                               */
289}
290vfs_stat_t;
291
[23]292/*********************************************************************************************
293 * This structure defines the information associated to a directory entry,
294 * returned to user space by the readdir() system call.
295 ********************************************************************************************/
[1]296
[23]297typedef struct vfs_dirent_s
[1]298{
[23]299    uint32_t    inum;                               /*! inode identifier                    */
300    uint32_t    type;                               /*! inode type                          */
301    char        name[CONFIG_VFS_MAX_NAME_LENGTH];   /*! dentry name                         */
[1]302}
[23]303vfs_dirent_t;
[1]304
305
306
307/*****************************************************************************************/
308/******************** VFS global functions ***********************************************/
309/*****************************************************************************************/ 
310
311
312/******************************************************************************************
[23]313 * This function mount a given file system type for a given process TODO.     
[1]314 *****************************************************************************************/
315error_t vfs_mount_fs_root( struct device_s  * device,
316                                       uint32_t           fs_type,
317                                       struct process_s * process );
318
319
320/*****************************************************************************************/
[188]321/******************* VFS Context related functions ****************************************/
[1]322/*****************************************************************************************/
323
324/******************************************************************************************
[188]325 * This function initialise a (statically allocated) VFS context in local cluster.
326 ******************************************************************************************
327 * @ fs_type        : file system type.
328 * @ attr           : global attributes (for all files in FS.
329 * @ total_clusters : total number of clusters on device.
330 * @ cluster_size   : cluster size on device (bytes).
331 * @ vfs_root_xp    : extended pointer on VFS root inode.
332 * @ extend         : fs_type_specific extension.
333 *****************************************************************************************/
334void vfs_ctx_init( vfs_fs_type_t   type,
335                   uint32_t        attr,
336                       uint32_t        total_clusters,
337                       uint32_t        cluster_size,
338                       xptr_t          vfs_root_xp,
339                   void          * extend );
340
341/******************************************************************************************
[1]342 * This function allocates an inode identifier from the local cluster inum allocator.
343 * The inum respects a fixed format:
344 * - the 16 MSB bits contain the cluster identifier : cxy
345 * - the 16 LSB bits contains the local inode identifier  : lid
346 ******************************************************************************************
347 * @ ctx      : local pointer on file system context.
348 * @ inum     : [ou] buffer for allocated inode identifier.
349 * @ return 0 if success / return non-zero if error.
350 *****************************************************************************************/
351error_t vfs_ctx_inum_alloc( vfs_ctx_t * ctx,
352                            uint32_t  * inum );
353
354/******************************************************************************************
355 * This function release an inode identifier.                                 
356 ******************************************************************************************
357 * @ ctx      : local pointer on file system context.
358 * @ inum     : released inode identifier.
359 *****************************************************************************************/
360void vfs_ctx_inum_release( vfs_ctx_t * ctx,
361                           uint32_t    inum );
362
363
364
365
366/*****************************************************************************************/
367/********************* Inode related functions *******************************************/
368/*****************************************************************************************/
369
370/******************************************************************************************
371 * This function allocates memory from local cluster for an inode descriptor and the
372 * associated mapper. It initialise these descriptors from arguments values.
373 * The parent dentry must have been previously created.
374 * If the client thread is not running in the cluster containing this inode,
375 * it must use the rpc_vfs_inode_create_client() function.
376 ******************************************************************************************
377 * @ dentry_xp  : extended pointer on associated dentry (in parent inode cluster).
[23]378 * @ fs_type    : file system type.
379 * @ inode_type : inode type.
[188]380 * @ extend     : local pointer on vs_type_specific extension.
[1]381 * @ attr       : inode attributes.
[23]382 * @ rights     : inode access rights.
[1]383 * @ uid        : user owner ID.
384 * @ gid        : group owner ID.
385 * @ inode_xp   : [out] buffer for extended pointer on created inode.
386 * # return 0 if success / return ENOMEM or EINVAL if error.
387 *****************************************************************************************/
[23]388error_t vfs_inode_create( xptr_t            dentry_xp,
389                          vfs_fs_type_t     fs_type,
390                          vfs_inode_type_t  inode_type,
[188]391                          void            * extend,
[23]392                          uint32_t          attr,
393                          uint32_t          rights,
394                          uid_t             uid,
395                          gid_t             gid,
396                          xptr_t          * inode_xp );
[1]397
398/******************************************************************************************
399 * This function releases memory allocated to an inode descriptor.
400 * It must be executed by a thread running in the cluster containing the inode,
401 * and the inode refcount must be zero.
402 * If the client thread is not running in the owner cluster, it must use the
403 * rpc_vfs_inode_destroy_client() function.
404 ******************************************************************************************
405 * @ inode  : local pointer on inode descriptor.
406 *****************************************************************************************/
407void vfs_inode_destroy( vfs_inode_t *  inode ); 
408
[238]409/******************************************************************************************
410 * This function scan an existing parent inode directory, identified by the <parent>
411 * argument to find a directory entry identified by the <name> argument, and update
412 * the remote child inode, identified by the <child_xp> argument.
413 * Depending on the file system type, it calls the relevant, FS specific function,
414 * to scan the directory, and set the "type", "size", and "extend" fields.
415 * It must be called by a thread running in the cluster containing the parent inode.
416 ******************************************************************************************
417 * @ parent    : local pointer on parent inode (directory).
418 * @ name      : child name.
419 * @ child_xp  : extended pointer on remote child inode (file or directory)
420 * @ return 0 if success / return ENOENT if not found.
421 *****************************************************************************************/
422error_t vfs_inode_load( vfs_inode_t * parent,
423                        char        * name,
424                        xptr_t        child_xp );
425
[1]426/******************************************************************************************
[23]427 * This function atomically increment/decrement the inode refcount.
[1]428 * It can be called by any thread running in any cluster.
429 *****************************************************************************************/
430void vfs_inode_remote_up( xptr_t  inode_xp );
431void vfs_inode_remote_down( xptr_t  inode_xp );
432
433/******************************************************************************************
434 * This function returns the <size> of a file/dir from a remote inode,
435 * taking the remote_rwlock protecting <size> in READ_MODE.
436 *****************************************************************************************
437 * @ inode_xp  : extended pointer on the remote inode.
438 * @ return the current size.
439 *****************************************************************************************/
440uint32_t vfs_inode_get_size( xptr_t inode_xp );
441
442/******************************************************************************************
443 * This function set the <size> of a file/dir to a remote inode,
444 * taking the remote_rwlock protecting <size> in WRITE_MODE.
445 *****************************************************************************************
446 * @ inode_xp  : extended pointer on the remote inode.
447 * @ size      : value to be written.
448 *****************************************************************************************/
449void vfs_inode_set_size( xptr_t   inode_xp,
450                         uint32_t size );
451
452/******************************************************************************************
453 * This function takes the main lock of a remote inode.
454 * This lock protect all inode fiels, including the children dentries.
455 *****************************************************************************************
456 * @ inode_xp  : extended pointer on the remote inode.
457 *****************************************************************************************/
[101]458void vfs_inode_lock( xptr_t inode_xp );
[1]459
460/******************************************************************************************
461 * This function releases the main lock of a remote inode.
462 * This lock protect all inode fiels, including the children dentries.
463 *****************************************************************************************
464 * @ inode_xp  : extended pointer on the remote inode.
465 *****************************************************************************************/
[101]466void vfs_inode_unlock( xptr_t inode_xp );
[1]467
468/******************************************************************************************
[101]469 * This debug function returns the current owner of the inode main lock.
470 *****************************************************************************************
471 * @ inode_xp  : extended pointer on the remote inode.
472 * @ return extended pointer on owner thread / return XPTR_NULL if lock not taken.
[1]473 *****************************************************************************************/
[101]474xptr_t vfs_inode_owner( xptr_t inode_xp );
[1]475
476/******************************************************************************************
[204]477 * This debug function diplays the name of the inode identified by the <inode_xp>
478 * argument, and all children names for a directory.
479 *****************************************************************************************
480 * @ inode_xp  : extended pointer on the remote inode.
481 *****************************************************************************************/
482void vfs_inode_display( xptr_t inode_xp );
483
484
485
486
487
488
489/******************************************************************************************
[1]490 * This function TODO                                                         
491 *****************************************************************************************/
492error_t vfs_inode_trunc( vfs_inode_t * inode );
493
494/******************************************************************************************
495 * This function TODO                                                         
496 *****************************************************************************************/
497error_t vfs_inode_link( vfs_inode_t * inode,
498                        uint32_t      igc );
499
500/******************************************************************************************
501 * This function TODO                                                         
502 *****************************************************************************************/
503error_t vfs_inode_unlink( vfs_inode_t * inode );
504
505/******************************************************************************************
506 * This function TODO                                                         
507 *****************************************************************************************/
508error_t vfs_inode_stat( vfs_inode_t * inode,
509                        uint32_t      inum );
510
511/******************************************************************************************
512 * This function TODO                                                         
513 *****************************************************************************************/
514error_t vfs_icache_del( vfs_inode_t * inode );
515
516
517/******************************************************************************************
518 * This function TODO  Pourquoi 2 arguments ?
519 *****************************************************************************************/
520error_t vfs_stat_inode( vfs_inode_t * inode,
521                        uint32_t      inum );
522
523
524/*****************************************************************************************/
525/***************** Dentry related functions **********************************************/
526/*****************************************************************************************/
527
528/******************************************************************************************
529 * This function allocates memory from local cluster for a dentry descriptor,
530 * initialises it from  arguments values, and returns the extended pointer on dentry.
531 * The inode field is not initialized, because the inode does not exist yet.
532 * If the client thread is not running in the target cluster for this inode,
533 * it must use the rpc_dentry_create_client() function.
534 ******************************************************************************************
[23]535 * @ fs_type    : file system type.
[1]536 * @ name       : directory entry file/dir name.
537 * @ parent     : local pointer on parent inode.
[23]538 * @ dentry_xp  : [out] buffer for extended pointer on created dentry.
[1]539 * @ return 0 if success / return ENOMEM or EINVAL if error.
540 *****************************************************************************************/
[23]541error_t vfs_dentry_create( vfs_fs_type_t   fs_type,
542                           char          * name,
543                           vfs_inode_t   * parent,
544                           xptr_t        * dentry_xp );
[1]545 
546/******************************************************************************************
547 * This function releases memory allocated to a dentry descriptor.
548 * It must be executed by a thread running in the cluster containing the dentry,
549 * and the dentry refcount must be zero.
550 * If the client thread is not running in the owner cluster, it must use the
551 * rpc_dentry_destroy_client() function.
552 ******************************************************************************************
553 * @ dentry  : local pointer on dentry descriptor.
554 *****************************************************************************************/
555void vfs_dentry_destroy( vfs_dentry_t *  dentry ); 
556
557/******************************************************************************************
[23]558 * These functions atomically increment/decrement the dentry refcount.
[1]559 * It can be called by any thread running in any cluster.
560 *****************************************************************************************/
561void vfs_dentry_remote_up( xptr_t dentry_xp );
[23]562void vfs_dentry_remote_down( xptr_t dentry_xp );
[1]563
[23]564
565/*****************************************************************************************/
566/************************ File descriptor related functions ******************************/
567/*****************************************************************************************/
568
[1]569/******************************************************************************************
[23]570 * This function allocates memory and initializes a new local file descriptor.
571 * It must be executed in the cluster containing the inode.
572 * If the client thread is not running in the owner cluster, it must use the
573 * rpc_vfs_file_create_client() function.
574 ******************************************************************************************
575 * @ inode    : local pointer on associated inode.
576 * @ attr     : file descriptor attributes.
577 * @ file_xp  : [out] buffer for extended pointer on created file descriptor.
578 * @ return 0 if success / return ENOMEM if error.
[1]579 *****************************************************************************************/
[23]580error_t vfs_file_create( vfs_inode_t * inode,
581                         uint32_t      attr,
582                         xptr_t      * file_xp ); 
[1]583
[23]584/******************************************************************************************
585 * This function releases memory allocated to a local file descriptor.
586 * It must be executed by a thread running in the cluster containing the inode,
587 * and the file refcount must be zero.
588 * If the client thread is not running in the owner cluster, it must use the
589 * rpc_vfs_file_destroy_client() function.
590 ******************************************************************************************
591 * @ file  : local pointer on file descriptor.
592 *****************************************************************************************/
593void vfs_file_destroy( vfs_file_t *  file ); 
[1]594
[23]595/******************************************************************************************
596 * These functions increment (resp. decrement) the count field in a remote file
597 * descriptor, using a remote_atomic access.
598 *****************************************************************************************/
599void vfs_file_count_up  ( xptr_t   file_xp );
600void vfs_file_count_down( xptr_t   file_xp );
601
602
603
[1]604/*****************************************************************************************/
[23]605/******************* Inode-Tree related functions ****************************************/ 
[1]606/*****************************************************************************************/ 
607
608/******************************************************************************************
[188]609 * This function randomly selects a cluster for a new inode.
610 ******************************************************************************************
611 * @ returns the selected cluster identifier.
612 *****************************************************************************************/
613cxy_t vfs_cluster_random_select();
614
615/******************************************************************************************
[1]616 * This function returns in a kernel buffer allocated by the caller function,
617 * the pathname of a file/dir identified by an extended pointer on the inode.
618 * It traverse the Inode Tree from the target node to the root.
619 * It can be called by any thread running in any cluster.
620 ******************************************************************************************
621 * @ inode_xp    : pointer on inode descriptor.
622 * @ buffer      : kernel buffer for pathname (must be allocated by caller).
623 * @ size        : max number of characters in buffer.
624 * @ return 0 if success / return EINVAL if buffer too small.
625 *****************************************************************************************/
626error_t vfs_get_path( xptr_t    inode_xp,
627                      char    * buffer,
628                      uint32_t  max_size );
629
630/******************************************************************************************
631 * This function takes a pathname (absolute or relative to cwd) and returns an extended
[23]632 * pointer on the associated inode.
633 * - If a given name in the path is not found in the inode tree, it try to load the missing
634 *   dentry/inode couple, from informations found in the parent directory.
635 * - If this directory entry does not exist on device, it returns an error.
636 * - If the the file identified by the pathname does not exist on device but the
637 *   flag CREATE is set, the inode is created.
638 * - If the the file identified by the pathname exist on device but both flags EXCL
639 *   and CREATE are set, an error is returned.
[1]640 ******************************************************************************************
[23]641 * @ cwd_xp      : extended pointer on current directory (for relative path).
642 * @ pathname    : path in kernel space (can be relative or absolute).
643 * @ lookup_mode : flags defining the working mode (defined above in this file).
[238]644 * @ inode_xp    : [out] buffer for extended pointer on searched inode.
[23]645 * @ return 0 if success / ENOENT if inode not found , EACCES if permissopn denied,
646 *                        EAGAIN if a new complete lookup must be made
[1]647 *****************************************************************************************/
[23]648error_t vfs_lookup( xptr_t             cwd_xp,
649                    char             * pathname,
650                    uint32_t           lookup_mode,
651                                        xptr_t           * inode_xp );
[1]652
653/******************************************************************************************
654 * This function creates a new couple dentry/inode, and insert it in the Inode-Tree.
[296]655 * It can be executed by any thread running in any cluster ( can be differente from both
656 * the child cluster and the parent cluster), as it uses the rpc_dentry_create_client()
657 * and rpc_inode_create client() if required. This is done in three steps:
[204]658 * 1) The dentry is created in the cluster containing the existing <parent_xp> inode.
659 *    The new dentry name is defined by the <name> argument.
660 * 2) The inode and its associated mapper are created in cluster identified by <child_cxy>.
661 *    The new inode and the parent inode can have different FS types.
[238]662 * 3) The "child_xp" field in created dentry (pointing on the created inode) is updated.
[1]663 ******************************************************************************************
[188]664 * @ child_cxy  : target cluster for child inode.
[23]665 * @ inode_type : new inode type
666 * @ fs_type    : new inode FS type.
[1]667 * @ parent_xp  : extended pointer on parent inode.
668 * @ name       : new directory entry name.
[188]669 * @ extend     : fs_type_specific inode extension.
[1]670 * @ child_xp   : [out] buffer for extended pointer on child inode.
[204]671 * @ return 0 if success / ENOMEM if dentry or inode cannot be created.
[1]672 *****************************************************************************************/
[188]673error_t vfs_add_child_in_parent( cxy_t              child_cxy,
674                                 vfs_inode_type_t   inode_type,
[23]675                                 vfs_fs_type_t      fs_type,
676                                 xptr_t             parent_xp,
677                                 char             * name,   
[188]678                                 void             * extend,
[23]679                                 xptr_t           * child_xp );
[1]680
681/******************************************************************************************
[23]682 * This function removes a couple dentry/inode from the Inode-Tree, and remove it from
683 * the external device.
684 * TODO                   
[1]685 ******************************************************************************************
686 * @ child_xp   : extended pointer on removed inode.
687 *****************************************************************************************/
688error_t vfs_remove_child_from_parent( xptr_t child_xp );
689
[188]690/******************************************************************************************
691 * This recursive function diplays a complete inode/dentry sub-tree.
692 * Any inode can be selected as the sub-tree root.
[238]693 * TODO this function is not protected against a concurrent inode/dentry removal...
[188]694 ******************************************************************************************
695 * @ inode_xp   : extended pointer on sub-tree root inode.
696 *****************************************************************************************/
697void vfs_display( xptr_t   inode_xp );
[23]698
699
700
701
702
[1]703/*****************************************************************************************/
[23]704/****************** File access API ******************************************************/
[1]705/*****************************************************************************************/
706
707/******************************************************************************************
708 * This function allocates a vfs_file_t structure in the cluster containing the inode
[23]709 * associated to the file identified by <cwd_xp> & <path>.
710 * It initializes it, register it in the reference process fd_array, and returns both
711 * the extended pointer on the remote file descriptor, and the index in the fd_array.
[1]712 * The pathname can be relative to current directory or absolute.
[23]713 * If the inode does not exist in the inode cache, it try to find the file on the mounted
[1]714 * device, and creates an inode on a pseudo randomly selected cluster if found.
715 * It the requested file does not exist on device, it creates a new inode if the
716 * O_CREAT flag is set and return an error otherwise.
717 ******************************************************************************************
[23]718 * @ cwd_xp      : extended pointer on current working directory file descriptor.
719 * @ path        : file pathname (absolute or relative to current directory).
720 * @ flags       : defined above
721 * @ mode        : access rights (as defined by chmod)
722 * @ file_xp     : [out] buffer for extended pointer on created remote file descriptor.
723 * @ file_id     : [out] buffer for created file descriptor index in reference fd_array.
[1]724 * @ return 0 if success / return non-zero if error.
725 *****************************************************************************************/
726error_t vfs_open( xptr_t     cwd_xp,
727                          char     * path,
728                          uint32_t   flags,
[23]729                  uint32_t   mode,
730                          xptr_t   * file_xp,
731                          uint32_t * file_id );
[1]732
733/******************************************************************************************
[313]734 * This function moves <size> bytes between a remote file mapper, identified by the
735 * <file_xp> argument, and a - possibly distributed - user space <buffer>, taken into
736 * account the offset in <file_xp>. The transfer direction is defined by <to_buffer>.
[317]737 * This function is called by the elf_load_process() function.
[23]738 ******************************************************************************************
[265]739 * @ to_buffer : mapper -> buffer if true / buffer -> mapper if false.
[23]740 * @ file_xp   : extended pointer on the remote file descriptor.
[313]741 * @ buffer    : user space pointer on buffer (can be physically distributed).
[1]742 * @ size      : requested number of bytes from offset.
[317]743 * @ returns 0 f success / -1 if error.
[1]744 *****************************************************************************************/
[313]745error_t vfs_user_move( bool_t   to_buffer,
746                       xptr_t   file_xp, 
747                       void   * buffer,
748                       uint32_t size );
[1]749
750/******************************************************************************************
[317]751 * This function moves <size> bytes between a remote file mapper, identified by the
752 * <file_xp> argument, and a - possibly remote - kernel <buffer_xp>, taken into
753 * account the offset in <file_xp>. The transfer direction is defined by <to_buffer>.
754 * This function is called by the  system calls.
755 ******************************************************************************************
756 * @ to_buffer : mapper -> buffer if true / buffer -> mapper if false.
757 * @ file_xp   : extended pointer on the remote file descriptor.
758 * @ buffer_xp : user space pointer on buffer (can be physically distributed).
759 * @ size      : requested number of bytes from offset.
760 * @ returns number of bytes actually transfered / -1 if error.
761 *****************************************************************************************/
762error_t vfs_kernel_move( bool_t   to_buffer,
763                         xptr_t   file_xp, 
764                         xptr_t   buffer_xp,
765                         uint32_t size );
766
767/******************************************************************************************
[1]768 * This function set a new value in the offset of the open file descriptor <file_xp>.
769 * This value depends on the <whence> argument:
770 * - if VFS_SEEK_SET, new value is <offset>
771 * - if VFS_SEEK_CUR, new value is current_offset + <offset>
772 * - if VFS_SEEK_END, new value is file_size + <offset>
773 ******************************************************************************************
774 * @ file_xp   : extended pointer on the remote open file descriptor.
775 * @ offset    : local pointer on source kernel buffer.
776 * @ whence    : VFS_SEEK_SET / VFS_SEEK_CUR / VFS_SEEK_END.
777 * @ new_offset : [out] buffer for new offset value.
778 * @ returns 0 if success / -1 if error.
779 *****************************************************************************************/
780error_t vfs_lseek( xptr_t     file_xp,
781                   uint32_t   offset,
782                   uint32_t   whence, 
783                   uint32_t * new_offset );
784
785/******************************************************************************************
[23]786 * This function close an open file descriptor:
787 * 1) All entries in fd_array copies are directly cancelled by the calling thread,
788 *    using remote accesses.
789 * 2) The memory allocated to file descriptor in cluster containing the inode is released.
790 *    It requires a RPC if cluster containing the file descriptor is remote.
[1]791 ******************************************************************************************
792 * @ file_xp     : extended pointer on the file descriptor.
[23]793 * @ file_id     : file descriptor index in fd_array.
794 * @ returns 0 if success / -1 if error.
[1]795 *****************************************************************************************/
[23]796error_t vfs_close( xptr_t    file_xp,
797                   uint32_t  file_id );
[1]798
799/******************************************************************************************
[23]800 * This function remove from the file system a directory entry identified by the
801 * <cwd_xp> & <path> arguments.
[1]802 ******************************************************************************************
[23]803 * @ cwd_xp   : extended pointer on the current working directory file descriptor.
[1]804 * @ path     : pathname (absolute or relative to current directory).
[23]805 * @ returns 0 if success / -1 if error.
[1]806 *****************************************************************************************/
807error_t vfs_unlink( xptr_t   cwd_xp,
808                    char   * path );
809
810/******************************************************************************************
[23]811 * This function returns, in the structure pointed by the <k_stat> kernel pointer,
812 * various informations on the file descriptor identified by the <file_xp> argument.
813 * TODO not implemented yet...
814 ******************************************************************************************
815 * @ file_xp    : extended pointer on the file descriptor of the searched directory .
816 * @ k_dirent   : local pointer on the dirent_t structure in kernel space.
817 * @ returns 0 if success / -1 if error.
[1]818 *****************************************************************************************/
819error_t vfs_stat( xptr_t       file_xp,
[23]820                  vfs_stat_t * k_stat );
[1]821
822/******************************************************************************************
[23]823 * This function returns, in the structure pointed by the <k_dirent> kernel pointer,
824 * various infos on the directory entry currently pointed by the <file_xp> file descriptor.
825 * TODO not implemented yet...
826 ******************************************************************************************
827 * @ file_xp    : extended pointer on the file descriptor of the searched directory .
828 * @ k_dirent   : local pointer on the dirent_t structure in kernel space.
829 * @ returns 0 if success / -1 if error.
[1]830 *****************************************************************************************/
[23]831error_t vfs_readdir( xptr_t         file_xp,
832                     vfs_dirent_t * k_dirent );
[1]833
834/******************************************************************************************
[23]835 * This function  creates a new inode and associated dentry  for the directory defined
836 * by the <cwd_xp> & <path> arguments.
837 * TODO not implemented yet...
838 ******************************************************************************************
839 * @ cwd_xp   : extended pointer on the current working directory file descriptor.
840 * @ path     : pathname (absolute or relative to current directory).                     
841 * @ mode     : access rights (as defined by chmod)
842 * @ returns 0 if success / -1 if error.
[1]843 *****************************************************************************************/
[23]844error_t vfs_mkdir( xptr_t     cwd_xp,
845                   char     * path,
846                   uint32_t   mode );
[1]847
848/******************************************************************************************
[23]849 * This function remove a directory identified by the <cwd_xp / path> arguments
850 * from the file system.
851 * TODO not implemented yet...
852 ******************************************************************************************
853 * @ cwd_xp   : extended pointer on the current working directory file descriptor.
854 * @ path     : pathname (absolute or relative to current directory).                     
855 * @ returns 0 if success / -1 if error.
[1]856 *****************************************************************************************/
[23]857error_t vfs_rmdir( xptr_t   cwd_xp,
858                   char   * path );
[1]859
860/******************************************************************************************
[23]861 * This function makes the directory identified by <cwd_xp / path> arguments to become
862 * the working directory for the calling process.
863 ******************************************************************************************
864 * @ cwd_xp      : extended pointer on current directory file descriptor (relative path).
865 * @ path        : file pathname (absolute or relative to current directory).
866 * return 0 if success / -1 if error.
[1]867 *****************************************************************************************/
[23]868error_t vfs_chdir( xptr_t   cwd_xp,
869                   char   * path );
[1]870
871/******************************************************************************************
[23]872 * This function change the access rigths for the file identified by the <cwd_xp / path>
873 * arguments. The new access rights are defined by the <mode> argument value.
874 ******************************************************************************************
875 * @ cwd_xp      : extended pointer on current directory file descriptor (relative path).
876 * @ path        : file pathname (absolute or relative to current directory).
877 * @ mode        : access rights new value.
878 * return 0 if success / -1 if error.
[1]879 *****************************************************************************************/
[23]880error_t vfs_chmod( xptr_t        cwd_xp,
881                   char        * path,
882                   uint32_t      mode );
[1]883
884/******************************************************************************************
[23]885 * This function creates a named FIFO file.
886 * TODO not implemented yet                                                         
887 ******************************************************************************************
888 * @ path        : FIFO pathname (absolute or relative to current directory).
889 * @ cwd_xp      : extended pointer on the current working directory file descriptor.
890 * @ mode        : access rights new value.
[1]891 *****************************************************************************************/
[23]892error_t vfs_mkfifo( xptr_t       cwd_xp,
893                    char       * path,
894                    uint32_t     mode );
[1]895
896
897/*****************************************************************************************/
[23]898/****************** Mapper access API ****************************************************/
[1]899/*****************************************************************************************/
900
[23]901/******************************************************************************************
[238]902 * This function makes an I/O operation to move one page to/from device from/to the mapper.
903 * It is used in case of MISS on the mapper, or when a dirty page in the mapper must
904 * be updated in the File System.
[23]905 * Depending on the file system type, it calls the proper, FS specific function.
906 * It must be executed by a thread running in the cluster containing the mapper.
907 * The mapper pointer is obtained from the page descriptor.
908 * It takes the mapper lock before launching the IO operation.
909 ******************************************************************************************
[238]910 * @ page      : local pointer on the page descriptor.
911 * @ to_mapper : transfer direction.
[23]912 * @ returns 0 if success / return EINVAL if it cannot access the external device.
[1]913 *****************************************************************************************/
[238]914error_t vfs_mapper_move_page( struct page_s * page,
915                              bool_t          to_mapper );
[1]916
[23]917/******************************************************************************************
[239]918 * This function makes I/O operations to move, from device to mapper, all pages covering
919 * a given inode, identified by the <inode> argument. Inode be a directory or a file,
920 * but this function is mainly used to load (prefetch) a complete directory to the mapper.
[23]921 * Depending on the file system type, it calls the proper, FS specific function.
922 * It must be executed by a thread running in the cluster containing the mapper.
[238]923 * The mapper pointer is obtained from the inode descriptor.
[23]924 * It takes the mapper lock before launching the IO operation.
925 ******************************************************************************************
[238]926 * @ inode  : local pointer on inode.
927 * @ return 0 if success / return EIO if device access failure.
[1]928 *****************************************************************************************/
[238]929error_t vfs_mapper_load_all( vfs_inode_t * inode );
[1]930
931
932
[23]933/* deprecated [AG]
934
935typedef error_t (lookup_inode_t)  ( vfs_inode_t  * parent ,
936                                    vfs_dentry_t * dentry );
937
938typedef error_t (write_inode_t)   ( vfs_inode_t  * inode );
939
940typedef error_t (release_inode_t) ( vfs_inode_t  * inode );
941
942typedef error_t (unlink_inode_t)  ( vfs_inode_t  * parent,
943                                    vfs_dentry_t * dentry,
944                                    uint32_t       flags );
945
946typedef error_t (stat_inode_t)    ( vfs_inode_t  * inode );
947
948typedef error_t (trunc_inode_t)   ( vfs_inode_t  * inode );
949
950typedef error_t (delete_inode_t)  ( vfs_inode_t  * inode );
951
952typedef struct vfs_inode_op_s
953{
954        init_inode_t    * init;   
955        create_inode_t  * create; 
956        lookup_inode_t  * lookup; 
957        write_inode_t   * write;
958        release_inode_t * release;
959        unlink_inode_t  * unlink;
960        delete_inode_t  * delete;
961        stat_inode_t    * stat;
962        trunc_inode_t   * trunc;    // change the size of a file
963}
964vfs_inode_op_t;
965
966 ******************************************************************************************
967 * These typedef define the set of FS specific operations on a VFS DENTRY descriptor.
968 * They must be implemented by any specific file system to be supported by ALMOS_MKH.
969 * This code is not actually used, and is only defined for documentation
970 ******************************************************************************************
971
972
973typedef error_t (vfs_compare_dentry_t) ( char * first , char * second );
974
975typedef struct vfs_dentry_op_s
976{
977        vfs_compare_dentry_t * compare;
978}
979vfs_dentry_op_t;
980
981
982 ******************************************************************************************
983 * These typedef define the set of FS specific operations on FILE descriptors
984 * They must be implemented by any specific file system to be supported by ALMOS_MKH.
985 * This code is not actually used, and is only defined for documentation
986 ******************************************************************************************
987
988
989typedef error_t (open_file_t   ) ( vfs_file_t * file,
990                                   void       * extend );
991
992typedef error_t (read_file_t   ) ( vfs_file_t * file,
993                                   char       * buffer,
994                                   uint32_t     count );
995
996typedef error_t (write_file_t  ) ( vfs_file_t * file,
997                                   char       * buffer,
998                                   uint32_t     count );
999
1000typedef error_t (lseek_file_t  ) ( vfs_file_t * file );
1001
1002typedef error_t (close_file_t  ) ( vfs_file_t * file );
1003
1004typedef error_t (release_file_t) ( vfs_file_t * file );
1005
1006typedef error_t (read_dir_t    ) ( vfs_file_t * file );
1007
1008typedef error_t (mmap_file_t   ) ( vfs_file_t    * file ,
1009                                   struct vseg_s * vseg );
1010
1011typedef error_t (munmap_file_t ) ( vfs_file_t    * file,
1012                                   struct vseg_s * vseg );
1013
1014typedef struct vfs_file_op_s
1015{
1016        open_file_t    * open;
1017        read_file_t    * read;
1018        write_file_t   * write;
1019        lseek_file_t   * lseek;
1020        read_dir_t     * readdir;
1021        close_file_t   * close;
1022        release_file_t * release;
1023        mmap_file_t    * mmap;
1024        munmap_file_t  * munmap;
1025}
1026vfs_file_op_t;
1027
1028*/
1029
[1]1030#endif  /* _VFS_H_ */
Note: See TracBrowser for help on using the repository browser.