mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-03 01:38:52 +00:00
Kernel: Add Inode::truncate(size).
- Use this to implement the O_TRUNC open flag. - Fix creat() to pass O_CREAT | O_TRUNC | O_WRONLY. - Make sure we truncate wherever appropriate.
This commit is contained in:
parent
e9f2cc3595
commit
0058da734e
Notes:
sideshowbarker
2024-07-19 14:55:24 +09:00
Author: https://github.com/awesomekling
Commit: 0058da734e
8 changed files with 26 additions and 8 deletions
|
@ -170,7 +170,10 @@ KResultOr<Retained<FileDescriptor>> VFS::open(const String& path, int options, m
|
|||
if (inode_or_error.is_error())
|
||||
return inode_or_error.error();
|
||||
|
||||
auto metadata = inode_or_error.value()->metadata();
|
||||
auto inode = inode_or_error.value();
|
||||
auto metadata = inode->metadata();
|
||||
|
||||
bool should_truncate_file = false;
|
||||
|
||||
// NOTE: Read permission is a bit weird, since O_RDONLY == 0,
|
||||
// so we check if (NOT write_only OR read_and_write)
|
||||
|
@ -183,6 +186,7 @@ KResultOr<Retained<FileDescriptor>> VFS::open(const String& path, int options, m
|
|||
return KResult(-EACCES);
|
||||
if (metadata.is_directory())
|
||||
return KResult(-EISDIR);
|
||||
should_truncate_file = options & O_TRUNC;
|
||||
}
|
||||
|
||||
if (metadata.is_device()) {
|
||||
|
@ -193,10 +197,12 @@ KResultOr<Retained<FileDescriptor>> VFS::open(const String& path, int options, m
|
|||
auto descriptor_or_error = (*it).value->open(options);
|
||||
if (descriptor_or_error.is_error())
|
||||
return descriptor_or_error.error();
|
||||
descriptor_or_error.value()->set_original_inode(Badge<VFS>(), *inode_or_error.value());
|
||||
descriptor_or_error.value()->set_original_inode(Badge<VFS>(), *inode);
|
||||
return descriptor_or_error;
|
||||
}
|
||||
return FileDescriptor::create(*inode_or_error.value());
|
||||
if (should_truncate_file)
|
||||
inode->truncate(0);
|
||||
return FileDescriptor::create(*inode);
|
||||
}
|
||||
|
||||
KResultOr<Retained<FileDescriptor>> VFS::create(const String& path, int options, mode_t mode, Inode& base)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue