systemd-growfs: use sd_device_new_from_devnum()

Use sd_device_new_from_devnum() instead of
device_path_make_major_minor_sysfs().
This commit is contained in:
Devendra Tewari
2022-08-26 20:33:03 +01:00
committed by Luca Boccassi
parent 528ba54bbe
commit 0f79b3469f
3 changed files with 46 additions and 67 deletions
-48
View File
@@ -5,7 +5,6 @@
#include "chase-symlinks.h"
#include "devnum-util.h"
#include "fs-util.h"
#include "parse-util.h"
#include "path-util.h"
#include "string-util.h"
@@ -58,53 +57,6 @@ int device_path_make_major_minor(mode_t mode, dev_t devnum, char **ret) {
return 0;
}
int device_path_make_major_minor_sysfs(mode_t mode, dev_t devnum, char **ret) {
_cleanup_free_ char *syspath = NULL, *link = NULL, *fname = NULL;
_cleanup_free_ char *devpath = NULL;
const char *t;
int r;
/* Generates the /dev/... path given a dev_t. What makes this different
* from device_path_make_major_minor is that it works even when udev
* hasn't yet run */
if (S_ISCHR(mode))
t = "char";
else if (S_ISBLK(mode))
t = "block";
else
return -ENODEV;
if (asprintf(&syspath, "/sys/dev/%s/" DEVNUM_FORMAT_STR, t, DEVNUM_FORMAT_VAL(devnum)) < 0)
return -ENOMEM;
r = readlink_malloc(syspath, &link);
if (r < 0)
return r;
r = path_extract_filename(link, &fname);
if (r < 0)
return r;
devpath = path_join("/dev", fname);
if (!devpath)
return -ENOMEM;
struct stat st;
if (stat(devpath, &st) < 0)
return -errno;
if (((st.st_mode ^ mode) & S_IFMT) != 0)
return S_ISBLK(mode) ? -ENOTBLK : -ENODEV;
if (st.st_rdev != devnum)
return -ENXIO;
*ret = TAKE_PTR(devpath);
return 0;
}
int device_path_make_canonical(mode_t mode, dev_t devnum, char **ret) {
_cleanup_free_ char *p = NULL;
int r;
-1
View File
@@ -29,7 +29,6 @@ int parse_devnum(const char *s, dev_t *ret);
})
int device_path_make_major_minor(mode_t mode, dev_t devnum, char **ret);
int device_path_make_major_minor_sysfs(mode_t mode, dev_t devnum, char **ret);
int device_path_make_canonical(mode_t mode, dev_t devnum, char **ret);
int device_path_parse_major_minor(const char *path, mode_t *ret_mode, dev_t *ret_devnum);