mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-05 07:27:46 +00:00
du: migrate winapi
to windows-sys
crate
This commit is contained in:
parent
45dea119fa
commit
c26bf02a04
3 changed files with 14 additions and 21 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -2367,7 +2367,7 @@ dependencies = [
|
||||||
"clap 4.0.17",
|
"clap 4.0.17",
|
||||||
"glob",
|
"glob",
|
||||||
"uucore",
|
"uucore",
|
||||||
"winapi",
|
"windows-sys 0.42.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -22,7 +22,7 @@ clap = { version = "4.0", features = ["wrap_help", "cargo"] }
|
||||||
uucore = { version=">=0.0.16", package="uucore", path="../../uucore" }
|
uucore = { version=">=0.0.16", package="uucore", path="../../uucore" }
|
||||||
|
|
||||||
[target.'cfg(target_os = "windows")'.dependencies]
|
[target.'cfg(target_os = "windows")'.dependencies]
|
||||||
winapi = { version="0.3", features=[] }
|
windows-sys = { version = "0.42.0", default-features = false, features = ["Win32_Storage_FileSystem", "Win32_Foundation"] }
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "du"
|
name = "du"
|
||||||
|
|
|
@ -41,15 +41,12 @@ use uucore::format_usage;
|
||||||
use uucore::parse_glob;
|
use uucore::parse_glob;
|
||||||
use uucore::parse_size::{parse_size, ParseSizeError};
|
use uucore::parse_size::{parse_size, ParseSizeError};
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use winapi::shared::minwindef::{DWORD, LPVOID};
|
use windows_sys::Win32::Foundation::HANDLE;
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use winapi::um::fileapi::{FILE_ID_INFO, FILE_STANDARD_INFO};
|
use windows_sys::Win32::Storage::FileSystem::{
|
||||||
#[cfg(windows)]
|
FileIdInfo, FileStandardInfo, GetFileInformationByHandleEx, FILE_ID_128, FILE_ID_INFO,
|
||||||
use winapi::um::minwinbase::{FileIdInfo, FileStandardInfo};
|
FILE_STANDARD_INFO,
|
||||||
#[cfg(windows)]
|
};
|
||||||
use winapi::um::winbase::GetFileInformationByHandleEx;
|
|
||||||
#[cfg(windows)]
|
|
||||||
use winapi::um::winnt::FILE_ID_128;
|
|
||||||
|
|
||||||
mod options {
|
mod options {
|
||||||
pub const HELP: &str = "help";
|
pub const HELP: &str = "help";
|
||||||
|
@ -208,21 +205,19 @@ fn get_size_on_disk(path: &Path) -> u64 {
|
||||||
Err(_) => return size_on_disk, // opening directories will fail
|
Err(_) => return size_on_disk, // opening directories will fail
|
||||||
};
|
};
|
||||||
|
|
||||||
let handle = file.as_raw_handle();
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut file_info: FILE_STANDARD_INFO = core::mem::zeroed();
|
let mut file_info: FILE_STANDARD_INFO = core::mem::zeroed();
|
||||||
let file_info_ptr: *mut FILE_STANDARD_INFO = &mut file_info;
|
let file_info_ptr: *mut FILE_STANDARD_INFO = &mut file_info;
|
||||||
|
|
||||||
let success = GetFileInformationByHandleEx(
|
let success = GetFileInformationByHandleEx(
|
||||||
handle,
|
file.as_raw_handle() as HANDLE,
|
||||||
FileStandardInfo,
|
FileStandardInfo,
|
||||||
file_info_ptr as LPVOID,
|
file_info_ptr as _,
|
||||||
std::mem::size_of::<FILE_STANDARD_INFO>() as DWORD,
|
std::mem::size_of::<FILE_STANDARD_INFO>() as u32,
|
||||||
);
|
);
|
||||||
|
|
||||||
if success != 0 {
|
if success != 0 {
|
||||||
size_on_disk = *file_info.AllocationSize.QuadPart() as u64;
|
size_on_disk = file_info.AllocationSize as u64;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,17 +233,15 @@ fn get_file_info(path: &Path) -> Option<FileInfo> {
|
||||||
Err(_) => return result,
|
Err(_) => return result,
|
||||||
};
|
};
|
||||||
|
|
||||||
let handle = file.as_raw_handle();
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut file_info: FILE_ID_INFO = core::mem::zeroed();
|
let mut file_info: FILE_ID_INFO = core::mem::zeroed();
|
||||||
let file_info_ptr: *mut FILE_ID_INFO = &mut file_info;
|
let file_info_ptr: *mut FILE_ID_INFO = &mut file_info;
|
||||||
|
|
||||||
let success = GetFileInformationByHandleEx(
|
let success = GetFileInformationByHandleEx(
|
||||||
handle,
|
file.as_raw_handle() as HANDLE,
|
||||||
FileIdInfo,
|
FileIdInfo,
|
||||||
file_info_ptr as LPVOID,
|
file_info_ptr as _,
|
||||||
std::mem::size_of::<FILE_ID_INFO>() as DWORD,
|
std::mem::size_of::<FILE_ID_INFO>() as u32,
|
||||||
);
|
);
|
||||||
|
|
||||||
if success != 0 {
|
if success != 0 {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue