Skip to content

Port mmc-tool - #25

Open
skr4n wants to merge 6 commits into
mainfrom
mmc-tool
Open

Port mmc-tool#25
skr4n wants to merge 6 commits into
mainfrom
mmc-tool

Conversation

@skr4n

@skr4n skr4n commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

This PR adds the mmc-tool CLI utility in libcdio-cli.

The following options have been omitted in the port:
-b, --blocksize: The implementation was found to be incorrect.
-C, --drive-cap: Used a mode page that has been deprecated since MMC-4.
-S, --speed-X: Removed in favor of -S, --speed (without the 'X', in KB/s).

This option has been modified and fixed:
-i, --idle: The implementation was found to be incorrect. It has been replaced with -s, --standby.

Also, adds a new method in libcdio-rs:

  • set_power_state(): Puts the drive into the given power state (such as idle, standby, etc).

pub struct Cli {
/// Show debugging information (1 = Error, 2 = Warn, 3 = Info, 4 = Debug)
#[arg(
default_value = "2",

Copy link
Copy Markdown
Contributor

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:

$ ./mmc-tool-rs -d -c
error: a value is required for '--debug <LEVEL>' but none was supplied

For more information, try '--help'.

$ ./mmc-tool-rs --help
libcdio-cli version 0.1.0

..

Options:
  -d, --debug <LEVEL>
          Show debugging information (1 = Error, 2 = Warn, 3 = Info, 4 = Debug)

