first draft
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "cdrustanoia_capi_types"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
publish = false
|
||||
|
||||
[lib]
|
||||
name = "cdrustanoia_capi_types"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
libc.workspace = true
|
||||
@@ -0,0 +1,165 @@
|
||||
//! C ABI-compatible public structures shared by the two cdda libraries.
|
||||
|
||||
use libc::{c_char, c_int, c_long, c_void, sigset_t};
|
||||
|
||||
pub const MAXTRK: usize = 100;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Default)]
|
||||
pub struct Toc {
|
||||
pub b_flags: u8,
|
||||
pub b_track: u8,
|
||||
pub dw_start_sector: i32,
|
||||
}
|
||||
|
||||
pub type EnableCddaFn = Option<unsafe extern "C" fn(*mut CdromDrive, c_int) -> c_int>;
|
||||
pub type ReadTocFn = Option<unsafe extern "C" fn(*mut CdromDrive) -> c_int>;
|
||||
pub type ReadAudioFn =
|
||||
Option<unsafe extern "C" fn(*mut CdromDrive, *mut c_void, c_long, c_long) -> c_long>;
|
||||
pub type SetSpeedFn = Option<unsafe extern "C" fn(*mut CdromDrive, c_int) -> c_int>;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct CddaPrivateData {
|
||||
pub holder: *mut c_void,
|
||||
pub last_milliseconds: c_int,
|
||||
pub clock: c_int,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct CdromDrive {
|
||||
pub opened: c_int,
|
||||
pub cdda_device_name: *mut c_char,
|
||||
pub ioctl_device_name: *mut c_char,
|
||||
pub cdda_fd: c_int,
|
||||
pub ioctl_fd: c_int,
|
||||
pub drive_model: *mut c_char,
|
||||
pub drive_type: c_int,
|
||||
pub interface: c_int,
|
||||
pub bigendianp: c_int,
|
||||
pub nsectors: c_int,
|
||||
pub cd_extra: c_int,
|
||||
pub tracks: c_int,
|
||||
pub disc_toc: [Toc; MAXTRK],
|
||||
pub audio_first_sector: c_long,
|
||||
pub audio_last_sector: c_long,
|
||||
pub errordest: c_int,
|
||||
pub messagedest: c_int,
|
||||
pub errorbuf: *mut c_char,
|
||||
pub messagebuf: *mut c_char,
|
||||
pub enable_cdda: EnableCddaFn,
|
||||
pub read_toc: ReadTocFn,
|
||||
pub read_audio: ReadAudioFn,
|
||||
pub set_speed: SetSpeedFn,
|
||||
pub error_retry: c_int,
|
||||
pub report_all: c_int,
|
||||
pub is_atapi: c_int,
|
||||
pub is_mmc: c_int,
|
||||
pub private: *mut CddaPrivateData,
|
||||
pub reserved: *mut c_void,
|
||||
pub inqbytes: [u8; 4],
|
||||
pub density: u8,
|
||||
pub orgdens: u8,
|
||||
pub orgsize: u32,
|
||||
pub bigbuff: c_long,
|
||||
pub adjust_ssize: c_int,
|
||||
pub fua: c_int,
|
||||
pub lun: c_int,
|
||||
pub sigset: sigset_t,
|
||||
}
|
||||
|
||||
impl CdromDrive {
|
||||
pub fn empty() -> Self {
|
||||
Self {
|
||||
opened: 0,
|
||||
cdda_device_name: std::ptr::null_mut(),
|
||||
ioctl_device_name: std::ptr::null_mut(),
|
||||
cdda_fd: -1,
|
||||
ioctl_fd: -1,
|
||||
drive_model: std::ptr::null_mut(),
|
||||
drive_type: 0,
|
||||
interface: 0,
|
||||
bigendianp: -1,
|
||||
nsectors: -1,
|
||||
cd_extra: 0,
|
||||
tracks: 0,
|
||||
disc_toc: [Toc::default(); MAXTRK],
|
||||
audio_first_sector: 0,
|
||||
audio_last_sector: 0,
|
||||
errordest: 0,
|
||||
messagedest: 0,
|
||||
errorbuf: std::ptr::null_mut(),
|
||||
messagebuf: std::ptr::null_mut(),
|
||||
enable_cdda: None,
|
||||
read_toc: None,
|
||||
read_audio: None,
|
||||
set_speed: None,
|
||||
error_retry: 0,
|
||||
report_all: 0,
|
||||
is_atapi: 0,
|
||||
is_mmc: 0,
|
||||
private: std::ptr::null_mut(),
|
||||
reserved: std::ptr::null_mut(),
|
||||
inqbytes: [0; 4],
|
||||
density: 0,
|
||||
orgdens: 0,
|
||||
orgsize: 0,
|
||||
bigbuff: 0,
|
||||
adjust_ssize: 1,
|
||||
fua: 0,
|
||||
lun: 0,
|
||||
sigset: unsafe { std::mem::zeroed() },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub const INTERFACE_GENERIC_SCSI: c_int = 0;
|
||||
pub const INTERFACE_COOKED_IOCTL: c_int = 1;
|
||||
pub const INTERFACE_TEST: c_int = 2;
|
||||
pub const INTERFACE_SGIO_SCSI: c_int = 3;
|
||||
pub const INTERFACE_SGIO_SCSI_BUGGY1: c_int = 4;
|
||||
|
||||
pub const CDDA_MESSAGE_FORGETIT: c_int = 0;
|
||||
pub const CDDA_MESSAGE_PRINTIT: c_int = 1;
|
||||
pub const CDDA_MESSAGE_LOGIT: c_int = 2;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::mem::{offset_of, size_of};
|
||||
|
||||
#[test]
|
||||
fn abi_layout_matches_cdparanoia() {
|
||||
assert_eq!(size_of::<Toc>(), 8);
|
||||
assert_eq!(offset_of!(Toc, b_flags), 0);
|
||||
assert_eq!(offset_of!(Toc, b_track), 1);
|
||||
assert_eq!(offset_of!(Toc, dw_start_sector), 4);
|
||||
assert_eq!(size_of::<CdromDrive>(), 1136);
|
||||
assert_eq!(offset_of!(CdromDrive, opened), 0);
|
||||
assert_eq!(offset_of!(CdromDrive, cdda_device_name), 8);
|
||||
assert_eq!(offset_of!(CdromDrive, cdda_fd), 24);
|
||||
assert_eq!(offset_of!(CdromDrive, drive_model), 32);
|
||||
assert_eq!(offset_of!(CdromDrive, drive_type), 40);
|
||||
assert_eq!(offset_of!(CdromDrive, interface), 44);
|
||||
assert_eq!(offset_of!(CdromDrive, bigendianp), 48);
|
||||
assert_eq!(offset_of!(CdromDrive, nsectors), 52);
|
||||
assert_eq!(offset_of!(CdromDrive, cd_extra), 56);
|
||||
assert_eq!(offset_of!(CdromDrive, tracks), 60);
|
||||
assert_eq!(offset_of!(CdromDrive, disc_toc), 64);
|
||||
assert_eq!(offset_of!(CdromDrive, audio_first_sector), 864);
|
||||
assert_eq!(offset_of!(CdromDrive, errordest), 880);
|
||||
assert_eq!(offset_of!(CdromDrive, errorbuf), 888);
|
||||
assert_eq!(offset_of!(CdromDrive, error_retry), 936);
|
||||
assert_eq!(offset_of!(CdromDrive, report_all), 940);
|
||||
assert_eq!(offset_of!(CdromDrive, is_atapi), 944);
|
||||
assert_eq!(offset_of!(CdromDrive, is_mmc), 948);
|
||||
assert_eq!(offset_of!(CdromDrive, private), 952);
|
||||
assert_eq!(offset_of!(CdromDrive, reserved), 960);
|
||||
assert_eq!(offset_of!(CdromDrive, inqbytes), 968);
|
||||
assert_eq!(offset_of!(CdromDrive, density), 972);
|
||||
assert_eq!(offset_of!(CdromDrive, bigbuff), 984);
|
||||
assert_eq!(offset_of!(CdromDrive, adjust_ssize), 992);
|
||||
assert_eq!(offset_of!(CdromDrive, fua), 996);
|
||||
assert_eq!(offset_of!(CdromDrive, lun), 1000);
|
||||
assert_eq!(offset_of!(CdromDrive, sigset), 1008);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user