-
Notifications
You must be signed in to change notification settings - Fork 0
Port mmc-tool
#25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
skr4n
wants to merge
6
commits into
main
Choose a base branch
from
mmc-tool
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+169
−5
Open
Port mmc-tool
#25
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5ca7565
cli: Add mmc-tool
skr4n 8b81062
cli/mmc-tool: Add eject and close tray
skr4n 2b31b07
lib/mmc: Add method to set power state
skr4n b025eb6
cli/mmc-tool: Add option to put the device into standby
skr4n f778827
cli/mmc-tool: Add options to get MCN and Hardware identifers
skr4n 55b950a
cli/mmc-tool: Add options to set drive speed
skr4n File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| // Copyright (C) 2026 Shiva Kiran Koninty <shiva@skran.xyz> | ||
| // | ||
| // This file is part of libcdio-cli. | ||
| // | ||
| // libcdio-cli is free software: you can redistribute it and/or | ||
| // modify it under the terms of the GNU General Public License as | ||
| // published by the Free Software Foundation, either version 3 of the | ||
| // License, or (at your option) any later version. | ||
| // | ||
| // libcdio-cli is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| // General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU General Public License | ||
| // along with libcdio-cli. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| use std::path::PathBuf; | ||
|
|
||
| use clap::{Args, Parser}; | ||
|
|
||
| #[derive(Debug, Parser)] | ||
| #[command(arg_required_else_help = true, long_about = libcdio_cli::HEADER, version)] | ||
| pub struct Cli { | ||
| /// Show debugging information (1 = Error, 2 = Warn, 3 = Info, 4 = Debug) | ||
| #[arg( | ||
| default_value = "2", | ||
| short, | ||
| long, | ||
| value_name = "LEVEL", | ||
| value_parser = clap::value_parser!(u8).range(1..=4), | ||
| )] | ||
| pub debug: u8, | ||
|
|
||
| /// Path to an MMC device. | ||
| pub device: Option<PathBuf>, | ||
|
|
||
| #[command(flatten)] | ||
| pub actions: MmcActions, | ||
| } | ||
|
|
||
| #[derive(Args, Debug)] | ||
| #[group(required = true, multiple = false)] | ||
| pub struct MmcActions { | ||
| /// Eject the drive | ||
| #[arg(short, long)] | ||
| pub eject: bool, | ||
|
|
||
| /// Close the tray, if present | ||
| #[arg(short, long)] | ||
| pub close_tray: bool, | ||
|
|
||
| /// Put the device into standby | ||
| #[arg(short, long)] | ||
| pub standby: bool, | ||
|
|
||
| /// Get the MCN (Media Catalog Number) of the media | ||
| #[arg(short, long)] | ||
| pub mcn: bool, | ||
|
|
||
| /// Get hardware identifiers (Product, Vendor and Revision) | ||
| #[arg(short, long)] | ||
| pub inquiry: bool, | ||
|
|
||
| /// Set the drive read and write speed in KB/s. | ||
| /// | ||
| /// Falls back to the nearest supported value if the provided value is not | ||
| /// supported. | ||
| #[arg(short = 'S', long)] | ||
| pub speed: Option<u16>, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // Copyright (C) 2026 Shiva Kiran Koninty <shiva@skran.xyz> | ||
| // | ||
| // This file is part of libcdio-cli. | ||
| // | ||
| // libcdio-cli is free software: you can redistribute it and/or | ||
| // modify it under the terms of the GNU General Public License as | ||
| // published by the Free Software Foundation, either version 3 of the | ||
| // License, or (at your option) any later version. | ||
| // | ||
| // libcdio-cli is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| // General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU General Public License | ||
| // along with libcdio-cli. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| use anyhow::{Context, Result}; | ||
| use clap::Parser; | ||
| use libcdio_rs::{ | ||
| Mmc, | ||
| mmc::{PowerCondition, RotationMode}, | ||
| }; | ||
|
|
||
| use crate::cli::Cli; | ||
|
|
||
| mod cli; | ||
|
|
||
| fn main() -> Result<()> { | ||
| let cli = Cli::parse(); | ||
| libcdio_cli::setup_logs(cli.debug); | ||
| let mmc = if let Some(device) = cli.device { | ||
| Mmc::with_device(device)? | ||
| } else { | ||
| Mmc::new()? | ||
| }; | ||
|
|
||
| if cli.actions.eject { | ||
| mmc.allow_media_removal()?; | ||
| mmc.eject()?; | ||
| } else if cli.actions.close_tray { | ||
| mmc.close_tray()?; | ||
|
skr4n marked this conversation as resolved.
|
||
| } else if cli.actions.standby { | ||
| mmc.set_power_state(PowerCondition::Standby)?; | ||
| } else if cli.actions.mcn { | ||
| let mcn = mmc | ||
| .media_catalog_number() | ||
| .context("could not get MCN")? | ||
| .context("current media does not have a Media Catalog Number")?; | ||
| println!("{}", mcn); | ||
| } else if cli.actions.inquiry { | ||
| let ident = mmc.hardware_identifiers()?; | ||
| println!("Product: {}", ident.product); | ||
| println!("Vendor: {}", ident.vendor); | ||
| println!("Revision: {}", ident.revision); | ||
| } else if let Some(speed) = cli.actions.speed { | ||
| // some drives may not support CLV (Constant Linear Velocity) | ||
| if mmc.set_cd_speed(RotationMode::Clv, speed, speed).is_err() { | ||
| mmc.set_cd_speed(RotationMode::Cav, speed, speed)?; | ||
| } | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default_value = "2" doesn't seem to be working:
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value is used when the option is not provided.
On a side note for later, I think using an env variable is more appropriate to accept log levels, rather than a dedicated user-facing option.
Example:
LOG_LEVEL=debug mmc-tool --close-trayinstead of
mmc-tool -d4 --close-tray