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

Last change on this file since 295 was 266, checked in by alain, 7 years ago

Implement vfs_lseek() function.

File size: 52.6 KB
Line 
1/*
2 * vfs.h - Virtual File System definition.
3 *
4 * Author  Mohamed Lamine Karaoui (2014,2015)
5 *         Alain Greiner (2016,2017)
6 *
7 * Copyright (c) UPMC Sorbonne Universites
8 *
9 * This file is part of ALMOS-MKH.
10 *
11 * ALMOS-MKH is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2.0 of the License.
14 *
15 * ALMOS-MKH is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25#ifndef _VFS_H_
26#define _VFS_H_
27
28#include <kernel_config.h>
29#include <hal_types.h>
30#include <hal_atomic.h>
31#include <remote_rwlock.h>
32#include <remote_spinlock.h>
33#include <spinlock.h>
34#include <list.h>
35#include <xlist.h>
36#include <slist.h>
37#include <bits.h>
38#include <xhtab.h>
39#include <errno.h>
40#include <metafs.h>
41
42#include <fatfs.h>
43#include <ramfs.h>
44#include <devfs.h>
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;
66struct page_s;
67
68
69/******************************************************************************************
70 * These flags are used to define the working mode of the vfs_lookup() function. 
71 *****************************************************************************************/
72
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                     */   
78
79/******************************************************************************************
80 * This define the masks for the POSIX access rights to inodes
81 *****************************************************************************************/
82
83#define VFS_ISUID                0x0004000
84#define VFS_ISGID                0x0002000
85#define VFS_ISVTX                0x0001000
86
87#define VFS_IRWXU            0x0000700
88#define VFS_IRUSR            0x0000400
89#define VFS_IWUSR            0x0000200
90#define VFS_IXUSR            0x0000100
91
92#define VFS_IRWXG            0x0000070
93#define VFS_IRGRP            0x0000040
94#define VFS_IWGRP            0x0000020
95#define VFS_IXGRP            0x0000010
96
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
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 *****************************************************************************************/
112
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;
122
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;
129
130typedef struct vfs_ctx_s
131{
132        vfs_fs_type_t  type;                     /*! File System type                        */
133        uint32_t           attr;                     /*! global attributes for all files in FS   */
134        uint32_t       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      */
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;
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.
149 * Syncrhonisation:
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
155 *   the relevant page for read/write.
156 *****************************************************************************************/
157
158/* this enum define the VFS inode types values */
159
160typedef enum   
161{
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                                 */
169}
170vfs_inode_type_t;
171
172/* this enum define the VFS inode attributes values */
173
174typedef enum 
175{
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                      */
179}
180vfs_inode_attr_t;
181
182typedef struct vfs_inode_s
183{
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            */
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{
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                       */
223}
224vfs_dentry_t;
225
226/******************************************************************************************
227 * This file structure describes an open file/directory for a given process.
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.
230 * It cannot exist a file structure without an inode structure.
231 * As the fd_array (containing extended pointers on the open file descriptors)
232 * is replicated in all process descriptors, we need a references counter.
233 *****************************************************************************************/
234
235typedef enum
236{
237    VFS_SEEK_SET,
238    VFS_SEEK_CUR,
239    VFS_SEEK_END,
240}
241vfs_lseek_cmd_t;
242
243typedef enum
244{
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                          */
251}
252vfs_file_attr_t;
253
254typedef struct vfs_file_s
255{
256        struct vfs_ctx_s      * ctx;        /*! local pointer on FS context.                 */
257        uint32_t                gc;         /*! generation counter                           */
258        vfs_file_attr_t         attr;       /*! file attributes bit vector (see above)       */
259        vfs_inode_type_t        type;       /*! same type as inode                           */
260        uint32_t                offset;     /*! seek position in file                        */
261        uint32_t                refcount;   /*! all pointers on this file descriptor         */
262        remote_rwlock_t         lock;       /*! protect offset modifications                 */
263        struct mapper_s       * mapper;     /*! associated file cache                        */
264        struct vfs_inode_s    * inode;      /*! local pointer on associated inode            */
265        void                  * extend;     /*! FS specific extension                        */
266}
267vfs_file_t;
268
269/******************************************************************************************
270 * This structure define the informations associated to a file descriptor,
271 * returned to user space by the stat() system call.
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
292/*********************************************************************************************
293 * This structure defines the information associated to a directory entry,
294 * returned to user space by the readdir() system call.
295 ********************************************************************************************/
296
297typedef struct vfs_dirent_s
298{
299    uint32_t    inum;                               /*! inode identifier                    */
300    uint32_t    type;                               /*! inode type                          */
301    char        name[CONFIG_VFS_MAX_NAME_LENGTH];   /*! dentry name                         */
302}
303vfs_dirent_t;
304
305
306
307/*****************************************************************************************/
308/******************** VFS global functions ***********************************************/
309/*****************************************************************************************/ 
310
311
312/******************************************************************************************
313 * This function mount a given file system type for a given process TODO.     
314 *****************************************************************************************/
315error_t vfs_mount_fs_root( struct device_s  * device,
316                                       uint32_t           fs_type,
317                                       struct process_s * process );
318
319
320/*****************************************************************************************/
321/******************* VFS Context related functions ****************************************/
322/*****************************************************************************************/
323
324/******************************************************************************************
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/******************************************************************************************
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).
378 * @ fs_type    : file system type.
379 * @ inode_type : inode type.
380 * @ extend     : local pointer on vs_type_specific extension.
381 * @ attr       : inode attributes.
382 * @ rights     : inode access rights.
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 *****************************************************************************************/
388error_t vfs_inode_create( xptr_t            dentry_xp,
389                          vfs_fs_type_t     fs_type,
390                          vfs_inode_type_t  inode_type,
391                          void            * extend,
392                          uint32_t          attr,
393                          uint32_t          rights,
394                          uid_t             uid,
395                          gid_t             gid,
396                          xptr_t          * inode_xp );
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
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
426/******************************************************************************************
427 * This function atomically increment/decrement the inode refcount.
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 *****************************************************************************************/
458void vfs_inode_lock( xptr_t inode_xp );
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 *****************************************************************************************/
466void vfs_inode_unlock( xptr_t inode_xp );
467
468/******************************************************************************************
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.
473 *****************************************************************************************/
474xptr_t vfs_inode_owner( xptr_t inode_xp );
475
476/******************************************************************************************
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/******************************************************************************************
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 ******************************************************************************************
535 * @ fs_type    : file system type.
536 * @ name       : directory entry file/dir name.
537 * @ parent     : local pointer on parent inode.
538 * @ dentry_xp  : [out] buffer for extended pointer on created dentry.
539 * @ return 0 if success / return ENOMEM or EINVAL if error.
540 *****************************************************************************************/
541error_t vfs_dentry_create( vfs_fs_type_t   fs_type,
542                           char          * name,
543                           vfs_inode_t   * parent,
544                           xptr_t        * dentry_xp );
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/******************************************************************************************
558 * These functions atomically increment/decrement the dentry refcount.
559 * It can be called by any thread running in any cluster.
560 *****************************************************************************************/
561void vfs_dentry_remote_up( xptr_t dentry_xp );
562void vfs_dentry_remote_down( xptr_t dentry_xp );
563
564
565/*****************************************************************************************/
566/************************ File descriptor related functions ******************************/
567/*****************************************************************************************/
568
569/******************************************************************************************
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.
579 *****************************************************************************************/
580error_t vfs_file_create( vfs_inode_t * inode,
581                         uint32_t      attr,
582                         xptr_t      * file_xp ); 
583
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 ); 
594
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
604/*****************************************************************************************/
605/******************* Inode-Tree related functions ****************************************/ 
606/*****************************************************************************************/ 
607
608/******************************************************************************************
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/******************************************************************************************
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
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.
640 ******************************************************************************************
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).
644 * @ inode_xp    : [out] buffer for extended pointer on searched inode.
645 * @ return 0 if success / ENOENT if inode not found , EACCES if permissopn denied,
646 *                        EAGAIN if a new complete lookup must be made
647 *****************************************************************************************/
648error_t vfs_lookup( xptr_t             cwd_xp,
649                    char             * pathname,
650                    uint32_t           lookup_mode,
651                                        xptr_t           * inode_xp );
652
653/******************************************************************************************
654 * This function creates a new couple dentry/inode, and insert it in the Inode-Tree.
655 * It can be executed by any thread running in any cluster, as this function
656 * uses the rpc_dentry_create_client() and rpc_inode_create client() if required.
657 * This is done in three steps:
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.
662 * 3) The "child_xp" field in created dentry (pointing on the created inode) is updated.
663 ******************************************************************************************
664 * @ child_cxy  : target cluster for child inode.
665 * @ inode_type : new inode type
666 * @ fs_type    : new inode FS type.
667 * @ parent_xp  : extended pointer on parent inode.
668 * @ name       : new directory entry name.
669 * @ extend     : fs_type_specific inode extension.
670 * @ child_xp   : [out] buffer for extended pointer on child inode.
671 * @ return 0 if success / ENOMEM if dentry or inode cannot be created.
672 *****************************************************************************************/
673error_t vfs_add_child_in_parent( cxy_t              child_cxy,
674                                 vfs_inode_type_t   inode_type,
675                                 vfs_fs_type_t      fs_type,
676                                 xptr_t             parent_xp,
677                                 char             * name,   
678                                 void             * extend,
679                                 xptr_t           * child_xp );
680
681/******************************************************************************************
682 * This function removes a couple dentry/inode from the Inode-Tree, and remove it from
683 * the external device.
684 * TODO                   
685 ******************************************************************************************
686 * @ child_xp   : extended pointer on removed inode.
687 *****************************************************************************************/
688error_t vfs_remove_child_from_parent( xptr_t child_xp );
689
690/******************************************************************************************
691 * This recursive function diplays a complete inode/dentry sub-tree.
692 * Any inode can be selected as the sub-tree root.
693 * TODO this function is not protected against a concurrent inode/dentry removal...
694 ******************************************************************************************
695 * @ inode_xp   : extended pointer on sub-tree root inode.
696 *****************************************************************************************/
697void vfs_display( xptr_t   inode_xp );
698
699
700
701
702
703/*****************************************************************************************/
704/****************** File access API ******************************************************/
705/*****************************************************************************************/
706
707/******************************************************************************************
708 * This function allocates a vfs_file_t structure in the cluster containing the inode
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.
712 * The pathname can be relative to current directory or absolute.
713 * If the inode does not exist in the inode cache, it try to find the file on the mounted
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 ******************************************************************************************
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.
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,
729                  uint32_t   mode,
730                          xptr_t   * file_xp,
731                          uint32_t * file_id );
732
733/******************************************************************************************
734 * This function moves <size> bytes between the file identified by the open file descriptor
735 * <file_xp> and a local kernel or user <buffer>, as defined by the <is_user> argument,
736 * and taken into account the offset in <file_xp>.
737 * The transfer direction is defined by the <to_buffer> argument.
738 ******************************************************************************************
739 * @ to_buffer : mapper -> buffer if true / buffer -> mapper if false.
740 * @ is_user   : user space buffer if true / local kernel buffer if false.
741 * @ file_xp   : extended pointer on the remote file descriptor.
742 * @ buffer    : local pointer on buffer.
743 * @ size      : requested number of bytes from offset.
744 * @ returns number of bytes actually transfered / -1 if error.
745 *****************************************************************************************/
746error_t vfs_move( bool_t   to_buffer,
747                  bool_t   is_user,
748                  xptr_t   file_xp, 
749                  void   * buffer,
750                  uint32_t size );
751
752/******************************************************************************************
753 * This function set a new value in the offset of the open file descriptor <file_xp>.
754 * This value depends on the <whence> argument:
755 * - if VFS_SEEK_SET, new value is <offset>
756 * - if VFS_SEEK_CUR, new value is current_offset + <offset>
757 * - if VFS_SEEK_END, new value is file_size + <offset>
758 ******************************************************************************************
759 * @ file_xp   : extended pointer on the remote open file descriptor.
760 * @ offset    : local pointer on source kernel buffer.
761 * @ whence    : VFS_SEEK_SET / VFS_SEEK_CUR / VFS_SEEK_END.
762 * @ new_offset : [out] buffer for new offset value.
763 * @ returns 0 if success / -1 if error.
764 *****************************************************************************************/
765error_t vfs_lseek( xptr_t     file_xp,
766                   uint32_t   offset,
767                   uint32_t   whence, 
768                   uint32_t * new_offset );
769
770/******************************************************************************************
771 * This function close an open file descriptor:
772 * 1) All entries in fd_array copies are directly cancelled by the calling thread,
773 *    using remote accesses.
774 * 2) The memory allocated to file descriptor in cluster containing the inode is released.
775 *    It requires a RPC if cluster containing the file descriptor is remote.
776 ******************************************************************************************
777 * @ file_xp     : extended pointer on the file descriptor.
778 * @ file_id     : file descriptor index in fd_array.
779 * @ returns 0 if success / -1 if error.
780 *****************************************************************************************/
781error_t vfs_close( xptr_t    file_xp,
782                   uint32_t  file_id );
783
784/******************************************************************************************
785 * This function remove from the file system a directory entry identified by the
786 * <cwd_xp> & <path> arguments.
787 ******************************************************************************************
788 * @ cwd_xp   : extended pointer on the current working directory file descriptor.
789 * @ path     : pathname (absolute or relative to current directory).
790 * @ returns 0 if success / -1 if error.
791 *****************************************************************************************/
792error_t vfs_unlink( xptr_t   cwd_xp,
793                    char   * path );
794
795/******************************************************************************************
796 * This function returns, in the structure pointed by the <k_stat> kernel pointer,
797 * various informations on the file descriptor identified by the <file_xp> argument.
798 * TODO not implemented yet...
799 ******************************************************************************************
800 * @ file_xp    : extended pointer on the file descriptor of the searched directory .
801 * @ k_dirent   : local pointer on the dirent_t structure in kernel space.
802 * @ returns 0 if success / -1 if error.
803 *****************************************************************************************/
804error_t vfs_stat( xptr_t       file_xp,
805                  vfs_stat_t * k_stat );
806
807/******************************************************************************************
808 * This function returns, in the structure pointed by the <k_dirent> kernel pointer,
809 * various infos on the directory entry currently pointed by the <file_xp> file descriptor.
810 * TODO not implemented yet...
811 ******************************************************************************************
812 * @ file_xp    : extended pointer on the file descriptor of the searched directory .
813 * @ k_dirent   : local pointer on the dirent_t structure in kernel space.
814 * @ returns 0 if success / -1 if error.
815 *****************************************************************************************/
816error_t vfs_readdir( xptr_t         file_xp,
817                     vfs_dirent_t * k_dirent );
818
819/******************************************************************************************
820 * This function  creates a new inode and associated dentry  for the directory defined
821 * by the <cwd_xp> & <path> arguments.
822 * TODO not implemented yet...
823 ******************************************************************************************
824 * @ cwd_xp   : extended pointer on the current working directory file descriptor.
825 * @ path     : pathname (absolute or relative to current directory).                     
826 * @ mode     : access rights (as defined by chmod)
827 * @ returns 0 if success / -1 if error.
828 *****************************************************************************************/
829error_t vfs_mkdir( xptr_t     cwd_xp,
830                   char     * path,
831                   uint32_t   mode );
832
833/******************************************************************************************
834 * This function remove a directory identified by the <cwd_xp / path> arguments
835 * from the file system.
836 * TODO not implemented yet...
837 ******************************************************************************************
838 * @ cwd_xp   : extended pointer on the current working directory file descriptor.
839 * @ path     : pathname (absolute or relative to current directory).                     
840 * @ returns 0 if success / -1 if error.
841 *****************************************************************************************/
842error_t vfs_rmdir( xptr_t   cwd_xp,
843                   char   * path );
844
845/******************************************************************************************
846 * This function makes the directory identified by <cwd_xp / path> arguments to become
847 * the working directory for the calling process.
848 ******************************************************************************************
849 * @ cwd_xp      : extended pointer on current directory file descriptor (relative path).
850 * @ path        : file pathname (absolute or relative to current directory).
851 * return 0 if success / -1 if error.
852 *****************************************************************************************/
853error_t vfs_chdir( xptr_t   cwd_xp,
854                   char   * path );
855
856/******************************************************************************************
857 * This function change the access rigths for the file identified by the <cwd_xp / path>
858 * arguments. The new access rights are defined by the <mode> argument value.
859 ******************************************************************************************
860 * @ cwd_xp      : extended pointer on current directory file descriptor (relative path).
861 * @ path        : file pathname (absolute or relative to current directory).
862 * @ mode        : access rights new value.
863 * return 0 if success / -1 if error.
864 *****************************************************************************************/
865error_t vfs_chmod( xptr_t        cwd_xp,
866                   char        * path,
867                   uint32_t      mode );
868
869/******************************************************************************************
870 * This function creates a named FIFO file.
871 * TODO not implemented yet                                                         
872 ******************************************************************************************
873 * @ path        : FIFO pathname (absolute or relative to current directory).
874 * @ cwd_xp      : extended pointer on the current working directory file descriptor.
875 * @ mode        : access rights new value.
876 *****************************************************************************************/
877error_t vfs_mkfifo( xptr_t       cwd_xp,
878                    char       * path,
879                    uint32_t     mode );
880
881
882/*****************************************************************************************/
883/****************** Mapper access API ****************************************************/
884/*****************************************************************************************/
885
886/******************************************************************************************
887 * This function makes an I/O operation to move one page to/from device from/to the mapper.
888 * It is used in case of MISS on the mapper, or when a dirty page in the mapper must
889 * be updated in the File System.
890 * Depending on the file system type, it calls the proper, FS specific function.
891 * It must be executed by a thread running in the cluster containing the mapper.
892 * The mapper pointer is obtained from the page descriptor.
893 * It takes the mapper lock before launching the IO operation.
894 ******************************************************************************************
895 * @ page      : local pointer on the page descriptor.
896 * @ to_mapper : transfer direction.
897 * @ returns 0 if success / return EINVAL if it cannot access the external device.
898 *****************************************************************************************/
899error_t vfs_mapper_move_page( struct page_s * page,
900                              bool_t          to_mapper );
901
902/******************************************************************************************
903 * This function makes I/O operations to move, from device to mapper, all pages covering
904 * a given inode, identified by the <inode> argument. Inode be a directory or a file,
905 * but this function is mainly used to load (prefetch) a complete directory to the mapper.
906 * Depending on the file system type, it calls the proper, FS specific function.
907 * It must be executed by a thread running in the cluster containing the mapper.
908 * The mapper pointer is obtained from the inode descriptor.
909 * It takes the mapper lock before launching the IO operation.
910 ******************************************************************************************
911 * @ inode  : local pointer on inode.
912 * @ return 0 if success / return EIO if device access failure.
913 *****************************************************************************************/
914error_t vfs_mapper_load_all( vfs_inode_t * inode );
915
916
917
918/* deprecated [AG]
919
920typedef error_t (lookup_inode_t)  ( vfs_inode_t  * parent ,
921                                    vfs_dentry_t * dentry );
922
923typedef error_t (write_inode_t)   ( vfs_inode_t  * inode );
924
925typedef error_t (release_inode_t) ( vfs_inode_t  * inode );
926
927typedef error_t (unlink_inode_t)  ( vfs_inode_t  * parent,
928                                    vfs_dentry_t * dentry,
929                                    uint32_t       flags );
930
931typedef error_t (stat_inode_t)    ( vfs_inode_t  * inode );
932
933typedef error_t (trunc_inode_t)   ( vfs_inode_t  * inode );
934
935typedef error_t (delete_inode_t)  ( vfs_inode_t  * inode );
936
937typedef struct vfs_inode_op_s
938{
939        init_inode_t    * init;   
940        create_inode_t  * create; 
941        lookup_inode_t  * lookup; 
942        write_inode_t   * write;
943        release_inode_t * release;
944        unlink_inode_t  * unlink;
945        delete_inode_t  * delete;
946        stat_inode_t    * stat;
947        trunc_inode_t   * trunc;    // change the size of a file
948}
949vfs_inode_op_t;
950
951 ******************************************************************************************
952 * These typedef define the set of FS specific operations on a VFS DENTRY descriptor.
953 * They must be implemented by any specific file system to be supported by ALMOS_MKH.
954 * This code is not actually used, and is only defined for documentation
955 ******************************************************************************************
956
957
958typedef error_t (vfs_compare_dentry_t) ( char * first , char * second );
959
960typedef struct vfs_dentry_op_s
961{
962        vfs_compare_dentry_t * compare;
963}
964vfs_dentry_op_t;
965
966
967 ******************************************************************************************
968 * These typedef define the set of FS specific operations on FILE descriptors
969 * They must be implemented by any specific file system to be supported by ALMOS_MKH.
970 * This code is not actually used, and is only defined for documentation
971 ******************************************************************************************
972
973
974typedef error_t (open_file_t   ) ( vfs_file_t * file,
975                                   void       * extend );
976
977typedef error_t (read_file_t   ) ( vfs_file_t * file,
978                                   char       * buffer,
979                                   uint32_t     count );
980
981typedef error_t (write_file_t  ) ( vfs_file_t * file,
982                                   char       * buffer,
983                                   uint32_t     count );
984
985typedef error_t (lseek_file_t  ) ( vfs_file_t * file );
986
987typedef error_t (close_file_t  ) ( vfs_file_t * file );
988
989typedef error_t (release_file_t) ( vfs_file_t * file );
990
991typedef error_t (read_dir_t    ) ( vfs_file_t * file );
992
993typedef error_t (mmap_file_t   ) ( vfs_file_t    * file ,
994                                   struct vseg_s * vseg );
995
996typedef error_t (munmap_file_t ) ( vfs_file_t    * file,
997                                   struct vseg_s * vseg );
998
999typedef struct vfs_file_op_s
1000{
1001        open_file_t    * open;
1002        read_file_t    * read;
1003        write_file_t   * write;
1004        lseek_file_t   * lseek;
1005        read_dir_t     * readdir;
1006        close_file_t   * close;
1007        release_file_t * release;
1008        mmap_file_t    * mmap;
1009        munmap_file_t  * munmap;
1010}
1011vfs_file_op_t;
1012
1013*/
1014
1015#endif  /* _VFS_H_ */
Note: See TracBrowser for help on using the repository browser.