          [default: 2]

@skr4n skr4n Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author

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-tray
instead of
mmc-tool -d4 --close-tray

@rocky

rocky commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Overall, I like. Much needed!

@rocky

rocky commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

When I run the --speed option, I am seeing nothing.

Here is a log:

$ target/debug/mmc-tool-rs -S 65535
# No output
$ target/debug/mmc-tool-rs -d 4 -S 65535
2026-08-03T13:59:10.154687Z DEBUG libcdio_rs::logging: Trying driver AIX
2026-08-03T13:59:10.154719Z DEBUG libcdio_rs::logging: Trying driver FreeBSD
2026-08-03T13:59:10.154727Z DEBUG libcdio_rs::logging: Trying driver NetBSD
2026-08-03T13:59:10.154735Z DEBUG libcdio_rs::logging: Trying driver GNU/Linux
2026-08-03T13:59:10.174783Z  INFO libcdio_rs::logging: found driver GNU/Linux
2026-08-03T13:59:10.185566Z  INFO libcdio_rs::logging: ioctl CDROM_SEND_PACKET for command MODE SENSE (6) (0x1a) failed:
	Input/output error
$

Is this expected?

I should have mentioned before, but in the tests I am consistently seeing MODE_SENSE(6) and READ_TOC when running tests:

---- mmc::get_config::tests::features stdout ----
2026-08-03T13:16:19.927909Z  INFO libcdio_rs::logging: found driver GNU/Linux
2026-08-03T13:16:19.938583Z  INFO libcdio_rs::logging: ioctl CDROM_SEND_PACKET for command MODE SENSE (6) (0x1a) failed:
	Input/output error

---- mmc::get_event_status::tests::busy_status stdout ----
2026-08-03T13:16:19.985306Z  INFO libcdio_rs::logging: found driver GNU/Linux
2026-08-03T13:16:19.995942Z  INFO libcdio_rs::logging: ioctl CDROM_SEND_PACKET for command MODE SENSE (6) (0x1a) failed:
	Input/output error
2026-08-03T13:16:20.533577Z  INFO libcdio_rs::mmc::get_event_status::tests: status=Ok(BusyStatus { event: None, state: NotBusy, busy_time: None })

---- mmc::get_event_status::tests::external_status stdout ----
2026-08-03T13:16:20.028268Z  INFO libcdio_rs::logging: found driver GNU/Linux
2026-08-03T13:16:20.038835Z  INFO libcdio_rs::logging: ioctl CDROM_SEND_PACKET for command MODE SENSE (6) (0x1a) failed:
	Input/output error
2026-08-03T13:16:20.533604Z  INFO libcdio_rs::mmc::get_event_status::tests: status=Ok(ExternalRequestStatus { event: None, state: Ready, request: None })

---- mmc::get_event_status::tests::media_status stdout ----
2026-08-03T13:16:20.081197Z  INFO libcdio_rs::logging: found driver GNU/Linux
2026-08-03T13:16:20.092011Z  INFO libcdio_rs::logging: ioctl CDROM_SEND_PACKET for command MODE SENSE (6) (0x1a) failed:
	Input/output error
2026-08-03T13:16:20.533680Z  INFO libcdio_rs::mmc::get_event_status::tests: status=Ok(MediaStatus { event: None, state: MediaState(MediaPresent), start_slot: 0, end_slot: 0 })

---- mmc::get_event_status::tests::is_tray_open stdout ----
2026-08-03T13:16:20.134301Z  INFO libcdio_rs::logging: found driver GNU/Linux
2026-08-03T13:16:20.144740Z  INFO libcdio_rs::logging: ioctl CDROM_SEND_PACKET for command MODE SENSE (6) (0x1a) failed:
	Input/output error
2026-08-03T13:16:20.533710Z  INFO libcdio_rs::mmc::get_event_status::tests: is_tray_open=Ok(false)

---- mmc::get_event_status::tests::operational_status stdout ----
2026-08-03T13:16:20.187115Z  INFO libcdio_rs::logging: found driver GNU/Linux
2026-08-03T13:16:20.197761Z  INFO libcdio_rs::logging: ioctl CDROM_SEND_PACKET for command MODE SENSE (6) (0x1a) failed:
	Input/output error
2026-08-03T13:16:20.533739Z  INFO libcdio_rs::mmc::get_event_status::tests: status=Ok(OperationalStatus { event: None, persistent_prevent: false })

---- mmc::get_event_status::tests::multihost_status stdout ----
2026-08-03T13:16:20.240200Z  INFO libcdio_rs::logging: found driver GNU/Linux
2026-08-03T13:16:20.251011Z  INFO libcdio_rs::logging: ioctl CDROM_SEND_PACKET for command MODE SENSE (6) (0x1a) failed:
	Input/output error
2026-08-03T13:16:20.533775Z  INFO libcdio_rs::mmc::get_event_status::tests: status=Err(EventNotSupported(EventClass(MultiHost)))

---- mmc::get_event_status::tests::supported_events stdout ----
2026-08-03T13:16:20.346364Z  INFO libcdio_rs::logging: found driver GNU/Linux
2026-08-03T13:16:20.356690Z  INFO libcdio_rs::logging: ioctl CDROM_SEND_PACKET for command MODE SENSE (6) (0x1a) failed:
	Input/output error

---- mmc::get_event_status::tests::power_status stdout ----
2026-08-03T13:16:20.293108Z  INFO libcdio_rs::logging: found driver GNU/Linux
2026-08-03T13:16:20.303701Z  INFO libcdio_rs::logging: ioctl CDROM_SEND_PACKET for command MODE SENSE (6) (0x1a) failed:
	Input/output error
2026-08-03T13:16:20.533819Z  INFO libcdio_rs::mmc::get_event_status::tests: status=Ok(PowerStatus { event: None, state: Standby })

---- mmc::read_disc_info::tests::is_disc_erasable stdout ----
2026-08-03T13:16:20.399266Z  INFO libcdio_rs::logging: found driver GNU/Linux
2026-08-03T13:16:20.409764Z  INFO libcdio_rs::logging: ioctl CDROM_SEND_PACKET for command MODE SENSE (6) (0x1a) failed:
	Input/output error
2026-08-03T13:16:20.533888Z  INFO libcdio_rs::mmc::read_disc_info::tests: is_disc_erasable=false

---- mmc::inquiry::tests::hardware_identifiers stdout ----
2026-08-03T13:16:20.452314Z  INFO libcdio_rs::logging: found driver GNU/Linux
2026-08-03T13:16:20.462996Z  INFO libcdio_rs::logging: ioctl CDROM_SEND_PACKET for command MODE SENSE (6) (0x1a) failed:
	Input/output error
2026-08-03T13:16:20.533917Z  INFO libcdio_rs::mmc::inquiry::tests: hardware_identifiers=HardwareIdentifiers { product: "BD-RW   BDR-UD02", vendor: "PIONEER", revision: "1.00" }

---- mmc::read_subchannel::tests::audio_status stdout ----
2026-08-03T13:16:20.496359Z  INFO libcdio_rs::logging: found driver GNU/Linux
2026-08-03T13:16:20.505969Z  INFO libcdio_rs::logging: ioctl CDROM_SEND_PACKET for command MODE SENSE (6) (0x1a) failed:
	Input/output error
2026-08-03T13:16:20.584017Z  INFO libcdio_rs::mmc::read_subchannel::tests: audio_status=Ok(NoStatus)

---- mmc::read_subchannel::tests::cd_current_position stdout ----
2026-08-03T13:16:20.573115Z  INFO libcdio_rs::logging: found driver GNU/Linux
2026-08-03T13:16:20.583934Z  INFO libcdio_rs::logging: ioctl CDROM_SEND_PACKET for command MODE SENSE (6) (0x1a) failed:
	Input/output error
2026-08-03T13:16:21.117044Z  INFO libcdio_rs::mmc::read_subchannel::tests: cd_current_position=CdCurrentPosition { track: 1, index: 1, absolute_position: TimePosition { hour: 0, minute: 0, second: 3, frame: 66 }, relative_position: TimePosition { hour: 0, minute: 0, second: 1, frame: 66 } }

---- mmc::read_subchannel::tests::isrc stdout ----
2026-08-03T13:16:20.636297Z  INFO libcdio_rs::logging: found driver GNU/Linux
2026-08-03T13:16:20.646970Z  INFO libcdio_rs::logging: ioctl CDROM_SEND_PACKET for command MODE SENSE (6) (0x1a) failed:
	Input/output error
2026-08-03T13:16:21.149863Z  INFO libcdio_rs::mmc::read_subchannel::tests: isrc=Some("000000000000")

---- mmc::tests::level stdout ----
2026-08-03T13:16:20.689398Z  INFO libcdio_rs::logging: found driver GNU/Linux
2026-08-03T13:16:20.699651Z  INFO libcdio_rs::logging: ioctl CDROM_SEND_PACKET for command MODE SENSE (6) (0x1a) failed:
	Input/output error
2026-08-03T13:16:20.727644Z  INFO libcdio_rs::logging: ioctl CDROM_SEND_PACKET for command MODE SENSE (6) (0x1a) failed:
	Input/output error

---- mmc::tests::sense_data stdout ----
2026-08-03T13:16:21.106660Z  INFO libcdio_rs::logging: found driver GNU/Linux
2026-08-03T13:16:21.116953Z  INFO libcdio_rs::logging: ioctl CDROM_SEND_PACKET for command MODE SENSE (6) (0x1a) failed:
	Input/output error
2026-08-03T13:16:21.149782Z  INFO libcdio_rs::logging: ioctl CDROM_SEND_PACKET for command READ TOC (0x43) failed:
	Input/output error
2026-08-03T13:16:21.149878Z  INFO libcdio_rs::mmc::tests: sense_data=MmcSenseData { sense_key: IllegalRequest, asc: 36, ascq: 0, ili: false, csi: [0, 0, 0, 0], fruc: 0, sks: [204, 0, 1], asb: [0, 0, 0, 0, 0, 0, 81, 0, 0, 0, 0, 0, 0, 0, 170, 138, 28, 251, 5, 0, 0, 0, 47, 4, 113, 192, 237, 162, 242, 189, 38, 0, 0, 0, 0, 0, 0, 0, 115, 119, 172, 192, 177, 95, 0, 0] }

---- mmc::read_toc::tests::cd_text stdout ----
2026-08-03T13:16:20.755237Z  INFO libcdio_rs::logging: found driver GNU/Linux
2026-08-03T13:16:20.765868Z  INFO libcdio_rs::logging: ioctl CDROM_SEND_PACKET for command MODE SENSE (6) (0x1a) failed:
	Input/output error
2026-08-03T13:16:21.150072Z  INFO libcdio_rs::mmc::read_toc::tests: cd_text=[128, 0, 0, 0, 74, 111, 105, 110, 32, 117, 115, 32, 110, 111, 119, 32, 75, 67, 128, 0, 1, 12, 119, 101, 32, 104, 97, 118, 101, 32, 116, 104, 101, 32, 16, 228, 128, 0, 2, 15, 115, 111, 102, 116, 119, 97, 114, 101, 0, 83, 111, 102, 179, 227, 128, 1, 3, 3, 116, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 146, 16, 129, 0, 4, 0, 82, 105, 99, 104, 97, 114, 100, 32, 83, 116, 97, 108, 241, 101, 129, 0, 5, 12, 108, 109, 97, 110, 0, 82, 105, 99, 104, 97, 114, 100, 64, 249, 129, 1, 6, 7, 32, 83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 139, 143, 0, 7, 0, 0, 1, 1, 0, 4, 3, 0, 0, 0, 0, 0, 0, 158, 113, 143, 1, 8, 0, 0, 0, 0, 0, 0, 0, 0, 3, 9, 0, 0, 0, 214, 166, 143, 2, 9, 0, 0, 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 10, 78, 0, 0] len=182

---- mmc::read_subchannel::tests::media_catalog_number stdout ----
2026-08-03T13:16:20.813415Z  INFO libcdio_rs::logging: found driver GNU/Linux
2026-08-03T13:16:20.824048Z  INFO libcdio_rs::logging: ioctl CDROM_SEND_PACKET for command MODE SENSE (6) (0x1a) failed:
	Input/output error
2026-08-03T13:16:21.150258Z  INFO libcdio_rs::mmc::read_subchannel::tests: mcn=Some("0000010271955")

---- mmc::tests::with_device stdout ----
2026-08-03T13:16:20.902200Z  INFO libcdio_rs::logging: found driver GNU/Linux
2026-08-03T13:16:20.909966Z  INFO libcdio_rs::logging: ioctl CDROM_SEND_PACKET for command MODE SENSE (6) (0x1a) failed:
	Input/output error

---- mmc::read_toc::tests::cd_type stdout ----
2026-08-03T13:16:20.866440Z  INFO libcdio_rs::logging: found driver GNU/Linux
2026-08-03T13:16:20.876982Z  INFO libcdio_rs::logging: ioctl CDROM_SEND_PACKET for command MODE SENSE (6) (0x1a) failed:
	Input/output error
2026-08-03T13:16:21.150357Z  INFO libcdio_rs::mmc::read_toc::tests: cd_type=CddaOrCdData

---- mmc::read_toc::tests::last_sector stdout ----
2026-08-03T13:16:20.947030Z  INFO libcdio_rs::logging: found driver GNU/Linux
2026-08-03T13:16:20.957809Z  INFO libcdio_rs::logging: ioctl CDROM_SEND_PACKET for command MODE SENSE (6) (0x1a) failed:
	Input/output error
2026-08-03T13:16:21.150495Z  INFO libcdio_rs::mmc::read_toc::tests: last_sector=301

---- mmc::test_unit_ready::tests::test_unit_ready stdout ----
2026-08-03T13:16:21.000190Z  INFO libcdio_rs::logging: found driver GNU/Linux
2026-08-03T13:16:21.010952Z  INFO libcdio_rs::logging: ioctl CDROM_SEND_PACKET for command MODE SENSE (6) (0x1a) failed:
	Input/output error

---- mmc::set_cd_speed::tests::set_cd_speed stdout ----
2026-08-03T13:16:21.054390Z  INFO libcdio_rs::logging: found driver GNU/Linux
2026-08-03T13:16:21.063881Z  INFO libcdio_rs::logging: ioctl CDROM_SEND_PACKET for command MODE SENSE (6) (0x1a) failed:
	Input/output error

Comment thread libcdio-cli/src/mmc-tool/main.rs
@skr4n

skr4n commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author

When I run the --speed option, I am seeing nothing.

If the command has succeeded, it returns nothing, keeping things POSIX-like.
To verify the speed change, for now, you may use the wodim tool.
sudo wodim dev=/dev/cdrom -prcap

I do a plan to add an option to display the current speeds.
However, that requires implementing a new MMC command (not present in libcdio C), thus out of scope for the current project.
I shall be adding it once we're done with everything in the project scope (CI, static linking).

@rocky

rocky commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

When I run the --speed option, I am seeing nothing.

If the command has succeeded, it returns nothing, keeping things POSIX-like. To verify the speed change, for now, you may use the wodim tool. sudo wodim dev=/dev/cdrom -prcap

I don't see where I see what the current speed is set to. Where is it in the output below?

Device type    : Removable CD-ROM
Version        : 0
Response Format: 2
Capabilities   : 
Vendor_info    : 'PIONEER '
Identification : 'BD-RW   BDR-UD02'
Revision       : '1.00'
Device seems to be: Generic mmc2 DVD-R/DVD-RW.

Drive capabilities, per MMC-3 page 2A:

