Skip to content

Commit 83f4922

Browse files
committed
anylinuxfs list for images seems to work now
1 parent 80787db commit 83f4922

2 files changed

Lines changed: 43 additions & 9 deletions

File tree

anylinuxfs/src/devinfo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl DevInfo {
160160
vm_path: "/dev/vda".to_owned(),
161161
fs_driver: None,
162162
da_info: diskutil::DiskInfo::default(),
163-
size_bytes: None,
163+
size_bytes: Some(whole_probe.get_size() as u64),
164164
}];
165165

166166
if let Ok(mut partitions) = whole_probe.get_partitions() {

anylinuxfs/src/diskutil.rs

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -476,20 +476,40 @@ pub fn list_partitions(
476476
let normalized_pt = normalize_pt_type(pt_type);
477477
let whole_size = whole.size().map(format_partition_size).unwrap_or_default();
478478
*entry.scheme_mut() = format!(
479-
" 0: {:>26} {:<23} {:<10} {}",
479+
" 0: {:>26} {:<22} +{:<10} {}",
480480
normalized_pt, "", whole_size, image_name,
481481
);
482-
for (i, dev) in probe_devs[1..].iter().enumerate() {
483-
let fs_type = dev.fs_type().unwrap_or("");
482+
for (i, dev_info) in probe_devs[1..].iter().enumerate() {
483+
let fs_type = dev_info.fs_type().unwrap_or("");
484484

485485
// Filter by filesystem type to match diskutil behavior
486486
if !filter.fs_types.iter().any(|t| t == &fs_type) {
487487
continue;
488488
}
489489

490-
let label = dev.label().unwrap_or("");
490+
let is_enc = fs_type == "crypto_LUKS" || fs_type == "BitLocker";
491+
let is_raid = fs_type == "linux_raid_member";
492+
let is_lvm = fs_type == "LVM2_member";
493+
494+
if is_raid {
495+
assemble_raid = true;
496+
}
497+
498+
if is_lvm || is_raid || (enc_partitions.is_some() && is_enc) {
499+
pv_dev_infos.push(dev_info.to_owned());
500+
pv_dev_idents.push(image_name.clone());
501+
502+
if decrypt_all && is_enc {
503+
all_enc_partitions.push(path.to_owned());
504+
}
505+
}
506+
507+
let label = dev_info.label().unwrap_or("");
491508
let truncated_label = trunc_with_ellipsis(label, 23);
492-
let size_str = dev.size().map(format_partition_size).unwrap_or_default();
509+
let size_str = dev_info
510+
.size()
511+
.map(format_partition_size)
512+
.unwrap_or_default();
493513
let ident = format!("{}@s{}", image_name, i + 1);
494514
entry.partitions_mut().push(format!(
495515
"{:>4}: {:>26} {:<23} {:<10} {}",
@@ -502,13 +522,27 @@ pub fn list_partitions(
502522
}
503523
} else {
504524
// Whole-disk image without partition table
505-
let fs_type = whole.fs_type().unwrap_or("");
525+
let dev_info = whole;
526+
let fs_type = dev_info.fs_type().unwrap_or("");
506527

507528
// Filter by filesystem type to match diskutil behavior
508529
if filter.fs_types.iter().any(|t| t == &fs_type) {
509-
let label = whole.label().unwrap_or("");
530+
let is_enc = fs_type == "crypto_LUKS" || fs_type == "BitLocker";
531+
if fs_type == "LVM2_member" || (enc_partitions.is_some() && is_enc) {
532+
pv_dev_infos.push(dev_info.clone());
533+
pv_dev_idents.push(image_name.clone());
534+
535+
if decrypt_all && is_enc {
536+
all_enc_partitions.push(path.to_owned());
537+
}
538+
}
539+
540+
let label = dev_info.label().unwrap_or("");
510541
let truncated_label = trunc_with_ellipsis(label, 23);
511-
let size_str = whole.size().map(format_partition_size).unwrap_or_default();
542+
let size_str = dev_info
543+
.size()
544+
.map(format_partition_size)
545+
.unwrap_or_default();
512546
entry.partitions_mut().push(format!(
513547
" 0: {:>26} {:<23} {:<10} {}",
514548
fs_type, truncated_label, size_str, image_name,

0 commit comments

Comments
 (0)