Skip to content

Commit

Permalink
more feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
dlowe committed Nov 27, 2024
1 parent 78f0362 commit 5078136
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 29 deletions.
6 changes: 1 addition & 5 deletions src/unix/apple/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,11 +538,7 @@ unsafe fn new_disk(
)
};

let is_read_only = if refresh_kind.details() {
(c_disk.f_flags & libc::MNT_RDONLY as u32) != 0
} else {
false
};
let is_read_only = refresh_kind.details() && (c_disk.f_flags & libc::MNT_RDONLY as u32) != 0;

Some(Disk {
inner: DiskInner {
Expand Down
16 changes: 9 additions & 7 deletions src/unix/freebsd/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,16 @@ fn refresh_disk(disk: &mut DiskInner, refresh_kind: DiskRefreshKind) -> bool {
let (total_space, available_space) = unsafe {
let mut vfs: libc::statvfs = std::mem::zeroed();
if libc::statvfs(disk.c_mount_point.as_ptr() as *const _, &mut vfs as *mut _) < 0 {
return false;
}
let block_size: u64 = vfs.f_frsize as _;
sysinfo_debug!("statvfs failed");
(0, 0)
} else {
let block_size: u64 = vfs.f_frsize as _;

(
vfs.f_blocks.saturating_mul(block_size),
vfs.f_favail.saturating_mul(block_size),
)
(
vfs.f_blocks.saturating_mul(block_size),
vfs.f_favail.saturating_mul(block_size),
)
}
};

disk.total_space = total_space;
Expand Down
31 changes: 14 additions & 17 deletions src/unix/linux/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,25 +100,22 @@ impl DiskInner {
if self.actual_device_name.is_none() {
self.actual_device_name = Some(get_actual_device_name(&self.device_name));
}
let (read_bytes, written_bytes) = if let Some((read_bytes, written_bytes)) =
procfs_disk_stats
.get(self.actual_device_name.as_ref().unwrap())
.map(|stat| {
(
stat.sectors_read * SECTOR_SIZE,
stat.sectors_written * SECTOR_SIZE,
)
}) {
(read_bytes, written_bytes)
if let Some((read_bytes, written_bytes)) = procfs_disk_stats
.get(self.actual_device_name.as_ref().unwrap())
.map(|stat| {
(
stat.sectors_read * SECTOR_SIZE,
stat.sectors_written * SECTOR_SIZE,
)
})
{
self.old_read_bytes = self.read_bytes;
self.old_written_bytes = self.written_bytes;
self.read_bytes = read_bytes;
self.written_bytes = written_bytes;
} else {
sysinfo_debug!("Failed to update disk i/o stats");
(0, 0)
};

self.old_read_bytes = self.read_bytes;
self.old_written_bytes = self.written_bytes;
self.read_bytes = read_bytes;
self.written_bytes = written_bytes;
}
}

if refresh_kind.details() {
Expand Down

0 comments on commit 5078136

Please sign in to comment.