#include <sys/time.h>
#include <sys/ioctl.h>
#include <linux/cdrom.h>
-#include "../../udev.h"
+
+#include "../../udev/udev.h"
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
if (debug) {
fprintf(stderr, "[%d] ", (int) getpid());
vfprintf(stderr, format, args);
- fprintf(stderr, "\n");
} else
vsyslog(priority, format, args);
va_end(args);
static unsigned int cd_media_mrw_w;
static const char *cd_media_state;
-static unsigned int cd_media_has_audio;
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;
#define ERRCODE(s) ((((s)[2] & 0x0F) << 16) | ((s)[12] << 8) | ((s)[13]))
static void info_scsi_cmd_err(const char *cmd, int err)
{
if (err == -1) {
- info("%s failed", cmd);
+ info("%s failed\n", cmd);
return;
}
- info("%s failed with SK=%Xh/ASC=%02Xh/ACQ=%02Xh", cmd, SK(err), ASC(err), ASCQ(err));
+ info("%s failed with SK=%Xh/ASC=%02Xh/ACQ=%02Xh\n", cmd, SK(err), ASC(err), ASCQ(err));
}
struct scsi_cmd {
capabilty = ioctl(fd, CDROM_GET_CAPABILITY, NULL);
if (capabilty < 0) {
- info("CDROM_GET_CAPABILITY failed");
+ info("CDROM_GET_CAPABILITY failed\n");
return -1;
}
}
if ((inq[0] & 0x1F) != 5) {
- info("not an MMC unit");
+ info("not an MMC unit\n");
return -1;
}
- info("INQUIRY: [%.8s][%.16s][%.4s]", inq + 8, inq + 16, inq + 32);
+ info("INQUIRY: [%.8s][%.16s][%.4s]\n", inq + 8, inq + 16, inq + 32);
return 0;
}
}
len = 4 + (header[0] << 24 | header[1] << 16 | header[2] << 8 | header[3]);
- info("GET CONFIGURATION: number of profiles %i", len);
+ info("GET CONFIGURATION: number of profiles %i\n", len);
if (len > sizeof(profiles)) {
- info("invalid number of profiles");
+ info("invalid number of profiles\n");
return -1;
}
unsigned int profile = (profiles[i] << 8 | profiles[i + 1]);
if (profile == 0)
continue;
- info("profile 0x%02x", profile);
+ info("profile 0x%02x\n", profile);
switch (profile) {
case 0x03:
/* current media profile */
cur_profile = header[6] << 8 | header[7];
- info("current profile 0x%02x", cur_profile);
+ info("current profile 0x%02x\n", cur_profile);
if (cur_profile == 0) {
- info("no current profile, assuming no media");
+ info("no current profile, assuming no media\n");
return -1;
}
return -1;
};
- info("disk type %02x", header[8]);
+ info("disk type %02x\n", header[8]);
if ((header[2] & 3) < 4)
cd_media_state = media_status[header[2] & 3];
}
len = (header[0] << 8 | header[1]) + 2;
- info("READ TOC: len: %d", len);
+ info("READ TOC: len: %d\n", len);
if (len > sizeof(toc))
return -1;
+ if (len < 2)
+ return -1;
- /* check if we have a data track */
- info("ctl %02x (0x04 is data/audio)", header[5]);
- cd_media_has_audio = (header[5] & 0x04) == 0;
+ /* empty media has no tracks */
+ if (len < 8)
+ return 0;
scsi_cmd_set(&sc, 0, 0x43);
scsi_cmd_set(&sc, 6, header[2]); /* First Track/Session Number */
for (p = toc+4, i = 4; i < len-8; i += 8, p += 8) {
unsigned int block;
+ unsigned int is_data_track;
+
+ is_data_track = (p[1] & 0x04) != 0;
block = p[4] << 24 | p[5] << 16 | p[6] << 8 | p[7];
- info("track %u starts at block %u", p[2], block);
+ info("track=%u info=0x%x(%s) start_block=%u\n",
+ p[2], p[1] & 0x0f, is_data_track ? "data":"audio", block);
+
+ if (is_data_track)
+ cd_media_track_count_data++;
+ else
+ cd_media_track_count_audio++;
}
scsi_cmd_set(&sc, 0, 0x43);
return -1;
}
len = header[4+4] << 24 | header[4+5] << 16 | header[4+6] << 8 | header[4+7];
- info("last track %u starts at block %u", header[4+2], len);
+ info("last track %u starts at block %u\n", header[4+2], len);
cd_media_session_last_offset = (unsigned long long int)len * 2048;
return 0;
}
break;
case 'h':
printf("Usage: cdrom_id [options] <device>\n"
- " --export export key/value pairs\n"
- " --help\n\n");
+ " --export export key/value pairs\n"
+ " --debug debug to stderr\n"
+ " --help print this help text\n\n");
goto exit;
default:
rc = 1;
node = argv[optind];
if (!node) {
- err("no device");
+ err("no device\n");
fprintf(stderr, "no device\n");
rc = 1;
goto exit;
fd = open(node, O_RDONLY | O_NONBLOCK);
if (fd < 0) {
- info("unable to open '%s'", node);
+ info("unable to open '%s'\n", node);
rc = 1;
goto exit;
}
- info("probing: '%s'", node);
+ info("probing: '%s'\n", node);
/* same data as original cdrom_id */
if (cd_capability_compat(fd) < 0) {
if (cd_media_state != NULL)
printf("ID_CDROM_MEDIA_STATE=%s\n", cd_media_state);
- if (cd_media_has_audio)
- printf("ID_CDROM_MEDIA_HAS_AUDIO=1\n");
if (cd_media_session_next > 0)
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_track_count > 0)
printf("ID_CDROM_MEDIA_TRACK_COUNT=%d\n", cd_media_track_count);
- if (cd_media_session_last_offset)
+ 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)