summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem/VirtualFileSystem.cpp
AgeCommit message (Collapse)Author
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-22Revert "Kernel: Move Singleton class to AK"Andreas Kling
This reverts commit f0906250a181c831508a45434b9f645ff98f33e4.
2020-08-22Revert "AK: Get rid of make_singleton function"Andreas Kling
This reverts commit 5a98e329d157a2db8379e0c97c6bdc1328027843.
2020-08-22AK: Get rid of make_singleton functionTom
Just default the InitFunction template argument.
2020-08-22Kernel: Move Singleton class to AKTom
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-08-05Kernel: Make Inode::directory_entry_count errors observable.Brian Gianforcaro
Certain implementations of Inode::directory_entry_count were calling functions which returned errors, but had no way of surfacing them. Switch the return type to KResultOr<size_t> and start observing these error paths.
2020-07-19Kernel: Implement FIFOs/named pipesPeter Elliott
2020-07-05Kernel: Fix .. directory entry at mount point handling a littleSergey Bugaev
It's still broken, but at least it now appears to work if the file system doesn't return the same inode for "..".
2020-07-05AK: Make Vector::unstable_remove() return the removed valueSergey Bugaev
...and rename it to unstable_take(), to align with other take...() methods.
2020-07-01Kernel: Turn Thread::current and Process::current into functionsTom
This allows us to query the current thread and process on a per processor basis
2020-06-25Kernel: Port mounts to reference inodes directlySergey Bugaev
...instead of going through their identifiers. See the previous commit for reasoning.
2020-06-25Kernel: Deemphasize inode identifiersSergey Bugaev
These APIs were clearly modeled after Ext2FS internals, and make perfect sense in Ext2FS context. The new APIs are more generic, and map better to the semantics exported to the userspace, where inode identifiers only appear in stat() and readdir() output, but never in any input. This will also hopefully reduce the potential for races (see commit https://github.com/SerenityOS/serenity/commit/c44b4d61f350703fcf1bbd8f6e353b9c6c4210c2). Lastly, this makes it way more viable to implement a filesystem that only synthesizes its inodes lazily when queried, and destroys them when they are no longer in use. With inode identifiers being used to reference inodes, the only choice for such a filesystem is to persist any inode it has given out the identifier for, because it might be queried at any later time. With direct references to inodes, the filesystem will know when the last reference is dropped and the inode can be safely destroyed.
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+Base: Mount root filesystem read-only :^)Sergey Bugaev
We remount /home and /root as read-write, to keep the ability to modify files there. /tmp remains read-write, as it is mounted from a TmpFS.
2020-05-29Kernel: Support read-only filesystem mountsSergey Bugaev
This adds support for MS_RDONLY, a mount flag that tells the kernel to disallow any attempts to write to the newly mounted filesystem. As this flag is per-mount, and different mounts of the same filesystems (such as in case of bind mounts) can have different mutability settings, you have to go though a custody to find out if the filesystem is mounted read-only, instead of just asking the filesystem itself whether it's inherently read-only. This also adds a lot of checks we were previously missing; and moves some of them to happen after more specific checks (such as regular permission checks). One outstanding hole in this system is sys$mprotect(PROT_WRITE), as there's no way we can know if the original file description this region has been mounted from had been opened through a readonly mount point. Currently, we always allow such sys$mprotect() calls to succeed, which effectively allows anyone to circumvent the effect of MS_RDONLY. We should solve this one way or another.
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-05-26AK: Rename FileSystemPath -> LexicalPathSergey Bugaev
And move canonicalized_path() to a static method on LexicalPath. This is to make it clear that FileSystemPath/canonicalized_path() only perform *lexical* canonicalization.
2020-04-19Kernel: rmdir("/") should fail instead of assertingAndreas Kling
We can't assume there's always a parent custody -- when we open "/" there isn't gonna be one! Fixes #1858.
2020-04-06Kernel: Change Ext2FS to be backed by a file instead of a block deviceLiav A
In contrast to the previous patchset that was reverted, this time we use a "special" method to access a file with block size of 512 bytes (like a harddrive essentially).
2020-04-04Kernel: Strip SUID+SGID bits from file when written to or chownedAndreas Kling
Fixes #1624.
2020-04-04Kernel: Enforce file system veil on file creationAndreas Kling
Fixes #1621.
2020-04-03Revert "Kernel: Change Ext2FS to be backed by a file instead of a block device"Andreas Kling
This reverts commit 6b59311d4bdc1447e085573f9bd2c42819e264dd. Reverting these changes since they broke things. Fixes #1608.
2020-04-02Kernel: Change Ext2FS to be backed by a file instead of a block deviceLiav A
This ensures that we can mount image files as virtual disks without the need of implementing gross hacks like loopback devices :)
2020-03-19Kernel: Resolve relative paths when there is a veil (#1474)Alex Muscar
2020-03-02Kernel: Use klog() instead of kprintf()Liav A
Also, duplicate data in dbg() and klog() calls were removed. In addition, leakage of virtual address to kernel log is prevented. This is done by replacing kprintf() calls to dbg() calls with the leaked data instead. Also, other kprintf() calls were replaced with klog().
2020-02-26Kernel: Remove unused artifacts of the Custody cacheAndreas Kling
We'll probably want some kind of Custody caching in the future, but as it's not used at the moment, let's simplify things a bit.
2020-02-25AK: Make Vector use size_t for its size and capacityAndreas Kling
2020-02-20Kernel: Fix a panic in VFS::rename()Sergey Bugaev
If we get an -ENOENT when resolving the target because of some part, that is not the very last part, missing, we should just return the error instead of panicking later :^) To test: $ mkdir /tmp/foo/ $ mv /tmp/foo/ /tmp/bar/ Related to https://github.com/SerenityOS/serenity/issues/1253
2020-02-20Kernel: Support trailing slashes in VFS::mkdir()Sergey Bugaev
This is apparently a special case unlike any other, so let's handle it directly in VFS::mkdir() instead of adding an alternative code path into VFS::resolve_path(). Fixes https://github.com/SerenityOS/serenity/issues/1253
2020-02-17Kernel: Replace "current" with Thread::current and Process::currentAndreas Kling
Suggested by Sergey. The currently running Thread and Process are now Thread::current and Process::current respectively. :^)
2020-02-16Kernel: Add forward declaration headerAndreas Kling
2020-02-16Kernel: Move all code into the Kernel namespaceAndreas Kling
2020-02-08Kernel: Simplify FS::create_inode() a little bitAndreas Kling
Return a KResultOr<NonnullRefPtr<Inode>> instead of returning errors in an out-parameter.
2020-02-08Kernel: Simplify FS::create_directory() a little bitAndreas Kling
None of the clients of this function actually used the returned Inode, so it can simply return a KResult instead.
2020-02-01Kernel: Make Inode::lookup() return a RefPtr<Inode>Andreas Kling
Previously this API would return an InodeIdentifier, which meant that there was a race in path resolution where an inode could be unlinked in between finding the InodeIdentifier for a path component, and actually resolving that to an Inode object. Attaching a test that would quickly trip an assertion before. Test: Kernel/path-resolution-race.cpp
2020-01-30Kernel: Dump backtrace when denying a path because of a veilSergey Bugaev
This will make it much easier to see why a process wants to open the file.
2020-01-21Kernel: Rename UnveilState to VeilStateAndreas Kling
2020-01-21Kernel: Tidy up debug logging a little bitAndreas Kling
When using dbg() in the kernel, the output is automatically prefixed with [Process(PID:TID)]. This makes it a lot easier to understand which thread is generating the output. This patch also cleans up some common logging messages and removes the now-unnecessary "dbg() << *current << ..." pattern.
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-18Kernel: Move setting file flags and r/w mode to VFS::open()Sergey Bugaev
Previously, VFS::open() would only use the passed flags for permission checking purposes, and Process::sys$open() would set them on the created FileDescription explicitly. Now, they should be set by VFS::open() on any files being opened, including files that the kernel opens internally. This also lets us get rid of the explicit check for whether or not the returned FileDescription was a preopen fd, and in fact, fixes a bug where a read-only preopen fd without any other flags would be considered freshly opened (due to O_RDONLY being indistinguishable from 0) and granted a new set of flags.
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: Misc tweaksSergey Bugaev
2020-01-17Kernel: Let inodes provide pre-open file descriptionsSergey Bugaev
Some magical inodes, such as /proc/pid/fd/fileno, are going to want to open() to a custom FileDescription, so add a hook for that.
2020-01-17Kernel: Let symlinks resolve themselvesSergey Bugaev
Symlink resolution is now a virtual method on an inode, Inode::resolve_as_symlink(). The default implementation just reads the stored inode contents, treats them as a path and calls through to VFS::resolve_path(). This will let us support other, magical files that appear to be plain old symlinks but resolve to something else. This is particularly useful for ProcFS.