diff options
author | sjg <sjg@FreeBSD.org> | 2014-05-08 23:54:15 +0000 |
---|---|---|
committer | sjg <sjg@FreeBSD.org> | 2014-05-08 23:54:15 +0000 |
commit | ed3fc70bf5a8edaf648093b11acca450802244ef (patch) | |
tree | 8ce0ddd0e6f508bd20c77429c448969589170fae /usr.bin/stat | |
parent | d4e443e0426fee44056ba3c1123455666d083aef (diff) | |
parent | a2e6be0add027bf3e713c0d56ba9715b83a01144 (diff) | |
download | FreeBSD-src-ed3fc70bf5a8edaf648093b11acca450802244ef.zip FreeBSD-src-ed3fc70bf5a8edaf648093b11acca450802244ef.tar.gz |
Merge from head
Diffstat (limited to 'usr.bin/stat')
-rw-r--r-- | usr.bin/stat/stat.1 | 8 | ||||
-rw-r--r-- | usr.bin/stat/stat.c | 41 |
2 files changed, 44 insertions, 5 deletions
diff --git a/usr.bin/stat/stat.1 b/usr.bin/stat/stat.1 index 7d591b8..eb8894c 100644 --- a/usr.bin/stat/stat.1 +++ b/usr.bin/stat/stat.1 @@ -38,7 +38,7 @@ .Nd display file status .Sh SYNOPSIS .Nm -.Op Fl FLnq +.Op Fl FHLnq .Op Fl f Ar format | Fl l | r | s | x .Op Fl t Ar timefmt .Op Ar @@ -124,6 +124,12 @@ The use of .Fl F implies .Fl l . +.It Fl H +Treat each argument as the hexadecimal representation of an NFS file handle, +and use +.Xr fhstat 2 +instead of +.Xr lstat 2 . .It Fl L Use .Xr stat 2 diff --git a/usr.bin/stat/stat.c b/usr.bin/stat/stat.c index 984ec7b..7b43882 100644 --- a/usr.bin/stat/stat.c +++ b/usr.bin/stat/stat.c @@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$"); #include <sys/param.h> #include <sys/types.h> #include <sys/stat.h> +#include <sys/mount.h> #include <ctype.h> #include <err.h> @@ -203,15 +204,17 @@ main(int argc, char *argv[]) { struct stat st; int ch, rc, errs, am_readlink; - int lsF, fmtchar, usestat, fn, nonl, quiet; + int lsF, fmtchar, usestat, nfs_handle, fn, nonl, quiet; const char *statfmt, *options, *synopsis; char dname[sizeof _PATH_DEV + SPECNAMELEN] = _PATH_DEV; + fhandle_t fhnd; const char *file; am_readlink = 0; lsF = 0; fmtchar = '\0'; usestat = 0; + nfs_handle = 0; nonl = 0; quiet = 0; linkfail = 0; @@ -226,9 +229,9 @@ main(int argc, char *argv[]) fmtchar = 'f'; quiet = 1; } else { - options = "f:FlLnqrst:x"; + options = "f:FHlLnqrst:x"; synopsis = "[-FLnq] [-f format | -l | -r | -s | -x] " - "[-t timefmt] [file ...]"; + "[-t timefmt] [file|handle ...]"; } while ((ch = getopt(argc, argv, options)) != -1) @@ -236,6 +239,9 @@ main(int argc, char *argv[]) case 'F': lsF = 1; break; + case 'H': + nfs_handle = 1; + break; case 'L': usestat = 1; break; @@ -320,8 +326,35 @@ main(int argc, char *argv[]) file = "(stdin)"; rc = fstat(STDIN_FILENO, &st); } else { + int j; + char *inval; + file = argv[0]; - if (usestat) { + if (nfs_handle) { + rc = 0; + bzero (&fhnd, sizeof fhnd); + j = MIN(2 * sizeof fhnd, strlen(file)); + if (j & 1) { + rc = -1; + } else { + while (j) { + ((char*) &fhnd)[j / 2 - 1] = + strtol(&file[j - 2], + &inval, 16); + if (inval != NULL) { + rc = -1; + break; + } + argv[0][j - 2] = '\0'; + j -= 2; + } + if (!rc) + rc = fhstat(&fhnd, &st); + else + errno = EINVAL; + } + + } else if (usestat) { /* * Try stat() and if it fails, fall back to * lstat() just in case we're examining a |