mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
Kernel/SysFS: Add two methods related to relative paths for components
These methods will be used later on to introduce symbolic links support in the SysFS, so the kernel will be able to resolve relative paths of components in filesystem based on using the m_parent_directory pointer in each SysFSComponent object.
This commit is contained in:
parent
4744ccbff0
commit
7e88bbe550
Notes:
sideshowbarker
2024-07-17 09:41:18 +09:00
Author: https://github.com/supercomputer7 Commit: https://github.com/SerenityOS/serenity/commit/7e88bbe550 Pull-request: https://github.com/SerenityOS/serenity/pull/13779
2 changed files with 35 additions and 4 deletions
|
@ -7,6 +7,7 @@
|
|||
#include <Kernel/FileSystem/SysFS.h>
|
||||
#include <Kernel/FileSystem/SysFS/Component.h>
|
||||
#include <Kernel/FileSystem/SysFS/Registry.h>
|
||||
#include <Kernel/KLexicalPath.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
|
@ -21,11 +22,36 @@ static size_t allocate_inode_index()
|
|||
return s_next_inode_index.value();
|
||||
}
|
||||
|
||||
SysFSComponent::SysFSComponent(SysFSDirectory const& parent_directory)
|
||||
: m_parent_directory(parent_directory)
|
||||
, m_component_index(allocate_inode_index())
|
||||
{
|
||||
}
|
||||
|
||||
SysFSComponent::SysFSComponent()
|
||||
: m_component_index(allocate_inode_index())
|
||||
{
|
||||
}
|
||||
|
||||
ErrorOr<NonnullOwnPtr<KString>> SysFSComponent::relative_path(NonnullOwnPtr<KString> name, size_t current_hop) const
|
||||
{
|
||||
if (current_hop >= 128)
|
||||
return Error::from_errno(ELOOP);
|
||||
if (!m_parent_directory)
|
||||
return name;
|
||||
auto joined_name = TRY(KLexicalPath::try_join(m_parent_directory->name(), name->view()));
|
||||
return m_parent_directory->relative_path(move(joined_name), current_hop + 1);
|
||||
}
|
||||
|
||||
ErrorOr<size_t> SysFSComponent::relative_path_hops_count_from_mountpoint(size_t current_hop) const
|
||||
{
|
||||
if (current_hop >= 128)
|
||||
return Error::from_errno(ELOOP);
|
||||
if (!m_parent_directory)
|
||||
return current_hop;
|
||||
return m_parent_directory->relative_path_hops_count_from_mountpoint(current_hop + 1);
|
||||
}
|
||||
|
||||
mode_t SysFSComponent::permissions() const
|
||||
{
|
||||
return S_IRUSR | S_IRGRP | S_IROTH;
|
||||
|
@ -56,8 +82,7 @@ RefPtr<SysFSComponent> SysFSDirectory::lookup(StringView name)
|
|||
}
|
||||
|
||||
SysFSDirectory::SysFSDirectory(SysFSDirectory const& parent_directory)
|
||||
: SysFSComponent()
|
||||
, m_parent_directory(parent_directory)
|
||||
: SysFSComponent(parent_directory)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ struct SysFSInodeData : public OpenFileDescriptionData {
|
|||
OwnPtr<KBuffer> buffer;
|
||||
};
|
||||
|
||||
class SysFSDirectory;
|
||||
class SysFSComponent : public RefCounted<SysFSComponent> {
|
||||
public:
|
||||
virtual StringView name() const = 0;
|
||||
|
@ -42,9 +43,15 @@ public:
|
|||
|
||||
virtual ~SysFSComponent() = default;
|
||||
|
||||
ErrorOr<NonnullOwnPtr<KString>> relative_path(NonnullOwnPtr<KString>, size_t current_hop = 0) const;
|
||||
ErrorOr<size_t> relative_path_hops_count_from_mountpoint(size_t current_hop = 0) const;
|
||||
|
||||
protected:
|
||||
explicit SysFSComponent(SysFSDirectory const& parent_directory);
|
||||
SysFSComponent();
|
||||
|
||||
RefPtr<SysFSDirectory> m_parent_directory;
|
||||
|
||||
private:
|
||||
InodeIndex m_component_index {};
|
||||
};
|
||||
|
@ -57,10 +64,9 @@ public:
|
|||
virtual ErrorOr<NonnullRefPtr<SysFSInode>> to_inode(SysFS const& sysfs_instance) const override final;
|
||||
|
||||
protected:
|
||||
SysFSDirectory() = default;
|
||||
SysFSDirectory() {};
|
||||
explicit SysFSDirectory(SysFSDirectory const& parent_directory);
|
||||
NonnullRefPtrVector<SysFSComponent> m_components;
|
||||
RefPtr<SysFSDirectory> m_parent_directory;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue