summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem
AgeCommit message (Collapse)Author
2021-05-28Kernel: Rename Custody::create() => try_create()Andreas Kling
The try_ prefix indicates that this may fail. :^)
2021-05-28Kernel: Use a KString for Custody::m_nameAndreas Kling
2021-05-27Kernel+AK: Move UBSanitizer to AK, and to AK namespaceAndrew Kaster
In preparation for copying UBSanitizer to userspace, move the header to AK :^)
2021-05-26Kernel: Switch Inode to IntrusiveList from InlineLinkedListBrian Gianforcaro
2021-05-22Kernel: Remove an allocation from VFS::resolve_path_without_veil (#7287)Mart G
Use GenericLexer to replace a call to StringView::split() since that returns its result in a heap-allocating Vector.
2021-05-19Kernel: static vs non-static constexpr variablesLenny Maiorani
Problem: - `static` variables consume memory and sometimes are less optimizable. - `static const` variables can be `constexpr`, usually. - `static` function-local variables require an initialization check every time the function is run. Solution: - If a global `static` variable is only used in a single function then move it into the function and make it non-`static` and `constexpr`. - Make all global `static` variables `constexpr` instead of `const`. - Change function-local `static const[expr]` variables to be just `constexpr`.
2021-05-19Kernel: Expose FileSystem's fragment sizeJustin
This commit will add a fragment_size() function similar to the block_size() function.
2021-05-19Kernel: Ignore null parent custody without error in VFS::openMax Wipfli
This modifies the error checks in VFS::open after the call to resolve_path to ignore a null parent custody if there is no error, as this is expected when the path to resolve points to "/". Rather, a null parent custody only constitutes an error if it is accompanied by ENOENT. This behavior is documented in the VFS::resolve_path_without_veil method. To accompany this change, the order of the error checks have been changed to more naturally fit the new logic.
2021-05-16Kernel: Rename Console => ConsoleDeviceLiav A
This change will help to distinguish between the console device and the Console abstraction layer in the Graphics subsystem later.
2021-05-16AK+Kernel+LibELF: Remove the need for `IteratorDecision::Continue`Nicholas Baron
By constraining two implementations, the compiler will select the best fitting one. All this will require is duplicating the implementation and simplifying for the `void` case. This constraining also informs both the caller and compiler by passing the callback parameter types as part of the constraint (e.g.: `IterationFunction<int>`). Some `for_each` functions in LibELF only take functions which return `void`. This is a minimal correctness check, as it removes one way for a function to incompletely do something. There seems to be a possible idiom where inside a lambda, a `return;` is the same as `continue;` in a for-loop.
2021-05-13Kernel: Make UserOrKernelBuffer R/W helpers return KResultOr<size_t>Andreas Kling
This makes error propagation less cumbersome (and also exposed some places where we were not doing it.)
2021-05-13Kernel: Make InodeWatcher::crate API OOM safeBrian Gianforcaro
2021-05-13Kernel: Replace make<T>() with adopt_own_if_nonnull() in Ext2FileSystemBrian Gianforcaro
The make<T> factory function allocates internally and immediately dereferences the pointer, and always returns a NonnullOwnPtr<T> making it impossible to propagate an error on OOM.
2021-05-13Kernel: Replace bare new in Custody::create() with adopt_ref_if_nonnullBrian Gianforcaro
2021-05-13Kernel: Remove unused header from FileDescription.cppBrian Gianforcaro
2021-05-13Kernel: Move FileDescription::get_dir_entries to KResultOr<ssize_t>Brian Gianforcaro
This normalizes the error handling with the rest of the subsystem.
2021-05-13Kernel: Make FileDescription::create() APIs OOM safeBrian Gianforcaro
2021-05-13Kernel: Make InodeFile::create() API OOM safeBrian Gianforcaro
2021-05-12Kernel: Implement multi-watch InodeWatcher :^)sin-ack
This patch modifies InodeWatcher to switch to a one watcher, multiple watches architecture. The following changes have been made: - The watch_file syscall is removed, and in its place the create_iwatcher, iwatcher_add_watch and iwatcher_remove_watch calls have been added. - InodeWatcher now holds multiple WatchDescriptions for each file that is being watched. - The InodeWatcher file descriptor can be read from to receive events on all watched files. Co-authored-by: Gunnar Beutner <gunnar@beutner.name>
2021-05-12Kernel+LibC: Make get_dir_entries syscall retriableMart G
The get_dir_entries syscall failed if the serialized form of all the directory entries together was too large to fit in its temporary buffer. Now the kernel uses a fixed size buffer, that is flushed to an output buffer when it is full. If this flushing operation fails because there is not enough space available, the syscall will return -EINVAL. That error code is then used in userspace as a signal to allocate a larger buffer and retry the syscall.
2021-05-10Kernel: Plumb OOM propagation through Custody factoryBrian Gianforcaro
Modify the Custody::create(..) API so it has the ability to propagate OOM back to the caller.
2021-05-08Kernel: Traverse ext2 directories blockwise.Mart G
Instead of reading in the entire contents of a directory into a large buffer, we can iterate block by block. This only requires a small buffer. Because directory entries are guaranteed to never span multiple blocks we do not have to handle any edge cases related to that.
2021-05-08Kernel: Place ext2 dir entries so they don't span multiple blocksMart G
Ext2 dir entries spanning multiple blocks are not allowed. If they do occur they are flagged as corrupt by e2fsck for example.
2021-05-08Kernel-VFS: Fixed kernel crash if parent custody is nullr-paiva
In VFS::rename, if new_path is equal to '/', then, parent custody is set to null. VFS::rename would then use parent custody without checking it first. Fixed VFS::rename to check both old and new path parent custody before actually using them.
2021-05-07Kernel: Allow Ext2FSInode::write_bytes calls with a byte count of zeroMart G
write_bytes is called with a count of 0 bytes if a directory is being deleted, because in that case even the . and .. pseudo directories are getting removed. In this case write_bytes is now a no-op. Before write_bytes would fail because it would check to see if there were any blocks available to write in (even though it wasn't going to write in them anyway). This behaviour was uncovered because of a recent change where directories are correctly reduced in size. Which in this case results in all the blocks being removed from the inode, whereas previously there would be some stale blocks around to pass the check.
2021-05-07Kernel: Set unused block pointers in ext2 inodes to zeroMart G
e2fsck considers all blocks reachable through any of the pointers in m_raw_inode.i_block as part of this inode regardless of the value in m_raw_inode.i_size. When it finds more blocks than the amount that is indicated by i_size or i_blocks it offers to repair the filesystem by changing those values. That will actually cause further corruption. So we must zero all pointers to blocks that are now unused.
2021-05-06Kernel: Resize Ext2FSInode when writing directory contents (#6897)Mart G
Ext2 directory contents are stored in a linked list of ext2_dir_entry structs. There is no sentinel value to determine where the list ends. Instead the list fills the entirety of the allocated space for the inode. Previously the inode was not correctly resized when it became smaller. This resulted in stale data being interpreted as part of the linked list of directory entries.
2021-05-05Kernel: Allow remapping Caps Lock to Control (#6883)Spencer Dixon
We use a global setting to determine if Caps Lock should be remapped to Control because we don't care how keyboard events come in, just that they should be massaged into different scan codes. The `proc` filesystem is able to manipulate this global variable using the `sysctl` utility like so: ``` # sysctl caps_lock_to_ctrl=1 ```
2021-05-05Kernel: Fix `write`s to `ProcFS` (#6879)Spencer Dixon
When using `sysctl` you can enable/disable values by writing to the ProcFS. Some drift must have occured where writing was failing due to a missing `set_mtime` call. Whenever one `write`'s a file the modified time (mtime) will be updated so we need to implement this interface in ProcFS.
2021-05-04Kernel: Return one kernel frame from procfs$tid_stack for normal users.Brian Gianforcaro
Previously we would return a 0xdeadc0de frame for every kernel frame in the real kernel stack when an non super-user issued the request. This isn't useful, and just produces visual clutter in tools which attempt to symbolize stacks.
2021-05-04Kernel: Remove unused function ProcFS::add_sys_stringBrian Gianforcaro
2021-05-04Kernel: Remove unused header includes from ProcFS.cppBrian Gianforcaro
2021-05-03Kernel: Fix some 64-bit portability issuesGunnar Beutner
2021-05-02Kernel: Fix ProcFS for non-process backed sub dirsSpencer Dixon
While hacking on `sysctl` an issue in ProcFS was making me unable to read/write from `/proc/sys/XXX`. Some directories in the ProcFS are not actually backed by a process and need to return `nullptr` so callbacks get properly set. We now do an explicit check for the parent to ensure it's one that is PID-based.
2021-05-02Kernel: Change Inode::{read/write}_bytes interface to KResultOr<ssize_t>Brian Gianforcaro
The error handling in all these cases was still using the old style negative values to indicate errors. We have a nicer solution for this now with KResultOr<T>. This change switches the interface and then all implementers to use the new style.
2021-05-01Kernel: Harden Ext2FileSystem Vector usage against OOM.Brian Gianforcaro
2021-05-01Kernel: Harden DevFS Vector usage against OOM.Brian Gianforcaro
The dance here is not complicated, but it is something that should be taken note of. Since we append to both lists, we don't want to orphan the new Inode in the m_links/m_subfolders Vector in the event that the append to m_parent_fs.m_nodes fails.
2021-04-30Kernel: chmod()/chown() for PTYs should return EROFSGunnar Beutner
All the other methods already do this and this is also what OpenSSH expects when trying to change modes/ownership for devpts files.
2021-04-30Kernel: Make Inode::set_{a,c,m}time return KResultAndreas Kling
This exposed some missing error propagation, which this patch also takes care of.
2021-04-30Kernel: Closing a file descriptor should not always close the fileGunnar Beutner
When there is more than one file descriptor for a file closing one of them should not close the underlying file. Previously this relied on the file's ref_count() but at least for sockets this didn't work reliably.
2021-04-29Everywhere: "indexes" => "indices"Andreas Kling
I've wasted a silly amount of time in the past fretting over which of these words to use. Let's just choose one and use it everywhere. :^)
2021-04-29Everywhere: "file name" => "filename"Andreas Kling
2021-04-25Kernel: Remove the now defunct `LOCKER(..)` macro.Brian Gianforcaro
2021-04-25Kernel: Add lock_count to procfs$all when LOCK_DEBUG is enabled.Brian Gianforcaro
2021-04-23AK: Rename adopt() to adopt_ref()Andreas Kling
This makes it more symmetrical with adopt_own() (which is used to create a NonnullOwnPtr from the result of a naked new.)
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-21Kernel: Convert String::format() => String::formatted()Andreas Kling
2021-04-20Ext2FS: Put bg_used_dirs_count debug logging behind EXT2_DEBUGAndreas Kling
2021-04-17Kernel+LibC: Update struct stat to use struct timespec instead of time_tGunnar Beutner
Some programs unconditionally expect struct stat to have nanosecond support.
2021-04-16AK+Kernel: Make IntrusiveList capable of holding non-raw pointersAnotherTest
This should allow creating intrusive lists that have smart pointers, while remaining free (compared to the impl before this commit) when holding raw pointers :^) As a sidenote, this also adds a `RawPtr<T>` type, which is just equivalent to `T*`. Note that this does not actually use such functionality, but is only expected to pave the way for #6369, to replace NonnullRefPtrVector<T> with intrusive lists. As it is with zero-cost things, this makes the interface a bit less nice by requiring the type name of what an `IntrusiveListNode` holds (and optionally its container, if not RawPtr), and also requiring the type of the container (normally `RawPtr`) on the `IntrusiveList` instance.