  Does read CD-R media
  Does write CD-R media
  Does read CD-RW media
  Does write CD-RW media
  Does read DVD-ROM media
  Does read DVD-R media
  Does write DVD-R media
  Does read DVD-RAM media
  Does write DVD-RAM media
  Does support test writing

  Does read Mode 2 Form 1 blocks
  Does read Mode 2 Form 2 blocks
  Does read digital audio blocks
  Does restart non-streamed digital audio reads accurately
  Does support Buffer-Underrun-Free recording
  Does read multi-session CDs
  Does read fixed-packet CD media using Method 2
  Does not read CD bar code
  Does not read R-W subcode information
  Does read raw P-W subcode data from lead in
  Does return CD media catalog number
  Does return CD ISRC information
  Does not support C2 error pointers
  Does not deliver composite A/V data

  Does play audio CDs
  Number of volume control levels: 256
  Does support individual volume control setting for each channel
  Does support independent mute setting for each channel
  Does not support digital output on port 1
  Does not support digital output on port 2

  Loading mechanism type: tray
  Does support ejection of CD via START/STOP command
  Does not lock media on power up via prevent jumper
  Does allow media to be locked in the drive via PREVENT/ALLOW command
  Is currently in a media-locked state
  Does not support changing side of disk
  Does not have load-empty-slot-in-changer feature
  Does not support Individual Disk Present feature

