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>
29 #include <linux/cdrom.h>
31 #include "../../logging.h"
32 #include "../../udev_utils.h"
35 void log_message(int priority, const char *format, ...)
38 static int udev_log = -1;
43 value = getenv("UDEV_LOG");
45 udev_log = log_priority(value);
50 if (priority > udev_log)
53 va_start(args, format);
54 vsyslog(priority, format, args);
59 int main(int argc, char *argv[])
61 const char *node = NULL;
68 logging_init("cdrom_id");
70 for (i = 1 ; i < argc; i++) {
73 if (strcmp(arg, "--export") == 0) {
79 err("no node specified");
84 fd = open(node, O_RDONLY);
86 if (errno == ENOMEDIUM)
87 fd = open(node, O_RDONLY|O_NONBLOCK);
89 err("unable to open '%s'", node);
94 result = ioctl(fd, CDROM_GET_CAPABILITY, NULL);
96 err("CDROM_GET_CABILITY failed for '%s'", node);
101 printf("ID_CDROM=1\n");
103 if (result & CDC_CD_R)
104 printf("ID_CDROM_CD_R=1\n");
105 if (result & CDC_CD_RW)
106 printf("ID_CDROM_CD_RW=1\n");
108 if (result & CDC_DVD)
109 printf("ID_CDROM_DVD=1\n");
110 if (result & CDC_DVD_R)
111 printf("ID_CDROM_DVD_R=1\n");
112 if (result & CDC_DVD_RAM)
113 printf("ID_CDROM_DVD_RAM=1\n");
115 if (result & CDC_MRW)
116 printf("ID_CDROM_MRW=1\n");
117 if (result & CDC_MRW_W)
118 printf("ID_CDROM_MRW_W=1\n");
120 if (result & CDC_RAM)
121 printf("ID_CDROM_RAM=1\n");