[1] | 1 | /* |
---|
| 2 | * vfs.h - Virtual File System definition. |
---|
| 3 | * |
---|
[23] | 4 | * Author Mohamed Lamine Karaoui (2014,2015) |
---|
[437] | 5 | * Alain Greiner (2016,2017,2018) |
---|
[1] | 6 | * |
---|
| 7 | * Copyright (c) UPMC Sorbonne Universites |
---|
| 8 | * |
---|
| 9 | * This file is part of ALMOS-MKH. |
---|
| 10 | * |
---|
| 11 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
| 12 | * under the terms of the GNU General Public License as published by |
---|
| 13 | * the Free Software Foundation; version 2.0 of the License. |
---|
| 14 | * |
---|
| 15 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 18 | * General Public License for more details. |
---|
| 19 | * |
---|
| 20 | * You should have received a copy of the GNU General Public License |
---|
| 21 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
| 22 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | #ifndef _VFS_H_ |
---|
| 26 | #define _VFS_H_ |
---|
| 27 | |
---|
[14] | 28 | #include <kernel_config.h> |
---|
[457] | 29 | #include <hal_kernel_types.h> |
---|
[1] | 30 | #include <hal_atomic.h> |
---|
| 31 | #include <remote_rwlock.h> |
---|
[568] | 32 | #include <remote_busylock.h> |
---|
| 33 | #include <busylock.h> |
---|
[1] | 34 | #include <list.h> |
---|
| 35 | #include <xlist.h> |
---|
| 36 | #include <bits.h> |
---|
| 37 | #include <xhtab.h> |
---|
| 38 | #include <errno.h> |
---|
[407] | 39 | #include <shared_syscalls.h> |
---|
[1] | 40 | #include <fatfs.h> |
---|
| 41 | #include <ramfs.h> |
---|
[23] | 42 | #include <devfs.h> |
---|
[1] | 43 | |
---|
| 44 | /**** Forward declarations ***/ |
---|
| 45 | |
---|
| 46 | struct vfs_inode_s; |
---|
[611] | 47 | struct vfs_dentry_s; |
---|
| 48 | struct vfs_ctx_s; |
---|
[1] | 49 | struct vfs_file_s; |
---|
| 50 | |
---|
| 51 | struct mapper_s; |
---|
| 52 | struct process_s; |
---|
| 53 | struct device_s; |
---|
| 54 | struct vseg_s; |
---|
[23] | 55 | struct page_s; |
---|
[1] | 56 | |
---|
[23] | 57 | /****************************************************************************************** |
---|
| 58 | * These flags are used to define the working mode of the vfs_lookup() function. |
---|
| 59 | *****************************************************************************************/ |
---|
[1] | 60 | |
---|
[610] | 61 | #define VFS_LOOKUP_DIR 0x01 /* the searched inode must be a directory */ |
---|
[23] | 62 | #define VFS_LOOKUP_OPEN 0x02 /* the search is for an open/opendir */ |
---|
| 63 | #define VFS_LOOKUP_PARENT 0x04 /* return the parent inode (not the inode itself) */ |
---|
| 64 | #define VFS_LOOKUP_CREATE 0x10 /* file must be created if missing */ |
---|
[610] | 65 | #define VFS_LOOKUP_EXCL 0x20 /* file cannot previously exist */ |
---|
[1] | 66 | |
---|
[23] | 67 | /****************************************************************************************** |
---|
[568] | 68 | * This structure defines a VFS context, that contains informations common to all inodes |
---|
| 69 | * and dentries for a given file system. As it is declared as a global variable in the |
---|
[602] | 70 | * kdata segment (fs_context[] array), it is replicated in all clusters. |
---|
| 71 | * The <extend> field is a pointer on the FS specific context extension. |
---|
| 72 | * This extension is dynamically allocated by kernel_init in all clusters. |
---|
| 73 | * In each cluster, both this VFS context and the FS specific context are handled as |
---|
| 74 | * private by the local OS intance. |
---|
[23] | 75 | *****************************************************************************************/ |
---|
[1] | 76 | |
---|
[23] | 77 | typedef enum |
---|
| 78 | { |
---|
| 79 | FS_TYPE_DEVFS = 0, |
---|
| 80 | FS_TYPE_FATFS = 1, |
---|
| 81 | FS_TYPE_RAMFS = 2, |
---|
| 82 | |
---|
| 83 | FS_TYPES_NR = 3, |
---|
| 84 | } |
---|
| 85 | vfs_fs_type_t; |
---|
[1] | 86 | |
---|
[23] | 87 | typedef enum |
---|
| 88 | { |
---|
| 89 | CTX_ATTR_READ_ONLY = 0x01, /*! write access prohibited */ |
---|
| 90 | CTX_ATTR_SYNC = 0x10, /*! synchronise FS on each write */ |
---|
| 91 | } |
---|
| 92 | vfs_ctx_attr_t; |
---|
[1] | 93 | |
---|
[23] | 94 | typedef struct vfs_ctx_s |
---|
| 95 | { |
---|
| 96 | vfs_fs_type_t type; /*! File System type */ |
---|
| 97 | uint32_t attr; /*! global attributes for all files in FS */ |
---|
[188] | 98 | uint32_t total_clusters; /*! total number of clusters on device */ |
---|
| 99 | uint32_t cluster_size; /*! cluster size on device (bytes) */ |
---|
| 100 | xptr_t vfs_root_xp; /*! extended pointer on VFS root inode */ |
---|
[568] | 101 | busylock_t lock; /*! lock protecting inum allocator */ |
---|
[23] | 102 | uint32_t bitmap[BITMAP_SIZE(CONFIG_VFS_MAX_INODES)]; /* inum allocator */ |
---|
| 103 | void * extend; /*! FS specific context extension */ |
---|
| 104 | } |
---|
| 105 | vfs_ctx_t; |
---|
[1] | 106 | |
---|
| 107 | /****************************************************************************************** |
---|
| 108 | * This structure define a VFS inode. |
---|
[610] | 109 | * An inode has several children dentries (if it is a directory), an can have several |
---|
| 110 | * parents dentries (if it hass several aliases links): |
---|
| 111 | * - The "parents" field is the root of the xlist of parents dentries, and the "links" |
---|
| 112 | * fiels define the number of aliases parent dentries. only a FILE inode can have |
---|
| 113 | * several parents (no hard links for directories). |
---|
| 114 | * - The "children" field is an embedded xhtab containing pointers on all local children |
---|
| 115 | * dentries. This set of children is empty for a FILE inode. |
---|
[568] | 116 | * Synchronisation: |
---|
[610] | 117 | * - the main_lock (remote_rwlock) is used during the inode tree traversal, |
---|
| 118 | * or for inode modification (add/remove children in xhtab). |
---|
| 119 | * - the size_lock (remote_rwlock) is used during read/write accesses to the size |
---|
| 120 | * field in the mapper. |
---|
| 121 | * - access to the data stored in the associated mapper use the mapper remote_rwlock |
---|
| 122 | * protecting radix tree traversal and modifications. |
---|
[1] | 123 | *****************************************************************************************/ |
---|
| 124 | |
---|
[611] | 125 | /* this enum define the VFS inode types values */ |
---|
| 126 | /* WARNING : this enum must be kept consistent with macros in <shared_stat.h> file */ |
---|
| 127 | /* and with types in <shared_dirent.h> file. */ |
---|
[23] | 128 | |
---|
[10] | 129 | typedef enum |
---|
| 130 | { |
---|
[598] | 131 | INODE_TYPE_FILE = 0, /*! regular file */ |
---|
[430] | 132 | INODE_TYPE_DIR = 1, /*! directory */ |
---|
| 133 | INODE_TYPE_FIFO = 2, /*! POSIX named pipe */ |
---|
| 134 | INODE_TYPE_PIPE = 3, /*! POSIX anonymous pipe */ |
---|
| 135 | INODE_TYPE_SOCK = 4, /*! POSIX socket */ |
---|
[598] | 136 | INODE_TYPE_DEV = 5, /*! character device */ |
---|
[611] | 137 | INODE_TYPE_BLK = 6, /*! block device */ |
---|
| 138 | INODE_TYPE_SYML = 7, /*! symbolic link */ |
---|
[10] | 139 | } |
---|
| 140 | vfs_inode_type_t; |
---|
| 141 | |
---|
[23] | 142 | /* this enum define the VFS inode attributes values */ |
---|
| 143 | |
---|
[1] | 144 | typedef enum |
---|
| 145 | { |
---|
[23] | 146 | INODE_ATTR_DIRTY = 0x01, /* modified versus the value on device */ |
---|
| 147 | INODE_ATTR_INLOAD = 0x04, /* loading from device in progress */ |
---|
| 148 | INODE_ATTR_NEW = 0x08, /* not saved on device yet */ |
---|
[1] | 149 | } |
---|
[10] | 150 | vfs_inode_attr_t; |
---|
[1] | 151 | |
---|
| 152 | typedef struct vfs_inode_s |
---|
| 153 | { |
---|
[188] | 154 | struct vfs_ctx_s * ctx; /*! local pointer on FS context */ |
---|
| 155 | uint32_t inum; /*! inode identifier (unique in file system) */ |
---|
| 156 | uint32_t attr; /*! inode attributes (see above) */ |
---|
| 157 | vfs_inode_type_t type; /*! inode type (see above) */ |
---|
| 158 | uint32_t size; /*! number of bytes */ |
---|
[598] | 159 | uint32_t uid; /*! user owner identifier */ |
---|
| 160 | uint32_t gid; /*! group owner identifier */ |
---|
[188] | 161 | uint32_t rights; /*! access rights */ |
---|
[610] | 162 | xlist_entry_t parents; /*! root of list of parents dentries */ |
---|
| 163 | uint32_t links; /*! number of parent dentries (hard links) */ |
---|
[188] | 164 | xhtab_t children; /*! embedded xhtab of children dentries */ |
---|
[610] | 165 | remote_rwlock_t size_lock; /*! protect read/write to size */ |
---|
| 166 | remote_rwlock_t main_lock; /*! protect inode tree traversal and modifs */ |
---|
| 167 | // list_entry_t list; /*! member of set of inodes in same cluster */ |
---|
| 168 | // list_entry_t wait_root; /*! root of threads waiting on this inode */ |
---|
[188] | 169 | struct mapper_s * mapper; /*! associated file cache */ |
---|
| 170 | void * extend; /*! fs_type_specific inode extension */ |
---|
[1] | 171 | } |
---|
| 172 | vfs_inode_t; |
---|
| 173 | |
---|
[598] | 174 | /* This define the masks for the inode <rights> field */ |
---|
| 175 | |
---|
| 176 | #define VFS_ISUID 0x0004000 |
---|
| 177 | #define VFS_ISGID 0x0002000 |
---|
[611] | 178 | #define VFS_ISVTX 0x0001000 |
---|
[598] | 179 | |
---|
| 180 | #define VFS_IRWXU 0x0000700 |
---|
| 181 | #define VFS_IRUSR 0x0000400 |
---|
| 182 | #define VFS_IWUSR 0x0000200 |
---|
| 183 | #define VFS_IXUSR 0x0000100 |
---|
| 184 | |
---|
| 185 | #define VFS_IRWXG 0x0000070 |
---|
| 186 | #define VFS_IRGRP 0x0000040 |
---|
| 187 | #define VFS_IWGRP 0x0000020 |
---|
| 188 | #define VFS_IXGRP 0x0000010 |
---|
| 189 | |
---|
| 190 | #define VFS_IRWXO 0x0000007 |
---|
| 191 | #define VFS_IROTH 0x0000004 |
---|
| 192 | #define VFS_IWOTH 0x0000002 |
---|
| 193 | #define VFS_IXOTH 0x0000001 |
---|
| 194 | |
---|
[1] | 195 | /****************************************************************************************** |
---|
| 196 | * This structure defines a directory entry. |
---|
| 197 | * A dentry contains the name of a remote file/dir, an extended pointer on the |
---|
[610] | 198 | * inode representing this file/dir, a local pointer on the inode representing |
---|
[1] | 199 | * the parent directory. |
---|
[610] | 200 | * A dentry can be member of the set of children of a given directory inode (xhtab). |
---|
| 201 | * A dentry can be member of the set of parents of a given inode (xlist). |
---|
[1] | 202 | *****************************************************************************************/ |
---|
| 203 | |
---|
| 204 | typedef struct vfs_dentry_s |
---|
| 205 | { |
---|
[188] | 206 | struct vfs_ctx_s * ctx; /*! local pointer on FS context */ |
---|
| 207 | char name[CONFIG_VFS_MAX_NAME_LENGTH]; |
---|
| 208 | uint32_t length; /*! name length (bytes) */ |
---|
| 209 | struct vfs_inode_s * parent; /*! local pointer on parent inode */ |
---|
| 210 | xptr_t child_xp; /*! extended pointer on child inode */ |
---|
[610] | 211 | xlist_entry_t children; /*! member of set of children dentries */ |
---|
| 212 | xlist_entry_t parents; /*! member of set of parent dentries */ |
---|
[188] | 213 | void * extend; /*! FS specific extension */ |
---|
[1] | 214 | } |
---|
| 215 | vfs_dentry_t; |
---|
| 216 | |
---|
| 217 | /****************************************************************************************** |
---|
[23] | 218 | * This file structure describes an open file/directory for a given process. |
---|
[1] | 219 | * It is not replicated, and is dynamically allocated in the cluster that contains |
---|
| 220 | * the inode, when a thread makes an open() or opendir() system call. |
---|
[459] | 221 | * It cannot exist a file structure without an inode structure in same cluster. |
---|
[266] | 222 | * As the fd_array (containing extended pointers on the open file descriptors) |
---|
[23] | 223 | * is replicated in all process descriptors, we need a references counter. |
---|
[1] | 224 | *****************************************************************************************/ |
---|
| 225 | |
---|
| 226 | typedef enum |
---|
| 227 | { |
---|
[23] | 228 | FD_ATTR_READ_ENABLE = 0x01, /*! read access possible */ |
---|
| 229 | FD_ATTR_WRITE_ENABLE = 0x02, /*! write access possible */ |
---|
| 230 | FD_ATTR_APPEND = 0x04, /*! append on each write */ |
---|
| 231 | FD_ATTR_CLOSE_EXEC = 0x08, /*! close file on exec */ |
---|
| 232 | FD_ATTR_SYNC = 0x10, /*! synchronise FS on each write */ |
---|
| 233 | FD_ATTR_IS_DIR = 0x20, /*! this is a directory */ |
---|
[1] | 234 | } |
---|
[23] | 235 | vfs_file_attr_t; |
---|
[1] | 236 | |
---|
| 237 | typedef struct vfs_file_s |
---|
| 238 | { |
---|
[23] | 239 | struct vfs_ctx_s * ctx; /*! local pointer on FS context. */ |
---|
[1] | 240 | uint32_t gc; /*! generation counter */ |
---|
[23] | 241 | vfs_file_attr_t attr; /*! file attributes bit vector (see above) */ |
---|
| 242 | vfs_inode_type_t type; /*! same type as inode */ |
---|
[1] | 243 | uint32_t offset; /*! seek position in file */ |
---|
[23] | 244 | uint32_t refcount; /*! all pointers on this file descriptor */ |
---|
| 245 | remote_rwlock_t lock; /*! protect offset modifications */ |
---|
[1] | 246 | struct mapper_s * mapper; /*! associated file cache */ |
---|
| 247 | struct vfs_inode_s * inode; /*! local pointer on associated inode */ |
---|
[23] | 248 | void * extend; /*! FS specific extension */ |
---|
[1] | 249 | } |
---|
| 250 | vfs_file_t; |
---|
| 251 | |
---|
| 252 | |
---|
[602] | 253 | /****************************************************************************************** |
---|
| 254 | * These functions access / modify a VFS context. |
---|
[1] | 255 | *****************************************************************************************/ |
---|
| 256 | |
---|
| 257 | /****************************************************************************************** |
---|
[188] | 258 | * This function initialise a (statically allocated) VFS context in local cluster. |
---|
| 259 | ****************************************************************************************** |
---|
| 260 | * @ fs_type : file system type. |
---|
| 261 | * @ attr : global attributes (for all files in FS. |
---|
| 262 | * @ total_clusters : total number of clusters on device. |
---|
| 263 | * @ cluster_size : cluster size on device (bytes). |
---|
| 264 | * @ vfs_root_xp : extended pointer on VFS root inode. |
---|
| 265 | * @ extend : fs_type_specific extension. |
---|
| 266 | *****************************************************************************************/ |
---|
| 267 | void vfs_ctx_init( vfs_fs_type_t type, |
---|
| 268 | uint32_t attr, |
---|
| 269 | uint32_t total_clusters, |
---|
| 270 | uint32_t cluster_size, |
---|
| 271 | xptr_t vfs_root_xp, |
---|
| 272 | void * extend ); |
---|
| 273 | |
---|
| 274 | /****************************************************************************************** |
---|
[1] | 275 | * This function allocates an inode identifier from the local cluster inum allocator. |
---|
| 276 | * The inum respects a fixed format: |
---|
| 277 | * - the 16 MSB bits contain the cluster identifier : cxy |
---|
| 278 | * - the 16 LSB bits contains the local inode identifier : lid |
---|
| 279 | ****************************************************************************************** |
---|
| 280 | * @ ctx : local pointer on file system context. |
---|
| 281 | * @ inum : [ou] buffer for allocated inode identifier. |
---|
| 282 | * @ return 0 if success / return non-zero if error. |
---|
| 283 | *****************************************************************************************/ |
---|
| 284 | error_t vfs_ctx_inum_alloc( vfs_ctx_t * ctx, |
---|
| 285 | uint32_t * inum ); |
---|
| 286 | |
---|
| 287 | /****************************************************************************************** |
---|
| 288 | * This function release an inode identifier. |
---|
| 289 | ****************************************************************************************** |
---|
| 290 | * @ ctx : local pointer on file system context. |
---|
| 291 | * @ inum : released inode identifier. |
---|
| 292 | *****************************************************************************************/ |
---|
| 293 | void vfs_ctx_inum_release( vfs_ctx_t * ctx, |
---|
| 294 | uint32_t inum ); |
---|
| 295 | |
---|
| 296 | |
---|
| 297 | |
---|
[602] | 298 | /****************************************************************************************** |
---|
| 299 | * These low-level functions access / modify a VFS inode descriptor |
---|
| 300 | *****************************************************************************************/ |
---|
[1] | 301 | |
---|
| 302 | /****************************************************************************************** |
---|
[602] | 303 | * This function returns a printable string for the inode type. |
---|
| 304 | *****************************************************************************************/ |
---|
| 305 | const char * vfs_inode_type_str( vfs_inode_type_t type ); |
---|
| 306 | |
---|
| 307 | /****************************************************************************************** |
---|
[1] | 308 | * This function allocates memory from local cluster for an inode descriptor and the |
---|
| 309 | * associated mapper. It initialise these descriptors from arguments values. |
---|
[611] | 310 | * It must called by a local thread. Use the RPC_INODE_CREATE if client thread is remote. |
---|
[1] | 311 | ****************************************************************************************** |
---|
[23] | 312 | * @ fs_type : file system type. |
---|
| 313 | * @ inode_type : inode type. |
---|
[1] | 314 | * @ attr : inode attributes. |
---|
[23] | 315 | * @ rights : inode access rights. |
---|
[1] | 316 | * @ uid : user owner ID. |
---|
| 317 | * @ gid : group owner ID. |
---|
| 318 | * @ inode_xp : [out] buffer for extended pointer on created inode. |
---|
[459] | 319 | * @ return 0 if success / return ENOMEM or EINVAL if error. |
---|
[1] | 320 | *****************************************************************************************/ |
---|
[610] | 321 | error_t vfs_inode_create( vfs_fs_type_t fs_type, |
---|
[23] | 322 | vfs_inode_type_t inode_type, |
---|
| 323 | uint32_t attr, |
---|
| 324 | uint32_t rights, |
---|
| 325 | uid_t uid, |
---|
| 326 | gid_t gid, |
---|
| 327 | xptr_t * inode_xp ); |
---|
[1] | 328 | |
---|
| 329 | /****************************************************************************************** |
---|
[602] | 330 | * This function releases memory allocated to an inode descriptor, including |
---|
| 331 | * all memory allocated to the mapper (both mapper descriptor and radix tree). |
---|
[610] | 332 | * The mapper should not contain any dirty page (should be synchronized before deletion). |
---|
[602] | 333 | * It must be executed by a thread running in the cluster containing the inode. |
---|
| 334 | * Use the rpc_vfs_inode_destroy_client() function if required. |
---|
[1] | 335 | ****************************************************************************************** |
---|
| 336 | * @ inode : local pointer on inode descriptor. |
---|
| 337 | *****************************************************************************************/ |
---|
[602] | 338 | void vfs_inode_destroy( vfs_inode_t * inode ); |
---|
[1] | 339 | |
---|
| 340 | /****************************************************************************************** |
---|
| 341 | * This function returns the <size> of a file/dir from a remote inode, |
---|
| 342 | * taking the remote_rwlock protecting <size> in READ_MODE. |
---|
| 343 | ***************************************************************************************** |
---|
| 344 | * @ inode_xp : extended pointer on the remote inode. |
---|
| 345 | * @ return the current size. |
---|
| 346 | *****************************************************************************************/ |
---|
| 347 | uint32_t vfs_inode_get_size( xptr_t inode_xp ); |
---|
| 348 | |
---|
| 349 | /****************************************************************************************** |
---|
| 350 | * This function set the <size> of a file/dir to a remote inode, |
---|
| 351 | * taking the remote_rwlock protecting <size> in WRITE_MODE. |
---|
| 352 | ***************************************************************************************** |
---|
| 353 | * @ inode_xp : extended pointer on the remote inode. |
---|
| 354 | * @ size : value to be written. |
---|
| 355 | *****************************************************************************************/ |
---|
| 356 | void vfs_inode_set_size( xptr_t inode_xp, |
---|
| 357 | uint32_t size ); |
---|
| 358 | |
---|
| 359 | /****************************************************************************************** |
---|
| 360 | * This function takes the main lock of a remote inode. |
---|
[602] | 361 | * This lock protect all inode fields, including the children dentries. |
---|
[1] | 362 | ***************************************************************************************** |
---|
| 363 | * @ inode_xp : extended pointer on the remote inode. |
---|
| 364 | *****************************************************************************************/ |
---|
[101] | 365 | void vfs_inode_lock( xptr_t inode_xp ); |
---|
[1] | 366 | |
---|
| 367 | /****************************************************************************************** |
---|
| 368 | * This function releases the main lock of a remote inode. |
---|
| 369 | * This lock protect all inode fiels, including the children dentries. |
---|
| 370 | ***************************************************************************************** |
---|
| 371 | * @ inode_xp : extended pointer on the remote inode. |
---|
| 372 | *****************************************************************************************/ |
---|
[101] | 373 | void vfs_inode_unlock( xptr_t inode_xp ); |
---|
[1] | 374 | |
---|
| 375 | /****************************************************************************************** |
---|
[409] | 376 | * This debug function copies the name of a remote inode identified by the <inode_xp> |
---|
| 377 | * argument to a local buffer identified by the <name> argument. |
---|
| 378 | * The local buffer size must be at least CONFIG_VFS_MAX_NAME_LENGTH. |
---|
[101] | 379 | ***************************************************************************************** |
---|
| 380 | * @ inode_xp : extended pointer on the remote inode. |
---|
[409] | 381 | * @ name : local buffer pointer. |
---|
[1] | 382 | *****************************************************************************************/ |
---|
[409] | 383 | void vfs_inode_get_name( xptr_t inode_xp, |
---|
| 384 | char * name ); |
---|
[1] | 385 | |
---|
[602] | 386 | /****************************************************************************************** |
---|
| 387 | * This function accesses successively all pages of a file identified by the <inode>, |
---|
| 388 | * argument, to force misses, and load all pages into mapper. |
---|
| 389 | * The target inode can be a directory or a file, but this function is mainly used |
---|
| 390 | * to prefetch a complete directory to the mapper. |
---|
| 391 | * It must be executed by a thread running in the cluster containing the inode. |
---|
| 392 | * This function does NOT take any lock. |
---|
| 393 | ****************************************************************************************** |
---|
| 394 | * @ inode : local pointer on inode. |
---|
| 395 | * @ return 0 if success / return -1 if device access failure. |
---|
| 396 | *****************************************************************************************/ |
---|
| 397 | error_t vfs_inode_load_all_pages( vfs_inode_t * inode ); |
---|
[204] | 398 | |
---|
[1] | 399 | |
---|
[611] | 400 | |
---|
[602] | 401 | /****************************************************************************************** |
---|
| 402 | * These low-level functions access / modify a VFS dentry descriptor |
---|
| 403 | *****************************************************************************************/ |
---|
| 404 | |
---|
[1] | 405 | /****************************************************************************************** |
---|
| 406 | * This function allocates memory from local cluster for a dentry descriptor, |
---|
| 407 | * initialises it from arguments values, and returns the extended pointer on dentry. |
---|
[611] | 408 | * It must called by a local thread. Use the RPC_DENTRY_CREATE if client thread is remote. |
---|
[1] | 409 | ****************************************************************************************** |
---|
[23] | 410 | * @ fs_type : file system type. |
---|
[1] | 411 | * @ name : directory entry file/dir name. |
---|
[23] | 412 | * @ dentry_xp : [out] buffer for extended pointer on created dentry. |
---|
[1] | 413 | * @ return 0 if success / return ENOMEM or EINVAL if error. |
---|
| 414 | *****************************************************************************************/ |
---|
[23] | 415 | error_t vfs_dentry_create( vfs_fs_type_t fs_type, |
---|
| 416 | char * name, |
---|
| 417 | xptr_t * dentry_xp ); |
---|
[1] | 418 | |
---|
| 419 | /****************************************************************************************** |
---|
[610] | 420 | * This function removes the dentry from the parent inode xhtab, and releases the memory |
---|
| 421 | * allocated to the dentry descriptor. |
---|
[602] | 422 | * It must be executed by a thread running in the cluster containing the dentry. |
---|
| 423 | * Use the rpc_vfs_dentry_destroy_client() function if required. |
---|
[1] | 424 | ****************************************************************************************** |
---|
| 425 | * @ dentry : local pointer on dentry descriptor. |
---|
| 426 | *****************************************************************************************/ |
---|
[602] | 427 | void vfs_dentry_destroy( vfs_dentry_t * dentry ); |
---|
[1] | 428 | |
---|
| 429 | |
---|
[602] | 430 | /****************************************************************************************** |
---|
| 431 | * These low-level functions access / modify a VFS file descriptor |
---|
| 432 | *****************************************************************************************/ |
---|
[23] | 433 | |
---|
[1] | 434 | /****************************************************************************************** |
---|
[23] | 435 | * This function allocates memory and initializes a new local file descriptor. |
---|
| 436 | * It must be executed in the cluster containing the inode. |
---|
| 437 | * If the client thread is not running in the owner cluster, it must use the |
---|
| 438 | * rpc_vfs_file_create_client() function. |
---|
| 439 | ****************************************************************************************** |
---|
| 440 | * @ inode : local pointer on associated inode. |
---|
| 441 | * @ attr : file descriptor attributes. |
---|
| 442 | * @ file_xp : [out] buffer for extended pointer on created file descriptor. |
---|
| 443 | * @ return 0 if success / return ENOMEM if error. |
---|
[1] | 444 | *****************************************************************************************/ |
---|
[23] | 445 | error_t vfs_file_create( vfs_inode_t * inode, |
---|
| 446 | uint32_t attr, |
---|
| 447 | xptr_t * file_xp ); |
---|
[1] | 448 | |
---|
[23] | 449 | /****************************************************************************************** |
---|
| 450 | * This function releases memory allocated to a local file descriptor. |
---|
| 451 | * It must be executed by a thread running in the cluster containing the inode, |
---|
| 452 | * and the file refcount must be zero. |
---|
| 453 | * If the client thread is not running in the owner cluster, it must use the |
---|
| 454 | * rpc_vfs_file_destroy_client() function. |
---|
| 455 | ****************************************************************************************** |
---|
| 456 | * @ file : local pointer on file descriptor. |
---|
| 457 | *****************************************************************************************/ |
---|
| 458 | void vfs_file_destroy( vfs_file_t * file ); |
---|
[1] | 459 | |
---|
[23] | 460 | /****************************************************************************************** |
---|
| 461 | * These functions increment (resp. decrement) the count field in a remote file |
---|
| 462 | * descriptor, using a remote_atomic access. |
---|
| 463 | *****************************************************************************************/ |
---|
| 464 | void vfs_file_count_up ( xptr_t file_xp ); |
---|
| 465 | void vfs_file_count_down( xptr_t file_xp ); |
---|
| 466 | |
---|
| 467 | |
---|
| 468 | |
---|
[602] | 469 | /****************************************************************************************** |
---|
[610] | 470 | * These functions access / modify the distributed VFS Inode Tree |
---|
[598] | 471 | *****************************************************************************************/ |
---|
| 472 | |
---|
| 473 | /****************************************************************************************** |
---|
[610] | 474 | * This function returns in a kernel <buffer> allocated by the caller function, |
---|
| 475 | * the pathname of a file/dir identified by the <inode_xp> argument. |
---|
[1] | 476 | * It traverse the Inode Tree from the target node to the root. |
---|
| 477 | * It can be called by any thread running in any cluster. |
---|
[610] | 478 | * As this buffer if filled in "reverse order" (i.e. from the target inode to the root), |
---|
| 479 | * the pathname is stored in the higher part of the buffer. |
---|
| 480 | * A pointer on the first character of the pathname is returned in <first> buffer. |
---|
| 481 | * |
---|
| 482 | * WARNING : This function takes & releases the remote_rwlock protecting the Inode Tree. |
---|
[1] | 483 | ****************************************************************************************** |
---|
[610] | 484 | * @ inode_xp : [in] extended pointer on target inode descriptor. |
---|
| 485 | * @ buffer : [in] kernel buffer for pathname (allocated by caller). |
---|
| 486 | * @ first : [out] pointer on first character in buffer. |
---|
| 487 | * @ max_size : [in] max number of characters in buffer. |
---|
[1] | 488 | * @ return 0 if success / return EINVAL if buffer too small. |
---|
| 489 | *****************************************************************************************/ |
---|
| 490 | error_t vfs_get_path( xptr_t inode_xp, |
---|
| 491 | char * buffer, |
---|
[610] | 492 | char ** first, |
---|
[1] | 493 | uint32_t max_size ); |
---|
| 494 | |
---|
| 495 | /****************************************************************************************** |
---|
[610] | 496 | * This function traverses the the Inode Tree, from inode identified by the <root_xp> |
---|
| 497 | * argument, and returns in <inode_xp> the inode identified by the < pathname> argument. |
---|
| 498 | * It can be called by a thread running in any cluster. |
---|
| 499 | * It supports the following flags that define the lookup modes : |
---|
| 500 | * - VFS_LOOKUP_DIR : the searched inode must be a directory |
---|
| 501 | * - VFS_LOOKUP_OPEN : the search is for an open/opendir |
---|
| 502 | * - VFS_LOOKUP_PARENT : return the parent inode (not the inode itself) |
---|
| 503 | * - VFS_LOOKUP_CREATE : file/directory must be created if missing on IOC |
---|
| 504 | * - VFS_LOOKUP_EXCL : file cannot previously exist |
---|
| 505 | * As the inode Tree is a cache, the search policy is the following : |
---|
[459] | 506 | * - If a given directory name in the path is not found in the inode tree, it try to load |
---|
| 507 | * the missing dentry/inode couple, from informations found in the parent directory. |
---|
[610] | 508 | * - If this directory entry does not exist on IOC, it returns an error. |
---|
| 509 | * - If the the file identified by the pathname does not exist on IOC but the |
---|
| 510 | * flag CREATE is set, the inode is created. It returns an error otherwise. |
---|
| 511 | * - If the the file identified by the pathname exist on device, but both flags EXCL |
---|
[23] | 512 | * and CREATE are set, an error is returned. |
---|
[610] | 513 | * - If the PARENT flag is set, it returns in <inode_xp> an extended pointer on the parent |
---|
| 514 | * inode, and copies in <last_name> buffer a string containing the last name in path. |
---|
| 515 | * |
---|
| 516 | * WARNING : The remote_rwlock protecting the Inode Tree must be taken by the caller. |
---|
| 517 | * |
---|
| 518 | * TODO the access rights are not checked yet. |
---|
[1] | 519 | ****************************************************************************************** |
---|
[610] | 520 | * @ root_xp : [in] extended pointer on root inode (can be root of a subtree). |
---|
| 521 | * @ pathname : [in] path (can be relative or absolute). |
---|
| 522 | * @ lookup_mode : [in] flags defining the searching mode. |
---|
[238] | 523 | * @ inode_xp : [out] buffer for extended pointer on searched inode. |
---|
[610] | 524 | * @ last_name : [out] pointer on buffer for last name in path. |
---|
[407] | 525 | * @ return 0 if success / ENOENT if inode not found , EACCES if permisson denied, |
---|
[1] | 526 | *****************************************************************************************/ |
---|
[610] | 527 | error_t vfs_lookup( xptr_t root_xp, |
---|
[23] | 528 | char * pathname, |
---|
| 529 | uint32_t lookup_mode, |
---|
[610] | 530 | xptr_t * inode_xp, |
---|
| 531 | char * last_name ); |
---|
[1] | 532 | |
---|
| 533 | /****************************************************************************************** |
---|
| 534 | * This function creates a new couple dentry/inode, and insert it in the Inode-Tree. |
---|
[610] | 535 | * Only the distributed Inode Tree is modified: it does NOT modify the parent mapper, |
---|
| 536 | * and does NOT update the FS on IOC device. |
---|
[407] | 537 | * It can be executed by any thread running in any cluster (can be different from both |
---|
[610] | 538 | * the child cluster and the parent cluster). |
---|
[602] | 539 | * |
---|
| 540 | * [Implementation] |
---|
[611] | 541 | * As there are cross-references between inode and dentry, this function implements |
---|
| 542 | * a three steps scenario : |
---|
[602] | 543 | * 1) The dentry descriptor is created in the cluster containing the existing <parent_xp> |
---|
[611] | 544 | * inode, and partially initialized, using the RPC_VFS_CREATE DENTRY if required. |
---|
[602] | 545 | * 2) The inode and its associated mapper are created in cluster identified by <child_cxy>, |
---|
[611] | 546 | * and partially initialised, using the RPC_VFS_CREATE_INODE if required. |
---|
| 547 | * The new inode and the parent inode can have different FS types. |
---|
| 548 | * 3) The pointers between the parent inode, the new dentry, and the child inode |
---|
| 549 | * are updated, using remote accesses. |
---|
[1] | 550 | ****************************************************************************************** |
---|
[602] | 551 | * @ child_inode_cxy : [in] target cluster for child inode. |
---|
| 552 | * @ child_inode_type : [in] child inode type |
---|
| 553 | * @ fs_type : [in] child inode FS type. |
---|
| 554 | * @ parent_inode_xp : [in] extended pointer on parent inode. |
---|
| 555 | * @ name : [in] new directory entry name. |
---|
| 556 | * @ dentry_xp : [out] buffer for extended pointer on dentry |
---|
| 557 | * @ child_inode_xp : [out] buffer for extended pointer on child inode. |
---|
| 558 | * @ return 0 if success / -1 if dentry or inode cannot be created. |
---|
[1] | 559 | *****************************************************************************************/ |
---|
[610] | 560 | error_t vfs_add_child_in_parent( cxy_t child_inode_cxy, |
---|
| 561 | vfs_inode_type_t child_inode_type, |
---|
[23] | 562 | vfs_fs_type_t fs_type, |
---|
[602] | 563 | xptr_t parent_inode_xp, |
---|
| 564 | char * name, |
---|
| 565 | xptr_t * dentry_xp, |
---|
| 566 | xptr_t * child_inode_xp ); |
---|
[1] | 567 | |
---|
| 568 | /****************************************************************************************** |
---|
[610] | 569 | * This function removes a remote dentry from the Inode-Tree. |
---|
| 570 | * - It removes the dentry from the parent inode xhtab ("children" field), and from the |
---|
| 571 | * child inode xlist ("parents" field). |
---|
| 572 | * - It releases the memory allocated to the dentry descriptor. |
---|
| 573 | * - If the number of parents of the child inode is one, it also releases the memory |
---|
| 574 | * allocated to the child inode. |
---|
| 575 | * Only the Inode Tree is modified: it does NOT modify the parent mapper, |
---|
| 576 | * and does NOT update the FS on IOC device. |
---|
[602] | 577 | * It can be executed by any thread running in any cluster (can be different from both |
---|
[610] | 578 | * the inode cluster and the dentry cluster). |
---|
[1] | 579 | ****************************************************************************************** |
---|
[610] | 580 | * @ dentry_xp : extended pointer on removed dentry. |
---|
[1] | 581 | *****************************************************************************************/ |
---|
[610] | 582 | void vfs_remove_child_from_parent( xptr_t dentry_xp ); |
---|
[1] | 583 | |
---|
[188] | 584 | /****************************************************************************************** |
---|
[602] | 585 | * This function is called by the vfs_lookup() function when a new dentry/inode must |
---|
| 586 | * be created from scratch and introduced in both the Inode Tree and the IOC device. |
---|
| 587 | * The dentry and inode descriptors have been created by the caller: |
---|
| 588 | * - It allocates one cluster from the relevant FS, and updates the File Allocation |
---|
| 589 | * Table (both the FAT mapper, and the IOC device). |
---|
| 590 | * - It set the "size", and "extend" fields in child inode descriptor. |
---|
| 591 | * - It updates the parent directory to introduce the new child in the parent directory |
---|
| 592 | * inode descriptor (radix tree), in theparent inode mapper, and on IOC device. |
---|
| 593 | * - It set the "extend" field in dentry descriptor. |
---|
| 594 | * It can be called by a thread running in any cluster. |
---|
| 595 | ****************************************************************************************** |
---|
| 596 | * @ parent_xp : extended pointer on parent inode descriptor. |
---|
| 597 | * @ dentry_xp : extended pointer on new dentry descriptor. |
---|
| 598 | * @ child_xp : extended pointer on child inode descriptor. |
---|
| 599 | * @ return 0 if success / -1 if failure. |
---|
| 600 | *****************************************************************************************/ |
---|
| 601 | error_t vfs_new_child_init( xptr_t parent_xp, |
---|
[610] | 602 | xptr_t dentry_xp, |
---|
| 603 | xptr_t child_xp ); |
---|
[602] | 604 | |
---|
| 605 | /****************************************************************************************** |
---|
[611] | 606 | * This function is called by the vfs_mkdir() function to create the two special dentries |
---|
| 607 | * <.> and <..> in a new directory identified by the <child_xp> argument. The parent |
---|
| 608 | * directory inode is defined by the <parent_xp> argument. |
---|
| 609 | * The two dentries are introduced in the Inode Tree. They are also introduced in the |
---|
| 610 | * in the child directory mapper, and the IOC device is updated. |
---|
| 611 | ****************************************************************************************** |
---|
| 612 | * @ child_xp : extended pointer on new directory inode. |
---|
| 613 | * @ parent_xp : extended pointer on parent directory inode. |
---|
| 614 | * @ return 0 if success / -1 if failure. |
---|
| 615 | *****************************************************************************************/ |
---|
| 616 | error_t vfs_add_special_dentries( xptr_t child_xp, |
---|
| 617 | xptr_t parent_xp ); |
---|
| 618 | |
---|
| 619 | /****************************************************************************************** |
---|
[188] | 620 | * This recursive function diplays a complete inode/dentry sub-tree. |
---|
| 621 | * Any inode can be selected as the sub-tree root. |
---|
[611] | 622 | * WARNING : this function is not protected against a concurrent inode/dentry removal... |
---|
[188] | 623 | ****************************************************************************************** |
---|
| 624 | * @ inode_xp : extended pointer on sub-tree root inode. |
---|
| 625 | *****************************************************************************************/ |
---|
| 626 | void vfs_display( xptr_t inode_xp ); |
---|
[23] | 627 | |
---|
[602] | 628 | /****************************************************************************************** |
---|
| 629 | * This function mount a given file system type for a given process |
---|
| 630 | * TODO non implemented yet [AG]. |
---|
| 631 | *****************************************************************************************/ |
---|
| 632 | error_t vfs_mount_fs_root( struct device_s * device, |
---|
| 633 | uint32_t fs_type, |
---|
| 634 | struct process_s * process ); |
---|
[23] | 635 | |
---|
| 636 | |
---|
| 637 | |
---|
[602] | 638 | /****************************************************************************************** |
---|
| 639 | * These functions define the VFS "syscalls" API (user commands) |
---|
[1] | 640 | *****************************************************************************************/ |
---|
| 641 | |
---|
| 642 | /****************************************************************************************** |
---|
[313] | 643 | * This function moves <size> bytes between a remote file mapper, identified by the |
---|
| 644 | * <file_xp> argument, and a - possibly distributed - user space <buffer>, taken into |
---|
| 645 | * account the offset in <file_xp>. The transfer direction is defined by <to_buffer>. |
---|
[407] | 646 | * It is called by the sys_read() and sys_write() functions. |
---|
[23] | 647 | ****************************************************************************************** |
---|
[265] | 648 | * @ to_buffer : mapper -> buffer if true / buffer -> mapper if false. |
---|
[23] | 649 | * @ file_xp : extended pointer on the remote file descriptor. |
---|
[313] | 650 | * @ buffer : user space pointer on buffer (can be physically distributed). |
---|
[1] | 651 | * @ size : requested number of bytes from offset. |
---|
[407] | 652 | * @ returns number of bytes actually moved if success / -1 if error. |
---|
[1] | 653 | *****************************************************************************************/ |
---|
[407] | 654 | int vfs_user_move( bool_t to_buffer, |
---|
| 655 | xptr_t file_xp, |
---|
| 656 | void * buffer, |
---|
| 657 | uint32_t size ); |
---|
[1] | 658 | |
---|
| 659 | /****************************************************************************************** |
---|
[317] | 660 | * This function moves <size> bytes between a remote file mapper, identified by the |
---|
| 661 | * <file_xp> argument, and a - possibly remote - kernel <buffer_xp>, taken into |
---|
| 662 | * account the offset in <file_xp>. The transfer direction is defined by <to_buffer>. |
---|
[407] | 663 | * It is called by the elf_load_process() function. |
---|
[317] | 664 | ****************************************************************************************** |
---|
| 665 | * @ to_buffer : mapper -> buffer if true / buffer -> mapper if false. |
---|
| 666 | * @ file_xp : extended pointer on the remote file descriptor. |
---|
| 667 | * @ buffer_xp : user space pointer on buffer (can be physically distributed). |
---|
| 668 | * @ size : requested number of bytes from offset. |
---|
[407] | 669 | * @ returns 0 if success / -1 if error. |
---|
[317] | 670 | *****************************************************************************************/ |
---|
| 671 | error_t vfs_kernel_move( bool_t to_buffer, |
---|
| 672 | xptr_t file_xp, |
---|
| 673 | xptr_t buffer_xp, |
---|
| 674 | uint32_t size ); |
---|
| 675 | |
---|
| 676 | /****************************************************************************************** |
---|
[602] | 677 | * This function allocates a vfs_file_t structure in the cluster containing the inode |
---|
[610] | 678 | * identified by the <root_xp> & <path> arguments. |
---|
[602] | 679 | * It initializes it, register it in the reference process fd_array identified by the |
---|
[610] | 680 | * <process_xp> argument, and returns both the extended pointer on the file descriptor, |
---|
| 681 | * and the allocated index in the <file_xp> and <file_id> buffers. |
---|
[602] | 682 | * The pathname can be relative to current directory or absolute. |
---|
[610] | 683 | * If the inode does not exist in the inode cache, it try to find the file on the IOC |
---|
[602] | 684 | * device, and creates an inode on a pseudo randomly selected cluster if found. |
---|
| 685 | * It the requested file does not exist on device, it creates a new inode if the |
---|
| 686 | * O_CREAT flag is set, and return an error otherwise. |
---|
[610] | 687 | * |
---|
| 688 | * WARNING : this function takes & releases the remote_rwlock protecting the Inode Tree. |
---|
[602] | 689 | ****************************************************************************************** |
---|
[610] | 690 | * @ root_xp : extended pointer on path root inode. |
---|
[602] | 691 | * @ path : file pathname (absolute or relative to current directory). |
---|
[610] | 692 | * @ process_xp : extended pointer on client reference process. |
---|
[602] | 693 | * @ flags : defined in vfs_file_t structure. |
---|
| 694 | * @ mode : access rights (as defined by chmod). |
---|
| 695 | * @ file_xp : [out] buffer for extended pointer on created remote file descriptor. |
---|
| 696 | * @ file_id : [out] buffer for created file descriptor index in reference fd_array. |
---|
| 697 | * @ return 0 if success / return non-zero if error. |
---|
| 698 | *****************************************************************************************/ |
---|
[610] | 699 | error_t vfs_open( xptr_t root_xp, |
---|
[602] | 700 | char * path, |
---|
[610] | 701 | xptr_t process_xp, |
---|
[602] | 702 | uint32_t flags, |
---|
| 703 | uint32_t mode, |
---|
| 704 | xptr_t * file_xp, |
---|
| 705 | uint32_t * file_id ); |
---|
| 706 | |
---|
| 707 | /****************************************************************************************** |
---|
[1] | 708 | * This function set a new value in the offset of the open file descriptor <file_xp>. |
---|
| 709 | * This value depends on the <whence> argument: |
---|
| 710 | * - if VFS_SEEK_SET, new value is <offset> |
---|
| 711 | * - if VFS_SEEK_CUR, new value is current_offset + <offset> |
---|
| 712 | * - if VFS_SEEK_END, new value is file_size + <offset> |
---|
| 713 | ****************************************************************************************** |
---|
| 714 | * @ file_xp : extended pointer on the remote open file descriptor. |
---|
| 715 | * @ offset : local pointer on source kernel buffer. |
---|
| 716 | * @ whence : VFS_SEEK_SET / VFS_SEEK_CUR / VFS_SEEK_END. |
---|
| 717 | * @ new_offset : [out] buffer for new offset value. |
---|
| 718 | * @ returns 0 if success / -1 if error. |
---|
| 719 | *****************************************************************************************/ |
---|
| 720 | error_t vfs_lseek( xptr_t file_xp, |
---|
| 721 | uint32_t offset, |
---|
| 722 | uint32_t whence, |
---|
| 723 | uint32_t * new_offset ); |
---|
| 724 | |
---|
| 725 | /****************************************************************************************** |
---|
[602] | 726 | * This function close the - non-replicated - file descriptor identified by the <file_xp> |
---|
[459] | 727 | * and <file_id> arguments. |
---|
| 728 | * 1) All entries in the fd_array copies are directly reset by the calling thread, |
---|
[23] | 729 | * using remote accesses. |
---|
| 730 | * 2) The memory allocated to file descriptor in cluster containing the inode is released. |
---|
| 731 | * It requires a RPC if cluster containing the file descriptor is remote. |
---|
[1] | 732 | ****************************************************************************************** |
---|
[459] | 733 | * @ file_xp : extended pointer on the file descriptor in owner cluster. |
---|
[23] | 734 | * @ file_id : file descriptor index in fd_array. |
---|
| 735 | * @ returns 0 if success / -1 if error. |
---|
[1] | 736 | *****************************************************************************************/ |
---|
[23] | 737 | error_t vfs_close( xptr_t file_xp, |
---|
| 738 | uint32_t file_id ); |
---|
[1] | 739 | |
---|
| 740 | /****************************************************************************************** |
---|
[602] | 741 | * This function is called by the kernel to create in the file system a new directory |
---|
[610] | 742 | * identified by the <root_xp> & <path> arguments, with the access permission defined |
---|
| 743 | * by the <rights> argument. All nodes in the path - but the last - must exist. |
---|
| 744 | * |
---|
| 745 | * WARNING : this function takes & releases the remote_rwlock protecting the Inode Tree. |
---|
| 746 | ****************************************************************************************** |
---|
| 747 | * @ root_xp : extended pointer on path root inode (any inode in Inode Tree). |
---|
| 748 | * @ path : pathname (absolute or relative to current directory). |
---|
| 749 | * @ rights : access rights. |
---|
| 750 | * @ returns 0 if success / -1 if error. |
---|
| 751 | *****************************************************************************************/ |
---|
| 752 | error_t vfs_mkdir( xptr_t root_xp, |
---|
| 753 | char * path, |
---|
| 754 | uint32_t rights ); |
---|
| 755 | |
---|
| 756 | /****************************************************************************************** |
---|
| 757 | * This function is called by the kernel to create in the file system a new directory |
---|
| 758 | * entry identified by the <new_root_xp> & <new_path> arguments, to be linked to an |
---|
| 759 | * existing inode, identified by the <old_root_xp> & <old_path> arguments. |
---|
| 760 | * If the link is successful, the link count of the target inode is incremented. |
---|
| 761 | * The <new_path> and <old_path> share equal access rights to the underlying inode. |
---|
[602] | 762 | * Both the IOC device and the Inode Tree are modified. |
---|
[610] | 763 | $ |
---|
| 764 | * TODO This function should handle any type of node, but the current implementation |
---|
| 765 | * handles only the FILE and DIR types. |
---|
| 766 | * |
---|
| 767 | * WARNING : this function takes & releases the remote_rwlock protecting the Inode Tree. |
---|
[1] | 768 | ****************************************************************************************** |
---|
[610] | 769 | * @ old_root_xp : extended pointer on old path root inode (any inode in Inode Tree). |
---|
| 770 | * @ old_path : old pathname (absolute or relative to current directory). |
---|
| 771 | * @ nld_root_xp : extended pointer on new path root inode (any inode in Inode Tree). |
---|
| 772 | * @ new_path : new pathname (absolute or relative to current directory). |
---|
[602] | 773 | * @ returns 0 if success / -1 if error. |
---|
| 774 | *****************************************************************************************/ |
---|
[610] | 775 | error_t vfs_link( xptr_t old_root_xp, |
---|
| 776 | char * old_path, |
---|
| 777 | xptr_t new_root_xp, |
---|
| 778 | char * new_path ); |
---|
[602] | 779 | |
---|
| 780 | /****************************************************************************************** |
---|
| 781 | * This function is called by the kernel to remove from the file system a directory entry |
---|
[610] | 782 | * identified by the <root_xp> & <path> arguments. |
---|
| 783 | * The link count of the target node is decremented. |
---|
| 784 | * If the removed link is the last, the target inode is deleted. |
---|
[602] | 785 | * Both the IOC device and the Inode Tree are modified. |
---|
[610] | 786 | * |
---|
| 787 | * TODO This function should handle any type of node, but the current implementation |
---|
| 788 | * handles only only the FILE and DIR types. |
---|
| 789 | * |
---|
| 790 | * WARNING : this function takes & releases the remote_rwlock protecting the Inode Tree. |
---|
[602] | 791 | ****************************************************************************************** |
---|
[610] | 792 | * @ root_xp : extended pointer on root inode (can be any inode in Inode Tree). |
---|
[1] | 793 | * @ path : pathname (absolute or relative to current directory). |
---|
[23] | 794 | * @ returns 0 if success / -1 if error. |
---|
[1] | 795 | *****************************************************************************************/ |
---|
[610] | 796 | error_t vfs_unlink( xptr_t root_xp, |
---|
[1] | 797 | char * path ); |
---|
| 798 | |
---|
| 799 | /****************************************************************************************** |
---|
[610] | 800 | * This function returns, in the structure pointed by the <st> pointer, various |
---|
| 801 | * informations on the inode identified by the <root_inode_xp> and <patname> arguments. |
---|
| 802 | * |
---|
| 803 | * TODO : only partially implemented yet (only size and inum fields). |
---|
| 804 | * |
---|
| 805 | * WARNING : this function takes & releases the remote_rwlock protecting the Inode Tree. |
---|
[23] | 806 | ****************************************************************************************** |
---|
[610] | 807 | * @ root_xp : extended pointer on path root inode (any inode in Inode Tree) |
---|
| 808 | * @ pathname : pathname to target inode. |
---|
[598] | 809 | * @ st : local pointer on the stat structure in kernel space. |
---|
[23] | 810 | * @ returns 0 if success / -1 if error. |
---|
[1] | 811 | *****************************************************************************************/ |
---|
[610] | 812 | error_t vfs_stat( xptr_t root_xp, |
---|
| 813 | char * pathname, |
---|
[598] | 814 | struct stat * st ); |
---|
[1] | 815 | |
---|
| 816 | /****************************************************************************************** |
---|
[610] | 817 | * This function creates a new directory as defined by the <root_xp> & <path> arguments. |
---|
[23] | 818 | * TODO not implemented yet... |
---|
| 819 | ****************************************************************************************** |
---|
[610] | 820 | * @ root_xp : extended pointer on the path root directory. |
---|
| 821 | * @ path : pathname (absolute or relative to CWD). |
---|
[23] | 822 | * @ mode : access rights (as defined by chmod) |
---|
| 823 | * @ returns 0 if success / -1 if error. |
---|
[1] | 824 | *****************************************************************************************/ |
---|
[610] | 825 | error_t vfs_mkdir( xptr_t root_xp, |
---|
[23] | 826 | char * path, |
---|
| 827 | uint32_t mode ); |
---|
[1] | 828 | |
---|
| 829 | /****************************************************************************************** |
---|
[610] | 830 | * This function makes the directory identified by the <root_xp and <path> arguments |
---|
| 831 | * to become the working directory for the calling process. |
---|
[23] | 832 | ****************************************************************************************** |
---|
[610] | 833 | * @ root_xp : extended pointer on the path root directory. |
---|
| 834 | * @ path : pathname (absolute or relative to CWD). |
---|
[23] | 835 | * return 0 if success / -1 if error. |
---|
[1] | 836 | *****************************************************************************************/ |
---|
[610] | 837 | error_t vfs_chdir( xptr_t root_xp, |
---|
[23] | 838 | char * path ); |
---|
[1] | 839 | |
---|
| 840 | /****************************************************************************************** |
---|
[610] | 841 | * This function change the access rigths for the file/directory identified by the |
---|
| 842 | * <root_xp> and <path> arguments as defined by the <mode> argument value. |
---|
[23] | 843 | ****************************************************************************************** |
---|
[610] | 844 | * @ root_xp : extended pointer on the path root directory. |
---|
| 845 | * @ path : pathname (absolute or relative to CWD). |
---|
| 846 | * @ mode : access rights |
---|
[23] | 847 | * return 0 if success / -1 if error. |
---|
[1] | 848 | *****************************************************************************************/ |
---|
[610] | 849 | error_t vfs_chmod( xptr_t root_xp, |
---|
[23] | 850 | char * path, |
---|
| 851 | uint32_t mode ); |
---|
[1] | 852 | |
---|
| 853 | /****************************************************************************************** |
---|
[23] | 854 | * This function creates a named FIFO file. |
---|
| 855 | * TODO not implemented yet |
---|
| 856 | ****************************************************************************************** |
---|
[610] | 857 | * @ root_xp : extended pointer on the path root directory. |
---|
| 858 | * @ path : pathname (absolute or relative to CWD). |
---|
| 859 | * @ mode : access rights new value. |
---|
[1] | 860 | *****************************************************************************************/ |
---|
[610] | 861 | error_t vfs_mkfifo( xptr_t root_xp, |
---|
[23] | 862 | char * path, |
---|
| 863 | uint32_t mode ); |
---|
[1] | 864 | |
---|
| 865 | |
---|
| 866 | |
---|
[23] | 867 | /****************************************************************************************** |
---|
[602] | 868 | * These functions define the VFS "FS" API (to a specific File System) |
---|
| 869 | *****************************************************************************************/ |
---|
| 870 | |
---|
| 871 | /****************************************************************************************** |
---|
| 872 | * This function updates the mapper associated to a directory inode identified by the |
---|
| 873 | * <parent> argument, to add a new entry identified by the <dentry> argument. |
---|
| 874 | * The directory inode descriptor and the dentry descriptor are in the same cluster. |
---|
[23] | 875 | * Depending on the file system type, it calls the proper, FS specific function. |
---|
[611] | 876 | * It also updates the dentry descriptor and/or the inode descriptor extensions |
---|
[602] | 877 | * as required by the specific file system type. |
---|
| 878 | * Finally, it synchronously updates the parent directory on IOC device. |
---|
| 879 | * |
---|
| 880 | * It must be executed by a thread running in the cluster containing the parent directory. |
---|
[611] | 881 | * It can be the RPC_VFS_FS_ADD_DENTRY. This function does NOT take any lock. |
---|
[23] | 882 | ****************************************************************************************** |
---|
[602] | 883 | * @ parent : local pointer on parent (directory) inode. |
---|
| 884 | * @ dentry : local pointer on dentry containing name. |
---|
| 885 | * @ return 0 if success / return -1 if device access failure. |
---|
[1] | 886 | *****************************************************************************************/ |
---|
[602] | 887 | error_t vfs_fs_add_dentry( vfs_inode_t * parent, |
---|
| 888 | vfs_dentry_t * dentry ); |
---|
[1] | 889 | |
---|
[23] | 890 | /****************************************************************************************** |
---|
[602] | 891 | * This function updates the mapper associated to a directory inode identified by the |
---|
| 892 | * <parent> argument, to remove an entry identified by the <dentry> argument. |
---|
| 893 | * The directory inode descriptor and the dentry descriptor are in the same cluster. |
---|
[23] | 894 | * Depending on the file system type, it calls the proper, FS specific function. |
---|
[602] | 895 | * Finally, it synchronously updates the parent directory on IOC device. |
---|
| 896 | * |
---|
| 897 | * It must be executed by a thread running in the cluster containing the parent directory. |
---|
| 898 | * It can be the RPC_VFS_VS_REMOVE_DENTRY. This function does NOT take any lock. |
---|
[23] | 899 | ****************************************************************************************** |
---|
[602] | 900 | * @ parent : local pointer on parent (directory) inode. |
---|
| 901 | * @ dentry : local pointer on dentry containing name. |
---|
| 902 | * @ return 0 if success / return -1 if device access failure. |
---|
[1] | 903 | *****************************************************************************************/ |
---|
[602] | 904 | error_t vfs_fs_remove_dentry( vfs_inode_t * parent, |
---|
| 905 | vfs_dentry_t * dentry ); |
---|
[1] | 906 | |
---|
[602] | 907 | /****************************************************************************************** |
---|
| 908 | * This function scan the mapper of an an existing parent inode directory, identified by |
---|
| 909 | * the <parent> argument to find a directory entry identified by the <name> argument, |
---|
| 910 | * and updates both the child inode descriptor, identified by the <child_xp> argument, |
---|
| 911 | * and the associated dentry descriptor : |
---|
| 912 | * - It set the "size", and "extend" fields in inode descriptor. |
---|
| 913 | * - It set the "extend" field in dentry descriptor. |
---|
| 914 | * It is called by the vfs_lookup() function in case of miss. |
---|
| 915 | * |
---|
| 916 | * Depending on the file system type, it calls the relevant, FS specific function. |
---|
| 917 | * It must be called by a thread running in the cluster containing the parent inode. |
---|
| 918 | * This function does NOT take any lock. |
---|
| 919 | ****************************************************************************************** |
---|
| 920 | * @ parent : local pointer on parent inode (directory). |
---|
| 921 | * @ name : child name. |
---|
| 922 | * @ child_xp : extended pointer on remote child inode (file or directory) |
---|
| 923 | * @ return 0 if success / return ENOENT if not found. |
---|
| 924 | *****************************************************************************************/ |
---|
| 925 | error_t vfs_fs_child_init( vfs_inode_t * parent, |
---|
| 926 | char * name, |
---|
| 927 | xptr_t child_xp ); |
---|
[1] | 928 | |
---|
[602] | 929 | /***************************************************************************************** |
---|
| 930 | * This function updates the FS on the IOC device for a given inode identified by |
---|
| 931 | * the <inode> argument. It scan all pages registered in the associated mapper, |
---|
| 932 | * and copies from mapper to device each page marked as dirty. |
---|
| 933 | * WARNING : The target <inode> cannot be a directory, because all modifications in a |
---|
| 934 | * directory are synchronously done on the IOC device by the two vfs_fs_add_dentry() |
---|
| 935 | * and vfs_fs_remove_dentry() functions. |
---|
| 936 | * |
---|
| 937 | * Depending on the file system type, it calls the relevant, FS specific function. |
---|
| 938 | * It must be called by a thread running in the inode cluster. |
---|
| 939 | ***************************************************************************************** |
---|
| 940 | * @ inode : local pointer on inode. |
---|
| 941 | * @ return 0 if success / return EIO if failure during device access. |
---|
| 942 | ****************************************************************************************/ |
---|
| 943 | error_t vfs_fs_sync_inode( struct vfs_inode_s * inode ); |
---|
| 944 | |
---|
| 945 | /***************************************************************************************** |
---|
[610] | 946 | * This function updates the FS defined by the <fs_type> argument on the IOC device |
---|
| 947 | * for the FAT itself. It scan all clusters registered in the FAT mapper, and copies |
---|
| 948 | * to device each page marked as dirty. |
---|
[602] | 949 | * |
---|
| 950 | * Depending on the file system type, it calls the relevant, FS specific function. |
---|
| 951 | * It can be called by a thread running in any cluster. |
---|
| 952 | ***************************************************************************************** |
---|
[610] | 953 | * @ fs_type : specific file system type. |
---|
[602] | 954 | * @ return 0 if success / return EIO if failure during device access. |
---|
| 955 | ****************************************************************************************/ |
---|
[610] | 956 | error_t vfs_fs_sync_fat( vfs_fs_type_t fs_type ); |
---|
[602] | 957 | |
---|
| 958 | /***************************************************************************************** |
---|
[610] | 959 | * This function updates the free clusters info on the IOC device for the FS defined |
---|
| 960 | * by the <fs_type> argument. |
---|
[602] | 961 | * |
---|
| 962 | * Depending on the file system type, it calls the relevant, FS specific function. |
---|
| 963 | * It can be called by a thread running in any cluster. |
---|
| 964 | ***************************************************************************************** |
---|
[610] | 965 | * @ fs_type : specific file system type. |
---|
[602] | 966 | * @ return 0 if success / return EIO if failure during device access. |
---|
| 967 | ****************************************************************************************/ |
---|
[610] | 968 | error_t vfs_fs_sync_free_info( vfs_fs_type_t fs_type ); |
---|
[602] | 969 | |
---|
| 970 | /****************************************************************************************** |
---|
| 971 | * This function allocates a free cluster from the FS identified by the <fs_type> |
---|
| 972 | * argument. It updates the selected FS File Allocation Table. |
---|
| 973 | * |
---|
| 974 | * Depending on the file system type, it calls the relevant, FS specific function. |
---|
| 975 | * It can be called by a thread running in any cluster. |
---|
| 976 | ****************************************************************************************** |
---|
| 977 | * @ fs_type : [in] File System type. |
---|
| 978 | * @ cluster : [out] cluster index in File system. |
---|
| 979 | * @ return 0 if success / return -1 if no free cluster |
---|
| 980 | *****************************************************************************************/ |
---|
| 981 | error_t vfs_fs_cluster_alloc( uint32_t fs_type, |
---|
| 982 | uint32_t * cluster ); |
---|
| 983 | |
---|
| 984 | /****************************************************************************************** |
---|
| 985 | * This function makes all I/O operations required to release all clusters allocated |
---|
| 986 | * on IOC device to a given inode, identified by the <inode_xp> argument. |
---|
| 987 | * Depending on the file system type, it calls the proper, FS specific function. |
---|
| 988 | * It is called by the vfs_unlink() function. |
---|
| 989 | * It can be executed by a thread running in any cluster. |
---|
| 990 | * This function does NOT take any lock. |
---|
| 991 | ****************************************************************************************** |
---|
| 992 | * @ inode_xp : extended pointer on inode. |
---|
| 993 | * @ return 0 if success / return -1 if device access failure. |
---|
| 994 | *****************************************************************************************/ |
---|
| 995 | error_t vfs_fs_release_inode( xptr_t inode_xp ); |
---|
| 996 | |
---|
| 997 | /****************************************************************************************** |
---|
| 998 | * This function makes the I/O operation to move one page identified by the <page_xp> |
---|
| 999 | * argument to/from the IOC device from/to the mapper, as defined by <to_mapper>. |
---|
| 1000 | * Depending on the file system type, it calls the proper, FS specific function. |
---|
| 1001 | * It is used in case of MISS on the mapper, or when a dirty page in the mapper must |
---|
| 1002 | * be updated in the File System. |
---|
| 1003 | * The mapper pointer is obtained from the page descriptor. |
---|
| 1004 | * It can be executed by any thread running in any cluster. |
---|
| 1005 | * This function does NOT take any lock. |
---|
| 1006 | ****************************************************************************************** |
---|
| 1007 | * @ page_xp : extended pointer on the page descriptor. |
---|
| 1008 | * @ to_mapper : transfer direction. |
---|
| 1009 | * @ returns 0 if success / return -1 if device access failure. |
---|
| 1010 | *****************************************************************************************/ |
---|
| 1011 | error_t vfs_fs_move_page( xptr_t page_xp, |
---|
| 1012 | bool_t to_mapper ); |
---|
| 1013 | |
---|
| 1014 | |
---|
[1] | 1015 | #endif /* _VFS_H_ */ |
---|