  Maximum read  speed:  4233 kB/s (CD  24x, DVD  3x)
  Current read  speed:  4233 kB/s (CD  24x, DVD  3x)
  Maximum write speed:  4234 kB/s (CD  24x, DVD  3x)
  Current write speed:  4234 kB/s (CD  24x, DVD  3x)
  Rotational control selected: CLV/PCAV
  Buffer size in KB: 4000
  Copy management revision supported: 1
  Number of supported write speeds: 5
  Write speed # 0:  4234 kB/s CLV/PCAV (CD  24x, DVD  3x)
  Write speed # 1:  3528 kB/s CLV/PCAV (CD  20x, DVD  2x)
  Write speed # 2:  2823 kB/s CLV/PCAV (CD  16x, DVD  2x)
  Write speed # 3:  1764 kB/s CLV/PCAV (CD  10x, DVD  1x)
  Write speed # 4:   706 kB/s CLV/PCAV (CD   4x, DVD  0x)

Supported CD-RW media types according to MMC-4 feature 0x37:
  Does write multi speed       CD-RW media
  Does write high  speed       CD-RW media
  Does write ultra high speed  CD-RW media
  Does not write ultra high speed+ CD-RW media

@skr4n

skr4n commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author
  Maximum read  speed:  4233 kB/s (CD  24x, DVD  3x)
  Current read  speed:  4233 kB/s (CD  24x, DVD  3x)
  Maximum write speed:  4234 kB/s (CD  24x, DVD  3x)
  Current write speed:  4234 kB/s (CD  24x, DVD  3x)

See the 16th line from the last.

@skr4n

skr4n commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author

I should have mentioned before, but in the tests I am consistently seeing MODE_SENSE(6) and READ_TOC when running tests:

Check if you're using a clean build of libcdio C, from master.

@rocky

rocky commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

When I run the --speed option, I am seeing nothing.

If the command has succeeded, it returns nothing, keeping things POSIX-like. To verify the speed change, for now, you may use the wodim tool. sudo wodim dev=/dev/cdrom -prcap

This is useful information. We need to add it somewhere to the documentation for others.

I do a plan to add an option to display the current speeds. However, that requires implementing a new MMC command (not present in libcdio C), thus out of scope for the current project.

Noted.

I shall be adding it once we're done with everything in the project scope (CI, static linking).

Much appreciated!

@rocky

rocky commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

I should have mentioned before, but in the tests I am consistently seeing MODE_SENSE(6) and READ_TOC when running tests:

Check if you're using a clean build of libcdio C, from master.

I am now certain I'm using the current master libcdio C branch. (I updated the version number in libcdio C in here and installed that and set SYSTEM_DEPS_* environment variables. I then did a cargo clean && cargo build.

I am still seeing MODE SENSE 6 failures and that READ_TOC failure. Using wodim, I am not seeing those failures.

I will check on another system with another CD drive.

@rocky

rocky commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

I should have mentioned before, but in the tests I am consistently seeing MODE_SENSE(6) and READ_TOC when running tests:

Check if you're using a clean build of libcdio C, from master.

I am now certain I'm using the current master libcdio C branch. (I updated the version number in libcdio C in here and installed that and set SYSTEM_DEPS_* environment variables. I then did a cargo clean && cargo build.

I am still seeing MODE SENSE 6 failures and that READ_TOC failure. Using wodim, I am not seeing those failures.

I will check on another system with another CD drive.

For what it's worth, in libcdio C, running cd-drive -d4, I get a MODE SENSE failure as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants