Commit Graph

28 Commits

Author SHA1 Message Date
Andreas Kling
cda2b9e71c Kernel: Improvements to Custody absolute path serialization
- Renamed try_create_absolute_path() => try_serialize_absolute_path()
- Use KResultOr and TRY() to propagate errors
- Don't call this when it's only for debug logging
2021-09-06 13:06:05 +02:00
sin-ack
566c5d1e99 AK+Kernel: Move KResult.h to Kernel/API for userspace access
This commit moves the KResult and KResultOr objects to Kernel/API to
signify that they may now be freely used by userspace code at points
where a syscall-related error result is to be expected. It also exposes
KResult and KResultOr to the global namespace to make it nicer to use
for userspace code.
2021-09-05 12:54:48 +02:00
Andreas Kling
d6d7d11590 Kernel: Cache Custody objects (weakly) to avoid expensive reconstruction
This patch adds a (spinlock-protected) custody cache. It's a simple
intrusive list containing all currently live custody objects.

This allows us to re-use existing custodies instead of creating them
again and again.

This gives a pretty decent performance improvement on "find /" :^)
2021-08-15 23:30:52 +02:00
Andreas Kling
7a4e6257b7 Kernel: Switch Custody to east-const style 2021-07-11 00:51:38 +02:00
Max Wipfli
95f769ea51 Kernel: Add Custody::try_create_absolute_path()
This adds a way to get a Custody's absolute path as KString, which
enables it to fail gracefully on OOM.
2021-07-07 15:32:17 +02:00
Andreas Kling
9d801d2345 Kernel: Rename Custody::create() => try_create()
The try_ prefix indicates that this may fail. :^)
2021-05-28 11:23:00 +02:00
Andreas Kling
9a827ad3da Kernel: Use a KString for Custody::m_name 2021-05-28 11:21:00 +02:00
Brian Gianforcaro
5dc5f31f76 Kernel: Replace bare new in Custody::create() with adopt_ref_if_nonnull 2021-05-13 16:21:53 +02:00
Brian Gianforcaro
0b7395848a Kernel: Plumb OOM propagation through Custody factory
Modify the Custody::create(..) API so it has the ability to propagate
OOM back to the caller.
2021-05-10 11:55:52 +02:00
Andreas Kling
b91c49364d AK: Rename adopt() to adopt_ref()
This makes it more symmetrical with adopt_own() (which is used to
create a NonnullOwnPtr from the result of a naked new.)
2021-04-23 16:46:57 +02:00
Brian Gianforcaro
1682f0b760 Everything: Move to SPDX license identifiers in all files.
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-04-22 11:22:27 +02:00
Sergey Bugaev
fdb71cdf8f Kernel: Support read-only filesystem mounts
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-29 07:53:30 +02:00
Andreas Kling
d5fe839166 Kernel: Remove unused artifacts of the Custody cache
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-26 15:25:53 +01:00
Andreas Kling
6428669a37 Kernel: Make Custody slab-allocated 2020-02-22 14:33:51 +01:00
Andreas Kling
635ae70b8f Kernel: More header dependency reduction work 2020-02-16 02:15:33 +01:00
Andreas Kling
a356e48150 Kernel: Move all code into the Kernel namespace 2020-02-16 01:27:42 +01:00
Andreas Kling
94ca55cefd Meta: Add license header to source files
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-18 09:45:54 +01:00
Sergey Bugaev
4566c2d811 Kernel+LibC: Add support for mount flags
At the moment, the actual flags are ignored, but we correctly propagate them all
the way from the original mount() syscall to each custody that resides on the
mounted FS.
2020-01-11 18:57:53 +01:00
Andreas Kling
73fdbba59c AK: Rename <AK/AKString.h> to <AK/String.h>
This was a workaround to be able to build on case-insensitive file
systems where it might get confused about <string.h> vs <String.h>.

Let's just not support building that way, so String.h can have an
objectively nicer name. :^)
2019-09-06 15:36:54 +02:00
Andreas Kling
b020a5e7ce Kernel: Don't create a String every time we look up a Custody by name 2019-08-25 06:45:14 +02:00
Andreas Kling
318068fe1b Kernel: Turns global Custody and Inode tables into InlineLinkedLists
Yet more of this same thing. Each one of these patches has a small but
noticeable impact on the steady-state kmalloc numbers. :^)
2019-08-08 11:11:22 +02:00
Andreas Kling
d343fb2429 AK: Rename Retainable.h => RefCounted.h. 2019-06-21 18:58:45 +02:00
Andreas Kling
550b0b062b AK: Rename RetainPtr.h => RefPtr.h, Retained.h => NonnullRefPtr.h. 2019-06-21 18:45:59 +02:00
Andreas Kling
90b1354688 AK: Rename RetainPtr => RefPtr and Retained => NonnullRefPtr. 2019-06-21 18:37:47 +02:00
Andreas Kling
77b9fa89dd AK: Rename Retainable => RefCounted.
(And various related renames that go along with it.)
2019-06-21 15:30:03 +02:00
Andreas Kling
8adadf8a46 FileSystem: Reuse existing custodies when possible, and keep them updated.
Walk the custody cache and try to reuse an existing one when possible.
The VFS is responsible for updating them when something happens that would
cause the described relationship to change.

This is definitely not perfect but it does work for the basic scenarios like
renaming and removing directory entries.
2019-05-31 15:22:52 +02:00
Andreas Kling
393851418b FileSystem: Port most of the code over to using custodies.
The current working directory is now stored as a custody. Likewise for a
process executable file. This unbreaks /proc/PID/fd which has not been
working since we made the filesystem bigger.

This still needs a bunch of work, for instance when renaming or removing
a file somewhere, we have to update the relevant custody links.
2019-05-30 18:58:59 +02:00
Andreas Kling
4cb87b1753 FileSystem: Add a Custody class that represents a parent/child guardianship.
A custody is kind of a directory entry abstraction that represents a single
entry in a parent directory that tells us the name of a child inode.

The idea here is for path resolution to produce a chain of custody objects.
2019-05-30 17:46:08 +02:00