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

Last change on this file since 233 was 204, checked in by alain, 7 years ago

Bug fix in kernel_init
-This line, and those below, will be ignored--

M params.mk
M kernel_config.h
M Makefile
M hdd/virt_hdd.dmg
M tools/bootloader_tsar/boot.c
M kernel/libk/bits.h
M kernel/libk/elf.c
M kernel/libk/xhtab.c
M kernel/libk/elf.h
M kernel/libk/xhtab.h
M kernel/devices/dev_pic.c
M kernel/mm/vmm.c
M kernel/mm/mapper.c
M kernel/mm/mapper.h
M kernel/vfs/devfs.h
M kernel/vfs/vfs.c
M kernel/vfs/vfs.h
M kernel/vfs/devfs.c
M kernel/kern/chdev.h
M kernel/kern/kernel_init.c
M kernel/kern/process.c
M kernel/kern/process.h
M hal/tsar_mips32/core/hal_remote.c
M hal/tsar_mips32/drivers/soclib_pic.c

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