Import 2.3.6
[davej-history.git] / include / linux / cdrom.h
bloba8c028fb39557f990bc727bf68eae196bb25c05e
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 Moenkeberg, emoenke@gwdg.de
6 * 1996 David van Leeuwen, david@tm.tno.nl
7 * 1997, 1998 Erik Andersen, andersee@debian.org
8 * 1998, 1999 Jens Axboe, axboe@image.dk
9 */
11 #ifndef _LINUX_CDROM_H
12 #define _LINUX_CDROM_H
14 /*******************************************************
15 * As of Linux 2.1.x, all Linux CD-ROM application programs will use this
16 * (and only this) include file. It is my hope to provide Linux with
17 * a uniform interface between software accessing CD-ROMs and the various
18 * device drivers that actually talk to the drives. There may still be
19 * 23 different kinds of strange CD-ROM drives, but at least there will
20 * now be one, and only one, Linux CD-ROM interface.
22 * Additionally, as of Linux 2.1.x, all Linux application programs
23 * should use the O_NONBLOCK option when opening a CD-ROM device
24 * for subsequent ioctl commands. This allows for neat system errors
25 * like "No medium found" or "Wrong medium type" upon attempting to
26 * mount or play an empty slot, mount an audio disc, or play a data disc.
27 * Generally, changing an application program to support O_NONBLOCK
28 * is as easy as the following:
29 * - drive = open("/dev/cdrom", O_RDONLY);
30 * + drive = open("/dev/cdrom", O_RDONLY | O_NONBLOCK);
31 * It is worth the small change.
33 * Patches for many common CD programs (provided by David A. van Leeuwen)
34 * can be found at: ftp://ftp.gwdg.de/pub/linux/cdrom/drivers/cm206/
36 *******************************************************/
38 /* When a driver supports a certain function, but the cdrom drive we are
39 * using doesn't, we will return the error EDRIVE_CANT_DO_THIS. We will
40 * borrow the "Operation not supported" error from the network folks to
41 * accomplish this. Maybe someday we will get a more targeted error code,
42 * but this will do for now... */
43 #define EDRIVE_CANT_DO_THIS EOPNOTSUPP
45 /*******************************************************
46 * The CD-ROM IOCTL commands -- these should be supported by
47 * all the various cdrom drivers. For the CD-ROM ioctls, we
48 * will commandeer byte 0x53, or 'S'.
49 *******************************************************/
50 #define CDROMPAUSE 0x5301 /* Pause Audio Operation */
51 #define CDROMRESUME 0x5302 /* Resume paused Audio Operation */
52 #define CDROMPLAYMSF 0x5303 /* Play Audio MSF (struct cdrom_msf) */
53 #define CDROMPLAYTRKIND 0x5304 /* Play Audio Track/index
54 (struct cdrom_ti) */
55 #define CDROMREADTOCHDR 0x5305 /* Read TOC header
56 (struct cdrom_tochdr) */
57 #define CDROMREADTOCENTRY 0x5306 /* Read TOC entry
58 (struct cdrom_tocentry) */
59 #define CDROMSTOP 0x5307 /* Stop the cdrom drive */
60 #define CDROMSTART 0x5308 /* Start the cdrom drive */
61 #define CDROMEJECT 0x5309 /* Ejects the cdrom media */
62 #define CDROMVOLCTRL 0x530a /* Control output volume
63 (struct cdrom_volctrl) */
64 #define CDROMSUBCHNL 0x530b /* Read subchannel data
65 (struct cdrom_subchnl) */
66 #define CDROMREADMODE2 0x530c /* Read CDROM mode 2 data (2336 Bytes)
67 (struct cdrom_read) */
68 #define CDROMREADMODE1 0x530d /* Read CDROM mode 1 data (2048 Bytes)
69 (struct cdrom_read) */
70 #define CDROMREADAUDIO 0x530e /* (struct cdrom_read_audio) */
71 #define CDROMEJECT_SW 0x530f /* enable(1)/disable(0) auto-ejecting */
72 #define CDROMMULTISESSION 0x5310 /* Obtain the start-of-last-session
73 address of multi session disks
74 (struct cdrom_multisession) */
75 #define CDROM_GET_MCN 0x5311 /* Obtain the "Universal Product Code"
76 if available (struct cdrom_mcn) */
77 #define CDROM_GET_UPC CDROM_GET_MCN /* This one is depricated,
78 but here anyway for compatability */
79 #define CDROMRESET 0x5312 /* hard-reset the drive */
80 #define CDROMVOLREAD 0x5313 /* Get the drive's volume setting
81 (struct cdrom_volctrl) */
82 #define CDROMREADRAW 0x5314 /* read data in raw mode (2352 Bytes)
83 (struct cdrom_read) */
84 /*
85 * These ioctls are used only used in aztcd.c and optcd.c
87 #define CDROMREADCOOKED 0x5315 /* read data in cooked mode */
88 #define CDROMSEEK 0x5316 /* seek msf address */
91 * This ioctl is only used by the scsi-cd driver.
92 It is for playing audio in logical block addressing mode.
94 #define CDROMPLAYBLK 0x5317 /* (struct cdrom_blk) */
96 /*
97 * These ioctls are used only used in optcd.c
99 #define CDROMREADALL 0x5318 /* read all 2646 bytes */
100 #define CDROMCLOSETRAY 0x5319 /* pendant of CDROMEJECT */
103 * These ioctls are implemented through the uniform CD-ROM driver
104 * They _will_ be adopted by all CD-ROM drivers, when all the CD-ROM
105 * drivers are eventually ported to the uniform CD-ROM driver interface.
107 #define CDROM_SET_OPTIONS 0x5320 /* Set behavior options */
108 #define CDROM_CLEAR_OPTIONS 0x5321 /* Clear behavior options */
109 #define CDROM_SELECT_SPEED 0x5322 /* Set the CD-ROM speed */
110 #define CDROM_SELECT_DISC 0x5323 /* Select disc (for juke-boxes) */
111 #define CDROM_MEDIA_CHANGED 0x5325 /* Check is media changed */
112 #define CDROM_DRIVE_STATUS 0x5326 /* Get tray position, etc. */
113 #define CDROM_DISC_STATUS 0x5327 /* Get disc type, etc. */
114 #define CDROM_CHANGER_NSLOTS 0x5328 /* Get number of slots */
115 #define CDROM_LOCKDOOR 0x5329 /* lock or unlock door */
116 #define CDROM_DEBUG 0x5330 /* Turn debug messages on/off */
117 #define CDROM_GET_CAPABILITY 0x5331 /* get capabilities */
119 /* This ioctl is only used by sbpcd at the moment */
120 #define CDROMAUDIOBUFSIZ 0x5382 /* set the audio buffer size */
122 /*******************************************************
123 * CDROM IOCTL structures
124 *******************************************************/
126 /* Address in MSF format */
127 struct cdrom_msf0
129 u_char minute;
130 u_char second;
131 u_char frame;
134 /* Address in either MSF or logical format */
135 union cdrom_addr
137 struct cdrom_msf0 msf;
138 int lba;
141 /* This struct is used by the CDROMPLAYMSF ioctl */
142 struct cdrom_msf
144 u_char cdmsf_min0; /* start minute */
145 u_char cdmsf_sec0; /* start second */
146 u_char cdmsf_frame0; /* start frame */
147 u_char cdmsf_min1; /* end minute */
148 u_char cdmsf_sec1; /* end second */
149 u_char cdmsf_frame1; /* end frame */
152 /* This struct is used by the CDROMPLAYTRKIND ioctl */
153 struct cdrom_ti
155 u_char cdti_trk0; /* start track */
156 u_char cdti_ind0; /* start index */
157 u_char cdti_trk1; /* end track */
158 u_char cdti_ind1; /* end index */
161 /* This struct is used by the CDROMREADTOCHDR ioctl */
162 struct cdrom_tochdr
164 u_char cdth_trk0; /* start track */
165 u_char cdth_trk1; /* end track */
168 /* This struct is used by the CDROMVOLCTRL and CDROMVOLREAD ioctls */
169 struct cdrom_volctrl
171 u_char channel0;
172 u_char channel1;
173 u_char channel2;
174 u_char channel3;
177 /* This struct is used by the CDROMSUBCHNL ioctl */
178 struct cdrom_subchnl
180 u_char cdsc_format;
181 u_char cdsc_audiostatus;
182 u_char cdsc_adr: 4;
183 u_char cdsc_ctrl: 4;
184 u_char cdsc_trk;
185 u_char cdsc_ind;
186 union cdrom_addr cdsc_absaddr;
187 union cdrom_addr cdsc_reladdr;
191 /* This struct is used by the CDROMREADTOCENTRY ioctl */
192 struct cdrom_tocentry
194 u_char cdte_track;
195 u_char cdte_adr :4;
196 u_char cdte_ctrl :4;
197 u_char cdte_format;
198 union cdrom_addr cdte_addr;
199 u_char cdte_datamode;
202 /* This struct is used by the CDROMREADMODE1, and CDROMREADMODE2 ioctls */
203 struct cdrom_read
205 int cdread_lba;
206 caddr_t cdread_bufaddr;
207 int cdread_buflen;
210 /* This struct is used by the CDROMREADAUDIO ioctl */
211 struct cdrom_read_audio
213 union cdrom_addr addr; /* frame address */
214 u_char addr_format; /* CDROM_LBA or CDROM_MSF */
215 int nframes; /* number of 2352-byte-frames to read at once */
216 u_char *buf; /* frame buffer (size: nframes*2352 bytes) */
219 /* This struct is used with the CDROMMULTISESSION ioctl */
220 struct cdrom_multisession
222 union cdrom_addr addr; /* frame address: start-of-last-session
223 (not the new "frame 16"!). Only valid
224 if the "xa_flag" is true. */
225 u_char xa_flag; /* 1: "is XA disk" */
226 u_char addr_format; /* CDROM_LBA or CDROM_MSF */
229 /* This struct is used with the CDROM_GET_MCN ioctl.
230 * Very few audio discs actually have Universal Product Code information,
231 * which should just be the Medium Catalog Number on the box. Also note
232 * that the way the codeis written on CD is _not_ uniform across all discs!
234 struct cdrom_mcn
236 u_char medium_catalog_number[14]; /* 13 ASCII digits, null-terminated */
239 /* This is used by the CDROMPLAYBLK ioctl */
240 struct cdrom_blk
242 unsigned from;
243 unsigned short len;
248 * A CD-ROM physical sector size is 2048, 2052, 2056, 2324, 2332, 2336,
249 * 2340, or 2352 bytes long.
251 * Sector types of the standard CD-ROM data formats:
253 * format sector type user data size (bytes)
254 * -----------------------------------------------------------------------------
255 * 1 (Red Book) CD-DA 2352 (CD_FRAMESIZE_RAW)
256 * 2 (Yellow Book) Mode1 Form1 2048 (CD_FRAMESIZE)
257 * 3 (Yellow Book) Mode1 Form2 2336 (CD_FRAMESIZE_RAW0)
258 * 4 (Green Book) Mode2 Form1 2048 (CD_FRAMESIZE)
259 * 5 (Green Book) Mode2 Form2 2328 (2324+4 spare bytes)
262 * The layout of the standard CD-ROM data formats:
263 * -----------------------------------------------------------------------------
264 * - audio (red): | audio_sample_bytes |
265 * | 2352 |
267 * - data (yellow, mode1): | sync - head - data - EDC - zero - ECC |
268 * | 12 - 4 - 2048 - 4 - 8 - 276 |
270 * - data (yellow, mode2): | sync - head - data |
271 * | 12 - 4 - 2336 |
273 * - XA data (green, mode2 form1): | sync - head - sub - data - EDC - ECC |
274 * | 12 - 4 - 8 - 2048 - 4 - 276 |
276 * - XA data (green, mode2 form2): | sync - head - sub - data - Spare |
277 * | 12 - 4 - 8 - 2324 - 4 |
281 /* Some generally useful CD-ROM information -- mostly based on the above */
282 #define CD_MINS 74 /* max. minutes per CD, not really a limit */
283 #define CD_SECS 60 /* seconds per minute */
284 #define CD_FRAMES 75 /* frames per second */
285 #define CD_SYNC_SIZE 12 /* 12 sync bytes per raw data frame */
286 #define CD_MSF_OFFSET 150 /* MSF numbering offset of first frame */
287 #define CD_CHUNK_SIZE 24 /* lowest-level "data bytes piece" */
288 #define CD_NUM_OF_CHUNKS 98 /* chunks per frame */
289 #define CD_FRAMESIZE_SUB 96 /* subchannel data "frame" size */
290 #define CD_HEAD_SIZE 4 /* header (address) bytes per raw data frame */
291 #define CD_SUBHEAD_SIZE 8 /* subheader bytes per raw XA data frame */
292 #define CD_EDC_SIZE 4 /* bytes EDC per most raw data frame types */
293 #define CD_ZERO_SIZE 8 /* bytes zero per yellow book mode 1 frame */
294 #define CD_ECC_SIZE 276 /* bytes ECC per most raw data frame types */
295 #define CD_FRAMESIZE 2048 /* bytes per frame, "cooked" mode */
296 #define CD_FRAMESIZE_RAW 2352 /* bytes per frame, "raw" mode */
297 #define CD_FRAMESIZE_RAWER 2646 /* The maximum possible returned bytes */
298 /* most drives don't deliver everything: */
299 #define CD_FRAMESIZE_RAW1 (CD_FRAMESIZE_RAW-CD_SYNC_SIZE) /*2340*/
300 #define CD_FRAMESIZE_RAW0 (CD_FRAMESIZE_RAW-CD_SYNC_SIZE-CD_HEAD_SIZE) /*2336*/
302 #define CD_XA_HEAD (CD_HEAD_SIZE+CD_SUBHEAD_SIZE) /* "before data" part of raw XA frame */
303 #define CD_XA_TAIL (CD_EDC_SIZE+CD_ECC_SIZE) /* "after data" part of raw XA frame */
304 #define CD_XA_SYNC_HEAD (CD_SYNC_SIZE+CD_XA_HEAD) /* sync bytes + header of XA frame */
306 /* CD-ROM address types (cdrom_tocentry.cdte_format) */
307 #define CDROM_LBA 0x01 /* "logical block": first frame is #0 */
308 #define CDROM_MSF 0x02 /* "minute-second-frame": binary, not bcd here! */
310 /* bit to tell whether track is data or audio (cdrom_tocentry.cdte_ctrl) */
311 #define CDROM_DATA_TRACK 0x04
313 /* The leadout track is always 0xAA, regardless of # of tracks on disc */
314 #define CDROM_LEADOUT 0xAA
316 /* audio states (from SCSI-2, but seen with other drives, too) */
317 #define CDROM_AUDIO_INVALID 0x00 /* audio status not supported */
318 #define CDROM_AUDIO_PLAY 0x11 /* audio play operation in progress */
319 #define CDROM_AUDIO_PAUSED 0x12 /* audio play operation paused */
320 #define CDROM_AUDIO_COMPLETED 0x13 /* audio play successfully completed */
321 #define CDROM_AUDIO_ERROR 0x14 /* audio play stopped due to error */
322 #define CDROM_AUDIO_NO_STATUS 0x15 /* no current audio status to return */
324 /* CD-ROM-specific SCSI command opcodes */
325 #define SCMD_READ_TOC 0x43 /* read table of contents */
326 #define SCMD_PLAYAUDIO_MSF 0x47 /* play data at time offset */
327 #define SCMD_PLAYAUDIO_TI 0x48 /* play data at track/index */
328 #define SCMD_PAUSE_RESUME 0x4B /* pause/resume audio */
329 #define SCMD_READ_SUBCHANNEL 0x42 /* read SC info on playing disc */
330 #define SCMD_PLAYAUDIO10 0x45 /* play data at logical block */
332 /* capability flags used with the uniform CD-ROM driver */
333 #define CDC_CLOSE_TRAY 0x1 /* caddy systems _can't_ close */
334 #define CDC_OPEN_TRAY 0x2 /* but _can_ eject. */
335 #define CDC_LOCK 0x4 /* disable manual eject */
336 #define CDC_SELECT_SPEED 0x8 /* programmable speed */
337 #define CDC_SELECT_DISC 0x10 /* select disc from juke-box */
338 #define CDC_MULTI_SESSION 0x20 /* read sessions>1 */
339 #define CDC_MCN 0x40 /* Medium Catalog Number */
340 #define CDC_MEDIA_CHANGED 0x80 /* media changed */
341 #define CDC_PLAY_AUDIO 0x100 /* audio functions */
342 #define CDC_RESET 0x200 /* hard reset device */
343 #define CDC_IOCTLS 0x400 /* driver has non-standard ioctls */
344 #define CDC_DRIVE_STATUS 0x800 /* driver implements drive status */
346 /* drive status possibilities returned by CDROM_DRIVE_STATUS ioctl */
347 #define CDS_NO_INFO 0 /* if not implemented */
348 #define CDS_NO_DISC 1
349 #define CDS_TRAY_OPEN 2
350 #define CDS_DRIVE_NOT_READY 3
351 #define CDS_DISC_OK 4
353 /* return values for the CDROM_DISC_STATUS ioctl */
354 /* can also return CDS_NO_[INFO|DISC], from above */
355 #define CDS_AUDIO 100
356 #define CDS_DATA_1 101
357 #define CDS_DATA_2 102
358 #define CDS_XA_2_1 103
359 #define CDS_XA_2_2 104
360 #define CDS_MIXED 105
362 /* User-configurable behavior options for the uniform CD-ROM driver */
363 #define CDO_AUTO_CLOSE 0x1 /* close tray on first open() */
364 #define CDO_AUTO_EJECT 0x2 /* open tray on last release() */
365 #define CDO_USE_FFLAGS 0x4 /* use O_NONBLOCK information on open */
366 #define CDO_LOCK 0x8 /* lock tray on open files */
367 #define CDO_CHECK_TYPE 0x10 /* check type on open for data */
369 /* Special codes used when specifying changer slots. */
370 #define CDSL_NONE ((int) (~0U>>1)-1)
371 #define CDSL_CURRENT ((int) (~0U>>1))
373 #ifdef __KERNEL__
374 /* Uniform cdrom data structures for cdrom.c */
375 struct cdrom_device_info {
376 struct cdrom_device_ops *ops; /* link to device_ops */
377 struct cdrom_device_info *next; /* next device_info for this major */
378 void *handle; /* driver-dependent data */
379 /* specifications */
380 kdev_t dev; /* device number */
381 int mask; /* mask of capability: disables them */
382 int speed; /* maximum speed for reading data */
383 int capacity; /* number of discs in jukebox */
384 /* device-related storage */
385 int options : 30; /* options flags */
386 unsigned mc_flags : 2; /* media change buffer flags */
387 int use_count; /* number of times device opened */
388 char name[20]; /* name of the device type */
392 struct cdrom_device_ops {
393 /* routines */
394 int (*open) (struct cdrom_device_info *, int);
395 void (*release) (struct cdrom_device_info *);
396 int (*drive_status) (struct cdrom_device_info *, int);
397 int (*media_changed) (struct cdrom_device_info *, int);
398 int (*tray_move) (struct cdrom_device_info *, int);
399 int (*lock_door) (struct cdrom_device_info *, int);
400 int (*select_speed) (struct cdrom_device_info *, int);
401 int (*select_disc) (struct cdrom_device_info *, int);
402 int (*get_last_session) (struct cdrom_device_info *,
403 struct cdrom_multisession *);
404 int (*get_mcn) (struct cdrom_device_info *,
405 struct cdrom_mcn *);
406 /* hard reset device */
407 int (*reset) (struct cdrom_device_info *);
408 /* play stuff */
409 int (*audio_ioctl) (struct cdrom_device_info *,unsigned int, void *);
410 /* dev-specific */
411 int (*dev_ioctl) (struct cdrom_device_info *,
412 unsigned int, unsigned long);
413 /* driver specifications */
414 const int capability; /* capability flags */
415 int n_minors; /* number of active minor devices */
418 /* the general file operations structure: */
419 extern struct file_operations cdrom_fops;
421 extern int register_cdrom(struct cdrom_device_info *cdi);
422 extern int unregister_cdrom(struct cdrom_device_info *cdi);
423 typedef struct {
424 int data;
425 int audio;
426 int cdi;
427 int xa;
428 long error;
429 } tracktype;
430 extern void cdrom_count_tracks(struct cdrom_device_info *cdi,tracktype* tracks);
431 #endif /* End of kernel only stuff */
433 #endif /* _LINUX_CDROM_H */