summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem/InodeFile.h
AgeCommit message (Collapse)Author
2021-12-18Kernel: Make File::stat() & friends return Error<struct stat>Andreas Kling
Instead of making the caller provide a stat buffer, let's just return one as a value.
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: Clarify ambiguous {File,Description}::absolute_pathBen Wiederhake
Found due to smelly code in InodeFile::absolute_path. In particular, this replaces the following misleading methods: File::absolute_path This method *never* returns an actual path, and if called on an InodeFile (which is impossible), it would VERIFY_NOT_REACHED(). OpenFileDescription::try_serialize_absolute_path OpenFileDescription::absolute_path These methods do not guarantee to return an actual path (just like the other method), and just like Custody::absolute_path they do not guarantee accuracy. In particular, just renaming the method made a TOCTOU bug obvious. The new method signatures use KResultOr, just like try_serialize_absolute_path() already did.
2021-10-03Kernel: Use `operator ""sv` in all class_name() implementationsBrian Gianforcaro
Previously there was a mix of returning plain strings and returning explicit string views using `operator ""sv`. This change switches them all to standardized on `operator ""sv` as it avoids a call to strlen.
2021-09-12Kernel+LibC: Implement fsyncTheFightingCatfish
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-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-06Kernel: Rename Range => VirtualRangeAndreas Kling
...and also RangeAllocator => VirtualRangeAllocator. This clarifies that the ranges we're dealing with are *virtual* memory ranges and not anything else.
2021-08-06Kernel: Move Kernel/Memory/ code into Kernel::Memory namespaceAndreas Kling
2021-07-27Kernel: Modify the IOCTL API to return KResultBrian Gianforcaro
The kernel has been gradually moving towards KResult from just bare int's, this change migrates the IOCTL paths.
2021-07-27Kernel: Utilize AK::Userspace<T> in the ioctl interfaceBrian Gianforcaro
It's easy to forget the responsibility of validating and safely copying kernel parameters in code that is far away from syscalls. ioctl's are one such example, and bugs there are just as dangerous as at the root syscall level. To avoid this case, utilize the AK::Userspace<T> template in the ioctl kernel interface so that implementors have no choice but to properly validate and copy ioctl pointer arguments.
2021-07-11Kernel: Make various T::class_name() and similar return StringViewAndreas Kling
Instead of returning char const*, we can also give you a StringView.
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-08Kernel: Implement InodeFile::stat() and simplify FileDescription::stat()Max Wipfli
2021-05-13Kernel: Make InodeFile::create() API OOM safeBrian 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-19Kernel: Refactor storage stack with u64 as mmap offsetJean-Baptiste Boric
2021-03-17Kernel: Refactor storage stack with u64 as file operations offsetJean-Baptiste Boric
2021-01-30Kernel: Add FIBMAP ioctl to Ext2FileSystemPeter Elliott
FIBMAP is a linux ioctl that gives the location on disk of a specific block of a file
2021-01-25Kernel: Hoist VM range allocation up to sys$mmap() itselfAndreas Kling
Instead of letting each File subclass do range allocation in their mmap() override, do it up front in sys$mmap(). This makes us honor alignment requests for file-backed memory mappings and simplifies the code somwhat.
2020-09-13Kernel: Make copy_to/from_user safe and remove unnecessary checksTom
Since the CPU already does almost all necessary validation steps for us, we don't really need to attempt to do this. Doing it ourselves doesn't really work very reliably, because we'd have to account for other processors modifying virtual memory, and we'd have to account for e.g. pages not being able to be allocated due to insufficient resources. So change the copy_to/from_user (and associated helper functions) to use the new safe_memcpy, which will return whether it succeeded or not. The only manual validation step needed (which the CPU can't perform for us) is making sure the pointers provided by user mode aren't pointing to kernel mappings. To make it easier to read/write from/to either kernel or user mode data add the UserOrKernelBuffer helper class, which will internally either use copy_from/to_user or directly memcpy, or pass the data through directly using a temporary buffer on the stack. Last but not least we need to keep syscall params trivial as we need to copy them from/to user mode using copy_from/to_user.
2020-08-04Kernel: Make File::write() and File::read() return KResultOr<size_t>Andreas Kling
Instead of returning a ssize_t where negative values mean error, we now return KResultOr<size_t> and use the error state to report errors exclusively.
2020-05-29Kernel: Pass a FileDescription to File::chmod() and File::chown()Sergey Bugaev
We're going to make use of it in the next commit. But the idea is we want to know how this File (more specifically, InodeFile) was opened in order to decide how chown()/chmod() should behave, in particular whether it should be allowed or not. Note that many other File operations, such as read(), write(), and ioctl(), already require the caller to pass a FileDescription.
2020-04-10Kernel: Add explicit offset parameter to File::read etcConrad Pankoff
2020-02-28Kernel: Implement basic support for sys$mmap() with MAP_PRIVATEAndreas Kling
You can now mmap a file as private and writable, and the changes you make will only be visible to you. This works because internally a MAP_PRIVATE region is backed by a unique PrivateInodeVMObject instead of using the globally shared SharedInodeVMObject like we always did before. :^) Fixes #1045.
2020-02-16Kernel: Move all code into the Kernel namespaceAndreas Kling
2020-02-08Kernel: Make File::truncate() take a u64Andreas Kling
No point in taking a signed type here. We validate at the syscall layer and then pass around a u64 from then on.
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-03Kernel: Allow fchmod() and fchown() on pre-bind() local socketsAndreas Kling
In order to ensure a specific owner and mode when the local socket filesystem endpoint is instantiated, we need to be able to call fchmod() and fchown() on a socket fd between socket() and bind(). This is because until we call bind(), there is no filesystem inode for the socket yet.
2019-11-04Kernel: Make File's can_read/can_write take a const FileDescription&Andreas Kling
Asking a File if we could possibly read or write it will never mutate the asking FileDescription&, so it should be const.
2019-07-09Kernel: Move File.{cpp,h} into FileSystem/Andreas Kling
Also tweak the kernel's Makefile to use -nostdinc and -nostdinc++. This prevents us from picking up random headers from ../Root, which may include older versions of kernel headers. Since we still need <initializer_list> for Vector, we specifically include the necessary GCC path. This is a bit hackish but it works for now.
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 => RefPtr and Retained => NonnullRefPtr.Andreas Kling
2019-06-07Kernel: Rename LinearAddress => VirtualAddress.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-02Kernel: Memory-mapped files now have the absolute path as their name.Andreas Kling
It's generated when the mapping is first created, so it won't update if the file moves. Maybe that's something we should support, too.
2019-06-01Kernel: Make File::absolute_path() const.Andreas Kling
2019-05-30Kernel: Add InodeFile, a File subclass for regular files.Andreas Kling
Finally everything that can be held by a FileDescriptor actually inherits from the File class.