1*8ea61889SMauro Carvalho Chehab======================= 2*8ea61889SMauro Carvalho ChehabA Linux CD-ROM standard 3*8ea61889SMauro Carvalho Chehab======================= 4*8ea61889SMauro Carvalho Chehab 5*8ea61889SMauro Carvalho Chehab:Author: David van Leeuwen <david@ElseWare.cistron.nl> 6*8ea61889SMauro Carvalho Chehab:Date: 12 March 1999 7*8ea61889SMauro Carvalho Chehab:Updated by: Erik Andersen (andersee@debian.org) 8*8ea61889SMauro Carvalho Chehab:Updated by: Jens Axboe (axboe@image.dk) 9*8ea61889SMauro Carvalho Chehab 10*8ea61889SMauro Carvalho Chehab 11*8ea61889SMauro Carvalho ChehabIntroduction 12*8ea61889SMauro Carvalho Chehab============ 13*8ea61889SMauro Carvalho Chehab 14*8ea61889SMauro Carvalho ChehabLinux is probably the Unix-like operating system that supports 15*8ea61889SMauro Carvalho Chehabthe widest variety of hardware devices. The reasons for this are 16*8ea61889SMauro Carvalho Chehabpresumably 17*8ea61889SMauro Carvalho Chehab 18*8ea61889SMauro Carvalho Chehab- The large list of hardware devices available for the many platforms 19*8ea61889SMauro Carvalho Chehab that Linux now supports (i.e., i386-PCs, Sparc Suns, etc.) 20*8ea61889SMauro Carvalho Chehab- The open design of the operating system, such that anybody can write a 21*8ea61889SMauro Carvalho Chehab driver for Linux. 22*8ea61889SMauro Carvalho Chehab- There is plenty of source code around as examples of how to write a driver. 23*8ea61889SMauro Carvalho Chehab 24*8ea61889SMauro Carvalho ChehabThe openness of Linux, and the many different types of available 25*8ea61889SMauro Carvalho Chehabhardware has allowed Linux to support many different hardware devices. 26*8ea61889SMauro Carvalho ChehabUnfortunately, the very openness that has allowed Linux to support 27*8ea61889SMauro Carvalho Chehaball these different devices has also allowed the behavior of each 28*8ea61889SMauro Carvalho Chehabdevice driver to differ significantly from one device to another. 29*8ea61889SMauro Carvalho ChehabThis divergence of behavior has been very significant for CD-ROM 30*8ea61889SMauro Carvalho Chehabdevices; the way a particular drive reacts to a `standard` *ioctl()* 31*8ea61889SMauro Carvalho Chehabcall varies greatly from one device driver to another. To avoid making 32*8ea61889SMauro Carvalho Chehabtheir drivers totally inconsistent, the writers of Linux CD-ROM 33*8ea61889SMauro Carvalho Chehabdrivers generally created new device drivers by understanding, copying, 34*8ea61889SMauro Carvalho Chehaband then changing an existing one. Unfortunately, this practice did not 35*8ea61889SMauro Carvalho Chehabmaintain uniform behavior across all the Linux CD-ROM drivers. 36*8ea61889SMauro Carvalho Chehab 37*8ea61889SMauro Carvalho ChehabThis document describes an effort to establish Uniform behavior across 38*8ea61889SMauro Carvalho Chehaball the different CD-ROM device drivers for Linux. This document also 39*8ea61889SMauro Carvalho Chehabdefines the various *ioctl()'s*, and how the low-level CD-ROM device 40*8ea61889SMauro Carvalho Chehabdrivers should implement them. Currently (as of the Linux 2.1.\ *x* 41*8ea61889SMauro Carvalho Chehabdevelopment kernels) several low-level CD-ROM device drivers, including 42*8ea61889SMauro Carvalho Chehabboth IDE/ATAPI and SCSI, now use this Uniform interface. 43*8ea61889SMauro Carvalho Chehab 44*8ea61889SMauro Carvalho ChehabWhen the CD-ROM was developed, the interface between the CD-ROM drive 45*8ea61889SMauro Carvalho Chehaband the computer was not specified in the standards. As a result, many 46*8ea61889SMauro Carvalho Chehabdifferent CD-ROM interfaces were developed. Some of them had their 47*8ea61889SMauro Carvalho Chehabown proprietary design (Sony, Mitsumi, Panasonic, Philips), other 48*8ea61889SMauro Carvalho Chehabmanufacturers adopted an existing electrical interface and changed 49*8ea61889SMauro Carvalho Chehabthe functionality (CreativeLabs/SoundBlaster, Teac, Funai) or simply 50*8ea61889SMauro Carvalho Chehabadapted their drives to one or more of the already existing electrical 51*8ea61889SMauro Carvalho Chehabinterfaces (Aztech, Sanyo, Funai, Vertos, Longshine, Optics Storage and 52*8ea61889SMauro Carvalho Chehabmost of the `NoName` manufacturers). In cases where a new drive really 53*8ea61889SMauro Carvalho Chehabbrought its own interface or used its own command set and flow control 54*8ea61889SMauro Carvalho Chehabscheme, either a separate driver had to be written, or an existing 55*8ea61889SMauro Carvalho Chehabdriver had to be enhanced. History has delivered us CD-ROM support for 56*8ea61889SMauro Carvalho Chehabmany of these different interfaces. Nowadays, almost all new CD-ROM 57*8ea61889SMauro Carvalho Chehabdrives are either IDE/ATAPI or SCSI, and it is very unlikely that any 58*8ea61889SMauro Carvalho Chehabmanufacturer will create a new interface. Even finding drives for the 59*8ea61889SMauro Carvalho Chehabold proprietary interfaces is getting difficult. 60*8ea61889SMauro Carvalho Chehab 61*8ea61889SMauro Carvalho ChehabWhen (in the 1.3.70's) I looked at the existing software interface, 62*8ea61889SMauro Carvalho Chehabwhich was expressed through `cdrom.h`, it appeared to be a rather wild 63*8ea61889SMauro Carvalho Chehabset of commands and data formats [#f1]_. It seemed that many 64*8ea61889SMauro Carvalho Chehabfeatures of the software interface had been added to accommodate the 65*8ea61889SMauro Carvalho Chehabcapabilities of a particular drive, in an *ad hoc* manner. More 66*8ea61889SMauro Carvalho Chehabimportantly, it appeared that the behavior of the `standard` commands 67*8ea61889SMauro Carvalho Chehabwas different for most of the different drivers: e. g., some drivers 68*8ea61889SMauro Carvalho Chehabclose the tray if an *open()* call occurs when the tray is open, while 69*8ea61889SMauro Carvalho Chehabothers do not. Some drivers lock the door upon opening the device, to 70*8ea61889SMauro Carvalho Chehabprevent an incoherent file system, but others don't, to allow software 71*8ea61889SMauro Carvalho Chehabejection. Undoubtedly, the capabilities of the different drives vary, 72*8ea61889SMauro Carvalho Chehabbut even when two drives have the same capability their drivers' 73*8ea61889SMauro Carvalho Chehabbehavior was usually different. 74*8ea61889SMauro Carvalho Chehab 75*8ea61889SMauro Carvalho Chehab.. [#f1] 76*8ea61889SMauro Carvalho Chehab I cannot recollect what kernel version I looked at, then, 77*8ea61889SMauro Carvalho Chehab presumably 1.2.13 and 1.3.34 --- the latest kernel that I was 78*8ea61889SMauro Carvalho Chehab indirectly involved in. 79*8ea61889SMauro Carvalho Chehab 80*8ea61889SMauro Carvalho ChehabI decided to start a discussion on how to make all the Linux CD-ROM 81*8ea61889SMauro Carvalho Chehabdrivers behave more uniformly. I began by contacting the developers of 82*8ea61889SMauro Carvalho Chehabthe many CD-ROM drivers found in the Linux kernel. Their reactions 83*8ea61889SMauro Carvalho Chehabencouraged me to write the Uniform CD-ROM Driver which this document is 84*8ea61889SMauro Carvalho Chehabintended to describe. The implementation of the Uniform CD-ROM Driver is 85*8ea61889SMauro Carvalho Chehabin the file `cdrom.c`. This driver is intended to be an additional software 86*8ea61889SMauro Carvalho Chehablayer that sits on top of the low-level device drivers for each CD-ROM drive. 87*8ea61889SMauro Carvalho ChehabBy adding this additional layer, it is possible to have all the different 88*8ea61889SMauro Carvalho ChehabCD-ROM devices behave **exactly** the same (insofar as the underlying 89*8ea61889SMauro Carvalho Chehabhardware will allow). 90*8ea61889SMauro Carvalho Chehab 91*8ea61889SMauro Carvalho ChehabThe goal of the Uniform CD-ROM Driver is **not** to alienate driver developers 92*8ea61889SMauro Carvalho Chehabwhohave not yet taken steps to support this effort. The goal of Uniform CD-ROM 93*8ea61889SMauro Carvalho ChehabDriver is simply to give people writing application programs for CD-ROM drives 94*8ea61889SMauro Carvalho Chehab**one** Linux CD-ROM interface with consistent behavior for all 95*8ea61889SMauro Carvalho ChehabCD-ROM devices. In addition, this also provides a consistent interface 96*8ea61889SMauro Carvalho Chehabbetween the low-level device driver code and the Linux kernel. Care 97*8ea61889SMauro Carvalho Chehabis taken that 100% compatibility exists with the data structures and 98*8ea61889SMauro Carvalho Chehabprogrammer's interface defined in `cdrom.h`. This guide was written to 99*8ea61889SMauro Carvalho Chehabhelp CD-ROM driver developers adapt their code to use the Uniform CD-ROM 100*8ea61889SMauro Carvalho ChehabDriver code defined in `cdrom.c`. 101*8ea61889SMauro Carvalho Chehab 102*8ea61889SMauro Carvalho ChehabPersonally, I think that the most important hardware interfaces are 103*8ea61889SMauro Carvalho Chehabthe IDE/ATAPI drives and, of course, the SCSI drives, but as prices 104*8ea61889SMauro Carvalho Chehabof hardware drop continuously, it is also likely that people may have 105*8ea61889SMauro Carvalho Chehabmore than one CD-ROM drive, possibly of mixed types. It is important 106*8ea61889SMauro Carvalho Chehabthat these drives behave in the same way. In December 1994, one of the 107*8ea61889SMauro Carvalho Chehabcheapest CD-ROM drives was a Philips cm206, a double-speed proprietary 108*8ea61889SMauro Carvalho Chehabdrive. In the months that I was busy writing a Linux driver for it, 109*8ea61889SMauro Carvalho Chehabproprietary drives became obsolete and IDE/ATAPI drives became the 110*8ea61889SMauro Carvalho Chehabstandard. At the time of the last update to this document (November 111*8ea61889SMauro Carvalho Chehab1997) it is becoming difficult to even **find** anything less than a 112*8ea61889SMauro Carvalho Chehab16 speed CD-ROM drive, and 24 speed drives are common. 113*8ea61889SMauro Carvalho Chehab 114*8ea61889SMauro Carvalho Chehab.. _cdrom_api: 115*8ea61889SMauro Carvalho Chehab 116*8ea61889SMauro Carvalho ChehabStandardizing through another software level 117*8ea61889SMauro Carvalho Chehab============================================ 118*8ea61889SMauro Carvalho Chehab 119*8ea61889SMauro Carvalho ChehabAt the time this document was conceived, all drivers directly 120*8ea61889SMauro Carvalho Chehabimplemented the CD-ROM *ioctl()* calls through their own routines. This 121*8ea61889SMauro Carvalho Chehabled to the danger of different drivers forgetting to do important things 122*8ea61889SMauro Carvalho Chehablike checking that the user was giving the driver valid data. More 123*8ea61889SMauro Carvalho Chehabimportantly, this led to the divergence of behavior, which has already 124*8ea61889SMauro Carvalho Chehabbeen discussed. 125*8ea61889SMauro Carvalho Chehab 126*8ea61889SMauro Carvalho ChehabFor this reason, the Uniform CD-ROM Driver was created to enforce consistent 127*8ea61889SMauro Carvalho ChehabCD-ROM drive behavior, and to provide a common set of services to the various 128*8ea61889SMauro Carvalho Chehablow-level CD-ROM device drivers. The Uniform CD-ROM Driver now provides another 129*8ea61889SMauro Carvalho Chehabsoftware-level, that separates the *ioctl()* and *open()* implementation 130*8ea61889SMauro Carvalho Chehabfrom the actual hardware implementation. Note that this effort has 131*8ea61889SMauro Carvalho Chehabmade few changes which will affect a user's application programs. The 132*8ea61889SMauro Carvalho Chehabgreatest change involved moving the contents of the various low-level 133*8ea61889SMauro Carvalho ChehabCD-ROM drivers\' header files to the kernel's cdrom directory. This was 134*8ea61889SMauro Carvalho Chehabdone to help ensure that the user is only presented with only one cdrom 135*8ea61889SMauro Carvalho Chehabinterface, the interface defined in `cdrom.h`. 136*8ea61889SMauro Carvalho Chehab 137*8ea61889SMauro Carvalho ChehabCD-ROM drives are specific enough (i. e., different from other 138*8ea61889SMauro Carvalho Chehabblock-devices such as floppy or hard disc drives), to define a set 139*8ea61889SMauro Carvalho Chehabof common **CD-ROM device operations**, *<cdrom-device>_dops*. 140*8ea61889SMauro Carvalho ChehabThese operations are different from the classical block-device file 141*8ea61889SMauro Carvalho Chehaboperations, *<block-device>_fops*. 142*8ea61889SMauro Carvalho Chehab 143*8ea61889SMauro Carvalho ChehabThe routines for the Uniform CD-ROM Driver interface level are implemented 144*8ea61889SMauro Carvalho Chehabin the file `cdrom.c`. In this file, the Uniform CD-ROM Driver interfaces 145*8ea61889SMauro Carvalho Chehabwith the kernel as a block device by registering the following general 146*8ea61889SMauro Carvalho Chehab*struct file_operations*:: 147*8ea61889SMauro Carvalho Chehab 148*8ea61889SMauro Carvalho Chehab struct file_operations cdrom_fops = { 149*8ea61889SMauro Carvalho Chehab NULL, /∗ lseek ∗/ 150*8ea61889SMauro Carvalho Chehab block _read , /∗ read—general block-dev read ∗/ 151*8ea61889SMauro Carvalho Chehab block _write, /∗ write—general block-dev write ∗/ 152*8ea61889SMauro Carvalho Chehab NULL, /∗ readdir ∗/ 153*8ea61889SMauro Carvalho Chehab NULL, /∗ select ∗/ 154*8ea61889SMauro Carvalho Chehab cdrom_ioctl, /∗ ioctl ∗/ 155*8ea61889SMauro Carvalho Chehab NULL, /∗ mmap ∗/ 156*8ea61889SMauro Carvalho Chehab cdrom_open, /∗ open ∗/ 157*8ea61889SMauro Carvalho Chehab cdrom_release, /∗ release ∗/ 158*8ea61889SMauro Carvalho Chehab NULL, /∗ fsync ∗/ 159*8ea61889SMauro Carvalho Chehab NULL, /∗ fasync ∗/ 160*8ea61889SMauro Carvalho Chehab cdrom_media_changed, /∗ media change ∗/ 161*8ea61889SMauro Carvalho Chehab NULL /∗ revalidate ∗/ 162*8ea61889SMauro Carvalho Chehab }; 163*8ea61889SMauro Carvalho Chehab 164*8ea61889SMauro Carvalho ChehabEvery active CD-ROM device shares this *struct*. The routines 165*8ea61889SMauro Carvalho Chehabdeclared above are all implemented in `cdrom.c`, since this file is the 166*8ea61889SMauro Carvalho Chehabplace where the behavior of all CD-ROM-devices is defined and 167*8ea61889SMauro Carvalho Chehabstandardized. The actual interface to the various types of CD-ROM 168*8ea61889SMauro Carvalho Chehabhardware is still performed by various low-level CD-ROM-device 169*8ea61889SMauro Carvalho Chehabdrivers. These routines simply implement certain **capabilities** 170*8ea61889SMauro Carvalho Chehabthat are common to all CD-ROM (and really, all removable-media 171*8ea61889SMauro Carvalho Chehabdevices). 172*8ea61889SMauro Carvalho Chehab 173*8ea61889SMauro Carvalho ChehabRegistration of a low-level CD-ROM device driver is now done through 174*8ea61889SMauro Carvalho Chehabthe general routines in `cdrom.c`, not through the Virtual File System 175*8ea61889SMauro Carvalho Chehab(VFS) any more. The interface implemented in `cdrom.c` is carried out 176*8ea61889SMauro Carvalho Chehabthrough two general structures that contain information about the 177*8ea61889SMauro Carvalho Chehabcapabilities of the driver, and the specific drives on which the 178*8ea61889SMauro Carvalho Chehabdriver operates. The structures are: 179*8ea61889SMauro Carvalho Chehab 180*8ea61889SMauro Carvalho Chehabcdrom_device_ops 181*8ea61889SMauro Carvalho Chehab This structure contains information about the low-level driver for a 182*8ea61889SMauro Carvalho Chehab CD-ROM device. This structure is conceptually connected to the major 183*8ea61889SMauro Carvalho Chehab number of the device (although some drivers may have different 184*8ea61889SMauro Carvalho Chehab major numbers, as is the case for the IDE driver). 185*8ea61889SMauro Carvalho Chehab 186*8ea61889SMauro Carvalho Chehabcdrom_device_info 187*8ea61889SMauro Carvalho Chehab This structure contains information about a particular CD-ROM drive, 188*8ea61889SMauro Carvalho Chehab such as its device name, speed, etc. This structure is conceptually 189*8ea61889SMauro Carvalho Chehab connected to the minor number of the device. 190*8ea61889SMauro Carvalho Chehab 191*8ea61889SMauro Carvalho ChehabRegistering a particular CD-ROM drive with the Uniform CD-ROM Driver 192*8ea61889SMauro Carvalho Chehabis done by the low-level device driver though a call to:: 193*8ea61889SMauro Carvalho Chehab 194*8ea61889SMauro Carvalho Chehab register_cdrom(struct cdrom_device_info * <device>_info) 195*8ea61889SMauro Carvalho Chehab 196*8ea61889SMauro Carvalho ChehabThe device information structure, *<device>_info*, contains all the 197*8ea61889SMauro Carvalho Chehabinformation needed for the kernel to interface with the low-level 198*8ea61889SMauro Carvalho ChehabCD-ROM device driver. One of the most important entries in this 199*8ea61889SMauro Carvalho Chehabstructure is a pointer to the *cdrom_device_ops* structure of the 200*8ea61889SMauro Carvalho Chehablow-level driver. 201*8ea61889SMauro Carvalho Chehab 202*8ea61889SMauro Carvalho ChehabThe device operations structure, *cdrom_device_ops*, contains a list 203*8ea61889SMauro Carvalho Chehabof pointers to the functions which are implemented in the low-level 204*8ea61889SMauro Carvalho Chehabdevice driver. When `cdrom.c` accesses a CD-ROM device, it does it 205*8ea61889SMauro Carvalho Chehabthrough the functions in this structure. It is impossible to know all 206*8ea61889SMauro Carvalho Chehabthe capabilities of future CD-ROM drives, so it is expected that this 207*8ea61889SMauro Carvalho Chehablist may need to be expanded from time to time as new technologies are 208*8ea61889SMauro Carvalho Chehabdeveloped. For example, CD-R and CD-R/W drives are beginning to become 209*8ea61889SMauro Carvalho Chehabpopular, and support will soon need to be added for them. For now, the 210*8ea61889SMauro Carvalho Chehabcurrent *struct* is:: 211*8ea61889SMauro Carvalho Chehab 212*8ea61889SMauro Carvalho Chehab struct cdrom_device_ops { 213*8ea61889SMauro Carvalho Chehab int (*open)(struct cdrom_device_info *, int) 214*8ea61889SMauro Carvalho Chehab void (*release)(struct cdrom_device_info *); 215*8ea61889SMauro Carvalho Chehab int (*drive_status)(struct cdrom_device_info *, int); 216*8ea61889SMauro Carvalho Chehab unsigned int (*check_events)(struct cdrom_device_info *, 217*8ea61889SMauro Carvalho Chehab unsigned int, int); 218*8ea61889SMauro Carvalho Chehab int (*media_changed)(struct cdrom_device_info *, int); 219*8ea61889SMauro Carvalho Chehab int (*tray_move)(struct cdrom_device_info *, int); 220*8ea61889SMauro Carvalho Chehab int (*lock_door)(struct cdrom_device_info *, int); 221*8ea61889SMauro Carvalho Chehab int (*select_speed)(struct cdrom_device_info *, int); 222*8ea61889SMauro Carvalho Chehab int (*select_disc)(struct cdrom_device_info *, int); 223*8ea61889SMauro Carvalho Chehab int (*get_last_session) (struct cdrom_device_info *, 224*8ea61889SMauro Carvalho Chehab struct cdrom_multisession *); 225*8ea61889SMauro Carvalho Chehab int (*get_mcn)(struct cdrom_device_info *, struct cdrom_mcn *); 226*8ea61889SMauro Carvalho Chehab int (*reset)(struct cdrom_device_info *); 227*8ea61889SMauro Carvalho Chehab int (*audio_ioctl)(struct cdrom_device_info *, 228*8ea61889SMauro Carvalho Chehab unsigned int, void *); 229*8ea61889SMauro Carvalho Chehab const int capability; /* capability flags */ 230*8ea61889SMauro Carvalho Chehab int (*generic_packet)(struct cdrom_device_info *, 231*8ea61889SMauro Carvalho Chehab struct packet_command *); 232*8ea61889SMauro Carvalho Chehab }; 233*8ea61889SMauro Carvalho Chehab 234*8ea61889SMauro Carvalho ChehabWhen a low-level device driver implements one of these capabilities, 235*8ea61889SMauro Carvalho Chehabit should add a function pointer to this *struct*. When a particular 236*8ea61889SMauro Carvalho Chehabfunction is not implemented, however, this *struct* should contain a 237*8ea61889SMauro Carvalho ChehabNULL instead. The *capability* flags specify the capabilities of the 238*8ea61889SMauro Carvalho ChehabCD-ROM hardware and/or low-level CD-ROM driver when a CD-ROM drive 239*8ea61889SMauro Carvalho Chehabis registered with the Uniform CD-ROM Driver. 240*8ea61889SMauro Carvalho Chehab 241*8ea61889SMauro Carvalho ChehabNote that most functions have fewer parameters than their 242*8ea61889SMauro Carvalho Chehab*blkdev_fops* counterparts. This is because very little of the 243*8ea61889SMauro Carvalho Chehabinformation in the structures *inode* and *file* is used. For most 244*8ea61889SMauro Carvalho Chehabdrivers, the main parameter is the *struct* *cdrom_device_info*, from 245*8ea61889SMauro Carvalho Chehabwhich the major and minor number can be extracted. (Most low-level 246*8ea61889SMauro Carvalho ChehabCD-ROM drivers don't even look at the major and minor number though, 247*8ea61889SMauro Carvalho Chehabsince many of them only support one device.) This will be available 248*8ea61889SMauro Carvalho Chehabthrough *dev* in *cdrom_device_info* described below. 249*8ea61889SMauro Carvalho Chehab 250*8ea61889SMauro Carvalho ChehabThe drive-specific, minor-like information that is registered with 251*8ea61889SMauro Carvalho Chehab`cdrom.c`, currently contains the following fields:: 252*8ea61889SMauro Carvalho Chehab 253*8ea61889SMauro Carvalho Chehab struct cdrom_device_info { 254*8ea61889SMauro Carvalho Chehab const struct cdrom_device_ops * ops; /* device operations for this major */ 255*8ea61889SMauro Carvalho Chehab struct list_head list; /* linked list of all device_info */ 256*8ea61889SMauro Carvalho Chehab struct gendisk * disk; /* matching block layer disk */ 257*8ea61889SMauro Carvalho Chehab void * handle; /* driver-dependent data */ 258*8ea61889SMauro Carvalho Chehab 259*8ea61889SMauro Carvalho Chehab int mask; /* mask of capability: disables them */ 260*8ea61889SMauro Carvalho Chehab int speed; /* maximum speed for reading data */ 261*8ea61889SMauro Carvalho Chehab int capacity; /* number of discs in a jukebox */ 262*8ea61889SMauro Carvalho Chehab 263*8ea61889SMauro Carvalho Chehab unsigned int options:30; /* options flags */ 264*8ea61889SMauro Carvalho Chehab unsigned mc_flags:2; /* media-change buffer flags */ 265*8ea61889SMauro Carvalho Chehab unsigned int vfs_events; /* cached events for vfs path */ 266*8ea61889SMauro Carvalho Chehab unsigned int ioctl_events; /* cached events for ioctl path */ 267*8ea61889SMauro Carvalho Chehab int use_count; /* number of times device is opened */ 268*8ea61889SMauro Carvalho Chehab char name[20]; /* name of the device type */ 269*8ea61889SMauro Carvalho Chehab 270*8ea61889SMauro Carvalho Chehab __u8 sanyo_slot : 2; /* Sanyo 3-CD changer support */ 271*8ea61889SMauro Carvalho Chehab __u8 keeplocked : 1; /* CDROM_LOCKDOOR status */ 272*8ea61889SMauro Carvalho Chehab __u8 reserved : 5; /* not used yet */ 273*8ea61889SMauro Carvalho Chehab int cdda_method; /* see CDDA_* flags */ 274*8ea61889SMauro Carvalho Chehab __u8 last_sense; /* saves last sense key */ 275*8ea61889SMauro Carvalho Chehab __u8 media_written; /* dirty flag, DVD+RW bookkeeping */ 276*8ea61889SMauro Carvalho Chehab unsigned short mmc3_profile; /* current MMC3 profile */ 277*8ea61889SMauro Carvalho Chehab int for_data; /* unknown:TBD */ 278*8ea61889SMauro Carvalho Chehab int (*exit)(struct cdrom_device_info *);/* unknown:TBD */ 279*8ea61889SMauro Carvalho Chehab int mrw_mode_page; /* which MRW mode page is in use */ 280*8ea61889SMauro Carvalho Chehab }; 281*8ea61889SMauro Carvalho Chehab 282*8ea61889SMauro Carvalho ChehabUsing this *struct*, a linked list of the registered minor devices is 283*8ea61889SMauro Carvalho Chehabbuilt, using the *next* field. The device number, the device operations 284*8ea61889SMauro Carvalho Chehabstruct and specifications of properties of the drive are stored in this 285*8ea61889SMauro Carvalho Chehabstructure. 286*8ea61889SMauro Carvalho Chehab 287*8ea61889SMauro Carvalho ChehabThe *mask* flags can be used to mask out some of the capabilities listed 288*8ea61889SMauro Carvalho Chehabin *ops->capability*, if a specific drive doesn't support a feature 289*8ea61889SMauro Carvalho Chehabof the driver. The value *speed* specifies the maximum head-rate of the 290*8ea61889SMauro Carvalho Chehabdrive, measured in units of normal audio speed (176kB/sec raw data or 291*8ea61889SMauro Carvalho Chehab150kB/sec file system data). The parameters are declared *const* 292*8ea61889SMauro Carvalho Chehabbecause they describe properties of the drive, which don't change after 293*8ea61889SMauro Carvalho Chehabregistration. 294*8ea61889SMauro Carvalho Chehab 295*8ea61889SMauro Carvalho ChehabA few registers contain variables local to the CD-ROM drive. The 296*8ea61889SMauro Carvalho Chehabflags *options* are used to specify how the general CD-ROM routines 297*8ea61889SMauro Carvalho Chehabshould behave. These various flags registers should provide enough 298*8ea61889SMauro Carvalho Chehabflexibility to adapt to the different users' wishes (and **not** the 299*8ea61889SMauro Carvalho Chehab`arbitrary` wishes of the author of the low-level device driver, as is 300*8ea61889SMauro Carvalho Chehabthe case in the old scheme). The register *mc_flags* is used to buffer 301*8ea61889SMauro Carvalho Chehabthe information from *media_changed()* to two separate queues. Other 302*8ea61889SMauro Carvalho Chehabdata that is specific to a minor drive, can be accessed through *handle*, 303*8ea61889SMauro Carvalho Chehabwhich can point to a data structure specific to the low-level driver. 304*8ea61889SMauro Carvalho ChehabThe fields *use_count*, *next*, *options* and *mc_flags* need not be 305*8ea61889SMauro Carvalho Chehabinitialized. 306*8ea61889SMauro Carvalho Chehab 307*8ea61889SMauro Carvalho ChehabThe intermediate software layer that `cdrom.c` forms will perform some 308*8ea61889SMauro Carvalho Chehabadditional bookkeeping. The use count of the device (the number of 309*8ea61889SMauro Carvalho Chehabprocesses that have the device opened) is registered in *use_count*. The 310*8ea61889SMauro Carvalho Chehabfunction *cdrom_ioctl()* will verify the appropriate user-memory regions 311*8ea61889SMauro Carvalho Chehabfor read and write, and in case a location on the CD is transferred, 312*8ea61889SMauro Carvalho Chehabit will `sanitize` the format by making requests to the low-level 313*8ea61889SMauro Carvalho Chehabdrivers in a standard format, and translating all formats between the 314*8ea61889SMauro Carvalho Chehabuser-software and low level drivers. This relieves much of the drivers' 315*8ea61889SMauro Carvalho Chehabmemory checking and format checking and translation. Also, the necessary 316*8ea61889SMauro Carvalho Chehabstructures will be declared on the program stack. 317*8ea61889SMauro Carvalho Chehab 318*8ea61889SMauro Carvalho ChehabThe implementation of the functions should be as defined in the 319*8ea61889SMauro Carvalho Chehabfollowing sections. Two functions **must** be implemented, namely 320*8ea61889SMauro Carvalho Chehab*open()* and *release()*. Other functions may be omitted, their 321*8ea61889SMauro Carvalho Chehabcorresponding capability flags will be cleared upon registration. 322*8ea61889SMauro Carvalho ChehabGenerally, a function returns zero on success and negative on error. A 323*8ea61889SMauro Carvalho Chehabfunction call should return only after the command has completed, but of 324*8ea61889SMauro Carvalho Chehabcourse waiting for the device should not use processor time. 325*8ea61889SMauro Carvalho Chehab 326*8ea61889SMauro Carvalho Chehab:: 327*8ea61889SMauro Carvalho Chehab 328*8ea61889SMauro Carvalho Chehab int open(struct cdrom_device_info *cdi, int purpose) 329*8ea61889SMauro Carvalho Chehab 330*8ea61889SMauro Carvalho Chehab*Open()* should try to open the device for a specific *purpose*, which 331*8ea61889SMauro Carvalho Chehabcan be either: 332*8ea61889SMauro Carvalho Chehab 333*8ea61889SMauro Carvalho Chehab- Open for reading data, as done by `mount()` (2), or the 334*8ea61889SMauro Carvalho Chehab user commands `dd` or `cat`. 335*8ea61889SMauro Carvalho Chehab- Open for *ioctl* commands, as done by audio-CD playing programs. 336*8ea61889SMauro Carvalho Chehab 337*8ea61889SMauro Carvalho ChehabNotice that any strategic code (closing tray upon *open()*, etc.) is 338*8ea61889SMauro Carvalho Chehabdone by the calling routine in `cdrom.c`, so the low-level routine 339*8ea61889SMauro Carvalho Chehabshould only be concerned with proper initialization, such as spinning 340*8ea61889SMauro Carvalho Chehabup the disc, etc. 341*8ea61889SMauro Carvalho Chehab 342*8ea61889SMauro Carvalho Chehab:: 343*8ea61889SMauro Carvalho Chehab 344*8ea61889SMauro Carvalho Chehab void release(struct cdrom_device_info *cdi) 345*8ea61889SMauro Carvalho Chehab 346*8ea61889SMauro Carvalho ChehabDevice-specific actions should be taken such as spinning down the device. 347*8ea61889SMauro Carvalho ChehabHowever, strategic actions such as ejection of the tray, or unlocking 348*8ea61889SMauro Carvalho Chehabthe door, should be left over to the general routine *cdrom_release()*. 349*8ea61889SMauro Carvalho ChehabThis is the only function returning type *void*. 350*8ea61889SMauro Carvalho Chehab 351*8ea61889SMauro Carvalho Chehab.. _cdrom_drive_status: 352*8ea61889SMauro Carvalho Chehab 353*8ea61889SMauro Carvalho Chehab:: 354*8ea61889SMauro Carvalho Chehab 355*8ea61889SMauro Carvalho Chehab int drive_status(struct cdrom_device_info *cdi, int slot_nr) 356*8ea61889SMauro Carvalho Chehab 357*8ea61889SMauro Carvalho ChehabThe function *drive_status*, if implemented, should provide 358*8ea61889SMauro Carvalho Chehabinformation on the status of the drive (not the status of the disc, 359*8ea61889SMauro Carvalho Chehabwhich may or may not be in the drive). If the drive is not a changer, 360*8ea61889SMauro Carvalho Chehab*slot_nr* should be ignored. In `cdrom.h` the possibilities are listed:: 361*8ea61889SMauro Carvalho Chehab 362*8ea61889SMauro Carvalho Chehab 363*8ea61889SMauro Carvalho Chehab CDS_NO_INFO /* no information available */ 364*8ea61889SMauro Carvalho Chehab CDS_NO_DISC /* no disc is inserted, tray is closed */ 365*8ea61889SMauro Carvalho Chehab CDS_TRAY_OPEN /* tray is opened */ 366*8ea61889SMauro Carvalho Chehab CDS_DRIVE_NOT_READY /* something is wrong, tray is moving? */ 367*8ea61889SMauro Carvalho Chehab CDS_DISC_OK /* a disc is loaded and everything is fine */ 368*8ea61889SMauro Carvalho Chehab 369*8ea61889SMauro Carvalho Chehab:: 370*8ea61889SMauro Carvalho Chehab 371*8ea61889SMauro Carvalho Chehab int media_changed(struct cdrom_device_info *cdi, int disc_nr) 372*8ea61889SMauro Carvalho Chehab 373*8ea61889SMauro Carvalho ChehabThis function is very similar to the original function in $struct 374*8ea61889SMauro Carvalho Chehabfile_operations*. It returns 1 if the medium of the device *cdi->dev* 375*8ea61889SMauro Carvalho Chehabhas changed since the last call, and 0 otherwise. The parameter 376*8ea61889SMauro Carvalho Chehab*disc_nr* identifies a specific slot in a juke-box, it should be 377*8ea61889SMauro Carvalho Chehabignored for single-disc drives. Note that by `re-routing` this 378*8ea61889SMauro Carvalho Chehabfunction through *cdrom_media_changed()*, we can implement separate 379*8ea61889SMauro Carvalho Chehabqueues for the VFS and a new *ioctl()* function that can report device 380*8ea61889SMauro Carvalho Chehabchanges to software (e. g., an auto-mounting daemon). 381*8ea61889SMauro Carvalho Chehab 382*8ea61889SMauro Carvalho Chehab:: 383*8ea61889SMauro Carvalho Chehab 384*8ea61889SMauro Carvalho Chehab int tray_move(struct cdrom_device_info *cdi, int position) 385*8ea61889SMauro Carvalho Chehab 386*8ea61889SMauro Carvalho ChehabThis function, if implemented, should control the tray movement. (No 387*8ea61889SMauro Carvalho Chehabother function should control this.) The parameter *position* controls 388*8ea61889SMauro Carvalho Chehabthe desired direction of movement: 389*8ea61889SMauro Carvalho Chehab 390*8ea61889SMauro Carvalho Chehab- 0 Close tray 391*8ea61889SMauro Carvalho Chehab- 1 Open tray 392*8ea61889SMauro Carvalho Chehab 393*8ea61889SMauro Carvalho ChehabThis function returns 0 upon success, and a non-zero value upon 394*8ea61889SMauro Carvalho Chehaberror. Note that if the tray is already in the desired position, no 395*8ea61889SMauro Carvalho Chehabaction need be taken, and the return value should be 0. 396*8ea61889SMauro Carvalho Chehab 397*8ea61889SMauro Carvalho Chehab:: 398*8ea61889SMauro Carvalho Chehab 399*8ea61889SMauro Carvalho Chehab int lock_door(struct cdrom_device_info *cdi, int lock) 400*8ea61889SMauro Carvalho Chehab 401*8ea61889SMauro Carvalho ChehabThis function (and no other code) controls locking of the door, if the 402*8ea61889SMauro Carvalho Chehabdrive allows this. The value of *lock* controls the desired locking 403*8ea61889SMauro Carvalho Chehabstate: 404*8ea61889SMauro Carvalho Chehab 405*8ea61889SMauro Carvalho Chehab- 0 Unlock door, manual opening is allowed 406*8ea61889SMauro Carvalho Chehab- 1 Lock door, tray cannot be ejected manually 407*8ea61889SMauro Carvalho Chehab 408*8ea61889SMauro Carvalho ChehabThis function returns 0 upon success, and a non-zero value upon 409*8ea61889SMauro Carvalho Chehaberror. Note that if the door is already in the requested state, no 410*8ea61889SMauro Carvalho Chehabaction need be taken, and the return value should be 0. 411*8ea61889SMauro Carvalho Chehab 412*8ea61889SMauro Carvalho Chehab:: 413*8ea61889SMauro Carvalho Chehab 414*8ea61889SMauro Carvalho Chehab int select_speed(struct cdrom_device_info *cdi, int speed) 415*8ea61889SMauro Carvalho Chehab 416*8ea61889SMauro Carvalho ChehabSome CD-ROM drives are capable of changing their head-speed. There 417*8ea61889SMauro Carvalho Chehabare several reasons for changing the speed of a CD-ROM drive. Badly 418*8ea61889SMauro Carvalho Chehabpressed CD-ROM s may benefit from less-than-maximum head rate. Modern 419*8ea61889SMauro Carvalho ChehabCD-ROM drives can obtain very high head rates (up to *24x* is 420*8ea61889SMauro Carvalho Chehabcommon). It has been reported that these drives can make reading 421*8ea61889SMauro Carvalho Chehaberrors at these high speeds, reducing the speed can prevent data loss 422*8ea61889SMauro Carvalho Chehabin these circumstances. Finally, some of these drives can 423*8ea61889SMauro Carvalho Chehabmake an annoyingly loud noise, which a lower speed may reduce. 424*8ea61889SMauro Carvalho Chehab 425*8ea61889SMauro Carvalho ChehabThis function specifies the speed at which data is read or audio is 426*8ea61889SMauro Carvalho Chehabplayed back. The value of *speed* specifies the head-speed of the 427*8ea61889SMauro Carvalho Chehabdrive, measured in units of standard cdrom speed (176kB/sec raw data 428*8ea61889SMauro Carvalho Chehabor 150kB/sec file system data). So to request that a CD-ROM drive 429*8ea61889SMauro Carvalho Chehaboperate at 300kB/sec you would call the CDROM_SELECT_SPEED *ioctl* 430*8ea61889SMauro Carvalho Chehabwith *speed=2*. The special value `0` means `auto-selection`, i. e., 431*8ea61889SMauro Carvalho Chehabmaximum data-rate or real-time audio rate. If the drive doesn't have 432*8ea61889SMauro Carvalho Chehabthis `auto-selection` capability, the decision should be made on the 433*8ea61889SMauro Carvalho Chehabcurrent disc loaded and the return value should be positive. A negative 434*8ea61889SMauro Carvalho Chehabreturn value indicates an error. 435*8ea61889SMauro Carvalho Chehab 436*8ea61889SMauro Carvalho Chehab:: 437*8ea61889SMauro Carvalho Chehab 438*8ea61889SMauro Carvalho Chehab int select_disc(struct cdrom_device_info *cdi, int number) 439*8ea61889SMauro Carvalho Chehab 440*8ea61889SMauro Carvalho ChehabIf the drive can store multiple discs (a juke-box) this function 441*8ea61889SMauro Carvalho Chehabwill perform disc selection. It should return the number of the 442*8ea61889SMauro Carvalho Chehabselected disc on success, a negative value on error. Currently, only 443*8ea61889SMauro Carvalho Chehabthe ide-cd driver supports this functionality. 444*8ea61889SMauro Carvalho Chehab 445*8ea61889SMauro Carvalho Chehab:: 446*8ea61889SMauro Carvalho Chehab 447*8ea61889SMauro Carvalho Chehab int get_last_session(struct cdrom_device_info *cdi, 448*8ea61889SMauro Carvalho Chehab struct cdrom_multisession *ms_info) 449*8ea61889SMauro Carvalho Chehab 450*8ea61889SMauro Carvalho ChehabThis function should implement the old corresponding *ioctl()*. For 451*8ea61889SMauro Carvalho Chehabdevice *cdi->dev*, the start of the last session of the current disc 452*8ea61889SMauro Carvalho Chehabshould be returned in the pointer argument *ms_info*. Note that 453*8ea61889SMauro Carvalho Chehabroutines in `cdrom.c` have sanitized this argument: its requested 454*8ea61889SMauro Carvalho Chehabformat will **always** be of the type *CDROM_LBA* (linear block 455*8ea61889SMauro Carvalho Chehabaddressing mode), whatever the calling software requested. But 456*8ea61889SMauro Carvalho Chehabsanitization goes even further: the low-level implementation may 457*8ea61889SMauro Carvalho Chehabreturn the requested information in *CDROM_MSF* format if it wishes so 458*8ea61889SMauro Carvalho Chehab(setting the *ms_info->addr_format* field appropriately, of 459*8ea61889SMauro Carvalho Chehabcourse) and the routines in `cdrom.c` will make the transformation if 460*8ea61889SMauro Carvalho Chehabnecessary. The return value is 0 upon success. 461*8ea61889SMauro Carvalho Chehab 462*8ea61889SMauro Carvalho Chehab:: 463*8ea61889SMauro Carvalho Chehab 464*8ea61889SMauro Carvalho Chehab int get_mcn(struct cdrom_device_info *cdi, 465*8ea61889SMauro Carvalho Chehab struct cdrom_mcn *mcn) 466*8ea61889SMauro Carvalho Chehab 467*8ea61889SMauro Carvalho ChehabSome discs carry a `Media Catalog Number` (MCN), also called 468*8ea61889SMauro Carvalho Chehab`Universal Product Code` (UPC). This number should reflect the number 469*8ea61889SMauro Carvalho Chehabthat is generally found in the bar-code on the product. Unfortunately, 470*8ea61889SMauro Carvalho Chehabthe few discs that carry such a number on the disc don't even use the 471*8ea61889SMauro Carvalho Chehabsame format. The return argument to this function is a pointer to a 472*8ea61889SMauro Carvalho Chehabpre-declared memory region of type *struct cdrom_mcn*. The MCN is 473*8ea61889SMauro Carvalho Chehabexpected as a 13-character string, terminated by a null-character. 474*8ea61889SMauro Carvalho Chehab 475*8ea61889SMauro Carvalho Chehab:: 476*8ea61889SMauro Carvalho Chehab 477*8ea61889SMauro Carvalho Chehab int reset(struct cdrom_device_info *cdi) 478*8ea61889SMauro Carvalho Chehab 479*8ea61889SMauro Carvalho ChehabThis call should perform a hard-reset on the drive (although in 480*8ea61889SMauro Carvalho Chehabcircumstances that a hard-reset is necessary, a drive may very well not 481*8ea61889SMauro Carvalho Chehablisten to commands anymore). Preferably, control is returned to the 482*8ea61889SMauro Carvalho Chehabcaller only after the drive has finished resetting. If the drive is no 483*8ea61889SMauro Carvalho Chehablonger listening, it may be wise for the underlying low-level cdrom 484*8ea61889SMauro Carvalho Chehabdriver to time out. 485*8ea61889SMauro Carvalho Chehab 486*8ea61889SMauro Carvalho Chehab:: 487*8ea61889SMauro Carvalho Chehab 488*8ea61889SMauro Carvalho Chehab int audio_ioctl(struct cdrom_device_info *cdi, 489*8ea61889SMauro Carvalho Chehab unsigned int cmd, void *arg) 490*8ea61889SMauro Carvalho Chehab 491*8ea61889SMauro Carvalho ChehabSome of the CD-ROM-\ *ioctl()*\ 's defined in `cdrom.h` can be 492*8ea61889SMauro Carvalho Chehabimplemented by the routines described above, and hence the function 493*8ea61889SMauro Carvalho Chehab*cdrom_ioctl* will use those. However, most *ioctl()*\ 's deal with 494*8ea61889SMauro Carvalho Chehabaudio-control. We have decided to leave these to be accessed through a 495*8ea61889SMauro Carvalho Chehabsingle function, repeating the arguments *cmd* and *arg*. Note that 496*8ea61889SMauro Carvalho Chehabthe latter is of type *void*, rather than *unsigned long int*. 497*8ea61889SMauro Carvalho ChehabThe routine *cdrom_ioctl()* does do some useful things, 498*8ea61889SMauro Carvalho Chehabthough. It sanitizes the address format type to *CDROM_MSF* (Minutes, 499*8ea61889SMauro Carvalho ChehabSeconds, Frames) for all audio calls. It also verifies the memory 500*8ea61889SMauro Carvalho Chehablocation of *arg*, and reserves stack-memory for the argument. This 501*8ea61889SMauro Carvalho Chehabmakes implementation of the *audio_ioctl()* much simpler than in the 502*8ea61889SMauro Carvalho Chehabold driver scheme. For example, you may look up the function 503*8ea61889SMauro Carvalho Chehab*cm206_audio_ioctl()* `cm206.c` that should be updated with 504*8ea61889SMauro Carvalho Chehabthis documentation. 505*8ea61889SMauro Carvalho Chehab 506*8ea61889SMauro Carvalho ChehabAn unimplemented ioctl should return *-ENOSYS*, but a harmless request 507*8ea61889SMauro Carvalho Chehab(e. g., *CDROMSTART*) may be ignored by returning 0 (success). Other 508*8ea61889SMauro Carvalho Chehaberrors should be according to the standards, whatever they are. When 509*8ea61889SMauro Carvalho Chehaban error is returned by the low-level driver, the Uniform CD-ROM Driver 510*8ea61889SMauro Carvalho Chehabtries whenever possible to return the error code to the calling program. 511*8ea61889SMauro Carvalho Chehab(We may decide to sanitize the return value in *cdrom_ioctl()* though, in 512*8ea61889SMauro Carvalho Chehaborder to guarantee a uniform interface to the audio-player software.) 513*8ea61889SMauro Carvalho Chehab 514*8ea61889SMauro Carvalho Chehab:: 515*8ea61889SMauro Carvalho Chehab 516*8ea61889SMauro Carvalho Chehab int dev_ioctl(struct cdrom_device_info *cdi, 517*8ea61889SMauro Carvalho Chehab unsigned int cmd, unsigned long arg) 518*8ea61889SMauro Carvalho Chehab 519*8ea61889SMauro Carvalho ChehabSome *ioctl()'s* seem to be specific to certain CD-ROM drives. That is, 520*8ea61889SMauro Carvalho Chehabthey are introduced to service some capabilities of certain drives. In 521*8ea61889SMauro Carvalho Chehabfact, there are 6 different *ioctl()'s* for reading data, either in some 522*8ea61889SMauro Carvalho Chehabparticular kind of format, or audio data. Not many drives support 523*8ea61889SMauro Carvalho Chehabreading audio tracks as data, I believe this is because of protection 524*8ea61889SMauro Carvalho Chehabof copyrights of artists. Moreover, I think that if audio-tracks are 525*8ea61889SMauro Carvalho Chehabsupported, it should be done through the VFS and not via *ioctl()'s*. A 526*8ea61889SMauro Carvalho Chehabproblem here could be the fact that audio-frames are 2352 bytes long, 527*8ea61889SMauro Carvalho Chehabso either the audio-file-system should ask for 75264 bytes at once 528*8ea61889SMauro Carvalho Chehab(the least common multiple of 512 and 2352), or the drivers should 529*8ea61889SMauro Carvalho Chehabbend their backs to cope with this incoherence (to which I would be 530*8ea61889SMauro Carvalho Chehabopposed). Furthermore, it is very difficult for the hardware to find 531*8ea61889SMauro Carvalho Chehabthe exact frame boundaries, since there are no synchronization headers 532*8ea61889SMauro Carvalho Chehabin audio frames. Once these issues are resolved, this code should be 533*8ea61889SMauro Carvalho Chehabstandardized in `cdrom.c`. 534*8ea61889SMauro Carvalho Chehab 535*8ea61889SMauro Carvalho ChehabBecause there are so many *ioctl()'s* that seem to be introduced to 536*8ea61889SMauro Carvalho Chehabsatisfy certain drivers [#f2]_, any non-standard *ioctl()*\ s 537*8ea61889SMauro Carvalho Chehabare routed through the call *dev_ioctl()*. In principle, `private` 538*8ea61889SMauro Carvalho Chehab*ioctl()*\ 's should be numbered after the device's major number, and not 539*8ea61889SMauro Carvalho Chehabthe general CD-ROM *ioctl* number, `0x53`. Currently the 540*8ea61889SMauro Carvalho Chehabnon-supported *ioctl()'s* are: 541*8ea61889SMauro Carvalho Chehab 542*8ea61889SMauro Carvalho Chehab CDROMREADMODE1, CDROMREADMODE2, CDROMREADAUDIO, CDROMREADRAW, 543*8ea61889SMauro Carvalho Chehab CDROMREADCOOKED, CDROMSEEK, CDROMPLAY-BLK and CDROM-READALL 544*8ea61889SMauro Carvalho Chehab 545*8ea61889SMauro Carvalho Chehab.. [#f2] 546*8ea61889SMauro Carvalho Chehab 547*8ea61889SMauro Carvalho Chehab Is there software around that actually uses these? I'd be interested! 548*8ea61889SMauro Carvalho Chehab 549*8ea61889SMauro Carvalho Chehab.. _cdrom_capabilities: 550*8ea61889SMauro Carvalho Chehab 551*8ea61889SMauro Carvalho ChehabCD-ROM capabilities 552*8ea61889SMauro Carvalho Chehab------------------- 553*8ea61889SMauro Carvalho Chehab 554*8ea61889SMauro Carvalho ChehabInstead of just implementing some *ioctl* calls, the interface in 555*8ea61889SMauro Carvalho Chehab`cdrom.c` supplies the possibility to indicate the **capabilities** 556*8ea61889SMauro Carvalho Chehabof a CD-ROM drive. This can be done by ORing any number of 557*8ea61889SMauro Carvalho Chehabcapability-constants that are defined in `cdrom.h` at the registration 558*8ea61889SMauro Carvalho Chehabphase. Currently, the capabilities are any of:: 559*8ea61889SMauro Carvalho Chehab 560*8ea61889SMauro Carvalho Chehab CDC_CLOSE_TRAY /* can close tray by software control */ 561*8ea61889SMauro Carvalho Chehab CDC_OPEN_TRAY /* can open tray */ 562*8ea61889SMauro Carvalho Chehab CDC_LOCK /* can lock and unlock the door */ 563*8ea61889SMauro Carvalho Chehab CDC_SELECT_SPEED /* can select speed, in units of * sim*150 ,kB/s */ 564*8ea61889SMauro Carvalho Chehab CDC_SELECT_DISC /* drive is juke-box */ 565*8ea61889SMauro Carvalho Chehab CDC_MULTI_SESSION /* can read sessions *> rm1* */ 566*8ea61889SMauro Carvalho Chehab CDC_MCN /* can read Media Catalog Number */ 567*8ea61889SMauro Carvalho Chehab CDC_MEDIA_CHANGED /* can report if disc has changed */ 568*8ea61889SMauro Carvalho Chehab CDC_PLAY_AUDIO /* can perform audio-functions (play, pause, etc) */ 569*8ea61889SMauro Carvalho Chehab CDC_RESET /* hard reset device */ 570*8ea61889SMauro Carvalho Chehab CDC_IOCTLS /* driver has non-standard ioctls */ 571*8ea61889SMauro Carvalho Chehab CDC_DRIVE_STATUS /* driver implements drive status */ 572*8ea61889SMauro Carvalho Chehab 573*8ea61889SMauro Carvalho ChehabThe capability flag is declared *const*, to prevent drivers from 574*8ea61889SMauro Carvalho Chehabaccidentally tampering with the contents. The capability fags actually 575*8ea61889SMauro Carvalho Chehabinform `cdrom.c` of what the driver can do. If the drive found 576*8ea61889SMauro Carvalho Chehabby the driver does not have the capability, is can be masked out by 577*8ea61889SMauro Carvalho Chehabthe *cdrom_device_info* variable *mask*. For instance, the SCSI CD-ROM 578*8ea61889SMauro Carvalho Chehabdriver has implemented the code for loading and ejecting CD-ROM's, and 579*8ea61889SMauro Carvalho Chehabhence its corresponding flags in *capability* will be set. But a SCSI 580*8ea61889SMauro Carvalho ChehabCD-ROM drive might be a caddy system, which can't load the tray, and 581*8ea61889SMauro Carvalho Chehabhence for this drive the *cdrom_device_info* struct will have set 582*8ea61889SMauro Carvalho Chehabthe *CDC_CLOSE_TRAY* bit in *mask*. 583*8ea61889SMauro Carvalho Chehab 584*8ea61889SMauro Carvalho ChehabIn the file `cdrom.c` you will encounter many constructions of the type:: 585*8ea61889SMauro Carvalho Chehab 586*8ea61889SMauro Carvalho Chehab if (cdo->capability & ∼cdi->mask & CDC _⟨capability⟩) ... 587*8ea61889SMauro Carvalho Chehab 588*8ea61889SMauro Carvalho ChehabThere is no *ioctl* to set the mask... The reason is that 589*8ea61889SMauro Carvalho ChehabI think it is better to control the **behavior** rather than the 590*8ea61889SMauro Carvalho Chehab**capabilities**. 591*8ea61889SMauro Carvalho Chehab 592*8ea61889SMauro Carvalho ChehabOptions 593*8ea61889SMauro Carvalho Chehab------- 594*8ea61889SMauro Carvalho Chehab 595*8ea61889SMauro Carvalho ChehabA final flag register controls the **behavior** of the CD-ROM 596*8ea61889SMauro Carvalho Chehabdrives, in order to satisfy different users' wishes, hopefully 597*8ea61889SMauro Carvalho Chehabindependently of the ideas of the respective author who happened to 598*8ea61889SMauro Carvalho Chehabhave made the drive's support available to the Linux community. The 599*8ea61889SMauro Carvalho Chehabcurrent behavior options are:: 600*8ea61889SMauro Carvalho Chehab 601*8ea61889SMauro Carvalho Chehab CDO_AUTO_CLOSE /* try to close tray upon device open() */ 602*8ea61889SMauro Carvalho Chehab CDO_AUTO_EJECT /* try to open tray on last device close() */ 603*8ea61889SMauro Carvalho Chehab CDO_USE_FFLAGS /* use file_pointer->f_flags to indicate purpose for open() */ 604*8ea61889SMauro Carvalho Chehab CDO_LOCK /* try to lock door if device is opened */ 605*8ea61889SMauro Carvalho Chehab CDO_CHECK_TYPE /* ensure disc type is data if opened for data */ 606*8ea61889SMauro Carvalho Chehab 607*8ea61889SMauro Carvalho ChehabThe initial value of this register is 608*8ea61889SMauro Carvalho Chehab`CDO_AUTO_CLOSE | CDO_USE_FFLAGS | CDO_LOCK`, reflecting my own view on user 609*8ea61889SMauro Carvalho Chehabinterface and software standards. Before you protest, there are two 610*8ea61889SMauro Carvalho Chehabnew *ioctl()'s* implemented in `cdrom.c`, that allow you to control the 611*8ea61889SMauro Carvalho Chehabbehavior by software. These are:: 612*8ea61889SMauro Carvalho Chehab 613*8ea61889SMauro Carvalho Chehab CDROM_SET_OPTIONS /* set options specified in (int)arg */ 614*8ea61889SMauro Carvalho Chehab CDROM_CLEAR_OPTIONS /* clear options specified in (int)arg */ 615*8ea61889SMauro Carvalho Chehab 616*8ea61889SMauro Carvalho ChehabOne option needs some more explanation: *CDO_USE_FFLAGS*. In the next 617*8ea61889SMauro Carvalho Chehabnewsection we explain what the need for this option is. 618*8ea61889SMauro Carvalho Chehab 619*8ea61889SMauro Carvalho ChehabA software package `setcd`, available from the Debian distribution 620*8ea61889SMauro Carvalho Chehaband `sunsite.unc.edu`, allows user level control of these flags. 621*8ea61889SMauro Carvalho Chehab 622*8ea61889SMauro Carvalho Chehab 623*8ea61889SMauro Carvalho ChehabThe need to know the purpose of opening the CD-ROM device 624*8ea61889SMauro Carvalho Chehab========================================================= 625*8ea61889SMauro Carvalho Chehab 626*8ea61889SMauro Carvalho ChehabTraditionally, Unix devices can be used in two different `modes`, 627*8ea61889SMauro Carvalho Chehabeither by reading/writing to the device file, or by issuing 628*8ea61889SMauro Carvalho Chehabcontrolling commands to the device, by the device's *ioctl()* 629*8ea61889SMauro Carvalho Chehabcall. The problem with CD-ROM drives, is that they can be used for 630*8ea61889SMauro Carvalho Chehabtwo entirely different purposes. One is to mount removable 631*8ea61889SMauro Carvalho Chehabfile systems, CD-ROM's, the other is to play audio CD's. Audio commands 632*8ea61889SMauro Carvalho Chehabare implemented entirely through *ioctl()\'s*, presumably because the 633*8ea61889SMauro Carvalho Chehabfirst implementation (SUN?) has been such. In principle there is 634*8ea61889SMauro Carvalho Chehabnothing wrong with this, but a good control of the `CD player` demands 635*8ea61889SMauro Carvalho Chehabthat the device can **always** be opened in order to give the 636*8ea61889SMauro Carvalho Chehab*ioctl* commands, regardless of the state the drive is in. 637*8ea61889SMauro Carvalho Chehab 638*8ea61889SMauro Carvalho ChehabOn the other hand, when used as a removable-media disc drive (what the 639*8ea61889SMauro Carvalho Chehaboriginal purpose of CD-ROM s is) we would like to make sure that the 640*8ea61889SMauro Carvalho Chehabdisc drive is ready for operation upon opening the device. In the old 641*8ea61889SMauro Carvalho Chehabscheme, some CD-ROM drivers don't do any integrity checking, resulting 642*8ea61889SMauro Carvalho Chehabin a number of i/o errors reported by the VFS to the kernel when an 643*8ea61889SMauro Carvalho Chehabattempt for mounting a CD-ROM on an empty drive occurs. This is not a 644*8ea61889SMauro Carvalho Chehabparticularly elegant way to find out that there is no CD-ROM inserted; 645*8ea61889SMauro Carvalho Chehabit more-or-less looks like the old IBM-PC trying to read an empty floppy 646*8ea61889SMauro Carvalho Chehabdrive for a couple of seconds, after which the system complains it 647*8ea61889SMauro Carvalho Chehabcan't read from it. Nowadays we can **sense** the existence of a 648*8ea61889SMauro Carvalho Chehabremovable medium in a drive, and we believe we should exploit that 649*8ea61889SMauro Carvalho Chehabfact. An integrity check on opening of the device, that verifies the 650*8ea61889SMauro Carvalho Chehabavailability of a CD-ROM and its correct type (data), would be 651*8ea61889SMauro Carvalho Chehabdesirable. 652*8ea61889SMauro Carvalho Chehab 653*8ea61889SMauro Carvalho ChehabThese two ways of using a CD-ROM drive, principally for data and 654*8ea61889SMauro Carvalho Chehabsecondarily for playing audio discs, have different demands for the 655*8ea61889SMauro Carvalho Chehabbehavior of the *open()* call. Audio use simply wants to open the 656*8ea61889SMauro Carvalho Chehabdevice in order to get a file handle which is needed for issuing 657*8ea61889SMauro Carvalho Chehab*ioctl* commands, while data use wants to open for correct and 658*8ea61889SMauro Carvalho Chehabreliable data transfer. The only way user programs can indicate what 659*8ea61889SMauro Carvalho Chehabtheir *purpose* of opening the device is, is through the *flags* 660*8ea61889SMauro Carvalho Chehabparameter (see `open(2)`). For CD-ROM devices, these flags aren't 661*8ea61889SMauro Carvalho Chehabimplemented (some drivers implement checking for write-related flags, 662*8ea61889SMauro Carvalho Chehabbut this is not strictly necessary if the device file has correct 663*8ea61889SMauro Carvalho Chehabpermission flags). Most option flags simply don't make sense to 664*8ea61889SMauro Carvalho ChehabCD-ROM devices: *O_CREAT*, *O_NOCTTY*, *O_TRUNC*, *O_APPEND*, and 665*8ea61889SMauro Carvalho Chehab*O_SYNC* have no meaning to a CD-ROM. 666*8ea61889SMauro Carvalho Chehab 667*8ea61889SMauro Carvalho ChehabWe therefore propose to use the flag *O_NONBLOCK* to indicate 668*8ea61889SMauro Carvalho Chehabthat the device is opened just for issuing *ioctl* 669*8ea61889SMauro Carvalho Chehabcommands. Strictly, the meaning of *O_NONBLOCK* is that opening and 670*8ea61889SMauro Carvalho Chehabsubsequent calls to the device don't cause the calling process to 671*8ea61889SMauro Carvalho Chehabwait. We could interpret this as don't wait until someone has 672*8ea61889SMauro Carvalho Chehabinserted some valid data-CD-ROM. Thus, our proposal of the 673*8ea61889SMauro Carvalho Chehabimplementation for the *open()* call for CD-ROM s is: 674*8ea61889SMauro Carvalho Chehab 675*8ea61889SMauro Carvalho Chehab- If no other flags are set than *O_RDONLY*, the device is opened 676*8ea61889SMauro Carvalho Chehab for data transfer, and the return value will be 0 only upon successful 677*8ea61889SMauro Carvalho Chehab initialization of the transfer. The call may even induce some actions 678*8ea61889SMauro Carvalho Chehab on the CD-ROM, such as closing the tray. 679*8ea61889SMauro Carvalho Chehab- If the option flag *O_NONBLOCK* is set, opening will always be 680*8ea61889SMauro Carvalho Chehab successful, unless the whole device doesn't exist. The drive will take 681*8ea61889SMauro Carvalho Chehab no actions whatsoever. 682*8ea61889SMauro Carvalho Chehab 683*8ea61889SMauro Carvalho ChehabAnd what about standards? 684*8ea61889SMauro Carvalho Chehab------------------------- 685*8ea61889SMauro Carvalho Chehab 686*8ea61889SMauro Carvalho ChehabYou might hesitate to accept this proposal as it comes from the 687*8ea61889SMauro Carvalho ChehabLinux community, and not from some standardizing institute. What 688*8ea61889SMauro Carvalho Chehababout SUN, SGI, HP and all those other Unix and hardware vendors? 689*8ea61889SMauro Carvalho ChehabWell, these companies are in the lucky position that they generally 690*8ea61889SMauro Carvalho Chehabcontrol both the hardware and software of their supported products, 691*8ea61889SMauro Carvalho Chehaband are large enough to set their own standard. They do not have to 692*8ea61889SMauro Carvalho Chehabdeal with a dozen or more different, competing hardware 693*8ea61889SMauro Carvalho Chehabconfigurations\ [#f3]_. 694*8ea61889SMauro Carvalho Chehab 695*8ea61889SMauro Carvalho Chehab.. [#f3] 696*8ea61889SMauro Carvalho Chehab 697*8ea61889SMauro Carvalho Chehab Incidentally, I think that SUN's approach to mounting CD-ROM s is very 698*8ea61889SMauro Carvalho Chehab good in origin: under Solaris a volume-daemon automatically mounts a 699*8ea61889SMauro Carvalho Chehab newly inserted CD-ROM under `/cdrom/*<volume-name>*`. 700*8ea61889SMauro Carvalho Chehab 701*8ea61889SMauro Carvalho Chehab In my opinion they should have pushed this 702*8ea61889SMauro Carvalho Chehab further and have **every** CD-ROM on the local area network be 703*8ea61889SMauro Carvalho Chehab mounted at the similar location, i. e., no matter in which particular 704*8ea61889SMauro Carvalho Chehab machine you insert a CD-ROM, it will always appear at the same 705*8ea61889SMauro Carvalho Chehab position in the directory tree, on every system. When I wanted to 706*8ea61889SMauro Carvalho Chehab implement such a user-program for Linux, I came across the 707*8ea61889SMauro Carvalho Chehab differences in behavior of the various drivers, and the need for an 708*8ea61889SMauro Carvalho Chehab *ioctl* informing about media changes. 709*8ea61889SMauro Carvalho Chehab 710*8ea61889SMauro Carvalho ChehabWe believe that using *O_NONBLOCK* to indicate that a device is being opened 711*8ea61889SMauro Carvalho Chehabfor *ioctl* commands only can be easily introduced in the Linux 712*8ea61889SMauro Carvalho Chehabcommunity. All the CD-player authors will have to be informed, we can 713*8ea61889SMauro Carvalho Chehabeven send in our own patches to the programs. The use of *O_NONBLOCK* 714*8ea61889SMauro Carvalho Chehabhas most likely no influence on the behavior of the CD-players on 715*8ea61889SMauro Carvalho Chehabother operating systems than Linux. Finally, a user can always revert 716*8ea61889SMauro Carvalho Chehabto old behavior by a call to 717*8ea61889SMauro Carvalho Chehab*ioctl(file_descriptor, CDROM_CLEAR_OPTIONS, CDO_USE_FFLAGS)*. 718*8ea61889SMauro Carvalho Chehab 719*8ea61889SMauro Carvalho ChehabThe preferred strategy of *open()* 720*8ea61889SMauro Carvalho Chehab---------------------------------- 721*8ea61889SMauro Carvalho Chehab 722*8ea61889SMauro Carvalho ChehabThe routines in `cdrom.c` are designed in such a way that run-time 723*8ea61889SMauro Carvalho Chehabconfiguration of the behavior of CD-ROM devices (of **any** type) 724*8ea61889SMauro Carvalho Chehabcan be carried out, by the *CDROM_SET/CLEAR_OPTIONS* *ioctls*. Thus, various 725*8ea61889SMauro Carvalho Chehabmodes of operation can be set: 726*8ea61889SMauro Carvalho Chehab 727*8ea61889SMauro Carvalho Chehab`CDO_AUTO_CLOSE | CDO_USE_FFLAGS | CDO_LOCK` 728*8ea61889SMauro Carvalho Chehab This is the default setting. (With *CDO_CHECK_TYPE* it will be better, in 729*8ea61889SMauro Carvalho Chehab the future.) If the device is not yet opened by any other process, and if 730*8ea61889SMauro Carvalho Chehab the device is being opened for data (*O_NONBLOCK* is not set) and the 731*8ea61889SMauro Carvalho Chehab tray is found to be open, an attempt to close the tray is made. Then, 732*8ea61889SMauro Carvalho Chehab it is verified that a disc is in the drive and, if *CDO_CHECK_TYPE* is 733*8ea61889SMauro Carvalho Chehab set, that it contains tracks of type `data mode 1`. Only if all tests 734*8ea61889SMauro Carvalho Chehab are passed is the return value zero. The door is locked to prevent file 735*8ea61889SMauro Carvalho Chehab system corruption. If the drive is opened for audio (*O_NONBLOCK* is 736*8ea61889SMauro Carvalho Chehab set), no actions are taken and a value of 0 will be returned. 737*8ea61889SMauro Carvalho Chehab 738*8ea61889SMauro Carvalho Chehab`CDO_AUTO_CLOSE | CDO_AUTO_EJECT | CDO_LOCK` 739*8ea61889SMauro Carvalho Chehab This mimics the behavior of the current sbpcd-driver. The option flags are 740*8ea61889SMauro Carvalho Chehab ignored, the tray is closed on the first open, if necessary. Similarly, 741*8ea61889SMauro Carvalho Chehab the tray is opened on the last release, i. e., if a CD-ROM is unmounted, 742*8ea61889SMauro Carvalho Chehab it is automatically ejected, such that the user can replace it. 743*8ea61889SMauro Carvalho Chehab 744*8ea61889SMauro Carvalho ChehabWe hope that these option can convince everybody (both driver 745*8ea61889SMauro Carvalho Chehabmaintainers and user program developers) to adopt the new CD-ROM 746*8ea61889SMauro Carvalho Chehabdriver scheme and option flag interpretation. 747*8ea61889SMauro Carvalho Chehab 748*8ea61889SMauro Carvalho ChehabDescription of routines in `cdrom.c` 749*8ea61889SMauro Carvalho Chehab==================================== 750*8ea61889SMauro Carvalho Chehab 751*8ea61889SMauro Carvalho ChehabOnly a few routines in `cdrom.c` are exported to the drivers. In this 752*8ea61889SMauro Carvalho Chehabnew section we will discuss these, as well as the functions that `take 753*8ea61889SMauro Carvalho Chehabover' the CD-ROM interface to the kernel. The header file belonging 754*8ea61889SMauro Carvalho Chehabto `cdrom.c` is called `cdrom.h`. Formerly, some of the contents of this 755*8ea61889SMauro Carvalho Chehabfile were placed in the file `ucdrom.h`, but this file has now been 756*8ea61889SMauro Carvalho Chehabmerged back into `cdrom.h`. 757*8ea61889SMauro Carvalho Chehab 758*8ea61889SMauro Carvalho Chehab:: 759*8ea61889SMauro Carvalho Chehab 760*8ea61889SMauro Carvalho Chehab struct file_operations cdrom_fops 761*8ea61889SMauro Carvalho Chehab 762*8ea61889SMauro Carvalho ChehabThe contents of this structure were described in cdrom_api_. 763*8ea61889SMauro Carvalho ChehabA pointer to this structure is assigned to the *fops* field 764*8ea61889SMauro Carvalho Chehabof the *struct gendisk*. 765*8ea61889SMauro Carvalho Chehab 766*8ea61889SMauro Carvalho Chehab:: 767*8ea61889SMauro Carvalho Chehab 768*8ea61889SMauro Carvalho Chehab int register_cdrom(struct cdrom_device_info *cdi) 769*8ea61889SMauro Carvalho Chehab 770*8ea61889SMauro Carvalho ChehabThis function is used in about the same way one registers *cdrom_fops* 771*8ea61889SMauro Carvalho Chehabwith the kernel, the device operations and information structures, 772*8ea61889SMauro Carvalho Chehabas described in cdrom_api_, should be registered with the 773*8ea61889SMauro Carvalho ChehabUniform CD-ROM Driver:: 774*8ea61889SMauro Carvalho Chehab 775*8ea61889SMauro Carvalho Chehab register_cdrom(&<device>_info); 776*8ea61889SMauro Carvalho Chehab 777*8ea61889SMauro Carvalho Chehab 778*8ea61889SMauro Carvalho ChehabThis function returns zero upon success, and non-zero upon 779*8ea61889SMauro Carvalho Chehabfailure. The structure *<device>_info* should have a pointer to the 780*8ea61889SMauro Carvalho Chehabdriver's *<device>_dops*, as in:: 781*8ea61889SMauro Carvalho Chehab 782*8ea61889SMauro Carvalho Chehab struct cdrom_device_info <device>_info = { 783*8ea61889SMauro Carvalho Chehab <device>_dops; 784*8ea61889SMauro Carvalho Chehab ... 785*8ea61889SMauro Carvalho Chehab } 786*8ea61889SMauro Carvalho Chehab 787*8ea61889SMauro Carvalho ChehabNote that a driver must have one static structure, *<device>_dops*, while 788*8ea61889SMauro Carvalho Chehabit may have as many structures *<device>_info* as there are minor devices 789*8ea61889SMauro Carvalho Chehabactive. *Register_cdrom()* builds a linked list from these. 790*8ea61889SMauro Carvalho Chehab 791*8ea61889SMauro Carvalho Chehab 792*8ea61889SMauro Carvalho Chehab:: 793*8ea61889SMauro Carvalho Chehab 794*8ea61889SMauro Carvalho Chehab void unregister_cdrom(struct cdrom_device_info *cdi) 795*8ea61889SMauro Carvalho Chehab 796*8ea61889SMauro Carvalho ChehabUnregistering device *cdi* with minor number *MINOR(cdi->dev)* removes 797*8ea61889SMauro Carvalho Chehabthe minor device from the list. If it was the last registered minor for 798*8ea61889SMauro Carvalho Chehabthe low-level driver, this disconnects the registered device-operation 799*8ea61889SMauro Carvalho Chehabroutines from the CD-ROM interface. This function returns zero upon 800*8ea61889SMauro Carvalho Chehabsuccess, and non-zero upon failure. 801*8ea61889SMauro Carvalho Chehab 802*8ea61889SMauro Carvalho Chehab:: 803*8ea61889SMauro Carvalho Chehab 804*8ea61889SMauro Carvalho Chehab int cdrom_open(struct inode * ip, struct file * fp) 805*8ea61889SMauro Carvalho Chehab 806*8ea61889SMauro Carvalho ChehabThis function is not called directly by the low-level drivers, it is 807*8ea61889SMauro Carvalho Chehablisted in the standard *cdrom_fops*. If the VFS opens a file, this 808*8ea61889SMauro Carvalho Chehabfunction becomes active. A strategy is implemented in this routine, 809*8ea61889SMauro Carvalho Chehabtaking care of all capabilities and options that are set in the 810*8ea61889SMauro Carvalho Chehab*cdrom_device_ops* connected to the device. Then, the program flow is 811*8ea61889SMauro Carvalho Chehabtransferred to the device_dependent *open()* call. 812*8ea61889SMauro Carvalho Chehab 813*8ea61889SMauro Carvalho Chehab:: 814*8ea61889SMauro Carvalho Chehab 815*8ea61889SMauro Carvalho Chehab void cdrom_release(struct inode *ip, struct file *fp) 816*8ea61889SMauro Carvalho Chehab 817*8ea61889SMauro Carvalho ChehabThis function implements the reverse-logic of *cdrom_open()*, and then 818*8ea61889SMauro Carvalho Chehabcalls the device-dependent *release()* routine. When the use-count has 819*8ea61889SMauro Carvalho Chehabreached 0, the allocated buffers are flushed by calls to *sync_dev(dev)* 820*8ea61889SMauro Carvalho Chehaband *invalidate_buffers(dev)*. 821*8ea61889SMauro Carvalho Chehab 822*8ea61889SMauro Carvalho Chehab 823*8ea61889SMauro Carvalho Chehab.. _cdrom_ioctl: 824*8ea61889SMauro Carvalho Chehab 825*8ea61889SMauro Carvalho Chehab:: 826*8ea61889SMauro Carvalho Chehab 827*8ea61889SMauro Carvalho Chehab int cdrom_ioctl(struct inode *ip, struct file *fp, 828*8ea61889SMauro Carvalho Chehab unsigned int cmd, unsigned long arg) 829*8ea61889SMauro Carvalho Chehab 830*8ea61889SMauro Carvalho ChehabThis function handles all the standard *ioctl* requests for CD-ROM 831*8ea61889SMauro Carvalho Chehabdevices in a uniform way. The different calls fall into three 832*8ea61889SMauro Carvalho Chehabcategories: *ioctl()'s* that can be directly implemented by device 833*8ea61889SMauro Carvalho Chehaboperations, ones that are routed through the call *audio_ioctl()*, and 834*8ea61889SMauro Carvalho Chehabthe remaining ones, that are presumable device-dependent. Generally, a 835*8ea61889SMauro Carvalho Chehabnegative return value indicates an error. 836*8ea61889SMauro Carvalho Chehab 837*8ea61889SMauro Carvalho ChehabDirectly implemented *ioctl()'s* 838*8ea61889SMauro Carvalho Chehab-------------------------------- 839*8ea61889SMauro Carvalho Chehab 840*8ea61889SMauro Carvalho ChehabThe following `old` CD-ROM *ioctl()*\ 's are implemented by directly 841*8ea61889SMauro Carvalho Chehabcalling device-operations in *cdrom_device_ops*, if implemented and 842*8ea61889SMauro Carvalho Chehabnot masked: 843*8ea61889SMauro Carvalho Chehab 844*8ea61889SMauro Carvalho Chehab`CDROMMULTISESSION` 845*8ea61889SMauro Carvalho Chehab Requests the last session on a CD-ROM. 846*8ea61889SMauro Carvalho Chehab`CDROMEJECT` 847*8ea61889SMauro Carvalho Chehab Open tray. 848*8ea61889SMauro Carvalho Chehab`CDROMCLOSETRAY` 849*8ea61889SMauro Carvalho Chehab Close tray. 850*8ea61889SMauro Carvalho Chehab`CDROMEJECT_SW` 851*8ea61889SMauro Carvalho Chehab If *arg\not=0*, set behavior to auto-close (close 852*8ea61889SMauro Carvalho Chehab tray on first open) and auto-eject (eject on last release), otherwise 853*8ea61889SMauro Carvalho Chehab set behavior to non-moving on *open()* and *release()* calls. 854*8ea61889SMauro Carvalho Chehab`CDROM_GET_MCN` 855*8ea61889SMauro Carvalho Chehab Get the Media Catalog Number from a CD. 856*8ea61889SMauro Carvalho Chehab 857*8ea61889SMauro Carvalho Chehab*Ioctl*s routed through *audio_ioctl()* 858*8ea61889SMauro Carvalho Chehab--------------------------------------- 859*8ea61889SMauro Carvalho Chehab 860*8ea61889SMauro Carvalho ChehabThe following set of *ioctl()'s* are all implemented through a call to 861*8ea61889SMauro Carvalho Chehabthe *cdrom_fops* function *audio_ioctl()*. Memory checks and 862*8ea61889SMauro Carvalho Chehaballocation are performed in *cdrom_ioctl()*, and also sanitization of 863*8ea61889SMauro Carvalho Chehabaddress format (*CDROM_LBA*/*CDROM_MSF*) is done. 864*8ea61889SMauro Carvalho Chehab 865*8ea61889SMauro Carvalho Chehab`CDROMSUBCHNL` 866*8ea61889SMauro Carvalho Chehab Get sub-channel data in argument *arg* of type 867*8ea61889SMauro Carvalho Chehab `struct cdrom_subchnl *`. 868*8ea61889SMauro Carvalho Chehab`CDROMREADTOCHDR` 869*8ea61889SMauro Carvalho Chehab Read Table of Contents header, in *arg* of type 870*8ea61889SMauro Carvalho Chehab `struct cdrom_tochdr *`. 871*8ea61889SMauro Carvalho Chehab`CDROMREADTOCENTRY` 872*8ea61889SMauro Carvalho Chehab Read a Table of Contents entry in *arg* and specified by *arg* 873*8ea61889SMauro Carvalho Chehab of type `struct cdrom_tocentry *`. 874*8ea61889SMauro Carvalho Chehab`CDROMPLAYMSF` 875*8ea61889SMauro Carvalho Chehab Play audio fragment specified in Minute, Second, Frame format, 876*8ea61889SMauro Carvalho Chehab delimited by *arg* of type `struct cdrom_msf *`. 877*8ea61889SMauro Carvalho Chehab`CDROMPLAYTRKIND` 878*8ea61889SMauro Carvalho Chehab Play audio fragment in track-index format delimited by *arg* 879*8ea61889SMauro Carvalho Chehab of type `struct cdrom_ti *`. 880*8ea61889SMauro Carvalho Chehab`CDROMVOLCTRL` 881*8ea61889SMauro Carvalho Chehab Set volume specified by *arg* of type `struct cdrom_volctrl *`. 882*8ea61889SMauro Carvalho Chehab`CDROMVOLREAD` 883*8ea61889SMauro Carvalho Chehab Read volume into by *arg* of type `struct cdrom_volctrl *`. 884*8ea61889SMauro Carvalho Chehab`CDROMSTART` 885*8ea61889SMauro Carvalho Chehab Spin up disc. 886*8ea61889SMauro Carvalho Chehab`CDROMSTOP` 887*8ea61889SMauro Carvalho Chehab Stop playback of audio fragment. 888*8ea61889SMauro Carvalho Chehab`CDROMPAUSE` 889*8ea61889SMauro Carvalho Chehab Pause playback of audio fragment. 890*8ea61889SMauro Carvalho Chehab`CDROMRESUME` 891*8ea61889SMauro Carvalho Chehab Resume playing. 892*8ea61889SMauro Carvalho Chehab 893*8ea61889SMauro Carvalho ChehabNew *ioctl()'s* in `cdrom.c` 894*8ea61889SMauro Carvalho Chehab---------------------------- 895*8ea61889SMauro Carvalho Chehab 896*8ea61889SMauro Carvalho ChehabThe following *ioctl()'s* have been introduced to allow user programs to 897*8ea61889SMauro Carvalho Chehabcontrol the behavior of individual CD-ROM devices. New *ioctl* 898*8ea61889SMauro Carvalho Chehabcommands can be identified by the underscores in their names. 899*8ea61889SMauro Carvalho Chehab 900*8ea61889SMauro Carvalho Chehab`CDROM_SET_OPTIONS` 901*8ea61889SMauro Carvalho Chehab Set options specified by *arg*. Returns the option flag register 902*8ea61889SMauro Carvalho Chehab after modification. Use *arg = \rm0* for reading the current flags. 903*8ea61889SMauro Carvalho Chehab`CDROM_CLEAR_OPTIONS` 904*8ea61889SMauro Carvalho Chehab Clear options specified by *arg*. Returns the option flag register 905*8ea61889SMauro Carvalho Chehab after modification. 906*8ea61889SMauro Carvalho Chehab`CDROM_SELECT_SPEED` 907*8ea61889SMauro Carvalho Chehab Select head-rate speed of disc specified as by *arg* in units 908*8ea61889SMauro Carvalho Chehab of standard cdrom speed (176\,kB/sec raw data or 909*8ea61889SMauro Carvalho Chehab 150kB/sec file system data). The value 0 means `auto-select`, 910*8ea61889SMauro Carvalho Chehab i. e., play audio discs at real time and data discs at maximum speed. 911*8ea61889SMauro Carvalho Chehab The value *arg* is checked against the maximum head rate of the 912*8ea61889SMauro Carvalho Chehab drive found in the *cdrom_dops*. 913*8ea61889SMauro Carvalho Chehab`CDROM_SELECT_DISC` 914*8ea61889SMauro Carvalho Chehab Select disc numbered *arg* from a juke-box. 915*8ea61889SMauro Carvalho Chehab 916*8ea61889SMauro Carvalho Chehab First disc is numbered 0. The number *arg* is checked against the 917*8ea61889SMauro Carvalho Chehab maximum number of discs in the juke-box found in the *cdrom_dops*. 918*8ea61889SMauro Carvalho Chehab`CDROM_MEDIA_CHANGED` 919*8ea61889SMauro Carvalho Chehab Returns 1 if a disc has been changed since the last call. 920*8ea61889SMauro Carvalho Chehab Note that calls to *cdrom_media_changed* by the VFS are treated 921*8ea61889SMauro Carvalho Chehab by an independent queue, so both mechanisms will detect a 922*8ea61889SMauro Carvalho Chehab media change once. For juke-boxes, an extra argument *arg* 923*8ea61889SMauro Carvalho Chehab specifies the slot for which the information is given. The special 924*8ea61889SMauro Carvalho Chehab value *CDSL_CURRENT* requests that information about the currently 925*8ea61889SMauro Carvalho Chehab selected slot be returned. 926*8ea61889SMauro Carvalho Chehab`CDROM_DRIVE_STATUS` 927*8ea61889SMauro Carvalho Chehab Returns the status of the drive by a call to 928*8ea61889SMauro Carvalho Chehab *drive_status()*. Return values are defined in cdrom_drive_status_. 929*8ea61889SMauro Carvalho Chehab Note that this call doesn't return information on the 930*8ea61889SMauro Carvalho Chehab current playing activity of the drive; this can be polled through 931*8ea61889SMauro Carvalho Chehab an *ioctl* call to *CDROMSUBCHNL*. For juke-boxes, an extra argument 932*8ea61889SMauro Carvalho Chehab *arg* specifies the slot for which (possibly limited) information is 933*8ea61889SMauro Carvalho Chehab given. The special value *CDSL_CURRENT* requests that information 934*8ea61889SMauro Carvalho Chehab about the currently selected slot be returned. 935*8ea61889SMauro Carvalho Chehab`CDROM_DISC_STATUS` 936*8ea61889SMauro Carvalho Chehab Returns the type of the disc currently in the drive. 937*8ea61889SMauro Carvalho Chehab It should be viewed as a complement to *CDROM_DRIVE_STATUS*. 938*8ea61889SMauro Carvalho Chehab This *ioctl* can provide *some* information about the current 939*8ea61889SMauro Carvalho Chehab disc that is inserted in the drive. This functionality used to be 940*8ea61889SMauro Carvalho Chehab implemented in the low level drivers, but is now carried out 941*8ea61889SMauro Carvalho Chehab entirely in Uniform CD-ROM Driver. 942*8ea61889SMauro Carvalho Chehab 943*8ea61889SMauro Carvalho Chehab The history of development of the CD's use as a carrier medium for 944*8ea61889SMauro Carvalho Chehab various digital information has lead to many different disc types. 945*8ea61889SMauro Carvalho Chehab This *ioctl* is useful only in the case that CDs have \emph {only 946*8ea61889SMauro Carvalho Chehab one} type of data on them. While this is often the case, it is 947*8ea61889SMauro Carvalho Chehab also very common for CDs to have some tracks with data, and some 948*8ea61889SMauro Carvalho Chehab tracks with audio. Because this is an existing interface, rather 949*8ea61889SMauro Carvalho Chehab than fixing this interface by changing the assumptions it was made 950*8ea61889SMauro Carvalho Chehab under, thereby breaking all user applications that use this 951*8ea61889SMauro Carvalho Chehab function, the Uniform CD-ROM Driver implements this *ioctl* as 952*8ea61889SMauro Carvalho Chehab follows: If the CD in question has audio tracks on it, and it has 953*8ea61889SMauro Carvalho Chehab absolutely no CD-I, XA, or data tracks on it, it will be reported 954*8ea61889SMauro Carvalho Chehab as *CDS_AUDIO*. If it has both audio and data tracks, it will 955*8ea61889SMauro Carvalho Chehab return *CDS_MIXED*. If there are no audio tracks on the disc, and 956*8ea61889SMauro Carvalho Chehab if the CD in question has any CD-I tracks on it, it will be 957*8ea61889SMauro Carvalho Chehab reported as *CDS_XA_2_2*. Failing that, if the CD in question 958*8ea61889SMauro Carvalho Chehab has any XA tracks on it, it will be reported as *CDS_XA_2_1*. 959*8ea61889SMauro Carvalho Chehab Finally, if the CD in question has any data tracks on it, 960*8ea61889SMauro Carvalho Chehab it will be reported as a data CD (*CDS_DATA_1*). 961*8ea61889SMauro Carvalho Chehab 962*8ea61889SMauro Carvalho Chehab This *ioctl* can return:: 963*8ea61889SMauro Carvalho Chehab 964*8ea61889SMauro Carvalho Chehab CDS_NO_INFO /* no information available */ 965*8ea61889SMauro Carvalho Chehab CDS_NO_DISC /* no disc is inserted, or tray is opened */ 966*8ea61889SMauro Carvalho Chehab CDS_AUDIO /* Audio disc (2352 audio bytes/frame) */ 967*8ea61889SMauro Carvalho Chehab CDS_DATA_1 /* data disc, mode 1 (2048 user bytes/frame) */ 968*8ea61889SMauro Carvalho Chehab CDS_XA_2_1 /* mixed data (XA), mode 2, form 1 (2048 user bytes) */ 969*8ea61889SMauro Carvalho Chehab CDS_XA_2_2 /* mixed data (XA), mode 2, form 1 (2324 user bytes) */ 970*8ea61889SMauro Carvalho Chehab CDS_MIXED /* mixed audio/data disc */ 971*8ea61889SMauro Carvalho Chehab 972*8ea61889SMauro Carvalho Chehab For some information concerning frame layout of the various disc 973*8ea61889SMauro Carvalho Chehab types, see a recent version of `cdrom.h`. 974*8ea61889SMauro Carvalho Chehab 975*8ea61889SMauro Carvalho Chehab`CDROM_CHANGER_NSLOTS` 976*8ea61889SMauro Carvalho Chehab Returns the number of slots in a juke-box. 977*8ea61889SMauro Carvalho Chehab`CDROMRESET` 978*8ea61889SMauro Carvalho Chehab Reset the drive. 979*8ea61889SMauro Carvalho Chehab`CDROM_GET_CAPABILITY` 980*8ea61889SMauro Carvalho Chehab Returns the *capability* flags for the drive. Refer to section 981*8ea61889SMauro Carvalho Chehab cdrom_capabilities_ for more information on these flags. 982*8ea61889SMauro Carvalho Chehab`CDROM_LOCKDOOR` 983*8ea61889SMauro Carvalho Chehab Locks the door of the drive. `arg == 0` unlocks the door, 984*8ea61889SMauro Carvalho Chehab any other value locks it. 985*8ea61889SMauro Carvalho Chehab`CDROM_DEBUG` 986*8ea61889SMauro Carvalho Chehab Turns on debugging info. Only root is allowed to do this. 987*8ea61889SMauro Carvalho Chehab Same semantics as CDROM_LOCKDOOR. 988*8ea61889SMauro Carvalho Chehab 989*8ea61889SMauro Carvalho Chehab 990*8ea61889SMauro Carvalho ChehabDevice dependent *ioctl()'s* 991*8ea61889SMauro Carvalho Chehab---------------------------- 992*8ea61889SMauro Carvalho Chehab 993*8ea61889SMauro Carvalho ChehabFinally, all other *ioctl()'s* are passed to the function *dev_ioctl()*, 994*8ea61889SMauro Carvalho Chehabif implemented. No memory allocation or verification is carried out. 995*8ea61889SMauro Carvalho Chehab 996*8ea61889SMauro Carvalho ChehabHow to update your driver 997*8ea61889SMauro Carvalho Chehab========================= 998*8ea61889SMauro Carvalho Chehab 999*8ea61889SMauro Carvalho Chehab- Make a backup of your current driver. 1000*8ea61889SMauro Carvalho Chehab- Get hold of the files `cdrom.c` and `cdrom.h`, they should be in 1001*8ea61889SMauro Carvalho Chehab the directory tree that came with this documentation. 1002*8ea61889SMauro Carvalho Chehab- Make sure you include `cdrom.h`. 1003*8ea61889SMauro Carvalho Chehab- Change the 3rd argument of *register_blkdev* from `&<your-drive>_fops` 1004*8ea61889SMauro Carvalho Chehab to `&cdrom_fops`. 1005*8ea61889SMauro Carvalho Chehab- Just after that line, add the following to register with the Uniform 1006*8ea61889SMauro Carvalho Chehab CD-ROM Driver:: 1007*8ea61889SMauro Carvalho Chehab 1008*8ea61889SMauro Carvalho Chehab register_cdrom(&<your-drive>_info);* 1009*8ea61889SMauro Carvalho Chehab 1010*8ea61889SMauro Carvalho Chehab Similarly, add a call to *unregister_cdrom()* at the appropriate place. 1011*8ea61889SMauro Carvalho Chehab- Copy an example of the device-operations *struct* to your 1012*8ea61889SMauro Carvalho Chehab source, e. g., from `cm206.c` *cm206_dops*, and change all 1013*8ea61889SMauro Carvalho Chehab entries to names corresponding to your driver, or names you just 1014*8ea61889SMauro Carvalho Chehab happen to like. If your driver doesn't support a certain function, 1015*8ea61889SMauro Carvalho Chehab make the entry *NULL*. At the entry *capability* you should list all 1016*8ea61889SMauro Carvalho Chehab capabilities your driver currently supports. If your driver 1017*8ea61889SMauro Carvalho Chehab has a capability that is not listed, please send me a message. 1018*8ea61889SMauro Carvalho Chehab- Copy the *cdrom_device_info* declaration from the same example 1019*8ea61889SMauro Carvalho Chehab driver, and modify the entries according to your needs. If your 1020*8ea61889SMauro Carvalho Chehab driver dynamically determines the capabilities of the hardware, this 1021*8ea61889SMauro Carvalho Chehab structure should also be declared dynamically. 1022*8ea61889SMauro Carvalho Chehab- Implement all functions in your `<device>_dops` structure, 1023*8ea61889SMauro Carvalho Chehab according to prototypes listed in `cdrom.h`, and specifications given 1024*8ea61889SMauro Carvalho Chehab in cdrom_api_. Most likely you have already implemented 1025*8ea61889SMauro Carvalho Chehab the code in a large part, and you will almost certainly need to adapt the 1026*8ea61889SMauro Carvalho Chehab prototype and return values. 1027*8ea61889SMauro Carvalho Chehab- Rename your `<device>_ioctl()` function to *audio_ioctl* and 1028*8ea61889SMauro Carvalho Chehab change the prototype a little. Remove entries listed in the first 1029*8ea61889SMauro Carvalho Chehab part in cdrom_ioctl_, if your code was OK, these are 1030*8ea61889SMauro Carvalho Chehab just calls to the routines you adapted in the previous step. 1031*8ea61889SMauro Carvalho Chehab- You may remove all remaining memory checking code in the 1032*8ea61889SMauro Carvalho Chehab *audio_ioctl()* function that deals with audio commands (these are 1033*8ea61889SMauro Carvalho Chehab listed in the second part of cdrom_ioctl_. There is no 1034*8ea61889SMauro Carvalho Chehab need for memory allocation either, so most *case*s in the *switch* 1035*8ea61889SMauro Carvalho Chehab statement look similar to:: 1036*8ea61889SMauro Carvalho Chehab 1037*8ea61889SMauro Carvalho Chehab case CDROMREADTOCENTRY: 1038*8ea61889SMauro Carvalho Chehab get_toc_entry\bigl((struct cdrom_tocentry *) arg); 1039*8ea61889SMauro Carvalho Chehab 1040*8ea61889SMauro Carvalho Chehab- All remaining *ioctl* cases must be moved to a separate 1041*8ea61889SMauro Carvalho Chehab function, *<device>_ioctl*, the device-dependent *ioctl()'s*. Note that 1042*8ea61889SMauro Carvalho Chehab memory checking and allocation must be kept in this code! 1043*8ea61889SMauro Carvalho Chehab- Change the prototypes of *<device>_open()* and 1044*8ea61889SMauro Carvalho Chehab *<device>_release()*, and remove any strategic code (i. e., tray 1045*8ea61889SMauro Carvalho Chehab movement, door locking, etc.). 1046*8ea61889SMauro Carvalho Chehab- Try to recompile the drivers. We advise you to use modules, both 1047*8ea61889SMauro Carvalho Chehab for `cdrom.o` and your driver, as debugging is much easier this 1048*8ea61889SMauro Carvalho Chehab way. 1049*8ea61889SMauro Carvalho Chehab 1050*8ea61889SMauro Carvalho ChehabThanks 1051*8ea61889SMauro Carvalho Chehab====== 1052*8ea61889SMauro Carvalho Chehab 1053*8ea61889SMauro Carvalho ChehabThanks to all the people involved. First, Erik Andersen, who has 1054*8ea61889SMauro Carvalho Chehabtaken over the torch in maintaining `cdrom.c` and integrating much 1055*8ea61889SMauro Carvalho ChehabCD-ROM-related code in the 2.1-kernel. Thanks to Scott Snyder and 1056*8ea61889SMauro Carvalho ChehabGerd Knorr, who were the first to implement this interface for SCSI 1057*8ea61889SMauro Carvalho Chehaband IDE-CD drivers and added many ideas for extension of the data 1058*8ea61889SMauro Carvalho Chehabstructures relative to kernel~2.0. Further thanks to Heiko Eißfeldt, 1059*8ea61889SMauro Carvalho ChehabThomas Quinot, Jon Tombs, Ken Pizzini, Eberhard Mönkeberg and Andrew Kroll, 1060*8ea61889SMauro Carvalho Chehabthe Linux CD-ROM device driver developers who were kind 1061*8ea61889SMauro Carvalho Chehabenough to give suggestions and criticisms during the writing. Finally 1062*8ea61889SMauro Carvalho Chehabof course, I want to thank Linus Torvalds for making this possible in 1063*8ea61889SMauro Carvalho Chehabthe first place. 1064