mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-11 15:46:53 +00:00
e6b019c29d
# Conflicts: # .github/workflows/build.yml # .github/workflows/ci.yml # Cargo.lock # Cargo.toml # appauth/src/token.rs # crates/config/src/config.rs # crates/event-notifier/examples/simple.rs # crates/event-notifier/src/global.rs # crates/event-notifier/src/lib.rs # crates/event-notifier/src/notifier.rs # crates/event-notifier/src/store.rs # crates/filemeta/src/filemeta.rs # crates/notify/examples/webhook.rs # crates/utils/Cargo.toml # ecstore/Cargo.toml # ecstore/src/cmd/bucket_replication.rs # ecstore/src/config/com.rs # ecstore/src/disk/error.rs # ecstore/src/disk/mod.rs # ecstore/src/set_disk.rs # ecstore/src/store_api.rs # ecstore/src/store_list_objects.rs # iam/Cargo.toml # iam/src/manager.rs # policy/Cargo.toml # rustfs/src/admin/rpc.rs # rustfs/src/main.rs # rustfs/src/storage/mod.rs
73 lines
2.1 KiB
Rust
73 lines
2.1 KiB
Rust
use super::{DiskInfo, IOStats};
|
|
use nix::sys::{stat::stat, statfs::statfs};
|
|
use std::io::Error;
|
|
use std::path::Path;
|
|
|
|
/// Returns total and free bytes available in a directory, e.g. `/`.
|
|
pub fn get_info(p: impl AsRef<Path>) -> std::io::Result<DiskInfo> {
|
|
let stat = statfs(p.as_ref())?;
|
|
|
|
let bsize = stat.block_size() as u64;
|
|
let bfree = stat.blocks_free();
|
|
let bavail = stat.blocks_available();
|
|
let blocks = stat.blocks();
|
|
|
|
let reserved = match bfree.checked_sub(bavail) {
|
|
Some(reserved) => reserved,
|
|
None => {
|
|
return Err(Error::other(format!(
|
|
"detected f_bavail space ({}) > f_bfree space ({}), fs corruption at ({}). please run 'fsck'",
|
|
bavail,
|
|
bfree,
|
|
p.as_ref().display()
|
|
)));
|
|
}
|
|
};
|
|
|
|
let total = match blocks.checked_sub(reserved) {
|
|
Some(total) => total * bsize,
|
|
None => {
|
|
return Err(Error::other(format!(
|
|
"detected reserved space ({}) > blocks space ({}), fs corruption at ({}). please run 'fsck'",
|
|
reserved,
|
|
blocks,
|
|
p.as_ref().display()
|
|
)));
|
|
}
|
|
};
|
|
|
|
let free = bavail * bsize;
|
|
let used = match total.checked_sub(free) {
|
|
Some(used) => used,
|
|
None => {
|
|
return Err(Error::other(format!(
|
|
"detected free space ({}) > total drive space ({}), fs corruption at ({}). please run 'fsck'",
|
|
free,
|
|
total,
|
|
p.as_ref().display()
|
|
)));
|
|
}
|
|
};
|
|
|
|
Ok(DiskInfo {
|
|
total,
|
|
free,
|
|
used,
|
|
files: stat.files(),
|
|
ffree: stat.files_free(),
|
|
fstype: stat.filesystem_type_name().to_string(),
|
|
..Default::default()
|
|
})
|
|
}
|
|
|
|
pub fn same_disk(disk1: &str, disk2: &str) -> std::io::Result<bool> {
|
|
let stat1 = stat(disk1)?;
|
|
let stat2 = stat(disk2)?;
|
|
|
|
Ok(stat1.st_dev == stat2.st_dev)
|
|
}
|
|
|
|
pub fn get_drive_stats(_major: u32, _minor: u32) -> std::io::Result<IOStats> {
|
|
Ok(IOStats::default())
|
|
}
|