use crate::ffi;
use bitflags::bitflags;
bitflags! {
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct Access: ffi::c_uint {
const READ_OK = linux_raw_sys::general::R_OK;
const WRITE_OK = linux_raw_sys::general::W_OK;
const EXEC_OK = linux_raw_sys::general::X_OK;
const EXISTS = linux_raw_sys::general::F_OK;
const _ = !0;
}
}
bitflags! {
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct AtFlags: ffi::c_uint {
const SYMLINK_NOFOLLOW = linux_raw_sys::general::AT_SYMLINK_NOFOLLOW;
const EACCESS = linux_raw_sys::general::AT_EACCESS;
const REMOVEDIR = linux_raw_sys::general::AT_REMOVEDIR;
const SYMLINK_FOLLOW = linux_raw_sys::general::AT_SYMLINK_FOLLOW;
const NO_AUTOMOUNT = linux_raw_sys::general::AT_NO_AUTOMOUNT;
const EMPTY_PATH = linux_raw_sys::general::AT_EMPTY_PATH;
const STATX_SYNC_AS_STAT = linux_raw_sys::general::AT_STATX_SYNC_AS_STAT;
const STATX_FORCE_SYNC = linux_raw_sys::general::AT_STATX_FORCE_SYNC;
const STATX_DONT_SYNC = linux_raw_sys::general::AT_STATX_DONT_SYNC;
const _ = !0;
}
}
bitflags! {
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct Mode: RawMode {
const RWXU = linux_raw_sys::general::S_IRWXU;
const RUSR = linux_raw_sys::general::S_IRUSR;
const WUSR = linux_raw_sys::general::S_IWUSR;
const XUSR = linux_raw_sys::general::S_IXUSR;
const RWXG = linux_raw_sys::general::S_IRWXG;
const RGRP = linux_raw_sys::general::S_IRGRP;
const WGRP = linux_raw_sys::general::S_IWGRP;
const XGRP = linux_raw_sys::general::S_IXGRP;
const RWXO = linux_raw_sys::general::S_IRWXO;
const ROTH = linux_raw_sys::general::S_IROTH;
const WOTH = linux_raw_sys::general::S_IWOTH;
const XOTH = linux_raw_sys::general::S_IXOTH;
const SUID = linux_raw_sys::general::S_ISUID;
const SGID = linux_raw_sys::general::S_ISGID;
const SVTX = linux_raw_sys::general::S_ISVTX;
const _ = !0;
}
}
impl Mode {
#[inline]
pub const fn from_raw_mode(st_mode: RawMode) -> Self {
Self::from_bits_truncate(st_mode & !linux_raw_sys::general::S_IFMT)
}
#[inline]
pub const fn as_raw_mode(self) -> RawMode {
self.bits()
}
}
impl From<RawMode> for Mode {
#[inline]
fn from(st_mode: RawMode) -> Self {
Self::from_raw_mode(st_mode)
}
}
impl From<Mode> for RawMode {
#[inline]
fn from(mode: Mode) -> Self {
mode.as_raw_mode()
}
}
bitflags! {
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct OFlags: ffi::c_uint {
const ACCMODE = linux_raw_sys::general::O_ACCMODE;
const RWMODE = linux_raw_sys::general::O_RDONLY |
linux_raw_sys::general::O_WRONLY |
linux_raw_sys::general::O_RDWR;
const APPEND = linux_raw_sys::general::O_APPEND;
#[doc(alias = "CREAT")]
const CREATE = linux_raw_sys::general::O_CREAT;
const DIRECTORY = linux_raw_sys::general::O_DIRECTORY;
const DSYNC = linux_raw_sys::general::O_SYNC;
const EXCL = linux_raw_sys::general::O_EXCL;
const FSYNC = linux_raw_sys::general::O_SYNC;
const NOFOLLOW = linux_raw_sys::general::O_NOFOLLOW;
const NONBLOCK = linux_raw_sys::general::O_NONBLOCK;
const RDONLY = linux_raw_sys::general::O_RDONLY;
const WRONLY = linux_raw_sys::general::O_WRONLY;
const RDWR = linux_raw_sys::general::O_RDWR;
const NOCTTY = linux_raw_sys::general::O_NOCTTY;
const RSYNC = linux_raw_sys::general::O_SYNC;
const SYNC = linux_raw_sys::general::O_SYNC;
const TRUNC = linux_raw_sys::general::O_TRUNC;
const PATH = linux_raw_sys::general::O_PATH;
const CLOEXEC = linux_raw_sys::general::O_CLOEXEC;
const TMPFILE = linux_raw_sys::general::O_TMPFILE;
const NOATIME = linux_raw_sys::general::O_NOATIME;
const DIRECT = linux_raw_sys::general::O_DIRECT;
const LARGEFILE = linux_raw_sys::general::O_LARGEFILE;
const ASYNC = linux_raw_sys::general::FASYNC;
const _ = !0;
}
}
bitflags! {
#[repr(transparent)]
#[derive(Default, Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct ResolveFlags: u64 {
const NO_XDEV = linux_raw_sys::general::RESOLVE_NO_XDEV as u64;
const NO_MAGICLINKS = linux_raw_sys::general::RESOLVE_NO_MAGICLINKS as u64;
const NO_SYMLINKS = linux_raw_sys::general::RESOLVE_NO_SYMLINKS as u64;
const BENEATH = linux_raw_sys::general::RESOLVE_BENEATH as u64;
const IN_ROOT = linux_raw_sys::general::RESOLVE_IN_ROOT as u64;
const CACHED = linux_raw_sys::general::RESOLVE_CACHED as u64;
const _ = !0;
}
}
bitflags! {
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct RenameFlags: ffi::c_uint {
const EXCHANGE = linux_raw_sys::general::RENAME_EXCHANGE;
const NOREPLACE = linux_raw_sys::general::RENAME_NOREPLACE;
const WHITEOUT = linux_raw_sys::general::RENAME_WHITEOUT;
const _ = !0;
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum FileType {
RegularFile = linux_raw_sys::general::S_IFREG as isize,
Directory = linux_raw_sys::general::S_IFDIR as isize,
Symlink = linux_raw_sys::general::S_IFLNK as isize,
#[doc(alias = "IFO")]
Fifo = linux_raw_sys::general::S_IFIFO as isize,
Socket = linux_raw_sys::general::S_IFSOCK as isize,
CharacterDevice = linux_raw_sys::general::S_IFCHR as isize,
BlockDevice = linux_raw_sys::general::S_IFBLK as isize,
Unknown,
}
impl FileType {
#[inline]
pub const fn from_raw_mode(st_mode: RawMode) -> Self {
match st_mode & linux_raw_sys::general::S_IFMT {
linux_raw_sys::general::S_IFREG => Self::RegularFile,
linux_raw_sys::general::S_IFDIR => Self::Directory,
linux_raw_sys::general::S_IFLNK => Self::Symlink,
linux_raw_sys::general::S_IFIFO => Self::Fifo,
linux_raw_sys::general::S_IFSOCK => Self::Socket,
linux_raw_sys::general::S_IFCHR => Self::CharacterDevice,
linux_raw_sys::general::S_IFBLK => Self::BlockDevice,
_ => Self::Unknown,
}
}
#[inline]
pub const fn as_raw_mode(self) -> RawMode {
match self {
Self::RegularFile => linux_raw_sys::general::S_IFREG,
Self::Directory => linux_raw_sys::general::S_IFDIR,
Self::Symlink => linux_raw_sys::general::S_IFLNK,
Self::Fifo => linux_raw_sys::general::S_IFIFO,
Self::Socket => linux_raw_sys::general::S_IFSOCK,
Self::CharacterDevice => linux_raw_sys::general::S_IFCHR,
Self::BlockDevice => linux_raw_sys::general::S_IFBLK,
Self::Unknown => linux_raw_sys::general::S_IFMT,
}
}
#[inline]
pub(crate) const fn from_dirent_d_type(d_type: u8) -> Self {
match d_type as u32 {
linux_raw_sys::general::DT_REG => Self::RegularFile,
linux_raw_sys::general::DT_DIR => Self::Directory,
linux_raw_sys::general::DT_LNK => Self::Symlink,
linux_raw_sys::general::DT_SOCK => Self::Socket,
linux_raw_sys::general::DT_FIFO => Self::Fifo,
linux_raw_sys::general::DT_CHR => Self::CharacterDevice,
linux_raw_sys::general::DT_BLK => Self::BlockDevice,
_ => Self::Unknown,
}
}
}
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[repr(u32)]
pub enum Advice {
Normal = linux_raw_sys::general::POSIX_FADV_NORMAL,
Sequential = linux_raw_sys::general::POSIX_FADV_SEQUENTIAL,
Random = linux_raw_sys::general::POSIX_FADV_RANDOM,
NoReuse = linux_raw_sys::general::POSIX_FADV_NOREUSE,
WillNeed = linux_raw_sys::general::POSIX_FADV_WILLNEED,
DontNeed = linux_raw_sys::general::POSIX_FADV_DONTNEED,
}
bitflags! {
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct MemfdFlags: ffi::c_uint {
const CLOEXEC = linux_raw_sys::general::MFD_CLOEXEC;
const ALLOW_SEALING = linux_raw_sys::general::MFD_ALLOW_SEALING;
const HUGETLB = linux_raw_sys::general::MFD_HUGETLB;
const NOEXEC_SEAL = linux_raw_sys::general::MFD_NOEXEC_SEAL;
const EXEC = linux_raw_sys::general::MFD_EXEC;
const HUGE_64KB = linux_raw_sys::general::MFD_HUGE_64KB;
const HUGE_512KB = linux_raw_sys::general::MFD_HUGE_512KB;
const HUGE_1MB = linux_raw_sys::general::MFD_HUGE_1MB;
const HUGE_2MB = linux_raw_sys::general::MFD_HUGE_2MB;
const HUGE_8MB = linux_raw_sys::general::MFD_HUGE_8MB;
const HUGE_16MB = linux_raw_sys::general::MFD_HUGE_16MB;
const HUGE_32MB = linux_raw_sys::general::MFD_HUGE_32MB;
const HUGE_256MB = linux_raw_sys::general::MFD_HUGE_256MB;
const HUGE_512MB = linux_raw_sys::general::MFD_HUGE_512MB;
const HUGE_1GB = linux_raw_sys::general::MFD_HUGE_1GB;
const HUGE_2GB = linux_raw_sys::general::MFD_HUGE_2GB;
const HUGE_16GB = linux_raw_sys::general::MFD_HUGE_16GB;
const _ = !0;
}
}
bitflags! {
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct SealFlags: u32 {
const SEAL = linux_raw_sys::general::F_SEAL_SEAL;
const SHRINK = linux_raw_sys::general::F_SEAL_SHRINK;
const GROW = linux_raw_sys::general::F_SEAL_GROW;
const WRITE = linux_raw_sys::general::F_SEAL_WRITE;
const FUTURE_WRITE = linux_raw_sys::general::F_SEAL_FUTURE_WRITE;
const _ = !0;
}
}
bitflags! {
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct FallocateFlags: u32 {
const KEEP_SIZE = linux_raw_sys::general::FALLOC_FL_KEEP_SIZE;
const PUNCH_HOLE = linux_raw_sys::general::FALLOC_FL_PUNCH_HOLE;
const NO_HIDE_STALE = linux_raw_sys::general::FALLOC_FL_NO_HIDE_STALE;
const COLLAPSE_RANGE = linux_raw_sys::general::FALLOC_FL_COLLAPSE_RANGE;
const ZERO_RANGE = linux_raw_sys::general::FALLOC_FL_ZERO_RANGE;
const INSERT_RANGE = linux_raw_sys::general::FALLOC_FL_INSERT_RANGE;
const UNSHARE_RANGE = linux_raw_sys::general::FALLOC_FL_UNSHARE_RANGE;
const _ = !0;
}
}
bitflags! {
#[repr(transparent)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct StatVfsMountFlags: u64 {
const MANDLOCK = linux_raw_sys::general::MS_MANDLOCK as u64;
const NOATIME = linux_raw_sys::general::MS_NOATIME as u64;
const NODEV = linux_raw_sys::general::MS_NODEV as u64;
const NODIRATIME = linux_raw_sys::general::MS_NODIRATIME as u64;
const NOEXEC = linux_raw_sys::general::MS_NOEXEC as u64;
const NOSUID = linux_raw_sys::general::MS_NOSUID as u64;
const RDONLY = linux_raw_sys::general::MS_RDONLY as u64;
const RELATIME = linux_raw_sys::general::MS_RELATIME as u64;
const SYNCHRONOUS = linux_raw_sys::general::MS_SYNCHRONOUS as u64;
const _ = !0;
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[repr(u32)]
pub enum FlockOperation {
LockShared = linux_raw_sys::general::LOCK_SH,
LockExclusive = linux_raw_sys::general::LOCK_EX,
Unlock = linux_raw_sys::general::LOCK_UN,
NonBlockingLockShared = linux_raw_sys::general::LOCK_SH | linux_raw_sys::general::LOCK_NB,
NonBlockingLockExclusive = linux_raw_sys::general::LOCK_EX | linux_raw_sys::general::LOCK_NB,
NonBlockingUnlock = linux_raw_sys::general::LOCK_UN | linux_raw_sys::general::LOCK_NB,
}
#[cfg(any(
target_pointer_width = "32",
target_arch = "mips64",
target_arch = "mips64r6"
))]
#[derive(Debug, Copy, Clone)]
#[allow(missing_docs)]
#[non_exhaustive]
pub struct Stat {
pub st_dev: u64,
pub st_mode: u32,
pub st_nlink: u32,
pub st_uid: u32,
pub st_gid: u32,
pub st_rdev: u64,
pub st_size: i64,
pub st_blksize: u32,
pub st_blocks: u64,
pub st_atime: i64,
pub st_atime_nsec: u32,
pub st_mtime: i64,
pub st_mtime_nsec: u32,
pub st_ctime: i64,
pub st_ctime_nsec: u32,
pub st_ino: u64,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
#[allow(missing_docs)]
#[non_exhaustive]
#[cfg(target_arch = "x86_64")]
pub struct Stat {
pub st_dev: ffi::c_ulong,
pub st_ino: ffi::c_ulong,
pub st_nlink: ffi::c_ulong,
pub st_mode: ffi::c_uint,
pub st_uid: ffi::c_uint,
pub st_gid: ffi::c_uint,
pub(crate) __pad0: ffi::c_uint,
pub st_rdev: ffi::c_ulong,
pub st_size: ffi::c_long,
pub st_blksize: ffi::c_long,
pub st_blocks: ffi::c_long,
pub st_atime: ffi::c_long,
pub st_atime_nsec: ffi::c_ulong,
pub st_mtime: ffi::c_long,
pub st_mtime_nsec: ffi::c_ulong,
pub st_ctime: ffi::c_long,
pub st_ctime_nsec: ffi::c_ulong,
pub(crate) __unused: [ffi::c_long; 3],
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
#[allow(missing_docs)]
#[non_exhaustive]
#[cfg(target_arch = "aarch64")]
pub struct Stat {
pub st_dev: ffi::c_ulong,
pub st_ino: ffi::c_ulong,
pub st_mode: ffi::c_uint,
pub st_nlink: ffi::c_uint,
pub st_uid: ffi::c_uint,
pub st_gid: ffi::c_uint,
pub st_rdev: ffi::c_ulong,
pub(crate) __pad1: ffi::c_ulong,
pub st_size: ffi::c_long,
pub st_blksize: ffi::c_int,
pub(crate) __pad2: ffi::c_int,
pub st_blocks: ffi::c_long,
pub st_atime: ffi::c_long,
pub st_atime_nsec: ffi::c_ulong,
pub st_mtime: ffi::c_long,
pub st_mtime_nsec: ffi::c_ulong,
pub st_ctime: ffi::c_long,
pub st_ctime_nsec: ffi::c_ulong,
pub(crate) __unused4: ffi::c_uint,
pub(crate) __unused5: ffi::c_uint,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
#[allow(missing_docs)]
#[non_exhaustive]
#[cfg(target_arch = "riscv64")]
pub struct Stat {
pub st_dev: ffi::c_ulong,
pub st_ino: ffi::c_ulong,
pub st_mode: ffi::c_uint,
pub st_nlink: ffi::c_uint,
pub st_uid: ffi::c_uint,
pub st_gid: ffi::c_uint,
pub st_rdev: ffi::c_ulong,
pub(crate) __pad1: ffi::c_ulong,
pub st_size: ffi::c_long,
pub st_blksize: ffi::c_int,
pub(crate) __pad2: ffi::c_int,
pub st_blocks: ffi::c_long,
pub st_atime: ffi::c_long,
pub st_atime_nsec: ffi::c_ulong,
pub st_mtime: ffi::c_long,
pub st_mtime_nsec: ffi::c_ulong,
pub st_ctime: ffi::c_long,
pub st_ctime_nsec: ffi::c_ulong,
pub(crate) __unused4: ffi::c_uint,
pub(crate) __unused5: ffi::c_uint,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
#[allow(missing_docs)]
#[non_exhaustive]
#[cfg(target_arch = "powerpc64")]
pub struct Stat {
pub st_dev: ffi::c_ulong,
pub st_ino: ffi::c_ulong,
pub st_nlink: ffi::c_ulong,
pub st_mode: ffi::c_uint,
pub st_uid: ffi::c_uint,
pub st_gid: ffi::c_uint,
pub st_rdev: ffi::c_ulong,
pub st_size: ffi::c_long,
pub st_blksize: ffi::c_ulong,
pub st_blocks: ffi::c_ulong,
pub st_atime: ffi::c_long,
pub st_atime_nsec: ffi::c_ulong,
pub st_mtime: ffi::c_long,
pub st_mtime_nsec: ffi::c_ulong,
pub st_ctime: ffi::c_long,
pub st_ctime_nsec: ffi::c_ulong,
pub(crate) __unused4: ffi::c_ulong,
pub(crate) __unused5: ffi::c_ulong,
pub(crate) __unused6: ffi::c_ulong,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
#[allow(missing_docs)]
#[non_exhaustive]
#[cfg(target_arch = "s390x")]
pub struct Stat {
pub st_dev: ffi::c_ulong,
pub st_ino: ffi::c_ulong,
pub st_nlink: ffi::c_ulong,
pub st_mode: ffi::c_uint,
pub st_uid: ffi::c_uint,
pub st_gid: ffi::c_uint,
pub(crate) __pad1: ffi::c_uint,
pub st_rdev: ffi::c_ulong,
pub st_size: ffi::c_long, pub st_atime: ffi::c_long,
pub st_atime_nsec: ffi::c_ulong,
pub st_mtime: ffi::c_long,
pub st_mtime_nsec: ffi::c_ulong,
pub st_ctime: ffi::c_long,
pub st_ctime_nsec: ffi::c_ulong,
pub st_blksize: ffi::c_ulong,
pub st_blocks: ffi::c_long,
pub(crate) __unused: [ffi::c_ulong; 3],
}
#[allow(clippy::module_name_repetitions)]
#[repr(C)]
#[cfg_attr(target_arch = "arm", repr(packed(4)))]
#[derive(Debug, Copy, Clone)]
#[allow(missing_docs)]
#[non_exhaustive]
pub struct StatFs {
pub f_type: FsWord,
#[cfg(not(any(target_arch = "arm", target_arch = "s390x")))]
pub f_bsize: ffi::c_long,
#[cfg(any(target_arch = "arm", target_arch = "s390x"))]
pub f_bsize: ffi::c_uint,
pub f_blocks: u64,
pub f_bfree: u64,
pub f_bavail: u64,
pub f_files: u64,
pub f_ffree: u64,
pub f_fsid: Fsid,
#[cfg(not(any(target_arch = "arm", target_arch = "s390x")))]
pub f_namelen: ffi::c_long,
#[cfg(any(target_arch = "arm", target_arch = "s390x"))]
pub f_namelen: ffi::c_uint,
#[cfg(not(any(target_arch = "arm", target_arch = "s390x")))]
pub f_frsize: ffi::c_long,
#[cfg(any(target_arch = "arm", target_arch = "s390x"))]
pub f_frsize: ffi::c_uint,
#[cfg(not(any(target_arch = "arm", target_arch = "s390x")))]
pub f_flags: ffi::c_long,
#[cfg(any(target_arch = "arm", target_arch = "s390x"))]
pub f_flags: ffi::c_uint,
#[cfg(not(target_arch = "s390x"))]
pub(crate) f_spare: [ffi::c_long; 4],
#[cfg(target_arch = "s390x")]
pub(crate) f_spare: [ffi::c_uint; 5],
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
#[allow(missing_docs)]
pub struct Fsid {
pub(crate) val: [ffi::c_int; 2],
}
#[allow(missing_docs)]
pub struct StatVfs {
pub f_bsize: u64,
pub f_frsize: u64,
pub f_blocks: u64,
pub f_bfree: u64,
pub f_bavail: u64,
pub f_files: u64,
pub f_ffree: u64,
pub f_favail: u64,
pub f_fsid: u64,
pub f_flag: StatVfsMountFlags,
pub f_namemax: u64,
}
pub type RawMode = ffi::c_uint;
pub type Dev = u64;
#[cfg(not(any(
target_arch = "mips64",
target_arch = "mips64r6",
target_arch = "s390x"
)))]
pub type FsWord = ffi::c_long;
#[cfg(any(target_arch = "mips64", target_arch = "mips64r6"))]
pub type FsWord = i64;
#[cfg(target_arch = "s390x")]
pub type FsWord = u32;