vfs: change fs_ops struct in fs to a pointer
This commit is contained in:
parent
7832f4a896
commit
ad16d47783
3 changed files with 24 additions and 14 deletions
24
fs/ext2.c
24
fs/ext2.c
|
|
@ -15,6 +15,8 @@
|
||||||
#define ITYPE_DECL(_ino, _de) [(_ino >> 12)] = (_de)
|
#define ITYPE_DECL(_ino, _de) [(_ino >> 12)] = (_de)
|
||||||
#define DTYPE_DECL(_de, _ino) [(_de)] = (_ino)
|
#define DTYPE_DECL(_de, _ino) [(_de)] = (_ino)
|
||||||
|
|
||||||
|
static struct fs_ops *ext2_ops;
|
||||||
|
|
||||||
static uint8_t inode_to_ftype[] = {
|
static uint8_t inode_to_ftype[] = {
|
||||||
ITYPE_DECL(EXT2_INO_FIFO, VFS_FILE_FIFO), ITYPE_DECL(EXT2_INO_CHARDEV, VFS_FILE_CHARDEV),
|
ITYPE_DECL(EXT2_INO_FIFO, VFS_FILE_FIFO), ITYPE_DECL(EXT2_INO_CHARDEV, VFS_FILE_CHARDEV),
|
||||||
ITYPE_DECL(EXT2_INO_DIR, VFS_FILE_DIR), ITYPE_DECL(EXT2_INO_BLKDEV, VFS_FILE_BLKDEV),
|
ITYPE_DECL(EXT2_INO_DIR, VFS_FILE_DIR), ITYPE_DECL(EXT2_INO_BLKDEV, VFS_FILE_BLKDEV),
|
||||||
|
|
@ -1162,14 +1164,22 @@ struct fs *ext2_init_fs(struct block_device *bdev)
|
||||||
ret->fs = extfs;
|
ret->fs = extfs;
|
||||||
ret->type = VFS_TYPE_EXT2;
|
ret->type = VFS_TYPE_EXT2;
|
||||||
|
|
||||||
struct fs_ops ops = { .open = ext2_open_file,
|
ext2_ops = kmalloc(sizeof(struct fs_ops), ALLOC_KERN);
|
||||||
.read = ext2_read_file,
|
|
||||||
.write = ext2_write_file,
|
|
||||||
.readdir = ext2_readdir,
|
|
||||||
.mkdir = ext2_mkdir,
|
|
||||||
.unlink = ext2_unlink };
|
|
||||||
|
|
||||||
ret->ops = ops;
|
if(!ext2_ops) {
|
||||||
|
kfree(extfs->bgdt);
|
||||||
|
kfree(extfs);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ext2_ops->open = ext2_open_file;
|
||||||
|
ext2_ops->read = ext2_read_file;
|
||||||
|
ext2_ops->write = ext2_write_file;
|
||||||
|
ext2_ops->readdir = ext2_readdir;
|
||||||
|
ext2_ops->mkdir = ext2_mkdir;
|
||||||
|
ext2_ops->unlink = ext2_unlink;
|
||||||
|
|
||||||
|
ret->ops = ext2_ops;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
12
fs/vfs.c
12
fs/vfs.c
|
|
@ -29,7 +29,7 @@ int write(int fd, void *buf, size_t count)
|
||||||
if (fdesc->file.type != VFS_FILE_FILE)
|
if (fdesc->file.type != VFS_FILE_FILE)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
int ret = fdesc->fs->ops.write(fdesc->fs, &fdesc->file, buf, fdesc->pos, count);
|
int ret = fdesc->fs->ops->write(fdesc->fs, &fdesc->file, buf, fdesc->pos, count);
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
@ -54,7 +54,7 @@ int read(int fd, void *buf, size_t count)
|
||||||
if (fdesc->file.type != VFS_FILE_FILE)
|
if (fdesc->file.type != VFS_FILE_FILE)
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
int ret = fdesc->fs->ops.read(fdesc->fs, &fdesc->file, buf, fdesc->pos, count);
|
int ret = fdesc->fs->ops->read(fdesc->fs, &fdesc->file, buf, fdesc->pos, count);
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
@ -90,7 +90,7 @@ int open(const char *pathname, int flags)
|
||||||
memset(fd, 0, sizeof(struct file_descriptor));
|
memset(fd, 0, sizeof(struct file_descriptor));
|
||||||
|
|
||||||
/* find the file */
|
/* find the file */
|
||||||
int result = rootfs->ops.open(rootfs, &fd->file, pathname);
|
int result = rootfs->ops->open(rootfs, &fd->file, pathname);
|
||||||
|
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
kprintf(LOG_ERROR "Failed to open %s: %s\n", pathname, strerror(-result));
|
kprintf(LOG_ERROR "Failed to open %s: %s\n", pathname, strerror(-result));
|
||||||
|
|
@ -166,12 +166,12 @@ size_t tell(int fd)
|
||||||
|
|
||||||
int unlink(const char *pathname)
|
int unlink(const char *pathname)
|
||||||
{
|
{
|
||||||
return rootfs->ops.unlink(rootfs, pathname);
|
return rootfs->ops->unlink(rootfs, pathname);
|
||||||
}
|
}
|
||||||
|
|
||||||
int mkdir(const char *pathname)
|
int mkdir(const char *pathname)
|
||||||
{
|
{
|
||||||
return rootfs->ops.mkdir(rootfs, pathname);
|
return rootfs->ops->mkdir(rootfs, pathname);
|
||||||
}
|
}
|
||||||
|
|
||||||
DIR *opendir(const char *name)
|
DIR *opendir(const char *name)
|
||||||
|
|
@ -215,7 +215,7 @@ struct dirent *readdir(DIR *dir)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (dir->dirents == NULL)
|
if (dir->dirents == NULL)
|
||||||
dir->num_dirents = fs->ops.readdir(fs, file->inode_num, &dir->dirents);
|
dir->num_dirents = fs->ops->readdir(fs, file->inode_num, &dir->dirents);
|
||||||
|
|
||||||
if (dir->dirents == NULL)
|
if (dir->dirents == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,7 @@ struct fs_ops {
|
||||||
struct fs {
|
struct fs {
|
||||||
void *fs;
|
void *fs;
|
||||||
uint32_t type;
|
uint32_t type;
|
||||||
struct fs_ops ops;
|
struct fs_ops *ops;
|
||||||
|
|
||||||
char *mount_point;
|
char *mount_point;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue