X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=extras%2Fvolume_id%2Fudev_volume_id.c;h=9e8c3bfb117b16e7d10ad915a09658f76dee206f;hb=c2fe814e305aaede3b03cfa2e86f1a317e1a66c4;hp=e88445054b22eecc3d2b194ff154dd383faa3752;hpb=c506c4087efe567b3cb382bd228644cde3453b04;p=elogind.git diff --git a/extras/volume_id/udev_volume_id.c b/extras/volume_id/udev_volume_id.c index e88445054..9e8c3bfb1 100644 --- a/extras/volume_id/udev_volume_id.c +++ b/extras/volume_id/udev_volume_id.c @@ -24,16 +24,18 @@ #include #include #include +#include #include -#include #include #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, ...) @@ -73,16 +75,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 +104,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 +118,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 +154,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 +175,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; @@ -268,5 +263,7 @@ exit: if (vid != NULL) volume_id_close(vid); + logging_close(); + exit(rc); }