summaryrefslogtreecommitdiff
path: root/Kernel/FileSystem/FileDescription.h
AgeCommit message (Collapse)Author
2020-06-02Kernel: Allow File::close() to failSergey Bugaev
And pass the result through to sys$close() return value. Fixes https://github.com/SerenityOS/serenity/issues/427
2020-05-26Kernel: Plumb KResult through FileDescription::read_entire_file() ↵Brian Gianforcaro
implementation. Allow file system implementation to return meaningful error codes to callers of the FileDescription::read_entire_file(). This allows both Process::sys$readlink() and Process::sys$module_load() to return more detailed errors to the user.
2020-05-16Kernel: Absorb LibBareMetal back into the kernelAndreas Kling
This was supposed to be the foundation for some kind of pre-kernel environment, but nobody is working on it right now, so let's move everything back into the kernel and remove all the confusion.
2020-04-18Kernel: Compactify FileDescrptionSergey Bugaev
The next commit is going to make it bigger again by increasing the size of Lock, so make use of bitfields to make sure FileDescription still fits into 64 bytes, and so can still be allocated with the SlabAllocator.
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-22Kernel: Make FileDescription slab-allocatedAndreas Kling
2020-02-16Kernel: Move all code into the Kernel namespaceAndreas Kling
2020-02-09Kernel: Use VirtualAddress & PhysicalAddress classes from LibBareMetalLiav A
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-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-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-12Kernel: Add a basic lock to FileDescriptionAndreas Kling
Let's prevent two processes sharing a FileDescription from messing with it at the same time for now.
2020-01-12Kernel: Allow getting a Device from a FileDescriptionSergey Bugaev
Like we already do for other kinds of files.
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.
2020-01-03Kernel: read() and write() should fail with EBADF for wrong mode fd'sAndreas Kling
It was previously possible to write to read-only file descriptors, and read from write-only file descriptors. All FileDescription objects now start out non-readable + non-writable, and whoever is creating them has to "manually" enable reading/writing by calling set_readable() and/or set_writable() on them.
2020-01-02Kernel: Remove broken implementation of Unix SHMAndreas Kling
This code never worked, as was never used for anything. We can build a much better SHM implementation on top of TmpFS or similar when we get to the point when we need one.
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-10-25Kernel: FileDescription::is_directory() should not assert !is_fifo()Andreas Kling
I have no idea why this was here. It makes no sense. If you're trying to find out if something is a directory, why wouldn't you be allowed to ask that about a FIFO? :^) Thanks to Brandon for spotting this! Also, while we're here, cache the directory state in a bool member so we don't have to keep fetching inode metadata when checking this repeatedly. This is important since sys$read() now calls it.
2019-08-11Kernel: Move socket role tracking to the Socket class itselfSergey Bugaev
This is more logical and allows us to solve the problem of non-blocking TCP sockets getting stuck in SocketRole::None. The only complication is that a single LocalSocket may be shared between two file descriptions (on the connect and accept sides), and should have two different roles depending from which side you look at it. To deal with it, Socket::role() is made a virtual method that accepts a file description, and LocalSocket internally tracks which FileDescription is the which one and returns a correct role.
2019-08-11Kernel: Fix cloning file descriptions on forkSergey Bugaev
After a fork, the parent and the child are supposed to share the same file description. For example, modifying the current offset of a file description is visible in both of them.
2019-08-11FileDescription: Disallow construction with a null FileAndreas Kling
It's not valid for a FileDescription to not have a file, so let's disallow it by taking a File& (or FIFO&) in the constructor.
2019-08-05Kernel: Use KBuffers for ProcFS and SynthFSAndreas Kling
Instead of generating ByteBuffers and keeping those lying around, have these filesystems generate KBuffers instead. These are way less spooky to leave around for a while. Since FileDescription will keep a generated file buffer around until userspace has read the whole thing, this prevents trivially exhausting the kmalloc heap by opening many files in /proc for example. The code responsible for generating each /proc file is not perfectly efficient and many of them still use ByteBuffers internally but they at least go away when we return now. :^)
2019-07-19Kernel: Some small refinements to the thread blockers.Andreas Kling
Committing some things my hands did while browsing through this code. - Mark all leaf classes "final". - FileDescriptionBlocker now stores a NonnullRefPtr<FileDescription>. - FileDescriptionBlocker::blocked_description() now returns a reference. - ConditionBlocker takes a Function&&.
2019-07-11Kernel: Remove use of copy_ref() in favor of regular RefPtr copies.Andreas Kling
This is obviously more readable. If we ever run into a situation where ref count churn is actually causing trouble in the future, we can deal with it then. For now, let's keep it simple. :^)
2019-07-09Kernel: Move VirtualAddress.h into VM/Andreas Kling
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 Retainable.h => RefCounted.h.Andreas Kling
2019-06-21AK: Rename RetainPtr => RefPtr and Retained => NonnullRefPtr.Andreas Kling
2019-06-21AK: Rename Retainable => RefCounted.Andreas Kling
(And various related renames that go along with it.)
2019-06-07Meta: Tweak .clang-format to not wrap braces after enums.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).