summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem/VirtualFileSystem.h
AgeCommit message (Collapse)Author
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.
2020-01-11Kernel: Implement bind mountsSergey Bugaev
You can now bind-mount files and directories. This essentially exposes an existing part of the file system in another place, and can be used as an alternative to symlinks or hardlinks. Here's an example of doing this: # mkdir /tmp/foo # mount /home/anon/myfile.txt /tmp/foo -o bind # cat /tmp/foo This is anon's file.
2020-01-11Kernel+LibC: Implement a few mount flagsSergey Bugaev
We now support these mount flags: * MS_NODEV: disallow opening any devices from this file system * MS_NOEXEC: disallow executing any executables from this file system * MS_NOSUID: ignore set-user-id bits on executables from this file system The fourth flag, MS_BIND, is defined, but currently ignored.
2020-01-11Kernel+LibC: Add O_EXEC, move exec permission checking to VFS::open()Sergey Bugaev
O_EXEC is mentioned by POSIX, so let's have it. Currently, it is only used inside the kernel to ensure the process has the right permissions when opening an executable.
2020-01-11Kernel+LibC: Add support for mount flagsSergey Bugaev
At the moment, the actual flags are ignored, but we correctly propagate them all the way from the original mount() syscall to each custody that resides on the mounted FS.
2020-01-11Kernel: Simplify VFS::Mount handlingSergey Bugaev
No need to pass around RefPtr<>s and NonnullRefPtr<>s and no need to heap-allocate them. Also remove VFS::mount(NonnullRefPtr<FS>&&, StringView path) - it has been unused for a long time.
2020-01-03Kernel: Allow passing initial UID and GID when creating new inodesAndreas Kling
If we're creating something that should have a different owner than the current process's UID/GID, we need to plumb that all the way through VFS down to the FS functions.
2019-12-24Kernel: Implement recursion limit on path resolutionShannon Booth
Cautiously use 5 as a limit for now so that we don't blow the stack. This can be increased in the future if we are sure that we won't be blowing the stack, or if the implementation is changed to not use recursion :^)
2019-11-05Kernel: Implement O_DIRECT open() flag to bypass disk cachesAndreas Kling
Files opened with O_DIRECT will now bypass the disk cache in read/write operations (though metadata operations will still hit the disk cache.) This will allow us to test actual disk performance instead of testing disk *cache* performance, if that's what we want. :^) There's room for improvment here, we're very aggressively flushing any dirty cache entries for the specific block before reading/writing that block. This is done by walking the entire cache, which may be slow.
2019-09-06AK: Rename <AK/AKString.h> to <AK/String.h>Andreas Kling
This was a workaround to be able to build on case-insensitive file systems where it might get confused about <string.h> vs <String.h>. Let's just not support building that way, so String.h can have an objectively nicer name. :^)
2019-08-18Kernel: Move device lookup to Device class itselfSergey Bugaev
Previously, VFS stored a list of all devices, and devices had to register and unregister themselves with it. This cleans up things a bit.
2019-08-17Kernel: Do the umount() by the guest's root inode identifierAndreas Kling
It was previously possible to unmount a filesystem mounted on /mnt by doing e.g "umount /mnt/some/path".
2019-08-17Kernel: Added unmount ability to VFSJesse Buhagiar
It is now possible to unmount file systems from the VFS via `umount`. It works via looking up the `fsid` of the filesystem from the `Inode`'s metatdata so I'm not sure how fragile it is. It seems to work for now though as something to get us going.
2019-08-11Kernel: Remove an unused VFS function declarationAndreas Kling
2019-08-02Kernel: Generalize VFS metadata lookup and use it in mount() and stat()Andreas Kling
Refactored VFS::stat() into VFS::lookup_metadata(), which can now be used for general VFS metadata lookup by path.
2019-08-02Kernel: Some improvements to the mount syscallAndreas Kling
- You must now have superuser privileges to use mount(). - We now verify that the mount point is a valid path first, before trying to find a filesystem on the specified device. - Convert some dbgprintf() to dbg().
2019-07-24Kernel: Convert Vector<OwnPtr> to NonnullOwnPtrVector.Andreas Kling
2019-07-16Kernel: Remove use of [[gnu::pure]].Andreas Kling
I was messing around with this to tell the compiler that these functions always return the same value no matter how many times you call them. It doesn't really seem to improve code generation and it looks weird so let's just get rid of it.
2019-07-03AK: Rename the common integer typedefs to make it obvious what they are.Andreas Kling
These types can be picked up by including <AK/Types.h>: * u8, u16, u32, u64 (unsigned) * i8, i16, i32, i64 (signed)
2019-06-21AK: Rename RetainPtr.h => RefPtr.h, Retained.h => NonnullRefPtr.h.Andreas Kling
2019-06-21AK: Rename RetainPtr => RefPtr and Retained => NonnullRefPtr.Andreas Kling
2019-06-09FileSystem: Don't perform path resolution twice for open() with O_CREAT.Andreas Kling
2019-06-07Kernel: Rename FileDescriptor to FileDescription.Andreas Kling
After reading a bunch of POSIX specs, I've learned that a file descriptor is the number that refers to a file description, not the description itself. So this patch renames FileDescriptor to FileDescription, and Process now has FileDescription* file_description(int fd).
2019-06-02FileSystem: Rename VFS::fchmod() -> chmod().Andreas Kling
2019-06-02FileSystem: Route chown() and fchown() through VFS for access control.Andreas Kling
2019-06-01FileSystem: Don't create a temporary FileDescriptor every time we stat().Andreas Kling
Instead, move the stat buffer population into InodeMetadata so we can call it directly from VFS::stat() once we have an Inode.
2019-05-31FileSystem: VFS should require Badge<Device> for device registration.Andreas Kling
2019-05-31FileSystem: Don't expose VFS::root_inode().Andreas Kling
It seems like we don't need to expose this anymore, it's only used by VFS internally to construct the root custody.
2019-05-31FileSystem: Rename VFS::resolve_path_to_custody() => resolve_path().Andreas Kling