fs.h
1 #ifndef FS_H 2 #define FS_H 3 4 #include "types.h" 5 6 // Simple filesystem node 7 struct fs_node { 8 char name[128]; // Filename 9 uint32_t mask; // Permissions mask 10 uint32_t uid; // Owning user 11 uint32_t gid; // Owning group 12 uint32_t flags; // Node type flags 13 uint32_t inode; // Device-specific 14 uint32_t length; // Size of file 15 uint32_t impl; // Implementation-defined 16 17 // Function pointers for operations 18 uint32_t (*read)(struct fs_node*, uint32_t, uint32_t, uint8_t*); 19 uint32_t (*write)(struct fs_node*, uint32_t, uint32_t, uint8_t*); 20 void (*open)(struct fs_node*); 21 void (*close)(struct fs_node*); 22 struct dirent* (*readdir)(struct fs_node*, uint32_t); 23 struct fs_node* (*finddir)(struct fs_node*, char*); 24 25 struct fs_node* ptr; // Used by mountpoints and symlinks 26 }; 27 28 // Directory entry 29 struct dirent { 30 char name[128]; 31 uint32_t ino; 32 }; 33 34 // Filesystem flags 35 #define FS_FILE 0x01 36 #define FS_DIRECTORY 0x02 37 #define FS_CHARDEVICE 0x03 38 #define FS_BLOCKDEVICE 0x04 39 #define FS_PIPE 0x05 40 #define FS_SYMLINK 0x06 41 #define FS_MOUNTPOINT 0x08 42 43 // Filesystem operations 44 uint32_t fs_read(struct fs_node* node, uint32_t offset, uint32_t size, uint8_t* buffer); 45 uint32_t fs_write(struct fs_node* node, uint32_t offset, uint32_t size, uint8_t* buffer); 46 void fs_open(struct fs_node* node, uint8_t read, uint8_t write); 47 void fs_close(struct fs_node* node); 48 struct dirent* fs_readdir(struct fs_node* node, uint32_t index); 49 struct fs_node* fs_finddir(struct fs_node* node, char* name); 50 51 // Root filesystem 52 extern struct fs_node* fs_root; 53 54 // Initialize filesystem 55 void fs_init(void); 56 57 #endif // FS_H