Finished adding untested bare functionality vfs

Finished adding untested shm syscalls.
Finished adding untested l4 send/recv helpers

Everything compiles. Now going to fix lots of bugs ;-)
This commit is contained in:
Bahadir Balban
2008-02-03 17:42:38 +00:00
parent 05e9028e90
commit cab2e8bdd3
51 changed files with 1661 additions and 227 deletions

8
tasks/fs0/include/bdev.h Normal file
View File

@@ -0,0 +1,8 @@
#ifndef __BDEV_H__
#define __BDEV_H__
/*
* This is a mock-up compiled in blockdev buffer, to be used temporarily.
*/
void *vfs_rootdev_open(void);
#endif/* __BDEV_H__ */

18
tasks/fs0/include/file.h Normal file
View File

@@ -0,0 +1,18 @@
#ifndef __FS0_MM_H__
#define __FS0_MM_H__
/*
* Describes the in-memory representation of a file. This is used to track
* file content, i.e. file pages by mm0, this is a temporary mock up until
* fs0 and mm0 are wired together.
*/
struct vm_file {
unsigned long vnum;
unsigned long length;
/* This is the cache of physical pages that this file has in memory. */
struct list_head page_cache_list;
struct vm_pager *pager;
};
#endif /* __FS0_MM_H__ */

View File

