Kernel: Move setting file flags and r/w mode to VFS::open()

Previously, VFS::open() would only use the passed flags for permission checking
purposes, and Process::sys$open() would set them on the created FileDescription
explicitly. Now, they should be set by VFS::open() on any files being opened,
including files that the kernel opens internally.

This also lets us get rid of the explicit check for whether or not the returned
FileDescription was a preopen fd, and in fact, fixes a bug where a read-only
preopen fd without any other flags would be considered freshly opened (due to
O_RDONLY being indistinguishable from 0) and granted a new set of flags.
This commit is contained in:
Sergey Bugaev 2020-01-19 01:15:52 +03:00 committed by Andreas Kling
parent 544b8286da
commit d0d13e2bf5
Notes: sideshowbarker 2024-07-19 09:58:21 +09:00
4 changed files with 10 additions and 12 deletions

View file

@ -277,7 +277,10 @@ KResultOr<NonnullRefPtr<FileDescription>> VFS::open(StringView path, int options
inode.truncate(0);
inode.set_mtime(kgettimeofday().tv_sec);
}
return FileDescription::create(custody);
auto description = FileDescription::create(custody);
description->set_rw_mode(options);
description->set_file_flags(options);
return description;
}
KResult VFS::mknod(StringView path, mode_t mode, dev_t dev, Custody& base)
@ -309,8 +312,6 @@ KResult VFS::mknod(StringView path, mode_t mode, dev_t dev, Custody& base)
KResultOr<NonnullRefPtr<FileDescription>> VFS::create(StringView path, int options, mode_t mode, Custody& parent_custody, Optional<UidAndGid> owner)
{
(void)options;
if (!is_socket(mode) && !is_fifo(mode) && !is_block_device(mode) && !is_character_device(mode)) {
// Turn it into a regular file. (This feels rather hackish.)
mode |= 0100000;
@ -332,7 +333,10 @@ KResultOr<NonnullRefPtr<FileDescription>> VFS::create(StringView path, int optio
return KResult(error);
auto new_custody = Custody::create(&parent_custody, p.basename(), *new_file, parent_custody.mount_flags());
return FileDescription::create(*new_custody);
auto description = FileDescription::create(*new_custody);
description->set_rw_mode(options);
description->set_file_flags(options);
return description;
}
KResult VFS::mkdir(StringView path, mode_t mode, Custody& base)