]>
git.wh0rd.org - dump.git/blob - dump/main.c
0b4270eb19e4279c275c110b91adacd9daa57752
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.64 2002/01/10 09:02:54 stelian Exp $";
48 #include <compatlfs.h>
50 #include <compaterr.h>
59 #include <sys/param.h>
64 #ifdef HAVE_EXT2FS_EXT2_FS_H
65 #include <ext2fs/ext2_fs.h>
67 #include <linux/ext2_fs.h>
69 #include <ext2fs/ext2fs.h>
71 #include <bsdcompat.h>
73 #include <sys/vnode.h>
75 #include <ufs/inode.h>
78 #include <ufs/ufs/dinode.h>
79 #include <ufs/ffs/fs.h>
82 #include <protocols/dumprestore.h>
85 #include "pathnames.h"
89 #define SBOFF (SBLOCK * DEV_BSIZE)
93 * Dump maps used to describe what is to be dumped.
95 int mapsize
; /* size of the state maps */
96 char *usedinomap
; /* map of allocated inodes */
97 char *dumpdirmap
; /* map of directories to be dumped */
98 char *dumpinomap
; /* map of files to be dumped */
100 const char *disk
; /* name of the disk file */
101 char tape
[MAXPATHLEN
];/* name of the tape file */
102 char *tapeprefix
; /* prefix of the tape file */
103 char *dumpdates
; /* name of the file containing dump date information*/
104 char lastlevel
; /* dump level of previous dump */
105 char level
; /* dump level of this dump */
106 int bzipflag
; /* compression is done using bzlib */
107 int uflag
; /* update flag */
108 int Mflag
; /* multi-volume flag */
109 int qflag
; /* quit on errors flag */
110 int breademax
= 32; /* maximum number of bread errors before we quit */
111 char *eot_script
; /* end of volume script fiag */
112 int diskfd
; /* disk file descriptor */
113 int tapefd
; /* tape file descriptor */
114 int pipeout
; /* true => output to standard output */
115 int fifoout
; /* true => output to fifo */
116 dump_ino_t curino
; /* current inumber; used globally */
117 int newtape
; /* new tape flag */
118 int density
; /* density in 0.1" units */
119 long tapesize
; /* estimated tape size, blocks */
120 long tsize
; /* tape size in 0.1" units */
121 long asize
; /* number of 0.1" units written on current tape */
122 int etapes
; /* estimated number of tapes */
123 int nonodump
; /* if set, do not honor UF_NODUMP user flags */
124 int unlimited
; /* if set, write to end of medium */
125 int compressed
; /* if set, dump is to be compressed */
126 long long bytes_written
;/* total bytes written to tape */
127 long uncomprblks
; /* uncompressed blocks written to tape */
128 int notify
; /* notify operator flag */
129 int blockswritten
; /* number of blocks written on current tape */
130 int tapeno
; /* current tape number */
131 time_t tstart_writing
; /* when started writing the first tape block */
132 time_t tend_writing
; /* after writing the last tape block */
136 struct fs
*sblock
; /* the file system super block */
137 char sblock_buf
[MAXBSIZE
];
139 long xferrate
; /* averaged transfer rate of all volumes */
140 long dev_bsize
; /* block size of underlying disk device */
141 int dev_bshift
; /* log2(dev_bsize) */
142 int tp_bshift
; /* log2(TP_BSIZE) */
148 int32_t gThisDumpDate
;
151 struct dumptime
*dthead
; /* head of the list version */
152 int nddates
; /* number of records (might be zero) */
153 int ddates_in
; /* we have read the increment file */
154 struct dumpdates
**ddatev
; /* the arrayfied version */
156 int notify
= 0; /* notify operator flag */
157 int blockswritten
= 0; /* number of blocks written on current tape */
158 int tapeno
= 0; /* current tape number */
159 int density
= 0; /* density in bytes/0.1" " <- this is for hilit19 */
160 int ntrec
= NTREC
; /* # tape blocks in each tape record */
161 int cartridge
= 0; /* Assume non-cartridge tape */
163 int tapepos
= 0; /* assume no QFA tapeposition needed by user */
165 int dokerberos
= 0; /* Use Kerberos authentication */
166 long dev_bsize
= 1; /* recalculated below */
167 long blocksperfile
; /* output blocks per file */
168 char *host
= NULL
; /* remote host (if any) */
169 int sizest
= 0; /* return size estimate only */
170 int compressed
= 0; /* use zlib to compress the output, compress level 1-9 */
171 long long bytes_written
= 0; /* total bytes written */
172 long uncomprblks
= 0;/* uncompressed blocks written */
178 int maxbsize
= 64*1024; /* XXX MAXBSIZE from sys/param.h */
179 static long numarg
__P((const char *, long, long));
180 static void obsolete
__P((int *, char **[]));
181 static void usage
__P((void));
182 static void do_exclude_from_file
__P((char *));
183 static void do_exclude_ino_str
__P((char *));
184 static void incompat_flags
__P((int, char, char));
186 static dump_ino_t iexclude_list
[IEXCLUDE_MAXNUM
];/* the inode exclude list */
187 static int iexclude_num
= 0; /* number of elements in the list */
190 main(int argc
, char *argv
[])
192 register dump_ino_t ino
;
194 register struct dinode
*dp
;
195 register struct fstab
*dt
;
198 int i
, anydirskipped
;
199 int aflag
= 0, bflag
= 0, Tflag
= 0, honorlevel
= 1;
205 char directory
[MAXPATHLEN
];
206 char pathname
[MAXPATHLEN
];
211 spcl
.c_label
[0] = '\0';
212 spcl
.c_date
= time(NULL
);
215 __progname
= argv
[0];
217 initialize_ext2_error_table();
220 tsize
= 0; /* Default later, based on 'c' option for cart tapes */
223 if ((tapeprefix
= getenv("TAPE")) == NULL
)
224 tapeprefix
= _PATH_DEFTAPE
;
225 dumpdates
= _PATH_DUMPDATES
;
226 if (TP_BSIZE
/ DEV_BSIZE
== 0 || TP_BSIZE
% DEV_BSIZE
!= 0)
227 quit("TP_BSIZE must be a multiple of DEV_BSIZE\n");
233 obsolete(&argc
, &argv
);
239 while ((ch
= getopt(argc
, argv
,
240 "0123456789aB:b:cd:e:E:f:F:h:I:"
259 case '0': case '1': case '2': case '3': case '4':
260 case '5': case '6': case '7': case '8': case '9':
264 case 'a': /* `auto-size', Write to EOM. */
269 case 'B': /* blocks per output file */
271 blocksperfile
= numarg("number of blocks per file",
275 case 'b': /* blocks per tape write */
276 ntrec
= numarg("number of blocks per write",
278 if (ntrec
> maxbsize
/1024) {
279 msg("Please choose a blocksize <= %dkB\n",
281 msg("The ENTIRE dump is aborted.\n");
287 case 'c': /* Tape is cart. not 9-track */
292 case 'd': /* density, in bits per inch */
294 density
= numarg("density", 10L, 327670L) / 10;
295 if (density
>= 625 && !bflag
)
296 ntrec
= HIGHDENSITYTREC
;
300 case 'e': /* exclude an inode */
302 char *p
= optarg
, *q
;
303 while ((q
= strchr(p
, ','))) {
305 do_exclude_ino_str(p
);
308 do_exclude_ino_str(p
);
312 case 'E': /* exclude inodes read from file */
313 do_exclude_from_file(optarg
);
316 case 'f': /* output file */
320 case 'F': /* end of tape script */
325 honorlevel
= numarg("honor level", 0L, 10L);
333 compressed
= numarg("compress level", 1L, 9L);
335 #endif /* HAVE_BZLIB */
339 numarg ("number of errors to ignore", 1L, 0L);
350 * Note that although there are LBLSIZE characters,
351 * the last must be '\0', so the limit on strlen()
352 * is really LBLSIZE-1.
354 strncpy(spcl
.c_label
, optarg
, LBLSIZE
);
355 spcl
.c_label
[LBLSIZE
-1] = '\0';
356 if (strlen(optarg
) > LBLSIZE
-1) {
358 "WARNING Label `%s' is larger than limit of %d characters.\n",
360 msg("WARNING: Using truncated label `%s'.\n",
365 case 'M': /* multi-volume flag */
369 case 'n': /* notify operators */
378 case 'Q': /* create tapeposfile */
379 gTapeposfile
= optarg
;
384 case 's': /* tape size, feet */
386 tsize
= numarg("tape size", 1L, 0L) * 12 * 10;
390 sizest
= 1; /* return size estimate only */
393 case 'T': /* time of last dump */
394 spcl
.c_ddate
= unctime(optarg
);
395 if (spcl
.c_ddate
< 0) {
396 msg("bad time \"%s\"\n", optarg
);
397 msg("The ENTIRE dump is aborted.\n");
404 case 'u': /* update dumpdates */
408 case 'W': /* what to do */
411 exit(X_FINOK
); /* do nothing else */
416 compressed
= numarg("compress level", 1L, 9L);
418 #endif /* HAVE_ZLIB */
427 msg("Must specify disk or filesystem\n");
428 msg("The ENTIRE dump is aborted.\n");
432 if (strlen(diskparam
) >= MAXPATHLEN
) {
433 msg("Disk or filesystem name too long: %s\n", diskparam
);
434 msg("The ENTIRE dump is aborted.\n");
438 incompat_flags(Tflag
&& uflag
, 'T', 'u');
439 incompat_flags(aflag
&& blocksperfile
, 'a', 'B');
440 incompat_flags(aflag
&& cartridge
, 'a', 'c');
441 incompat_flags(aflag
&& density
, 'a', 'd');
442 incompat_flags(aflag
&& tsize
, 'a', 's');
444 if (strcmp(tapeprefix
, "-") == 0) {
446 tapeprefix
= "standard output";
449 if (blocksperfile
&& !compressed
)
450 blocksperfile
= blocksperfile
/ ntrec
* ntrec
; /* round down */
451 else if (!unlimited
) {
453 * Determine how to default tape size and density
456 * 9-track 1600 bpi (160 bytes/.1") 2300 ft.
457 * 9-track 6250 bpi (625 bytes/.1") 2300 ft.
458 * cartridge 8000 bpi (100 bytes/.1") 1700 ft.
460 * hilit19 hits again: "
463 density
= cartridge
? 100 : 160;
465 tsize
= cartridge
? 1700L*120L : 2300L*120L;
468 if (strchr(tapeprefix
, ':')) {
470 tapeprefix
= strchr(host
, ':');
471 *tapeprefix
++ = '\0';
473 if (index(tapeprefix
, '\n')) {
474 msg("invalid characters in tape\n");
475 msg("The ENTIRE dump is aborted.\n");
478 if (rmthost(host
) == 0)
481 msg("remote dump not enabled\n");
482 msg("The ENTIRE dump is aborted.\n");
486 (void)setuid(getuid()); /* rmthost() is the only reason to be setuid */
488 if (signal(SIGHUP
, SIG_IGN
) != SIG_IGN
)
490 if (signal(SIGTRAP
, SIG_IGN
) != SIG_IGN
)
491 signal(SIGTRAP
, sig
);
492 if (signal(SIGFPE
, SIG_IGN
) != SIG_IGN
)
494 if (signal(SIGBUS
, SIG_IGN
) != SIG_IGN
)
496 if (signal(SIGSEGV
, SIG_IGN
) != SIG_IGN
)
497 signal(SIGSEGV
, sig
);
498 if (signal(SIGTERM
, SIG_IGN
) != SIG_IGN
)
499 signal(SIGTERM
, sig
);
500 if (signal(SIGINT
, interrupt
) == SIG_IGN
)
501 signal(SIGINT
, SIG_IGN
);
503 signal(SIGXCPU
, SIG_IGN
);
506 signal(SIGXFSZ
, SIG_IGN
);
509 set_operators(); /* /etc/group snarfed */
510 getfstab(); /* /etc/fstab snarfed */
513 * disk may end in / and this can confuse
516 i
= strlen(diskparam
) - 1;
517 if (i
> 1 && diskparam
[i
] == '/')
520 disk
= get_device_name(diskparam
);
521 if (!disk
) { /* null means the disk is some form
522 of LABEL= or UID= but it was not
524 msg("Cannot find a disk having %s\n", diskparam
);
525 msg("The ENTIRE dump is aborted.\n");
529 * disk can be either the full special file name,
530 * the suffix of the special file name,
531 * the special name missing the leading '/',
532 * the file system name with or without the leading '/'.
534 if ((dt
= fstabsearch(disk
)) != NULL
) {
535 /* if found then only one parameter (i.e. partition)
538 (void)fprintf(stderr
, "Unknown arguments to dump:");
540 (void)fprintf(stderr
, " %s", *argv
++);
541 (void)fprintf(stderr
, "\n");
542 msg("The ENTIRE dump is aborted.\n");
545 disk
= rawname(dt
->fs_spec
);
546 (void)strncpy(spcl
.c_dev
, dt
->fs_spec
, NAMELEN
);
547 (void)strncpy(spcl
.c_filesys
, dt
->fs_file
, NAMELEN
);
551 if (realpath(disk
, pathname
) == NULL
)
553 strcpy(pathname
, disk
);
555 * The argument could be now a mountpoint of
556 * a filesystem specified in fstab. Search for it.
558 if ((dt
= fstabsearch(pathname
)) != NULL
) {
559 disk
= rawname(dt
->fs_spec
);
560 (void)strncpy(spcl
.c_dev
, dt
->fs_spec
, NAMELEN
);
561 (void)strncpy(spcl
.c_filesys
, dt
->fs_file
, NAMELEN
);
564 * The argument was not found in the fstab
565 * assume that this is a subtree and search for it
567 dt
= fstabsearchdir(pathname
, directory
);
569 char name
[MAXPATHLEN
];
570 (void)strncpy(spcl
.c_dev
, dt
->fs_spec
, NAMELEN
);
571 (void)snprintf(name
, sizeof(name
), "%s (dir %s)",
572 dt
->fs_file
, directory
);
573 (void)strncpy(spcl
.c_filesys
, name
, NAMELEN
);
574 disk
= rawname(dt
->fs_spec
);
576 (void)strncpy(spcl
.c_dev
, disk
, NAMELEN
);
577 (void)strncpy(spcl
.c_filesys
, "an unlisted file system",
582 (void)strncpy(spcl
.c_dev
, disk
, NAMELEN
);
583 (void)strncpy(spcl
.c_filesys
, "an unlisted file system",
588 if (directory
[0] != 0) {
590 msg("Only level 0 dumps are allowed on a subdirectory\n");
591 msg("The ENTIRE dump is aborted.\n");
595 msg("You can't update the dumpdates file when dumping a subdirectory\n");
596 msg("The ENTIRE dump is aborted.\n");
600 spcl
.c_dev
[NAMELEN
-1] = '\0';
601 spcl
.c_filesys
[NAMELEN
-1] = '\0';
602 (void)gethostname(spcl
.c_host
, NAMELEN
);
603 spcl
.c_host
[NAMELEN
-1] = '\0';
604 spcl
.c_level
= level
- '0';
605 spcl
.c_type
= TS_TAPE
;
607 getdumptime(uflag
); /* dumpdates snarfed */
609 if (spcl
.c_ddate
== 0 && spcl
.c_level
) {
610 msg("WARNING: There is no inferior level dump on this filesystem\n");
611 msg("WARNING: Assuming a level 0 dump by default\n");
617 snprintf(tape
, MAXPATHLEN
, "%s%03d", tapeprefix
, tapeno
+ 1);
619 strncpy(tape
, tapeprefix
, MAXPATHLEN
);
620 tape
[MAXPATHLEN
- 1] = '\0';
623 if (STAT(tape
, &statbuf
) != -1)
624 fifoout
= statbuf
.st_mode
& S_IFIFO
;
629 msg("Date of this level %c dump: %s", level
,
630 ctime4(&spcl
.c_date
));
632 gThisDumpDate
= spcl
.c_date
;
635 msg("Date of last level %c dump: %s", lastlevel
,
636 ctime4(&spcl
.c_ddate
));
637 msg("Dumping %s (%s) ", disk
, spcl
.c_filesys
);
639 msgtail("to %s on host %s\n", tape
, host
);
641 msgtail("to %s\n", tape
);
642 } /* end of size estimate */
645 if ((diskfd
= OPEN(disk
, O_RDONLY
)) < 0) {
646 msg("Cannot open %s\n", disk
);
647 msg("The ENTIRE dump is aborted.\n");
651 (void)ioctl(diskfd
, BLKFLSBUF
);
653 retval
= dump_fs_open(disk
, &fs
);
655 com_err(disk
, retval
, "while opening filesystem");
656 if (retval
== EXT2_ET_REV_TOO_HIGH
)
657 msg("Get a newer version of dump!\n");
658 msg("The ENTIRE dump is aborted.\n");
661 if (fs
->super
->s_rev_level
> DUMP_CURRENT_REV
) {
662 com_err(disk
, retval
, "while opening filesystem");
663 msg("Get a newer version of dump!\n");
664 msg("The ENTIRE dump is aborted.\n");
667 /* if no user label specified, use ext2 filesystem label if available */
668 if (spcl
.c_label
[0] == '\0') {
670 if ( (lbl
= get_device_label(disk
)) != NULL
) {
671 strncpy(spcl
.c_label
, lbl
, LBLSIZE
);
672 spcl
.c_label
[LBLSIZE
-1] = '\0';
675 strcpy(spcl
.c_label
, "none"); /* safe strcpy. */
678 dev_bsize
= DEV_BSIZE
;
679 dev_bshift
= ffs(dev_bsize
) - 1;
680 if (dev_bsize
!= (1 << dev_bshift
))
681 quit("dev_bsize (%d) is not a power of 2", dev_bsize
);
682 tp_bshift
= ffs(TP_BSIZE
) - 1;
683 if (TP_BSIZE
!= (1 << tp_bshift
))
684 quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE
);
685 maxino
= fs
->super
->s_inodes_count
+ 1;
687 spcl
.c_flags
|= DR_NEWINODEFMT
;
689 #else /* __linux __*/
690 if ((diskfd
= open(disk
, O_RDONLY
)) < 0) {
691 msg("Cannot open %s\n", disk
);
692 msg("The ENTIRE dump is aborted.\n");
696 sblock
= (struct fs
*)sblock_buf
;
697 bread(SBOFF
, (char *) sblock
, SBSIZE
);
698 if (sblock
->fs_magic
!= FS_MAGIC
)
699 quit("bad sblock magic number\n");
700 dev_bsize
= sblock
->fs_fsize
/ fsbtodb(sblock
, 1);
701 dev_bshift
= ffs(dev_bsize
) - 1;
702 if (dev_bsize
!= (1 << dev_bshift
))
703 quit("dev_bsize (%d) is not a power of 2", dev_bsize
);
704 tp_bshift
= ffs(TP_BSIZE
) - 1;
705 if (TP_BSIZE
!= (1 << tp_bshift
))
706 quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE
);
708 if (sblock
->fs_inodefmt
>= FS_44INODEFMT
)
709 spcl
.c_flags
|= DR_NEWINODEFMT
;
711 maxino
= sblock
->fs_ipg
* sblock
->fs_ncg
;
712 #endif /* __linux__ */
713 mapsize
= roundup(howmany(maxino
, NBBY
), TP_BSIZE
);
714 usedinomap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
715 dumpdirmap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
716 dumpinomap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
717 if (usedinomap
== NULL
|| dumpdirmap
== NULL
|| dumpinomap
== NULL
)
718 quit("out of memory allocating inode maps\n");
719 tapesize
= 2 * (howmany(mapsize
* sizeof(char), TP_BSIZE
) + 1);
721 nonodump
= spcl
.c_level
< honorlevel
;
724 msg("Label: %s\n", spcl
.c_label
);
727 msg("Compressing output at compression level %d (%s)\n",
728 compressed
, bzipflag
? "bzlib" : "zlib");
732 (void)signal(SIGINFO
, statussig
);
736 msg("mapping (Pass I) [regular files]\n");
738 if (directory
[0] == 0)
739 anydirskipped
= mapfiles(maxino
, &tapesize
);
741 if (STAT(pathname
, &statbuf
) == -1) {
742 msg("File cannot be accessed (%s).\n", pathname
);
743 msg("The ENTIRE dump is aborted.\n");
746 filedev
= statbuf
.st_dev
;
747 if (!(statbuf
.st_mode
& S_IFDIR
)) /* is a file */
748 anydirskipped
= maponefile(maxino
, &tapesize
,
751 anydirskipped
= mapfilesfromdir(maxino
, &tapesize
,
757 /* check if file is available */
758 if (STAT(p
, &statbuf
) == -1) {
759 msg("File cannot be accessed (%s).\n", p
);
760 msg("The ENTIRE dump is aborted.\n");
763 /* check if file is on same unix partiton as the first
765 if (statbuf
.st_dev
!= filedev
) {
766 msg("Files are not on same file system (%s).\n", p
);
767 msg("The ENTIRE dump is aborted.\n");
770 /* check if file is a directory */
771 if (!(statbuf
.st_mode
& S_IFDIR
))
772 anydirskipped2
= maponefile(maxino
, &tapesize
,
773 p
+strlen(dt
->fs_file
));
775 /* read directory inodes.
776 * NOTE: nested directories are not recognized
777 * so inodes may be umped twice!
779 anydirskipped2
= mapfilesfromdir(maxino
, &tapesize
,
780 p
+strlen(dt
->fs_file
));
782 anydirskipped
= anydirskipped2
;
786 anydirskipped
= mapfiles(maxino
, &tapesize
);
790 msg("mapping (Pass II) [directories]\n");
791 while (anydirskipped
) {
792 anydirskipped
= mapdirs(maxino
, &tapesize
);
796 printf("%.0f\n", ((double)tapesize
+ 1 + ntrec
) * TP_BSIZE
);
798 } /* stop here for size estimate */
800 if (pipeout
|| unlimited
) {
801 tapesize
+= 1 + ntrec
; /* 1 map header + trailer blocks */
802 msg("estimated %ld tape blocks.\n", tapesize
);
807 fetapes
= (double) tapesize
/ blocksperfile
;
808 else if (cartridge
) {
809 /* Estimate number of tapes, assuming streaming stops at
810 the end of each block written, and not in mid-block.
811 Assume no erroneous blocks; this can be compensated
812 for with an artificially low tape size. */
814 ( (double) tapesize
/* blocks */
815 * TP_BSIZE
/* bytes/block */
816 * (1.0/density
) /* 0.1" / byte " */
818 (double) tapesize
/* blocks */
819 * (1.0/ntrec
) /* streaming-stops per block */
820 * 15.48 /* 0.1" / streaming-stop " */
821 ) * (1.0 / tsize
); /* tape / 0.1" " */
823 /* Estimate number of tapes, for old fashioned 9-track
825 int tenthsperirg
= (density
== 625) ? 3 : 7;
827 ( (double) tapesize
/* blocks */
828 * TP_BSIZE
/* bytes / block */
829 * (1.0/density
) /* 0.1" / byte " */
831 (double) tapesize
/* blocks */
832 * (1.0/ntrec
) /* IRG's / block */
833 * tenthsperirg
/* 0.1" / IRG " */
834 ) * (1.0 / tsize
); /* tape / 0.1" " */
836 etapes
= fetapes
; /* truncating assignment */
838 /* count the dumped inodes map on each additional tape */
839 tapesize
+= (etapes
- 1) *
840 (howmany(mapsize
* sizeof(char), TP_BSIZE
) + 1);
841 tapesize
+= etapes
+ ntrec
; /* headers + trailer blks */
842 msg("estimated %ld tape blocks on %3.2f tape(s).\n",
848 msg("writing QFA positions to %s\n", gTapeposfile
);
849 if ((gTapeposfd
= open(gTapeposfile
, O_RDWR
|O_CREAT
, S_IRUSR
| S_IWUSR
)) < 0)
850 quit("can't open tapeposfile\n");
851 /* print QFA-file header */
852 sprintf(gTps
, "%s\n%s\n%ld\n\n", QFA_MAGIC
, QFA_VERSION
, (unsigned long)spcl
.c_date
);
853 if (write(gTapeposfd
, gTps
, strlen(gTps
)) != strlen(gTps
))
854 quit("can't write tapeposfile\n");
855 sprintf(gTps
, "ino\ttapeno\ttapepos\n");
856 if (write(gTapeposfd
, gTps
, strlen(gTps
)) != strlen(gTps
))
857 quit("can't write tapeposfile\n");
862 * Allocate tape buffer.
866 "can't allocate tape buffers - try a smaller blocking factor.\n");
869 tstart_writing
= time(NULL
);
870 dumpmap(usedinomap
, TS_CLRI
, maxino
- 1);
872 msg("dumping (Pass III) [directories]\n");
873 dirty
= 0; /* XXX just to get gcc to shut up */
874 for (map
= dumpdirmap
, ino
= 1; ino
< maxino
; ino
++) {
875 if (((ino
- 1) % NBBY
) == 0) /* map is offset by 1 */
879 if ((dirty
& 1) == 0)
882 * Skip directory inodes deleted and maybe reallocated
885 if ((dp
->di_mode
& IFMT
) != IFDIR
)
889 * Skip directory inodes deleted and not yes reallocated...
891 if (dp
->di_nlink
== 0 || dp
->di_dtime
!= 0)
893 (void)dumpdirino(dp
, ino
);
895 (void)dumpino(dp
, ino
);
899 msg("dumping (Pass IV) [regular files]\n");
900 for (map
= dumpinomap
, ino
= 1; ino
< maxino
; ino
++) {
901 if (((ino
- 1) % NBBY
) == 0) /* map is offset by 1 */
905 if ((dirty
& 1) == 0)
908 * Skip inodes deleted and reallocated as directories.
911 if ((dp
->di_mode
& IFMT
) == IFDIR
)
915 * No need to check here for deleted and not yet reallocated
916 * inodes since this is done in dumpino().
919 (void)dumpino(dp
, ino
);
922 tend_writing
= time(NULL
);
923 spcl
.c_type
= TS_END
;
925 * Finish off the current tape record with trailer blocks, to ensure
926 * at least the data in the last partial record makes it to tape.
927 * Also make sure we write at least 1 trailer block.
929 for (i
= ntrec
- (spcl
.c_tapea
% ntrec
); i
; --i
)
930 writeheader(maxino
- 1);
934 if (pipeout
|| fifoout
)
935 msg("%ld tape blocks (%.2fMB)\n", spcl
.c_tapea
,
936 ((double)spcl
.c_tapea
* TP_BSIZE
/ 1048576));
938 msg("%ld tape blocks (%.2fMB) on %d volume(s)\n",
940 ((double)spcl
.c_tapea
* TP_BSIZE
/ 1048576),
943 /* report dump performance, avoid division by zero */
944 if (tend_writing
- tstart_writing
== 0)
945 msg("finished in less than a second\n");
947 msg("finished in %d seconds, throughput %d kBytes/sec\n",
948 tend_writing
- tstart_writing
,
949 spcl
.c_tapea
/ (tend_writing
- tstart_writing
));
952 msg("Date of this level %c dump: %s", level
,
953 spcl
.c_date
== 0 ? "the epoch\n" : ctime4(&spcl
.c_date
));
954 msg("Date this dump completed: %s", ctime(&tnow
));
956 msg("Average transfer rate: %ld kB/s\n", xferrate
/ tapeno
);
958 long tapekb
= bytes_written
/ 1024;
959 double rate
= .0005 + (double) spcl
.c_tapea
/ tapekb
;
960 msg("Wrote %ldkB uncompressed, %ldkB compressed, %1.3f:1\n",
961 spcl
.c_tapea
, tapekb
, rate
);
964 broadcast("DUMP IS DONE!\7\7\n");
965 msg("DUMP IS DONE\n");
968 return 0; /* gcc - shut up */
974 char white
[MAXPATHLEN
];
975 const char *ext2ver
, *ext2date
;
977 memset(white
, ' ', MAXPATHLEN
);
978 white
[MIN(strlen(__progname
), MAXPATHLEN
- 1)] = '\0';
981 ext2fs_get_library_version(&ext2ver
, &ext2date
);
982 fprintf(stderr
, "%s %s (using libext2fs %s of %s)\n",
983 __progname
, _DUMP_VERSION
, ext2ver
, ext2date
);
985 fprintf(stderr
, "%s %s\n", __progname
, _DUMP_VERSION
);
988 "usage:\t%s [-0123456789ac"
993 "] [-B records] [-b blocksize] [-d density]\n"
994 "\t%s [-e inode#,inode#,...] [-E file] [-f file] [-h level]\n"
995 "\t%s [-I nr errors] "
1002 "[-s feet] [-T date] "
1008 __progname
, white
, white
, __progname
);
1013 * Pick up a numeric argument. It must be nonnegative and in the given
1014 * range (except that a vmax of 0 means unlimited).
1017 numarg(const char *meaning
, long vmin
, long vmax
)
1022 val
= strtol(optarg
, &p
, 10);
1024 errx(X_STARTUP
, "illegal %s -- %s", meaning
, optarg
);
1025 if (val
< vmin
|| (vmax
&& val
> vmax
))
1026 errx(X_STARTUP
, "%s must be between %ld and %ld", meaning
, vmin
, vmax
);
1040 if (pipeout
|| fifoout
)
1041 quit("Signal on pipe: cannot recover\n");
1042 msg("Rewriting attempted as response to unknown signal: %d.\n", signo
);
1043 (void)fflush(stderr
);
1044 (void)fflush(stdout
);
1049 msg("SIGSEGV: ABORTING!\n");
1050 (void)signal(SIGSEGV
, SIG_DFL
);
1051 (void)kill(0, SIGSEGV
);
1057 rawname(const char *cp
)
1061 #else /* __linux__ */
1062 static char rawbuf
[MAXPATHLEN
];
1063 char *dp
= strrchr(cp
, '/');
1067 (void)strncpy(rawbuf
, cp
, min(dp
-cp
, MAXPATHLEN
- 1));
1068 rawbuf
[min(dp
-cp
, MAXPATHLEN
-1)] = '\0';
1069 (void)strncat(rawbuf
, "/r", MAXPATHLEN
- 1 - strlen(rawbuf
));
1070 (void)strncat(rawbuf
, dp
+ 1, MAXPATHLEN
- 1 - strlen(rawbuf
));
1072 #endif /* __linux__ */
1077 * Change set of key letters and ordered arguments into something
1078 * getopt(3) will like.
1081 obsolete(int *argcp
, char **argvp
[])
1084 char *ap
, **argv
, *flagsp
=NULL
, **nargv
, *p
=NULL
;
1090 /* Return if no arguments or first argument has leading dash. */
1092 if (argc
== 1 || *ap
== '-')
1095 /* Allocate space for new arguments. */
1096 if ((*argvp
= nargv
= malloc((argc
+ 1) * sizeof(char *))) == NULL
||
1097 (p
= flagsp
= malloc(strlen(ap
) + 2)) == NULL
)
1098 err(X_STARTUP
, "malloc new args");
1103 for (flags
= 0; *ap
; ++ap
) {
1117 if (*argv
== NULL
) {
1118 warnx("option requires an argument -- %c", *ap
);
1121 if ((nargv
[0] = malloc(strlen(*argv
) + 2 + 1)) == NULL
)
1122 err(X_STARTUP
, "malloc arg");
1125 (void)strcpy(&nargv
[0][2], *argv
);
1139 /* Terminate flags. */
1145 /* Copy remaining arguments. */
1146 while ((*nargv
++ = *argv
++));
1148 /* Update argument count. */
1149 *argcp
= nargv
- *argvp
- 1;
1153 * This tests whether an inode is in the exclude list
1156 exclude_ino(dump_ino_t ino
)
1159 if (iexclude_num
) { /* if there are inodes in the exclude list */
1160 int idx
; /* then check this inode against it */
1161 for (idx
= 0; idx
< iexclude_num
; idx
++)
1162 if (ino
== iexclude_list
[idx
])
1169 * This tests adds an inode to the exclusion list if it isn't already there
1172 do_exclude_ino(dump_ino_t ino
, const char *reason
)
1174 if (!exclude_ino(ino
)) {
1175 if (iexclude_num
== IEXCLUDE_MAXNUM
) {
1176 msg("Too many exclude options\n");
1177 msg("The ENTIRE dump is aborted.\n");
1181 msg("Added inode %u to exclude list (%s)\n",
1184 msg("Added inode %u to exclude list\n", ino
);
1185 iexclude_list
[iexclude_num
++] = ino
;
1190 do_exclude_ino_str(char * ino
) {
1194 inod
= strtoul(ino
, &r
, 10);
1195 if (*r
!= '\0' || inod
<= ROOTINO
) {
1196 msg("Invalid inode argument %s\n", ino
);
1197 msg("The ENTIRE dump is aborted.\n");
1200 do_exclude_ino(inod
, NULL
);
1204 * This reads a file containing one inode number per line and exclude them all
1207 do_exclude_from_file(char *file
) {
1209 char *p
, fname
[MAXPATHLEN
];
1212 if (!( f
= fopen(file
, "r")) ) {
1213 msg("Cannot open file for reading: %s\n", file
);
1214 msg("The ENTIRE dump is aborted.\n");
1217 while (( p
= fgets(fname
, MAXPATHLEN
, f
))) {
1218 if ( *p
&& *(p
+ strlen(p
) - 1) == '\n' ) /* possible null string */
1219 *(p
+ strlen(p
) - 1) = '\0';
1220 if ( !*p
) /* skip empty lines */
1222 do_exclude_ino_str(p
);
1227 static void incompat_flags(int cond
, char flag1
, char flag2
) {
1229 msg("You cannot use the %c and %c flags together.\n",
1231 msg("The ENTIRE dump is aborted.\n");