MBRPartitionTable.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/ByteBuffer.h>
  8. #include <AK/RefPtr.h>
  9. #include <AK/Result.h>
  10. #include <AK/Vector.h>
  11. #include <Kernel/Storage/Partition/PartitionTable.h>
  12. namespace Kernel {
  13. class MBRPartitionTable : public PartitionTable {
  14. public:
  15. struct [[gnu::packed]] Entry {
  16. u8 status;
  17. u8 chs1[3];
  18. u8 type;
  19. u8 chs2[3];
  20. u32 offset;
  21. u32 length;
  22. };
  23. struct [[gnu::packed]] Header {
  24. u8 code1[218];
  25. u16 ts_zero;
  26. u8 ts_drive;
  27. u8 ts_seconds;
  28. u8 ts_minutes;
  29. u8 ts_hours;
  30. u8 code2[216];
  31. u32 disk_signature;
  32. u16 disk_signature_zero;
  33. Entry entry[4];
  34. u16 mbr_signature;
  35. };
  36. public:
  37. ~MBRPartitionTable();
  38. static Result<NonnullOwnPtr<MBRPartitionTable>, PartitionTable::Error> try_to_initialize(const StorageDevice&);
  39. static OwnPtr<MBRPartitionTable> try_to_initialize(const StorageDevice&, u32 start_lba);
  40. explicit MBRPartitionTable(const StorageDevice&);
  41. MBRPartitionTable(const StorageDevice&, u32 start_lba);
  42. bool is_protective_mbr() const;
  43. bool contains_ebr() const;
  44. virtual bool is_valid() const override { return m_valid; };
  45. protected:
  46. const Header& header() const;
  47. bool is_header_valid() const { return m_header_valid; };
  48. private:
  49. bool read_boot_record();
  50. bool initialize();
  51. bool m_valid { false };
  52. bool m_header_valid { false };
  53. const u32 m_start_lba;
  54. ByteBuffer m_cached_header;
  55. };
  56. }