cdrom_id.c revision c1b7f60deac0bc0e87a139648d57085512fd9e62
/*
* cdrom_id - optical drive and media information prober
*
* Copyright (C) 2008-2010 Kay Sievers <kay.sievers@vrfy.org>
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _GNU_SOURCE
#define _GNU_SOURCE 1
#endif
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <limits.h>
#include <fcntl.h>
#include <errno.h>
#include <getopt.h>
#include <time.h>
#include "libudev.h"
#include "libudev-private.h"
static int debug;
{
if (debug) {
} else {
}
}
/* device info */
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 = 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;
static int is_mounted(const char *device)
{
int mounted = 0;
return -ENODEV;
return -ENOSYS;
mounted = 1;
break;
}
}
return mounted;
}
{
if (err == -1) {
return;
}
}
struct scsi_cmd {
struct cdrom_generic_command cgc;
union {
struct request_sense s;
unsigned char u[18];
} _sense;
};
{
if (i == 0) {
}
}
#define CHECK_CONDITION 0x01
static int scsi_cmd_run(struct udev *udev, struct scsi_cmd *cmd, int fd, unsigned char *buf, size_t bufsize)
{
int ret = 0;
return -1;
ret = -1;
if (ret == 0)
ret = -1;
}
}
return ret;
}
{
int capability;
if (capability < 0) {
return -1;
}
if (capability & CDC_CD_R)
cd_cd_r = 1;
if (capability & CDC_CD_RW)
cd_cd_rw = 1;
if (capability & CDC_DVD)
cd_dvd_rom = 1;
if (capability & CDC_DVD_R)
cd_dvd_r = 1;
if (capability & CDC_DVD_RAM)
cd_dvd_ram = 1;
if (capability & CDC_MRW)
cd_mrw = 1;
if (capability & CDC_MRW_W)
cd_mrw_w = 1;
return 0;
}
{
return -1;
}
cd_media = 1;
return 0;
}
unsigned char inq[128];
int err;
if ((err < 0)) {
return -1;
}
return -1;
}
return 0;
}
{
unsigned char header[8];
unsigned char profiles[512];
unsigned int cur_profile;
unsigned int len;
unsigned int i;
int err;
if ((err < 0)) {
return -1;
}
return -1;
}
if ((err < 0)) {
return -1;
}
/* device profiles */
if (profile == 0)
continue;
switch (profile) {
case 0x03:
case 0x04:
case 0x05:
cd_mo = 1;
break;
case 0x10:
cd_dvd_rom = 1;
break;
case 0x12:
cd_dvd_ram = 1;
break;
case 0x13:
case 0x14:
cd_dvd_rw = 1;
break;
case 0x1B:
cd_dvd_plus_r = 1;
break;
case 0x1A:
cd_dvd_plus_rw = 1;
break;
case 0x2A:
cd_dvd_plus_rw_dl = 1;
break;
case 0x2B:
cd_dvd_plus_r_dl = 1;
break;
case 0x40:
cd_bd = 1;
break;
case 0x41:
case 0x42:
cd_bd_r = 1;
break;
case 0x43:
cd_bd_re = 1;
break;
case 0x50:
cd_hddvd = 1;
break;
case 0x51:
cd_hddvd_r = 1;
break;
case 0x52:
cd_hddvd_rw = 1;
break;
default:
break;
}
}
/* current media profile */
if (cur_profile == 0) {
return -1;
}
cd_media = 1;
switch (cur_profile) {
case 0x03:
case 0x04:
case 0x05:
cd_media_mo = 1;
break;
case 0x08:
cd_media_cd_rom = 1;
break;
case 0x09:
cd_media_cd_r = 1;
break;
case 0x0a:
cd_media_cd_rw = 1;
break;
case 0x10:
cd_media_dvd_rom = 1;
break;
case 0x11:
cd_media_dvd_r = 1;
break;
case 0x12:
cd_media_dvd_ram = 1;
break;
case 0x13:
case 0x14:
cd_media_dvd_rw = 1;
break;
case 0x1B:
cd_media_dvd_plus_r = 1;
break;
case 0x1A:
cd_media_dvd_plus_rw = 1;
break;
case 0x2A:
break;
case 0x2B:
break;
case 0x40:
cd_media_bd = 1;
break;
case 0x41:
case 0x42:
cd_media_bd_r = 1;
break;
case 0x43:
cd_media_bd_re = 1;
break;
case 0x50:
cd_media_hddvd = 1;
break;
case 0x51:
cd_media_hddvd_r = 1;
break;
case 0x52:
cd_media_hddvd_rw = 1;
break;
default:
break;
}
return 0;
}
{
unsigned char header[32];
static const char *media_status[] = {
"blank",
"appendable",
"complete",
"other"
};
int err;
if ((err < 0)) {
return -1;
};
/* exclude plain CDROM, some fake cdroms return 0 for "blank" media here */
return 0;
}
{
unsigned char header[12];
unsigned char toc[2048];
unsigned int len, i;
unsigned char *p;
int err;
if ((err < 0)) {
return -1;
}
return -1;
if (len < 2)
return -1;
/* empty media has no tracks */
if (len < 8)
return 0;
if ((err < 0)) {
return -1;
}
unsigned int block;
unsigned int is_data_track;
if (is_data_track)
else
}
if ((err < 0)) {
return -1;
}
return 0;
}
{
{}
};
int export = 0;
int fd = -1;
int cnt;
int rc = 0;
goto exit;
udev_log_init("cdrom_id");
while (1) {
int option;
if (option == -1)
break;
switch (option) {
case 'd':
debug = 1;
break;
case 'x':
export = 1;
break;
case 'h':
printf("Usage: cdrom_id [options] <device>\n"
" --debug debug to stderr\n"
" --help print this help text\n\n");
goto exit;
default:
rc = 1;
goto exit;
}
}
if (!node) {
rc = 1;
goto exit;
}
break;
}
if (fd < 0) {
rc = 1;
goto exit;
}
/* same data as original cdrom_id */
rc = 1;
goto exit;
}
/* check for media - don't bail if there's no media as we still need to
* to read profiles */
/* check if drive talks MMC */
goto print;
/* read drive and possibly current profile */
goto print;
goto print;
/* get writable media state */
goto print;
printf("ID_CDROM=1\n");
if (cd_cd_rom)
printf("ID_CDROM_CD=1\n");
if (cd_cd_r)
printf("ID_CDROM_CD_R=1\n");
if (cd_cd_rw)
printf("ID_CDROM_CD_RW=1\n");
if (cd_dvd_rom)
printf("ID_CDROM_DVD=1\n");
if (cd_dvd_r)
printf("ID_CDROM_DVD_R=1\n");
if (cd_dvd_rw)
printf("ID_CDROM_DVD_RW=1\n");
if (cd_dvd_ram)
printf("ID_CDROM_DVD_RAM=1\n");
if (cd_dvd_plus_r)
printf("ID_CDROM_DVD_PLUS_R=1\n");
if (cd_dvd_plus_rw)
printf("ID_CDROM_DVD_PLUS_RW=1\n");
if (cd_dvd_plus_r_dl)
printf("ID_CDROM_DVD_PLUS_R_DL=1\n");
if (cd_dvd_plus_rw_dl)
printf("ID_CDROM_DVD_PLUS_RW_DL=1\n");
if (cd_bd)
printf("ID_CDROM_BD=1\n");
if (cd_bd_r)
printf("ID_CDROM_BD_R=1\n");
if (cd_bd_re)
printf("ID_CDROM_BD_RE=1\n");
if (cd_hddvd)
printf("ID_CDROM_HDDVD=1\n");
if (cd_hddvd_r)
printf("ID_CDROM_HDDVD_R=1\n");
if (cd_hddvd_rw)
printf("ID_CDROM_HDDVD_RW=1\n");
if (cd_mo)
printf("ID_CDROM_MO=1\n");
if (cd_mrw)
printf("ID_CDROM_MRW=1\n");
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)
printf("ID_CDROM_MEDIA_MRW=1\n");
if (cd_media_mrw_w)
printf("ID_CDROM_MEDIA_MRW_W=1\n");
if (cd_media_cd_rom)
printf("ID_CDROM_MEDIA_CD=1\n");
if (cd_media_cd_r)
printf("ID_CDROM_MEDIA_CD_R=1\n");
if (cd_media_cd_rw)
printf("ID_CDROM_MEDIA_CD_RW=1\n");
if (cd_media_dvd_rom)
printf("ID_CDROM_MEDIA_DVD=1\n");
if (cd_media_dvd_r)
printf("ID_CDROM_MEDIA_DVD_R=1\n");
if (cd_media_dvd_ram)
printf("ID_CDROM_MEDIA_DVD_RAM=1\n");
if (cd_media_dvd_rw)
printf("ID_CDROM_MEDIA_DVD_RW=1\n");
if (cd_media_dvd_plus_r)
printf("ID_CDROM_MEDIA_DVD_PLUS_R=1\n");
if (cd_media_dvd_plus_rw)
printf("ID_CDROM_MEDIA_DVD_PLUS_RW=1\n");
printf("ID_CDROM_MEDIA_DVD_PLUS_RW_DL=1\n");
printf("ID_CDROM_MEDIA_DVD_PLUS_R_DL=1\n");
if (cd_media_bd)
printf("ID_CDROM_MEDIA_BD=1\n");
if (cd_media_bd_r)
printf("ID_CDROM_MEDIA_BD_R=1\n");
if (cd_media_bd_re)
printf("ID_CDROM_MEDIA_BD_RE=1\n");
if (cd_media_hddvd)
printf("ID_CDROM_MEDIA_HDDVD=1\n");
if (cd_media_hddvd_r)
printf("ID_CDROM_MEDIA_HDDVD_R=1\n");
if (cd_media_hddvd_rw)
printf("ID_CDROM_MEDIA_HDDVD_RW=1\n");
if (cd_media_state != NULL)
if (cd_media_session_next > 0)
if (cd_media_session_count > 0)
if (cd_media_track_count > 0)
if (cd_media_track_count_audio > 0)
if (cd_media_track_count_data > 0)
if (cd_media_session_last_offset > 0)
exit:
if (fd >= 0)
return rc;
}