chiark / gitweb /
path_id: support identification of Xen virtual block devices
[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 static int debug;
43
44 static void log_fn(struct udev *udev, int priority,
45                    const char *file, int line, const char *fn,
46                    const char *format, va_list args)
47 {
48         if (debug) {
49                 fprintf(stderr, "%s: ", fn);
50                 vfprintf(stderr, format, args);
51         } else {
52                 vsyslog(priority, format, args);
53         }
54 }
55
56 /* device info */
57 static unsigned int cd_cd_rom;
58 static unsigned int cd_cd_r;
59 static unsigned int cd_cd_rw;
60 static unsigned int cd_dvd_rom;
61 static unsigned int cd_dvd_r;
62 static unsigned int cd_dvd_rw;
63 static unsigned int cd_dvd_ram;
64 static unsigned int cd_dvd_plus_r;
65 static unsigned int cd_dvd_plus_rw;
66 static unsigned int cd_dvd_plus_r_dl;
67 static unsigned int cd_dvd_plus_rw_dl;
68 static unsigned int cd_bd;
69 static unsigned int cd_bd_r;
70 static unsigned int cd_bd_re;
71 static unsigned int cd_hddvd;
72 static unsigned int cd_hddvd_r;
73 static unsigned int cd_hddvd_rw;
74 static unsigned int cd_mo;
75 static unsigned int cd_mrw;
76 static unsigned int cd_mrw_w;
77
78 /* media info */
79 static unsigned int cd_media_cd_rom;
80 static unsigned int cd_media_cd_r;
81 static unsigned int cd_media_cd_rw;
82 static unsigned int cd_media_dvd_rom;
83 static unsigned int cd_media_dvd_r;
84 static unsigned int cd_media_dvd_rw;
85 static unsigned int cd_media_dvd_ram;
86 static unsigned int cd_media_dvd_plus_r;
87 static unsigned int cd_media_dvd_plus_rw;
88 static unsigned int cd_media_dvd_plus_r_dl;
89 static unsigned int cd_media_dvd_plus_rw_dl;
90 static unsigned int cd_media_bd;
91 static unsigned int cd_media_bd_r;
92 static unsigned int cd_media_bd_re;
93 static unsigned int cd_media_hddvd;
94 static unsigned int cd_media_hddvd_r;
95 static unsigned int cd_media_hddvd_rw;
96 static unsigned int cd_media_mo;
97 static unsigned int cd_media_mrw;
98 static unsigned int cd_media_mrw_w;
99
100 static const char *cd_media_state;
101 static unsigned int cd_media_session_next;
102 static unsigned int cd_media_session_count;
103 static unsigned int cd_media_track_count;
104 static unsigned int cd_media_track_count_data;
105 static unsigned int cd_media_track_count_audio;
106 static 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
113 static void info_scsi_cmd_err(struct udev *udev, char *cmd, int err)
114 {
115         if (err == -1) {
116                 info(udev, "%s failed\n", cmd);
117                 return;
118         }
119         info(udev, "%s failed with SK=%Xh/ASC=%02Xh/ACQ=%02Xh\n", cmd, SK(err), ASC(err), ASCQ(err));
120 }
121
122 struct 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
131 static void scsi_cmd_set(struct udev *udev, struct scsi_cmd *cmd, size_t i, int arg)
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
150 static int scsi_cmd_run(struct udev *udev, struct scsi_cmd *cmd, int fd, unsigned char *buf, size_t bufsize)
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
172 static int cd_capability_compat(struct udev *udev, int fd)
173 {
174         int capabilty;
175
176         capabilty = ioctl(fd, CDROM_GET_CAPABILITY, NULL);
177         if (capabilty < 0) {
178                 info(udev, "CDROM_GET_CAPABILITY failed\n");
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
199 static int cd_inquiry(struct udev *udev, int fd) {
200         struct scsi_cmd sc;
201         unsigned char inq[128];
202         int err;
203
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);
208         if ((err < 0)) {
209                 info_scsi_cmd_err(udev, "INQUIRY", err);
210                 return -1;
211         }
212
213         if ((inq[0] & 0x1F) != 5) {
214                 info(udev, "not an MMC unit\n");
215                 return -1;
216         }
217
218         info(udev, "INQUIRY: [%.8s][%.16s][%.4s]\n", inq + 8, inq + 16, inq + 32);
219         return 0;
220 }
221
222 static int cd_profiles(struct udev *udev, int fd)
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
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));
237         if ((err < 0)) {
238                 info_scsi_cmd_err(udev, "GET CONFIGURATION", err);
239                 return -1;
240         }
241
242         len = 4 + (header[0] << 24 | header[1] << 16 | header[2] << 8 | header[3]);
243         info(udev, "GET CONFIGURATION: number of profiles %i\n", len);
244         if (len > sizeof(profiles)) {
245                 info(udev, "invalid number of profiles\n");
246                 return -1;
247         }
248
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);
256         if ((err < 0)) {
257                 info_scsi_cmd_err(udev, "GET CONFIGURATION", err);
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;
266                 info(udev, "profile 0x%02x\n", profile);
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];
322         info(udev, "current profile 0x%02x\n", cur_profile);
323         if (cur_profile == 0) {
324                 info(udev, "no current profile, assuming no media\n");
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
393 static int cd_media_info(struct udev *udev, int fd)
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
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));
409         if ((err < 0)) {
410                 info_scsi_cmd_err(udev, "READ DISC INFORMATION", err);
411                 return -1;
412         };
413
414         info(udev, "disk type %02x\n", header[8]);
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
426 static int cd_media_toc(struct udev *udev, int fd)
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
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));
440         if ((err < 0)) {
441                 info_scsi_cmd_err(udev, "READ TOC", err);
442                 return -1;
443         }
444
445         len = (header[0] << 8 | header[1]) + 2;
446         info(udev, "READ TOC: len: %d\n", len);
447         if (len > sizeof(toc))
448                 return -1;
449         if (len < 2)
450                 return -1;
451
452         /* empty media has no tracks */
453         if (len < 8)
454                 return 0;
455
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);
462         if ((err < 0)) {
463                 info_scsi_cmd_err(udev, "READ TOC (tracks)", err);
464                 return -1;
465         }
466
467         for (p = toc+4, i = 4; i < len-8; i += 8, p += 8) {
468                 unsigned int block;
469                 unsigned int is_data_track;
470
471                 is_data_track = (p[1] & 0x04) != 0;
472
473                 block = p[4] << 24 | p[5] << 16 | p[6] << 8 | p[7];
474                 info(udev, "track=%u info=0x%x(%s) start_block=%u\n",
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++;
481         }
482
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));
488         if ((err < 0)) {
489                 info_scsi_cmd_err(udev, "READ TOC (multi session)", err);
490                 return -1;
491         }
492         len = header[4+4] << 24 | header[4+5] << 16 | header[4+6] << 8 | header[4+7];
493         info(udev, "last track %u starts at block %u\n", header[4+2], len);
494         cd_media_session_last_offset = (unsigned long long int)len * 2048;
495         return 0;
496 }
497
498 int main(int argc, char *argv[])
499 {
500         struct udev *udev;
501         static const struct option options[] = {
502                 { "export", no_argument, NULL, 'x' },
503                 { "debug", no_argument, NULL, 'd' },
504                 { "help", no_argument, NULL, 'h' },
505                 {}
506         };
507         const char *node = NULL;
508         int export = 0;
509         int fd = -1;
510         int rc = 0;
511
512         udev = udev_new();
513         if (udev == NULL)
514                 goto exit;
515
516         logging_init("cdrom_id");
517         udev_set_log_fn(udev, log_fn);
518
519         while (1) {
520                 int option;
521
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;
529                         if (udev_get_log_priority(udev) < LOG_INFO)
530                                 udev_set_log_priority(udev, LOG_INFO);
531                         break;
532                 case 'x':
533                         export = 1;
534                         break;
535                 case 'h':
536                         printf("Usage: cdrom_id [options] <device>\n"
537                                "  --export        export key/value pairs\n"
538                                "  --debug         debug to stderr\n"
539                                "  --help          print this help text\n\n");
540                         goto exit;
541                 default:
542                         rc = 1;
543                         goto exit;
544                 }
545         }
546
547         node = argv[optind];
548         if (!node) {
549                 err(udev, "no device\n");
550                 fprintf(stderr, "no device\n");
551                 rc = 1;
552                 goto exit;
553         }
554
555         fd = open(node, O_RDONLY | O_NONBLOCK);
556         if (fd < 0) {
557                 info(udev, "unable to open '%s'\n", node);
558                 rc = 1;
559                 goto exit;
560         }
561         info(udev, "probing: '%s'\n", node);
562
563         /* same data as original cdrom_id */
564         if (cd_capability_compat(udev, fd) < 0) {
565                 rc = 1;
566                 goto exit;
567         }
568
569         /* check drive */
570         if (cd_inquiry(udev, fd) < 0) {
571                 rc = 2;
572                 goto exit;
573         }
574
575         /* read drive and possibly current profile */
576         if (cd_profiles(udev, fd) < 0)
577                 goto print;
578
579         /* get session/track info */
580         if (cd_media_toc(udev, fd) < 0)
581                 goto print;
582
583         /* get writable media state */
584         if (cd_media_info(udev, fd) < 0)
585                 goto print;
586
587 print:
588         printf("ID_CDROM=1\n");
589         if (cd_cd_rom)
590                 printf("ID_CDROM_CD=1\n");
591         if (cd_cd_r)
592                 printf("ID_CDROM_CD_R=1\n");
593         if (cd_cd_rw)
594                 printf("ID_CDROM_CD_RW=1\n");
595         if (cd_dvd_rom)
596                 printf("ID_CDROM_DVD=1\n");
597         if (cd_dvd_r)
598                 printf("ID_CDROM_DVD_R=1\n");
599         if (cd_dvd_rw)
600                 printf("ID_CDROM_DVD_RW=1\n");
601         if (cd_dvd_ram)
602                 printf("ID_CDROM_DVD_RAM=1\n");
603         if (cd_dvd_plus_r)
604                 printf("ID_CDROM_DVD_PLUS_R=1\n");
605         if (cd_dvd_plus_rw)
606                 printf("ID_CDROM_DVD_PLUS_RW=1\n");
607         if (cd_dvd_plus_r_dl)
608                 printf("ID_CDROM_DVD_PLUS_R_DL=1\n");
609         if (cd_dvd_plus_rw_dl)
610                 printf("ID_CDROM_DVD_PLUS_RW_DL=1\n");
611         if (cd_bd)
612                 printf("ID_CDROM_BD=1\n");
613         if (cd_bd_r)
614                 printf("ID_CDROM_BD_R=1\n");
615         if (cd_bd_re)
616                 printf("ID_CDROM_BD_RE=1\n");
617         if (cd_hddvd)
618                 printf("ID_CDROM_HDDVD=1\n");
619         if (cd_hddvd_r)
620                 printf("ID_CDROM_HDDVD_R=1\n");
621         if (cd_hddvd_rw)
622                 printf("ID_CDROM_HDDVD_RW=1\n");
623         if (cd_mo)
624                 printf("ID_CDROM_MO=1\n");
625         if (cd_mrw)
626                 printf("ID_CDROM_MRW=1\n");
627         if (cd_mrw_w)
628                 printf("ID_CDROM_MRW_W=1\n");
629
630         if (cd_media_mo)
631                 printf("ID_CDROM_MEDIA_MO=1\n");
632         if (cd_media_mrw)
633                 printf("ID_CDROM_MEDIA_MRW=1\n");
634         if (cd_media_mrw_w)
635                 printf("ID_CDROM_MEDIA_MRW_W=1\n");
636         if (cd_media_cd_rom)
637                 printf("ID_CDROM_MEDIA_CD=1\n");
638         if (cd_media_cd_r)
639                 printf("ID_CDROM_MEDIA_CD_R=1\n");
640         if (cd_media_cd_rw)
641                 printf("ID_CDROM_MEDIA_CD_RW=1\n");
642         if (cd_media_dvd_rom)
643                 printf("ID_CDROM_MEDIA_DVD=1\n");
644         if (cd_media_dvd_r)
645                 printf("ID_CDROM_MEDIA_DVD_R=1\n");
646         if (cd_media_dvd_ram)
647                 printf("ID_CDROM_MEDIA_DVD_RAM=1\n");
648         if (cd_media_dvd_rw)
649                 printf("ID_CDROM_MEDIA_DVD_RW=1\n");
650         if (cd_media_dvd_plus_r)
651                 printf("ID_CDROM_MEDIA_DVD_PLUS_R=1\n");
652         if (cd_media_dvd_plus_rw)
653                 printf("ID_CDROM_MEDIA_DVD_PLUS_RW=1\n");
654         if (cd_media_dvd_plus_rw_dl)
655                 printf("ID_CDROM_MEDIA_DVD_PLUS_RW_DL=1\n");
656         if (cd_media_dvd_plus_r_dl)
657                 printf("ID_CDROM_MEDIA_DVD_PLUS_R_DL=1\n");
658         if (cd_media_bd)
659                 printf("ID_CDROM_MEDIA_BD=1\n");
660         if (cd_media_bd_r)
661                 printf("ID_CDROM_MEDIA_BD_R=1\n");
662         if (cd_media_bd_re)
663                 printf("ID_CDROM_MEDIA_BD_RE=1\n");
664         if (cd_media_hddvd)
665                 printf("ID_CDROM_MEDIA_HDDVD=1\n");
666         if (cd_media_hddvd_r)
667                 printf("ID_CDROM_MEDIA_HDDVD_R=1\n");
668         if (cd_media_hddvd_rw)
669                 printf("ID_CDROM_MEDIA_HDDVD_RW=1\n");
670
671         if (cd_media_state != NULL)
672                 printf("ID_CDROM_MEDIA_STATE=%s\n", cd_media_state);
673         if (cd_media_session_next > 0)
674                 printf("ID_CDROM_MEDIA_SESSION_NEXT=%d\n", cd_media_session_next);
675         if (cd_media_session_count > 0)
676                 printf("ID_CDROM_MEDIA_SESSION_COUNT=%d\n", cd_media_session_count);
677         if (cd_media_track_count > 0)
678                 printf("ID_CDROM_MEDIA_TRACK_COUNT=%d\n", cd_media_track_count);
679         if (cd_media_track_count_audio > 0)
680                 printf("ID_CDROM_MEDIA_TRACK_COUNT_AUDIO=%d\n", cd_media_track_count_audio);
681         if (cd_media_track_count_data > 0)
682                 printf("ID_CDROM_MEDIA_TRACK_COUNT_DATA=%d\n", cd_media_track_count_data);
683         if (cd_media_session_last_offset > 0)
684                 printf("ID_CDROM_MEDIA_SESSION_LAST_OFFSET=%llu\n", cd_media_session_last_offset);
685 exit:
686         if (fd >= 0)
687                 close(fd);
688         udev_unref(udev);
689         logging_close();
690         return rc;
691 }
692