Skip to content

Commit 3ba8106

Browse files
committed
fix: resolve Windows cross-compilation errors
- Add raw_handle() and as_overlapped_ptr() accessors for IOCP types - Replace num_cpus with std::thread::available_parallelism() - Fix visibility for search_multi_drive_filtered (pub(crate)) - Restore execute_index_query function lost in prior refactor - Add missing imports (MftReader, debug macro) - Inline parse_buffer_zero_copy_inner to fix private type access - Remove unused DriveResult import
1 parent 542e8a3 commit 3ba8106

File tree

14 files changed

+80
-40
lines changed

14 files changed

+80
-40
lines changed

crates/uffs-cli/src/commands/raw_io.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,58 @@ pub(super) async fn load_and_filter_data_index_multi(
728728
Ok(final_result)
729729
}
730730

731+
/// Execute query against an `MftIndex` and return results as a `DataFrame`.
732+
///
733+
/// This function uses the fast `IndexQuery` path for filtering and then
734+
/// converts the results to a `DataFrame` for downstream processing.
735+
#[cfg(windows)]
736+
fn execute_index_query(
737+
index: &uffs_mft::MftIndex,
738+
filters: &QueryFilters<'_>,
739+
resolve_paths: bool,
740+
) -> Result<uffs_mft::DataFrame> {
741+
use uffs_core::{IndexQuery, TypeFilter, compile_parsed_pattern};
742+
743+
let mut query = IndexQuery::new(index);
744+
745+
let pattern = compile_parsed_pattern(filters.parsed);
746+
query = query.with_pattern_result(pattern);
747+
748+
if let Some(ext_str) = filters.ext_filter {
749+
let parsed_ext_filter = ExtensionFilter::parse(ext_str)
750+
.map_err(|err| anyhow::anyhow!("Invalid extension filter: {err}"))?;
751+
let exts: Vec<&str> = parsed_ext_filter
752+
.extensions()
753+
.iter()
754+
.map(String::as_str)
755+
.collect();
756+
query = query.extensions(&exts);
757+
}
758+
759+
if filters.files_only {
760+
query = query.with_type_filter(TypeFilter::FilesOnly);
761+
} else if filters.dirs_only {
762+
query = query.with_type_filter(TypeFilter::DirsOnly);
763+
}
764+
765+
if let Some(min) = filters.min_size {
766+
query = query.min_size(min);
767+
}
768+
if let Some(max) = filters.max_size {
769+
query = query.max_size(max);
770+
}
771+
772+
if filters.limit > 0 {
773+
query = query.limit(filters.limit as usize);
774+
}
775+
776+
query = query.case_sensitive(filters.parsed.is_case_sensitive());
777+
query = query.with_resolve_paths(resolve_paths);
778+
779+
let results = query.collect();
780+
results_to_dataframe(index, results, resolve_paths)
781+
}
782+
731783
/// Build and execute the MFT query with all filters applied.
732784
#[tracing::instrument(
733785
level = "debug",

crates/uffs-cli/src/commands/search/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ mod multi_drive;
2828
mod streaming;
2929

3030
#[cfg(windows)]
31-
pub(super) use self::multi_drive::search_multi_drive_filtered;
31+
pub(crate) use self::multi_drive::search_multi_drive_filtered;
3232
#[cfg(windows)]
3333
use self::streaming::search_streaming;
3434

crates/uffs-cli/src/commands/search/multi_drive.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use tokio::task::JoinSet;
99
use tracing::info;
1010
use uffs_mft::IntoLazy;
1111

12-
use super::drive_search::{DriveResult, reorder_drive_column, search_single_drive};
12+
use super::drive_search::{reorder_drive_column, search_single_drive};
1313
use crate::commands::raw_io::{OwnedQueryFilters, QueryFilters};
1414
use crate::commands::{add_drive_progress, create_multi_progress};
1515

