// vfs.h // Author: Josh Holtrop // Date: 08/22/04 // Modified: 12/21/04 #ifndef __HOS_VFS_H__ #define __HOS_VFS_H__ __HOS_VFS_H__ #include "hos_defines.h" #include "fs/devices.h" #define FS_EXT2 1 #define VFS_MAX_FS 10 #define VFS_FT_UNKNOWN 0 #define VFS_FT_FILE 1 #define VFS_FT_DIR 2 #define VFS_FT_CHAR 3 #define VFS_FT_BLOCK 4 #define VFS_FT_FIFO 5 #define VFS_FT_SOCK 6 #define VFS_FT_SYMLINK 7 #define VFS_PERMS_OX 0x0001 #define VFS_PERMS_OW 0x0002 #define VFS_PERMS_OR 0x0004 #define VFS_PERMS_GX 0x0008 #define VFS_PERMS_GW 0x0010 #define VFS_PERMS_GR 0x0020 #define VFS_PERMS_UX 0x0040 #define VFS_PERMS_UW 0x0080 #define VFS_PERMS_UR 0x0100 #define VFS_PERMS_STICKY 0x0200 #define VFS_PERMS_SGID 0x0400 #define VFS_PERMS_SUID 0x0800 #define EOF 1000000 /* Structure to hold information about a mount point */ typedef struct { int refs; void *super; int fs; major_t major; minor_t minor; } vfs_mount_t; /* This structure represents a node of the "VFS Mount Tree" */ struct vfs_node_s { char chr; // the character we are at vfs_mount_t *mount; // is there a mount at this character? struct vfs_node_s *up; // the parent struct vfs_node_s *next; // the next sibling struct vfs_node_s *down; // subtree for submounts }; typedef struct vfs_node_s vfs_node_t; /* This structure is generated when a path is matched. For example, if /dev is mounted on device (4,2) and '/dev/yoda' is looked up, the structure returned would be {4, 2, 4} and then the lookup could continue on device (4,2) with 4 characters stripped off the front of the initial path (ex '/yoda') */ typedef struct { vfs_mount_t *mount; int length; } vfs_mount_match_t; typedef struct { u16_t type; // file type, of VFS_FILE_TYPE_* u32_t size; u32_t inode; u16_t permissions; u16_t uid; u16_t gid; u32_t atime; u32_t mtime; u32_t ctime; u16_t links; u32_t dev; } vfs_stat_t; typedef struct { vfs_mount_t *mount; void *fs_data; } vfs_open_file_t; typedef struct { char name[257]; } vfs_dir_entry_t; /* Every filesystem must provide pointers to its respective functions in a structure like this */ typedef struct { void *(*mount_super)(major_t major, minor_t minor); int (*umount_super)(vfs_mount_t *mount); int (*stat)(vfs_mount_t *mount, char *file, vfs_stat_t *stat); int (*open_dir)(vfs_mount_t *mount, char *file, vfs_open_file_t *dir); int (*read_dir)(vfs_mount_t *mount, vfs_open_file_t *dir, vfs_dir_entry_t *dentry); int (*close_dir)(vfs_mount_t *mount, vfs_open_file_t *dir); int (*open_file)(vfs_mount_t *mount, char *file, vfs_open_file_t *open_file); int (*read_file)(vfs_mount_t *mount, vfs_open_file_t *open_file); int (*close_file)(vfs_mount_t *mount, vfs_open_file_t *open_file); int (*open_block_file)(vfs_mount_t *mount, char *file, vfs_open_file_t *open_file); int (*read_block_file)(vfs_mount_t *mount, vfs_open_file_t *open_file, void *buffer); int (*block_file_seek)(vfs_mount_t *mount, vfs_open_file_t *open_file, u32_t block_number); int (*close_block_file)(vfs_mount_t *mount, vfs_open_file_t *open_file); } vfs_fs_t; int vfs_init(); int vfs_mount(major_t maj, minor_t min, int fsType, char *mountPoint); int vfs_register_fs(int fsn, vfs_fs_t *fs); int vfs_add_mount(vfs_mount_t *mnt, char *mountPoint); vfs_mount_t *vfs_find_mount(char *mountPoint); vfs_mount_match_t vfs_get_rel_path(char *path); int vfs_umount(char *mountPoint); int vfs_retire_node(vfs_node_t *node); int vfs_stat(char *file, vfs_stat_t *stat); vfs_open_file_t *vfs_open_dir(char *file); int vfs_read_dir(vfs_open_file_t *open_dir, vfs_dir_entry_t *dentry); int vfs_close_dir(vfs_open_file_t *open_dir); vfs_open_file_t *vfs_open_block_file(char *file); int vfs_read_block_file(vfs_open_file_t *open_file, void *buffer); int vfs_block_file_seek(vfs_open_file_t *open_file, u32_t block_number); int vfs_close_block_file(vfs_open_file_t *open_file); // DEBUG routines void vfs_dump_tree(); void vfs_dump_node(vfs_node_t *node, int level); #endif