| 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 |  | 
|---|
| 48 | struct vfs_inode_s; | 
|---|
| 49 | struct vfs_dentry_t; | 
|---|
| 50 | struct vfs_ctx_t; | 
|---|
| 51 | struct vfs_file_ref_s; | 
|---|
| 52 | struct vfs_file_s; | 
|---|
| 53 |  | 
|---|
| 54 | struct vfs_inode_op_s; | 
|---|
| 55 | struct vfs_dentry_op_s; | 
|---|
| 56 | struct vfs_file_op_s; | 
|---|
| 57 | struct vfs_ctx_op_s; | 
|---|
| 58 |  | 
|---|
| 59 | struct vfs_lookup_cmd_s; | 
|---|
| 60 | struct vfs_lookup_rsp_s; | 
|---|
| 61 |  | 
|---|
| 62 | struct mapper_s; | 
|---|
| 63 | struct process_s; | 
|---|
| 64 | struct device_s; | 
|---|
| 65 | struct vseg_s; | 
|---|
| 66 | struct 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 |  | 
|---|
| 113 | typedef enum | 
|---|
| 114 | { | 
|---|
| 115 | FS_TYPE_DEVFS = 0, | 
|---|
| 116 | FS_TYPE_FATFS = 1, | 
|---|
| 117 | FS_TYPE_RAMFS = 2, | 
|---|
| 118 |  | 
|---|
| 119 | FS_TYPES_NR   = 3, | 
|---|
| 120 | } | 
|---|
| 121 | vfs_fs_type_t; | 
|---|
| 122 |  | 
|---|
| 123 | typedef enum | 
|---|
| 124 | { | 
|---|
| 125 | CTX_ATTR_READ_ONLY    = 0x01,            /*! write access prohibited                 */ | 
|---|
| 126 | CTX_ATTR_SYNC         = 0x10,            /*! synchronise FS on each write            */ | 
|---|
| 127 | } | 
|---|
| 128 | vfs_ctx_attr_t; | 
|---|
| 129 |  | 
|---|
| 130 | typedef 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 | } | 
|---|
| 141 | vfs_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 |  | 
|---|
| 160 | typedef 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 | } | 
|---|
| 170 | vfs_inode_type_t; | 
|---|
| 171 |  | 
|---|
| 172 | /* this enum define the VFS inode attributes values */ | 
|---|
| 173 |  | 
|---|
| 174 | typedef 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 | } | 
|---|
| 180 | vfs_inode_attr_t; | 
|---|
| 181 |  | 
|---|
| 182 | typedef 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 | } | 
|---|
| 204 | vfs_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 |  | 
|---|
| 213 | typedef 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 | } | 
|---|
| 224 | vfs_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 | * Aa the fd_array (containing extended pointers on the open file descriptors)* is replicated in all process descriptors, we need a references counter. | 
|---|
| 232 | * is replicated in all process descriptors, we need a references counter. | 
|---|
| 233 | *****************************************************************************************/ | 
|---|
| 234 |  | 
|---|
| 235 | typedef enum | 
|---|
| 236 | { | 
|---|
| 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                          */ | 
|---|
| 243 | } | 
|---|
| 244 | vfs_file_attr_t; | 
|---|
| 245 |  | 
|---|
| 246 | typedef struct vfs_file_s | 
|---|
| 247 | { | 
|---|
| 248 | struct vfs_ctx_s      * ctx;        /*! local pointer on FS context.                 */ | 
|---|
| 249 | uint32_t                gc;         /*! generation counter                           */ | 
|---|
| 250 | vfs_file_attr_t         attr;       /*! file attributes bit vector (see above)       */ | 
|---|
| 251 | vfs_inode_type_t        type;       /*! same type as inode                           */ | 
|---|
| 252 | uint32_t                offset;     /*! seek position in file                        */ | 
|---|
| 253 | uint32_t                refcount;   /*! all pointers on this file descriptor         */ | 
|---|
| 254 | remote_rwlock_t         lock;       /*! protect offset modifications                 */ | 
|---|
| 255 | struct mapper_s       * mapper;     /*! associated file cache                        */ | 
|---|
| 256 | struct vfs_inode_s    * inode;      /*! local pointer on associated inode            */ | 
|---|
| 257 | void                  * extend;     /*! FS specific extension                        */ | 
|---|
| 258 | } | 
|---|
| 259 | vfs_file_t; | 
|---|
| 260 |  | 
|---|
| 261 | /****************************************************************************************** | 
|---|
| 262 | * This structure define the informations associated to a file descriptor, | 
|---|
| 263 | * returned to user space by the stat() system call. | 
|---|
| 264 | *****************************************************************************************/ | 
|---|
| 265 |  | 
|---|
| 266 | typedef 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 | } | 
|---|
| 282 | vfs_stat_t; | 
|---|
| 283 |  | 
|---|
| 284 | /********************************************************************************************* | 
|---|
| 285 | * This structure defines the information associated to a directory entry, | 
|---|
| 286 | * returned to user space by the readdir() system call. | 
|---|
| 287 | ********************************************************************************************/ | 
|---|
| 288 |  | 
|---|
| 289 | typedef struct vfs_dirent_s | 
|---|
| 290 | { | 
|---|
| 291 | uint32_t    inum;                               /*! inode identifier                    */ | 
|---|
| 292 | uint32_t    type;                               /*! inode type                          */ | 
|---|
| 293 | char        name[CONFIG_VFS_MAX_NAME_LENGTH];   /*! dentry name                         */ | 
|---|
| 294 | } | 
|---|
| 295 | vfs_dirent_t; | 
|---|
| 296 |  | 
|---|
| 297 |  | 
|---|
| 298 |  | 
|---|
| 299 | /*****************************************************************************************/ | 
|---|
| 300 | /******************** VFS global functions ***********************************************/ | 
|---|
| 301 | /*****************************************************************************************/ | 
|---|
| 302 |  | 
|---|
| 303 |  | 
|---|
| 304 | /****************************************************************************************** | 
|---|
| 305 | * This function mount a given file system type for a given process TODO. | 
|---|
| 306 | *****************************************************************************************/ | 
|---|
| 307 | error_t vfs_mount_fs_root( struct device_s  * device, | 
|---|
| 308 | uint32_t           fs_type, | 
|---|
| 309 | struct process_s * process ); | 
|---|
| 310 |  | 
|---|
| 311 |  | 
|---|
| 312 | /*****************************************************************************************/ | 
|---|
| 313 | /******************* VFS Context related functions ****************************************/ | 
|---|
| 314 | /*****************************************************************************************/ | 
|---|
| 315 |  | 
|---|
| 316 | /****************************************************************************************** | 
|---|
| 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 | *****************************************************************************************/ | 
|---|
| 326 | void 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 | /****************************************************************************************** | 
|---|
| 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 | *****************************************************************************************/ | 
|---|
| 343 | error_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 | *****************************************************************************************/ | 
|---|
| 352 | void 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). | 
|---|
| 370 | * @ fs_type    : file system type. | 
|---|
| 371 | * @ inode_type : inode type. | 
|---|
| 372 | * @ extend     : local pointer on vs_type_specific extension. | 
|---|
| 373 | * @ attr       : inode attributes. | 
|---|
| 374 | * @ rights     : inode access rights. | 
|---|
| 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 | *****************************************************************************************/ | 
|---|
| 380 | error_t vfs_inode_create( xptr_t            dentry_xp, | 
|---|
| 381 | vfs_fs_type_t     fs_type, | 
|---|
| 382 | vfs_inode_type_t  inode_type, | 
|---|
| 383 | void            * extend, | 
|---|
| 384 | uint32_t          attr, | 
|---|
| 385 | uint32_t          rights, | 
|---|
| 386 | uid_t             uid, | 
|---|
| 387 | gid_t             gid, | 
|---|
| 388 | xptr_t          * inode_xp ); | 
|---|
| 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 | *****************************************************************************************/ | 
|---|
| 399 | void vfs_inode_destroy( vfs_inode_t *  inode ); | 
|---|
| 400 |  | 
|---|
| 401 | /****************************************************************************************** | 
|---|
| 402 | * This function atomically increment/decrement the inode refcount. | 
|---|
| 403 | * It can be called by any thread running in any cluster. | 
|---|
| 404 | *****************************************************************************************/ | 
|---|
| 405 | void vfs_inode_remote_up( xptr_t  inode_xp ); | 
|---|
| 406 | void 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 | *****************************************************************************************/ | 
|---|
| 415 | uint32_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 | *****************************************************************************************/ | 
|---|
| 424 | void 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 | *****************************************************************************************/ | 
|---|
| 433 | void vfs_inode_lock( xptr_t inode_xp ); | 
|---|
| 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 | *****************************************************************************************/ | 
|---|
| 441 | void vfs_inode_unlock( xptr_t inode_xp ); | 
|---|
| 442 |  | 
|---|
| 443 | /****************************************************************************************** | 
|---|
| 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. | 
|---|
| 448 | *****************************************************************************************/ | 
|---|
| 449 | xptr_t vfs_inode_owner( xptr_t inode_xp ); | 
|---|
| 450 |  | 
|---|
| 451 | /****************************************************************************************** | 
|---|
| 452 | * This function TODO | 
|---|
| 453 | *****************************************************************************************/ | 
|---|
| 454 | error_t vfs_inode_trunc( vfs_inode_t * inode ); | 
|---|
| 455 |  | 
|---|
| 456 | /****************************************************************************************** | 
|---|
| 457 | * This function TODO | 
|---|
| 458 | *****************************************************************************************/ | 
|---|
| 459 | error_t vfs_inode_link( vfs_inode_t * inode, | 
|---|
| 460 | uint32_t      igc ); | 
|---|
| 461 |  | 
|---|
| 462 | /****************************************************************************************** | 
|---|
| 463 | * This function TODO | 
|---|
| 464 | *****************************************************************************************/ | 
|---|
| 465 | error_t vfs_inode_unlink( vfs_inode_t * inode ); | 
|---|
| 466 |  | 
|---|
| 467 | /****************************************************************************************** | 
|---|
| 468 | * This function TODO | 
|---|
| 469 | *****************************************************************************************/ | 
|---|
| 470 | error_t vfs_inode_stat( vfs_inode_t * inode, | 
|---|
| 471 | uint32_t      inum ); | 
|---|
| 472 |  | 
|---|
| 473 | /****************************************************************************************** | 
|---|
| 474 | * This function TODO | 
|---|
| 475 | *****************************************************************************************/ | 
|---|
| 476 | error_t vfs_icache_del( vfs_inode_t * inode ); | 
|---|
| 477 |  | 
|---|
| 478 |  | 
|---|
| 479 | /****************************************************************************************** | 
|---|
| 480 | * This function TODO  Pourquoi 2 arguments ? | 
|---|
| 481 | *****************************************************************************************/ | 
|---|
| 482 | error_t vfs_stat_inode( vfs_inode_t * inode, | 
|---|
| 483 | uint32_t      inum ); | 
|---|
| 484 |  | 
|---|
| 485 |  | 
|---|
| 486 | /*****************************************************************************************/ | 
|---|
| 487 | /***************** Dentry related functions **********************************************/ | 
|---|
| 488 | /*****************************************************************************************/ | 
|---|
| 489 |  | 
|---|
| 490 | /****************************************************************************************** | 
|---|
| 491 | * This function allocates memory from local cluster for a dentry descriptor, | 
|---|
| 492 | * initialises it from  arguments values, and returns the extended pointer on dentry. | 
|---|
| 493 | * The inode field is not initialized, because the inode does not exist yet. | 
|---|
| 494 | * If the client thread is not running in the target cluster for this inode, | 
|---|
| 495 | * it must use the rpc_dentry_create_client() function. | 
|---|
| 496 | ****************************************************************************************** | 
|---|
| 497 | * @ fs_type    : file system type. | 
|---|
| 498 | * @ name       : directory entry file/dir name. | 
|---|
| 499 | * @ parent     : local pointer on parent inode. | 
|---|
| 500 | * @ dentry_xp  : [out] buffer for extended pointer on created dentry. | 
|---|
| 501 | * @ return 0 if success / return ENOMEM or EINVAL if error. | 
|---|
| 502 | *****************************************************************************************/ | 
|---|
| 503 | error_t vfs_dentry_create( vfs_fs_type_t   fs_type, | 
|---|
| 504 | char          * name, | 
|---|
| 505 | vfs_inode_t   * parent, | 
|---|
| 506 | xptr_t        * dentry_xp ); | 
|---|
| 507 |  | 
|---|
| 508 | /****************************************************************************************** | 
|---|
| 509 | * This function releases memory allocated to a dentry descriptor. | 
|---|
| 510 | * It must be executed by a thread running in the cluster containing the dentry, | 
|---|
| 511 | * and the dentry refcount must be zero. | 
|---|
| 512 | * If the client thread is not running in the owner cluster, it must use the | 
|---|
| 513 | * rpc_dentry_destroy_client() function. | 
|---|
| 514 | ****************************************************************************************** | 
|---|
| 515 | * @ dentry  : local pointer on dentry descriptor. | 
|---|
| 516 | *****************************************************************************************/ | 
|---|
| 517 | void vfs_dentry_destroy( vfs_dentry_t *  dentry ); | 
|---|
| 518 |  | 
|---|
| 519 | /****************************************************************************************** | 
|---|
| 520 | * These functions atomically increment/decrement the dentry refcount. | 
|---|
| 521 | * It can be called by any thread running in any cluster. | 
|---|
| 522 | *****************************************************************************************/ | 
|---|
| 523 | void vfs_dentry_remote_up( xptr_t dentry_xp ); | 
|---|
| 524 | void vfs_dentry_remote_down( xptr_t dentry_xp ); | 
|---|
| 525 |  | 
|---|
| 526 |  | 
|---|
| 527 | /*****************************************************************************************/ | 
|---|
| 528 | /************************ File descriptor related functions ******************************/ | 
|---|
| 529 | /*****************************************************************************************/ | 
|---|
| 530 |  | 
|---|
| 531 | /****************************************************************************************** | 
|---|
| 532 | * This function allocates memory and initializes a new local file descriptor. | 
|---|
| 533 | * It must be executed in the cluster containing the inode. | 
|---|
| 534 | * If the client thread is not running in the owner cluster, it must use the | 
|---|
| 535 | * rpc_vfs_file_create_client() function. | 
|---|
| 536 | ****************************************************************************************** | 
|---|
| 537 | * @ inode    : local pointer on associated inode. | 
|---|
| 538 | * @ attr     : file descriptor attributes. | 
|---|
| 539 | * @ file_xp  : [out] buffer for extended pointer on created file descriptor. | 
|---|
| 540 | * @ return 0 if success / return ENOMEM if error. | 
|---|
| 541 | *****************************************************************************************/ | 
|---|
| 542 | error_t vfs_file_create( vfs_inode_t * inode, | 
|---|
| 543 | uint32_t      attr, | 
|---|
| 544 | xptr_t      * file_xp ); | 
|---|
| 545 |  | 
|---|
| 546 | /****************************************************************************************** | 
|---|
| 547 | * This function releases memory allocated to a local file descriptor. | 
|---|
| 548 | * It must be executed by a thread running in the cluster containing the inode, | 
|---|
| 549 | * and the file refcount must be zero. | 
|---|
| 550 | * If the client thread is not running in the owner cluster, it must use the | 
|---|
| 551 | * rpc_vfs_file_destroy_client() function. | 
|---|
| 552 | ****************************************************************************************** | 
|---|
| 553 | * @ file  : local pointer on file descriptor. | 
|---|
| 554 | *****************************************************************************************/ | 
|---|
| 555 | void vfs_file_destroy( vfs_file_t *  file ); | 
|---|
| 556 |  | 
|---|
| 557 | /****************************************************************************************** | 
|---|
| 558 | * These functions increment (resp. decrement) the count field in a remote file | 
|---|
| 559 | * descriptor, using a remote_atomic access. | 
|---|
| 560 | *****************************************************************************************/ | 
|---|
| 561 | void vfs_file_count_up  ( xptr_t   file_xp ); | 
|---|
| 562 | void vfs_file_count_down( xptr_t   file_xp ); | 
|---|
| 563 |  | 
|---|
| 564 |  | 
|---|
| 565 |  | 
|---|
| 566 | /*****************************************************************************************/ | 
|---|
| 567 | /******************* Inode-Tree related functions ****************************************/ | 
|---|
| 568 | /*****************************************************************************************/ | 
|---|
| 569 |  | 
|---|
| 570 | /****************************************************************************************** | 
|---|
| 571 | * This function randomly selects a cluster for a new inode. | 
|---|
| 572 | ****************************************************************************************** | 
|---|
| 573 | * @ returns the selected cluster identifier. | 
|---|
| 574 | *****************************************************************************************/ | 
|---|
| 575 | cxy_t vfs_cluster_random_select(); | 
|---|
| 576 |  | 
|---|
| 577 | /****************************************************************************************** | 
|---|
| 578 | * This function returns in a kernel buffer allocated by the caller function, | 
|---|
| 579 | * the pathname of a file/dir identified by an extended pointer on the inode. | 
|---|
| 580 | * It traverse the Inode Tree from the target node to the root. | 
|---|
| 581 | * It can be called by any thread running in any cluster. | 
|---|
| 582 | ****************************************************************************************** | 
|---|
| 583 | * @ inode_xp    : pointer on inode descriptor. | 
|---|
| 584 | * @ buffer      : kernel buffer for pathname (must be allocated by caller). | 
|---|
| 585 | * @ size        : max number of characters in buffer. | 
|---|
| 586 | * @ return 0 if success / return EINVAL if buffer too small. | 
|---|
| 587 | *****************************************************************************************/ | 
|---|
| 588 | error_t vfs_get_path( xptr_t    inode_xp, | 
|---|
| 589 | char    * buffer, | 
|---|
| 590 | uint32_t  max_size ); | 
|---|
| 591 |  | 
|---|
| 592 | /****************************************************************************************** | 
|---|
| 593 | * This function takes a pathname (absolute or relative to cwd) and returns an extended | 
|---|
| 594 | * pointer on the associated inode. | 
|---|
| 595 | * - If a given name in the path is not found in the inode tree, it try to load the missing | 
|---|
| 596 | *   dentry/inode couple, from informations found in the parent directory. | 
|---|
| 597 | * - If this directory entry does not exist on device, it returns an error. | 
|---|
| 598 | * - If the the file identified by the pathname does not exist on device but the | 
|---|
| 599 | *   flag CREATE is set, the inode is created. | 
|---|
| 600 | * - If the the file identified by the pathname exist on device but both flags EXCL | 
|---|
| 601 | *   and CREATE are set, an error is returned. | 
|---|
| 602 | ****************************************************************************************** | 
|---|
| 603 | * @ cwd_xp      : extended pointer on current directory (for relative path). | 
|---|
| 604 | * @ pathname    : path in kernel space (can be relative or absolute). | 
|---|
| 605 | * @ lookup_mode : flags defining the working mode (defined above in this file). | 
|---|
| 606 | * @ inode_xp    : [out] buffer for extended pointer on inode. | 
|---|
| 607 | * @ return 0 if success / ENOENT if inode not found , EACCES if permissopn denied, | 
|---|
| 608 | *                        EAGAIN if a new complete lookup must be made | 
|---|
| 609 | *****************************************************************************************/ | 
|---|
| 610 | error_t vfs_lookup( xptr_t             cwd_xp, | 
|---|
| 611 | char             * pathname, | 
|---|
| 612 | uint32_t           lookup_mode, | 
|---|
| 613 | xptr_t           * inode_xp ); | 
|---|
| 614 |  | 
|---|
| 615 | /****************************************************************************************** | 
|---|
| 616 | * This function creates a new couple dentry/inode, and insert it in the Inode-Tree. | 
|---|
| 617 | * It can be executed by any thread running in any cluster, as this function | 
|---|
| 618 | * uses the rpc_dentry_create_client() and rpc_inode_create client() if required. | 
|---|
| 619 | * - The dentry is created in the cluster containing the existing <parent_xp> inode. | 
|---|
| 620 | * - the inode and its associated mapper are created in cluster identified by <child_cxy>. | 
|---|
| 621 | * - The new dentry name is defined by the <name> argument. | 
|---|
| 622 | * - The new inode and the parent inode can have different FS types. | 
|---|
| 623 | ****************************************************************************************** | 
|---|
| 624 | * @ child_cxy  : target cluster for child inode. | 
|---|
| 625 | * @ inode_type : new inode type | 
|---|
| 626 | * @ fs_type    : new inode FS type. | 
|---|
| 627 | * @ parent_xp  : extended pointer on parent inode. | 
|---|
| 628 | * @ name       : new directory entry name. | 
|---|
| 629 | * @ extend     : fs_type_specific inode extension. | 
|---|
| 630 | * @ child_xp   : [out] buffer for extended pointer on child inode. | 
|---|
| 631 | * @ return 0 if success / ENOENT if entry not found in parent directory | 
|---|
| 632 | *****************************************************************************************/ | 
|---|
| 633 | error_t vfs_add_child_in_parent( cxy_t              child_cxy, | 
|---|
| 634 | vfs_inode_type_t   inode_type, | 
|---|
| 635 | vfs_fs_type_t      fs_type, | 
|---|
| 636 | xptr_t             parent_xp, | 
|---|
| 637 | char             * name, | 
|---|
| 638 | void             * extend, | 
|---|
| 639 | xptr_t           * child_xp ); | 
|---|
| 640 |  | 
|---|
| 641 | /****************************************************************************************** | 
|---|
| 642 | * This function removes a couple dentry/inode from the Inode-Tree, and remove it from | 
|---|
| 643 | * the external device. | 
|---|
| 644 | * TODO | 
|---|
| 645 | ****************************************************************************************** | 
|---|
| 646 | * @ child_xp   : extended pointer on removed inode. | 
|---|
| 647 | *****************************************************************************************/ | 
|---|
| 648 | error_t vfs_remove_child_from_parent( xptr_t child_xp ); | 
|---|
| 649 |  | 
|---|
| 650 | /****************************************************************************************** | 
|---|
| 651 | * This recursive function diplays a complete inode/dentry sub-tree. | 
|---|
| 652 | * Any inode can be selected as the sub-tree root. | 
|---|
| 653 | * TODO this function is not ptotected against a concurrent node removal... | 
|---|
| 654 | ****************************************************************************************** | 
|---|
| 655 | * @ inode_xp   : extended pointer on sub-tree root inode. | 
|---|
| 656 | *****************************************************************************************/ | 
|---|
| 657 | void vfs_display( xptr_t   inode_xp ); | 
|---|
| 658 |  | 
|---|
| 659 |  | 
|---|
| 660 |  | 
|---|
| 661 |  | 
|---|
| 662 |  | 
|---|
| 663 | /*****************************************************************************************/ | 
|---|
| 664 | /****************** File access API ******************************************************/ | 
|---|
| 665 | /*****************************************************************************************/ | 
|---|
| 666 |  | 
|---|
| 667 | /****************************************************************************************** | 
|---|
| 668 | * This function allocates a vfs_file_t structure in the cluster containing the inode | 
|---|
| 669 | * associated to the file identified by <cwd_xp> & <path>. | 
|---|
| 670 | * It initializes it, register it in the reference process fd_array, and returns both | 
|---|
| 671 | * the extended pointer on the remote file descriptor, and the index in the fd_array. | 
|---|
| 672 | * The pathname can be relative to current directory or absolute. | 
|---|
| 673 | * If the inode does not exist in the inode cache, it try to find the file on the mounted | 
|---|
| 674 | * device, and creates an inode on a pseudo randomly selected cluster if found. | 
|---|
| 675 | * It the requested file does not exist on device, it creates a new inode if the | 
|---|
| 676 | * O_CREAT flag is set and return an error otherwise. | 
|---|
| 677 | ****************************************************************************************** | 
|---|
| 678 | * @ cwd_xp      : extended pointer on current working directory file descriptor. | 
|---|
| 679 | * @ path        : file pathname (absolute or relative to current directory). | 
|---|
| 680 | * @ flags       : defined above | 
|---|
| 681 | * @ mode        : access rights (as defined by chmod) | 
|---|
| 682 | * @ file_xp     : [out] buffer for extended pointer on created remote file descriptor. | 
|---|
| 683 | * @ file_id     : [out] buffer for created file descriptor index in reference fd_array. | 
|---|
| 684 | * @ return 0 if success / return non-zero if error. | 
|---|
| 685 | *****************************************************************************************/ | 
|---|
| 686 | error_t vfs_open( xptr_t     cwd_xp, | 
|---|
| 687 | char     * path, | 
|---|
| 688 | uint32_t   flags, | 
|---|
| 689 | uint32_t   mode, | 
|---|
| 690 | xptr_t   * file_xp, | 
|---|
| 691 | uint32_t * file_id ); | 
|---|
| 692 |  | 
|---|
| 693 | /****************************************************************************************** | 
|---|
| 694 | * This function moves <size> bytes between the file identified by the open file descriptor | 
|---|
| 695 | * <file_xp> and a local kernel <buffer> , taken into account the offset in <file_xp>. | 
|---|
| 696 | * The transfer direction is defined by the <to_buffer> argument. | 
|---|
| 697 | ****************************************************************************************** | 
|---|
| 698 | * @ to_buffer : mapper -> buffer if true / buffer->mapper if false. | 
|---|
| 699 | * @ file_xp   : extended pointer on the remote file descriptor. | 
|---|
| 700 | * @ buffer    : local pointer on local kernel buffer. | 
|---|
| 701 | * @ size      : requested number of bytes from offset. | 
|---|
| 702 | * @ returns number of bytes actually transfered / -1 if error. | 
|---|
| 703 | *****************************************************************************************/ | 
|---|
| 704 | error_t vfs_move( bool_t   to_buffer, | 
|---|
| 705 | xptr_t   file_xp, | 
|---|
| 706 | void   * buffer, | 
|---|
| 707 | uint32_t size ); | 
|---|
| 708 |  | 
|---|
| 709 | /****************************************************************************************** | 
|---|
| 710 | * This function set a new value in the offset of the open file descriptor <file_xp>. | 
|---|
| 711 | * This value depends on the <whence> argument: | 
|---|
| 712 | * - if VFS_SEEK_SET, new value is <offset> | 
|---|
| 713 | * - if VFS_SEEK_CUR, new value is current_offset + <offset> | 
|---|
| 714 | * - if VFS_SEEK_END, new value is file_size + <offset> | 
|---|
| 715 | ****************************************************************************************** | 
|---|
| 716 | * @ file_xp   : extended pointer on the remote open file descriptor. | 
|---|
| 717 | * @ offset    : local pointer on source kernel buffer. | 
|---|
| 718 | * @ whence    : VFS_SEEK_SET / VFS_SEEK_CUR / VFS_SEEK_END. | 
|---|
| 719 | * @ new_offset : [out] buffer for new offset value. | 
|---|
| 720 | * @ returns 0 if success / -1 if error. | 
|---|
| 721 | *****************************************************************************************/ | 
|---|
| 722 | error_t vfs_lseek( xptr_t     file_xp, | 
|---|
| 723 | uint32_t   offset, | 
|---|
| 724 | uint32_t   whence, | 
|---|
| 725 | uint32_t * new_offset ); | 
|---|
| 726 |  | 
|---|
| 727 | /****************************************************************************************** | 
|---|
| 728 | * This function close an open file descriptor: | 
|---|
| 729 | * 1) All entries in fd_array copies are directly cancelled by the calling thread, | 
|---|
| 730 | *    using remote accesses. | 
|---|
| 731 | * 2) The memory allocated to file descriptor in cluster containing the inode is released. | 
|---|
| 732 | *    It requires a RPC if cluster containing the file descriptor is remote. | 
|---|
| 733 | ****************************************************************************************** | 
|---|
| 734 | * @ file_xp     : extended pointer on the file descriptor. | 
|---|
| 735 | * @ file_id     : file descriptor index in fd_array. | 
|---|
| 736 | * @ returns 0 if success / -1 if error. | 
|---|
| 737 | *****************************************************************************************/ | 
|---|
| 738 | error_t vfs_close( xptr_t    file_xp, | 
|---|
| 739 | uint32_t  file_id ); | 
|---|
| 740 |  | 
|---|
| 741 | /****************************************************************************************** | 
|---|
| 742 | * This function remove from the file system a directory entry identified by the | 
|---|
| 743 | * <cwd_xp> & <path> arguments. | 
|---|
| 744 | ****************************************************************************************** | 
|---|
| 745 | * @ cwd_xp   : extended pointer on the current working directory file descriptor. | 
|---|
| 746 | * @ path     : pathname (absolute or relative to current directory). | 
|---|
| 747 | * @ returns 0 if success / -1 if error. | 
|---|
| 748 | *****************************************************************************************/ | 
|---|
| 749 | error_t vfs_unlink( xptr_t   cwd_xp, | 
|---|
| 750 | char   * path ); | 
|---|
| 751 |  | 
|---|
| 752 | /****************************************************************************************** | 
|---|
| 753 | * This function returns, in the structure pointed by the <k_stat> kernel pointer, | 
|---|
| 754 | * various informations on the file descriptor identified by the <file_xp> argument. | 
|---|
| 755 | * TODO not implemented yet... | 
|---|
| 756 | ****************************************************************************************** | 
|---|
| 757 | * @ file_xp    : extended pointer on the file descriptor of the searched directory . | 
|---|
| 758 | * @ k_dirent   : local pointer on the dirent_t structure in kernel space. | 
|---|
| 759 | * @ returns 0 if success / -1 if error. | 
|---|
| 760 | *****************************************************************************************/ | 
|---|
| 761 | error_t vfs_stat( xptr_t       file_xp, | 
|---|
| 762 | vfs_stat_t * k_stat ); | 
|---|
| 763 |  | 
|---|
| 764 | /****************************************************************************************** | 
|---|
| 765 | * This function returns, in the structure pointed by the <k_dirent> kernel pointer, | 
|---|
| 766 | * various infos on the directory entry currently pointed by the <file_xp> file descriptor. | 
|---|
| 767 | * TODO not implemented yet... | 
|---|
| 768 | ****************************************************************************************** | 
|---|
| 769 | * @ file_xp    : extended pointer on the file descriptor of the searched directory . | 
|---|
| 770 | * @ k_dirent   : local pointer on the dirent_t structure in kernel space. | 
|---|
| 771 | * @ returns 0 if success / -1 if error. | 
|---|
| 772 | *****************************************************************************************/ | 
|---|
| 773 | error_t vfs_readdir( xptr_t         file_xp, | 
|---|
| 774 | vfs_dirent_t * k_dirent ); | 
|---|
| 775 |  | 
|---|
| 776 | /****************************************************************************************** | 
|---|
| 777 | * This function  creates a new inode and associated dentry  for the directory defined | 
|---|
| 778 | * by the <cwd_xp> & <path> arguments. | 
|---|
| 779 | * TODO not implemented yet... | 
|---|
| 780 | ****************************************************************************************** | 
|---|
| 781 | * @ cwd_xp   : extended pointer on the current working directory file descriptor. | 
|---|
| 782 | * @ path     : pathname (absolute or relative to current directory). | 
|---|
| 783 | * @ mode     : access rights (as defined by chmod) | 
|---|
| 784 | * @ returns 0 if success / -1 if error. | 
|---|
| 785 | *****************************************************************************************/ | 
|---|
| 786 | error_t vfs_mkdir( xptr_t     cwd_xp, | 
|---|
| 787 | char     * path, | 
|---|
| 788 | uint32_t   mode ); | 
|---|
| 789 |  | 
|---|
| 790 | /****************************************************************************************** | 
|---|
| 791 | * This function remove a directory identified by the <cwd_xp / path> arguments | 
|---|
| 792 | * from the file system. | 
|---|
| 793 | * TODO not implemented yet... | 
|---|
| 794 | ****************************************************************************************** | 
|---|
| 795 | * @ cwd_xp   : extended pointer on the current working directory file descriptor. | 
|---|
| 796 | * @ path     : pathname (absolute or relative to current directory). | 
|---|
| 797 | * @ returns 0 if success / -1 if error. | 
|---|
| 798 | *****************************************************************************************/ | 
|---|
| 799 | error_t vfs_rmdir( xptr_t   cwd_xp, | 
|---|
| 800 | char   * path ); | 
|---|
| 801 |  | 
|---|
| 802 | /****************************************************************************************** | 
|---|
| 803 | * This function makes the directory identified by <cwd_xp / path> arguments to become | 
|---|
| 804 | * the working directory for the calling process. | 
|---|
| 805 | ****************************************************************************************** | 
|---|
| 806 | * @ cwd_xp      : extended pointer on current directory file descriptor (relative path). | 
|---|
| 807 | * @ path        : file pathname (absolute or relative to current directory). | 
|---|
| 808 | * return 0 if success / -1 if error. | 
|---|
| 809 | *****************************************************************************************/ | 
|---|
| 810 | error_t vfs_chdir( xptr_t   cwd_xp, | 
|---|
| 811 | char   * path ); | 
|---|
| 812 |  | 
|---|
| 813 | /****************************************************************************************** | 
|---|
| 814 | * This function change the access rigths for the file identified by the <cwd_xp / path> | 
|---|
| 815 | * arguments. The new access rights are defined by the <mode> argument value. | 
|---|
| 816 | ****************************************************************************************** | 
|---|
| 817 | * @ cwd_xp      : extended pointer on current directory file descriptor (relative path). | 
|---|
| 818 | * @ path        : file pathname (absolute or relative to current directory). | 
|---|
| 819 | * @ mode        : access rights new value. | 
|---|
| 820 | * return 0 if success / -1 if error. | 
|---|
| 821 | *****************************************************************************************/ | 
|---|
| 822 | error_t vfs_chmod( xptr_t        cwd_xp, | 
|---|
| 823 | char        * path, | 
|---|
| 824 | uint32_t      mode ); | 
|---|
| 825 |  | 
|---|
| 826 | /****************************************************************************************** | 
|---|
| 827 | * This function creates a named FIFO file. | 
|---|
| 828 | * TODO not implemented yet | 
|---|
| 829 | ****************************************************************************************** | 
|---|
| 830 | * @ path        : FIFO pathname (absolute or relative to current directory). | 
|---|
| 831 | * @ cwd_xp      : extended pointer on the current working directory file descriptor. | 
|---|
| 832 | * @ mode        : access rights new value. | 
|---|
| 833 | *****************************************************************************************/ | 
|---|
| 834 | error_t vfs_mkfifo( xptr_t       cwd_xp, | 
|---|
| 835 | char       * path, | 
|---|
| 836 | uint32_t     mode ); | 
|---|
| 837 |  | 
|---|
| 838 |  | 
|---|
| 839 | /*****************************************************************************************/ | 
|---|
| 840 | /****************** Mapper access API ****************************************************/ | 
|---|
| 841 | /*****************************************************************************************/ | 
|---|
| 842 |  | 
|---|
| 843 | /****************************************************************************************** | 
|---|
| 844 | * This function makes an I/O operation to move one page from VFS to a given mapper, | 
|---|
| 845 | * in case of MISS on the mapper cache. | 
|---|
| 846 | * Depending on the file system type, it calls the proper, FS specific function. | 
|---|
| 847 | * It must be executed by a thread running in the cluster containing the mapper. | 
|---|
| 848 | * The mapper pointer is obtained from the page descriptor. | 
|---|
| 849 | * It takes the mapper lock before launching the IO operation. | 
|---|
| 850 | ****************************************************************************************** | 
|---|
| 851 | * @ page   : local pointer on the page descriptor. | 
|---|
| 852 | * @ returns 0 if success / return EINVAL if it cannot access the external device. | 
|---|
| 853 | *****************************************************************************************/ | 
|---|
| 854 | error_t vfs_move_page_to_mapper( struct page_s * page ); | 
|---|
| 855 |  | 
|---|
| 856 | /****************************************************************************************** | 
|---|
| 857 | * This function makes an I/0 operation to move one page from a given mapper to VFS, | 
|---|
| 858 | * when a dirty page in the mapper cache must be updated in the File System. | 
|---|
| 859 | * Depending on the file system type, it calls the proper, FS specific function. | 
|---|
| 860 | * It must be executed by a thread running in the cluster containing the mapper. | 
|---|
| 861 | * The mapper pointer is obtained from the page descriptor. | 
|---|
| 862 | * It takes the mapper lock before launching the IO operation. | 
|---|
| 863 | * It does nothing if the page is not dirty. If the page is dirty, it clear the page | 
|---|
| 864 | * dirty bit, and remove the page from the PPM dirty list. | 
|---|
| 865 | ****************************************************************************************** | 
|---|
| 866 | * @ page   : local pointer on the page descriptor. | 
|---|
| 867 | * @ returns 0 if success / return EINVAL if it cannot access the external device. | 
|---|
| 868 | *****************************************************************************************/ | 
|---|
| 869 | error_t vfs_move_page_from_mapper( struct page_s * page ); | 
|---|
| 870 |  | 
|---|
| 871 |  | 
|---|
| 872 |  | 
|---|
| 873 |  | 
|---|
| 874 |  | 
|---|
| 875 |  | 
|---|
| 876 | /////////////////////////////////////////////////////////////////////////////////////////// | 
|---|
| 877 | // These typedef define the FS specific operations that must be implemented by any | 
|---|
| 878 | // specific file system to be supported by the ALMOS_MKH VFS. | 
|---|
| 879 | // These typedef are not actually used, and are only defined for documentation | 
|---|
| 880 | /////////////////////////////////////////////////////////////////////////////////////////// | 
|---|
| 881 |  | 
|---|
| 882 | typedef error_t (fs_init_t)          ( xptr_t vfs_root_xp ); | 
|---|
| 883 |  | 
|---|
| 884 | typedef error_t (fs_inode_extend_t)  ( struct vfs_inode_s * inode, | 
|---|
| 885 | void               * extend ); | 
|---|
| 886 |  | 
|---|
| 887 | typedef void    (fs_inode_release_t) ( struct vfs_inode_s * inode ); | 
|---|
| 888 |  | 
|---|
| 889 | typedef error_t (fs_write_page_t)    ( struct page_s * page ); | 
|---|
| 890 |  | 
|---|
| 891 | typedef error_t (fs_read_page_t)     ( struct page_s * page ); | 
|---|
| 892 |  | 
|---|
| 893 |  | 
|---|
| 894 |  | 
|---|
| 895 |  | 
|---|
| 896 |  | 
|---|
| 897 |  | 
|---|
| 898 |  | 
|---|
| 899 |  | 
|---|
| 900 | /* deprecated [AG] | 
|---|
| 901 |  | 
|---|
| 902 | typedef error_t (lookup_inode_t)  ( vfs_inode_t  * parent , | 
|---|
| 903 | vfs_dentry_t * dentry ); | 
|---|
| 904 |  | 
|---|
| 905 | typedef error_t (write_inode_t)   ( vfs_inode_t  * inode ); | 
|---|
| 906 |  | 
|---|
| 907 | typedef error_t (release_inode_t) ( vfs_inode_t  * inode ); | 
|---|
| 908 |  | 
|---|
| 909 | typedef error_t (unlink_inode_t)  ( vfs_inode_t  * parent, | 
|---|
| 910 | vfs_dentry_t * dentry, | 
|---|
| 911 | uint32_t       flags ); | 
|---|
| 912 |  | 
|---|
| 913 | typedef error_t (stat_inode_t)    ( vfs_inode_t  * inode ); | 
|---|
| 914 |  | 
|---|
| 915 | typedef error_t (trunc_inode_t)   ( vfs_inode_t  * inode ); | 
|---|
| 916 |  | 
|---|
| 917 | typedef error_t (delete_inode_t)  ( vfs_inode_t  * inode ); | 
|---|
| 918 |  | 
|---|
| 919 | typedef struct vfs_inode_op_s | 
|---|
| 920 | { | 
|---|
| 921 | init_inode_t    * init; | 
|---|
| 922 | create_inode_t  * create; | 
|---|
| 923 | lookup_inode_t  * lookup; | 
|---|
| 924 | write_inode_t   * write; | 
|---|
| 925 | release_inode_t * release; | 
|---|
| 926 | unlink_inode_t  * unlink; | 
|---|
| 927 | delete_inode_t  * delete; | 
|---|
| 928 | stat_inode_t    * stat; | 
|---|
| 929 | trunc_inode_t   * trunc;    // change the size of a file | 
|---|
| 930 | } | 
|---|
| 931 | vfs_inode_op_t; | 
|---|
| 932 |  | 
|---|
| 933 | ****************************************************************************************** | 
|---|
| 934 | * These typedef define the set of FS specific operations on a VFS DENTRY descriptor. | 
|---|
| 935 | * They must be implemented by any specific file system to be supported by ALMOS_MKH. | 
|---|
| 936 | * This code is not actually used, and is only defined for documentation | 
|---|
| 937 | ****************************************************************************************** | 
|---|
| 938 |  | 
|---|
| 939 |  | 
|---|
| 940 | typedef error_t (vfs_compare_dentry_t) ( char * first , char * second ); | 
|---|
| 941 |  | 
|---|
| 942 | typedef struct vfs_dentry_op_s | 
|---|
| 943 | { | 
|---|
| 944 | vfs_compare_dentry_t * compare; | 
|---|
| 945 | } | 
|---|
| 946 | vfs_dentry_op_t; | 
|---|
| 947 |  | 
|---|
| 948 |  | 
|---|
| 949 | ****************************************************************************************** | 
|---|
| 950 | * These typedef define the set of FS specific operations on FILE descriptors | 
|---|
| 951 | * They must be implemented by any specific file system to be supported by ALMOS_MKH. | 
|---|
| 952 | * This code is not actually used, and is only defined for documentation | 
|---|
| 953 | ****************************************************************************************** | 
|---|
| 954 |  | 
|---|
| 955 |  | 
|---|
| 956 | typedef error_t (open_file_t   ) ( vfs_file_t * file, | 
|---|
| 957 | void       * extend ); | 
|---|
| 958 |  | 
|---|
| 959 | typedef error_t (read_file_t   ) ( vfs_file_t * file, | 
|---|
| 960 | char       * buffer, | 
|---|
| 961 | uint32_t     count ); | 
|---|
| 962 |  | 
|---|
| 963 | typedef error_t (write_file_t  ) ( vfs_file_t * file, | 
|---|
| 964 | char       * buffer, | 
|---|
| 965 | uint32_t     count ); | 
|---|
| 966 |  | 
|---|
| 967 | typedef error_t (lseek_file_t  ) ( vfs_file_t * file ); | 
|---|
| 968 |  | 
|---|
| 969 | typedef error_t (close_file_t  ) ( vfs_file_t * file ); | 
|---|
| 970 |  | 
|---|
| 971 | typedef error_t (release_file_t) ( vfs_file_t * file ); | 
|---|
| 972 |  | 
|---|
| 973 | typedef error_t (read_dir_t    ) ( vfs_file_t * file ); | 
|---|
| 974 |  | 
|---|
| 975 | typedef error_t (mmap_file_t   ) ( vfs_file_t    * file , | 
|---|
| 976 | struct vseg_s * vseg ); | 
|---|
| 977 |  | 
|---|
| 978 | typedef error_t (munmap_file_t ) ( vfs_file_t    * file, | 
|---|
| 979 | struct vseg_s * vseg ); | 
|---|
| 980 |  | 
|---|
| 981 | typedef struct vfs_file_op_s | 
|---|
| 982 | { | 
|---|
| 983 | open_file_t    * open; | 
|---|
| 984 | read_file_t    * read; | 
|---|
| 985 | write_file_t   * write; | 
|---|
| 986 | lseek_file_t   * lseek; | 
|---|
| 987 | read_dir_t     * readdir; | 
|---|
| 988 | close_file_t   * close; | 
|---|
| 989 | release_file_t * release; | 
|---|
| 990 | mmap_file_t    * mmap; | 
|---|
| 991 | munmap_file_t  * munmap; | 
|---|
| 992 | } | 
|---|
| 993 | vfs_file_op_t; | 
|---|
| 994 |  | 
|---|
| 995 | */ | 
|---|
| 996 |  | 
|---|
| 997 | #endif  /* _VFS_H_ */ | 
|---|