chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix spelling
[elogind.git]
/
extras
/
cdrom_id
/
cdrom_id.c
diff --git
a/extras/cdrom_id/cdrom_id.c
b/extras/cdrom_id/cdrom_id.c
index 627ae0dee4f7a4897a93abbb3beb41912e4b42f2..6ea763b415b3fdfca21d0663b162141beafa566c 100644
(file)
--- a/
extras/cdrom_id/cdrom_id.c
+++ b/
extras/cdrom_id/cdrom_id.c
@@
-37,11
+37,8
@@
#include <sys/ioctl.h>
#include <linux/cdrom.h>
#include <sys/ioctl.h>
#include <linux/cdrom.h>
-#include "../../udev/udev.h"
-
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
-#endif
+#include "libudev.h"
+#include "libudev-private.h"
static int debug;
static int debug;
@@
-80,6
+77,7
@@
static unsigned int cd_mrw;
static unsigned int cd_mrw_w;
/* media info */
static unsigned int cd_mrw_w;
/* media info */
+static unsigned int cd_media;
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_cd_rom;
static unsigned int cd_media_cd_r;
static unsigned int cd_media_cd_rw;
@@
-175,31
+173,41
@@
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)
{
static int cd_capability_compat(struct udev *udev, int fd)
{
- int capabilty;
+ int capabil
i
ty;
- capabilty = ioctl(fd, CDROM_GET_CAPABILITY, NULL);
- if (capabilty < 0) {
+ capabil
i
ty = ioctl(fd, CDROM_GET_CAPABILITY, NULL);
+ if (capabil
i
ty < 0) {
info(udev, "CDROM_GET_CAPABILITY failed\n");
return -1;
}
info(udev, "CDROM_GET_CAPABILITY failed\n");
return -1;
}
- if (capabilty & CDC_CD_R)
+ if (capabil
i
ty & CDC_CD_R)
cd_cd_r = 1;
cd_cd_r = 1;
- if (capabilty & CDC_CD_RW)
+ if (capabil
i
ty & CDC_CD_RW)
cd_cd_rw = 1;
cd_cd_rw = 1;
- if (capabilty & CDC_DVD)
+ if (capabil
i
ty & CDC_DVD)
cd_dvd_rom = 1;
cd_dvd_rom = 1;
- if (capabilty & CDC_DVD_R)
+ if (capabil
i
ty & CDC_DVD_R)
cd_dvd_r = 1;
cd_dvd_r = 1;
- if (capabilty & CDC_DVD_RAM)
+ if (capabil
i
ty & CDC_DVD_RAM)
cd_dvd_ram = 1;
cd_dvd_ram = 1;
- if (capabilty & CDC_MRW)
+ if (capabil
i
ty & CDC_MRW)
cd_mrw = 1;
cd_mrw = 1;
- if (capabilty & CDC_MRW_W)
+ if (capabil
i
ty & CDC_MRW_W)
cd_mrw_w = 1;
return 0;
}
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];
static int cd_inquiry(struct udev *udev, int fd) {
struct scsi_cmd sc;
unsigned char inq[128];
@@
-329,6
+337,8
@@
static int cd_profiles(struct udev *udev, int fd)
return -1;
}
return -1;
}
+ cd_media = 1;
+
switch (cur_profile) {
case 0x03:
case 0x04:
switch (cur_profile) {
case 0x03:
case 0x04:
@@
-417,8
+427,10
@@
static int cd_media_info(struct udev *udev, int fd)
info(udev, "disk type %02x\n", header[8]);
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 && (header[2] & 3) < 4)
cd_media_state = media_status[header[2] & 3];
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];
if ((header[2] & 3) != 2)
cd_media_session_next = header[10] << 8 | header[5];
cd_media_session_count = header[9] << 8 | header[4];
@@
-503,9
+515,9
@@
int main(int argc, char *argv[])
{
struct udev *udev;
static const struct option options[] = {
{
struct udev *udev;
static const struct option options[] = {
- { "export",
0
, NULL, 'x' },
- { "debug",
0
, NULL, 'd' },
- { "help",
0
, NULL, 'h' },
+ { "export",
no_argument
, NULL, 'x' },
+ { "debug",
no_argument
, NULL, 'd' },
+ { "help",
no_argument
, NULL, 'h' },
{}
};
const char *node = NULL;
{}
};
const char *node = NULL;
@@
-517,7
+529,7
@@
int main(int argc, char *argv[])
if (udev == NULL)
goto exit;
if (udev == NULL)
goto exit;
-
loggin
g_init("cdrom_id");
+
udev_lo
g_init("cdrom_id");
udev_set_log_fn(udev, log_fn);
while (1) {
udev_set_log_fn(udev, log_fn);
while (1) {
@@
-559,6
+571,7
@@
int main(int argc, char *argv[])
fd = open(node, O_RDONLY | O_NONBLOCK);
if (fd < 0) {
info(udev, "unable to open '%s'\n", node);
fd = open(node, O_RDONLY | O_NONBLOCK);
if (fd < 0) {
info(udev, "unable to open '%s'\n", node);
+ fprintf(stderr, "unable to open '%s'\n", node);
rc = 1;
goto exit;
}
rc = 1;
goto exit;
}
@@
-570,11
+583,13
@@
int main(int argc, char *argv[])
goto exit;
}
goto exit;
}
- /* check drive */
- if (cd_inquiry(udev, fd) < 0) {
- rc = 2;
- goto exit;
- }
+ /* check for media */
+ if (cd_media_compat(udev, fd) < 0)
+ goto print;
+
+ /* check if drive talks MMC */
+ if (cd_inquiry(udev, fd) < 0)
+ goto print;
/* read drive and possibly current profile */
if (cd_profiles(udev, fd) < 0)
/* read drive and possibly current profile */
if (cd_profiles(udev, fd) < 0)
@@
-631,6
+646,8
@@
print:
if (cd_mrw_w)
printf("ID_CDROM_MRW_W=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)
if (cd_media_mo)
printf("ID_CDROM_MEDIA_MO=1\n");
if (cd_media_mrw)
@@
-690,7
+707,7
@@
exit:
if (fd >= 0)
close(fd);
udev_unref(udev);
if (fd >= 0)
close(fd);
udev_unref(udev);
-
loggin
g_close();
+
udev_lo
g_close();
return rc;
}
return rc;
}