shithub: riscv

Download patch

ref: 5c1803e1adc869ef6781eb65d2ee08b30326aee1
parent: 2e94406e7f66b0c5f4e2b1d5c2158a37e8677724
author: cinap_lenrek <[email protected]>
date: Sun Dec 14 19:52:22 EST 2014

disk/mkfs: add -o flag to list source files

--- a/sys/man/8/mkfs
+++ b/sys/man/8/mkfs
@@ -3,7 +3,7 @@
 mkfs, mkext \- archive or update a file system
 .SH SYNOPSIS
 .B disk/mkfs
-.RB [ -aprvxU ]
+.RB [ -aprvoxU ]
 .RB [ -d
 .IR root ]
 .RB [ -n
@@ -82,6 +82,12 @@
 For use with
 .BR -a ,
 this option writes a list of file names, dates, and sizes to standard output
+rather than producing an archive file.
+.TP
+.B o
+Similar to
+.BR -x
+above, but produces a list of source file names to standard output
 rather than producing an archive file.
 .TP
 .BI "d " root
--- a/sys/src/cmd/disk/mkfs.c
+++ b/sys/src/cmd/disk/mkfs.c
@@ -46,6 +46,7 @@
 int	ream;
 int	debug;
 int	xflag;
+int	oflag;
 int	sfd;
 int	fskind;			/* Kfs, Fs, Archive */
 int	setuid;			/* on Fs: set uid and gid? */
@@ -106,6 +107,9 @@
 	case 'v':
 		verb = 1;
 		break;
+	case 'o':
+		oflag = 1;
+		break;
 	case 'x':
 		xflag = 1;
 		break;
@@ -116,9 +120,14 @@
 		usage();
 	}ARGEND
 
-	if(!argc)	
+	if(!argc)
 		usage();
 
+	if((xflag || oflag) && fskind != Archive){
+		fprint(2, "cannot use -x and -o without -a\n");
+		usage();
+	}
+
 	buf = malloc(buflen);
 	zbuf = malloc(buflen);
 	memset(zbuf, 0, buflen);
@@ -145,7 +154,8 @@
 	if(errs)
 		exits("skipped protos");
 	if(fskind == Archive){
-		Bprint(&bout, "end of archive\n");
+		if(!xflag && !oflag)
+			Bprint(&bout, "end of archive\n");
 		Bterm(&bout);
 	}
 	exits(0);
@@ -319,6 +329,11 @@
 	sprint(newfile, "%s%s", newroot, new);
 	sprint(oldfile, "%s", old);
 
+	if(oflag){
+		if(!(d->mode & DMDIR))
+			Bprint(&bout, "%q\n", cleanname(oldfile));
+		return;
+	}
 	if(xflag){
 		Bprint(&bout, "%q\t%ld\t%lld\n", new, d->mtime, d->length);
 		return;
@@ -438,6 +453,6 @@
 void
 usage(void)
 {
-	fprint(2, "usage: %q [-adprvxUD] [-d root] [-n name] [-s source] [-u users] [-z n] proto ...\n", prog);
+	fprint(2, "usage: %q [-adprvoxUD] [-d root] [-n name] [-s source] [-u users] [-z n] proto ...\n", prog);
 	exits("usage");
 }