This commit is contained in:
Marian Ohligs 2011-11-09 12:51:21 +01:00
parent 6a10fb1a0b
commit b292e96cec
2 changed files with 76 additions and 71 deletions

View file

@ -86,13 +86,15 @@ int open_fs(fildes_t* file, const char* name)
i++; j++; i++; j++;
} }
fname[i] = '\0'; 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); file_node = finddir_fs(dir_node, fname);
if (name[j] == '/') if (name[j] == '/')
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 */ /* file exists */
if(file_node) { if(file_node) {
spinlock_lock(&file_node->lock); spinlock_lock(&file_node->lock);

View file

@ -59,85 +59,86 @@ static ssize_t initrd_read(fildes_t* file, uint8_t* buffer, size_t size)
{ {
vfs_node_t* node = file->node; vfs_node_t* node = file->node;
if (node->type != FS_DIRECTORY) { uint32_t i, pos = 0, found = 0;
/*********** The original read function ****************/ off_t offset = 0;
uint32_t i, pos = 0, found = 0; char* data = NULL;
off_t offset = 0; block_list_t* blist = &node->block_list;
char* data = NULL;
block_list_t* blist = &node->block_list;
if (file->flags & O_WRONLY) if (file->flags & O_WRONLY)
return -EACCES; return -EACCES;
/* init the tmp offset */ /* init the tmp offset */
offset = file->offset; offset = file->offset;
/* searching for the valid data block */ /* searching for the valid data block */
if (offset) { if (offset) {
pos = offset / node->block_size; pos = offset / node->block_size;
offset = offset % node->block_size; offset = offset % node->block_size;
} }
do { do {
for(i=0; i<MAX_DATABLOCKS && !data; i++) { for(i=0; i<MAX_DATABLOCKS && !data; i++) {
if (blist->data[i]) { if (blist->data[i]) {
found++; found++;
if (found > pos) if (found > pos)
data = (char*) blist->data[i]; data = (char*) blist->data[i];
}
} }
}
blist = blist->next; blist = blist->next;
} while(blist && !data); } while(blist && !data);
if (BUILTIN_EXPECT(!data, 0)) if (BUILTIN_EXPECT(!data, 0))
return 0; return 0;
/* /*
* If the data block is not large engough, * If the data block is not large engough,
* we copy only the rest of the current block. * we copy only the rest of the current block.
* The user has to restart the read operation * The user has to restart the read operation
* for the next block. * for the next block.
*/ */
if ((offset + size) >= node->block_size) if ((offset + size) >= node->block_size)
size = node->block_size - offset; size = node->block_size - offset;
memcpy(buffer, data + offset, size); memcpy(buffer, data + offset, size);
file->offset += size; file->offset += size;
return 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 { static ssize_t initrd_emu_readdir(fildes_t* file, uint8_t* buffer, size_t size)
for(i=0,count=0; i<MAX_DATABLOCKS; i++) { {
dirblock = (dir_block_t*) blist->data[i]; vfs_node_t* node = file->node;
for(j=0; dirblock && j<MAX_DIRENTRIES; j++) {
dirent = &dirblock->entries[j]; uint32_t i, j, k, count;
if (dirent->vfs_node) { uint32_t index = file->offset;
count++; dirent_t* dirent;
if (count > index) { dir_block_t* dirblock;
k=0; block_list_t* blist = &node->block_list;
do {
buffer[k] = dirent->name[k]; do {
k++; for(i=0,count=0; i<MAX_DATABLOCKS; i++) {
} while(dirent->name[k] != '\0'); dirblock = (dir_block_t*) blist->data[i];
file->offset++; for(j=0; dirblock && j<MAX_DIRENTRIES; j++) {
return k; dirent = &dirblock->entries[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; blist = blist->next;
} while(blist); } while(blist);
return -EINVAL; return -EINVAL;
}
} }
static ssize_t initrd_write(fildes_t* file, uint8_t* buffer, size_t size) static ssize_t initrd_write(fildes_t* file, uint8_t* buffer, size_t size)
@ -248,6 +249,7 @@ static int initrd_open(fildes_t* file, const char* name)
} }
if (file->node->type == FS_DIRECTORY) { if (file->node->type == FS_DIRECTORY) {
/* opendir was called: */ /* opendir was called: */
if (name[0] == '\0') if (name[0] == '\0')
return 0; return 0;
@ -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)); memset(new_node, 0x00, sizeof(vfs_node_t));
new_node->type = FS_DIRECTORY; new_node->type = FS_DIRECTORY;
new_node->read = &initrd_read; new_node->read = &initrd_emu_readdir;
new_node->readdir = &initrd_readdir; new_node->readdir = &initrd_readdir;
new_node->finddir = &initrd_finddir; new_node->finddir = &initrd_finddir;
new_node->mkdir = &initrd_mkdir; new_node->mkdir = &initrd_mkdir;
@ -451,6 +453,7 @@ int initrd_init(void)
fs_root = &initrd_root; fs_root = &initrd_root;
memset(&initrd_root, 0x00, sizeof(vfs_node_t)); memset(&initrd_root, 0x00, sizeof(vfs_node_t));
initrd_root.type = FS_DIRECTORY; initrd_root.type = FS_DIRECTORY;
initrd_root.read = &initrd_emu_readdir;
initrd_root.readdir = &initrd_readdir; initrd_root.readdir = &initrd_readdir;
initrd_root.finddir = &initrd_finddir; initrd_root.finddir = &initrd_finddir;
initrd_root.mkdir = &initrd_mkdir; initrd_root.mkdir = &initrd_mkdir;