New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add statx #1660
base: master
Are you sure you want to change the base?
Add statx #1660
Conversation
Resolves nix-rust#1649.
src/fcntl/statx.rs
Outdated
); | ||
*/ | ||
|
||
/// Attempt to retrieve stats of `pathname`. If `pathname` is relative, `dirfd` is used as starting directory for lookups. If `dirfs` is None, current directory is used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrap to 80 cols, please.
src/fcntl/statx.rs
Outdated
|
||
impl Statx { | ||
/// Retrieve file type, if it has been returned by kernel | ||
pub fn r#type(&self) -> Option<SFlag> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method name will be hard for users to type. I suggest filetype
.
src/fcntl/statx.rs
Outdated
} | ||
|
||
/// Retrieve file access time, if it has been returned by kernel | ||
pub fn atime(&self) -> Option<libc::statx_timestamp> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning the raw libc type isn't very useful. Is it identical to a struct timespec
? If so, I suggest you convert it into a nix::sys::time::TimeSpec
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, also added the appropriate From
TimeSpec
implementation within the statx
module. Or should it be moved to the place where other TimeSpec
From
implementations live with a duplicated #[cfg]
line?
src/fcntl/statx.rs
Outdated
} | ||
|
||
/// Retrieve file size as a number of blocks, if it has been returned by kernel | ||
pub fn blksize(&self) -> Option<u64> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this identical to blocks
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, probably I just forgot to fill in new doccomment and implementation after copying neighbouring method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is it supposed to do then? Because it's just returning the same stx_blocks variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed to return blocksize
, fixed the doccomment.
Co-authored-by: Alan Somers <asomers@gmail.com>
src/fcntl/statx.rs
Outdated
} | ||
|
||
/// Retrieve file size as a number of blocks, if it has been returned by kernel | ||
pub fn blksize(&self) -> Option<u64> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is it supposed to do then? Because it's just returning the same stx_blocks variable.
src/fcntl/statx.rs
Outdated
); | ||
|
||
/// Attempt to retrieve stats of `pathname`. If `pathname` is relative, `dirfd` | ||
/// is used as starting directory for lookups. If `dirfs` is None, current |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// is used as starting directory for lookups. If `dirfs` is None, current | |
/// is used as starting directory for lookups. If `dirfd` is None, current |
/// is used as starting directory for lookups. If `dirfs` is None, current | ||
/// directory is used. | ||
/// `pathname` may be empty string. But instead of specifying empty string | ||
/// literal, you are adviced to use zero-terminated `CStr` to avoid extra allocation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about adding some examples to show usage? That would be especially helpful for the "empty pathname" case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Shall doc examples be marked as testable code (and assert something about typical external files e.g. /dev/null
)?
src/fcntl/statx.rs
Outdated
pub struct Statx { | ||
pub inner: libc::statx, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it has only one member, it can be a NewType.
pub struct Statx { | |
pub inner: libc::statx, | |
} | |
#[repr(transparent)] | |
pub struct Statx(libc::statx); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done (inner tuple field is still pub
, unlike in the suggested change).
} | ||
} | ||
|
||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are these two methods commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of current version of libc
crate does not expose e.g. STATX_ATTR_VERITY
. See my question at #1649 (comment).
Android target's libc lacks even more consts in libc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I submitted a PR to add the missing constants on GNU/Linux
Hey @vi :) What is the status of this PR? I really hope this can be merged I just tried it myself, sadly, there is a lot of missing stuff in |
@@ -889,3 +889,6 @@ pub fn posix_fallocate(fd: RawFd, offset: libc::off_t, len: libc::off_t) -> Resu | |||
} | |||
} | |||
} | |||
|
|||
#[cfg(all(feature="fs", any(target_os = "android", target_os = "linux")))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[cfg(all(
any(
target_os = "android",
all(target_os = "linux", not(target_env = "musl")),
),
feature = "fs"
))]
Since this is not available on musl
, this configuration should work
|
||
let mut dst = mem::MaybeUninit::uninit(); | ||
let res = pathname.with_nix_path(|cstr| unsafe { | ||
libc::statx( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wrapper function is only exposed on GNU/Linux as glibc added it.
What about making this statx
module temporarily exclusive to GNU/Linux? When the missing stuff is added, we can easily add support for other platforms by changing a few lines of code.
It is waiting for answers for questions:
|
IMHO, this is not a good idea as |
Resolves #1649.
In current state this breaks the build for Musl targets.