vfs: add vfs stubs
this also adds a small compatibility layer to the ext2 functions
This commit is contained in:
parent
e3efdde2df
commit
5ebafca2e6
4 changed files with 108 additions and 11 deletions
24
fs/ext2.c
24
fs/ext2.c
|
|
@ -3,6 +3,7 @@
|
||||||
#include <dev/console.h>
|
#include <dev/console.h>
|
||||||
|
|
||||||
#include <fs/ext2.h>
|
#include <fs/ext2.h>
|
||||||
|
#include <fs/vfs.h>
|
||||||
|
|
||||||
static int ext2_read_super(struct block_device *bdev, struct ext2_superblock *sb_struct)
|
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;
|
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 */
|
/* find the inode of the file */
|
||||||
struct ext2_inode *inode = kmalloc(sizeof(struct ext2_inode), ALLOC_KERN);
|
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);
|
spinlock_acquire(&strtok_lock);
|
||||||
|
|
||||||
char *token = strtok(path_copy, "/");
|
char *token = strtok(path_copy, "/");
|
||||||
|
uint32_t inode_no = 2;
|
||||||
while (token) {
|
while (token) {
|
||||||
struct ext2_dir_entry *entry = kmalloc(fs->block_size, ALLOC_DMA);
|
struct ext2_dir_entry *entry = kmalloc(fs->block_size, ALLOC_DMA);
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
|
|
@ -166,6 +168,7 @@ int ext2_open_file(struct ext2fs *fs, struct ext2_file *file, const char *path)
|
||||||
|
|
||||||
kfree(name);
|
kfree(name);
|
||||||
|
|
||||||
|
inode_no = entry->inode;
|
||||||
entry = (void *)entry + entry->rec_len;
|
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);
|
kfree(path_copy);
|
||||||
|
|
||||||
file->inode = *inode;
|
memcpy(&file->inode, inode, sizeof(struct inode));
|
||||||
file->offset = 0;
|
|
||||||
file->size = inode->size;
|
file->size = inode->size;
|
||||||
|
file->inode_num = inode_no;
|
||||||
|
|
||||||
/* check for long filesize */
|
/* check for long filesize */
|
||||||
if (fs->sb.feature_ro_compat & EXT2_FLAG_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;
|
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
|
#ifdef KDEBUG
|
||||||
static void ext2_print_dir(struct ext2fs *fs, struct ext2_inode *inode, int indent)
|
static void ext2_print_dir(struct ext2fs *fs, struct ext2_inode *inode, int indent)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
28
fs/vfs.c
28
fs/vfs.c
|
|
@ -1,2 +1,30 @@
|
||||||
/* SDPX-License-Identifier: GPL-2.0-only */
|
/* SDPX-License-Identifier: GPL-2.0-only */
|
||||||
|
|
||||||
|
#include <fs/vfs.h>
|
||||||
|
#include <kernel/slab.h>
|
||||||
|
#include <kernel/block.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -132,14 +132,6 @@ struct ext2_dir_entry {
|
||||||
char name[];
|
char name[];
|
||||||
} PACKED;
|
} PACKED;
|
||||||
|
|
||||||
struct ext2_file {
|
|
||||||
struct ext2_inode inode;
|
|
||||||
uint32_t block;
|
|
||||||
uint32_t offset;
|
|
||||||
uint64_t size;
|
|
||||||
uint32_t pos;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ext2fs {
|
struct ext2fs {
|
||||||
struct ext2_superblock sb;
|
struct ext2_superblock sb;
|
||||||
struct block_device *bdev;
|
struct block_device *bdev;
|
||||||
|
|
|
||||||
59
include/fs/vfs.h
Normal file
59
include/fs/vfs.h
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||||
|
#ifndef _VFS_H_
|
||||||
|
#define _VFS_H_
|
||||||
|
|
||||||
|
#include <kernel/common.h>
|
||||||
|
|
||||||
|
#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_ */
|
||||||
Loading…
Reference in a new issue