mirror of
https://github.com/drasko/codezero.git
synced 2026-01-12 02:43:15 +01:00
A first step in writing a dynamically created bootfs for boot images.
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
82
tasks/fs0/src/bootfs/bootfs.c
Normal file
82
tasks/fs0/src/bootfs/bootfs.c
Normal file
@@ -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 <fs.h>
|
||||
#include <l4/lib/list.h>
|
||||
|
||||
/*
|
||||
* 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();
|
||||
}
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <l4/api/ipc.h>
|
||||
#include <l4lib/kip.h>
|
||||
#include <l4lib/arch/syscalls.h>
|
||||
|
||||
/* 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 */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user