btrfs_cli/quota/
enable.rs1use crate::{Format, Runnable};
2use anyhow::{Context, Result};
3use clap::Parser;
4use std::{fs::File, os::unix::io::AsFd, path::PathBuf};
5
6#[derive(Parser, Debug)]
8pub struct QuotaEnableCommand {
9 pub path: PathBuf,
11
12 #[clap(short = 's', long)]
14 pub simple: bool,
15}
16
17impl Runnable for QuotaEnableCommand {
18 fn run(&self, _format: Format, _dry_run: bool) -> Result<()> {
19 let file = File::open(&self.path).with_context(|| {
20 format!("failed to open '{}'", self.path.display())
21 })?;
22
23 btrfs_uapi::quota::quota_enable(file.as_fd(), self.simple)
24 .with_context(|| {
25 format!("failed to enable quota on '{}'", self.path.display())
26 })?;
27
28 if self.simple {
29 println!(
30 "quota enabled (simple mode) on '{}'",
31 self.path.display()
32 );
33 } else {
34 println!("quota enabled on '{}'", self.path.display());
35 }
36
37 Ok(())
38 }
39}