Serenity Operating System
at master 58 lines 1.4 kB view raw
1/* 2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#pragma once 8 9#include <AK/ByteBuffer.h> 10#include <AK/DistinctNumeric.h> 11#include <AK/Types.h> 12 13namespace Kernel { 14 15class FileSystem; 16struct InodeMetadata; 17 18AK_TYPEDEF_DISTINCT_ORDERED_ID(u32, FileSystemID); 19AK_TYPEDEF_DISTINCT_ORDERED_ID(u64, InodeIndex); 20 21class InodeIdentifier { 22public: 23 InodeIdentifier() = default; 24 InodeIdentifier(FileSystemID fsid, InodeIndex inode) 25 : m_fsid(fsid) 26 , m_index(inode) 27 { 28 } 29 30 bool is_valid() const { return m_fsid != 0 && m_index != 0; } 31 32 FileSystemID fsid() const { return m_fsid; } 33 InodeIndex index() const { return m_index; } 34 35 bool operator==(InodeIdentifier const& other) const 36 { 37 return m_fsid == other.m_fsid && m_index == other.m_index; 38 } 39 40 bool operator!=(InodeIdentifier const& other) const 41 { 42 return m_fsid != other.m_fsid || m_index != other.m_index; 43 } 44 45private: 46 FileSystemID m_fsid { 0 }; 47 InodeIndex m_index { 0 }; 48}; 49 50} 51 52template<> 53struct AK::Formatter<Kernel::InodeIdentifier> : AK::Formatter<FormatString> { 54 ErrorOr<void> format(FormatBuilder& builder, Kernel::InodeIdentifier value) 55 { 56 return AK::Formatter<FormatString>::format(builder, "{}:{}"sv, value.fsid(), value.index()); 57 } 58};