From 4c370ad3774128917ff1f2f9b73248fbe5a4bf19 Mon Sep 17 00:00:00 2001 From: Marian Ohligs Date: Tue, 26 Apr 2011 16:43:57 +0200 Subject: [PATCH] Bug fixed in stdout: printf is working some test changes in initrd_write --- drivers/stdout/stdout.c | 5 ++- fs/initrd.c | 80 ++++++++++++++++++++++++++++++++++++++--- include/metalsvm/fs.h | 3 ++ kernel/syscall.c | 2 +- newlib/examples/hello.c | 18 +++------- newlib/examples/test | 3 +- 6 files changed, 90 insertions(+), 21 deletions(-) diff --git a/drivers/stdout/stdout.c b/drivers/stdout/stdout.c index 29fbb035..99d82ad7 100644 --- a/drivers/stdout/stdout.c +++ b/drivers/stdout/stdout.c @@ -33,7 +33,10 @@ static ssize_t stdout_read(vfs_node_t* node, uint8_t* buffer, size_t size, off_t static ssize_t stdout_write(vfs_node_t* node, uint8_t* buffer, size_t size, off_t offset) { - size = kprintf("%s\0", buffer); + int i; + for (i = 0; iblock_list; - char* data = (char*) blist->data[0]; - //////////ACHTUNG keine Überprüfung der Blcoklängen etc. - memcpy(data, buffer, size); + do { + data = (char*) blist->data[0]; + if ((size - writtenbytes) >= MAX_DATABLOCKS) + writebytes = MAX_DATABLOCKS; + else + writebytes = size - writtenbytes; + + memcpy(data, buffer, writebytes); + writtenbytes += writebytes; + //kprintf("geschrieben: %i", writtenbytes); - return size; + if (!blist->next) { + blist->next = (block_list_t*) kmalloc(sizeof(block_list_t)); + if (blist->next) { + memset(blist->next, 0x00, sizeof(block_list_t)); + } + } + + blist = blist->next; + } while(size > writtenbytes); + + return writtenbytes; + +/* + uint32_t i, pos = 0, found = 0; + char* data = NULL; + block_list_t* blist = &node->block_list; + + kprintf("tatsachen offset %i\n", offset); + + // searching for the valid data block + if (offset) { + pos = offset / node->block_size; + offset = offset % node->block_size; + } + kprintf("Pos: %i, Offset: %i, %i", pos, offset, node->block_size); + + + + do { + for(i=0; idata[i]) { + found++; + if (found > pos) + data = (char*) blist->data[i]; + break; + } + } + if all blocks have already been used, we have to allocate a new one + if (!blist->next) { + blist->next = (block_list_t*) kmalloc(sizeof(block_list_t)); + if (blist->next) { + kprintf("?"); + memset(blist->next, 0x00, sizeof(block_list_t)); + } + } + + blist = blist->next; + } while(blist && !data); + + 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 write operation + * for the next block. + */ +/* if (offset+size >= node->block_size) + size = node->block_size - offset; + + memcpy(data + offset, buffer, size); + +*/ //return size; } diff --git a/include/metalsvm/fs.h b/include/metalsvm/fs.h index b9dbfb2e..58897aa2 100644 --- a/include/metalsvm/fs.h +++ b/include/metalsvm/fs.h @@ -196,6 +196,9 @@ vfs_node_t* findnode_fs(const char* name); /* @} */ int null_init(vfs_node_t* node, const char* name); +int stdin_init(vfs_node_t* node, const char* name); +int stdout_init(vfs_node_t* node, const char* name); +int stderr_init(vfs_node_t* node, const char* name); int initrd_init(void); #endif diff --git a/kernel/syscall.c b/kernel/syscall.c index 9fafcef0..85290fca 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -42,7 +42,7 @@ static int sys_write(int fd, const char *buf, size_t len) { unsigned int wrotebytes; wrotebytes = write_fs(per_core(current_task)->fildes_table[fd].node, (uint8_t*)buf, len, per_core(current_task)->fildes_table[fd].offset); - //kprintf("ins Dateis. geschr. -- fd:%i, Dateilaenge:%i, Dateiinhalt: %s \n", fd, wrotebytes, buf); + //kprintf("ins Dateis. geschr. -- fd:%i, Dateilaenge:%i, Schreiblaenge: %i, Dateiinhalt: %s \n", fd, len, wrotebytes, buf); per_core(current_task)->fildes_table[fd].offset += wrotebytes; return wrotebytes; diff --git a/newlib/examples/hello.c b/newlib/examples/hello.c index 861cb6f6..61f9efc5 100644 --- a/newlib/examples/hello.c +++ b/newlib/examples/hello.c @@ -29,26 +29,18 @@ int main(int argc, char** argv) { //int i; char* str = (char *)malloc(20 * sizeof(char)); - char* str2 = (char *)malloc(20 * sizeof(char)); - FILE* testfile; testfile = fopen("/bin/test", "w+r"); setbuf(testfile, NULL); fflush(NULL); - fread(str2, 1, 10, testfile); - fflush(NULL); - printf("Datei gelesen (/bin/test):%s\n", str2); - fflush(NULL); + fwrite("wsblablaxxxyyyyzzzzzz", 1, 19, testfile); + fclose(testfile); + testfile = fopen("/bin/test", "w+r"); setbuf(testfile, NULL); + fread(str, 1, 20, testfile); fflush(NULL); - fwrite("wtest1", 1, 7, testfile); - setbuf(testfile, NULL); - - fread(str, 1, 10, testfile); - fflush(NULL); - - //printf("Aus Datei gelesen (/bin/test):%s\n", str); + printf("Aus Datei gelesen (/bin/test):%s\n", str); return errno; } diff --git a/newlib/examples/test b/newlib/examples/test index 3d6ab3f2..d00491fd 100644 --- a/newlib/examples/test +++ b/newlib/examples/test @@ -1,2 +1 @@ -HalloXA!! - +1