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 <uapi/linux/cdrom.h>
20 unsigned char cmd
[CDROM_PACKET_SIZE
];
21 unsigned char *buffer
;
24 struct request_sense
*sense
;
25 unsigned char data_direction
;
32 * _OLD will use PIO transfer on atapi devices, _BPC_* will use DMA
34 #define CDDA_OLD 0 /* old style */
35 #define CDDA_BPC_SINGLE 1 /* single frame block pc */
36 #define CDDA_BPC_FULL 2 /* multi frame block pc */
38 /* Uniform cdrom data structures for cdrom.c */
39 struct cdrom_device_info
{
40 const struct cdrom_device_ops
*ops
; /* link to device_ops */
41 struct list_head list
; /* linked list of all device_info */
42 struct gendisk
*disk
; /* matching block layer disk */
43 void *handle
; /* driver-dependent data */
45 int mask
; /* mask of capability: disables them */
46 int speed
; /* maximum speed for reading data */
47 int capacity
; /* number of discs in jukebox */
48 /* device-related storage */
49 unsigned int options
: 30; /* options flags */
50 unsigned mc_flags
: 2; /* media change buffer flags */
51 unsigned int vfs_events
; /* cached events for vfs path */
52 unsigned int ioctl_events
; /* cached events for ioctl path */
53 int use_count
; /* number of times device opened */
54 char name
[20]; /* name of the device type */
55 /* per-device flags */
56 __u8 sanyo_slot
: 2; /* Sanyo 3 CD changer support */
57 __u8 keeplocked
: 1; /* CDROM_LOCKDOOR status */
58 __u8 reserved
: 5; /* not used yet */
59 int cdda_method
; /* see flags */
61 __u8 media_written
; /* dirty flag, DVD+RW bookkeeping */
62 unsigned short mmc3_profile
; /* current MMC3 profile */
64 int (*exit
)(struct cdrom_device_info
*);
68 struct cdrom_device_ops
{
70 int (*open
) (struct cdrom_device_info
*, int);
71 void (*release
) (struct cdrom_device_info
*);
72 int (*drive_status
) (struct cdrom_device_info
*, int);
73 unsigned int (*check_events
) (struct cdrom_device_info
*cdi
,
74 unsigned int clearing
, int slot
);
75 int (*media_changed
) (struct cdrom_device_info
*, int);
76 int (*tray_move
) (struct cdrom_device_info
*, int);
77 int (*lock_door
) (struct cdrom_device_info
*, int);
78 int (*select_speed
) (struct cdrom_device_info
*, int);
79 int (*select_disc
) (struct cdrom_device_info
*, int);
80 int (*get_last_session
) (struct cdrom_device_info
*,
81 struct cdrom_multisession
*);
82 int (*get_mcn
) (struct cdrom_device_info
*,
84 /* hard reset device */
85 int (*reset
) (struct cdrom_device_info
*);
87 int (*audio_ioctl
) (struct cdrom_device_info
*,unsigned int, void *);
89 /* driver specifications */
90 const int capability
; /* capability flags */
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
);
126 extern int cdrom_dummy_generic_packet(struct cdrom_device_info
*cdi
,
127 struct packet_command
*cgc
);
129 /* The SCSI spec says there could be 256 slots. */
130 #define CDROM_MAX_SLOTS 256
132 struct cdrom_mechstat_header
{
133 #if defined(__BIG_ENDIAN_BITFIELD)
135 __u8 changer_state
: 2;
140 #elif defined(__LITTLE_ENDIAN_BITFIELD)
142 __u8 changer_state
: 2;
154 #if defined(__BIG_ENDIAN_BITFIELD)
155 __u8 disc_present
: 1;
158 #elif defined(__LITTLE_ENDIAN_BITFIELD)
161 __u8 disc_present
: 1;
166 struct cdrom_changer_info
{
167 struct cdrom_mechstat_header hdr
;
168 struct cdrom_slot slots
[CDROM_MAX_SLOTS
];
175 mechtype_individual_changer
= 4,
176 mechtype_cartridge_changer
= 5
180 #if defined(__BIG_ENDIAN_BITFIELD)
190 __u8 multi_session
: 2; /* or border, DVD */
195 __u8 data_block_type
: 4;
196 #elif defined(__LITTLE_ENDIAN_BITFIELD)
209 __u8 multi_session
: 2; /* or border, DVD */
210 __u8 data_block_type
: 4;
215 #if defined(__BIG_ENDIAN_BITFIELD)
218 #elif defined(__LITTLE_ENDIAN_BITFIELD)
232 } __attribute__((packed
)) write_param_page
;
239 __u8 block_desc_length
;
241 __u8 number_of_blocks_hi
;
242 __u8 number_of_blocks_med
;
243 __u8 number_of_blocks_lo
;
245 __u8 block_length_hi
;
246 __u8 block_length_med
;
247 __u8 block_length_lo
;
251 __u16 report_key_length
;
254 #if defined(__BIG_ENDIAN_BITFIELD)
258 #elif defined(__LITTLE_ENDIAN_BITFIELD)
268 struct event_header
{
270 #if defined(__BIG_ENDIAN_BITFIELD)
273 __u8 notification_class
: 3;
274 #elif defined(__LITTLE_ENDIAN_BITFIELD)
275 __u8 notification_class
: 3;
279 __u8 supp_event_class
;
282 struct media_event_desc
{
283 #if defined(__BIG_ENDIAN_BITFIELD)
285 __u8 media_event_code
: 4;
287 __u8 media_present
: 1;
289 #elif defined(__LITTLE_ENDIAN_BITFIELD)
290 __u8 media_event_code
: 4;
293 __u8 media_present
: 1;
300 extern int cdrom_get_media_event(struct cdrom_device_info
*cdi
, struct media_event_desc
*med
);
302 static inline void lba_to_msf(int lba
, u8
*m
, u8
*s
, u8
*f
)
304 lba
+= CD_MSF_OFFSET
;
305 lba
&= 0xffffff; /* negative lbas use only 24 bits */
306 *m
= lba
/ (CD_SECS
* CD_FRAMES
);
307 lba
%= (CD_SECS
* CD_FRAMES
);
308 *s
= lba
/ CD_FRAMES
;
309 *f
= lba
% CD_FRAMES
;
312 static inline int msf_to_lba(u8 m
, u8 s
, u8 f
)
314 return (((m
* CD_SECS
) + s
) * CD_FRAMES
+ f
) - CD_MSF_OFFSET
;
316 #endif /* _LINUX_CDROM_H */