gpt-auto-generator: replace udev_device by sd_device

This commit is contained in:
Yu Watanabe 2018-08-22 13:55:45 +09:00
parent dcd265239b
commit 85624f018d

View file

@ -5,7 +5,7 @@
#include <sys/statfs.h> #include <sys/statfs.h>
#include <unistd.h> #include <unistd.h>
#include "libudev.h" #include "sd-device.h"
#include "sd-id128.h" #include "sd-id128.h"
#include "alloc-util.h" #include "alloc-util.h"
@ -30,7 +30,7 @@
#include "specifier.h" #include "specifier.h"
#include "stat-util.h" #include "stat-util.h"
#include "string-util.h" #include "string-util.h"
#include "udev-util.h" #include "strv.h"
#include "unit-name.h" #include "unit-name.h"
#include "util.h" #include "util.h"
#include "virt.h" #include "virt.h"
@ -446,41 +446,36 @@ static int add_esp(DissectedPartition *p) {
#endif #endif
static int open_parent(dev_t devnum, int *ret) { static int open_parent(dev_t devnum, int *ret) {
_cleanup_(udev_device_unrefp) struct udev_device *d = NULL; _cleanup_(sd_device_unrefp) sd_device *d = NULL;
_cleanup_(udev_unrefp) struct udev *udev = NULL;
const char *name, *devtype, *node; const char *name, *devtype, *node;
struct udev_device *parent; sd_device *parent;
dev_t pn; dev_t pn;
int fd; int fd, r;
assert(ret); assert(ret);
udev = udev_new(); r = sd_device_new_from_devnum(&d, 'b', devnum);
if (!udev) if (r < 0)
return log_oom(); return log_debug_errno(r, "Failed to open device: %m");
d = udev_device_new_from_devnum(udev, 'b', devnum); if (sd_device_get_devname(d, &name) < 0) {
if (!d) r = sd_device_get_syspath(d, &name);
return log_oom(); if (r < 0) {
log_debug_errno(r, "Device %u:%u does not have a name, ignoring: %m", major(devnum), minor(devnum));
name = udev_device_get_devnode(d); goto not_found;
if (!name) }
name = udev_device_get_syspath(d);
if (!name) {
log_debug("Device %u:%u does not have a name, ignoring.", major(devnum), minor(devnum));
goto not_found;
} }
parent = udev_device_get_parent(d); r = sd_device_get_parent(d, &parent);
if (!parent) { if (r < 0) {
log_debug("%s: not a partitioned device, ignoring.", name); log_debug_errno(r, "%s: not a partitioned device, ignoring: %m", name);
goto not_found; goto not_found;
} }
/* Does it have a devtype? */ /* Does it have a devtype? */
devtype = udev_device_get_devtype(parent); r = sd_device_get_devtype(parent, &devtype);
if (!devtype) { if (r < 0) {
log_debug("%s: parent doesn't have a device type, ignoring.", name); log_debug_errno(r, "%s: parent doesn't have a device type, ignoring: %m", name);
goto not_found; goto not_found;
} }
@ -491,17 +486,17 @@ static int open_parent(dev_t devnum, int *ret) {
} }
/* Does it have a device node? */ /* Does it have a device node? */
node = udev_device_get_devnode(parent); r = sd_device_get_devname(parent, &node);
if (!node) { if (r < 0) {
log_debug("%s: parent device does not have device node, ignoring.", name); log_debug_errno(r, "%s: parent device does not have device node, ignoring: %m", name);
goto not_found; goto not_found;
} }
log_debug("%s: root device %s.", name, node); log_debug("%s: root device %s.", name, node);
pn = udev_device_get_devnum(parent); r = sd_device_get_devnum(parent, &pn);
if (major(pn) == 0) { if (r < 0) {
log_debug("%s: parent device is not a proper block device, ignoring.", name); log_debug_errno(r, "%s: parent device is not a proper block device, ignoring: %m", name);
goto not_found; goto not_found;
} }