From 96f9ab0a284d55768aa00a64d352ba944455a4cb Mon Sep 17 00:00:00 2001 From: Jorgen Lundman Date: Mon, 21 Jun 2021 16:40:39 +0900 Subject: [PATCH] Upstream: dirname -> zfs_dirnamelen [squash] Forgot to actually change it to zfs_dirnamelen Signed-off-by: Jorgen Lundman --- cmd/zpool/zpool_vdev.c | 12 +++++++++--- lib/libzutil/zutil_device_path.c | 17 +++++++++++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/cmd/zpool/zpool_vdev.c b/cmd/zpool/zpool_vdev.c index 7c75cf77557f..f5fc7597dd07 100644 --- a/cmd/zpool/zpool_vdev.c +++ b/cmd/zpool/zpool_vdev.c @@ -275,7 +275,8 @@ make_leaf_vdev(nvlist_t *props, const char *arg, boolean_t is_primary) { char path[MAXPATHLEN]; char *d, *b; - char *dpath, *bname; + char *dpath; + const char *bname; struct stat64 statbuf; nvlist_t *vdev = NULL; char *type = NULL; @@ -317,9 +318,14 @@ make_leaf_vdev(nvlist_t *props, const char *arg, boolean_t is_primary) */ d = strdup(arg); b = strdup(arg); - dpath = dirname(d); - bname = basename(b); + int idx = zfs_dirnamelen(d); + if (idx != -1) + d[idx] = 0; + dpath = d; + bname = zfs_basename(b); if (realpath(dpath, path) == NULL) { + free(d); + free(b); (void) fprintf(stderr, gettext("cannot resolve path '%s'\n"), dpath); return (NULL); diff --git a/lib/libzutil/zutil_device_path.c b/lib/libzutil/zutil_device_path.c index 265c0d8e2e6c..3789b954f53f 100644 --- a/lib/libzutil/zutil_device_path.c +++ b/lib/libzutil/zutil_device_path.c @@ -159,7 +159,7 @@ zfs_strcmp_pathname(const char *name, const char *cmp, int wholedisk) char cmp_name[MAXPATHLEN]; char *dir, *tmp = NULL; char *d, *b; - char *dpath, *bname; + const char *dpath, *bname; /* Strip redundant slashes if they exist due to ZPOOL_IMPORT_PATH */ cmp_name[0] = '\0'; @@ -187,18 +187,27 @@ zfs_strcmp_pathname(const char *name, const char *cmp, int wholedisk) if ((path_len == cmp_len) && strcmp(path_name, cmp_name) == 0) return (0); else { + int idx; d = strdup(path_name); b = strdup(path_name); - dpath = dirname(d); - bname = basename(b); + idx = zfs_dirnamelen(d); + if (idx != -1) + d[idx] = 0; + dpath = d; + bname = zfs_basename(b); if (realpath(dpath, path_name) == NULL) { (void) fprintf(stderr, "cannot resolve path '%s'\n", dpath); + free(d); + free(b); return (ENOENT); } - if (strcmp(dpath, path_name) == 0) + if (strcmp(dpath, path_name) == 0) { + free(d); + free(b); return (ENOENT); // We already tried this path + } strlcat(path_name, "/", sizeof (path_name)); path_len = strlcat(path_name, bname, sizeof (path_name));