Subject: bin/36194: add a '-V' flag to pax for verbose summary without listing (and other minor fixes)
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: Greg A. Woods <woods@planix.com>
List: netbsd-bugs
Date: 04/22/2007 18:50:00
>Number:         36194
>Category:       bin
>Synopsis:       add a '-V' flag to pax for verbose summary without listing (and other minor fixes)
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sun Apr 22 18:50:00 +0000 2007
>Originator:     Greg A. Woods
>Release:        NetBSD-current 20070422
>Organization:
Planix, Inc.; Toronto, Ontario; Canada
>Environment:
System: NetBSD
>Description:

	add a '-V' flag to pax (and tar and cpio) for verbose summary
	without listing (and a couple of other very minor fixes and
	clarifications)

>How-To-Repeat:

	desire to see the summary stats without also a file listing, e.g.:


$ ./pax -Vw -f /dev/null . 
pax: ustar vol 1, 47 files, 0 bytes read, 2355200 bytes written in 1 secs (2355200 bytes/sec)
$ 


>Fix:

	Dunno about the use of the potentially non-portable u_int64_t
	and 0x0ULL stuff in here, but the whole FLGCH stuff is kinda
	bogus in the first place anyway....

Index: bin/pax/ar_io.c
===================================================================
RCS file: /cvs/master/m-NetBSD/main/src/bin/pax/ar_io.c,v
retrieving revision 1.47
diff -u -r1.47 ar_io.c
--- bin/pax/ar_io.c	11 Feb 2006 10:43:17 -0000	1.47
+++ bin/pax/ar_io.c	22 Apr 2007 17:58:09 -0000
@@ -379,7 +379,7 @@
 	 * going on (this avoids the user hitting control-c thinking pax is
 	 * broken).
 	 */
