Commit Graph

1509 Commits

Author SHA1 Message Date
Hendiadyoin1
c5d713864b Meta+Kernel: Enable -fno-sanitize-recover=undefined by default
This makes the Kernel UBSan deadly by compile time,
it can be made recoverable by setting
`ENABLE_KERNEL_UNDEFINED_SANITIZER_ALWAYS_DEADLY` to `OFF` in the
CMake options, and the `ubsan_is_deadly` sysctl option to `0`.
2025-06-20 23:22:07 +02:00
Sönke Holz
2656a81d03 Kernel: Make SysFSSystemBooleanVariable::set_value fallible 2025-06-20 23:22:07 +02:00
implicitfield
5c5256127d Kernel/FileSystem: Prefer non-recursive Spinlocks 2025-06-05 22:02:40 +02:00
implicitfield
797fdb93bd Kernel/Custody: Remove the IntrusiveList-based caching mechanism
This is nigh-impossible to reconcile with non-recursive Spinlocks.
2025-06-05 22:02:40 +02:00
implicitfield
7cf3c76295 Kernel/VFS: Don't rely on parent custodies being the same object
This assumption doesn't hold without the current Custody caching
mechanism.
2025-06-05 22:02:40 +02:00
implicitfield
21a64a8b8b Kernel/Inode: Avoid double-locking m_flocks 2025-06-05 22:02:40 +02:00
implicitfield
6a4ceb6bf2 Kernel: Avoid double-locking devices when trying to acquire them
Previously, you'd occasionally see this sort of construct (simplified):
```
return FooDevice::all_instances().with([&](auto& list) {
    for (auto& device : list) {
        if (/* search condition */)
            continue;
        return do_something_that_reacquires(device.index());
    }
    return ENOENT;
});
```

This would only work if the relevant `all_instances()` used a recursive
spinlock, since reacquiring the device would lock that again.

To get around this, a new helper has been added in `Device` through
which devices can be accessed whilst locking the device list, removing
the need to loop through the device type's `all_instances()`.
2025-06-05 22:02:40 +02:00
implicitfield
6836d5bc01 Kernel: Allocate BlockBasedFilesystem caches upfront
This eliminates the possibility of panicking due to encountering a page
fault while trying access the cache inside an interrupt handler.
2025-06-05 22:02:40 +02:00
implicitfield
b4d16ff640 Kernel/FATFS: Don't confuse the root directory with clusterless entries
7fa12df7 overlooked the fact that we use `first_cluster == 0` to
represent root directories in addition to clusterless entries. This
patch makes compute_cluster_list return a cluster list that actually
contains cluster #0 if we're dealing with the root directory (like it
used to), but retains the new behavior for all other entries.
2025-05-24 17:43:50 -04:00
implicitfield
743e968561 Kernel/FATFS: Make compute_cluster_list not take any parameters
Instead, this patch makes it get all the information it needs directly
from the inode object or the filesystem. This also inlines the
cluster-freeing mechanism in remove_child_impl since we can no longer
use compute_cluster_list there.
2025-05-24 17:43:50 -04:00
implicitfield
2057c1e4f1 Kernel/FATFS: Skip freeing clusters if the first one is an EOC marker
This isn't a valid scenario, and we don't really guard against malformed
filesystems in most places, but this becomes somewhat relevant in the
next commit.
2025-05-24 17:43:50 -04:00
implicitfield
e230265b71 Kernel/FATFS: Fix a typo 2025-05-24 17:43:50 -04:00
implicitfield
45f2376a33 Kernel/FATFS: Add support for writing timestamps 2025-05-08 22:17:28 +02:00
implicitfield
c3ea257d5d Kernel/FATFS: Make sure that locks are held when they should be 2025-05-08 22:17:28 +02:00
implicitfield
1ac4f3fc60 Kernel/FATFS: Refuse to create special files 2025-05-08 22:17:28 +02:00
implicitfield
64a5ab9434 Kernel/FATFS: Remove the add_child implementation
Since the VFS renaming refactor, this function has only been used for
hardlinking, which isn't possible on FATFS since there's no real concept
of inodes or anything comparable to those.
2025-05-08 22:17:28 +02:00
implicitfield
1a379670c6 Kernel/FATFS: Don't preallocate the first cluster when creating a file 2025-05-08 22:17:28 +02:00
implicitfield
7fa12df7d0 Kernel/FATFS: Be cognizant that empty cluster lists exist 2025-05-08 22:17:28 +02:00
implicitfield
d7ed7549c7 Kernel/FATFS: Use the inode metadata location to generate an ID
The first cluster isn't sufficiently unique for this, since it is
entirely valid for an empty file to have no first cluster at all.
2025-05-08 22:17:28 +02:00
implicitfield
e93ec8a198 Kernel/FUSE: Store node IDs and unique IDs as u64s 2025-04-27 11:01:18 +02:00
implicitfield
f084073ad6 Kernel/FUSE: Implement basic write support 2025-04-27 11:01:18 +02:00
implicitfield
a264a8333c AK+Kernel: Rename SpinlockProtected => RecursiveSpinlockProtected 2025-04-27 11:01:18 +02:00
Sönke Holz
ea82138f65 Kernel: Rename HID* to Input*
The term "Human Interface Device" (HID) is commonly used for the HID
specification specifically, not just input devices in general.

Also remove the "HID" prefix from the "HIDMouse" and "HIDKeyboard"
DeviceMapper.ini configuration groups, since it's unnecessary and
misleading.

The next few commits will introduce actual HID support, so the naming
would otherwise get confusing.
2025-03-24 10:29:31 +01:00
implicitfield
9a66ea24e3 Kernel/FATFS: Compute cluster lists somewhat lazily
Now we no longer compute the cluster list at the exact moment when an
in-memory inode is created, but rather defer doing that until we
actually need the cluster list. This distinction is important when
traversing directories, as we *are* interested in the inode, but not
really in its contents (though now we do have to resort to using the
file size to approximate the amount of allocated blocks, but this
shouldn't be an issue when working with well-formed filesystems.)
2025-03-13 21:41:18 +01:00
implicitfield
5b980796f5 Kernel/FATFS: Optimize resizing and zeroing
Plain resizes (that increase file size) are now much faster, as the
zeroing is now done in a more efficient way (rather than just looping
over `write_bytes_locked`.) Writes should also be faster, since we no
longer zero out the underlying bytes if we are going to write something
in that very same location anyway.
2025-03-13 21:41:18 +01:00
implicitfield
5379e47ffe Kernel/FATFS: Keep the next free cluster hint up to date 2025-03-13 21:41:18 +01:00
implicitfield
222acc9d38 Kernel/BlockBasedFileSystem: Drop remove_disk_cache_before_last_unmount
There's not much use in having this function, as the only remotely
useful thing that it does is that it ensures that the disk cache is
locked before destroying it. However, there shouldn't be any filesystem
activity this late in the unmounting process anyway, so the locking
doesn't seem necessary either.
2025-03-10 14:04:55 +01:00
implicitfield
71f970ff8f Kernel: Break a reference cycle between BlockBasedFileSystem & DiskCache
Co-authored-by: Sönke Holz <sholz8530@gmail.com>
2025-03-10 14:04:55 +01:00
Sönke Holz
0d11e70cfe Kernel/MM: Set the correct memory type for mmap()s
Make the MemoryType used by mmap() configurable by
File::vmobject_and_memory_type_for_mmap overrides (previously called
vmobject_for_mmap).

All mmap()s were previously MemoryType::Normal.
2025-01-13 19:30:54 +01:00
Liav A.
1dfc9e2df3 Kernel+Userland: Add immutable mounts
Immutable mounts are mounts that can't be changed in any aspect, if the
VFSRootContext that hold them is used by a process. This includes two
operations on a mount:
1. Trying to remove the mount from the mount table.
2. Trying to change the flags of the mount.

The condition of a VFSRootContext being held by a process or not is
crucial, as the intention is to allow removal of mounts that marked as
immutable if the VFSRootContext is not being used anymore (for example,
if the container that was created with such context stopped).

Marking mounts as immutable on the first VFS root context essentially
ensures they will never be modified because there will be a process
using that context (which is the "main" VFS root context in the system
runtime).

It should be noted that setting a mount as immutable can be done in
creation time of the mount by passing the MS_IMMUTABLE flag, or by doing
a remount with MS_IMMUTABLE flag.
2024-12-23 20:38:38 +01:00
implicitfield
8ed7225810 Kernel/VFS: Don't explicitly remove "." and ".." entries
No behavior change intended.
2024-12-17 19:02:15 -05:00
implicitfield
0e94887b2c Kernel/VFS: Make filesystem implementations responsible for renames
Previously, the VFS layer would try to handle renames more-or-less by
itself, which really only worked for ext2, and even that was only due to
the replace_child kludge existing specifically for this purpose. This
never worked properly for FATFS, since the VFS layer effectively
depended on filesystems having some kind of reference-counting for
inodes, which is something that simply doesn't exist on any FAT variant
we support.

To resolve various issues with the existing scheme, this commit makes
filesystem implementations themselves responsible for the actual rename
operation, while keeping all the existing validation inside the VFS
layer. The only intended behavior change here is that rename operations
should actually properly work on FATFS.
2024-12-17 19:02:15 -05:00
implicitfield
666ba3b970 Kernel/Ext2FS: Make to_ext2_file_type a static member of Ext2FSInode 2024-12-17 19:02:15 -05:00
implicitfield
8db6dd47c7 Kernel/FATFS: Allocate new entries properly in allocate_entries
There were two separate issues at play which made this work incorrectly.
The first was that the newly allocated block was incorrectly computed,
because it was assumed that the cached block list was updated when a new
cluster was allocated. The second issue was that there was an off-by-one
in the loop that collected the newly allocated entries, which meant that
the resulting list had an entry less than what was requested.
2024-12-17 19:02:15 -05:00
implicitfield
1a4036e8ed Kernel/FATFS: Don't shadow lfn_entries in add_child 2024-12-17 19:02:15 -05:00
implicitfield
c6e483d65e Kernel/FATFS: Make (an overload of) first_cluster actually freestanding
The old overload still depended on m_entry being initialized, which
meant that (due to where this method is used) all inodes ended up
getting the same index.
2024-12-17 19:02:15 -05:00
implicitfield
0e368bb71a Kernel/Ext2FS: Add full support for large inodes
128-byte inodes are more-or-less deprecated since they store timestamps
as unsigned 32-bit integer offsets from the UNIX epoch. Large inodes, on
the other hand, contain records that may specify a different epoch, and
are thus less susceptible to overflows. These very same records also
have the capability to store timestamps with nanosecond precision, which
this commit adds full support for as well.
2024-11-29 10:59:24 -05:00
implicitfield
2a205768b6 Kernel/Ext2FS: Backport a missing large inode member 2024-11-29 10:59:24 -05:00
implicitfield
e7baffaba0 Ext2FS: Serialize timestamps as signed offsets
The header would have you believe these are unsigned, but they should
really be treated as signed.
2024-11-29 10:59:24 -05:00
Sönke Holz
d3a0ae5c57 Kernel/MM: Replace Region::Cacheable with a more generic MemoryType enum
This replaces all usages of Cacheable::Yes with MemoryType::Normal and
Cacheable::No with either MemoryType::NonCacheable or MemoryType::IO,
depending on the context.

The Page{Directory,Table}::set_cache_disabled function therefore also
has been replaced with a more appropriate set_memory_type_function.
Adding a memory_type "getter" would not be as easy, as some
architectures may not support all memory types, so getting the memory
type again may be a lossy conversion. The is_cache_disabled function
was never used, so just simply remove it altogether.

There is no difference between MemoryType::NonCacheable and
MemoryType::IO on x86 for now.

Other architectures currently don't respect the MemoryType at all.
2024-11-23 19:29:50 +01:00
implicitfield
b765ee22d3 Kernel/FATFS: Fix a typo 2024-11-20 20:47:46 -05:00
implicitfield
70f29d064f Kernel/FATFS: Use last() and take_last() where possible 2024-11-20 20:47:46 -05:00
implicitfield
423e80d22f Kernel/FATFS: Handle the "." and ".." entries correctly in remove_child 2024-11-20 20:47:46 -05:00
implicitfield
c74ee7d36a Kernel/FATFS: Fill in first cluster metadata for new ".." entries 2024-11-20 20:47:46 -05:00
implicitfield
b83be2b754 Kernel/FATFS: Fix an off-by-one in create_sfn_from_lfn
With this change, we no longer crash after finding more than one period
in a filename.
2024-11-20 20:47:46 -05:00
implicitfield
ce871de432 Kernel/FATFS: Abstract out SFN helpers and make them usable in userspace 2024-11-20 20:47:46 -05:00
implicitfield
54bfc3d294 Kernel/Ext2FS: Cache blocks less aggressively
With this patch, we now only cache at most 2^14 blocks, which greatly
relieves memory pressure when working with large files.
2024-11-05 20:14:21 +01:00
implicitfield
54b8fe1fa4 Kernel/Ext2FS: Add a helper to free every block an inode holds 2024-11-05 20:14:21 +01:00
implicitfield
a32b9c903b Kernel/Ext2FS: Make block allocation properly fallible
For some context, write_bytes_locked used to simply bail out before
writing any data if there weren't enough blocks to cover the entire size
of an inode before 1bf7f99a.

We're not actually restoring that behavior here, since computing the
amount of blocks to be allocated would get exceedingly complex,
considering that there could always be holes in between already
allocated blocks.

Instead, this simply makes allocate_blocks() bail out properly if there
aren't any free blocks left.

Fixes #24980
2024-11-05 20:14:21 +01:00
implicitfield
dca1a755c2 Kernel/FATFS: Make lookups case-insensitive 2024-11-02 15:54:29 -04:00