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