ext2: add ext2 driver v2

This driver is not yet feature complete, yet it is much cleaner than the
old one.
This commit is contained in:
Michael Shaw 2025-02-17 19:41:07 -05:00
commit 623cb5905a
5 changed files with 336 additions and 723 deletions

View file

@ -90,8 +90,6 @@ struct fs *devfs_init()
devfs->ops->write = devfs_write;
devfs->ops->unlink = devfs_unlink;
devfs->ops->open_vno = devfs_open_vno;
devfs->ops->readdir = devfs_readdir;
devfs->ops->open_dir = devfs_open_dir;
devfs->root->flags = VFS_VNO_DIR;
devfs->root->fs = devfs;

1063
fs/ext2.c

File diff suppressed because it is too large Load diff

View file

@ -132,15 +132,6 @@ struct file *vfs_open(const char *pathname, int *err)
goto out_2;
}
if (new_vnode->flags & VFS_VNO_DIR) {
int res = fs->ops->open_dir(new_vnode->fs, new_vnode);
if (res < 0) {
ATTEMPT_WRITE(err, res);
slab_free(vnode_slab, new_vnode);
goto out_2;
}
}
cur_vnode = new_vnode;
entry->vnode = cur_vnode;
}
@ -213,7 +204,6 @@ ssize_t vfs_read(struct file *file, void *buf, off_t off, size_t count)
if (off + count > file->vnode->size)
count = file->vnode->size - off;
return file->vnode->fs->ops->read(file->vnode, buf, off, count);
}
@ -456,14 +446,8 @@ struct fs *vfs_mount_root(const char *dev, const char *mount_point)
strcpy(fs->mount_point, mount_point);
struct vnode *root = fs->root;
struct dirent *dirents = NULL;
int num_dirents = fs->ops->readdir(root, &dirents);
if (num_dirents < 0)
goto out_dealloc_fs;
root->dirents = dirents;
root->num_dirents = num_dirents;
root->no_free = true;
return fs;
out_dealloc_fs:

View file

@ -146,6 +146,8 @@ struct ext2fs {
uint32_t bgdt_num_blocks;
struct ext2_group_desc *bgdt;
spinlock_t lock;
uint32_t indir_block_size;
uint32_t block_size;

View file

@ -117,10 +117,8 @@ struct file_descriptor {
struct fs_ops {
int (*read)(struct vnode *vnode, void *buf, size_t offset, size_t size);
int (*write)(struct vnode *vnode, void *buf, size_t offset, size_t size);
int (*readdir)(struct vnode *vnode, struct dirent **dir);
int (*unlink)(struct fs *fs, const char *path); /* change to vno, not path) */
int (*open_vno)(struct fs *vfs, struct vnode *out, ino_t ino_num);
int (*open_dir)(struct fs *vfs, struct vnode *out);
};
struct fs {