From owner-svn-src-all@FreeBSD.ORG Wed May 7 19:22:55 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 2FABE9B4; Wed, 7 May 2014 19:22:55 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D8BD41C0; Wed, 7 May 2014 19:22:54 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s47JMs8t042028; Wed, 7 May 2014 19:22:54 GMT (envelope-from thomas@svn.freebsd.org) Received: (from thomas@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s47JMs6Q042026; Wed, 7 May 2014 19:22:54 GMT (envelope-from thomas@svn.freebsd.org) Message-Id: <201405071922.s47JMs6Q042026@svn.freebsd.org> From: Thomas Quinot Date: Wed, 7 May 2014 19:22:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r265591 - head/usr.bin/stat X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 May 2014 19:22:55 -0000 Author: thomas Date: Wed May 7 19:22:54 2014 New Revision: 265591 URL: http://svnweb.freebsd.org/changeset/base/265591 Log: Introduce a new command line switch '-H' for stat(1) causing arguments to be interpreted as NFS file handles. Reviewed by: -arch (jhb, eadler) MFC after: 1 month Modified: head/usr.bin/stat/stat.1 head/usr.bin/stat/stat.c Modified: head/usr.bin/stat/stat.1 ============================================================================== --- head/usr.bin/stat/stat.1 Wed May 7 19:20:54 2014 (r265590) +++ head/usr.bin/stat/stat.1 Wed May 7 19:22:54 2014 (r265591) @@ -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 Modified: head/usr.bin/stat/stat.c ============================================================================== --- head/usr.bin/stat/stat.c Wed May 7 19:20:54 2014 (r265590) +++ head/usr.bin/stat/stat.c Wed May 7 19:22:54 2014 (r265591) @@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -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