1
1
use std:: collections:: HashMap ;
2
- #[ cfg( feature = "install-to-disk" ) ]
3
2
use std:: env;
4
- #[ cfg( feature = "install-to-disk" ) ]
5
3
use std:: path:: Path ;
6
4
use std:: process:: Command ;
7
5
use std:: sync:: OnceLock ;
8
6
9
7
use anyhow:: { anyhow, Context , Result } ;
10
8
use camino:: Utf8Path ;
11
- #[ cfg( feature = "install-to-disk" ) ]
12
9
use camino:: Utf8PathBuf ;
13
10
use fn_error_context:: context;
14
11
use regex:: Regex ;
@@ -23,34 +20,34 @@ struct DevicesOutput {
23
20
24
21
#[ allow( dead_code) ]
25
22
#[ derive( Debug , Deserialize ) ]
26
- pub ( crate ) struct Device {
27
- pub ( crate ) name : String ,
28
- pub ( crate ) serial : Option < String > ,
29
- pub ( crate ) model : Option < String > ,
30
- pub ( crate ) partlabel : Option < String > ,
31
- pub ( crate ) children : Option < Vec < Device > > ,
32
- pub ( crate ) size : u64 ,
23
+ pub struct Device {
24
+ pub name : String ,
25
+ pub serial : Option < String > ,
26
+ pub model : Option < String > ,
27
+ pub partlabel : Option < String > ,
28
+ pub children : Option < Vec < Device > > ,
29
+ pub size : u64 ,
33
30
#[ serde( rename = "maj:min" ) ]
34
- pub ( crate ) maj_min : Option < String > ,
31
+ pub maj_min : Option < String > ,
35
32
// NOTE this one is not available on older util-linux, and
36
33
// will also not exist for whole blockdevs (as opposed to partitions).
37
- pub ( crate ) start : Option < u64 > ,
34
+ pub start : Option < u64 > ,
38
35
39
36
// Filesystem-related properties
40
- pub ( crate ) label : Option < String > ,
41
- pub ( crate ) fstype : Option < String > ,
42
- pub ( crate ) path : Option < String > ,
37
+ pub label : Option < String > ,
38
+ pub fstype : Option < String > ,
39
+ pub path : Option < String > ,
43
40
}
44
41
45
42
impl Device {
46
43
#[ allow( dead_code) ]
47
44
// RHEL8's lsblk doesn't have PATH, so we do it
48
- pub ( crate ) fn path ( & self ) -> String {
45
+ pub fn path ( & self ) -> String {
49
46
self . path . clone ( ) . unwrap_or ( format ! ( "/dev/{}" , & self . name) )
50
47
}
51
48
52
49
#[ allow( dead_code) ]
53
- pub ( crate ) fn has_children ( & self ) -> bool {
50
+ pub fn has_children ( & self ) -> bool {
54
51
self . children . as_ref ( ) . map_or ( false , |v| !v. is_empty ( ) )
55
52
}
56
53
@@ -77,7 +74,7 @@ impl Device {
77
74
}
78
75
79
76
/// Older versions of util-linux may be missing some properties. Backfill them if they're missing.
80
- pub ( crate ) fn backfill_missing ( & mut self ) -> Result < ( ) > {
77
+ pub fn backfill_missing ( & mut self ) -> Result < ( ) > {
81
78
// Add new properties to backfill here
82
79
self . backfill_start ( ) ?;
83
80
// And recurse to child devices
@@ -89,7 +86,7 @@ impl Device {
89
86
}
90
87
91
88
#[ context( "Listing device {dev}" ) ]
92
- pub ( crate ) fn list_dev ( dev : & Utf8Path ) -> Result < Device > {
89
+ pub fn list_dev ( dev : & Utf8Path ) -> Result < Device > {
93
90
let mut devs: DevicesOutput = Command :: new ( "lsblk" )
94
91
. args ( [ "-J" , "-b" , "-O" ] )
95
92
. arg ( dev)
@@ -111,52 +108,52 @@ struct SfDiskOutput {
111
108
112
109
#[ derive( Debug , Deserialize ) ]
113
110
#[ allow( dead_code) ]
114
- pub ( crate ) struct Partition {
115
- pub ( crate ) node : String ,
116
- pub ( crate ) start : u64 ,
117
- pub ( crate ) size : u64 ,
111
+ pub struct Partition {
112
+ pub node : String ,
113
+ pub start : u64 ,
114
+ pub size : u64 ,
118
115
#[ serde( rename = "type" ) ]
119
- pub ( crate ) parttype : String ,
120
- pub ( crate ) uuid : Option < String > ,
121
- pub ( crate ) name : Option < String > ,
116
+ pub parttype : String ,
117
+ pub uuid : Option < String > ,
118
+ pub name : Option < String > ,
122
119
}
123
120
124
121
#[ derive( Debug , Deserialize , PartialEq , Eq ) ]
125
122
#[ serde( rename_all = "kebab-case" ) ]
126
- pub ( crate ) enum PartitionType {
123
+ pub enum PartitionType {
127
124
Dos ,
128
125
Gpt ,
129
126
Unknown ( String ) ,
130
127
}
131
128
132
129
#[ derive( Debug , Deserialize ) ]
133
130
#[ allow( dead_code) ]
134
- pub ( crate ) struct PartitionTable {
135
- pub ( crate ) label : PartitionType ,
136
- pub ( crate ) id : String ,
137
- pub ( crate ) device : String ,
131
+ pub struct PartitionTable {
132
+ pub label : PartitionType ,
133
+ pub id : String ,
134
+ pub device : String ,
138
135
// We're not using these fields
139
- // pub(crate) unit: String,
140
- // pub(crate) firstlba: u64,
141
- // pub(crate) lastlba: u64,
142
- // pub(crate) sectorsize: u64,
143
- pub ( crate ) partitions : Vec < Partition > ,
136
+ // pub unit: String,
137
+ // pub firstlba: u64,
138
+ // pub lastlba: u64,
139
+ // pub sectorsize: u64,
140
+ pub partitions : Vec < Partition > ,
144
141
}
145
142
146
143
impl PartitionTable {
147
144
/// Find the partition with the given device name
148
145
#[ allow( dead_code) ]
149
- pub ( crate ) fn find < ' a > ( & ' a self , devname : & str ) -> Option < & ' a Partition > {
146
+ pub fn find < ' a > ( & ' a self , devname : & str ) -> Option < & ' a Partition > {
150
147
self . partitions . iter ( ) . find ( |p| p. node . as_str ( ) == devname)
151
148
}
152
149
153
- pub ( crate ) fn path ( & self ) -> & Utf8Path {
150
+ pub fn path ( & self ) -> & Utf8Path {
154
151
self . device . as_str ( ) . into ( )
155
152
}
156
153
157
154
// Find the partition with the given offset (starting at 1)
158
155
#[ allow( dead_code) ]
159
- pub ( crate ) fn find_partno ( & self , partno : u32 ) -> Result < & Partition > {
156
+ pub fn find_partno ( & self , partno : u32 ) -> Result < & Partition > {
160
157
let r = self
161
158
. partitions
162
159
. get ( partno. checked_sub ( 1 ) . expect ( "1 based partition offset" ) as usize )
@@ -167,28 +164,26 @@ impl PartitionTable {
167
164
168
165
impl Partition {
169
166
#[ allow( dead_code) ]
170
- pub ( crate ) fn path ( & self ) -> & Utf8Path {
167
+ pub fn path ( & self ) -> & Utf8Path {
171
168
self . node . as_str ( ) . into ( )
172
169
}
173
170
}
174
171
175
172
#[ context( "Listing partitions of {dev}" ) ]
176
- pub ( crate ) fn partitions_of ( dev : & Utf8Path ) -> Result < PartitionTable > {
173
+ pub fn partitions_of ( dev : & Utf8Path ) -> Result < PartitionTable > {
177
174
let o: SfDiskOutput = Command :: new ( "sfdisk" )
178
175
. args ( [ "-J" , dev. as_str ( ) ] )
179
176
. run_and_parse_json ( ) ?;
180
177
Ok ( o. partitiontable )
181
178
}
182
179
183
- #[ cfg( feature = "install-to-disk" ) ]
184
- pub ( crate ) struct LoopbackDevice {
185
- pub ( crate ) dev : Option < Utf8PathBuf > ,
180
+ pub struct LoopbackDevice {
181
+ pub dev : Option < Utf8PathBuf > ,
186
182
}
187
183
188
- #[ cfg( feature = "install-to-disk" ) ]
189
184
impl LoopbackDevice {
190
185
// Create a new loopback block device targeting the provided file path.
191
- pub ( crate ) fn new ( path : & Path ) -> Result < Self > {
186
+ pub fn new ( path : & Path ) -> Result < Self > {
192
187
let direct_io = match env:: var ( "BOOTC_DIRECT_IO" ) {
193
188
Ok ( val) => {
194
189
if val == "on" {
@@ -215,7 +210,7 @@ impl LoopbackDevice {
215
210
}
216
211
217
212
// Access the path to the loopback block device.
218
- pub ( crate ) fn path ( & self ) -> & Utf8Path {
213
+ pub fn path ( & self ) -> & Utf8Path {
219
214
// SAFETY: The option cannot be destructured until we are dropped
220
215
self . dev . as_deref ( ) . unwrap ( )
221
216
}
@@ -231,12 +226,11 @@ impl LoopbackDevice {
231
226
}
232
227
233
228
/// Consume this device, unmounting it.
234
- pub ( crate ) fn close ( mut self ) -> Result < ( ) > {
229
+ pub fn close ( mut self ) -> Result < ( ) > {
235
230
self . impl_close ( )
236
231
}
237
232
}
238
233
239
- #[ cfg( feature = "install-to-disk" ) ]
240
234
impl Drop for LoopbackDevice {
241
235
fn drop ( & mut self ) {
242
236
// Best effort to unmount if we're dropped without invoking `close`
@@ -259,7 +253,7 @@ fn split_lsblk_line(line: &str) -> HashMap<String, String> {
259
253
/// This is a bit fuzzy, but... this function will return every block device in the parent
260
254
/// hierarchy of `device` capable of containing other partitions. So e.g. parent devices of type
261
255
/// "part" doesn't match, but "disk" and "mpath" does.
262
- pub ( crate ) fn find_parent_devices ( device : & str ) -> Result < Vec < String > > {
256
+ pub fn find_parent_devices ( device : & str ) -> Result < Vec < String > > {
263
257
let output = Command :: new ( "lsblk" )
264
258
// Older lsblk, e.g. in CentOS 7.6, doesn't support PATH, but --paths option
265
259
. arg ( "--pairs" )
@@ -291,8 +285,7 @@ pub(crate) fn find_parent_devices(device: &str) -> Result<Vec<String>> {
291
285
}
292
286
293
287
/// Parse a string into mibibytes
294
- #[ cfg( feature = "install-to-disk" ) ]
295
- pub ( crate ) fn parse_size_mib ( mut s : & str ) -> Result < u64 > {
288
+ pub fn parse_size_mib ( mut s : & str ) -> Result < u64 > {
296
289
let suffixes = [
297
290
( "MiB" , 1u64 ) ,
298
291
( "M" , 1u64 ) ,
0 commit comments