Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 42 additions & 127 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion msd-tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ publish.workspace = true
anyhow = "1.0.86"
byteorder = "1.5.0"
cap-std = "4.0.0"
clap = { version = "4.5.8", features = ["derive"] }
rustix = { version = "1.1.3", features = ["fs", "net", "process", "thread"] }
tracing = "0.1.40"
tracing-subscriber = "0.3.18"
winnow-args = { version = "0.6.1", features = ["terminal-size"] }

[dependencies.sepatch]
git = "https://github.com/chenxiaolong/sepatch"
Expand Down
53 changes: 14 additions & 39 deletions msd-tool/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-FileCopyrightText: 2024 Andrew Gunnerson
// SPDX-FileCopyrightText: 2024-2026 Andrew Gunnerson
// SPDX-License-Identifier: GPL-3.0-only

use std::{fs::File, os::unix::net::UnixStream, path::PathBuf};

use anyhow::{Context, Result, bail};
use byteorder::{ReadBytesExt, WriteBytesExt};
use clap::{CommandFactory, Parser, Subcommand, ValueEnum};
use winnow_args::{Args, Subcommand, ValueEnum};

use crate::{
daemon,
Expand Down Expand Up @@ -63,35 +63,11 @@ pub fn subcommand_client(cli: &ClientCli) -> Result<()> {
}
ClientCommand::SetMassStorage(c) => {
if c.file.len() != c.type_.len() {
let (arg_id, actual_len, expected_len) = if c.file.len() < c.type_.len() {
("file", c.file.len(), c.type_.len())
} else {
("type_", c.type_.len(), c.file.len())
};

let mut command = SetMassStorageCli::command();
command.build();

let arg = command
.get_arguments()
.find(|a| a.get_id() == arg_id)
.expect("argument not found");

let mut error = clap::Error::new(clap::error::ErrorKind::WrongNumberOfValues)
.with_cmd(&command);
error.insert(
clap::error::ContextKind::InvalidArg,
clap::error::ContextValue::String(arg.to_string()),
bail!(
"Number of disk images ({}) and device types ({}) must match",
c.file.len(),
c.type_.len(),
);
error.insert(
clap::error::ContextKind::ActualNumValues,
clap::error::ContextValue::Number(actual_len as isize),
);
error.insert(
clap::error::ContextKind::ExpectedNumValues,
clap::error::ContextValue::Number(expected_len as isize),
);
error.exit();
}

let mut devices = vec![];
Expand Down Expand Up @@ -139,9 +115,8 @@ pub fn subcommand_client(cli: &ClientCli) -> Result<()> {
(false, true) => MassStorageType::DiskRo,
(false, false) => MassStorageType::DiskRw,
};
let type_value = type_.to_possible_value().unwrap();

println!("{} -> {:?}", type_value.get_name(), device.file);
println!("{} -> {:?}", type_.name(), device.file);
}
}
r => bail!("Invalid response: {r:?}"),
Expand All @@ -153,7 +128,7 @@ pub fn subcommand_client(cli: &ClientCli) -> Result<()> {
}

/// Get currently active USB controller functions.
#[derive(Debug, Parser)]
#[derive(Debug, Args)]
struct GetFunctionsCli;

#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
Expand All @@ -170,19 +145,19 @@ enum MassStorageType {
///
/// This command always replaces all mass storage devices. To remove all of
/// them, don't specify any files.
#[derive(Debug, Parser)]
#[derive(Debug, Args)]
struct SetMassStorageCli {
/// Disk image or ISO file.
#[clap(short, long, value_parser)]
#[arg(short, long)]
file: Vec<PathBuf>,

/// Mass storage device type.
#[clap(short, long)]
#[arg(short, long = "type")]
type_: Vec<MassStorageType>,
}

/// Get currently active mass storage devices.
#[derive(Debug, Parser)]
#[derive(Debug, Args)]
struct GetMassStorageCli;

#[allow(clippy::enum_variant_names)]
Expand All @@ -194,8 +169,8 @@ enum ClientCommand {
}

/// Send messages to daemon.
#[derive(Debug, Parser)]
#[derive(Debug, Args)]
pub struct ClientCli {
#[command(subcommand)]
#[arg(subcommand)]
command: ClientCommand,
}
6 changes: 3 additions & 3 deletions msd-tool/src/daemon.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2024-2025 Andrew Gunnerson
// SPDX-FileCopyrightText: 2024-2026 Andrew Gunnerson
// SPDX-License-Identifier: GPL-3.0-only

//! This module implements the daemon that runs as the system user and listens
Expand Down Expand Up @@ -33,12 +33,12 @@ use std::os::linux::net::SocketAddrExt;

use anyhow::{Context, Result, anyhow, bail};
use byteorder::{ReadBytesExt, WriteBytesExt};
use clap::Parser;
use rustix::{
fs::{FileType, Gid, Mode, Uid},
thread::{CapabilitySet, CapabilitySets},
};
use tracing::{debug, error, info, info_span, warn};
use winnow_args::Args;

use crate::{
message::{
Expand Down Expand Up @@ -461,5 +461,5 @@ pub fn subcommand_daemon(_cli: &DaemonCli) -> Result<()> {
}

/// Run daemon.
#[derive(Debug, Parser)]
#[derive(Debug, Args)]
pub struct DaemonCli;
Loading
Loading