Newer
Older
/*
* 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/>.
*/
use num_derive::FromPrimitive;
use num_traits::FromPrimitive;
#[derive(
::serde::Deserialize,
::serde::Serialize,
Clone,
Copy,
FromPrimitive,
PartialEq,
Eq,
PartialOrd,
Ord,
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
127
128
#[serde(deny_unknown_fields)]
pub enum Flag {
Bit0 = 0,
Bit1 = 1,
Bit2,
Bit3,
Bit4,
Bit5,
Bit6,
Bit7,
Bit8,
Bit9,
Bit10,
Bit11,
Bit12,
Bit13,
Bit14,
Bit15,
Bit16,
Bit17,
Bit18,
Bit19,
Bit20,
Bit21,
Bit22,
Bit23,
Bit24,
Bit25,
Bit26,
Bit27,
Bit28,
Bit29,
Bit30,
Bit31,
Bit32,
Bit33,
Bit34,
Bit35,
Bit36,
Bit37,
Bit38,
Bit39,
Bit40,
Bit41,
Bit42,
Bit43,
Bit44,
Bit45,
Bit46,
Bit47,
Bit48,
Bit49,
Bit50,
Bit51,
Bit52,
Bit53,
Bit54,
Bit55,
Bit56,
Bit57,
Bit58,
Bit59,
Bit60,
Bit61,
Bit62,
Bit63,
// These next are user-friendly names
// for the above bits
// common
PlatformRequired,
EfiIgnore,
LegacyBiosBootable,
// ChromeOS
// little endian? big endian?
ChromeOsPriorityBit0,
ChromeOsPriorityBit1,
ChromeOsPriorityBit2,
ChromeOsPriorityBit3,
// little endian? big endian?
ChromeOsRetriesBit0,
ChromeOsRetriesBit1,
ChromeOsRetriesBit2,
ChromeOsRetriesBit3,
ChromeOsSuccessfulBoot,
// Microsoft
MSReadOnly,
MSShadowCopy,
MSHidden,
MSNoDriveLetter,
// Linux Systemd
SystemdGrowPartition,
SystemdReadOnly,
SystemdNoAuto,
}
impl Flag {
pub fn from_bits(bits: u64) -> Vec<Flag> {
let mut ret = Vec::with_capacity(8);
for idx in 0..63 {
let raw_flag = bits & (1 << idx);
if raw_flag != 0 {
if let Some(flag) = FromPrimitive::from_u64(idx) {
ret.push(flag);
}
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
match self {
Flag::Bit0
| Flag::Bit1
| Flag::Bit2
| Flag::Bit3
| Flag::Bit4
| Flag::Bit5
| Flag::Bit6
| Flag::Bit7
| Flag::Bit8
| Flag::Bit9
| Flag::Bit10
| Flag::Bit11
| Flag::Bit12
| Flag::Bit13
| Flag::Bit14
| Flag::Bit15
| Flag::Bit16
| Flag::Bit17
| Flag::Bit18
| Flag::Bit19
| Flag::Bit20
| Flag::Bit21
| Flag::Bit22
| Flag::Bit23
| Flag::Bit24
| Flag::Bit25
| Flag::Bit26
| Flag::Bit27
| Flag::Bit28
| Flag::Bit29
| Flag::Bit30
| Flag::Bit31
| Flag::Bit32
| Flag::Bit33
| Flag::Bit34
| Flag::Bit35
| Flag::Bit36
| Flag::Bit37
| Flag::Bit38
| Flag::Bit39
| Flag::Bit40
| Flag::Bit41
| Flag::Bit42
| Flag::Bit43
| Flag::Bit44
| Flag::Bit45
| Flag::Bit46
| Flag::Bit47
| Flag::Bit48
| Flag::Bit49
| Flag::Bit50
| Flag::Bit51
| Flag::Bit52
| Flag::Bit53
| Flag::Bit54
| Flag::Bit55
| Flag::Bit56
| Flag::Bit57
| Flag::Bit58
| Flag::Bit59
| Flag::Bit60
| Flag::Bit61
| Flag::Bit62
Flag::PlatformRequired => 0b1 as u64,
Flag::EfiIgnore => 0b10 as u64,
Flag::LegacyBiosBootable => 0b100 as u64,
// FIXME: Endianness???
Flag::ChromeOsPriorityBit0 => (1 as u64) << 47,
Flag::ChromeOsPriorityBit1 => (1 as u64) << 48,
Flag::ChromeOsPriorityBit2 => (1 as u64) << 49,
Flag::ChromeOsPriorityBit3 => (1 as u64) << 50,
Flag::ChromeOsRetriesBit0 => (1 as u64) << 51,
Flag::ChromeOsRetriesBit1 => (1 as u64) << 52,
Flag::ChromeOsRetriesBit2 => (1 as u64) << 53,
Flag::ChromeOsRetriesBit3 => (1 as u64) << 54,
Flag::ChromeOsSuccessfulBoot => (1 as u64) << 55,
Flag::MSReadOnly => (1 as u64) << 59,
Flag::MSShadowCopy => (1 as u64) << 60,
Flag::MSHidden => (1 as u64) << 61,
Flag::MSNoDriveLetter => (1 as u64) << 62,
Flag::SystemdGrowPartition => (1 as u64) << 58,
Flag::SystemdReadOnly => (1 as u64) << 59,
Flag::SystemdNoAuto => (1 as u64) << 62,
}
}
}