chiark / gitweb /
cdrom_id: add and use ID_CDROM_MEDIA to decide if we run vol_id
[elogind.git] / extras / cdrom_id / cdrom_id.c
index 627ae0dee4f7a4897a93abbb3beb41912e4b42f2..371d6a2dbd197898c69d381d2cee4fe5267662b5 100644 (file)
 
 #include "../../udev/udev.h"
 
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
-#endif
-
 static int debug;
 
 static void log_fn(struct udev *udev, int priority,
@@ -80,6 +76,7 @@ static unsigned int cd_mrw;
 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;
@@ -329,6 +326,8 @@ static int cd_profiles(struct udev *udev, int fd)
                return -1;
        }
 
+       cd_media = 1;
+
        switch (cur_profile) {
        case 0x03:
        case 0x04:
@@ -503,9 +502,9 @@ int main(int argc, char *argv[])
 {
        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;
@@ -571,10 +570,8 @@ int main(int argc, char *argv[])
        }
 
        /* check drive */
-       if (cd_inquiry(udev, fd) < 0) {
-               rc = 2;
-               goto exit;
-       }
+       if (cd_inquiry(udev, fd) < 0)
+               goto print;
 
        /* read drive and possibly current profile */
        if (cd_profiles(udev, fd) < 0)
@@ -631,6 +628,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)