]>
git.wh0rd.org - dump.git/blob - dump/main.c
0c896738608f9e8b318db313cd31a7a6262f84ab
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.47 2001/04/27 12:23:23 stelian Exp $";
49 #include <compaterr.h>
58 #include <sys/param.h>
61 #include <linux/ext2_fs.h>
62 #include <ext2fs/ext2fs.h>
65 #include <bsdcompat.h>
67 #include <sys/vnode.h>
69 #include <ufs/inode.h>
72 #include <ufs/ufs/dinode.h>
73 #include <ufs/ffs/fs.h>
76 #include <protocols/dumprestore.h>
79 #include "pathnames.h"
83 #define SBOFF (SBLOCK * DEV_BSIZE)
86 int notify
= 0; /* notify operator flag */
87 int blockswritten
= 0; /* number of blocks written on current tape */
88 int tapeno
= 0; /* current tape number */
89 int density
= 0; /* density in bytes/0.1" " <- this is for hilit19 */
90 int ntrec
= NTREC
; /* # tape blocks in each tape record */
91 int cartridge
= 0; /* Assume non-cartridge tape */
93 int tapepos
= 0; /* assume no QFA tapeposition needed by user */
95 int dokerberos
= 0; /* Use Kerberos authentication */
96 long dev_bsize
= 1; /* recalculated below */
97 long blocksperfile
; /* output blocks per file */
98 char *host
= NULL
; /* remote host (if any) */
99 int sizest
= 0; /* return size estimate only */
100 int compressed
= 0; /* use zlib to compress the output, compress level 1-9 */
101 long long bytes_written
= 0; /* total bytes written */
102 long uncomprblks
= 0;/* uncompressed blocks written */
108 int maxbsize
= 64*1024; /* XXX MAXBSIZE from sys/param.h */
109 static long numarg
__P((const char *, long, long));
110 static void obsolete
__P((int *, char **[]));
111 static void usage
__P((void));
113 dump_ino_t iexclude_list
[IEXCLUDE_MAXNUM
];/* the inode exclude list */
114 int iexclude_num
= 0; /* number of elements in the list */
117 main(int argc
, char *argv
[])
119 register dump_ino_t ino
;
121 register struct dinode
*dp
;
122 register struct fstab
*dt
;
125 int i
, anydirskipped
, bflag
= 0, Tflag
= 0, honorlevel
= 1;
131 char directory
[MAXPATHLEN
];
132 char pathname
[MAXPATHLEN
];
137 spcl
.c_label
[0] = '\0';
138 spcl
.c_date
= time(NULL
);
141 __progname
= argv
[0];
143 initialize_ext2_error_table();
146 tsize
= 0; /* Default later, based on 'c' option for cart tapes */
149 if ((tapeprefix
= getenv("TAPE")) == NULL
)
150 tapeprefix
= _PATH_DEFTAPE
;
151 dumpdates
= _PATH_DUMPDATES
;
152 if (TP_BSIZE
/ DEV_BSIZE
== 0 || TP_BSIZE
% DEV_BSIZE
!= 0)
153 quit("TP_BSIZE must be a multiple of DEV_BSIZE\n");
159 obsolete(&argc
, &argv
);
165 while ((ch
= getopt(argc
, argv
,
166 "0123456789aB:b:cd:e:f:F:h:L:"
181 case '0': case '1': case '2': case '3': case '4':
182 case '5': case '6': case '7': case '8': case '9':
186 case 'a': /* `auto-size', Write to EOM. */
190 case 'B': /* blocks per output file */
192 blocksperfile
= numarg("number of blocks per file",
196 case 'b': /* blocks per tape write */
197 ntrec
= numarg("number of blocks per write",
199 if (ntrec
> maxbsize
/1024) {
200 msg("Please choose a blocksize <= %dkB\n",
202 msg("The ENTIRE dump is aborted.\n");
208 case 'c': /* Tape is cart. not 9-track */
213 case 'd': /* density, in bits per inch */
215 density
= numarg("density", 10L, 327670L) / 10;
216 if (density
>= 625 && !bflag
)
217 ntrec
= HIGHDENSITYTREC
;
221 case 'e': /* exclude an inode */
222 if (iexclude_num
== IEXCLUDE_MAXNUM
) {
223 msg("Too many -e options\n");
224 msg("The ENTIRE dump is aborted.\n");
227 iexclude_list
[iexclude_num
++] = numarg("inode to exclude",0L,0L);
228 if (iexclude_list
[iexclude_num
-1] <= ROOTINO
) {
229 msg("Cannot exclude inode %ld\n", (long)iexclude_list
[iexclude_num
-1]);
230 msg("The ENTIRE dump is aborted.\n");
233 msg("Added %d to exclude list\n",
234 iexclude_list
[iexclude_num
-1]);
237 case 'f': /* output file */
241 case 'F': /* end of tape script */
246 honorlevel
= numarg("honor level", 0L, 10L);
257 * Note that although there are LBLSIZE characters,
258 * the last must be '\0', so the limit on strlen()
259 * is really LBLSIZE-1.
261 strncpy(spcl
.c_label
, optarg
, LBLSIZE
);
262 spcl
.c_label
[LBLSIZE
-1] = '\0';
263 if (strlen(optarg
) > LBLSIZE
-1) {
265 "WARNING Label `%s' is larger than limit of %d characters.\n",
267 msg("WARNING: Using truncated label `%s'.\n",
272 case 'M': /* multi-volume flag */
276 case 'n': /* notify operators */
281 case 'Q': /* create tapeposfile */
282 gTapeposfile
= optarg
;
287 case 's': /* tape size, feet */
289 tsize
= numarg("tape size", 1L, 0L) * 12 * 10;
293 sizest
= 1; /* return size estimate only */
296 case 'T': /* time of last dump */
297 spcl
.c_ddate
= unctime(optarg
);
298 if (spcl
.c_ddate
< 0) {
299 msg("bad time \"%s\"\n", optarg
);
300 msg("The ENTIRE dump is aborted.\n");
307 case 'u': /* update dumpdates */
311 case 'W': /* what to do */
314 exit(X_FINOK
); /* do nothing else */
319 compressed
= numarg("compress level", 1L, 9L);
321 #endif /* HAVE_ZLIB */
330 msg("Must specify disk or filesystem\n");
331 msg("The ENTIRE dump is aborted.\n");
335 if (strlen(diskparam
) >= MAXPATHLEN
) {
336 msg("Disk or filesystem name too long: %s\n", diskparam
);
337 msg("The ENTIRE dump is aborted.\n");
341 if (Tflag
&& uflag
) {
342 msg("You cannot use the T and u flags together.\n");
343 msg("The ENTIRE dump is aborted.\n");
346 if (strcmp(tapeprefix
, "-") == 0) {
348 tapeprefix
= "standard output";
352 blocksperfile
= blocksperfile
/ ntrec
* ntrec
; /* round down */
353 else if (!unlimited
) {
355 * Determine how to default tape size and density
358 * 9-track 1600 bpi (160 bytes/.1") 2300 ft.
359 * 9-track 6250 bpi (625 bytes/.1") 2300 ft.
360 * cartridge 8000 bpi (100 bytes/.1") 1700 ft.
362 * hilit19 hits again: "
365 density
= cartridge
? 100 : 160;
367 tsize
= cartridge
? 1700L*120L : 2300L*120L;
370 if (strchr(tapeprefix
, ':')) {
372 tapeprefix
= strchr(host
, ':');
373 *tapeprefix
++ = '\0';
375 if (index(tapeprefix
, '\n')) {
376 msg("invalid characters in tape\n");
377 msg("The ENTIRE dump is aborted.\n");
380 if (rmthost(host
) == 0)
383 msg("remote dump not enabled\n");
384 msg("The ENTIRE dump is aborted.\n");
388 (void)setuid(getuid()); /* rmthost() is the only reason to be setuid */
390 if (signal(SIGHUP
, SIG_IGN
) != SIG_IGN
)
392 if (signal(SIGTRAP
, SIG_IGN
) != SIG_IGN
)
393 signal(SIGTRAP
, sig
);
394 if (signal(SIGFPE
, SIG_IGN
) != SIG_IGN
)
396 if (signal(SIGBUS
, SIG_IGN
) != SIG_IGN
)
398 if (signal(SIGSEGV
, SIG_IGN
) != SIG_IGN
)
399 signal(SIGSEGV
, sig
);
400 if (signal(SIGTERM
, SIG_IGN
) != SIG_IGN
)
401 signal(SIGTERM
, sig
);
402 if (signal(SIGINT
, interrupt
) == SIG_IGN
)
403 signal(SIGINT
, SIG_IGN
);
404 set_operators(); /* /etc/group snarfed */
405 getfstab(); /* /etc/fstab snarfed */
408 * disk may end in / and this can confuse
411 i
= strlen(diskparam
) - 1;
412 if (i
> 1 && diskparam
[i
] == '/')
415 disk
= get_device_name(diskparam
);
416 if (!disk
) { /* null means the disk is some form
417 of LABEL= or UID= but it was not
419 msg("Cannot find a disk having %s\n", diskparam
);
420 msg("The ENTIRE dump is aborted.\n");
424 * disk can be either the full special file name,
425 * the suffix of the special file name,
426 * the special name missing the leading '/',
427 * the file system name with or without the leading '/'.
429 if ((dt
= fstabsearch(disk
)) != NULL
) {
430 /* if found then only one parameter (i.e. partition)
433 (void)fprintf(stderr
, "Unknown arguments to dump:");
435 (void)fprintf(stderr
, " %s", *argv
++);
436 (void)fprintf(stderr
, "\n");
437 msg("The ENTIRE dump is aborted.\n");
440 disk
= rawname(dt
->fs_spec
);
441 (void)strncpy(spcl
.c_dev
, dt
->fs_spec
, NAMELEN
);
442 (void)strncpy(spcl
.c_filesys
, dt
->fs_file
, NAMELEN
);
446 if (realpath(disk
, pathname
) == NULL
)
448 strcpy(pathname
, disk
);
450 * The argument could be now a mountpoint of
451 * a filesystem specified in fstab. Search for it.
453 if ((dt
= fstabsearch(pathname
)) != NULL
) {
454 disk
= rawname(dt
->fs_spec
);
455 (void)strncpy(spcl
.c_dev
, dt
->fs_spec
, NAMELEN
);
456 (void)strncpy(spcl
.c_filesys
, dt
->fs_file
, NAMELEN
);
459 * The argument was not found in the fstab
460 * assume that this is a subtree and search for it
462 dt
= fstabsearchdir(pathname
, directory
);
464 char name
[MAXPATHLEN
];
465 (void)strncpy(spcl
.c_dev
, dt
->fs_spec
, NAMELEN
);
466 (void)snprintf(name
, sizeof(name
), "%s (dir %s)",
467 dt
->fs_file
, directory
);
468 (void)strncpy(spcl
.c_filesys
, name
, NAMELEN
);
469 disk
= rawname(dt
->fs_spec
);
471 (void)strncpy(spcl
.c_dev
, disk
, NAMELEN
);
472 (void)strncpy(spcl
.c_filesys
, "an unlisted file system",
477 (void)strncpy(spcl
.c_dev
, disk
, NAMELEN
);
478 (void)strncpy(spcl
.c_filesys
, "an unlisted file system",
483 if (directory
[0] != 0) {
485 msg("Only level 0 dumps are allowed on a subdirectory\n");
486 msg("The ENTIRE dump is aborted.\n");
490 msg("You can't update the dumpdates file when dumping a subdirectory\n");
491 msg("The ENTIRE dump is aborted.\n");
495 spcl
.c_dev
[NAMELEN
-1] = '\0';
496 spcl
.c_filesys
[NAMELEN
-1] = '\0';
497 (void)gethostname(spcl
.c_host
, NAMELEN
);
498 spcl
.c_host
[NAMELEN
-1] = '\0';
499 spcl
.c_level
= level
- '0';
500 spcl
.c_type
= TS_TAPE
;
502 getdumptime(uflag
); /* dumpdates snarfed */
504 if (spcl
.c_ddate
== 0 && spcl
.c_level
) {
505 msg("WARNING: There is no inferior level dump on this filesystem\n");
506 msg("WARNING: Assuming a level 0 dump by default\n");
512 snprintf(tape
, MAXPATHLEN
, "%s%03d", tapeprefix
, tapeno
+ 1);
514 strncpy(tape
, tapeprefix
, MAXPATHLEN
);
515 tape
[MAXPATHLEN
- 1] = '\0';
519 msg("Date of this level %c dump: %s", level
,
520 ctime4(&spcl
.c_date
));
522 msg("Date of last level %c dump: %s", lastlevel
,
523 ctime4(&spcl
.c_ddate
));
524 msg("Dumping %s (%s) ", disk
, spcl
.c_filesys
);
526 msgtail("to %s on host %s\n", tape
, host
);
528 msgtail("to %s\n", tape
);
529 } /* end of size estimate */
532 retval
= dump_fs_open(disk
, &fs
);
534 com_err(disk
, retval
, "while opening filesystem");
535 if (retval
== EXT2_ET_REV_TOO_HIGH
)
536 msg("Get a newer version of dump!\n");
537 msg("The ENTIRE dump is aborted.\n");
540 if (fs
->super
->s_rev_level
> DUMP_CURRENT_REV
) {
541 com_err(disk
, retval
, "while opening filesystem");
542 msg("Get a newer version of dump!\n");
543 msg("The ENTIRE dump is aborted.\n");
546 if ((diskfd
= open(disk
, O_RDONLY
)) < 0) {
547 msg("Cannot open %s\n", disk
);
548 msg("The ENTIRE dump is aborted.\n");
551 /* if no user label specified, use ext2 filesystem label if available */
552 if (spcl
.c_label
[0] == '\0') {
554 if ( (lbl
= get_device_label(disk
)) != NULL
) {
555 strncpy(spcl
.c_label
, lbl
, LBLSIZE
);
556 spcl
.c_label
[LBLSIZE
-1] = '\0';
559 strcpy(spcl
.c_label
, "none"); /* safe strcpy. */
562 dev_bsize
= DEV_BSIZE
;
563 dev_bshift
= ffs(dev_bsize
) - 1;
564 if (dev_bsize
!= (1 << dev_bshift
))
565 quit("dev_bsize (%d) is not a power of 2", dev_bsize
);
566 tp_bshift
= ffs(TP_BSIZE
) - 1;
567 if (TP_BSIZE
!= (1 << tp_bshift
))
568 quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE
);
569 maxino
= fs
->super
->s_inodes_count
;
571 spcl
.c_flags
|= DR_NEWINODEFMT
;
573 #else /* __linux __*/
574 if ((diskfd
= open(disk
, O_RDONLY
)) < 0) {
575 msg("Cannot open %s\n", disk
);
576 msg("The ENTIRE dump is aborted.\n");
580 sblock
= (struct fs
*)sblock_buf
;
581 bread(SBOFF
, (char *) sblock
, SBSIZE
);
582 if (sblock
->fs_magic
!= FS_MAGIC
)
583 quit("bad sblock magic number\n");
584 dev_bsize
= sblock
->fs_fsize
/ fsbtodb(sblock
, 1);
585 dev_bshift
= ffs(dev_bsize
) - 1;
586 if (dev_bsize
!= (1 << dev_bshift
))
587 quit("dev_bsize (%d) is not a power of 2", dev_bsize
);
588 tp_bshift
= ffs(TP_BSIZE
) - 1;
589 if (TP_BSIZE
!= (1 << tp_bshift
))
590 quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE
);
592 if (sblock
->fs_inodefmt
>= FS_44INODEFMT
)
593 spcl
.c_flags
|= DR_NEWINODEFMT
;
595 maxino
= sblock
->fs_ipg
* sblock
->fs_ncg
;
596 #endif /* __linux__ */
597 mapsize
= roundup(howmany(maxino
, NBBY
), TP_BSIZE
);
598 usedinomap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
599 dumpdirmap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
600 dumpinomap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
601 if (usedinomap
== NULL
|| dumpdirmap
== NULL
|| dumpinomap
== NULL
)
602 quit("out of memory allocating inode maps\n");
603 tapesize
= 2 * (howmany(mapsize
* sizeof(char), TP_BSIZE
) + 1);
605 nonodump
= spcl
.c_level
< honorlevel
;
608 msg("Label: %s\n", spcl
.c_label
);
611 msg("Compressing output at compression level %d\n",
616 (void)signal(SIGINFO
, statussig
);
620 msg("mapping (Pass I) [regular files]\n");
622 if (directory
[0] == 0)
623 anydirskipped
= mapfiles(maxino
, &tapesize
);
625 if (stat(pathname
, &statbuf
) == -1) {
626 msg("File cannot be accessed (%s).\n", pathname
);
627 msg("The ENTIRE dump is aborted.\n");
630 filedev
= statbuf
.st_dev
;
631 if (!(statbuf
.st_mode
& S_IFDIR
)) /* is a file */
632 anydirskipped
= maponefile(maxino
, &tapesize
,
635 anydirskipped
= mapfilesfromdir(maxino
, &tapesize
,
641 /* check if file is available */
642 if (stat(p
, &statbuf
) == -1) {
643 msg("File cannot be accessed (%s).\n", p
);
644 msg("The ENTIRE dump is aborted.\n");
647 /* check if file is on same unix partiton as the first
649 if (statbuf
.st_dev
!= filedev
) {
650 msg("Files are not on same file system (%s).\n", p
);
651 msg("The ENTIRE dump is aborted.\n");
654 /* check if file is a directory */
655 if (!(statbuf
.st_mode
& S_IFDIR
))
656 anydirskipped2
= maponefile(maxino
, &tapesize
,
657 p
+strlen(dt
->fs_file
));
659 /* read directory inodes.
660 * NOTE: nested directories are not recognized
661 * so inodes may be umped twice!
663 anydirskipped2
= mapfilesfromdir(maxino
, &tapesize
,
664 p
+strlen(dt
->fs_file
));
666 anydirskipped
= anydirskipped2
;
670 anydirskipped
= mapfiles(maxino
, &tapesize
);
674 msg("mapping (Pass II) [directories]\n");
675 while (anydirskipped
) {
676 anydirskipped
= mapdirs(maxino
, &tapesize
);
680 printf("%.0f\n", ((double)tapesize
+ 1 + ntrec
) * TP_BSIZE
);
682 } /* stop here for size estimate */
684 if (pipeout
|| unlimited
) {
685 tapesize
+= 1 + ntrec
; /* 1 map header + trailer blocks */
686 msg("estimated %ld tape blocks.\n", tapesize
);
691 fetapes
= (double) tapesize
/ blocksperfile
;
692 else if (cartridge
) {
693 /* Estimate number of tapes, assuming streaming stops at
694 the end of each block written, and not in mid-block.
695 Assume no erroneous blocks; this can be compensated
696 for with an artificially low tape size. */
698 ( (double) tapesize
/* blocks */
699 * TP_BSIZE
/* bytes/block */
700 * (1.0/density
) /* 0.1" / byte " */
702 (double) tapesize
/* blocks */
703 * (1.0/ntrec
) /* streaming-stops per block */
704 * 15.48 /* 0.1" / streaming-stop " */
705 ) * (1.0 / tsize
); /* tape / 0.1" " */
707 /* Estimate number of tapes, for old fashioned 9-track
709 int tenthsperirg
= (density
== 625) ? 3 : 7;
711 ( (double) tapesize
/* blocks */
712 * TP_BSIZE
/* bytes / block */
713 * (1.0/density
) /* 0.1" / byte " */
715 (double) tapesize
/* blocks */
716 * (1.0/ntrec
) /* IRG's / block */
717 * tenthsperirg
/* 0.1" / IRG " */
718 ) * (1.0 / tsize
); /* tape / 0.1" " */
720 etapes
= fetapes
; /* truncating assignment */
722 /* count the dumped inodes map on each additional tape */
723 tapesize
+= (etapes
- 1) *
724 (howmany(mapsize
* sizeof(char), TP_BSIZE
) + 1);
725 tapesize
+= etapes
+ ntrec
; /* headers + trailer blks */
726 msg("estimated %ld tape blocks on %3.2f tape(s).\n",
732 msg("writing QFA positions to %s\n", gTapeposfile
);
733 if ((gTapeposfd
= open(gTapeposfile
, O_RDWR
|O_CREAT
)) < 0)
734 quit("can't open tapeposfile\n");
735 /* print QFA-file header */
736 sprintf(gTps
, "%s\n%s\n%ld\n\n", QFA_MAGIC
, QFA_VERSION
, (unsigned long)spcl
.c_date
);
737 if (write(gTapeposfd
, gTps
, strlen(gTps
)) != strlen(gTps
))
738 quit("can't write tapeposfile\n");
739 sprintf(gTps
, "ino\ttapeno\ttapepos\n");
740 if (write(gTapeposfd
, gTps
, strlen(gTps
)) != strlen(gTps
))
741 quit("can't write tapeposfile\n");
746 * Allocate tape buffer.
750 "can't allocate tape buffers - try a smaller blocking factor.\n");
753 tstart_writing
= time(NULL
);
754 dumpmap(usedinomap
, TS_CLRI
, maxino
- 1);
756 msg("dumping (Pass III) [directories]\n");
757 dirty
= 0; /* XXX just to get gcc to shut up */
758 for (map
= dumpdirmap
, ino
= 1; ino
< maxino
; ino
++) {
759 if (((ino
- 1) % NBBY
) == 0) /* map is offset by 1 */
763 if ((dirty
& 1) == 0)
766 * Skip directory inodes deleted and maybe reallocated
769 if ((dp
->di_mode
& IFMT
) != IFDIR
)
773 * Skip directory inodes deleted and not yes reallocated...
775 if (dp
->di_nlink
== 0 || dp
->di_dtime
!= 0)
777 (void)dumpdirino(dp
, ino
);
779 (void)dumpino(dp
, ino
);
783 msg("dumping (Pass IV) [regular files]\n");
784 for (map
= dumpinomap
, ino
= 1; ino
< maxino
; ino
++) {
785 if (((ino
- 1) % NBBY
) == 0) /* map is offset by 1 */
789 if ((dirty
& 1) == 0)
792 * Skip inodes deleted and reallocated as directories.
795 if ((dp
->di_mode
& IFMT
) == IFDIR
)
799 * No need to check here for deleted and not yet reallocated
800 * inodes since this is done in dumpino().
803 (void)dumpino(dp
, ino
);
806 tend_writing
= time(NULL
);
807 spcl
.c_type
= TS_END
;
809 * Finish off the current tape record with trailer blocks, to ensure
810 * at least the data in the last partial record makes it to tape.
811 * Also make sure we write at least 1 trailer block.
813 for (i
= ntrec
- (spcl
.c_tapea
% ntrec
); i
; --i
)
814 writeheader(maxino
- 1);
819 msg("%ld tape blocks (%.2fMB)\n", spcl
.c_tapea
,
820 ((double)spcl
.c_tapea
* TP_BSIZE
/ 1048576));
822 msg("%ld tape blocks (%.2fMB) on %d volume(s)\n",
824 ((double)spcl
.c_tapea
* TP_BSIZE
/ 1048576),
827 /* report dump performance, avoid division by zero */
828 if (tend_writing
- tstart_writing
== 0)
829 msg("finished in less than a second\n");
831 msg("finished in %d seconds, throughput %d kBytes/sec\n",
832 tend_writing
- tstart_writing
,
833 spcl
.c_tapea
/ (tend_writing
- tstart_writing
));
836 msg("Date of this level %c dump: %s", level
,
837 spcl
.c_date
== 0 ? "the epoch\n" : ctime4(&spcl
.c_date
));
838 msg("Date this dump completed: %s", ctime(&tnow
));
840 msg("Average transfer rate: %ld kB/s\n", xferrate
/ tapeno
);
842 long tapekb
= bytes_written
/ 1024;
843 double rate
= .0005 + (double) spcl
.c_tapea
/ tapekb
;
844 msg("Wrote %ldkB uncompressed, %ldkB compressed, %1.3f:1\n",
845 spcl
.c_tapea
, tapekb
, rate
);
848 broadcast("DUMP IS DONE!\7\7\n");
849 msg("DUMP IS DONE\n");
852 return 0; /* gcc - shut up */
858 char white
[MAXPATHLEN
];
859 const char *ext2ver
, *ext2date
;
861 memset(white
, ' ', MAXPATHLEN
);
862 white
[MIN(strlen(__progname
), MAXPATHLEN
- 1)] = '\0';
865 ext2fs_get_library_version(&ext2ver
, &ext2date
);
866 fprintf(stderr
, "%s %s (using libext2fs %s of %s)\n",
867 __progname
, _DUMP_VERSION
, ext2ver
, ext2date
);
869 fprintf(stderr
, "%s %s\n", __progname
, _DUMP_VERSION
);
872 "usage:\t%s [-0123456789ac"
877 "] [-B records] [-b blocksize] [-d density]\n"
878 "\t%s [-e inode#] [-f file] [-h level] "
889 __progname
, white
, white
, __progname
);
894 * Pick up a numeric argument. It must be nonnegative and in the given
895 * range (except that a vmax of 0 means unlimited).
898 numarg(const char *meaning
, long vmin
, long vmax
)
903 val
= strtol(optarg
, &p
, 10);
905 errx(X_STARTUP
, "illegal %s -- %s", meaning
, optarg
);
906 if (val
< vmin
|| (vmax
&& val
> vmax
))
907 errx(X_STARTUP
, "%s must be between %ld and %ld", meaning
, vmin
, vmax
);
922 quit("Signal on pipe: cannot recover\n");
923 msg("Rewriting attempted as response to unknown signal: %d.\n", signo
);
924 (void)fflush(stderr
);
925 (void)fflush(stdout
);
930 msg("SIGSEGV: ABORTING!\n");
931 (void)signal(SIGSEGV
, SIG_DFL
);
932 (void)kill(0, SIGSEGV
);
938 rawname(const char *cp
)
942 #else /* __linux__ */
943 static char rawbuf
[MAXPATHLEN
];
944 char *dp
= strrchr(cp
, '/');
948 (void)strncpy(rawbuf
, cp
, min(dp
-cp
, MAXPATHLEN
- 1));
949 rawbuf
[min(dp
-cp
, MAXPATHLEN
-1)] = '\0';
950 (void)strncat(rawbuf
, "/r", MAXPATHLEN
- 1 - strlen(rawbuf
));
951 (void)strncat(rawbuf
, dp
+ 1, MAXPATHLEN
- 1 - strlen(rawbuf
));
953 #endif /* __linux__ */
958 * Change set of key letters and ordered arguments into something
959 * getopt(3) will like.
962 obsolete(int *argcp
, char **argvp
[])
965 char *ap
, **argv
, *flagsp
=NULL
, **nargv
, *p
=NULL
;
971 /* Return if no arguments or first argument has leading dash. */
973 if (argc
== 1 || *ap
== '-')
976 /* Allocate space for new arguments. */
977 if ((*argvp
= nargv
= malloc((argc
+ 1) * sizeof(char *))) == NULL
||
978 (p
= flagsp
= malloc(strlen(ap
) + 2)) == NULL
)
979 err(X_STARTUP
, "malloc new args");
984 for (flags
= 0; *ap
; ++ap
) {
998 warnx("option requires an argument -- %c", *ap
);
1001 if ((nargv
[0] = malloc(strlen(*argv
) + 2 + 1)) == NULL
)
1002 err(X_STARTUP
, "malloc arg");
1005 (void)strcpy(&nargv
[0][2], *argv
);
1019 /* Terminate flags. */
1025 /* Copy remaining arguments. */
1026 while ((*nargv
++ = *argv
++));
1028 /* Update argument count. */
1029 *argcp
= nargv
- *argvp
- 1;