summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem
AgeCommit message (Collapse)Author
2023-05-27AK+Everywhere: Don't crash on invalid monthsBen Wiederhake
Sadly, we don't have proper error propagation here. However, crashing the Kernel just because a CDROM contains an invalid month seems like a bad idea.
2023-05-27AK: Test from_unix_time_parts intensivelyBen Wiederhake
2023-05-27Kernel: Make Ext2FSInode::traverse_as_directory to take m_inode_lockLiav A
The contents of the directory inode could change if we are not taking so we must take the m_inode_lock to prevent corruption when reading the directory contents.
2023-05-27Kernel: Don't lock ProcFS mutex when calling traverse_as_directoryLiav A
This is not needed, because when we are doing this traversing, functions that are called from this function are using proper and more "atomic" locking.
2023-05-27Kernel: Don't lock SysFS filesystem mutex calling traverse_as_directoryLiav A
This locking is simply not needed because the associated SysFS component will use proper and more "atomic" locking on its own.
2023-05-24Kernel: Use UnixDateTime wherever applicablekleines Filmröllchen
"Wherever applicable" = most places, actually :^), especially for networking and filesystem timestamps. This includes changes to unzip, which uses DOSPackedTime, since that is changed for the FAT file systems.
2023-05-24AK: Rename Time to Durationkleines Filmröllchen
That's what this class really is; in fact that's what the first line of the comment says it is. This commit does not rename the main files, since those will contain other time-related classes in a little bit.
2023-05-19Kernel: Move a bunch of generic devices code into new subdirectoryLiav A
2023-05-17Kernel: Add RPi Watchdog and use it for system shutdownDaniel Bertalan
The Raspberry Pi hardware doesn't support a proper software-initiated shutdown, so this instead uses the watchdog to reboot to a special partition which the firmware interprets as an immediate halt on shutdown. When running under Qemu, this causes the emulator to exit.
2023-05-15Kernel: Remove `FIFO::{attach,detach}(Direction)`Daniel Bertalan
These functions would have caused a `-Woverloaded-virtual` warning with GCC 13, as they shadow `File::{attach,detach}(OpenFileDescription&)`. Both of these functions had a single call site. This commit inlines `attach` into its only caller, `FIFO::open_direction`. Instead of explicitly checking `is_fifo()` in `~OpenFileDescription` before running the `detach(Direction)` overload, let's just override the regular `detach(OpenFileDescription&)` for `FIFO` to perform this action instead.
2023-05-06Kernel: Promote the entry to the front during a cache hitPankaj Raghav
Whenever an entry is added to the cache, the last element is removed to make space for the new entry(if the cache is full). To make this an LRU cache, the entry needs to be moved to the front of the list when there is a cache hit so that the least recently used entry moves to the end to be evicted first.
2023-04-25Kernel: Colorize log message for paths which haven't been unveiledTimothy Flynn
The log message can be hard to spot in a sea of debug messages. Colorize it to make the message more immediately pop out.
2023-04-22Kernel: Protect internal structures in InodeWatcher with spinlocksLiav A
This was the last change that was needed to be able boot with the flag of LOCK_IN_CRITICAL_DEBUG. That flag is not always enabled because there are still other issues in which we hold a spinlock and still try to lock a mutex. Instead of using one global mutex we can protect internal structures of the InodeWatcher class with SpinlockProtected wrappers. This in turn allows the InodeWatcher code to be called from other parts in the kernel while holding a prior spinlock properly.
2023-04-21Kernel+Userland: Remove the `nfds` entry from `/sys/kernel/processes`Tim Schumacher
`process.fds()` is protected by a Mutex, which causes issues when we try to acquire it while holding a Spinlock. Since nothing seems to use this value, let's just remove it entirely for now.
2023-04-17Kernel: Remove unused functions related to reading full inodesTim Schumacher
2023-04-17Kernel: Use purpose-sized buffers when resolving inodes as linksTim Schumacher
2023-04-17Kernel: Add `Inode::read_until_filled_or_end`Tim Schumacher
The existing `read_entire` is quite slow due to allocating and copying multiple times, but it is simultaneously quite hard to get rid of in a single step. As a replacement, add a new function that reads as much as possible directly into a user-provided buffer.
2023-04-14Kernel: Get rid of *LockRefPtr in the SysFS filesystem codeLiav A
To do this we also need to get rid of LockRefPtrs in the USB code as well. Most of the SysFS nodes are statically generated during boot and are not mutated afterwards. The same goes for general device code - once we generate the appropriate SysFS nodes, we almost never mutate the node pointers afterwards, making locking unnecessary.
2023-04-10Kernel: Add the futimens syscallLiav A
We have a problem with the original utimensat syscall because when we do call LibC futimens function, internally we provide an empty path, and the Kernel get_syscall_path_argument method will detect this as an invalid path. This happens to spit an error for example in the touch utility, so if a user is running "touch non_existing_file", it will create that file, but the user will still see an error coming from LibC futimens function. This new syscall gets an open file description and it provides the same functionality as utimensat, on the specified open file description. The new syscall will be used later by LibC to properly implement LibC futimens function so the situation described with relation to the "touch" utility could be fixed.
2023-04-09Kernel: Remove redundant HID name from all associated filesLiav A
2023-04-08Kernel: Mark a bunch of NonnullRefPtrs also const to ensure immutabilityLiav A
These were easy to pick-up as these pointers are assigned during the construction point and are never changed afterwards. This small change to these pointers will ensure that our code will not accidentally assign these pointers with a new object which is always a kind of bug we will want to prevent.
2023-04-05Kernel: Stop using *LockRefPtr for TTYAndreas Kling
TTY was only stored in Process::m_tty, so make that a SpinlockProtected.
2023-04-04Kernel: Stop using *LockRefPtr for ThreadAndreas Kling
These were stored in a bunch of places. The main one that's a bit iffy is the Mutex::m_holder one, which I'm going to simplify in a subsequent commit. In Plan9FS and WorkQueue, we can't make the NNRPs const due to initialization order problems. That's probably doable with further cleanup, but left as an exercise for our future selves. Before starting this, I expected the thread blockers to be a problem, but as it turns out they were super straightforward (for once!) as they don't mutate the thread after initiating a block, so they can just use simple const-ified NNRPs.
2023-04-04Kernel: Simplify Process factory functionsAndreas Kling
- Instead of taking the first new thread as an out-parameter, we now bundle the process and its first thread in a struct and use that as the return value. - Make all Process factory functions return ErrorOr. Use this to convert some places to more TRY(). - Drop the "try_" prefix on Process factory functions.
2023-04-04Kernel: Stop using *LockRefPtr for Process pointersAndreas Kling
The only persistent one of these was Thread::m_process and that never changes after initialization. Make it const to enforce this and switch everything over to RefPtr & NonnullRefPtr.
2023-04-04Kernel: Simplify Mount internalsAndreas Kling
- The host custody never changes after initialization, so there's no need to protect it with a spinlock. - To enforce the fact that some members don't change after initialization, make them const.
2023-04-04Kernel: Stop using *LockRefPtr for FileSystem pointersAndreas Kling
There was only one permanent storage location for these: as a member in the Mount class. That member is never modified after Mount initialization, so we don't need to worry about races there.
2023-04-02Kernel: Initialize DiskCache's buffer before the dirty&clean listsMarco Cutecchia
This commit fixes a kernel panic that happened when unmounting a disk due to an invalid memory access. This was because `DiskCache` initializes two linked lists that use an argument `KBuffer` as the storage for their elements. Since the member `KBuffer` was declared after the two lists, when `DiskCache`'s destructor was called, then `KBuffer`'s destructor was called before the ones of the two lists, causing a page fault in the kernel.
2023-03-13AK: Rename Stream::write_entire_buffer to Stream::write_until_depletedTim Schumacher
No functional changes.
2023-03-12Kernel: Make the Jails' internal design a lot more saneLiav A
This is done with 2 major steps: 1. Remove JailManagement singleton and use a structure that resembles what we have with the Process object. This is required later for the second step in this commit, but on its own, is a major change that removes this clunky singleton that had no real usage by itself. 2. Use IntrusiveLists to keep references to Process objects in the same Jail so it will be much more straightforward to iterate on this kind of objects when needed. Previously we locked the entire Process list and we did a simple pointer comparison to check if the checked Process we iterate on is in the same Jail or not, which required taking multiple Spinlocks in a very clumsy and heavyweight way.
2023-03-10Kernel: Use RefPtr instead of LockRefPtr for File and subclassesAndreas Kling
This was mostly straightforward, as all the storage locations are guarded by some related mutex. The use of old-school associated mutexes instead of MutexProtected is unfortunate, but the process to modernize such code is ongoing.
2023-03-09Kernel: Switch LockRefPtr<Inode> to RefPtr<Inode>Andreas Kling
The main place where this is a little iffy is in RAMFS where inodes have a LockWeakPtr to their parent inode. I've left that as a LockWeakPtr for now.
2023-03-07Kernel: Use non-locking {Nonnull,}RefPtr for OpenFileDescriptionAndreas Kling
This patch switches away from {Nonnull,}LockRefPtr to the non-locking smart pointers throughout the kernel. I've looked at the handful of places where these were being persisted and I don't see any race situations. Note that the process file descriptor table (Process::m_fds) was already guarded via MutexProtected.
2023-03-06Kernel: Stop using NonnullLockRefPtrVectorAndreas Kling
2023-03-06Everywhere: Remove NonnullOwnPtr.h includesAndreas Kling
2023-03-06Everywhere: Stop using NonnullOwnPtrVectorAndreas Kling
Same as NonnullRefPtrVector: weird semantics, questionable benefits.
2023-03-05Kernel: Actually check Process unveil data when creating perfcore dumpLiav A
Before of this patch, we looked at the unveil data of the FinalizerTask, which naturally doesn't have any unveil restrictions, therefore allowing an unveil bypass for a process that enabled performance coredumps. To ensure we always check the dumped process unveil data, an option to pass a Process& has been added to a couple of methods in the class of VirtualFileSystem.
2023-02-24Kernel/FileSystem: Simplify the ProcFS significantlyLiav A
Since the ProcFS doesn't hold many global objects within it, the need for a fully-structured design of backing components and a registry like with the SysFS is no longer true. To acommodate this, let's remove all backing store and components of the ProcFS, so now it resembles what we had in the early days of ProcFS in the project - a mostly-static filesystem, with very small amount of kmalloc allocations needed. We still use the inode index mechanism to understand the role of each inode, but this is done in a much "static"ier way than before.
2023-02-24Kernel: Fix typo proccess => process in a name of Process methodLiav A
2023-02-24AK+Kernel: Add includes before removing Kernel/ProcessExposed.hLiav A
Apparently without this file, we won't be able to compile due to missing includes to TimeManagement and KBufferBuilder.
2023-02-21Kernel: Fix const-correctness of PCI::DeviceIdentifier usageAndreas Kling
2023-02-19Kernel+Userland: Add constants subdirectory at /sys/kernel directoryLiav A
This subdirectory is meant to hold all constant data related to the kernel. This means that this data is never meant to updated and is relevant from system boot to system shutdown. Move the inodes of "load_base", "cmdline" and "system_mode" to that directory. All nodes under this new subdirectory are generated during boot, and therefore don't require calling kmalloc each time we need to read them. Locking is also not necessary, because these nodes and their data are completely static once being generated.
2023-02-19Kernel: Remove unnecessary include from SysFS PowerStateSwitch codeLiav A
I added that include in 2e55956784ac0c61fe877c316867074e0f432452 by a mistake, so we should get rid of it as soon as possible.
2023-02-19Kernel/FileSystem: Don't assume flags for root filesystem mount flagsLiav A
This is considered somewhat an abstraction layer violation, because we should always let userspace to decide on the root filesystem mount flags because it allows the user to configure the mount table to preferences that they desire. Now that SystemServer is modified to re-mount the root mount with the desired flags, we can just mount the root filesystem without assuming special flags.
2023-02-19Kernel/FileSystem: Fix check of read offset for the RAMFSInode codeLiav A
The check of ensuring we are not trying to read beyond the end of the inode data buffer is already there, it's just that we need to disallow further reading if the read offset equals to the inode data size.
2023-02-19Kernel/FileSystem: Add check of read offset for the FATInode codeLiav A
Apparently we lacked this important check from the beginning of this piece of code. This check is crucial to ensure we only give back data being related to the FATInode data buffer and nothing beyond it.
2023-02-19Kernel: Change polarity of weak ownership between Inode and LocalSocketPeter Elliott
There was a bug in which bound Inodes would lose all their references (because localsocket does not reference them), and they would be deallocated, and clients would get ECONNREFUSED as a result. now LocalSocket has a strong reference to inode so that the inode will live as long as the socket, and Inode has a weak reference to the socket, because if the socket stops being referenced anywhere it should not be bound. This still prevents the reference loop that 220b7dd77905b7d573ded093cf88d2dc51f57c69 was trying to fix.
2023-02-18Kernel: Dont crash if power states gets set to an invalid valueUndefine
2023-02-12AK: Add conversion functions for packed DOS time formatOllrogge
This also adjusts the FATFS code to use the new functions and removes the now redundant old conversion functions.
2023-02-10Kernel: Explicitly copy Plan9FS read errors to registered delegatesTimothy Flynn