[ -z "$fid" ] && error "path2fid unable to get $tf FID"
# check that we get the same pathname back
- local found=$($LFS fid2path $MOUNT "$fid")
- [ -z "$found" ] && error "fid2path unable to get '$fid' path"
- [ "$found" == "$tf" ] ||
- error "fid2path($fid=path2fid($tf)) = $found != $tf"
+ local rootpath
+ local found
+ for rootpath in "$MOUNT" "$MOUNT///" "$MOUNT/$tfile"; do
+ echo "$rootpath $fid"
+ found=$($LFS fid2path $rootpath "$fid")
+ [ -z "$found" ] && error "fid2path unable to get '$fid' path"
+ [ "$found" == "$tf" ] || error "fid2path $found != $tf"
+ done
+
+ # check wrong root path format
+ rootpath=$MOUNT"_wrong"
+ found=$($LFS fid2path $rootpath "$fid")
+ [ -z "$found" ] || error "should fail ($rootpath != $MOUNT)"
}
run_test 154A "lfs path2fid and fid2path basic checks"
$LFS fid2path $submount $fid && error "fid2path should fail"
cleanup_247 $submount
}
-run_test 247c "running fid2path outside root"
+run_test 247c "running fid2path outside subdirectory root"
test_247d() {
lctl get_param -n mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
FILESET="$FILESET/$tdir" mount_client $submount ||
error "mount $submount failed"
trap "cleanup_247 $submount" EXIT
- local fid=$($LFS path2fid $submount/dir1)
- $LFS fid2path $submount $fid || error "fid2path should succeed"
+
+ local td=$submount/dir1
+ local fid=$($LFS path2fid $td)
+ [ -z "$fid" ] && error "path2fid unable to get $td FID"
+
+ # check that we get the same pathname back
+ local rootpath
+ local found
+ for rootpath in "$submount" "$submount///" "$submount/dir1"; do
+ echo "$rootpath $fid"
+ found=$($LFS fid2path $rootpath "$fid")
+ [ -n "found" ] || error "fid2path should succeed"
+ [ "$found" == "$td" ] || error "fid2path $found != $td"
+ done
+ # check wrong root path format
+ rootpath=$submount"_wrong"
+ found=$($LFS fid2path $rootpath "$fid")
+ [ -z "$found" ] || error "fid2path should fail ($rootpath != $submount)"
+
cleanup_247 $submount
}
-run_test 247d "running fid2path inside root"
+run_test 247d "running fid2path inside subdirectory root"
# LU-8037
test_247e() {
{ .val = 'l', .name = "link", .has_arg = required_argument },
{ .val = 'r', .name = "rec", .has_arg = required_argument },
{ .name = NULL } };
- char short_opts[] = "cl:r:";
- char *device, *fid, *path;
+ char short_opts[] = "cl:r:";
+ char mntdir[PATH_MAX];
+ char *device, *fid, *path, *rootpath;
long long recno = -1;
int linkno = -1;
int lnktmp;
}
rc = 0;
+ /* in case that device is not the mountpoint */
+ if (device[0] == '/') {
+ rc = llapi_search_mounts(device, 0, mntdir, NULL);
+ if (rc == 0) {
+ rootpath = mntdir;
+ } else {
+ fprintf(stderr,
+ "%s fid2path: %s has no mountpoint: %s\n",
+ progname, device, strerror(-rc));
+ goto out;
+ }
+ }
while (optind < argc) {
fid = argv[optind++];
&rectmp, &lnktmp);
if (rc2 < 0) {
fprintf(stderr,
- "%s fid2path: cannot find '%s': %s\n",
- progname, fid, strerror(errno = -rc2));
+ "%s fid2path: cannot find %s %s: %s\n",
+ progname, device, fid,
+ strerror(errno = -rc2));
if (rc == 0)
rc = rc2;
break;
if (printcur)
fprintf(stdout, "%lld ", rectmp);
if (device[0] == '/') {
- fprintf(stdout, "%s", device);
- if (device[strlen(device) - 1] != '/')
+ fprintf(stdout, "%s", rootpath);
+ if (rootpath[strlen(rootpath) - 1] != '/')
fprintf(stdout, "/");
} else if (path[0] == '\0') {
fprintf(stdout, "/");
break;
}
}
-
+out:
free(path);
return rc;
}
char buf[PATH_MAX], mntdir[PATH_MAX];
char *ptr, *ptr_end;
FILE *fp;
- int idx = 0, len = 0, mntlen, fd;
+ int idx = 0, mntlen = 0, fd;
int rc = -ENODEV;
int fsnamelen, mountlen;
rc = 0;
break;
/* Otherwise find the longest matching path */
- } else if ((strlen(path) >= mntlen) && (mntlen >= len) &&
+ } else if ((strlen(path) >= mntlen) &&
(strncmp(mnt.mnt_dir, path, mntlen) == 0)) {
+ /* check the path format */
+ if (strlen(path) > mntlen && path[mntlen] != '/')
+ continue;
strncpy(mntdir, mnt.mnt_dir, sizeof(mntdir) - 1);
mntdir[sizeof(mntdir) - 1] = '\0';
- len = mntlen;
if ((want & WANT_FSNAME) && fsname != NULL) {
strncpy(fsname, ptr, mountlen);
fsname[mountlen] = '\0';
}
rc = 0;
+ break;
}
}
endmntent(fp);
/* Found it */
if (rc == 0) {
if ((want & WANT_PATH) && path != NULL) {
- strncpy(path, mntdir, PATH_MAX);
- path[strlen(mntdir)] = '\0';
+ strncpy(path, mntdir, mntlen);
+ path[mntlen] = '\0';
}
if (want & WANT_FD) {
fd = open(mntdir, O_RDONLY | O_DIRECTORY | O_NONBLOCK);