Scanner.h
Go to the documentation of this file.
1 /****
2  * Scanner.h
3  *
4  * Copyright 2022 mikee47 <mike@sillyhouse.net>
5  *
6  * This file is part of the DiskStorage Library
7  *
8  * This library is free software: you can redistribute it and/or modify it under the terms of the
9  * GNU General Public License as published by the Free Software Foundation, version 3 or later.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along with this library.
16  * If not, see <https://www.gnu.org/licenses/>.
17  *
18  ****/
19 
20 #pragma once
21 
22 #include <Storage/Device.h>
23 #include "PartInfo.h"
24 #include "SectorBuffer.h"
25 
26 namespace Storage
27 {
28 namespace Disk
29 {
30 struct gpt_mbr_record_t;
31 
37 class Scanner
38 {
39 public:
40  Scanner(Device& device);
41  ~Scanner();
42 
46  std::unique_ptr<PartInfo> next();
47 
48  explicit operator bool() const
49  {
50  return state != State::error;
51  }
52 
53 private:
54  enum class State {
55  idle,
56  MBR,
57  GPT,
58  error,
59  done,
60  };
61 
62  unsigned scanMbrEntries(uint32_t baseLba);
63 
64  Device& device;
65  SectorBuffer buffer;
66  SectorBuffer entryBuffer; // GPT
67  State state{};
68  uint64_t sector{0}; // GPT
69  std::unique_ptr<gpt_mbr_record_t[]> mbrEntries; // MBR
70  uint16_t numPartitionEntries{0};
71  uint16_t partitionIndex{0};
72  uint16_t mbrPartID{0};
73  uint16_t sectorSize{0};
74  uint8_t sectorSizeShift{0};
75 };
76 
77 } // namespace Disk
78 } // namespace Storage
std::unique_ptr< PartInfo > next()
Obtains the next partition entry (if any)
Definition: FileDevice.h:25
Scanner(Device &device)
@ error
Action could not be completed.
Definition: efi.h:71