summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem
AgeCommit message (Collapse)Author
2022-01-04Kernel: Include correct header for DistinctNumeric in DeviceFileTypes.hDaniel Bertalan
Fixes an aarch64 build failure.
2022-01-04Kernel: Replace divide_rounded_up uses with ceil_div in Ext2FileSystemOwen Smith
This function was duplicated with ceil_div in AK.
2022-01-02Kernel: Always pass InodeIdentifier by valueAndreas Kling
These objects are small, there are no benefits to passing by reference.
2022-01-02Kernel/TmpFS: Prevent TmpFS::add_child() from adding duplicate childrenAndreas Kling
If asked to add an already existing name to a directory inode, fail with EEXIST, consistent with other filesystems.
2022-01-01Kernel+LibC+LibCore: Add lchown and fchownat functionscircl
This modifies sys$chown to allow specifying whether or not to follow symlinks and in which directory. This was then used to implement lchown and fchownat in LibC and LibCore.
2021-12-30Kernel: Tighten String-related includesDaniel Bertalan
2021-12-30Kernel: Propagate allocation failure in resolve_path_without_veilDaniel Bertalan
2021-12-29Kernel: Make File::unref virtualIdan Horowitz
This is required for SlavePTY's custom unref handler to function correctly, as otherwise a SlavePTY held in a File RefPtr would call the base's (RefCounted<>) unref method instead of SlavePTY's version.
2021-12-29Kernel: Port File to RefCountedIdan Horowitz
Since RefCounted automatically calls a method named `will_be_destoyed` on classes that have one, so there's no need to have a custom implementation of unref in File.
2021-12-29Kernel: Rename File::{before_removing => will_be_destroyed}Idan Horowitz
This will allow File and it's descendants to use RefCounted instead of having a custom implementation of unref. (Since RefCounted calls will_be_destroyed automatically) This commit also removes an erroneous call to `before_removing` in AHCIPort, this is a duplicate call, as the only reference to the device is immediately dropped following the call, which in turns calls `before_removing` via File::unref.
2021-12-29Kernel: Port Custody to ListedRefCountedIdan Horowitz
Custody's unref is one of many implementions of ListedRefCounted's behaviour in the Kernel, which results in avoidable bugs caused by the fragmentation of the implementations. This commit starts the work of replacing all custom implementations with ListedRefCounted by porting Custody to it.
2021-12-29Kernel: Support Mutex Protected lists in ListedRefCountedIdan Horowitz
This will allow us to support Mutex Protected lists like the custodies list as well.
2021-12-28Kernel: Remove the kmalloc_eternal heap :^)Andreas Kling
This was a premature optimization from the early days of SerenityOS. The eternal heap was a simple bump pointer allocator over a static byte array. My original idea was to avoid heap fragmentation and improve data locality, but both ideas were rooted in cargo culting, not data. We would reserve 4 MiB at boot and only ended up using ~256 KiB, wasting the rest. This patch replaces all kmalloc_eternal() usage by regular kmalloc().
2021-12-28Kernel: Fix race condition in TmpFSInode::notify_watchers()Andreas Kling
We were doing this dance in notify_watchers(): set_metadata_dirty(true); set_metadata_dirty(false); This was done in order to force out inode watcher events immediately. Unfortunately, this was racy, as if SyncTask got scheduled at the wrong moment, it would try to flush metadata for a clean inode. This then got trapped by the VERIFY() statement in Inode::sync_all(): VERIFY(inode.is_metadata_dirty()); This patch fixes the issue by replacing notify_watchers() with lazy metadata notifications like all other filesystems.
2021-12-26Kernel: Remove old SlabAllocator :^)Andreas Kling
This is no longer useful since kmalloc() does automatic slab allocation without any of the limitations of the old SlabAllocator. :^)
2021-12-26Kernel: Remove all uses of MAKE_SLAB_ALLOCATED()Andreas Kling
Objects that were previously allocated via slab_alloc()/slab_dealloc() now go through kmalloc()/kfree_sized() instead.
2021-12-26Kernel: Fix deadlock caused by page faults while holding disk cache lockAndreas Kling
If the data passed to sys$write() is backed by a not-yet-paged-in inode mapping, we could end up in a situation where we get a page fault when trying to copy data from userspace. If that page fault handler tried reading from an inode that someone else had locked while waiting for the disk cache lock, we'd deadlock. This patch fixes the issue by copying the userspace data into a local buffer before acquiring the disk cache lock. This is not ideal since it incurs an extra copy, and I'm sure we can think of a better solution eventually. This was a frequent cause of startup deadlocks on x86_64 for me. :^)
2021-12-23Kernel: Make major and minor numbers to be DistinctNumericsLiav A
This helps avoid confusion in general, and make constructors, methods and code patterns much more clean and understandable.
2021-12-22Kernel: Always initialize ext2_inode and ext_super_block structsBrian Gianforcaro
Found by PVS Studio Static Analysis
2021-12-21Kernel: Move symlink recursion limit to .h, increase it to 8Martin Bříza
As pointed out by BertalanD on Discord, POSIX specifies that _SC_SYMLOOP_MAX (implemented in the following commit) always needs to be equal or more than _POSIX_SYMLOOP_MAX (8, defined in LibC/bits/posix1_lim.h), hence I've increased it to that value to comply with the standard. The move to header is required for the following commit - to make this constant accessible outside of the VFS class, namely in sysconf.
2021-12-18Kernel: Make File::stat() & friends return Error<struct stat>Andreas Kling
Instead of making the caller provide a stat buffer, let's just return one as a value.
2021-12-18Kernel: Use copy_typed_from_user() in more places :^)Andreas Kling
2021-12-16Kernel+LibC: Move errno definitions to Kernel/API/POSIXsin-ack
This fixes at least half of our LibC includes in the kernel. The source of truth for errno codes and their description strings now lives in Kernel/API/POSIX/errno.h as an enumeration, which LibC includes.
2021-12-15Kernel: Remove duplicate access specifier in DevTmpFSInodeHendiadyoin1
As per clang-tidy.
2021-12-15Kernel: Remove else statements after return in Plan9FileSystem.cppHendiadyoin1
As per clang-tidy.
2021-12-15Kernel: Add implied auto-specifiers in FileSystemHendiadyoin1
As per clang-tidy.
2021-12-15Kernel: Fix missing include in FileSystem/Mount.hHendiadyoin1
2021-12-14Kernel/SysFS: Prevent allocation for component name during constructionLiav A
Instead, allocate before constructing the object and pass NonnullOwnPtr of KString to the object if needed. Some classes can determine their names as they have a known attribute to look for or have a static name.
2021-12-12Kernel+SystemServer: Add /dev/ttyDaniel Bertalan
This file refers to the controlling terminal associated with the current process. It's specified by POSIX, and is used by ports like openssh to interface with the terminal even if the standard input/output is redirected to somewhere else. Our implementation leverages ProcFS's existing facilities to create process-specific symbolic links. In our setup, `/dev/tty` is a symbolic link to `/proc/self/tty`, which itself is a symlink to the appropriate `/dev/pts` entry. If no TTY is attached, `/dev/tty` is left dangling.
2021-12-11Kernel: Remove unused String.h includesHendiadyoin1
This makes searching for not yet OOM safe interfaces a bit easier.
2021-12-11Everywhere: Fix -Winconsistent-missing-override warnings from ClangDaniel Bertalan
This option is already enabled when building Lagom, so let's enable it for the main build too. We will no longer be surprised by Lagom Clang CI builds failing while everything compiles locally. Furthermore, the stronger `-Wsuggest-override` warning is enabled in this commit, which enforces the use of the `override` keyword in all classes, not just those which already have some methods marked as `override`. This works with both GCC and Clang.
2021-12-06Kernel: Remove unused Inode::preopen_fd()Andreas Kling
2021-12-05Kernel: Mark kernel smart-pointer classes as [[nodiscard]]Sam Atkins
And cast the unused return values to void.
2021-11-30Kernel: Handle string format errors in FileSystem APIs :^)Brian Gianforcaro
2021-11-18Kernel: Use DistinctNumeric for filesystem ID'sAndreas Kling
This patch adds the FileSystemID type, which is a distinct u32. This prevents accidental conversion from arbitrary integers.
2021-11-18Kernel: Propagate Vector append failures from Inode::apply_flock()Andreas Kling
2021-11-17Kernel: Allow mmap() with PROT_WRITE+MAP_SHAREDAndreas Kling
Now that we have a way to flush changes back to disk, let's allow this type of mapping.
2021-11-17AK: Convert AK::Format formatting helpers to returning ErrorOr<void>Andreas Kling
This isn't a complete conversion to ErrorOr<void>, but a good chunk. The end goal here is to propagate buffer allocation failures to the caller, and allow the use of TRY() with formatting functions.
2021-11-17Kernel: Reject writable shared file mappingsDaniel Bertalan
We have no way of writing changes to memory-mapped files back to disk, and software relying on this functionality for output would fail miserably. Let's just return ENOTSUP instead to allow callers to fall back to standard file IO instead of silently discarding writes. This makes the LLD port work, which uses memory-mapped files to write its output by default.
2021-11-16Kernel: Use static_ptr_cast to convert between Userspace<T*> typesAndrew Kaster
Some calls of copy_to_user were converting Userspace<T*> to Userspace<U*> via the implicit conversion to FlatPtr. Change them to use the static_ptr_cast overload that is designed to express this conversion
2021-11-14Kernel: Resolve clang-tidy readability-make-member-function-constAndrew Kaster
... In files included from Kernel/Thread.cpp or Kernel/Process.cpp Some places the warning is suppressed, because we do not want a const object do have non-const access to the returned sub-object.
2021-11-14Kernel: Resolve clang-tidy readability-implicit-bool-conversion warningsAndrew Kaster
... In files included from Kernel/Process.cpp and Kernel/Thread.cpp
2021-11-11Everywhere: Pass AK::StringView by valueAndreas Kling
2021-11-11Kernel/Ext2FS: Propagate HashMap errors instead of panickingAndreas Kling
2021-11-10Kernel/Ext2FS: Propagate errors from block list computation functionsAndreas Kling
2021-11-10Kernel: Propagate Vector append errors in two places in Ext2FSAndreas Kling
There are a bunch more of these, just taking care of some simple ones.
2021-11-10Kernel: Make Inode::traverse_as_directory() callback return ErrorOrAndreas Kling
This allows us to propagate errors from inside the callback with TRY().
2021-11-10AK: Make Vector::try_* functions return ErrorOr<void>Andreas Kling
Instead of signalling allocation failure with a bool return value (false), we now use ErrorOr<void> and return ENOMEM as appropriate. This allows us to use TRY() and MUST() with Vector. :^)
2021-11-10AK+Kernel: Make BitmapView read-onlyBen Wiederhake
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. :^)