mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-06 02:55:49 +03:00
Kernel: Add callback on ".." directory entry for a TmpFS root directory
This commit is contained in:
parent
5ee1758f46
commit
6a555af1f1
Notes:
sideshowbarker
2024-07-17 07:20:49 +09:00
Author: https://github.com/supercomputer7 Commit: https://github.com/SerenityOS/serenity/commit/6a555af1f1 Pull-request: https://github.com/SerenityOS/serenity/pull/16300 Reviewed-by: https://github.com/ADKaster ✅
@ -32,7 +32,9 @@ private:
|
||||
|
||||
LockRefPtr<TmpFSInode> m_root_inode;
|
||||
|
||||
unsigned m_next_inode_index { 1 };
|
||||
// NOTE: We start by assigning InodeIndex of 2, because 0 is invalid and 1
|
||||
// is reserved for the root directory inode.
|
||||
unsigned m_next_inode_index { 2 };
|
||||
unsigned next_inode_index();
|
||||
};
|
||||
|
||||
|
@ -18,6 +18,18 @@ TmpFSInode::TmpFSInode(TmpFS& fs, InodeMetadata const& metadata, LockWeakPtr<Tmp
|
||||
m_metadata.inode = identifier();
|
||||
}
|
||||
|
||||
TmpFSInode::TmpFSInode(TmpFS& fs)
|
||||
: Inode(fs, 1)
|
||||
, m_root_directory_inode(true)
|
||||
{
|
||||
auto now = kgettimeofday();
|
||||
m_metadata.inode = identifier();
|
||||
m_metadata.atime = now;
|
||||
m_metadata.ctime = now;
|
||||
m_metadata.mtime = now;
|
||||
m_metadata.mode = S_IFDIR | S_ISVTX | 0777;
|
||||
}
|
||||
|
||||
TmpFSInode::~TmpFSInode() = default;
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<TmpFSInode>> TmpFSInode::try_create(TmpFS& fs, InodeMetadata const& metadata, LockWeakPtr<TmpFSInode> parent)
|
||||
@ -27,13 +39,7 @@ ErrorOr<NonnullLockRefPtr<TmpFSInode>> TmpFSInode::try_create(TmpFS& fs, InodeMe
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<TmpFSInode>> TmpFSInode::try_create_root(TmpFS& fs)
|
||||
{
|
||||
InodeMetadata metadata;
|
||||
auto now = kgettimeofday();
|
||||
metadata.atime = now;
|
||||
metadata.ctime = now;
|
||||
metadata.mtime = now;
|
||||
metadata.mode = S_IFDIR | S_ISVTX | 0777;
|
||||
return try_create(fs, metadata, {});
|
||||
return adopt_nonnull_lock_ref_or_enomem(new (nothrow) TmpFSInode(fs));
|
||||
}
|
||||
|
||||
InodeMetadata TmpFSInode::metadata() const
|
||||
@ -51,8 +57,11 @@ ErrorOr<void> TmpFSInode::traverse_as_directory(Function<ErrorOr<void>(FileSyste
|
||||
return ENOTDIR;
|
||||
|
||||
TRY(callback({ "."sv, identifier(), 0 }));
|
||||
if (auto parent = m_parent.strong_ref())
|
||||
if (m_root_directory_inode) {
|
||||
TRY(callback({ ".."sv, identifier(), 0 }));
|
||||
} else if (auto parent = m_parent.strong_ref()) {
|
||||
TRY(callback({ ".."sv, parent->identifier(), 0 }));
|
||||
}
|
||||
|
||||
for (auto& child : m_children) {
|
||||
TRY(callback({ child.name->view(), child.inode->identifier(), 0 }));
|
||||
|
@ -38,6 +38,7 @@ public:
|
||||
|
||||
private:
|
||||
TmpFSInode(TmpFS& fs, InodeMetadata const& metadata, LockWeakPtr<TmpFSInode> parent);
|
||||
explicit TmpFSInode(TmpFS& fs);
|
||||
static ErrorOr<NonnullLockRefPtr<TmpFSInode>> try_create(TmpFS&, InodeMetadata const& metadata, LockWeakPtr<TmpFSInode> parent);
|
||||
static ErrorOr<NonnullLockRefPtr<TmpFSInode>> try_create_root(TmpFS&);
|
||||
|
||||
@ -84,6 +85,8 @@ private:
|
||||
NonnullLockRefPtr<Memory::AnonymousVMObject> m_content_buffer_vmobject;
|
||||
};
|
||||
|
||||
bool const m_root_directory_inode { false };
|
||||
|
||||
DataBlock::List m_blocks;
|
||||
Child::List m_children;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user