summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem/VirtualFileSystem.h
AgeCommit message (Collapse)Author
2022-05-21Kernel+LibC+VFS: Implement utimensat(3)Ariel Don
Create POSIX utimensat() library call and corresponding system call to update file access and modification times.
2022-04-01Everywhere: Run clang-formatIdan Horowitz
2022-02-27Everywhere: Make JSON serialization fallibleIdan Horowitz
This allows us to eliminate a major source of infallible allocation in the Kernel, as well as lay down the groundwork for OOM fallibility in userland.
2022-02-03Kernel: Protect mounted filesystem list with spinlock instead of mutexAndreas Kling
2022-01-12Kernel+LibC+LibCore+UE: Implement `fchmodat(2)`Daniel Bertalan
This function is an extended version of `chmod(2)` that lets one control whether to dereference symlinks, and specify a file descriptor to a directory that will be used as the base for relative paths.
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-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-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-11Kernel: Remove unused String.h includesHendiadyoin1
This makes searching for not yet OOM safe interfaces a bit easier.
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-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-10-31Kernel: Enable early-returns from VFS::for_each_mountBen Wiederhake
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-05Kernel: Tidy up VirtualFileSystem::mount_root() a little bitAndreas Kling
- Return KResult instead of bool - Use TRY()
2021-09-05AK+Kernel: Move KResult.h to Kernel/API for userspace accesssin-ack
This commit moves the KResult and KResultOr objects to Kernel/API to signify that they may now be freely used by userspace code at points where a syscall-related error result is to be expected. It also exposes KResult and KResultOr to the global namespace to make it nicer to use for userspace code.
2021-08-29Kernel: Strongly typed user & group ID'sAndreas Kling
Prior to this change, both uid_t and gid_t were typedef'ed to `u32`. This made it easy to use them interchangeably. Let's not allow that. This patch adds UserID and GroupID using the AK::DistinctNumeric mechanism we've already been employing for pid_t/ProcessID.
2021-08-22Kernel: Rename ProtectedValue<T> => MutexProtected<T>Andreas Kling
Let's make it obvious what we're protecting it with.
2021-08-16Kernel: Use ProtectedValue for VirtualFileSystem::m_mountsAndreas Kling
This is what VirtualFileSystem::m_lock was actually guarding, and wrapping it in a ProtectedValue makes it so much more obvious how it all works. :^)
2021-08-14Kernel: Move VFS-internal O_FOO definitions to VirtualFileSystem.hAndreas Kling
2021-08-06Kernel: Move UnveilNode.h into Kernel/FileSystem/Andreas Kling
2021-07-17Kernel: Rename Lock to MutexAndreas Kling
Let's be explicit about what kind of lock this is meant to be.
2021-07-11Kernel: Use Forward.h headers moreAndreas Kling
2021-07-11Kernel: Only allow looking up Mounts by InodeIdentifierAndreas Kling
Let's simplify the interface by not allowing lookup by Inode&.
2021-07-11Kernel: Make VirtualFileSystem::Mount a top-level classAndreas Kling
And move it to its own compilation unit.
2021-07-11Kernel: Make VirtualFileSystem::sync() staticAndreas Kling
2021-07-11Kernel: Rename VFS => VirtualFileSystemAndreas Kling
2021-07-11Kernel: Rename FS => FileSystemAndreas Kling
This matches our common naming style better.
2021-07-05Kernel: Don't allocate Strings unnecessarily in process veil validationMax Wipfli
Previously, Custody::absolute_path() was called for every call to validate_path_against_process_veil(). For processes that don't have a veil, the path is not used by the function. This means that it is unnecessarily generated. This introduces an overload to validate_path_against_process_veil(), which takes a Custody const& and only generates the absolute path if it there is actually a veil and it is thus needed. This patch results in a speed up of Assistant's file system cache building by around 16 percent.
2021-06-08Kernel: Don't assume there are no nodes if m_unveiled_paths.is_empty()Max Wipfli
If m_unveiled_paths.is_empty(), the root node (which is m_unveiled_paths itself) is the matching veil. This means we should not return nullptr in this case, but just use the code path for the general case. This fixes a bug where calling e.g. unveil("/", "r") would refuse you access to anything, because find_matching_unveiled_path would wrongly return nullptr. Since find_matching_unveiled_path can no longer return nullptr, we can now just return a reference instead.
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 *
2020-12-26Kernel: Implement unveil() as a prefix-treeAnotherTest
Fixes #4530.
2020-09-12Kernel: Fix various forward declarationsBen Wiederhake
I decided to modify MappedROM.h because all other entried in Forward.h are also classes, and this is visually more pleasing. Other than that, it just doesn't make any difference which way we resolve the conflicts.
2020-08-25Kernel: Switch singletons to use new Singleton classTom
MemoryManager cannot use the Singleton class because MemoryManager::initialize is called before the global constructors are run. That caused the Singleton to be re-initialized, causing it to create another MemoryManager instance. Fixes #3226
2020-08-22Revert "Kernel: Switch singletons to use new Singleton class"Andreas Kling
This reverts commit f48feae0b2a300992479abf0b2ded85e45ac6045.
2020-08-21Kernel: Switch singletons to use new Singleton classTom
Fixes #3226
2020-08-18Kernel: Add DirectoryEntryView for VFS directory traversalAndreas Kling
Unlike DirectoryEntry (which is used when constructing directories), DirectoryEntryView does not manage storage for file names. Names are just StringViews. This is much more suited to the directory traversal API and makes it easier to implement this in file system classes since they no longer need to create temporary name copies while traversing.
2020-08-05Kernel: Propagate a few KResults properly in FileSystem subsystemsBrian Gianforcaro
Propagating un-obsevered KResults up the stack.
2020-06-25Kernel: Port mounts to reference inodes directlySergey Bugaev
...instead of going through their identifiers. See the previous commit for reasoning.
2020-05-29Kernel+Userland: Support remounting filesystems :^)Sergey Bugaev
This makes it possible to change flags of a mount after the fact, with the caveats outlined in the man page.
2020-05-29Kernel: Misc tweaksSergey Bugaev
2020-05-29Kernel+LibC: Move O_* and MS_* flags to UnixTypes.hSergey Bugaev
That's where the other similar definitions reside. Also, use bit shift operations for MS_* values.
2020-05-29Kernel: Pass a Custody instead of Inode to VFS methodsSergey Bugaev
VFS no longer deals with inodes in public API, only with custodies and file descriptions. Talk directly to the file system if you need to operate on a inode. In most cases you actually want to go though VFS, to get proper permission check and other niceties. For this to work, you have to provide a custody, which describes *how* you have opened the inode, not just what the inode is.
2020-03-19Kernel: Resolve relative paths when there is a veil (#1474)Alex Muscar
2020-02-16Kernel: Move all code into the Kernel namespaceAndreas Kling
2020-01-21Kernel+LibC: Clean up open() flag (O_*) definitionsAndreas Kling
These were using a mix of decimal, octal and hexadecimal for no reason.
2020-01-21Kernel: Make O_RDONLY non-zeroAndreas Kling
Sergey suggested that having a non-zero O_RDONLY would make some things less confusing, and it seems like he's right about that. We can now easily check read/write permissions separately instead of dancing around with the bits. This patch also fixes unveil() validation for O_RDWR which previously forgot to check for "r" permission.
2020-01-20Kernel: Add a basic implementation of unveil()Andreas Kling
This syscall is a complement to pledge() and adds the same sort of incremental relinquishing of capabilities for filesystem access. The first call to unveil() will "drop a veil" on the process, and from now on, only unveiled parts of the filesystem are visible to it. Each call to unveil() specifies a path to either a directory or a file along with permissions for that path. The permissions are a combination of the following: - r: Read access (like the "rpath" promise) - w: Write access (like the "wpath" promise) - x: Execute access - c: Create/remove access (like the "cpath" promise) Attempts to open a path that has not been unveiled with fail with ENOENT. If the unveiled path lacks sufficient permissions, it will fail with EACCES. Like pledge(), subsequent calls to unveil() with the same path can only remove permissions, not add them. Once you call unveil(nullptr, nullptr), the veil is locked, and it's no longer possible to unveil any more paths for the process, ever. This concept comes from OpenBSD, and their implementation does various things differently, I'm sure. This is just a first implementation for SerenityOS, and we'll keep improving on it as we go. :^)
2020-01-18Meta: Add license header to source filesAndreas Kling
As suggested by Joshua, this commit adds the 2-clause BSD license as a comment block to the top of every source file. For the first pass, I've just added myself for simplicity. I encourage everyone to add themselves as copyright holders of any file they've added or modified in some significant way. If I've added myself in error somewhere, feel free to replace it with the appropriate copyright holder instead. Going forward, all new source files should include a license header.
2020-01-17Kernel: Simplify VFS::resolve_path() furtherSergey Bugaev
It turns out we don't even need to store the whole custody chain, as we only ever access its last element. So we can just store one custody. This also fixes a performance FIXME :^) Also, rename parent_custody to out_parent.
2020-01-12Kernel: Properly propagate bind mount flagsSergey Bugaev
Previously, when performing a bind mount flags other than MS_BIND were ignored. Now, they're properly propagated the same way a for any other mount.