From 2192b22677ab21d4050f217a25376057a0dc4125 Mon Sep 17 00:00:00 2001 From: Bahadir Balban Date: Thu, 8 Oct 2009 17:00:00 +0300 Subject: [PATCH] Added a filesystem index value for each superblock --- conts/posix/libposix/chdir.c | 2 +- conts/posix/mm0/fs/init.c | 9 +++++++++ conts/posix/mm0/fs/memfs/memfs.c | 2 +- conts/posix/mm0/fs/memfs/vnode.c | 6 +++--- conts/posix/mm0/fs/vfs.c | 3 ++- conts/posix/mm0/include/fs.h | 1 + conts/posix/mm0/include/memfs/memfs.h | 1 + conts/posix/mm0/include/vfs.h | 9 +++++++++ 8 files changed, 27 insertions(+), 6 deletions(-) diff --git a/conts/posix/libposix/chdir.c b/conts/posix/libposix/chdir.c index dd3aa5f..2f9988c 100644 --- a/conts/posix/libposix/chdir.c +++ b/conts/posix/libposix/chdir.c @@ -25,7 +25,7 @@ static inline int l4_chdir(const char *pathname) utcb_full_strcpy_from(pathname); /* Call pager with shmget() request. Check ipc error. */ - if ((fd = l4_sendrecv_full(VFS_TID, VFS_TID, L4_IPC_TAG_CHDIR)) < 0) { + if ((fd = l4_sendrecv_full(PAGER_TID, PAGER_TID, L4_IPC_TAG_CHDIR)) < 0) { print_err("%s: L4 IPC Error: %d.\n", __FUNCTION__, fd); return fd; } diff --git a/conts/posix/mm0/fs/init.c b/conts/posix/mm0/fs/init.c index 2b33ef8..cd1c41f 100644 --- a/conts/posix/mm0/fs/init.c +++ b/conts/posix/mm0/fs/init.c @@ -56,6 +56,15 @@ int vfs_init(void) void *rootdev_blocks; struct superblock *root_sb; + /* Initialize superblock ids */ + vfs_fsidx_pool = id_pool_new_init(VFS_FSIDX_SIZE); + + /* + * Waste first one so that vnums + * always orr with a non-zero value + */ + id_new(vfs_fsidx_pool); + /* Get standard init data from microkernel */ // request_initdata(&initdata); diff --git a/conts/posix/mm0/fs/memfs/memfs.c b/conts/posix/mm0/fs/memfs/memfs.c index 72bb764..ebe42c5 100644 --- a/conts/posix/mm0/fs/memfs/memfs.c +++ b/conts/posix/mm0/fs/memfs/memfs.c @@ -126,7 +126,7 @@ int memfs_init_rootdir(struct superblock *sb) */ v = sb->root = sb->ops->alloc_vnode(sb); msb->root_vnum = sb->root->vnum; - BUG_ON(msb->root_vnum != 0); + BUG_ON(msb->root_vnum == 0); /* Initialise fields */ vfs_set_type(v, S_IFDIR); diff --git a/conts/posix/mm0/fs/memfs/vnode.c b/conts/posix/mm0/fs/memfs/vnode.c index ff1b6b0..0ebfa6a 100644 --- a/conts/posix/mm0/fs/memfs/vnode.c +++ b/conts/posix/mm0/fs/memfs/vnode.c @@ -122,7 +122,7 @@ struct vnode *memfs_alloc_vnode(struct superblock *sb) /* Associate the two together */ v->inode = i; - v->vnum = i->inum; + v->vnum = i->inum | sb->fsidx; /* Globalize by fsidx */ /* Associate memfs-specific fields with vnode */ v->ops = memfs_vnode_operations; @@ -174,7 +174,7 @@ int memfs_read_vnode(struct superblock *sb, struct vnode *v) return -EEXIST; /* Simply copy common fields */ - v->vnum = i->inum; + v->vnum = i->inum | sb->fsidx; v->size = i->size; v->mode = i->mode; v->owner = i->owner; @@ -194,7 +194,7 @@ int memfs_write_vnode(struct superblock *sb, struct vnode *v) BUG_ON(!i); /* Simply copy common fields */ - i->inum = v->vnum; + i->inum = v->vnum & ~VFS_FSIDX_MASK; i->size = v->size; i->mode = v->mode; i->owner = v->owner; diff --git a/conts/posix/mm0/fs/vfs.c b/conts/posix/mm0/fs/vfs.c index 488b785..f15b9d1 100644 --- a/conts/posix/mm0/fs/vfs.c +++ b/conts/posix/mm0/fs/vfs.c @@ -12,6 +12,7 @@ LINK_DECLARE(vnode_cache); LINK_DECLARE(dentry_cache); struct vfs_mountpoint vfs_root; +struct id_pool *vfs_fsidx_pool; /* * Vnodes in the vnode cache have 2 keys. One is their dentry names, the other @@ -68,7 +69,7 @@ int vfs_mount_root(struct superblock *sb) * Lookup the root vnode of this superblock. * The root superblock has vnode number 0. */ - vfs_root.pivot = vfs_lookup_byvnum(sb, 0); + vfs_root.pivot = vfs_lookup_byvnum(sb, sb->fsidx | 0); vfs_root.sb = sb; return 0; diff --git a/conts/posix/mm0/include/fs.h b/conts/posix/mm0/include/fs.h index 20f7d49..ad48af3 100644 --- a/conts/posix/mm0/include/fs.h +++ b/conts/posix/mm0/include/fs.h @@ -156,6 +156,7 @@ struct superblock *get_superblock(void *buf); struct superblock { u64 fssize; + int fsidx; unsigned int blocksize; struct link list; struct file_system_type *fs; diff --git a/conts/posix/mm0/include/memfs/memfs.h b/conts/posix/mm0/include/memfs/memfs.h index ea1fbec..229d97e 100644 --- a/conts/posix/mm0/include/memfs/memfs.h +++ b/conts/posix/mm0/include/memfs/memfs.h @@ -62,6 +62,7 @@ struct memfs_inode { struct memfs_superblock { u32 magic; /* Filesystem magic number */ char name[8]; + int fsidx; /* Index that gets orred to get global vnum */ u32 blocksize; /* Filesystem block size */ u64 fmaxblocks; /* Maximum number of blocks per file */ u64 fssize; /* Total size of filesystem */ diff --git a/conts/posix/mm0/include/vfs.h b/conts/posix/mm0/include/vfs.h index a0e8682..2b8978e 100644 --- a/conts/posix/mm0/include/vfs.h +++ b/conts/posix/mm0/include/vfs.h @@ -10,8 +10,14 @@ #include #include +/* Top nibble of vnum indicates filesystem index */ +#define VFS_FSIDX_MASK 0xF0000000 +#define VFS_FSIDX_SHIFT 28 +#define VFS_FSIDX_SIZE 16 + extern struct link vnode_cache; extern struct link dentry_cache; +extern struct id_pool *vfs_fsidx_pool; /* * This is a temporary origacement for page cache support provided by mm0. @@ -69,6 +75,9 @@ static inline void vfs_free_vnode(struct vnode *v) static inline struct superblock *vfs_alloc_superblock(void) { struct superblock *sb = kmalloc(sizeof(struct superblock)); + int fsidx = id_new(vfs_fsidx_pool); + + sb->fsidx = fsidx << VFS_FSIDX_SHIFT; link_init(&sb->list); return sb;