cdrom.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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 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
  9. */
  10. #ifndef _LINUX_CDROM_H
  11. #define _LINUX_CDROM_H
  12. #include <linux/fs.h> /* not really needed, later.. */
  13. #include <linux/list.h>
  14. #include <uapi/linux/cdrom.h>
  15. struct packet_command
  16. {
  17. unsigned char cmd[CDROM_PACKET_SIZE];
  18. unsigned char *buffer;
  19. unsigned int buflen;
  20. int stat;
  21. struct request_sense *sense;
  22. unsigned char data_direction;
  23. int quiet;
  24. int timeout;
  25. void *reserved[1];
  26. };
  27. /*
  28. * _OLD will use PIO transfer on atapi devices, _BPC_* will use DMA
  29. */
  30. #define CDDA_OLD 0 /* old style */
  31. #define CDDA_BPC_SINGLE 1 /* single frame block pc */
  32. #define CDDA_BPC_FULL 2 /* multi frame block pc */
  33. /* Uniform cdrom data structures for cdrom.c */
  34. struct cdrom_device_info {
  35. struct cdrom_device_ops *ops; /* link to device_ops */
  36. struct list_head list; /* linked list of all device_info */
  37. struct gendisk *disk; /* matching block layer disk */
  38. void *handle; /* driver-dependent data */
  39. /* specifications */
  40. int mask; /* mask of capability: disables them */
  41. int speed; /* maximum speed for reading data */
  42. int capacity; /* number of discs in jukebox */
  43. /* device-related storage */
  44. unsigned int options : 30; /* options flags */
  45. unsigned mc_flags : 2; /* media change buffer flags */
  46. unsigned int vfs_events; /* cached events for vfs path */
  47. unsigned int ioctl_events; /* cached events for ioctl path */
  48. int use_count; /* number of times device opened */
  49. char name[20]; /* name of the device type */
  50. /* per-device flags */
  51. __u8 sanyo_slot : 2; /* Sanyo 3 CD changer support */
  52. __u8 keeplocked : 1; /* CDROM_LOCKDOOR status */
  53. __u8 reserved : 5; /* not used yet */
  54. int cdda_method; /* see flags */
  55. __u8 last_sense;
  56. __u8 media_written; /* dirty flag, DVD+RW bookkeeping */
  57. unsigned short mmc3_profile; /* current MMC3 profile */
  58. int for_data;
  59. int (*exit)(struct cdrom_device_info *);
  60. int mrw_mode_page;
  61. };
  62. struct cdrom_device_ops {
  63. /* routines */
  64. int (*open) (struct cdrom_device_info *, int);
  65. void (*release) (struct cdrom_device_info *);
  66. int (*drive_status) (struct cdrom_device_info *, int);
  67. unsigned int (*check_events) (struct cdrom_device_info *cdi,
  68. unsigned int clearing, int slot);
  69. int (*media_changed) (struct cdrom_device_info *, int);
  70. int (*tray_move) (struct cdrom_device_info *, int);
  71. int (*lock_door) (struct cdrom_device_info *, int);
  72. int (*select_speed) (struct cdrom_device_info *, int);
  73. int (*select_disc) (struct cdrom_device_info *, int);
  74. int (*get_last_session) (struct cdrom_device_info *,
  75. struct cdrom_multisession *);
  76. int (*get_mcn) (struct cdrom_device_info *,
  77. struct cdrom_mcn *);
  78. /* hard reset device */
  79. int (*reset) (struct cdrom_device_info *);
  80. /* play stuff */
  81. int (*audio_ioctl) (struct cdrom_device_info *,unsigned int, void *);
  82. /* driver specifications */
  83. const int capability; /* capability flags */
  84. int n_minors; /* number of active minor devices */
  85. /* handle uniform packets for scsi type devices (scsi,atapi) */
  86. int (*generic_packet) (struct cdrom_device_info *,
  87. struct packet_command *);
  88. };
  89. /* the general block_device operations structure: */
  90. extern int cdrom_open(struct cdrom_device_info *cdi, struct block_device *bdev,
  91. fmode_t mode);
  92. extern void cdrom_release(struct cdrom_device_info *cdi, fmode_t mode);
  93. extern int cdrom_ioctl(struct cdrom_device_info *cdi, struct block_device *bdev,
  94. fmode_t mode, unsigned int cmd, unsigned long arg);
  95. extern unsigned int cdrom_check_events(struct cdrom_device_info *cdi,
  96. unsigned int clearing);
  97. extern int cdrom_media_changed(struct cdrom_device_info *);
  98. extern int register_cdrom(struct cdrom_device_info *cdi);
  99. extern void unregister_cdrom(struct cdrom_device_info *cdi);
  100. typedef struct {
  101. int data;
  102. int audio;
  103. int cdi;
  104. int xa;
  105. long error;
  106. } tracktype;
  107. extern int cdrom_get_last_written(struct cdrom_device_info *cdi, long *last_written);
  108. extern int cdrom_number_of_slots(struct cdrom_device_info *cdi);
  109. extern int cdrom_mode_select(struct cdrom_device_info *cdi,
  110. struct packet_command *cgc);
  111. extern int cdrom_mode_sense(struct cdrom_device_info *cdi,
  112. struct packet_command *cgc,
  113. int page_code, int page_control);
  114. extern void init_cdrom_command(struct packet_command *cgc,
  115. void *buffer, int len, int type);
  116. /* The SCSI spec says there could be 256 slots. */
  117. #define CDROM_MAX_SLOTS 256
  118. struct cdrom_mechstat_header {
  119. #if defined(__BIG_ENDIAN_BITFIELD)
  120. __u8 fault : 1;
  121. __u8 changer_state : 2;
  122. __u8 curslot : 5;
  123. __u8 mech_state : 3;
  124. __u8 door_open : 1;
  125. __u8 reserved1 : 4;
  126. #elif defined(__LITTLE_ENDIAN_BITFIELD)
  127. __u8 curslot : 5;
  128. __u8 changer_state : 2;
  129. __u8 fault : 1;
  130. __u8 reserved1 : 4;
  131. __u8 door_open : 1;
  132. __u8 mech_state : 3;
  133. #endif
  134. __u8 curlba[3];
  135. __u8 nslots;
  136. __u16 slot_tablelen;
  137. };
  138. struct cdrom_slot {
  139. #if defined(__BIG_ENDIAN_BITFIELD)
  140. __u8 disc_present : 1;
  141. __u8 reserved1 : 6;
  142. __u8 change : 1;
  143. #elif defined(__LITTLE_ENDIAN_BITFIELD)
  144. __u8 change : 1;
  145. __u8 reserved1 : 6;
  146. __u8 disc_present : 1;
  147. #endif
  148. __u8 reserved2[3];
  149. };
  150. struct cdrom_changer_info {
  151. struct cdrom_mechstat_header hdr;
  152. struct cdrom_slot slots[CDROM_MAX_SLOTS];
  153. };
  154. typedef enum {
  155. mechtype_caddy = 0,
  156. mechtype_tray = 1,
  157. mechtype_popup = 2,
  158. mechtype_individual_changer = 4,
  159. mechtype_cartridge_changer = 5
  160. } mechtype_t;
  161. typedef struct {
  162. #if defined(__BIG_ENDIAN_BITFIELD)
  163. __u8 ps : 1;
  164. __u8 reserved1 : 1;
  165. __u8 page_code : 6;
  166. __u8 page_length;
  167. __u8 reserved2 : 1;
  168. __u8 bufe : 1;
  169. __u8 ls_v : 1;
  170. __u8 test_write : 1;
  171. __u8 write_type : 4;
  172. __u8 multi_session : 2; /* or border, DVD */
  173. __u8 fp : 1;
  174. __u8 copy : 1;
  175. __u8 track_mode : 4;
  176. __u8 reserved3 : 4;
  177. __u8 data_block_type : 4;
  178. #elif defined(__LITTLE_ENDIAN_BITFIELD)
  179. __u8 page_code : 6;
  180. __u8 reserved1 : 1;
  181. __u8 ps : 1;
  182. __u8 page_length;
  183. __u8 write_type : 4;
  184. __u8 test_write : 1;
  185. __u8 ls_v : 1;
  186. __u8 bufe : 1;
  187. __u8 reserved2 : 1;
  188. __u8 track_mode : 4;
  189. __u8 copy : 1;
  190. __u8 fp : 1;
  191. __u8 multi_session : 2; /* or border, DVD */
  192. __u8 data_block_type : 4;
  193. __u8 reserved3 : 4;
  194. #endif
  195. __u8 link_size;
  196. __u8 reserved4;
  197. #if defined(__BIG_ENDIAN_BITFIELD)
  198. __u8 reserved5 : 2;
  199. __u8 app_code : 6;
  200. #elif defined(__LITTLE_ENDIAN_BITFIELD)
  201. __u8 app_code : 6;
  202. __u8 reserved5 : 2;
  203. #endif
  204. __u8 session_format;
  205. __u8 reserved6;
  206. __be32 packet_size;
  207. __u16 audio_pause;
  208. __u8 mcn[16];
  209. __u8 isrc[16];
  210. __u8 subhdr0;
  211. __u8 subhdr1;
  212. __u8 subhdr2;
  213. __u8 subhdr3;
  214. } __attribute__((packed)) write_param_page;
  215. struct modesel_head
  216. {
  217. __u8 reserved1;
  218. __u8 medium;
  219. __u8 reserved2;
  220. __u8 block_desc_length;
  221. __u8 density;
  222. __u8 number_of_blocks_hi;
  223. __u8 number_of_blocks_med;
  224. __u8 number_of_blocks_lo;
  225. __u8 reserved3;
  226. __u8 block_length_hi;
  227. __u8 block_length_med;
  228. __u8 block_length_lo;
  229. };
  230. typedef struct {
  231. __u16 report_key_length;
  232. __u8 reserved1;
  233. __u8 reserved2;
  234. #if defined(__BIG_ENDIAN_BITFIELD)
  235. __u8 type_code : 2;
  236. __u8 vra : 3;
  237. __u8 ucca : 3;
  238. #elif defined(__LITTLE_ENDIAN_BITFIELD)
  239. __u8 ucca : 3;
  240. __u8 vra : 3;
  241. __u8 type_code : 2;
  242. #endif
  243. __u8 region_mask;
  244. __u8 rpc_scheme;
  245. __u8 reserved3;
  246. } rpc_state_t;
  247. struct event_header {
  248. __be16 data_len;
  249. #if defined(__BIG_ENDIAN_BITFIELD)
  250. __u8 nea : 1;
  251. __u8 reserved1 : 4;
  252. __u8 notification_class : 3;
  253. #elif defined(__LITTLE_ENDIAN_BITFIELD)
  254. __u8 notification_class : 3;
  255. __u8 reserved1 : 4;
  256. __u8 nea : 1;
  257. #endif
  258. __u8 supp_event_class;
  259. };
  260. struct media_event_desc {
  261. #if defined(__BIG_ENDIAN_BITFIELD)
  262. __u8 reserved1 : 4;
  263. __u8 media_event_code : 4;
  264. __u8 reserved2 : 6;
  265. __u8 media_present : 1;
  266. __u8 door_open : 1;
  267. #elif defined(__LITTLE_ENDIAN_BITFIELD)
  268. __u8 media_event_code : 4;
  269. __u8 reserved1 : 4;
  270. __u8 door_open : 1;
  271. __u8 media_present : 1;
  272. __u8 reserved2 : 6;
  273. #endif
  274. __u8 start_slot;
  275. __u8 end_slot;
  276. };
  277. extern int cdrom_get_media_event(struct cdrom_device_info *cdi, struct media_event_desc *med);
  278. static inline void lba_to_msf(int lba, u8 *m, u8 *s, u8 *f)
  279. {
  280. lba += CD_MSF_OFFSET;
  281. lba &= 0xffffff; /* negative lbas use only 24 bits */
  282. *m = lba / (CD_SECS * CD_FRAMES);
  283. lba %= (CD_SECS * CD_FRAMES);
  284. *s = lba / CD_FRAMES;
  285. *f = lba % CD_FRAMES;
  286. }
  287. static inline int msf_to_lba(u8 m, u8 s, u8 f)
  288. {
  289. return (((m * CD_SECS) + s) * CD_FRAMES + f) - CD_MSF_OFFSET;
  290. }
  291. #endif /* _LINUX_CDROM_H */