libbtrfs 0.0.20

Rust library for working with the btrfs filesystem
Documentation
#[cfg(feature = "use-syscalls")]
pub(crate) mod use_syscalls;

mod subvolume;
pub(crate) use subvolume::*;

mod path;
pub(crate) use path::*;

mod common {
    use std::{
        fs::File,
        io,
        os::unix::io::{AsRawFd, RawFd},
    };

    /// Enum that holds either a raw file descriptor [`RawFd`] or a rust file type [`File`]
    ///
    /// Implements `AsRawFd` so the raw file descriptor can be obtained for either variant
    pub enum OptionFd {
        Raw(RawFd),
        File(File),
    }

    impl AsRawFd for OptionFd {
        fn as_raw_fd(&self) -> RawFd {
            match self {
                Self::Raw(fd) => *fd,
                Self::File(file) => file.as_raw_fd(),
            }
        }
    }

    // Note: ioctl handlers are by filesystem type of the file descriptor argument.
    //
    /// Ioctl wrapper function for the btrfs filesystem
    ///
    /// Returns [`io::ErrorKind::Unsupported`] if the file descriptor is not btrfs
    pub fn btrfs_ioctl<T>(fd: RawFd, op: libc::Ioctl, argp: *mut T) -> io::Result<()> {
        if crate::fs::fd::is_btrfs(fd)? {
            syscall!(unsafe { ioctl(fd, op, argp) })?;
        } else {
            error!(Unsupported);
        }
        Ok(())
    }
}
pub use common::*;