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.
10 * Framework based on ata_id which is:
11 * Copyright (C) 2005 Kay Sievers <kay.sievers@vrfy.org>
25 #include <sys/ioctl.h>
26 #include <sys/types.h>
28 #include <linux/types.h>
30 #include "../../logging.h"
31 #include "../../udev_utils.h"
34 * Taken from the cdrom.h kernel include file.
35 * Included here as some distros don't have an updated version
36 * with all of the DVD flags. So we just include our own, aren't
39 #define CDROM_GET_CAPABILITY 0x5331 /* get capabilities */
41 /* capability flags used with the uniform CD-ROM driver */
42 #define CDC_CLOSE_TRAY 0x1 /* caddy systems _can't_ close */
43 #define CDC_OPEN_TRAY 0x2 /* but _can_ eject. */
44 #define CDC_LOCK 0x4 /* disable manual eject */
45 #define CDC_SELECT_SPEED 0x8 /* programmable speed */
46 #define CDC_SELECT_DISC 0x10 /* select disc from juke-box */
47 #define CDC_MULTI_SESSION 0x20 /* read sessions>1 */
48 #define CDC_MCN 0x40 /* Medium Catalog Number */
49 #define CDC_MEDIA_CHANGED 0x80 /* media changed */
50 #define CDC_PLAY_AUDIO 0x100 /* audio functions */
51 #define CDC_RESET 0x200 /* hard reset device */
52 #define CDC_IOCTLS 0x400 /* driver has non-standard ioctls */
53 #define CDC_DRIVE_STATUS 0x800 /* driver implements drive status */
54 #define CDC_GENERIC_PACKET 0x1000 /* driver implements generic packets */
55 #define CDC_CD_R 0x2000 /* drive is a CD-R */
56 #define CDC_CD_RW 0x4000 /* drive is a CD-RW */
57 #define CDC_DVD 0x8000 /* drive is a DVD */
58 #define CDC_DVD_R 0x10000 /* drive can write DVD-R */
59 #define CDC_DVD_RAM 0x20000 /* drive can write DVD-RAM */
60 #define CDC_MO_DRIVE 0x40000 /* drive is an MO device */
61 #define CDC_MRW 0x80000 /* drive can read MRW */
62 #define CDC_MRW_W 0x100000 /* drive can write MRW */
63 #define CDC_RAM 0x200000 /* ok to open for WRITE */
66 void log_message(int priority, const char *format, ...)
69 static int udev_log = -1;
74 value = getenv("UDEV_LOG");
76 udev_log = log_priority(value);
81 if (priority > udev_log)
84 va_start(args, format);
85 vsyslog(priority, format, args);
90 int main(int argc, char *argv[])
92 const char *node = NULL;
99 logging_init("cdrom_id");
101 for (i = 1 ; i < argc; i++) {
104 if (strcmp(arg, "--export") == 0) {
110 info("no node specified");
115 fd = open(node, O_RDONLY|O_NONBLOCK);
117 info("unable to open '%s'", node);
122 result = ioctl(fd, CDROM_GET_CAPABILITY, NULL);
124 info("CDROM_GET_CAPABILITY failed for '%s'", node);
129 printf("ID_CDROM=1\n");
131 if (result & CDC_CD_R)
132 printf("ID_CDROM_CD_R=1\n");
133 if (result & CDC_CD_RW)
134 printf("ID_CDROM_CD_RW=1\n");
136 if (result & CDC_DVD)
137 printf("ID_CDROM_DVD=1\n");
138 if (result & CDC_DVD_R)
139 printf("ID_CDROM_DVD_R=1\n");
140 if (result & CDC_DVD_RAM)
141 printf("ID_CDROM_DVD_RAM=1\n");
143 if (result & CDC_MRW)
144 printf("ID_CDROM_MRW=1\n");
145 if (result & CDC_MRW_W)
146 printf("ID_CDROM_MRW_W=1\n");
148 if (result & CDC_RAM)
149 printf("ID_CDROM_RAM=1\n");