kernel+libc: Add O_DIRECTORY and use it in opendir()
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-03-29 22:23:52 +02:00
parent 61f969c60c
commit 2fbc6105d7
Signed by: apio
GPG Key ID: B8A7D06E42258954
3 changed files with 4 additions and 2 deletions

View File

@ -44,6 +44,8 @@ Result<u64> sys_open(Registers*, SyscallArgs args)
if ((flags & O_WRONLY) && (inode->mode() & S_IWUSR) == 0) return err(EACCES);
}
if(inode->type() != VFS::InodeType::Directory && (flags & O_DIRECTORY)) return err(ENOTDIR);
if ((flags & O_WRONLY) && (flags & O_TRUNC)) inode->truncate(0);
int fd = TRY(current->allocate_fd(0));

View File

@ -12,6 +12,7 @@
#define O_TRUNC 32
#define O_NONBLOCK 64
#define O_CLOEXEC 128
#define O_DIRECTORY 256
#define O_ACCMODE O_RDWR

View File

@ -13,8 +13,7 @@ extern "C"
DIR* dp = (DIR*)malloc(sizeof(DIR));
if (!dp) { return nullptr; }
// FIXME: Use O_DIRECTORY (validate that path is actually a directory)
int fd = open(path, O_RDONLY);
int fd = open(path, O_RDONLY | O_DIRECTORY);
if (fd < 0)
{
free(dp);