diff --git a/cryptpilot-core/src/fs/mkfs.rs b/cryptpilot-core/src/fs/mkfs.rs index e098bfa..58d8f6e 100644 --- a/cryptpilot-core/src/fs/mkfs.rs +++ b/cryptpilot-core/src/fs/mkfs.rs @@ -191,7 +191,12 @@ pub async fn force_mkfs( Ok(()) } -pub async fn is_empty_disk(device_path: &Path) -> Result { +/// Checks whether the device contains valuable data (i.e., a known filesystem). +/// +/// - Partition tables (e.g., PTTYPE="atari") are ignored and treated as "no valuable data". +/// - If `fs_hint` is `Some`, and the expected filesystem is not detected, returns an error. +/// - If `fs_hint` is `None`, returns `true` if something detected on the device. +pub async fn has_valuable_data(device_path: &Path, fs_hint: Option) -> Result { Command::new("blkid") .arg("-p") .arg(device_path) @@ -199,31 +204,54 @@ pub async fn is_empty_disk(device_path: &Path) -> Result { .run_with_status_checker(|code, stdout, stderr| { match code { 0 => { - // Found signatures, check if they are ext4, xfs, vfat or swap let output = String::from_utf8_lossy(&stdout); - let has_fs = output.contains("TYPE=\"ext4\"") - || output.contains("TYPE=\"xfs\"") - || output.contains("TYPE=\"vfat\"") - || output.contains("TYPE=\"swap\""); - Ok(!has_fs) // Return true if NOT one of these filesystems (empty or other fs) + + match fs_hint { + Some(expected_fs) => { + let expected_str = match expected_fs { + MakeFsType::Swap => "swap", + MakeFsType::Ext4 => "ext4", + MakeFsType::Xfs => "xfs", + MakeFsType::Vfat => "vfat", + }; + + if output.contains(&format!("TYPE=\"{}\"", expected_str)) { + Ok(true) + } else { + // Something else detected (may have partition table, unknown FS, etc.) + bail!( + "Something else on {device_path:?} is detected, but expected '{expected_str}', found blkid output '{}'", + output.trim() + ); + } + } + None => { + // Check if it's mistakenly identified as PTTYPE="atari" partition table. + // See: https://bugs.launchpad.net/ubuntu/+source/util-linux/+bug/2015355 + if output.contains("PTTYPE=\"atari\"") { + tracing::debug!("Found PTTYPE=\"atari\" partition table on {device_path:?}, treating as no valuable data"); + Ok(false) + }else{ + // Log which one was found (for debug) + tracing::debug!("Found filesystem signature on {device_path:?}, blkid output: {}", output.trim()); + Ok(true) + } + } + } + } + 2 => { + // No signatures found + Ok(false) } - 2 => Ok(true), // No signatures found _ => { let stdout = String::from_utf8_lossy(&stdout); let stderr = String::from_utf8_lossy(&stderr); - if stdout.contains("Input/output error") - || stderr.contains("Input/output error") - { - // If we can't even read the disk, treat it as "uninitialized" - Ok(true) - } else { - bail!( - "blkid failed with exit code {}: stdout={}, stderr={}", - code, - stdout, - stderr - ) - } + bail!( + "blkid failed with exit code {}: stdout='{}', stderr='{}'", + code, + stdout.trim(), + stderr.trim() + ); } } }) diff --git a/cryptpilot-crypt/src/cmd/open.rs b/cryptpilot-crypt/src/cmd/open.rs index f80ead8..bb3884c 100644 --- a/cryptpilot-crypt/src/cmd/open.rs +++ b/cryptpilot-crypt/src/cmd/open.rs @@ -58,7 +58,11 @@ pub async fn open_for_specific_volume(volume_config: &VolumeConfig, check_fs: bo // Check if filesystem is ready if check_fs && volume_config.extra_config.makefs.is_some() - && cryptpilot::fs::mkfs::is_empty_disk(&volume_config.volume_path()).await? + && !cryptpilot::fs::mkfs::has_valuable_data( + &volume_config.volume_path(), + volume_config.extra_config.makefs, + ) + .await? { // TODO: replace with RAII here let _ = cryptpilot::fs::luks2::close(&volume_config.volume).await; diff --git a/cryptpilot-crypt/tests/volume_tests.rs b/cryptpilot-crypt/tests/volume_tests.rs index d794a48..ff30e3a 100644 --- a/cryptpilot-crypt/tests/volume_tests.rs +++ b/cryptpilot-crypt/tests/volume_tests.rs @@ -164,7 +164,11 @@ pub async fn run_test_on_volume(config_str: &str, use_external_suite: bool) -> R open_then(&volume_config, |volume_config| async move { if !matches!(volume_config.extra_config.integrity, Some(true)) { assert!( - !cryptpilot::fs::mkfs::is_empty_disk(&volume_config.volume_path()).await? + cryptpilot::fs::mkfs::has_valuable_data( + &volume_config.volume_path(), + volume_config.extra_config.makefs + ) + .await? ); } Ok(()) @@ -221,7 +225,11 @@ pub async fn run_test_on_volume(config_str: &str, use_external_suite: bool) -> R open_then(&volume_config, |volume_config| async move { if !matches!(volume_config.extra_config.integrity, Some(true)) { assert!( - !cryptpilot::fs::mkfs::is_empty_disk(&volume_config.volume_path()).await? + cryptpilot::fs::mkfs::has_valuable_data( + &volume_config.volume_path(), + volume_config.extra_config.makefs + ) + .await? ); } Ok(()) @@ -288,14 +296,26 @@ pub async fn run_test_on_volume(config_str: &str, use_external_suite: bool) -> R // Just Open it and do nothing but checking open_then(&volume_config, |volume_config| async move { // Add assertion to check if disk is empty - assert!(cryptpilot::fs::mkfs::is_empty_disk(&volume_config.volume_path()).await?); + assert!( + !cryptpilot::fs::mkfs::has_valuable_data( + &volume_config.volume_path(), + volume_config.extra_config.makefs + ) + .await? + ); Ok(()) }) .await?; // Test again open_then(&volume_config, |volume_config| async move { // Add assertion to check if disk is still empty after re-open - assert!(cryptpilot::fs::mkfs::is_empty_disk(&volume_config.volume_path()).await?); + assert!( + !cryptpilot::fs::mkfs::has_valuable_data( + &volume_config.volume_path(), + volume_config.extra_config.makefs + ) + .await? + ); Ok(()) }) .await?; diff --git a/debian/changelog b/debian/changelog deleted file mode 100644 index 46ab4ff..0000000 --- a/debian/changelog +++ /dev/null @@ -1,31 +0,0 @@ -cryptpilot (0.3.1-1) unstable; urgency=medium - - * feat(kbs): support both one-shot and daemon modes for CDH - * refactor(kbs): implement ttrpc client for daemon mode - * fix(blktrace): fix invalid casting on aarch64 - * build: migrate CI to native aarch64 runners - * chore: rename source tarball to include vendored-source suffix - * fix(init): add interactive protection and RAII volume management - * fix(mkfs): use blkid -p for better empty disk detection - - -- Kun Lai Thu, 15 Jan 2026 00:00:00 +0800 - -cryptpilot (0.3.0-1) unstable; urgency=medium - - * feat(cryptpilot-crypt): add JSON output and volume filtering to show command - * test: support running integration tests without external binaries - * docs: restructure documentation and add Chinese translations - * refactor: split monolithic package into cryptpilot-fde and cryptpilot-crypt - * refactor(cryptpilot): improve tracing and logging - * build(cryptpilot-verity): split cryptpilot-verity into separate package - - -- Kun Lai Mon, 13 Jan 2026 00:00:00 +0800 - -cryptpilot (0.2.10-1) unstable; urgency=medium - - * Initial Debian package release. - * fde: support ubuntu GRUB configuration - * cryptpilot-convert: add Debian/Ubuntu system support - * build: add Debian/Ubuntu package building support - - -- Kun Lai Thu, 09 Jan 2026 00:00:00 +0800 diff --git a/debian/rules b/debian/rules index 1551cca..05aff71 100755 --- a/debian/rules +++ b/debian/rules @@ -8,9 +8,22 @@ export DEB_BUILD_MAINT_OPTIONS = hardening=+all VENDOR_DIR = $(CURDIR)/vendor USE_OFFLINE = $(shell test -d $(VENDOR_DIR) && echo "--offline") +# Extract version from Cargo.toml +# Use awk to find version under [workspace.package] section +VERSION = $(shell awk '/\[workspace\.package\]/{f=1} f && /^version = \"/{gsub(/[^0-9.]/, "", $$3); print $$3; exit}' Cargo.toml) + %: dh $@ +override_dh_auto_configure: + # Auto-generate changelog from Cargo.toml version + @echo "Generating changelog for version $$(VERSION)" + @echo "cryptpilot ($$(VERSION)-1) unstable; urgency=medium" > debian/changelog + @echo "" >> debian/changelog + @echo " * Automated build from Cargo.toml" >> debian/changelog + @echo "" >> debian/changelog + @echo " -- Auto Builder $$(date -R)" >> debian/changelog + override_dh_auto_build: # Build cryptpilot-fde cargo install --path $(CURDIR)/cryptpilot-fde --bin cryptpilot-fde \