From c921197e69438f91520d0e70288386607b8dcd47 Mon Sep 17 00:00:00 2001 From: Bahadir Balban Date: Wed, 16 Jan 2008 01:37:24 +0000 Subject: [PATCH] A first step in writing a dynamically created bootfs for boot images. --- tasks/fs0/include/fs.h | 11 +++-- tasks/fs0/src/bootfs/bootfs.c | 82 +++++++++++++++++++++++++++++++++++ tasks/fs0/src/dentry.c | 0 tasks/fs0/src/init.c | 2 +- tasks/fs0/src/mount.c | 0 tasks/fs0/src/vfs.c | 25 ----------- tasks/fs0/src/vnode.c | 0 7 files changed, 90 insertions(+), 30 deletions(-) create mode 100644 tasks/fs0/src/bootfs/bootfs.c delete mode 100644 tasks/fs0/src/dentry.c delete mode 100644 tasks/fs0/src/mount.c delete mode 100644 tasks/fs0/src/vfs.c delete mode 100644 tasks/fs0/src/vnode.c diff --git a/tasks/fs0/include/fs.h b/tasks/fs0/include/fs.h index f2d36cf..b9be109 100644 --- a/tasks/fs0/include/fs.h +++ b/tasks/fs0/include/fs.h @@ -48,7 +48,7 @@ struct superblock_ops { struct dentry; struct file; -struct filesystem; +struct file_system_type; struct superblock; struct vnode; @@ -80,13 +80,16 @@ struct vnode { unsigned long size; /* Total size of vnode in bytes */ }; -struct filesystem { - unsigned long magic; +struct file_system_type { char name[256]; + unsigned long magic; + unsigned int flags; + struct superblock *(*get_sb)(void); + struct list_head sb_list; }; struct superblock { - struct filesystem fs; + struct file_system_type fs; struct superblock_ops ops; struct dentry *root_dirent; }; diff --git a/tasks/fs0/src/bootfs/bootfs.c b/tasks/fs0/src/bootfs/bootfs.c new file mode 100644 index 0000000..7682cce --- /dev/null +++ b/tasks/fs0/src/bootfs/bootfs.c @@ -0,0 +1,82 @@ +/* + * An imaginary filesystem for reading the in-memory + * server tasks loaded out of the initial elf executable. + * + * Copyright (C) 2007, 2008 Bahadir Balban + */ +#include +#include + +/* + * These are preallocated structures for forging a filesystem tree + * from the elf loaded server segments available from kdata info. + */ +#define BOOTFS_IMG_MAX 10 +struct vnode bootfs_vnode[BOOTFS_IMG_MAX]; +struct dentry bootfs_dentry[BOOTFS_IMG_MAX]; +struct file bootfs_file[BOOTFS_IMG_MAX]; + +/* These are for the root */ +struct dentry bootfs_root; +struct vnode bootfs_rootvn; + +void bootfs_init_root(struct dentry *r) +{ + struct vnode *v = r->vnode; + + /* Initialise dentry for rootdir */ + r->refcnt = 0; + strcpy(r->name, ""); + INIT_LIST_HEAD(&r->child); + INIT_LIST_HEAD(&r->children); + INIT_LIST_HEAD(&r->vref); + r->parent = r; + + /* Initialise vnode for rootdir */ + v->id = 0; + v->refcnt = 0; + INIT_LIST_HEAD(&v->dirents); + INIT_LIST_HEAD(&v->state_list); + list_add(&r->vref, &v->dirents); + v->size = 0; +} + +struct superblock *bootfs_init_sb(struct superblock *sb) +{ + sb->root = &bootfs_root; + sb->root->vnode = &bootfs_rootvn; + + bootfs_init_root(&sb->root); + + return sb; +} + +struct superblock bootfs_sb = { + .fs = bootfs_type, + .ops = { + .read_sb = bootfs_read_sb, + .write_sb = bootfs_write_sb, + .read_vnode = bootfs_read_vnode, + .write_vnode = bootfs_write_vnode, + }, +}; + +struct superblock *bootfs_get_sb(void) +{ + bootfs_init_sb(&bootfs_sb); + return &bootfs_sb; +} + +struct file_system_type bootfs_type = { + .name = "bootfs", + .magic = 0, + .get_sb = bootfs_get_sb, +}; + +void init_bootfs() +{ + struct superblock *sb; + + sb = bootfs_type.get_sb(); +} + diff --git a/tasks/fs0/src/dentry.c b/tasks/fs0/src/dentry.c deleted file mode 100644 index e69de29..0000000 diff --git a/tasks/fs0/src/init.c b/tasks/fs0/src/init.c index 1b32994..207fc95 100644 --- a/tasks/fs0/src/init.c +++ b/tasks/fs0/src/init.c @@ -43,7 +43,7 @@ void init_root(struct vnode *root_vn, struct dentry *root_d) root_vn->refcnt = 0; INIT_LIST_HEAD(&root_vn->dirents); INIT_LIST_HEAD(&root_vn->state_list); - list_add(&root_d->dref_list, &root_vn->dirents); + list_add(&root_d->vnlist, &root_vn->dirents); root_vn->size = 0; /* Initialise global struct rootdir ptr */ diff --git a/tasks/fs0/src/mount.c b/tasks/fs0/src/mount.c deleted file mode 100644 index e69de29..0000000 diff --git a/tasks/fs0/src/vfs.c b/tasks/fs0/src/vfs.c deleted file mode 100644 index ccd2bd0..0000000 --- a/tasks/fs0/src/vfs.c +++ /dev/null @@ -1,25 +0,0 @@ - -#include -#include -#include -#include - -/* Simply calls a wait ipc to sync with the given partner thread */ -void wait_task(l4id_t partner) -{ - u32 tag = L4_IPC_TAG_WAIT; - l4_ipc(partner, l4_nilthread, tag); - printf("%d synced with us.\n", (int)partner); -} - -void mount_root(void) -{ - /* - * We know the primary block device from compile-time. - * It is expected to have the root filesystem. - */ - wait_task(BLKDEV_TID); - - /* Set up a shared memory area with the block device */ -} - diff --git a/tasks/fs0/src/vnode.c b/tasks/fs0/src/vnode.c deleted file mode 100644 index e69de29..0000000