InodeIdentifier.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. TYPEDEF_DISTINCT_ORDERED_ID(u32, FileSystemID);
  14. 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. FileSystem* fs();
  27. const FileSystem* fs() const;
  28. bool operator==(const InodeIdentifier& other) const
  29. {
  30. return m_fsid == other.m_fsid && m_index == other.m_index;
  31. }
  32. bool operator!=(const InodeIdentifier& other) const
  33. {
  34. return m_fsid != other.m_fsid || m_index != other.m_index;
  35. }
  36. private:
  37. FileSystemID m_fsid { 0 };
  38. InodeIndex m_index { 0 };
  39. };
  40. }
  41. template<>
  42. struct AK::Formatter<Kernel::InodeIdentifier> : AK::Formatter<FormatString> {
  43. ErrorOr<void> format(FormatBuilder& builder, Kernel::InodeIdentifier value)
  44. {
  45. return AK::Formatter<FormatString>::format(builder, "{}:{}", value.fsid(), value.index());
  46. }
  47. };