@@ -1,25 +1,41 @@
/*
* VFS definitions.
*
* Copyright (C) 2007 Bahadir Balban.
* Copyright (C) 2007, 2008 Bahadir Balban.
*/
#ifndef __FS_H__
#define __FS_H__
#include <l4/lib/list.h>
typedef void (*dentry_op_t)(void);
typedef void (*superblock_op_t)(void);
#include <l4/lib/list.h>
#include <l4/macros.h>
#include <l4lib/types.h>
#include <stat.h>
typedef void (*vnode_op_t)(void);
typedef void (*file_op_t)(void);
struct dentry;
struct file;
struct file_system_type;
struct superblock;
struct vnode;
struct dentry_ops {
dentry_op_t compare;
int (*compare)(struct dentry *d, char *n);
};
/* Operations that work on file content */
struct file_ops {
/* Read a vnode's contents by page range */
int (*read)(struct vnode *v, unsigned long pfn,
unsigned long npages, void *buf);
/* Write a vnode's contents by page range */
int (*write)(struct vnode *v, unsigned long pfn,
unsigned long npages, void *buf);
file_op_t open;
file_op_t read;
file_op_t write;
file_op_t close;
file_op_t mmap;
file_op_t lseek;
@@ -27,9 +43,11 @@ struct file_ops {
file_op_t fsync;
};
/* Operations that work on vnode fields and associations between vnodes */
struct vnode_ops {
vnode_op_t create;
vnode_op_t lookup;
struct vnode *(*lookup)(struct vnode *root, char *path);
void * (*readdir)(struct vnode *v, void *dirbuf);
vnode_op_t link;
vnode_op_t unlink;
vnode_op_t mkdir;
@@ -40,22 +58,28 @@ struct vnode_ops {
};
struct superblock_ops {
superblock_op_t read_sb;
superblock_op_t write_sb;
superblock_op_t read_vnode;
superblock_op_t write_vnode;
int (*write_sb)(struct superblock *sb);
/*
* Given a vnum, reads the disk-inode and copies its data
* into the vnode's generic fields
*/
int (*read_vnode)(struct superblock *sb, struct vnode *v);
/* Writes vnode's generic fields into the disk-inode structure */
int (*write_vnode)(struct superblock *sb, struct vnode *v);
/* Allocates a disk-inode along with a vnode, and associates the two */
struct vnode *(*alloc_vnode)(struct superblock *sb);
/* Frees the vnode and the corresponding on-disk inode */
int (*free_vnode)(struct superblock *sb, struct vnode *v);
};
struct dentry;
struct file;
struct file_system_type;
struct superblock;
struct vnode;
#define VFS_DENTRY_NAME_MAX 512
#define VFS_DNAME_MAX 256
struct dentry {
int refcnt;
char name[VFS_DENTRY_NAME_MAX];
char name[VFS_DNAME_MAX];
struct dentry *parent; /* Parent dentry */
struct list_head child; /* List of dentries with same parent */
struct list_head children; /* List of children dentries */
@@ -64,35 +88,54 @@ struct dentry {
struct dentry_ops ops;
};
struct file {
int refcnt;
struct dentry *dentry;
struct file_ops ops;
};
struct vnode {
unsigned long id; /* Filesystem-wide unique vnode id */
unsigned long vnum; /* Filesystem-wide unique vnode id */
int refcnt; /* Reference counter */
int hardlinks; /* Number of hard links */
struct superblock *sb; /* Reference to superblock */
struct vnode_ops ops; /* Operations on this vnode */
struct list_head dirents; /* Dirents that refer to this vnode */
struct file_ops fops; /* File-related operations on this vnode */
struct list_head dentries; /* Dirents that refer to this vnode */
struct list_head state_list; /* List for vnode's dirty/clean state */
unsigned long size; /* Total size of vnode in bytes */
u32 type; /* Vnode type, dev? socket? dir? ... */
u32 mode; /* Permissions */
u32 owner; /* Owner */
u64 atime; /* Last access time */
u64 mtime; /* Last content modification */
u64 ctime; /* Last vnode modification */
u64 size; /* Size of contents */
void *inode; /* Ptr to fs-specific inode */
};
struct file_system_type {
char name[256];
unsigned long magic;
unsigned int flags;
struct superblock *(*get_sb)(void);
struct list_head sb_list;
/* FS0 vfs specific macros */
#define vfs_isdir(v) S_ISDIR((v)->type)
struct fstype_ops {
struct superblock *(*get_superblock)(void *buf);
};
#define VFS_FSNAME_MAX 256
struct file_system_type {
char name[VFS_FSNAME_MAX];
unsigned long magic;
struct fstype_ops ops;
struct list_head list; /* Member of list of all fs types */
struct list_head sblist; /* List of superblocks with this type */
};
struct superblock *get_superblock(void *buf);
struct superblock {
struct file_system_type fs;
struct superblock_ops ops;
struct dentry *root_dirent;
u64 fssize;
unsigned int blocksize;
struct list_head list;
struct file_system_type *fs;
struct superblock_ops *ops;
struct vnode *root;
void *fs_super;
};
void vfs_mount_fs(struct superblock *sb);
extern struct dentry_ops generic_dentry_operations;
#endif /* __FS_H__ */

7
tasks/fs0/include/init.h Normal file
View File

@@ -0,0 +1,7 @@
#ifndef __INIT_H__
#define __INIT_H__
/* FS0 initialisation */
int initialise(void);
#endif /* __INIT_H__ */

View File

@@ -0,0 +1,19 @@
#ifndef __PRIVATE_MALLOC_H__
#define __PRIVATE_MALLOC_H__
#include <stddef.h>
#include <string.h>
void *kmalloc(size_t size);
void kfree(void *blk);
static inline void *kzalloc(size_t size)
{
void *buf = kmalloc(size);
memset(buf, 0, size);
return buf;
}
#endif /*__PRIVATE_MALLOC_H__ */

View File

@@ -4,13 +4,11 @@
#ifndef __MM0_SPINLOCK_H__
#define __MM0_SPINLOCK_H__
struct spinlock {
int lock;
};
static inline void spin_lock_init(struct spinlock *s) { }
static inline void spin_lock_init(struct spinlock *s) { }
static inline void spin_lock(struct spinlock *s) { }
static inline void spin_unlock(struct spinlock *s) { }

View File

@@ -30,13 +30,13 @@ SECTIONS
/* rodata is needed else your strings will link at physical! */
.rodata : AT (ADDR(.rodata) - offset) { *(.rodata) }
.rodata1 : AT (ADDR(.rodata1) - offset) { *(.rodata1) }
.data : AT (ADDR(.data) - offset)
.data : AT (ADDR(.data) - offset)
{
. = ALIGN(4K);
_start_ramdisk = .;
*(.data.diskspace)
_end_ramdisk = .;
*(.data)
_start_bdev = .;
*(.data.memfs)
_end_bdev = .;
*(.data)
}
.bss : AT (ADDR(.bss) - offset) { *(.bss) }
_end = .;

View File

@@ -1,7 +0,0 @@
#ifndef __PRIVATE_MALLOC_H__
#define __PRIVATE_MALLOC_H__
void *kmalloc(size_t size);
void kfree(void *blk);
#endif /*__PRIVATE_MALLOC_H__ */

View File

@@ -0,0 +1,97 @@
/*
* The disk layout of our simple unix-like filesystem.
*
* Copyright (C) 2007, 2008 Bahadir Balban
*/
#ifndef __MEMFS_LAYOUT_H__
#define __MEMFS_LAYOUT_H__
#include <l4lib/types.h>
#include <l4/lib/list.h>
#include <l4/macros.h>
#include <l4/config.h>
#include INC_GLUE(memory.h)
#include <memcache/memcache.h>
#include <lib/idpool.h>
/*
*
* Filesystem layout:
*
* |---------------|
* | Superblock |
* |---------------|
*
* Superblock layout:
*
* |---------------|
* | inode cache |
* |---------------|
* | dentry cache |
* |---------------|
* | block cache |
* |---------------|
*
*/
/*
* These fixed filesystem limits make it much easier to implement
* filesystem space allocation.
*/
#define MEMFS_TOTAL_SIZE SZ_8MB
#define MEMFS_TOTAL_INODES 128
#define MEMFS_TOTAL_BLOCKS 2000
#define MEMFS_FMAX_BLOCKS 5
#define MEMFS_BLOCK_SIZE PAGE_SIZE
#define MEMFS_MAGIC 0xB
#define MEMFS_NAME "memfs"
#define MEMFS_NAME_SIZE 8
struct memfs_inode {
u32 inum; /* Inode number */
u32 mode; /* File permissions */
u32 owner; /* File owner */
u64 atime; /* Last access time */
u64 mtime; /* Last content modification */
u64 ctime; /* Last inode modification */
u64 size; /* Size of contents */
void *block[5]; /* Number of blocks */
};
struct memfs_superblock {
u32 magic; /* Filesystem magic number */
char name[8];
u32 blocksize; /* Filesystem block size */
u64 fmaxblocks; /* Maximum number of blocks per file */
u64 fssize; /* Total size of filesystem */
struct memfs_inode *root; /* The root of this superblock */
struct list_head inode_cache_list; /* Chain of alloc caches */
struct list_head block_cache_list; /* Chain of alloc caches */
struct id_pool *ipool; /* Index pool for inodes */
struct id_pool *bpool; /* Index pool for blocks */
struct memfs_inode *inode[MEMFS_TOTAL_INODES]; /* Table of inodes */
void *block[MEMFS_TOTAL_BLOCKS]; /* Table of fs blocks */
} __attribute__ ((__packed__));
#define MEMFS_DNAME_MAX 32
struct memfs_dentry {
u32 inum; /* Inode number */
u32 nlength; /* Name length */
u8 name[MEMFS_DNAME_MAX]; /* Name string */
};
extern struct vnode_ops memfs_vnode_operations;
extern struct superblock_ops memfs_superblock_operations;
extern struct file_ops memfs_file_operations;
extern struct memfs_superblock *memfs_superblock;
int memfs_format_filesystem(void *buffer);
struct memfs_inode *memfs_create_inode(struct memfs_superblock *sb);
void memfs_register_fstype(struct list_head *);
struct superblock *memfs_get_superblock(void *block);
int memfs_generate_superblock(void *block);
void *memfs_alloc_block(struct memfs_superblock *sb);
int memfs_free_block(struct memfs_superblock *sb, void *block);
#endif /* __MEMFS_LAYOUT_H__ */

View File

@@ -0,0 +1,7 @@
#ifndef __MEMFS_VNODE_H__
#define __MEMFS_VNODE_H__
#include <fs.h>
#endif /* __MEMFS_VNODE_H__ */

View File

@@ -1,7 +1,25 @@
/*
* Copyright (C) 2008 Bahadir Balban
*/
#ifndef __FS0_TASK_H__
#define __FS0_TASK_H__
#include <lib/idpool.h>
#include <l4/lib/list.h>
#define __TASKNAME__ "FS0"
#endif /* __FS0_TASK_H__ */
#define TASK_OFILES_MAX 32
/* Thread control block, fs0 portion */
struct tcb {
l4id_t tid;
struct list_head list;
int fd[TASK_OFILES_MAX];
struct id_pool *fdpool;
};
struct tcb *find_task(int tid);
void init_task_data(void);
#endif /* __FS0_TASK_H__ */