diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2017-10-31 11:30:40 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2017-11-30 12:59:23 +0100 |
commit | c67f84b0254640168977ff52f3a961db407f472e (patch) | |
tree | f86d7262930e6d1e87d898a71630d76854681288 /src/udev/udev-node.c | |
parent | Add a little helper to make /sys/dev/block/major:minor paths (diff) | |
download | systemd-c67f84b0254640168977ff52f3a961db407f472e.tar.xz systemd-c67f84b0254640168977ff52f3a961db407f472e.zip |
Add a helper for /dev/block/major:minor paths
Diffstat (limited to 'src/udev/udev-node.c')
-rw-r--r-- | src/udev/udev-node.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/udev/udev-node.c b/src/udev/udev-node.c index dcea890d7f..ef893247ad 100644 --- a/src/udev/udev-node.c +++ b/src/udev/udev-node.c @@ -25,6 +25,7 @@ #include <sys/stat.h> #include <unistd.h> +#include "device-nodes.h" #include "dirent-util.h" #include "format-util.h" #include "fs-util.h" @@ -337,7 +338,7 @@ out: void udev_node_add(struct udev_device *dev, bool apply, mode_t mode, uid_t uid, gid_t gid, struct udev_list *seclabel_list) { - char filename[sizeof("/dev/block/:") + 2*DECIMAL_STR_MAX(unsigned)]; + char filename[DEV_NUM_PATH_MAX]; struct udev_list_entry *list_entry; log_debug("handling device node '%s', devnum=%s, mode=%#o, uid="UID_FMT", gid="GID_FMT, @@ -347,10 +348,9 @@ void udev_node_add(struct udev_device *dev, bool apply, return; /* always add /dev/{block,char}/$major:$minor */ - xsprintf(filename, "/dev/%s/%u:%u", - streq(udev_device_get_subsystem(dev), "block") ? "block" : "char", - major(udev_device_get_devnum(dev)), - minor(udev_device_get_devnum(dev))); + xsprintf_dev_num_path(filename, + streq(udev_device_get_subsystem(dev), "block") ? "block" : "char", + udev_device_get_devnum(dev)); node_symlink(dev, udev_device_get_devnode(dev), filename); /* create/update symlinks, add symlinks to name index */ @@ -360,16 +360,15 @@ void udev_node_add(struct udev_device *dev, bool apply, void udev_node_remove(struct udev_device *dev) { struct udev_list_entry *list_entry; - char filename[sizeof("/dev/block/:") + 2*DECIMAL_STR_MAX(unsigned)]; + char filename[DEV_NUM_PATH_MAX]; /* remove/update symlinks, remove symlinks from name index */ udev_list_entry_foreach(list_entry, udev_device_get_devlinks_list_entry(dev)) link_update(dev, udev_list_entry_get_name(list_entry), false); /* remove /dev/{block,char}/$major:$minor */ - xsprintf(filename, "/dev/%s/%u:%u", - streq(udev_device_get_subsystem(dev), "block") ? "block" : "char", - major(udev_device_get_devnum(dev)), - minor(udev_device_get_devnum(dev))); + xsprintf_dev_num_path(filename, + streq(udev_device_get_subsystem(dev), "block") ? "block" : "char", + udev_device_get_devnum(dev)); unlink(filename); } |