Commit 64b5d33
Merge #1919
1919: feat: I/O safety for 'sys/statfs' r=asomers a=SteveLauC
### What this PR does:
1. Adds I/O safety for module `sys/statfs`.
This PR is pretty small as all we need to do is to change the interface of `fstatfs(2)`:
from:
```rust
pub fn fstatfs<T: AsRawFd>(fd: &T) -> Result<Statfs>
```
to:
```rust
pub fn fstatfs<Fd: AsFd>(fd: &Fd) -> Result<Statfs>
```
------
~Besides from the changes in module `sys/statfs`, there are two extra places where care needs to be taken:~
```shell
$ cd nix
# Search for the usage of `fstatfs(2)` in `nix`
$ rg "fstatfs\("
test/test_fcntl.rs
386: let statfs = nix::sys::statfs::fstatfs(&tmp).unwrap();
424: let statfs = nix::sys::statfs::fstatfs(&tmp).unwrap();
CHANGELOG.md
849:- Now functions `statfs()` and `fstatfs()` return result with `Statfs` wrapper
src/sys/statfs.rs
769: check_fstatfs("/tmp");
770: check_fstatfs("/dev");
771: check_fstatfs("/run");
772: check_fstatfs("/");
775: fn check_fstatfs(path: &str) {
781: let fs = fstatfs(&file).unwrap();
830: let fs = fstatfs(&file);
```
~As you can see, `fstatfs(2)` is used in the tests in `test/test_fcntl.rs`:~
```rust
// Test code that involves `fstatfs(2)`
let tmp: NamedTempFile = NamedTempFile::new().unwrap();
let fd = tmp.as_raw_fd();
let statfs = nix::sys::statfs::fstatfs(&tmp).unwrap();
```
~`tmp` is of type [`NamedTempFile`](https://docs.rs/tempfile/latest/tempfile/struct.NamedTempFile.html), which does not implement `AsFd` in the current implementation of `tempfile`, but the implementation should be easy as it contains `std::fs::File` internally:~
```rust
pub struct NamedTempFile {
path: TempPath,
file: File,
}
```
~So I am thinking about making a PR to `tempfile` to make `NamedTempFile` `AsFd`, any thoughts on this?~
Co-authored-by: Steve Lau <stevelauc@outlook.com>2 files changed
+5
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
740 | 740 | | |
741 | 741 | | |
742 | 742 | | |
743 | | - | |
| 743 | + | |
744 | 744 | | |
745 | 745 | | |
746 | | - | |
| 746 | + | |
747 | 747 | | |
748 | 748 | | |
749 | 749 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
383 | 383 | | |
384 | 384 | | |
385 | 385 | | |
386 | | - | |
| 386 | + | |
387 | 387 | | |
388 | 388 | | |
389 | 389 | | |
| |||
421 | 421 | | |
422 | 422 | | |
423 | 423 | | |
424 | | - | |
| 424 | + | |
425 | 425 | | |
426 | 426 | | |
427 | 427 | | |
| |||
0 commit comments