mirror of
https://github.com/uutils/coreutils
synced 2025-01-05 17:59:00 +00:00
Merge pull request #4065 from niyaznigmatullin/migrate_winapi_windows-sys
Migrate from `winapi` to `windows-sys`
This commit is contained in:
commit
ab3994c221
23 changed files with 177 additions and 156 deletions
96
Cargo.lock
generated
96
Cargo.lock
generated
|
@ -869,7 +869,7 @@ dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"libc",
|
"libc",
|
||||||
"redox_syscall",
|
"redox_syscall",
|
||||||
"windows-sys",
|
"windows-sys 0.36.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1264,7 +1264,7 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"log",
|
"log",
|
||||||
"wasi",
|
"wasi",
|
||||||
"windows-sys",
|
"windows-sys 0.36.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1469,7 +1469,7 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"redox_syscall",
|
"redox_syscall",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"windows-sys",
|
"windows-sys 0.36.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1790,7 +1790,7 @@ dependencies = [
|
||||||
"io-lifetimes",
|
"io-lifetimes",
|
||||||
"libc",
|
"libc",
|
||||||
"linux-raw-sys",
|
"linux-raw-sys",
|
||||||
"windows-sys",
|
"windows-sys 0.36.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -2029,7 +2029,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8440c860cf79def6164e4a0a983bcc2305d82419177a0e0c71930d049e3ac5a1"
|
checksum = "8440c860cf79def6164e4a0a983bcc2305d82419177a0e0c71930d049e3ac5a1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"rustix",
|
"rustix",
|
||||||
"windows-sys",
|
"windows-sys 0.36.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -2276,7 +2276,6 @@ dependencies = [
|
||||||
"selinux",
|
"selinux",
|
||||||
"uucore",
|
"uucore",
|
||||||
"walkdir",
|
"walkdir",
|
||||||
"winapi",
|
|
||||||
"xattr",
|
"xattr",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -2309,7 +2308,7 @@ dependencies = [
|
||||||
"clap 4.0.17",
|
"clap 4.0.17",
|
||||||
"libc",
|
"libc",
|
||||||
"uucore",
|
"uucore",
|
||||||
"winapi",
|
"windows-sys 0.42.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -2368,7 +2367,7 @@ dependencies = [
|
||||||
"clap 4.0.17",
|
"clap 4.0.17",
|
||||||
"glob",
|
"glob",
|
||||||
"uucore",
|
"uucore",
|
||||||
"winapi",
|
"windows-sys 0.42.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -2499,7 +2498,7 @@ dependencies = [
|
||||||
"clap 4.0.17",
|
"clap 4.0.17",
|
||||||
"hostname",
|
"hostname",
|
||||||
"uucore",
|
"uucore",
|
||||||
"winapi",
|
"windows-sys 0.42.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -2801,7 +2800,7 @@ dependencies = [
|
||||||
"remove_dir_all 0.7.0",
|
"remove_dir_all 0.7.0",
|
||||||
"uucore",
|
"uucore",
|
||||||
"walkdir",
|
"walkdir",
|
||||||
"winapi",
|
"windows-sys 0.42.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -2944,7 +2943,7 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"nix",
|
"nix",
|
||||||
"uucore",
|
"uucore",
|
||||||
"winapi",
|
"windows-sys 0.42.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -2969,8 +2968,8 @@ dependencies = [
|
||||||
"notify",
|
"notify",
|
||||||
"same-file",
|
"same-file",
|
||||||
"uucore",
|
"uucore",
|
||||||
"winapi",
|
|
||||||
"winapi-util",
|
"winapi-util",
|
||||||
|
"windows-sys 0.42.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -3011,7 +3010,7 @@ dependencies = [
|
||||||
"filetime",
|
"filetime",
|
||||||
"time",
|
"time",
|
||||||
"uucore",
|
"uucore",
|
||||||
"winapi",
|
"windows-sys 0.42.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -3148,7 +3147,7 @@ dependencies = [
|
||||||
"clap 4.0.17",
|
"clap 4.0.17",
|
||||||
"libc",
|
"libc",
|
||||||
"uucore",
|
"uucore",
|
||||||
"winapi",
|
"windows-sys 0.42.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -3181,8 +3180,8 @@ dependencies = [
|
||||||
"uucore_procs",
|
"uucore_procs",
|
||||||
"walkdir",
|
"walkdir",
|
||||||
"wild",
|
"wild",
|
||||||
"winapi",
|
|
||||||
"winapi-util",
|
"winapi-util",
|
||||||
|
"windows-sys 0.42.0",
|
||||||
"z85",
|
"z85",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -3334,43 +3333,100 @@ version = "0.36.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2"
|
checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows_aarch64_msvc",
|
"windows_aarch64_msvc 0.36.1",
|
||||||
"windows_i686_gnu",
|
"windows_i686_gnu 0.36.1",
|
||||||
"windows_i686_msvc",
|
"windows_i686_msvc 0.36.1",
|
||||||
"windows_x86_64_gnu",
|
"windows_x86_64_gnu 0.36.1",
|
||||||
"windows_x86_64_msvc",
|
"windows_x86_64_msvc 0.36.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-sys"
|
||||||
|
version = "0.42.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
|
||||||
|
dependencies = [
|
||||||
|
"windows_aarch64_gnullvm",
|
||||||
|
"windows_aarch64_msvc 0.42.0",
|
||||||
|
"windows_i686_gnu 0.42.0",
|
||||||
|
"windows_i686_msvc 0.42.0",
|
||||||
|
"windows_x86_64_gnu 0.42.0",
|
||||||
|
"windows_x86_64_gnullvm",
|
||||||
|
"windows_x86_64_msvc 0.42.0",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_gnullvm"
|
||||||
|
version = "0.42.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_aarch64_msvc"
|
name = "windows_aarch64_msvc"
|
||||||
version = "0.36.1"
|
version = "0.36.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47"
|
checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_msvc"
|
||||||
|
version = "0.42.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_i686_gnu"
|
name = "windows_i686_gnu"
|
||||||
version = "0.36.1"
|
version = "0.36.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6"
|
checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_gnu"
|
||||||
|
version = "0.42.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_i686_msvc"
|
name = "windows_i686_msvc"
|
||||||
version = "0.36.1"
|
version = "0.36.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024"
|
checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_msvc"
|
||||||
|
version = "0.42.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_x86_64_gnu"
|
name = "windows_x86_64_gnu"
|
||||||
version = "0.36.1"
|
version = "0.36.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1"
|
checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnu"
|
||||||
|
version = "0.42.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnullvm"
|
||||||
|
version = "0.42.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows_x86_64_msvc"
|
name = "windows_x86_64_msvc"
|
||||||
version = "0.36.1"
|
version = "0.36.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680"
|
checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_msvc"
|
||||||
|
version = "0.42.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "xattr"
|
name = "xattr"
|
||||||
version = "0.2.3"
|
version = "0.2.3"
|
||||||
|
|
|
@ -74,6 +74,13 @@ skip = [
|
||||||
{ name = "clap", version = "=3.2.22" },
|
{ name = "clap", version = "=3.2.22" },
|
||||||
# bindgen (via selinux-sys & fts-sys)
|
# bindgen (via selinux-sys & fts-sys)
|
||||||
{ name = "clap_lex", version = "=0.2.4" },
|
{ name = "clap_lex", version = "=0.2.4" },
|
||||||
|
# windows-sys (via terminal_size, crossterm -> parking_lot, notify -> filetime)
|
||||||
|
{ name = "windows-sys", version = "=0.36.1" },
|
||||||
|
{ name = "windows_aarch64_msvc", version = "=0.36.1" },
|
||||||
|
{ name = "windows_i686_gnu", version = "=0.36.1" },
|
||||||
|
{ name = "windows_i686_msvc", version = "=0.36.1" },
|
||||||
|
{ name = "windows_x86_64_gnu", version = "=0.36.1" },
|
||||||
|
{ name = "windows_x86_64_msvc", version = "=0.36.1" },
|
||||||
]
|
]
|
||||||
# spell-checker: enable
|
# spell-checker: enable
|
||||||
|
|
||||||
|
|
|
@ -27,9 +27,6 @@ selinux = { version="0.3", optional=true }
|
||||||
uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["entries", "fs", "perms", "mode"] }
|
uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["entries", "fs", "perms", "mode"] }
|
||||||
walkdir = "2.2"
|
walkdir = "2.2"
|
||||||
|
|
||||||
[target.'cfg(target_os = "windows")'.dependencies]
|
|
||||||
winapi = { version="0.3", features=["fileapi"] }
|
|
||||||
|
|
||||||
[target.'cfg(unix)'.dependencies]
|
[target.'cfg(unix)'.dependencies]
|
||||||
xattr="0.2.3"
|
xattr="0.2.3"
|
||||||
exacl= { version = "0.9.0", optional=true }
|
exacl= { version = "0.9.0", optional=true }
|
||||||
|
|
|
@ -23,7 +23,7 @@ uucore = { version=">=0.0.16", package="uucore", path="../../uucore" }
|
||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
winapi = { version = "0.3", features = ["minwinbase", "sysinfoapi", "minwindef"] }
|
windows-sys = { version = "0.42.0", default-features = false, features = ["Win32_Foundation", "Win32_System_SystemInformation"] }
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "date"
|
name = "date"
|
||||||
|
|
|
@ -23,10 +23,7 @@ use uucore::error::FromIo;
|
||||||
use uucore::error::{UResult, USimpleError};
|
use uucore::error::{UResult, USimpleError};
|
||||||
use uucore::{format_usage, show_error};
|
use uucore::{format_usage, show_error};
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use winapi::{
|
use windows_sys::Win32::{Foundation::SYSTEMTIME, System::SystemInformation::SetSystemTime};
|
||||||
shared::minwindef::WORD,
|
|
||||||
um::{minwinbase::SYSTEMTIME, sysinfoapi::SetSystemTime},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Options
|
// Options
|
||||||
const DATE: &str = "date";
|
const DATE: &str = "date";
|
||||||
|
@ -409,16 +406,16 @@ fn set_system_datetime(date: DateTime<Utc>) -> UResult<()> {
|
||||||
/// https://docs.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-systemtime
|
/// https://docs.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-systemtime
|
||||||
fn set_system_datetime(date: DateTime<Utc>) -> UResult<()> {
|
fn set_system_datetime(date: DateTime<Utc>) -> UResult<()> {
|
||||||
let system_time = SYSTEMTIME {
|
let system_time = SYSTEMTIME {
|
||||||
wYear: date.year() as WORD,
|
wYear: date.year() as u16,
|
||||||
wMonth: date.month() as WORD,
|
wMonth: date.month() as u16,
|
||||||
// Ignored
|
// Ignored
|
||||||
wDayOfWeek: 0,
|
wDayOfWeek: 0,
|
||||||
wDay: date.day() as WORD,
|
wDay: date.day() as u16,
|
||||||
wHour: date.hour() as WORD,
|
wHour: date.hour() as u16,
|
||||||
wMinute: date.minute() as WORD,
|
wMinute: date.minute() as u16,
|
||||||
wSecond: date.second() as WORD,
|
wSecond: date.second() as u16,
|
||||||
// TODO: be careful of leap seconds - valid range is [0, 999] - how to handle?
|
// TODO: be careful of leap seconds - valid range is [0, 999] - how to handle?
|
||||||
wMilliseconds: ((date.nanosecond() / 1_000_000) % 1000) as WORD,
|
wMilliseconds: ((date.nanosecond() / 1_000_000) % 1000) as u16,
|
||||||
};
|
};
|
||||||
|
|
||||||
let result = unsafe { SetSystemTime(&system_time) };
|
let result = unsafe { SetSystemTime(&system_time) };
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -20,11 +20,11 @@ hostname = { version = "0.3", features = ["set"] }
|
||||||
uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["wide"] }
|
uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["wide"] }
|
||||||
|
|
||||||
[target.'cfg(target_os = "windows")'.dependencies]
|
[target.'cfg(target_os = "windows")'.dependencies]
|
||||||
winapi = { version="0.3", features=["sysinfoapi", "winsock2"] }
|
windows-sys = { version = "0.42.0", default-features = false, features = ["Win32_Networking_WinSock", "Win32_Foundation"] }
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "hostname"
|
name = "hostname"
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|
||||||
[package.metadata.cargo-udeps.ignore]
|
[package.metadata.cargo-udeps.ignore]
|
||||||
normal = ["uucore_procs", "winapi"]
|
normal = ["uucore_procs"]
|
||||||
|
|
|
@ -32,15 +32,14 @@ static OPT_HOST: &str = "host";
|
||||||
mod wsa {
|
mod wsa {
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
use winapi::shared::minwindef::MAKEWORD;
|
use windows_sys::Win32::Networking::WinSock::{WSACleanup, WSAStartup, WSADATA};
|
||||||
use winapi::um::winsock2::{WSACleanup, WSAStartup, WSADATA};
|
|
||||||
|
|
||||||
pub(super) struct WsaHandle(());
|
pub(super) struct WsaHandle(());
|
||||||
|
|
||||||
pub(super) fn start() -> io::Result<WsaHandle> {
|
pub(super) fn start() -> io::Result<WsaHandle> {
|
||||||
let err = unsafe {
|
let err = unsafe {
|
||||||
let mut data = std::mem::MaybeUninit::<WSADATA>::uninit();
|
let mut data = std::mem::MaybeUninit::<WSADATA>::uninit();
|
||||||
WSAStartup(MAKEWORD(2, 2), data.as_mut_ptr())
|
WSAStartup(0x0202, data.as_mut_ptr())
|
||||||
};
|
};
|
||||||
if err != 0 {
|
if err != 0 {
|
||||||
Err(io::Error::from_raw_os_error(err))
|
Err(io::Error::from_raw_os_error(err))
|
||||||
|
|
|
@ -21,7 +21,7 @@ remove_dir_all = "0.7.0"
|
||||||
uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["fs"] }
|
uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["fs"] }
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
winapi = { version="0.3", features=[] }
|
windows-sys = { version = "0.42.0", default-features = false, features = ["Win32_Storage_FileSystem"] }
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "rm"
|
name = "rm"
|
||||||
|
|
|
@ -510,7 +510,7 @@ use std::os::windows::prelude::MetadataExt;
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
fn is_symlink_dir(metadata: &fs::Metadata) -> bool {
|
fn is_symlink_dir(metadata: &fs::Metadata) -> bool {
|
||||||
use winapi::um::winnt::FILE_ATTRIBUTE_DIRECTORY;
|
use windows_sys::Win32::Storage::FileSystem::FILE_ATTRIBUTE_DIRECTORY;
|
||||||
|
|
||||||
metadata.file_type().is_symlink()
|
metadata.file_type().is_symlink()
|
||||||
&& ((metadata.file_attributes() & FILE_ATTRIBUTE_DIRECTORY) != 0)
|
&& ((metadata.file_attributes() & FILE_ATTRIBUTE_DIRECTORY) != 0)
|
||||||
|
|
|
@ -23,11 +23,11 @@ uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=[
|
||||||
nix = "0.25"
|
nix = "0.25"
|
||||||
|
|
||||||
[target.'cfg(target_os = "windows")'.dependencies]
|
[target.'cfg(target_os = "windows")'.dependencies]
|
||||||
winapi = { version = "0.3", features = ["errhandlingapi", "fileapi", "handleapi", "std", "winbase", "winerror"] }
|
windows-sys = { version = "0.42.0", default-features = false, features = ["Win32_Storage_FileSystem", "Win32_System_WindowsProgramming", "Win32_Foundation"] }
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "sync"
|
name = "sync"
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|
||||||
[package.metadata.cargo-udeps.ignore]
|
[package.metadata.cargo-udeps.ignore]
|
||||||
normal = ["uucore_procs", "winapi"]
|
normal = ["uucore_procs"]
|
||||||
|
|
|
@ -70,29 +70,27 @@ mod platform {
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
mod platform {
|
mod platform {
|
||||||
extern crate winapi;
|
|
||||||
use self::winapi::shared::minwindef;
|
|
||||||
use self::winapi::shared::winerror;
|
|
||||||
use self::winapi::um::handleapi;
|
|
||||||
use self::winapi::um::winbase;
|
|
||||||
use self::winapi::um::winnt;
|
|
||||||
use std::fs::OpenOptions;
|
use std::fs::OpenOptions;
|
||||||
use std::os::windows::prelude::*;
|
use std::os::windows::prelude::*;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use uucore::crash;
|
use uucore::crash;
|
||||||
use uucore::wide::{FromWide, ToWide};
|
use uucore::wide::{FromWide, ToWide};
|
||||||
|
use windows_sys::Win32::Foundation::{
|
||||||
|
GetLastError, ERROR_NO_MORE_FILES, HANDLE, INVALID_HANDLE_VALUE, MAX_PATH,
|
||||||
|
};
|
||||||
|
use windows_sys::Win32::Storage::FileSystem::{
|
||||||
|
FindFirstVolumeW, FindNextVolumeW, FindVolumeClose, FlushFileBuffers, GetDriveTypeW,
|
||||||
|
};
|
||||||
|
use windows_sys::Win32::System::WindowsProgramming::DRIVE_FIXED;
|
||||||
|
|
||||||
unsafe fn flush_volume(name: &str) {
|
unsafe fn flush_volume(name: &str) {
|
||||||
let name_wide = name.to_wide_null();
|
let name_wide = name.to_wide_null();
|
||||||
if winapi::um::fileapi::GetDriveTypeW(name_wide.as_ptr()) == winbase::DRIVE_FIXED {
|
if GetDriveTypeW(name_wide.as_ptr()) == DRIVE_FIXED {
|
||||||
let sliced_name = &name[..name.len() - 1]; // eliminate trailing backslash
|
let sliced_name = &name[..name.len() - 1]; // eliminate trailing backslash
|
||||||
match OpenOptions::new().write(true).open(sliced_name) {
|
match OpenOptions::new().write(true).open(sliced_name) {
|
||||||
Ok(file) => {
|
Ok(file) => {
|
||||||
if winapi::um::fileapi::FlushFileBuffers(file.as_raw_handle()) == 0 {
|
if FlushFileBuffers(file.as_raw_handle() as HANDLE) == 0 {
|
||||||
crash!(
|
crash!(GetLastError() as i32, "failed to flush file buffer");
|
||||||
winapi::um::errhandlingapi::GetLastError() as i32,
|
|
||||||
"failed to flush file buffer"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => crash!(
|
Err(e) => crash!(
|
||||||
|
@ -103,17 +101,11 @@ mod platform {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn find_first_volume() -> (String, winnt::HANDLE) {
|
unsafe fn find_first_volume() -> (String, HANDLE) {
|
||||||
let mut name: [winnt::WCHAR; minwindef::MAX_PATH] = [0; minwindef::MAX_PATH];
|
let mut name: [u16; MAX_PATH as usize] = [0; MAX_PATH as usize];
|
||||||
let handle = winapi::um::fileapi::FindFirstVolumeW(
|
let handle = FindFirstVolumeW(name.as_mut_ptr(), name.len() as u32);
|
||||||
name.as_mut_ptr(),
|
if handle == INVALID_HANDLE_VALUE {
|
||||||
name.len() as minwindef::DWORD,
|
crash!(GetLastError() as i32, "failed to find first volume");
|
||||||
);
|
|
||||||
if handle == handleapi::INVALID_HANDLE_VALUE {
|
|
||||||
crash!(
|
|
||||||
winapi::um::errhandlingapi::GetLastError() as i32,
|
|
||||||
"failed to find first volume"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
(String::from_wide_null(&name), handle)
|
(String::from_wide_null(&name), handle)
|
||||||
}
|
}
|
||||||
|
@ -122,16 +114,11 @@ mod platform {
|
||||||
let (first_volume, next_volume_handle) = find_first_volume();
|
let (first_volume, next_volume_handle) = find_first_volume();
|
||||||
let mut volumes = vec![first_volume];
|
let mut volumes = vec![first_volume];
|
||||||
loop {
|
loop {
|
||||||
let mut name: [winnt::WCHAR; minwindef::MAX_PATH] = [0; minwindef::MAX_PATH];
|
let mut name: [u16; MAX_PATH as usize] = [0; MAX_PATH as usize];
|
||||||
if winapi::um::fileapi::FindNextVolumeW(
|
if FindNextVolumeW(next_volume_handle, name.as_mut_ptr(), name.len() as u32) == 0 {
|
||||||
next_volume_handle,
|
match GetLastError() {
|
||||||
name.as_mut_ptr(),
|
ERROR_NO_MORE_FILES => {
|
||||||
name.len() as minwindef::DWORD,
|
FindVolumeClose(next_volume_handle);
|
||||||
) == 0
|
|
||||||
{
|
|
||||||
match winapi::um::errhandlingapi::GetLastError() {
|
|
||||||
winerror::ERROR_NO_MORE_FILES => {
|
|
||||||
winapi::um::fileapi::FindVolumeClose(next_volume_handle);
|
|
||||||
return volumes;
|
return volumes;
|
||||||
}
|
}
|
||||||
err => crash!(err as i32, "failed to find next volume"),
|
err => crash!(err as i32, "failed to find next volume"),
|
||||||
|
|
|
@ -24,7 +24,7 @@ uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=[
|
||||||
same-file = "1.0.6"
|
same-file = "1.0.6"
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
winapi = { version="0.3", features=["fileapi", "handleapi", "processthreadsapi", "synchapi", "winbase"] }
|
windows-sys = { version = "0.42.0", default-features = false, features = ["Win32_System_Threading", "Win32_Foundation"] }
|
||||||
winapi-util = { version="0.1.5" }
|
winapi-util = { version="0.1.5" }
|
||||||
|
|
||||||
[target.'cfg(unix)'.dependencies]
|
[target.'cfg(unix)'.dependencies]
|
||||||
|
|
|
@ -6,17 +6,12 @@
|
||||||
* For the full copyright and license information, please view the LICENSE
|
* For the full copyright and license information, please view the LICENSE
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
use windows_sys::Win32::Foundation::{CloseHandle, BOOL, HANDLE, WAIT_FAILED, WAIT_OBJECT_0};
|
||||||
|
use windows_sys::Win32::System::Threading::{
|
||||||
|
OpenProcess, WaitForSingleObject, PROCESS_SYNCHRONIZE,
|
||||||
|
};
|
||||||
|
|
||||||
extern crate winapi;
|
pub type Pid = u32;
|
||||||
|
|
||||||
use self::winapi::shared::minwindef::DWORD;
|
|
||||||
use self::winapi::um::handleapi::CloseHandle;
|
|
||||||
use self::winapi::um::processthreadsapi::OpenProcess;
|
|
||||||
use self::winapi::um::synchapi::WaitForSingleObject;
|
|
||||||
use self::winapi::um::winbase::{WAIT_FAILED, WAIT_OBJECT_0};
|
|
||||||
use self::winapi::um::winnt::{HANDLE, SYNCHRONIZE};
|
|
||||||
|
|
||||||
pub type Pid = DWORD;
|
|
||||||
|
|
||||||
pub struct ProcessChecker {
|
pub struct ProcessChecker {
|
||||||
dead: bool,
|
dead: bool,
|
||||||
|
@ -26,10 +21,10 @@ pub struct ProcessChecker {
|
||||||
impl ProcessChecker {
|
impl ProcessChecker {
|
||||||
pub fn new(process_id: self::Pid) -> Self {
|
pub fn new(process_id: self::Pid) -> Self {
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
let FALSE = 0i32;
|
let FALSE: BOOL = 0;
|
||||||
let h = unsafe { OpenProcess(SYNCHRONIZE, FALSE, process_id as DWORD) };
|
let h = unsafe { OpenProcess(PROCESS_SYNCHRONIZE, FALSE, process_id) };
|
||||||
Self {
|
Self {
|
||||||
dead: h.is_null(),
|
dead: h == 0,
|
||||||
handle: h,
|
handle: h,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ time = { version = "0.3", features = ["parsing", "formatting", "local-offset", "
|
||||||
uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["libc"] }
|
uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["libc"] }
|
||||||
|
|
||||||
[target.'cfg(target_os = "windows")'.dependencies]
|
[target.'cfg(target_os = "windows")'.dependencies]
|
||||||
winapi = { version = "0.3" }
|
windows-sys = { version = "0.42.0", default-features = false, features = ["Win32_Storage_FileSystem", "Win32_Foundation"] }
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "touch"
|
name = "touch"
|
||||||
|
|
|
@ -472,19 +472,16 @@ fn pathbuf_from_stdout() -> UResult<PathBuf> {
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
{
|
{
|
||||||
use std::os::windows::prelude::AsRawHandle;
|
use std::os::windows::prelude::AsRawHandle;
|
||||||
use winapi::shared::minwindef::{DWORD, MAX_PATH};
|
use windows_sys::Win32::Foundation::{
|
||||||
use winapi::shared::winerror::{
|
GetLastError, ERROR_INVALID_PARAMETER, ERROR_NOT_ENOUGH_MEMORY, ERROR_PATH_NOT_FOUND,
|
||||||
ERROR_INVALID_PARAMETER, ERROR_NOT_ENOUGH_MEMORY, ERROR_PATH_NOT_FOUND,
|
HANDLE, MAX_PATH,
|
||||||
|
};
|
||||||
|
use windows_sys::Win32::Storage::FileSystem::{
|
||||||
|
GetFinalPathNameByHandleW, FILE_NAME_OPENED,
|
||||||
};
|
};
|
||||||
use winapi::um::errhandlingapi::GetLastError;
|
|
||||||
use winapi::um::fileapi::GetFinalPathNameByHandleW;
|
|
||||||
use winapi::um::winnt::WCHAR;
|
|
||||||
|
|
||||||
let handle = std::io::stdout().lock().as_raw_handle();
|
let handle = std::io::stdout().lock().as_raw_handle() as HANDLE;
|
||||||
let mut file_path_buffer: [WCHAR; MAX_PATH as usize] = [0; MAX_PATH as usize];
|
let mut file_path_buffer: [u16; MAX_PATH as usize] = [0; MAX_PATH as usize];
|
||||||
|
|
||||||
// Couldn't find this in winapi
|
|
||||||
const FILE_NAME_OPENED: DWORD = 0x8;
|
|
||||||
|
|
||||||
// https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfinalpathnamebyhandlea#examples
|
// https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfinalpathnamebyhandlea#examples
|
||||||
// SAFETY: We transmute the handle to be able to cast *mut c_void into a
|
// SAFETY: We transmute the handle to be able to cast *mut c_void into a
|
||||||
|
|
|
@ -19,7 +19,7 @@ clap = { version = "4.0", features = ["wrap_help", "cargo"] }
|
||||||
uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["entries"] }
|
uucore = { version=">=0.0.16", package="uucore", path="../../uucore", features=["entries"] }
|
||||||
|
|
||||||
[target.'cfg(target_os = "windows")'.dependencies]
|
[target.'cfg(target_os = "windows")'.dependencies]
|
||||||
winapi = { version = "0.3", features = ["lmcons"] }
|
windows-sys = { version = "0.42.0", default-features = false, features = ["Win32_NetworkManagement_NetManagement", "Win32_System_WindowsProgramming", "Win32_Foundation"] }
|
||||||
|
|
||||||
[target.'cfg(unix)'.dependencies]
|
[target.'cfg(unix)'.dependencies]
|
||||||
libc = "0.2.135"
|
libc = "0.2.135"
|
||||||
|
|
|
@ -10,17 +10,15 @@
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::os::windows::ffi::OsStringExt;
|
use std::os::windows::ffi::OsStringExt;
|
||||||
|
use windows_sys::Win32::NetworkManagement::NetManagement::UNLEN;
|
||||||
use winapi::shared::lmcons;
|
use windows_sys::Win32::System::WindowsProgramming::GetUserNameW;
|
||||||
use winapi::shared::minwindef::DWORD;
|
|
||||||
use winapi::um::winbase;
|
|
||||||
|
|
||||||
pub fn get_username() -> io::Result<OsString> {
|
pub fn get_username() -> io::Result<OsString> {
|
||||||
const BUF_LEN: DWORD = lmcons::UNLEN + 1;
|
const BUF_LEN: u32 = UNLEN + 1;
|
||||||
let mut buffer = [0_u16; BUF_LEN as usize];
|
let mut buffer = [0_u16; BUF_LEN as usize];
|
||||||
let mut len = BUF_LEN;
|
let mut len = BUF_LEN;
|
||||||
// SAFETY: buffer.len() == len
|
// SAFETY: buffer.len() == len
|
||||||
if unsafe { winbase::GetUserNameW(buffer.as_mut_ptr(), &mut len) } == 0 {
|
if unsafe { GetUserNameW(buffer.as_mut_ptr(), &mut len) } == 0 {
|
||||||
return Err(io::Error::last_os_error());
|
return Err(io::Error::last_os_error());
|
||||||
}
|
}
|
||||||
Ok(OsString::from_wide(&buffer[..len as usize - 1]))
|
Ok(OsString::from_wide(&buffer[..len as usize - 1]))
|
||||||
|
|
|
@ -45,16 +45,16 @@ clap = "4.0"
|
||||||
once_cell = "1.13"
|
once_cell = "1.13"
|
||||||
|
|
||||||
[target.'cfg(target_os = "windows")'.dependencies]
|
[target.'cfg(target_os = "windows")'.dependencies]
|
||||||
winapi = { version = "0.3", features = ["errhandlingapi", "fileapi", "handleapi", "winerror"] }
|
|
||||||
winapi-util = { version= "0.1.5", optional=true }
|
winapi-util = { version= "0.1.5", optional=true }
|
||||||
|
windows-sys = { version = "0.42.0", optional = true, default-features = false, features = ["Win32_Storage_FileSystem", "Win32_Foundation", "Win32_System_WindowsProgramming"] }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = []
|
default = []
|
||||||
# * non-default features
|
# * non-default features
|
||||||
encoding = ["data-encoding", "data-encoding-macro", "z85", "thiserror"]
|
encoding = ["data-encoding", "data-encoding-macro", "z85", "thiserror"]
|
||||||
entries = ["libc"]
|
entries = ["libc"]
|
||||||
fs = ["libc", "nix", "winapi-util"]
|
fs = ["libc", "nix", "winapi-util", "windows-sys"]
|
||||||
fsext = ["libc", "nix", "time"]
|
fsext = ["libc", "nix", "time", "windows-sys"]
|
||||||
lines = []
|
lines = []
|
||||||
memo = ["itertools"]
|
memo = ["itertools"]
|
||||||
mode = ["libc"]
|
mode = ["libc"]
|
||||||
|
|
|
@ -81,9 +81,10 @@ impl FileInformation {
|
||||||
let mut open_options = OpenOptions::new();
|
let mut open_options = OpenOptions::new();
|
||||||
let mut custom_flags = 0;
|
let mut custom_flags = 0;
|
||||||
if !dereference {
|
if !dereference {
|
||||||
custom_flags |= winapi::um::winbase::FILE_FLAG_OPEN_REPARSE_POINT;
|
custom_flags |=
|
||||||
|
windows_sys::Win32::Storage::FileSystem::FILE_FLAG_OPEN_REPARSE_POINT;
|
||||||
}
|
}
|
||||||
custom_flags |= winapi::um::winbase::FILE_FLAG_BACKUP_SEMANTICS;
|
custom_flags |= windows_sys::Win32::Storage::FileSystem::FILE_FLAG_BACKUP_SEMANTICS;
|
||||||
open_options.custom_flags(custom_flags);
|
open_options.custom_flags(custom_flags);
|
||||||
let file = open_options.read(true).open(path.as_ref())?;
|
let file = open_options.read(true).open(path.as_ref())?;
|
||||||
Self::from_file(&file)
|
Self::from_file(&file)
|
||||||
|
|
|
@ -32,18 +32,14 @@ use std::ffi::OsStr;
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use std::os::windows::ffi::OsStrExt;
|
use std::os::windows::ffi::OsStrExt;
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use winapi::shared::minwindef::DWORD;
|
use windows_sys::Win32::Foundation::{ERROR_NO_MORE_FILES, INVALID_HANDLE_VALUE};
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use winapi::um::fileapi::GetDiskFreeSpaceW;
|
use windows_sys::Win32::Storage::FileSystem::{
|
||||||
#[cfg(windows)]
|
FindFirstVolumeW, FindNextVolumeW, FindVolumeClose, GetDiskFreeSpaceW, GetDriveTypeW,
|
||||||
use winapi::um::fileapi::{
|
GetVolumeInformationW, GetVolumePathNamesForVolumeNameW, QueryDosDeviceW,
|
||||||
FindFirstVolumeW, FindNextVolumeW, FindVolumeClose, GetDriveTypeW, GetVolumeInformationW,
|
|
||||||
GetVolumePathNamesForVolumeNameW, QueryDosDeviceW,
|
|
||||||
};
|
};
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use winapi::um::handleapi::INVALID_HANDLE_VALUE;
|
use windows_sys::Win32::System::WindowsProgramming::DRIVE_REMOTE;
|
||||||
#[cfg(windows)]
|
|
||||||
use winapi::um::winbase::DRIVE_REMOTE;
|
|
||||||
|
|
||||||
// Warning: the pointer has to be used *immediately* or the Vec
|
// Warning: the pointer has to be used *immediately* or the Vec
|
||||||
// it points to will be dropped!
|
// it points to will be dropped!
|
||||||
|
@ -265,7 +261,7 @@ impl MountInfo {
|
||||||
.collect::<Vec<u16>>()
|
.collect::<Vec<u16>>()
|
||||||
.as_ptr(),
|
.as_ptr(),
|
||||||
dev_name_buf.as_mut_ptr(),
|
dev_name_buf.as_mut_ptr(),
|
||||||
dev_name_buf.len() as DWORD,
|
dev_name_buf.len() as u32,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
volume_name.push('\\');
|
volume_name.push('\\');
|
||||||
|
@ -276,7 +272,7 @@ impl MountInfo {
|
||||||
GetVolumePathNamesForVolumeNameW(
|
GetVolumePathNamesForVolumeNameW(
|
||||||
String2LPWSTR!(volume_name),
|
String2LPWSTR!(volume_name),
|
||||||
mount_root_buf.as_mut_ptr(),
|
mount_root_buf.as_mut_ptr(),
|
||||||
mount_root_buf.len() as DWORD,
|
mount_root_buf.len() as u32,
|
||||||
ptr::null_mut(),
|
ptr::null_mut(),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
@ -296,7 +292,7 @@ impl MountInfo {
|
||||||
ptr::null_mut(),
|
ptr::null_mut(),
|
||||||
ptr::null_mut(),
|
ptr::null_mut(),
|
||||||
fs_type_buf.as_mut_ptr(),
|
fs_type_buf.as_mut_ptr(),
|
||||||
fs_type_buf.len() as DWORD,
|
fs_type_buf.len() as u32,
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
let fs_type = if 0 != success {
|
let fs_type = if 0 != success {
|
||||||
|
@ -443,9 +439,8 @@ pub fn read_fs_list() -> Result<Vec<MountInfo>, std::io::Error> {
|
||||||
{
|
{
|
||||||
let mut volume_name_buf = [0u16; MAX_PATH];
|
let mut volume_name_buf = [0u16; MAX_PATH];
|
||||||
// As recommended in the MS documentation, retrieve the first volume before the others
|
// As recommended in the MS documentation, retrieve the first volume before the others
|
||||||
let find_handle = unsafe {
|
let find_handle =
|
||||||
FindFirstVolumeW(volume_name_buf.as_mut_ptr(), volume_name_buf.len() as DWORD)
|
unsafe { FindFirstVolumeW(volume_name_buf.as_mut_ptr(), volume_name_buf.len() as u32) };
|
||||||
};
|
|
||||||
if INVALID_HANDLE_VALUE == find_handle {
|
if INVALID_HANDLE_VALUE == find_handle {
|
||||||
crash!(
|
crash!(
|
||||||
EXIT_ERR,
|
EXIT_ERR,
|
||||||
|
@ -467,12 +462,11 @@ pub fn read_fs_list() -> Result<Vec<MountInfo>, std::io::Error> {
|
||||||
FindNextVolumeW(
|
FindNextVolumeW(
|
||||||
find_handle,
|
find_handle,
|
||||||
volume_name_buf.as_mut_ptr(),
|
volume_name_buf.as_mut_ptr(),
|
||||||
volume_name_buf.len() as DWORD,
|
volume_name_buf.len() as u32,
|
||||||
)
|
)
|
||||||
} {
|
} {
|
||||||
let err = IOError::last_os_error();
|
let err = IOError::last_os_error();
|
||||||
if err.raw_os_error() != Some(winapi::shared::winerror::ERROR_NO_MORE_FILES as i32)
|
if err.raw_os_error() != Some(ERROR_NO_MORE_FILES as i32) {
|
||||||
{
|
|
||||||
crash!(EXIT_ERR, "FindNextVolumeW failed: {}", err);
|
crash!(EXIT_ERR, "FindNextVolumeW failed: {}", err);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -524,7 +518,7 @@ impl FsUsage {
|
||||||
//path_utf8.as_ptr(),
|
//path_utf8.as_ptr(),
|
||||||
String2LPWSTR!(path.as_os_str()),
|
String2LPWSTR!(path.as_os_str()),
|
||||||
root_path.as_mut_ptr(),
|
root_path.as_mut_ptr(),
|
||||||
root_path.len() as DWORD,
|
root_path.len() as u32,
|
||||||
ptr::null_mut(),
|
ptr::null_mut(),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
// * feature-gated external crates (re-shared as public internal modules)
|
// * feature-gated external crates (re-shared as public internal modules)
|
||||||
#[cfg(feature = "libc")]
|
#[cfg(feature = "libc")]
|
||||||
pub extern crate libc;
|
pub extern crate libc;
|
||||||
#[cfg(feature = "winapi")]
|
#[cfg(all(feature = "windows-sys", target_os = "windows"))]
|
||||||
pub extern crate winapi;
|
pub extern crate windows_sys;
|
||||||
|
|
||||||
//## internal modules
|
//## internal modules
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue