Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
* Copyright (c) 2021, Luca Fulchir <luker@fenrirproject.org>
*
* This file is part of dfim.
*
* dfim is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* dfim is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with dfim. If not, see <https://www.gnu.org/licenses/>.
*/
mod flags;
mod part_type;
mod verify;
pub use flags::Flag;
pub use verify::verify;
use super::errors;
use strum_macros::Display;
#[::serde_with::serde_as]
#[derive(::serde::Deserialize, Clone)]
#[serde(deny_unknown_fields)]
pub enum PartId {
#[serde_as(as = "serde_with::hex::Hex")]
GPTFdisk(u16),
Def(part_type::PartType),
UUID(::uuid::Uuid),
}
// This is an enum to force ron to use Alignemnt(u64) so the user will never
// confuse the fields
#[derive(::serde::Deserialize, Clone)]
#[serde(deny_unknown_fields)]
pub enum Alignment {
Alignment(u64),
}
#[derive(::serde::Deserialize, Clone)]
#[serde(deny_unknown_fields)]
pub struct Size(u64);
#[derive(::serde::Deserialize, Clone)]
#[serde(deny_unknown_fields)]
pub struct LBA(u64);
#[derive(::serde::Deserialize, Clone)]
#[serde(deny_unknown_fields)]
pub enum PartFrom {
/// LBAs to leave free from the partition
SkipFreeLBA(LBA, Alignment),
/// Size to leave from the last partition
SkipFreeSize(Size, Alignment),
/// specify LBA number directly
LBA(LBA, Alignment),
/// give a size, it will be converted to the appropriate LBA
Size(Size, Alignment),
/// this partition will have at most size X, calculated from the
/// end of the drive, or from the partitions at the end of the drive
SizeFromEndOrLast(Size, Alignment),
}
#[derive(::serde::Deserialize, Clone)]
#[serde(deny_unknown_fields)]
pub enum PartTo {
/// specify LBA number directly
LBA(LBA, Alignment),
/// give a size, it will be converted to the appropriate LBA
Size(Size, Alignment),
/// use all, leaving this size free
LeaveSize(Size, Alignment),
/// use the specified percentage of the free disk
Percent(f32, Alignment),
/// use all, leaving this percentage of disk free
LeavePercent(f32, Alignment),
}
#[derive(::serde::Deserialize, Clone)]
#[serde(deny_unknown_fields)]
pub enum PartUUID {
Random,
UUID(::uuid::Uuid),
}
#[derive(::serde::Deserialize, Clone)]
#[serde(deny_unknown_fields)]
pub struct Partition {
label: String,
part_type: PartId,
part_uuid: PartUUID,
#[serde(default)]
flags: Vec<flags::Flag>,
from: PartFrom,
to: PartTo,
}
#[derive(::serde::Deserialize, Clone)]
#[serde(deny_unknown_fields)]
pub enum GptUuid {
Random,
UUID(::uuid::Uuid),
}
#[derive(::serde::Deserialize, Clone)]
#[serde(deny_unknown_fields)]
pub struct GPT {
dfim_id: String,
guid: GptUuid,
#[serde(default)]
partitions: Vec<Partition>,
}
#[derive(::serde::Deserialize, Clone)]
#[serde(deny_unknown_fields)]
// somehow marking this "untagged" breaks the parsing of Gpt :/
//#[serde(untagged)]
pub enum GptId {
DfimId(String),
InlineGPT(GPT),
}