2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2019-02-03 14:33:11 +03:00
|
|
|
#pragma once
|
|
|
|
|
2020-02-16 03:50:16 +03:00
|
|
|
#include <AK/HashMap.h>
|
2019-02-03 14:33:11 +03:00
|
|
|
#include <AK/Types.h>
|
2019-04-03 13:25:24 +03:00
|
|
|
#include <Kernel/FileSystem/FileSystem.h>
|
2019-05-16 04:02:37 +03:00
|
|
|
#include <Kernel/FileSystem/Inode.h>
|
2021-07-11 12:49:16 +03:00
|
|
|
#include <Kernel/Forward.h>
|
2020-09-17 22:51:09 +03:00
|
|
|
#include <Kernel/KBufferBuilder.h>
|
2021-07-18 10:10:27 +03:00
|
|
|
#include <Kernel/Locking/Mutex.h>
|
Kernel: Introduce the new ProcFS design
The new ProcFS design consists of two main parts:
1. The representative ProcFS class, which is derived from the FS class.
The ProcFS and its inodes are much more lean - merely 3 classes to
represent the common type of inodes - regular files, symbolic links and
directories. They're backed by a ProcFSExposedComponent object, which
is responsible for the functional operation behind the scenes.
2. The backend of the ProcFS - the ProcFSComponentsRegistrar class
and all derived classes from the ProcFSExposedComponent class. These
together form the entire backend and handle all the functions you can
expect from the ProcFS.
The ProcFSExposedComponent derived classes split to 3 types in the
manner of lifetime in the kernel:
1. Persistent objects - this category includes all basic objects, like
the root folder, /proc/bus folder, main blob files in the root folders,
etc. These objects are persistent and cannot die ever.
2. Semi-persistent objects - this category includes all PID folders,
and subdirectories to the PID folders. It also includes exposed objects
like the unveil JSON'ed blob. These object are persistent as long as the
the responsible process they represent is still alive.
3. Dynamic objects - this category includes files in the subdirectories
of a PID folder, like /proc/PID/fd/* or /proc/PID/stacks/*. Essentially,
these objects are always created dynamically and when no longer in need
after being used, they're deallocated.
Nevertheless, the new allocated backend objects and inodes try to use
the same InodeIndex if possible - this might change only when a thread
dies and a new thread is born with a new thread stack, or when a file
descriptor is closed and a new one within the same file descriptor
number is opened. This is needed to actually be able to do something
useful with these objects.
The new design assures that many ProcFS instances can be used at once,
with one backend for usage for all instances.
2021-06-12 04:23:58 +03:00
|
|
|
#include <Kernel/ProcessExposed.h>
|
2021-08-10 20:51:28 +03:00
|
|
|
#include <Kernel/UnixTypes.h>
|
2019-02-03 14:33:11 +03:00
|
|
|
|
2020-02-16 03:27:42 +03:00
|
|
|
namespace Kernel {
|
|
|
|
|
2021-07-11 01:20:38 +03:00
|
|
|
class ProcFS final : public FileSystem {
|
2019-02-03 14:33:11 +03:00
|
|
|
friend class ProcFSInode;
|
Kernel: Introduce the new ProcFS design
The new ProcFS design consists of two main parts:
1. The representative ProcFS class, which is derived from the FS class.
The ProcFS and its inodes are much more lean - merely 3 classes to
represent the common type of inodes - regular files, symbolic links and
directories. They're backed by a ProcFSExposedComponent object, which
is responsible for the functional operation behind the scenes.
2. The backend of the ProcFS - the ProcFSComponentsRegistrar class
and all derived classes from the ProcFSExposedComponent class. These
together form the entire backend and handle all the functions you can
expect from the ProcFS.
The ProcFSExposedComponent derived classes split to 3 types in the
manner of lifetime in the kernel:
1. Persistent objects - this category includes all basic objects, like
the root folder, /proc/bus folder, main blob files in the root folders,
etc. These objects are persistent and cannot die ever.
2. Semi-persistent objects - this category includes all PID folders,
and subdirectories to the PID folders. It also includes exposed objects
like the unveil JSON'ed blob. These object are persistent as long as the
the responsible process they represent is still alive.
3. Dynamic objects - this category includes files in the subdirectories
of a PID folder, like /proc/PID/fd/* or /proc/PID/stacks/*. Essentially,
these objects are always created dynamically and when no longer in need
after being used, they're deallocated.
Nevertheless, the new allocated backend objects and inodes try to use
the same InodeIndex if possible - this might change only when a thread
dies and a new thread is born with a new thread stack, or when a file
descriptor is closed and a new one within the same file descriptor
number is opened. This is needed to actually be able to do something
useful with these objects.
The new design assures that many ProcFS instances can be used at once,
with one backend for usage for all instances.
2021-06-12 04:23:58 +03:00
|
|
|
friend class ProcFSDirectoryInode;
|
2021-08-10 20:51:28 +03:00
|
|
|
friend class ProcFSProcessDirectoryInode;
|
|
|
|
friend class ProcFSGlobalInode;
|
|
|
|
friend class ProcFSAssociatedProcessInode;
|
|
|
|
friend class ProcFSProcessSubDirectoryInode;
|
2019-05-28 12:53:16 +03:00
|
|
|
|
2019-02-03 14:33:11 +03:00
|
|
|
public:
|
|
|
|
virtual ~ProcFS() override;
|
2021-08-14 15:39:51 +03:00
|
|
|
static KResultOr<NonnullRefPtr<ProcFS>> try_create();
|
2019-02-03 14:33:11 +03:00
|
|
|
|
2021-08-14 15:02:47 +03:00
|
|
|
virtual KResult initialize() override;
|
2021-07-17 21:59:06 +03:00
|
|
|
virtual StringView class_name() const override { return "ProcFS"sv; }
|
2019-02-03 14:33:11 +03:00
|
|
|
|
2021-07-18 02:50:47 +03:00
|
|
|
virtual Inode& root_inode() override;
|
2019-02-03 14:33:11 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
ProcFS();
|
|
|
|
|
2021-08-14 15:39:51 +03:00
|
|
|
RefPtr<ProcFSDirectoryInode> m_root_inode;
|
2019-02-03 14:33:11 +03:00
|
|
|
};
|
|
|
|
|
Kernel: Introduce the new ProcFS design
The new ProcFS design consists of two main parts:
1. The representative ProcFS class, which is derived from the FS class.
The ProcFS and its inodes are much more lean - merely 3 classes to
represent the common type of inodes - regular files, symbolic links and
directories. They're backed by a ProcFSExposedComponent object, which
is responsible for the functional operation behind the scenes.
2. The backend of the ProcFS - the ProcFSComponentsRegistrar class
and all derived classes from the ProcFSExposedComponent class. These
together form the entire backend and handle all the functions you can
expect from the ProcFS.
The ProcFSExposedComponent derived classes split to 3 types in the
manner of lifetime in the kernel:
1. Persistent objects - this category includes all basic objects, like
the root folder, /proc/bus folder, main blob files in the root folders,
etc. These objects are persistent and cannot die ever.
2. Semi-persistent objects - this category includes all PID folders,
and subdirectories to the PID folders. It also includes exposed objects
like the unveil JSON'ed blob. These object are persistent as long as the
the responsible process they represent is still alive.
3. Dynamic objects - this category includes files in the subdirectories
of a PID folder, like /proc/PID/fd/* or /proc/PID/stacks/*. Essentially,
these objects are always created dynamically and when no longer in need
after being used, they're deallocated.
Nevertheless, the new allocated backend objects and inodes try to use
the same InodeIndex if possible - this might change only when a thread
dies and a new thread is born with a new thread stack, or when a file
descriptor is closed and a new one within the same file descriptor
number is opened. This is needed to actually be able to do something
useful with these objects.
The new design assures that many ProcFS instances can be used at once,
with one backend for usage for all instances.
2021-06-12 04:23:58 +03:00
|
|
|
class ProcFSInode : public Inode {
|
2019-02-03 14:33:11 +03:00
|
|
|
friend class ProcFS;
|
2019-05-28 12:53:16 +03:00
|
|
|
|
2019-02-03 14:33:11 +03:00
|
|
|
public:
|
|
|
|
virtual ~ProcFSInode() override;
|
2021-08-10 20:51:28 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
ProcFSInode(const ProcFS&, InodeIndex);
|
|
|
|
|
|
|
|
ProcFS& procfs() { return static_cast<ProcFS&>(Inode::fs()); }
|
|
|
|
ProcFS const& procfs() const { return static_cast<ProcFS const&>(Inode::fs()); }
|
|
|
|
|
|
|
|
// ^Inode
|
2021-09-07 14:39:11 +03:00
|
|
|
virtual KResult attach(OpenFileDescription& description) = 0;
|
|
|
|
virtual void did_seek(OpenFileDescription&, off_t) = 0;
|
2021-08-10 20:51:28 +03:00
|
|
|
virtual void flush_metadata() override final;
|
2021-08-28 23:11:16 +03:00
|
|
|
virtual KResultOr<NonnullRefPtr<Inode>> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override final;
|
2021-08-10 20:51:28 +03:00
|
|
|
virtual KResult add_child(Inode&, const StringView& name, mode_t) override final;
|
|
|
|
virtual KResult remove_child(const StringView& name) override final;
|
|
|
|
virtual KResult chmod(mode_t) override final;
|
2021-08-28 23:11:16 +03:00
|
|
|
virtual KResult chown(UserID, GroupID) override final;
|
2021-08-10 20:51:28 +03:00
|
|
|
virtual KResult truncate(u64) override final;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ProcFSGlobalInode : public ProcFSInode {
|
|
|
|
friend class ProcFS;
|
|
|
|
|
|
|
|
public:
|
2021-08-14 15:39:51 +03:00
|
|
|
static KResultOr<NonnullRefPtr<ProcFSGlobalInode>> try_create(const ProcFS&, const ProcFSExposedComponent&);
|
2021-08-10 20:51:28 +03:00
|
|
|
virtual ~ProcFSGlobalInode() override {};
|
Kernel: Introduce the new ProcFS design
The new ProcFS design consists of two main parts:
1. The representative ProcFS class, which is derived from the FS class.
The ProcFS and its inodes are much more lean - merely 3 classes to
represent the common type of inodes - regular files, symbolic links and
directories. They're backed by a ProcFSExposedComponent object, which
is responsible for the functional operation behind the scenes.
2. The backend of the ProcFS - the ProcFSComponentsRegistrar class
and all derived classes from the ProcFSExposedComponent class. These
together form the entire backend and handle all the functions you can
expect from the ProcFS.
The ProcFSExposedComponent derived classes split to 3 types in the
manner of lifetime in the kernel:
1. Persistent objects - this category includes all basic objects, like
the root folder, /proc/bus folder, main blob files in the root folders,
etc. These objects are persistent and cannot die ever.
2. Semi-persistent objects - this category includes all PID folders,
and subdirectories to the PID folders. It also includes exposed objects
like the unveil JSON'ed blob. These object are persistent as long as the
the responsible process they represent is still alive.
3. Dynamic objects - this category includes files in the subdirectories
of a PID folder, like /proc/PID/fd/* or /proc/PID/stacks/*. Essentially,
these objects are always created dynamically and when no longer in need
after being used, they're deallocated.
Nevertheless, the new allocated backend objects and inodes try to use
the same InodeIndex if possible - this might change only when a thread
dies and a new thread is born with a new thread stack, or when a file
descriptor is closed and a new one within the same file descriptor
number is opened. This is needed to actually be able to do something
useful with these objects.
The new design assures that many ProcFS instances can be used at once,
with one backend for usage for all instances.
2021-06-12 04:23:58 +03:00
|
|
|
StringView name() const;
|
|
|
|
|
|
|
|
protected:
|
2021-08-10 20:51:28 +03:00
|
|
|
ProcFSGlobalInode(const ProcFS&, const ProcFSExposedComponent&);
|
2019-02-03 14:33:11 +03:00
|
|
|
|
|
|
|
// ^Inode
|
2021-09-07 14:39:11 +03:00
|
|
|
virtual KResult attach(OpenFileDescription& description) override final;
|
|
|
|
virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override final;
|
|
|
|
virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, OpenFileDescription*) override final;
|
|
|
|
virtual void did_seek(OpenFileDescription&, off_t) override final;
|
Kernel: Introduce the new ProcFS design
The new ProcFS design consists of two main parts:
1. The representative ProcFS class, which is derived from the FS class.
The ProcFS and its inodes are much more lean - merely 3 classes to
represent the common type of inodes - regular files, symbolic links and
directories. They're backed by a ProcFSExposedComponent object, which
is responsible for the functional operation behind the scenes.
2. The backend of the ProcFS - the ProcFSComponentsRegistrar class
and all derived classes from the ProcFSExposedComponent class. These
together form the entire backend and handle all the functions you can
expect from the ProcFS.
The ProcFSExposedComponent derived classes split to 3 types in the
manner of lifetime in the kernel:
1. Persistent objects - this category includes all basic objects, like
the root folder, /proc/bus folder, main blob files in the root folders,
etc. These objects are persistent and cannot die ever.
2. Semi-persistent objects - this category includes all PID folders,
and subdirectories to the PID folders. It also includes exposed objects
like the unveil JSON'ed blob. These object are persistent as long as the
the responsible process they represent is still alive.
3. Dynamic objects - this category includes files in the subdirectories
of a PID folder, like /proc/PID/fd/* or /proc/PID/stacks/*. Essentially,
these objects are always created dynamically and when no longer in need
after being used, they're deallocated.
Nevertheless, the new allocated backend objects and inodes try to use
the same InodeIndex if possible - this might change only when a thread
dies and a new thread is born with a new thread stack, or when a file
descriptor is closed and a new one within the same file descriptor
number is opened. This is needed to actually be able to do something
useful with these objects.
The new design assures that many ProcFS instances can be used at once,
with one backend for usage for all instances.
2021-06-12 04:23:58 +03:00
|
|
|
virtual InodeMetadata metadata() const override;
|
2021-08-10 20:51:28 +03:00
|
|
|
virtual KResult traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
|
2021-08-14 14:32:35 +03:00
|
|
|
virtual KResultOr<NonnullRefPtr<Inode>> lookup(StringView) override;
|
Kernel: Introduce the new ProcFS design
The new ProcFS design consists of two main parts:
1. The representative ProcFS class, which is derived from the FS class.
The ProcFS and its inodes are much more lean - merely 3 classes to
represent the common type of inodes - regular files, symbolic links and
directories. They're backed by a ProcFSExposedComponent object, which
is responsible for the functional operation behind the scenes.
2. The backend of the ProcFS - the ProcFSComponentsRegistrar class
and all derived classes from the ProcFSExposedComponent class. These
together form the entire backend and handle all the functions you can
expect from the ProcFS.
The ProcFSExposedComponent derived classes split to 3 types in the
manner of lifetime in the kernel:
1. Persistent objects - this category includes all basic objects, like
the root folder, /proc/bus folder, main blob files in the root folders,
etc. These objects are persistent and cannot die ever.
2. Semi-persistent objects - this category includes all PID folders,
and subdirectories to the PID folders. It also includes exposed objects
like the unveil JSON'ed blob. These object are persistent as long as the
the responsible process they represent is still alive.
3. Dynamic objects - this category includes files in the subdirectories
of a PID folder, like /proc/PID/fd/* or /proc/PID/stacks/*. Essentially,
these objects are always created dynamically and when no longer in need
after being used, they're deallocated.
Nevertheless, the new allocated backend objects and inodes try to use
the same InodeIndex if possible - this might change only when a thread
dies and a new thread is born with a new thread stack, or when a file
descriptor is closed and a new one within the same file descriptor
number is opened. This is needed to actually be able to do something
useful with these objects.
The new design assures that many ProcFS instances can be used at once,
with one backend for usage for all instances.
2021-06-12 04:23:58 +03:00
|
|
|
|
|
|
|
NonnullRefPtr<ProcFSExposedComponent> m_associated_component;
|
|
|
|
};
|
2019-02-03 14:33:11 +03:00
|
|
|
|
2021-08-10 20:51:28 +03:00
|
|
|
class ProcFSLinkInode : public ProcFSGlobalInode {
|
Kernel: Introduce the new ProcFS design
The new ProcFS design consists of two main parts:
1. The representative ProcFS class, which is derived from the FS class.
The ProcFS and its inodes are much more lean - merely 3 classes to
represent the common type of inodes - regular files, symbolic links and
directories. They're backed by a ProcFSExposedComponent object, which
is responsible for the functional operation behind the scenes.
2. The backend of the ProcFS - the ProcFSComponentsRegistrar class
and all derived classes from the ProcFSExposedComponent class. These
together form the entire backend and handle all the functions you can
expect from the ProcFS.
The ProcFSExposedComponent derived classes split to 3 types in the
manner of lifetime in the kernel:
1. Persistent objects - this category includes all basic objects, like
the root folder, /proc/bus folder, main blob files in the root folders,
etc. These objects are persistent and cannot die ever.
2. Semi-persistent objects - this category includes all PID folders,
and subdirectories to the PID folders. It also includes exposed objects
like the unveil JSON'ed blob. These object are persistent as long as the
the responsible process they represent is still alive.
3. Dynamic objects - this category includes files in the subdirectories
of a PID folder, like /proc/PID/fd/* or /proc/PID/stacks/*. Essentially,
these objects are always created dynamically and when no longer in need
after being used, they're deallocated.
Nevertheless, the new allocated backend objects and inodes try to use
the same InodeIndex if possible - this might change only when a thread
dies and a new thread is born with a new thread stack, or when a file
descriptor is closed and a new one within the same file descriptor
number is opened. This is needed to actually be able to do something
useful with these objects.
The new design assures that many ProcFS instances can be used at once,
with one backend for usage for all instances.
2021-06-12 04:23:58 +03:00
|
|
|
friend class ProcFS;
|
2020-09-17 22:51:09 +03:00
|
|
|
|
Kernel: Introduce the new ProcFS design
The new ProcFS design consists of two main parts:
1. The representative ProcFS class, which is derived from the FS class.
The ProcFS and its inodes are much more lean - merely 3 classes to
represent the common type of inodes - regular files, symbolic links and
directories. They're backed by a ProcFSExposedComponent object, which
is responsible for the functional operation behind the scenes.
2. The backend of the ProcFS - the ProcFSComponentsRegistrar class
and all derived classes from the ProcFSExposedComponent class. These
together form the entire backend and handle all the functions you can
expect from the ProcFS.
The ProcFSExposedComponent derived classes split to 3 types in the
manner of lifetime in the kernel:
1. Persistent objects - this category includes all basic objects, like
the root folder, /proc/bus folder, main blob files in the root folders,
etc. These objects are persistent and cannot die ever.
2. Semi-persistent objects - this category includes all PID folders,
and subdirectories to the PID folders. It also includes exposed objects
like the unveil JSON'ed blob. These object are persistent as long as the
the responsible process they represent is still alive.
3. Dynamic objects - this category includes files in the subdirectories
of a PID folder, like /proc/PID/fd/* or /proc/PID/stacks/*. Essentially,
these objects are always created dynamically and when no longer in need
after being used, they're deallocated.
Nevertheless, the new allocated backend objects and inodes try to use
the same InodeIndex if possible - this might change only when a thread
dies and a new thread is born with a new thread stack, or when a file
descriptor is closed and a new one within the same file descriptor
number is opened. This is needed to actually be able to do something
useful with these objects.
The new design assures that many ProcFS instances can be used at once,
with one backend for usage for all instances.
2021-06-12 04:23:58 +03:00
|
|
|
public:
|
2021-08-14 15:39:51 +03:00
|
|
|
static KResultOr<NonnullRefPtr<ProcFSLinkInode>> try_create(const ProcFS&, const ProcFSExposedComponent&);
|
2021-02-19 11:41:35 +03:00
|
|
|
|
Kernel: Introduce the new ProcFS design
The new ProcFS design consists of two main parts:
1. The representative ProcFS class, which is derived from the FS class.
The ProcFS and its inodes are much more lean - merely 3 classes to
represent the common type of inodes - regular files, symbolic links and
directories. They're backed by a ProcFSExposedComponent object, which
is responsible for the functional operation behind the scenes.
2. The backend of the ProcFS - the ProcFSComponentsRegistrar class
and all derived classes from the ProcFSExposedComponent class. These
together form the entire backend and handle all the functions you can
expect from the ProcFS.
The ProcFSExposedComponent derived classes split to 3 types in the
manner of lifetime in the kernel:
1. Persistent objects - this category includes all basic objects, like
the root folder, /proc/bus folder, main blob files in the root folders,
etc. These objects are persistent and cannot die ever.
2. Semi-persistent objects - this category includes all PID folders,
and subdirectories to the PID folders. It also includes exposed objects
like the unveil JSON'ed blob. These object are persistent as long as the
the responsible process they represent is still alive.
3. Dynamic objects - this category includes files in the subdirectories
of a PID folder, like /proc/PID/fd/* or /proc/PID/stacks/*. Essentially,
these objects are always created dynamically and when no longer in need
after being used, they're deallocated.
Nevertheless, the new allocated backend objects and inodes try to use
the same InodeIndex if possible - this might change only when a thread
dies and a new thread is born with a new thread stack, or when a file
descriptor is closed and a new one within the same file descriptor
number is opened. This is needed to actually be able to do something
useful with these objects.
The new design assures that many ProcFS instances can be used at once,
with one backend for usage for all instances.
2021-06-12 04:23:58 +03:00
|
|
|
protected:
|
|
|
|
ProcFSLinkInode(const ProcFS&, const ProcFSExposedComponent&);
|
|
|
|
virtual InodeMetadata metadata() const override;
|
2019-02-03 14:33:11 +03:00
|
|
|
};
|
2020-01-15 14:05:02 +03:00
|
|
|
|
2021-08-10 20:51:28 +03:00
|
|
|
class ProcFSDirectoryInode final : public ProcFSGlobalInode {
|
Kernel: Introduce the new ProcFS design
The new ProcFS design consists of two main parts:
1. The representative ProcFS class, which is derived from the FS class.
The ProcFS and its inodes are much more lean - merely 3 classes to
represent the common type of inodes - regular files, symbolic links and
directories. They're backed by a ProcFSExposedComponent object, which
is responsible for the functional operation behind the scenes.
2. The backend of the ProcFS - the ProcFSComponentsRegistrar class
and all derived classes from the ProcFSExposedComponent class. These
together form the entire backend and handle all the functions you can
expect from the ProcFS.
The ProcFSExposedComponent derived classes split to 3 types in the
manner of lifetime in the kernel:
1. Persistent objects - this category includes all basic objects, like
the root folder, /proc/bus folder, main blob files in the root folders,
etc. These objects are persistent and cannot die ever.
2. Semi-persistent objects - this category includes all PID folders,
and subdirectories to the PID folders. It also includes exposed objects
like the unveil JSON'ed blob. These object are persistent as long as the
the responsible process they represent is still alive.
3. Dynamic objects - this category includes files in the subdirectories
of a PID folder, like /proc/PID/fd/* or /proc/PID/stacks/*. Essentially,
these objects are always created dynamically and when no longer in need
after being used, they're deallocated.
Nevertheless, the new allocated backend objects and inodes try to use
the same InodeIndex if possible - this might change only when a thread
dies and a new thread is born with a new thread stack, or when a file
descriptor is closed and a new one within the same file descriptor
number is opened. This is needed to actually be able to do something
useful with these objects.
The new design assures that many ProcFS instances can be used at once,
with one backend for usage for all instances.
2021-06-12 04:23:58 +03:00
|
|
|
friend class ProcFS;
|
2020-01-15 14:05:02 +03:00
|
|
|
|
|
|
|
public:
|
2021-08-14 15:39:51 +03:00
|
|
|
static KResultOr<NonnullRefPtr<ProcFSDirectoryInode>> try_create(const ProcFS&, const ProcFSExposedComponent&);
|
Kernel: Introduce the new ProcFS design
The new ProcFS design consists of two main parts:
1. The representative ProcFS class, which is derived from the FS class.
The ProcFS and its inodes are much more lean - merely 3 classes to
represent the common type of inodes - regular files, symbolic links and
directories. They're backed by a ProcFSExposedComponent object, which
is responsible for the functional operation behind the scenes.
2. The backend of the ProcFS - the ProcFSComponentsRegistrar class
and all derived classes from the ProcFSExposedComponent class. These
together form the entire backend and handle all the functions you can
expect from the ProcFS.
The ProcFSExposedComponent derived classes split to 3 types in the
manner of lifetime in the kernel:
1. Persistent objects - this category includes all basic objects, like
the root folder, /proc/bus folder, main blob files in the root folders,
etc. These objects are persistent and cannot die ever.
2. Semi-persistent objects - this category includes all PID folders,
and subdirectories to the PID folders. It also includes exposed objects
like the unveil JSON'ed blob. These object are persistent as long as the
the responsible process they represent is still alive.
3. Dynamic objects - this category includes files in the subdirectories
of a PID folder, like /proc/PID/fd/* or /proc/PID/stacks/*. Essentially,
these objects are always created dynamically and when no longer in need
after being used, they're deallocated.
Nevertheless, the new allocated backend objects and inodes try to use
the same InodeIndex if possible - this might change only when a thread
dies and a new thread is born with a new thread stack, or when a file
descriptor is closed and a new one within the same file descriptor
number is opened. This is needed to actually be able to do something
useful with these objects.
The new design assures that many ProcFS instances can be used at once,
with one backend for usage for all instances.
2021-06-12 04:23:58 +03:00
|
|
|
virtual ~ProcFSDirectoryInode() override;
|
2020-01-15 14:05:02 +03:00
|
|
|
|
Kernel: Introduce the new ProcFS design
The new ProcFS design consists of two main parts:
1. The representative ProcFS class, which is derived from the FS class.
The ProcFS and its inodes are much more lean - merely 3 classes to
represent the common type of inodes - regular files, symbolic links and
directories. They're backed by a ProcFSExposedComponent object, which
is responsible for the functional operation behind the scenes.
2. The backend of the ProcFS - the ProcFSComponentsRegistrar class
and all derived classes from the ProcFSExposedComponent class. These
together form the entire backend and handle all the functions you can
expect from the ProcFS.
The ProcFSExposedComponent derived classes split to 3 types in the
manner of lifetime in the kernel:
1. Persistent objects - this category includes all basic objects, like
the root folder, /proc/bus folder, main blob files in the root folders,
etc. These objects are persistent and cannot die ever.
2. Semi-persistent objects - this category includes all PID folders,
and subdirectories to the PID folders. It also includes exposed objects
like the unveil JSON'ed blob. These object are persistent as long as the
the responsible process they represent is still alive.
3. Dynamic objects - this category includes files in the subdirectories
of a PID folder, like /proc/PID/fd/* or /proc/PID/stacks/*. Essentially,
these objects are always created dynamically and when no longer in need
after being used, they're deallocated.
Nevertheless, the new allocated backend objects and inodes try to use
the same InodeIndex if possible - this might change only when a thread
dies and a new thread is born with a new thread stack, or when a file
descriptor is closed and a new one within the same file descriptor
number is opened. This is needed to actually be able to do something
useful with these objects.
The new design assures that many ProcFS instances can be used at once,
with one backend for usage for all instances.
2021-06-12 04:23:58 +03:00
|
|
|
protected:
|
|
|
|
ProcFSDirectoryInode(const ProcFS&, const ProcFSExposedComponent&);
|
2020-01-15 14:05:02 +03:00
|
|
|
// ^Inode
|
|
|
|
virtual InodeMetadata metadata() const override;
|
2021-07-11 01:20:38 +03:00
|
|
|
virtual KResult traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
|
2021-08-14 14:32:35 +03:00
|
|
|
virtual KResultOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
|
2020-01-15 14:05:02 +03:00
|
|
|
};
|
2021-07-11 12:49:16 +03:00
|
|
|
|
2021-08-10 20:51:28 +03:00
|
|
|
class ProcFSProcessAssociatedInode : public ProcFSInode {
|
|
|
|
friend class ProcFS;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
ProcFSProcessAssociatedInode(const ProcFS&, ProcessID, InodeIndex);
|
|
|
|
ProcessID associated_pid() const { return m_pid; }
|
|
|
|
|
|
|
|
// ^Inode
|
2021-09-07 14:39:11 +03:00
|
|
|
virtual KResultOr<size_t> write_bytes(off_t, size_t, const UserOrKernelBuffer& buffer, OpenFileDescription*) override final;
|
2021-08-10 20:51:28 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
const ProcessID m_pid;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ProcFSProcessDirectoryInode final : public ProcFSProcessAssociatedInode {
|
|
|
|
friend class ProcFS;
|
|
|
|
|
|
|
|
public:
|
2021-08-14 15:39:51 +03:00
|
|
|
static KResultOr<NonnullRefPtr<ProcFSProcessDirectoryInode>> try_create(const ProcFS&, ProcessID);
|
2021-08-10 20:51:28 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
ProcFSProcessDirectoryInode(const ProcFS&, ProcessID);
|
|
|
|
// ^Inode
|
2021-09-07 14:39:11 +03:00
|
|
|
virtual KResult attach(OpenFileDescription& description) override;
|
|
|
|
virtual void did_seek(OpenFileDescription&, off_t) override { }
|
2021-08-10 20:51:28 +03:00
|
|
|
virtual InodeMetadata metadata() const override;
|
|
|
|
virtual KResult traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
|
2021-09-07 14:39:11 +03:00
|
|
|
virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override final;
|
2021-08-14 14:32:35 +03:00
|
|
|
virtual KResultOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
|
2021-08-10 20:51:28 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class ProcFSProcessSubDirectoryInode final : public ProcFSProcessAssociatedInode {
|
|
|
|
friend class ProcFS;
|
|
|
|
|
|
|
|
public:
|
2021-08-14 15:39:51 +03:00
|
|
|
static KResultOr<NonnullRefPtr<ProcFSProcessSubDirectoryInode>> try_create(const ProcFS&, SegmentedProcFSIndex::ProcessSubDirectory, ProcessID);
|
2021-08-10 20:51:28 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
ProcFSProcessSubDirectoryInode(const ProcFS&, SegmentedProcFSIndex::ProcessSubDirectory, ProcessID);
|
|
|
|
// ^Inode
|
2021-09-07 14:39:11 +03:00
|
|
|
virtual KResult attach(OpenFileDescription& description) override;
|
|
|
|
virtual void did_seek(OpenFileDescription&, off_t) override;
|
2021-08-10 20:51:28 +03:00
|
|
|
virtual InodeMetadata metadata() const override;
|
|
|
|
virtual KResult traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
|
2021-09-07 14:39:11 +03:00
|
|
|
virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override final;
|
2021-08-14 14:32:35 +03:00
|
|
|
virtual KResultOr<NonnullRefPtr<Inode>> lookup(StringView name) override;
|
2021-08-10 20:51:28 +03:00
|
|
|
|
|
|
|
const SegmentedProcFSIndex::ProcessSubDirectory m_sub_directory_type;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ProcFSProcessPropertyInode final : public ProcFSProcessAssociatedInode {
|
|
|
|
friend class ProcFS;
|
|
|
|
|
|
|
|
public:
|
2021-08-14 15:39:51 +03:00
|
|
|
static KResultOr<NonnullRefPtr<ProcFSProcessPropertyInode>> try_create_for_file_description_link(const ProcFS&, unsigned, ProcessID);
|
|
|
|
static KResultOr<NonnullRefPtr<ProcFSProcessPropertyInode>> try_create_for_thread_stack(const ProcFS&, ThreadID, ProcessID);
|
|
|
|
static KResultOr<NonnullRefPtr<ProcFSProcessPropertyInode>> try_create_for_pid_property(const ProcFS&, SegmentedProcFSIndex::MainProcessProperty, ProcessID);
|
2021-08-10 20:51:28 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
ProcFSProcessPropertyInode(const ProcFS&, SegmentedProcFSIndex::MainProcessProperty, ProcessID);
|
|
|
|
ProcFSProcessPropertyInode(const ProcFS&, ThreadID, ProcessID);
|
|
|
|
ProcFSProcessPropertyInode(const ProcFS&, unsigned, ProcessID);
|
|
|
|
// ^Inode
|
2021-09-07 14:39:11 +03:00
|
|
|
virtual KResult attach(OpenFileDescription& description) override;
|
|
|
|
virtual void did_seek(OpenFileDescription&, off_t) override;
|
2021-08-10 20:51:28 +03:00
|
|
|
virtual InodeMetadata metadata() const override;
|
|
|
|
virtual KResult traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)>) const override;
|
2021-09-07 14:39:11 +03:00
|
|
|
virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override final;
|
2021-08-14 14:32:35 +03:00
|
|
|
virtual KResultOr<NonnullRefPtr<Inode>> lookup(StringView name) override final;
|
2021-08-10 20:51:28 +03:00
|
|
|
|
2021-09-07 14:39:11 +03:00
|
|
|
KResult refresh_data(OpenFileDescription& description);
|
2021-08-10 20:51:28 +03:00
|
|
|
KResult try_to_acquire_data(Process& process, KBufferBuilder& builder) const;
|
|
|
|
|
|
|
|
const SegmentedProcFSIndex::ProcessSubDirectory m_parent_sub_directory_type;
|
|
|
|
union {
|
|
|
|
SegmentedProcFSIndex::MainProcessProperty property_type;
|
|
|
|
unsigned property_index;
|
|
|
|
} m_possible_data;
|
|
|
|
mutable Mutex m_refresh_lock;
|
|
|
|
};
|
2020-02-16 03:27:42 +03:00
|
|
|
}
|