add flags to fildes_t

allow lseek for CHARDEVICE

support for O_APPEND, O_CREATE and O_EXCL
This commit is contained in:
Marian Ohligs 2011-06-21 14:17:57 +02:00
parent 5d8da1103d
commit aafb9d2cbb
4 changed files with 34 additions and 12 deletions

View file

@ -162,4 +162,3 @@ vfs_node_t* findnode_fs(const char* name)
return ret;
}

View file

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

View file

@ -30,6 +30,7 @@ extern "C" {
typedef struct fildes {
vfs_node_t* node; /* */
off_t offset; /* */
int flags; /* */
int mode; /* */
} fildes_t;

View file

@ -26,9 +26,14 @@
#include <metalsvm/spinlock.h>
#include <metalsvm/time.h>
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)