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
10 #ifndef _LINUX_CDROM_H
11 #define _LINUX_CDROM_H
13 #include <linux/fs.h> /* not really needed, later.. */
14 #include <linux/list.h>
15 #include <uapi/linux/cdrom.h>
19 unsigned char cmd
[CDROM_PACKET_SIZE
];
20 unsigned char *buffer
;
23 struct request_sense
*sense
;
24 unsigned char data_direction
;
31 * _OLD will use PIO transfer on atapi devices, _BPC_* will use DMA
33 #define CDDA_OLD 0 /* old style */
34 #define CDDA_BPC_SINGLE 1 /* single frame block pc */
35 #define CDDA_BPC_FULL 2 /* multi frame block pc */
37 /* Uniform cdrom data structures for cdrom.c */
38 struct cdrom_device_info
{
39 struct cdrom_device_ops
*ops
; /* link to device_ops */
40 struct list_head list
; /* linked list of all device_info */
41 struct gendisk
*disk
; /* matching block layer disk */
42 void *handle
; /* driver-dependent data */
44 int mask
; /* mask of capability: disables them */
45 int speed
; /* maximum speed for reading data */
46 int capacity
; /* number of discs in jukebox */
47 /* device-related storage */
48 unsigned int options
: 30; /* options flags */
49 unsigned mc_flags
: 2; /* media change buffer flags */
50 unsigned int vfs_events
; /* cached events for vfs path */
51 unsigned int ioctl_events
; /* cached events for ioctl path */
52 int use_count
; /* number of times device opened */
53 char name
[20]; /* name of the device type */
54 /* per-device flags */
55 __u8 sanyo_slot
: 2; /* Sanyo 3 CD changer support */
56 __u8 keeplocked
: 1; /* CDROM_LOCKDOOR status */
57 __u8 reserved
: 5; /* not used yet */
58 int cdda_method
; /* see flags */
60 __u8 media_written
; /* dirty flag, DVD+RW bookkeeping */
61 unsigned short mmc3_profile
; /* current MMC3 profile */
63 int (*exit
)(struct cdrom_device_info
*);
67 struct cdrom_device_ops
{
69 int (*open
) (struct cdrom_device_info
*, int);
70 void (*release
) (struct cdrom_device_info
*);
71 int (*drive_status
) (struct cdrom_device_info
*, int);
72 unsigned int (*check_events
) (struct cdrom_device_info
*cdi
,
73 unsigned int clearing
, int slot
);
74 int (*media_changed
) (struct cdrom_device_info
*, int);
75 int (*tray_move
) (struct cdrom_device_info
*, int);
76 int (*lock_door
) (struct cdrom_device_info
*, int);
77 int (*select_speed
) (struct cdrom_device_info
*, int);
78 int (*select_disc
) (struct cdrom_device_info
*, int);
79 int (*get_last_session
) (struct cdrom_device_info
*,
80 struct cdrom_multisession
*);
81 int (*get_mcn
) (struct cdrom_device_info
*,
83 /* hard reset device */
84 int (*reset
) (struct cdrom_device_info
*);
86 int (*audio_ioctl
) (struct cdrom_device_info
*,unsigned int, void *);
88 /* driver specifications */
89 const int capability
; /* capability flags */
90 int n_minors
; /* number of active minor devices */
91 /* handle uniform packets for scsi type devices (scsi,atapi) */
92 int (*generic_packet
) (struct cdrom_device_info
*,
93 struct packet_command
*);
96 /* the general block_device operations structure: */
97 extern int cdrom_open(struct cdrom_device_info
*cdi
, struct block_device
*bdev
,
99 extern void cdrom_release(struct cdrom_device_info
*cdi
, fmode_t mode
);
100 extern int cdrom_ioctl(struct cdrom_device_info
*cdi
, struct block_device
*bdev
,
101 fmode_t mode
, unsigned int cmd
, unsigned long arg
);
102 extern unsigned int cdrom_check_events(struct cdrom_device_info
*cdi
,
103 unsigned int clearing
);
104 extern int cdrom_media_changed(struct cdrom_device_info
*);
106 extern int register_cdrom(struct cdrom_device_info
*cdi
);
107 extern void unregister_cdrom(struct cdrom_device_info
*cdi
);
117 extern int cdrom_get_last_written(struct cdrom_device_info
*cdi
, long *last_written
);
118 extern int cdrom_number_of_slots(struct cdrom_device_info
*cdi
);
119 extern int cdrom_mode_select(struct cdrom_device_info
*cdi
,
120 struct packet_command
*cgc
);
121 extern int cdrom_mode_sense(struct cdrom_device_info
*cdi
,
122 struct packet_command
*cgc
,
123 int page_code
, int page_control
);
124 extern void init_cdrom_command(struct packet_command
*cgc
,
125 void *buffer
, int len
, int type
);
127 /* The SCSI spec says there could be 256 slots. */
128 #define CDROM_MAX_SLOTS 256
130 struct cdrom_mechstat_header
{
131 #if defined(__BIG_ENDIAN_BITFIELD)
133 __u8 changer_state
: 2;
138 #elif defined(__LITTLE_ENDIAN_BITFIELD)
140 __u8 changer_state
: 2;
152 #if defined(__BIG_ENDIAN_BITFIELD)
153 __u8 disc_present
: 1;
156 #elif defined(__LITTLE_ENDIAN_BITFIELD)
159 __u8 disc_present
: 1;
164 struct cdrom_changer_info
{
165 struct cdrom_mechstat_header hdr
;
166 struct cdrom_slot slots
[CDROM_MAX_SLOTS
];
173 mechtype_individual_changer
= 4,
174 mechtype_cartridge_changer
= 5
178 #if defined(__BIG_ENDIAN_BITFIELD)
188 __u8 multi_session
: 2; /* or border, DVD */
193 __u8 data_block_type
: 4;
194 #elif defined(__LITTLE_ENDIAN_BITFIELD)
207 __u8 multi_session
: 2; /* or border, DVD */
208 __u8 data_block_type
: 4;
213 #if defined(__BIG_ENDIAN_BITFIELD)
216 #elif defined(__LITTLE_ENDIAN_BITFIELD)
230 } __attribute__((packed
)) write_param_page
;
237 __u8 block_desc_length
;
239 __u8 number_of_blocks_hi
;
240 __u8 number_of_blocks_med
;
241 __u8 number_of_blocks_lo
;
243 __u8 block_length_hi
;
244 __u8 block_length_med
;
245 __u8 block_length_lo
;
249 __u16 report_key_length
;
252 #if defined(__BIG_ENDIAN_BITFIELD)
256 #elif defined(__LITTLE_ENDIAN_BITFIELD)
266 struct event_header
{
268 #if defined(__BIG_ENDIAN_BITFIELD)
271 __u8 notification_class
: 3;
272 #elif defined(__LITTLE_ENDIAN_BITFIELD)
273 __u8 notification_class
: 3;
277 __u8 supp_event_class
;
280 struct media_event_desc
{
281 #if defined(__BIG_ENDIAN_BITFIELD)
283 __u8 media_event_code
: 4;
285 __u8 media_present
: 1;
287 #elif defined(__LITTLE_ENDIAN_BITFIELD)
288 __u8 media_event_code
: 4;
291 __u8 media_present
: 1;
298 extern int cdrom_get_media_event(struct cdrom_device_info
*cdi
, struct media_event_desc
*med
);
300 static inline void lba_to_msf(int lba
, u8
*m
, u8
*s
, u8
*f
)
302 lba
+= CD_MSF_OFFSET
;
303 lba
&= 0xffffff; /* negative lbas use only 24 bits */
304 *m
= lba
/ (CD_SECS
* CD_FRAMES
);
305 lba
%= (CD_SECS
* CD_FRAMES
);
306 *s
= lba
/ CD_FRAMES
;
307 *f
= lba
% CD_FRAMES
;
310 static inline int msf_to_lba(u8 m
, u8 s
, u8 f
)
312 return (((m
* CD_SECS
) + s
) * CD_FRAMES
+ f
) - CD_MSF_OFFSET
;
314 #endif /* _LINUX_CDROM_H */