mirror of
https://github.com/ClementTsang/bottom.git
synced 2024-09-11 11:46:59 +03:00
deps: bump windows to 0.51.1 (#1279)
* deps: bump windows to 0.51.1 * some changes to fit new API
This commit is contained in:
parent
2e2b32ce71
commit
ac55add21e
14
Cargo.lock
generated
14
Cargo.lock
generated
@ -1452,9 +1452,19 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "windows"
|
||||
version = "0.48.0"
|
||||
version = "0.51.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f"
|
||||
checksum = "ca229916c5ee38c2f2bc1e9d8f04df975b4bd93f9955dc69fabb5d91270045c9"
|
||||
dependencies = [
|
||||
"windows-core",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.51.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
@ -114,7 +114,7 @@ core-foundation = "0.9.3"
|
||||
mach2 = "0.4.1"
|
||||
|
||||
[target.'cfg(target_os = "windows")'.dependencies]
|
||||
windows = { version = "0.48.0", features = [
|
||||
windows = { version = "0.51.1", features = [
|
||||
"Win32_Foundation",
|
||||
"Win32_Security",
|
||||
"Win32_Storage_FileSystem",
|
||||
|
@ -9,9 +9,9 @@ use std::{
|
||||
|
||||
use anyhow::bail;
|
||||
use windows::Win32::{
|
||||
Foundation::{self, CloseHandle},
|
||||
Foundation::{self, CloseHandle, HANDLE},
|
||||
Storage::FileSystem::{
|
||||
CreateFileW, FindFirstVolumeW, FindNextVolumeW, FindVolumeClose, FindVolumeHandle,
|
||||
CreateFileW, FindFirstVolumeW, FindNextVolumeW, FindVolumeClose,
|
||||
GetVolumeNameForVolumeMountPointW, FILE_FLAGS_AND_ATTRIBUTES, FILE_SHARE_READ,
|
||||
FILE_SHARE_WRITE, OPEN_EXISTING,
|
||||
},
|
||||
@ -77,28 +77,12 @@ fn volume_io(volume: &Path) -> anyhow::Result<DISK_PERFORMANCE> {
|
||||
|
||||
// SAFETY: This should be safe, we will check the result as well.
|
||||
let handle_result = unsafe { CloseHandle(h_device) };
|
||||
if !handle_result.as_bool() {
|
||||
const ERROR_INVALID_FUNCTION: i32 = Foundation::ERROR_INVALID_FUNCTION.0 as i32;
|
||||
const ERROR_NOT_SUPPORTED: i32 = Foundation::ERROR_NOT_SUPPORTED.0 as i32;
|
||||
|
||||
match io::Error::last_os_error().raw_os_error() {
|
||||
Some(ERROR_INVALID_FUNCTION) => {
|
||||
bail!("Handle error: invalid function");
|
||||
}
|
||||
Some(ERROR_NOT_SUPPORTED) => {
|
||||
bail!("Handle error: not supported");
|
||||
}
|
||||
_ => {
|
||||
bail!(
|
||||
"Unknown handle device result error: {:?}",
|
||||
io::Error::last_os_error()
|
||||
);
|
||||
}
|
||||
}
|
||||
if let Err(err) = handle_result {
|
||||
bail!("Handle error: {err:?}");
|
||||
}
|
||||
|
||||
if !ret.as_bool() {
|
||||
bail!("Device I/O error: {:?}", io::Error::last_os_error());
|
||||
if let Err(err) = ret {
|
||||
bail!("Device I/O error: {err:?}");
|
||||
} else {
|
||||
Ok(disk_performance)
|
||||
}
|
||||
@ -111,15 +95,11 @@ fn current_volume(buffer: &[u16]) -> PathBuf {
|
||||
PathBuf::from(path_string)
|
||||
}
|
||||
|
||||
fn close_find_handle(handle: FindVolumeHandle) -> anyhow::Result<()> {
|
||||
fn close_find_handle(handle: HANDLE) -> anyhow::Result<()> {
|
||||
// Clean up the handle.
|
||||
// SAFETY: This should be safe, we will check the result as well.
|
||||
let handle_result = unsafe { FindVolumeClose(handle) };
|
||||
if !handle_result.as_bool() {
|
||||
bail!("Could not close volume handle.");
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
let res = unsafe { FindVolumeClose(handle) };
|
||||
Ok(res?)
|
||||
}
|
||||
|
||||
/// Returns the I/O for all volumes.
|
||||
@ -144,17 +124,18 @@ pub(crate) fn all_volume_io() -> anyhow::Result<Vec<anyhow::Result<(DISK_PERFORM
|
||||
}
|
||||
|
||||
// Now iterate until there are no more volumes.
|
||||
while unsafe { FindNextVolumeW(handle, &mut buffer) }.as_bool() {
|
||||
while unsafe { FindNextVolumeW(handle, &mut buffer) }.is_ok() {
|
||||
let volume = current_volume(&buffer);
|
||||
ret.push(volume_io(&volume).map(|res| (res, volume.to_string_lossy().to_string())));
|
||||
}
|
||||
|
||||
let err = io::Error::last_os_error();
|
||||
match err.raw_os_error() {
|
||||
// Iteration completed successfully, continue on.
|
||||
Some(ERROR_NO_MORE_FILES) => {}
|
||||
// Some error occured.
|
||||
Some(ERROR_NO_MORE_FILES) => {
|
||||
// Iteration completed successfully, continue on.
|
||||
}
|
||||
_ => {
|
||||
// Some error occured.
|
||||
close_find_handle(handle)?;
|
||||
bail!("Error while iterating over volumes: {err:?}");
|
||||
}
|
||||
@ -187,11 +168,8 @@ pub(crate) fn volume_name_from_mount(mount: &str) -> anyhow::Result<String> {
|
||||
GetVolumeNameForVolumeMountPointW(windows::core::PCWSTR(mount.as_ptr()), &mut buffer)
|
||||
};
|
||||
|
||||
if !result.as_bool() {
|
||||
bail!(
|
||||
"Could not get volume name for mount point: {:?}",
|
||||
io::Error::last_os_error()
|
||||
);
|
||||
if let Err(err) = result {
|
||||
bail!("Could not get volume name for mount point: {err:?}");
|
||||
} else {
|
||||
Ok(current_volume(&buffer).to_string_lossy().to_string())
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
use std::mem::{size_of, zeroed};
|
||||
|
||||
use windows::Win32::Foundation::TRUE;
|
||||
use windows::Win32::System::ProcessStatus::{GetPerformanceInfo, PERFORMANCE_INFORMATION};
|
||||
|
||||
use crate::data_harvester::memory::MemHarvest;
|
||||
@ -14,7 +13,7 @@ pub(crate) fn get_swap_usage() -> Option<MemHarvest> {
|
||||
// the bindings are "safe" to use with how we call them.
|
||||
unsafe {
|
||||
let mut perf_info: PERFORMANCE_INFORMATION = zeroed();
|
||||
if GetPerformanceInfo(&mut perf_info, size_of::<PERFORMANCE_INFORMATION>() as u32) == TRUE {
|
||||
if GetPerformanceInfo(&mut perf_info, size_of::<PERFORMANCE_INFORMATION>() as u32).is_ok() {
|
||||
// Saturating sub by perf_info.PhysicalTotal for what sysinfo does.
|
||||
let swap_total = perf_info.PageSize.saturating_mul(perf_info.CommitLimit) as u64;
|
||||
let swap_used = perf_info.PageSize.saturating_mul(perf_info.CommitTotal) as u64;
|
||||
|
@ -29,7 +29,7 @@ impl Process {
|
||||
fn kill(self) -> Result<(), String> {
|
||||
// SAFETY: Windows API call, this is safe as we are passing in the handle.
|
||||
let result = unsafe { TerminateProcess(self.0, 1) };
|
||||
if result.0 == 0 {
|
||||
if result.is_err() {
|
||||
return Err("process may have already been terminated.".to_string());
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ impl Drop for Process {
|
||||
fn drop(&mut self) {
|
||||
// SAFETY: Windows API call, this is safe as we are passing in the handle.
|
||||
unsafe {
|
||||
CloseHandle(self.0);
|
||||
let _ = CloseHandle(self.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user