InodeIdentifier.h 1.3 KB

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