1 /* SPDX-License-Identifier: GPL-2.0 */
4 * General header file for linux CD-ROM drivers
5 * Copyright (C) 1992 David Giller, rafetmad@oxy.edu
6 * 1994, 1995 Eberhard Mönkeberg, emoenke@gwdg.de
7 * 1996 David van Leeuwen, david@tm.tno.nl
8 * 1997, 1998 Erik Andersen, andersee@debian.org
9 * 1998-2002 Jens Axboe, axboe@suse.de
11 #ifndef _LINUX_CDROM_H
12 #define _LINUX_CDROM_H
14 #include <linux/fs.h> /* not really needed, later.. */
15 #include <linux/list.h>
16 #include <scsi/scsi_common.h>
17 #include <uapi/linux/cdrom.h>
21 unsigned char cmd[CDROM_PACKET_SIZE];
22 unsigned char *buffer;
25 struct scsi_sense_hdr *sshdr;
26 unsigned char data_direction;
33 * _OLD will use PIO transfer on atapi devices, _BPC_* will use DMA
35 #define CDDA_OLD 0 /* old style */
36 #define CDDA_BPC_SINGLE 1 /* single frame block pc */
37 #define CDDA_BPC_FULL 2 /* multi frame block pc */
39 /* Uniform cdrom data structures for cdrom.c */
40 struct cdrom_device_info {
41 const struct cdrom_device_ops *ops; /* link to device_ops */
42 struct list_head list; /* linked list of all device_info */
43 struct gendisk *disk; /* matching block layer disk */
44 void *handle; /* driver-dependent data */
46 int mask; /* mask of capability: disables them */
47 int speed; /* maximum speed for reading data */
48 int capacity; /* number of discs in jukebox */
49 /* device-related storage */
50 unsigned int options : 30; /* options flags */
51 unsigned mc_flags : 2; /* media change buffer flags */
52 unsigned int vfs_events; /* cached events for vfs path */
53 unsigned int ioctl_events; /* cached events for ioctl path */
54 int use_count; /* number of times device opened */
55 char name[20]; /* name of the device type */
56 /* per-device flags */
57 __u8 sanyo_slot : 2; /* Sanyo 3 CD changer support */
58 __u8 keeplocked : 1; /* CDROM_LOCKDOOR status */
59 __u8 reserved : 5; /* not used yet */
60 int cdda_method; /* see flags */
62 __u8 media_written; /* dirty flag, DVD+RW bookkeeping */
63 unsigned short mmc3_profile; /* current MMC3 profile */
65 int (*exit)(struct cdrom_device_info *);
69 struct cdrom_device_ops {
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 *,
85 /* hard reset device */
86 int (*reset) (struct cdrom_device_info *);
88 int (*audio_ioctl) (struct cdrom_device_info *,unsigned int, void *);
90 /* driver specifications */
91 const int capability; /* capability flags */
92 /* handle uniform packets for scsi type devices (scsi,atapi) */
93 int (*generic_packet) (struct cdrom_device_info *,
94 struct packet_command *);
97 /* the general block_device operations structure: */
98 extern int cdrom_open(struct cdrom_device_info *cdi, struct block_device *bdev,
100 extern void cdrom_release(struct cdrom_device_info *cdi, fmode_t mode);
101 extern int cdrom_ioctl(struct cdrom_device_info *cdi, struct block_device *bdev,
102 fmode_t mode, unsigned int cmd, unsigned long arg);
103 extern unsigned int cdrom_check_events(struct cdrom_device_info *cdi,
104 unsigned int clearing);
105 extern int cdrom_media_changed(struct cdrom_device_info *);
107 extern int register_cdrom(struct cdrom_device_info *cdi);
108 extern void unregister_cdrom(struct cdrom_device_info *cdi);
118 extern int cdrom_get_last_written(struct cdrom_device_info *cdi, long *last_written);
119 extern int cdrom_number_of_slots(struct cdrom_device_info *cdi);
120 extern int cdrom_mode_select(struct cdrom_device_info *cdi,
121 struct packet_command *cgc);
122 extern int cdrom_mode_sense(struct cdrom_device_info *cdi,
123 struct packet_command *cgc,
124 int page_code, int page_control);
125 extern void init_cdrom_command(struct packet_command *cgc,
126 void *buffer, int len, int type);
127 extern int cdrom_dummy_generic_packet(struct cdrom_device_info *cdi,
128 struct packet_command *cgc);
130 /* The SCSI spec says there could be 256 slots. */
131 #define CDROM_MAX_SLOTS 256
133 struct cdrom_mechstat_header {
134 #if defined(__BIG_ENDIAN_BITFIELD)
136 __u8 changer_state : 2;
141 #elif defined(__LITTLE_ENDIAN_BITFIELD)
143 __u8 changer_state : 2;
155 #if defined(__BIG_ENDIAN_BITFIELD)
156 __u8 disc_present : 1;
159 #elif defined(__LITTLE_ENDIAN_BITFIELD)
162 __u8 disc_present : 1;
167 struct cdrom_changer_info {
168 struct cdrom_mechstat_header hdr;
169 struct cdrom_slot slots[CDROM_MAX_SLOTS];
176 mechtype_individual_changer = 4,
177 mechtype_cartridge_changer = 5
181 #if defined(__BIG_ENDIAN_BITFIELD)
191 __u8 multi_session : 2; /* or border, DVD */
196 __u8 data_block_type : 4;
197 #elif defined(__LITTLE_ENDIAN_BITFIELD)
210 __u8 multi_session : 2; /* or border, DVD */
211 __u8 data_block_type : 4;
216 #if defined(__BIG_ENDIAN_BITFIELD)
219 #elif defined(__LITTLE_ENDIAN_BITFIELD)
233 } __attribute__((packed)) write_param_page;
240 __u8 block_desc_length;
242 __u8 number_of_blocks_hi;
243 __u8 number_of_blocks_med;
244 __u8 number_of_blocks_lo;
246 __u8 block_length_hi;
247 __u8 block_length_med;
248 __u8 block_length_lo;
252 __u16 report_key_length;
255 #if defined(__BIG_ENDIAN_BITFIELD)
259 #elif defined(__LITTLE_ENDIAN_BITFIELD)
269 struct event_header {
271 #if defined(__BIG_ENDIAN_BITFIELD)
274 __u8 notification_class : 3;
275 #elif defined(__LITTLE_ENDIAN_BITFIELD)
276 __u8 notification_class : 3;
280 __u8 supp_event_class;
283 struct media_event_desc {
284 #if defined(__BIG_ENDIAN_BITFIELD)
286 __u8 media_event_code : 4;
288 __u8 media_present : 1;
290 #elif defined(__LITTLE_ENDIAN_BITFIELD)
291 __u8 media_event_code : 4;
294 __u8 media_present : 1;
301 extern int cdrom_get_media_event(struct cdrom_device_info *cdi, struct media_event_desc *med);
303 static inline void lba_to_msf(int lba, u8 *m, u8 *s, u8 *f)
305 lba += CD_MSF_OFFSET;
306 lba &= 0xffffff; /* negative lbas use only 24 bits */
307 *m = lba / (CD_SECS * CD_FRAMES);
308 lba %= (CD_SECS * CD_FRAMES);
309 *s = lba / CD_FRAMES;
310 *f = lba % CD_FRAMES;
313 static inline int msf_to_lba(u8 m, u8 s, u8 f)
315 return (((m * CD_SECS) + s) * CD_FRAMES + f) - CD_MSF_OFFSET;
317 #endif /* _LINUX_CDROM_H */