fix(ecstore): gate rustix fs diagnostics on windows (#3267)

* fix(ecstore): gate rustix fs diagnostics on windows

* fix(ecstore): improve windows disk validation diagnostics

* build(deps): bump workspace dependency versions
This commit is contained in:
houseme
2026-06-08 08:05:55 +08:00
committed by GitHub
parent c452dd8ad7
commit c479f3d0cb
5 changed files with 365 additions and 291 deletions
+11
View File
@@ -733,8 +733,13 @@ fn validate_local_physical_disk_independence(pools: &[Endpoints]) -> Result<()>
match crate::disk::endpoint::windows_fallback_local_path(path, &err, "disk independence validation") {
Ok(absolute) => {
let abs_path = absolute.to_string_lossy().into_owned();
diagnostic.canonical_path = Some(abs_path.clone());
if let Ok(serial) = rustfs_utils::os::get_volume_serial_number(&abs_path) {
diagnostic.device_numbers = Some(format!("serial:{serial:#010x}"));
}
match rustfs_utils::os::get_physical_device_ids(&abs_path) {
Ok(ids) => {
diagnostic.device_ids = Some(ids.clone());
for device_id in ids {
device_paths.entry(device_id).or_default().insert(abs_path.clone());
}
@@ -745,6 +750,7 @@ fn validate_local_physical_disk_independence(pools: &[Endpoints]) -> Result<()>
)));
}
}
diagnostics.push(diagnostic);
continue;
}
Err(fallback_err) => {
@@ -769,9 +775,14 @@ fn validate_local_physical_disk_independence(pools: &[Endpoints]) -> Result<()>
};
let canonical_path = canonical.to_string_lossy().into_owned();
diagnostic.canonical_path = Some(canonical_path.clone());
#[cfg(not(windows))]
if let Ok(stat) = rustix::fs::stat(canonical.as_path()) {
diagnostic.device_numbers = Some(format!("{}:{}", rustix::fs::major(stat.st_dev), rustix::fs::minor(stat.st_dev)));
}
#[cfg(windows)]
if let Ok(serial) = rustfs_utils::os::get_volume_serial_number(&canonical_path) {
diagnostic.device_numbers = Some(format!("serial:{serial:#010x}"));
}
let device_ids = rustfs_utils::os::get_physical_device_ids(&canonical_path).map_err(|err| {
Error::other(format!("failed to inspect physical disk for local endpoint '{canonical_path}': {err}"))
})?;
+3 -1
View File
@@ -30,7 +30,9 @@ pub use linux::{check_cross_device_mounts, get_drive_stats, get_info, get_physic
pub use unix::{check_cross_device_mounts, get_drive_stats, get_info, get_physical_device_ids, same_disk};
#[cfg(target_os = "windows")]
pub use windows::{check_cross_device_mounts, get_drive_stats, get_info, get_physical_device_ids, same_disk};
pub use windows::{
check_cross_device_mounts, get_drive_stats, get_info, get_physical_device_ids, get_volume_serial_number, same_disk,
};
#[derive(Debug, Default, PartialEq)]
pub struct IOStats {
+36
View File
@@ -165,6 +165,42 @@ pub fn get_physical_device_ids(disk: &str) -> std::io::Result<Vec<String>> {
Ok(vec![String::from_utf16_lossy(&volume)])
}
/// Returns the volume serial number for the filesystem backing `path`.
///
/// This is the Windows equivalent of Linux's `st_dev` major:minor pair and is
/// useful for diagnostic purposes when validating physical disk independence.
// SAFETY: `path_wide` is a valid null-terminated UTF-16 string and all output
// pointers target initialized stack variables with documented MAX_PATH sizing.
#[allow(unsafe_code)]
pub fn get_volume_serial_number(path: &str) -> std::io::Result<u32> {
let path_wide = to_wide_path(Path::new(path));
let volume = get_volume_name(&path_wide)?;
let mut volume_serial_number = 0u32;
let mut maximum_component_length = 0u32;
let mut file_system_flags = 0u32;
let mut volume_name_buffer = [0u16; MAX_PATH as usize];
let mut file_system_name_buffer = [0u16; MAX_PATH as usize];
// SAFETY:
// 1. `volume` is a valid null-terminated UTF-16 string (volume root path).
// 2. Buffers are allocated with `MAX_PATH` size.
// 3. Pointers to output variables are valid.
unsafe {
GetVolumeInformationW(
windows::core::PCWSTR::from_raw(volume.as_ptr()),
Some(&mut volume_name_buffer),
Some(&mut volume_serial_number),
Some(&mut maximum_component_length),
Some(&mut file_system_flags),
Some(&mut file_system_name_buffer),
)
.map_err(|e| Error::from_raw_os_error(e.code().0))?;
}
Ok(volume_serial_number)
}
pub fn check_cross_device_mounts(_paths: &[String]) -> std::io::Result<()> {
Ok(())
}