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