1+ //! Block device utilities for bootc.
2+ //!
3+ //! This module provides utilities for querying and managing block devices,
4+ //! partitions, and filesystems during bootc installation and operation.
5+
16use std:: env;
27use std:: path:: Path ;
38use std:: process:: { Command , Stdio } ;
@@ -26,27 +31,41 @@ struct DevicesOutput {
2631
2732#[ allow( dead_code) ]
2833#[ derive( Debug , Clone , Deserialize ) ]
34+ /// Information about a block device.
2935pub struct Device {
36+ /// Device name (e.g., "sda", "sda1").
3037 pub name : String ,
38+ /// Device serial number.
3139 pub serial : Option < String > ,
40+ /// Device model.
3241 pub model : Option < String > ,
42+ /// Partition label.
3343 pub partlabel : Option < String > ,
44+ /// Partition type.
3445 pub parttype : Option < String > ,
46+ /// Partition UUID.
3547 pub partuuid : Option < String > ,
3648 /// Partition number (1-indexed). None for whole disk devices.
3749 pub partn : Option < u32 > ,
50+ /// Child devices (partitions for a disk).
3851 pub children : Option < Vec < Device > > ,
52+ /// Device size in bytes.
3953 pub size : u64 ,
54+ /// Major:minor device numbers.
4055 #[ serde( rename = "maj:min" ) ]
4156 pub maj_min : Option < String > ,
4257 // NOTE this one is not available on older util-linux, and
4358 // will also not exist for whole blockdevs (as opposed to partitions).
4459 pub start : Option < u64 > ,
4560
4661 // Filesystem-related properties
62+ /// Filesystem label.
4763 pub label : Option < String > ,
64+ /// Filesystem type.
4865 pub fstype : Option < String > ,
66+ /// Filesystem UUID.
4967 pub uuid : Option < String > ,
68+ /// Device path.
5069 pub path : Option < String > ,
5170 /// Partition table type (e.g., "gpt", "dos"). Only present on whole disk devices.
5271 pub pttype : Option < String > ,
@@ -234,6 +253,7 @@ impl Device {
234253 }
235254}
236255
256+ /// List information about a block device.
237257#[ context( "Listing device {dev}" ) ]
238258pub fn list_dev ( dev : & Utf8Path ) -> Result < Device > {
239259 let mut devs: DevicesOutput = Command :: new ( "lsblk" )
@@ -256,7 +276,9 @@ pub fn list_dev_by_dir(dir: &Dir) -> Result<Device> {
256276 list_dev ( & Utf8PathBuf :: from ( & fsinfo. source ) )
257277}
258278
279+ /// A loopback block device backed by a file.
259280pub struct LoopbackDevice {
281+ /// The loopback device path (e.g., "/dev/loop0").
260282 pub dev : Option < Utf8PathBuf > ,
261283 // Handle to the cleanup helper process
262284 cleanup_handle : Option < LoopbackCleanupHandle > ,
@@ -384,8 +406,10 @@ impl Drop for LoopbackDevice {
384406 }
385407}
386408
387- /// Main function for the loopback cleanup helper process
388- /// This function does not return - it either exits normally or via signal
409+ /// Run the loopback cleanup helper process.
410+ ///
411+ /// This function does not return - it either exits normally or via signal.
412+ /// It is used to clean up loopback devices when the parent process dies.
389413pub async fn run_loopback_cleanup_helper ( device_path : & str ) -> Result < ( ) > {
390414 // Check if we're running as a cleanup helper
391415 if std:: env:: var ( "BOOTC_LOOPBACK_CLEANUP_HELPER" ) . is_err ( ) {
@@ -434,7 +458,9 @@ pub async fn run_loopback_cleanup_helper(device_path: &str) -> Result<()> {
434458 }
435459}
436460
437- /// Parse a string into mibibytes
461+ /// Parse a size string into mebibytes.
462+ ///
463+ /// Supports suffixes: MiB/M, GiB/G, TiB/T.
438464pub fn parse_size_mib ( mut s : & str ) -> Result < u64 > {
439465 let suffixes = [
440466 ( "MiB" , 1u64 ) ,
0 commit comments