From a11897414d5d5566fe60301c1ca71ad4a83cdef1 Mon Sep 17 00:00:00 2001 From: Marian Ohligs Date: Thu, 21 Jul 2011 10:24:37 +0200 Subject: [PATCH] - O_TRUNC is working yet - fixing some bugs in O_TRUNC - disable some buggy code --- fs/initrd.c | 59 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/fs/initrd.c b/fs/initrd.c index 22915cb8..df3f12ae 100644 --- a/fs/initrd.c +++ b/fs/initrd.c @@ -176,31 +176,52 @@ static int initrd_open(fildes_t* file, const char* name) uint32_t i; char* data = NULL; block_list_t* blist = &file->node->block_list; - block_list_t* preblist = NULL; - do { - for(i=0; idata[i]) { - kfree(blist->data[i], - sizeof(data_block_t)); - } + block_list_t* lastblist = NULL; + + /* the first blist pointer have do remain valid. */ + for(i=0; idata[i]) { + kfree(blist->data[i], + sizeof(data_block_t)); } - preblist = blist; + } + if (blist->next) { + lastblist = blist; blist = blist->next; - kfree(preblist, sizeof(block_list_t)); - } while(blist); + lastblist->next = NULL; + + /* kfree all other pointers */ + do { + for(i=0; idata[i]) { + kfree(blist->data[i], sizeof(data_block_t)); + } + } + lastblist = blist; + blist = blist->next; + kfree(lastblist, sizeof(block_list_t)); + } while(blist); + } + /* reset the block_size */ file->node->block_size = 0; } } - if (file->node->type == FS_DIRECTORY) { + + + + +/////blist = &tmp->block_list; !!! + +/* if (file->node->type == FS_DIRECTORY) { if (!(file->flags & O_CREAT)) return -EINVAL; uint32_t i, j; block_list_t* blist = NULL; - /* CREATE FILE */ - vfs_node_t* new_node = kmalloc(sizeof(vfs_node_t)); +*/ /* CREATE FILE */ +/* vfs_node_t* new_node = kmalloc(sizeof(vfs_node_t)); if (BUILTIN_EXPECT(!new_node, 0)) return -EINVAL; @@ -215,8 +236,8 @@ static int initrd_open(fildes_t* file, const char* name) new_node->open = initrd_open; spinlock_init(&new_node->lock); - /* create a entry for the new node in the directory block of current node */ - do { +*/ /* create a entry for the new node in the directory block of current node */ +/* do { for(i=0; idata[i]) { dir_block = (dir_block_t*) blist->data[i]; @@ -225,13 +246,13 @@ static int initrd_open(fildes_t* file, const char* name) if (!dirent->vfs_node) { dirent->vfs_node = new_node; strncpy(dirent->name, (char*) name, MAX_FNAME); - goto exit_create_file; /* there might be a better Solution *********************************/ + goto exit_create_file; // there might be a better Solution ******************************** } } } } - /* if all blocks are reserved, we have to allocate a new one */ - if (!blist->next) { +*/ /* if all blocks are reserved, we have to allocate a new one */ +/* if (!blist->next) { blist->next = (block_list_t*) kmalloc(sizeof(block_list_t)); if (blist->next) memset(blist->next, 0x00, sizeof(block_list_t)); @@ -244,7 +265,7 @@ exit_create_file: file->node = new_node; file->node->block_size = 0; } - return 0; +*/ return 0; }