#ifndef _NUCLEUS_VFS_H #define _NUCLEUS_VFS_H #include #include #include #include #include #include #include typedef Inode *(*mount_callback_t)(FSType *, int, const char *, void *); /* Structure for a Super Block */ struct SuperBlock { Object obj; FSType *type; SuperOps *ops; Inode *root; ObjectList *inodes; /* List of cached inodes */ File *back; void *data; }; struct SuperOps { Inode *(*alloc_inode)(SuperBlock *); int (*write_inode)(Inode *); void (*delete_inode)(Inode *); }; /* Structure for an Inode */ struct Inode { Object obj; ino_t ino; uid_t uid; gid_t gid; mode_t mode; nlink_t nlink; size_t size; dev_t dev; InodeOps *ops; FileOps *fileOps; SuperBlock *super; ObjectList *dirEntries; ObjectList *pages; }; struct InodeOps { int (*create)(Inode *, DirEntry *, mode_t); Inode *(*lookup)(Inode *, const char *); int (*mkdir)(Inode *, DirEntry *, mode_t); int (*rmdir)(Inode *, DirEntry *); int (*mknod)(Inode *, DirEntry *, mode_t, dev_t); int (*rename)(Inode *, DirEntry *, Inode *, DirEntry *); }; /* Structure for a Directory Entry */ struct DirEntry { Object obj; Inode *inode, *mnt; uint32_t hash; char name[NAME_MAX]; SuperBlock *super; }; /* Structure for an open File */ struct File { Object obj; Inode *inode; int flags; off_t pos; FileOps *ops; ObjectList *path; }; struct FileOps { size_t (*read)(File *, char *, size_t, off_t); size_t (*write)(File *, char *, size_t, off_t); int (*open)(File *); int (*ioctl)(File *, unsigned long, uintptr_t); int (*readdir)(File *, struct dirent *, off_t); void (*mmap)(File *, void *, size_t, off_t); }; extern ObjectType fstypeType; extern ObjectType fsType; extern ObjectType filesType; extern ObjectType superBlockType; extern ObjectType inodeType; extern ObjectType dirEntryType; extern ObjectType fileType; void init_vfs(void); File *create_anonymous_file(void); void register_fstype(const char *name, mount_callback_t mount); Inode *lookup(const char *path, ObjectList *newcustody); /* Super Block functions */ Inode *super_alloc_inode(SuperBlock *sb); Inode *super_find_inode(SuperBlock *sb, ino_t ino); /* Inode functions */ int permission(Inode *inode, int mask); int inode_create(Inode *inode, DirEntry *entry, mode_t mode); DirEntry *inode_lookup(Inode *inode, const char *name); int inode_mkdir(Inode *inode, DirEntry *entry, mode_t mode); int inode_rmdir(Inode *inode, DirEntry *entry); int inode_mknod(Inode *inode, DirEntry *entry, mode_t mode, dev_t dev); /* Directory Entry functions */ DirEntry *find_direntry(ObjectList *list, const char *name); /* File functions */ int file_open(File *file); size_t file_read(File *file, char *buf, size_t count); size_t file_write(File *file, char *buf, size_t count); int file_ioctl(File *file, unsigned long request, uintptr_t arpg); int file_readdir(File *file, struct dirent *dent, off_t index); void file_mmap(File *file, void *addr, size_t len, off_t offset); /* Files namespace functions */ File *get_file_by_fd(int fd); int allocate_fd(void); void install_fd(int fd, File *file); #endif