@@ -117,6 +117,7 @@ pub struct Partition {
117117 pub parttype : String ,
118118 pub uuid : Option < String > ,
119119 pub name : Option < String > ,
120+ pub bootable : Option < bool > ,
120121}
121122
122123#[ derive( Debug , Deserialize , PartialEq , Eq ) ]
@@ -169,6 +170,10 @@ impl PartitionTable {
169170 pub fn find_partition_of_type ( & self , uuid : & str ) -> Option < & Partition > {
170171 self . partitions . iter ( ) . find ( |p| p. parttype_matches ( uuid) )
171172 }
173+
174+ pub fn find_partition_of_bootable ( & self ) -> Option < & Partition > {
175+ self . partitions . iter ( ) . find ( |p| p. is_bootable ( ) )
176+ }
172177}
173178
174179impl Partition {
@@ -184,6 +189,11 @@ impl Partition {
184189 pub fn parttype_matches ( & self , uuid : & str ) -> bool {
185190 self . parttype . eq_ignore_ascii_case ( uuid)
186191 }
192+
193+ /// Check this partition's bootable property.
194+ pub fn is_bootable ( & self ) -> bool {
195+ self . bootable . unwrap_or ( false )
196+ }
187197}
188198
189199#[ context( "Listing partitions of {dev}" ) ]
@@ -531,6 +541,7 @@ mod test {
531541 parttype : "c12a7328-f81f-11d2-ba4b-00a0c93ec93b" . to_string ( ) , // lowercase ESP UUID
532542 uuid : Some ( "58A4C5F0-BD12-424C-B563-195AC65A25DD" . to_string ( ) ) ,
533543 name : Some ( "EFI System" . to_string ( ) ) ,
544+ bootable : None ,
534545 } ;
535546
536547 // Test exact match (lowercase)
@@ -602,4 +613,47 @@ mod test {
602613
603614 Ok ( ( ) )
604615 }
616+ #[ test]
617+ fn test_find_partition_of_bootable ( ) -> Result < ( ) > {
618+ let fixture = indoc:: indoc! { r#"
619+ {
620+ "partitiontable": {
621+ "label": "dos",
622+ "id": "0xc1748067",
623+ "device": "/dev/mmcblk0",
624+ "unit": "sectors",
625+ "sectorsize": 512,
626+ "partitions": [
627+ {
628+ "node": "/dev/mmcblk0p1",
629+ "start": 2048,
630+ "size": 1026048,
631+ "type": "6",
632+ "bootable": true
633+ },{
634+ "node": "/dev/mmcblk0p2",
635+ "start": 1028096,
636+ "size": 2097152,
637+ "type": "83"
638+ },{
639+ "node": "/dev/mmcblk0p3",
640+ "start": 3125248,
641+ "size": 121610240,
642+ "type": "83"
643+ }
644+ ]
645+ }
646+ }
647+ "# } ;
648+ let table: SfDiskOutput = serde_json:: from_str ( fixture) . unwrap ( ) ;
649+
650+ // Find ESP partition using bootalbe is true
651+ assert_eq ! ( table. partitiontable. label, PartitionType :: Dos ) ;
652+ let esp = table
653+ . partitiontable
654+ . find_partition_of_bootable ( )
655+ . expect ( "bootable partition not found" ) ;
656+ assert_eq ! ( esp. node, "/dev/mmcblk0p1" ) ;
657+ Ok ( ( ) )
658+ }
605659}
0 commit comments