PartInfo.h
Go to the documentation of this file.
1 /****
2  * PartInfo.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/Partition.h>
23 #include <Data/Uuid.h>
24 #include "Error.h"
25 
26 namespace Storage::Disk
27 {
28 /*
29  * While not a native feature of file systems, operating systems should also aim to align partitions correctly,
30  * which avoids excessive read-modify-write cycles.
31  * A typical practice for personal computers is to have each partition aligned to start at a 1 MiB (= 1,048,576 bytes) mark,
32  * which covers all common SSD page and block size scenarios, as it is divisible by all commonly used sizes
33  * - 1 MiB, 512 KiB, 128 KiB, 4 KiB, and 512 B.
34  */
35 constexpr uint32_t PARTITION_ALIGN{0x100000U};
36 
40 enum class SysType : uint8_t {
41  unknown,
42  fat12,
43  fat16,
44  fat32,
45  exfat,
46 };
47 
49 
51 
57  SI_FAT12 = 0x01,
58  SI_FAT16 = 0x04,
59  SI_FAT16B = 0x06,
60  SI_IFS = 0x07,
61  SI_EXFAT = 0x07,
62  SI_FAT32X = 0x0c,
63 };
64 
66 {
67  switch(si) {
68  case SI_FAT12:
69  return SysType::fat12;
70  case SI_FAT16:
71  case SI_FAT16B:
72  return SysType::fat16;
73  case SI_FAT32X:
74  return SysType::fat32;
75  case SI_EXFAT:
76  return SysType::exfat;
77  default:
78  return SysType::unknown;
79  }
80 }
81 
85 struct DiskPart {
90 
94  size_t printTo(Print& p) const;
95 };
96 
102 struct PartInfo : public Partition::Info, public DiskPart {
104 
105  template <typename... Args> PartInfo(Args... args) : Partition::Info(args...)
106  {
107  }
108 
114  const Disk::DiskPart* diskpart() const override
115  {
116  return this;
117  }
118 
122  size_t printTo(Print& p) const override;
123 };
124 
129 {
130 };
131 
146 Error validate(BasePartitionTable& table, storage_size_t firstAvailableBlock, storage_size_t totalAvailableBlocks,
147  uint32_t blockSize);
148 
149 } // namespace Storage::Disk
150 
uint32_t storage_size_t
Definition: Components/Storage/src/include/Storage/Types.h:19
String toString(Storage::Disk::SysType type)
Provides formatted output to stream.
Definition: Print.h:37
Common type for MBR/GPT partition table.
Definition: PartInfo.h:129
Represents a flash partition.
Definition: Partition.h:86
The String class.
Definition: WString.h:137
Definition: Partition.h:78
Error validate(BasePartitionTable &table, storage_size_t firstAvailableBlock, storage_size_t totalAvailableBlocks, uint32_t blockSize)
Validate partition table entries.
SysIndicator
MBR partition system type indicator values.
Definition: PartInfo.h:56
@ SI_EXFAT
Definition: PartInfo.h:61
@ SI_FAT32X
FAT32 with LBA.
Definition: PartInfo.h:62
@ SI_FAT16B
FAT16B with 65536 or more sectors.
Definition: PartInfo.h:59
@ SI_FAT16
FAT16 with fewer than 65536 sectors.
Definition: PartInfo.h:58
@ SI_IFS
Definition: PartInfo.h:60
@ SI_FAT12
Definition: PartInfo.h:57
SysType
Identifies exact disk volume type.
Definition: PartInfo.h:40
@ unknown
Partition type not recognised.
Error
Definition: Libraries/DiskStorage/src/include/Storage/Disk/Error.h:37
constexpr uint32_t PARTITION_ALIGN
Definition: PartInfo.h:35
SysType getSysTypeFromIndicator(SysIndicator si)
Definition: PartInfo.h:65
static constexpr SysTypes fatTypes
Definition: PartInfo.h:50
Adds information specific to MBR/GPT disk partitions.
Definition: PartInfo.h:85
Uuid uniqueGuid
GPT partition unique GUID.
Definition: PartInfo.h:87
SysIndicator sysind
Partition sys value.
Definition: PartInfo.h:89
SysType systype
Identifies volume filing system type.
Definition: PartInfo.h:88
Uuid typeGuid
GPT type GUID.
Definition: PartInfo.h:86
size_t printTo(Print &p) const
Print full contents of this structure.
In-memory partition information.
Definition: PartInfo.h:102
size_t printTo(Print &p) const override
Print important fields only.
const Disk::DiskPart * diskpart() const override
Obtain additional disk information.
Definition: PartInfo.h:114
PartInfo(Args... args)
Definition: PartInfo.h:105
Partition information.
Definition: Partition.h:181
Info()
Definition: Partition.h:191
Class for manipulating UUID (aka GUID) entities.
Definition: Uuid.h:26