]>
git.wh0rd.org - dump.git/blob - dump/main.c
2 * Ported to Linux's Second Extended File System as part of the
3 * dump and restore backup suit
4 * Remy Card <card@Linux.EU.Org>, 1994-1997
5 * Stelian Pop <pop@noos.fr>, 1999-2000
6 * Stelian Pop <pop@noos.fr> - AlcĂ´ve <www.alcove.fr>, 2000
10 * Copyright (c) 1980, 1991, 1993, 1994
11 * The Regents of the University of California. All rights reserved.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. All advertising materials mentioning features or use of this software
22 * must display the following acknowledgement:
23 * This product includes software developed by the University of
24 * California, Berkeley and its contributors.
25 * 4. Neither the name of the University nor the names of its contributors
26 * may be used to endorse or promote products derived from this software
27 * without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43 static const char rcsid
[] =
44 "$Id: main.c,v 1.48 2001/04/27 15:22:47 stelian Exp $";
48 #include <compatlfs.h>
50 #include <compaterr.h>
59 #include <sys/param.h>
62 #include <linux/ext2_fs.h>
63 #include <ext2fs/ext2fs.h>
66 #include <bsdcompat.h>
68 #include <sys/vnode.h>
70 #include <ufs/inode.h>
73 #include <ufs/ufs/dinode.h>
74 #include <ufs/ffs/fs.h>
77 #include <protocols/dumprestore.h>
80 #include "pathnames.h"
84 #define SBOFF (SBLOCK * DEV_BSIZE)
87 int notify
= 0; /* notify operator flag */
88 int blockswritten
= 0; /* number of blocks written on current tape */
89 int tapeno
= 0; /* current tape number */
90 int density
= 0; /* density in bytes/0.1" " <- this is for hilit19 */
91 int ntrec
= NTREC
; /* # tape blocks in each tape record */
92 int cartridge
= 0; /* Assume non-cartridge tape */
94 int tapepos
= 0; /* assume no QFA tapeposition needed by user */
96 int dokerberos
= 0; /* Use Kerberos authentication */
97 long dev_bsize
= 1; /* recalculated below */
98 long blocksperfile
; /* output blocks per file */
99 char *host
= NULL
; /* remote host (if any) */
100 int sizest
= 0; /* return size estimate only */
101 int compressed
= 0; /* use zlib to compress the output, compress level 1-9 */
102 long long bytes_written
= 0; /* total bytes written */
103 long uncomprblks
= 0;/* uncompressed blocks written */
109 int maxbsize
= 64*1024; /* XXX MAXBSIZE from sys/param.h */
110 static long numarg
__P((const char *, long, long));
111 static void obsolete
__P((int *, char **[]));
112 static void usage
__P((void));
114 dump_ino_t iexclude_list
[IEXCLUDE_MAXNUM
];/* the inode exclude list */
115 int iexclude_num
= 0; /* number of elements in the list */
118 main(int argc
, char *argv
[])
120 register dump_ino_t ino
;
122 register struct dinode
*dp
;
123 register struct fstab
*dt
;
126 int i
, anydirskipped
, bflag
= 0, Tflag
= 0, honorlevel
= 1;
132 char directory
[MAXPATHLEN
];
133 char pathname
[MAXPATHLEN
];
138 spcl
.c_label
[0] = '\0';
139 spcl
.c_date
= time(NULL
);
142 __progname
= argv
[0];
144 initialize_ext2_error_table();
147 tsize
= 0; /* Default later, based on 'c' option for cart tapes */
150 if ((tapeprefix
= getenv("TAPE")) == NULL
)
151 tapeprefix
= _PATH_DEFTAPE
;
152 dumpdates
= _PATH_DUMPDATES
;
153 if (TP_BSIZE
/ DEV_BSIZE
== 0 || TP_BSIZE
% DEV_BSIZE
!= 0)
154 quit("TP_BSIZE must be a multiple of DEV_BSIZE\n");
160 obsolete(&argc
, &argv
);
166 while ((ch
= getopt(argc
, argv
,
167 "0123456789aB:b:cd:e:f:F:h:L:"
182 case '0': case '1': case '2': case '3': case '4':
183 case '5': case '6': case '7': case '8': case '9':
187 case 'a': /* `auto-size', Write to EOM. */
191 case 'B': /* blocks per output file */
193 blocksperfile
= numarg("number of blocks per file",
197 case 'b': /* blocks per tape write */
198 ntrec
= numarg("number of blocks per write",
200 if (ntrec
> maxbsize
/1024) {
201 msg("Please choose a blocksize <= %dkB\n",
203 msg("The ENTIRE dump is aborted.\n");
209 case 'c': /* Tape is cart. not 9-track */
214 case 'd': /* density, in bits per inch */
216 density
= numarg("density", 10L, 327670L) / 10;
217 if (density
>= 625 && !bflag
)
218 ntrec
= HIGHDENSITYTREC
;
222 case 'e': /* exclude an inode */
223 if (iexclude_num
== IEXCLUDE_MAXNUM
) {
224 msg("Too many -e options\n");
225 msg("The ENTIRE dump is aborted.\n");
228 iexclude_list
[iexclude_num
++] = numarg("inode to exclude",0L,0L);
229 if (iexclude_list
[iexclude_num
-1] <= ROOTINO
) {
230 msg("Cannot exclude inode %ld\n", (long)iexclude_list
[iexclude_num
-1]);
231 msg("The ENTIRE dump is aborted.\n");
234 msg("Added %d to exclude list\n",
235 iexclude_list
[iexclude_num
-1]);
238 case 'f': /* output file */
242 case 'F': /* end of tape script */
247 honorlevel
= numarg("honor level", 0L, 10L);
258 * Note that although there are LBLSIZE characters,
259 * the last must be '\0', so the limit on strlen()
260 * is really LBLSIZE-1.
262 strncpy(spcl
.c_label
, optarg
, LBLSIZE
);
263 spcl
.c_label
[LBLSIZE
-1] = '\0';
264 if (strlen(optarg
) > LBLSIZE
-1) {
266 "WARNING Label `%s' is larger than limit of %d characters.\n",
268 msg("WARNING: Using truncated label `%s'.\n",
273 case 'M': /* multi-volume flag */
277 case 'n': /* notify operators */
282 case 'Q': /* create tapeposfile */
283 gTapeposfile
= optarg
;
288 case 's': /* tape size, feet */
290 tsize
= numarg("tape size", 1L, 0L) * 12 * 10;
294 sizest
= 1; /* return size estimate only */
297 case 'T': /* time of last dump */
298 spcl
.c_ddate
= unctime(optarg
);
299 if (spcl
.c_ddate
< 0) {
300 msg("bad time \"%s\"\n", optarg
);
301 msg("The ENTIRE dump is aborted.\n");
308 case 'u': /* update dumpdates */
312 case 'W': /* what to do */
315 exit(X_FINOK
); /* do nothing else */
320 compressed
= numarg("compress level", 1L, 9L);
322 #endif /* HAVE_ZLIB */
331 msg("Must specify disk or filesystem\n");
332 msg("The ENTIRE dump is aborted.\n");
336 if (strlen(diskparam
) >= MAXPATHLEN
) {
337 msg("Disk or filesystem name too long: %s\n", diskparam
);
338 msg("The ENTIRE dump is aborted.\n");
342 if (Tflag
&& uflag
) {
343 msg("You cannot use the T and u flags together.\n");
344 msg("The ENTIRE dump is aborted.\n");
347 if (strcmp(tapeprefix
, "-") == 0) {
349 tapeprefix
= "standard output";
353 blocksperfile
= blocksperfile
/ ntrec
* ntrec
; /* round down */
354 else if (!unlimited
) {
356 * Determine how to default tape size and density
359 * 9-track 1600 bpi (160 bytes/.1") 2300 ft.
360 * 9-track 6250 bpi (625 bytes/.1") 2300 ft.
361 * cartridge 8000 bpi (100 bytes/.1") 1700 ft.
363 * hilit19 hits again: "
366 density
= cartridge
? 100 : 160;
368 tsize
= cartridge
? 1700L*120L : 2300L*120L;
371 if (strchr(tapeprefix
, ':')) {
373 tapeprefix
= strchr(host
, ':');
374 *tapeprefix
++ = '\0';
376 if (index(tapeprefix
, '\n')) {
377 msg("invalid characters in tape\n");
378 msg("The ENTIRE dump is aborted.\n");
381 if (rmthost(host
) == 0)
384 msg("remote dump not enabled\n");
385 msg("The ENTIRE dump is aborted.\n");
389 (void)setuid(getuid()); /* rmthost() is the only reason to be setuid */
391 if (signal(SIGHUP
, SIG_IGN
) != SIG_IGN
)
393 if (signal(SIGTRAP
, SIG_IGN
) != SIG_IGN
)
394 signal(SIGTRAP
, sig
);
395 if (signal(SIGFPE
, SIG_IGN
) != SIG_IGN
)
397 if (signal(SIGBUS
, SIG_IGN
) != SIG_IGN
)
399 if (signal(SIGSEGV
, SIG_IGN
) != SIG_IGN
)
400 signal(SIGSEGV
, sig
);
401 if (signal(SIGTERM
, SIG_IGN
) != SIG_IGN
)
402 signal(SIGTERM
, sig
);
403 if (signal(SIGINT
, interrupt
) == SIG_IGN
)
404 signal(SIGINT
, SIG_IGN
);
405 set_operators(); /* /etc/group snarfed */
406 getfstab(); /* /etc/fstab snarfed */
409 * disk may end in / and this can confuse
412 i
= strlen(diskparam
) - 1;
413 if (i
> 1 && diskparam
[i
] == '/')
416 disk
= get_device_name(diskparam
);
417 if (!disk
) { /* null means the disk is some form
418 of LABEL= or UID= but it was not
420 msg("Cannot find a disk having %s\n", diskparam
);
421 msg("The ENTIRE dump is aborted.\n");
425 * disk can be either the full special file name,
426 * the suffix of the special file name,
427 * the special name missing the leading '/',
428 * the file system name with or without the leading '/'.
430 if ((dt
= fstabsearch(disk
)) != NULL
) {
431 /* if found then only one parameter (i.e. partition)
434 (void)fprintf(stderr
, "Unknown arguments to dump:");
436 (void)fprintf(stderr
, " %s", *argv
++);
437 (void)fprintf(stderr
, "\n");
438 msg("The ENTIRE dump is aborted.\n");
441 disk
= rawname(dt
->fs_spec
);
442 (void)strncpy(spcl
.c_dev
, dt
->fs_spec
, NAMELEN
);
443 (void)strncpy(spcl
.c_filesys
, dt
->fs_file
, NAMELEN
);
447 if (realpath(disk
, pathname
) == NULL
)
449 strcpy(pathname
, disk
);
451 * The argument could be now a mountpoint of
452 * a filesystem specified in fstab. Search for it.
454 if ((dt
= fstabsearch(pathname
)) != NULL
) {
455 disk
= rawname(dt
->fs_spec
);
456 (void)strncpy(spcl
.c_dev
, dt
->fs_spec
, NAMELEN
);
457 (void)strncpy(spcl
.c_filesys
, dt
->fs_file
, NAMELEN
);
460 * The argument was not found in the fstab
461 * assume that this is a subtree and search for it
463 dt
= fstabsearchdir(pathname
, directory
);
465 char name
[MAXPATHLEN
];
466 (void)strncpy(spcl
.c_dev
, dt
->fs_spec
, NAMELEN
);
467 (void)snprintf(name
, sizeof(name
), "%s (dir %s)",
468 dt
->fs_file
, directory
);
469 (void)strncpy(spcl
.c_filesys
, name
, NAMELEN
);
470 disk
= rawname(dt
->fs_spec
);
472 (void)strncpy(spcl
.c_dev
, disk
, NAMELEN
);
473 (void)strncpy(spcl
.c_filesys
, "an unlisted file system",
478 (void)strncpy(spcl
.c_dev
, disk
, NAMELEN
);
479 (void)strncpy(spcl
.c_filesys
, "an unlisted file system",
484 if (directory
[0] != 0) {
486 msg("Only level 0 dumps are allowed on a subdirectory\n");
487 msg("The ENTIRE dump is aborted.\n");
491 msg("You can't update the dumpdates file when dumping a subdirectory\n");
492 msg("The ENTIRE dump is aborted.\n");
496 spcl
.c_dev
[NAMELEN
-1] = '\0';
497 spcl
.c_filesys
[NAMELEN
-1] = '\0';
498 (void)gethostname(spcl
.c_host
, NAMELEN
);
499 spcl
.c_host
[NAMELEN
-1] = '\0';
500 spcl
.c_level
= level
- '0';
501 spcl
.c_type
= TS_TAPE
;
503 getdumptime(uflag
); /* dumpdates snarfed */
505 if (spcl
.c_ddate
== 0 && spcl
.c_level
) {
506 msg("WARNING: There is no inferior level dump on this filesystem\n");
507 msg("WARNING: Assuming a level 0 dump by default\n");
513 snprintf(tape
, MAXPATHLEN
, "%s%03d", tapeprefix
, tapeno
+ 1);
515 strncpy(tape
, tapeprefix
, MAXPATHLEN
);
516 tape
[MAXPATHLEN
- 1] = '\0';
520 msg("Date of this level %c dump: %s", level
,
521 ctime4(&spcl
.c_date
));
523 msg("Date of last level %c dump: %s", lastlevel
,
524 ctime4(&spcl
.c_ddate
));
525 msg("Dumping %s (%s) ", disk
, spcl
.c_filesys
);
527 msgtail("to %s on host %s\n", tape
, host
);
529 msgtail("to %s\n", tape
);
530 } /* end of size estimate */
533 retval
= dump_fs_open(disk
, &fs
);
535 com_err(disk
, retval
, "while opening filesystem");
536 if (retval
== EXT2_ET_REV_TOO_HIGH
)
537 msg("Get a newer version of dump!\n");
538 msg("The ENTIRE dump is aborted.\n");
541 if (fs
->super
->s_rev_level
> DUMP_CURRENT_REV
) {
542 com_err(disk
, retval
, "while opening filesystem");
543 msg("Get a newer version of dump!\n");
544 msg("The ENTIRE dump is aborted.\n");
547 if ((diskfd
= OPEN(disk
, O_RDONLY
)) < 0) {
548 msg("Cannot open %s\n", disk
);
549 msg("The ENTIRE dump is aborted.\n");
552 /* if no user label specified, use ext2 filesystem label if available */
553 if (spcl
.c_label
[0] == '\0') {
555 if ( (lbl
= get_device_label(disk
)) != NULL
) {
556 strncpy(spcl
.c_label
, lbl
, LBLSIZE
);
557 spcl
.c_label
[LBLSIZE
-1] = '\0';
560 strcpy(spcl
.c_label
, "none"); /* safe strcpy. */
563 dev_bsize
= DEV_BSIZE
;
564 dev_bshift
= ffs(dev_bsize
) - 1;
565 if (dev_bsize
!= (1 << dev_bshift
))
566 quit("dev_bsize (%d) is not a power of 2", dev_bsize
);
567 tp_bshift
= ffs(TP_BSIZE
) - 1;
568 if (TP_BSIZE
!= (1 << tp_bshift
))
569 quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE
);
570 maxino
= fs
->super
->s_inodes_count
;
572 spcl
.c_flags
|= DR_NEWINODEFMT
;
574 #else /* __linux __*/
575 if ((diskfd
= open(disk
, O_RDONLY
)) < 0) {
576 msg("Cannot open %s\n", disk
);
577 msg("The ENTIRE dump is aborted.\n");
581 sblock
= (struct fs
*)sblock_buf
;
582 bread(SBOFF
, (char *) sblock
, SBSIZE
);
583 if (sblock
->fs_magic
!= FS_MAGIC
)
584 quit("bad sblock magic number\n");
585 dev_bsize
= sblock
->fs_fsize
/ fsbtodb(sblock
, 1);
586 dev_bshift
= ffs(dev_bsize
) - 1;
587 if (dev_bsize
!= (1 << dev_bshift
))
588 quit("dev_bsize (%d) is not a power of 2", dev_bsize
);
589 tp_bshift
= ffs(TP_BSIZE
) - 1;
590 if (TP_BSIZE
!= (1 << tp_bshift
))
591 quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE
);
593 if (sblock
->fs_inodefmt
>= FS_44INODEFMT
)
594 spcl
.c_flags
|= DR_NEWINODEFMT
;
596 maxino
= sblock
->fs_ipg
* sblock
->fs_ncg
;
597 #endif /* __linux__ */
598 mapsize
= roundup(howmany(maxino
, NBBY
), TP_BSIZE
);
599 usedinomap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
600 dumpdirmap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
601 dumpinomap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
602 if (usedinomap
== NULL
|| dumpdirmap
== NULL
|| dumpinomap
== NULL
)
603 quit("out of memory allocating inode maps\n");
604 tapesize
= 2 * (howmany(mapsize
* sizeof(char), TP_BSIZE
) + 1);
606 nonodump
= spcl
.c_level
< honorlevel
;
609 msg("Label: %s\n", spcl
.c_label
);
612 msg("Compressing output at compression level %d\n",
617 (void)signal(SIGINFO
, statussig
);
621 msg("mapping (Pass I) [regular files]\n");
623 if (directory
[0] == 0)
624 anydirskipped
= mapfiles(maxino
, &tapesize
);
626 if (STAT(pathname
, &statbuf
) == -1) {
627 msg("File cannot be accessed (%s).\n", pathname
);
628 msg("The ENTIRE dump is aborted.\n");
631 filedev
= statbuf
.st_dev
;
632 if (!(statbuf
.st_mode
& S_IFDIR
)) /* is a file */
633 anydirskipped
= maponefile(maxino
, &tapesize
,
636 anydirskipped
= mapfilesfromdir(maxino
, &tapesize
,
642 /* check if file is available */
643 if (STAT(p
, &statbuf
) == -1) {
644 msg("File cannot be accessed (%s).\n", p
);
645 msg("The ENTIRE dump is aborted.\n");
648 /* check if file is on same unix partiton as the first
650 if (statbuf
.st_dev
!= filedev
) {
651 msg("Files are not on same file system (%s).\n", p
);
652 msg("The ENTIRE dump is aborted.\n");
655 /* check if file is a directory */
656 if (!(statbuf
.st_mode
& S_IFDIR
))
657 anydirskipped2
= maponefile(maxino
, &tapesize
,
658 p
+strlen(dt
->fs_file
));
660 /* read directory inodes.
661 * NOTE: nested directories are not recognized
662 * so inodes may be umped twice!
664 anydirskipped2
= mapfilesfromdir(maxino
, &tapesize
,
665 p
+strlen(dt
->fs_file
));
667 anydirskipped
= anydirskipped2
;
671 anydirskipped
= mapfiles(maxino
, &tapesize
);
675 msg("mapping (Pass II) [directories]\n");
676 while (anydirskipped
) {
677 anydirskipped
= mapdirs(maxino
, &tapesize
);
681 printf("%.0f\n", ((double)tapesize
+ 1 + ntrec
) * TP_BSIZE
);
683 } /* stop here for size estimate */
685 if (pipeout
|| unlimited
) {
686 tapesize
+= 1 + ntrec
; /* 1 map header + trailer blocks */
687 msg("estimated %ld tape blocks.\n", tapesize
);
692 fetapes
= (double) tapesize
/ blocksperfile
;
693 else if (cartridge
) {
694 /* Estimate number of tapes, assuming streaming stops at
695 the end of each block written, and not in mid-block.
696 Assume no erroneous blocks; this can be compensated
697 for with an artificially low tape size. */
699 ( (double) tapesize
/* blocks */
700 * TP_BSIZE
/* bytes/block */
701 * (1.0/density
) /* 0.1" / byte " */
703 (double) tapesize
/* blocks */
704 * (1.0/ntrec
) /* streaming-stops per block */
705 * 15.48 /* 0.1" / streaming-stop " */
706 ) * (1.0 / tsize
); /* tape / 0.1" " */
708 /* Estimate number of tapes, for old fashioned 9-track
710 int tenthsperirg
= (density
== 625) ? 3 : 7;
712 ( (double) tapesize
/* blocks */
713 * TP_BSIZE
/* bytes / block */
714 * (1.0/density
) /* 0.1" / byte " */
716 (double) tapesize
/* blocks */
717 * (1.0/ntrec
) /* IRG's / block */
718 * tenthsperirg
/* 0.1" / IRG " */
719 ) * (1.0 / tsize
); /* tape / 0.1" " */
721 etapes
= fetapes
; /* truncating assignment */
723 /* count the dumped inodes map on each additional tape */
724 tapesize
+= (etapes
- 1) *
725 (howmany(mapsize
* sizeof(char), TP_BSIZE
) + 1);
726 tapesize
+= etapes
+ ntrec
; /* headers + trailer blks */
727 msg("estimated %ld tape blocks on %3.2f tape(s).\n",
733 msg("writing QFA positions to %s\n", gTapeposfile
);
734 if ((gTapeposfd
= open(gTapeposfile
, O_RDWR
|O_CREAT
)) < 0)
735 quit("can't open tapeposfile\n");
736 /* print QFA-file header */
737 sprintf(gTps
, "%s\n%s\n%ld\n\n", QFA_MAGIC
, QFA_VERSION
, (unsigned long)spcl
.c_date
);
738 if (write(gTapeposfd
, gTps
, strlen(gTps
)) != strlen(gTps
))
739 quit("can't write tapeposfile\n");
740 sprintf(gTps
, "ino\ttapeno\ttapepos\n");
741 if (write(gTapeposfd
, gTps
, strlen(gTps
)) != strlen(gTps
))
742 quit("can't write tapeposfile\n");
747 * Allocate tape buffer.
751 "can't allocate tape buffers - try a smaller blocking factor.\n");
754 tstart_writing
= time(NULL
);
755 dumpmap(usedinomap
, TS_CLRI
, maxino
- 1);
757 msg("dumping (Pass III) [directories]\n");
758 dirty
= 0; /* XXX just to get gcc to shut up */
759 for (map
= dumpdirmap
, ino
= 1; ino
< maxino
; ino
++) {
760 if (((ino
- 1) % NBBY
) == 0) /* map is offset by 1 */
764 if ((dirty
& 1) == 0)
767 * Skip directory inodes deleted and maybe reallocated
770 if ((dp
->di_mode
& IFMT
) != IFDIR
)
774 * Skip directory inodes deleted and not yes reallocated...
776 if (dp
->di_nlink
== 0 || dp
->di_dtime
!= 0)
778 (void)dumpdirino(dp
, ino
);
780 (void)dumpino(dp
, ino
);
784 msg("dumping (Pass IV) [regular files]\n");
785 for (map
= dumpinomap
, ino
= 1; ino
< maxino
; ino
++) {
786 if (((ino
- 1) % NBBY
) == 0) /* map is offset by 1 */
790 if ((dirty
& 1) == 0)
793 * Skip inodes deleted and reallocated as directories.
796 if ((dp
->di_mode
& IFMT
) == IFDIR
)
800 * No need to check here for deleted and not yet reallocated
801 * inodes since this is done in dumpino().
804 (void)dumpino(dp
, ino
);
807 tend_writing
= time(NULL
);
808 spcl
.c_type
= TS_END
;
810 * Finish off the current tape record with trailer blocks, to ensure
811 * at least the data in the last partial record makes it to tape.
812 * Also make sure we write at least 1 trailer block.
814 for (i
= ntrec
- (spcl
.c_tapea
% ntrec
); i
; --i
)
815 writeheader(maxino
- 1);
820 msg("%ld tape blocks (%.2fMB)\n", spcl
.c_tapea
,
821 ((double)spcl
.c_tapea
* TP_BSIZE
/ 1048576));
823 msg("%ld tape blocks (%.2fMB) on %d volume(s)\n",
825 ((double)spcl
.c_tapea
* TP_BSIZE
/ 1048576),
828 /* report dump performance, avoid division by zero */
829 if (tend_writing
- tstart_writing
== 0)
830 msg("finished in less than a second\n");
832 msg("finished in %d seconds, throughput %d kBytes/sec\n",
833 tend_writing
- tstart_writing
,
834 spcl
.c_tapea
/ (tend_writing
- tstart_writing
));
837 msg("Date of this level %c dump: %s", level
,
838 spcl
.c_date
== 0 ? "the epoch\n" : ctime4(&spcl
.c_date
));
839 msg("Date this dump completed: %s", ctime(&tnow
));
841 msg("Average transfer rate: %ld kB/s\n", xferrate
/ tapeno
);
843 long tapekb
= bytes_written
/ 1024;
844 double rate
= .0005 + (double) spcl
.c_tapea
/ tapekb
;
845 msg("Wrote %ldkB uncompressed, %ldkB compressed, %1.3f:1\n",
846 spcl
.c_tapea
, tapekb
, rate
);
849 broadcast("DUMP IS DONE!\7\7\n");
850 msg("DUMP IS DONE\n");
853 return 0; /* gcc - shut up */
859 char white
[MAXPATHLEN
];
860 const char *ext2ver
, *ext2date
;
862 memset(white
, ' ', MAXPATHLEN
);
863 white
[MIN(strlen(__progname
), MAXPATHLEN
- 1)] = '\0';
866 ext2fs_get_library_version(&ext2ver
, &ext2date
);
867 fprintf(stderr
, "%s %s (using libext2fs %s of %s)\n",
868 __progname
, _DUMP_VERSION
, ext2ver
, ext2date
);
870 fprintf(stderr
, "%s %s\n", __progname
, _DUMP_VERSION
);
873 "usage:\t%s [-0123456789ac"
878 "] [-B records] [-b blocksize] [-d density]\n"
879 "\t%s [-e inode#] [-f file] [-h level] "
890 __progname
, white
, white
, __progname
);
895 * Pick up a numeric argument. It must be nonnegative and in the given
896 * range (except that a vmax of 0 means unlimited).
899 numarg(const char *meaning
, long vmin
, long vmax
)
904 val
= strtol(optarg
, &p
, 10);
906 errx(X_STARTUP
, "illegal %s -- %s", meaning
, optarg
);
907 if (val
< vmin
|| (vmax
&& val
> vmax
))
908 errx(X_STARTUP
, "%s must be between %ld and %ld", meaning
, vmin
, vmax
);
923 quit("Signal on pipe: cannot recover\n");
924 msg("Rewriting attempted as response to unknown signal: %d.\n", signo
);
925 (void)fflush(stderr
);
926 (void)fflush(stdout
);
931 msg("SIGSEGV: ABORTING!\n");
932 (void)signal(SIGSEGV
, SIG_DFL
);
933 (void)kill(0, SIGSEGV
);
939 rawname(const char *cp
)
943 #else /* __linux__ */
944 static char rawbuf
[MAXPATHLEN
];
945 char *dp
= strrchr(cp
, '/');
949 (void)strncpy(rawbuf
, cp
, min(dp
-cp
, MAXPATHLEN
- 1));
950 rawbuf
[min(dp
-cp
, MAXPATHLEN
-1)] = '\0';
951 (void)strncat(rawbuf
, "/r", MAXPATHLEN
- 1 - strlen(rawbuf
));
952 (void)strncat(rawbuf
, dp
+ 1, MAXPATHLEN
- 1 - strlen(rawbuf
));
954 #endif /* __linux__ */
959 * Change set of key letters and ordered arguments into something
960 * getopt(3) will like.
963 obsolete(int *argcp
, char **argvp
[])
966 char *ap
, **argv
, *flagsp
=NULL
, **nargv
, *p
=NULL
;
972 /* Return if no arguments or first argument has leading dash. */
974 if (argc
== 1 || *ap
== '-')
977 /* Allocate space for new arguments. */
978 if ((*argvp
= nargv
= malloc((argc
+ 1) * sizeof(char *))) == NULL
||
979 (p
= flagsp
= malloc(strlen(ap
) + 2)) == NULL
)
980 err(X_STARTUP
, "malloc new args");
985 for (flags
= 0; *ap
; ++ap
) {
999 warnx("option requires an argument -- %c", *ap
);
1002 if ((nargv
[0] = malloc(strlen(*argv
) + 2 + 1)) == NULL
)
1003 err(X_STARTUP
, "malloc arg");
1006 (void)strcpy(&nargv
[0][2], *argv
);
1020 /* Terminate flags. */
1026 /* Copy remaining arguments. */
1027 while ((*nargv
++ = *argv
++));
1029 /* Update argument count. */
1030 *argcp
= nargv
- *argvp
- 1;