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