Skip to main content

libcdio_rs/mmc/
test_unit_ready.rs

1// Copyright (C) 2026 Shiva Kiran Koninty <shiva@skran.xyz>
2//
3// This file is part of libcdio-rs.
4//
5// libcdio-rs is free software: you can redistribute it and/or
6// modify it under the terms of the GNU General Public License as
7// published by the Free Software Foundation, either version 3 of the
8// License, or (at your option) any later version.
9//
10// libcdio-rs is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13// General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with libcdio-rs. If not, see <https://www.gnu.org/licenses/>.
17
18//! Routines on MMC `TEST UNIT READY`.
19
20use displaydoc::Display;
21use thiserror::Error;
22
23use crate::{
24    Mmc,
25    mmc::{Cdb, MmcCommand, MmcError},
26};
27
28/// Routines on MMC `TEST UNIT READY`.
29impl Mmc {
30    /// Returns `Ok` if the device is ready.
31    pub fn test_unit_ready(&self) -> Result<(), MmcTestUnitReadyError> {
32        let mut cdb = Cdb::default();
33        cdb[0] = MmcCommand::TestUnitReady as u8;
34
35        self.run_command(None, &mut [], cdb)?;
36
37        Ok(())
38    }
39}
40
41/// error from an MMC `TEST UNIT READY` command.
42#[derive(Debug, Display, Error)]
43pub struct MmcTestUnitReadyError {
44    #[from]
45    pub source: MmcError,
46}
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51
52    #[test_log::test(test)]
53    #[ignore = "requires a drive with mmc"]
54    fn test_unit_ready() {
55        Mmc::new().unwrap().test_unit_ready().unwrap();
56    }
57}