1b8a62b91Sopenharmony_ci//! Functions which operate on file descriptors. 2b8a62b91Sopenharmony_ci 3b8a62b91Sopenharmony_ci#[cfg(not(target_os = "wasi"))] 4b8a62b91Sopenharmony_ciuse crate::fs::Mode; 5b8a62b91Sopenharmony_ciuse crate::io::SeekFrom; 6b8a62b91Sopenharmony_ci#[cfg(not(target_os = "wasi"))] 7b8a62b91Sopenharmony_ciuse crate::process::{Gid, Uid}; 8b8a62b91Sopenharmony_ciuse crate::{backend, io}; 9b8a62b91Sopenharmony_ciuse backend::fd::{AsFd, BorrowedFd}; 10b8a62b91Sopenharmony_ci 11b8a62b91Sopenharmony_ci#[cfg(not(any(target_os = "solaris", target_os = "wasi")))] 12b8a62b91Sopenharmony_cipub use backend::fs::types::FlockOperation; 13b8a62b91Sopenharmony_ci 14b8a62b91Sopenharmony_ci#[cfg(not(any( 15b8a62b91Sopenharmony_ci target_os = "aix", 16b8a62b91Sopenharmony_ci target_os = "dragonfly", 17b8a62b91Sopenharmony_ci target_os = "illumos", 18b8a62b91Sopenharmony_ci target_os = "netbsd", 19b8a62b91Sopenharmony_ci target_os = "openbsd", 20b8a62b91Sopenharmony_ci target_os = "redox", 21b8a62b91Sopenharmony_ci target_os = "solaris", 22b8a62b91Sopenharmony_ci)))] 23b8a62b91Sopenharmony_cipub use backend::fs::types::FallocateFlags; 24b8a62b91Sopenharmony_ci 25b8a62b91Sopenharmony_cipub use backend::fs::types::Stat; 26b8a62b91Sopenharmony_ci 27b8a62b91Sopenharmony_ci#[cfg(not(any( 28b8a62b91Sopenharmony_ci target_os = "haiku", 29b8a62b91Sopenharmony_ci target_os = "illumos", 30b8a62b91Sopenharmony_ci target_os = "netbsd", 31b8a62b91Sopenharmony_ci target_os = "redox", 32b8a62b91Sopenharmony_ci target_os = "solaris", 33b8a62b91Sopenharmony_ci target_os = "wasi", 34b8a62b91Sopenharmony_ci)))] 35b8a62b91Sopenharmony_cipub use backend::fs::types::StatFs; 36b8a62b91Sopenharmony_ci 37b8a62b91Sopenharmony_ci#[cfg(not(any( 38b8a62b91Sopenharmony_ci target_os = "haiku", 39b8a62b91Sopenharmony_ci target_os = "illumos", 40b8a62b91Sopenharmony_ci target_os = "redox", 41b8a62b91Sopenharmony_ci target_os = "solaris", 42b8a62b91Sopenharmony_ci target_os = "wasi", 43b8a62b91Sopenharmony_ci)))] 44b8a62b91Sopenharmony_cipub use backend::fs::types::{StatVfs, StatVfsMountFlags}; 45b8a62b91Sopenharmony_ci 46b8a62b91Sopenharmony_ci#[cfg(any(target_os = "android", target_os = "linux"))] 47b8a62b91Sopenharmony_cipub use backend::fs::types::FsWord; 48b8a62b91Sopenharmony_ci 49b8a62b91Sopenharmony_ci/// Timestamps used by [`utimensat`] and [`futimens`]. 50b8a62b91Sopenharmony_ci/// 51b8a62b91Sopenharmony_ci/// [`utimensat`]: crate::fs::utimensat 52b8a62b91Sopenharmony_ci/// [`futimens`]: crate::fs::futimens 53b8a62b91Sopenharmony_ci// This is `repr(C)` and specifically laid out to match the representation used 54b8a62b91Sopenharmony_ci// by `utimensat` and `futimens`, which expect 2-element arrays of timestamps. 55b8a62b91Sopenharmony_ci#[repr(C)] 56b8a62b91Sopenharmony_ci#[derive(Clone, Debug)] 57b8a62b91Sopenharmony_cipub struct Timestamps { 58b8a62b91Sopenharmony_ci /// The timestamp of the last access to a filesystem object. 59b8a62b91Sopenharmony_ci pub last_access: crate::fs::Timespec, 60b8a62b91Sopenharmony_ci 61b8a62b91Sopenharmony_ci /// The timestamp of the last modification of a filesystem object. 62b8a62b91Sopenharmony_ci pub last_modification: crate::fs::Timespec, 63b8a62b91Sopenharmony_ci} 64b8a62b91Sopenharmony_ci 65b8a62b91Sopenharmony_ci/// The filesystem magic number for procfs. 66b8a62b91Sopenharmony_ci/// 67b8a62b91Sopenharmony_ci/// See [the `fstatfs` man page] for more information. 68b8a62b91Sopenharmony_ci/// 69b8a62b91Sopenharmony_ci/// [the `fstatfs` man page]: https://man7.org/linux/man-pages/man2/fstatfs.2.html#DESCRIPTION 70b8a62b91Sopenharmony_ci#[cfg(any(target_os = "android", target_os = "linux"))] 71b8a62b91Sopenharmony_cipub const PROC_SUPER_MAGIC: FsWord = backend::fs::types::PROC_SUPER_MAGIC; 72b8a62b91Sopenharmony_ci 73b8a62b91Sopenharmony_ci/// The filesystem magic number for NFS. 74b8a62b91Sopenharmony_ci/// 75b8a62b91Sopenharmony_ci/// See [the `fstatfs` man page] for more information. 76b8a62b91Sopenharmony_ci/// 77b8a62b91Sopenharmony_ci/// [the `fstatfs` man page]: https://man7.org/linux/man-pages/man2/fstatfs.2.html#DESCRIPTION 78b8a62b91Sopenharmony_ci#[cfg(any(target_os = "android", target_os = "linux"))] 79b8a62b91Sopenharmony_cipub const NFS_SUPER_MAGIC: FsWord = backend::fs::types::NFS_SUPER_MAGIC; 80b8a62b91Sopenharmony_ci 81b8a62b91Sopenharmony_ci/// `lseek(fd, offset, whence)`—Repositions a file descriptor within a file. 82b8a62b91Sopenharmony_ci/// 83b8a62b91Sopenharmony_ci/// # References 84b8a62b91Sopenharmony_ci/// - [POSIX] 85b8a62b91Sopenharmony_ci/// - [Linux] 86b8a62b91Sopenharmony_ci/// 87b8a62b91Sopenharmony_ci/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/lseek.html 88b8a62b91Sopenharmony_ci/// [Linux]: https://man7.org/linux/man-pages/man2/lseek.2.html 89b8a62b91Sopenharmony_ci#[inline] 90b8a62b91Sopenharmony_ci#[doc(alias = "lseek")] 91b8a62b91Sopenharmony_cipub fn seek<Fd: AsFd>(fd: Fd, pos: SeekFrom) -> io::Result<u64> { 92b8a62b91Sopenharmony_ci backend::fs::syscalls::seek(fd.as_fd(), pos) 93b8a62b91Sopenharmony_ci} 94b8a62b91Sopenharmony_ci 95b8a62b91Sopenharmony_ci/// `lseek(fd, 0, SEEK_CUR)`—Returns the current position within a file. 96b8a62b91Sopenharmony_ci/// 97b8a62b91Sopenharmony_ci/// Return the current position of the file descriptor. This is a subset of 98b8a62b91Sopenharmony_ci/// the functionality of `seek`, but this interface makes it easier for users 99b8a62b91Sopenharmony_ci/// to declare their intent not to mutate any state. 100b8a62b91Sopenharmony_ci/// 101b8a62b91Sopenharmony_ci/// # References 102b8a62b91Sopenharmony_ci/// - [POSIX] 103b8a62b91Sopenharmony_ci/// - [Linux] 104b8a62b91Sopenharmony_ci/// 105b8a62b91Sopenharmony_ci/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/lseek.html 106b8a62b91Sopenharmony_ci/// [Linux]: https://man7.org/linux/man-pages/man2/lseek.2.html 107b8a62b91Sopenharmony_ci#[inline] 108b8a62b91Sopenharmony_ci#[doc(alias = "lseek")] 109b8a62b91Sopenharmony_cipub fn tell<Fd: AsFd>(fd: Fd) -> io::Result<u64> { 110b8a62b91Sopenharmony_ci backend::fs::syscalls::tell(fd.as_fd()) 111b8a62b91Sopenharmony_ci} 112b8a62b91Sopenharmony_ci 113b8a62b91Sopenharmony_ci/// `fchmod(fd)`—Sets open file or directory permissions. 114b8a62b91Sopenharmony_ci/// 115b8a62b91Sopenharmony_ci/// This implementation does not support `O_PATH` file descriptors, even on 116b8a62b91Sopenharmony_ci/// platforms where the host libc emulates it. 117b8a62b91Sopenharmony_ci/// 118b8a62b91Sopenharmony_ci/// # References 119b8a62b91Sopenharmony_ci/// - [POSIX] 120b8a62b91Sopenharmony_ci/// - [Linux] 121b8a62b91Sopenharmony_ci/// 122b8a62b91Sopenharmony_ci/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fchmod.html 123b8a62b91Sopenharmony_ci/// [Linux]: https://man7.org/linux/man-pages/man2/fchmod.2.html 124b8a62b91Sopenharmony_ci#[cfg(not(target_os = "wasi"))] 125b8a62b91Sopenharmony_ci#[inline] 126b8a62b91Sopenharmony_cipub fn fchmod<Fd: AsFd>(fd: Fd, mode: Mode) -> io::Result<()> { 127b8a62b91Sopenharmony_ci backend::fs::syscalls::fchmod(fd.as_fd(), mode) 128b8a62b91Sopenharmony_ci} 129b8a62b91Sopenharmony_ci 130b8a62b91Sopenharmony_ci/// `fchown(fd)`—Sets open file or directory ownership. 131b8a62b91Sopenharmony_ci/// 132b8a62b91Sopenharmony_ci/// # References 133b8a62b91Sopenharmony_ci/// - [POSIX] 134b8a62b91Sopenharmony_ci/// - [Linux] 135b8a62b91Sopenharmony_ci/// 136b8a62b91Sopenharmony_ci/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fchown.html 137b8a62b91Sopenharmony_ci/// [Linux]: https://man7.org/linux/man-pages/man2/fchown.2.html 138b8a62b91Sopenharmony_ci#[cfg(not(target_os = "wasi"))] 139b8a62b91Sopenharmony_ci#[inline] 140b8a62b91Sopenharmony_cipub fn fchown<Fd: AsFd>(fd: Fd, owner: Option<Uid>, group: Option<Gid>) -> io::Result<()> { 141b8a62b91Sopenharmony_ci backend::fs::syscalls::fchown(fd.as_fd(), owner, group) 142b8a62b91Sopenharmony_ci} 143b8a62b91Sopenharmony_ci 144b8a62b91Sopenharmony_ci/// `fstat(fd)`—Queries metadata for an open file or directory. 145b8a62b91Sopenharmony_ci/// 146b8a62b91Sopenharmony_ci/// [`Mode::from_raw_mode`] and [`FileType::from_raw_mode`] may be used to 147b8a62b91Sopenharmony_ci/// interpret the `st_mode` field. 148b8a62b91Sopenharmony_ci/// 149b8a62b91Sopenharmony_ci/// # References 150b8a62b91Sopenharmony_ci/// - [POSIX] 151b8a62b91Sopenharmony_ci/// - [Linux] 152b8a62b91Sopenharmony_ci/// 153b8a62b91Sopenharmony_ci/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fstat.html 154b8a62b91Sopenharmony_ci/// [Linux]: https://man7.org/linux/man-pages/man2/fstat.2.html 155b8a62b91Sopenharmony_ci/// [`Mode::from_raw_mode`]: crate::fs::Mode::from_raw_mode 156b8a62b91Sopenharmony_ci/// [`FileType::from_raw_mode`]: crate::fs::FileType::from_raw_mode 157b8a62b91Sopenharmony_ci#[inline] 158b8a62b91Sopenharmony_cipub fn fstat<Fd: AsFd>(fd: Fd) -> io::Result<Stat> { 159b8a62b91Sopenharmony_ci backend::fs::syscalls::fstat(fd.as_fd()) 160b8a62b91Sopenharmony_ci} 161b8a62b91Sopenharmony_ci 162b8a62b91Sopenharmony_ci/// `fstatfs(fd)`—Queries filesystem statistics for an open file or directory. 163b8a62b91Sopenharmony_ci/// 164b8a62b91Sopenharmony_ci/// Compared to [`fstatvfs`], this function often provides more information, 165b8a62b91Sopenharmony_ci/// though it's less portable. 166b8a62b91Sopenharmony_ci/// 167b8a62b91Sopenharmony_ci/// # References 168b8a62b91Sopenharmony_ci/// - [Linux] 169b8a62b91Sopenharmony_ci/// 170b8a62b91Sopenharmony_ci/// [Linux]: https://man7.org/linux/man-pages/man2/fstatfs.2.html 171b8a62b91Sopenharmony_ci#[cfg(not(any( 172b8a62b91Sopenharmony_ci target_os = "haiku", 173b8a62b91Sopenharmony_ci target_os = "illumos", 174b8a62b91Sopenharmony_ci target_os = "netbsd", 175b8a62b91Sopenharmony_ci target_os = "redox", 176b8a62b91Sopenharmony_ci target_os = "solaris", 177b8a62b91Sopenharmony_ci target_os = "wasi", 178b8a62b91Sopenharmony_ci)))] 179b8a62b91Sopenharmony_ci#[inline] 180b8a62b91Sopenharmony_cipub fn fstatfs<Fd: AsFd>(fd: Fd) -> io::Result<StatFs> { 181b8a62b91Sopenharmony_ci backend::fs::syscalls::fstatfs(fd.as_fd()) 182b8a62b91Sopenharmony_ci} 183b8a62b91Sopenharmony_ci 184b8a62b91Sopenharmony_ci/// `fstatvfs(fd)`—Queries filesystem statistics for an open file or 185b8a62b91Sopenharmony_ci/// directory, POSIX version. 186b8a62b91Sopenharmony_ci/// 187b8a62b91Sopenharmony_ci/// Compared to [`fstatfs`], this function often provides less information, 188b8a62b91Sopenharmony_ci/// but it is more portable. But even so, filesystems are very diverse and not 189b8a62b91Sopenharmony_ci/// all the fields are meaningful for every filesystem. And `f_fsid` doesn't 190b8a62b91Sopenharmony_ci/// seem to have a clear meaning anywhere. 191b8a62b91Sopenharmony_ci/// 192b8a62b91Sopenharmony_ci/// # References 193b8a62b91Sopenharmony_ci/// - [POSIX] 194b8a62b91Sopenharmony_ci/// - [Linux] 195b8a62b91Sopenharmony_ci/// 196b8a62b91Sopenharmony_ci/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fstatvfs.html 197b8a62b91Sopenharmony_ci/// [Linux]: https://man7.org/linux/man-pages/man2/fstatvfs.2.html 198b8a62b91Sopenharmony_ci#[cfg(not(any( 199b8a62b91Sopenharmony_ci target_os = "haiku", 200b8a62b91Sopenharmony_ci target_os = "illumos", 201b8a62b91Sopenharmony_ci target_os = "redox", 202b8a62b91Sopenharmony_ci target_os = "solaris", 203b8a62b91Sopenharmony_ci target_os = "wasi", 204b8a62b91Sopenharmony_ci)))] 205b8a62b91Sopenharmony_ci#[inline] 206b8a62b91Sopenharmony_cipub fn fstatvfs<Fd: AsFd>(fd: Fd) -> io::Result<StatVfs> { 207b8a62b91Sopenharmony_ci backend::fs::syscalls::fstatvfs(fd.as_fd()) 208b8a62b91Sopenharmony_ci} 209b8a62b91Sopenharmony_ci 210b8a62b91Sopenharmony_ci/// `futimens(fd, times)`—Sets timestamps for an open file or directory. 211b8a62b91Sopenharmony_ci/// 212b8a62b91Sopenharmony_ci/// # References 213b8a62b91Sopenharmony_ci/// - [POSIX] 214b8a62b91Sopenharmony_ci/// - [Linux] 215b8a62b91Sopenharmony_ci/// 216b8a62b91Sopenharmony_ci/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/futimens.html 217b8a62b91Sopenharmony_ci/// [Linux]: https://man7.org/linux/man-pages/man2/utimensat.2.html 218b8a62b91Sopenharmony_ci#[inline] 219b8a62b91Sopenharmony_cipub fn futimens<Fd: AsFd>(fd: Fd, times: &Timestamps) -> io::Result<()> { 220b8a62b91Sopenharmony_ci backend::fs::syscalls::futimens(fd.as_fd(), times) 221b8a62b91Sopenharmony_ci} 222b8a62b91Sopenharmony_ci 223b8a62b91Sopenharmony_ci/// `fallocate(fd, mode, offset, len)`—Adjusts file allocation. 224b8a62b91Sopenharmony_ci/// 225b8a62b91Sopenharmony_ci/// This is a more general form of `posix_fallocate`, adding a `mode` argument 226b8a62b91Sopenharmony_ci/// which modifies the behavior. On platforms which only support 227b8a62b91Sopenharmony_ci/// `posix_fallocate` and not the more general form, no `FallocateFlags` values 228b8a62b91Sopenharmony_ci/// are defined so it will always be empty. 229b8a62b91Sopenharmony_ci/// 230b8a62b91Sopenharmony_ci/// # References 231b8a62b91Sopenharmony_ci/// - [POSIX] 232b8a62b91Sopenharmony_ci/// - [Linux `fallocate`] 233b8a62b91Sopenharmony_ci/// - [Linux `posix_fallocate`] 234b8a62b91Sopenharmony_ci/// 235b8a62b91Sopenharmony_ci/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_fallocate.html 236b8a62b91Sopenharmony_ci/// [Linux `fallocate`]: https://man7.org/linux/man-pages/man2/fallocate.2.html 237b8a62b91Sopenharmony_ci/// [Linux `posix_fallocate`]: https://man7.org/linux/man-pages/man3/posix_fallocate.3.html 238b8a62b91Sopenharmony_ci#[cfg(not(any( 239b8a62b91Sopenharmony_ci target_os = "aix", 240b8a62b91Sopenharmony_ci target_os = "dragonfly", 241b8a62b91Sopenharmony_ci target_os = "illumos", 242b8a62b91Sopenharmony_ci target_os = "netbsd", 243b8a62b91Sopenharmony_ci target_os = "openbsd", 244b8a62b91Sopenharmony_ci target_os = "redox", 245b8a62b91Sopenharmony_ci target_os = "solaris", 246b8a62b91Sopenharmony_ci)))] // not implemented in libc for netbsd yet 247b8a62b91Sopenharmony_ci#[inline] 248b8a62b91Sopenharmony_ci#[doc(alias = "posix_fallocate")] 249b8a62b91Sopenharmony_cipub fn fallocate<Fd: AsFd>(fd: Fd, mode: FallocateFlags, offset: u64, len: u64) -> io::Result<()> { 250b8a62b91Sopenharmony_ci backend::fs::syscalls::fallocate(fd.as_fd(), mode, offset, len) 251b8a62b91Sopenharmony_ci} 252b8a62b91Sopenharmony_ci 253b8a62b91Sopenharmony_ci/// `fcntl(fd, F_GETFL) & O_ACCMODE` 254b8a62b91Sopenharmony_ci/// 255b8a62b91Sopenharmony_ci/// Returns a pair of booleans indicating whether the file descriptor is 256b8a62b91Sopenharmony_ci/// readable and/or writable, respectively. This is only reliable on files; for 257b8a62b91Sopenharmony_ci/// example, it doesn't reflect whether sockets have been shut down; for 258b8a62b91Sopenharmony_ci/// general I/O handle support, use [`io::is_read_write`]. 259b8a62b91Sopenharmony_ci#[inline] 260b8a62b91Sopenharmony_cipub fn is_file_read_write<Fd: AsFd>(fd: Fd) -> io::Result<(bool, bool)> { 261b8a62b91Sopenharmony_ci _is_file_read_write(fd.as_fd()) 262b8a62b91Sopenharmony_ci} 263b8a62b91Sopenharmony_ci 264b8a62b91Sopenharmony_cipub(crate) fn _is_file_read_write(fd: BorrowedFd<'_>) -> io::Result<(bool, bool)> { 265b8a62b91Sopenharmony_ci let mode = backend::fs::syscalls::fcntl_getfl(fd)?; 266b8a62b91Sopenharmony_ci 267b8a62b91Sopenharmony_ci // Check for `O_PATH`. 268b8a62b91Sopenharmony_ci #[cfg(any( 269b8a62b91Sopenharmony_ci target_os = "android", 270b8a62b91Sopenharmony_ci target_os = "fuchsia", 271b8a62b91Sopenharmony_ci target_os = "linux", 272b8a62b91Sopenharmony_ci target_os = "emscripten", 273b8a62b91Sopenharmony_ci ))] 274b8a62b91Sopenharmony_ci if mode.contains(crate::fs::OFlags::PATH) { 275b8a62b91Sopenharmony_ci return Ok((false, false)); 276b8a62b91Sopenharmony_ci } 277b8a62b91Sopenharmony_ci 278b8a62b91Sopenharmony_ci // Use `RWMODE` rather than `ACCMODE` as `ACCMODE` may include `O_PATH`. 279b8a62b91Sopenharmony_ci // We handled `O_PATH` above. 280b8a62b91Sopenharmony_ci match mode & crate::fs::OFlags::RWMODE { 281b8a62b91Sopenharmony_ci crate::fs::OFlags::RDONLY => Ok((true, false)), 282b8a62b91Sopenharmony_ci crate::fs::OFlags::RDWR => Ok((true, true)), 283b8a62b91Sopenharmony_ci crate::fs::OFlags::WRONLY => Ok((false, true)), 284b8a62b91Sopenharmony_ci _ => unreachable!(), 285b8a62b91Sopenharmony_ci } 286b8a62b91Sopenharmony_ci} 287b8a62b91Sopenharmony_ci 288b8a62b91Sopenharmony_ci/// `fsync(fd)`—Ensures that file data and metadata is written to the 289b8a62b91Sopenharmony_ci/// underlying storage device. 290b8a62b91Sopenharmony_ci/// 291b8a62b91Sopenharmony_ci/// On iOS and macOS this isn't sufficient to ensure that data has reached 292b8a62b91Sopenharmony_ci/// persistent storage; use [`fcntl_fullfsync`] to ensure that. 293b8a62b91Sopenharmony_ci/// 294b8a62b91Sopenharmony_ci/// # References 295b8a62b91Sopenharmony_ci/// - [POSIX] 296b8a62b91Sopenharmony_ci/// - [Linux] 297b8a62b91Sopenharmony_ci/// 298b8a62b91Sopenharmony_ci/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fsync.html 299b8a62b91Sopenharmony_ci/// [Linux]: https://man7.org/linux/man-pages/man2/fsync.2.html 300b8a62b91Sopenharmony_ci/// [`fcntl_fullfsync`]: https://docs.rs/rustix/*/x86_64-apple-darwin/rustix/fs/fn.fcntl_fullfsync.html 301b8a62b91Sopenharmony_ci#[inline] 302b8a62b91Sopenharmony_cipub fn fsync<Fd: AsFd>(fd: Fd) -> io::Result<()> { 303b8a62b91Sopenharmony_ci backend::fs::syscalls::fsync(fd.as_fd()) 304b8a62b91Sopenharmony_ci} 305b8a62b91Sopenharmony_ci 306b8a62b91Sopenharmony_ci/// `fdatasync(fd)`—Ensures that file data is written to the underlying 307b8a62b91Sopenharmony_ci/// storage device. 308b8a62b91Sopenharmony_ci/// 309b8a62b91Sopenharmony_ci/// # References 310b8a62b91Sopenharmony_ci/// - [POSIX] 311b8a62b91Sopenharmony_ci/// - [Linux] 312b8a62b91Sopenharmony_ci/// 313b8a62b91Sopenharmony_ci/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fdatasync.html 314b8a62b91Sopenharmony_ci/// [Linux]: https://man7.org/linux/man-pages/man2/fdatasync.2.html 315b8a62b91Sopenharmony_ci#[cfg(not(any( 316b8a62b91Sopenharmony_ci target_os = "dragonfly", 317b8a62b91Sopenharmony_ci target_os = "haiku", 318b8a62b91Sopenharmony_ci target_os = "ios", 319b8a62b91Sopenharmony_ci target_os = "macos", 320b8a62b91Sopenharmony_ci target_os = "redox", 321b8a62b91Sopenharmony_ci)))] 322b8a62b91Sopenharmony_ci#[inline] 323b8a62b91Sopenharmony_cipub fn fdatasync<Fd: AsFd>(fd: Fd) -> io::Result<()> { 324b8a62b91Sopenharmony_ci backend::fs::syscalls::fdatasync(fd.as_fd()) 325b8a62b91Sopenharmony_ci} 326b8a62b91Sopenharmony_ci 327b8a62b91Sopenharmony_ci/// `ftruncate(fd, length)`—Sets the length of a file. 328b8a62b91Sopenharmony_ci/// 329b8a62b91Sopenharmony_ci/// # References 330b8a62b91Sopenharmony_ci/// - [POSIX] 331b8a62b91Sopenharmony_ci/// - [Linux] 332b8a62b91Sopenharmony_ci/// 333b8a62b91Sopenharmony_ci/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/ftruncate.html 334b8a62b91Sopenharmony_ci/// [Linux]: https://man7.org/linux/man-pages/man2/ftruncate.2.html 335b8a62b91Sopenharmony_ci#[inline] 336b8a62b91Sopenharmony_cipub fn ftruncate<Fd: AsFd>(fd: Fd, length: u64) -> io::Result<()> { 337b8a62b91Sopenharmony_ci backend::fs::syscalls::ftruncate(fd.as_fd(), length) 338b8a62b91Sopenharmony_ci} 339b8a62b91Sopenharmony_ci 340b8a62b91Sopenharmony_ci/// `flock(fd, operation)`—Acquire or release an advisory lock on an open file. 341b8a62b91Sopenharmony_ci/// 342b8a62b91Sopenharmony_ci/// # References 343b8a62b91Sopenharmony_ci/// - [Linux] 344b8a62b91Sopenharmony_ci/// 345b8a62b91Sopenharmony_ci/// [Linux]: https://man7.org/linux/man-pages/man2/flock.2.html 346b8a62b91Sopenharmony_ci#[cfg(not(any(target_os = "solaris", target_os = "wasi")))] 347b8a62b91Sopenharmony_ci#[inline] 348b8a62b91Sopenharmony_cipub fn flock<Fd: AsFd>(fd: Fd, operation: FlockOperation) -> io::Result<()> { 349b8a62b91Sopenharmony_ci backend::fs::syscalls::flock(fd.as_fd(), operation) 350b8a62b91Sopenharmony_ci} 351