diff --git a/fs/fs.c b/fs/fs.c index 61f56e99..49465a16 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -162,4 +162,3 @@ vfs_node_t* findnode_fs(const char* name) return ret; } - diff --git a/include/metalsvm/fs.h b/include/metalsvm/fs.h index 4f4f5895..6f0dc887 100644 --- a/include/metalsvm/fs.h +++ b/include/metalsvm/fs.h @@ -37,19 +37,21 @@ //#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_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_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 +//#define O_NDELAY 2048 +//#define O_SYNC 4096 +//#define O_ASYNC 8192 /*lseek defines*/ #ifndef SEEK_SET diff --git a/include/metalsvm/fs_types.h b/include/metalsvm/fs_types.h index 7f2d75be..da4e4b64 100644 --- a/include/metalsvm/fs_types.h +++ b/include/metalsvm/fs_types.h @@ -30,6 +30,7 @@ extern "C" { typedef struct fildes { vfs_node_t* node; /* */ off_t offset; /* */ + int flags; /* */ int mode; /* */ } fildes_t; diff --git a/kernel/syscall.c b/kernel/syscall.c index 31086347..ba1769dd 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -26,9 +26,14 @@ #include #include + static int sys_write(int fd, const char *buf, size_t len) { unsigned int wrotebytes; + if (per_core(current_task)->fildes_table[fd].flags & O_APPEND) { + per_core(current_task)->fildes_table[fd].offset = per_core(current_task)->fildes_table[fd].node->block_size; + } + wrotebytes = write_fs(per_core(current_task)->fildes_table[fd].node, (uint8_t*)buf, len, per_core(current_task)->fildes_table[fd].offset); //kprintf("writing into filesystem -- fd:%i, Filelength:%i, Writtenbytes: %i, Bufferlength: %s \n", fd, len, wrotebytes, buf); per_core(current_task)->fildes_table[fd].offset += wrotebytes; @@ -39,16 +44,30 @@ static int sys_write(int fd, const char *buf, size_t len) static int sys_open(const char* file, int flags, int mode) { int fd; + if (!findnode_fs((char*) file)) { + if (flags & O_CREAT) { + //create file, not implemented yet + } + return -EINVAL; + } else { + if ((flags & O_CREAT) && (flags & O_EXCL)); + return -EINVAL; + } + for (fd = 3; fd < NR_OPEN; fd++) { if (per_core(current_task)->fildes_table[fd].node == NULL) { per_core(current_task)->fildes_table[fd].node = findnode_fs((char*) file); - return fd; + per_core(current_task)->fildes_table[fd].mode = mode; + per_core(current_task)->fildes_table[fd].flags = flags; } } if (fd >= NR_OPEN) { kprintf("Unable to create filedescriptor"); return -EINVAL; } + + return fd; + } static int sys_close(int fd) @@ -77,7 +96,8 @@ static int sys_lseek(int fd, off_t pos, int origin) { int ret = -EINVAL; - if (BUILTIN_EXPECT(per_core(current_task)->fildes_table[fd].node->type != FS_FILE, 0)) + if (BUILTIN_EXPECT(per_core(current_task)->fildes_table[fd].node->type != FS_FILE + && per_core(current_task)->fildes_table[fd].node->type != FS_CHARDEVICE, 0)); return -EINVAL; switch(origin)