1 2 #ifndef __SYS_VFS_H__ 3 #define __SYS_VFS_H__ 4 5 #include <sys/kmem.h> 6 #include <sys/stat.h> 7 8 typedef struct VFSOp VFSOp; 9 typedef struct VNode VNode; 10 11 typedef struct VFS { 12 VFSOp *op; 13 Disk *disk; 14 Spinlock lock; 15 uint64_t refCount; 16 // FS Fields 17 void *fsptr; 18 uint64_t fsval; 19 uint64_t blksize; 20 VNode *root; 21 void *bitmap[16]; 22 } VFS; 23 24 typedef struct VNode { 25 VFSOp *op; 26 Disk *disk; 27 Spinlock lock; 28 uint64_t refCount; 29 // FS Fields 30 void *fsptr; 31 uint64_t fsval; 32 VFS *vfs; 33 } VNode; 34 35 DECLARE_SLAB(VFS); 36 DECLARE_SLAB(VNode); 37 38 typedef struct VFSOp { 39 // VFS Operations 40 int (*unmount)(VFS *fs); 41 int (*getroot)(VFS *fs, VNode **dn); 42 // VNode Operations 43 int (*lookup)(VNode *dn, VNode **fn, const char *name); 44 int (*open)(VNode *fn); 45 int (*close)(VNode *fn); 46 int (*stat)(VNode *fn, struct stat *sb); 47 int (*read)(VNode *fn, void *buf, uint64_t off, uint64_t len); 48 int (*write)(VNode *fn, void *buf, uint64_t off, uint64_t len); 49 int (*readdir)(VNode *fn, void *buf, uint64_t len, uint64_t *off); 50 } VFSOp; 51 52 int VFS_MountRoot(Disk *root); 53 VNode *VFS_Lookup(const char *path); 54 // XXX: Release/Retain 55 int VFS_Stat(const char *path, struct stat *sb); 56 int VFS_Open(VNode *fn); 57 int VFS_Close(VNode *fn); 58 int VFS_Read(VNode *fn, void *buf, uint64_t off, uint64_t len); 59 int VFS_Write(VNode *fn, void *buf, uint64_t off, uint64_t len); 60 int VFS_ReadDir(VNode *fn, void *buf, uint64_t len, uint64_t *off); 61 62 #endif /* __SYS_VFS_H__ */ 63 64