FS0 compiles now, with a mock-up rootfs.

Having progress on vfs slowly but surely ;-)
This commit is contained in:
Bahadir Balban
2008-01-15 00:34:10 +00:00
parent efd797c678
commit 6bb5b45212
14 changed files with 174 additions and 275 deletions

View File

@@ -22,7 +22,7 @@ struct file_ops {
file_op_t write;
file_op_t close;
file_op_t mmap;
file_op_t seek;
file_op_t lseek;
file_op_t flush;
file_op_t fsync;
};
@@ -52,11 +52,14 @@ struct filesystem;
struct superblock;
struct vnode;
#define VFS_DENTRY_NAME_MAX 512
struct dentry {
int refcnt;
char name[512];
char name[VFS_DENTRY_NAME_MAX];
struct dentry *parent; /* Parent dentry */
struct list_head siblings; /* List of dentries with same parent */
struct list_head child; /* List of dentries with same parent */
struct list_head children; /* List of children dentries */
struct list_head dref_list; /* For vnode's dirent reference list */
struct vnode *vnode; /* The vnode associated with dirent */
struct dentry_ops ops;
};
@@ -70,6 +73,7 @@ struct file {
struct vnode {
unsigned long id; /* Filesystem-wide unique vnode id */
int refcnt; /* Reference counter */
int hardlinks; /* Number of hard links */
struct vnode_ops ops; /* Operations on this vnode */
struct list_head dirents; /* Dirents that refer to this vnode */
struct list_head state_list; /* List for vnode's dirty/clean state */

View File

@@ -15,7 +15,6 @@
struct initdata {
struct bootdesc *bootdesc;
struct block_device *bdev;
};
extern struct initdata initdata;

View File

@@ -0,0 +1,14 @@
/*
* System call function signatures.
*
* Copyright (C) 2007, 2008 Bahadir Balban
*/
#ifndef __FS0_SYSCALLS_H__
#define __FS0_SYSCALLS_H__
int sys_open(l4id_t sender, char *pathname, int flags, u32 mode);
int sys_read(l4id_t sender, int fd, void *buf, int cnt);
int sys_write(l4id_t sender, int fd, void *buf, int cnt);
int sys_lseek(l4id_t sender, int fd, unsigned long offset, int whence);
#endif /* __FS0_SYSCALLS_H__ */

View File

@@ -7,18 +7,21 @@
#include <string.h>
#include <l4lib/arch/message.h>
#include <l4lib/arch/syscalls.h>
#include <l4lib/arch/syslib.h>
#include <l4lib/kip.h>
#include <l4lib/utcb.h>
#include <l4lib/ipcdefs.h>
#include <fs.h>
#include <init.h>
#include <kdata.h>
#include <syscalls.h>
#include <task.h>
/* Synchronise with pager via a `wait' tagged ipc with destination as pager */
void wait_pager(l4id_t partner)
{
u32 tag = L4_IPC_TAG_WAIT;
printf("Going to wait till pager finishes dumping.\n");
l4_ipc(partner, l4_nilthread, tag);
printf("Pager synced with us.\n");
l4_send(partner, L4_IPC_TAG_WAIT);
printf("%s: Pager synced with us.\n", __TASKNAME__);
}
void handle_fs_requests(void)
@@ -68,6 +71,8 @@ void handle_fs_requests(void)
void main(void)
{
initialise();
wait_pager(PAGER_TID);
while (1) {

120
tasks/fs0/src/init.c Normal file
View File

@@ -0,0 +1,120 @@
/*
* FS0 Initialisation.
*
* Copyright (C) 2007 Bahadir Balban
*/
#include <kdata.h>
#include <fs.h>
#include <string.h>
#include <stdio.h>
#include <l4/lib/list.h>
#include <init.h>
struct filesystem bootfs = {
.magic = 0,
.name = "Tempfs for boot images",
};
struct superblock bootfs_sb;
#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];
struct rootdir {
struct dentry *d;
struct filesystem *fs;
};
struct rootdir bootfs_root;
void init_root(struct vnode *root_vn, struct dentry *root_d)
{
/* Initialise dentry for rootdir */
root_d->refcnt = 0;
strcpy(root_d->name, "");
INIT_LIST_HEAD(&root_d->child);
INIT_LIST_HEAD(&root_d->children);
INIT_LIST_HEAD(&root_d->dref_list);
root_d->vnode = root_vn;
/* Initialise vnode for rootdir */
root_vn->id = 0;
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);
root_vn->size = 0;
/* Initialise global struct rootdir ptr */
bootfs_root.d = root_d;
bootfs_root.fs = &bootfs;
}
#define PATH_SEP "/"
#define PATH_CURDIR "."
#define PATH_OUTDIR ".."
void fs_debug_list_all(struct dentry *root)
{
struct dentry *d;
int stotal = 0;
/* List paths first */
printf("%s%s\n", root->name, PATH_SEP);
list_for_each_entry(d, &root->children, child) {
printf("%s%s%s, size: 0x%x\n", d->parent->name, PATH_SEP, d->name, d->vnode->size);
stotal += d->vnode->size;
}
}
void init_bootfs(struct initdata *initdata)
{
struct bootdesc *bd = initdata->bootdesc;
struct dentry *img_d = &bootfs_dentry[1];
struct vnode *img_vn = &bootfs_vnode[1];
struct file *img_f = &bootfs_file[1];
struct svc_image *img;
/* The first vfs object slot is for the root */
init_root(&bootfs_vnode[0], &bootfs_dentry[0]);
BUG_ON(bd->total_images >= BOOTFS_IMG_MAX);
for (int i = 0; i < bd->total_images; i++) {
img = &bd->images[i];
/* Initialise dentry for image */
img_d->refcnt = 0;
strncpy(img_d->name, img->name, VFS_DENTRY_NAME_MAX);
INIT_LIST_HEAD(&img_d->child);
INIT_LIST_HEAD(&img_d->children);
img_d->vnode = img_vn;
img_d->parent = bootfs_root.d;
list_add(&img_d->child, &bootfs_root.d->children);
/* Initialise vnode for image */
img_vn->id = img->phys_start;
img_vn->refcnt = 0;
INIT_LIST_HEAD(&img_vn->dirents);
list_add(&img_d->dref_list, &img_vn->dirents);
img_vn->size = img->phys_end - img->phys_start;
/* Initialise file struct for image */
img_f->refcnt = 0;
img_f->dentry = img_d;
img_d++;
img_vn++;
img_f++;
}
}
void initialise(void)
{
request_initdata(&initdata);
init_bootfs(&initdata);
/* A debug call that lists all vfs structures */
fs_debug_list_all(bootfs_root.d);
}