Skip to content

Commit 7058bce

Browse files
committed
feat: I/O safety for 'sys/statfs'
1 parent e2257db commit 7058bce

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/sys/statfs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use std::ffi::CStr;
66
use std::fmt::{self, Debug};
77
use std::mem;
8-
use std::os::unix::io::AsRawFd;
8+
use std::os::unix::io::{AsFd, AsRawFd};
99

1010
use cfg_if::cfg_if;
1111

@@ -740,10 +740,10 @@ pub fn statfs<P: ?Sized + NixPath>(path: &P) -> Result<Statfs> {
740740
/// # Arguments
741741
///
742742
/// `fd` - File descriptor of any open file within the file system to describe
743-
pub fn fstatfs<T: AsRawFd>(fd: &T) -> Result<Statfs> {
743+
pub fn fstatfs<Fd: AsFd>(fd: &Fd) -> Result<Statfs> {
744744
unsafe {
745745
let mut stat = mem::MaybeUninit::<type_of_statfs>::uninit();
746-
Errno::result(LIBC_FSTATFS(fd.as_raw_fd(), stat.as_mut_ptr()))
746+
Errno::result(LIBC_FSTATFS(fd.as_fd().as_raw_fd(), stat.as_mut_ptr()))
747747
.map(|_| Statfs(stat.assume_init()))
748748
}
749749
}

test/test_fcntl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ mod linux_android {
383383
let tmp = NamedTempFile::new().unwrap();
384384

385385
let fd = tmp.as_raw_fd();
386-
let statfs = nix::sys::statfs::fstatfs(&tmp).unwrap();
386+
let statfs = nix::sys::statfs::fstatfs(tmp.as_file()).unwrap();
387387
if statfs.filesystem_type() == nix::sys::statfs::OVERLAYFS_SUPER_MAGIC {
388388
// OverlayFS is a union file system. It returns one inode value in
389389
// stat(2), but a different one shows up in /proc/locks. So we must
@@ -421,7 +421,7 @@ mod linux_android {
421421
let tmp = NamedTempFile::new().unwrap();
422422

423423
let fd = tmp.as_raw_fd();
424-
let statfs = nix::sys::statfs::fstatfs(&tmp).unwrap();
424+
let statfs = nix::sys::statfs::fstatfs(tmp.as_file()).unwrap();
425425
if statfs.filesystem_type() == nix::sys::statfs::OVERLAYFS_SUPER_MAGIC {
426426
// OverlayFS is a union file system. It returns one inode value in
427427
// stat(2), but a different one shows up in /proc/locks. So we must

0 commit comments

Comments
 (0)