2020-01-18 08:38:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 08:38:21 +00:00
|
|
|
*/
|
|
|
|
|
2018-10-10 09:53:07 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/ByteBuffer.h>
|
2021-02-12 08:18:47 +00:00
|
|
|
#include <AK/DistinctNumeric.h>
|
2018-10-10 09:53:07 +00:00
|
|
|
#include <AK/Types.h>
|
|
|
|
|
2020-02-16 00:27:42 +00:00
|
|
|
namespace Kernel {
|
|
|
|
|
2021-07-10 22:20:38 +00:00
|
|
|
class FileSystem;
|
2018-10-10 09:53:07 +00:00
|
|
|
struct InodeMetadata;
|
|
|
|
|
2021-11-18 14:11:31 +00:00
|
|
|
TYPEDEF_DISTINCT_ORDERED_ID(u32, FileSystemID);
|
2021-07-05 19:38:17 +00:00
|
|
|
TYPEDEF_DISTINCT_ORDERED_ID(u64, InodeIndex);
|
2021-02-12 08:18:47 +00:00
|
|
|
|
2018-10-10 09:53:07 +00:00
|
|
|
class InodeIdentifier {
|
|
|
|
public:
|
2021-02-28 13:42:08 +00:00
|
|
|
InodeIdentifier() = default;
|
2021-11-18 14:11:31 +00:00
|
|
|
InodeIdentifier(FileSystemID fsid, InodeIndex inode)
|
2019-01-31 16:31:23 +00:00
|
|
|
: m_fsid(fsid)
|
2018-10-10 09:53:07 +00:00
|
|
|
, m_index(inode)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-12-02 23:20:00 +00:00
|
|
|
bool is_valid() const { return m_fsid != 0 && m_index != 0; }
|
2018-10-10 09:53:07 +00:00
|
|
|
|
2021-11-18 14:11:31 +00:00
|
|
|
FileSystemID fsid() const { return m_fsid; }
|
2021-02-12 08:18:47 +00:00
|
|
|
InodeIndex index() const { return m_index; }
|
2018-10-10 09:53:07 +00:00
|
|
|
|
2021-07-10 22:20:38 +00:00
|
|
|
FileSystem* fs();
|
|
|
|
const FileSystem* fs() const;
|
2018-10-10 09:53:07 +00:00
|
|
|
|
|
|
|
bool operator==(const InodeIdentifier& other) const
|
|
|
|
{
|
2018-12-02 23:20:00 +00:00
|
|
|
return m_fsid == other.m_fsid && m_index == other.m_index;
|
2018-10-10 09:53:07 +00:00
|
|
|
}
|
|
|
|
|
2018-10-24 12:28:22 +00:00
|
|
|
bool operator!=(const InodeIdentifier& other) const
|
|
|
|
{
|
2018-12-02 23:20:00 +00:00
|
|
|
return m_fsid != other.m_fsid || m_index != other.m_index;
|
2018-10-24 12:28:22 +00:00
|
|
|
}
|
|
|
|
|
2018-10-10 09:53:07 +00:00
|
|
|
private:
|
2021-11-18 14:11:31 +00:00
|
|
|
FileSystemID m_fsid { 0 };
|
2021-02-12 08:18:47 +00:00
|
|
|
InodeIndex m_index { 0 };
|
2018-10-10 09:53:07 +00:00
|
|
|
};
|
2019-07-08 13:38:44 +00:00
|
|
|
|
2020-02-16 00:27:42 +00:00
|
|
|
}
|
2021-01-10 14:17:54 +00:00
|
|
|
|
|
|
|
template<>
|
|
|
|
struct AK::Formatter<Kernel::InodeIdentifier> : AK::Formatter<FormatString> {
|
2021-11-16 00:15:21 +00:00
|
|
|
ErrorOr<void> format(FormatBuilder& builder, Kernel::InodeIdentifier value)
|
2021-01-10 14:17:54 +00:00
|
|
|
{
|
|
|
|
return AK::Formatter<FormatString>::format(builder, "{}:{}", value.fsid(), value.index());
|
|
|
|
}
|
|
|
|
};
|