Compare commits

...

2 Commits

Author SHA1 Message Date
2fbc6105d7
kernel+libc: Add O_DIRECTORY and use it in opendir()
All checks were successful
continuous-integration/drone/push Build is passing
2023-03-29 22:23:52 +02:00
61f969c60c
ls: Explicitly initialize booleans to false 2023-03-29 22:19:53 +02:00
4 changed files with 6 additions and 4 deletions

View File

@ -8,8 +8,8 @@
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
StringView pathname; StringView pathname;
bool show_all; bool show_all { false };
bool show_almost_all; bool show_almost_all { false };
ArgumentParser parser; ArgumentParser parser;
parser.add_positional_argument(pathname, "directory"_sv, "/"_sv); parser.add_positional_argument(pathname, "directory"_sv, "/"_sv);

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 ((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); if ((flags & O_WRONLY) && (flags & O_TRUNC)) inode->truncate(0);
int fd = TRY(current->allocate_fd(0)); int fd = TRY(current->allocate_fd(0));

View File

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

View File

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