From a2b9a5dabf5a6a66192cc15beb03fba8bde167af 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 Lustre-commit: 116b73d69bf2462fa9e9b8b9f629794bbda90ee5 Lustre-change: https://review.whamcloud.com/30078 Signed-off-by: Ben Evans Signed-off-by: Bob Glossman Change-Id: I30591585ccf62e4d793ee658d2772ce1db242034 Reviewed-on: https://review.whamcloud.com/30078 Reviewed-by: Steve Guminski Reviewed-by: Andreas Dilger Reviewed-by: John L. Hammond Reviewed-on: https://review.whamcloud.com/31775 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: James Nunez --- 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 c774d0d..6598f13 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -4550,6 +4550,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 == '[') @@ -4578,11 +4580,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