From 5ebafca2e661a27d552929d251e1455e87838f40 Mon Sep 17 00:00:00 2001 From: Michael Shaw Date: Thu, 19 Oct 2023 01:03:27 -0400 Subject: [PATCH] vfs: add vfs stubs this also adds a small compatibility layer to the ext2 functions --- fs/ext2.c | 24 ++++++++++++++++--- fs/vfs.c | 28 ++++++++++++++++++++++ include/fs/ext2.h | 8 ------- include/fs/vfs.h | 59 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+), 11 deletions(-) create mode 100644 include/fs/vfs.h diff --git a/fs/ext2.c b/fs/ext2.c index e224423..42622e3 100644 --- a/fs/ext2.c +++ b/fs/ext2.c @@ -3,6 +3,7 @@ #include #include +#include static int ext2_read_super(struct block_device *bdev, struct ext2_superblock *sb_struct) { @@ -113,7 +114,7 @@ int ext2_write_inode(struct ext2fs *fs, struct ext2_inode *in, uint32_t inode) return 0; } -int ext2_open_file(struct ext2fs *fs, struct ext2_file *file, const char *path) +int ext2_open_file(struct ext2fs *fs, struct file *file, const char *path) { /* find the inode of the file */ struct ext2_inode *inode = kmalloc(sizeof(struct ext2_inode), ALLOC_KERN); @@ -137,6 +138,7 @@ int ext2_open_file(struct ext2fs *fs, struct ext2_file *file, const char *path) spinlock_acquire(&strtok_lock); char *token = strtok(path_copy, "/"); + uint32_t inode_no = 2; while (token) { struct ext2_dir_entry *entry = kmalloc(fs->block_size, ALLOC_DMA); if (!entry) { @@ -166,6 +168,7 @@ int ext2_open_file(struct ext2fs *fs, struct ext2_file *file, const char *path) kfree(name); + inode_no = entry->inode; entry = (void *)entry + entry->rec_len; } @@ -185,9 +188,9 @@ int ext2_open_file(struct ext2fs *fs, struct ext2_file *file, const char *path) kfree(path_copy); - file->inode = *inode; - file->offset = 0; + memcpy(&file->inode, inode, sizeof(struct inode)); file->size = inode->size; + file->inode_num = inode_no; /* check for long filesize */ if (fs->sb.feature_ro_compat & EXT2_FLAG_LONG_FILESIZE) @@ -196,6 +199,21 @@ int ext2_open_file(struct ext2fs *fs, struct ext2_file *file, const char *path) return 0; } +int ext2_close_file(struct ext2fs *fs, struct file *file) +{ + return 0; +} + +int ext2_write_file(struct ext2fs *fs, struct file *file, const void *buf, size_t count) +{ + return 0; +} + +int ext2_read_file(struct ext2fs *fs, struct file *file, const void *buf, size_t count) +{ + return 0; +} + #ifdef KDEBUG static void ext2_print_dir(struct ext2fs *fs, struct ext2_inode *inode, int indent) { diff --git a/fs/vfs.c b/fs/vfs.c index 0bba9d5..c6f9d98 100644 --- a/fs/vfs.c +++ b/fs/vfs.c @@ -1,2 +1,30 @@ /* SDPX-License-Identifier: GPL-2.0-only */ +#include +#include +#include + +void vfs_init(struct block_device *root) +{ + +} + +int write(int fd, const void *buf, size_t count) +{ + return 0; +} + +int read(int fd, void *buf, size_t count) +{ + return 0; +} + +int open(const char *pathname, int flags) +{ + return 0; +} + +int close(int fd) +{ + return 0; +} diff --git a/include/fs/ext2.h b/include/fs/ext2.h index e759173..5368214 100644 --- a/include/fs/ext2.h +++ b/include/fs/ext2.h @@ -132,14 +132,6 @@ struct ext2_dir_entry { char name[]; } PACKED; -struct ext2_file { - struct ext2_inode inode; - uint32_t block; - uint32_t offset; - uint64_t size; - uint32_t pos; -}; - struct ext2fs { struct ext2_superblock sb; struct block_device *bdev; diff --git a/include/fs/vfs.h b/include/fs/vfs.h new file mode 100644 index 0000000..d4559b0 --- /dev/null +++ b/include/fs/vfs.h @@ -0,0 +1,59 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _VFS_H_ +#define _VFS_H_ + +#include + +#define VFS_TYPE_EXT2 0x0001 + +struct inode { + uint16_t mode; + uint16_t uid; + uint32_t size; + + uint32_t atime; + uint32_t ctime; + uint32_t mtime; + uint32_t dtime; + + uint16_t gid; + uint16_t links_count; + uint32_t blocks; + uint32_t flags; + uint32_t osd1; + uint32_t block[12]; + + uint32_t block_indirect; + uint32_t block_dindirect; + uint32_t block_tindirect; + + uint32_t generation; + uint32_t file_acl; + uint32_t dir_acl; + uint32_t faddr; +} PACKED; /* PACKED to allow for memcpy */ + +struct file { + struct inode inode; + + uint32_t inode_num; /* inode number */ + uint64_t size; /* size of the file */ + uint64_t pos; /* current position in the file */ + + void *fs_data; +}; + +struct fs_ops { + int (*read)(void *fs, struct file *file, void *buf, size_t offset, size_t size); + int (*write)(void *fs, struct file *file, void *buf, size_t offset, size_t size); + int (*open)(void *fs, struct file *file, const char *path); + int (*close)(void *fs, struct file *file); +}; + +struct fs { + void *fs; + uint32_t type; + struct fs_ops ops; +}; + +#endif /* _VFS_H_ */