From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/sysinfo/src/apple/disk.rs | 66 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 vendor/sysinfo/src/apple/disk.rs (limited to 'vendor/sysinfo/src/apple/disk.rs') diff --git a/vendor/sysinfo/src/apple/disk.rs b/vendor/sysinfo/src/apple/disk.rs new file mode 100644 index 000000000..9f0b4a3a3 --- /dev/null +++ b/vendor/sysinfo/src/apple/disk.rs @@ -0,0 +1,66 @@ +// Take a look at the license at the top of the repository in the LICENSE file. + +use crate::utils::to_cpath; +use crate::{DiskExt, DiskType}; + +#[cfg(target_os = "macos")] +pub(crate) use crate::sys::inner::disk::*; + +use libc::statfs; +use std::ffi::{OsStr, OsString}; +use std::mem; +use std::path::{Path, PathBuf}; + +#[doc = include_str!("../../md_doc/disk.md")] +pub struct Disk { + pub(crate) type_: DiskType, + pub(crate) name: OsString, + pub(crate) file_system: Vec, + pub(crate) mount_point: PathBuf, + pub(crate) total_space: u64, + pub(crate) available_space: u64, + pub(crate) is_removable: bool, +} + +impl DiskExt for Disk { + fn type_(&self) -> DiskType { + self.type_ + } + + fn name(&self) -> &OsStr { + &self.name + } + + fn file_system(&self) -> &[u8] { + &self.file_system + } + + fn mount_point(&self) -> &Path { + &self.mount_point + } + + fn total_space(&self) -> u64 { + self.total_space + } + + fn available_space(&self) -> u64 { + self.available_space + } + + fn is_removable(&self) -> bool { + self.is_removable + } + + fn refresh(&mut self) -> bool { + unsafe { + let mut stat: statfs = mem::zeroed(); + let mount_point_cpath = to_cpath(&self.mount_point); + if statfs(mount_point_cpath.as_ptr() as *const i8, &mut stat) == 0 { + self.available_space = u64::from(stat.f_bsize).saturating_mul(stat.f_bavail); + true + } else { + false + } + } + } +} -- cgit v1.2.3