/// Timestamps used by [`utimensat`] and [`futimens`]. /// /// [`utimensat`]: crate::fs::utimensat /// [`futimens`]: crate::fs::futimens // This is `repr(C)` and specifically laid out to match the representation used // by `utimensat` and `futimens`, which expect 2-element arrays of timestamps. #[repr(C)] #[derive(Clone)] pubstruct Timestamps { /// The timestamp of the last access to a filesystem object. pub last_access: Timespec,
/// The timestamp of the last modification of a filesystem object. pub last_modification: Timespec,
}
/// The filesystem magic number for procfs. /// /// See [the `fstatfs` manual page] for more information. /// /// [the `fstatfs` manual page]: https://man7.org/linux/man-pages/man2/fstatfs.2.html#DESCRIPTION #[cfg(linux_kernel)] pubconst PROC_SUPER_MAGIC: FsWord = backend::c::PROC_SUPER_MAGIC as FsWord;
/// The filesystem magic number for NFS. /// /// See [the `fstatfs` manual page] for more information. /// /// [the `fstatfs` manual page]: https://man7.org/linux/man-pages/man2/fstatfs.2.html#DESCRIPTION #[cfg(linux_kernel)] pubconst NFS_SUPER_MAGIC: FsWord = backend::c::NFS_SUPER_MAGIC as FsWord;
/// `lseek(fd, 0, SEEK_CUR)`—Returns the current position within a file. /// /// Return the current position of the file descriptor. This is a subset of /// the functionality of `seek`, but this interface makes it easier for users /// to declare their intent not to mutate any state. /// /// # References /// - [POSIX] /// - [Linux] /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/lseek.html /// [Linux]: https://man7.org/linux/man-pages/man2/lseek.2.html #[inline] #[doc(alias = "lseek")] pubfn tell<Fd: AsFd>(fd: Fd) -> io::Result<u64> {
backend::fs::syscalls::tell(fd.as_fd())
}
/// `fchmod(fd, mode)`—Sets open file or directory permissions. /// /// This implementation does not support [`OFlags::PATH`] file descriptors, /// even on platforms where the host libc emulates it. /// /// # References /// - [POSIX] /// - [Linux] /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fchmod.html /// [Linux]: https://man7.org/linux/man-pages/man2/fchmod.2.html #[cfg(not(target_os = "wasi"))] #[inline] pubfn fchmod<Fd: AsFd>(fd: Fd, mode: Mode) -> io::Result<()> {
backend::fs::syscalls::fchmod(fd.as_fd(), mode)
}
/// `fstat(fd)`—Queries metadata for an open file or directory. /// /// [`Mode::from_raw_mode`] and [`FileType::from_raw_mode`] may be used to /// interpret the `st_mode` field. /// /// # References /// - [POSIX] /// - [Linux] /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fstat.html /// [Linux]: https://man7.org/linux/man-pages/man2/fstat.2.html /// [`Mode::from_raw_mode`]: Mode::from_raw_mode /// [`FileType::from_raw_mode`]: crate::fs::FileType::from_raw_mode #[inline] pubfn fstat<Fd: AsFd>(fd: Fd) -> io::Result<Stat> {
backend::fs::syscalls::fstat(fd.as_fd())
}
/// `fstatfs(fd)`—Queries filesystem statistics for an open file or directory. /// /// Compared to [`fstatvfs`], this function often provides more information, /// though it's less portable. /// /// # References /// - [Linux] /// /// [Linux]: https://man7.org/linux/man-pages/man2/fstatfs.2.html #[cfg(not(any(
solarish,
target_os = "espidf",
target_os = "haiku",
target_os = "netbsd",
target_os = "nto",
target_os = "redox",
target_os = "vita",
target_os = "wasi",
)))] #[inline] pubfn fstatfs<Fd: AsFd>(fd: Fd) -> io::Result<StatFs> {
backend::fs::syscalls::fstatfs(fd.as_fd())
}
/// `fstatvfs(fd)`—Queries filesystem statistics for an open file or /// directory, POSIX version. /// /// Compared to [`fstatfs`], this function often provides less information, /// but it is more portable. But even so, filesystems are very diverse and not /// all the fields are meaningful for every filesystem. And `f_fsid` doesn't /// seem to have a clear meaning anywhere. /// /// # References /// - [POSIX] /// - [Linux] /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fstatvfs.html /// [Linux]: https://man7.org/linux/man-pages/man2/fstatvfs.2.html #[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))] #[inline] pubfn fstatvfs<Fd: AsFd>(fd: Fd) -> io::Result<StatVfs> {
backend::fs::syscalls::fstatvfs(fd.as_fd())
}
/// `fallocate(fd, mode, offset, len)`—Adjusts file allocation. /// /// This is a more general form of `posix_fallocate`, adding a `mode` argument /// which modifies the behavior. On platforms which only support /// `posix_fallocate` and not the more general form, no `FallocateFlags` values /// are defined so it will always be empty. /// /// # References /// - [POSIX] /// - [Linux `fallocate`] /// - [Linux `posix_fallocate`] /// /// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_fallocate.html /// [Linux `fallocate`]: https://man7.org/linux/man-pages/man2/fallocate.2.html /// [Linux `posix_fallocate`]: https://man7.org/linux/man-pages/man3/posix_fallocate.3.html #[cfg(not(any(
netbsdlike,
solarish,
target_os = "dragonfly",
target_os = "espidf",
target_os = "nto",
target_os = "redox",
target_os = "vita",
)))] // not implemented in libc for netbsd yet #[inline] #[doc(alias = "posix_fallocate")] pubfn fallocate<Fd: AsFd>(fd: Fd, mode: FallocateFlags, offset: u64, len: u64) -> io::Result<()> {
backend::fs::syscalls::fallocate(fd.as_fd(), mode, offset, len)
}
/// `fcntl(fd, F_GETFL) & O_ACCMODE` /// /// Returns a pair of booleans indicating whether the file descriptor is /// readable and/or writable, respectively. This is only reliable on files; for /// example, it doesn't reflect whether sockets have been shut down; for /// general I/O handle support, use [`io::is_read_write`]. #[inline] pubfn is_file_read_write<Fd: AsFd>(fd: Fd) -> io::Result<(bool, bool)> {
_is_file_read_write(fd.as_fd())
}
// Check for `O_PATH`. #[cfg(any(linux_kernel, target_os = "emscripten", target_os = "fuchsia"))] if mode.contains(OFlags::PATH) { return Ok((false, false));
}
// Use `RWMODE` rather than `ACCMODE` as `ACCMODE` may include `O_PATH`. // We handled `O_PATH` above. match mode & OFlags::RWMODE {
OFlags::RDONLY => Ok((true, false)),
OFlags::RDWR => Ok((true, true)),
OFlags::WRONLY => Ok((false, true)),
_ => unreachable!(),
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.