1
2
3
4
5
6
7
8
9
10
11#ifndef _LINUX_CDROM_H
12#define _LINUX_CDROM_H
13
14#include <linux/fs.h>
15#include <linux/list.h>
16#include <scsi/scsi_common.h>
17#include <uapi/linux/cdrom.h>
18
19struct packet_command
20{
21 unsigned char cmd[CDROM_PACKET_SIZE];
22 unsigned char *buffer;
23 unsigned int buflen;
24 int stat;
25 struct scsi_sense_hdr *sshdr;
26 unsigned char data_direction;
27 int quiet;
28 int timeout;
29 void *reserved[1];
30};
31
32
33
34
35#define CDDA_OLD 0
36#define CDDA_BPC_SINGLE 1
37#define CDDA_BPC_FULL 2
38
39
40struct cdrom_device_info {
41 const struct cdrom_device_ops *ops;
42 struct list_head list;
43 struct gendisk *disk;
44 void *handle;
45
46 int mask;
47 int speed;
48 int capacity;
49
50 unsigned int options : 30;
51 unsigned mc_flags : 2;
52 unsigned int vfs_events;
53 unsigned int ioctl_events;
54 int use_count;
55 char name[20];
56
57 __u8 sanyo_slot : 2;
58 __u8 keeplocked : 1;
59 __u8 reserved : 5;
60 int cdda_method;
61 __u8 last_sense;
62 __u8 media_written;
63 unsigned short mmc3_profile;
64 int for_data;
65 int (*exit)(struct cdrom_device_info *);
66 int mrw_mode_page;
67};
68
69struct cdrom_device_ops {
70
71 int (*open) (struct cdrom_device_info *, int);
72 void (*release) (struct cdrom_device_info *);
73 int (*drive_status) (struct cdrom_device_info *, int);
74 unsigned int (*check_events) (struct cdrom_device_info *cdi,
75 unsigned int clearing, int slot);
76 int (*media_changed) (struct cdrom_device_info *, int);
77 int (*tray_move) (struct cdrom_device_info *, int);
78 int (*lock_door) (struct cdrom_device_info *, int);
79 int (*select_speed) (struct cdrom_device_info *, int);
80 int (*select_disc) (struct cdrom_device_info *, int);
81 int (*get_last_session) (struct cdrom_device_info *,
82 struct cdrom_multisession *);
83 int (*get_mcn) (struct cdrom_device_info *,
84 struct cdrom_mcn *);
85
86 int (*reset) (struct cdrom_device_info *);
87
88 int (*audio_ioctl) (struct cdrom_device_info *,unsigned int, void *);
89
90
91 const int capability;
92
93 int (*generic_packet) (struct cdrom_device_info *,
94 struct packet_command *);
95};
96
97
98extern int cdrom_open(struct cdrom_device_info *cdi, struct block_device *bdev,
99 fmode_t mode);
100extern void cdrom_release(struct cdrom_device_info *cdi, fmode_t mode);
101extern int cdrom_ioctl(struct cdrom_device_info *cdi, struct block_device *bdev,
102 fmode_t mode, unsigned int cmd, unsigned long arg);
103extern unsigned int cdrom_check_events(struct cdrom_device_info *cdi,
104 unsigned int clearing);
105extern int cdrom_media_changed(struct cdrom_device_info *);
106
107extern int register_cdrom(struct cdrom_device_info *cdi);
108extern void unregister_cdrom(struct cdrom_device_info *cdi);
109
110typedef struct {
111 int data;
112 int audio;
113 int cdi;
114 int xa;
115 long error;
116} tracktype;
117
118extern int cdrom_get_last_written(struct cdrom_device_info *cdi, long *last_written);
119extern int cdrom_number_of_slots(struct cdrom_device_info *cdi);
120extern int cdrom_mode_select(struct cdrom_device_info *cdi,
121 struct packet_command *cgc);
122extern int cdrom_mode_sense(struct cdrom_device_info *cdi,
123 struct packet_command *cgc,
124 int page_code, int page_control);
125extern void init_cdrom_command(struct packet_command *cgc,
126 void *buffer, int len, int type);
127extern int cdrom_dummy_generic_packet(struct cdrom_device_info *cdi,
128 struct packet_command *cgc);
129
130
131#define CDROM_MAX_SLOTS 256
132
133struct cdrom_mechstat_header {
134#if defined(__BIG_ENDIAN_BITFIELD)
135 __u8 fault : 1;
136 __u8 changer_state : 2;
137 __u8 curslot : 5;
138 __u8 mech_state : 3;
139 __u8 door_open : 1;
140 __u8 reserved1 : 4;
141#elif defined(__LITTLE_ENDIAN_BITFIELD)
142 __u8 curslot : 5;
143 __u8 changer_state : 2;
144 __u8 fault : 1;
145 __u8 reserved1 : 4;
146 __u8 door_open : 1;
147 __u8 mech_state : 3;
148#endif
149 __u8 curlba[3];
150 __u8 nslots;
151 __u16 slot_tablelen;
152};
153
154struct cdrom_slot {
155#if defined(__BIG_ENDIAN_BITFIELD)
156 __u8 disc_present : 1;
157 __u8 reserved1 : 6;
158 __u8 change : 1;
159#elif defined(__LITTLE_ENDIAN_BITFIELD)
160 __u8 change : 1;
161 __u8 reserved1 : 6;
162 __u8 disc_present : 1;
163#endif
164 __u8 reserved2[3];
165};
166
167struct cdrom_changer_info {
168 struct cdrom_mechstat_header hdr;
169 struct cdrom_slot slots[CDROM_MAX_SLOTS];
170};
171
172typedef enum {
173 mechtype_caddy = 0,
174 mechtype_tray = 1,
175 mechtype_popup = 2,
176 mechtype_individual_changer = 4,
177 mechtype_cartridge_changer = 5
178} mechtype_t;
179
180typedef struct {
181#if defined(__BIG_ENDIAN_BITFIELD)
182 __u8 ps : 1;
183 __u8 reserved1 : 1;
184 __u8 page_code : 6;
185 __u8 page_length;
186 __u8 reserved2 : 1;
187 __u8 bufe : 1;
188 __u8 ls_v : 1;
189 __u8 test_write : 1;
190 __u8 write_type : 4;
191 __u8 multi_session : 2;
192 __u8 fp : 1;
193 __u8 copy : 1;
194 __u8 track_mode : 4;
195 __u8 reserved3 : 4;
196 __u8 data_block_type : 4;
197#elif defined(__LITTLE_ENDIAN_BITFIELD)
198 __u8 page_code : 6;
199 __u8 reserved1 : 1;
200 __u8 ps : 1;
201 __u8 page_length;
202 __u8 write_type : 4;
203 __u8 test_write : 1;
204 __u8 ls_v : 1;
205 __u8 bufe : 1;
206 __u8 reserved2 : 1;
207 __u8 track_mode : 4;
208 __u8 copy : 1;
209 __u8 fp : 1;
210 __u8 multi_session : 2;
211 __u8 data_block_type : 4;
212 __u8 reserved3 : 4;
213#endif
214 __u8 link_size;
215 __u8 reserved4;
216#if defined(__BIG_ENDIAN_BITFIELD)
217 __u8 reserved5 : 2;
218 __u8 app_code : 6;
219#elif defined(__LITTLE_ENDIAN_BITFIELD)
220 __u8 app_code : 6;
221 __u8 reserved5 : 2;
222#endif
223 __u8 session_format;
224 __u8 reserved6;
225 __be32 packet_size;
226 __u16 audio_pause;
227 __u8 mcn[16];
228 __u8 isrc[16];
229 __u8 subhdr0;
230 __u8 subhdr1;
231 __u8 subhdr2;
232 __u8 subhdr3;
233} __attribute__((packed)) write_param_page;
234
235struct modesel_head
236{
237 __u8 reserved1;
238 __u8 medium;
239 __u8 reserved2;
240 __u8 block_desc_length;
241 __u8 density;
242 __u8 number_of_blocks_hi;
243 __u8 number_of_blocks_med;
244 __u8 number_of_blocks_lo;
245 __u8 reserved3;
246 __u8 block_length_hi;
247 __u8 block_length_med;
248 __u8 block_length_lo;
249};
250
251typedef struct {
252 __u16 report_key_length;
253 __u8 reserved1;
254 __u8 reserved2;
255#if defined(__BIG_ENDIAN_BITFIELD)
256 __u8 type_code : 2;
257 __u8 vra : 3;
258 __u8 ucca : 3;
259#elif defined(__LITTLE_ENDIAN_BITFIELD)
260 __u8 ucca : 3;
261 __u8 vra : 3;
262 __u8 type_code : 2;
263#endif
264 __u8 region_mask;
265 __u8 rpc_scheme;
266 __u8 reserved3;
267} rpc_state_t;
268
269struct event_header {
270 __be16 data_len;
271#if defined(__BIG_ENDIAN_BITFIELD)
272 __u8 nea : 1;
273 __u8 reserved1 : 4;
274 __u8 notification_class : 3;
275#elif defined(__LITTLE_ENDIAN_BITFIELD)
276 __u8 notification_class : 3;
277 __u8 reserved1 : 4;
278 __u8 nea : 1;
279#endif
280 __u8 supp_event_class;
281};
282
283struct media_event_desc {
284#if defined(__BIG_ENDIAN_BITFIELD)
285 __u8 reserved1 : 4;
286 __u8 media_event_code : 4;
287 __u8 reserved2 : 6;
288 __u8 media_present : 1;
289 __u8 door_open : 1;
290#elif defined(__LITTLE_ENDIAN_BITFIELD)
291 __u8 media_event_code : 4;
292 __u8 reserved1 : 4;
293 __u8 door_open : 1;
294 __u8 media_present : 1;
295 __u8 reserved2 : 6;
296#endif
297 __u8 start_slot;
298 __u8 end_slot;
299};
300
301extern int cdrom_get_media_event(struct cdrom_device_info *cdi, struct media_event_desc *med);
302
303static inline void lba_to_msf(int lba, u8 *m, u8 *s, u8 *f)
304{
305 lba += CD_MSF_OFFSET;
306 lba &= 0xffffff;
307 *m = lba / (CD_SECS * CD_FRAMES);
308 lba %= (CD_SECS * CD_FRAMES);
309 *s = lba / CD_FRAMES;
310 *f = lba % CD_FRAMES;
311}
312
313static inline int msf_to_lba(u8 m, u8 s, u8 f)
314{
315 return (((m * CD_SECS) + s) * CD_FRAMES + f) - CD_MSF_OFFSET;
316}
317#endif
318