2 * cdrom_id - determines the capabilities of cdrom drives
4 * Copyright (C) 2005 Greg Kroah-Hartman <gregkh@suse.de>
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation version 2 of the License.
22 #include <sys/ioctl.h>
23 #include <sys/types.h>
25 #include <linux/types.h>
27 #include "../../logging.h"
28 #include "../../udev_utils.h"
31 * Taken from the cdrom.h kernel include file.
32 * Included here as some distros don't have an updated version
33 * with all of the DVD flags. So we just include our own, aren't
36 #define CDROM_GET_CAPABILITY 0x5331 /* get capabilities */
38 /* capability flags used with the uniform CD-ROM driver */
39 #define CDC_CLOSE_TRAY 0x1 /* caddy systems _can't_ close */
40 #define CDC_OPEN_TRAY 0x2 /* but _can_ eject. */
41 #define CDC_LOCK 0x4 /* disable manual eject */
42 #define CDC_SELECT_SPEED 0x8 /* programmable speed */
43 #define CDC_SELECT_DISC 0x10 /* select disc from juke-box */
44 #define CDC_MULTI_SESSION 0x20 /* read sessions>1 */
45 #define CDC_MCN 0x40 /* Medium Catalog Number */
46 #define CDC_MEDIA_CHANGED 0x80 /* media changed */
47 #define CDC_PLAY_AUDIO 0x100 /* audio functions */
48 #define CDC_RESET 0x200 /* hard reset device */
49 #define CDC_IOCTLS 0x400 /* driver has non-standard ioctls */
50 #define CDC_DRIVE_STATUS 0x800 /* driver implements drive status */
51 #define CDC_GENERIC_PACKET 0x1000 /* driver implements generic packets */
52 #define CDC_CD_R 0x2000 /* drive is a CD-R */
53 #define CDC_CD_RW 0x4000 /* drive is a CD-RW */
54 #define CDC_DVD 0x8000 /* drive is a DVD */
55 #define CDC_DVD_R 0x10000 /* drive can write DVD-R */
56 #define CDC_DVD_RAM 0x20000 /* drive can write DVD-RAM */
57 #define CDC_MO_DRIVE 0x40000 /* drive is an MO device */
58 #define CDC_MRW 0x80000 /* drive can read MRW */
59 #define CDC_MRW_W 0x100000 /* drive can write MRW */
60 #define CDC_RAM 0x200000 /* ok to open for WRITE */
63 void log_message(int priority, const char *format, ...)
66 static int udev_log = -1;
71 value = getenv("UDEV_LOG");
73 udev_log = log_priority(value);
78 if (priority > udev_log)
81 va_start(args, format);
82 vsyslog(priority, format, args);
87 int main(int argc, char *argv[])
89 const char *node = NULL;
96 logging_init("cdrom_id");
98 for (i = 1 ; i < argc; i++) {
101 if (strcmp(arg, "--export") == 0) {
107 info("no node specified");
112 fd = open(node, O_RDONLY|O_NONBLOCK);
114 info("unable to open '%s'", node);
119 result = ioctl(fd, CDROM_GET_CAPABILITY, NULL);
121 info("CDROM_GET_CAPABILITY failed for '%s'", node);
126 printf("ID_CDROM=1\n");
128 if (result & CDC_CD_R)
129 printf("ID_CDROM_CD_R=1\n");
130 if (result & CDC_CD_RW)
131 printf("ID_CDROM_CD_RW=1\n");
133 if (result & CDC_DVD)
134 printf("ID_CDROM_DVD=1\n");
135 if (result & CDC_DVD_R)
136 printf("ID_CDROM_DVD_R=1\n");
137 if (result & CDC_DVD_RAM)
138 printf("ID_CDROM_DVD_RAM=1\n");
140 if (result & CDC_MRW)
141 printf("ID_CDROM_MRW=1\n");
142 if (result & CDC_MRW_W)
143 printf("ID_CDROM_MRW_W=1\n");
145 if (result & CDC_RAM)
146 printf("ID_CDROM_RAM=1\n");