kernel+libc: Add O_DIRECTORY and use it in opendir()
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
61f969c60c
commit
2fbc6105d7
@ -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));
|
||||
|
@ -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
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user