X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=extras%2Fcdrom_id%2Fcdrom_id.c;h=2bea2e4b0c9e1b9f5cc50e2b76afcf8442a40a0d;hb=cbcb846a4c9c9b8215a3f484d70e3cefde5ba226;hp=7be0789f35bc2bf92013a2571fefb22c07eb7430;hpb=e02d738ee4da950e9228802ea52d9a6f0992c442;p=elogind.git diff --git a/extras/cdrom_id/cdrom_id.c b/extras/cdrom_id/cdrom_id.c index 7be0789f3..2bea2e4b0 100644 --- a/extras/cdrom_id/cdrom_id.c +++ b/extras/cdrom_id/cdrom_id.c @@ -1,7 +1,7 @@ /* * cdrom_id - optical drive and media information prober * - * Copyright (C) 2008 Kay Sievers + * Copyright (C) 2008-2010 Kay Sievers * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -37,7 +38,8 @@ #include #include -#include "../../udev/udev.h" +#include "libudev.h" +#include "libudev-private.h" static int debug; @@ -54,62 +56,86 @@ static void log_fn(struct udev *udev, int priority, } /* device info */ -static unsigned int cd_cd_rom; -static unsigned int cd_cd_r; -static unsigned int cd_cd_rw; -static unsigned int cd_dvd_rom; -static unsigned int cd_dvd_r; -static unsigned int cd_dvd_rw; -static unsigned int cd_dvd_ram; -static unsigned int cd_dvd_plus_r; -static unsigned int cd_dvd_plus_rw; -static unsigned int cd_dvd_plus_r_dl; -static unsigned int cd_dvd_plus_rw_dl; -static unsigned int cd_bd; -static unsigned int cd_bd_r; -static unsigned int cd_bd_re; -static unsigned int cd_hddvd; -static unsigned int cd_hddvd_r; -static unsigned int cd_hddvd_rw; -static unsigned int cd_mo; -static unsigned int cd_mrw; -static unsigned int cd_mrw_w; +static unsigned int cd_cd_rom = 0; +static unsigned int cd_cd_r = 0; +static unsigned int cd_cd_rw = 0; +static unsigned int cd_dvd_rom = 0; +static unsigned int cd_dvd_r = 0; +static unsigned int cd_dvd_rw = 0; +static unsigned int cd_dvd_ram = 0; +static unsigned int cd_dvd_plus_r = 0; +static unsigned int cd_dvd_plus_rw = 0; +static unsigned int cd_dvd_plus_r_dl = 0; +static unsigned int cd_dvd_plus_rw_dl = 0; +static unsigned int cd_bd = 0; +static unsigned int cd_bd_r = 0; +static unsigned int cd_bd_re = 0; +static unsigned int cd_hddvd = 0; +static unsigned int cd_hddvd_r = 0; +static unsigned int cd_hddvd_rw = 0; +static unsigned int cd_mo = 0; +static unsigned int cd_mrw = 0; +static unsigned int cd_mrw_w = 0; /* media info */ -static unsigned int cd_media_cd_rom; -static unsigned int cd_media_cd_r; -static unsigned int cd_media_cd_rw; -static unsigned int cd_media_dvd_rom; -static unsigned int cd_media_dvd_r; -static unsigned int cd_media_dvd_rw; -static unsigned int cd_media_dvd_ram; -static unsigned int cd_media_dvd_plus_r; -static unsigned int cd_media_dvd_plus_rw; -static unsigned int cd_media_dvd_plus_r_dl; -static unsigned int cd_media_dvd_plus_rw_dl; -static unsigned int cd_media_bd; -static unsigned int cd_media_bd_r; -static unsigned int cd_media_bd_re; -static unsigned int cd_media_hddvd; -static unsigned int cd_media_hddvd_r; -static unsigned int cd_media_hddvd_rw; -static unsigned int cd_media_mo; -static unsigned int cd_media_mrw; -static unsigned int cd_media_mrw_w; - -static const char *cd_media_state; -static unsigned int cd_media_session_next; -static unsigned int cd_media_session_count; -static unsigned int cd_media_track_count; -static unsigned int cd_media_track_count_data; -static unsigned int cd_media_track_count_audio; -static unsigned long long int cd_media_session_last_offset; +static unsigned int cd_media = 0; +static unsigned int cd_media_cd_rom = 0; +static unsigned int cd_media_cd_r = 0; +static unsigned int cd_media_cd_rw = 0; +static unsigned int cd_media_dvd_rom = 0; +static unsigned int cd_media_dvd_r = 0; +static unsigned int cd_media_dvd_rw = 0; +static unsigned int cd_media_dvd_ram = 0; +static unsigned int cd_media_dvd_plus_r = 0; +static unsigned int cd_media_dvd_plus_rw = 0; +static unsigned int cd_media_dvd_plus_r_dl = 0; +static unsigned int cd_media_dvd_plus_rw_dl = 0; +static unsigned int cd_media_bd = 0; +static unsigned int cd_media_bd_r = 0; +static unsigned int cd_media_bd_re = 0; +static unsigned int cd_media_hddvd = 0; +static unsigned int cd_media_hddvd_r = 0; +static unsigned int cd_media_hddvd_rw = 0; +static unsigned int cd_media_mo = 0; +static unsigned int cd_media_mrw = 0; +static unsigned int cd_media_mrw_w = 0; + +static const char *cd_media_state = NULL; +static unsigned int cd_media_session_next = 0; +static unsigned int cd_media_session_count = 0; +static unsigned int cd_media_track_count = 0; +static unsigned int cd_media_track_count_data = 0; +static unsigned int cd_media_track_count_audio = 0; +static unsigned long long int cd_media_session_last_offset = 0; #define ERRCODE(s) ((((s)[2] & 0x0F) << 16) | ((s)[12] << 8) | ((s)[13])) #define SK(errcode) (((errcode) >> 16) & 0xF) #define ASC(errcode) (((errcode) >> 8) & 0xFF) #define ASCQ(errcode) ((errcode) & 0xFF) +static int is_mounted(const char *device) +{ + struct stat statbuf; + FILE *fp; + int maj, min; + int mounted = 0; + + if (stat(device, &statbuf) < 0) + return -ENODEV; + + fp = fopen("/proc/self/mountinfo", "r"); + if (fp == NULL) + return -ENOSYS; + while (fscanf(fp, "%*s %*s %i:%i %*[^\n]", &maj, &min) == 2) { + if (makedev(maj, min) == statbuf.st_rdev) { + mounted = 1; + break; + } + } + fclose(fp); + return mounted; +} + static void info_scsi_cmd_err(struct udev *udev, char *cmd, int err) { if (err == -1) { @@ -128,19 +154,22 @@ struct scsi_cmd { struct sg_io_hdr sg_io; }; -static void scsi_cmd_set(struct udev *udev, struct scsi_cmd *cmd, size_t i, int arg) +static void scsi_cmd_init(struct udev *udev, struct scsi_cmd *cmd, unsigned char *buf, size_t bufsize) +{ + memset(cmd, 0x00, sizeof(struct scsi_cmd)); + memset(buf, 0x00, bufsize); + cmd->cgc.quiet = 1; + cmd->cgc.sense = &cmd->_sense.s; + memset(&cmd->sg_io, 0, sizeof(cmd->sg_io)); + cmd->sg_io.interface_id = 'S'; + cmd->sg_io.mx_sb_len = sizeof(cmd->_sense); + cmd->sg_io.cmdp = cmd->cgc.cmd; + cmd->sg_io.sbp = cmd->_sense.u; + cmd->sg_io.flags = SG_FLAG_LUN_INHIBIT | SG_FLAG_DIRECT_IO; +} + +static void scsi_cmd_set(struct udev *udev, struct scsi_cmd *cmd, size_t i, unsigned char arg) { - if (i == 0) { - memset(cmd, 0x00, sizeof(struct scsi_cmd)); - cmd->cgc.quiet = 1; - cmd->cgc.sense = &cmd->_sense.s; - memset(&cmd->sg_io, 0, sizeof(cmd->sg_io)); - cmd->sg_io.interface_id = 'S'; - cmd->sg_io.mx_sb_len = sizeof(cmd->_sense); - cmd->sg_io.cmdp = cmd->cgc.cmd; - cmd->sg_io.sbp = cmd->_sense.u; - cmd->sg_io.flags = SG_FLAG_LUN_INHIBIT | SG_FLAG_DIRECT_IO; - } cmd->sg_io.cmd_len = i + 1; cmd->cgc.cmd[i] = arg; } @@ -171,41 +200,52 @@ static int scsi_cmd_run(struct udev *udev, struct scsi_cmd *cmd, int fd, unsigne static int cd_capability_compat(struct udev *udev, int fd) { - int capabilty; + int capability; - capabilty = ioctl(fd, CDROM_GET_CAPABILITY, NULL); - if (capabilty < 0) { + capability = ioctl(fd, CDROM_GET_CAPABILITY, NULL); + if (capability < 0) { info(udev, "CDROM_GET_CAPABILITY failed\n"); return -1; } - if (capabilty & CDC_CD_R) + if (capability & CDC_CD_R) cd_cd_r = 1; - if (capabilty & CDC_CD_RW) + if (capability & CDC_CD_RW) cd_cd_rw = 1; - if (capabilty & CDC_DVD) + if (capability & CDC_DVD) cd_dvd_rom = 1; - if (capabilty & CDC_DVD_R) + if (capability & CDC_DVD_R) cd_dvd_r = 1; - if (capabilty & CDC_DVD_RAM) + if (capability & CDC_DVD_RAM) cd_dvd_ram = 1; - if (capabilty & CDC_MRW) + if (capability & CDC_MRW) cd_mrw = 1; - if (capabilty & CDC_MRW_W) + if (capability & CDC_MRW_W) cd_mrw_w = 1; return 0; } +static int cd_media_compat(struct udev *udev, int fd) +{ + if (ioctl(fd, CDROM_DRIVE_STATUS, CDSL_CURRENT) != CDS_DISC_OK) { + info(udev, "CDROM_DRIVE_STATUS != CDS_DISC_OK\n"); + return -1; + } + cd_media = 1; + return 0; +} + static int cd_inquiry(struct udev *udev, int fd) { struct scsi_cmd sc; unsigned char inq[128]; int err; + scsi_cmd_init(udev, &sc, inq, sizeof(inq)); scsi_cmd_set(udev, &sc, 0, 0x12); scsi_cmd_set(udev, &sc, 4, 36); scsi_cmd_set(udev, &sc, 5, 0); err = scsi_cmd_run(udev, &sc, fd, inq, 36); - if ((err < 0)) { + if ((err != 0)) { info_scsi_cmd_err(udev, "INQUIRY", err); return -1; } @@ -219,108 +259,144 @@ static int cd_inquiry(struct udev *udev, int fd) { return 0; } -static int cd_profiles(struct udev *udev, int fd) +static int feature_profiles(struct udev *udev, const unsigned char *profiles, size_t size) { - struct scsi_cmd sc; - unsigned char header[8]; - unsigned char profiles[512]; - unsigned int cur_profile; - unsigned int len; unsigned int i; - int err; - scsi_cmd_set(udev, &sc, 0, 0x46); - scsi_cmd_set(udev, &sc, 1, 0); - scsi_cmd_set(udev, &sc, 8, sizeof(header)); - scsi_cmd_set(udev, &sc, 9, 0); - err = scsi_cmd_run(udev, &sc, fd, header, sizeof(header)); - if ((err < 0)) { - info_scsi_cmd_err(udev, "GET CONFIGURATION", err); - return -1; - } - - len = 4 + (header[0] << 24 | header[1] << 16 | header[2] << 8 | header[3]); - info(udev, "GET CONFIGURATION: number of profiles %i\n", len); - if (len > sizeof(profiles)) { - info(udev, "invalid number of profiles\n"); - return -1; - } - - scsi_cmd_set(udev, &sc, 0, 0x46); - scsi_cmd_set(udev, &sc, 1, 1); - scsi_cmd_set(udev, &sc, 6, len >> 16); - scsi_cmd_set(udev, &sc, 7, len >> 8); - scsi_cmd_set(udev, &sc, 8, len); - scsi_cmd_set(udev, &sc, 9, 0); - err = scsi_cmd_run(udev, &sc, fd, profiles, len); - if ((err < 0)) { - info_scsi_cmd_err(udev, "GET CONFIGURATION", err); - return -1; - } - - /* device profiles */ - for (i = 12; i < profiles[11]; i += 4) { - unsigned int profile = (profiles[i] << 8 | profiles[i + 1]); - if (profile == 0) - continue; - info(udev, "profile 0x%02x\n", profile); + for (i = 0; i+4 <= size; i += 4) { + int profile; + profile = profiles[i] << 8 | profiles[i+1]; switch (profile) { case 0x03: case 0x04: case 0x05: + info(udev, "profile 0x%02x mo\n", profile); cd_mo = 1; - break; + break; + case 0x08: + info(udev, "profile 0x%02x cd_rom\n", profile); + cd_cd_rom = 1; + break; + case 0x09: + info(udev, "profile 0x%02x cd_r\n", profile); + cd_cd_r = 1; + break; + case 0x0A: + info(udev, "profile 0x%02x cd_rw\n", profile); + cd_cd_rw = 1; + break; case 0x10: + info(udev, "profile 0x%02x dvd_rom\n", profile); cd_dvd_rom = 1; break; case 0x12: + info(udev, "profile 0x%02x dvd_ram\n", profile); cd_dvd_ram = 1; break; case 0x13: case 0x14: + info(udev, "profile 0x%02x dvd_rw\n", profile); cd_dvd_rw = 1; break; case 0x1B: + info(udev, "profile 0x%02x dvd_plus_r\n", profile); cd_dvd_plus_r = 1; break; case 0x1A: + info(udev, "profile 0x%02x dvd_plus_rw\n", profile); cd_dvd_plus_rw = 1; break; case 0x2A: + info(udev, "profile 0x%02x dvd_plus_rw_dl\n", profile); cd_dvd_plus_rw_dl = 1; break; case 0x2B: + info(udev, "profile 0x%02x dvd_plus_r_dl\n", profile); cd_dvd_plus_r_dl = 1; break; case 0x40: cd_bd = 1; + info(udev, "profile 0x%02x bd\n", profile); break; case 0x41: case 0x42: cd_bd_r = 1; + info(udev, "profile 0x%02x bd_r\n", profile); break; case 0x43: cd_bd_re = 1; + info(udev, "profile 0x%02x bd_re\n", profile); break; case 0x50: cd_hddvd = 1; + info(udev, "profile 0x%02x hddvd\n", profile); break; case 0x51: cd_hddvd_r = 1; + info(udev, "profile 0x%02x hddvd_r\n", profile); break; case 0x52: cd_hddvd_rw = 1; + info(udev, "profile 0x%02x hddvd_rw\n", profile); + break; + default: + info(udev, "profile 0x%02x \n", profile); + break; + } + } + return 0; +} + +static int cd_profiles(struct udev *udev, int fd) +{ + struct scsi_cmd sc; + unsigned char features[65530]; + unsigned int cur_profile = 0; + unsigned int len; + unsigned int i; + int err; + + scsi_cmd_init(udev, &sc, features, sizeof(features)); + scsi_cmd_set(udev, &sc, 0, 0x46); + scsi_cmd_set(udev, &sc, 7, (sizeof(features) >> 8) & 0xff); + scsi_cmd_set(udev, &sc, 8, sizeof(features) & 0xff); + scsi_cmd_set(udev, &sc, 9, 0); + err = scsi_cmd_run(udev, &sc, fd, features, sizeof(features)); + if ((err != 0)) { + info_scsi_cmd_err(udev, "GET CONFIGURATION", err); + return -1; + } + + len = features[0] << 24 | features[1] << 16 | features[2] << 8 | features[3]; + info(udev, "GET CONFIGURATION: size of features buffer 0x%04x\n", len); + + if (len > sizeof(features)) { + info(udev, "can not get features in a single query, truncating\n"); + len = sizeof(features); + } + + /* device features */ + for (i = 8; i+4 < len; i += (4 + features[i+3])) { + unsigned int feature; + + feature = features[i] << 8 | features[i+1]; + + switch (feature) { + case 0x00: + info(udev, "GET CONFIGURATION: feature 'profiles', with %i entries\n", features[i+3] / 4); + feature_profiles(udev, &features[i]+4, features[i+3]); break; default: + info(udev, "GET CONFIGURATION: feature 0x%04x , with 0x%02x bytes\n", feature, features[i+3]); break; } } - /* current media profile */ - cur_profile = header[6] << 8 | header[7]; - info(udev, "current profile 0x%02x\n", cur_profile); - if (cur_profile == 0) { + cur_profile = features[6] << 8 | features[7]; + if (cur_profile > 0) { + info(udev, "current profile 0x%02x\n", cur_profile); + } else { info(udev, "no current profile, assuming no media\n"); return -1; } @@ -329,62 +405,99 @@ static int cd_profiles(struct udev *udev, int fd) case 0x03: case 0x04: case 0x05: + info(udev, "profile 0x%02x \n", cur_profile); + cd_media = 1; cd_media_mo = 1; break; case 0x08: + info(udev, "profile 0x%02x media_cd_rom\n", cur_profile); + cd_media = 1; cd_media_cd_rom = 1; break; case 0x09: + info(udev, "profile 0x%02x media_cd_r\n", cur_profile); + cd_media = 1; cd_media_cd_r = 1; break; case 0x0a: + info(udev, "profile 0x%02x media_cd_rw\n", cur_profile); + cd_media = 1; cd_media_cd_rw = 1; break; case 0x10: + info(udev, "profile 0x%02x media_dvd_ro\n", cur_profile); + cd_media = 1; cd_media_dvd_rom = 1; break; case 0x11: + info(udev, "profile 0x%02x media_dvd_r\n", cur_profile); + cd_media = 1; cd_media_dvd_r = 1; break; case 0x12: + info(udev, "profile 0x%02x media_dvd_ram\n", cur_profile); + cd_media = 1; cd_media_dvd_ram = 1; break; case 0x13: case 0x14: + info(udev, "profile 0x%02x media_dvd_rw\n", cur_profile); + cd_media = 1; cd_media_dvd_rw = 1; break; case 0x1B: + info(udev, "profile 0x%02x media_dvd_plus_r\n", cur_profile); + cd_media = 1; cd_media_dvd_plus_r = 1; break; case 0x1A: + info(udev, "profile 0x%02x media_dvd_plus_rw\n", cur_profile); + cd_media = 1; cd_media_dvd_plus_rw = 1; break; case 0x2A: + info(udev, "profile 0x%02x media_dvd_plus_rw_dl\n", cur_profile); + cd_media = 1; cd_media_dvd_plus_rw_dl = 1; break; case 0x2B: + info(udev, "profile 0x%02x media_dvd_plus_r_dl\n", cur_profile); + cd_media = 1; cd_media_dvd_plus_r_dl = 1; break; case 0x40: + info(udev, "profile 0x%02x media_bd\n", cur_profile); + cd_media = 1; cd_media_bd = 1; break; case 0x41: case 0x42: + info(udev, "profile 0x%02x media_bd_r\n", cur_profile); + cd_media = 1; cd_media_bd_r = 1; break; case 0x43: + info(udev, "profile 0x%02x media_bd_re\n", cur_profile); + cd_media = 1; cd_media_bd_re = 1; break; case 0x50: + info(udev, "profile 0x%02x media_hddvd\n", cur_profile); + cd_media = 1; cd_media_hddvd = 1; break; case 0x51: + info(udev, "profile 0x%02x media_hddvd_r\n", cur_profile); + cd_media = 1; cd_media_hddvd_r = 1; break; case 0x52: + info(udev, "profile 0x%02x media_hddvd_rw\n", cur_profile); + cd_media = 1; cd_media_hddvd_rw = 1; break; default: + info(udev, "profile 0x%02x \n", cur_profile); break; } return 0; @@ -402,19 +515,23 @@ static int cd_media_info(struct udev *udev, int fd) }; int err; + scsi_cmd_init(udev, &sc, header, sizeof(header)); scsi_cmd_set(udev, &sc, 0, 0x51); - scsi_cmd_set(udev, &sc, 8, sizeof(header)); + scsi_cmd_set(udev, &sc, 8, sizeof(header) & 0xff); scsi_cmd_set(udev, &sc, 9, 0); err = scsi_cmd_run(udev, &sc, fd, header, sizeof(header)); - if ((err < 0)) { + if ((err != 0)) { info_scsi_cmd_err(udev, "READ DISC INFORMATION", err); return -1; }; + cd_media = 1; info(udev, "disk type %02x\n", header[8]); - if ((header[2] & 3) < 4) + /* exclude plain CDROM, some fake cdroms return 0 for "blank" media here */ + if (!cd_media_cd_rom) cd_media_state = media_status[header[2] & 3]; + if ((header[2] & 3) != 2) cd_media_session_next = header[10] << 8 | header[5]; cd_media_session_count = header[9] << 8 | header[4]; @@ -432,12 +549,13 @@ static int cd_media_toc(struct udev *udev, int fd) unsigned char *p; int err; + scsi_cmd_init(udev, &sc, header, sizeof(header)); scsi_cmd_set(udev, &sc, 0, 0x43); scsi_cmd_set(udev, &sc, 6, 1); - scsi_cmd_set(udev, &sc, 8, sizeof(header)); + scsi_cmd_set(udev, &sc, 8, sizeof(header) & 0xff); scsi_cmd_set(udev, &sc, 9, 0); err = scsi_cmd_run(udev, &sc, fd, header, sizeof(header)); - if ((err < 0)) { + if ((err != 0)) { info_scsi_cmd_err(udev, "READ TOC", err); return -1; } @@ -453,13 +571,14 @@ static int cd_media_toc(struct udev *udev, int fd) if (len < 8) return 0; + scsi_cmd_init(udev, &sc, toc, sizeof(toc)); scsi_cmd_set(udev, &sc, 0, 0x43); scsi_cmd_set(udev, &sc, 6, header[2]); /* First Track/Session Number */ - scsi_cmd_set(udev, &sc, 7, len >> 8); - scsi_cmd_set(udev, &sc, 8, len); + scsi_cmd_set(udev, &sc, 7, (len >> 8) & 0xff); + scsi_cmd_set(udev, &sc, 8, len & 0xff); scsi_cmd_set(udev, &sc, 9, 0); err = scsi_cmd_run(udev, &sc, fd, toc, len); - if ((err < 0)) { + if ((err != 0)) { info_scsi_cmd_err(udev, "READ TOC (tracks)", err); return -1; } @@ -480,12 +599,13 @@ static int cd_media_toc(struct udev *udev, int fd) cd_media_track_count_audio++; } + scsi_cmd_init(udev, &sc, header, sizeof(header)); scsi_cmd_set(udev, &sc, 0, 0x43); scsi_cmd_set(udev, &sc, 2, 1); /* Session Info */ - scsi_cmd_set(udev, &sc, 8, 12); + scsi_cmd_set(udev, &sc, 8, sizeof(header)); scsi_cmd_set(udev, &sc, 9, 0); err = scsi_cmd_run(udev, &sc, fd, header, sizeof(header)); - if ((err < 0)) { + if ((err != 0)) { info_scsi_cmd_err(udev, "READ TOC (multi session)", err); return -1; } @@ -507,13 +627,14 @@ int main(int argc, char *argv[]) const char *node = NULL; int export = 0; int fd = -1; + int cnt; int rc = 0; udev = udev_new(); if (udev == NULL) goto exit; - logging_init("cdrom_id"); + udev_log_init("cdrom_id"); udev_set_log_fn(udev, log_fn); while (1) { @@ -552,9 +673,20 @@ int main(int argc, char *argv[]) goto exit; } - fd = open(node, O_RDONLY | O_NONBLOCK); + srand((unsigned int)getpid()); + for (cnt = 20; cnt > 0; cnt--) { + struct timespec duration; + + fd = open(node, O_RDONLY|O_NONBLOCK|(is_mounted(node) ? 0 : O_EXCL)); + if (fd >= 0 || errno != EBUSY) + break; + duration.tv_sec = 0; + duration.tv_nsec = (100 * 1000 * 1000) + (rand() % 100 * 1000 * 1000); + nanosleep(&duration, NULL); + } if (fd < 0) { info(udev, "unable to open '%s'\n", node); + fprintf(stderr, "unable to open '%s'\n", node); rc = 1; goto exit; } @@ -566,24 +698,26 @@ int main(int argc, char *argv[]) goto exit; } - /* check drive */ - if (cd_inquiry(udev, fd) < 0) { - rc = 2; - goto exit; - } + /* check for media - don't bail if there's no media as we still need to + * to read profiles */ + cd_media_compat(udev, fd); - /* read drive and possibly current profile */ - if (cd_profiles(udev, fd) < 0) + /* check if drive talks MMC */ + if (cd_inquiry(udev, fd) < 0) goto print; - /* get session/track info */ - if (cd_media_toc(udev, fd) < 0) + /* read drive and possibly current profile */ + if (cd_profiles(udev, fd) < 0) goto print; /* get writable media state */ if (cd_media_info(udev, fd) < 0) goto print; + /* get session/track info */ + if (cd_media_toc(udev, fd) < 0) + goto print; + print: printf("ID_CDROM=1\n"); if (cd_cd_rom) @@ -627,6 +761,8 @@ print: if (cd_mrw_w) printf("ID_CDROM_MRW_W=1\n"); + if (cd_media) + printf("ID_CDROM_MEDIA=1\n"); if (cd_media_mo) printf("ID_CDROM_MEDIA_MO=1\n"); if (cd_media_mrw) @@ -674,19 +810,19 @@ print: printf("ID_CDROM_MEDIA_SESSION_NEXT=%d\n", cd_media_session_next); if (cd_media_session_count > 0) printf("ID_CDROM_MEDIA_SESSION_COUNT=%d\n", cd_media_session_count); + if (cd_media_session_count > 1 && cd_media_session_last_offset > 0) + printf("ID_CDROM_MEDIA_SESSION_LAST_OFFSET=%llu\n", cd_media_session_last_offset); if (cd_media_track_count > 0) printf("ID_CDROM_MEDIA_TRACK_COUNT=%d\n", cd_media_track_count); if (cd_media_track_count_audio > 0) printf("ID_CDROM_MEDIA_TRACK_COUNT_AUDIO=%d\n", cd_media_track_count_audio); if (cd_media_track_count_data > 0) printf("ID_CDROM_MEDIA_TRACK_COUNT_DATA=%d\n", cd_media_track_count_data); - if (cd_media_session_last_offset > 0) - printf("ID_CDROM_MEDIA_SESSION_LAST_OFFSET=%llu\n", cd_media_session_last_offset); exit: if (fd >= 0) close(fd); udev_unref(udev); - logging_close(); + udev_log_close(); return rc; }