Merge branch 'docs-next' of git://git.lwn.net/linux-2.6
[linux-2.6/next.git] / include / linux / cdrom.h
blob78e904796622532ff822cdc78e6e19669b87f48c
1 /*
2 * -- <linux/cdrom.h>
3 * General header file for linux CD-ROM drivers
4 * Copyright (C) 1992 David Giller, rafetmad@oxy.edu
5 * 1994, 1995 Eberhard Mönkeberg, emoenke@gwdg.de
6 * 1996 David van Leeuwen, david@tm.tno.nl
7 * 1997, 1998 Erik Andersen, andersee@debian.org
8 * 1998-2002 Jens Axboe, axboe@suse.de
9 */
11 #ifndef _LINUX_CDROM_H
12 #define _LINUX_CDROM_H
14 #include <linux/types.h>
15 #include <asm/byteorder.h>
17 /*******************************************************
18 * As of Linux 2.1.x, all Linux CD-ROM application programs will use this
19 * (and only this) include file. It is my hope to provide Linux with
20 * a uniform interface between software accessing CD-ROMs and the various
21 * device drivers that actually talk to the drives. There may still be
22 * 23 different kinds of strange CD-ROM drives, but at least there will
23 * now be one, and only one, Linux CD-ROM interface.
25 * Additionally, as of Linux 2.1.x, all Linux application programs
26 * should use the O_NONBLOCK option when opening a CD-ROM device
27 * for subsequent ioctl commands. This allows for neat system errors
28 * like "No medium found" or "Wrong medium type" upon attempting to
29 * mount or play an empty slot, mount an audio disc, or play a data disc.
30 * Generally, changing an application program to support O_NONBLOCK
31 * is as easy as the following:
32 * - drive = open("/dev/cdrom", O_RDONLY);
33 * + drive = open("/dev/cdrom", O_RDONLY | O_NONBLOCK);
34 * It is worth the small change.
36 * Patches for many common CD programs (provided by David A. van Leeuwen)
37 * can be found at: ftp://ftp.gwdg.de/pub/linux/cdrom/drivers/cm206/
39 *******************************************************/
41 /* When a driver supports a certain function, but the cdrom drive we are
42 * using doesn't, we will return the error EDRIVE_CANT_DO_THIS. We will
43 * borrow the "Operation not supported" error from the network folks to
44 * accomplish this. Maybe someday we will get a more targeted error code,
45 * but this will do for now... */
46 #define EDRIVE_CANT_DO_THIS EOPNOTSUPP
48 /*******************************************************
49 * The CD-ROM IOCTL commands -- these should be supported by
50 * all the various cdrom drivers. For the CD-ROM ioctls, we
51 * will commandeer byte 0x53, or 'S'.
52 *******************************************************/
53 #define CDROMPAUSE 0x5301 /* Pause Audio Operation */
54 #define CDROMRESUME 0x5302 /* Resume paused Audio Operation */
55 #define CDROMPLAYMSF 0x5303 /* Play Audio MSF (struct cdrom_msf) */
56 #define CDROMPLAYTRKIND 0x5304 /* Play Audio Track/index
57 (struct cdrom_ti) */
58 #define CDROMREADTOCHDR 0x5305 /* Read TOC header
59 (struct cdrom_tochdr) */
60 #define CDROMREADTOCENTRY 0x5306 /* Read TOC entry
61 (struct cdrom_tocentry) */
62 #define CDROMSTOP 0x5307 /* Stop the cdrom drive */
63 #define CDROMSTART 0x5308 /* Start the cdrom drive */
64 #define CDROMEJECT 0x5309 /* Ejects the cdrom media */
65 #define CDROMVOLCTRL 0x530a /* Control output volume
66 (struct cdrom_volctrl) */
67 #define CDROMSUBCHNL 0x530b /* Read subchannel data
68 (struct cdrom_subchnl) */
69 #define CDROMREADMODE2 0x530c /* Read CDROM mode 2 data (2336 Bytes)
70 (struct cdrom_read) */
71 #define CDROMREADMODE1 0x530d /* Read CDROM mode 1 data (2048 Bytes)
72 (struct cdrom_read) */
73 #define CDROMREADAUDIO 0x530e /* (struct cdrom_read_audio) */
74 #define CDROMEJECT_SW 0x530f /* enable(1)/disable(0) auto-ejecting */
75 #define CDROMMULTISESSION 0x5310 /* Obtain the start-of-last-session
76 address of multi session disks
77 (struct cdrom_multisession) */
78 #define CDROM_GET_MCN 0x5311 /* Obtain the "Universal Product Code"
79 if available (struct cdrom_mcn) */
80 #define CDROM_GET_UPC CDROM_GET_MCN /* This one is deprecated,
81 but here anyway for compatibility */
82 #define CDROMRESET 0x5312 /* hard-reset the drive */
83 #define CDROMVOLREAD 0x5313 /* Get the drive's volume setting
84 (struct cdrom_volctrl) */
85 #define CDROMREADRAW 0x5314 /* read data in raw mode (2352 Bytes)
86 (struct cdrom_read) */
87 /*
88 * These ioctls are used only used in aztcd.c and optcd.c
90 #define CDROMREADCOOKED 0x5315 /* read data in cooked mode */
91 #define CDROMSEEK 0x5316 /* seek msf address */
94 * This ioctl is only used by the scsi-cd driver.
95 It is for playing audio in logical block addressing mode.
97 #define CDROMPLAYBLK 0x5317 /* (struct cdrom_blk) */
99 /*
100 * These ioctls are only used in optcd.c
102 #define CDROMREADALL 0x5318 /* read all 2646 bytes */
105 * These ioctls are (now) only in ide-cd.c for controlling
106 * drive spindown time. They should be implemented in the
107 * Uniform driver, via generic packet commands, GPCMD_MODE_SELECT_10,
108 * GPCMD_MODE_SENSE_10 and the GPMODE_POWER_PAGE...
109 * -Erik
111 #define CDROMGETSPINDOWN 0x531d
112 #define CDROMSETSPINDOWN 0x531e
115 * These ioctls are implemented through the uniform CD-ROM driver
116 * They _will_ be adopted by all CD-ROM drivers, when all the CD-ROM
117 * drivers are eventually ported to the uniform CD-ROM driver interface.
119 #define CDROMCLOSETRAY 0x5319 /* pendant of CDROMEJECT */
120 #define CDROM_SET_OPTIONS 0x5320 /* Set behavior options */
121 #define CDROM_CLEAR_OPTIONS 0x5321 /* Clear behavior options */
122 #define CDROM_SELECT_SPEED 0x5322 /* Set the CD-ROM speed */
123 #define CDROM_SELECT_DISC 0x5323 /* Select disc (for juke-boxes) */
124 #define CDROM_MEDIA_CHANGED 0x5325 /* Check is media changed */
125 #define CDROM_DRIVE_STATUS 0x5326 /* Get tray position, etc. */
126 #define CDROM_DISC_STATUS 0x5327 /* Get disc type, etc. */
127 #define CDROM_CHANGER_NSLOTS 0x5328 /* Get number of slots */
128 #define CDROM_LOCKDOOR 0x5329 /* lock or unlock door */
129 #define CDROM_DEBUG 0x5330 /* Turn debug messages on/off */
130 #define CDROM_GET_CAPABILITY 0x5331 /* get capabilities */
132 /* Note that scsi/scsi_ioctl.h also uses 0x5382 - 0x5386.
133 * Future CDROM ioctls should be kept below 0x537F
136 /* This ioctl is only used by sbpcd at the moment */
137 #define CDROMAUDIOBUFSIZ 0x5382 /* set the audio buffer size */
138 /* conflict with SCSI_IOCTL_GET_IDLUN */
140 /* DVD-ROM Specific ioctls */
141 #define DVD_READ_STRUCT 0x5390 /* Read structure */
142 #define DVD_WRITE_STRUCT 0x5391 /* Write structure */
143 #define DVD_AUTH 0x5392 /* Authentication */
145 #define CDROM_SEND_PACKET 0x5393 /* send a packet to the drive */
146 #define CDROM_NEXT_WRITABLE 0x5394 /* get next writable block */
147 #define CDROM_LAST_WRITTEN 0x5395 /* get last block written on disc */
149 /*******************************************************
150 * CDROM IOCTL structures
151 *******************************************************/
153 /* Address in MSF format */
154 struct cdrom_msf0
156 __u8 minute;
157 __u8 second;
158 __u8 frame;
161 /* Address in either MSF or logical format */
162 union cdrom_addr
164 struct cdrom_msf0 msf;
165 int lba;
168 /* This struct is used by the CDROMPLAYMSF ioctl */
169 struct cdrom_msf
171 __u8 cdmsf_min0; /* start minute */
172 __u8 cdmsf_sec0; /* start second */
173 __u8 cdmsf_frame0; /* start frame */
174 __u8 cdmsf_min1; /* end minute */
175 __u8 cdmsf_sec1; /* end second */
176 __u8 cdmsf_frame1; /* end frame */
179 /* This struct is used by the CDROMPLAYTRKIND ioctl */
180 struct cdrom_ti
182 __u8 cdti_trk0; /* start track */
183 __u8 cdti_ind0; /* start index */
184 __u8 cdti_trk1; /* end track */
185 __u8 cdti_ind1; /* end index */
188 /* This struct is used by the CDROMREADTOCHDR ioctl */
189 struct cdrom_tochdr
191 __u8 cdth_trk0; /* start track */
192 __u8 cdth_trk1; /* end track */
195 /* This struct is used by the CDROMVOLCTRL and CDROMVOLREAD ioctls */
196 struct cdrom_volctrl
198 __u8 channel0;
199 __u8 channel1;
200 __u8 channel2;
201 __u8 channel3;
204 /* This struct is used by the CDROMSUBCHNL ioctl */
205 struct cdrom_subchnl
207 __u8 cdsc_format;
208 __u8 cdsc_audiostatus;
209 __u8 cdsc_adr: 4;
210 __u8 cdsc_ctrl: 4;
211 __u8 cdsc_trk;
212 __u8 cdsc_ind;
213 union cdrom_addr cdsc_absaddr;
214 union cdrom_addr cdsc_reladdr;
218 /* This struct is used by the CDROMREADTOCENTRY ioctl */
219 struct cdrom_tocentry
221 __u8 cdte_track;
222 __u8 cdte_adr :4;
223 __u8 cdte_ctrl :4;
224 __u8 cdte_format;
225 union cdrom_addr cdte_addr;
226 __u8 cdte_datamode;
229 /* This struct is used by the CDROMREADMODE1, and CDROMREADMODE2 ioctls */
230 struct cdrom_read
232 int cdread_lba;
233 char *cdread_bufaddr;
234 int cdread_buflen;
237 /* This struct is used by the CDROMREADAUDIO ioctl */
238 struct cdrom_read_audio
240 union cdrom_addr addr; /* frame address */
241 __u8 addr_format; /* CDROM_LBA or CDROM_MSF */
242 int nframes; /* number of 2352-byte-frames to read at once */
243 __u8 __user *buf; /* frame buffer (size: nframes*2352 bytes) */
246 /* This struct is used with the CDROMMULTISESSION ioctl */
247 struct cdrom_multisession
249 union cdrom_addr addr; /* frame address: start-of-last-session
250 (not the new "frame 16"!). Only valid
251 if the "xa_flag" is true. */
252 __u8 xa_flag; /* 1: "is XA disk" */
253 __u8 addr_format; /* CDROM_LBA or CDROM_MSF */
256 /* This struct is used with the CDROM_GET_MCN ioctl.
257 * Very few audio discs actually have Universal Product Code information,
258 * which should just be the Medium Catalog Number on the box. Also note
259 * that the way the codeis written on CD is _not_ uniform across all discs!
261 struct cdrom_mcn
263 __u8 medium_catalog_number[14]; /* 13 ASCII digits, null-terminated */
266 /* This is used by the CDROMPLAYBLK ioctl */
267 struct cdrom_blk
269 unsigned from;
270 unsigned short len;
273 #define CDROM_PACKET_SIZE 12
275 #define CGC_DATA_UNKNOWN 0
276 #define CGC_DATA_WRITE 1
277 #define CGC_DATA_READ 2
278 #define CGC_DATA_NONE 3
280 /* for CDROM_PACKET_COMMAND ioctl */
281 struct cdrom_generic_command
283 unsigned char cmd[CDROM_PACKET_SIZE];
284 unsigned char __user *buffer;
285 unsigned int buflen;
286 int stat;
287 struct request_sense __user *sense;
288 unsigned char data_direction;
289 int quiet;
290 int timeout;
291 void __user *reserved[1]; /* unused, actually */
295 * A CD-ROM physical sector size is 2048, 2052, 2056, 2324, 2332, 2336,
296 * 2340, or 2352 bytes long.
298 * Sector types of the standard CD-ROM data formats:
300 * format sector type user data size (bytes)
301 * -----------------------------------------------------------------------------
302 * 1 (Red Book) CD-DA 2352 (CD_FRAMESIZE_RAW)
303 * 2 (Yellow Book) Mode1 Form1 2048 (CD_FRAMESIZE)
304 * 3 (Yellow Book) Mode1 Form2 2336 (CD_FRAMESIZE_RAW0)
305 * 4 (Green Book) Mode2 Form1 2048 (CD_FRAMESIZE)
306 * 5 (Green Book) Mode2 Form2 2328 (2324+4 spare bytes)
309 * The layout of the standard CD-ROM data formats:
310 * -----------------------------------------------------------------------------
311 * - audio (red): | audio_sample_bytes |
312 * | 2352 |
314 * - data (yellow, mode1): | sync - head - data - EDC - zero - ECC |
315 * | 12 - 4 - 2048 - 4 - 8 - 276 |
317 * - data (yellow, mode2): | sync - head - data |
318 * | 12 - 4 - 2336 |
320 * - XA data (green, mode2 form1): | sync - head - sub - data - EDC - ECC |
321 * | 12 - 4 - 8 - 2048 - 4 - 276 |
323 * - XA data (green, mode2 form2): | sync - head - sub - data - Spare |
324 * | 12 - 4 - 8 - 2324 - 4 |
328 /* Some generally useful CD-ROM information -- mostly based on the above */
329 #define CD_MINS 74 /* max. minutes per CD, not really a limit */
330 #define CD_SECS 60 /* seconds per minute */
331 #define CD_FRAMES 75 /* frames per second */
332 #define CD_SYNC_SIZE 12 /* 12 sync bytes per raw data frame */
333 #define CD_MSF_OFFSET 150 /* MSF numbering offset of first frame */
334 #define CD_CHUNK_SIZE 24 /* lowest-level "data bytes piece" */
335 #define CD_NUM_OF_CHUNKS 98 /* chunks per frame */
336 #define CD_FRAMESIZE_SUB 96 /* subchannel data "frame" size */
337 #define CD_HEAD_SIZE 4 /* header (address) bytes per raw data frame */
338 #define CD_SUBHEAD_SIZE 8 /* subheader bytes per raw XA data frame */
339 #define CD_EDC_SIZE 4 /* bytes EDC per most raw data frame types */
340 #define CD_ZERO_SIZE 8 /* bytes zero per yellow book mode 1 frame */
341 #define CD_ECC_SIZE 276 /* bytes ECC per most raw data frame types */
342 #define CD_FRAMESIZE 2048 /* bytes per frame, "cooked" mode */
343 #define CD_FRAMESIZE_RAW 2352 /* bytes per frame, "raw" mode */
344 #define CD_FRAMESIZE_RAWER 2646 /* The maximum possible returned bytes */
345 /* most drives don't deliver everything: */
346 #define CD_FRAMESIZE_RAW1 (CD_FRAMESIZE_RAW-CD_SYNC_SIZE) /*2340*/
347 #define CD_FRAMESIZE_RAW0 (CD_FRAMESIZE_RAW-CD_SYNC_SIZE-CD_HEAD_SIZE) /*2336*/
349 #define CD_XA_HEAD (CD_HEAD_SIZE+CD_SUBHEAD_SIZE) /* "before data" part of raw XA frame */
350 #define CD_XA_TAIL (CD_EDC_SIZE+CD_ECC_SIZE) /* "after data" part of raw XA frame */
351 #define CD_XA_SYNC_HEAD (CD_SYNC_SIZE+CD_XA_HEAD) /* sync bytes + header of XA frame */
353 /* CD-ROM address types (cdrom_tocentry.cdte_format) */
354 #define CDROM_LBA 0x01 /* "logical block": first frame is #0 */
355 #define CDROM_MSF 0x02 /* "minute-second-frame": binary, not bcd here! */
357 /* bit to tell whether track is data or audio (cdrom_tocentry.cdte_ctrl) */
358 #define CDROM_DATA_TRACK 0x04
360 /* The leadout track is always 0xAA, regardless of # of tracks on disc */
361 #define CDROM_LEADOUT 0xAA
363 /* audio states (from SCSI-2, but seen with other drives, too) */
364 #define CDROM_AUDIO_INVALID 0x00 /* audio status not supported */
365 #define CDROM_AUDIO_PLAY 0x11 /* audio play operation in progress */
366 #define CDROM_AUDIO_PAUSED 0x12 /* audio play operation paused */
367 #define CDROM_AUDIO_COMPLETED 0x13 /* audio play successfully completed */
368 #define CDROM_AUDIO_ERROR 0x14 /* audio play stopped due to error */
369 #define CDROM_AUDIO_NO_STATUS 0x15 /* no current audio status to return */
371 /* capability flags used with the uniform CD-ROM driver */
372 #define CDC_CLOSE_TRAY 0x1 /* caddy systems _can't_ close */
373 #define CDC_OPEN_TRAY 0x2 /* but _can_ eject. */
374 #define CDC_LOCK 0x4 /* disable manual eject */
375 #define CDC_SELECT_SPEED 0x8 /* programmable speed */
376 #define CDC_SELECT_DISC 0x10 /* select disc from juke-box */
377 #define CDC_MULTI_SESSION 0x20 /* read sessions>1 */
378 #define CDC_MCN 0x40 /* Medium Catalog Number */
379 #define CDC_MEDIA_CHANGED 0x80 /* media changed */
380 #define CDC_PLAY_AUDIO 0x100 /* audio functions */
381 #define CDC_RESET 0x200 /* hard reset device */
382 #define CDC_DRIVE_STATUS 0x800 /* driver implements drive status */
383 #define CDC_GENERIC_PACKET 0x1000 /* driver implements generic packets */
384 #define CDC_CD_R 0x2000 /* drive is a CD-R */
385 #define CDC_CD_RW 0x4000 /* drive is a CD-RW */
386 #define CDC_DVD 0x8000 /* drive is a DVD */
387 #define CDC_DVD_R 0x10000 /* drive can write DVD-R */
388 #define CDC_DVD_RAM 0x20000 /* drive can write DVD-RAM */
389 #define CDC_MO_DRIVE 0x40000 /* drive is an MO device */
390 #define CDC_MRW 0x80000 /* drive can read MRW */
391 #define CDC_MRW_W 0x100000 /* drive can write MRW */
392 #define CDC_RAM 0x200000 /* ok to open for WRITE */
394 /* drive status possibilities returned by CDROM_DRIVE_STATUS ioctl */
395 #define CDS_NO_INFO 0 /* if not implemented */
396 #define CDS_NO_DISC 1
397 #define CDS_TRAY_OPEN 2
398 #define CDS_DRIVE_NOT_READY 3
399 #define CDS_DISC_OK 4
401 /* return values for the CDROM_DISC_STATUS ioctl */
402 /* can also return CDS_NO_[INFO|DISC], from above */
403 #define CDS_AUDIO 100
404 #define CDS_DATA_1 101
405 #define CDS_DATA_2 102
406 #define CDS_XA_2_1 103
407 #define CDS_XA_2_2 104
408 #define CDS_MIXED 105
410 /* User-configurable behavior options for the uniform CD-ROM driver */
411 #define CDO_AUTO_CLOSE 0x1 /* close tray on first open() */
412 #define CDO_AUTO_EJECT 0x2 /* open tray on last release() */
413 #define CDO_USE_FFLAGS 0x4 /* use O_NONBLOCK information on open */
414 #define CDO_LOCK 0x8 /* lock tray on open files */
415 #define CDO_CHECK_TYPE 0x10 /* check type on open for data */
417 /* Special codes used when specifying changer slots. */
418 #define CDSL_NONE (INT_MAX-1)
419 #define CDSL_CURRENT INT_MAX
421 /* For partition based multisession access. IDE can handle 64 partitions
422 * per drive - SCSI CD-ROM's use minors to differentiate between the
423 * various drives, so we can't do multisessions the same way there.
424 * Use the -o session=x option to mount on them.
426 #define CD_PART_MAX 64
427 #define CD_PART_MASK (CD_PART_MAX - 1)
429 /*********************************************************************
430 * Generic Packet commands, MMC commands, and such
431 *********************************************************************/
433 /* The generic packet command opcodes for CD/DVD Logical Units,
434 * From Table 57 of the SFF8090 Ver. 3 (Mt. Fuji) draft standard. */
435 #define GPCMD_BLANK 0xa1
436 #define GPCMD_CLOSE_TRACK 0x5b
437 #define GPCMD_FLUSH_CACHE 0x35
438 #define GPCMD_FORMAT_UNIT 0x04
439 #define GPCMD_GET_CONFIGURATION 0x46
440 #define GPCMD_GET_EVENT_STATUS_NOTIFICATION 0x4a
441 #define GPCMD_GET_PERFORMANCE 0xac
442 #define GPCMD_INQUIRY 0x12
443 #define GPCMD_LOAD_UNLOAD 0xa6
444 #define GPCMD_MECHANISM_STATUS 0xbd
445 #define GPCMD_MODE_SELECT_10 0x55
446 #define GPCMD_MODE_SENSE_10 0x5a
447 #define GPCMD_PAUSE_RESUME 0x4b
448 #define GPCMD_PLAY_AUDIO_10 0x45
449 #define GPCMD_PLAY_AUDIO_MSF 0x47
450 #define GPCMD_PLAY_AUDIO_TI 0x48
451 #define GPCMD_PLAY_CD 0xbc
452 #define GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL 0x1e
453 #define GPCMD_READ_10 0x28
454 #define GPCMD_READ_12 0xa8
455 #define GPCMD_READ_BUFFER 0x3c
456 #define GPCMD_READ_BUFFER_CAPACITY 0x5c
457 #define GPCMD_READ_CDVD_CAPACITY 0x25
458 #define GPCMD_READ_CD 0xbe
459 #define GPCMD_READ_CD_MSF 0xb9
460 #define GPCMD_READ_DISC_INFO 0x51
461 #define GPCMD_READ_DVD_STRUCTURE 0xad
462 #define GPCMD_READ_FORMAT_CAPACITIES 0x23
463 #define GPCMD_READ_HEADER 0x44
464 #define GPCMD_READ_TRACK_RZONE_INFO 0x52
465 #define GPCMD_READ_SUBCHANNEL 0x42
466 #define GPCMD_READ_TOC_PMA_ATIP 0x43
467 #define GPCMD_REPAIR_RZONE_TRACK 0x58
468 #define GPCMD_REPORT_KEY 0xa4
469 #define GPCMD_REQUEST_SENSE 0x03
470 #define GPCMD_RESERVE_RZONE_TRACK 0x53
471 #define GPCMD_SEND_CUE_SHEET 0x5d
472 #define GPCMD_SCAN 0xba
473 #define GPCMD_SEEK 0x2b
474 #define GPCMD_SEND_DVD_STRUCTURE 0xbf
475 #define GPCMD_SEND_EVENT 0xa2
476 #define GPCMD_SEND_KEY 0xa3
477 #define GPCMD_SEND_OPC 0x54
478 #define GPCMD_SET_READ_AHEAD 0xa7
479 #define GPCMD_SET_STREAMING 0xb6
480 #define GPCMD_START_STOP_UNIT 0x1b
481 #define GPCMD_STOP_PLAY_SCAN 0x4e
482 #define GPCMD_TEST_UNIT_READY 0x00
483 #define GPCMD_VERIFY_10 0x2f
484 #define GPCMD_WRITE_10 0x2a
485 #define GPCMD_WRITE_12 0xaa
486 #define GPCMD_WRITE_AND_VERIFY_10 0x2e
487 #define GPCMD_WRITE_BUFFER 0x3b
488 /* This is listed as optional in ATAPI 2.6, but is (curiously)
489 * missing from Mt. Fuji, Table 57. It _is_ mentioned in Mt. Fuji
490 * Table 377 as an MMC command for SCSi devices though... Most ATAPI
491 * drives support it. */
492 #define GPCMD_SET_SPEED 0xbb
493 /* This seems to be a SCSI specific CD-ROM opcode
494 * to play data at track/index */
495 #define GPCMD_PLAYAUDIO_TI 0x48
497 * From MS Media Status Notification Support Specification. For
498 * older drives only.
500 #define GPCMD_GET_MEDIA_STATUS 0xda
502 /* Mode page codes for mode sense/set */
503 #define GPMODE_VENDOR_PAGE 0x00
504 #define GPMODE_R_W_ERROR_PAGE 0x01
505 #define GPMODE_WRITE_PARMS_PAGE 0x05
506 #define GPMODE_WCACHING_PAGE 0x08
507 #define GPMODE_AUDIO_CTL_PAGE 0x0e
508 #define GPMODE_POWER_PAGE 0x1a
509 #define GPMODE_FAULT_FAIL_PAGE 0x1c
510 #define GPMODE_TO_PROTECT_PAGE 0x1d
511 #define GPMODE_CAPABILITIES_PAGE 0x2a
512 #define GPMODE_ALL_PAGES 0x3f
513 /* Not in Mt. Fuji, but in ATAPI 2.6 -- deprecated now in favor
514 * of MODE_SENSE_POWER_PAGE */
515 #define GPMODE_CDROM_PAGE 0x0d
519 /* DVD struct types */
520 #define DVD_STRUCT_PHYSICAL 0x00
521 #define DVD_STRUCT_COPYRIGHT 0x01
522 #define DVD_STRUCT_DISCKEY 0x02
523 #define DVD_STRUCT_BCA 0x03
524 #define DVD_STRUCT_MANUFACT 0x04
526 struct dvd_layer {
527 __u8 book_version : 4;
528 __u8 book_type : 4;
529 __u8 min_rate : 4;
530 __u8 disc_size : 4;
531 __u8 layer_type : 4;
532 __u8 track_path : 1;
533 __u8 nlayers : 2;
534 __u8 track_density : 4;
535 __u8 linear_density : 4;
536 __u8 bca : 1;
537 __u32 start_sector;
538 __u32 end_sector;
539 __u32 end_sector_l0;
542 #define DVD_LAYERS 4
544 struct dvd_physical {
545 __u8 type;
546 __u8 layer_num;
547 struct dvd_layer layer[DVD_LAYERS];
550 struct dvd_copyright {
551 __u8 type;
553 __u8 layer_num;
554 __u8 cpst;
555 __u8 rmi;
558 struct dvd_disckey {
559 __u8 type;
561 unsigned agid : 2;
562 __u8 value[2048];
565 struct dvd_bca {
566 __u8 type;
568 int len;
569 __u8 value[188];
572 struct dvd_manufact {
573 __u8 type;
575 __u8 layer_num;
576 int len;
577 __u8 value[2048];
580 typedef union {
581 __u8 type;
583 struct dvd_physical physical;
584 struct dvd_copyright copyright;
585 struct dvd_disckey disckey;
586 struct dvd_bca bca;
587 struct dvd_manufact manufact;
588 } dvd_struct;
591 * DVD authentication ioctl
594 /* Authentication states */
595 #define DVD_LU_SEND_AGID 0
596 #define DVD_HOST_SEND_CHALLENGE 1
597 #define DVD_LU_SEND_KEY1 2
598 #define DVD_LU_SEND_CHALLENGE 3
599 #define DVD_HOST_SEND_KEY2 4
601 /* Termination states */
602 #define DVD_AUTH_ESTABLISHED 5
603 #define DVD_AUTH_FAILURE 6
605 /* Other functions */
606 #define DVD_LU_SEND_TITLE_KEY 7
607 #define DVD_LU_SEND_ASF 8
608 #define DVD_INVALIDATE_AGID 9
609 #define DVD_LU_SEND_RPC_STATE 10
610 #define DVD_HOST_SEND_RPC_STATE 11
612 /* State data */
613 typedef __u8 dvd_key[5]; /* 40-bit value, MSB is first elem. */
614 typedef __u8 dvd_challenge[10]; /* 80-bit value, MSB is first elem. */
616 struct dvd_lu_send_agid {
617 __u8 type;
618 unsigned agid : 2;
621 struct dvd_host_send_challenge {
622 __u8 type;
623 unsigned agid : 2;
625 dvd_challenge chal;
628 struct dvd_send_key {
629 __u8 type;
630 unsigned agid : 2;
632 dvd_key key;
635 struct dvd_lu_send_challenge {
636 __u8 type;
637 unsigned agid : 2;
639 dvd_challenge chal;
642 #define DVD_CPM_NO_COPYRIGHT 0
643 #define DVD_CPM_COPYRIGHTED 1
645 #define DVD_CP_SEC_NONE 0
646 #define DVD_CP_SEC_EXIST 1
648 #define DVD_CGMS_UNRESTRICTED 0
649 #define DVD_CGMS_SINGLE 2
650 #define DVD_CGMS_RESTRICTED 3
652 struct dvd_lu_send_title_key {
653 __u8 type;
654 unsigned agid : 2;
656 dvd_key title_key;
657 int lba;
658 unsigned cpm : 1;
659 unsigned cp_sec : 1;
660 unsigned cgms : 2;
663 struct dvd_lu_send_asf {
664 __u8 type;
665 unsigned agid : 2;
667 unsigned asf : 1;
670 struct dvd_host_send_rpcstate {
671 __u8 type;
672 __u8 pdrc;
675 struct dvd_lu_send_rpcstate {
676 __u8 type : 2;
677 __u8 vra : 3;
678 __u8 ucca : 3;
679 __u8 region_mask;
680 __u8 rpc_scheme;
683 typedef union {
684 __u8 type;
686 struct dvd_lu_send_agid lsa;
687 struct dvd_host_send_challenge hsc;
688 struct dvd_send_key lsk;
689 struct dvd_lu_send_challenge lsc;
690 struct dvd_send_key hsk;
691 struct dvd_lu_send_title_key lstk;
692 struct dvd_lu_send_asf lsasf;
693 struct dvd_host_send_rpcstate hrpcs;
694 struct dvd_lu_send_rpcstate lrpcs;
695 } dvd_authinfo;
697 struct request_sense {
698 #if defined(__BIG_ENDIAN_BITFIELD)
699 __u8 valid : 1;
700 __u8 error_code : 7;
701 #elif defined(__LITTLE_ENDIAN_BITFIELD)
702 __u8 error_code : 7;
703 __u8 valid : 1;
704 #endif
705 __u8 segment_number;
706 #if defined(__BIG_ENDIAN_BITFIELD)
707 __u8 reserved1 : 2;
708 __u8 ili : 1;
709 __u8 reserved2 : 1;
710 __u8 sense_key : 4;
711 #elif defined(__LITTLE_ENDIAN_BITFIELD)
712 __u8 sense_key : 4;
713 __u8 reserved2 : 1;
714 __u8 ili : 1;
715 __u8 reserved1 : 2;
716 #endif
717 __u8 information[4];
718 __u8 add_sense_len;
719 __u8 command_info[4];
720 __u8 asc;
721 __u8 ascq;
722 __u8 fruc;
723 __u8 sks[3];
724 __u8 asb[46];
728 * feature profile
730 #define CDF_RWRT 0x0020 /* "Random Writable" */
731 #define CDF_HWDM 0x0024 /* "Hardware Defect Management" */
732 #define CDF_MRW 0x0028
735 * media status bits
737 #define CDM_MRW_NOTMRW 0
738 #define CDM_MRW_BGFORMAT_INACTIVE 1
739 #define CDM_MRW_BGFORMAT_ACTIVE 2
740 #define CDM_MRW_BGFORMAT_COMPLETE 3
743 * mrw address spaces
745 #define MRW_LBA_DMA 0
746 #define MRW_LBA_GAA 1
749 * mrw mode pages (first is deprecated) -- probed at init time and
750 * cdi->mrw_mode_page is set
752 #define MRW_MODE_PC_PRE1 0x2c
753 #define MRW_MODE_PC 0x03
755 struct mrw_feature_desc {
756 __be16 feature_code;
757 #if defined(__BIG_ENDIAN_BITFIELD)
758 __u8 reserved1 : 2;
759 __u8 feature_version : 4;
760 __u8 persistent : 1;
761 __u8 curr : 1;
762 #elif defined(__LITTLE_ENDIAN_BITFIELD)
763 __u8 curr : 1;
764 __u8 persistent : 1;
765 __u8 feature_version : 4;
766 __u8 reserved1 : 2;
767 #endif
768 __u8 add_len;
769 #if defined(__BIG_ENDIAN_BITFIELD)
770 __u8 reserved2 : 7;
771 __u8 write : 1;
772 #elif defined(__LITTLE_ENDIAN_BITFIELD)
773 __u8 write : 1;
774 __u8 reserved2 : 7;
775 #endif
776 __u8 reserved3;
777 __u8 reserved4;
778 __u8 reserved5;
781 /* cf. mmc4r02g.pdf 5.3.10 Random Writable Feature (0020h) pg 197 of 635 */
782 struct rwrt_feature_desc {
783 __be16 feature_code;
784 #if defined(__BIG_ENDIAN_BITFIELD)
785 __u8 reserved1 : 2;
786 __u8 feature_version : 4;
787 __u8 persistent : 1;
788 __u8 curr : 1;
789 #elif defined(__LITTLE_ENDIAN_BITFIELD)
790 __u8 curr : 1;
791 __u8 persistent : 1;
792 __u8 feature_version : 4;
793 __u8 reserved1 : 2;
794 #endif
795 __u8 add_len;
796 __u32 last_lba;
797 __u32 block_size;
798 __u16 blocking;
799 #if defined(__BIG_ENDIAN_BITFIELD)
800 __u8 reserved2 : 7;
801 __u8 page_present : 1;
802 #elif defined(__LITTLE_ENDIAN_BITFIELD)
803 __u8 page_present : 1;
804 __u8 reserved2 : 7;
805 #endif
806 __u8 reserved3;
809 typedef struct {
810 __be16 disc_information_length;
811 #if defined(__BIG_ENDIAN_BITFIELD)
812 __u8 reserved1 : 3;
813 __u8 erasable : 1;
814 __u8 border_status : 2;
815 __u8 disc_status : 2;
816 #elif defined(__LITTLE_ENDIAN_BITFIELD)
817 __u8 disc_status : 2;
818 __u8 border_status : 2;
819 __u8 erasable : 1;
820 __u8 reserved1 : 3;
821 #else
822 #error "Please fix <asm/byteorder.h>"
823 #endif
824 __u8 n_first_track;
825 __u8 n_sessions_lsb;
826 __u8 first_track_lsb;
827 __u8 last_track_lsb;
828 #if defined(__BIG_ENDIAN_BITFIELD)
829 __u8 did_v : 1;
830 __u8 dbc_v : 1;
831 __u8 uru : 1;
832 __u8 reserved2 : 2;
833 __u8 dbit : 1;
834 __u8 mrw_status : 2;
835 #elif defined(__LITTLE_ENDIAN_BITFIELD)
836 __u8 mrw_status : 2;
837 __u8 dbit : 1;
838 __u8 reserved2 : 2;
839 __u8 uru : 1;
840 __u8 dbc_v : 1;
841 __u8 did_v : 1;
842 #endif
843 __u8 disc_type;
844 __u8 n_sessions_msb;
845 __u8 first_track_msb;
846 __u8 last_track_msb;
847 __u32 disc_id;
848 __u32 lead_in;
849 __u32 lead_out;
850 __u8 disc_bar_code[8];
851 __u8 reserved3;
852 __u8 n_opc;
853 } disc_information;
855 typedef struct {
856 __be16 track_information_length;
857 __u8 track_lsb;
858 __u8 session_lsb;
859 __u8 reserved1;
860 #if defined(__BIG_ENDIAN_BITFIELD)
861 __u8 reserved2 : 2;
862 __u8 damage : 1;
863 __u8 copy : 1;
864 __u8 track_mode : 4;
865 __u8 rt : 1;
866 __u8 blank : 1;
867 __u8 packet : 1;
868 __u8 fp : 1;
869 __u8 data_mode : 4;
870 __u8 reserved3 : 6;
871 __u8 lra_v : 1;
872 __u8 nwa_v : 1;
873 #elif defined(__LITTLE_ENDIAN_BITFIELD)
874 __u8 track_mode : 4;
875 __u8 copy : 1;
876 __u8 damage : 1;
877 __u8 reserved2 : 2;
878 __u8 data_mode : 4;
879 __u8 fp : 1;
880 __u8 packet : 1;
881 __u8 blank : 1;
882 __u8 rt : 1;
883 __u8 nwa_v : 1;
884 __u8 lra_v : 1;
885 __u8 reserved3 : 6;
886 #endif
887 __be32 track_start;
888 __be32 next_writable;
889 __be32 free_blocks;
890 __be32 fixed_packet_size;
891 __be32 track_size;
892 __be32 last_rec_address;
893 } track_information;
895 struct feature_header {
896 __u32 data_len;
897 __u8 reserved1;
898 __u8 reserved2;
899 __u16 curr_profile;
902 struct mode_page_header {
903 __be16 mode_data_length;
904 __u8 medium_type;
905 __u8 reserved1;
906 __u8 reserved2;
907 __u8 reserved3;
908 __be16 desc_length;
911 #ifdef __KERNEL__
912 #include <linux/fs.h> /* not really needed, later.. */
913 #include <linux/device.h>
914 #include <linux/list.h>
916 struct packet_command
918 unsigned char cmd[CDROM_PACKET_SIZE];
919 unsigned char *buffer;
920 unsigned int buflen;
921 int stat;
922 struct request_sense *sense;
923 unsigned char data_direction;
924 int quiet;
925 int timeout;
926 void *reserved[1];
930 * _OLD will use PIO transfer on atapi devices, _BPC_* will use DMA
932 #define CDDA_OLD 0 /* old style */
933 #define CDDA_BPC_SINGLE 1 /* single frame block pc */
934 #define CDDA_BPC_FULL 2 /* multi frame block pc */
936 /* Uniform cdrom data structures for cdrom.c */
937 struct cdrom_device_info {
938 struct cdrom_device_ops *ops; /* link to device_ops */
939 struct list_head list; /* linked list of all device_info */
940 struct gendisk *disk; /* matching block layer disk */
941 void *handle; /* driver-dependent data */
942 /* specifications */
943 int mask; /* mask of capability: disables them */
944 int speed; /* maximum speed for reading data */
945 int capacity; /* number of discs in jukebox */
946 /* device-related storage */
947 unsigned int options : 30; /* options flags */
948 unsigned mc_flags : 2; /* media change buffer flags */
949 int use_count; /* number of times device opened */
950 char name[20]; /* name of the device type */
951 /* per-device flags */
952 __u8 sanyo_slot : 2; /* Sanyo 3 CD changer support */
953 __u8 reserved : 6; /* not used yet */
954 int cdda_method; /* see flags */
955 __u8 last_sense;
956 __u8 media_written; /* dirty flag, DVD+RW bookkeeping */
957 unsigned short mmc3_profile; /* current MMC3 profile */
958 int for_data;
959 int (*exit)(struct cdrom_device_info *);
960 int mrw_mode_page;
963 struct cdrom_device_ops {
964 /* routines */
965 int (*open) (struct cdrom_device_info *, int);
966 void (*release) (struct cdrom_device_info *);
967 int (*drive_status) (struct cdrom_device_info *, int);
968 int (*media_changed) (struct cdrom_device_info *, int);
969 int (*tray_move) (struct cdrom_device_info *, int);
970 int (*lock_door) (struct cdrom_device_info *, int);
971 int (*select_speed) (struct cdrom_device_info *, int);
972 int (*select_disc) (struct cdrom_device_info *, int);
973 int (*get_last_session) (struct cdrom_device_info *,
974 struct cdrom_multisession *);
975 int (*get_mcn) (struct cdrom_device_info *,
976 struct cdrom_mcn *);
977 /* hard reset device */
978 int (*reset) (struct cdrom_device_info *);
979 /* play stuff */
980 int (*audio_ioctl) (struct cdrom_device_info *,unsigned int, void *);
982 /* driver specifications */
983 const int capability; /* capability flags */
984 int n_minors; /* number of active minor devices */
985 /* handle uniform packets for scsi type devices (scsi,atapi) */
986 int (*generic_packet) (struct cdrom_device_info *,
987 struct packet_command *);
990 /* the general block_device operations structure: */
991 extern int cdrom_open(struct cdrom_device_info *cdi, struct block_device *bdev,
992 fmode_t mode);
993 extern void cdrom_release(struct cdrom_device_info *cdi, fmode_t mode);
994 extern int cdrom_ioctl(struct cdrom_device_info *cdi, struct block_device *bdev,
995 fmode_t mode, unsigned int cmd, unsigned long arg);
996 extern int cdrom_media_changed(struct cdrom_device_info *);
998 extern int register_cdrom(struct cdrom_device_info *cdi);
999 extern void unregister_cdrom(struct cdrom_device_info *cdi);
1001 typedef struct {
1002 int data;
1003 int audio;
1004 int cdi;
1005 int xa;
1006 long error;
1007 } tracktype;
1009 extern int cdrom_get_last_written(struct cdrom_device_info *cdi, long *last_written);
1010 extern int cdrom_number_of_slots(struct cdrom_device_info *cdi);
1011 extern int cdrom_mode_select(struct cdrom_device_info *cdi,
1012 struct packet_command *cgc);
1013 extern int cdrom_mode_sense(struct cdrom_device_info *cdi,
1014 struct packet_command *cgc,
1015 int page_code, int page_control);
1016 extern void init_cdrom_command(struct packet_command *cgc,
1017 void *buffer, int len, int type);
1019 /* The SCSI spec says there could be 256 slots. */
1020 #define CDROM_MAX_SLOTS 256
1022 struct cdrom_mechstat_header {
1023 #if defined(__BIG_ENDIAN_BITFIELD)
1024 __u8 fault : 1;
1025 __u8 changer_state : 2;
1026 __u8 curslot : 5;
1027 __u8 mech_state : 3;
1028 __u8 door_open : 1;
1029 __u8 reserved1 : 4;
1030 #elif defined(__LITTLE_ENDIAN_BITFIELD)
1031 __u8 curslot : 5;
1032 __u8 changer_state : 2;
1033 __u8 fault : 1;
1034 __u8 reserved1 : 4;
1035 __u8 door_open : 1;
1036 __u8 mech_state : 3;
1037 #endif
1038 __u8 curlba[3];
1039 __u8 nslots;
1040 __u16 slot_tablelen;
1043 struct cdrom_slot {
1044 #if defined(__BIG_ENDIAN_BITFIELD)
1045 __u8 disc_present : 1;
1046 __u8 reserved1 : 6;
1047 __u8 change : 1;
1048 #elif defined(__LITTLE_ENDIAN_BITFIELD)
1049 __u8 change : 1;
1050 __u8 reserved1 : 6;
1051 __u8 disc_present : 1;
1052 #endif
1053 __u8 reserved2[3];
1056 struct cdrom_changer_info {
1057 struct cdrom_mechstat_header hdr;
1058 struct cdrom_slot slots[CDROM_MAX_SLOTS];
1061 typedef enum {
1062 mechtype_caddy = 0,
1063 mechtype_tray = 1,
1064 mechtype_popup = 2,
1065 mechtype_individual_changer = 4,
1066 mechtype_cartridge_changer = 5
1067 } mechtype_t;
1069 typedef struct {
1070 #if defined(__BIG_ENDIAN_BITFIELD)
1071 __u8 ps : 1;
1072 __u8 reserved1 : 1;
1073 __u8 page_code : 6;
1074 __u8 page_length;
1075 __u8 reserved2 : 1;
1076 __u8 bufe : 1;
1077 __u8 ls_v : 1;
1078 __u8 test_write : 1;
1079 __u8 write_type : 4;
1080 __u8 multi_session : 2; /* or border, DVD */
1081 __u8 fp : 1;
1082 __u8 copy : 1;
1083 __u8 track_mode : 4;
1084 __u8 reserved3 : 4;
1085 __u8 data_block_type : 4;
1086 #elif defined(__LITTLE_ENDIAN_BITFIELD)
1087 __u8 page_code : 6;
1088 __u8 reserved1 : 1;
1089 __u8 ps : 1;
1090 __u8 page_length;
1091 __u8 write_type : 4;
1092 __u8 test_write : 1;
1093 __u8 ls_v : 1;
1094 __u8 bufe : 1;
1095 __u8 reserved2 : 1;
1096 __u8 track_mode : 4;
1097 __u8 copy : 1;
1098 __u8 fp : 1;
1099 __u8 multi_session : 2; /* or border, DVD */
1100 __u8 data_block_type : 4;
1101 __u8 reserved3 : 4;
1102 #endif
1103 __u8 link_size;
1104 __u8 reserved4;
1105 #if defined(__BIG_ENDIAN_BITFIELD)
1106 __u8 reserved5 : 2;
1107 __u8 app_code : 6;
1108 #elif defined(__LITTLE_ENDIAN_BITFIELD)
1109 __u8 app_code : 6;
1110 __u8 reserved5 : 2;
1111 #endif
1112 __u8 session_format;
1113 __u8 reserved6;
1114 __be32 packet_size;
1115 __u16 audio_pause;
1116 __u8 mcn[16];
1117 __u8 isrc[16];
1118 __u8 subhdr0;
1119 __u8 subhdr1;
1120 __u8 subhdr2;
1121 __u8 subhdr3;
1122 } __attribute__((packed)) write_param_page;
1124 struct modesel_head
1126 __u8 reserved1;
1127 __u8 medium;
1128 __u8 reserved2;
1129 __u8 block_desc_length;
1130 __u8 density;
1131 __u8 number_of_blocks_hi;
1132 __u8 number_of_blocks_med;
1133 __u8 number_of_blocks_lo;
1134 __u8 reserved3;
1135 __u8 block_length_hi;
1136 __u8 block_length_med;
1137 __u8 block_length_lo;
1140 typedef struct {
1141 __u16 report_key_length;
1142 __u8 reserved1;
1143 __u8 reserved2;
1144 #if defined(__BIG_ENDIAN_BITFIELD)
1145 __u8 type_code : 2;
1146 __u8 vra : 3;
1147 __u8 ucca : 3;
1148 #elif defined(__LITTLE_ENDIAN_BITFIELD)
1149 __u8 ucca : 3;
1150 __u8 vra : 3;
1151 __u8 type_code : 2;
1152 #endif
1153 __u8 region_mask;
1154 __u8 rpc_scheme;
1155 __u8 reserved3;
1156 } rpc_state_t;
1158 struct event_header {
1159 __be16 data_len;
1160 #if defined(__BIG_ENDIAN_BITFIELD)
1161 __u8 nea : 1;
1162 __u8 reserved1 : 4;
1163 __u8 notification_class : 3;
1164 #elif defined(__LITTLE_ENDIAN_BITFIELD)
1165 __u8 notification_class : 3;
1166 __u8 reserved1 : 4;
1167 __u8 nea : 1;
1168 #endif
1169 __u8 supp_event_class;
1172 struct media_event_desc {
1173 #if defined(__BIG_ENDIAN_BITFIELD)
1174 __u8 reserved1 : 4;
1175 __u8 media_event_code : 4;
1176 __u8 reserved2 : 6;
1177 __u8 media_present : 1;
1178 __u8 door_open : 1;
1179 #elif defined(__LITTLE_ENDIAN_BITFIELD)
1180 __u8 media_event_code : 4;
1181 __u8 reserved1 : 4;
1182 __u8 door_open : 1;
1183 __u8 media_present : 1;
1184 __u8 reserved2 : 6;
1185 #endif
1186 __u8 start_slot;
1187 __u8 end_slot;
1190 extern int cdrom_get_media_event(struct cdrom_device_info *cdi, struct media_event_desc *med);
1192 static inline void lba_to_msf(int lba, u8 *m, u8 *s, u8 *f)
1194 lba += CD_MSF_OFFSET;
1195 lba &= 0xffffff; /* negative lbas use only 24 bits */
1196 *m = lba / (CD_SECS * CD_FRAMES);
1197 lba %= (CD_SECS * CD_FRAMES);
1198 *s = lba / CD_FRAMES;
1199 *f = lba % CD_FRAMES;
1202 static inline int msf_to_lba(u8 m, u8 s, u8 f)
1204 return (((m * CD_SECS) + s) * CD_FRAMES + f) - CD_MSF_OFFSET;
1206 #endif /* End of kernel only stuff */
1208 #endif /* _LINUX_CDROM_H */