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
127
128
129
130
131
132
133
134
135
136
137
/*
* 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 super::{CheckResult, CheckStatus, NextTarget};
use crate::config::target;
// we could use lifetimes here instead of copying stuff, but
// - we should have realatively low usage anyway
// - lifetimes can get messy
// - we don't have enough modules to fully know how lifetimes will impact the
// code.
// so for now, clone
pub struct GPT(crate::config::target::gpt::GPT);
impl GPT {
pub fn new(cfg: &crate::config::target::gpt::GPT) -> Self {
GPT(cfg.clone())
}
}
impl super::TargetApply for GPT {
fn check(
&mut self,
logger: &::slog::Logger,
cfg: &crate::state::cfg::Cfg,
dev: &::udev::Device,
) -> Result<CheckResult, ::std::io::Error> {
let node = match dev.devnode() {
Some(node) => ::std::path::Path::new(node),
None => {
::slog::error!(
logger,
"GPT: device \"{:?}\" does not have a corresponding node",
dev.syspath()
);
return Err(::std::io::Error::new(
::std::io::ErrorKind::NotFound,
"GPT: device does not have a node",
));
}
};
let cfg = ::gpt::GptConfig::new().writable(false);
if let Ok(true) = crate::state::is_empty(dev) {
return Ok(CheckResult {
status: CheckStatus::CanBeApplied,
// FIXME
next: Vec::new(),
});
}
let disk = match cfg.open(node) {
Ok(disk) => disk,
Err(e) => {
::slog::error!(
logger,
"GPT: device \"{:?}\" node \"{:?}\": can't open",
dev.syspath(),
node
);
return Err(e);
}
};
let disk_guid = disk.guid();
if let target::gpt::GptUuid::UUID(uuid) = self.0.guid {
if *disk_guid != uuid {
::slog::debug!(
logger,
"GPT: device \"{:?}\" wrong guid. Got: {:?} Expected: {:?}",
dev.syspath(),
disk_guid,
uuid
);
return Ok(CheckResult {
status: CheckStatus::DoNotApply,
next: Vec::new(),
});
}
}
let disk_part = disk.partitions();
if disk_part.len() != self.0.partitions.len() {
::slog::debug!(
logger,
"GPT: device \"{:?}\" partitions don't match",
dev.syspath()
);
return Ok(CheckResult {
status: CheckStatus::DoNotApply,
next: Vec::new(),
});
}
for (idx, p) in disk_part {
match self
.0
.partitions
.iter()
.find(|x| x.number == Some(*idx as u8))
{
None => {}
Some(_) => {}
}
}
Err(::std::io::Error::new(
::std::io::ErrorKind::Other,
"Exec: nonZero exit status",
))
}
fn apply(
&mut self,
logger: &::slog::Logger,
cfg: &crate::state::cfg::Cfg,
cfg_dev: &crate::config::device::Device,
dev: &::udev::Device,
) -> Result<Vec<NextTarget>, ::std::io::Error> {
Err(::std::io::Error::new(
::std::io::ErrorKind::Other,
"Exec: nonZero exit status",
))
}
}