18ea61889SMauro Carvalho Chehab======================= 28ea61889SMauro Carvalho ChehabA Linux CD-ROM standard 38ea61889SMauro Carvalho Chehab======================= 48ea61889SMauro Carvalho Chehab 58ea61889SMauro Carvalho Chehab:Author: David van Leeuwen <david@ElseWare.cistron.nl> 68ea61889SMauro Carvalho Chehab:Date: 12 March 1999 78ea61889SMauro Carvalho Chehab:Updated by: Erik Andersen (andersee@debian.org) 88ea61889SMauro Carvalho Chehab:Updated by: Jens Axboe (axboe@image.dk) 98ea61889SMauro Carvalho Chehab 108ea61889SMauro Carvalho Chehab 118ea61889SMauro Carvalho ChehabIntroduction 128ea61889SMauro Carvalho Chehab============ 138ea61889SMauro Carvalho Chehab 148ea61889SMauro Carvalho ChehabLinux is probably the Unix-like operating system that supports 158ea61889SMauro Carvalho Chehabthe widest variety of hardware devices. The reasons for this are 168ea61889SMauro Carvalho Chehabpresumably 178ea61889SMauro Carvalho Chehab 188ea61889SMauro Carvalho Chehab- The large list of hardware devices available for the many platforms 198ea61889SMauro Carvalho Chehab that Linux now supports (i.e., i386-PCs, Sparc Suns, etc.) 208ea61889SMauro Carvalho Chehab- The open design of the operating system, such that anybody can write a 218ea61889SMauro Carvalho Chehab driver for Linux. 228ea61889SMauro Carvalho Chehab- There is plenty of source code around as examples of how to write a driver. 238ea61889SMauro Carvalho Chehab 248ea61889SMauro Carvalho ChehabThe openness of Linux, and the many different types of available 258ea61889SMauro Carvalho Chehabhardware has allowed Linux to support many different hardware devices. 268ea61889SMauro Carvalho ChehabUnfortunately, the very openness that has allowed Linux to support 278ea61889SMauro Carvalho Chehaball these different devices has also allowed the behavior of each 288ea61889SMauro Carvalho Chehabdevice driver to differ significantly from one device to another. 298ea61889SMauro Carvalho ChehabThis divergence of behavior has been very significant for CD-ROM 308ea61889SMauro Carvalho Chehabdevices; the way a particular drive reacts to a `standard` *ioctl()* 318ea61889SMauro Carvalho Chehabcall varies greatly from one device driver to another. To avoid making 328ea61889SMauro Carvalho Chehabtheir drivers totally inconsistent, the writers of Linux CD-ROM 338ea61889SMauro Carvalho Chehabdrivers generally created new device drivers by understanding, copying, 348ea61889SMauro Carvalho Chehaband then changing an existing one. Unfortunately, this practice did not 358ea61889SMauro Carvalho Chehabmaintain uniform behavior across all the Linux CD-ROM drivers. 368ea61889SMauro Carvalho Chehab 378ea61889SMauro Carvalho ChehabThis document describes an effort to establish Uniform behavior across 388ea61889SMauro Carvalho Chehaball the different CD-ROM device drivers for Linux. This document also 398ea61889SMauro Carvalho Chehabdefines the various *ioctl()'s*, and how the low-level CD-ROM device 408ea61889SMauro Carvalho Chehabdrivers should implement them. Currently (as of the Linux 2.1.\ *x* 418ea61889SMauro Carvalho Chehabdevelopment kernels) several low-level CD-ROM device drivers, including 428ea61889SMauro Carvalho Chehabboth IDE/ATAPI and SCSI, now use this Uniform interface. 438ea61889SMauro Carvalho Chehab 448ea61889SMauro Carvalho ChehabWhen the CD-ROM was developed, the interface between the CD-ROM drive 458ea61889SMauro Carvalho Chehaband the computer was not specified in the standards. As a result, many 468ea61889SMauro Carvalho Chehabdifferent CD-ROM interfaces were developed. Some of them had their 478ea61889SMauro Carvalho Chehabown proprietary design (Sony, Mitsumi, Panasonic, Philips), other 488ea61889SMauro Carvalho Chehabmanufacturers adopted an existing electrical interface and changed 498ea61889SMauro Carvalho Chehabthe functionality (CreativeLabs/SoundBlaster, Teac, Funai) or simply 508ea61889SMauro Carvalho Chehabadapted their drives to one or more of the already existing electrical 518ea61889SMauro Carvalho Chehabinterfaces (Aztech, Sanyo, Funai, Vertos, Longshine, Optics Storage and 528ea61889SMauro Carvalho Chehabmost of the `NoName` manufacturers). In cases where a new drive really 538ea61889SMauro Carvalho Chehabbrought its own interface or used its own command set and flow control 548ea61889SMauro Carvalho Chehabscheme, either a separate driver had to be written, or an existing 558ea61889SMauro Carvalho Chehabdriver had to be enhanced. History has delivered us CD-ROM support for 568ea61889SMauro Carvalho Chehabmany of these different interfaces. Nowadays, almost all new CD-ROM 578ea61889SMauro Carvalho Chehabdrives are either IDE/ATAPI or SCSI, and it is very unlikely that any 588ea61889SMauro Carvalho Chehabmanufacturer will create a new interface. Even finding drives for the 598ea61889SMauro Carvalho Chehabold proprietary interfaces is getting difficult. 608ea61889SMauro Carvalho Chehab 618ea61889SMauro Carvalho ChehabWhen (in the 1.3.70's) I looked at the existing software interface, 628ea61889SMauro Carvalho Chehabwhich was expressed through `cdrom.h`, it appeared to be a rather wild 638ea61889SMauro Carvalho Chehabset of commands and data formats [#f1]_. It seemed that many 648ea61889SMauro Carvalho Chehabfeatures of the software interface had been added to accommodate the 658ea61889SMauro Carvalho Chehabcapabilities of a particular drive, in an *ad hoc* manner. More 668ea61889SMauro Carvalho Chehabimportantly, it appeared that the behavior of the `standard` commands 678ea61889SMauro Carvalho Chehabwas different for most of the different drivers: e. g., some drivers 688ea61889SMauro Carvalho Chehabclose the tray if an *open()* call occurs when the tray is open, while 698ea61889SMauro Carvalho Chehabothers do not. Some drivers lock the door upon opening the device, to 708ea61889SMauro Carvalho Chehabprevent an incoherent file system, but others don't, to allow software 718ea61889SMauro Carvalho Chehabejection. Undoubtedly, the capabilities of the different drives vary, 728ea61889SMauro Carvalho Chehabbut even when two drives have the same capability their drivers' 738ea61889SMauro Carvalho Chehabbehavior was usually different. 748ea61889SMauro Carvalho Chehab 758ea61889SMauro Carvalho Chehab.. [#f1] 768ea61889SMauro Carvalho Chehab I cannot recollect what kernel version I looked at, then, 778ea61889SMauro Carvalho Chehab presumably 1.2.13 and 1.3.34 --- the latest kernel that I was 788ea61889SMauro Carvalho Chehab indirectly involved in. 798ea61889SMauro Carvalho Chehab 808ea61889SMauro Carvalho ChehabI decided to start a discussion on how to make all the Linux CD-ROM 818ea61889SMauro Carvalho Chehabdrivers behave more uniformly. I began by contacting the developers of 828ea61889SMauro Carvalho Chehabthe many CD-ROM drivers found in the Linux kernel. Their reactions 838ea61889SMauro Carvalho Chehabencouraged me to write the Uniform CD-ROM Driver which this document is 848ea61889SMauro Carvalho Chehabintended to describe. The implementation of the Uniform CD-ROM Driver is 858ea61889SMauro Carvalho Chehabin the file `cdrom.c`. This driver is intended to be an additional software 868ea61889SMauro Carvalho Chehablayer that sits on top of the low-level device drivers for each CD-ROM drive. 878ea61889SMauro Carvalho ChehabBy adding this additional layer, it is possible to have all the different 888ea61889SMauro Carvalho ChehabCD-ROM devices behave **exactly** the same (insofar as the underlying 898ea61889SMauro Carvalho Chehabhardware will allow). 908ea61889SMauro Carvalho Chehab 918ea61889SMauro Carvalho ChehabThe goal of the Uniform CD-ROM Driver is **not** to alienate driver developers 928ea61889SMauro Carvalho Chehabwhohave not yet taken steps to support this effort. The goal of Uniform CD-ROM 938ea61889SMauro Carvalho ChehabDriver is simply to give people writing application programs for CD-ROM drives 948ea61889SMauro Carvalho Chehab**one** Linux CD-ROM interface with consistent behavior for all 958ea61889SMauro Carvalho ChehabCD-ROM devices. In addition, this also provides a consistent interface 968ea61889SMauro Carvalho Chehabbetween the low-level device driver code and the Linux kernel. Care 978ea61889SMauro Carvalho Chehabis taken that 100% compatibility exists with the data structures and 988ea61889SMauro Carvalho Chehabprogrammer's interface defined in `cdrom.h`. This guide was written to 998ea61889SMauro Carvalho Chehabhelp CD-ROM driver developers adapt their code to use the Uniform CD-ROM 1008ea61889SMauro Carvalho ChehabDriver code defined in `cdrom.c`. 1018ea61889SMauro Carvalho Chehab 1028ea61889SMauro Carvalho ChehabPersonally, I think that the most important hardware interfaces are 1038ea61889SMauro Carvalho Chehabthe IDE/ATAPI drives and, of course, the SCSI drives, but as prices 1048ea61889SMauro Carvalho Chehabof hardware drop continuously, it is also likely that people may have 1058ea61889SMauro Carvalho Chehabmore than one CD-ROM drive, possibly of mixed types. It is important 1068ea61889SMauro Carvalho Chehabthat these drives behave in the same way. In December 1994, one of the 1078ea61889SMauro Carvalho Chehabcheapest CD-ROM drives was a Philips cm206, a double-speed proprietary 1088ea61889SMauro Carvalho Chehabdrive. In the months that I was busy writing a Linux driver for it, 1098ea61889SMauro Carvalho Chehabproprietary drives became obsolete and IDE/ATAPI drives became the 1108ea61889SMauro Carvalho Chehabstandard. At the time of the last update to this document (November 1118ea61889SMauro Carvalho Chehab1997) it is becoming difficult to even **find** anything less than a 1128ea61889SMauro Carvalho Chehab16 speed CD-ROM drive, and 24 speed drives are common. 1138ea61889SMauro Carvalho Chehab 1148ea61889SMauro Carvalho Chehab.. _cdrom_api: 1158ea61889SMauro Carvalho Chehab 1168ea61889SMauro Carvalho ChehabStandardizing through another software level 1178ea61889SMauro Carvalho Chehab============================================ 1188ea61889SMauro Carvalho Chehab 1198ea61889SMauro Carvalho ChehabAt the time this document was conceived, all drivers directly 1208ea61889SMauro Carvalho Chehabimplemented the CD-ROM *ioctl()* calls through their own routines. This 1218ea61889SMauro Carvalho Chehabled to the danger of different drivers forgetting to do important things 1228ea61889SMauro Carvalho Chehablike checking that the user was giving the driver valid data. More 1238ea61889SMauro Carvalho Chehabimportantly, this led to the divergence of behavior, which has already 1248ea61889SMauro Carvalho Chehabbeen discussed. 1258ea61889SMauro Carvalho Chehab 1268ea61889SMauro Carvalho ChehabFor this reason, the Uniform CD-ROM Driver was created to enforce consistent 1278ea61889SMauro Carvalho ChehabCD-ROM drive behavior, and to provide a common set of services to the various 1288ea61889SMauro Carvalho Chehablow-level CD-ROM device drivers. The Uniform CD-ROM Driver now provides another 1298ea61889SMauro Carvalho Chehabsoftware-level, that separates the *ioctl()* and *open()* implementation 1308ea61889SMauro Carvalho Chehabfrom the actual hardware implementation. Note that this effort has 1318ea61889SMauro Carvalho Chehabmade few changes which will affect a user's application programs. The 1328ea61889SMauro Carvalho Chehabgreatest change involved moving the contents of the various low-level 1338ea61889SMauro Carvalho ChehabCD-ROM drivers\' header files to the kernel's cdrom directory. This was 1348ea61889SMauro Carvalho Chehabdone to help ensure that the user is only presented with only one cdrom 1358ea61889SMauro Carvalho Chehabinterface, the interface defined in `cdrom.h`. 1368ea61889SMauro Carvalho Chehab 1378ea61889SMauro Carvalho ChehabCD-ROM drives are specific enough (i. e., different from other 1388ea61889SMauro Carvalho Chehabblock-devices such as floppy or hard disc drives), to define a set 1398ea61889SMauro Carvalho Chehabof common **CD-ROM device operations**, *<cdrom-device>_dops*. 1408ea61889SMauro Carvalho ChehabThese operations are different from the classical block-device file 1418ea61889SMauro Carvalho Chehaboperations, *<block-device>_fops*. 1428ea61889SMauro Carvalho Chehab 1438ea61889SMauro Carvalho ChehabThe routines for the Uniform CD-ROM Driver interface level are implemented 1448ea61889SMauro Carvalho Chehabin the file `cdrom.c`. In this file, the Uniform CD-ROM Driver interfaces 1458ea61889SMauro Carvalho Chehabwith the kernel as a block device by registering the following general 1468ea61889SMauro Carvalho Chehab*struct file_operations*:: 1478ea61889SMauro Carvalho Chehab 1488ea61889SMauro Carvalho Chehab struct file_operations cdrom_fops = { 149918d9c77SMauro Carvalho Chehab NULL, /* lseek */ 150918d9c77SMauro Carvalho Chehab block _read , /* read--general block-dev read */ 151918d9c77SMauro Carvalho Chehab block _write, /* write--general block-dev write */ 152918d9c77SMauro Carvalho Chehab NULL, /* readdir */ 153918d9c77SMauro Carvalho Chehab NULL, /* select */ 154918d9c77SMauro Carvalho Chehab cdrom_ioctl, /* ioctl */ 155918d9c77SMauro Carvalho Chehab NULL, /* mmap */ 156918d9c77SMauro Carvalho Chehab cdrom_open, /* open */ 157918d9c77SMauro Carvalho Chehab cdrom_release, /* release */ 158918d9c77SMauro Carvalho Chehab NULL, /* fsync */ 159918d9c77SMauro Carvalho Chehab NULL, /* fasync */ 160918d9c77SMauro Carvalho Chehab NULL /* revalidate */ 1618ea61889SMauro Carvalho Chehab }; 1628ea61889SMauro Carvalho Chehab 1638ea61889SMauro Carvalho ChehabEvery active CD-ROM device shares this *struct*. The routines 1648ea61889SMauro Carvalho Chehabdeclared above are all implemented in `cdrom.c`, since this file is the 1658ea61889SMauro Carvalho Chehabplace where the behavior of all CD-ROM-devices is defined and 1668ea61889SMauro Carvalho Chehabstandardized. The actual interface to the various types of CD-ROM 1678ea61889SMauro Carvalho Chehabhardware is still performed by various low-level CD-ROM-device 1688ea61889SMauro Carvalho Chehabdrivers. These routines simply implement certain **capabilities** 1698ea61889SMauro Carvalho Chehabthat are common to all CD-ROM (and really, all removable-media 1708ea61889SMauro Carvalho Chehabdevices). 1718ea61889SMauro Carvalho Chehab 1728ea61889SMauro Carvalho ChehabRegistration of a low-level CD-ROM device driver is now done through 1738ea61889SMauro Carvalho Chehabthe general routines in `cdrom.c`, not through the Virtual File System 1748ea61889SMauro Carvalho Chehab(VFS) any more. The interface implemented in `cdrom.c` is carried out 1758ea61889SMauro Carvalho Chehabthrough two general structures that contain information about the 1768ea61889SMauro Carvalho Chehabcapabilities of the driver, and the specific drives on which the 1778ea61889SMauro Carvalho Chehabdriver operates. The structures are: 1788ea61889SMauro Carvalho Chehab 1798ea61889SMauro Carvalho Chehabcdrom_device_ops 1808ea61889SMauro Carvalho Chehab This structure contains information about the low-level driver for a 1818ea61889SMauro Carvalho Chehab CD-ROM device. This structure is conceptually connected to the major 1828ea61889SMauro Carvalho Chehab number of the device (although some drivers may have different 1838ea61889SMauro Carvalho Chehab major numbers, as is the case for the IDE driver). 1848ea61889SMauro Carvalho Chehab 1858ea61889SMauro Carvalho Chehabcdrom_device_info 1868ea61889SMauro Carvalho Chehab This structure contains information about a particular CD-ROM drive, 1878ea61889SMauro Carvalho Chehab such as its device name, speed, etc. This structure is conceptually 1888ea61889SMauro Carvalho Chehab connected to the minor number of the device. 1898ea61889SMauro Carvalho Chehab 1908ea61889SMauro Carvalho ChehabRegistering a particular CD-ROM drive with the Uniform CD-ROM Driver 1918ea61889SMauro Carvalho Chehabis done by the low-level device driver though a call to:: 1928ea61889SMauro Carvalho Chehab 1938ea61889SMauro Carvalho Chehab register_cdrom(struct cdrom_device_info * <device>_info) 1948ea61889SMauro Carvalho Chehab 1958ea61889SMauro Carvalho ChehabThe device information structure, *<device>_info*, contains all the 1968ea61889SMauro Carvalho Chehabinformation needed for the kernel to interface with the low-level 1978ea61889SMauro Carvalho ChehabCD-ROM device driver. One of the most important entries in this 1988ea61889SMauro Carvalho Chehabstructure is a pointer to the *cdrom_device_ops* structure of the 1998ea61889SMauro Carvalho Chehablow-level driver. 2008ea61889SMauro Carvalho Chehab 2018ea61889SMauro Carvalho ChehabThe device operations structure, *cdrom_device_ops*, contains a list 2028ea61889SMauro Carvalho Chehabof pointers to the functions which are implemented in the low-level 2038ea61889SMauro Carvalho Chehabdevice driver. When `cdrom.c` accesses a CD-ROM device, it does it 2048ea61889SMauro Carvalho Chehabthrough the functions in this structure. It is impossible to know all 2058ea61889SMauro Carvalho Chehabthe capabilities of future CD-ROM drives, so it is expected that this 2068ea61889SMauro Carvalho Chehablist may need to be expanded from time to time as new technologies are 2078ea61889SMauro Carvalho Chehabdeveloped. For example, CD-R and CD-R/W drives are beginning to become 2088ea61889SMauro Carvalho Chehabpopular, and support will soon need to be added for them. For now, the 2098ea61889SMauro Carvalho Chehabcurrent *struct* is:: 2108ea61889SMauro Carvalho Chehab 2118ea61889SMauro Carvalho Chehab struct cdrom_device_ops { 2128ea61889SMauro Carvalho Chehab int (*open)(struct cdrom_device_info *, int) 2138ea61889SMauro Carvalho Chehab void (*release)(struct cdrom_device_info *); 2148ea61889SMauro Carvalho Chehab int (*drive_status)(struct cdrom_device_info *, int); 2158ea61889SMauro Carvalho Chehab unsigned int (*check_events)(struct cdrom_device_info *, 2168ea61889SMauro Carvalho Chehab unsigned int, int); 2178ea61889SMauro Carvalho Chehab int (*media_changed)(struct cdrom_device_info *, int); 2188ea61889SMauro Carvalho Chehab int (*tray_move)(struct cdrom_device_info *, int); 2198ea61889SMauro Carvalho Chehab int (*lock_door)(struct cdrom_device_info *, int); 220*9fad9d56SJustin Stitt int (*select_speed)(struct cdrom_device_info *, unsigned long); 2218ea61889SMauro Carvalho Chehab int (*get_last_session) (struct cdrom_device_info *, 2228ea61889SMauro Carvalho Chehab struct cdrom_multisession *); 2238ea61889SMauro Carvalho Chehab int (*get_mcn)(struct cdrom_device_info *, struct cdrom_mcn *); 2248ea61889SMauro Carvalho Chehab int (*reset)(struct cdrom_device_info *); 2258ea61889SMauro Carvalho Chehab int (*audio_ioctl)(struct cdrom_device_info *, 2268ea61889SMauro Carvalho Chehab unsigned int, void *); 2278ea61889SMauro Carvalho Chehab const int capability; /* capability flags */ 2288ea61889SMauro Carvalho Chehab int (*generic_packet)(struct cdrom_device_info *, 2298ea61889SMauro Carvalho Chehab struct packet_command *); 2308ea61889SMauro Carvalho Chehab }; 2318ea61889SMauro Carvalho Chehab 2328ea61889SMauro Carvalho ChehabWhen a low-level device driver implements one of these capabilities, 2338ea61889SMauro Carvalho Chehabit should add a function pointer to this *struct*. When a particular 2348ea61889SMauro Carvalho Chehabfunction is not implemented, however, this *struct* should contain a 2358ea61889SMauro Carvalho ChehabNULL instead. The *capability* flags specify the capabilities of the 2368ea61889SMauro Carvalho ChehabCD-ROM hardware and/or low-level CD-ROM driver when a CD-ROM drive 2378ea61889SMauro Carvalho Chehabis registered with the Uniform CD-ROM Driver. 2388ea61889SMauro Carvalho Chehab 2398ea61889SMauro Carvalho ChehabNote that most functions have fewer parameters than their 2408ea61889SMauro Carvalho Chehab*blkdev_fops* counterparts. This is because very little of the 2418ea61889SMauro Carvalho Chehabinformation in the structures *inode* and *file* is used. For most 2428ea61889SMauro Carvalho Chehabdrivers, the main parameter is the *struct* *cdrom_device_info*, from 2438ea61889SMauro Carvalho Chehabwhich the major and minor number can be extracted. (Most low-level 2448ea61889SMauro Carvalho ChehabCD-ROM drivers don't even look at the major and minor number though, 2458ea61889SMauro Carvalho Chehabsince many of them only support one device.) This will be available 2468ea61889SMauro Carvalho Chehabthrough *dev* in *cdrom_device_info* described below. 2478ea61889SMauro Carvalho Chehab 2488ea61889SMauro Carvalho ChehabThe drive-specific, minor-like information that is registered with 2498ea61889SMauro Carvalho Chehab`cdrom.c`, currently contains the following fields:: 2508ea61889SMauro Carvalho Chehab 2518ea61889SMauro Carvalho Chehab struct cdrom_device_info { 2528ea61889SMauro Carvalho Chehab const struct cdrom_device_ops * ops; /* device operations for this major */ 2538ea61889SMauro Carvalho Chehab struct list_head list; /* linked list of all device_info */ 2548ea61889SMauro Carvalho Chehab struct gendisk * disk; /* matching block layer disk */ 2558ea61889SMauro Carvalho Chehab void * handle; /* driver-dependent data */ 2568ea61889SMauro Carvalho Chehab 2578ea61889SMauro Carvalho Chehab int mask; /* mask of capability: disables them */ 2588ea61889SMauro Carvalho Chehab int speed; /* maximum speed for reading data */ 2598ea61889SMauro Carvalho Chehab int capacity; /* number of discs in a jukebox */ 2608ea61889SMauro Carvalho Chehab 2618ea61889SMauro Carvalho Chehab unsigned int options:30; /* options flags */ 2628ea61889SMauro Carvalho Chehab unsigned mc_flags:2; /* media-change buffer flags */ 2638ea61889SMauro Carvalho Chehab unsigned int vfs_events; /* cached events for vfs path */ 2648ea61889SMauro Carvalho Chehab unsigned int ioctl_events; /* cached events for ioctl path */ 2658ea61889SMauro Carvalho Chehab int use_count; /* number of times device is opened */ 2668ea61889SMauro Carvalho Chehab char name[20]; /* name of the device type */ 2678ea61889SMauro Carvalho Chehab 2688ea61889SMauro Carvalho Chehab __u8 sanyo_slot : 2; /* Sanyo 3-CD changer support */ 2698ea61889SMauro Carvalho Chehab __u8 keeplocked : 1; /* CDROM_LOCKDOOR status */ 2708ea61889SMauro Carvalho Chehab __u8 reserved : 5; /* not used yet */ 2718ea61889SMauro Carvalho Chehab int cdda_method; /* see CDDA_* flags */ 2728ea61889SMauro Carvalho Chehab __u8 last_sense; /* saves last sense key */ 2738ea61889SMauro Carvalho Chehab __u8 media_written; /* dirty flag, DVD+RW bookkeeping */ 2748ea61889SMauro Carvalho Chehab unsigned short mmc3_profile; /* current MMC3 profile */ 2758ea61889SMauro Carvalho Chehab int for_data; /* unknown:TBD */ 2768ea61889SMauro Carvalho Chehab int (*exit)(struct cdrom_device_info *);/* unknown:TBD */ 2778ea61889SMauro Carvalho Chehab int mrw_mode_page; /* which MRW mode page is in use */ 2788ea61889SMauro Carvalho Chehab }; 2798ea61889SMauro Carvalho Chehab 2808ea61889SMauro Carvalho ChehabUsing this *struct*, a linked list of the registered minor devices is 2818ea61889SMauro Carvalho Chehabbuilt, using the *next* field. The device number, the device operations 2828ea61889SMauro Carvalho Chehabstruct and specifications of properties of the drive are stored in this 2838ea61889SMauro Carvalho Chehabstructure. 2848ea61889SMauro Carvalho Chehab 2858ea61889SMauro Carvalho ChehabThe *mask* flags can be used to mask out some of the capabilities listed 2868ea61889SMauro Carvalho Chehabin *ops->capability*, if a specific drive doesn't support a feature 2878ea61889SMauro Carvalho Chehabof the driver. The value *speed* specifies the maximum head-rate of the 2888ea61889SMauro Carvalho Chehabdrive, measured in units of normal audio speed (176kB/sec raw data or 2898ea61889SMauro Carvalho Chehab150kB/sec file system data). The parameters are declared *const* 2908ea61889SMauro Carvalho Chehabbecause they describe properties of the drive, which don't change after 2918ea61889SMauro Carvalho Chehabregistration. 2928ea61889SMauro Carvalho Chehab 2938ea61889SMauro Carvalho ChehabA few registers contain variables local to the CD-ROM drive. The 2948ea61889SMauro Carvalho Chehabflags *options* are used to specify how the general CD-ROM routines 2958ea61889SMauro Carvalho Chehabshould behave. These various flags registers should provide enough 2968ea61889SMauro Carvalho Chehabflexibility to adapt to the different users' wishes (and **not** the 2978ea61889SMauro Carvalho Chehab`arbitrary` wishes of the author of the low-level device driver, as is 2988ea61889SMauro Carvalho Chehabthe case in the old scheme). The register *mc_flags* is used to buffer 2998ea61889SMauro Carvalho Chehabthe information from *media_changed()* to two separate queues. Other 3008ea61889SMauro Carvalho Chehabdata that is specific to a minor drive, can be accessed through *handle*, 3018ea61889SMauro Carvalho Chehabwhich can point to a data structure specific to the low-level driver. 3028ea61889SMauro Carvalho ChehabThe fields *use_count*, *next*, *options* and *mc_flags* need not be 3038ea61889SMauro Carvalho Chehabinitialized. 3048ea61889SMauro Carvalho Chehab 3058ea61889SMauro Carvalho ChehabThe intermediate software layer that `cdrom.c` forms will perform some 3068ea61889SMauro Carvalho Chehabadditional bookkeeping. The use count of the device (the number of 3078ea61889SMauro Carvalho Chehabprocesses that have the device opened) is registered in *use_count*. The 3088ea61889SMauro Carvalho Chehabfunction *cdrom_ioctl()* will verify the appropriate user-memory regions 3098ea61889SMauro Carvalho Chehabfor read and write, and in case a location on the CD is transferred, 3108ea61889SMauro Carvalho Chehabit will `sanitize` the format by making requests to the low-level 3118ea61889SMauro Carvalho Chehabdrivers in a standard format, and translating all formats between the 3128ea61889SMauro Carvalho Chehabuser-software and low level drivers. This relieves much of the drivers' 3138ea61889SMauro Carvalho Chehabmemory checking and format checking and translation. Also, the necessary 3148ea61889SMauro Carvalho Chehabstructures will be declared on the program stack. 3158ea61889SMauro Carvalho Chehab 3168ea61889SMauro Carvalho ChehabThe implementation of the functions should be as defined in the 3178ea61889SMauro Carvalho Chehabfollowing sections. Two functions **must** be implemented, namely 3188ea61889SMauro Carvalho Chehab*open()* and *release()*. Other functions may be omitted, their 3198ea61889SMauro Carvalho Chehabcorresponding capability flags will be cleared upon registration. 3208ea61889SMauro Carvalho ChehabGenerally, a function returns zero on success and negative on error. A 3218ea61889SMauro Carvalho Chehabfunction call should return only after the command has completed, but of 3228ea61889SMauro Carvalho Chehabcourse waiting for the device should not use processor time. 3238ea61889SMauro Carvalho Chehab 3248ea61889SMauro Carvalho Chehab:: 3258ea61889SMauro Carvalho Chehab 3268ea61889SMauro Carvalho Chehab int open(struct cdrom_device_info *cdi, int purpose) 3278ea61889SMauro Carvalho Chehab 3288ea61889SMauro Carvalho Chehab*Open()* should try to open the device for a specific *purpose*, which 3298ea61889SMauro Carvalho Chehabcan be either: 3308ea61889SMauro Carvalho Chehab 3318ea61889SMauro Carvalho Chehab- Open for reading data, as done by `mount()` (2), or the 3328ea61889SMauro Carvalho Chehab user commands `dd` or `cat`. 3338ea61889SMauro Carvalho Chehab- Open for *ioctl* commands, as done by audio-CD playing programs. 3348ea61889SMauro Carvalho Chehab 3358ea61889SMauro Carvalho ChehabNotice that any strategic code (closing tray upon *open()*, etc.) is 3368ea61889SMauro Carvalho Chehabdone by the calling routine in `cdrom.c`, so the low-level routine 3378ea61889SMauro Carvalho Chehabshould only be concerned with proper initialization, such as spinning 3388ea61889SMauro Carvalho Chehabup the disc, etc. 3398ea61889SMauro Carvalho Chehab 3408ea61889SMauro Carvalho Chehab:: 3418ea61889SMauro Carvalho Chehab 3428ea61889SMauro Carvalho Chehab void release(struct cdrom_device_info *cdi) 3438ea61889SMauro Carvalho Chehab 3448ea61889SMauro Carvalho ChehabDevice-specific actions should be taken such as spinning down the device. 3458ea61889SMauro Carvalho ChehabHowever, strategic actions such as ejection of the tray, or unlocking 3468ea61889SMauro Carvalho Chehabthe door, should be left over to the general routine *cdrom_release()*. 3478ea61889SMauro Carvalho ChehabThis is the only function returning type *void*. 3488ea61889SMauro Carvalho Chehab 3498ea61889SMauro Carvalho Chehab.. _cdrom_drive_status: 3508ea61889SMauro Carvalho Chehab 3518ea61889SMauro Carvalho Chehab:: 3528ea61889SMauro Carvalho Chehab 3538ea61889SMauro Carvalho Chehab int drive_status(struct cdrom_device_info *cdi, int slot_nr) 3548ea61889SMauro Carvalho Chehab 3558ea61889SMauro Carvalho ChehabThe function *drive_status*, if implemented, should provide 3568ea61889SMauro Carvalho Chehabinformation on the status of the drive (not the status of the disc, 3578ea61889SMauro Carvalho Chehabwhich may or may not be in the drive). If the drive is not a changer, 3588ea61889SMauro Carvalho Chehab*slot_nr* should be ignored. In `cdrom.h` the possibilities are listed:: 3598ea61889SMauro Carvalho Chehab 3608ea61889SMauro Carvalho Chehab 3618ea61889SMauro Carvalho Chehab CDS_NO_INFO /* no information available */ 3628ea61889SMauro Carvalho Chehab CDS_NO_DISC /* no disc is inserted, tray is closed */ 3638ea61889SMauro Carvalho Chehab CDS_TRAY_OPEN /* tray is opened */ 3648ea61889SMauro Carvalho Chehab CDS_DRIVE_NOT_READY /* something is wrong, tray is moving? */ 3658ea61889SMauro Carvalho Chehab CDS_DISC_OK /* a disc is loaded and everything is fine */ 3668ea61889SMauro Carvalho Chehab 3678ea61889SMauro Carvalho Chehab:: 3688ea61889SMauro Carvalho Chehab 3698ea61889SMauro Carvalho Chehab int tray_move(struct cdrom_device_info *cdi, int position) 3708ea61889SMauro Carvalho Chehab 3718ea61889SMauro Carvalho ChehabThis function, if implemented, should control the tray movement. (No 3728ea61889SMauro Carvalho Chehabother function should control this.) The parameter *position* controls 3738ea61889SMauro Carvalho Chehabthe desired direction of movement: 3748ea61889SMauro Carvalho Chehab 3758ea61889SMauro Carvalho Chehab- 0 Close tray 3768ea61889SMauro Carvalho Chehab- 1 Open tray 3778ea61889SMauro Carvalho Chehab 3788ea61889SMauro Carvalho ChehabThis function returns 0 upon success, and a non-zero value upon 3798ea61889SMauro Carvalho Chehaberror. Note that if the tray is already in the desired position, no 3808ea61889SMauro Carvalho Chehabaction need be taken, and the return value should be 0. 3818ea61889SMauro Carvalho Chehab 3828ea61889SMauro Carvalho Chehab:: 3838ea61889SMauro Carvalho Chehab 3848ea61889SMauro Carvalho Chehab int lock_door(struct cdrom_device_info *cdi, int lock) 3858ea61889SMauro Carvalho Chehab 3868ea61889SMauro Carvalho ChehabThis function (and no other code) controls locking of the door, if the 3878ea61889SMauro Carvalho Chehabdrive allows this. The value of *lock* controls the desired locking 3888ea61889SMauro Carvalho Chehabstate: 3898ea61889SMauro Carvalho Chehab 3908ea61889SMauro Carvalho Chehab- 0 Unlock door, manual opening is allowed 3918ea61889SMauro Carvalho Chehab- 1 Lock door, tray cannot be ejected manually 3928ea61889SMauro Carvalho Chehab 3938ea61889SMauro Carvalho ChehabThis function returns 0 upon success, and a non-zero value upon 3948ea61889SMauro Carvalho Chehaberror. Note that if the door is already in the requested state, no 3958ea61889SMauro Carvalho Chehabaction need be taken, and the return value should be 0. 3968ea61889SMauro Carvalho Chehab 3978ea61889SMauro Carvalho Chehab:: 3988ea61889SMauro Carvalho Chehab 399*9fad9d56SJustin Stitt int select_speed(struct cdrom_device_info *cdi, unsigned long speed) 4008ea61889SMauro Carvalho Chehab 4018ea61889SMauro Carvalho ChehabSome CD-ROM drives are capable of changing their head-speed. There 4028ea61889SMauro Carvalho Chehabare several reasons for changing the speed of a CD-ROM drive. Badly 4038ea61889SMauro Carvalho Chehabpressed CD-ROM s may benefit from less-than-maximum head rate. Modern 4048ea61889SMauro Carvalho ChehabCD-ROM drives can obtain very high head rates (up to *24x* is 4058ea61889SMauro Carvalho Chehabcommon). It has been reported that these drives can make reading 4068ea61889SMauro Carvalho Chehaberrors at these high speeds, reducing the speed can prevent data loss 4078ea61889SMauro Carvalho Chehabin these circumstances. Finally, some of these drives can 4088ea61889SMauro Carvalho Chehabmake an annoyingly loud noise, which a lower speed may reduce. 4098ea61889SMauro Carvalho Chehab 4108ea61889SMauro Carvalho ChehabThis function specifies the speed at which data is read or audio is 4118ea61889SMauro Carvalho Chehabplayed back. The value of *speed* specifies the head-speed of the 4128ea61889SMauro Carvalho Chehabdrive, measured in units of standard cdrom speed (176kB/sec raw data 4138ea61889SMauro Carvalho Chehabor 150kB/sec file system data). So to request that a CD-ROM drive 4148ea61889SMauro Carvalho Chehaboperate at 300kB/sec you would call the CDROM_SELECT_SPEED *ioctl* 4158ea61889SMauro Carvalho Chehabwith *speed=2*. The special value `0` means `auto-selection`, i. e., 4168ea61889SMauro Carvalho Chehabmaximum data-rate or real-time audio rate. If the drive doesn't have 4178ea61889SMauro Carvalho Chehabthis `auto-selection` capability, the decision should be made on the 4188ea61889SMauro Carvalho Chehabcurrent disc loaded and the return value should be positive. A negative 4198ea61889SMauro Carvalho Chehabreturn value indicates an error. 4208ea61889SMauro Carvalho Chehab 4218ea61889SMauro Carvalho Chehab:: 4228ea61889SMauro Carvalho Chehab 4238ea61889SMauro Carvalho Chehab int get_last_session(struct cdrom_device_info *cdi, 4248ea61889SMauro Carvalho Chehab struct cdrom_multisession *ms_info) 4258ea61889SMauro Carvalho Chehab 4268ea61889SMauro Carvalho ChehabThis function should implement the old corresponding *ioctl()*. For 4278ea61889SMauro Carvalho Chehabdevice *cdi->dev*, the start of the last session of the current disc 4288ea61889SMauro Carvalho Chehabshould be returned in the pointer argument *ms_info*. Note that 4298ea61889SMauro Carvalho Chehabroutines in `cdrom.c` have sanitized this argument: its requested 4308ea61889SMauro Carvalho Chehabformat will **always** be of the type *CDROM_LBA* (linear block 4318ea61889SMauro Carvalho Chehabaddressing mode), whatever the calling software requested. But 4328ea61889SMauro Carvalho Chehabsanitization goes even further: the low-level implementation may 4338ea61889SMauro Carvalho Chehabreturn the requested information in *CDROM_MSF* format if it wishes so 4348ea61889SMauro Carvalho Chehab(setting the *ms_info->addr_format* field appropriately, of 4358ea61889SMauro Carvalho Chehabcourse) and the routines in `cdrom.c` will make the transformation if 4368ea61889SMauro Carvalho Chehabnecessary. The return value is 0 upon success. 4378ea61889SMauro Carvalho Chehab 4388ea61889SMauro Carvalho Chehab:: 4398ea61889SMauro Carvalho Chehab 4408ea61889SMauro Carvalho Chehab int get_mcn(struct cdrom_device_info *cdi, 4418ea61889SMauro Carvalho Chehab struct cdrom_mcn *mcn) 4428ea61889SMauro Carvalho Chehab 4438ea61889SMauro Carvalho ChehabSome discs carry a `Media Catalog Number` (MCN), also called 4448ea61889SMauro Carvalho Chehab`Universal Product Code` (UPC). This number should reflect the number 4458ea61889SMauro Carvalho Chehabthat is generally found in the bar-code on the product. Unfortunately, 4468ea61889SMauro Carvalho Chehabthe few discs that carry such a number on the disc don't even use the 4478ea61889SMauro Carvalho Chehabsame format. The return argument to this function is a pointer to a 4488ea61889SMauro Carvalho Chehabpre-declared memory region of type *struct cdrom_mcn*. The MCN is 4498ea61889SMauro Carvalho Chehabexpected as a 13-character string, terminated by a null-character. 4508ea61889SMauro Carvalho Chehab 4518ea61889SMauro Carvalho Chehab:: 4528ea61889SMauro Carvalho Chehab 4538ea61889SMauro Carvalho Chehab int reset(struct cdrom_device_info *cdi) 4548ea61889SMauro Carvalho Chehab 4558ea61889SMauro Carvalho ChehabThis call should perform a hard-reset on the drive (although in 4568ea61889SMauro Carvalho Chehabcircumstances that a hard-reset is necessary, a drive may very well not 4578ea61889SMauro Carvalho Chehablisten to commands anymore). Preferably, control is returned to the 4588ea61889SMauro Carvalho Chehabcaller only after the drive has finished resetting. If the drive is no 4598ea61889SMauro Carvalho Chehablonger listening, it may be wise for the underlying low-level cdrom 4608ea61889SMauro Carvalho Chehabdriver to time out. 4618ea61889SMauro Carvalho Chehab 4628ea61889SMauro Carvalho Chehab:: 4638ea61889SMauro Carvalho Chehab 4648ea61889SMauro Carvalho Chehab int audio_ioctl(struct cdrom_device_info *cdi, 4658ea61889SMauro Carvalho Chehab unsigned int cmd, void *arg) 4668ea61889SMauro Carvalho Chehab 4678ea61889SMauro Carvalho ChehabSome of the CD-ROM-\ *ioctl()*\ 's defined in `cdrom.h` can be 4688ea61889SMauro Carvalho Chehabimplemented by the routines described above, and hence the function 4698ea61889SMauro Carvalho Chehab*cdrom_ioctl* will use those. However, most *ioctl()*\ 's deal with 4708ea61889SMauro Carvalho Chehabaudio-control. We have decided to leave these to be accessed through a 4718ea61889SMauro Carvalho Chehabsingle function, repeating the arguments *cmd* and *arg*. Note that 4728ea61889SMauro Carvalho Chehabthe latter is of type *void*, rather than *unsigned long int*. 4738ea61889SMauro Carvalho ChehabThe routine *cdrom_ioctl()* does do some useful things, 4748ea61889SMauro Carvalho Chehabthough. It sanitizes the address format type to *CDROM_MSF* (Minutes, 4758ea61889SMauro Carvalho ChehabSeconds, Frames) for all audio calls. It also verifies the memory 4768ea61889SMauro Carvalho Chehablocation of *arg*, and reserves stack-memory for the argument. This 4778ea61889SMauro Carvalho Chehabmakes implementation of the *audio_ioctl()* much simpler than in the 4788ea61889SMauro Carvalho Chehabold driver scheme. For example, you may look up the function 4798ea61889SMauro Carvalho Chehab*cm206_audio_ioctl()* `cm206.c` that should be updated with 4808ea61889SMauro Carvalho Chehabthis documentation. 4818ea61889SMauro Carvalho Chehab 4828ea61889SMauro Carvalho ChehabAn unimplemented ioctl should return *-ENOSYS*, but a harmless request 4838ea61889SMauro Carvalho Chehab(e. g., *CDROMSTART*) may be ignored by returning 0 (success). Other 4848ea61889SMauro Carvalho Chehaberrors should be according to the standards, whatever they are. When 4858ea61889SMauro Carvalho Chehaban error is returned by the low-level driver, the Uniform CD-ROM Driver 4868ea61889SMauro Carvalho Chehabtries whenever possible to return the error code to the calling program. 4878ea61889SMauro Carvalho Chehab(We may decide to sanitize the return value in *cdrom_ioctl()* though, in 4888ea61889SMauro Carvalho Chehaborder to guarantee a uniform interface to the audio-player software.) 4898ea61889SMauro Carvalho Chehab 4908ea61889SMauro Carvalho Chehab:: 4918ea61889SMauro Carvalho Chehab 4928ea61889SMauro Carvalho Chehab int dev_ioctl(struct cdrom_device_info *cdi, 4938ea61889SMauro Carvalho Chehab unsigned int cmd, unsigned long arg) 4948ea61889SMauro Carvalho Chehab 4958ea61889SMauro Carvalho ChehabSome *ioctl()'s* seem to be specific to certain CD-ROM drives. That is, 4968ea61889SMauro Carvalho Chehabthey are introduced to service some capabilities of certain drives. In 4978ea61889SMauro Carvalho Chehabfact, there are 6 different *ioctl()'s* for reading data, either in some 4988ea61889SMauro Carvalho Chehabparticular kind of format, or audio data. Not many drives support 4998ea61889SMauro Carvalho Chehabreading audio tracks as data, I believe this is because of protection 5008ea61889SMauro Carvalho Chehabof copyrights of artists. Moreover, I think that if audio-tracks are 5018ea61889SMauro Carvalho Chehabsupported, it should be done through the VFS and not via *ioctl()'s*. A 5028ea61889SMauro Carvalho Chehabproblem here could be the fact that audio-frames are 2352 bytes long, 5038ea61889SMauro Carvalho Chehabso either the audio-file-system should ask for 75264 bytes at once 5048ea61889SMauro Carvalho Chehab(the least common multiple of 512 and 2352), or the drivers should 5058ea61889SMauro Carvalho Chehabbend their backs to cope with this incoherence (to which I would be 5068ea61889SMauro Carvalho Chehabopposed). Furthermore, it is very difficult for the hardware to find 5078ea61889SMauro Carvalho Chehabthe exact frame boundaries, since there are no synchronization headers 5088ea61889SMauro Carvalho Chehabin audio frames. Once these issues are resolved, this code should be 5098ea61889SMauro Carvalho Chehabstandardized in `cdrom.c`. 5108ea61889SMauro Carvalho Chehab 5118ea61889SMauro Carvalho ChehabBecause there are so many *ioctl()'s* that seem to be introduced to 5128ea61889SMauro Carvalho Chehabsatisfy certain drivers [#f2]_, any non-standard *ioctl()*\ s 5138ea61889SMauro Carvalho Chehabare routed through the call *dev_ioctl()*. In principle, `private` 5148ea61889SMauro Carvalho Chehab*ioctl()*\ 's should be numbered after the device's major number, and not 5158ea61889SMauro Carvalho Chehabthe general CD-ROM *ioctl* number, `0x53`. Currently the 5168ea61889SMauro Carvalho Chehabnon-supported *ioctl()'s* are: 5178ea61889SMauro Carvalho Chehab 5188ea61889SMauro Carvalho Chehab CDROMREADMODE1, CDROMREADMODE2, CDROMREADAUDIO, CDROMREADRAW, 5198ea61889SMauro Carvalho Chehab CDROMREADCOOKED, CDROMSEEK, CDROMPLAY-BLK and CDROM-READALL 5208ea61889SMauro Carvalho Chehab 5218ea61889SMauro Carvalho Chehab.. [#f2] 5228ea61889SMauro Carvalho Chehab 5238ea61889SMauro Carvalho Chehab Is there software around that actually uses these? I'd be interested! 5248ea61889SMauro Carvalho Chehab 5258ea61889SMauro Carvalho Chehab.. _cdrom_capabilities: 5268ea61889SMauro Carvalho Chehab 5278ea61889SMauro Carvalho ChehabCD-ROM capabilities 5288ea61889SMauro Carvalho Chehab------------------- 5298ea61889SMauro Carvalho Chehab 5308ea61889SMauro Carvalho ChehabInstead of just implementing some *ioctl* calls, the interface in 5318ea61889SMauro Carvalho Chehab`cdrom.c` supplies the possibility to indicate the **capabilities** 5328ea61889SMauro Carvalho Chehabof a CD-ROM drive. This can be done by ORing any number of 5338ea61889SMauro Carvalho Chehabcapability-constants that are defined in `cdrom.h` at the registration 5348ea61889SMauro Carvalho Chehabphase. Currently, the capabilities are any of:: 5358ea61889SMauro Carvalho Chehab 5368ea61889SMauro Carvalho Chehab CDC_CLOSE_TRAY /* can close tray by software control */ 5378ea61889SMauro Carvalho Chehab CDC_OPEN_TRAY /* can open tray */ 5388ea61889SMauro Carvalho Chehab CDC_LOCK /* can lock and unlock the door */ 5398ea61889SMauro Carvalho Chehab CDC_SELECT_SPEED /* can select speed, in units of * sim*150 ,kB/s */ 5408ea61889SMauro Carvalho Chehab CDC_SELECT_DISC /* drive is juke-box */ 5418ea61889SMauro Carvalho Chehab CDC_MULTI_SESSION /* can read sessions *> rm1* */ 5428ea61889SMauro Carvalho Chehab CDC_MCN /* can read Media Catalog Number */ 5438ea61889SMauro Carvalho Chehab CDC_MEDIA_CHANGED /* can report if disc has changed */ 5448ea61889SMauro Carvalho Chehab CDC_PLAY_AUDIO /* can perform audio-functions (play, pause, etc) */ 5458ea61889SMauro Carvalho Chehab CDC_RESET /* hard reset device */ 5468ea61889SMauro Carvalho Chehab CDC_IOCTLS /* driver has non-standard ioctls */ 5478ea61889SMauro Carvalho Chehab CDC_DRIVE_STATUS /* driver implements drive status */ 5488ea61889SMauro Carvalho Chehab 5498ea61889SMauro Carvalho ChehabThe capability flag is declared *const*, to prevent drivers from 550502b6750SRemi Andruccioliaccidentally tampering with the contents. The capability flags actually 5518ea61889SMauro Carvalho Chehabinform `cdrom.c` of what the driver can do. If the drive found 5528ea61889SMauro Carvalho Chehabby the driver does not have the capability, is can be masked out by 5538ea61889SMauro Carvalho Chehabthe *cdrom_device_info* variable *mask*. For instance, the SCSI CD-ROM 5548ea61889SMauro Carvalho Chehabdriver has implemented the code for loading and ejecting CD-ROM's, and 5558ea61889SMauro Carvalho Chehabhence its corresponding flags in *capability* will be set. But a SCSI 5568ea61889SMauro Carvalho ChehabCD-ROM drive might be a caddy system, which can't load the tray, and 5578ea61889SMauro Carvalho Chehabhence for this drive the *cdrom_device_info* struct will have set 5588ea61889SMauro Carvalho Chehabthe *CDC_CLOSE_TRAY* bit in *mask*. 5598ea61889SMauro Carvalho Chehab 5608ea61889SMauro Carvalho ChehabIn the file `cdrom.c` you will encounter many constructions of the type:: 5618ea61889SMauro Carvalho Chehab 562918d9c77SMauro Carvalho Chehab if (cdo->capability & ~cdi->mask & CDC _<capability>) ... 5638ea61889SMauro Carvalho Chehab 5648ea61889SMauro Carvalho ChehabThere is no *ioctl* to set the mask... The reason is that 5658ea61889SMauro Carvalho ChehabI think it is better to control the **behavior** rather than the 5668ea61889SMauro Carvalho Chehab**capabilities**. 5678ea61889SMauro Carvalho Chehab 5688ea61889SMauro Carvalho ChehabOptions 5698ea61889SMauro Carvalho Chehab------- 5708ea61889SMauro Carvalho Chehab 5718ea61889SMauro Carvalho ChehabA final flag register controls the **behavior** of the CD-ROM 5728ea61889SMauro Carvalho Chehabdrives, in order to satisfy different users' wishes, hopefully 5738ea61889SMauro Carvalho Chehabindependently of the ideas of the respective author who happened to 5748ea61889SMauro Carvalho Chehabhave made the drive's support available to the Linux community. The 5758ea61889SMauro Carvalho Chehabcurrent behavior options are:: 5768ea61889SMauro Carvalho Chehab 5778ea61889SMauro Carvalho Chehab CDO_AUTO_CLOSE /* try to close tray upon device open() */ 5788ea61889SMauro Carvalho Chehab CDO_AUTO_EJECT /* try to open tray on last device close() */ 5798ea61889SMauro Carvalho Chehab CDO_USE_FFLAGS /* use file_pointer->f_flags to indicate purpose for open() */ 5808ea61889SMauro Carvalho Chehab CDO_LOCK /* try to lock door if device is opened */ 5818ea61889SMauro Carvalho Chehab CDO_CHECK_TYPE /* ensure disc type is data if opened for data */ 5828ea61889SMauro Carvalho Chehab 5838ea61889SMauro Carvalho ChehabThe initial value of this register is 5848ea61889SMauro Carvalho Chehab`CDO_AUTO_CLOSE | CDO_USE_FFLAGS | CDO_LOCK`, reflecting my own view on user 5858ea61889SMauro Carvalho Chehabinterface and software standards. Before you protest, there are two 5868ea61889SMauro Carvalho Chehabnew *ioctl()'s* implemented in `cdrom.c`, that allow you to control the 5878ea61889SMauro Carvalho Chehabbehavior by software. These are:: 5888ea61889SMauro Carvalho Chehab 5898ea61889SMauro Carvalho Chehab CDROM_SET_OPTIONS /* set options specified in (int)arg */ 5908ea61889SMauro Carvalho Chehab CDROM_CLEAR_OPTIONS /* clear options specified in (int)arg */ 5918ea61889SMauro Carvalho Chehab 5928ea61889SMauro Carvalho ChehabOne option needs some more explanation: *CDO_USE_FFLAGS*. In the next 5938ea61889SMauro Carvalho Chehabnewsection we explain what the need for this option is. 5948ea61889SMauro Carvalho Chehab 5958ea61889SMauro Carvalho ChehabA software package `setcd`, available from the Debian distribution 5968ea61889SMauro Carvalho Chehaband `sunsite.unc.edu`, allows user level control of these flags. 5978ea61889SMauro Carvalho Chehab 5988ea61889SMauro Carvalho Chehab 5998ea61889SMauro Carvalho ChehabThe need to know the purpose of opening the CD-ROM device 6008ea61889SMauro Carvalho Chehab========================================================= 6018ea61889SMauro Carvalho Chehab 6028ea61889SMauro Carvalho ChehabTraditionally, Unix devices can be used in two different `modes`, 6038ea61889SMauro Carvalho Chehabeither by reading/writing to the device file, or by issuing 6048ea61889SMauro Carvalho Chehabcontrolling commands to the device, by the device's *ioctl()* 6058ea61889SMauro Carvalho Chehabcall. The problem with CD-ROM drives, is that they can be used for 6068ea61889SMauro Carvalho Chehabtwo entirely different purposes. One is to mount removable 6078ea61889SMauro Carvalho Chehabfile systems, CD-ROM's, the other is to play audio CD's. Audio commands 6088ea61889SMauro Carvalho Chehabare implemented entirely through *ioctl()\'s*, presumably because the 6098ea61889SMauro Carvalho Chehabfirst implementation (SUN?) has been such. In principle there is 6108ea61889SMauro Carvalho Chehabnothing wrong with this, but a good control of the `CD player` demands 6118ea61889SMauro Carvalho Chehabthat the device can **always** be opened in order to give the 6128ea61889SMauro Carvalho Chehab*ioctl* commands, regardless of the state the drive is in. 6138ea61889SMauro Carvalho Chehab 6148ea61889SMauro Carvalho ChehabOn the other hand, when used as a removable-media disc drive (what the 6158ea61889SMauro Carvalho Chehaboriginal purpose of CD-ROM s is) we would like to make sure that the 6168ea61889SMauro Carvalho Chehabdisc drive is ready for operation upon opening the device. In the old 6178ea61889SMauro Carvalho Chehabscheme, some CD-ROM drivers don't do any integrity checking, resulting 6188ea61889SMauro Carvalho Chehabin a number of i/o errors reported by the VFS to the kernel when an 6198ea61889SMauro Carvalho Chehabattempt for mounting a CD-ROM on an empty drive occurs. This is not a 6208ea61889SMauro Carvalho Chehabparticularly elegant way to find out that there is no CD-ROM inserted; 6218ea61889SMauro Carvalho Chehabit more-or-less looks like the old IBM-PC trying to read an empty floppy 6228ea61889SMauro Carvalho Chehabdrive for a couple of seconds, after which the system complains it 6238ea61889SMauro Carvalho Chehabcan't read from it. Nowadays we can **sense** the existence of a 6248ea61889SMauro Carvalho Chehabremovable medium in a drive, and we believe we should exploit that 6258ea61889SMauro Carvalho Chehabfact. An integrity check on opening of the device, that verifies the 6268ea61889SMauro Carvalho Chehabavailability of a CD-ROM and its correct type (data), would be 6278ea61889SMauro Carvalho Chehabdesirable. 6288ea61889SMauro Carvalho Chehab 6298ea61889SMauro Carvalho ChehabThese two ways of using a CD-ROM drive, principally for data and 6308ea61889SMauro Carvalho Chehabsecondarily for playing audio discs, have different demands for the 6318ea61889SMauro Carvalho Chehabbehavior of the *open()* call. Audio use simply wants to open the 6328ea61889SMauro Carvalho Chehabdevice in order to get a file handle which is needed for issuing 6338ea61889SMauro Carvalho Chehab*ioctl* commands, while data use wants to open for correct and 6348ea61889SMauro Carvalho Chehabreliable data transfer. The only way user programs can indicate what 6358ea61889SMauro Carvalho Chehabtheir *purpose* of opening the device is, is through the *flags* 6368ea61889SMauro Carvalho Chehabparameter (see `open(2)`). For CD-ROM devices, these flags aren't 6378ea61889SMauro Carvalho Chehabimplemented (some drivers implement checking for write-related flags, 6388ea61889SMauro Carvalho Chehabbut this is not strictly necessary if the device file has correct 6398ea61889SMauro Carvalho Chehabpermission flags). Most option flags simply don't make sense to 6408ea61889SMauro Carvalho ChehabCD-ROM devices: *O_CREAT*, *O_NOCTTY*, *O_TRUNC*, *O_APPEND*, and 6418ea61889SMauro Carvalho Chehab*O_SYNC* have no meaning to a CD-ROM. 6428ea61889SMauro Carvalho Chehab 6438ea61889SMauro Carvalho ChehabWe therefore propose to use the flag *O_NONBLOCK* to indicate 6448ea61889SMauro Carvalho Chehabthat the device is opened just for issuing *ioctl* 6458ea61889SMauro Carvalho Chehabcommands. Strictly, the meaning of *O_NONBLOCK* is that opening and 6468ea61889SMauro Carvalho Chehabsubsequent calls to the device don't cause the calling process to 6478ea61889SMauro Carvalho Chehabwait. We could interpret this as don't wait until someone has 6488ea61889SMauro Carvalho Chehabinserted some valid data-CD-ROM. Thus, our proposal of the 6498ea61889SMauro Carvalho Chehabimplementation for the *open()* call for CD-ROM s is: 6508ea61889SMauro Carvalho Chehab 6518ea61889SMauro Carvalho Chehab- If no other flags are set than *O_RDONLY*, the device is opened 6528ea61889SMauro Carvalho Chehab for data transfer, and the return value will be 0 only upon successful 6538ea61889SMauro Carvalho Chehab initialization of the transfer. The call may even induce some actions 6548ea61889SMauro Carvalho Chehab on the CD-ROM, such as closing the tray. 6558ea61889SMauro Carvalho Chehab- If the option flag *O_NONBLOCK* is set, opening will always be 6568ea61889SMauro Carvalho Chehab successful, unless the whole device doesn't exist. The drive will take 6578ea61889SMauro Carvalho Chehab no actions whatsoever. 6588ea61889SMauro Carvalho Chehab 6598ea61889SMauro Carvalho ChehabAnd what about standards? 6608ea61889SMauro Carvalho Chehab------------------------- 6618ea61889SMauro Carvalho Chehab 6628ea61889SMauro Carvalho ChehabYou might hesitate to accept this proposal as it comes from the 6638ea61889SMauro Carvalho ChehabLinux community, and not from some standardizing institute. What 6648ea61889SMauro Carvalho Chehababout SUN, SGI, HP and all those other Unix and hardware vendors? 6658ea61889SMauro Carvalho ChehabWell, these companies are in the lucky position that they generally 6668ea61889SMauro Carvalho Chehabcontrol both the hardware and software of their supported products, 6678ea61889SMauro Carvalho Chehaband are large enough to set their own standard. They do not have to 6688ea61889SMauro Carvalho Chehabdeal with a dozen or more different, competing hardware 6698ea61889SMauro Carvalho Chehabconfigurations\ [#f3]_. 6708ea61889SMauro Carvalho Chehab 6718ea61889SMauro Carvalho Chehab.. [#f3] 6728ea61889SMauro Carvalho Chehab 6738ea61889SMauro Carvalho Chehab Incidentally, I think that SUN's approach to mounting CD-ROM s is very 6748ea61889SMauro Carvalho Chehab good in origin: under Solaris a volume-daemon automatically mounts a 6758ea61889SMauro Carvalho Chehab newly inserted CD-ROM under `/cdrom/*<volume-name>*`. 6768ea61889SMauro Carvalho Chehab 6778ea61889SMauro Carvalho Chehab In my opinion they should have pushed this 6788ea61889SMauro Carvalho Chehab further and have **every** CD-ROM on the local area network be 6798ea61889SMauro Carvalho Chehab mounted at the similar location, i. e., no matter in which particular 6808ea61889SMauro Carvalho Chehab machine you insert a CD-ROM, it will always appear at the same 6818ea61889SMauro Carvalho Chehab position in the directory tree, on every system. When I wanted to 6828ea61889SMauro Carvalho Chehab implement such a user-program for Linux, I came across the 6838ea61889SMauro Carvalho Chehab differences in behavior of the various drivers, and the need for an 6848ea61889SMauro Carvalho Chehab *ioctl* informing about media changes. 6858ea61889SMauro Carvalho Chehab 6868ea61889SMauro Carvalho ChehabWe believe that using *O_NONBLOCK* to indicate that a device is being opened 6878ea61889SMauro Carvalho Chehabfor *ioctl* commands only can be easily introduced in the Linux 6888ea61889SMauro Carvalho Chehabcommunity. All the CD-player authors will have to be informed, we can 6898ea61889SMauro Carvalho Chehabeven send in our own patches to the programs. The use of *O_NONBLOCK* 6908ea61889SMauro Carvalho Chehabhas most likely no influence on the behavior of the CD-players on 6918ea61889SMauro Carvalho Chehabother operating systems than Linux. Finally, a user can always revert 6928ea61889SMauro Carvalho Chehabto old behavior by a call to 6938ea61889SMauro Carvalho Chehab*ioctl(file_descriptor, CDROM_CLEAR_OPTIONS, CDO_USE_FFLAGS)*. 6948ea61889SMauro Carvalho Chehab 6958ea61889SMauro Carvalho ChehabThe preferred strategy of *open()* 6968ea61889SMauro Carvalho Chehab---------------------------------- 6978ea61889SMauro Carvalho Chehab 6988ea61889SMauro Carvalho ChehabThe routines in `cdrom.c` are designed in such a way that run-time 6998ea61889SMauro Carvalho Chehabconfiguration of the behavior of CD-ROM devices (of **any** type) 7008ea61889SMauro Carvalho Chehabcan be carried out, by the *CDROM_SET/CLEAR_OPTIONS* *ioctls*. Thus, various 7018ea61889SMauro Carvalho Chehabmodes of operation can be set: 7028ea61889SMauro Carvalho Chehab 7038ea61889SMauro Carvalho Chehab`CDO_AUTO_CLOSE | CDO_USE_FFLAGS | CDO_LOCK` 7048ea61889SMauro Carvalho Chehab This is the default setting. (With *CDO_CHECK_TYPE* it will be better, in 7058ea61889SMauro Carvalho Chehab the future.) If the device is not yet opened by any other process, and if 7068ea61889SMauro Carvalho Chehab the device is being opened for data (*O_NONBLOCK* is not set) and the 7078ea61889SMauro Carvalho Chehab tray is found to be open, an attempt to close the tray is made. Then, 7088ea61889SMauro Carvalho Chehab it is verified that a disc is in the drive and, if *CDO_CHECK_TYPE* is 7098ea61889SMauro Carvalho Chehab set, that it contains tracks of type `data mode 1`. Only if all tests 7108ea61889SMauro Carvalho Chehab are passed is the return value zero. The door is locked to prevent file 7118ea61889SMauro Carvalho Chehab system corruption. If the drive is opened for audio (*O_NONBLOCK* is 7128ea61889SMauro Carvalho Chehab set), no actions are taken and a value of 0 will be returned. 7138ea61889SMauro Carvalho Chehab 7148ea61889SMauro Carvalho Chehab`CDO_AUTO_CLOSE | CDO_AUTO_EJECT | CDO_LOCK` 7158ea61889SMauro Carvalho Chehab This mimics the behavior of the current sbpcd-driver. The option flags are 7168ea61889SMauro Carvalho Chehab ignored, the tray is closed on the first open, if necessary. Similarly, 7178ea61889SMauro Carvalho Chehab the tray is opened on the last release, i. e., if a CD-ROM is unmounted, 7188ea61889SMauro Carvalho Chehab it is automatically ejected, such that the user can replace it. 7198ea61889SMauro Carvalho Chehab 7208ea61889SMauro Carvalho ChehabWe hope that these option can convince everybody (both driver 7218ea61889SMauro Carvalho Chehabmaintainers and user program developers) to adopt the new CD-ROM 7228ea61889SMauro Carvalho Chehabdriver scheme and option flag interpretation. 7238ea61889SMauro Carvalho Chehab 7248ea61889SMauro Carvalho ChehabDescription of routines in `cdrom.c` 7258ea61889SMauro Carvalho Chehab==================================== 7268ea61889SMauro Carvalho Chehab 7278ea61889SMauro Carvalho ChehabOnly a few routines in `cdrom.c` are exported to the drivers. In this 7288ea61889SMauro Carvalho Chehabnew section we will discuss these, as well as the functions that `take 729502b6750SRemi Andruccioliover` the CD-ROM interface to the kernel. The header file belonging 7308ea61889SMauro Carvalho Chehabto `cdrom.c` is called `cdrom.h`. Formerly, some of the contents of this 7318ea61889SMauro Carvalho Chehabfile were placed in the file `ucdrom.h`, but this file has now been 7328ea61889SMauro Carvalho Chehabmerged back into `cdrom.h`. 7338ea61889SMauro Carvalho Chehab 7348ea61889SMauro Carvalho Chehab:: 7358ea61889SMauro Carvalho Chehab 7368ea61889SMauro Carvalho Chehab struct file_operations cdrom_fops 7378ea61889SMauro Carvalho Chehab 7388ea61889SMauro Carvalho ChehabThe contents of this structure were described in cdrom_api_. 7398ea61889SMauro Carvalho ChehabA pointer to this structure is assigned to the *fops* field 7408ea61889SMauro Carvalho Chehabof the *struct gendisk*. 7418ea61889SMauro Carvalho Chehab 7428ea61889SMauro Carvalho Chehab:: 7438ea61889SMauro Carvalho Chehab 7448ea61889SMauro Carvalho Chehab int register_cdrom(struct cdrom_device_info *cdi) 7458ea61889SMauro Carvalho Chehab 7468ea61889SMauro Carvalho ChehabThis function is used in about the same way one registers *cdrom_fops* 7478ea61889SMauro Carvalho Chehabwith the kernel, the device operations and information structures, 7488ea61889SMauro Carvalho Chehabas described in cdrom_api_, should be registered with the 7498ea61889SMauro Carvalho ChehabUniform CD-ROM Driver:: 7508ea61889SMauro Carvalho Chehab 7518ea61889SMauro Carvalho Chehab register_cdrom(&<device>_info); 7528ea61889SMauro Carvalho Chehab 7538ea61889SMauro Carvalho Chehab 7548ea61889SMauro Carvalho ChehabThis function returns zero upon success, and non-zero upon 7558ea61889SMauro Carvalho Chehabfailure. The structure *<device>_info* should have a pointer to the 7568ea61889SMauro Carvalho Chehabdriver's *<device>_dops*, as in:: 7578ea61889SMauro Carvalho Chehab 7588ea61889SMauro Carvalho Chehab struct cdrom_device_info <device>_info = { 7598ea61889SMauro Carvalho Chehab <device>_dops; 7608ea61889SMauro Carvalho Chehab ... 7618ea61889SMauro Carvalho Chehab } 7628ea61889SMauro Carvalho Chehab 7638ea61889SMauro Carvalho ChehabNote that a driver must have one static structure, *<device>_dops*, while 7648ea61889SMauro Carvalho Chehabit may have as many structures *<device>_info* as there are minor devices 7658ea61889SMauro Carvalho Chehabactive. *Register_cdrom()* builds a linked list from these. 7668ea61889SMauro Carvalho Chehab 7678ea61889SMauro Carvalho Chehab 7688ea61889SMauro Carvalho Chehab:: 7698ea61889SMauro Carvalho Chehab 7708ea61889SMauro Carvalho Chehab void unregister_cdrom(struct cdrom_device_info *cdi) 7718ea61889SMauro Carvalho Chehab 7728ea61889SMauro Carvalho ChehabUnregistering device *cdi* with minor number *MINOR(cdi->dev)* removes 7738ea61889SMauro Carvalho Chehabthe minor device from the list. If it was the last registered minor for 7748ea61889SMauro Carvalho Chehabthe low-level driver, this disconnects the registered device-operation 7758ea61889SMauro Carvalho Chehabroutines from the CD-ROM interface. This function returns zero upon 7768ea61889SMauro Carvalho Chehabsuccess, and non-zero upon failure. 7778ea61889SMauro Carvalho Chehab 7788ea61889SMauro Carvalho Chehab:: 7798ea61889SMauro Carvalho Chehab 7808ea61889SMauro Carvalho Chehab int cdrom_open(struct inode * ip, struct file * fp) 7818ea61889SMauro Carvalho Chehab 7828ea61889SMauro Carvalho ChehabThis function is not called directly by the low-level drivers, it is 7838ea61889SMauro Carvalho Chehablisted in the standard *cdrom_fops*. If the VFS opens a file, this 7848ea61889SMauro Carvalho Chehabfunction becomes active. A strategy is implemented in this routine, 7858ea61889SMauro Carvalho Chehabtaking care of all capabilities and options that are set in the 7868ea61889SMauro Carvalho Chehab*cdrom_device_ops* connected to the device. Then, the program flow is 7878ea61889SMauro Carvalho Chehabtransferred to the device_dependent *open()* call. 7888ea61889SMauro Carvalho Chehab 7898ea61889SMauro Carvalho Chehab:: 7908ea61889SMauro Carvalho Chehab 7918ea61889SMauro Carvalho Chehab void cdrom_release(struct inode *ip, struct file *fp) 7928ea61889SMauro Carvalho Chehab 7938ea61889SMauro Carvalho ChehabThis function implements the reverse-logic of *cdrom_open()*, and then 7948ea61889SMauro Carvalho Chehabcalls the device-dependent *release()* routine. When the use-count has 7958ea61889SMauro Carvalho Chehabreached 0, the allocated buffers are flushed by calls to *sync_dev(dev)* 7968ea61889SMauro Carvalho Chehaband *invalidate_buffers(dev)*. 7978ea61889SMauro Carvalho Chehab 7988ea61889SMauro Carvalho Chehab 7998ea61889SMauro Carvalho Chehab.. _cdrom_ioctl: 8008ea61889SMauro Carvalho Chehab 8018ea61889SMauro Carvalho Chehab:: 8028ea61889SMauro Carvalho Chehab 8038ea61889SMauro Carvalho Chehab int cdrom_ioctl(struct inode *ip, struct file *fp, 8048ea61889SMauro Carvalho Chehab unsigned int cmd, unsigned long arg) 8058ea61889SMauro Carvalho Chehab 8068ea61889SMauro Carvalho ChehabThis function handles all the standard *ioctl* requests for CD-ROM 8078ea61889SMauro Carvalho Chehabdevices in a uniform way. The different calls fall into three 8088ea61889SMauro Carvalho Chehabcategories: *ioctl()'s* that can be directly implemented by device 8098ea61889SMauro Carvalho Chehaboperations, ones that are routed through the call *audio_ioctl()*, and 8108ea61889SMauro Carvalho Chehabthe remaining ones, that are presumable device-dependent. Generally, a 8118ea61889SMauro Carvalho Chehabnegative return value indicates an error. 8128ea61889SMauro Carvalho Chehab 8138ea61889SMauro Carvalho ChehabDirectly implemented *ioctl()'s* 8148ea61889SMauro Carvalho Chehab-------------------------------- 8158ea61889SMauro Carvalho Chehab 8168ea61889SMauro Carvalho ChehabThe following `old` CD-ROM *ioctl()*\ 's are implemented by directly 8178ea61889SMauro Carvalho Chehabcalling device-operations in *cdrom_device_ops*, if implemented and 8188ea61889SMauro Carvalho Chehabnot masked: 8198ea61889SMauro Carvalho Chehab 8208ea61889SMauro Carvalho Chehab`CDROMMULTISESSION` 8218ea61889SMauro Carvalho Chehab Requests the last session on a CD-ROM. 8228ea61889SMauro Carvalho Chehab`CDROMEJECT` 8238ea61889SMauro Carvalho Chehab Open tray. 8248ea61889SMauro Carvalho Chehab`CDROMCLOSETRAY` 8258ea61889SMauro Carvalho Chehab Close tray. 8268ea61889SMauro Carvalho Chehab`CDROMEJECT_SW` 8278ea61889SMauro Carvalho Chehab If *arg\not=0*, set behavior to auto-close (close 8288ea61889SMauro Carvalho Chehab tray on first open) and auto-eject (eject on last release), otherwise 8298ea61889SMauro Carvalho Chehab set behavior to non-moving on *open()* and *release()* calls. 8308ea61889SMauro Carvalho Chehab`CDROM_GET_MCN` 8318ea61889SMauro Carvalho Chehab Get the Media Catalog Number from a CD. 8328ea61889SMauro Carvalho Chehab 8338ea61889SMauro Carvalho Chehab*Ioctl*s routed through *audio_ioctl()* 8348ea61889SMauro Carvalho Chehab--------------------------------------- 8358ea61889SMauro Carvalho Chehab 8368ea61889SMauro Carvalho ChehabThe following set of *ioctl()'s* are all implemented through a call to 8378ea61889SMauro Carvalho Chehabthe *cdrom_fops* function *audio_ioctl()*. Memory checks and 8388ea61889SMauro Carvalho Chehaballocation are performed in *cdrom_ioctl()*, and also sanitization of 8398ea61889SMauro Carvalho Chehabaddress format (*CDROM_LBA*/*CDROM_MSF*) is done. 8408ea61889SMauro Carvalho Chehab 8418ea61889SMauro Carvalho Chehab`CDROMSUBCHNL` 8428ea61889SMauro Carvalho Chehab Get sub-channel data in argument *arg* of type 8438ea61889SMauro Carvalho Chehab `struct cdrom_subchnl *`. 8448ea61889SMauro Carvalho Chehab`CDROMREADTOCHDR` 8458ea61889SMauro Carvalho Chehab Read Table of Contents header, in *arg* of type 8468ea61889SMauro Carvalho Chehab `struct cdrom_tochdr *`. 8478ea61889SMauro Carvalho Chehab`CDROMREADTOCENTRY` 8488ea61889SMauro Carvalho Chehab Read a Table of Contents entry in *arg* and specified by *arg* 8498ea61889SMauro Carvalho Chehab of type `struct cdrom_tocentry *`. 8508ea61889SMauro Carvalho Chehab`CDROMPLAYMSF` 8518ea61889SMauro Carvalho Chehab Play audio fragment specified in Minute, Second, Frame format, 8528ea61889SMauro Carvalho Chehab delimited by *arg* of type `struct cdrom_msf *`. 8538ea61889SMauro Carvalho Chehab`CDROMPLAYTRKIND` 8548ea61889SMauro Carvalho Chehab Play audio fragment in track-index format delimited by *arg* 8558ea61889SMauro Carvalho Chehab of type `struct cdrom_ti *`. 8568ea61889SMauro Carvalho Chehab`CDROMVOLCTRL` 8578ea61889SMauro Carvalho Chehab Set volume specified by *arg* of type `struct cdrom_volctrl *`. 8588ea61889SMauro Carvalho Chehab`CDROMVOLREAD` 8598ea61889SMauro Carvalho Chehab Read volume into by *arg* of type `struct cdrom_volctrl *`. 8608ea61889SMauro Carvalho Chehab`CDROMSTART` 8618ea61889SMauro Carvalho Chehab Spin up disc. 8628ea61889SMauro Carvalho Chehab`CDROMSTOP` 8638ea61889SMauro Carvalho Chehab Stop playback of audio fragment. 8648ea61889SMauro Carvalho Chehab`CDROMPAUSE` 8658ea61889SMauro Carvalho Chehab Pause playback of audio fragment. 8668ea61889SMauro Carvalho Chehab`CDROMRESUME` 8678ea61889SMauro Carvalho Chehab Resume playing. 8688ea61889SMauro Carvalho Chehab 8698ea61889SMauro Carvalho ChehabNew *ioctl()'s* in `cdrom.c` 8708ea61889SMauro Carvalho Chehab---------------------------- 8718ea61889SMauro Carvalho Chehab 8728ea61889SMauro Carvalho ChehabThe following *ioctl()'s* have been introduced to allow user programs to 8738ea61889SMauro Carvalho Chehabcontrol the behavior of individual CD-ROM devices. New *ioctl* 8748ea61889SMauro Carvalho Chehabcommands can be identified by the underscores in their names. 8758ea61889SMauro Carvalho Chehab 8768ea61889SMauro Carvalho Chehab`CDROM_SET_OPTIONS` 8778ea61889SMauro Carvalho Chehab Set options specified by *arg*. Returns the option flag register 8788ea61889SMauro Carvalho Chehab after modification. Use *arg = \rm0* for reading the current flags. 8798ea61889SMauro Carvalho Chehab`CDROM_CLEAR_OPTIONS` 8808ea61889SMauro Carvalho Chehab Clear options specified by *arg*. Returns the option flag register 8818ea61889SMauro Carvalho Chehab after modification. 8828ea61889SMauro Carvalho Chehab`CDROM_SELECT_SPEED` 8838ea61889SMauro Carvalho Chehab Select head-rate speed of disc specified as by *arg* in units 8848ea61889SMauro Carvalho Chehab of standard cdrom speed (176\,kB/sec raw data or 8858ea61889SMauro Carvalho Chehab 150kB/sec file system data). The value 0 means `auto-select`, 8868ea61889SMauro Carvalho Chehab i. e., play audio discs at real time and data discs at maximum speed. 8878ea61889SMauro Carvalho Chehab The value *arg* is checked against the maximum head rate of the 8888ea61889SMauro Carvalho Chehab drive found in the *cdrom_dops*. 8898ea61889SMauro Carvalho Chehab`CDROM_SELECT_DISC` 8908ea61889SMauro Carvalho Chehab Select disc numbered *arg* from a juke-box. 8918ea61889SMauro Carvalho Chehab 8928ea61889SMauro Carvalho Chehab First disc is numbered 0. The number *arg* is checked against the 8938ea61889SMauro Carvalho Chehab maximum number of discs in the juke-box found in the *cdrom_dops*. 8948ea61889SMauro Carvalho Chehab`CDROM_MEDIA_CHANGED` 8958ea61889SMauro Carvalho Chehab Returns 1 if a disc has been changed since the last call. 8968c22eb3aSChristoph Hellwig For juke-boxes, an extra argument *arg* 8978ea61889SMauro Carvalho Chehab specifies the slot for which the information is given. The special 8988ea61889SMauro Carvalho Chehab value *CDSL_CURRENT* requests that information about the currently 8998ea61889SMauro Carvalho Chehab selected slot be returned. 90067f1e027SLukas Prediger`CDROM_TIMED_MEDIA_CHANGE` 90167f1e027SLukas Prediger Checks whether the disc has been changed since a user supplied time 90267f1e027SLukas Prediger and returns the time of the last disc change. 90367f1e027SLukas Prediger 90467f1e027SLukas Prediger *arg* is a pointer to a *cdrom_timed_media_change_info* struct. 90567f1e027SLukas Prediger *arg->last_media_change* may be set by calling code to signal 90667f1e027SLukas Prediger the timestamp of the last known media change (by the caller). 90767f1e027SLukas Prediger Upon successful return, this ioctl call will set 90867f1e027SLukas Prediger *arg->last_media_change* to the latest media change timestamp (in ms) 90967f1e027SLukas Prediger known by the kernel/driver and set *arg->has_changed* to 1 if 91067f1e027SLukas Prediger that timestamp is more recent than the timestamp set by the caller. 9118ea61889SMauro Carvalho Chehab`CDROM_DRIVE_STATUS` 9128ea61889SMauro Carvalho Chehab Returns the status of the drive by a call to 9138ea61889SMauro Carvalho Chehab *drive_status()*. Return values are defined in cdrom_drive_status_. 9148ea61889SMauro Carvalho Chehab Note that this call doesn't return information on the 9158ea61889SMauro Carvalho Chehab current playing activity of the drive; this can be polled through 9168ea61889SMauro Carvalho Chehab an *ioctl* call to *CDROMSUBCHNL*. For juke-boxes, an extra argument 9178ea61889SMauro Carvalho Chehab *arg* specifies the slot for which (possibly limited) information is 9188ea61889SMauro Carvalho Chehab given. The special value *CDSL_CURRENT* requests that information 9198ea61889SMauro Carvalho Chehab about the currently selected slot be returned. 9208ea61889SMauro Carvalho Chehab`CDROM_DISC_STATUS` 9218ea61889SMauro Carvalho Chehab Returns the type of the disc currently in the drive. 9228ea61889SMauro Carvalho Chehab It should be viewed as a complement to *CDROM_DRIVE_STATUS*. 9238ea61889SMauro Carvalho Chehab This *ioctl* can provide *some* information about the current 9248ea61889SMauro Carvalho Chehab disc that is inserted in the drive. This functionality used to be 9258ea61889SMauro Carvalho Chehab implemented in the low level drivers, but is now carried out 9268ea61889SMauro Carvalho Chehab entirely in Uniform CD-ROM Driver. 9278ea61889SMauro Carvalho Chehab 9288ea61889SMauro Carvalho Chehab The history of development of the CD's use as a carrier medium for 9298ea61889SMauro Carvalho Chehab various digital information has lead to many different disc types. 9308ea61889SMauro Carvalho Chehab This *ioctl* is useful only in the case that CDs have \emph {only 9318ea61889SMauro Carvalho Chehab one} type of data on them. While this is often the case, it is 9328ea61889SMauro Carvalho Chehab also very common for CDs to have some tracks with data, and some 9338ea61889SMauro Carvalho Chehab tracks with audio. Because this is an existing interface, rather 9348ea61889SMauro Carvalho Chehab than fixing this interface by changing the assumptions it was made 9358ea61889SMauro Carvalho Chehab under, thereby breaking all user applications that use this 9368ea61889SMauro Carvalho Chehab function, the Uniform CD-ROM Driver implements this *ioctl* as 9378ea61889SMauro Carvalho Chehab follows: If the CD in question has audio tracks on it, and it has 9388ea61889SMauro Carvalho Chehab absolutely no CD-I, XA, or data tracks on it, it will be reported 9398ea61889SMauro Carvalho Chehab as *CDS_AUDIO*. If it has both audio and data tracks, it will 9408ea61889SMauro Carvalho Chehab return *CDS_MIXED*. If there are no audio tracks on the disc, and 9418ea61889SMauro Carvalho Chehab if the CD in question has any CD-I tracks on it, it will be 9428ea61889SMauro Carvalho Chehab reported as *CDS_XA_2_2*. Failing that, if the CD in question 9438ea61889SMauro Carvalho Chehab has any XA tracks on it, it will be reported as *CDS_XA_2_1*. 9448ea61889SMauro Carvalho Chehab Finally, if the CD in question has any data tracks on it, 9458ea61889SMauro Carvalho Chehab it will be reported as a data CD (*CDS_DATA_1*). 9468ea61889SMauro Carvalho Chehab 9478ea61889SMauro Carvalho Chehab This *ioctl* can return:: 9488ea61889SMauro Carvalho Chehab 9498ea61889SMauro Carvalho Chehab CDS_NO_INFO /* no information available */ 9508ea61889SMauro Carvalho Chehab CDS_NO_DISC /* no disc is inserted, or tray is opened */ 9518ea61889SMauro Carvalho Chehab CDS_AUDIO /* Audio disc (2352 audio bytes/frame) */ 9528ea61889SMauro Carvalho Chehab CDS_DATA_1 /* data disc, mode 1 (2048 user bytes/frame) */ 9538ea61889SMauro Carvalho Chehab CDS_XA_2_1 /* mixed data (XA), mode 2, form 1 (2048 user bytes) */ 9548ea61889SMauro Carvalho Chehab CDS_XA_2_2 /* mixed data (XA), mode 2, form 1 (2324 user bytes) */ 9558ea61889SMauro Carvalho Chehab CDS_MIXED /* mixed audio/data disc */ 9568ea61889SMauro Carvalho Chehab 9578ea61889SMauro Carvalho Chehab For some information concerning frame layout of the various disc 9588ea61889SMauro Carvalho Chehab types, see a recent version of `cdrom.h`. 9598ea61889SMauro Carvalho Chehab 9608ea61889SMauro Carvalho Chehab`CDROM_CHANGER_NSLOTS` 9618ea61889SMauro Carvalho Chehab Returns the number of slots in a juke-box. 9628ea61889SMauro Carvalho Chehab`CDROMRESET` 9638ea61889SMauro Carvalho Chehab Reset the drive. 9648ea61889SMauro Carvalho Chehab`CDROM_GET_CAPABILITY` 9658ea61889SMauro Carvalho Chehab Returns the *capability* flags for the drive. Refer to section 9668ea61889SMauro Carvalho Chehab cdrom_capabilities_ for more information on these flags. 9678ea61889SMauro Carvalho Chehab`CDROM_LOCKDOOR` 9688ea61889SMauro Carvalho Chehab Locks the door of the drive. `arg == 0` unlocks the door, 9698ea61889SMauro Carvalho Chehab any other value locks it. 9708ea61889SMauro Carvalho Chehab`CDROM_DEBUG` 9718ea61889SMauro Carvalho Chehab Turns on debugging info. Only root is allowed to do this. 9728ea61889SMauro Carvalho Chehab Same semantics as CDROM_LOCKDOOR. 9738ea61889SMauro Carvalho Chehab 9748ea61889SMauro Carvalho Chehab 9758ea61889SMauro Carvalho ChehabDevice dependent *ioctl()'s* 9768ea61889SMauro Carvalho Chehab---------------------------- 9778ea61889SMauro Carvalho Chehab 9788ea61889SMauro Carvalho ChehabFinally, all other *ioctl()'s* are passed to the function *dev_ioctl()*, 9798ea61889SMauro Carvalho Chehabif implemented. No memory allocation or verification is carried out. 9808ea61889SMauro Carvalho Chehab 9818ea61889SMauro Carvalho ChehabHow to update your driver 9828ea61889SMauro Carvalho Chehab========================= 9838ea61889SMauro Carvalho Chehab 9848ea61889SMauro Carvalho Chehab- Make a backup of your current driver. 9858ea61889SMauro Carvalho Chehab- Get hold of the files `cdrom.c` and `cdrom.h`, they should be in 9868ea61889SMauro Carvalho Chehab the directory tree that came with this documentation. 9878ea61889SMauro Carvalho Chehab- Make sure you include `cdrom.h`. 9888ea61889SMauro Carvalho Chehab- Change the 3rd argument of *register_blkdev* from `&<your-drive>_fops` 9898ea61889SMauro Carvalho Chehab to `&cdrom_fops`. 9908ea61889SMauro Carvalho Chehab- Just after that line, add the following to register with the Uniform 9918ea61889SMauro Carvalho Chehab CD-ROM Driver:: 9928ea61889SMauro Carvalho Chehab 9938ea61889SMauro Carvalho Chehab register_cdrom(&<your-drive>_info);* 9948ea61889SMauro Carvalho Chehab 9958ea61889SMauro Carvalho Chehab Similarly, add a call to *unregister_cdrom()* at the appropriate place. 9968ea61889SMauro Carvalho Chehab- Copy an example of the device-operations *struct* to your 9978ea61889SMauro Carvalho Chehab source, e. g., from `cm206.c` *cm206_dops*, and change all 9988ea61889SMauro Carvalho Chehab entries to names corresponding to your driver, or names you just 9998ea61889SMauro Carvalho Chehab happen to like. If your driver doesn't support a certain function, 10008ea61889SMauro Carvalho Chehab make the entry *NULL*. At the entry *capability* you should list all 10018ea61889SMauro Carvalho Chehab capabilities your driver currently supports. If your driver 10028ea61889SMauro Carvalho Chehab has a capability that is not listed, please send me a message. 10038ea61889SMauro Carvalho Chehab- Copy the *cdrom_device_info* declaration from the same example 10048ea61889SMauro Carvalho Chehab driver, and modify the entries according to your needs. If your 10058ea61889SMauro Carvalho Chehab driver dynamically determines the capabilities of the hardware, this 10068ea61889SMauro Carvalho Chehab structure should also be declared dynamically. 10078ea61889SMauro Carvalho Chehab- Implement all functions in your `<device>_dops` structure, 10088ea61889SMauro Carvalho Chehab according to prototypes listed in `cdrom.h`, and specifications given 10098ea61889SMauro Carvalho Chehab in cdrom_api_. Most likely you have already implemented 10108ea61889SMauro Carvalho Chehab the code in a large part, and you will almost certainly need to adapt the 10118ea61889SMauro Carvalho Chehab prototype and return values. 10128ea61889SMauro Carvalho Chehab- Rename your `<device>_ioctl()` function to *audio_ioctl* and 10138ea61889SMauro Carvalho Chehab change the prototype a little. Remove entries listed in the first 10148ea61889SMauro Carvalho Chehab part in cdrom_ioctl_, if your code was OK, these are 10158ea61889SMauro Carvalho Chehab just calls to the routines you adapted in the previous step. 10168ea61889SMauro Carvalho Chehab- You may remove all remaining memory checking code in the 10178ea61889SMauro Carvalho Chehab *audio_ioctl()* function that deals with audio commands (these are 10188ea61889SMauro Carvalho Chehab listed in the second part of cdrom_ioctl_. There is no 10198ea61889SMauro Carvalho Chehab need for memory allocation either, so most *case*s in the *switch* 10208ea61889SMauro Carvalho Chehab statement look similar to:: 10218ea61889SMauro Carvalho Chehab 10228ea61889SMauro Carvalho Chehab case CDROMREADTOCENTRY: 10238ea61889SMauro Carvalho Chehab get_toc_entry\bigl((struct cdrom_tocentry *) arg); 10248ea61889SMauro Carvalho Chehab 10258ea61889SMauro Carvalho Chehab- All remaining *ioctl* cases must be moved to a separate 10268ea61889SMauro Carvalho Chehab function, *<device>_ioctl*, the device-dependent *ioctl()'s*. Note that 10278ea61889SMauro Carvalho Chehab memory checking and allocation must be kept in this code! 10288ea61889SMauro Carvalho Chehab- Change the prototypes of *<device>_open()* and 10298ea61889SMauro Carvalho Chehab *<device>_release()*, and remove any strategic code (i. e., tray 10308ea61889SMauro Carvalho Chehab movement, door locking, etc.). 10318ea61889SMauro Carvalho Chehab- Try to recompile the drivers. We advise you to use modules, both 10328ea61889SMauro Carvalho Chehab for `cdrom.o` and your driver, as debugging is much easier this 10338ea61889SMauro Carvalho Chehab way. 10348ea61889SMauro Carvalho Chehab 10358ea61889SMauro Carvalho ChehabThanks 10368ea61889SMauro Carvalho Chehab====== 10378ea61889SMauro Carvalho Chehab 10388ea61889SMauro Carvalho ChehabThanks to all the people involved. First, Erik Andersen, who has 10398ea61889SMauro Carvalho Chehabtaken over the torch in maintaining `cdrom.c` and integrating much 10408ea61889SMauro Carvalho ChehabCD-ROM-related code in the 2.1-kernel. Thanks to Scott Snyder and 10418ea61889SMauro Carvalho ChehabGerd Knorr, who were the first to implement this interface for SCSI 10428ea61889SMauro Carvalho Chehaband IDE-CD drivers and added many ideas for extension of the data 10438ea61889SMauro Carvalho Chehabstructures relative to kernel~2.0. Further thanks to Heiko Eißfeldt, 10448ea61889SMauro Carvalho ChehabThomas Quinot, Jon Tombs, Ken Pizzini, Eberhard Mönkeberg and Andrew Kroll, 10458ea61889SMauro Carvalho Chehabthe Linux CD-ROM device driver developers who were kind 10468ea61889SMauro Carvalho Chehabenough to give suggestions and criticisms during the writing. Finally 10478ea61889SMauro Carvalho Chehabof course, I want to thank Linus Torvalds for making this possible in 10488ea61889SMauro Carvalho Chehabthe first place. 1049