]>
git.wh0rd.org - dump.git/blob - dump/main.c
3d4e693fc4ea6cb8672edd8a38716cd1959f0121
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 <stelian@popies.net>, 1999-2000
6 * Stelian Pop <stelian@popies.net> - AlcĂ´ve <www.alcove.com>, 2000-2002
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.70 2002/03/11 10:17:43 stelian Exp $";
48 #include <compatlfs.h>
50 #include <compaterr.h>
60 #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 Afile
= 0; /* archive file descriptor */
108 int uflag
; /* update flag */
109 int Mflag
; /* multi-volume flag */
110 int qflag
; /* quit on errors flag */
111 int breademax
= 32; /* maximum number of bread errors before we quit */
112 char *eot_script
; /* end of volume script fiag */
113 int diskfd
; /* disk file descriptor */
114 int tapefd
; /* tape file descriptor */
115 int pipeout
; /* true => output to standard output */
116 int fifoout
; /* true => output to fifo */
117 dump_ino_t curino
; /* current inumber; used globally */
118 int newtape
; /* new tape flag */
119 int density
; /* density in 0.1" units */
120 long tapesize
; /* estimated tape size, blocks */
121 long tsize
; /* tape size in 0.1" units */
122 long asize
; /* number of 0.1" units written on current tape */
123 int etapes
; /* estimated number of tapes */
124 int nonodump
; /* if set, do not honor UF_NODUMP user flags */
125 int unlimited
; /* if set, write to end of medium */
126 int compressed
; /* if set, dump is to be compressed */
127 long long bytes_written
;/* total bytes written to tape */
128 long uncomprblks
; /* uncompressed blocks written to tape */
129 int notify
; /* notify operator flag */
130 int blockswritten
; /* number of blocks written on current tape */
131 int tapeno
; /* current tape number */
132 time_t tstart_writing
; /* when started writing the first tape block */
133 time_t tend_writing
; /* after writing the last tape block */
137 struct fs
*sblock
; /* the file system super block */
138 char sblock_buf
[MAXBSIZE
];
140 long xferrate
; /* averaged transfer rate of all volumes */
141 long dev_bsize
; /* block size of underlying disk device */
142 int dev_bshift
; /* log2(dev_bsize) */
143 int tp_bshift
; /* log2(TP_BSIZE) */
144 dump_ino_t volinfo
[TP_NINOS
];/* which inode on which volume archive info */
150 int32_t gThisDumpDate
;
153 struct dumptime
*dthead
; /* head of the list version */
154 int nddates
; /* number of records (might be zero) */
155 int ddates_in
; /* we have read the increment file */
156 struct dumpdates
**ddatev
; /* the arrayfied version */
158 int notify
= 0; /* notify operator flag */
159 int blockswritten
= 0; /* number of blocks written on current tape */
160 int tapeno
= 0; /* current tape number */
161 int density
= 0; /* density in bytes/0.1" " <- this is for hilit19 */
162 int ntrec
= NTREC
; /* # tape blocks in each tape record */
163 int cartridge
= 0; /* Assume non-cartridge tape */
165 int tapepos
= 0; /* assume no QFA tapeposition needed by user */
167 int dokerberos
= 0; /* Use Kerberos authentication */
168 long dev_bsize
= 1; /* recalculated below */
169 long blocksperfile
; /* output blocks per file */
170 char *host
= NULL
; /* remote host (if any) */
171 int sizest
= 0; /* return size estimate only */
172 int compressed
= 0; /* use zlib to compress the output, compress level 1-9 */
173 long long bytes_written
= 0; /* total bytes written */
174 long uncomprblks
= 0;/* uncompressed blocks written */
180 int maxbsize
= 64*1024; /* XXX MAXBSIZE from sys/param.h */
181 static long numarg
__P((const char *, long, long));
182 static void obsolete
__P((int *, char **[]));
183 static void usage
__P((void));
184 static void do_exclude_from_file
__P((char *));
185 static void do_exclude_ino_str
__P((char *));
186 static void incompat_flags
__P((int, char, char));
188 static dump_ino_t iexclude_list
[IEXCLUDE_MAXNUM
];/* the inode exclude list */
189 static int iexclude_num
= 0; /* number of elements in the list */
192 main(int argc
, char *argv
[])
200 int i
, anydirskipped
;
201 int aflag
= 0, bflag
= 0, Tflag
= 0, honorlevel
= 1;
207 char directory
[MAXPATHLEN
];
208 char pathname
[MAXPATHLEN
];
214 spcl
.c_label
[0] = '\0';
215 spcl
.c_date
= time(NULL
);
218 __progname
= argv
[0];
220 initialize_ext2_error_table();
223 tsize
= 0; /* Default later, based on 'c' option for cart tapes */
226 if ((tapeprefix
= getenv("TAPE")) == NULL
)
227 tapeprefix
= _PATH_DEFTAPE
;
228 dumpdates
= _PATH_DUMPDATES
;
229 if (TP_BSIZE
/ DEV_BSIZE
== 0 || TP_BSIZE
% DEV_BSIZE
!= 0)
230 quit("TP_BSIZE must be a multiple of DEV_BSIZE\n");
236 obsolete(&argc
, &argv
);
242 while ((ch
= getopt(argc
, argv
,
243 "0123456789A:aB:b:cd:e:E:f:F:h:I:"
262 case '0': case '1': case '2': case '3': case '4':
263 case '5': case '6': case '7': case '8': case '9':
267 case 'A': /* archive file */
269 if ((Afile
= open(Apath
, O_RDWR
|O_CREAT
|O_TRUNC
,
270 S_IRUSR
| S_IWUSR
)) < 0) {
271 msg("Cannot open %s for writing: %s\n",
272 optarg
, strerror(errno
));
273 msg("The ENTIRE dump is aborted.\n");
276 memset(volinfo
, 0, TP_NINOS
* sizeof(dump_ino_t
));
279 case 'a': /* `auto-size', Write to EOM. */
284 case 'B': /* blocks per output file */
286 blocksperfile
= numarg("number of blocks per file",
290 case 'b': /* blocks per tape write */
291 ntrec
= numarg("number of blocks per write",
293 if (ntrec
> maxbsize
/1024) {
294 msg("Please choose a blocksize <= %dkB\n",
296 msg("The ENTIRE dump is aborted.\n");
302 case 'c': /* Tape is cart. not 9-track */
307 case 'd': /* density, in bits per inch */
309 density
= numarg("density", 10L, 327670L) / 10;
310 if (density
>= 625 && !bflag
)
311 ntrec
= HIGHDENSITYTREC
;
315 case 'e': /* exclude an inode */
317 char *p
= optarg
, *q
;
318 while ((q
= strchr(p
, ','))) {
320 do_exclude_ino_str(p
);
323 do_exclude_ino_str(p
);
327 case 'E': /* exclude inodes read from file */
328 do_exclude_from_file(optarg
);
331 case 'f': /* output file */
335 case 'F': /* end of tape script */
340 honorlevel
= numarg("honor level", 0L, 10L);
348 compressed
= numarg("compress level", 1L, 9L);
350 #endif /* HAVE_BZLIB */
354 numarg ("number of errors to ignore", 1L, 0L);
365 * Note that although there are LBLSIZE characters,
366 * the last must be '\0', so the limit on strlen()
367 * is really LBLSIZE-1.
369 strncpy(spcl
.c_label
, optarg
, LBLSIZE
);
370 spcl
.c_label
[LBLSIZE
-1] = '\0';
371 if (strlen(optarg
) > LBLSIZE
-1) {
373 "WARNING Label `%s' is larger than limit of %d characters.\n",
375 msg("WARNING: Using truncated label `%s'.\n",
380 case 'M': /* multi-volume flag */
384 case 'n': /* notify operators */
393 case 'Q': /* create tapeposfile */
394 gTapeposfile
= optarg
;
399 case 's': /* tape size, feet */
401 tsize
= numarg("tape size", 1L, 0L) * 12 * 10;
405 sizest
= 1; /* return size estimate only */
408 case 'T': /* time of last dump */
409 spcl
.c_ddate
= unctime(optarg
);
410 if (spcl
.c_ddate
< 0) {
411 msg("bad time \"%s\"\n", optarg
);
412 msg("The ENTIRE dump is aborted.\n");
419 case 'u': /* update dumpdates */
423 case 'W': /* what to do */
426 exit(X_FINOK
); /* do nothing else */
431 compressed
= numarg("compress level", 1L, 9L);
433 #endif /* HAVE_ZLIB */
442 msg("Must specify disk or filesystem\n");
443 msg("The ENTIRE dump is aborted.\n");
447 if (strlen(diskparam
) >= MAXPATHLEN
) {
448 msg("Disk or filesystem name too long: %s\n", diskparam
);
449 msg("The ENTIRE dump is aborted.\n");
453 incompat_flags(Tflag
&& uflag
, 'T', 'u');
454 incompat_flags(aflag
&& blocksperfile
, 'a', 'B');
455 incompat_flags(aflag
&& cartridge
, 'a', 'c');
456 incompat_flags(aflag
&& density
, 'a', 'd');
457 incompat_flags(aflag
&& tsize
, 'a', 's');
459 if (strcmp(tapeprefix
, "-") == 0) {
461 tapeprefix
= "standard output";
464 if (blocksperfile
&& !compressed
)
465 blocksperfile
= blocksperfile
/ ntrec
* ntrec
; /* round down */
466 else if (!unlimited
) {
468 * Determine how to default tape size and density
471 * 9-track 1600 bpi (160 bytes/.1") 2300 ft.
472 * 9-track 6250 bpi (625 bytes/.1") 2300 ft.
473 * cartridge 8000 bpi (100 bytes/.1") 1700 ft.
475 * hilit19 hits again: "
478 density
= cartridge
? 100 : 160;
480 tsize
= cartridge
? 1700L*120L : 2300L*120L;
483 if (strchr(tapeprefix
, ':')) {
485 tapeprefix
= strchr(host
, ':');
486 *tapeprefix
++ = '\0';
488 if (index(tapeprefix
, '\n')) {
489 msg("invalid characters in tape\n");
490 msg("The ENTIRE dump is aborted.\n");
493 if (rmthost(host
) == 0)
496 msg("remote dump not enabled\n");
497 msg("The ENTIRE dump is aborted.\n");
501 (void)setuid(getuid()); /* rmthost() is the only reason to be setuid */
503 if (signal(SIGHUP
, SIG_IGN
) != SIG_IGN
)
505 if (signal(SIGTRAP
, SIG_IGN
) != SIG_IGN
)
506 signal(SIGTRAP
, sig
);
507 if (signal(SIGFPE
, SIG_IGN
) != SIG_IGN
)
509 if (signal(SIGBUS
, SIG_IGN
) != SIG_IGN
)
511 if (signal(SIGSEGV
, SIG_IGN
) != SIG_IGN
)
512 signal(SIGSEGV
, sig
);
513 if (signal(SIGTERM
, SIG_IGN
) != SIG_IGN
)
514 signal(SIGTERM
, sig
);
515 if (signal(SIGINT
, interrupt
) == SIG_IGN
)
516 signal(SIGINT
, SIG_IGN
);
518 signal(SIGXCPU
, SIG_IGN
);
521 signal(SIGXFSZ
, SIG_IGN
);
524 set_operators(); /* /etc/group snarfed */
525 getfstab(); /* /etc/fstab snarfed */
528 * disk may end in / and this can confuse
531 i
= strlen(diskparam
) - 1;
532 if (i
> 1 && diskparam
[i
] == '/')
533 if (!(i
== 6 && !strcmp(diskparam
, "LABEL=/")))
536 disk
= get_device_name(diskparam
);
537 if (!disk
) { /* null means the disk is some form
538 of LABEL= or UID= but it was not
540 msg("Cannot find a disk having %s\n", diskparam
);
541 msg("The ENTIRE dump is aborted.\n");
545 * disk can be either the full special file name,
546 * the suffix of the special file name,
547 * the special name missing the leading '/',
548 * the file system name with or without the leading '/'.
550 if ((dt
= fstabsearch(disk
)) != NULL
) {
551 /* if found then only one parameter (i.e. partition)
554 (void)fprintf(stderr
, "Unknown arguments to dump:");
556 (void)fprintf(stderr
, " %s", *argv
++);
557 (void)fprintf(stderr
, "\n");
558 msg("The ENTIRE dump is aborted.\n");
561 disk
= rawname(dt
->fs_spec
);
562 (void)strncpy(spcl
.c_dev
, dt
->fs_spec
, NAMELEN
);
563 (void)strncpy(spcl
.c_filesys
, dt
->fs_file
, NAMELEN
);
567 if (realpath(disk
, pathname
) == NULL
)
569 strcpy(pathname
, disk
);
571 * The argument could be now a mountpoint of
572 * a filesystem specified in fstab. Search for it.
574 if ((dt
= fstabsearch(pathname
)) != NULL
) {
575 disk
= rawname(dt
->fs_spec
);
576 (void)strncpy(spcl
.c_dev
, dt
->fs_spec
, NAMELEN
);
577 (void)strncpy(spcl
.c_filesys
, dt
->fs_file
, NAMELEN
);
580 * The argument was not found in the fstab
581 * assume that this is a subtree and search for it
583 dt
= fstabsearchdir(pathname
, directory
);
585 char name
[MAXPATHLEN
];
586 (void)strncpy(spcl
.c_dev
, dt
->fs_spec
, NAMELEN
);
587 (void)snprintf(name
, sizeof(name
), "%s (dir %s)",
588 dt
->fs_file
, directory
);
589 (void)strncpy(spcl
.c_filesys
, name
, NAMELEN
);
590 disk
= rawname(dt
->fs_spec
);
592 (void)strncpy(spcl
.c_dev
, disk
, NAMELEN
);
593 (void)strncpy(spcl
.c_filesys
, "an unlisted file system",
598 (void)strncpy(spcl
.c_dev
, disk
, NAMELEN
);
599 (void)strncpy(spcl
.c_filesys
, "an unlisted file system",
604 if (directory
[0] != 0) {
606 msg("Only level 0 dumps are allowed on a subdirectory\n");
607 msg("The ENTIRE dump is aborted.\n");
611 msg("You can't update the dumpdates file when dumping a subdirectory\n");
612 msg("The ENTIRE dump is aborted.\n");
616 spcl
.c_dev
[NAMELEN
-1] = '\0';
617 spcl
.c_filesys
[NAMELEN
-1] = '\0';
618 (void)gethostname(spcl
.c_host
, NAMELEN
);
619 spcl
.c_host
[NAMELEN
-1] = '\0';
620 spcl
.c_level
= level
- '0';
621 spcl
.c_type
= TS_TAPE
;
623 getdumptime(uflag
); /* dumpdates snarfed */
625 if (spcl
.c_ddate
== 0 && spcl
.c_level
) {
626 msg("WARNING: There is no inferior level dump on this filesystem\n");
627 msg("WARNING: Assuming a level 0 dump by default\n");
633 snprintf(tape
, MAXPATHLEN
, "%s%03d", tapeprefix
, tapeno
+ 1);
635 strncpy(tape
, tapeprefix
, MAXPATHLEN
);
636 tape
[MAXPATHLEN
- 1] = '\0';
639 if (STAT(tape
, &statbuf
) != -1)
640 fifoout
= statbuf
.st_mode
& S_IFIFO
;
645 msg("Date of this level %c dump: %s", level
,
646 ctime4(&spcl
.c_date
));
648 gThisDumpDate
= spcl
.c_date
;
651 msg("Date of last level %c dump: %s", lastlevel
,
652 ctime4(&spcl
.c_ddate
));
653 msg("Dumping %s (%s) ", disk
, spcl
.c_filesys
);
655 msgtail("to %s on host %s\n", tape
, host
);
657 msgtail("to %s\n", tape
);
658 } /* end of size estimate */
661 if ((diskfd
= OPEN(disk
, O_RDONLY
)) < 0) {
662 msg("Cannot open %s\n", disk
);
663 msg("The ENTIRE dump is aborted.\n");
667 (void)ioctl(diskfd
, BLKFLSBUF
);
669 retval
= dump_fs_open(disk
, &fs
);
671 com_err(disk
, retval
, "while opening filesystem");
672 if (retval
== EXT2_ET_REV_TOO_HIGH
)
673 msg("Get a newer version of dump!\n");
674 msg("The ENTIRE dump is aborted.\n");
677 if (fs
->super
->s_rev_level
> DUMP_CURRENT_REV
) {
678 com_err(disk
, retval
, "while opening filesystem");
679 msg("Get a newer version of dump!\n");
680 msg("The ENTIRE dump is aborted.\n");
683 /* if no user label specified, use ext2 filesystem label if available */
684 if (spcl
.c_label
[0] == '\0') {
686 if ( (lbl
= get_device_label(disk
)) != NULL
) {
687 strncpy(spcl
.c_label
, lbl
, LBLSIZE
);
688 spcl
.c_label
[LBLSIZE
-1] = '\0';
691 strcpy(spcl
.c_label
, "none"); /* safe strcpy. */
694 dev_bsize
= DEV_BSIZE
;
695 dev_bshift
= ffs(dev_bsize
) - 1;
696 if (dev_bsize
!= (1 << dev_bshift
))
697 quit("dev_bsize (%d) is not a power of 2", dev_bsize
);
698 tp_bshift
= ffs(TP_BSIZE
) - 1;
699 if (TP_BSIZE
!= (1 << tp_bshift
))
700 quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE
);
701 maxino
= fs
->super
->s_inodes_count
+ 1;
703 spcl
.c_flags
|= DR_NEWINODEFMT
;
705 #else /* __linux __*/
706 if ((diskfd
= open(disk
, O_RDONLY
)) < 0) {
707 msg("Cannot open %s\n", disk
);
708 msg("The ENTIRE dump is aborted.\n");
712 sblock
= (struct fs
*)sblock_buf
;
713 bread(SBOFF
, (char *) sblock
, SBSIZE
);
714 if (sblock
->fs_magic
!= FS_MAGIC
)
715 quit("bad sblock magic number\n");
716 dev_bsize
= sblock
->fs_fsize
/ fsbtodb(sblock
, 1);
717 dev_bshift
= ffs(dev_bsize
) - 1;
718 if (dev_bsize
!= (1 << dev_bshift
))
719 quit("dev_bsize (%d) is not a power of 2", dev_bsize
);
720 tp_bshift
= ffs(TP_BSIZE
) - 1;
721 if (TP_BSIZE
!= (1 << tp_bshift
))
722 quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE
);
724 if (sblock
->fs_inodefmt
>= FS_44INODEFMT
)
725 spcl
.c_flags
|= DR_NEWINODEFMT
;
727 maxino
= sblock
->fs_ipg
* sblock
->fs_ncg
;
728 #endif /* __linux__ */
729 mapsize
= roundup(howmany(maxino
, NBBY
), TP_BSIZE
);
730 usedinomap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
731 dumpdirmap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
732 dumpinomap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
733 if (usedinomap
== NULL
|| dumpdirmap
== NULL
|| dumpinomap
== NULL
)
734 quit("out of memory allocating inode maps\n");
735 tapesize
= 2 * (howmany(mapsize
* sizeof(char), TP_BSIZE
) + 1);
737 nonodump
= spcl
.c_level
< honorlevel
;
740 msg("Label: %s\n", spcl
.c_label
);
743 msg("Compressing output at compression level %d (%s)\n",
744 compressed
, bzipflag
? "bzlib" : "zlib");
748 (void)signal(SIGINFO
, statussig
);
752 msg("mapping (Pass I) [regular files]\n");
754 if (directory
[0] == 0)
755 anydirskipped
= mapfiles(maxino
, &tapesize
);
757 if (STAT(pathname
, &statbuf
) == -1) {
758 msg("File cannot be accessed (%s).\n", pathname
);
759 msg("The ENTIRE dump is aborted.\n");
762 filedev
= statbuf
.st_dev
;
763 if (!(statbuf
.st_mode
& S_IFDIR
)) /* is a file */
764 anydirskipped
= maponefile(maxino
, &tapesize
,
767 anydirskipped
= mapfilesfromdir(maxino
, &tapesize
,
773 /* check if file is available */
774 if (STAT(p
, &statbuf
) == -1) {
775 msg("File cannot be accessed (%s).\n", p
);
776 msg("The ENTIRE dump is aborted.\n");
779 /* check if file is on same unix partiton as the first
781 if (statbuf
.st_dev
!= filedev
) {
782 msg("Files are not on same file system (%s).\n", p
);
783 msg("The ENTIRE dump is aborted.\n");
786 /* check if file is a directory */
787 if (!(statbuf
.st_mode
& S_IFDIR
))
788 anydirskipped2
= maponefile(maxino
, &tapesize
,
789 p
+strlen(dt
->fs_file
));
791 /* read directory inodes.
792 * NOTE: nested directories are not recognized
793 * so inodes may be umped twice!
795 anydirskipped2
= mapfilesfromdir(maxino
, &tapesize
,
796 p
+strlen(dt
->fs_file
));
798 anydirskipped
= anydirskipped2
;
802 anydirskipped
= mapfiles(maxino
, &tapesize
);
806 msg("mapping (Pass II) [directories]\n");
807 while (anydirskipped
) {
808 anydirskipped
= mapdirs(maxino
, &tapesize
);
812 printf("%.0f\n", ((double)tapesize
+ 1 + ntrec
) * TP_BSIZE
);
814 } /* stop here for size estimate */
816 if (pipeout
|| unlimited
) {
817 tapesize
+= 1 + ntrec
; /* 1 map header + trailer blocks */
818 msg("estimated %ld tape blocks.\n", tapesize
);
823 fetapes
= (double) tapesize
/ blocksperfile
;
824 else if (cartridge
) {
825 /* Estimate number of tapes, assuming streaming stops at
826 the end of each block written, and not in mid-block.
827 Assume no erroneous blocks; this can be compensated
828 for with an artificially low tape size. */
830 ( (double) tapesize
/* blocks */
831 * TP_BSIZE
/* bytes/block */
832 * (1.0/density
) /* 0.1" / byte " */
834 (double) tapesize
/* blocks */
835 * (1.0/ntrec
) /* streaming-stops per block */
836 * 15.48 /* 0.1" / streaming-stop " */
837 ) * (1.0 / tsize
); /* tape / 0.1" " */
839 /* Estimate number of tapes, for old fashioned 9-track
841 int tenthsperirg
= (density
== 625) ? 3 : 7;
843 ( (double) tapesize
/* blocks */
844 * TP_BSIZE
/* bytes / block */
845 * (1.0/density
) /* 0.1" / byte " */
847 (double) tapesize
/* blocks */
848 * (1.0/ntrec
) /* IRG's / block */
849 * tenthsperirg
/* 0.1" / IRG " */
850 ) * (1.0 / tsize
); /* tape / 0.1" " */
852 etapes
= fetapes
; /* truncating assignment */
854 /* count the dumped inodes map on each additional tape */
855 tapesize
+= (etapes
- 1) *
856 (howmany(mapsize
* sizeof(char), TP_BSIZE
) + 1);
857 tapesize
+= etapes
+ ntrec
; /* headers + trailer blks */
858 msg("estimated %ld tape blocks on %3.2f tape(s).\n",
864 msg("writing QFA positions to %s\n", gTapeposfile
);
865 if ((gTapeposfd
= open(gTapeposfile
, O_RDWR
|O_CREAT
|O_TRUNC
, S_IRUSR
| S_IWUSR
)) < 0)
866 quit("can't open tapeposfile\n");
867 /* print QFA-file header */
868 snprintf(gTps
, sizeof(gTps
), "%s\n%s\n%ld\n\n", QFA_MAGIC
, QFA_VERSION
, (unsigned long)spcl
.c_date
);
869 gTps
[sizeof(gTps
) - 1] = '\0';
870 if (write(gTapeposfd
, gTps
, strlen(gTps
)) != strlen(gTps
))
871 quit("can't write tapeposfile\n");
872 sprintf(gTps
, "ino\ttapeno\ttapepos\n");
873 if (write(gTapeposfd
, gTps
, strlen(gTps
)) != strlen(gTps
))
874 quit("can't write tapeposfile\n");
879 * Allocate tape buffer.
883 "can't allocate tape buffers - try a smaller blocking factor.\n");
886 tstart_writing
= time(NULL
);
887 dumpmap(usedinomap
, TS_CLRI
, maxino
- 1);
889 msg("dumping (Pass III) [directories]\n");
890 dirty
= 0; /* XXX just to get gcc to shut up */
891 for (map
= dumpdirmap
, ino
= 1; ino
< maxino
; ino
++) {
892 if (((ino
- 1) % NBBY
) == 0) /* map is offset by 1 */
896 if ((dirty
& 1) == 0)
899 * Skip directory inodes deleted and maybe reallocated
902 if ((dp
->di_mode
& IFMT
) != IFDIR
)
906 * Skip directory inodes deleted and not yes reallocated...
908 if (dp
->di_nlink
== 0 || dp
->di_dtime
!= 0)
910 (void)dumpdirino(dp
, ino
);
912 (void)dumpino(dp
, ino
);
916 msg("dumping (Pass IV) [regular files]\n");
917 for (map
= dumpinomap
, ino
= 1; ino
< maxino
; ino
++) {
918 if (((ino
- 1) % NBBY
) == 0) /* map is offset by 1 */
922 if ((dirty
& 1) == 0)
925 * Skip inodes deleted and reallocated as directories.
928 if ((dp
->di_mode
& IFMT
) == IFDIR
)
932 * No need to check here for deleted and not yet reallocated
933 * inodes since this is done in dumpino().
936 (void)dumpino(dp
, ino
);
939 tend_writing
= time(NULL
);
940 spcl
.c_type
= TS_END
;
943 volinfo
[1] = ROOTINO
;
944 memcpy(spcl
.c_inos
, volinfo
, TP_NINOS
* sizeof(dump_ino_t
));
945 spcl
.c_flags
|= DR_INODEINFO
;
949 * Finish off the current tape record with trailer blocks, to ensure
950 * at least the data in the last partial record makes it to tape.
951 * Also make sure we write at least 1 trailer block.
953 for (i
= ntrec
- (spcl
.c_tapea
% ntrec
); i
; --i
)
954 writeheader(maxino
- 1);
958 if (pipeout
|| fifoout
)
959 msg("%ld tape blocks (%.2fMB)\n", spcl
.c_tapea
,
960 ((double)spcl
.c_tapea
* TP_BSIZE
/ 1048576));
962 msg("%ld tape blocks (%.2fMB) on %d volume(s)\n",
964 ((double)spcl
.c_tapea
* TP_BSIZE
/ 1048576),
967 /* report dump performance, avoid division by zero */
968 if (tend_writing
- tstart_writing
== 0)
969 msg("finished in less than a second\n");
971 msg("finished in %d seconds, throughput %d kBytes/sec\n",
972 tend_writing
- tstart_writing
,
973 spcl
.c_tapea
/ (tend_writing
- tstart_writing
));
976 msg("Date of this level %c dump: %s", level
,
977 spcl
.c_date
== 0 ? "the epoch\n" : ctime4(&spcl
.c_date
));
978 msg("Date this dump completed: %s", ctime(&tnow
));
980 msg("Average transfer rate: %ld kB/s\n", xferrate
/ tapeno
);
982 long tapekb
= bytes_written
/ 1024;
983 double rate
= .0005 + (double) spcl
.c_tapea
/ tapekb
;
984 msg("Wrote %ldkB uncompressed, %ldkB compressed, %1.3f:1\n",
985 spcl
.c_tapea
, tapekb
, rate
);
989 msg("Archiving dump to %s\n", Apath
);
991 broadcast("DUMP IS DONE!\7\7\n");
992 msg("DUMP IS DONE\n");
995 return 0; /* gcc - shut up */
1001 char white
[MAXPATHLEN
];
1002 const char *ext2ver
, *ext2date
;
1004 memset(white
, ' ', MAXPATHLEN
);
1005 white
[MIN(strlen(__progname
), MAXPATHLEN
- 1)] = '\0';
1008 ext2fs_get_library_version(&ext2ver
, &ext2date
);
1009 fprintf(stderr
, "%s %s (using libext2fs %s of %s)\n",
1010 __progname
, _DUMP_VERSION
, ext2ver
, ext2date
);
1012 fprintf(stderr
, "%s %s\n", __progname
, _DUMP_VERSION
);
1015 "usage:\t%s [-0123456789ac"
1020 "] [-A file] [-B records] [-b blocksize]\n"
1021 "\t%s [-d density] [-e inode#,inode#,...] [-E file] [-f file]\n"
1022 "\t%s [-h level] [-I nr errors] "
1036 __progname
, white
, white
, white
, __progname
);
1041 * Pick up a numeric argument. It must be nonnegative and in the given
1042 * range (except that a vmax of 0 means unlimited).
1045 numarg(const char *meaning
, long vmin
, long vmax
)
1050 val
= strtol(optarg
, &p
, 10);
1052 errx(X_STARTUP
, "illegal %s -- %s", meaning
, optarg
);
1053 if (val
< vmin
|| (vmax
&& val
> vmax
))
1054 errx(X_STARTUP
, "%s must be between %ld and %ld", meaning
, vmin
, vmax
);
1068 if (pipeout
|| fifoout
)
1069 quit("Signal on pipe: cannot recover\n");
1070 msg("Rewriting attempted as response to unknown signal: %d.\n", signo
);
1071 (void)fflush(stderr
);
1072 (void)fflush(stdout
);
1077 msg("SIGSEGV: ABORTING!\n");
1078 (void)signal(SIGSEGV
, SIG_DFL
);
1079 (void)kill(0, SIGSEGV
);
1085 rawname(const char *cp
)
1089 #else /* __linux__ */
1090 static char rawbuf
[MAXPATHLEN
];
1091 char *dp
= strrchr(cp
, '/');
1095 (void)strncpy(rawbuf
, cp
, min(dp
-cp
, MAXPATHLEN
- 1));
1096 rawbuf
[min(dp
-cp
, MAXPATHLEN
-1)] = '\0';
1097 (void)strncat(rawbuf
, "/r", MAXPATHLEN
- 1 - strlen(rawbuf
));
1098 (void)strncat(rawbuf
, dp
+ 1, MAXPATHLEN
- 1 - strlen(rawbuf
));
1100 #endif /* __linux__ */
1105 * Change set of key letters and ordered arguments into something
1106 * getopt(3) will like.
1109 obsolete(int *argcp
, char **argvp
[])
1112 char *ap
, **argv
, *flagsp
=NULL
, **nargv
, *p
=NULL
;
1118 /* Return if no arguments or first argument has leading dash. */
1120 if (argc
== 1 || *ap
== '-')
1123 /* Allocate space for new arguments. */
1124 if ((*argvp
= nargv
= malloc((argc
+ 1) * sizeof(char *))) == NULL
||
1125 (p
= flagsp
= malloc(strlen(ap
) + 2)) == NULL
)
1126 err(X_STARTUP
, "malloc new args");
1131 for (flags
= 0; *ap
; ++ap
) {
1146 if (*argv
== NULL
) {
1147 warnx("option requires an argument -- %c", *ap
);
1150 if ((nargv
[0] = malloc(strlen(*argv
) + 2 + 1)) == NULL
)
1151 err(X_STARTUP
, "malloc arg");
1154 (void)strcpy(&nargv
[0][2], *argv
);
1168 /* Terminate flags. */
1174 /* Copy remaining arguments. */
1175 while ((*nargv
++ = *argv
++));
1177 /* Update argument count. */
1178 *argcp
= nargv
- *argvp
- 1;
1182 * This tests whether an inode is in the exclude list
1185 exclude_ino(dump_ino_t ino
)
1188 if (iexclude_num
) { /* if there are inodes in the exclude list */
1189 int idx
; /* then check this inode against it */
1190 for (idx
= 0; idx
< iexclude_num
; idx
++)
1191 if (ino
== iexclude_list
[idx
])
1198 * This tests adds an inode to the exclusion list if it isn't already there
1201 do_exclude_ino(dump_ino_t ino
, const char *reason
)
1203 if (!exclude_ino(ino
)) {
1204 if (iexclude_num
== IEXCLUDE_MAXNUM
) {
1205 msg("Too many exclude options\n");
1206 msg("The ENTIRE dump is aborted.\n");
1210 msg("Added inode %u to exclude list (%s)\n",
1213 msg("Added inode %u to exclude list\n", ino
);
1214 iexclude_list
[iexclude_num
++] = ino
;
1219 do_exclude_ino_str(char * ino
) {
1223 inod
= strtoul(ino
, &r
, 10);
1224 if (*r
!= '\0' || inod
<= ROOTINO
) {
1225 msg("Invalid inode argument %s\n", ino
);
1226 msg("The ENTIRE dump is aborted.\n");
1229 do_exclude_ino(inod
, NULL
);
1233 * This reads a file containing one inode number per line and exclude them all
1236 do_exclude_from_file(char *file
) {
1238 char *p
, fname
[MAXPATHLEN
];
1241 if (!( f
= fopen(file
, "r")) ) {
1242 msg("Cannot open file for reading: %s\n", file
);
1243 msg("The ENTIRE dump is aborted.\n");
1246 while (( p
= fgets(fname
, MAXPATHLEN
, f
))) {
1247 if ( *p
&& *(p
+ strlen(p
) - 1) == '\n' ) /* possible null string */
1248 *(p
+ strlen(p
) - 1) = '\0';
1249 if ( !*p
) /* skip empty lines */
1251 do_exclude_ino_str(p
);
1256 static void incompat_flags(int cond
, char flag1
, char flag2
) {
1258 msg("You cannot use the %c and %c flags together.\n",
1260 msg("The ENTIRE dump is aborted.\n");