diff options
author | Anton Kling <anton@kling.gg> | 2024-12-08 19:43:31 +0100 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2024-12-08 19:43:31 +0100 |
commit | a7ef3d06f74c8131b04b41cdf902e3c59f61769f (patch) | |
tree | bfb97ac76b6ceb4282e5c55e5827c8f1c1eebf02 /kernel/fs/vfs.c | |
parent | 3918a0e92f47f0998fadbc19f0a567e985445407 (diff) |
vfs: Force truncation even without permissions
O_TRUNC as a mode does not seem to imply write permissions
but we still wish to truncate the file before giving back a file
descriptor. Therefore the kernel can now override any permission checks
if it wishes to do a truncation while still using the "ordinary path".
Diffstat (limited to 'kernel/fs/vfs.c')
-rw-r--r-- | kernel/fs/vfs.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/kernel/fs/vfs.c b/kernel/fs/vfs.c index c06c71f..3b912ce 100644 --- a/kernel/fs/vfs.c +++ b/kernel/fs/vfs.c @@ -289,7 +289,7 @@ int vfs_open(const char *file, int flags, int mode) { // FIXME: Maybe it is sometimes a TTY? int rc = vfs_create_fd(flags, mode, 0 /*is_tty*/, inode, NULL); if (flags & O_TRUNC) { - vfs_ftruncate(rc, 0); + vfs_ftruncate(rc, 0, 1); } return rc; } @@ -488,12 +488,12 @@ int vfs_dup2(int org_fd, int new_fd) { return 1; } -int vfs_ftruncate(int fd, size_t length) { +int vfs_ftruncate(int fd, size_t length, int force_truncate) { vfs_fd_t *fd_ptr = get_vfs_fd(fd, NULL); if (!fd_ptr) { return -EBADF; } - if (!(fd_ptr->flags & O_READ)) { + if (!(fd_ptr->flags & O_WRITE) && !force_truncate) { return -EINVAL; } vfs_inode_t *inode = fd_ptr->inode; |