diff options
author | Ian Moffett <ian@osmora.org> | 2025-10-17 14:34:43 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-10-17 14:34:43 -0400 |
commit | 59abe1956c72576cbd9c362603b685e24e30ca41 (patch) | |
tree | 6784812f90f215958cc7ccef85ff03ae2445c9ba /src/sys | |
parent | ca8023a78e9d851896dc37141a213d3ac6895834 (diff) |
kern: filedesc: Add O_CREAT flag for fd_open()
Add an O_CREAT flag to the ABI headers so that files can be created in
the VFS.
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'src/sys')
-rw-r--r-- | src/sys/include/sys/fcntl.h | 1 | ||||
-rw-r--r-- | src/sys/os/os_filedes.c | 13 |
2 files changed, 13 insertions, 1 deletions
diff --git a/src/sys/include/sys/fcntl.h b/src/sys/include/sys/fcntl.h index 30d2ec4..1ab3e71 100644 --- a/src/sys/include/sys/fcntl.h +++ b/src/sys/include/sys/fcntl.h @@ -43,6 +43,7 @@ #define O_RDONLY 0x00 #define O_RDWR BIT(1) #define O_WRONLY BIT(2) +#define O_CREAT BIT(3) /* File access mode flags */ #define O_ACCMODE (O_RDWR | O_WRONLY) diff --git a/src/sys/os/os_filedes.c b/src/sys/os/os_filedes.c index 95452af..ca56fc3 100644 --- a/src/sys/os/os_filedes.c +++ b/src/sys/os/os_filedes.c @@ -160,8 +160,10 @@ fd_open(const char *path, mode_t mode) { struct filedesc *fd; struct nameidata nd; + struct vop_create_args creat_args; struct proc *self = proc_self(); struct vnode *vp; + uint32_t namei_flags = 0; int error; /* We need the current proc */ @@ -180,12 +182,21 @@ fd_open(const char *path, mode_t mode) } /* + * If we are creating a new file, we'll need to + * get the parent vnode so that we can use the + * create vop. + */ + if (ISSET(mode, O_CREAT)) { + namei_flags |= NAMEI_CREATE; + } + + /* * Now we try to do the lookup, we'll need * the vnode for file references to be * useful */ nd.path = path; - nd.flags = 0; + nd.flags = namei_flags; nd.vp_res = &vp; error = namei(&nd); if (error < 0) { |