Add command enum
This commit is contained in:
parent
fcd3f18919
commit
a8e72dbfb3
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "scsi-ng"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
# enum-map = { version = "2.6.1", features = ["no_std"] }
|
|
@ -0,0 +1,418 @@
|
|||
|
||||
// https://www.t10.org/lists/2op.htm
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum Command {
|
||||
Unrecognized,
|
||||
TestUnitReady,
|
||||
Rewind,
|
||||
RequestSense,
|
||||
Format,
|
||||
ReadBlockLimits,
|
||||
ReassignBlocks,
|
||||
InitializeElementStatus,
|
||||
Read6,
|
||||
Write6,
|
||||
Seek6,
|
||||
ReadReverse6,
|
||||
WriteFilemarks6,
|
||||
Space6,
|
||||
Inquiry,
|
||||
Verify6,
|
||||
RecoverBufferedData,
|
||||
ModeSelect6,
|
||||
Reserve6,
|
||||
Release6,
|
||||
Copy,
|
||||
Erase6,
|
||||
ModeSense6,
|
||||
StartStopUnit,
|
||||
LoadUnload,
|
||||
ReceiveDiagnosticResults,
|
||||
SendDiagnostic,
|
||||
PreventAllowMediumRemoval,
|
||||
ReadFormatCapacities,
|
||||
ReadCapacity10,
|
||||
Read10,
|
||||
ReadGeneration,
|
||||
Write10,
|
||||
Seek10,
|
||||
Locate10,
|
||||
Erase10,
|
||||
ReadUpdatedBlock,
|
||||
WriteAndVerify10,
|
||||
Verify10,
|
||||
SetLimits10,
|
||||
PreFetch10,
|
||||
ReadPosition,
|
||||
SynchronizeCache10,
|
||||
LockUnlockCache10,
|
||||
ReadDefectData10,
|
||||
InitializeElementStatusWithRange,
|
||||
MediumScan,
|
||||
Compare,
|
||||
CopyAndVerify,
|
||||
WriteBuffer,
|
||||
ReadBuffer,
|
||||
UpdateBlock,
|
||||
ReadLong10,
|
||||
WriteLong10,
|
||||
ChangeDefinition,
|
||||
WriteSame10,
|
||||
Unmap,
|
||||
ReadTocPmaAtip,
|
||||
ReportDensitySupport,
|
||||
PlayAudio10,
|
||||
GetConfiguration,
|
||||
PlayAudioMsf,
|
||||
Sanitize,
|
||||
GetEventStatusNotification,
|
||||
PauseResume,
|
||||
LogSelect,
|
||||
LogSense,
|
||||
XdWrite10,
|
||||
XpWrite10,
|
||||
ReadDiscInformation,
|
||||
XdRead10,
|
||||
XdWriteRead10,
|
||||
SendOpcInformation,
|
||||
ModeSelect10,
|
||||
Reserve10,
|
||||
Release10,
|
||||
RepairTrack,
|
||||
ModeSense10,
|
||||
CloseTrackSession,
|
||||
ReadBufferCapacity,
|
||||
SendCueSheet,
|
||||
PersistentReserveIn,
|
||||
PersistentReserveOut,
|
||||
ExtendedCdb,
|
||||
VariableLengthCdb,
|
||||
XdWriteExtended16,
|
||||
WriteFilemarks16,
|
||||
ReadReverse16,
|
||||
ThirdPartyCopyOut,
|
||||
ThirdPartyCopyIn,
|
||||
AtaPassThrough16,
|
||||
AccessControlIn,
|
||||
AccessControlOut,
|
||||
Read16,
|
||||
CompareAndWrite,
|
||||
Write16,
|
||||
OrWrite,
|
||||
ReadAttribute,
|
||||
WriteAttribute,
|
||||
WriteAndVerify16,
|
||||
Verify16,
|
||||
PreFetch16,
|
||||
SynchronizeCache16,
|
||||
Space16,
|
||||
LockUnlockCache16,
|
||||
Locate16,
|
||||
WriteSame16,
|
||||
Erase16,
|
||||
ServiceActionBidirectional,
|
||||
ServiceActionIn16,
|
||||
ServiceActionOut16,
|
||||
ReportLuns,
|
||||
AtaPassThrough12,
|
||||
SecurityProtocolIn,
|
||||
MaintenanceIn,
|
||||
MaintenanceOut,
|
||||
ReportKey,
|
||||
MoveMedium,
|
||||
PlayAudio12,
|
||||
ExchangeMedium,
|
||||
MoveMediumAttached,
|
||||
Read12,
|
||||
ServiceActionOut12,
|
||||
Write12,
|
||||
ServiceActionIn12,
|
||||
Erase12,
|
||||
ReadDvdStructure,
|
||||
WriteAndVerify12,
|
||||
Verify12,
|
||||
SearchDataHigh12,
|
||||
SearchDataEqual12,
|
||||
SearchDataLow12,
|
||||
SetLimits12,
|
||||
ReadElementStatusAttached,
|
||||
SecurityProtocolOut,
|
||||
SendVolumeTag,
|
||||
ReadDefectData12,
|
||||
ReadElementStatus,
|
||||
ReadCdMsf,
|
||||
RedundancyGroupIn,
|
||||
RedundancyGroupOut,
|
||||
SpareIn,
|
||||
SpareOut,
|
||||
VolumeSetIn,
|
||||
VolumeSetOut,
|
||||
}
|
||||
|
||||
impl Command {
|
||||
pub fn code(&self) -> u8 {
|
||||
match self {
|
||||
Command::Unrecognized => panic!("Unrecognized command"),
|
||||
Command::TestUnitReady => 0x00,
|
||||
Command::Rewind => 0x01,
|
||||
Command::RequestSense => 0x03,
|
||||
Command::Format => 0x04,
|
||||
Command::ReadBlockLimits => 0x05,
|
||||
Command::ReassignBlocks | Command::InitializeElementStatus => 0x07,
|
||||
Command::Read6 => 0x08,
|
||||
Command::Write6 => 0x0a,
|
||||
Command::Seek6 => 0x0b,
|
||||
Command::ReadReverse6 => 0x0f,
|
||||
Command::WriteFilemarks6 => 0x10,
|
||||
Command::Space6 => 0x11,
|
||||
Command::Inquiry => 0x12,
|
||||
Command::Verify6 => 0x13,
|
||||
Command::RecoverBufferedData => 0x14,
|
||||
Command::ModeSelect6 => 0x15,
|
||||
Command::Reserve6 => 0x16,
|
||||
Command::Release6 => 0x17,
|
||||
Command::Copy => 0x18,
|
||||
Command::Erase6 => 0x19,
|
||||
Command::ModeSense6 => 0x1a,
|
||||
Command::StartStopUnit | Command::LoadUnload => 0x1b,
|
||||
Command::ReceiveDiagnosticResults => 0x1c,
|
||||
Command::SendDiagnostic => 0x1d,
|
||||
Command::PreventAllowMediumRemoval => 0x1e,
|
||||
Command::ReadFormatCapacities => 0x23,
|
||||
Command::ReadCapacity10 => 0x25,
|
||||
Command::Read10 => 0x28,
|
||||
Command::ReadGeneration => 0x29,
|
||||
Command::Write10 => 0x2a,
|
||||
Command::Seek10 | Command::Locate10 => 0x2b,
|
||||
Command::Erase10 => 0x2c,
|
||||
Command::ReadUpdatedBlock => 0x2d,
|
||||
Command::WriteAndVerify10 => 0x2e,
|
||||
Command::Verify10 => 0x2f,
|
||||
Command::SetLimits10 => 0x33,
|
||||
Command::PreFetch10 | Command::ReadPosition => 0x34,
|
||||
Command::SynchronizeCache10 => 0x35,
|
||||
Command::LockUnlockCache10 => 0x36,
|
||||
Command::ReadDefectData10 | Command::InitializeElementStatusWithRange => 0x37,
|
||||
Command::MediumScan => 0x38,
|
||||
Command::Compare => 0x39,
|
||||
Command::CopyAndVerify => 0x3a,
|
||||
Command::WriteBuffer => 0x3b,
|
||||
Command::ReadBuffer => 0x3c,
|
||||
Command::UpdateBlock => 0x3d,
|
||||
Command::ReadLong10 => 0x3e,
|
||||
Command::WriteLong10 => 0x3f,
|
||||
Command::ChangeDefinition => 0x40,
|
||||
Command::WriteSame10 => 0x41,
|
||||
Command::Unmap => 0x42,
|
||||
Command::ReadTocPmaAtip => 0x43,
|
||||
Command::ReportDensitySupport => 0x44,
|
||||
Command::PlayAudio10 => 0x45,
|
||||
Command::GetConfiguration => 0x46,
|
||||
Command::PlayAudioMsf => 0x47,
|
||||
Command::Sanitize => 0x48,
|
||||
Command::GetEventStatusNotification => 0x4a,
|
||||
Command::PauseResume => 0x4b,
|
||||
Command::LogSelect => 0x4c,
|
||||
Command::LogSense => 0x4d,
|
||||
Command::XdWrite10 => 0x50,
|
||||
Command::XpWrite10 | Command::ReadDiscInformation => 0x51,
|
||||
Command::XdRead10 => 0x52,
|
||||
Command::XdWriteRead10 => 0x53,
|
||||
Command::SendOpcInformation => 0x54,
|
||||
Command::ModeSelect10 => 0x55,
|
||||
Command::Reserve10 => 0x56,
|
||||
Command::Release10 => 0x57,
|
||||
Command::RepairTrack => 0x58,
|
||||
Command::ModeSense10 => 0x5a,
|
||||
Command::CloseTrackSession => 0x5b,
|
||||
Command::ReadBufferCapacity => 0x5c,
|
||||
Command::SendCueSheet => 0x5d,
|
||||
Command::PersistentReserveIn => 0x5e,
|
||||
Command::PersistentReserveOut => 0x5f,
|
||||
Command::ExtendedCdb => 0x7e,
|
||||
Command::VariableLengthCdb => 0x7f,
|
||||
Command::XdWriteExtended16 | Command::WriteFilemarks16 => 0x80,
|
||||
Command::ReadReverse16 => 0x81,
|
||||
Command::ThirdPartyCopyOut => 0x83,
|
||||
Command::ThirdPartyCopyIn => 0x84,
|
||||
Command::AtaPassThrough16 => 0x85,
|
||||
Command::AccessControlIn => 0x86,
|
||||
Command::AccessControlOut => 0x87,
|
||||
Command::Read16 => 0x88,
|
||||
Command::CompareAndWrite => 0x89,
|
||||
Command::Write16 => 0x8a,
|
||||
Command::OrWrite => 0x8b,
|
||||
Command::ReadAttribute => 0x8c,
|
||||
Command::WriteAttribute => 0x8d,
|
||||
Command::WriteAndVerify16 => 0x8e,
|
||||
Command::Verify16 => 0x8f,
|
||||
Command::PreFetch16 => 0x90,
|
||||
Command::SynchronizeCache16 | Command::Space16 => 0x91,
|
||||
Command::LockUnlockCache16 | Command::Locate16 => 0x92,
|
||||
Command::WriteSame16 | Command::Erase16 => 0x93,
|
||||
Command::ServiceActionBidirectional | Command::ServiceActionIn16 => 0x9e,
|
||||
Command::ServiceActionOut16 => 0x9f,
|
||||
Command::ReportLuns => 0xa0,
|
||||
Command::AtaPassThrough12 => 0xa1,
|
||||
Command::SecurityProtocolIn => 0xa2,
|
||||
Command::MaintenanceIn => 0xa3,
|
||||
Command::MaintenanceOut | Command::ReportKey => 0xa4,
|
||||
Command::MoveMedium | Command::PlayAudio12 => 0xa5,
|
||||
Command::ExchangeMedium => 0xa6,
|
||||
Command::MoveMediumAttached => 0xa7,
|
||||
Command::Read12 => 0xa8,
|
||||
Command::ServiceActionOut12 => 0xa9,
|
||||
Command::Write12 => 0xaa,
|
||||
Command::ServiceActionIn12 => 0xab,
|
||||
Command::Erase12 => 0xac,
|
||||
Command::ReadDvdStructure => 0xad,
|
||||
Command::WriteAndVerify12 => 0xae,
|
||||
Command::Verify12 => 0xaf,
|
||||
Command::SearchDataHigh12 => 0xb0,
|
||||
Command::SearchDataEqual12 => 0xb1,
|
||||
Command::SearchDataLow12 => 0xb2,
|
||||
Command::SetLimits12 => 0xb3,
|
||||
Command::ReadElementStatusAttached => 0xb4,
|
||||
Command::SecurityProtocolOut => 0xb5,
|
||||
Command::SendVolumeTag => 0xb6,
|
||||
Command::ReadDefectData12 => 0xb7,
|
||||
Command::ReadElementStatus => 0xb8,
|
||||
Command::ReadCdMsf => 0xb9,
|
||||
Command::RedundancyGroupIn => 0xba,
|
||||
Command::RedundancyGroupOut => 0xbb,
|
||||
Command::SpareIn => 0xbc,
|
||||
Command::SpareOut => 0xbd,
|
||||
Command::VolumeSetIn => 0xbe,
|
||||
Command::VolumeSetOut => 0xbf,
|
||||
}
|
||||
}
|
||||
|
||||
fn from_code_trivial(code: u8) -> Option<Command> {
|
||||
match code {
|
||||
0x00 => Some(Command::TestUnitReady),
|
||||
0x01 => Some(Command::Rewind),
|
||||
0x03 => Some(Command::RequestSense),
|
||||
0x04 => Some(Command::Format),
|
||||
0x05 => Some(Command::ReadBlockLimits),
|
||||
0x08 => Some(Command::Read6),
|
||||
0x0a => Some(Command::Write6),
|
||||
0x0b => Some(Command::Seek6),
|
||||
0x0f => Some(Command::ReadReverse6),
|
||||
0x10 => Some(Command::WriteFilemarks6),
|
||||
0x11 => Some(Command::Space6),
|
||||
0x12 => Some(Command::Inquiry),
|
||||
0x13 => Some(Command::Verify6),
|
||||
0x14 => Some(Command::RecoverBufferedData),
|
||||
0x15 => Some(Command::ModeSelect6),
|
||||
0x16 => Some(Command::Reserve6),
|
||||
0x17 => Some(Command::Release6),
|
||||
0x18 => Some(Command::Copy),
|
||||
0x19 => Some(Command::Erase6),
|
||||
0x1a => Some(Command::ModeSense6),
|
||||
0x1c => Some(Command::ReceiveDiagnosticResults),
|
||||
0x1d => Some(Command::SendDiagnostic),
|
||||
0x1e => Some(Command::PreventAllowMediumRemoval),
|
||||
0x23 => Some(Command::ReadFormatCapacities),
|
||||
0x25 => Some(Command::ReadCapacity10),
|
||||
0x28 => Some(Command::Read10),
|
||||
0x29 => Some(Command::ReadGeneration),
|
||||
0x2a => Some(Command::Write10),
|
||||
0x2c => Some(Command::Erase10),
|
||||
0x2d => Some(Command::ReadUpdatedBlock),
|
||||
0x2e => Some(Command::WriteAndVerify10),
|
||||
0x2f => Some(Command::Verify10),
|
||||
0x33 => Some(Command::SetLimits10),
|
||||
0x35 => Some(Command::SynchronizeCache10),
|
||||
0x36 => Some(Command::LockUnlockCache10),
|
||||
0x38 => Some(Command::MediumScan),
|
||||
0x39 => Some(Command::Compare),
|
||||
0x3a => Some(Command::CopyAndVerify),
|
||||
0x3b => Some(Command::WriteBuffer),
|
||||
0x3c => Some(Command::ReadBuffer),
|
||||
0x3d => Some(Command::UpdateBlock),
|
||||
0x3e => Some(Command::ReadLong10),
|
||||
0x3f => Some(Command::WriteLong10),
|
||||
0x40 => Some(Command::ChangeDefinition),
|
||||
0x41 => Some(Command::WriteSame10),
|
||||
0x42 => Some(Command::Unmap),
|
||||
0x43 => Some(Command::ReadTocPmaAtip),
|
||||
0x44 => Some(Command::ReportDensitySupport),
|
||||
0x45 => Some(Command::PlayAudio10),
|
||||
0x46 => Some(Command::GetConfiguration),
|
||||
0x47 => Some(Command::PlayAudioMsf),
|
||||
0x48 => Some(Command::Sanitize),
|
||||
0x4a => Some(Command::GetEventStatusNotification),
|
||||
0x4b => Some(Command::PauseResume),
|
||||
0x4c => Some(Command::LogSelect),
|
||||
0x4d => Some(Command::LogSense),
|
||||
0x50 => Some(Command::XdWrite10),
|
||||
0x52 => Some(Command::XdRead10),
|
||||
0x53 => Some(Command::XdWriteRead10),
|
||||
0x54 => Some(Command::SendOpcInformation),
|
||||
0x55 => Some(Command::ModeSelect10),
|
||||
0x56 => Some(Command::Reserve10),
|
||||
0x57 => Some(Command::Release10),
|
||||
0x58 => Some(Command::RepairTrack),
|
||||
0x5a => Some(Command::ModeSense10),
|
||||
0x5b => Some(Command::CloseTrackSession),
|
||||
0x5c => Some(Command::ReadBufferCapacity),
|
||||
0x5d => Some(Command::SendCueSheet),
|
||||
0x5e => Some(Command::PersistentReserveIn),
|
||||
0x5f => Some(Command::PersistentReserveOut),
|
||||
0x81 => Some(Command::ReadReverse16),
|
||||
0x83 => Some(Command::ThirdPartyCopyOut),
|
||||
0x84 => Some(Command::ThirdPartyCopyIn),
|
||||
0x85 => Some(Command::AtaPassThrough16),
|
||||
0x86 => Some(Command::AccessControlIn),
|
||||
0x87 => Some(Command::AccessControlOut),
|
||||
0x88 => Some(Command::Read16),
|
||||
0x89 => Some(Command::CompareAndWrite),
|
||||
0x8a => Some(Command::Write16),
|
||||
0x8b => Some(Command::OrWrite),
|
||||
0x8c => Some(Command::ReadAttribute),
|
||||
0x8d => Some(Command::WriteAttribute),
|
||||
0x8e => Some(Command::WriteAndVerify16),
|
||||
0x8f => Some(Command::Verify16),
|
||||
0x90 => Some(Command::PreFetch16),
|
||||
0x9f => Some(Command::ServiceActionIn16),
|
||||
0xa0 => Some(Command::ReportLuns),
|
||||
0xa1 => Some(Command::AtaPassThrough12),
|
||||
0xa2 => Some(Command::SecurityProtocolIn),
|
||||
0xa3 => Some(Command::MaintenanceIn),
|
||||
0xa6 => Some(Command::ExchangeMedium),
|
||||
0xa7 => Some(Command::MoveMediumAttached),
|
||||
0xa8 => Some(Command::Read12),
|
||||
0xa9 => Some(Command::ServiceActionOut12),
|
||||
0xaa => Some(Command::Write12),
|
||||
0xab => Some(Command::ServiceActionIn12),
|
||||
0xac => Some(Command::Erase12),
|
||||
0xad => Some(Command::ReadDvdStructure),
|
||||
0xae => Some(Command::WriteAndVerify12),
|
||||
0xaf => Some(Command::Verify12),
|
||||
0xb0 => Some(Command::SearchDataHigh12),
|
||||
0xb1 => Some(Command::SearchDataEqual12),
|
||||
0xb2 => Some(Command::SearchDataLow12),
|
||||
0xb3 => Some(Command::SetLimits12),
|
||||
0xb4 => Some(Command::ReadElementStatusAttached),
|
||||
0xb5 => Some(Command::SecurityProtocolOut),
|
||||
0xb6 => Some(Command::SendVolumeTag),
|
||||
0xb7 => Some(Command::ReadDefectData12),
|
||||
0xb8 => Some(Command::ReadElementStatus),
|
||||
0xb9 => Some(Command::ReadCdMsf),
|
||||
0xba => Some(Command::RedundancyGroupIn),
|
||||
0xbb => Some(Command::RedundancyGroupOut),
|
||||
0xbc => Some(Command::SpareIn),
|
||||
0xbd => Some(Command::SpareOut),
|
||||
0xbe => Some(Command::VolumeSetIn),
|
||||
0xbf => Some(Command::VolumeSetOut),
|
||||
_ => None,
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_code(code: u8) -> Command {
|
||||
// TODO: handle non-trivial commands
|
||||
Command::from_code_trivial(code).unwrap_or_else(|| panic!("Unrecognized command code: {}", code))
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
#![no_std]
|
||||
|
||||
pub mod commands;
|
Loading…
Reference in New Issue