Hi,
Here's a patch that add the file size in the first column of the 't'
command of restore. With this, one can do:
$ restore -tf mydump | sort -n
to see what files are eating up all space.
The patch is a bit ugly because the file size computation is piggy
backed on the extractfile function that is called during actual file
walking.
Index: extern.h
===================================================================
RCS file: /cvs/src/sbin/restore/extern.h,v
retrieving revision 1.12
diff -u -p -r1.12 extern.h
--- extern.h 7 Sep 2014 19:43:35 -0000 1.12
+++ extern.h 10 Nov 2015 15:51:27 -0000
@@ -61,7 +61,6 @@ int inodetype(ino_t);
int linkit(char *, char *, int);
struct entry *lookupino(ino_t);
struct entry *lookupname(char *);
-long listfile(char *, ino_t, int);
ino_t lowerbnd(ino_t);
void mktempname(struct entry *);
void moveentry(struct entry *, char *);
@@ -94,6 +93,7 @@ void setup(void);
void skipdirs(void);
void skipfile(void);
void skipmaps(void);
+void Tprintfile(char *, ino_t, int, size_t);
void treescan(char *, ino_t, long (*)(char *, ino_t, int));
ino_t upperbnd(ino_t);
long verifyfile(char *, ino_t, int);
Index: main.c
===================================================================
RCS file: /cvs/src/sbin/restore/main.c,v
retrieving revision 1.23
diff -u -p -r1.23 main.c
--- main.c 20 Jan 2015 18:22:21 -0000 1.23
+++ main.c 10 Nov 2015 15:51:27 -0000
@@ -240,8 +240,9 @@ main(int argc, char *argv[])
ino = dirlookup(name);
if (ino == 0)
continue;
- treescan(name, ino, listfile);
+ treescan(name, ino, addfile);
}
+ createfiles();
break;
/*
* Batch extraction of tape contents.
Index: restore.8
===================================================================
RCS file: /cvs/src/sbin/restore/restore.8,v
retrieving revision 1.39
diff -u -p -r1.39 restore.8
--- restore.8 20 Jan 2014 05:07:49 -0000 1.39
+++ restore.8 10 Nov 2015 15:51:27 -0000
@@ -180,7 +180,7 @@ An example of correct usage:
# newfs /dev/rsd0g
# mount /dev/sd0g /mnt
# cd /mnt
-# restore rf /dev/rst0
+# restore -rf /dev/rst0
.Ed
.Pp
Note that
Index: restore.c
===================================================================
RCS file: /cvs/src/sbin/restore/restore.c,v
retrieving revision 1.17
diff -u -p -r1.17 restore.c
--- restore.c 24 Apr 2013 13:46:29 -0000 1.17
+++ restore.c 10 Nov 2015 15:51:27 -0000
@@ -44,22 +44,6 @@
static char *keyval(int);
/*
- * This implements the 't' option.
- * List entries on the tape.
- */
-long
-listfile(char *name, ino_t ino, int type)
-{
- long descend = hflag ? GOOD : FAIL;
-
- if (TSTINO(ino, dumpmap) == 0)
- return (descend);
- Vprintf(stdout, "%s", type == LEAF ? "leaf" : "dir ");
- fprintf(stdout, "%10llu\t%s\n", (unsigned long long)ino, name);
- return (descend);
-}
-
-/*
* This implements the 'x' option.
* Request that new entries be extracted.
*/
@@ -79,8 +63,12 @@ addfile(char *name, ino_t ino, int type)
(unsigned long long)ino);
name = buf;
if (type == NODE) {
- (void)genliteraldir(name, ino);
- return (descend);
+ if (command == 't') {
+ Tprintfile(name, ino, type, 0);
+ } else {
+ (void)genliteraldir(name, ino);
+ return (descend);
+ }
}
}
ep = lookupino(ino);
@@ -92,8 +80,13 @@ addfile(char *name, ino_t ino, int type)
type |= LINK;
}
ep = addentry(name, ino, type);
- if (type == NODE)
- newnode(ep);
+ if (type == NODE) {
+ if (command == 't') {
+ Tprintfile(name, ino, type, 0);
+ } else {
+ newnode(ep);
+ }
+ }
ep->e_flags |= NEW;
return (descend);
}
@@ -652,7 +645,7 @@ createfiles(void)
Vprintf(stdout, "Extract requested files\n");
curfile.action = SKIP;
- getvol((long)1);
+ if (command != 't') getvol((long)1);
skipmaps();
skipdirs();
first = lowerbnd(ROOTINO);
Index: tape.c
===================================================================
RCS file: /cvs/src/sbin/restore/tape.c,v
retrieving revision 1.46
diff -u -p -r1.46 tape.c
--- tape.c 25 Aug 2015 04:18:43 -0000 1.46
+++ tape.c 10 Nov 2015 15:51:27 -0000
@@ -75,6 +75,7 @@ static int ofile;
static char *map;
static char lnkbuf[PATH_MAX + 1];
static size_t pathlen;
+static size_t szcount = 0;
int oldinofmt; /* old inode format conversion required */
int Bcvt; /* Swap Bytes (for CCI or sun) */
@@ -124,6 +125,7 @@ static void xtrlnkskip(char *, size_t);
static void xtrmap(char *, size_t);
static void xtrmapskip(char *, size_t);
static void xtrskip(char *, size_t);
+static void xtrcount(char *, size_t);
/*
* Set up an input source
@@ -547,10 +549,19 @@ extractfile(char *name)
skipfile();
return (GOOD);
}
- Vprintf(stdout, "extract file %s\n", name);
- return (genliteraldir(name, curfile.ino));
-
+ Vprintf(stdout, "extract directory %s\n", name);
+ if (command != 't') {
+ return (genliteraldir(name, curfile.ino));
+ } else {
+ return (GOOD);
+ }
+
case IFLNK: {
+ if (command == 't') {
+ Tprintfile(name, curfile.ino, LINK, 0);
+ skipfile();
+ return (GOOD);
+ }
lnkbuf[0] = '\0';
pathlen = 0;
getfile(xtrlnkfile, xtrlnkskip);
@@ -568,6 +579,11 @@ extractfile(char *name)
case IFCHR:
case IFBLK:
+ if (command == 't') {
+ Tprintfile(name, curfile.ino, LEAF, 0);
+ skipfile();
+ return (GOOD);
+ }
Vprintf(stdout, "extract special file %s\n", name);
if (Nflag) {
skipfile();
@@ -588,6 +604,11 @@ extractfile(char *name)
return (GOOD);
case IFIFO:
+ if (command == 't') {
+ Tprintfile(name, curfile.ino, LEAF, 0);
+ skipfile();
+ return (GOOD);
+ }
Vprintf(stdout, "extract fifo %s\n", name);
if (Nflag) {
skipfile();
@@ -608,6 +629,12 @@ extractfile(char *name)
return (GOOD);
case IFREG:
+ if (command == 't') {
+ getfile(xtrcount, xtrcount);
+ Tprintfile(name, curfile.ino, LEAF, szcount);
+ szcount = 0;
+ return (GOOD);
+ }
Vprintf(stdout, "extract file %s\n", name);
if (Nflag) {
skipfile();
@@ -805,6 +832,12 @@ xtrnull(char *buf, size_t size)
{
return;
+}
+
+static void
+xtrcount(char *buf, size_t size)
+{
+ szcount += size;
}
/*
Index: utilities.c
===================================================================
RCS file: /cvs/src/sbin/restore/utilities.c,v
retrieving revision 1.19
diff -u -p -r1.19 utilities.c
--- utilities.c 7 Nov 2015 21:52:55 -0000 1.19
+++ utilities.c 10 Nov 2015 15:51:27 -0000
@@ -340,6 +340,23 @@ reply(char *question)
return (FAIL);
}
+void
+Tprintfile(char *name, ino_t ino, int type, size_t size)
+{
+ switch (type) {
+ case NODE:
+ Vprintf(stdout, "dir ");
+ break;
+ case LEAF:
+ Vprintf(stdout, "leaf");
+ break;
+ case LINK:
+ Vprintf(stdout, "link");
+ break;
+ }
+ fprintf(stdout, "%10d\t%10llu\t%s\n", size, (unsigned long long)ino,
name);
+}
+
/*
* handle unexpected inconsistencies
*/
--
Manuel Giraud