fs: move fs init into kernel cmdline

Previously, any partition with an ext2 filesystem would be mounted by
the gpt header parser. With this patch, the kernel cmdline `root=val` is
responsible for mounting the root filesystem.
This commit is contained in:
Michael Shaw 2023-10-19 11:08:54 -04:00
commit 25a828437a
10 changed files with 150 additions and 32 deletions

View file

@ -1,12 +1,38 @@
/* SDPX-License-Identifier: GPL-2.0-only */
#include <fs/vfs.h>
#include <kernel/slab.h>
#include <kernel/block.h>
#include <kernel/rbtree.h>
void vfs_init(struct block_device *root)
#include <fs/ext2.h>
#include <fs/vfs.h>
struct rbtree *kfd;
typedef struct fs *(*vfs_init_t)(struct block_device *);
void vfs_init(const char *rootfs)
{
kfd = kzalloc(sizeof(struct rbtree), ALLOC_DMA);
/* mount root */
struct block_device *rootdev = block_get_device(rootfs);
if (!rootdev) {
kprintf(LOG_ERROR "Failed to find root device %s\n", rootfs);
return;
} else {
kprintf(LOG_DEBUG "Found root device %s\n", rootfs);
/* TODO: detect filesystem type */
/* for now, assume ext2 */
struct fs *fs = ext2_init_fs(rootdev);
if (!fs) {
kprintf(LOG_ERROR "Failed to mount root device %s\n", rootfs);
return;
} else {
kprintf(LOG_DEBUG "Mounted root device %s\n", rootfs);
}
}
}
int write(int fd, const void *buf, size_t count)