]> git.ipfire.org Git - thirdparty/systemd.git/blame - extras/cdrom_id/cdrom_id.c
cdrom_id: add Xen cdrom support
[thirdparty/systemd.git] / extras / cdrom_id / cdrom_id.c
CommitLineData
8f6919e6 1/*
fd7a285e 2 * cdrom_id - optical drive and media information prober
8f6919e6 3 *
fd7a285e 4 * Copyright (C) 2008 Kay Sievers <kay.sievers@vrfy.org>
8f6919e6 5 *
55e9959b
KS
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
8f6919e6 10 *
55e9959b
KS
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
fd7a285e 15 *
55e9959b
KS
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
8f6919e6
GKH
18 */
19
20#ifndef _GNU_SOURCE
21#define _GNU_SOURCE 1
22#endif
23
24#include <stdio.h>
fd7a285e 25#include <stddef.h>
8f6919e6
GKH
26#include <stdlib.h>
27#include <unistd.h>
1aa1e248 28#include <string.h>
fd7a285e
KS
29#include <limits.h>
30#include <fcntl.h>
8f6919e6 31#include <errno.h>
fd7a285e
KS
32#include <getopt.h>
33#include <scsi/sg.h>
8f6919e6
GKH
34#include <sys/types.h>
35#include <sys/stat.h>
fd7a285e
KS
36#include <sys/time.h>
37#include <sys/ioctl.h>
38#include <linux/cdrom.h>
01618658
KS
39
40#include "../../udev/udev.h"
8f6919e6 41
fd7a285e 42static int debug;
903a3649 43
7d563a17
KS
44static void log_fn(struct udev *udev, int priority,
45 const char *file, int line, const char *fn,
46 const char *format, va_list args)
8f6919e6 47{
fd7a285e 48 if (debug) {
7d563a17 49 fprintf(stderr, "%s: ", fn);
fd7a285e 50 vfprintf(stderr, format, args);
7d563a17 51 } else {
fd7a285e 52 vsyslog(priority, format, args);
7d563a17 53 }
8f6919e6 54}
8f6919e6 55
fd7a285e
KS
56/* device info */
57static unsigned int cd_cd_rom;
58static unsigned int cd_cd_r;
59static unsigned int cd_cd_rw;
60static unsigned int cd_dvd_rom;
61static unsigned int cd_dvd_r;
62static unsigned int cd_dvd_rw;
63static unsigned int cd_dvd_ram;
64static unsigned int cd_dvd_plus_r;
65static unsigned int cd_dvd_plus_rw;
66static unsigned int cd_dvd_plus_r_dl;
67static unsigned int cd_dvd_plus_rw_dl;
68static unsigned int cd_bd;
69static unsigned int cd_bd_r;
70static unsigned int cd_bd_re;
71static unsigned int cd_hddvd;
72static unsigned int cd_hddvd_r;
73static unsigned int cd_hddvd_rw;
74static unsigned int cd_mo;
75static unsigned int cd_mrw;
76static unsigned int cd_mrw_w;
77
78/* media info */
79static unsigned int cd_media_cd_rom;
80static unsigned int cd_media_cd_r;
81static unsigned int cd_media_cd_rw;
82static unsigned int cd_media_dvd_rom;
83static unsigned int cd_media_dvd_r;
84static unsigned int cd_media_dvd_rw;
85static unsigned int cd_media_dvd_ram;
86static unsigned int cd_media_dvd_plus_r;
87static unsigned int cd_media_dvd_plus_rw;
88static unsigned int cd_media_dvd_plus_r_dl;
89static unsigned int cd_media_dvd_plus_rw_dl;
90static unsigned int cd_media_bd;
91static unsigned int cd_media_bd_r;
92static unsigned int cd_media_bd_re;
93static unsigned int cd_media_hddvd;
94static unsigned int cd_media_hddvd_r;
95static unsigned int cd_media_hddvd_rw;
96static unsigned int cd_media_mo;
97static unsigned int cd_media_mrw;
98static unsigned int cd_media_mrw_w;
99
100static const char *cd_media_state;
fd7a285e
KS
101static unsigned int cd_media_session_next;
102static unsigned int cd_media_session_count;
103static unsigned int cd_media_track_count;
ec404619
KS
104static unsigned int cd_media_track_count_data;
105static unsigned int cd_media_track_count_audio;
fd7a285e
KS
106static unsigned long long int cd_media_session_last_offset;
107
108#define ERRCODE(s) ((((s)[2] & 0x0F) << 16) | ((s)[12] << 8) | ((s)[13]))
109#define SK(errcode) (((errcode) >> 16) & 0xF)
110#define ASC(errcode) (((errcode) >> 8) & 0xFF)
111#define ASCQ(errcode) ((errcode) & 0xFF)
112
7d563a17 113static void info_scsi_cmd_err(struct udev *udev, char *cmd, int err)
fd7a285e
KS
114{
115 if (err == -1) {
7d563a17 116 info(udev, "%s failed\n", cmd);
fd7a285e
KS
117 return;
118 }
7d563a17 119 info(udev, "%s failed with SK=%Xh/ASC=%02Xh/ACQ=%02Xh\n", cmd, SK(err), ASC(err), ASCQ(err));
fd7a285e
KS
120}
121
122struct scsi_cmd {
123 struct cdrom_generic_command cgc;
124 union {
125 struct request_sense s;
126 unsigned char u[18];
127 } _sense;
128 struct sg_io_hdr sg_io;
129};
130
7d563a17 131static void scsi_cmd_set(struct udev *udev, struct scsi_cmd *cmd, size_t i, int arg)
fd7a285e
KS
132{
133 if (i == 0) {
134 memset(cmd, 0x00, sizeof(struct scsi_cmd));
135 cmd->cgc.quiet = 1;
136 cmd->cgc.sense = &cmd->_sense.s;
137 memset(&cmd->sg_io, 0, sizeof(cmd->sg_io));
138 cmd->sg_io.interface_id = 'S';
139 cmd->sg_io.mx_sb_len = sizeof(cmd->_sense);
140 cmd->sg_io.cmdp = cmd->cgc.cmd;
141 cmd->sg_io.sbp = cmd->_sense.u;
142 cmd->sg_io.flags = SG_FLAG_LUN_INHIBIT | SG_FLAG_DIRECT_IO;
143 }
144 cmd->sg_io.cmd_len = i + 1;
145 cmd->cgc.cmd[i] = arg;
146}
147
148#define CHECK_CONDITION 0x01
149
7d563a17 150static int scsi_cmd_run(struct udev *udev, struct scsi_cmd *cmd, int fd, unsigned char *buf, size_t bufsize)
fd7a285e
KS
151{
152 int ret = 0;
153
154 cmd->sg_io.dxferp = buf;
155 cmd->sg_io.dxfer_len = bufsize;
156 cmd->sg_io.dxfer_direction = SG_DXFER_FROM_DEV;
157 if (ioctl(fd, SG_IO, &cmd->sg_io))
158 return -1;
159
160 if ((cmd->sg_io.info & SG_INFO_OK_MASK) != SG_INFO_OK) {
161 errno = EIO;
162 ret = -1;
163 if (cmd->sg_io.masked_status & CHECK_CONDITION) {
164 ret = ERRCODE(cmd->_sense.u);
165 if (ret == 0)
166 ret = -1;
167 }
168 }
169 return ret;
170}
171
7d563a17 172static int cd_capability_compat(struct udev *udev, int fd)
fd7a285e
KS
173{
174 int capabilty;
175
176 capabilty = ioctl(fd, CDROM_GET_CAPABILITY, NULL);
177 if (capabilty < 0) {
7d563a17 178 info(udev, "CDROM_GET_CAPABILITY failed\n");
fd7a285e
KS
179 return -1;
180 }
181
182 if (capabilty & CDC_CD_R)
183 cd_cd_r = 1;
184 if (capabilty & CDC_CD_RW)
185 cd_cd_rw = 1;
186 if (capabilty & CDC_DVD)
187 cd_dvd_rom = 1;
188 if (capabilty & CDC_DVD_R)
189 cd_dvd_r = 1;
190 if (capabilty & CDC_DVD_RAM)
191 cd_dvd_ram = 1;
192 if (capabilty & CDC_MRW)
193 cd_mrw = 1;
194 if (capabilty & CDC_MRW_W)
195 cd_mrw_w = 1;
196 return 0;
197}
198
7d563a17 199static int cd_inquiry(struct udev *udev, int fd) {
fd7a285e
KS
200 struct scsi_cmd sc;
201 unsigned char inq[128];
202 int err;
203
7d563a17
KS
204 scsi_cmd_set(udev, &sc, 0, 0x12);
205 scsi_cmd_set(udev, &sc, 4, 36);
206 scsi_cmd_set(udev, &sc, 5, 0);
207 err = scsi_cmd_run(udev, &sc, fd, inq, 36);
fd7a285e 208 if ((err < 0)) {
7d563a17 209 info_scsi_cmd_err(udev, "INQUIRY", err);
fd7a285e
KS
210 return -1;
211 }
212
213 if ((inq[0] & 0x1F) != 5) {
7d563a17 214 info(udev, "not an MMC unit\n");
fd7a285e
KS
215 return -1;
216 }
217
7d563a17 218 info(udev, "INQUIRY: [%.8s][%.16s][%.4s]\n", inq + 8, inq + 16, inq + 32);
fd7a285e
KS
219 return 0;
220}
221
7d563a17 222static int cd_profiles(struct udev *udev, int fd)
fd7a285e
KS
223{
224 struct scsi_cmd sc;
225 unsigned char header[8];
226 unsigned char profiles[512];
227 unsigned int cur_profile;
228 unsigned int len;
229 unsigned int i;
230 int err;
231
7d563a17
KS
232 scsi_cmd_set(udev, &sc, 0, 0x46);
233 scsi_cmd_set(udev, &sc, 1, 0);
234 scsi_cmd_set(udev, &sc, 8, sizeof(header));
235 scsi_cmd_set(udev, &sc, 9, 0);
236 err = scsi_cmd_run(udev, &sc, fd, header, sizeof(header));
fd7a285e 237 if ((err < 0)) {
7d563a17 238 info_scsi_cmd_err(udev, "GET CONFIGURATION", err);
fd7a285e
KS
239 return -1;
240 }
241
242 len = 4 + (header[0] << 24 | header[1] << 16 | header[2] << 8 | header[3]);
7d563a17 243 info(udev, "GET CONFIGURATION: number of profiles %i\n", len);
fd7a285e 244 if (len > sizeof(profiles)) {
7d563a17 245 info(udev, "invalid number of profiles\n");
fd7a285e
KS
246 return -1;
247 }
248
7d563a17
KS
249 scsi_cmd_set(udev, &sc, 0, 0x46);
250 scsi_cmd_set(udev, &sc, 1, 1);
251 scsi_cmd_set(udev, &sc, 6, len >> 16);
252 scsi_cmd_set(udev, &sc, 7, len >> 8);
253 scsi_cmd_set(udev, &sc, 8, len);
254 scsi_cmd_set(udev, &sc, 9, 0);
255 err = scsi_cmd_run(udev, &sc, fd, profiles, len);
fd7a285e 256 if ((err < 0)) {
7d563a17 257 info_scsi_cmd_err(udev, "GET CONFIGURATION", err);
fd7a285e
KS
258 return -1;
259 }
260
261 /* device profiles */
262 for (i = 12; i < profiles[11]; i += 4) {
263 unsigned int profile = (profiles[i] << 8 | profiles[i + 1]);
264 if (profile == 0)
265 continue;
7d563a17 266 info(udev, "profile 0x%02x\n", profile);
fd7a285e
KS
267
268 switch (profile) {
269 case 0x03:
270 case 0x04:
271 case 0x05:
272 cd_mo = 1;
273 break;
274 case 0x10:
275 cd_dvd_rom = 1;
276 break;
277 case 0x12:
278 cd_dvd_ram = 1;
279 break;
280 case 0x13:
281 case 0x14:
282 cd_dvd_rw = 1;
283 break;
284 case 0x1B:
285 cd_dvd_plus_r = 1;
286 break;
287 case 0x1A:
288 cd_dvd_plus_rw = 1;
289 break;
290 case 0x2A:
291 cd_dvd_plus_rw_dl = 1;
292 break;
293 case 0x2B:
294 cd_dvd_plus_r_dl = 1;
295 break;
296 case 0x40:
297 cd_bd = 1;
298 break;
299 case 0x41:
300 case 0x42:
301 cd_bd_r = 1;
302 break;
303 case 0x43:
304 cd_bd_re = 1;
305 break;
306 case 0x50:
307 cd_hddvd = 1;
308 break;
309 case 0x51:
310 cd_hddvd_r = 1;
311 break;
312 case 0x52:
313 cd_hddvd_rw = 1;
314 break;
315 default:
316 break;
317 }
318 }
319
320 /* current media profile */
321 cur_profile = header[6] << 8 | header[7];
7d563a17 322 info(udev, "current profile 0x%02x\n", cur_profile);
fd7a285e 323 if (cur_profile == 0) {
7d563a17 324 info(udev, "no current profile, assuming no media\n");
fd7a285e
KS
325 return -1;
326 }
327
328 switch (cur_profile) {
329 case 0x03:
330 case 0x04:
331 case 0x05:
332 cd_media_mo = 1;
333 break;
334 case 0x08:
335 cd_media_cd_rom = 1;
336 break;
337 case 0x09:
338 cd_media_cd_r = 1;
339 break;
340 case 0x0a:
341 cd_media_cd_rw = 1;
342 break;
343 case 0x10:
344 cd_media_dvd_rom = 1;
345 break;
346 case 0x11:
347 cd_media_dvd_r = 1;
348 break;
349 case 0x12:
350 cd_media_dvd_ram = 1;
351 break;
352 case 0x13:
353 case 0x14:
354 cd_media_dvd_rw = 1;
355 break;
356 case 0x1B:
357 cd_media_dvd_plus_r = 1;
358 break;
359 case 0x1A:
360 cd_media_dvd_plus_rw = 1;
361 break;
362 case 0x2A:
363 cd_media_dvd_plus_rw_dl = 1;
364 break;
365 case 0x2B:
366 cd_media_dvd_plus_r_dl = 1;
367 break;
368 case 0x40:
369 cd_media_bd = 1;
370 break;
371 case 0x41:
372 case 0x42:
373 cd_media_bd_r = 1;
374 break;
375 case 0x43:
376 cd_media_bd_re = 1;
377 break;
378 case 0x50:
379 cd_media_hddvd = 1;
380 break;
381 case 0x51:
382 cd_media_hddvd_r = 1;
383 break;
384 case 0x52:
385 cd_media_hddvd_rw = 1;
386 break;
387 default:
388 break;
389 }
390 return 0;
391}
392
7d563a17 393static int cd_media_info(struct udev *udev, int fd)
fd7a285e
KS
394{
395 struct scsi_cmd sc;
396 unsigned char header[32];
397 static const char *media_status[] = {
398 "blank",
399 "appendable",
400 "complete",
401 "other"
402 };
403 int err;
404
7d563a17
KS
405 scsi_cmd_set(udev, &sc, 0, 0x51);
406 scsi_cmd_set(udev, &sc, 8, sizeof(header));
407 scsi_cmd_set(udev, &sc, 9, 0);
408 err = scsi_cmd_run(udev, &sc, fd, header, sizeof(header));
fd7a285e 409 if ((err < 0)) {
7d563a17 410 info_scsi_cmd_err(udev, "READ DISC INFORMATION", err);
fd7a285e
KS
411 return -1;
412 };
413
7d563a17 414 info(udev, "disk type %02x\n", header[8]);
fd7a285e
KS
415
416 if ((header[2] & 3) < 4)
417 cd_media_state = media_status[header[2] & 3];
418 if ((header[2] & 3) != 2)
419 cd_media_session_next = header[10] << 8 | header[5];
420 cd_media_session_count = header[9] << 8 | header[4];
421 cd_media_track_count = header[11] << 8 | header[6];
422
423 return 0;
424}
425
7d563a17 426static int cd_media_toc(struct udev *udev, int fd)
fd7a285e
KS
427{
428 struct scsi_cmd sc;
429 unsigned char header[12];
430 unsigned char toc[2048];
431 unsigned int len, i;
432 unsigned char *p;
433 int err;
434
7d563a17
KS
435 scsi_cmd_set(udev, &sc, 0, 0x43);
436 scsi_cmd_set(udev, &sc, 6, 1);
437 scsi_cmd_set(udev, &sc, 8, sizeof(header));
438 scsi_cmd_set(udev, &sc, 9, 0);
439 err = scsi_cmd_run(udev, &sc, fd, header, sizeof(header));
fd7a285e 440 if ((err < 0)) {
7d563a17 441 info_scsi_cmd_err(udev, "READ TOC", err);
fd7a285e
KS
442 return -1;
443 }
444
445 len = (header[0] << 8 | header[1]) + 2;
7d563a17 446 info(udev, "READ TOC: len: %d\n", len);
fd7a285e
KS
447 if (len > sizeof(toc))
448 return -1;
9bbdf6eb 449 if (len < 2)
4cd71da5 450 return -1;
fd7a285e 451
9bbdf6eb
KS
452 /* empty media has no tracks */
453 if (len < 8)
454 return 0;
455
7d563a17
KS
456 scsi_cmd_set(udev, &sc, 0, 0x43);
457 scsi_cmd_set(udev, &sc, 6, header[2]); /* First Track/Session Number */
458 scsi_cmd_set(udev, &sc, 7, len >> 8);
459 scsi_cmd_set(udev, &sc, 8, len);
460 scsi_cmd_set(udev, &sc, 9, 0);
461 err = scsi_cmd_run(udev, &sc, fd, toc, len);
fd7a285e 462 if ((err < 0)) {
7d563a17 463 info_scsi_cmd_err(udev, "READ TOC (tracks)", err);
fd7a285e
KS
464 return -1;
465 }
466
467 for (p = toc+4, i = 4; i < len-8; i += 8, p += 8) {
468 unsigned int block;
ec404619
KS
469 unsigned int is_data_track;
470
471 is_data_track = (p[1] & 0x04) != 0;
fd7a285e
KS
472
473 block = p[4] << 24 | p[5] << 16 | p[6] << 8 | p[7];
7d563a17 474 info(udev, "track=%u info=0x%x(%s) start_block=%u\n",
ec404619
KS
475 p[2], p[1] & 0x0f, is_data_track ? "data":"audio", block);
476
477 if (is_data_track)
478 cd_media_track_count_data++;
479 else
480 cd_media_track_count_audio++;
fd7a285e
KS
481 }
482
7d563a17
KS
483 scsi_cmd_set(udev, &sc, 0, 0x43);
484 scsi_cmd_set(udev, &sc, 2, 1); /* Session Info */
485 scsi_cmd_set(udev, &sc, 8, 12);
486 scsi_cmd_set(udev, &sc, 9, 0);
487 err = scsi_cmd_run(udev, &sc, fd, header, sizeof(header));
fd7a285e 488 if ((err < 0)) {
7d563a17 489 info_scsi_cmd_err(udev, "READ TOC (multi session)", err);
fd7a285e
KS
490 return -1;
491 }
492 len = header[4+4] << 24 | header[4+5] << 16 | header[4+6] << 8 | header[4+7];
7d563a17 493 info(udev, "last track %u starts at block %u\n", header[4+2], len);
fd7a285e
KS
494 cd_media_session_last_offset = (unsigned long long int)len * 2048;
495 return 0;
496}
497
8f6919e6
GKH
498int main(int argc, char *argv[])
499{
7d563a17 500 struct udev *udev;
fd7a285e 501 static const struct option options[] = {
033e9f8c
KS
502 { "export", no_argument, NULL, 'x' },
503 { "debug", no_argument, NULL, 'd' },
504 { "help", no_argument, NULL, 'h' },
fd7a285e
KS
505 {}
506 };
8f6919e6 507 const char *node = NULL;
8f6919e6 508 int export = 0;
fd7a285e 509 int fd = -1;
8f6919e6 510 int rc = 0;
8f6919e6 511
7d563a17
KS
512 udev = udev_new();
513 if (udev == NULL)
514 goto exit;
515
8f6919e6 516 logging_init("cdrom_id");
7d563a17 517 udev_set_log_fn(udev, log_fn);
8f6919e6 518
fd7a285e
KS
519 while (1) {
520 int option;
8f6919e6 521
fd7a285e
KS
522 option = getopt_long(argc, argv, "dxh", options, NULL);
523 if (option == -1)
524 break;
525
526 switch (option) {
527 case 'd':
528 debug = 1;
7d563a17
KS
529 if (udev_get_log_priority(udev) < LOG_INFO)
530 udev_set_log_priority(udev, LOG_INFO);
fd7a285e
KS
531 break;
532 case 'x':
8f6919e6 533 export = 1;
fd7a285e
KS
534 break;
535 case 'h':
536 printf("Usage: cdrom_id [options] <device>\n"
953080ab
KS
537 " --export export key/value pairs\n"
538 " --debug debug to stderr\n"
539 " --help print this help text\n\n");
fd7a285e
KS
540 goto exit;
541 default:
542 rc = 1;
543 goto exit;
544 }
8f6919e6 545 }
fd7a285e
KS
546
547 node = argv[optind];
8f6919e6 548 if (!node) {
7d563a17 549 err(udev, "no device\n");
fd7a285e 550 fprintf(stderr, "no device\n");
8f6919e6
GKH
551 rc = 1;
552 goto exit;
553 }
554
fd7a285e 555 fd = open(node, O_RDONLY | O_NONBLOCK);
8f6919e6 556 if (fd < 0) {
7d563a17 557 info(udev, "unable to open '%s'\n", node);
8f6919e6
GKH
558 rc = 1;
559 goto exit;
560 }
7d563a17 561 info(udev, "probing: '%s'\n", node);
fd7a285e
KS
562
563 /* same data as original cdrom_id */
7d563a17 564 if (cd_capability_compat(udev, fd) < 0) {
fd7a285e
KS
565 rc = 1;
566 goto exit;
567 }
8f6919e6 568
fd7a285e 569 /* check drive */
55d8f5e2
KS
570 if (cd_inquiry(udev, fd) < 0)
571 goto print;
8f6919e6 572
fd7a285e 573 /* read drive and possibly current profile */
7d563a17 574 if (cd_profiles(udev, fd) < 0)
fd7a285e
KS
575 goto print;
576
577 /* get session/track info */
7d563a17 578 if (cd_media_toc(udev, fd) < 0)
fd7a285e 579 goto print;
8f6919e6 580
fd7a285e 581 /* get writable media state */
7d563a17 582 if (cd_media_info(udev, fd) < 0)
fd7a285e
KS
583 goto print;
584
585print:
586 printf("ID_CDROM=1\n");
587 if (cd_cd_rom)
588 printf("ID_CDROM_CD=1\n");
589 if (cd_cd_r)
8ee99e32 590 printf("ID_CDROM_CD_R=1\n");
fd7a285e 591 if (cd_cd_rw)
8ee99e32 592 printf("ID_CDROM_CD_RW=1\n");
fd7a285e 593 if (cd_dvd_rom)
8ee99e32 594 printf("ID_CDROM_DVD=1\n");
fd7a285e 595 if (cd_dvd_r)
8ee99e32 596 printf("ID_CDROM_DVD_R=1\n");
fd7a285e
KS
597 if (cd_dvd_rw)
598 printf("ID_CDROM_DVD_RW=1\n");
599 if (cd_dvd_ram)
8ee99e32 600 printf("ID_CDROM_DVD_RAM=1\n");
fd7a285e
KS
601 if (cd_dvd_plus_r)
602 printf("ID_CDROM_DVD_PLUS_R=1\n");
603 if (cd_dvd_plus_rw)
604 printf("ID_CDROM_DVD_PLUS_RW=1\n");
605 if (cd_dvd_plus_r_dl)
606 printf("ID_CDROM_DVD_PLUS_R_DL=1\n");
607 if (cd_dvd_plus_rw_dl)
608 printf("ID_CDROM_DVD_PLUS_RW_DL=1\n");
609 if (cd_bd)
610 printf("ID_CDROM_BD=1\n");
611 if (cd_bd_r)
612 printf("ID_CDROM_BD_R=1\n");
613 if (cd_bd_re)
614 printf("ID_CDROM_BD_RE=1\n");
615 if (cd_hddvd)
616 printf("ID_CDROM_HDDVD=1\n");
617 if (cd_hddvd_r)
618 printf("ID_CDROM_HDDVD_R=1\n");
619 if (cd_hddvd_rw)
620 printf("ID_CDROM_HDDVD_RW=1\n");
621 if (cd_mo)
622 printf("ID_CDROM_MO=1\n");
623 if (cd_mrw)
8ee99e32 624 printf("ID_CDROM_MRW=1\n");
fd7a285e 625 if (cd_mrw_w)
8ee99e32 626 printf("ID_CDROM_MRW_W=1\n");
5a64cea1 627
fd7a285e
KS
628 if (cd_media_mo)
629 printf("ID_CDROM_MEDIA_MO=1\n");
630 if (cd_media_mrw)
631 printf("ID_CDROM_MEDIA_MRW=1\n");
632 if (cd_media_mrw_w)
633 printf("ID_CDROM_MEDIA_MRW_W=1\n");
634 if (cd_media_cd_rom)
635 printf("ID_CDROM_MEDIA_CD=1\n");
636 if (cd_media_cd_r)
637 printf("ID_CDROM_MEDIA_CD_R=1\n");
638 if (cd_media_cd_rw)
639 printf("ID_CDROM_MEDIA_CD_RW=1\n");
640 if (cd_media_dvd_rom)
641 printf("ID_CDROM_MEDIA_DVD=1\n");
642 if (cd_media_dvd_r)
643 printf("ID_CDROM_MEDIA_DVD_R=1\n");
644 if (cd_media_dvd_ram)
645 printf("ID_CDROM_MEDIA_DVD_RAM=1\n");
646 if (cd_media_dvd_rw)
647 printf("ID_CDROM_MEDIA_DVD_RW=1\n");
648 if (cd_media_dvd_plus_r)
649 printf("ID_CDROM_MEDIA_DVD_PLUS_R=1\n");
650 if (cd_media_dvd_plus_rw)
651 printf("ID_CDROM_MEDIA_DVD_PLUS_RW=1\n");
652 if (cd_media_dvd_plus_rw_dl)
653 printf("ID_CDROM_MEDIA_DVD_PLUS_RW_DL=1\n");
654 if (cd_media_dvd_plus_r_dl)
655 printf("ID_CDROM_MEDIA_DVD_PLUS_R_DL=1\n");
656 if (cd_media_bd)
657 printf("ID_CDROM_MEDIA_BD=1\n");
658 if (cd_media_bd_r)
659 printf("ID_CDROM_MEDIA_BD_R=1\n");
660 if (cd_media_bd_re)
661 printf("ID_CDROM_MEDIA_BD_RE=1\n");
662 if (cd_media_hddvd)
663 printf("ID_CDROM_MEDIA_HDDVD=1\n");
664 if (cd_media_hddvd_r)
665 printf("ID_CDROM_MEDIA_HDDVD_R=1\n");
666 if (cd_media_hddvd_rw)
667 printf("ID_CDROM_MEDIA_HDDVD_RW=1\n");
668
669 if (cd_media_state != NULL)
670 printf("ID_CDROM_MEDIA_STATE=%s\n", cd_media_state);
fd7a285e
KS
671 if (cd_media_session_next > 0)
672 printf("ID_CDROM_MEDIA_SESSION_NEXT=%d\n", cd_media_session_next);
673 if (cd_media_session_count > 0)
674 printf("ID_CDROM_MEDIA_SESSION_COUNT=%d\n", cd_media_session_count);
675 if (cd_media_track_count > 0)
676 printf("ID_CDROM_MEDIA_TRACK_COUNT=%d\n", cd_media_track_count);
f46a8a98 677 if (cd_media_track_count_audio > 0)
ec404619 678 printf("ID_CDROM_MEDIA_TRACK_COUNT_AUDIO=%d\n", cd_media_track_count_audio);
f46a8a98 679 if (cd_media_track_count_data > 0)
ec404619 680 printf("ID_CDROM_MEDIA_TRACK_COUNT_DATA=%d\n", cd_media_track_count_data);
f46a8a98 681 if (cd_media_session_last_offset > 0)
fd7a285e 682 printf("ID_CDROM_MEDIA_SESSION_LAST_OFFSET=%llu\n", cd_media_session_last_offset);
8f6919e6 683exit:
fd7a285e
KS
684 if (fd >= 0)
685 close(fd);
7d563a17 686 udev_unref(udev);
8f6919e6
GKH
687 logging_close();
688 return rc;
689}
fd7a285e 690