diff --git a/arch/x86/include/asm/kb.h b/arch/x86/include/asm/kb.h index 74d66d6c..99991d8b 100644 --- a/arch/x86/include/asm/kb.h +++ b/arch/x86/include/asm/kb.h @@ -43,6 +43,16 @@ extern "C" { */ void keyboard_init(void); +typedef struct +{ + char* buffer; + size_t maxsize; + size_t size; + tid_t tid; +} kb_buffer_t; + +kb_buffer_t kb_buffer; + #endif #ifdef __cplusplus diff --git a/arch/x86/kernel/kb.c b/arch/x86/kernel/kb.c index ac07d146..ce377862 100644 --- a/arch/x86/kernel/kb.c +++ b/arch/x86/kernel/kb.c @@ -24,6 +24,16 @@ #ifdef CONFIG_KEYBOARD +kb_buffer_t kb_buffer = {NULL, 0, 0, 0 }; + +kb_flush() { + kfree(kb_buffer.buffer, (kb_buffer.maxsize * sizeof(char))); + kb_buffer.buffer = NULL; + kb_buffer.size = 0; + kb_buffer.maxsize = 0; + kb_buffer.tid = 0; +} + /* * KBDUS means US Keyboard Layout. This is a scancode table * used to layout a standard US keyboard. I have left some @@ -99,6 +109,15 @@ static void keyboard_handler(struct state *r) * you would add 128 to the scancode when you look for it */ kputchar(kbdus[scancode]); + if (kb_buffer.size <= kb_buffer.maxsize) { + memcpy(kb_buffer.buffer + kb_buffer.size, &kbdus[scancode], 1); + kb_buffer.size++; + } + if (scancode == 28 || scancode == 15 || kb_buffer.size >= kb_buffer.maxsize) { + wakeup_task(kb_buffer.tid); + reschedule(); + } + } } diff --git a/drivers/stdin/stdin.c b/drivers/stdin/stdin.c index 07f7a4df..238f6c24 100644 --- a/drivers/stdin/stdin.c +++ b/drivers/stdin/stdin.c @@ -23,14 +23,27 @@ #include #include #include +#include + /* Implementation of a simple stdin device */ static ssize_t stdin_read(vfs_node_t* node, uint8_t* buffer, size_t size, off_t offset) { - while(size) { - size -= kputs((char*)buffer); - } + kb_buffer.buffer = kmalloc(size * sizeof(char)); + kb_buffer.maxsize = size; + kb_buffer.size = 0; + kb_buffer.tid = per_core(current_task)->id; + block_task(per_core(current_task)->id); + reschedule(); + size = kb_buffer.size; + + memcpy(buffer, kb_buffer.buffer, size); + + /*cleaning up */ + kb_flush(); + + //kprintf("Size: %i, offset: %i, buffer: %s", size, buffer, offset); return size; } diff --git a/fs/initrd.c b/fs/initrd.c index d8b193b9..ca9bf773 100644 --- a/fs/initrd.c +++ b/fs/initrd.c @@ -144,7 +144,6 @@ static ssize_t initrd_write(vfs_node_t* node, uint8_t* buffer, size_t size, off_ * for the next block. */ memcpy(data + offset, buffer, size); - return size; } diff --git a/include/metalsvm/fs.h b/include/metalsvm/fs.h index 695bf107..4f4f5895 100644 --- a/include/metalsvm/fs.h +++ b/include/metalsvm/fs.h @@ -37,6 +37,31 @@ //#define FS_SYMLINK 0x06 //#define FS_MOUNTPOINT 0x08 // Is the file an active mountpoint? +/*open flags*/ +#define O_RDONLY 0 +#define O_WRONLY 1 +#define O_RDWR 2 + +#define O_CREAT 64 +#define O_EXCL 128 +#define O_NOCTTY 256 +#define O_TRUNC 512 +#define O_APPEND 1024 +#define O_NDELAY 2048 +#define O_SYNC 4096 +#define O_ASYNC 8192 + +/*lseek defines*/ +#ifndef SEEK_SET +#define SEEK_SET 0 /* set file offset to offset */ +#endif +#ifndef SEEK_CUR +#define SEEK_CUR 1 /* set file offset to current plus offset */ +#endif +#ifndef SEEK_END +#define SEEK_END 2 /* set file offset to EOF plus offset */ +#endif + struct vfs_node; /** @defgroup fsprototypes FS access function prototypes diff --git a/include/metalsvm/stdio.h b/include/metalsvm/stdio.h index 527fd2b4..6f9fc20e 100644 --- a/include/metalsvm/stdio.h +++ b/include/metalsvm/stdio.h @@ -23,16 +23,6 @@ * @brief Stringstream related functions. Mainly printf-stuff. */ -#ifndef SEEK_SET -#define SEEK_SET 0 /* set file offset to offset */ -#endif -#ifndef SEEK_CUR -#define SEEK_CUR 1 /* set file offset to current plus offset */ -#endif -#ifndef SEEK_END -#define SEEK_END 2 /* set file offset to EOF plus offset */ -#endif - #ifndef __STDIO_H__ #define __STDIO_H__ diff --git a/kernel/syscall.c b/kernel/syscall.c index e27d6d3f..31086347 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -77,7 +77,8 @@ static int sys_lseek(int fd, off_t pos, int origin) { int ret = -EINVAL; - /* Beware: still not checking the filetype & size*/ + if (BUILTIN_EXPECT(per_core(current_task)->fildes_table[fd].node->type != FS_FILE, 0)) + return -EINVAL; switch(origin) { diff --git a/newlib/examples/hello.c b/newlib/examples/hello.c index 134f2522..fd357d5f 100644 --- a/newlib/examples/hello.c +++ b/newlib/examples/hello.c @@ -28,28 +28,9 @@ extern int errno; int main(int argc, char** argv) { int i; - long offset_x = 5; - char* str = (char *)malloc(50 * sizeof(char)); - FILE* testfile; - testfile = fopen("/bin/test", "w+r"); - setbuf(testfile, NULL); + char* str = (char *)malloc(40000 * sizeof(char)); + scanf("%s", str); + printf("SCANF: %s", str); fflush(NULL); - fwrite("wsx", 3, 1, testfile); - fseek(testfile, 2, SEEK_CUR); - fwrite("nextnextnext", 1, 10, testfile); - - fclose(testfile); - - testfile = fopen("/bin/test", "w+r"); - setbuf(testfile, NULL); - fread(str, 2, 40, testfile); - printf("reading (/bin/test):%s\n", str); - - testfile = fopen("/bin/test", "w+r"); - setbuf(testfile, NULL); - fread(str, 1, 10, testfile); - fwrite("wtest1\n", 1, 7, testfile); - fread(str, 1, 10, testfile); - - return errno; +return errno; }