- O_TRUNC is working yet

- fixing some bugs in O_TRUNC
- disable some buggy code
This commit is contained in:
Marian Ohligs 2011-07-21 10:24:37 +02:00
parent c6a5f9390e
commit a11897414d

View file

@ -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; i<MAX_DATABLOCKS && !data; i++) {
if (blist->data[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; i<MAX_DATABLOCKS && !data; i++) {
if (blist->data[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; i<MAX_DATABLOCKS && !data; i++) {
if (blist->data[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; i<MAX_DATABLOCKS; i++) {
if (blist->data[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;
}