use super::*;
use crate::{
KernelStr,
bindings::{
BTRFS_IOC_GET_SUBVOL_ROOTREF, btrfs_ioctl_get_subvol_rootref_args,
btrfs_ioctl_get_subvol_rootref_args__bindgen_ty_1,
},
};
#[repr(transparent)]
pub struct SubvolRootRef(btrfs_ioctl_get_subvol_rootref_args__bindgen_ty_1);
impl SubvolRootRef
{
pub const fn treeid(&self) -> u64
{
self.0.treeid
}
pub const fn dirid(&self) -> u64
{
self.0.dirid
}
}
pub fn get_rootref<P, F>(subvol: P, f: F) -> IoResult<()>
where
P: AsRef<Path>,
F: FnMut(SubvolRootRef, KernelStr<'_>, KernelStr<'_>) -> IoResult<()>,
{
File::open(subvol).and_then(|r| io::get_rootref(r, f))
}
pub mod io
{
use super::*;
pub fn get_rootref<R, F>(resource: R, mut f: F) -> IoResult<()>
where
R: AsFd,
F: FnMut(SubvolRootRef, KernelStr<'_>, KernelStr<'_>) -> IoResult<()>,
{
let mut args: btrfs_ioctl_get_subvol_rootref_args =
unsafe { MaybeUninit::zeroed().assume_init() };
btrfs_ioctl(resource.as_fd(), BTRFS_IOC_GET_SUBVOL_ROOTREF, &mut args)?;
let mut lubuf = crate::lookup::UserLookup::from(resource.as_fd());
for rref in args.rootref.into_iter().take(args.num_items as usize) {
let rref = SubvolRootRef(rref);
let (lookup, name) = lubuf.path_str(rref.dirid(), rref.treeid())?;
f(rref, lookup, name)?;
}
Ok(())
}
}