#pragma once #include "fsEntry.h" #include "process.h" #include "stdint.h" #include #include #define FS_NAME_MAXLEN 32 // Forward declaration struct file_system; struct file_system_instance; struct fs_stat; struct file; typedef enum { FS_INODE_REGULAR_FILE = 0x01, FS_INODE_DIRECTORY = 0x02, FS_INODE_SYMLINK = 0x04, FS_INODE_DEVICE_CHAR = 0x08, FS_INODE_DEVICE_BLOCK = 0x10 } fs_inode_type_t; struct inode_operation { }; struct inode { // inode_operation struct file_system_instance *fs; uint64_t location; size_t ondiskRef; size_t inmemRef; fs_inode_type_t type; #define FS_READABLE 00400 #define FS_WRITABLE 00200 #define FS_EXECUTABLE 00100 uint32_t mode; bool_t dirty; struct inode_operation *ops; union { struct inode_dir_ops *opsDir; struct inode_dir_symlink *opsSymlink; }; int (*destructor)(struct inode *this); int (*new_opened_file)(struct inode *this, const struct process *owner, uint32_t open_flags, struct file **result_of); int (*close_opened_file)(struct inode *this, struct file *of); void *custom; struct inode *prev_dirty, *next_dirty; }; struct file_system_instance_ops { // super_operations // From the inode location, instantiace a struct inode int (*getInodeFromDevice)(struct file_system_instance *this, uint64_t storage_location, struct inode **result); int (*allocateNewInode)(struct file_system_instance *this, fs_inode_type_t type, const struct process *creator, uint32_t access_rights, uint32_t open_creat_flags, struct inode **result); int (*statfs)(struct file_system_instance *this, struct fs_stat *result); }; struct file_system_instance { struct file_system *fsType; // this instance is of this type of file_system struct inode *device; // device (like block one) could have a disk associated #define FS_MOUNT_SYNC (1 << 0) #define FS_MOUNT_READONLY (1 << 1) #define FS_MOUNT_NOEXEC (1 << 2) uint32_t flags; struct fsEntry *root; // root fsEntry for this fs instance struct indoe *dirtyNodes; // list of inodes that are out of sync void *custom; // custom const struct file_system_instance_ops *ops; struct file_system_instance *prev, *next; }; struct file_system { char name[FS_NAME_MAXLEN]; struct file_system_instance *instances; void *custom; int (*mount)(struct file_system *this, struct inode *device, const char *args, struct file_system_instance **mounted_fs); int (*umount)(struct file_system *this, struct file_system_instance *mounted_fs); struct file_system *prev, *next; }; struct file_operations{ }; struct file { const struct process *owner; struct fs_entry *direntry; uint ref; int64_t position; #define O_ACCMODE 0003 #define O_RDONLY 00 #define O_WRONLY 01 #define O_RDWR 02 #define O_CREAT 0100 /* Not fcntl. */ #define O_EXCL 0200 /* Not fcntl. */ #define O_NOCTTY 0400 /* Not fcntl. */ #define O_TRUNC 01000 /* Not fcntl. */ #define O_APPEND 02000 #define O_DIRECTORY 0200000 /* Must be a directory. */ #define O_NOFOLLOW 0400000 /* Do not follow links. */ #define O_SYNC 04010000 #define O_CLOEXEC 02000000 /* Set close_on_exec. */ uint32_t flags; const struct file_operations *ops; int (*duplicate)(struct file *this, const struct process *for_owner, struct file **result); void *custom; }; int fsRegister(struct file_system *fs); int fsInodeUnref(struct inode *inode); int fsInodeRef(struct inode *inode);