2013年4月6日星期六

检测光驱的功能 及 属性

How to enumerate CD drives and get their properties/capabilities

光驱的 Capabilities(功能) 有:
such as CD-R/RW or DVD-ROM/R/RAM
CD Capabilities and Mechanical Status

光驱的 属性有:


SCSI Mode Sense Command

Page Code - see the separate Wikipedia page for a list of SCSI mode pages

15  OMO O OOOO OO   MODE SELECT(6)
1A  OMO O OOOO OO   MODE SENSE(6)      6-byte version

55  OOO OMOOOOMOMO  MODE SELECT(10)
5A  OOO OMOOOOMOMO  MODE SENSE(10)     10-byte version


CD/DVD Capabilities and Mechanical Status Page (Page Code 2Ah)

Media Identification Code - DVD table of contents(TOC)


Media Identification Code

The Media IDentification code (MID) is used on DVD-RDVD+R and DVD-RAM discs to identify the manufacturer and to assist the DVD burner to select the best write strategy for the inserted media. The technology is inherited from the ATIP code used on CD-R discs.
If the DVD burner recognizes the discs it means that the disc has been tested by the drive manufacturer to achieve the best possible burn using an optimal write strategy. The strategy is stored in the firmware. Writing to a disc with no MID code or a code that is not recognized can result in inaccurate recording and data read-back problems。

'DVD Identifier' retrieves and interprets the pre-recorded information 
that is present on all DVD+R/+RW, DVD-R/-RW and DVD-RAM media. 
This information contains a variety of parameters such as 
1)disc manufacturing information 
2)supported write speeds.

Media ID - Brand - Format
RICOHJPN-R01-002 - Sony DVD-R

D:\cdrtools-beta\cdrtools-3.01\cdrecord\diskid.c

DVD table of contents(TOC)

READ TOC Command 读轨道TOC命令. TOC是指光盘中轨道的开始地址及其它相关信息,这些信息存在于Q sub-channel(Q子信道)中

2013年4月5日星期五

aspi spti


主机与外围SCSI或ATAPI接口存储设备通讯的编程接口

ASPI(Advanced SCSI Programming Interface)是由存储领域大名鼎鼎的Adaptec于1990年代初期开发的,最初是为了支持SCSI驱动器,后来加入了ATAPI驱动器的支持。MS获取授权在windows 9x系列使用这个开发接口。
其目的是创建一个接口(一个标准层/设备驱动程序集),用于和SCSI总线上的设备直接通信(与设备talk)。
该技术后来,扩散到其它总线技术上:
IDE (Integrated Drive Electronics)
ATAPI (AT Attachment Packet Interface) i.e. CD Burners
SCSI-like i.e. parallel port
因为MS,当时没有相应的技术,所以MS获取授权在windows 9x系列使用这个开发接口。

MS在NT系列开发了自己的接口,这就是SPTI(SCSI Pass Through Interface)用以取代ASPI。NT系统默认是没有安装ASPI驱动的,不过有些存储应用程序还在使用ASPI接口,可以从Adaptec下载此驱动安装。

SPTD则是由Duplex Secure Ltd.开发的同类接口

Nero也开发了自己的ASPI驱动。其他比较有名的还有ASAPI等

Microsoft also created another drive access layer, called IOCTL (Input/Output Control).


The storage port drivers provide an interface for Win32 applications to send SCSI Command Descriptor Block (CDB) messages to SCSI devices. The interfaces are IOCTL_SCSI_PASS_THROUGH and IOCTL_SCSI_PASS_THROUGH_DIRECT. Applications can build a pass-through request and send it to the device by using this IOCTL.
SPTI is accessible to Windows software using the DeviceIoControl Windows API.[2]
ImgBurn offers SPTI as a method for accessing optical disc drives

SPTI (SCSI Pass Through Interface) is an API, allowing Microsoft Windows applications (starting with NT/2000) to work with SCSI-devices. 
In the context of data storage, SPTI support means you can connect to a server and export, via an iSCSI network, 
any physical SCSI-device (hard disk, tape or optical drive, etc).

SPTI is only available in the Windows NT family (NT4/2000/XP/2003/Vista) and needs an account with administrator rights to work.

