summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem/BlockBasedFileSystem.cpp
AgeCommit message (Collapse)Author
2021-11-08Kernel: Replace KResult and KResultOr<T> with Error and ErrorOr<T>Andreas Kling
We now use AK::Error and AK::ErrorOr<T> in both kernel and userspace! This was a slightly tedious refactoring that took a long time, so it's not unlikely that some bugs crept in. Nevertheless, it does pass basic functionality testing, and it's just real nice to finally see the same pattern in all contexts. :^)
2021-09-10AK+Everywhere: Reduce the number of template parameters of IntrusiveListAli Mohammad Pur
This makes the user-facing type only take the node member pointer, and lets the compiler figure out the other needed types from that.
2021-09-07Kernel: Make KBuffer::try_create_with_size() return KResultOrAndreas Kling
This allows us to use TRY() in a lot of new places.
2021-09-07Kernel: Rename FileDescription => OpenFileDescriptionAndreas Kling
Dr. POSIX really calls these "open file description", not just "file description", so let's call them exactly that. :^)
2021-09-07Kernel: Make UserOrKernelBuffer return KResult from read/write/memsetAndreas Kling
This allows us to simplify a whole bunch of call sites with TRY(). :^)
2021-09-06Kernel: Use TRY() in BlockBasedFileSystemAndreas Kling
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-08Kernel: Port BlockBasedFileSystem to ProtectedValue :^)Andreas 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-07-18Kernel: Rename Locker => MutexLockerAndreas Kling
2021-07-16Kernel: Don't hog file system lock when doing BlockBasedFileSystem I/OAndreas Kling
The file system lock is meant to protect the file system metadata (super blocks, bitmaps, etc.) Not protect processes from reading independent parts of the disk at once. This patch introduces a new lock to protect the *block cache* instead, which is the real thing that needs synchronization.
2021-07-16Kernel: Don't explicitly seek before I/O in BlockBasedFileSystemAndreas Kling
Use the new FileDescription APIs to avoid doing seek+read or seek+write as two separate operations.
2021-07-11Kernel: Rename BlockBasedFS => BlockBasedFileSystemAndreas Kling
2021-07-11Kernel: Rename FileBackedFS => FileBackedFileSystemAndreas Kling
2021-07-06Kernel: Promote various integers to 64 bits in storage layerJean-Baptiste Boric
2021-04-25Kernel: Remove the now defunct `LOCKER(..)` macro.Brian Gianforcaro
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-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.
2021-03-19Kernel: Make FileDescription::seek() return KResultOr<off_t>Andreas Kling
This exposed a bunch of places where errors were not propagated, so this patch is forced to deal with them as well.
2021-03-19Kernel: Make block-based file system code 64 bit readyJean-Baptiste Boric
2021-02-28Kernel: Use default con/de-structorsBen Wiederhake
This may seem like a no-op change, however it shrinks down the Kernel by a bit: .text -432 .unmap_after_init -60 .data -480 .debug_info -673 .debug_aranges 8 .debug_ranges -232 .debug_line -558 .debug_str -308 .debug_frame -40 With '= default', the compiler can do more inlining, hence the savings. I intentionally omitted some opportunities for '= default', because they would increase the Kernel size.
2021-02-26Kernel: Take FS lock in BlockBasedFS during seek/read/write operationsAndreas Kling
Since these filesystems operate on an underlying file descriptor and rely on its offset for correctness, let's use the FS lock to serialize these operations. This also means that FS subclasses can rely on block-level read/write operations being atomic.
2021-02-23Everywhere: Rename ASSERT => VERIFYAndreas Kling
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED) Since all of these checks are done in release builds as well, let's rename them to VERIFY to prevent confusion, as everyone is used to assertions being compiled out in release. We can introduce a new ASSERT macro that is specifically for debug checks, but I'm doing this wholesale conversion first since we've accumulated thousands of these already, and it's not immediately obvious which ones are suitable for ASSERT.
2021-02-12Kernel: Fix build with BBFS_DEBUGAndreas Kling
2021-02-12Kernel: Make BlockBasedFS::BlockIndex a distinct integer typeAndreas Kling
2021-01-26Meta: Split debug defines into multiple headers.asynts
The following script was used to make these changes: #!/bin/bash set -e tmp=$(mktemp -d) echo "tmp=$tmp" find Kernel \( -name '*.cpp' -o -name '*.h' \) | sort > $tmp/Kernel.files find . \( -path ./Toolchain -prune -o -path ./Build -prune -o -path ./Kernel -prune \) -o \( -name '*.cpp' -o -name '*.h' \) -print | sort > $tmp/EverythingExceptKernel.files cat $tmp/Kernel.files | xargs grep -Eho '[A-Z0-9_]+_DEBUG' | sort | uniq > $tmp/Kernel.macros cat $tmp/EverythingExceptKernel.files | xargs grep -Eho '[A-Z0-9_]+_DEBUG' | sort | uniq > $tmp/EverythingExceptKernel.macros comm -23 $tmp/Kernel.macros $tmp/EverythingExceptKernel.macros > $tmp/Kernel.unique comm -1 $tmp/Kernel.macros $tmp/EverythingExceptKernel.macros > $tmp/EverythingExceptKernel.unique cat $tmp/Kernel.unique | awk '{ print "#cmakedefine01 "$1 }' > $tmp/Kernel.header cat $tmp/EverythingExceptKernel.unique | awk '{ print "#cmakedefine01 "$1 }' > $tmp/EverythingExceptKernel.header for macro in $(cat $tmp/Kernel.unique) do cat $tmp/Kernel.files | xargs grep -l $macro >> $tmp/Kernel.new-includes ||: done cat $tmp/Kernel.new-includes | sort > $tmp/Kernel.new-includes.sorted for macro in $(cat $tmp/EverythingExceptKernel.unique) do cat $tmp/Kernel.files | xargs grep -l $macro >> $tmp/Kernel.old-includes ||: done cat $tmp/Kernel.old-includes | sort > $tmp/Kernel.old-includes.sorted comm -23 $tmp/Kernel.new-includes.sorted $tmp/Kernel.old-includes.sorted > $tmp/Kernel.includes.new comm -13 $tmp/Kernel.new-includes.sorted $tmp/Kernel.old-includes.sorted > $tmp/Kernel.includes.old comm -12 $tmp/Kernel.new-includes.sorted $tmp/Kernel.old-includes.sorted > $tmp/Kernel.includes.mixed for file in $(cat $tmp/Kernel.includes.new) do sed -i -E 's/#include <AK\/Debug\.h>/#include <Kernel\/Debug\.h>/' $file done for file in $(cat $tmp/Kernel.includes.mixed) do echo "mixed include in $file, requires manual editing." done
2021-01-25Everywhere: Hook up remaining debug macros to Debug.h.asynts
2021-01-25Everywhere: Remove unnecessary debug comments.asynts
It would be tempting to uncomment these statements, but that won't work with the new changes. This was done with the following commands: find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec awk -i inplace '$0 !~ /\/\/#define/ { if (!toggle) { print; } else { toggle = !toggle } } ; $0 ~/\/\/#define/ { toggle = 1 }' {} \; find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec awk -i inplace '$0 !~ /\/\/ #define/ { if (!toggle) { print; } else { toggle = !toggle } } ; $0 ~/\/\/ #define/ { toggle = 1 }' {} \;
2021-01-20Kernel+LibC: Turn errno codes into a strongly typed enumAndreas Kling
..and allow implicit creation of KResult and KResultOr from ErrnoCode. This means that kernel functions that return those types can finally do "return EINVAL;" and it will just work. There's a handful of functions that still deal with signed integers that should be converted to return KResults.
2021-01-20Kernel: Make BlockBasedFS read/write functions return a KResultAndreas Kling
This way, if something goes wrong, we get to keep the actual error. Also, KResults are nodiscard, so we have to deal with that in Ext2FS instead of just silently ignoring I/O errors(!)
2021-01-11Everywhere: Replace a bundle of dbg with dbgln.asynts
These changes are arbitrarily divided into multiple commits to make it easier to find potentially introduced bugs with git bisect.Everything:
2020-12-29Revert "Kernel: Convert read_block method to get a reference instead of pointer"Andreas Kling
This reverts commit 092a13211a4216c19c08280bd5e5803e1030f087. Fixes #4611.
2020-12-27Kernel: Convert read_block method to get a reference instead of pointerLiav A
BlockBasedFileSystem::read_block method should get a reference of a UserOrKernelBuffer. If we need to force caching a block, we will call other method to do so.
2020-12-21Everywhere: Switch from (void) to [[maybe_unused]] (#4473)Lenny Maiorani
Problem: - `(void)` simply casts the expression to void. This is understood to indicate that it is ignored, but this is really a compiler trick to get the compiler to not generate a warning. Solution: - Use the `[[maybe_unused]]` attribute to indicate the value is unused. Note: - Functions taking a `(void)` argument list have also been changed to `()` because this is not needed and shows up in the same grep command.
2020-11-24Kernel: Use a doubly-linked list for the BlockBasedFS cacheAndreas Kling
This makes misses in the BlockBasedFS's LRU block cache faster by storing the cache entries in one of two doubly-linked list. Dirty and clean cache entries are kept in two separate lists, and move between them when their state changes. This can probably be improved upon further.
2020-11-24Kernel: Add a fast lookup table to the BlockBasedFS disk cacheAndreas Kling
Instead of doing a linear scan of the entire cache when doing a lookup, we now have a nice O(1) HashMap in front of the cache. The cache miss case can still be improved, this patch really only helps the cache hit case. This dramatically improves cached filesystem I/O. :^)
2020-09-13Kernel: Make copy_to/from_user safe and remove unnecessary checksTom
Since the CPU already does almost all necessary validation steps for us, we don't really need to attempt to do this. Doing it ourselves doesn't really work very reliably, because we'd have to account for other processors modifying virtual memory, and we'd have to account for e.g. pages not being able to be allocated due to insufficient resources. So change the copy_to/from_user (and associated helper functions) to use the new safe_memcpy, which will return whether it succeeded or not. The only manual validation step needed (which the CPU can't perform for us) is making sure the pointers provided by user mode aren't pointing to kernel mappings. To make it easier to read/write from/to either kernel or user mode data add the UserOrKernelBuffer helper class, which will internally either use copy_from/to_user or directly memcpy, or pass the data through directly using a temporary buffer on the stack. Last but not least we need to keep syscall params trivial as we need to copy them from/to user mode using copy_from/to_user.
2020-08-30Kernel: Unbreak building with extra debug macros, part 1Ben Wiederhake
2020-08-05Kernel: Fix build break from missing KResult [[nodiscard]] suppressionsBrian Gianforcaro
Missed this somehow in previous change.
2020-08-04Kernel: Make File::write() and File::read() return KResultOr<size_t>Andreas Kling
Instead of returning a ssize_t where negative values mean error, we now return KResultOr<size_t> and use the error state to report errors exclusively.
2020-07-05Kernel: Split BlockBasedFileSystem off FileBackedFileSystemSergey Bugaev
FileBackedFileSystem is one that's backed by (mounted from) a file, in other words one that has a "source" of the mount; that doesn't mean it deals in blocks. The hierarchy now becomes: * FS * ProcFS * DevPtsFS * TmpFS * FileBackedFS * (future) Plan9FS * BlockBasedFS * Ext2FS