chiark / gitweb /
[PATCH] udev_volume_id: fix -d option
[elogind.git] / extras / volume_id / udev_volume_id.c
index e88445054b22eecc3d2b194ff154dd383faa3752..7b6985680414837457996c4a298be3a930487c43 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <string.h>
 #include <ctype.h>
-#include <linux/fs.h>
 #include <sys/ioctl.h>
 
 #include "../../libsysfs/sysfs/libsysfs.h"
-#include "../../udev_lib.h"
+#include "../../udev_utils.h"
 #include "../../logging.h"
 #include "volume_id.h"
 #include "dasdlabel.h"
 
+#define BLKGETSIZE64 _IOR(0x12,114,size_t)
+
 #ifdef LOG
-unsigned char logname[LOGNAME_SIZE];
 void log_message(int level, const char *format, ...)
 {
        va_list args;
@@ -73,16 +74,6 @@ static struct volume_id *open_classdev(struct sysfs_class_device *class_dev)
        return vid;
 }
 
-static unsigned long long get_size(struct volume_id *vid)
-{
-       unsigned long long size;
-
-       if (ioctl(vid->fd, BLKGETSIZE64, &size) != 0)
-               size = 0;
-
-       return size;
-}
-
 static char *usage_id_name(enum volume_id_usage usage)
 {
        switch(usage) {
@@ -112,7 +103,7 @@ int main(int argc, char *argv[])
                            "       -d disk label from main device\n"
                            "\n";
        static const char short_options[] = "htlud";
-       char sysfs_path[SYSFS_PATH_MAX];
+       char sysfs_mnt_path[SYSFS_PATH_MAX];
        char dev_path[SYSFS_PATH_MAX];
        struct sysfs_class_device *class_dev = NULL;
        struct sysfs_class_device *class_dev_parent = NULL;
@@ -126,6 +117,8 @@ int main(int argc, char *argv[])
        unsigned long long size;
        int rc = 1;
 
+       logging_init("udev_volume_id");
+
        while (1) {
                int option;
 
@@ -160,12 +153,12 @@ int main(int argc, char *argv[])
                goto exit;
        }
 
-       if (sysfs_get_mnt_path(sysfs_path, SYSFS_PATH_MAX) != 0) {
+       if (sysfs_get_mnt_path(sysfs_mnt_path, SYSFS_PATH_MAX) != 0) {
                printf("error getting sysfs mount path\n");
                goto exit;
        }
 
-       strfieldcpy(dev_path, sysfs_path);
+       strfieldcpy(dev_path, sysfs_mnt_path);
        strfieldcat(dev_path, devpath);
 
        class_dev = sysfs_open_class_device_path(dev_path);
@@ -181,7 +174,8 @@ int main(int argc, char *argv[])
                if (vid == NULL)
                        goto exit;
 
-               size = get_size(vid);
+               if (ioctl(vid->fd, BLKGETSIZE64, &size) != 0)
+                       size = 0;
 
                if (volume_id_probe(vid, VOLUME_ID_ALL, 0, size) == 0)
                        goto print;
@@ -192,7 +186,7 @@ int main(int argc, char *argv[])
                if (class_dev_parent != NULL)
                        vid = open_classdev(class_dev_parent);
                else
-                       vid = open_classdev(class_dev_parent);
+                       vid = open_classdev(class_dev);
                if (vid == NULL)
                        goto exit;
 
@@ -268,5 +262,7 @@ exit:
        if (vid != NULL)
                volume_id_close(vid);
 
+       logging_close();
+
        exit(rc);
 }