mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:48:11 +00:00
Kernel: Add distinct InodeIndex type
Use the DistinctNumeric mechanism to make InodeIndex a strongly typed integer type.
This commit is contained in:
parent
c8a90a31b6
commit
e44c1792a7
17 changed files with 63 additions and 56 deletions
|
@ -61,13 +61,13 @@ bool DevPtsFS::initialize()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned inode_index_to_pty_index(unsigned inode_index)
|
static unsigned inode_index_to_pty_index(InodeIndex inode_index)
|
||||||
{
|
{
|
||||||
ASSERT(inode_index > 1);
|
ASSERT(inode_index > 1);
|
||||||
return inode_index - 2;
|
return inode_index.value() - 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned pty_index_to_inode_index(unsigned pty_index)
|
static InodeIndex pty_index_to_inode_index(unsigned pty_index)
|
||||||
{
|
{
|
||||||
return pty_index + 2;
|
return pty_index + 2;
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ void DevPtsFS::unregister_slave_pty(SlavePTY& slave_pty)
|
||||||
s_ptys->remove(slave_pty.index());
|
s_ptys->remove(slave_pty.index());
|
||||||
}
|
}
|
||||||
|
|
||||||
DevPtsFSInode::DevPtsFSInode(DevPtsFS& fs, unsigned index, SlavePTY* pty)
|
DevPtsFSInode::DevPtsFSInode(DevPtsFS& fs, InodeIndex index, SlavePTY* pty)
|
||||||
: Inode(fs, index)
|
: Inode(fs, index)
|
||||||
{
|
{
|
||||||
if (pty)
|
if (pty)
|
||||||
|
|
|
@ -64,7 +64,7 @@ public:
|
||||||
virtual ~DevPtsFSInode() override;
|
virtual ~DevPtsFSInode() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DevPtsFSInode(DevPtsFS&, unsigned index, SlavePTY*);
|
DevPtsFSInode(DevPtsFS&, InodeIndex, SlavePTY*);
|
||||||
|
|
||||||
// ^Inode
|
// ^Inode
|
||||||
virtual ssize_t read_bytes(off_t, ssize_t, UserOrKernelBuffer& buffer, FileDescription*) const override;
|
virtual ssize_t read_bytes(off_t, ssize_t, UserOrKernelBuffer& buffer, FileDescription*) const override;
|
||||||
|
|
|
@ -46,7 +46,7 @@ static const ssize_t max_inline_symlink_length = 60;
|
||||||
|
|
||||||
struct Ext2FSDirectoryEntry {
|
struct Ext2FSDirectoryEntry {
|
||||||
String name;
|
String name;
|
||||||
Ext2FS::InodeIndex inode_index { 0 };
|
InodeIndex inode_index { 0 };
|
||||||
u8 file_type { 0 };
|
u8 file_type { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ NonnullRefPtr<Inode> Ext2FS::root_inode() const
|
||||||
return *get_inode({ fsid(), EXT2_ROOT_INO });
|
return *get_inode({ fsid(), EXT2_ROOT_INO });
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Ext2FS::find_block_containing_inode(unsigned inode, unsigned& block_index, unsigned& offset) const
|
bool Ext2FS::find_block_containing_inode(InodeIndex inode, unsigned& block_index, unsigned& offset) const
|
||||||
{
|
{
|
||||||
LOCKER(m_lock);
|
LOCKER(m_lock);
|
||||||
auto& super_block = this->super_block();
|
auto& super_block = this->super_block();
|
||||||
|
@ -185,7 +185,7 @@ bool Ext2FS::find_block_containing_inode(unsigned inode, unsigned& block_index,
|
||||||
|
|
||||||
auto& bgd = group_descriptor(group_index_from_inode(inode));
|
auto& bgd = group_descriptor(group_index_from_inode(inode));
|
||||||
|
|
||||||
offset = ((inode - 1) % inodes_per_group()) * inode_size();
|
offset = ((inode.value() - 1) % inodes_per_group()) * inode_size();
|
||||||
block_index = bgd.bg_inode_table + (offset >> EXT2_BLOCK_SIZE_BITS(&super_block));
|
block_index = bgd.bg_inode_table + (offset >> EXT2_BLOCK_SIZE_BITS(&super_block));
|
||||||
offset &= block_size() - 1;
|
offset &= block_size() - 1;
|
||||||
|
|
||||||
|
@ -620,7 +620,7 @@ void Ext2FS::flush_writes()
|
||||||
uncache_inode(index);
|
uncache_inode(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ext2FSInode::Ext2FSInode(Ext2FS& fs, unsigned index)
|
Ext2FSInode::Ext2FSInode(Ext2FS& fs, InodeIndex index)
|
||||||
: Inode(fs, index)
|
: Inode(fs, index)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -728,7 +728,7 @@ ssize_t Ext2FSInode::read_bytes(off_t offset, ssize_t count, UserOrKernelBuffer&
|
||||||
m_block_list = fs().block_list_for_inode(m_raw_inode);
|
m_block_list = fs().block_list_for_inode(m_raw_inode);
|
||||||
|
|
||||||
if (m_block_list.is_empty()) {
|
if (m_block_list.is_empty()) {
|
||||||
klog() << "ext2fs: read_bytes: empty block list for inode " << index();
|
dmesgln("Ext2FS: read_bytes: empty block list for inode {}", index());
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -990,7 +990,7 @@ KResult Ext2FSInode::write_directory(const Vector<Ext2FSDirectoryEntry>& entries
|
||||||
|
|
||||||
dbgln_if(EXT2_DEBUG, "* Inode: {}, name_len: {}, rec_len: {}, file_type: {}, name: {}", entry.inode_index, u16(entry.name.length()), u16(record_length), u8(entry.file_type), entry.name);
|
dbgln_if(EXT2_DEBUG, "* Inode: {}, name_len: {}, rec_len: {}, file_type: {}, name: {}", entry.inode_index, u16(entry.name.length()), u16(record_length), u8(entry.file_type), entry.name);
|
||||||
|
|
||||||
stream << u32(entry.inode_index);
|
stream << u32(entry.inode_index.value());
|
||||||
stream << u16(record_length);
|
stream << u16(record_length);
|
||||||
stream << u8(entry.name.length());
|
stream << u8(entry.name.length());
|
||||||
stream << u8(entry.file_type);
|
stream << u8(entry.file_type);
|
||||||
|
@ -1121,7 +1121,7 @@ unsigned Ext2FS::blocks_per_group() const
|
||||||
return EXT2_BLOCKS_PER_GROUP(&super_block());
|
return EXT2_BLOCKS_PER_GROUP(&super_block());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Ext2FS::write_ext2_inode(unsigned inode, const ext2_inode& e2inode)
|
bool Ext2FS::write_ext2_inode(InodeIndex inode, const ext2_inode& e2inode)
|
||||||
{
|
{
|
||||||
LOCKER(m_lock);
|
LOCKER(m_lock);
|
||||||
unsigned block_index;
|
unsigned block_index;
|
||||||
|
@ -1189,7 +1189,7 @@ Vector<Ext2FS::BlockIndex> Ext2FS::allocate_blocks(GroupIndex preferred_group_in
|
||||||
return blocks;
|
return blocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned Ext2FS::find_a_free_inode(GroupIndex preferred_group)
|
InodeIndex Ext2FS::find_a_free_inode(GroupIndex preferred_group)
|
||||||
{
|
{
|
||||||
LOCKER(m_lock);
|
LOCKER(m_lock);
|
||||||
dbgln_if(EXT2_DEBUG, "Ext2FS: find_a_free_inode(preferred_group: {})", preferred_group);
|
dbgln_if(EXT2_DEBUG, "Ext2FS: find_a_free_inode(preferred_group: {})", preferred_group);
|
||||||
|
@ -1221,16 +1221,16 @@ unsigned Ext2FS::find_a_free_inode(GroupIndex preferred_group)
|
||||||
|
|
||||||
auto& bgd = group_descriptor(group_index);
|
auto& bgd = group_descriptor(group_index);
|
||||||
unsigned inodes_in_group = min(inodes_per_group(), super_block().s_inodes_count);
|
unsigned inodes_in_group = min(inodes_per_group(), super_block().s_inodes_count);
|
||||||
unsigned first_free_inode_in_group = 0;
|
InodeIndex first_free_inode_in_group = 0;
|
||||||
|
|
||||||
unsigned first_inode_in_group = (group_index - 1) * inodes_per_group() + 1;
|
InodeIndex first_inode_in_group = (group_index - 1) * inodes_per_group() + 1;
|
||||||
|
|
||||||
auto& cached_bitmap = get_bitmap_block(bgd.bg_inode_bitmap);
|
auto& cached_bitmap = get_bitmap_block(bgd.bg_inode_bitmap);
|
||||||
auto inode_bitmap = Bitmap::wrap(cached_bitmap.buffer.data(), inodes_in_group);
|
auto inode_bitmap = Bitmap::wrap(cached_bitmap.buffer.data(), inodes_in_group);
|
||||||
for (size_t i = 0; i < inode_bitmap.size(); ++i) {
|
for (size_t i = 0; i < inode_bitmap.size(); ++i) {
|
||||||
if (inode_bitmap.get(i))
|
if (inode_bitmap.get(i))
|
||||||
continue;
|
continue;
|
||||||
first_free_inode_in_group = first_inode_in_group + i;
|
first_free_inode_in_group = InodeIndex(first_inode_in_group.value() + i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1239,7 +1239,7 @@ unsigned Ext2FS::find_a_free_inode(GroupIndex preferred_group)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned inode = first_free_inode_in_group;
|
InodeIndex inode = first_free_inode_in_group;
|
||||||
dbgln_if(EXT2_DEBUG, "Ext2FS: found suitable inode {}", inode);
|
dbgln_if(EXT2_DEBUG, "Ext2FS: found suitable inode {}", inode);
|
||||||
|
|
||||||
ASSERT(get_inode_allocation_state(inode) == false);
|
ASSERT(get_inode_allocation_state(inode) == false);
|
||||||
|
@ -1253,11 +1253,11 @@ Ext2FS::GroupIndex Ext2FS::group_index_from_block_index(BlockIndex block_index)
|
||||||
return (block_index - 1) / blocks_per_group() + 1;
|
return (block_index - 1) / blocks_per_group() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned Ext2FS::group_index_from_inode(unsigned inode) const
|
unsigned Ext2FS::group_index_from_inode(InodeIndex inode) const
|
||||||
{
|
{
|
||||||
if (!inode)
|
if (!inode)
|
||||||
return 0;
|
return 0;
|
||||||
return (inode - 1) / inodes_per_group() + 1;
|
return (inode.value() - 1) / inodes_per_group() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Ext2FS::get_inode_allocation_state(InodeIndex index) const
|
bool Ext2FS::get_inode_allocation_state(InodeIndex index) const
|
||||||
|
@ -1267,7 +1267,7 @@ bool Ext2FS::get_inode_allocation_state(InodeIndex index) const
|
||||||
return true;
|
return true;
|
||||||
unsigned group_index = group_index_from_inode(index);
|
unsigned group_index = group_index_from_inode(index);
|
||||||
auto& bgd = group_descriptor(group_index);
|
auto& bgd = group_descriptor(group_index);
|
||||||
unsigned index_in_group = index - ((group_index - 1) * inodes_per_group());
|
unsigned index_in_group = index.value() - ((group_index - 1) * inodes_per_group());
|
||||||
unsigned bit_index = (index_in_group - 1) % inodes_per_group();
|
unsigned bit_index = (index_in_group - 1) % inodes_per_group();
|
||||||
|
|
||||||
auto& cached_bitmap = const_cast<Ext2FS&>(*this).get_bitmap_block(bgd.bg_inode_bitmap);
|
auto& cached_bitmap = const_cast<Ext2FS&>(*this).get_bitmap_block(bgd.bg_inode_bitmap);
|
||||||
|
@ -1279,7 +1279,7 @@ bool Ext2FS::set_inode_allocation_state(InodeIndex inode_index, bool new_state)
|
||||||
LOCKER(m_lock);
|
LOCKER(m_lock);
|
||||||
unsigned group_index = group_index_from_inode(inode_index);
|
unsigned group_index = group_index_from_inode(inode_index);
|
||||||
auto& bgd = group_descriptor(group_index);
|
auto& bgd = group_descriptor(group_index);
|
||||||
unsigned index_in_group = inode_index - ((group_index - 1) * inodes_per_group());
|
unsigned index_in_group = inode_index.value() - ((group_index - 1) * inodes_per_group());
|
||||||
unsigned bit_index = (index_in_group - 1) % inodes_per_group();
|
unsigned bit_index = (index_in_group - 1) % inodes_per_group();
|
||||||
|
|
||||||
auto& cached_bitmap = get_bitmap_block(bgd.bg_inode_bitmap);
|
auto& cached_bitmap = get_bitmap_block(bgd.bg_inode_bitmap);
|
||||||
|
@ -1473,7 +1473,7 @@ bool Ext2FSInode::populate_lookup_cache() const
|
||||||
LOCKER(m_lock);
|
LOCKER(m_lock);
|
||||||
if (!m_lookup_cache.is_empty())
|
if (!m_lookup_cache.is_empty())
|
||||||
return true;
|
return true;
|
||||||
HashMap<String, unsigned> children;
|
HashMap<String, InodeIndex> children;
|
||||||
|
|
||||||
KResult result = traverse_as_directory([&children](auto& entry) {
|
KResult result = traverse_as_directory([&children](auto& entry) {
|
||||||
children.set(entry.name, entry.inode.index());
|
children.set(entry.name, entry.inode.index());
|
||||||
|
|
|
@ -83,14 +83,12 @@ private:
|
||||||
bool populate_lookup_cache() const;
|
bool populate_lookup_cache() const;
|
||||||
KResult resize(u64);
|
KResult resize(u64);
|
||||||
|
|
||||||
static u8 file_type_for_directory_entry(const ext2_dir_entry_2&);
|
|
||||||
|
|
||||||
Ext2FS& fs();
|
Ext2FS& fs();
|
||||||
const Ext2FS& fs() const;
|
const Ext2FS& fs() const;
|
||||||
Ext2FSInode(Ext2FS&, unsigned index);
|
Ext2FSInode(Ext2FS&, InodeIndex);
|
||||||
|
|
||||||
mutable Vector<unsigned> m_block_list;
|
mutable Vector<unsigned> m_block_list;
|
||||||
mutable HashMap<String, unsigned> m_lookup_cache;
|
mutable HashMap<String, InodeIndex> m_lookup_cache;
|
||||||
ext2_inode m_raw_inode;
|
ext2_inode m_raw_inode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -98,8 +96,6 @@ class Ext2FS final : public BlockBasedFS {
|
||||||
friend class Ext2FSInode;
|
friend class Ext2FSInode;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using InodeIndex = u32;
|
|
||||||
|
|
||||||
static NonnullRefPtr<Ext2FS> create(FileDescription&);
|
static NonnullRefPtr<Ext2FS> create(FileDescription&);
|
||||||
|
|
||||||
virtual ~Ext2FS() override;
|
virtual ~Ext2FS() override;
|
||||||
|
@ -132,7 +128,7 @@ private:
|
||||||
unsigned inode_size() const;
|
unsigned inode_size() const;
|
||||||
|
|
||||||
bool write_ext2_inode(InodeIndex, const ext2_inode&);
|
bool write_ext2_inode(InodeIndex, const ext2_inode&);
|
||||||
bool find_block_containing_inode(InodeIndex inode, BlockIndex& block_index, unsigned& offset) const;
|
bool find_block_containing_inode(InodeIndex, BlockIndex& block_index, unsigned& offset) const;
|
||||||
|
|
||||||
bool flush_super_block();
|
bool flush_super_block();
|
||||||
|
|
||||||
|
|
|
@ -227,7 +227,7 @@ ssize_t FileDescription::get_dir_entries(UserOrKernelBuffer& buffer, ssize_t siz
|
||||||
OutputMemoryStream stream { temp_buffer };
|
OutputMemoryStream stream { temp_buffer };
|
||||||
|
|
||||||
KResult result = VFS::the().traverse_directory_inode(*m_inode, [&stream, this](auto& entry) {
|
KResult result = VFS::the().traverse_directory_inode(*m_inode, [&stream, this](auto& entry) {
|
||||||
stream << (u32)entry.inode.index();
|
stream << (u32)entry.inode.index().value();
|
||||||
stream << m_inode->fs().internal_file_type_to_directory_entry_type(entry);
|
stream << m_inode->fs().internal_file_type_to_directory_entry_type(entry);
|
||||||
stream << (u32)entry.name.length();
|
stream << (u32)entry.name.length();
|
||||||
stream << entry.name.bytes();
|
stream << entry.name.bytes();
|
||||||
|
|
|
@ -116,7 +116,7 @@ namespace AK {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Traits<Kernel::InodeIdentifier> : public GenericTraits<Kernel::InodeIdentifier> {
|
struct Traits<Kernel::InodeIdentifier> : public GenericTraits<Kernel::InodeIdentifier> {
|
||||||
static unsigned hash(const Kernel::InodeIdentifier& inode) { return pair_int_hash(inode.fsid(), inode.index()); }
|
static unsigned hash(const Kernel::InodeIdentifier& inode) { return pair_int_hash(inode.fsid(), inode.index().value()); }
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,7 +116,7 @@ KResultOr<NonnullRefPtr<Custody>> Inode::resolve_as_link(Custody& base, RefPtr<C
|
||||||
return VFS::the().resolve_path(path, base, out_parent, options, symlink_recursion_level);
|
return VFS::the().resolve_path(path, base, out_parent, options, symlink_recursion_level);
|
||||||
}
|
}
|
||||||
|
|
||||||
Inode::Inode(FS& fs, unsigned index)
|
Inode::Inode(FS& fs, InodeIndex index)
|
||||||
: m_fs(fs)
|
: m_fs(fs)
|
||||||
, m_index(index)
|
, m_index(index)
|
||||||
{
|
{
|
||||||
|
|
|
@ -56,7 +56,7 @@ public:
|
||||||
FS& fs() { return m_fs; }
|
FS& fs() { return m_fs; }
|
||||||
const FS& fs() const { return m_fs; }
|
const FS& fs() const { return m_fs; }
|
||||||
unsigned fsid() const { return m_fs.fsid(); }
|
unsigned fsid() const { return m_fs.fsid(); }
|
||||||
unsigned index() const { return m_index; }
|
InodeIndex index() const { return m_index; }
|
||||||
|
|
||||||
size_t size() const { return metadata().size; }
|
size_t size() const { return metadata().size; }
|
||||||
bool is_symlink() const { return metadata().is_symlink(); }
|
bool is_symlink() const { return metadata().is_symlink(); }
|
||||||
|
@ -127,7 +127,7 @@ public:
|
||||||
static SpinLock<u32>& all_inodes_lock();
|
static SpinLock<u32>& all_inodes_lock();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Inode(FS& fs, unsigned index);
|
Inode(FS& fs, InodeIndex);
|
||||||
void set_metadata_dirty(bool);
|
void set_metadata_dirty(bool);
|
||||||
void inode_contents_changed(off_t, ssize_t, const UserOrKernelBuffer&);
|
void inode_contents_changed(off_t, ssize_t, const UserOrKernelBuffer&);
|
||||||
void inode_size_changed(size_t old_size, size_t new_size);
|
void inode_size_changed(size_t old_size, size_t new_size);
|
||||||
|
@ -140,7 +140,7 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FS& m_fs;
|
FS& m_fs;
|
||||||
unsigned m_index { 0 };
|
InodeIndex m_index { 0 };
|
||||||
WeakPtr<SharedInodeVMObject> m_shared_vmobject;
|
WeakPtr<SharedInodeVMObject> m_shared_vmobject;
|
||||||
RefPtr<LocalSocket> m_socket;
|
RefPtr<LocalSocket> m_socket;
|
||||||
HashTable<InodeWatcher*> m_watchers;
|
HashTable<InodeWatcher*> m_watchers;
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/ByteBuffer.h>
|
#include <AK/ByteBuffer.h>
|
||||||
|
#include <AK/DistinctNumeric.h>
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
|
|
||||||
|
@ -35,10 +36,12 @@ namespace Kernel {
|
||||||
class FS;
|
class FS;
|
||||||
struct InodeMetadata;
|
struct InodeMetadata;
|
||||||
|
|
||||||
|
TYPEDEF_DISTINCT_ORDERED_ID(unsigned, InodeIndex);
|
||||||
|
|
||||||
class InodeIdentifier {
|
class InodeIdentifier {
|
||||||
public:
|
public:
|
||||||
InodeIdentifier() { }
|
InodeIdentifier() { }
|
||||||
InodeIdentifier(u32 fsid, u32 inode)
|
InodeIdentifier(u32 fsid, InodeIndex inode)
|
||||||
: m_fsid(fsid)
|
: m_fsid(fsid)
|
||||||
, m_index(inode)
|
, m_index(inode)
|
||||||
{
|
{
|
||||||
|
@ -47,7 +50,7 @@ public:
|
||||||
bool is_valid() const { return m_fsid != 0 && m_index != 0; }
|
bool is_valid() const { return m_fsid != 0 && m_index != 0; }
|
||||||
|
|
||||||
u32 fsid() const { return m_fsid; }
|
u32 fsid() const { return m_fsid; }
|
||||||
u32 index() const { return m_index; }
|
InodeIndex index() const { return m_index; }
|
||||||
|
|
||||||
FS* fs();
|
FS* fs();
|
||||||
const FS* fs() const;
|
const FS* fs() const;
|
||||||
|
@ -66,12 +69,12 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
u32 m_fsid { 0 };
|
u32 m_fsid { 0 };
|
||||||
u32 m_index { 0 };
|
InodeIndex m_index { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
inline const LogStream& operator<<(const LogStream& stream, const InodeIdentifier& value)
|
inline const LogStream& operator<<(const LogStream& stream, const InodeIdentifier& value)
|
||||||
{
|
{
|
||||||
stream << value.fsid() << ':' << value.index();
|
stream << value.fsid() << ':' << value.index().value();
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,3 +87,11 @@ struct AK::Formatter<Kernel::InodeIdentifier> : AK::Formatter<FormatString> {
|
||||||
return AK::Formatter<FormatString>::format(builder, "{}:{}", value.fsid(), value.index());
|
return AK::Formatter<FormatString>::format(builder, "{}:{}", value.fsid(), value.index());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct AK::Formatter<Kernel::InodeIndex> : AK::Formatter<FormatString> {
|
||||||
|
void format(FormatBuilder& builder, Kernel::InodeIndex value)
|
||||||
|
{
|
||||||
|
return AK::Formatter<FormatString>::format(builder, "{}", value.value());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
@ -108,7 +108,7 @@ struct InodeMetadata {
|
||||||
if (!is_valid())
|
if (!is_valid())
|
||||||
return EIO;
|
return EIO;
|
||||||
buffer.st_rdev = encoded_device(major_device, minor_device);
|
buffer.st_rdev = encoded_device(major_device, minor_device);
|
||||||
buffer.st_ino = inode.index();
|
buffer.st_ino = inode.index().value();
|
||||||
buffer.st_mode = mode;
|
buffer.st_mode = mode;
|
||||||
buffer.st_nlink = link_count;
|
buffer.st_nlink = link_count;
|
||||||
buffer.st_uid = uid;
|
buffer.st_uid = uid;
|
||||||
|
|
|
@ -104,14 +104,14 @@ void InodeWatcher::notify_inode_event(Badge<Inode>, InodeWatcherEvent::Type even
|
||||||
void InodeWatcher::notify_child_added(Badge<Inode>, const InodeIdentifier& child_id)
|
void InodeWatcher::notify_child_added(Badge<Inode>, const InodeIdentifier& child_id)
|
||||||
{
|
{
|
||||||
LOCKER(m_lock);
|
LOCKER(m_lock);
|
||||||
m_queue.enqueue({ InodeWatcherEvent::Type::ChildAdded, child_id.index() });
|
m_queue.enqueue({ InodeWatcherEvent::Type::ChildAdded, child_id.index().value() });
|
||||||
evaluate_block_conditions();
|
evaluate_block_conditions();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InodeWatcher::notify_child_removed(Badge<Inode>, const InodeIdentifier& child_id)
|
void InodeWatcher::notify_child_removed(Badge<Inode>, const InodeIdentifier& child_id)
|
||||||
{
|
{
|
||||||
LOCKER(m_lock);
|
LOCKER(m_lock);
|
||||||
m_queue.enqueue({ InodeWatcherEvent::Type::ChildRemoved, child_id.index() });
|
m_queue.enqueue({ InodeWatcherEvent::Type::ChildRemoved, child_id.index().value() });
|
||||||
evaluate_block_conditions();
|
evaluate_block_conditions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -171,7 +171,7 @@ class Plan9FSInode final : public Inode {
|
||||||
public:
|
public:
|
||||||
virtual ~Plan9FSInode() override;
|
virtual ~Plan9FSInode() override;
|
||||||
|
|
||||||
u32 fid() const { return index(); }
|
u32 fid() const { return index().value(); }
|
||||||
|
|
||||||
// ^Inode
|
// ^Inode
|
||||||
virtual InodeMetadata metadata() const override;
|
virtual InodeMetadata metadata() const override;
|
||||||
|
|
|
@ -128,7 +128,7 @@ enum ProcFileType {
|
||||||
|
|
||||||
static inline ProcessID to_pid(const InodeIdentifier& identifier)
|
static inline ProcessID to_pid(const InodeIdentifier& identifier)
|
||||||
{
|
{
|
||||||
return identifier.index() >> 16u;
|
return identifier.index().value() >> 16u;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline ThreadID to_tid(const InodeIdentifier& identifier)
|
static inline ThreadID to_tid(const InodeIdentifier& identifier)
|
||||||
|
@ -139,25 +139,25 @@ static inline ThreadID to_tid(const InodeIdentifier& identifier)
|
||||||
|
|
||||||
static inline ProcParentDirectory to_proc_parent_directory(const InodeIdentifier& identifier)
|
static inline ProcParentDirectory to_proc_parent_directory(const InodeIdentifier& identifier)
|
||||||
{
|
{
|
||||||
return (ProcParentDirectory)((identifier.index() >> 12) & 0xf);
|
return (ProcParentDirectory)((identifier.index().value() >> 12) & 0xf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline ProcFileType to_proc_file_type(const InodeIdentifier& identifier)
|
static inline ProcFileType to_proc_file_type(const InodeIdentifier& identifier)
|
||||||
{
|
{
|
||||||
return (ProcFileType)(identifier.index() & 0xff);
|
return (ProcFileType)(identifier.index().value() & 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int to_fd(const InodeIdentifier& identifier)
|
static inline int to_fd(const InodeIdentifier& identifier)
|
||||||
{
|
{
|
||||||
ASSERT(to_proc_parent_directory(identifier) == PDI_PID_fd);
|
ASSERT(to_proc_parent_directory(identifier) == PDI_PID_fd);
|
||||||
return (identifier.index() & 0xff) - FI_MaxStaticFileIndex;
|
return (identifier.index().value() & 0xff) - FI_MaxStaticFileIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline size_t to_sys_index(const InodeIdentifier& identifier)
|
static inline size_t to_sys_index(const InodeIdentifier& identifier)
|
||||||
{
|
{
|
||||||
ASSERT(to_proc_parent_directory(identifier) == PDI_Root_sys);
|
ASSERT(to_proc_parent_directory(identifier) == PDI_Root_sys);
|
||||||
ASSERT(to_proc_file_type(identifier) == FI_Root_sys_variable);
|
ASSERT(to_proc_file_type(identifier) == FI_Root_sys_variable);
|
||||||
return identifier.index() >> 16u;
|
return identifier.index().value() >> 16u;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline InodeIdentifier to_identifier(unsigned fsid, ProcParentDirectory parent, ProcessID pid, ProcFileType proc_file_type)
|
static inline InodeIdentifier to_identifier(unsigned fsid, ProcParentDirectory parent, ProcessID pid, ProcFileType proc_file_type)
|
||||||
|
@ -1020,7 +1020,7 @@ RefPtr<Inode> ProcFS::get_inode(InodeIdentifier inode_id) const
|
||||||
return m_root_inode;
|
return m_root_inode;
|
||||||
|
|
||||||
LOCKER(m_inodes_lock);
|
LOCKER(m_inodes_lock);
|
||||||
auto it = m_inodes.find(inode_id.index());
|
auto it = m_inodes.find(inode_id.index().value());
|
||||||
if (it != m_inodes.end()) {
|
if (it != m_inodes.end()) {
|
||||||
// It's possible that the ProcFSInode ref count was dropped to 0 or
|
// It's possible that the ProcFSInode ref count was dropped to 0 or
|
||||||
// the ~ProcFSInode destructor is even running already, but blocked
|
// the ~ProcFSInode destructor is even running already, but blocked
|
||||||
|
@ -1032,12 +1032,12 @@ RefPtr<Inode> ProcFS::get_inode(InodeIdentifier inode_id) const
|
||||||
// We couldn't ref it, so just create a new one and replace the entry
|
// We couldn't ref it, so just create a new one and replace the entry
|
||||||
}
|
}
|
||||||
auto inode = adopt(*new ProcFSInode(const_cast<ProcFS&>(*this), inode_id.index()));
|
auto inode = adopt(*new ProcFSInode(const_cast<ProcFS&>(*this), inode_id.index()));
|
||||||
auto result = m_inodes.set(inode_id.index(), inode.ptr());
|
auto result = m_inodes.set(inode_id.index().value(), inode.ptr());
|
||||||
ASSERT(result == ((it == m_inodes.end()) ? AK::HashSetResult::InsertedNewEntry : AK::HashSetResult::ReplacedExistingEntry));
|
ASSERT(result == ((it == m_inodes.end()) ? AK::HashSetResult::InsertedNewEntry : AK::HashSetResult::ReplacedExistingEntry));
|
||||||
return inode;
|
return inode;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProcFSInode::ProcFSInode(ProcFS& fs, unsigned index)
|
ProcFSInode::ProcFSInode(ProcFS& fs, InodeIndex index)
|
||||||
: Inode(fs, index)
|
: Inode(fs, index)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -1045,7 +1045,7 @@ ProcFSInode::ProcFSInode(ProcFS& fs, unsigned index)
|
||||||
ProcFSInode::~ProcFSInode()
|
ProcFSInode::~ProcFSInode()
|
||||||
{
|
{
|
||||||
LOCKER(fs().m_inodes_lock);
|
LOCKER(fs().m_inodes_lock);
|
||||||
auto it = fs().m_inodes.find(index());
|
auto it = fs().m_inodes.find(index().value());
|
||||||
if (it != fs().m_inodes.end() && it->value == this)
|
if (it != fs().m_inodes.end() && it->value == this)
|
||||||
fs().m_inodes.remove(it);
|
fs().m_inodes.remove(it);
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,7 +116,7 @@ private:
|
||||||
|
|
||||||
ProcFS& fs() { return static_cast<ProcFS&>(Inode::fs()); }
|
ProcFS& fs() { return static_cast<ProcFS&>(Inode::fs()); }
|
||||||
const ProcFS& fs() const { return static_cast<const ProcFS&>(Inode::fs()); }
|
const ProcFS& fs() const { return static_cast<const ProcFS&>(Inode::fs()); }
|
||||||
ProcFSInode(ProcFS&, unsigned index);
|
ProcFSInode(ProcFS&, InodeIndex);
|
||||||
};
|
};
|
||||||
|
|
||||||
class ProcFSProxyInode final : public Inode {
|
class ProcFSProxyInode final : public Inode {
|
||||||
|
|
|
@ -62,7 +62,7 @@ void TmpFS::register_inode(TmpFSInode& inode)
|
||||||
LOCKER(m_lock);
|
LOCKER(m_lock);
|
||||||
ASSERT(inode.identifier().fsid() == fsid());
|
ASSERT(inode.identifier().fsid() == fsid());
|
||||||
|
|
||||||
unsigned index = inode.identifier().index();
|
auto index = inode.identifier().index();
|
||||||
m_inodes.set(index, inode);
|
m_inodes.set(index, inode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ private:
|
||||||
|
|
||||||
RefPtr<TmpFSInode> m_root_inode;
|
RefPtr<TmpFSInode> m_root_inode;
|
||||||
|
|
||||||
HashMap<unsigned, NonnullRefPtr<TmpFSInode>> m_inodes;
|
HashMap<InodeIndex, NonnullRefPtr<TmpFSInode>> m_inodes;
|
||||||
RefPtr<Inode> get_inode(InodeIdentifier identifier) const;
|
RefPtr<Inode> get_inode(InodeIdentifier identifier) const;
|
||||||
void register_inode(TmpFSInode&);
|
void register_inode(TmpFSInode&);
|
||||||
void unregister_inode(InodeIdentifier);
|
void unregister_inode(InodeIdentifier);
|
||||||
|
|
|
@ -146,7 +146,7 @@ bool VFS::mount_root(FS& file_system)
|
||||||
|
|
||||||
auto root_inode = file_system.root_inode();
|
auto root_inode = file_system.root_inode();
|
||||||
if (!root_inode->is_directory()) {
|
if (!root_inode->is_directory()) {
|
||||||
klog() << "VFS: root inode (" << String::format("%02u", file_system.fsid()) << ":" << String::format("%08u", root_inode->index()) << ") for / is not a directory :(";
|
klog() << "VFS: root inode (" << String::format("%02u", file_system.fsid()) << ":" << String::format("%08u", root_inode->index().value()) << ") for / is not a directory :(";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue