mirror of
https://github.com/RGBCube/serenity
synced 2025-05-15 09:34:59 +00:00
Kernel: Improve ProcFS behavior in low memory conditions
When ProcFS could no longer allocate KBuffer objects to serve calls to read, it would just return 0, indicating EOF. This then triggered parsing errors because code assumed it read the file. Because read isn't supposed to return ENOMEM, change ProcFS to populate the file data upon file open or seek to the beginning. This also means that calls to open can now return ENOMEM if needed. This allows the caller to either be able to successfully open the file and read it, or fail to open it in the first place.
This commit is contained in:
parent
b36f57e570
commit
f98ca35b83
24 changed files with 398 additions and 243 deletions
|
@ -299,13 +299,19 @@ KResultOr<NonnullRefPtr<FileDescription>> VFS::open(StringView path, int options
|
|||
if (metadata.is_fifo()) {
|
||||
auto fifo = inode.fifo();
|
||||
if (options & O_WRONLY) {
|
||||
auto description = fifo->open_direction_blocking(FIFO::Direction::Writer);
|
||||
auto open_result = fifo->open_direction_blocking(FIFO::Direction::Writer);
|
||||
if (open_result.is_error())
|
||||
return open_result.error();
|
||||
auto& description = open_result.value();
|
||||
description->set_rw_mode(options);
|
||||
description->set_file_flags(options);
|
||||
description->set_original_inode({}, inode);
|
||||
return description;
|
||||
} else if (options & O_RDONLY) {
|
||||
auto description = fifo->open_direction_blocking(FIFO::Direction::Reader);
|
||||
auto open_result = fifo->open_direction_blocking(FIFO::Direction::Reader);
|
||||
if (open_result.is_error())
|
||||
return open_result.error();
|
||||
auto& description = open_result.value();
|
||||
description->set_rw_mode(options);
|
||||
description->set_file_flags(options);
|
||||
description->set_original_inode({}, inode);
|
||||
|
@ -340,8 +346,10 @@ KResultOr<NonnullRefPtr<FileDescription>> VFS::open(StringView path, int options
|
|||
inode.set_mtime(kgettimeofday().tv_sec);
|
||||
}
|
||||
auto description = FileDescription::create(custody);
|
||||
description->set_rw_mode(options);
|
||||
description->set_file_flags(options);
|
||||
if (!description.is_error()) {
|
||||
description.value()->set_rw_mode(options);
|
||||
description.value()->set_file_flags(options);
|
||||
}
|
||||
return description;
|
||||
}
|
||||
|
||||
|
@ -400,8 +408,10 @@ KResultOr<NonnullRefPtr<FileDescription>> VFS::create(StringView path, int optio
|
|||
|
||||
auto new_custody = Custody::create(&parent_custody, p.basename(), inode_or_error.value(), parent_custody.mount_flags());
|
||||
auto description = FileDescription::create(*new_custody);
|
||||
description->set_rw_mode(options);
|
||||
description->set_file_flags(options);
|
||||
if (!description.is_error()) {
|
||||
description.value()->set_rw_mode(options);
|
||||
description.value()->set_file_flags(options);
|
||||
}
|
||||
return description;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue