123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269 |
- #pragma once
- #include <common/glib.h>
- #include <common/fcntl.h>
- #include <common/blk_types.h>
- #include <mm/slab.h>
- extern struct vfs_superblock_t *vfs_root_sb;
- #define VFS_DPT_MBR 0
- #define VFS_DPT_GPT 1
- #define VFS_SUCCESS 0
- #define VFS_E_FS_EXISTED 1
- #define VFS_E_FS_NOT_EXIST 2
- #define VFS_MAX_PATHLEN 1024
- #define VFS_IF_FILE (1UL << 0)
- #define VFS_IF_DIR (1UL << 1)
- #define VFS_IF_DEVICE (1UL << 2)
- #define VFS_IF_DEAD (1UL << 3)
- struct vfs_super_block_operations_t;
- struct vfs_inode_operations_t;
- struct vfs_index_node_t;
- struct vfs_dir_entry_operations_t;
- #define VFS_DF_MOUNTED (1 << 0)
- #define VFS_DF_CANNOT_MOUNT (1 << 1)
- struct vfs_dir_entry_t
- {
- char *name;
- int name_length;
- uint32_t d_flags;
- struct List child_node_list;
- struct List subdirs_list;
- struct vfs_index_node_t *dir_inode;
- struct vfs_dir_entry_t *parent;
- struct vfs_dir_entry_operations_t *dir_ops;
- };
- struct vfs_superblock_t
- {
- struct vfs_dir_entry_t *root;
- struct vfs_super_block_operations_t *sb_ops;
- struct vfs_dir_entry_operations_t *dir_ops;
- struct block_device *blk_device;
- void *private_sb_info;
- };
- struct vfs_index_node_t
- {
- uint64_t file_size;
- uint64_t blocks;
- uint64_t attribute;
- int32_t ref_count;
- struct vfs_superblock_t *sb;
- struct vfs_file_operations_t *file_ops;
- struct vfs_inode_operations_t *inode_ops;
- void *private_inode_info;
- };
- #define VFS_FILE_MODE_READ (1 << 0)
- #define VFS_FILE_MODE_WRITE (1 << 1)
- #define VFS_FILE_MODE_RW (VFS_FILE_MODE_READ | VFS_FILE_MODE_WRITE)
- #define vfs_file_can_read(file) (((file)->mode) & VFS_FILE_MODE_READ)
- #define vfs_file_can_write(file) (((file)->mode) & VFS_FILE_MODE_WRITE)
- #define vfs_file_can_rw(file) ((((file)->mode) & VFS_FILE_MODE_RW) == VFS_FILE_MODE_RW)
- struct vfs_file_t
- {
- long position;
- uint64_t mode;
- struct vfs_dir_entry_t *dEntry;
- struct vfs_file_operations_t *file_ops;
- void *private_data;
- };
- struct vfs_filesystem_type_t
- {
- char *name;
- int fs_flags;
- struct vfs_superblock_t *(*read_superblock)(struct block_device *blk);
- struct vfs_filesystem_type_t *next;
- };
- struct vfs_super_block_operations_t
- {
- void (*write_superblock)(struct vfs_superblock_t *sb);
- void (*put_superblock)(struct vfs_superblock_t *sb);
- void (*write_inode)(struct vfs_index_node_t *inode);
- };
- struct vfs_inode_operations_t
- {
-
- long (*create)(struct vfs_index_node_t *parent_inode, struct vfs_dir_entry_t *dest_dEntry, int mode);
-
- struct vfs_dir_entry_t *(*lookup)(struct vfs_index_node_t *parent_inode, struct vfs_dir_entry_t *dest_dEntry);
-
- long (*mkdir)(struct vfs_index_node_t *inode, struct vfs_dir_entry_t *dEntry, int mode);
- long (*rmdir)(struct vfs_index_node_t *inode, struct vfs_dir_entry_t *dEntry);
- long (*rename)(struct vfs_index_node_t *old_inode, struct vfs_dir_entry_t *old_dEntry, struct vfs_index_node_t *new_inode, struct vfs_dir_entry_t *new_dEntry);
- long (*getAttr)(struct vfs_dir_entry_t *dEntry, uint64_t *attr);
- long (*setAttr)(struct vfs_dir_entry_t *dEntry, uint64_t *attr);
- };
- struct vfs_dir_entry_operations_t
- {
- long (*compare)(struct vfs_dir_entry_t *parent_dEntry, char *source_filename, char *dest_filename);
- long (*hash)(struct vfs_dir_entry_t *dEntry, char *filename);
- long (*release)(struct vfs_dir_entry_t *dEntry);
- long (*iput)(struct vfs_dir_entry_t *dEntry, struct vfs_index_node_t *inode);
- };
- typedef int (*vfs_filldir_t)(void *buf, ino_t d_ino, char *name, int namelen, unsigned char type, off_t offset);
- struct vfs_file_operations_t
- {
- long (*open)(struct vfs_index_node_t *inode, struct vfs_file_t *file_ptr);
- long (*close)(struct vfs_index_node_t *inode, struct vfs_file_t *file_ptr);
- long (*read)(struct vfs_file_t *file_ptr, char *buf, int64_t count, long *position);
- long (*write)(struct vfs_file_t *file_ptr, char *buf, int64_t count, long *position);
- long (*lseek)(struct vfs_file_t *file_ptr, long offset, long origin);
- long (*ioctl)(struct vfs_index_node_t *inode, struct vfs_file_t *file_ptr, uint64_t cmd, uint64_t arg);
- long (*readdir)(struct vfs_file_t *file_ptr, void *dirent, vfs_filldir_t filler);
- };
- uint64_t vfs_register_filesystem(struct vfs_filesystem_type_t *fs);
- uint64_t vfs_unregister_filesystem(struct vfs_filesystem_type_t *fs);
- struct vfs_superblock_t *vfs_mount_fs(const char *path, char *name, struct block_device *blk);
- struct vfs_dir_entry_t *vfs_path_walk(const char *path, uint64_t flags);
- int vfs_fill_dirent(void *buf, ino_t d_ino, char *name, int namelen, unsigned char type, off_t offset);
- int vfs_init();
- struct vfs_dir_entry_t *vfs_alloc_dentry(const int name_size);
- struct vfs_index_node_t *vfs_alloc_inode();
- uint64_t do_open(const char *filename, int flags);
- int64_t vfs_mkdir(const char *path, mode_t mode, bool from_userland);
- int64_t vfs_rmdir(const char *path, bool from_userland);
|