diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2024-05-26 20:38:08 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2024-05-26 20:38:08 -0400 |
commit | aa985e6a44a58fa0d508cda7fdaa63acf872ced8 (patch) | |
tree | f15b7a1207f024abb12c6fc8d12c9e7adba778e1 /src | |
parent | 5b216318b887283d1b22fda055bb7cf381e6ae10 (diff) |
Format with rustfmt
Note that we're using struct/enum align options, which require nightly.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'src')
-rw-r--r-- | src/bcachefs.rs | 11 | ||||
-rw-r--r-- | src/commands/list.rs | 118 | ||||
-rw-r--r-- | src/commands/mod.rs | 8 | ||||
-rw-r--r-- | src/commands/mount.rs | 78 | ||||
-rw-r--r-- | src/commands/subvolume.rs | 42 | ||||
-rw-r--r-- | src/key.rs | 43 | ||||
-rw-r--r-- | src/wrappers/handle.rs | 77 |
7 files changed, 231 insertions, 146 deletions
diff --git a/src/bcachefs.rs b/src/bcachefs.rs index e8099ffa..d201acfd 100644 --- a/src/bcachefs.rs +++ b/src/bcachefs.rs @@ -1,11 +1,11 @@ -mod wrappers; mod commands; mod key; +mod wrappers; use std::ffi::{c_char, CString}; -use commands::logger::SimpleLogger; use bch_bindgen::c; +use commands::logger::SimpleLogger; #[derive(Debug)] pub struct ErrnoError(pub errno::Errno); @@ -25,10 +25,7 @@ fn handle_c_command(mut argv: Vec<String>, symlink_cmd: Option<&str>) -> i32 { let argc: i32 = argv.len().try_into().unwrap(); - let argv: Vec<_> = argv - .into_iter() - .map(|s| CString::new(s).unwrap()) - .collect(); + let argv: Vec<_> = argv.into_iter().map(|s| CString::new(s).unwrap()).collect(); let mut argv = argv .into_iter() .map(|s| Box::into_raw(s.into_boxed_c_str()) as *mut c_char) @@ -41,7 +38,7 @@ fn handle_c_command(mut argv: Vec<String>, symlink_cmd: Option<&str>) -> i32 { "--help" => { c::bcachefs_usage(); 0 - }, + } "data" => c::data_cmds(argc, argv), "device" => c::device_cmds(argc, argv), "dump" => c::cmd_dump(argc, argv), diff --git a/src/commands/list.rs b/src/commands/list.rs index fd61a516..082c9dc4 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs @@ -1,20 +1,23 @@ -use log::{error}; use bch_bindgen::bcachefs; -use bch_bindgen::opt_set; -use bch_bindgen::fs::Fs; use bch_bindgen::bkey::BkeySC; -use bch_bindgen::btree::BtreeTrans; use bch_bindgen::btree::BtreeIter; -use bch_bindgen::btree::BtreeNodeIter; use bch_bindgen::btree::BtreeIterFlags; -use clap::{Parser}; +use bch_bindgen::btree::BtreeNodeIter; +use bch_bindgen::btree::BtreeTrans; +use bch_bindgen::fs::Fs; +use bch_bindgen::opt_set; +use clap::Parser; +use log::error; use std::io::{stdout, IsTerminal}; fn list_keys(fs: &Fs, opt: Cli) -> anyhow::Result<()> { let trans = BtreeTrans::new(fs); - let mut iter = BtreeIter::new(&trans, opt.btree, opt.start, - BtreeIterFlags::ALL_SNAPSHOTS| - BtreeIterFlags::PREFETCH); + let mut iter = BtreeIter::new( + &trans, + opt.btree, + opt.start, + BtreeIterFlags::ALL_SNAPSHOTS | BtreeIterFlags::PREFETCH, + ); while let Some(k) = iter.peek_and_restart()? { if k.k.p > opt.end { @@ -37,9 +40,14 @@ fn list_keys(fs: &Fs, opt: Cli) -> anyhow::Result<()> { fn list_btree_formats(fs: &Fs, opt: Cli) -> anyhow::Result<()> { let trans = BtreeTrans::new(fs); - let mut iter = BtreeNodeIter::new(&trans, opt.btree, opt.start, - 0, opt.level, - BtreeIterFlags::PREFETCH); + let mut iter = BtreeNodeIter::new( + &trans, + opt.btree, + opt.start, + 0, + opt.level, + BtreeIterFlags::PREFETCH, + ); while let Some(b) = iter.peek_and_restart()? { if b.key.k.p > opt.end { @@ -55,9 +63,14 @@ fn list_btree_formats(fs: &Fs, opt: Cli) -> anyhow::Result<()> { fn list_btree_nodes(fs: &Fs, opt: Cli) -> anyhow::Result<()> { let trans = BtreeTrans::new(fs); - let mut iter = BtreeNodeIter::new(&trans, opt.btree, opt.start, - 0, opt.level, - BtreeIterFlags::PREFETCH); + let mut iter = BtreeNodeIter::new( + &trans, + opt.btree, + opt.start, + 0, + opt.level, + BtreeIterFlags::PREFETCH, + ); while let Some(b) = iter.peek_and_restart()? { if b.key.k.p > opt.end { @@ -73,9 +86,14 @@ fn list_btree_nodes(fs: &Fs, opt: Cli) -> anyhow::Result<()> { fn list_nodes_ondisk(fs: &Fs, opt: Cli) -> anyhow::Result<()> { let trans = BtreeTrans::new(fs); - let mut iter = BtreeNodeIter::new(&trans, opt.btree, opt.start, - 0, opt.level, - BtreeIterFlags::PREFETCH); + let mut iter = BtreeNodeIter::new( + &trans, + opt.btree, + opt.start, + 0, + opt.level, + BtreeIterFlags::PREFETCH, + ); while let Some(b) = iter.peek_and_restart()? { if b.key.k.p > opt.end { @@ -102,69 +120,77 @@ enum Mode { pub struct Cli { /// Btree to list from #[arg(short, long, default_value_t=bcachefs::btree_id::BTREE_ID_extents)] - btree: bcachefs::btree_id, + btree: bcachefs::btree_id, /// Bkey type to list - #[arg(short='k', long)] - bkey_type: Option<bcachefs::bch_bkey_type>, + #[arg(short = 'k', long)] + bkey_type: Option<bcachefs::bch_bkey_type>, /// Btree depth to descend to (0 == leaves) - #[arg(short, long, default_value_t=0)] - level: u32, + #[arg(short, long, default_value_t = 0)] + level: u32, /// Start position to list from - #[arg(short, long, default_value="POS_MIN")] - start: bcachefs::bpos, + #[arg(short, long, default_value = "POS_MIN")] + start: bcachefs::bpos, /// End position - #[arg(short, long, default_value="SPOS_MAX")] - end: bcachefs::bpos, + #[arg(short, long, default_value = "SPOS_MAX")] + end: bcachefs::bpos, - #[arg(short, long, default_value="keys")] - mode: Mode, + #[arg(short, long, default_value = "keys")] + mode: Mode, /// Check (fsck) the filesystem first #[arg(short, long)] - fsck: bool, + fsck: bool, /// Force color on/off. Default: autodetect tty #[arg(short, long, action = clap::ArgAction::Set, default_value_t=stdout().is_terminal())] - colorize: bool, + colorize: bool, /// Verbose mode #[arg(short, long)] - verbose: bool, + verbose: bool, #[arg(required(true))] - devices: Vec<std::path::PathBuf>, + devices: Vec<std::path::PathBuf>, } fn cmd_list_inner(opt: Cli) -> anyhow::Result<()> { let mut fs_opts: bcachefs::bch_opts = Default::default(); - opt_set!(fs_opts, nochanges, 1); - opt_set!(fs_opts, read_only, 1); - opt_set!(fs_opts, norecovery, 1); - opt_set!(fs_opts, degraded, 1); - opt_set!(fs_opts, very_degraded, 1); - opt_set!(fs_opts, errors, bcachefs::bch_error_actions::BCH_ON_ERROR_continue as u8); + opt_set!(fs_opts, nochanges, 1); + opt_set!(fs_opts, read_only, 1); + opt_set!(fs_opts, norecovery, 1); + opt_set!(fs_opts, degraded, 1); + opt_set!(fs_opts, very_degraded, 1); + opt_set!( + fs_opts, + errors, + bcachefs::bch_error_actions::BCH_ON_ERROR_continue as u8 + ); if opt.fsck { - opt_set!(fs_opts, fix_errors, bcachefs::fsck_err_opts::FSCK_FIX_yes as u8); - opt_set!(fs_opts, norecovery, 0); + opt_set!( + fs_opts, + fix_errors, + bcachefs::fsck_err_opts::FSCK_FIX_yes as u8 + ); + opt_set!(fs_opts, norecovery, 0); } if opt.verbose { - opt_set!(fs_opts, verbose, 1); + opt_set!(fs_opts, verbose, 1); } let fs = Fs::open(&opt.devices, fs_opts)?; match opt.mode { - Mode::Keys => list_keys(&fs, opt), - Mode::Formats => list_btree_formats(&fs, opt), - Mode::Nodes => list_btree_nodes(&fs, opt), - Mode::NodesOndisk => list_nodes_ondisk(&fs, opt), + Mode::Keys => list_keys(&fs, opt), + Mode::Formats => list_btree_formats(&fs, opt), + Mode::Nodes => list_btree_nodes(&fs, opt), + Mode::NodesOndisk => list_nodes_ondisk(&fs, opt), } } diff --git a/src/commands/mod.rs b/src/commands/mod.rs index c7645926..07c25966 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1,14 +1,14 @@ use clap::Subcommand; +pub mod completions; +pub mod list; pub mod logger; pub mod mount; -pub mod list; -pub mod completions; pub mod subvolume; -pub use mount::mount; -pub use list::list; pub use completions::completions; +pub use list::list; +pub use mount::mount; pub use subvolume::subvolume; #[derive(clap::Parser, Debug)] diff --git a/src/commands/mount.rs b/src/commands/mount.rs index 79667cca..f8edf9bc 100644 --- a/src/commands/mount.rs +++ b/src/commands/mount.rs @@ -1,14 +1,14 @@ -use bch_bindgen::{path_to_cstr, bcachefs, bcachefs::bch_sb_handle, opt_set}; -use log::{info, debug, error, LevelFilter}; -use std::collections::HashMap; +use crate::key; +use crate::key::UnlockPolicy; +use bch_bindgen::{bcachefs, bcachefs::bch_sb_handle, opt_set, path_to_cstr}; use clap::Parser; -use uuid::Uuid; +use log::{debug, error, info, LevelFilter}; +use std::collections::HashMap; +use std::ffi::{c_char, c_void, CString}; use std::io::{stdout, IsTerminal}; use std::path::{Path, PathBuf}; -use std::{fs, str, env}; -use crate::key; -use crate::key::UnlockPolicy; -use std::ffi::{CString, c_char, c_void}; +use std::{env, fs, str}; +use uuid::Uuid; fn mount_inner( src: String, @@ -17,7 +17,6 @@ fn mount_inner( mountflags: libc::c_ulong, data: Option<String>, ) -> anyhow::Result<()> { - // bind the CStrings to keep them alive let src = CString::new(src)?; let target = path_to_cstr(target); @@ -52,22 +51,22 @@ fn parse_mount_options(options: impl AsRef<str>) -> (Option<String>, libc::c_ulo .as_ref() .split(',') .map(|o| match o { - "dirsync" => Left(libc::MS_DIRSYNC), - "lazytime" => Left(1 << 25), // MS_LAZYTIME - "mand" => Left(libc::MS_MANDLOCK), - "noatime" => Left(libc::MS_NOATIME), - "nodev" => Left(libc::MS_NODEV), - "nodiratime" => Left(libc::MS_NODIRATIME), - "noexec" => Left(libc::MS_NOEXEC), - "nosuid" => Left(libc::MS_NOSUID), - "relatime" => Left(libc::MS_RELATIME), - "remount" => Left(libc::MS_REMOUNT), - "ro" => Left(libc::MS_RDONLY), - "rw" => Left(0), - "strictatime" => Left(libc::MS_STRICTATIME), - "sync" => Left(libc::MS_SYNCHRONOUS), - "" => Left(0), - o => Right(o), + "dirsync" => Left(libc::MS_DIRSYNC), + "lazytime" => Left(1 << 25), // MS_LAZYTIME + "mand" => Left(libc::MS_MANDLOCK), + "noatime" => Left(libc::MS_NOATIME), + "nodev" => Left(libc::MS_NODEV), + "nodiratime" => Left(libc::MS_NODIRATIME), + "noexec" => Left(libc::MS_NOEXEC), + "nosuid" => Left(libc::MS_NOSUID), + "relatime" => Left(libc::MS_RELATIME), + "remount" => Left(libc::MS_REMOUNT), + "ro" => Left(libc::MS_RDONLY), + "rw" => Left(0), + "strictatime" => Left(libc::MS_STRICTATIME), + "sync" => Left(libc::MS_SYNCHRONOUS), + "" => Left(0), + o => Right(o), }) .fold((Vec::new(), 0), |(mut opts, flags), next| match next { Left(f) => (opts, flags | f), @@ -235,7 +234,7 @@ pub struct Cli { /// by the specified passphrase file; it is decrypted. (i.e. Regardless /// if "fail" is specified for key_location/unlock_policy.) #[arg(short = 'f', long)] - passphrase_file: Option<PathBuf>, + passphrase_file: Option<PathBuf>, /// Password policy to use in case of encrypted filesystem. /// @@ -243,28 +242,33 @@ pub struct Cli { /// "fail" - don't ask for password, fail if filesystem is encrypted; /// "wait" - wait for password to become available before mounting; /// "ask" - prompt the user for password; - #[arg(short = 'k', long = "key_location", default_value = "ask", verbatim_doc_comment)] - unlock_policy: UnlockPolicy, + #[arg( + short = 'k', + long = "key_location", + default_value = "ask", + verbatim_doc_comment + )] + unlock_policy: UnlockPolicy, /// Device, or UUID=\<UUID\> - dev: String, + dev: String, /// Where the filesystem should be mounted. If not set, then the filesystem /// won't actually be mounted. But all steps preceeding mounting the /// filesystem (e.g. asking for passphrase) will still be performed. - mountpoint: Option<PathBuf>, + mountpoint: Option<PathBuf>, /// Mount options #[arg(short, default_value = "")] - options: String, + options: String, /// Force color on/off. Autodetect tty is used to define default: #[arg(short, long, action = clap::ArgAction::Set, default_value_t=stdout().is_terminal())] - colorize: bool, + colorize: bool, /// Verbose mode #[arg(short, long, action = clap::ArgAction::Count)] - verbose: u8, + verbose: u8, } fn devs_str_sbs_from_uuid( @@ -358,7 +362,10 @@ fn cmd_mount_inner(opt: Cli) -> anyhow::Result<()> { { // First by password_file, if available let fallback_to_unlock_policy = if let Some(passphrase_file) = &opt.passphrase_file { - match key::read_from_passphrase_file(&block_devices_to_mount[0], passphrase_file.as_path()) { + match key::read_from_passphrase_file( + &block_devices_to_mount[0], + passphrase_file.as_path(), + ) { Ok(()) => { // Decryption succeeded false @@ -391,8 +398,7 @@ fn cmd_mount_inner(opt: Cli) -> anyhow::Result<()> { } else { info!( "would mount with params: device: {}, options: {}", - devices, - &opt.options + devices, &opt.options ); } diff --git a/src/commands/subvolume.rs b/src/commands/subvolume.rs index 5f7cdc76..0691e34d 100644 --- a/src/commands/subvolume.rs +++ b/src/commands/subvolume.rs @@ -17,13 +17,13 @@ enum Subcommands { #[command(visible_aliases = ["new"])] Create { /// Paths - targets: Vec<PathBuf> + targets: Vec<PathBuf>, }, #[command(visible_aliases = ["del"])] Delete { /// Path - target: PathBuf + target: PathBuf, }, #[command(allow_missing_positional = true, visible_aliases = ["snap"])] @@ -31,9 +31,9 @@ enum Subcommands { /// Make snapshot read only #[arg(long, short)] read_only: bool, - source: Option<PathBuf>, - dest: PathBuf - } + source: Option<PathBuf>, + dest: PathBuf, + }, } pub fn subvolume(argv: Vec<String>) -> i32 { @@ -44,24 +44,42 @@ pub fn subvolume(argv: Vec<String>) -> i32 { for target in targets { if let Some(dirname) = target.parent() { let fs = unsafe { BcachefsHandle::open(dirname) }; - fs.create_subvolume(target).expect("Failed to create the subvolume"); + fs.create_subvolume(target) + .expect("Failed to create the subvolume"); } } } - , Subcommands::Delete { target } => { if let Some(dirname) = target.parent() { let fs = unsafe { BcachefsHandle::open(dirname) }; - fs.delete_subvolume(target).expect("Failed to delete the subvolume"); + fs.delete_subvolume(target) + .expect("Failed to delete the subvolume"); } - }, - Subcommands::Snapshot { read_only, source, dest } => { + } + Subcommands::Snapshot { + read_only, + source, + dest, + } => { if let Some(dirname) = dest.parent() { let dot = PathBuf::from("."); - let dir = if dirname.as_os_str().is_empty() { &dot } else { dirname }; + let dir = if dirname.as_os_str().is_empty() { + &dot + } else { + dirname + }; let fs = unsafe { BcachefsHandle::open(dir) }; - fs.snapshot_subvolume(if read_only { BCH_SUBVOL_SNAPSHOT_RO } else { 0x0 }, source, dest).expect("Failed to snapshot the subvolume"); + fs.snapshot_subvolume( + if read_only { + BCH_SUBVOL_SNAPSHOT_RO + } else { + 0x0 + }, + source, + dest, + ) + .expect("Failed to snapshot the subvolume"); } } } @@ -1,10 +1,13 @@ -use std::{fmt, fs, io::{stdin, IsTerminal}}; +use std::{ + fmt, fs, + io::{stdin, IsTerminal}, +}; -use log::info; -use bch_bindgen::bcachefs::bch_sb_handle; -use clap::builder::PossibleValue; use crate::c_str; use anyhow::anyhow; +use bch_bindgen::bcachefs::bch_sb_handle; +use clap::builder::PossibleValue; +use log::info; #[derive(Clone, Debug)] pub enum UnlockPolicy { @@ -18,11 +21,11 @@ impl std::str::FromStr for UnlockPolicy { type Err = anyhow::Error; fn from_str(s: &str) -> anyhow::Result<Self> { match s { - ""|"none" => Ok(UnlockPolicy::None), - "fail" => Ok(UnlockPolicy::Fail), - "wait" => Ok(UnlockPolicy::Wait), - "ask" => Ok(UnlockPolicy::Ask), - _ => Err(anyhow!("Invalid unlock policy provided")), + "" | "none" => Ok(UnlockPolicy::None), + "fail" => Ok(UnlockPolicy::Fail), + "wait" => Ok(UnlockPolicy::Wait), + "ask" => Ok(UnlockPolicy::Ask), + _ => Err(anyhow!("Invalid unlock policy provided")), } } } @@ -152,18 +155,32 @@ fn unlock_master_key(sb: &bch_sb_handle, passphrase: &str) -> anyhow::Result<()> } } -pub fn read_from_passphrase_file(block_device: &bch_sb_handle, passphrase_file: &std::path::Path) -> anyhow::Result<()> { +pub fn read_from_passphrase_file( + block_device: &bch_sb_handle, + passphrase_file: &std::path::Path, +) -> anyhow::Result<()> { // Attempts to unlock the master key by password_file // Return true if unlock was successful, false otherwise - info!("Attempting to unlock master key for filesystem {}, using password from file {}", block_device.sb().uuid(), passphrase_file.display()); + info!( + "Attempting to unlock master key for filesystem {}, using password from file {}", + block_device.sb().uuid(), + passphrase_file.display() + ); // Read the contents of the password_file into a string let passphrase = fs::read_to_string(passphrase_file)?; // Call decrypt_master_key with the read string unlock_master_key(block_device, &passphrase) } -pub fn apply_key_unlocking_policy(block_device: &bch_sb_handle, unlock_policy: UnlockPolicy) -> anyhow::Result<()> { - info!("Attempting to unlock master key for filesystem {}, using unlock policy {}", block_device.sb().uuid(), unlock_policy); +pub fn apply_key_unlocking_policy( + block_device: &bch_sb_handle, + unlock_policy: UnlockPolicy, +) -> anyhow::Result<()> { + info!( + "Attempting to unlock master key for filesystem {}, using unlock policy {}", + block_device.sb().uuid(), + unlock_policy + ); match unlock_policy { UnlockPolicy::Fail => Err(anyhow!("no passphrase available")), UnlockPolicy::Wait => Ok(wait_for_unlock(&block_device.sb().uuid())?), diff --git a/src/wrappers/handle.rs b/src/wrappers/handle.rs index 50023745..fa065dec 100644 --- a/src/wrappers/handle.rs +++ b/src/wrappers/handle.rs @@ -1,13 +1,16 @@ use std::path::Path; -use bch_bindgen::c::{bchfs_handle, BCH_IOCTL_SUBVOLUME_CREATE, BCH_IOCTL_SUBVOLUME_DESTROY, bch_ioctl_subvolume, bcache_fs_open, BCH_SUBVOL_SNAPSHOT_CREATE, bcache_fs_close}; +use bch_bindgen::c::{ + bcache_fs_close, bcache_fs_open, bch_ioctl_subvolume, bchfs_handle, BCH_IOCTL_SUBVOLUME_CREATE, + BCH_IOCTL_SUBVOLUME_DESTROY, BCH_SUBVOL_SNAPSHOT_CREATE, +}; use bch_bindgen::path_to_cstr; use errno::Errno; /// A handle to a bcachefs filesystem /// This can be used to send [`libc::ioctl`] to the underlying filesystem. pub(crate) struct BcachefsHandle { - inner: bchfs_handle + inner: bchfs_handle, } impl BcachefsHandle { @@ -16,13 +19,13 @@ impl BcachefsHandle { pub(crate) unsafe fn open<P: AsRef<Path>>(path: P) -> Self { let path = path_to_cstr(path); Self { - inner: bcache_fs_open(path.as_ptr()) + inner: bcache_fs_open(path.as_ptr()), } } } /// I/O control commands that can be sent to a bcachefs filesystem -/// Those are non-exhaustive +/// Those are non-exhaustive #[repr(u32)] #[non_exhaustive] pub enum BcachefsIoctl { @@ -39,14 +42,18 @@ pub enum BcachefsIoctlPayload { impl From<&BcachefsIoctlPayload> for *const libc::c_void { fn from(value: &BcachefsIoctlPayload) -> Self { match value { - BcachefsIoctlPayload::Subvolume(p) => p as *const _ as *const libc::c_void + BcachefsIoctlPayload::Subvolume(p) => p as *const _ as *const libc::c_void, } } } impl BcachefsHandle { /// Type-safe [`libc::ioctl`] for bcachefs filesystems - pub fn ioctl(&self, request: BcachefsIoctl, payload: &BcachefsIoctlPayload) -> Result<(), Errno> { + pub fn ioctl( + &self, + request: BcachefsIoctl, + payload: &BcachefsIoctlPayload, + ) -> Result<(), Errno> { let payload_ptr: *const libc::c_void = payload.into(); let ret = unsafe { libc::ioctl(self.inner.ioctl_fd, request as libc::Ioctl, payload_ptr) }; @@ -61,41 +68,55 @@ impl BcachefsHandle { /// at the given path pub fn create_subvolume<P: AsRef<Path>>(&self, dst: P) -> Result<(), Errno> { let dst = path_to_cstr(dst); - self.ioctl(BcachefsIoctl::SubvolumeCreate, &BcachefsIoctlPayload::Subvolume(bch_ioctl_subvolume { - dirfd: libc::AT_FDCWD as u32, - mode: 0o777, - dst_ptr: dst.as_ptr() as u64, - ..Default::default() - })) + self.ioctl( + BcachefsIoctl::SubvolumeCreate, + &BcachefsIoctlPayload::Subvolume(bch_ioctl_subvolume { + dirfd: libc::AT_FDCWD as u32, + mode: 0o777, + dst_ptr: dst.as_ptr() as u64, + ..Default::default() + }), + ) } /// Delete the subvolume at the given path /// for this bcachefs filesystem pub fn delete_subvolume<P: AsRef<Path>>(&self, dst: P) -> Result<(), Errno> { let dst = path_to_cstr(dst); - self.ioctl(BcachefsIoctl::SubvolumeDestroy, &BcachefsIoctlPayload::Subvolume(bch_ioctl_subvolume { - dirfd: libc::AT_FDCWD as u32, - mode: 0o777, - dst_ptr: dst.as_ptr() as u64, - ..Default::default() - })) + self.ioctl( + BcachefsIoctl::SubvolumeDestroy, + &BcachefsIoctlPayload::Subvolume(bch_ioctl_subvolume { + dirfd: libc::AT_FDCWD as u32, + mode: 0o777, + dst_ptr: dst.as_ptr() as u64, + ..Default::default() + }), + ) } /// Snapshot a subvolume for this bcachefs filesystem /// at the given path - pub fn snapshot_subvolume<P: AsRef<Path>>(&self, extra_flags: u32, src: Option<P>, dst: P) -> Result<(), Errno> { + pub fn snapshot_subvolume<P: AsRef<Path>>( + &self, + extra_flags: u32, + src: Option<P>, + dst: P, + ) -> Result<(), Errno> { let src = src.map(|src| path_to_cstr(src)); let dst = path_to_cstr(dst); - let res = self.ioctl(BcachefsIoctl::SubvolumeCreate, &BcachefsIoctlPayload::Subvolume(bch_ioctl_subvolume { - flags: BCH_SUBVOL_SNAPSHOT_CREATE | extra_flags, - dirfd: libc::AT_FDCWD as u32, - mode: 0o777, - src_ptr: src.as_ref().map_or(0, |x| x.as_ptr() as u64), - //src_ptr: if let Some(src) = src { src.as_ptr() } else { std::ptr::null() } as u64, - dst_ptr: dst.as_ptr() as u64, - ..Default::default() - })); + let res = self.ioctl( + BcachefsIoctl::SubvolumeCreate, + &BcachefsIoctlPayload::Subvolume(bch_ioctl_subvolume { + flags: BCH_SUBVOL_SNAPSHOT_CREATE | extra_flags, + dirfd: libc::AT_FDCWD as u32, + mode: 0o777, + src_ptr: src.as_ref().map_or(0, |x| x.as_ptr() as u64), + //src_ptr: if let Some(src) = src { src.as_ptr() } else { std::ptr::null() } as u64, + dst_ptr: dst.as_ptr() as u64, + ..Default::default() + }), + ); drop(src); drop(dst); |