-	if (vflag && (artyp == ISTAPE)) {
+	if ((vflag || Vflag) && (artyp == ISTAPE)) {
 		if (vfpart)
 			(void)putc('\n', listf);
 		(void)fprintf(listf,
@@ -416,7 +416,7 @@
 	if (zpid > 0)
 		waitpid(zpid, &status, 0);
 
-	if (vflag && (artyp == ISTAPE)) {
+	if ((vflag || Vflag) && (artyp == ISTAPE)) {
 		(void)fputs("done.\n", listf);
 		vfpart = 0;
 		(void)fflush(listf);
@@ -436,7 +436,7 @@
 	if (frmt != NULL)
 		++arvol;
 
-	if (!vflag) {
+	if (!vflag && !Vflag) {
 		flcnt = 0;
 		return;
 	}
@@ -448,20 +448,9 @@
 		(void)putc('\n', listf);
 		vfpart = 0;
 	}
-	/*
-	 * If we have not determined the format yet, we just say how many bytes
-	 * we have skipped over looking for a header to id. there is no way we
-	 * could have written anything yet.
-	 */
-	if (frmt == NULL) {
-		(void)fprintf(listf, "%s: unknown format, " OFFT_F
-		    " bytes skipped.\n", argv0, rdcnt);
-		(void)fflush(listf);
-		flcnt = 0;
-		return;
-	}
 
-	if (strcmp(NM_CPIO, argv0) == 0) {
+	/* mimic cpio's block count first */
+	if (frmt && strcmp(NM_CPIO, argv0) == 0) {
 		(void)fprintf(listf, OFFT_F " blocks\n",
 		    (rdcnt ? rdcnt : wrcnt) / 5120);
 	}
@@ -1646,10 +1635,10 @@
 {
 	time_t secs;
 	int len;
-	char buf[MAXPATHLEN];
-	char tbuf[MAXPATHLEN/4];
-	char s1buf[MAXPATHLEN/8];
-	char s2buf[MAXPATHLEN/8];
+	char buf[BUFSIZ];
+	char tbuf[MAXPATHLEN/4];	/* XXX silly size! */
+	char s1buf[MAXPATHLEN/8];	/* XXX very silly size! */
+	char s2buf[MAXPATHLEN/8];	/* XXX very silly size! */
 	FILE *outf;
 
 	if (act == LIST)
@@ -1683,10 +1672,11 @@
 	}
 
 
-	if (n != 0) {
+	if (n != 0 && *archd.name) {
 		len = snprintf(buf, sizeof(buf), "Working on `%s' (%s)\n",
 		    archd.name, sizefmt(s1buf, sizeof(s1buf), archd.sb.st_size));
 		(void)write(STDERR_FILENO, buf, len);
+		len = 0;
 	}
 
 
Index: bin/pax/ar_subs.c
===================================================================
RCS file: /cvs/master/m-NetBSD/main/src/bin/pax/ar_subs.c,v
retrieving revision 1.52
diff -u -r1.52 ar_subs.c
--- bin/pax/ar_subs.c	8 Mar 2007 17:01:30 -0000	1.52
+++ bin/pax/ar_subs.c	22 Apr 2007 17:59:29 -0000
@@ -802,7 +802,7 @@
 	/*
 	 * reading the archive may take a long time. If verbose tell the user
 	 */
-	if (vflag) {
+	if (vflag || Vflag) {
 		(void)fprintf(listf,
 			"%s: Reading archive to position at the end...", argv0);
 		vfpart = 1;
@@ -864,7 +864,7 @@
 	/*
 	 * tell the user we are done reading.
 	 */
-	if (vflag && vfpart) {
+	if ((vflag || Vflag) && vfpart) {
 		(void)safe_print("done.\n", listf);
 		vfpart = 0;
 	}
Index: bin/pax/extern.h
===================================================================
RCS file: /cvs/master/m-NetBSD/main/src/bin/pax/extern.h,v
retrieving revision 1.51
diff -u -r1.51 extern.h
--- bin/pax/extern.h	16 Apr 2006 16:20:21 -0000	1.51
+++ bin/pax/extern.h	22 Apr 2007 18:04:37 -0000
@@ -245,6 +245,7 @@
 extern int Hflag;
 extern int Lflag;
 extern int Mflag;
+extern int Vflag;
 extern int Xflag;
 extern int Yflag;
 extern int Zflag;
Index: bin/pax/options.c
===================================================================
RCS file: /cvs/master/m-NetBSD/main/src/bin/pax/options.c,v
retrieving revision 1.99
diff -u -r1.99 options.c
--- bin/pax/options.c	16 Jan 2007 19:06:41 -0000	1.99
+++ bin/pax/options.c	22 Apr 2007 18:35:00 -0000
@@ -255,8 +255,8 @@
 {
 	int c;
 	int i;
-	unsigned int flg = 0;
-	unsigned int bflg = 0;
+	u_int64_t flg = 0;
+	u_int64_t bflg = 0;
 	char *pt;
 	FSUB tmp;
 
@@ -264,7 +264,7 @@
 	 * process option flags
 	 */
 	while ((c = getopt_long(argc, argv,
-	    "0ab:cdf:ijklno:p:rs:tuvwx:zAB:DE:G:HLMN:OPT:U:XYZ",
+	    "0ab:cdf:ijklno:p:rs:tuvwx:zAB:DE:G:HLMN:OPT:U:VXYZ",
 	    pax_longopts, NULL)) != -1) {
 		switch (c) {
 		case '0':
@@ -606,6 +606,13 @@
 			}
 			flg |= CUF;
 			break;
+		case 'V':
+			/*
+			 * somewhat verbose operation mode (no listing)
+			 */
+			Vflag = 1;
+			flg |= VSF;
+			break;
 		case 'X':
 			/*
 			 * do not pass over mount points in the file system
@@ -751,6 +758,8 @@
 	{ "absolute-paths",	no_argument,		0,	'P' },
 	{ "sparse",		no_argument,		0,	'S' },
 	{ "files-from",		required_argument,	0,	'T' },
+	{ "summary",		no_argument,		0,	'V' },
+	{ "stats",		no_argument,		0,	'V' },
 	{ "exclude-from",	required_argument,	0,	'X' },
 	{ "compress",		no_argument,		0,	'Z' },
 	{ "uncompress",		no_argument,		0,	'Z' },
@@ -804,8 +813,8 @@
 						OPT_NULL },
 	{ "totals",		no_argument,		0,
 						OPT_TOTALS },
-	{ "volume-name",	required_argument,	0,	'V' },
-	{ "label",		required_argument,	0,	'V' },
+	{ "volume-name",	required_argument,	0,	'V' }, /* XXX */
+	{ "label",		required_argument,	0,	'V' }, /* XXX */
 	{ "version",		no_argument,		0,
 						OPT_VERSION },
 	{ "verify",		no_argument,		0,	'W' },
@@ -1046,6 +1055,12 @@
 		case 'S':
 			/* do nothing; we already generate sparse files */
 			break;
+		case 'V':
+			/*
+			 * semi-verbose operation mode (no listing)
+			 */
+			Vflag = 1;
+			break;
 		case 'X':
 			/*
 			 * GNU tar compat: exclude the files listed in optarg
@@ -1397,6 +1412,8 @@
 	{ "format",		required_argument,	0,	'H' },
 	{ "dereference",	no_argument,		0,	'L' },
 	{ "swap-halfwords",	no_argument,		0,	'S' },
+	{ "summary",		no_argument,		0,	'V' },
+	{ "stats",		no_argument,		0,	'V' },
 	{ "insecure",		no_argument,		0,
 						OPT_INSECURE },
 	{ "sparse",		no_argument,		0,
@@ -1410,7 +1427,7 @@
 	{ "swap-bytes",		no_argument,		0,	's' },
 	{ "message",		required_argument,	0,	'M' },
 	{ "owner",		required_argument,	0	'R' },
-	{ "dot",		no_argument,		0,	'V' },
+	{ "dot",		no_argument,		0,	'V' }, /* xxx */
 	{ "block-size",		required_argument,	0,
 						OPT_BLOCK_SIZE },
 	{ "no-absolute-pathnames", no_argument,		0,
@@ -1448,8 +1465,8 @@
 cpio_options(int argc, char **argv)
 {
 	FSUB tmp;
-	unsigned int flg = 0;
-	unsigned int bflg = 0;
+	u_int64_t flg = 0;
+	u_int64_t bflg = 0;
 	int c, i;
 	FILE *fp;
 	char *str;
@@ -1680,9 +1697,16 @@
 			cpio_swp_head = 1;
 			break;
 #ifdef notyet
-		case 'V':
+		case 'V':		/* print a '.' for each file processed */
 			break;
 #endif
+		case 'V':
+			/*
+			 * semi-verbose operation mode (no listing)
+			 */
+			Vflag = 1;
+			flg |= VF;
+			break;
 		case 'Z':
 			/*
 			 * use compress.  Non standard option.
Index: bin/pax/options.h
===================================================================
RCS file: /cvs/master/m-NetBSD/main/src/bin/pax/options.h,v
retrieving revision 1.10
diff -u -r1.10 options.h
--- bin/pax/options.h	11 May 2004 17:12:26 -0000	1.10
+++ bin/pax/options.h	22 Apr 2007 18:40:18 -0000
@@ -43,54 +43,57 @@
 #define NM_CPIO "cpio"
 #define NM_PAX  "pax"
 
+/* special value for -E */
+#define none	"none"
+
 /*
  * Constants used to specify the legal sets of flags in pax. For each major
  * operation mode of pax, a set of illegal flags is defined. If any one of
  * those illegal flags are found set, we scream and exit
  */
-#define none	"none"
 
 /*
  * flags (one for each option).
  */
-#define	AF	0x00000001
-#define	BF	0x00000002
-#define	CF	0x00000004
-#define	DF	0x00000008
-#define	FF	0x00000010
-#define	IF	0x00000020
-#define	KF	0x00000040
-#define	LF	0x00000080
-#define	NF	0x00000100
-#define	OF	0x00000200
-#define	PF	0x00000400
-#define	RF	0x00000800
-#define	SF	0x00001000
-#define	TF	0x00002000
-#define	UF	0x00004000
-#define	VF	0x00008000
-#define	WF	0x00010000
-#define	XF	0x00020000
-#define	CAF	0x00040000	/* nonstandard extension */
-#define	CBF	0x00080000	/* nonstandard extension */
-#define	CDF	0x00100000	/* nonstandard extension */
-#define	CEF	0x00200000	/* nonstandard extension */
-#define	CGF	0x00400000	/* nonstandard extension */
-#define	CHF	0x00800000	/* nonstandard extension */
-#define	CLF	0x01000000	/* nonstandard extension */
-#define	CMF	0x02000000	/* nonstandard extension */
-#define	CPF	0x04000000	/* nonstandard extension */
-#define	CTF	0x08000000	/* nonstandard extension */
-#define	CUF	0x10000000	/* nonstandard extension */
-#define	CXF	0x20000000
-#define	CYF	0x40000000	/* nonstandard extension */
-#define	CZF	0x80000000	/* nonstandard extension */
+#define AF	0x000000001ULL
+#define BF	0x000000002ULL
+#define CF	0x000000004ULL
+#define DF	0x000000008ULL
+#define FF	0x000000010ULL
+#define IF	0x000000020ULL
+#define KF	0x000000040ULL
+#define LF	0x000000080ULL
+#define NF	0x000000100ULL
+#define OF	0x000000200ULL
+#define PF	0x000000400ULL
+#define RF	0x000000800ULL
+#define SF	0x000001000ULL
+#define TF	0x000002000ULL
+#define UF	0x000004000ULL
+#define VF	0x000008000ULL
+#define WF	0x000010000ULL
+#define XF	0x000020000ULL
+#define CAF	0x000040000ULL	/* nonstandard extension */
+#define CBF	0x000080000ULL	/* nonstandard extension */
+#define CDF	0x000100000ULL	/* nonstandard extension */
+#define CEF	0x000200000ULL	/* nonstandard extension */
+#define CGF	0x000400000ULL	/* nonstandard extension */
+#define CHF	0x000800000ULL	/* nonstandard extension */
+#define CLF	0x001000000ULL	/* nonstandard extension */
+#define CMF	0x002000000ULL	/* nonstandard extension */
+#define CPF	0x004000000ULL	/* nonstandard extension */
+#define CTF	0x008000000ULL	/* nonstandard extension */
+#define CUF	0x010000000ULL	/* nonstandard extension */
+#define VSF	0x020000000ULL	/* non-standard */
+#define CXF	0x040000000ULL
+#define CYF	0x080000000ULL	/* nonstandard extension */
+#define CZF	0x100000000ULL	/* nonstandard extension */
 
 /*
  * ascii string indexed by bit position above (alter the above and you must
  * alter this string) used to tell the user what flags caused us to complain
  */
-#define FLGCH	"abcdfiklnoprstuvwxABDEGHLMPTUXYZ"
+#define FLGCH	"abcdfiklnoprstuvwxABDEGHLMPTUVXYZ"
 
 /*
  * legal pax operation bit patterns
Index: bin/pax/pax.1
===================================================================
RCS file: /cvs/master/m-NetBSD/main/src/bin/pax/pax.1,v
retrieving revision 1.51
diff -u -r1.51 pax.1
--- bin/pax/pax.1	22 Aug 2006 17:42:19 -0000	1.51
+++ bin/pax/pax.1	22 Apr 2007 18:07:19 -0000
@@ -41,7 +41,7 @@
 .Nd read and write file archives and copy directory hierarchies
 .Sh SYNOPSIS
 .Nm
-.Op Fl 0cdjnvzO
+.Op Fl 0cdjnvzVO
 .Bk -words
 .Op Fl E Ar limit
 .Ek
@@ -76,7 +76,7 @@
 .Op Ar pattern ...\&
 .Nm
 .Fl r
-.Op Fl cdijknuvzADOYZ
+.Op Fl cdijknuvzADOVYZ
 .Bk -words
 .Op Fl E Ar limit
 .Ek
@@ -119,7 +119,7 @@
 .Op Ar pattern ...\&
 .Nm
 .Fl w
-.Op Fl dijtuvzAHLMOPX
+.Op Fl dijtuvzAHLMOPVX
 .Bk -words
 .Op Fl b Ar blocksize
 .Ek
@@ -167,7 +167,7 @@
 .Nm
 .Fl r
 .Fl w
-.Op Fl dijklntuvzADHLMOPXYZ
+.Op Fl dijklntuvzADHLMOPVXYZ
 .Bk -words
 .Op Fl N Ar dbdir
 .Ek
@@ -712,6 +712,7 @@
 utility when used with the
 .Fl l
 option.
+.Pp
 Otherwise for all the other operational modes
 .Em ( read , write ,
 and
@@ -725,6 +726,9 @@
 The trailing
 .Aq Dv newline ,
 is not buffered, and is written only after the file has been read or written.
+.Pp
+A final summary of archive operations is printed after they have been
+completed.
 .It Fl x Ar format
 Specify the output archive format, with the default format being
 .Ar ustar .
@@ -1060,6 +1064,9 @@
 Multiple
 .Fl U
 options may be supplied and checking stops with the first match.
+.It Fl V
+A final summary of archive operations is printed after they have been
+completed.  Some potentially long-running tape operations are noted.
 .It Fl X
 When traversing the file hierarchy specified by a pathname,
 do not descend into directories that have a different device ID.
Index: bin/pax/pax.c
===================================================================
RCS file: /cvs/master/m-NetBSD/main/src/bin/pax/pax.c,v
retrieving revision 1.40
diff -u -r1.40 pax.c
--- bin/pax/pax.c	11 Feb 2006 11:04:57 -0000	1.40
+++ bin/pax/pax.c	22 Apr 2007 18:04:50 -0000
@@ -91,6 +91,7 @@
 int	Hflag;			/* follow command line symlinks (write only) */
 int	Lflag;			/* follow symlinks when writing */
 int	Mflag;			/* treat stdin as an mtree(8) specfile */
+int	Vflag;			/* produce somewhat verbose output (no listing) */
 int	Xflag;			/* archive files with same device id only */
 int	Yflag;			/* same as Dflg except after name mode */
 int	Zflag;			/* same as uflg except after name mode */
Index: bin/pax/tar.1
===================================================================
RCS file: /cvs/master/m-NetBSD/main/src/bin/pax/tar.1,v
retrieving revision 1.22
diff -u -r1.22 tar.1
--- bin/pax/tar.1	24 May 2005 00:05:01 -0000	1.22
+++ bin/pax/tar.1	8 Nov 2005 21:03:40 -0000
@@ -115,7 +115,8 @@
 .It Fl k , -keep-old-files
 Keep existing files; don't overwrite them from archive.
 .It Fl l , -one-file-system
-Do not cross filesystems.
+Do not decend across mount points.
+.\" should be '-X'
 .It Fl m , -modification-time
 Do not preserve modification time.
 .It Fl O
@@ -216,7 +217,21 @@
 This argument and its parameter may also appear in a file list specified by
 .Fl T .
 .It Fl H
-Follow symlinks given on command line only.
+Only follow symlinks given on command line.
+.Pp
+Note SysVr3/i386 picked up ISC/SCO UNIX compatabilty which implemented
+.Dq Fl F Ar file
+which was defined as obtaining a list of command line switches and files
+on which to operate from the specified file,
+but SunOS-5 uses
+.Dq Fl I Ar file
+because they use
+.Sq Fl F
+to mean something else.  We might someday provide SunOS-5 compatability
+but it makes little sense to confuse things with ISC/SCO compatability.
+.\".It Fl L
+.\"Do not follow any symlinks (do the opposite of
+.\".Fl h ).
 .It Fl P , -absolute-paths
 Do not strip leading slashes
 .Pq Sq /
@@ -229,6 +244,10 @@
 .Dq Fl C Ar directory .
 .It Fl X Ar file , Fl -exclude-from Ar file
 Exclude files listed in the given file.
+.\" exclude should be '-E' and '-X' should be one-file-system
+.Pp
+Note that it would be more standard to use this option to mean ``do not
+cross filesystem mount points.''
 .It Fl Z , -compress , -uncompress
 Compress archive using compress.
 .It Fl -strict
Index: bin/pax/tar.c
===================================================================
RCS file: /cvs/master/m-NetBSD/main/src/bin/pax/tar.c,v
retrieving revision 1.64
diff -u -r1.64 tar.c
--- bin/pax/tar.c	18 Mar 2006 05:43:47 -0000	1.64
+++ bin/pax/tar.c	3 May 2006 20:35:14 -0000
@@ -85,7 +85,7 @@
 
 static int tar_nodir;			/* do not write dirs under old tar */
 int is_gnutar;				/* behave like gnu tar; enable gnu
-					 * extensions and skip end-ofvolume
+					 * extensions and skip end-of-volume
 					 * checks
 					 */
 static int seen_gnu_warning;		/* Have we warned yet? */
@@ -789,7 +789,7 @@
 	    !seen_gnu_warning) {
 		seen_gnu_warning = 1;
 		tty_warn(0,
-		    "Trying to read GNU tar archive with extensions off");
+		    "Trying to read GNU tar archive with GNU extensions and end-of-volume checks off");
 	}
 	return check_sum(hd->chksum, sizeof(hd->chksum), blk, BLKMULT, 0);
 }
Index: bin/pax/tty_subs.c
===================================================================
RCS file: /cvs/master/m-NetBSD/main/src/bin/pax/tty_subs.c,v
retrieving revision 1.18
diff -u -r1.18 tty_subs.c
--- bin/pax/tty_subs.c	11 Feb 2006 10:43:18 -0000	1.18
+++ bin/pax/tty_subs.c	22 Apr 2007 18:04:12 -0000
@@ -156,7 +156,7 @@
 	 * when vflag we better ship out an extra \n to get this message on a
 	 * line by itself
 	 */
-	if (vflag && vfpart) {
+	if ((Vflag || vflag) && vfpart) {
 		(void)fputc('\n', stderr);
 		vfpart = 0;
 	}
@@ -183,7 +183,7 @@
 	 * when vflag we better ship out an extra \n to get this message on a
 	 * line by itself
 	 */
-	if (vflag && vfpart) {
+	if ((Vflag || vflag) && vfpart) {
 		(void)fputc('\n', stdout);
 		vfpart = 0;
 	}