@@ -29,7 +29,7 @@ use crate::commands::{add_drive_progress, create_multi_progress};
2929
///
3030
/// * `no_bitmap` - If true, disables MFT bitmap optimization (reads all
3131
/// records).
32-
pub(super) async fn search_multi_drive_filtered(
32+
pub(crate) async fn search_multi_drive_filtered(
3333
drives: &[char],
3434
filters: &QueryFilters<'_>,
3535
needs_paths: bool,

crates/uffs-mft/src/commands/windows/bench.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ pub async fn cmd_bench_all(
388388
hostname: hostname::get()
389389
.map(|h| h.to_string_lossy().to_string())
390390
.unwrap_or_else(|_| "unknown".to_string()),
391-
cpu_count: num_cpus::get(),
391+
cpu_count: std::thread::available_parallelism().map_or(1, |p| p.get()),
392392
uffs_version: env!("CARGO_PKG_VERSION").to_string(),
393393
drives: results,
394394
total_benchmark_time_ms: total_time_ms,

crates/uffs-mft/src/commands/windows/benchmark_mft.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ use crate::display::char_or_dot;
3333
clippy::fn_params_excessive_bools,
3434
reason = "bool params map directly to cli flags"
3535
)]
36+
#[expect(
37+
unsafe_code,
38+
reason = "FFI: SetFilePointerEx, ReadFile for raw volume I/O"
39+
)]
3640
pub async fn cmd_benchmark_mft(drive: char) -> Result<()> {
3741
use std::time::Instant;
3842

crates/uffs-mft/src/commands/windows/info.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use anyhow::{Context, Result};
44
use tracing::info;
55

66
use super::shared::drive_type_label;
7+
use uffs_mft::MftReader;
78
use crate::display::{format_bytes, format_duration, format_number_commas, truncate_string};
89

910
#[cfg(windows)]

crates/uffs-mft/src/io/readers/iocp/reader.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,9 @@ impl IocpMftReader {
237237

238238
// Find which slot completed by matching the overlapped pointer
239239
let mut completed_slot: Option<usize> = None;
240-
for (idx, slot) in in_flight.iter().enumerate() {
240+
for (idx, slot) in in_flight.iter_mut().enumerate() {
241241
if let Some(op) = slot {
242-
let op_ptr = &op.overlapped as *const _ as *mut _;
242+
let op_ptr = op.as_overlapped_ptr();
243243
if op_ptr == overlapped_ptr {
244244
completed_slot = Some(idx);
245245
break;

crates/uffs-mft/src/io/readers/parallel/bulk_iocp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl ParallelMftReader {
210210
// all synchronization is provided by the kernel-managed completion port.
211211
unsafe impl Sync for SendHandle {}
212212

213-
let iocp_handle_raw = SendHandle(iocp.handle.0 as isize);
213+
let iocp_handle_raw = SendHandle(iocp.raw_handle().0 as isize);
214214

215215
// Spawn worker threads
216216
let mut workers = Vec::with_capacity(num_workers);

crates/uffs-mft/src/io/readers/parallel/sliding_window.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,11 @@ impl ParallelMftReader {
248248
let mut overlapped_ptr: *mut windows::Win32::System::IO::OVERLAPPED =
249249
std::ptr::null_mut();
250250

251-
// SAFETY: `iocp.handle` is a live completion port and all out-pointers
251+
// SAFETY: `iocp.raw_handle()` is a live completion port and all out-pointers
252252
// reference writable stack storage for the duration of the wait.
253253
let result = unsafe {
254254
GetQueuedCompletionStatus(
255-
iocp.handle,
255+
iocp.raw_handle(),
256256
&mut bytes_transferred,
257257
&mut completion_key,
258258
&mut overlapped_ptr,

crates/uffs-mft/src/io/readers/parallel/to_index.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,11 @@ impl ParallelMftReader {
271271
let mut overlapped_ptr: *mut windows::Win32::System::IO::OVERLAPPED =
272272
std::ptr::null_mut();
273273

274-
// SAFETY: `iocp.handle` is a live completion port and all out-pointers
274+
// SAFETY: `iocp.raw_handle()` is a live completion port and all out-pointers
275275
// reference writable stack storage for the duration of the wait.
276276
let result = unsafe {
277277
GetQueuedCompletionStatus(
278-
iocp.handle,
278+
iocp.raw_handle(),
279279
&mut bytes_transferred,
280280
&mut completion_key,
281281
&mut overlapped_ptr,

0 commit comments

Comments
 (0)