summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem/Ext2FileSystem.cpp
AgeCommit message (Collapse)Author
2021-08-14Kernel: Stop allowing implicit conversion from KResult to intAndreas Kling
This patch removes KResult::operator int() and deals with the fallout. This forces a lot of code to be more explicit in its handling of errors, greatly improving readability.
2021-08-14Kernel: Make FileSystem::initialize() return KResultAndreas Kling
This forced me to also come up with error codes for a bunch of situations where we'd previously just panic the kernel.
2021-08-14Kernel: Make Inode::lookup() return a KResultOr<NonnullRefPtr<Inode>>Andreas Kling
This allows file systems to return arbitrary error codes instead of just an Inode or not an Inode.
2021-08-06Kernel: Add convenience values to the Memory::Region::Access enumAndreas Kling
Instead of `Memory::Region::Access::Read | Memory::Region::AccessWrite` you can now say `Memory::Region::Access::ReadWrite`.
2021-08-06Kernel: Move Kernel/Memory/ code into Kernel::Memory namespaceAndreas Kling
2021-08-03Kernel: Handle OOM in DiskCache when mounting Ext2 filesystemsBrian Gianforcaro
Create the disk cache up front, so we can verify it succeeds. Make the KBuffer allocation fail-able, so we can properly handle failure when the user asks up to mount a Ext2 filesystem under OOM conditions.
2021-08-03Kernel: Handle OOM from KBuffer usage in Ext2FS::get_bitmap_block()Brian Gianforcaro
Fixes up error handling on an OOM-able path, and removes one more usage of KBuffer::create_with_size.
2021-07-18Kernel/Ext2FS: Surface Vector allocation failures in block allocationAndreas Kling
2021-07-18Kernel: Make FileSystem::root_inode() return a plain Inode&Andreas Kling
All file system classes are expected to keep their root Inode object in memory, so this function can safely return an Inode&.
2021-07-18Kernel/Ext2FS: Cache the root inode in a member variableAndreas Kling
We often get queried for the root inode, and it will always be cached in memory anyway, so let's make Ext2FS::root_inode() fast by keeping the root inode in a dedicated member variable.
2021-07-18Kernel: Rename Locker => MutexLockerAndreas Kling
2021-07-17Kernel: Remove Inode::directory_entry_count()Andreas Kling
This was only used in one place: VirtualFileSystem::rmdir(), and that has now been converted to a simple directory traversal.
2021-07-17Kernel: Make Inode::create_child() take the name as a StringViewAndreas Kling
No sense in forcing callers to construct a String. One more small step towards not using String in the kernel.
2021-07-17Kernel: Rename Inode::m_lock => m_inode_lockAndreas Kling
This makes file system code much easier to read since it was hard when both the file system and inode locks were called "m_lock".
2021-07-17Kernel: Make FileSystem::class_name() return a StringViewAndreas Kling
2021-07-16Kernel/Ext2FS: Don't hog inode lock in traverse_as_directory()Andreas Kling
Reimplement directory traversal in terms of read_bytes() instead of doing direct block access. This lets us avoid taking the inode lock while iterating over the directory contents.
2021-07-16Kernel/Ext2FS: Don't hog FS lock when calling base class flush_writes()Andreas Kling
Once we've finalized all the file system metadata in flush_writes(), we no longer need to hold the file system lock during the call to BlockBasedFileSystem::flush_writes().
2021-07-16Kernel/Ext2FS: Uncache unknown inode indices when flushing writesAndreas Kling
Ext2FS::get_inode() will remember unknown inode indices that it has been asked about and put them into the inode cache as null inodes. flush_writes() was not null-checking these while iterating, which was a bug I finally managed to hit. Flushing also seemed like a good time to drop unknown inodes from the cache, since there's no good reason to hold to them indefinitely.
2021-07-16Kernel/Ext2FS: Don't hog both locks in Ext2FSInode::lookup()Andreas Kling
This function was acquiring both the inode and file system locks (in that order) which could lead to deadlocks.
2021-07-11Kernel: Rename BlockBasedFS => BlockBasedFileSystemAndreas Kling
2021-07-11Kernel: Rename FS => FileSystemAndreas Kling
This matches our common naming style better.
2021-07-06Kernel: Promote various integers to 64 bits in storage layerJean-Baptiste Boric
2021-06-24Everywhere: Use nothrow new with `adopt_{ref,own}_if_nonnull`Daniel Bertalan
This commit converts naked `new`s to `AK::try_make` and `AK::try_create` wherever possible. If the called constructor is private, this can not be done, so we instead now use the standard-defined and compiler-agnostic `new (nothrow)`.
2021-06-22Kernel: Ensure Ext2FSInode's lookup is populated before using itSam Atkins
This fixes #8133. Ext2FSInode::remove_child() searches the lookup cache, so if it's not initialized, removing the child fails. If the child was a directory, this led to it being corrupted and having 0 children. I also added populate_lookup_cache to add_child. I hadn't seen any bugs there, but if the cache wasn't populated before, adding that one entry would make it think it was populated, so that would cause bugs later.
2021-06-17Kernel: Remove obsolete size_t castsGunnar Beutner
2021-06-16Kernel: Remove various other uses of ssize_tGunnar Beutner
2021-06-12AK: Rename Vector::append(Vector) => Vector::extend(Vector)Andreas Kling
Let's make it a bit more clear when we're appending the elements from one vector to the end of another 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-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-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-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-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-03Kernel: Fix some 64-bit portability issuesGunnar Beutner
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-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-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-25Kernel: Remove the now defunct `LOCKER(..)` macro.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-20Ext2FS: Put bg_used_dirs_count debug logging behind EXT2_DEBUGAndreas Kling
2021-04-11Ext2FS: Use if-with-initializer a lot moreAndreas Kling
This pattern felt really cluttery: auto result = something(); if (result.is_error()) return result; Since it leaves "result" lying around in the no-error case. Let's use some C++17 if initializer expressions to improve this: if (auto result = something(); result.is_error()) return result; Now the "result" goes out of scope if we don't need it anymore. This is doubly nice since we're also free to reuse the "result" name later in the same function.
2021-04-10Ext2FS: Support reading from file holesAndreas Kling
It's perfectly valid for ext2 inodes to have blocks with index 0. It means that no physical block was allocated for that area of an inode and we should treat it as if it's filled with zeroes. Fixes #6139.
2021-04-10Ext2FS: Clarify error handling in Ext2FSInode::read_bytes() somewhatAndreas Kling
2021-04-04Kernel: Reading past the end of an Ext2FSInode should return 0Andreas Kling
Fixes #5763.
2021-03-19Kernel: Make block-based file system code 64 bit readyJean-Baptiste Boric