@@ -98,21 +98,7 @@ pub fn scan_gpt_partitions(disk: &mut Disk) -> AxResult<Vec<PartitionInfo>> {
9898 }
9999 }
100100
101- // If GPT parsing fails, try MBR
102- match parse_mbr_partitions ( disk) {
103- Ok ( partitions) if !partitions. is_empty ( ) => {
104- info ! ( "Found {} MBR partitions" , partitions. len( ) ) ;
105- return Ok ( partitions) ;
106- }
107- Ok ( _) => {
108- info ! ( "No MBR partitions found" ) ;
109- }
110- Err ( e) => {
111- warn ! ( "Failed to parse MBR: {:?}" , e) ;
112- }
113- }
114-
115- // If both GPT and MBR fail, treat the whole disk as a single partition
101+ // If both GPT fail, treat the whole disk as a single partition
116102 warn ! ( "No partition table found, treating whole disk as single partition" ) ;
117103 let filesystem_type = detect_filesystem_type ( disk, 0 ) ;
118104 let partition = PartitionInfo {
@@ -164,7 +150,6 @@ fn parse_gpt_partitions(disk: &mut Disk) -> AxResult<Vec<PartitionInfo>> {
164150 partition_entry_array_crc32 : header_data[ 88 ..92 ] . try_into ( ) . unwrap ( ) ,
165151 } ;
166152
167- let header_size = u32:: from_le_bytes ( header. header_size ) ;
168153 let partition_entry_lba = u64:: from_le_bytes ( header. partition_entry_lba ) ;
169154 let number_of_partition_entries = u32:: from_le_bytes ( header. number_of_partition_entries ) ;
170155 let size_of_partition_entry = u32:: from_le_bytes ( header. size_of_partition_entry ) ;
@@ -223,14 +208,6 @@ fn parse_gpt_partitions(disk: &mut Disk) -> AxResult<Vec<PartitionInfo>> {
223208 continue ;
224209 } ;
225210
226- // Debug: Print partition type GUID for all non-empty partitions
227- if !entry. partition_type_guid . iter ( ) . all ( |& b| b == 0 ) {
228- debug ! (
229- "Partition {}: type GUID: {:?}" ,
230- i, entry. partition_type_guid
231- ) ;
232- }
233-
234211 // Check if partition is in use (all zeros means unused)
235212 if entry. partition_type_guid . iter ( ) . all ( |& b| b == 0 ) {
236213 continue ;
@@ -240,11 +217,6 @@ fn parse_gpt_partitions(disk: &mut Disk) -> AxResult<Vec<PartitionInfo>> {
240217 let ending_lba = u64:: from_le_bytes ( entry. ending_lba ) ;
241218 let size_bytes = ( ending_lba - starting_lba + 1 ) * 512 ;
242219
243- debug ! (
244- "Partition {}: LBA range {} - {}, size {} bytes" ,
245- i, starting_lba, ending_lba, size_bytes
246- ) ;
247-
248220 // Convert partition name from UTF-16LE to UTF-8
249221 let name_str = {
250222 let mut name_utf16 = [ 0u16 ; 36 ] ;
@@ -284,70 +256,8 @@ fn parse_gpt_partitions(disk: &mut Disk) -> AxResult<Vec<PartitionInfo>> {
284256 } ;
285257
286258 info ! (
287- "Found GPT partition {}: '{}' ({} bytes) with filesystem: {:?}, UUID: {:?}" ,
288- partition. index,
289- partition. name,
290- partition. size_bytes,
291- partition. filesystem_type,
292- partition. filesystem_uuid
293- ) ;
294-
295- partitions. push ( partition) ;
296- }
297-
298- Ok ( partitions)
299- }
300-
301- /// Parse MBR partition table
302- fn parse_mbr_partitions ( disk : & mut Disk ) -> AxResult < Vec < PartitionInfo > > {
303- let mut partitions = Vec :: new ( ) ;
304-
305- // Read MBR from LBA 0
306- let mut mbr_data = [ 0u8 ; 512 ] ;
307- disk. set_position ( 0 ) ;
308- if read_exact ( disk, & mut mbr_data) . is_err ( ) {
309- return ax_err ! ( InvalidData , "Failed to read MBR" ) ;
310- }
311-
312- // Check for valid MBR signature
313- if mbr_data[ 510 ] != 0x55 || mbr_data[ 511 ] != 0xAA {
314- return ax_err ! ( InvalidData , "Invalid MBR signature" ) ;
315- }
316-
317- // Parse partition entries (4 entries at offset 0x1BE)
318- for i in 0 ..4 {
319- let entry_offset = 0x1BE + i * 16 ;
320- let entry = & mbr_data[ entry_offset..entry_offset + 16 ] ;
321-
322- // Check if partition is active (non-zero type)
323- if entry[ 4 ] == 0 {
324- continue ;
325- }
326-
327- let starting_lba = u32:: from_le_bytes ( [ entry[ 8 ] , entry[ 9 ] , entry[ 10 ] , entry[ 11 ] ] ) as u64 ;
328- let size_sectors = u32:: from_le_bytes ( [ entry[ 12 ] , entry[ 13 ] , entry[ 14 ] , entry[ 15 ] ] ) as u64 ;
329- let ending_lba = starting_lba + size_sectors - 1 ;
330- let size_bytes = size_sectors * 512 ;
331-
332- // Detect filesystem type
333- let filesystem_type = detect_filesystem_type ( disk, starting_lba) ;
334-
335- let partition = PartitionInfo {
336- index : i as u32 ,
337- name : format ! ( "mbr{}" , i + 1 ) ,
338- partition_type_guid : [ 0 ; 16 ] ,
339- unique_partition_guid : [ 0 ; 16 ] ,
340- filesystem_uuid : None ,
341-
342- starting_lba,
343- ending_lba,
344- size_bytes,
345- filesystem_type,
346- } ;
347-
348- info ! (
349- "Found MBR partition {}: '{}' ({} bytes) with filesystem: {:?}" ,
350- partition. index, partition. name, partition. size_bytes, partition. filesystem_type
259+ "Found GPT partition {}: '{}' ({} bytes) with filesystem: {:?}" ,
260+ partition. index, partition. name, partition. size_bytes, partition. filesystem_type,
351261 ) ;
352262
353263 partitions. push ( partition) ;
0 commit comments