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