Removed linux linked list dependency.

This commit is contained in:
Bahadir Balban
2009-06-02 13:19:17 +03:00
parent 4757f46f71
commit 276b4643c6
69 changed files with 455 additions and 885 deletions

View File

@@ -12,7 +12,7 @@ struct dentry *bootfs_dentry_lookup(struct dentry *d, char *dname)
{
struct dentry *this;
list_for_each_entry(this, child, &d->children) {
list_foreach_struct(this, child, &d->children) {
if (this->compare(this, dname))
return this;
}
@@ -65,16 +65,16 @@ void bootfs_populate(struct initdata *initdata, struct superblock *sb)
d->vnode = v;
d->parent = sb->root;
strncpy(d->name, img->name, VFS_DENTRY_NAME_MAX);
INIT_LIST_HEAD(&d->child);
INIT_LIST_HEAD(&d->children);
list_add(&d->child, &sb->root->children);
link_init(&d->child);
link_init(&d->children);
list_insert(&d->child, &sb->root->children);
/* Initialise vnode for image */
v->refcnt = 0;
v->id = img->phys_start;
v->size = img->phys_end - img->phys_start;
INIT_LIST_HEAD(&v->dirents);
list_add(&d->v_ref, &v->dirents);
link_init(&v->dirents);
list_insert(&d->v_ref, &v->dirents);
/* Initialise file struct for image */
f->refcnt = 0;
@@ -93,17 +93,17 @@ void bootfs_init_root(struct dentry *r)
/* 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);
link_init(&r->child);
link_init(&r->children);
link_init(&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);
link_init(&v->dirents);
link_init(&v->state_list);
list_insert(&r->vref, &v->dirents);
v->size = 0;
}

View File

@@ -23,7 +23,7 @@ struct file_system_type sfs_type = {
};
/* Registers sfs as an available filesystem type */
void sfs_register_fstype(struct list_head *fslist)
void sfs_register_fstype(struct link *fslist)
{
list_add(&sfs_type.list, fslist);
list_insert(&sfs_type.list, fslist);
}

View File

@@ -108,6 +108,6 @@ struct sfs_dentry {
} __attribute__ ((__packed__));
void sfs_register_type(struct list_head *);
void sfs_register_type(struct link *);
#endif /* __C0FS_LAYOUT_H__ */

View File

@@ -14,21 +14,21 @@
#include <l4/api/errno.h>
#include <memfs/memfs.h>
struct list_head fs_type_list;
struct link fs_type_list;
struct superblock *vfs_probe_filesystems(void *block)
{
struct file_system_type *fstype;
struct superblock *sb;
list_for_each_entry(fstype, &fs_type_list, list) {
list_foreach_struct(fstype, &fs_type_list, list) {
/* Does the superblock match for this fs type? */
if ((sb = fstype->ops.get_superblock(block))) {
/*
* Add this to the list of superblocks this
* fs already has.
*/
list_add(&sb->list, &fstype->sblist);
list_insert(&sb->list, &fstype->sblist);
return sb;
}
}
@@ -43,7 +43,7 @@ struct superblock *vfs_probe_filesystems(void *block)
void vfs_register_filesystems(void)
{
/* Initialise fstype list */
INIT_LIST_HEAD(&fs_type_list);
link_init(&fs_type_list);
/* Call per-fs registration functions */
memfs_register_fstype(&fs_type_list);

View File

@@ -22,7 +22,7 @@ struct vnode *lookup_dentry_children(struct dentry *parentdir,
struct vnode *v;
const char *component = pathdata_next_component(pdata);
list_for_each_entry(childdir, &parentdir->children, child)
list_foreach_struct(childdir, &parentdir->children, child)
if (IS_ERR(v = childdir->vnode->ops.lookup(childdir->vnode,
pdata, component)))
/* Means not found, continue search */
@@ -47,7 +47,7 @@ struct vnode *generic_vnode_lookup(struct vnode *thisnode,
int err;
/* Does this path component match with any of this vnode's dentries? */
list_for_each_entry(d, &thisnode->dentries, vref) {
list_foreach_struct(d, &thisnode->dentries, vref) {
if (d->ops.compare(d, component)) {
/* Is this a directory? */
if (vfs_isdir(thisnode)) {

View File

@@ -29,13 +29,13 @@ int memfs_init_caches(struct memfs_superblock *sb)
free_block = (void *)sb + sizeof(*sb);
block_cache = mem_cache_init(free_block, sb->fssize - sizeof(*sb),
sb->blocksize, 1);
list_add(&block_cache->list, &sb->block_cache_list);
list_insert(&block_cache->list, &sb->block_cache_list);
/* Allocate a block and initialise it as first inode cache */
free_block = mem_cache_alloc(block_cache);
inode_cache = mem_cache_init(free_block, sb->blocksize,
sizeof(struct memfs_inode), 0);
list_add(&inode_cache->list, &sb->inode_cache_list);
list_insert(&inode_cache->list, &sb->inode_cache_list);
return 0;
}
@@ -62,8 +62,8 @@ int memfs_format_filesystem(void *buffer)
sb->bpool = id_pool_new_init(MEMFS_TOTAL_BLOCKS);
/* Initialise bitmap allocation lists for blocks and inodes */
INIT_LIST_HEAD(&sb->block_cache_list);
INIT_LIST_HEAD(&sb->inode_cache_list);
link_init(&sb->block_cache_list);
link_init(&sb->inode_cache_list);
memfs_init_caches(sb);
return 0;
@@ -74,7 +74,7 @@ void *memfs_alloc_block(struct memfs_superblock *sb)
{
struct mem_cache *cache;
list_for_each_entry(cache, &sb->block_cache_list, list) {
list_foreach_struct(cache, &sb->block_cache_list, list) {
if (cache->free)
return mem_cache_zalloc(cache);
else
@@ -91,7 +91,7 @@ int memfs_free_block(struct memfs_superblock *sb, void *block)
{
struct mem_cache *c, *tmp;
list_for_each_entry_safe(c, tmp, &sb->block_cache_list, list)
list_foreach_removable_struct(c, tmp, &sb->block_cache_list, list)
if (!mem_cache_free(c, block))
return 0;
else
@@ -151,11 +151,11 @@ int memfs_init_rootdir(struct superblock *sb)
d->vnode = v;
/* Associate dentry with its vnode */
list_add(&d->vref, &d->vnode->dentries);
list_insert(&d->vref, &d->vnode->dentries);
/* Add both vnode and dentry to their flat caches */
list_add(&d->cache_list, &dentry_cache);
list_add(&v->cache_list, &vnode_cache);
list_insert(&d->cache_list, &dentry_cache);
list_insert(&v->cache_list, &vnode_cache);
return 0;
}
@@ -204,12 +204,12 @@ struct superblock *memfs_get_superblock(void *block)
}
/* Registers sfs as an available filesystem type */
void memfs_register_fstype(struct list_head *fslist)
void memfs_register_fstype(struct link *fslist)
{
/* Initialise superblock list for this fstype */
INIT_LIST_HEAD(&memfs_fstype.sblist);
link_init(&memfs_fstype.sblist);
/* Add this fstype to list of available fstypes. */
list_add(&memfs_fstype.list, fslist);
list_insert(&memfs_fstype.list, fslist);
}

View File

@@ -21,7 +21,7 @@ struct memfs_inode *memfs_alloc_inode(struct memfs_superblock *sb)
void *free_block;
/* Ask existing inode caches for a new inode */
list_for_each_entry(cache, &sb->inode_cache_list, list) {
list_foreach_struct(cache, &sb->inode_cache_list, list) {
if (cache->free)
if (!(i = mem_cache_zalloc(cache)))
return PTR_ERR(-ENOSPC);
@@ -38,7 +38,7 @@ struct memfs_inode *memfs_alloc_inode(struct memfs_superblock *sb)
/* Initialise it as an inode cache */
cache = mem_cache_init(free_block, sb->blocksize,
sizeof(struct memfs_inode), 0);
list_add(&cache->list, &sb->inode_cache_list);
list_insert(&cache->list, &sb->inode_cache_list);
if (!(i = mem_cache_zalloc(cache)))
return PTR_ERR(-ENOSPC);
@@ -53,13 +53,13 @@ int memfs_free_inode(struct memfs_superblock *sb, struct memfs_inode *i)
{
struct mem_cache *c, *tmp;
list_for_each_entry_safe(c, tmp, &sb->inode_cache_list, list) {
list_foreach_removable_struct(c, tmp, &sb->inode_cache_list, list) {
/* Free it, if success */
if (!mem_cache_free(c, i)) {
/* If cache completely emtpy */
if (mem_cache_is_empty(c)) {
/* Free the block, too. */
list_del(&c->list);
list_remove(&c->list);
memfs_free_block(sb, c);
}
return 0;
@@ -213,7 +213,7 @@ int memfs_write_vnode(struct superblock *sb, struct vnode *v)
struct vnode *memfs_vnode_mknod(struct vnode *v, const char *dirname,
unsigned int mode)
{
struct dentry *d, *parent = list_entry(v->dentries.next,
struct dentry *d, *parent = link_to_struct(v->dentries.next,
struct dentry, vref);
struct memfs_dentry *memfsd;
struct dentry *newd;
@@ -234,7 +234,7 @@ struct vnode *memfs_vnode_mknod(struct vnode *v, const char *dirname,
return PTR_ERR(err);
/* Check there's no existing child with same name */
list_for_each_entry(d, &parent->children, child) {
list_foreach_struct(d, &parent->children, child) {
/* Does the name exist as a child? */
if(d->ops.compare(d, dirname))
return PTR_ERR(-EEXIST);
@@ -278,14 +278,14 @@ struct vnode *memfs_vnode_mknod(struct vnode *v, const char *dirname,
strncpy(newd->name, dirname, VFS_DNAME_MAX);
/* Associate dentry with its vnode */
list_add(&newd->vref, &newd->vnode->dentries);
list_insert(&newd->vref, &newd->vnode->dentries);
/* Associate dentry with its parent */
list_add(&newd->child, &parent->children);
list_insert(&newd->child, &parent->children);
/* Add both vnode and dentry to their flat caches */
list_add(&newd->cache_list, &dentry_cache);
list_add(&newv->cache_list, &vnode_cache);
list_insert(&newd->cache_list, &dentry_cache);
list_insert(&newv->cache_list, &vnode_cache);
return newv;
}
@@ -303,7 +303,7 @@ int memfs_vnode_readdir(struct vnode *v)
{
int err;
struct memfs_dentry *memfsd;
struct dentry *parent = list_entry(v->dentries.next,
struct dentry *parent = link_to_struct(v->dentries.next,
struct dentry, vref);
/*
@@ -327,7 +327,7 @@ int memfs_vnode_readdir(struct vnode *v)
/*
* Fail if vnode size is bigger than a page. Since this allocation
* method is to be replaced, we can live with this limitation for now.
* method is to be origaced, we can live with this limitation for now.
*/
BUG_ON(v->size > PAGE_SIZE);
@@ -349,7 +349,7 @@ int memfs_vnode_readdir(struct vnode *v)
/* Initialise it */
newd->ops = generic_dentry_operations;
newd->parent = parent;
list_add(&newd->child, &parent->children);
list_insert(&newd->child, &parent->children);
/*
* Lookup the vnode for dentry by its vnode number. We call
@@ -367,7 +367,7 @@ int memfs_vnode_readdir(struct vnode *v)
}
/* Assing this dentry as a name of its vnode */
list_add(&newd->vref, &newd->vnode->dentries);
list_insert(&newd->vref, &newd->vnode->dentries);
/* Increase link count */
newv->links++;
@@ -376,8 +376,8 @@ int memfs_vnode_readdir(struct vnode *v)
memcpy(newd->name, memfsd[i].name, MEMFS_DNAME_MAX);
/* Add both vnode and dentry to their caches */
list_add(&newd->cache_list, &dentry_cache);
list_add(&newv->cache_list, &vnode_cache);
list_insert(&newd->cache_list, &dentry_cache);
list_insert(&newv->cache_list, &vnode_cache);
}
return 0;

View File

@@ -19,8 +19,8 @@ const char *pathdata_next_component(struct pathdata *pdata)
struct pathcomp *p, *n;
const char *pathstr;
list_for_each_entry_safe(p, n, &pdata->list, list) {
list_del(&p->list);
list_foreach_removable_struct(p, n, &pdata->list, list) {
list_remove(&p->list);
pathstr = p->str;
kfree(p);
return pathstr;
@@ -35,8 +35,8 @@ const char *pathdata_last_component(struct pathdata *pdata)
const char *pathstr;
if (!list_empty(&pdata->list)) {
p = list_entry(pdata->list.prev, struct pathcomp, list);
list_del(&p->list);
p = link_to_struct(pdata->list.prev, struct pathcomp, list);
list_remove(&p->list);
pathstr = p->str;
kfree(p);
return pathstr;
@@ -50,8 +50,8 @@ void pathdata_destroy(struct pathdata *p)
{
struct pathcomp *c, *n;
list_for_each_entry_safe(c, n, &p->list, list) {
list_del(&c->list);
list_foreach_removable_struct(c, n, &p->list, list) {
list_remove(&c->list);
kfree(c);
}
kfree(p);
@@ -62,7 +62,7 @@ void pathdata_print(struct pathdata *p)
struct pathcomp *comp;
printf("Extracted path is:\n");
list_for_each_entry(comp, &p->list, list)
list_foreach_struct(comp, &p->list, list)
printf("%s\n", comp->str);
}
@@ -78,7 +78,7 @@ struct pathdata *pathdata_parse(const char *pathname,
return PTR_ERR(-ENOMEM);
/* Initialise pathdata */
INIT_LIST_HEAD(&pdata->list);
link_init(&pdata->list);
strcpy(pathbuf, pathname);
/* First component is root if there's a root */
@@ -87,9 +87,9 @@ struct pathdata *pathdata_parse(const char *pathname,
kfree(pdata);
return PTR_ERR(-ENOMEM);
}
INIT_LIST_HEAD(&comp->list);
link_init(&comp->list);
comp->str = VFS_STR_ROOTDIR;
list_add_tail(&comp->list, &pdata->list);
list_insert_tail(&comp->list, &pdata->list);
if (task)
/* Lookup start vnode is root vnode */
@@ -105,15 +105,15 @@ struct pathdata *pathdata_parse(const char *pathname,
kfree(pdata);
return PTR_ERR(-ENOMEM);
}
INIT_LIST_HEAD(&comp->list);
link_init(&comp->list);
/* Get current dentry for this task */
curdir = list_entry(task->fs_data->curdir->dentries.next,
curdir = link_to_struct(task->fs_data->curdir->dentries.next,
struct dentry, vref);
/* Use its name in path component */
comp->str = curdir->name;
list_add_tail(&comp->list, &pdata->list);
list_insert_tail(&comp->list, &pdata->list);
/* Lookup start vnode is current dir vnode */
pdata->vstart = task->fs_data->curdir;
@@ -130,9 +130,9 @@ struct pathdata *pathdata_parse(const char *pathname,
pathdata_destroy(pdata);
return PTR_ERR(-ENOMEM);
}
INIT_LIST_HEAD(&comp->list);
link_init(&comp->list);
comp->str = str;
list_add_tail(&comp->list, &pdata->list);
list_insert_tail(&comp->list, &pdata->list);
}
/* Next component */

View File

@@ -55,7 +55,7 @@ int pager_sys_open(struct tcb *pager, l4id_t opener, int fd)
/*
* Write file information, they will
* be sent via the return reply.
* be sent via the return origy.
*/
write_mr(L4SYS_ARG0, v->vnum);
write_mr(L4SYS_ARG1, v->size);
@@ -89,7 +89,7 @@ int pager_open_bypath(struct tcb *pager, char *pathname)
/*
* Write file information, they will
* be sent via the return reply.
* be sent via the return origy.
*/
write_mr(L4SYS_ARG0, v->vnum);
write_mr(L4SYS_ARG1, v->size);
@@ -109,10 +109,10 @@ void print_vnode(struct vnode *v)
struct dentry *d, *c;
printf("Vnode names:\n");
list_for_each_entry(d, &v->dentries, vref) {
list_foreach_struct(d, &v->dentries, vref) {
printf("%s\n", d->name);
printf("Children dentries:\n");
list_for_each_entry(c, &d->children, child)
list_foreach_struct(c, &d->children, child)
printf("%s\n", c->name);
}
}
@@ -496,7 +496,7 @@ int sys_readdir(struct tcb *t, int fd, void *buf, int count)
if (!(v = vfs_lookup_byvnum(vfs_root.pivot->sb, vnum)))
return -EINVAL;
d = list_entry(v->dentries.next, struct dentry, vref);
d = link_to_struct(v->dentries.next, struct dentry, vref);
/* Ensure vnode is a directory */
if (!vfs_isdir(v))

View File

@@ -32,14 +32,14 @@ struct global_list global_tasks = {
void global_add_task(struct tcb *task)
{
BUG_ON(!list_empty(&task->list));
list_add_tail(&task->list, &global_tasks.list);
list_insert_tail(&task->list, &global_tasks.list);
global_tasks.total++;
}
void global_remove_task(struct tcb *task)
{
BUG_ON(list_empty(&task->list));
list_del_init(&task->list);
list_remove_init(&task->list);
BUG_ON(--global_tasks.total < 0);
}
@@ -47,7 +47,7 @@ struct tcb *find_task(int tid)
{
struct tcb *t;
list_for_each_entry(t, &global_tasks.list, list)
list_foreach_struct(t, &global_tasks.list, list)
if (t->tid == tid)
return t;
return 0;
@@ -95,7 +95,7 @@ struct tcb *tcb_alloc_init(unsigned int flags)
task->tid = TASK_ID_INVALID;
/* Initialise list structure */
INIT_LIST_HEAD(&task->list);
link_init(&task->list);
return task;
}

View File

@@ -8,8 +8,8 @@
#include <task.h>
#include <path.h>
LIST_HEAD(vnode_cache);
LIST_HEAD(dentry_cache);
LINK_DECLARE(vnode_cache);
LINK_DECLARE(dentry_cache);
/*
* /
@@ -33,7 +33,7 @@ struct vnode *vfs_lookup_byvnum(struct superblock *sb, unsigned long vnum)
int err;
/* Check the vnode flat list by vnum */
list_for_each_entry(v, &vnode_cache, cache_list)
list_foreach_struct(v, &vnode_cache, cache_list)
if (v->vnum == vnum)
return v;
@@ -48,7 +48,7 @@ struct vnode *vfs_lookup_byvnum(struct superblock *sb, unsigned long vnum)
}
/* Add the vnode back to vnode flat list */
list_add(&v->cache_list, &vnode_cache);
list_insert(&v->cache_list, &vnode_cache);
return v;
}