diff --git a/fs/fs.c b/fs/fs.c index 3a864ed7..eaa0e595 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -86,13 +86,15 @@ int open_fs(fildes_t* file, const char* name) i++; j++; } fname[i] = '\0'; - dir_node = file_node; /* file must be a dictionary */ + dir_node = file_node; /* file must be a directory */ file_node = finddir_fs(dir_node, fname); if (name[j] == '/') j++; } - //kprintf("dir_node = %p, file_node = %p, name = %s", dir_node, file_node, fname); + //kprintf("dir_node = %p, file_node = %p, name = %s \n", dir_node, file_node, fname); + if(fname[0] == '\0') + kprintf("Ist null"); /* file exists */ if(file_node) { spinlock_lock(&file_node->lock); diff --git a/fs/initrd.c b/fs/initrd.c index d7ac8ecc..3aaeb4e2 100644 --- a/fs/initrd.c +++ b/fs/initrd.c @@ -59,85 +59,86 @@ static ssize_t initrd_read(fildes_t* file, uint8_t* buffer, size_t size) { vfs_node_t* node = file->node; - if (node->type != FS_DIRECTORY) { - /*********** The original read function ****************/ - uint32_t i, pos = 0, found = 0; - off_t offset = 0; - char* data = NULL; - block_list_t* blist = &node->block_list; + uint32_t i, pos = 0, found = 0; + off_t offset = 0; + char* data = NULL; + block_list_t* blist = &node->block_list; - if (file->flags & O_WRONLY) - return -EACCES; + if (file->flags & O_WRONLY) + return -EACCES; - /* init the tmp offset */ - offset = file->offset; + /* init the tmp offset */ + offset = file->offset; - /* searching for the valid data block */ - if (offset) { - pos = offset / node->block_size; - offset = offset % node->block_size; - } - do { - for(i=0; idata[i]) { - found++; - if (found > pos) - data = (char*) blist->data[i]; - } + /* searching for the valid data block */ + if (offset) { + pos = offset / node->block_size; + offset = offset % node->block_size; + } + do { + for(i=0; idata[i]) { + found++; + if (found > pos) + data = (char*) blist->data[i]; } - - blist = blist->next; - } while(blist && !data); + } + + blist = blist->next; + } while(blist && !data); - if (BUILTIN_EXPECT(!data, 0)) - return 0; + if (BUILTIN_EXPECT(!data, 0)) + return 0; - /* - * If the data block is not large engough, - * we copy only the rest of the current block. - * The user has to restart the read operation - * for the next block. - */ - if ((offset + size) >= node->block_size) - size = node->block_size - offset; + /* + * If the data block is not large engough, + * we copy only the rest of the current block. + * The user has to restart the read operation + * for the next block. + */ + if ((offset + size) >= node->block_size) + size = node->block_size - offset; - memcpy(buffer, data + offset, size); + memcpy(buffer, data + offset, size); - file->offset += size; - return size; - } else { - /*********** The emulated readdir funtion *************/ - uint32_t i, j, k, count; - uint32_t index = file->offset; - dirent_t* dirent; - dir_block_t* dirblock; - block_list_t* blist = &node->block_list; - - do { - for(i=0,count=0; idata[i]; - for(j=0; dirblock && jentries[j]; - if (dirent->vfs_node) { - count++; - if (count > index) { - k=0; - do { - buffer[k] = dirent->name[k]; - k++; - } while(dirent->name[k] != '\0'); - file->offset++; - return k; - } + file->offset += size; + return size; +} + +static ssize_t initrd_emu_readdir(fildes_t* file, uint8_t* buffer, size_t size) +{ + vfs_node_t* node = file->node; + + uint32_t i, j, k, count; + uint32_t index = file->offset; + dirent_t* dirent; + dir_block_t* dirblock; + block_list_t* blist = &node->block_list; + + do { + for(i=0,count=0; idata[i]; + for(j=0; dirblock && jentries[j]; + if (dirent->vfs_node) { + count++; + if (count > index) { + k=0; + do { + buffer[k] = dirent->name[k]; + k++; + } while(dirent->name[k] != '\0'); + file->offset++; + return k; } } } + } + + blist = blist->next; + } while(blist); - blist = blist->next; - } while(blist); - - return -EINVAL; - } + return -EINVAL; } static ssize_t initrd_write(fildes_t* file, uint8_t* buffer, size_t size) @@ -248,8 +249,9 @@ static int initrd_open(fildes_t* file, const char* name) } if (file->node->type == FS_DIRECTORY) { + /* opendir was called: */ - if (name[0] == '\0') + if (name[0] == '\0') return 0; /* open file was called: */ @@ -379,7 +381,7 @@ static vfs_node_t* initrd_mkdir(vfs_node_t* node, const char* name) memset(new_node, 0x00, sizeof(vfs_node_t)); new_node->type = FS_DIRECTORY; - new_node->read = &initrd_read; + new_node->read = &initrd_emu_readdir; new_node->readdir = &initrd_readdir; new_node->finddir = &initrd_finddir; new_node->mkdir = &initrd_mkdir; @@ -451,6 +453,7 @@ int initrd_init(void) fs_root = &initrd_root; memset(&initrd_root, 0x00, sizeof(vfs_node_t)); initrd_root.type = FS_DIRECTORY; + initrd_root.read = &initrd_emu_readdir; initrd_root.readdir = &initrd_readdir; initrd_root.finddir = &initrd_finddir; initrd_root.mkdir = &initrd_mkdir;