Bug fixed in stdout: printf is working

some test changes in initrd_write
This commit is contained in:
Marian Ohligs 2011-04-26 16:43:57 +02:00
parent ef59f6cb8d
commit 4c370ad377
6 changed files with 90 additions and 21 deletions

View file

@ -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; i<size; i++, buffer++) {
kputchar(*buffer);
}
return size;
}

View file

@ -95,13 +95,85 @@ static ssize_t initrd_read(vfs_node_t* node, uint8_t* buffer, size_t size, off_t
static ssize_t initrd_write(vfs_node_t* node, uint8_t* buffer, size_t size, off_t offset)
{
uint32_t i, writtenbytes = 0, writebytes = 0;
char* data = NULL;
block_list_t* blist = &node->block_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; i<MAX_DATABLOCKS && !data; i++) {
if (blist->data[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;
}

View file

@ -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

View file

@ -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;

View file

@ -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;
}

View file

@ -1,2 +1 @@
HalloXA!!
1