/* SPDX-License-Identifier: GPL-2.0-only */ #ifndef _VFS_H_ #define _VFS_H_ #include #include #include #include #include #define FILE_NAME_MAX_LEN 255 #define S_IFMT 0xF000 #define S_IFREG 0x8000 #define S_IFDIR 0x4000 #define S_IFLNK 0xA000 #define S_IFCHR 0x2000 #define S_IFBLK 0x6000 #define S_IFIFO 0x1000 #define S_IFSOCK 0xC000 #define S_ISUID 0004000 /* setuid */ #define S_ISGID 0002000 /* setgid */ #define S_ISVTX 0001000 /* sticky bit */ #define S_IRWXU 0000700 /* owner mask */ #define S_IRUSR 0000400 #define S_IWUSR 0000200 #define S_IXUSR 0000100 #define S_IRWXG 0000070 /* group mask */ #define S_IRGRP 0000040 #define S_IWGRP 0000020 #define S_IXGRP 0000010 #define S_IRWXO 0000007 /* other mask */ #define S_IROTH 0000004 #define S_IWOTH 0000002 #define S_IXOTH 0000001 #define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO) #define FT_MASK 0x07 #define FT_UNKNOWN 0x00 #define FT_REG_FILE 0x01 #define FT_DIR 0x02 #define FT_CHRDEV 0x03 #define FT_BLKDEV 0x04 #define FT_FIFO 0x05 #define FT_SOCK 0x06 #define FT_SYMLINK 0x07 #define FS_RDONLY 0x00000001 struct block_device; struct fs_driver { char name[FILE_NAME_MAX_LEN + 1]; int (*init)(int flags, struct block_device *to_mount, fs_t **out); int (*deinit)(fs_t *fs); }; struct fs_ops { int (*alloc_inode)(fs_t *fs, u64 mode, inode_t **out); int (*free_inode)(fs_t *fs, inode_t *inode); int (*open_inode)(fs_t *fs, u64 id, dirent_t *dirent, inode_t **out); }; struct _fs { u64 type; u64 flags; size_t block_size; size_t n_blocks; void *priv; dirent_t *root_dirent; bool mounted; dirent_t *mount_point; spinlock_t lock; struct fs_ops fs_ops; }; struct dir_context { void *cookie; bool init; }; struct mount { struct mount *parent; list_t children; list_item_t *child_link; fs_t *fs; dirent_t *mountpoint; u64 flags; }; struct fildes { u64 fdno; dirent_t *file; struct proc *proc; }; void vfs_init(void); void vfs_register(struct fs_driver *fs); int vfs_open(const char *abs_path, dirent_t **out); int vfs_openat(struct mount *mnt, dirent_t *in, const char *name, dirent_t **out, struct mount **out_mnt, bool follow); void vfs_close(dirent_t *dent); int vfs_readdir(dirent_t *dir, struct dir_context *ctx, dirent_t **out); int vfs_creat(dirent_t *parent, const char *name, u64 mode, int flags, dirent_t **out); int vfs_unlink(dirent_t *parent, const char *name); int vfs_mount(const char *path, fs_t *fs, u64 flags); int vfs_umount(const char *path); fs_t *vfs_get_root(void); struct mount *vfs_get_root_mount(void); struct mount *mount_find_child(struct mount *parent, dirent_t *dent); ssize_t vfs_write(inode_t *ino, const char *buf, size_t size, size_t offset); ssize_t vfs_read(inode_t *ino, char *buf, size_t size, size_t offset); #endif /* _VFS_H_ */