From 116b73d69bf2462fa9e9b8b9f629794bbda90ee5 Mon Sep 17 00:00:00 2001 From: Ben Evans Date: Tue, 14 Nov 2017 10:28:12 -0500 Subject: [PATCH] LU-10199 utils: strip // from fid2path There are a few ways to get a path with a // back from fid2path, make sure we strip them all out Signed-off-by: Ben Evans Change-Id: I30591585ccf62e4d793ee658d2772ce1db242034 Reviewed-on: https://review.whamcloud.com/30078 Tested-by: Jenkins Reviewed-by: Steve Guminski Reviewed-by: Andreas Dilger Tested-by: Maloo Reviewed-by: John L. Hammond --- lustre/utils/liblustreapi.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index e6008a9..4383fd7 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -4551,6 +4551,8 @@ int llapi_fid2path(const char *device, const char *fidstr, char *buf, const char *fidstr_orig = fidstr; struct lu_fid fid; struct getinfo_fid2path *gf; + char *a; + char *b; int rc; while (*fidstr == '[') @@ -4579,11 +4581,21 @@ int llapi_fid2path(const char *device, const char *fidstr, char *buf, if (rc) goto out_free; - memcpy(buf, gf->gf_u.gf_path, gf->gf_pathlen); + b = buf; + /* strip out instances of // */ + for (a = gf->gf_u.gf_path; *a != '\0'; a++) { + if ((*a == '/') && (*(a + 1) == '/')) + continue; + *b = *a; + b++; + } + *b = '\0'; + if (buf[0] == '\0') { /* ROOT path */ buf[0] = '/'; buf[1] = '\0'; } + *recno = gf->gf_recno; *linkno = gf->gf_linkno; -- 1.8.3.1