mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-23 16:10:20 +00:00
e08d213830
This patch adds the FileSystemID type, which is a distinct u32. This prevents accidental conversion from arbitrary integers.
61 lines
1.4 KiB
C++
61 lines
1.4 KiB
C++
/*
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/ByteBuffer.h>
|
|
#include <AK/DistinctNumeric.h>
|
|
#include <AK/Types.h>
|
|
|
|
namespace Kernel {
|
|
|
|
class FileSystem;
|
|
struct InodeMetadata;
|
|
|
|
TYPEDEF_DISTINCT_ORDERED_ID(u32, FileSystemID);
|
|
TYPEDEF_DISTINCT_ORDERED_ID(u64, InodeIndex);
|
|
|
|
class InodeIdentifier {
|
|
public:
|
|
InodeIdentifier() = default;
|
|
InodeIdentifier(FileSystemID fsid, InodeIndex inode)
|
|
: m_fsid(fsid)
|
|
, m_index(inode)
|
|
{
|
|
}
|
|
|
|
bool is_valid() const { return m_fsid != 0 && m_index != 0; }
|
|
|
|
FileSystemID fsid() const { return m_fsid; }
|
|
InodeIndex index() const { return m_index; }
|
|
|
|
FileSystem* fs();
|
|
const FileSystem* fs() const;
|
|
|
|
bool operator==(const InodeIdentifier& other) const
|
|
{
|
|
return m_fsid == other.m_fsid && m_index == other.m_index;
|
|
}
|
|
|
|
bool operator!=(const InodeIdentifier& other) const
|
|
{
|
|
return m_fsid != other.m_fsid || m_index != other.m_index;
|
|
}
|
|
|
|
private:
|
|
FileSystemID m_fsid { 0 };
|
|
InodeIndex m_index { 0 };
|
|
};
|
|
|
|
}
|
|
|
|
template<>
|
|
struct AK::Formatter<Kernel::InodeIdentifier> : AK::Formatter<FormatString> {
|
|
ErrorOr<void> format(FormatBuilder& builder, Kernel::InodeIdentifier value)
|
|
{
|
|
return AK::Formatter<FormatString>::format(builder, "{}:{}", value.fsid(), value.index());
|
|
}
|
|
};
|