summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem/TmpFS.cpp
AgeCommit message (Collapse)Author
2022-01-14Kernel/TmpFS: Remove inode map from TmpFSAndreas Kling
The HashMap of InodeIndex->Inode in TmpFS only had one purpose: looking up parent inodes by index. Instead of using a map for this, we can simply give each inode a WeakPtr to its parent inode. This saves us the trouble of dealing with the fallibility of HashMap allocations, and it just generally simpler. :^)
2022-01-11Kernel: Synchronize removals from TmpFS inode mapAndreas Kling
Previously we were uncaching inodes from TmpFSInode::one_ref_left(). This was not safe, since one_ref_left() was effectively being called on a raw pointer after decrementing the local ref count and observing it become 1. There was a race here where someone else could trigger the destructor by unreffing to 0 before one_ref_left() got called, causing us to call one_ref_left() on a deleted inode. We fix this by using the new remove_from_secondary_lists() mechanism in ListedRefCounted and synchronizing all access to the TmpFS inode map with the main Inode::all_instances() lock. There's probably a nicer way to solve this.
2022-01-07Everywhere: Fix spelling mistakesmjz19910
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.
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-11-11Everywhere: Pass AK::StringView by valueAndreas Kling
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-21Kernel: Make Inode::flush_metadata() return a KResultAndreas Kling
Even if this goes nowhere yet, we have to start building an error propagation path somewhere.
2021-09-07Kernel/TmpFS: Stop leaking directory entry metadataAndreas Kling
When creating and removing a child to a TmpFS directory, we were forgetting to delete the TmpFSInode::Child struct.
2021-09-07Kernel: Make KBuffer::try_create_with_size() return KResultOrAndreas Kling
This allows us to use TRY() in a lot of new places.
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-07Kernel: Make UserOrKernelBuffer return KResult from read/write/memsetAndreas Kling
This allows us to simplify a whole bunch of call sites with TRY(). :^)
2021-09-06Kernel: Use TRY() in TmpFSInode::write_bytes()Andreas Kling
2021-09-06Kernel: Make KString factories return KResultOr + use TRY() everywhereAndreas Kling
There are a number of places that don't have an error propagation path right now, so I've added FIXME's about that.
2021-09-06Kernel: Tidy up TmpFS and TmpFSInode constructionAndreas Kling
- Use KResultOr<NonnullRefPtr<T>> - Propagate errors - Use TRY() at call sites
2021-09-05Kernel: Make FileSystem::get_inode() return KResultOr<NRP<Inode>>Andreas Kling
This allows for natural error propagation in a bunch of new places.
2021-09-01Kernel: Pass InodeMetadata by reference in TmpFSInode::createBrian Gianforcaro
This struct is non-trivially large, it makes sense to pass it by reference instead of by value in the factory method. Found by Sonar Cloud.
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-19Kernel: Move set_metadata_dirty calls to notify_watchersEdward Palmer
2021-08-14Kernel: Make FileSystem::initialize() return KResultAndreas Kling
This forced me to also come up with error codes for a bunch of situations where we'd previously just panic the kernel.
2021-08-14Kernel: Make Inode::lookup() return a KResultOr<NonnullRefPtr<Inode>>Andreas Kling
This allows file systems to return arbitrary error codes instead of just an Inode or not an Inode.
2021-07-18Kernel/TmpFS: Remove some unnecessary includesAndreas Kling
2021-07-18Kernel/TmpFS: Use IntrusiveList and KString for OOM safetyAndreas Kling
This patch moves TmpFS to using OOM-safe data types for storing directory children.
2021-07-18Kernel: Make FileSystem::root_inode() return a plain Inode&Andreas Kling
All file system classes are expected to keep their root Inode object in memory, so this function can safely return an Inode&.
2021-07-18Kernel: Rename Locker => MutexLockerAndreas Kling
2021-07-17Kernel: Remove Inode::directory_entry_count()Andreas Kling
This was only used in one place: VirtualFileSystem::rmdir(), and that has now been converted to a simple directory traversal.
2021-07-17Kernel: Make Inode::create_child() take the name as a StringViewAndreas Kling
No sense in forcing callers to construct a String. One more small step towards not using String in the kernel.
2021-07-17Kernel: Rename Inode::m_lock => m_inode_lockAndreas Kling
This makes file system code much easier to read since it was hard when both the file system and inode locks were called "m_lock".
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: Fix TmpFS resize behavior around INT32_MAX for 32-bit systemsAndrew Kaster
We need some overflow checks due to the implementation of TmpFS. When size_t is 32 bits and off_t is 64 bits, we might overflow our KBuffer max size and confuse the KBuffer set_size code, causing a VERIFY failure. Make sure that resulting offset + size will fit in a size_t. Another constraint, we make sure that the resulting offset + size will be less than half of the maximum value of a size_t, because we double the KBuffer size each time we resize it.
2021-07-11Kernel: Rename FS => FileSystemAndreas Kling
This matches our common naming style better.
2021-06-24Everywhere: Use nothrow new with `adopt_{ref,own}_if_nonnull`Daniel Bertalan
This commit converts naked `new`s to `AK::try_make` and `AK::try_create` wherever possible. If the called constructor is private, this can not be done, so we instead now use the standard-defined and compiler-agnostic `new (nothrow)`.
2021-06-24Kernel: Fix compiling TmpFSInode::write_bytes on x86_64Gunnar Beutner
2021-06-16Kernel: Remove various other uses of ssize_tGunnar Beutner
2021-06-01Kernel: Move TmpFS towards OOM safetyBrian Gianforcaro
2021-05-12Kernel: Implement multi-watch InodeWatcher :^)sin-ack
This patch modifies InodeWatcher to switch to a one watcher, multiple watches architecture. The following changes have been made: - The watch_file syscall is removed, and in its place the create_iwatcher, iwatcher_add_watch and iwatcher_remove_watch calls have been added. - InodeWatcher now holds multiple WatchDescriptions for each file that is being watched. - The InodeWatcher file descriptor can be read from to receive events on all watched files. Co-authored-by: Gunnar Beutner <gunnar@beutner.name>
2021-05-02Kernel: Change Inode::{read/write}_bytes interface to KResultOr<ssize_t>Brian Gianforcaro
The error handling in all these cases was still using the old style negative values to indicate errors. We have a nicer solution for this now with KResultOr<T>. This change switches the interface and then all implementers to use the new style.
2021-04-30Kernel: Make Inode::set_{a,c,m}time return KResultAndreas Kling
This exposed some missing error propagation, which this patch also takes care of.
2021-04-25Kernel: Remove the now defunct `LOCKER(..)` macro.Brian Gianforcaro
2021-04-23AK: Rename adopt() to adopt_ref()Andreas Kling
This makes it more symmetrical with adopt_own() (which is used to create a NonnullOwnPtr from the result of a naked new.)
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 *
2021-03-04Kernel: Stop trying to keep InodeVMObject in sync with disk changesAndreas Kling
As it turns out, Dr. POSIX doesn't require that post-mmap() changes to a file are reflected in the memory mappings. So we don't actually have to care about the file size changing (or the contents.) IIUC, as long as all the MAP_SHARED mappings that refer to the same inode are in sync, we're good. This means that VMObjects don't need resizing capabilities. I'm sure there are ways we can take advantage of this fact.
2021-03-02Kernel: Make kgettimeofday use AK::TimeBen Wiederhake
2021-03-02Kernel: Remove duplicative kgettimeofday(timeval&) functionBen Wiederhake
2021-02-23Everywhere: Rename ASSERT => VERIFYAndreas Kling
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED) Since all of these checks are done in release builds as well, let's rename them to VERIFY to prevent confusion, as everyone is used to assertions being compiled out in release. We can introduce a new ASSERT macro that is specifically for debug checks, but I'm doing this wholesale conversion first since we've accumulated thousands of these already, and it's not immediately obvious which ones are suitable for ASSERT.
2021-02-12Kernel: Add distinct InodeIndex typeAndreas Kling
Use the DistinctNumeric mechanism to make InodeIndex a strongly typed integer type.
2021-01-20Kernel+LibC: Turn errno codes into a strongly typed enumAndreas Kling
..and allow implicit creation of KResult and KResultOr from ErrnoCode. This means that kernel functions that return those types can finally do "return EINVAL;" and it will just work. There's a handful of functions that still deal with signed integers that should be converted to return KResults.
2020-12-18TmpFS: Use fallible KBuffer APIAndreas Kling
If allocation fails, some TmpFS operations can now fail with ENOMEM.
2020-11-14TmpFS: Set the root inode's timestamp to the current timeAndreas Kling
cc @bcoles :^)