1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-24 21:34:08 +03:00

udev: make udev_builtin_add_property() take sd_device instead of udev_device

This commit is contained in:
Yu Watanabe 2018-10-14 00:28:40 +09:00
parent 20fc56c02d
commit 0c9c063477
10 changed files with 78 additions and 72 deletions

View File

@ -32,65 +32,65 @@ static void print_property(struct udev_device *dev, bool test, const char *name,
s[0] = '\0';
if (streq(name, "TYPE")) {
udev_builtin_add_property(dev, test, "ID_FS_TYPE", value);
udev_builtin_add_property(dev->device, test, "ID_FS_TYPE", value);
} else if (streq(name, "USAGE")) {
udev_builtin_add_property(dev, test, "ID_FS_USAGE", value);
udev_builtin_add_property(dev->device, test, "ID_FS_USAGE", value);
} else if (streq(name, "VERSION")) {
udev_builtin_add_property(dev, test, "ID_FS_VERSION", value);
udev_builtin_add_property(dev->device, test, "ID_FS_VERSION", value);
} else if (streq(name, "UUID")) {
blkid_safe_string(value, s, sizeof(s));
udev_builtin_add_property(dev, test, "ID_FS_UUID", s);
udev_builtin_add_property(dev->device, test, "ID_FS_UUID", s);
blkid_encode_string(value, s, sizeof(s));
udev_builtin_add_property(dev, test, "ID_FS_UUID_ENC", s);
udev_builtin_add_property(dev->device, test, "ID_FS_UUID_ENC", s);
} else if (streq(name, "UUID_SUB")) {
blkid_safe_string(value, s, sizeof(s));
udev_builtin_add_property(dev, test, "ID_FS_UUID_SUB", s);
udev_builtin_add_property(dev->device, test, "ID_FS_UUID_SUB", s);
blkid_encode_string(value, s, sizeof(s));
udev_builtin_add_property(dev, test, "ID_FS_UUID_SUB_ENC", s);
udev_builtin_add_property(dev->device, test, "ID_FS_UUID_SUB_ENC", s);
} else if (streq(name, "LABEL")) {
blkid_safe_string(value, s, sizeof(s));
udev_builtin_add_property(dev, test, "ID_FS_LABEL", s);
udev_builtin_add_property(dev->device, test, "ID_FS_LABEL", s);
blkid_encode_string(value, s, sizeof(s));
udev_builtin_add_property(dev, test, "ID_FS_LABEL_ENC", s);
udev_builtin_add_property(dev->device, test, "ID_FS_LABEL_ENC", s);
} else if (streq(name, "PTTYPE")) {
udev_builtin_add_property(dev, test, "ID_PART_TABLE_TYPE", value);
udev_builtin_add_property(dev->device, test, "ID_PART_TABLE_TYPE", value);
} else if (streq(name, "PTUUID")) {
udev_builtin_add_property(dev, test, "ID_PART_TABLE_UUID", value);
udev_builtin_add_property(dev->device, test, "ID_PART_TABLE_UUID", value);
} else if (streq(name, "PART_ENTRY_NAME")) {
blkid_encode_string(value, s, sizeof(s));
udev_builtin_add_property(dev, test, "ID_PART_ENTRY_NAME", s);
udev_builtin_add_property(dev->device, test, "ID_PART_ENTRY_NAME", s);
} else if (streq(name, "PART_ENTRY_TYPE")) {
blkid_encode_string(value, s, sizeof(s));
udev_builtin_add_property(dev, test, "ID_PART_ENTRY_TYPE", s);
udev_builtin_add_property(dev->device, test, "ID_PART_ENTRY_TYPE", s);
} else if (startswith(name, "PART_ENTRY_")) {
strscpyl(s, sizeof(s), "ID_", name, NULL);
udev_builtin_add_property(dev, test, s, value);
udev_builtin_add_property(dev->device, test, s, value);
} else if (streq(name, "SYSTEM_ID")) {
blkid_encode_string(value, s, sizeof(s));
udev_builtin_add_property(dev, test, "ID_FS_SYSTEM_ID", s);
udev_builtin_add_property(dev->device, test, "ID_FS_SYSTEM_ID", s);
} else if (streq(name, "PUBLISHER_ID")) {
blkid_encode_string(value, s, sizeof(s));
udev_builtin_add_property(dev, test, "ID_FS_PUBLISHER_ID", s);
udev_builtin_add_property(dev->device, test, "ID_FS_PUBLISHER_ID", s);
} else if (streq(name, "APPLICATION_ID")) {
blkid_encode_string(value, s, sizeof(s));
udev_builtin_add_property(dev, test, "ID_FS_APPLICATION_ID", s);
udev_builtin_add_property(dev->device, test, "ID_FS_APPLICATION_ID", s);
} else if (streq(name, "BOOT_SYSTEM_ID")) {
blkid_encode_string(value, s, sizeof(s));
udev_builtin_add_property(dev, test, "ID_FS_BOOT_SYSTEM_ID", s);
udev_builtin_add_property(dev->device, test, "ID_FS_BOOT_SYSTEM_ID", s);
}
}
@ -172,7 +172,7 @@ static int find_gpt_root(struct udev_device *dev, blkid_probe pr, bool test) {
/* We found the ESP on this disk, and also found a root
* partition, nice! Let's export its UUID */
if (found_esp && root_id)
udev_builtin_add_property(dev, test, "ID_PART_GPT_AUTO_ROOT_UUID", root_id);
udev_builtin_add_property(dev->device, test, "ID_PART_GPT_AUTO_ROOT_UUID", root_id);
#endif
return 0;
@ -300,7 +300,7 @@ static int builtin_blkid(struct udev_device *dev, int argc, char *argv[], bool t
/* Is this a partition that matches the root partition
* property we inherited from our parent? */
if (root_partition && streq(name, "PART_ENTRY_UUID") && streq(data, root_partition))
udev_builtin_add_property(dev, test, "ID_PART_GPT_AUTO_ROOT", "1");
udev_builtin_add_property(dev->device, test, "ID_PART_GPT_AUTO_ROOT", "1");
}
if (is_gpt)

View File

@ -32,7 +32,7 @@ static int builtin_btrfs(struct udev_device *dev, int argc, char *argv[], bool t
if (err < 0)
return EXIT_FAILURE;
udev_builtin_add_property(dev, test, "ID_BTRFS_READY", one_zero(err == 0));
udev_builtin_add_property(dev->device, test, "ID_BTRFS_READY", one_zero(err == 0));
return EXIT_SUCCESS;
}

View File

@ -37,7 +37,7 @@ int udev_builtin_hwdb_lookup(struct udev_device *dev,
if (filter && fnmatch(filter, key, FNM_NOESCAPE) != 0)
continue;
if (udev_builtin_add_property(dev, test, key, value) < 0)
if (udev_builtin_add_property(dev->device, test, key, value) < 0)
return -ENOMEM;
n++;
}

View File

@ -65,8 +65,8 @@ static void extract_info(struct udev_device *dev, const char *devpath, bool test
xsprintf(width, "%d", abs_size_mm(&xabsinfo));
xsprintf(height, "%d", abs_size_mm(&yabsinfo));
udev_builtin_add_property(dev, test, "ID_INPUT_WIDTH_MM", width);
udev_builtin_add_property(dev, test, "ID_INPUT_HEIGHT_MM", height);
udev_builtin_add_property(dev->device, test, "ID_INPUT_WIDTH_MM", width);
udev_builtin_add_property(dev->device, test, "ID_INPUT_HEIGHT_MM", height);
}
/*
@ -162,7 +162,7 @@ static bool test_pointers(struct udev_device *dev,
is_accelerometer = true;
if (is_accelerometer) {
udev_builtin_add_property(dev, test, "ID_INPUT_ACCELEROMETER", "1");
udev_builtin_add_property(dev->device, test, "ID_INPUT_ACCELEROMETER", "1");
return true;
}
@ -232,17 +232,17 @@ static bool test_pointers(struct udev_device *dev,
is_mouse = true;
if (is_pointing_stick)
udev_builtin_add_property(dev, test, "ID_INPUT_POINTINGSTICK", "1");
udev_builtin_add_property(dev->device, test, "ID_INPUT_POINTINGSTICK", "1");
if (is_mouse)
udev_builtin_add_property(dev, test, "ID_INPUT_MOUSE", "1");
udev_builtin_add_property(dev->device, test, "ID_INPUT_MOUSE", "1");
if (is_touchpad)
udev_builtin_add_property(dev, test, "ID_INPUT_TOUCHPAD", "1");
udev_builtin_add_property(dev->device, test, "ID_INPUT_TOUCHPAD", "1");
if (is_touchscreen)
udev_builtin_add_property(dev, test, "ID_INPUT_TOUCHSCREEN", "1");
udev_builtin_add_property(dev->device, test, "ID_INPUT_TOUCHSCREEN", "1");
if (is_joystick)
udev_builtin_add_property(dev, test, "ID_INPUT_JOYSTICK", "1");
udev_builtin_add_property(dev->device, test, "ID_INPUT_JOYSTICK", "1");
if (is_tablet)
udev_builtin_add_property(dev, test, "ID_INPUT_TABLET", "1");
udev_builtin_add_property(dev->device, test, "ID_INPUT_TABLET", "1");
return is_tablet || is_mouse || is_touchpad || is_touchscreen || is_joystick || is_pointing_stick;
}
@ -284,7 +284,7 @@ static bool test_key(struct udev_device *dev,
}
if (found > 0) {
udev_builtin_add_property(dev, test, "ID_INPUT_KEY", "1");
udev_builtin_add_property(dev->device, test, "ID_INPUT_KEY", "1");
ret = true;
}
@ -292,7 +292,7 @@ static bool test_key(struct udev_device *dev,
* those, consider it a full keyboard; do not test KEY_RESERVED, though */
mask = 0xFFFFFFFE;
if (FLAGS_SET(bitmask_key[0], mask)) {
udev_builtin_add_property(dev, test, "ID_INPUT_KEYBOARD", "1");
udev_builtin_add_property(dev->device, test, "ID_INPUT_KEYBOARD", "1");
ret = true;
}
@ -321,7 +321,7 @@ static int builtin_input_id(struct udev_device *dev, int argc, char *argv[], boo
if (pdev) {
/* Use this as a flag that input devices were detected, so that this
* program doesn't need to be called more than once per device */
udev_builtin_add_property(dev, test, "ID_INPUT", "1");
udev_builtin_add_property(dev->device, test, "ID_INPUT", "1");
get_cap_mask(dev, pdev, "capabilities/ev", bitmask_ev, sizeof(bitmask_ev), test);
get_cap_mask(dev, pdev, "capabilities/abs", bitmask_abs, sizeof(bitmask_abs), test);
get_cap_mask(dev, pdev, "capabilities/rel", bitmask_rel, sizeof(bitmask_rel), test);
@ -334,9 +334,9 @@ static int builtin_input_id(struct udev_device *dev, int argc, char *argv[], boo
/* Some evdev nodes have only a scrollwheel */
if (!is_pointer && !is_key && test_bit(EV_REL, bitmask_ev) &&
(test_bit(REL_WHEEL, bitmask_rel) || test_bit(REL_HWHEEL, bitmask_rel)))
udev_builtin_add_property(dev, test, "ID_INPUT_KEY", "1");
udev_builtin_add_property(dev->device, test, "ID_INPUT_KEY", "1");
if (test_bit(EV_SW, bitmask_ev))
udev_builtin_add_property(dev, test, "ID_INPUT_SWITCH", "1");
udev_builtin_add_property(dev->device, test, "ID_INPUT_SWITCH", "1");
}

View File

@ -794,7 +794,7 @@ static int builtin_net_id(struct udev_device *dev, int argc, char *argv[], bool
xsprintf(str, "%sx%02x%02x%02x%02x%02x%02x", prefix,
names.mac[0], names.mac[1], names.mac[2],
names.mac[3], names.mac[4], names.mac[5]);
udev_builtin_add_property(dev, test, "ID_NET_NAME_MAC", str);
udev_builtin_add_property(dev->device, test, "ID_NET_NAME_MAC", str);
ieee_oui(dev, &names, test);
}
@ -805,7 +805,7 @@ static int builtin_net_id(struct udev_device *dev, int argc, char *argv[], bool
char str[IFNAMSIZ];
if (snprintf_ok(str, sizeof str, "%s%s", prefix, names.ccw_busid))
udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
udev_builtin_add_property(dev->device, test, "ID_NET_NAME_PATH", str);
goto out;
}
@ -815,7 +815,7 @@ static int builtin_net_id(struct udev_device *dev, int argc, char *argv[], bool
char str[IFNAMSIZ];
if (snprintf_ok(str, sizeof str, "%s%s", prefix, names.vio_slot))
udev_builtin_add_property(dev, test, "ID_NET_NAME_SLOT", str);
udev_builtin_add_property(dev->device, test, "ID_NET_NAME_SLOT", str);
goto out;
}
@ -825,7 +825,7 @@ static int builtin_net_id(struct udev_device *dev, int argc, char *argv[], bool
char str[IFNAMSIZ];
if (snprintf_ok(str, sizeof str, "%s%s", prefix, names.platform_path))
udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
udev_builtin_add_property(dev->device, test, "ID_NET_NAME_PATH", str);
goto out;
}
@ -840,19 +840,19 @@ static int builtin_net_id(struct udev_device *dev, int argc, char *argv[], bool
if (names.pci_onboard[0] &&
snprintf_ok(str, sizeof str, "%s%s", prefix, names.pci_onboard))
udev_builtin_add_property(dev, test, "ID_NET_NAME_ONBOARD", str);
udev_builtin_add_property(dev->device, test, "ID_NET_NAME_ONBOARD", str);
if (names.pci_onboard_label &&
snprintf_ok(str, sizeof str, "%s%s", prefix, names.pci_onboard_label))
udev_builtin_add_property(dev, test, "ID_NET_LABEL_ONBOARD", str);
udev_builtin_add_property(dev->device, test, "ID_NET_LABEL_ONBOARD", str);
if (names.pci_path[0] &&
snprintf_ok(str, sizeof str, "%s%s", prefix, names.pci_path))
udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
udev_builtin_add_property(dev->device, test, "ID_NET_NAME_PATH", str);
if (names.pci_slot[0] &&
snprintf_ok(str, sizeof str, "%s%s", prefix, names.pci_slot))
udev_builtin_add_property(dev, test, "ID_NET_NAME_SLOT", str);
udev_builtin_add_property(dev->device, test, "ID_NET_NAME_SLOT", str);
goto out;
}
@ -863,11 +863,11 @@ static int builtin_net_id(struct udev_device *dev, int argc, char *argv[], bool
if (names.pci_path[0] &&
snprintf_ok(str, sizeof str, "%s%s%s", prefix, names.pci_path, names.usb_ports))
udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
udev_builtin_add_property(dev->device, test, "ID_NET_NAME_PATH", str);
if (names.pci_slot[0] &&
snprintf_ok(str, sizeof str, "%s%s%s", prefix, names.pci_slot, names.usb_ports))
udev_builtin_add_property(dev, test, "ID_NET_NAME_SLOT", str);
udev_builtin_add_property(dev->device, test, "ID_NET_NAME_SLOT", str);
goto out;
}
@ -878,11 +878,11 @@ static int builtin_net_id(struct udev_device *dev, int argc, char *argv[], bool
if (names.pci_path[0] &&
snprintf_ok(str, sizeof str, "%s%s%s", prefix, names.pci_path, names.bcma_core))
udev_builtin_add_property(dev, test, "ID_NET_NAME_PATH", str);
udev_builtin_add_property(dev->device, test, "ID_NET_NAME_PATH", str);
if (names.pci_slot[0] &&
snprintf(str, sizeof str, "%s%s%s", prefix, names.pci_slot, names.bcma_core))
udev_builtin_add_property(dev, test, "ID_NET_NAME_SLOT", str);
udev_builtin_add_property(dev->device, test, "ID_NET_NAME_SLOT", str);
goto out;
}
out:

View File

@ -21,7 +21,7 @@ static int builtin_net_setup_link(struct udev_device *dev, int argc, char **argv
r = link_get_driver(ctx, dev->device, &driver);
if (r >= 0)
udev_builtin_add_property(dev, test, "ID_NET_DRIVER", driver);
udev_builtin_add_property(dev->device, test, "ID_NET_DRIVER", driver);
r = link_config_get(ctx, dev->device, &link);
if (r < 0) {
@ -38,10 +38,10 @@ static int builtin_net_setup_link(struct udev_device *dev, int argc, char **argv
if (r < 0)
log_warning_errno(r, "Could not apply link config to %s, ignoring: %m", udev_device_get_sysname(dev));
udev_builtin_add_property(dev, test, "ID_NET_LINK_FILE", link->filename);
udev_builtin_add_property(dev->device, test, "ID_NET_LINK_FILE", link->filename);
if (name)
udev_builtin_add_property(dev, test, "ID_NET_NAME", name);
udev_builtin_add_property(dev->device, test, "ID_NET_NAME", name);
return EXIT_SUCCESS;
}

View File

@ -666,8 +666,8 @@ static int builtin_path_id(struct udev_device *dev, int argc, char *argv[], bool
i--;
tag[i] = '\0';
udev_builtin_add_property(dev, test, "ID_PATH", path);
udev_builtin_add_property(dev, test, "ID_PATH_TAG", tag);
udev_builtin_add_property(dev->device, test, "ID_PATH", path);
udev_builtin_add_property(dev->device, test, "ID_PATH_TAG", tag);
}
return EXIT_SUCCESS;

View File

@ -428,27 +428,27 @@ fallback:
if (!isempty(instance_str))
strpcpyl(&s, l, "-", instance_str, NULL);
udev_builtin_add_property(dev, test, "ID_VENDOR", vendor_str);
udev_builtin_add_property(dev, test, "ID_VENDOR_ENC", vendor_str_enc);
udev_builtin_add_property(dev, test, "ID_VENDOR_ID", vendor_id);
udev_builtin_add_property(dev, test, "ID_MODEL", model_str);
udev_builtin_add_property(dev, test, "ID_MODEL_ENC", model_str_enc);
udev_builtin_add_property(dev, test, "ID_MODEL_ID", product_id);
udev_builtin_add_property(dev, test, "ID_REVISION", revision_str);
udev_builtin_add_property(dev, test, "ID_SERIAL", serial);
udev_builtin_add_property(dev->device, test, "ID_VENDOR", vendor_str);
udev_builtin_add_property(dev->device, test, "ID_VENDOR_ENC", vendor_str_enc);
udev_builtin_add_property(dev->device, test, "ID_VENDOR_ID", vendor_id);
udev_builtin_add_property(dev->device, test, "ID_MODEL", model_str);
udev_builtin_add_property(dev->device, test, "ID_MODEL_ENC", model_str_enc);
udev_builtin_add_property(dev->device, test, "ID_MODEL_ID", product_id);
udev_builtin_add_property(dev->device, test, "ID_REVISION", revision_str);
udev_builtin_add_property(dev->device, test, "ID_SERIAL", serial);
if (!isempty(serial_str))
udev_builtin_add_property(dev, test, "ID_SERIAL_SHORT", serial_str);
udev_builtin_add_property(dev->device, test, "ID_SERIAL_SHORT", serial_str);
if (!isempty(type_str))
udev_builtin_add_property(dev, test, "ID_TYPE", type_str);
udev_builtin_add_property(dev->device, test, "ID_TYPE", type_str);
if (!isempty(instance_str))
udev_builtin_add_property(dev, test, "ID_INSTANCE", instance_str);
udev_builtin_add_property(dev, test, "ID_BUS", "usb");
udev_builtin_add_property(dev->device, test, "ID_INSTANCE", instance_str);
udev_builtin_add_property(dev->device, test, "ID_BUS", "usb");
if (!isempty(packed_if_str))
udev_builtin_add_property(dev, test, "ID_USB_INTERFACES", packed_if_str);
udev_builtin_add_property(dev->device, test, "ID_USB_INTERFACES", packed_if_str);
if (ifnum != NULL)
udev_builtin_add_property(dev, test, "ID_USB_INTERFACE_NUM", ifnum);
udev_builtin_add_property(dev->device, test, "ID_USB_INTERFACE_NUM", ifnum);
if (driver != NULL)
udev_builtin_add_property(dev, test, "ID_USB_DRIVER", driver);
udev_builtin_add_property(dev->device, test, "ID_USB_DRIVER", driver);
return EXIT_SUCCESS;
}

View File

@ -4,9 +4,10 @@
#include <stdio.h>
#include <string.h>
#include "device-private.h"
#include "string-util.h"
#include "strv.h"
#include "udev-builtin.h"
#include "udev.h"
static bool initialized;
@ -117,8 +118,12 @@ int udev_builtin_run(struct udev_device *dev, enum udev_builtin_cmd cmd, const c
return builtins[cmd]->cmd(dev, strv_length(argv), argv, test);
}
int udev_builtin_add_property(struct udev_device *dev, bool test, const char *key, const char *val) {
udev_device_add_property(dev, key, val);
int udev_builtin_add_property(sd_device *dev, bool test, const char *key, const char *val) {
int r;
r = device_add_property(dev, key, val);
if (r < 0)
return r;
if (test)
printf("%s=%s\n", key, val);

View File

@ -4,6 +4,7 @@
#include <stdbool.h>
#include "libudev.h"
#include "libudev-device-internal.h"
enum udev_builtin_cmd {
#if HAVE_BLKID
@ -62,6 +63,6 @@ bool udev_builtin_run_once(enum udev_builtin_cmd cmd);
int udev_builtin_run(struct udev_device *dev, enum udev_builtin_cmd cmd, const char *command, bool test);
void udev_builtin_list(void);
bool udev_builtin_validate(void);
int udev_builtin_add_property(struct udev_device *dev, bool test, const char *key, const char *val);
int udev_builtin_add_property(sd_device *dev, bool test, const char *key, const char *val);
int udev_builtin_hwdb_lookup(struct udev_device *dev, const char *prefix, const char *modalias,
const char *filter, bool test);