Files
serenity/Kernel/FileSystem/UnsharedResourceFile.h
Liav A. f6db24dba4 Kernel+runc: Remove the pivot_root functionality in copy_mount syscall
That functionality seems to be too much complicated.
We shouldn't overengineer how the copy_mount syscall works, so instead
of allowing replacement of the root filesystem, let's make the unshare
file descriptor to be configured via a special ioctl call before we
initialize a new VFSRootContext object.

The special ioctl can either set a new root filesystem for the upcoming
VFSRootContext object, or remove it (by passing fd of -1).
If there's no specified root filesystem, a new RAMFS instance will be
created automatically when invoking the unshare_create syscall.

This also simplifies the code in the boot process, hence making it much
more readable.

It should be noted, that we assumed during pivot_root that the first
mountpoint in a context is the root mountpoint, which is probably a fair
assumption, but we don't assume this anywhere else in the VFSRootContext
code.
If this functionality ever comes back, we should ensure that we make
some effort to not assume this again.
2026-03-14 11:45:37 +01:00

40 lines
1.4 KiB
C++

/*
* Copyright (c) 2026, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <Kernel/API/Unshare.h>
#include <Kernel/FileSystem/File.h>
#include <Kernel/Locking/MutexProtected.h>
namespace Kernel {
class UnsharedResourceFile final : public File {
public:
static ErrorOr<NonnullRefPtr<UnsharedResourceFile>> create(UnshareType);
virtual ~UnsharedResourceFile() override;
virtual bool can_read(OpenFileDescription const&, u64) const override { return true; }
virtual bool can_write(OpenFileDescription const&, u64) const override { return true; }
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override { return ENOTSUP; }
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, UserOrKernelBuffer const&, size_t) override { return ENOTSUP; }
virtual ErrorOr<void> ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg) override;
virtual ErrorOr<NonnullOwnPtr<KString>> pseudo_path(OpenFileDescription const&) const override;
virtual StringView class_name() const override { return "UnsharedResourceFile"sv; }
ErrorOr<unsigned> initialize_resource();
private:
virtual bool is_unshared_resource_file() const override { return true; }
explicit UnsharedResourceFile(UnshareType);
UnshareType const m_type;
MutexProtected<RefPtr<FileSystem>> m_root_filesystem;
};
}