Real ASPI (i.e. Adaptec's one) doesn't support USB / Firewire. 

All about ASPI and SPTI

I have extracted the required code from AKRip CD-DA Audio Extraction Library for SPTI Support and integrated it into libscg (scsi-wnt.c)

libscg

libscg - a OS independant SCSI transport library.  

scg 应该是 SCSI general driver 缩写。

windows spti 接口(SCSI Pass-Through Interface
D:\cdrtools-beta\cdrtools-3.01\libscg\scsi-wnt.c
D:\cdrtools-beta\cdrtools-3.01\libscg\scg\spti-wnt.h
Send a SCSI command

EXPORT int  scg_cmd(scgp) SCSI *scgp;

typedef struct scg_ops {
int (*scgo_send) __PR((SCSI *scgp));

char * (*scgo_version) __PR((SCSI *scgp, int what));
#ifdef EOF /* stdio.h has been included */
int (*scgo_help) __PR((SCSI *scgp, FILE *f));
#else
int (*scgo_help) __PR((SCSI *scgp, void *f));
#endif
int (*scgo_open) __PR((SCSI *scgp, char *device));
int (*scgo_close) __PR((SCSI *scgp));
long (*scgo_maxdma) __PR((SCSI *scgp, long amt));
void * (*scgo_getbuf) __PR((SCSI *scgp, long amt));
void (*scgo_freebuf) __PR((SCSI *scgp));


int (*scgo_numbus) __PR((SCSI *scgp));
BOOL (*scgo_havebus) __PR((SCSI *scgp, int busno));
int (*scgo_fileno) __PR((SCSI *scgp, int busno, int tgt, int tlun));
int (*scgo_initiator_id) __PR((SCSI *scgp));
int (*scgo_isatapi) __PR((SCSI *scgp));
int (*scgo_reset) __PR((SCSI *scgp, int what));
} scg_ops_t;


scsitransp.h
struct scg_scsi {
scg_ops_t *ops; /* Ptr to low level SCSI transport ops */
int fd; /* File descriptor for next I/O */
scg_addr_t addr; /* SCSI address for next I/O */
int flags; /* Libscg flags (see below) */
int dflags; /* Drive specific flags (see below) */
int kdebug; /* Kernel debug value for next I/O */
int debug; /* Debug value for SCSI library */
int silent; /* Be silent if value > 0 */
int verbose; /* Be verbose if value > 0 */
int overbose; /* Be verbose in open() if value > 0 */
int disre_disable;
int deftimeout;
int noparity; /* Do not use SCSI parity fo next I/O */
int dev; /* from scsi_cdr.c */
struct scg_cmd *scmd;
char *cmdname;             命令名称
char *curcmdname;
BOOL running;
int error; /* libscg error number */

long maxdma; /* Max DMA limit for this open instance */
long maxbuf; /* Cur DMA buffer limit for this inst. */
/* This is the size behind bufptr */
struct timeval *cmdstart;
struct timeval *cmdstop;
const char **nonstderrs;
void *local; /* Local data from the low level code */
void *bufbase; /* needed for scsi_freebuf() */
void *bufptr; /* DMA buffer pointer for appl. use */
char *errstr; /* Error string for scsi_open/sendmcd */
char *errbeg; /* Pointer to begin of not flushed data */
char *errptr; /* Actual write pointer into errstr */
void *errfile; /* FILE to write errors to. NULL for not*/
/* writing and leaving errs in errstr */
scg_cb_t cb_fun;
void *cb_arg;

struct scsi_inquiry *inq;
struct scsi_capacity *cap;
};

cgp->cmdname = "read_format_capacities";
cgp->cmdname = "set streaming";
scgp->cmdname = "get performance"; (性能)
scgp->cmdname = "get_configuration";


BerliOS (short for "Berlin Open Source") is a project founded by FOKUS, a Fraunhofer Institute located in Berlin, to coordinate the different interest groups in the field of open source software (OSS) and to assume a neutral coordinator function. The target groups of BerliOS are developers and users of open source software on the one side and OSS-related companies on the other.

2013年4月4日星期四

微软的东东,多数是把聪明人搞晕,把晕的人搞残,把残的人搞死

呵呵

驱动模型 Vxd WDM(DDK) WDF(WDK)

驱动模型

Vxd
95/98/ME下  这个东西已经过时
Vxd驱动文件扩展名为:.vxd

WDM(开发包DDK)    Windows Driver Model
2000/XP/2003下
开发2000/XP/2003的驱动开发包为:DDK
WDM和WDF驱动文件扩展名为:.sys

WDF(开发包WDK)    Windows Driver Foudation
Vista及以后版本
对应的开发包:WDK
WDM和WDF驱动文件扩展名为:.sys


WDK可以看做是DDK的升级版本,现在一般的WDK是包含以前DDK相关的功能,现在XP下也可以用WDK开发驱动,WDK能编译出2000-2008的各种驱动

WDF驱动程序包括两个类型,
一个是内核级的,称为KMDF(Kernel-Mode Driver Framework),为SYS文件
一个是用户级的,称为UMDF(User-Mode Driver Framework),为DLL文件

WDM驱动模型和WDF驱动模型的最大的区别是
WDF驱动框架对WDM进行了一次封装
WDF 驱动采用队列进行IO处理,而WDM中将所有的IO操作都用默认的队列进行处理,如果要进行IRp同步,必须使用StartIO
WDF是面向对象的,而WDM是面向过程的,WDF提供对象的封装,如将IRP封装成WDFREQUEST,对象提供方法和Event

The IRP structure is a partial opaque structure that represents an I/O request packet

IOCTL_SCSI_PASS_THROUGH_DIRECT - Command Descriptor Block (CDB)

IOCTL_SCSI_PASS_THROUGH_DIRECT

Ntddscsi.h


typedef struct SCSI_PASS_THROUGH_DIRECT
{
    USHORT Length;
    UCHAR ScsiStatus;
    UCHAR PathId;
    UCHAR TargetId;
    UCHAR Lun;
    UCHAR CdbLength;
    UCHAR SenseInfoLength;
    UCHAR DataIn;
    ULONG DataTransferLength;
    ULONG TimeOutValue;
    PVOID DataBuffer;
    ULONG SenseInfoOffset;
    UCHAR Cdb[16];
} SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT;

SCSI Operation Codes
Command Descriptor Blocks 列表
there are specifications for CD/DVD devices (MMC), hard drives (SBC), tape drives (SSC), and more

SCSI Request Block (SRB)  == SCSI Pass Through request

SRBs and CDBs are used across any hard drive whether it's SCSI, ATA, Fibre Channel, RAID, SAS, or others.


SCSI Multimedia Commands



SCSI Multimedia Commands (MMC) defines a SCSI/ATAPI based command set for accessing multimedia features on devices capable of such functionality. T10 subcommittee is responsible for developing it as well as other SCSI command set standards.


R - C/DVD DEVICE (MMC-6) 



Cdrecord(刻录) 用到的命令

43       O          READ TOC/PMA/ATIP
46       M          GET CONFIGURATION
AC       O          GET PERFORMANCE
23       O          READ FORMAT CAPACITIES  read_format_capacities