Kernel, libc: Add O_APPEND and stub out O_CREAT and O_TRUNC
This commit is contained in:
parent
651ffe6d64
commit
a3c6635f3e
@ -17,6 +17,9 @@
|
|||||||
#define OPEN_NONBLOCK 4
|
#define OPEN_NONBLOCK 4
|
||||||
#define OPEN_CLOEXEC 8
|
#define OPEN_CLOEXEC 8
|
||||||
#define OPEN_DIRECTORY 16
|
#define OPEN_DIRECTORY 16
|
||||||
|
#define OPEN_TRUNCATED 32
|
||||||
|
#define OPEN_CREATE 64
|
||||||
|
#define OPEN_APPEND 128
|
||||||
|
|
||||||
#define SEEK_SET 0
|
#define SEEK_SET 0
|
||||||
#define SEEK_CUR 1
|
#define SEEK_CUR 1
|
||||||
@ -154,6 +157,8 @@ void sys_open(Context* context, const char* filename, int flags)
|
|||||||
VFS::Node* node = VFS::resolve_path(kfilename);
|
VFS::Node* node = VFS::resolve_path(kfilename);
|
||||||
if (!node)
|
if (!node)
|
||||||
{
|
{
|
||||||
|
bool create = (flags & OPEN_CREATE) > 0;
|
||||||
|
if (create) kwarnln("FIXME: open(O_CREAT) is not implemented");
|
||||||
kfree(kfilename);
|
kfree(kfilename);
|
||||||
context->rax = -ENOENT;
|
context->rax = -ENOENT;
|
||||||
return;
|
return;
|
||||||
@ -173,6 +178,17 @@ void sys_open(Context* context, const char* filename, int flags)
|
|||||||
|
|
||||||
bool only_directory = (flags & OPEN_DIRECTORY) > 0;
|
bool only_directory = (flags & OPEN_DIRECTORY) > 0;
|
||||||
|
|
||||||
|
bool truncate = (flags & OPEN_TRUNCATED) > 0;
|
||||||
|
if (truncate)
|
||||||
|
{
|
||||||
|
kfree(kfilename);
|
||||||
|
kerrorln("FIXME: open(O_TRUNC) is not implemented");
|
||||||
|
context->rax = -ENOTSUP;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool append = (flags & OPEN_APPEND) > 0;
|
||||||
|
|
||||||
if (only_directory && node->type != VFS_DIRECTORY)
|
if (only_directory && node->type != VFS_DIRECTORY)
|
||||||
{
|
{
|
||||||
kfree(kfilename);
|
kfree(kfilename);
|
||||||
@ -188,6 +204,12 @@ void sys_open(Context* context, const char* filename, int flags)
|
|||||||
|
|
||||||
kfree(kfilename);
|
kfree(kfilename);
|
||||||
current_task->files[fd].open(node, can_read, can_write, able_to_block, close_on_exec);
|
current_task->files[fd].open(node, can_read, can_write, able_to_block, close_on_exec);
|
||||||
|
|
||||||
|
if (append && current_task->files[fd].node()->type != VFS_DEVICE)
|
||||||
|
{
|
||||||
|
current_task->files[fd].seek((long)current_task->files[fd].length());
|
||||||
|
}
|
||||||
|
|
||||||
context->rax = fd;
|
context->rax = fd;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,12 @@
|
|||||||
#define O_CLOEXEC 8
|
#define O_CLOEXEC 8
|
||||||
/* Refuse to open the file if it is not a directory. */
|
/* Refuse to open the file if it is not a directory. */
|
||||||
#define O_DIRECTORY 16
|
#define O_DIRECTORY 16
|
||||||
|
/* Truncate the file on open. */
|
||||||
|
#define O_TRUNC 32
|
||||||
|
/* Create the file if it doesn't exist. */
|
||||||
|
#define O_CREAT 64
|
||||||
|
/* Open the file for appending. */
|
||||||
|
#define O_APPEND 128
|
||||||
|
|
||||||
/* Duplicate a file descriptor. */
|
/* Duplicate a file descriptor. */
|
||||||
#define F_DUPFD 0
|
#define F_DUPFD 0
|
||||||
|
Loading…
Reference in New Issue
Block a user