mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:37:35 +00:00
Kernel: Use DistinctNumeric for filesystem ID's
This patch adds the FileSystemID type, which is a distinct u32. This prevents accidental conversion from arbitrary integers.
This commit is contained in:
parent
7c57961c61
commit
e08d213830
18 changed files with 36 additions and 35 deletions
|
@ -16,9 +16,9 @@
|
|||
namespace Kernel {
|
||||
|
||||
static u32 s_lastFileSystemID;
|
||||
static Singleton<HashMap<u32, FileSystem*>> s_file_system_map;
|
||||
static Singleton<HashMap<FileSystemID, FileSystem*>> s_file_system_map;
|
||||
|
||||
static HashMap<u32, FileSystem*>& all_file_systems()
|
||||
static HashMap<FileSystemID, FileSystem*>& all_file_systems()
|
||||
{
|
||||
return *s_file_system_map;
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ FileSystem::~FileSystem()
|
|||
s_file_system_map->remove(m_fsid);
|
||||
}
|
||||
|
||||
FileSystem* FileSystem::from_fsid(u32 id)
|
||||
FileSystem* FileSystem::from_fsid(FileSystemID id)
|
||||
{
|
||||
auto it = all_file_systems().find(id);
|
||||
if (it != all_file_systems().end())
|
||||
|
|
|
@ -26,8 +26,8 @@ class FileSystem : public RefCounted<FileSystem> {
|
|||
public:
|
||||
virtual ~FileSystem();
|
||||
|
||||
unsigned fsid() const { return m_fsid; }
|
||||
static FileSystem* from_fsid(u32);
|
||||
FileSystemID fsid() const { return m_fsid; }
|
||||
static FileSystem* from_fsid(FileSystemID);
|
||||
static void sync();
|
||||
static void lock_all();
|
||||
|
||||
|
@ -72,7 +72,7 @@ protected:
|
|||
mutable Mutex m_lock { "FS" };
|
||||
|
||||
private:
|
||||
unsigned m_fsid { 0 };
|
||||
FileSystemID m_fsid;
|
||||
u64 m_block_size { 0 };
|
||||
size_t m_fragment_size { 0 };
|
||||
bool m_readonly { false };
|
||||
|
@ -94,7 +94,7 @@ namespace AK {
|
|||
|
||||
template<>
|
||||
struct Traits<Kernel::InodeIdentifier> : public GenericTraits<Kernel::InodeIdentifier> {
|
||||
static unsigned hash(const Kernel::InodeIdentifier& inode) { return pair_int_hash(inode.fsid(), inode.index().value()); }
|
||||
static unsigned hash(const Kernel::InodeIdentifier& inode) { return pair_int_hash(inode.fsid().value(), inode.index().value()); }
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ public:
|
|||
|
||||
FileSystem& fs() { return m_file_system; }
|
||||
FileSystem const& fs() const { return m_file_system; }
|
||||
unsigned fsid() const { return m_file_system.fsid(); }
|
||||
FileSystemID fsid() const { return m_file_system.fsid(); }
|
||||
InodeIndex index() const { return m_index; }
|
||||
|
||||
size_t size() const { return metadata().size; }
|
||||
|
|
|
@ -15,12 +15,13 @@ namespace Kernel {
|
|||
class FileSystem;
|
||||
struct InodeMetadata;
|
||||
|
||||
TYPEDEF_DISTINCT_ORDERED_ID(u32, FileSystemID);
|
||||
TYPEDEF_DISTINCT_ORDERED_ID(u64, InodeIndex);
|
||||
|
||||
class InodeIdentifier {
|
||||
public:
|
||||
InodeIdentifier() = default;
|
||||
InodeIdentifier(u32 fsid, InodeIndex inode)
|
||||
InodeIdentifier(FileSystemID fsid, InodeIndex inode)
|
||||
: m_fsid(fsid)
|
||||
, m_index(inode)
|
||||
{
|
||||
|
@ -28,7 +29,7 @@ public:
|
|||
|
||||
bool is_valid() const { return m_fsid != 0 && m_index != 0; }
|
||||
|
||||
u32 fsid() const { return m_fsid; }
|
||||
FileSystemID fsid() const { return m_fsid; }
|
||||
InodeIndex index() const { return m_index; }
|
||||
|
||||
FileSystem* fs();
|
||||
|
@ -45,7 +46,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
u32 m_fsid { 0 };
|
||||
FileSystemID m_fsid { 0 };
|
||||
InodeIndex m_index { 0 };
|
||||
};
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ NonnullRefPtr<SysFSRootDirectory> SysFSRootDirectory::create()
|
|||
return adopt_ref(*new (nothrow) SysFSRootDirectory);
|
||||
}
|
||||
|
||||
ErrorOr<void> SysFSRootDirectory::traverse_as_directory(unsigned fsid, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
|
||||
ErrorOr<void> SysFSRootDirectory::traverse_as_directory(FileSystemID fsid, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
|
||||
{
|
||||
MutexLocker locker(SysFSComponentRegistry::the().get_lock());
|
||||
TRY(callback({ ".", { fsid, component_index() }, 0 }));
|
||||
|
|
|
@ -19,7 +19,7 @@ class SysFSRootDirectory final : public SysFSDirectory {
|
|||
|
||||
public:
|
||||
static NonnullRefPtr<SysFSRootDirectory> create();
|
||||
virtual ErrorOr<void> traverse_as_directory(unsigned, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
|
||||
virtual ErrorOr<void> traverse_as_directory(FileSystemID, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
|
||||
|
||||
private:
|
||||
SysFSRootDirectory();
|
||||
|
@ -53,7 +53,7 @@ private:
|
|||
class SysFSBlockDevicesDirectory final : public SysFSDirectory {
|
||||
public:
|
||||
static NonnullRefPtr<SysFSBlockDevicesDirectory> must_create(SysFSDevicesDirectory const&);
|
||||
virtual ErrorOr<void> traverse_as_directory(unsigned, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
|
||||
virtual ErrorOr<void> traverse_as_directory(FileSystemID, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
|
||||
virtual RefPtr<SysFSComponent> lookup(StringView name) override;
|
||||
|
||||
private:
|
||||
|
@ -63,7 +63,7 @@ private:
|
|||
class SysFSCharacterDevicesDirectory final : public SysFSDirectory {
|
||||
public:
|
||||
static NonnullRefPtr<SysFSCharacterDevicesDirectory> must_create(SysFSDevicesDirectory const&);
|
||||
virtual ErrorOr<void> traverse_as_directory(unsigned, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
|
||||
virtual ErrorOr<void> traverse_as_directory(FileSystemID, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
|
||||
virtual RefPtr<SysFSComponent> lookup(StringView name) override;
|
||||
|
||||
private:
|
||||
|
|
|
@ -31,7 +31,7 @@ mode_t SysFSComponent::permissions() const
|
|||
return S_IRUSR | S_IRGRP | S_IROTH;
|
||||
}
|
||||
|
||||
ErrorOr<void> SysFSDirectory::traverse_as_directory(unsigned fsid, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
|
||||
ErrorOr<void> SysFSDirectory::traverse_as_directory(FileSystemID fsid, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)> callback) const
|
||||
{
|
||||
MutexLocker locker(SysFSComponentRegistry::the().get_lock());
|
||||
VERIFY(m_parent_directory);
|
||||
|
|
|
@ -27,7 +27,7 @@ class SysFSComponent : public RefCounted<SysFSComponent> {
|
|||
public:
|
||||
virtual StringView name() const { return m_name->view(); }
|
||||
virtual ErrorOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const { return Error::from_errno(ENOTIMPL); }
|
||||
virtual ErrorOr<void> traverse_as_directory(unsigned, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const { VERIFY_NOT_REACHED(); }
|
||||
virtual ErrorOr<void> traverse_as_directory(FileSystemID, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const { VERIFY_NOT_REACHED(); }
|
||||
virtual RefPtr<SysFSComponent> lookup(StringView) { VERIFY_NOT_REACHED(); };
|
||||
virtual mode_t permissions() const;
|
||||
virtual ErrorOr<void> truncate(u64) { return EPERM; }
|
||||
|
@ -51,7 +51,7 @@ private:
|
|||
|
||||
class SysFSDirectory : public SysFSComponent {
|
||||
public:
|
||||
virtual ErrorOr<void> traverse_as_directory(unsigned, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
|
||||
virtual ErrorOr<void> traverse_as_directory(FileSystemID, Function<ErrorOr<void>(FileSystem::DirectoryEntryView const&)>) const override;
|
||||
virtual RefPtr<SysFSComponent> lookup(StringView name) override;
|
||||
|
||||
virtual ErrorOr<NonnullRefPtr<SysFSInode>> to_inode(SysFS const& sysfs_instance) const override final;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue