]>
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 <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.73 2002/07/17 10:18:52 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 */
99 char *metainomap
; /* which of the inodes in dumpinomap will get
100 only their metadata dumped */
102 const char *disk
; /* name of the disk file */
103 char tape
[MAXPATHLEN
];/* name of the tape file */
104 char *tapeprefix
; /* prefix of the tape file */
105 char *dumpdates
; /* name of the file containing dump date information*/
106 char lastlevel
; /* dump level of previous dump */
107 char level
; /* dump level of this dump */
108 int bzipflag
; /* compression is done using bzlib */
109 int Afile
= 0; /* archive file descriptor */
110 int uflag
; /* update flag */
111 int mflag
; /* dump metadata only if possible */
112 int Mflag
; /* multi-volume flag */
113 int qflag
; /* quit on errors flag */
114 int vflag
; /* verbose flag */
115 int breademax
= 32; /* maximum number of bread errors before we quit */
116 char *eot_script
; /* end of volume script fiag */
117 int diskfd
; /* disk file descriptor */
118 int tapefd
; /* tape file descriptor */
119 int pipeout
; /* true => output to standard output */
120 int fifoout
; /* true => output to fifo */
121 dump_ino_t curino
; /* current inumber; used globally */
122 int newtape
; /* new tape flag */
123 int density
; /* density in 0.1" units */
124 long tapesize
; /* estimated tape size, blocks */
125 long tsize
; /* tape size in 0.1" units */
126 long asize
; /* number of 0.1" units written on current tape */
127 int etapes
; /* estimated number of tapes */
128 int nonodump
; /* if set, do not honor UF_NODUMP user flags */
129 int unlimited
; /* if set, write to end of medium */
130 int compressed
; /* if set, dump is to be compressed */
131 long long bytes_written
;/* total bytes written to tape */
132 long uncomprblks
; /* uncompressed blocks written to tape */
133 int notify
; /* notify operator flag */
134 int blockswritten
; /* number of blocks written on current tape */
135 int tapeno
; /* current tape number */
136 time_t tstart_writing
; /* when started writing the first tape block */
137 time_t tend_writing
; /* after writing the last tape block */
141 struct fs
*sblock
; /* the file system super block */
142 char sblock_buf
[MAXBSIZE
];
144 long xferrate
; /* averaged transfer rate of all volumes */
145 long dev_bsize
; /* block size of underlying disk device */
146 int dev_bshift
; /* log2(dev_bsize) */
147 int tp_bshift
; /* log2(TP_BSIZE) */
148 dump_ino_t volinfo
[TP_NINOS
];/* which inode on which volume archive info */
154 int32_t gThisDumpDate
;
157 struct dumptime
*dthead
; /* head of the list version */
158 int nddates
; /* number of records (might be zero) */
159 int ddates_in
; /* we have read the increment file */
160 struct dumpdates
**ddatev
; /* the arrayfied version */
162 int notify
= 0; /* notify operator flag */
163 int blockswritten
= 0; /* number of blocks written on current tape */
164 int tapeno
= 0; /* current tape number */
165 int density
= 0; /* density in bytes/0.1" " <- this is for hilit19 */
166 int ntrec
= NTREC
; /* # tape blocks in each tape record */
167 int cartridge
= 0; /* Assume non-cartridge tape */
169 int tapepos
= 0; /* assume no QFA tapeposition needed by user */
171 int dokerberos
= 0; /* Use Kerberos authentication */
172 long dev_bsize
= 1; /* recalculated below */
173 long blocksperfile
; /* output blocks per file */
174 char *host
= NULL
; /* remote host (if any) */
175 int sizest
= 0; /* return size estimate only */
176 int compressed
= 0; /* use zlib to compress the output, compress level 1-9 */
177 long long bytes_written
= 0; /* total bytes written */
178 long uncomprblks
= 0;/* uncompressed blocks written */
184 int maxbsize
= 64*1024; /* XXX MAXBSIZE from sys/param.h */
185 static long numarg
__P((const char *, long, long));
186 static void obsolete
__P((int *, char **[]));
187 static void usage
__P((void));
188 static void do_exclude_from_file
__P((char *));
189 static void do_exclude_ino_str
__P((char *));
190 static void incompat_flags
__P((int, char, char));
192 static dump_ino_t iexclude_list
[IEXCLUDE_MAXNUM
];/* the inode exclude list */
193 static int iexclude_num
= 0; /* number of elements in the list */
196 main(int argc
, char *argv
[])
204 int i
, anydirskipped
;
205 int aflag
= 0, bflag
= 0, Tflag
= 0, honorlevel
= 1;
211 char directory
[MAXPATHLEN
];
212 char pathname
[MAXPATHLEN
];
218 spcl
.c_label
[0] = '\0';
219 spcl
.c_date
= time(NULL
);
222 __progname
= argv
[0];
224 initialize_ext2_error_table();
227 tsize
= 0; /* Default later, based on 'c' option for cart tapes */
230 if ((tapeprefix
= getenv("TAPE")) == NULL
)
231 tapeprefix
= _PATH_DEFTAPE
;
232 dumpdates
= _PATH_DUMPDATES
;
233 if (TP_BSIZE
/ DEV_BSIZE
== 0 || TP_BSIZE
% DEV_BSIZE
!= 0)
234 quit("TP_BSIZE must be a multiple of DEV_BSIZE\n");
240 obsolete(&argc
, &argv
);
246 while ((ch
= getopt(argc
, argv
,
247 "0123456789A:aB:b:cd:e:E:f:F:h:I:"
266 case '0': case '1': case '2': case '3': case '4':
267 case '5': case '6': case '7': case '8': case '9':
271 case 'A': /* archive file */
273 if ((Afile
= open(Apath
, O_RDWR
|O_CREAT
|O_TRUNC
,
274 S_IRUSR
| S_IWUSR
)) < 0) {
275 msg("Cannot open %s for writing: %s\n",
276 optarg
, strerror(errno
));
277 msg("The ENTIRE dump is aborted.\n");
280 memset(volinfo
, 0, TP_NINOS
* sizeof(dump_ino_t
));
283 case 'a': /* `auto-size', Write to EOM. */
288 case 'B': /* blocks per output file */
290 blocksperfile
= numarg("number of blocks per file",
294 case 'b': /* blocks per tape write */
295 ntrec
= numarg("number of blocks per write",
297 if (ntrec
> maxbsize
/1024) {
298 msg("Please choose a blocksize <= %dkB\n",
300 msg("The ENTIRE dump is aborted.\n");
306 case 'c': /* Tape is cart. not 9-track */
311 case 'd': /* density, in bits per inch */
313 density
= numarg("density", 10L, 327670L) / 10;
314 if (density
>= 625 && !bflag
)
315 ntrec
= HIGHDENSITYTREC
;
319 case 'e': /* exclude an inode */
321 char *p
= optarg
, *q
;
322 while ((q
= strchr(p
, ','))) {
324 do_exclude_ino_str(p
);
327 do_exclude_ino_str(p
);
331 case 'E': /* exclude inodes read from file */
332 do_exclude_from_file(optarg
);
335 case 'f': /* output file */
339 case 'F': /* end of tape script */
344 honorlevel
= numarg("honor level", 0L, 10L);
352 compressed
= numarg("compress level", 1L, 9L);
354 #endif /* HAVE_BZLIB */
358 numarg ("number of errors to ignore", 1L, 0L);
369 * Note that although there are LBLSIZE characters,
370 * the last must be '\0', so the limit on strlen()
371 * is really LBLSIZE-1.
373 strncpy(spcl
.c_label
, optarg
, LBLSIZE
);
374 spcl
.c_label
[LBLSIZE
-1] = '\0';
375 if (strlen(optarg
) > LBLSIZE
-1) {
377 "WARNING Label `%s' is larger than limit of %d characters.\n",
379 msg("WARNING: Using truncated label `%s'.\n",
384 case 'm': /* metadata only flag */
388 case 'M': /* multi-volume flag */
392 case 'n': /* notify operators */
401 case 'Q': /* create tapeposfile */
402 gTapeposfile
= optarg
;
407 case 's': /* tape size, feet */
409 tsize
= numarg("tape size", 1L, 0L) * 12 * 10;
413 sizest
= 1; /* return size estimate only */
416 case 'T': /* time of last dump */
417 spcl
.c_ddate
= unctime(optarg
);
418 if (spcl
.c_ddate
< 0) {
419 msg("bad time \"%s\"\n", optarg
);
420 msg("The ENTIRE dump is aborted.\n");
427 case 'u': /* update dumpdates */
431 case 'v': /* verbose */
435 case 'W': /* what to do */
438 exit(X_FINOK
); /* do nothing else */
443 compressed
= numarg("compress level", 1L, 9L);
445 #endif /* HAVE_ZLIB */
454 msg("Must specify disk or filesystem\n");
455 msg("The ENTIRE dump is aborted.\n");
459 if (strlen(diskparam
) >= MAXPATHLEN
) {
460 msg("Disk or filesystem name too long: %s\n", diskparam
);
461 msg("The ENTIRE dump is aborted.\n");
465 incompat_flags(Tflag
&& uflag
, 'T', 'u');
466 incompat_flags(aflag
&& blocksperfile
, 'a', 'B');
467 incompat_flags(aflag
&& cartridge
, 'a', 'c');
468 incompat_flags(aflag
&& density
, 'a', 'd');
469 incompat_flags(aflag
&& tsize
, 'a', 's');
471 if (strcmp(tapeprefix
, "-") == 0) {
473 tapeprefix
= "standard output";
476 if (blocksperfile
&& !compressed
)
477 blocksperfile
= blocksperfile
/ ntrec
* ntrec
; /* round down */
478 else if (!unlimited
) {
480 * Determine how to default tape size and density
483 * 9-track 1600 bpi (160 bytes/.1") 2300 ft.
484 * 9-track 6250 bpi (625 bytes/.1") 2300 ft.
485 * cartridge 8000 bpi (100 bytes/.1") 1700 ft.
487 * hilit19 hits again: "
490 density
= cartridge
? 100 : 160;
492 tsize
= cartridge
? 1700L*120L : 2300L*120L;
495 if (strchr(tapeprefix
, ':')) {
497 tapeprefix
= strchr(host
, ':');
498 *tapeprefix
++ = '\0';
500 if (index(tapeprefix
, '\n')) {
501 msg("invalid characters in tape\n");
502 msg("The ENTIRE dump is aborted.\n");
505 if (rmthost(host
) == 0)
508 msg("remote dump not enabled\n");
509 msg("The ENTIRE dump is aborted.\n");
513 (void)setuid(getuid()); /* rmthost() is the only reason to be setuid */
515 if (signal(SIGHUP
, SIG_IGN
) != SIG_IGN
)
517 if (signal(SIGTRAP
, SIG_IGN
) != SIG_IGN
)
518 signal(SIGTRAP
, sig
);
519 if (signal(SIGFPE
, SIG_IGN
) != SIG_IGN
)
521 if (signal(SIGBUS
, SIG_IGN
) != SIG_IGN
)
523 if (signal(SIGSEGV
, SIG_IGN
) != SIG_IGN
)
524 signal(SIGSEGV
, sig
);
525 if (signal(SIGTERM
, SIG_IGN
) != SIG_IGN
)
526 signal(SIGTERM
, sig
);
527 if (signal(SIGINT
, interrupt
) == SIG_IGN
)
528 signal(SIGINT
, SIG_IGN
);
530 signal(SIGXCPU
, SIG_IGN
);
533 signal(SIGXFSZ
, SIG_IGN
);
536 set_operators(); /* /etc/group snarfed */
537 getfstab(); /* /etc/fstab snarfed */
540 * disk may end in / and this can confuse
543 i
= strlen(diskparam
) - 1;
544 if (i
> 1 && diskparam
[i
] == '/')
545 if (!(i
== 6 && !strcmp(diskparam
, "LABEL=/")))
548 disk
= get_device_name(diskparam
);
549 if (!disk
) { /* null means the disk is some form
550 of LABEL= or UID= but it was not
552 msg("Cannot find a disk having %s\n", diskparam
);
553 msg("The ENTIRE dump is aborted.\n");
557 * disk can be either the full special file name,
558 * the suffix of the special file name,
559 * the special name missing the leading '/',
560 * the file system name with or without the leading '/'.
562 if ((dt
= fstabsearch(disk
)) != NULL
) {
563 /* if found then only one parameter (i.e. partition)
566 (void)fprintf(stderr
, "Unknown arguments to dump:");
568 (void)fprintf(stderr
, " %s", *argv
++);
569 (void)fprintf(stderr
, "\n");
570 msg("The ENTIRE dump is aborted.\n");
573 disk
= rawname(dt
->fs_spec
);
574 (void)strncpy(spcl
.c_dev
, dt
->fs_spec
, NAMELEN
);
575 (void)strncpy(spcl
.c_filesys
, dt
->fs_file
, NAMELEN
);
579 if (realpath(disk
, pathname
) == NULL
)
581 strcpy(pathname
, disk
);
583 * The argument could be now a mountpoint of
584 * a filesystem specified in fstab. Search for it.
586 if ((dt
= fstabsearch(pathname
)) != NULL
) {
587 disk
= rawname(dt
->fs_spec
);
588 (void)strncpy(spcl
.c_dev
, dt
->fs_spec
, NAMELEN
);
589 (void)strncpy(spcl
.c_filesys
, dt
->fs_file
, NAMELEN
);
592 * The argument was not found in the fstab
593 * assume that this is a subtree and search for it
595 dt
= fstabsearchdir(pathname
, directory
);
597 char name
[MAXPATHLEN
];
598 (void)strncpy(spcl
.c_dev
, dt
->fs_spec
, NAMELEN
);
599 (void)snprintf(name
, sizeof(name
), "%s (dir %s)",
600 dt
->fs_file
, directory
);
601 (void)strncpy(spcl
.c_filesys
, name
, NAMELEN
);
602 disk
= rawname(dt
->fs_spec
);
604 (void)strncpy(spcl
.c_dev
, disk
, NAMELEN
);
605 (void)strncpy(spcl
.c_filesys
, "an unlisted file system",
610 (void)strncpy(spcl
.c_dev
, disk
, NAMELEN
);
611 (void)strncpy(spcl
.c_filesys
, "an unlisted file system",
616 if (directory
[0] != 0) {
618 msg("Only level 0 dumps are allowed on a subdirectory\n");
619 msg("The ENTIRE dump is aborted.\n");
623 msg("You can't update the dumpdates file when dumping a subdirectory\n");
624 msg("The ENTIRE dump is aborted.\n");
628 spcl
.c_dev
[NAMELEN
-1] = '\0';
629 spcl
.c_filesys
[NAMELEN
-1] = '\0';
630 (void)gethostname(spcl
.c_host
, NAMELEN
);
631 spcl
.c_host
[NAMELEN
-1] = '\0';
632 spcl
.c_level
= level
- '0';
633 spcl
.c_type
= TS_TAPE
;
635 getdumptime(uflag
); /* dumpdates snarfed */
637 if (spcl
.c_ddate
== 0 && spcl
.c_level
) {
638 msg("WARNING: There is no inferior level dump on this filesystem\n");
639 msg("WARNING: Assuming a level 0 dump by default\n");
645 snprintf(tape
, MAXPATHLEN
, "%s%03d", tapeprefix
, tapeno
+ 1);
647 strncpy(tape
, tapeprefix
, MAXPATHLEN
);
648 tape
[MAXPATHLEN
- 1] = '\0';
651 if (STAT(tape
, &statbuf
) != -1)
652 fifoout
= statbuf
.st_mode
& S_IFIFO
;
657 msg("Date of this level %c dump: %s", level
,
658 ctime4(&spcl
.c_date
));
660 gThisDumpDate
= spcl
.c_date
;
663 msg("Date of last level %c dump: %s", lastlevel
,
664 ctime4(&spcl
.c_ddate
));
665 msg("Dumping %s (%s) ", disk
, spcl
.c_filesys
);
667 msgtail("to %s on host %s\n", tape
, host
);
669 msgtail("to %s\n", tape
);
670 } /* end of size estimate */
673 if ((diskfd
= OPEN(disk
, O_RDONLY
)) < 0) {
674 msg("Cannot open %s\n", disk
);
675 msg("The ENTIRE dump is aborted.\n");
679 (void)ioctl(diskfd
, BLKFLSBUF
);
681 retval
= dump_fs_open(disk
, &fs
);
683 com_err(disk
, retval
, "while opening filesystem");
684 if (retval
== EXT2_ET_REV_TOO_HIGH
)
685 msg("Get a newer version of dump!\n");
686 msg("The ENTIRE dump is aborted.\n");
689 if (fs
->super
->s_rev_level
> DUMP_CURRENT_REV
) {
690 com_err(disk
, retval
, "while opening filesystem");
691 msg("Get a newer version of dump!\n");
692 msg("The ENTIRE dump is aborted.\n");
695 /* if no user label specified, use ext2 filesystem label if available */
696 if (spcl
.c_label
[0] == '\0') {
698 if ( (lbl
= get_device_label(disk
)) != NULL
) {
699 strncpy(spcl
.c_label
, lbl
, LBLSIZE
);
700 spcl
.c_label
[LBLSIZE
-1] = '\0';
703 strcpy(spcl
.c_label
, "none"); /* safe strcpy. */
706 dev_bsize
= DEV_BSIZE
;
707 dev_bshift
= ffs(dev_bsize
) - 1;
708 if (dev_bsize
!= (1 << dev_bshift
))
709 quit("dev_bsize (%d) is not a power of 2", dev_bsize
);
710 tp_bshift
= ffs(TP_BSIZE
) - 1;
711 if (TP_BSIZE
!= (1 << tp_bshift
))
712 quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE
);
713 maxino
= fs
->super
->s_inodes_count
+ 1;
714 spcl
.c_flags
|= DR_NEWINODEFMT
;
715 #else /* __linux __*/
716 if ((diskfd
= open(disk
, O_RDONLY
)) < 0) {
717 msg("Cannot open %s\n", disk
);
718 msg("The ENTIRE dump is aborted.\n");
722 sblock
= (struct fs
*)sblock_buf
;
723 bread(SBOFF
, (char *) sblock
, SBSIZE
);
724 if (sblock
->fs_magic
!= FS_MAGIC
)
725 quit("bad sblock magic number\n");
726 dev_bsize
= sblock
->fs_fsize
/ fsbtodb(sblock
, 1);
727 dev_bshift
= ffs(dev_bsize
) - 1;
728 if (dev_bsize
!= (1 << dev_bshift
))
729 quit("dev_bsize (%d) is not a power of 2", dev_bsize
);
730 tp_bshift
= ffs(TP_BSIZE
) - 1;
731 if (TP_BSIZE
!= (1 << tp_bshift
))
732 quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE
);
734 if (sblock
->fs_inodefmt
>= FS_44INODEFMT
)
735 spcl
.c_flags
|= DR_NEWINODEFMT
;
737 maxino
= sblock
->fs_ipg
* sblock
->fs_ncg
;
738 #endif /* __linux__ */
739 mapsize
= roundup(howmany(maxino
, NBBY
), TP_BSIZE
);
740 usedinomap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
741 dumpdirmap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
742 dumpinomap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
743 metainomap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
744 if (usedinomap
== NULL
|| dumpdirmap
== NULL
||
745 dumpinomap
== NULL
|| metainomap
== NULL
)
746 quit("out of memory allocating inode maps\n");
747 tapesize
= 2 * (howmany(mapsize
* sizeof(char), TP_BSIZE
) + 1);
749 nonodump
= spcl
.c_level
< honorlevel
;
752 msg("Label: %s\n", spcl
.c_label
);
755 msg("Compressing output at compression level %d (%s)\n",
756 compressed
, bzipflag
? "bzlib" : "zlib");
760 (void)signal(SIGINFO
, statussig
);
764 msg("mapping (Pass I) [regular files]\n");
766 if (directory
[0] == 0)
767 anydirskipped
= mapfiles(maxino
, &tapesize
);
769 if (STAT(pathname
, &statbuf
) == -1) {
770 msg("File cannot be accessed (%s).\n", pathname
);
771 msg("The ENTIRE dump is aborted.\n");
774 filedev
= statbuf
.st_dev
;
775 if (!(statbuf
.st_mode
& S_IFDIR
)) /* is a file */
776 anydirskipped
= maponefile(maxino
, &tapesize
,
779 anydirskipped
= mapfilesfromdir(maxino
, &tapesize
,
785 /* check if file is available */
786 if (STAT(p
, &statbuf
) == -1) {
787 msg("File cannot be accessed (%s).\n", p
);
788 msg("The ENTIRE dump is aborted.\n");
791 /* check if file is on same unix partiton as the first
793 if (statbuf
.st_dev
!= filedev
) {
794 msg("Files are not on same file system (%s).\n", p
);
795 msg("The ENTIRE dump is aborted.\n");
798 /* check if file is a directory */
799 if (!(statbuf
.st_mode
& S_IFDIR
))
800 anydirskipped2
= maponefile(maxino
, &tapesize
,
801 p
+strlen(dt
->fs_file
));
803 /* read directory inodes.
804 * NOTE: nested directories are not recognized
805 * so inodes may be umped twice!
807 anydirskipped2
= mapfilesfromdir(maxino
, &tapesize
,
808 p
+strlen(dt
->fs_file
));
810 anydirskipped
= anydirskipped2
;
814 anydirskipped
= mapfiles(maxino
, &tapesize
);
818 msg("mapping (Pass II) [directories]\n");
819 while (anydirskipped
) {
820 anydirskipped
= mapdirs(maxino
, &tapesize
);
824 printf("%.0f\n", ((double)tapesize
+ 1 + ntrec
) * TP_BSIZE
);
826 } /* stop here for size estimate */
828 if (pipeout
|| unlimited
) {
829 tapesize
+= 1 + ntrec
; /* 1 map header + trailer blocks */
830 msg("estimated %ld tape blocks.\n", tapesize
);
835 fetapes
= (double) tapesize
/ blocksperfile
;
836 else if (cartridge
) {
837 /* Estimate number of tapes, assuming streaming stops at
838 the end of each block written, and not in mid-block.
839 Assume no erroneous blocks; this can be compensated
840 for with an artificially low tape size. */
842 ( (double) tapesize
/* blocks */
843 * TP_BSIZE
/* bytes/block */
844 * (1.0/density
) /* 0.1" / byte " */
846 (double) tapesize
/* blocks */
847 * (1.0/ntrec
) /* streaming-stops per block */
848 * 15.48 /* 0.1" / streaming-stop " */
849 ) * (1.0 / tsize
); /* tape / 0.1" " */
851 /* Estimate number of tapes, for old fashioned 9-track
853 int tenthsperirg
= (density
== 625) ? 3 : 7;
855 ( (double) tapesize
/* blocks */
856 * TP_BSIZE
/* bytes / block */
857 * (1.0/density
) /* 0.1" / byte " */
859 (double) tapesize
/* blocks */
860 * (1.0/ntrec
) /* IRG's / block */
861 * tenthsperirg
/* 0.1" / IRG " */
862 ) * (1.0 / tsize
); /* tape / 0.1" " */
864 etapes
= fetapes
; /* truncating assignment */
866 /* count the dumped inodes map on each additional tape */
867 tapesize
+= (etapes
- 1) *
868 (howmany(mapsize
* sizeof(char), TP_BSIZE
) + 1);
869 tapesize
+= etapes
+ ntrec
; /* headers + trailer blks */
870 msg("estimated %ld tape blocks on %3.2f tape(s).\n",
876 msg("writing QFA positions to %s\n", gTapeposfile
);
877 if ((gTapeposfd
= open(gTapeposfile
, O_RDWR
|O_CREAT
|O_TRUNC
, S_IRUSR
| S_IWUSR
)) < 0)
878 quit("can't open tapeposfile\n");
879 /* print QFA-file header */
880 snprintf(gTps
, sizeof(gTps
), "%s\n%s\n%ld\n\n", QFA_MAGIC
, QFA_VERSION
, (unsigned long)spcl
.c_date
);
881 gTps
[sizeof(gTps
) - 1] = '\0';
882 if (write(gTapeposfd
, gTps
, strlen(gTps
)) != strlen(gTps
))
883 quit("can't write tapeposfile\n");
884 sprintf(gTps
, "ino\ttapeno\ttapepos\n");
885 if (write(gTapeposfd
, gTps
, strlen(gTps
)) != strlen(gTps
))
886 quit("can't write tapeposfile\n");
891 * Allocate tape buffer.
895 "can't allocate tape buffers - try a smaller blocking factor.\n");
898 tstart_writing
= time(NULL
);
899 dumpmap(usedinomap
, TS_CLRI
, maxino
- 1);
901 msg("dumping (Pass III) [directories]\n");
902 dirty
= 0; /* XXX just to get gcc to shut up */
903 for (map
= dumpdirmap
, ino
= 1; ino
< maxino
; ino
++) {
904 if (((ino
- 1) % NBBY
) == 0) /* map is offset by 1 */
908 if ((dirty
& 1) == 0)
911 * Skip directory inodes deleted and maybe reallocated
914 if ((dp
->di_mode
& IFMT
) != IFDIR
)
918 * Skip directory inodes deleted and not yes reallocated...
920 if (dp
->di_nlink
== 0 || dp
->di_dtime
!= 0)
923 msg("dumping directory inode %lu\n", ino
);
924 (void)dumpdirino(dp
, ino
);
926 (void)dumpino(dp
, ino
);
930 msg("dumping (Pass IV) [regular files]\n");
931 for (map
= dumpinomap
, ino
= 1; ino
< maxino
; ino
++) {
932 if (((ino
- 1) % NBBY
) == 0) /* map is offset by 1 */
936 if ((dirty
& 1) == 0)
939 * Skip inodes deleted and reallocated as directories.
942 if ((dp
->di_mode
& IFMT
) == IFDIR
)
946 * No need to check here for deleted and not yet reallocated
947 * inodes since this is done in dumpino().
951 if (mflag
&& TSTINO(ino
, metainomap
))
952 msg("dumping regular inode %lu (meta only)\n", ino
);
954 msg("dumping regular inode %lu\n", ino
);
956 (void)dumpino(dp
, ino
, mflag
&& TSTINO(ino
, metainomap
));
959 tend_writing
= time(NULL
);
960 spcl
.c_type
= TS_END
;
963 volinfo
[1] = ROOTINO
;
964 memcpy(spcl
.c_inos
, volinfo
, TP_NINOS
* sizeof(dump_ino_t
));
965 spcl
.c_flags
|= DR_INODEINFO
;
969 * Finish off the current tape record with trailer blocks, to ensure
970 * at least the data in the last partial record makes it to tape.
971 * Also make sure we write at least 1 trailer block.
973 for (i
= ntrec
- (spcl
.c_tapea
% ntrec
); i
; --i
)
974 writeheader(maxino
- 1);
978 if (pipeout
|| fifoout
)
979 msg("%ld tape blocks (%.2fMB)\n", spcl
.c_tapea
,
980 ((double)spcl
.c_tapea
* TP_BSIZE
/ 1048576));
982 msg("%ld tape blocks (%.2fMB) on %d volume(s)\n",
984 ((double)spcl
.c_tapea
* TP_BSIZE
/ 1048576),
987 /* report dump performance, avoid division by zero */
988 if (tend_writing
- tstart_writing
== 0)
989 msg("finished in less than a second\n");
991 msg("finished in %d seconds, throughput %d kBytes/sec\n",
992 tend_writing
- tstart_writing
,
993 spcl
.c_tapea
/ (tend_writing
- tstart_writing
));
996 msg("Date of this level %c dump: %s", level
,
997 spcl
.c_date
== 0 ? "the epoch\n" : ctime4(&spcl
.c_date
));
998 msg("Date this dump completed: %s", ctime(&tnow
));
1000 msg("Average transfer rate: %ld kB/s\n", xferrate
/ tapeno
);
1002 long tapekb
= bytes_written
/ 1024;
1003 double rate
= .0005 + (double) spcl
.c_tapea
/ tapekb
;
1004 msg("Wrote %ldkB uncompressed, %ldkB compressed, %1.3f:1\n",
1005 spcl
.c_tapea
, tapekb
, rate
);
1009 msg("Archiving dump to %s\n", Apath
);
1011 broadcast("DUMP IS DONE!\7\7\n");
1012 msg("DUMP IS DONE\n");
1015 return 0; /* gcc - shut up */
1021 char white
[MAXPATHLEN
];
1022 const char *ext2ver
, *ext2date
;
1024 memset(white
, ' ', MAXPATHLEN
);
1025 white
[MIN(strlen(__progname
), MAXPATHLEN
- 1)] = '\0';
1028 ext2fs_get_library_version(&ext2ver
, &ext2date
);
1029 fprintf(stderr
, "%s %s (using libext2fs %s of %s)\n",
1030 __progname
, _DUMP_VERSION
, ext2ver
, ext2date
);
1032 fprintf(stderr
, "%s %s\n", __progname
, _DUMP_VERSION
);
1035 "usage:\t%s [-0123456789ac"
1040 "] [-A file] [-B records] [-b blocksize]\n"
1041 "\t%s [-d density] [-e inode#,inode#,...] [-E file] [-f file]\n"
1042 "\t%s [-h level] [-I nr errors] "
1056 __progname
, white
, white
, white
, __progname
);
1061 * Pick up a numeric argument. It must be nonnegative and in the given
1062 * range (except that a vmax of 0 means unlimited).
1065 numarg(const char *meaning
, long vmin
, long vmax
)
1070 val
= strtol(optarg
, &p
, 10);
1072 errx(X_STARTUP
, "illegal %s -- %s", meaning
, optarg
);
1073 if (val
< vmin
|| (vmax
&& val
> vmax
))
1074 errx(X_STARTUP
, "%s must be between %ld and %ld", meaning
, vmin
, vmax
);
1088 if (pipeout
|| fifoout
)
1089 quit("Signal on pipe: cannot recover\n");
1090 msg("Rewriting attempted as response to unknown signal: %d.\n", signo
);
1091 (void)fflush(stderr
);
1092 (void)fflush(stdout
);
1097 msg("SIGSEGV: ABORTING!\n");
1098 (void)signal(SIGSEGV
, SIG_DFL
);
1099 (void)kill(0, SIGSEGV
);
1105 rawname(const char *cp
)
1109 #else /* __linux__ */
1110 static char rawbuf
[MAXPATHLEN
];
1111 char *dp
= strrchr(cp
, '/');
1115 (void)strncpy(rawbuf
, cp
, min(dp
-cp
, MAXPATHLEN
- 1));
1116 rawbuf
[min(dp
-cp
, MAXPATHLEN
-1)] = '\0';
1117 (void)strncat(rawbuf
, "/r", MAXPATHLEN
- 1 - strlen(rawbuf
));
1118 (void)strncat(rawbuf
, dp
+ 1, MAXPATHLEN
- 1 - strlen(rawbuf
));
1120 #endif /* __linux__ */
1125 * Change set of key letters and ordered arguments into something
1126 * getopt(3) will like.
1129 obsolete(int *argcp
, char **argvp
[])
1132 char *ap
, **argv
, *flagsp
=NULL
, **nargv
, *p
=NULL
;
1138 /* Return if no arguments or first argument has leading dash. */
1140 if (argc
== 1 || *ap
== '-')
1143 /* Allocate space for new arguments. */
1144 if ((*argvp
= nargv
= malloc((argc
+ 1) * sizeof(char *))) == NULL
||
1145 (p
= flagsp
= malloc(strlen(ap
) + 2)) == NULL
)
1146 err(X_STARTUP
, "malloc new args");
1151 for (flags
= 0; *ap
; ++ap
) {
1166 if (*argv
== NULL
) {
1167 warnx("option requires an argument -- %c", *ap
);
1170 if ((nargv
[0] = malloc(strlen(*argv
) + 2 + 1)) == NULL
)
1171 err(X_STARTUP
, "malloc arg");
1174 (void)strcpy(&nargv
[0][2], *argv
);
1188 /* Terminate flags. */
1194 /* Copy remaining arguments. */
1195 while ((*nargv
++ = *argv
++));
1197 /* Update argument count. */
1198 *argcp
= nargv
- *argvp
- 1;
1202 * This tests whether an inode is in the exclude list
1205 exclude_ino(dump_ino_t ino
)
1208 if (iexclude_num
) { /* if there are inodes in the exclude list */
1209 int idx
; /* then check this inode against it */
1210 for (idx
= 0; idx
< iexclude_num
; idx
++)
1211 if (ino
== iexclude_list
[idx
])
1218 * This tests adds an inode to the exclusion list if it isn't already there
1221 do_exclude_ino(dump_ino_t ino
, const char *reason
)
1223 if (!exclude_ino(ino
)) {
1224 if (iexclude_num
== IEXCLUDE_MAXNUM
) {
1225 msg("Too many exclude options\n");
1226 msg("The ENTIRE dump is aborted.\n");
1230 msg("Added inode %u to exclude list (%s)\n",
1233 msg("Added inode %u to exclude list\n", ino
);
1234 iexclude_list
[iexclude_num
++] = ino
;
1239 do_exclude_ino_str(char * ino
) {
1243 inod
= strtoul(ino
, &r
, 10);
1244 if (*r
!= '\0' || inod
<= ROOTINO
) {
1245 msg("Invalid inode argument %s\n", ino
);
1246 msg("The ENTIRE dump is aborted.\n");
1249 do_exclude_ino(inod
, NULL
);
1253 * This reads a file containing one inode number per line and exclude them all
1256 do_exclude_from_file(char *file
) {
1258 char *p
, fname
[MAXPATHLEN
];
1261 if (!( f
= fopen(file
, "r")) ) {
1262 msg("Cannot open file for reading: %s\n", file
);
1263 msg("The ENTIRE dump is aborted.\n");
1266 while (( p
= fgets(fname
, MAXPATHLEN
, f
))) {
1267 if ( *p
&& *(p
+ strlen(p
) - 1) == '\n' ) /* possible null string */
1268 *(p
+ strlen(p
) - 1) = '\0';
1269 if ( !*p
) /* skip empty lines */
1271 do_exclude_ino_str(p
);
1276 static void incompat_flags(int cond
, char flag1
, char flag2
) {
1278 msg("You cannot use the %c and %c flags together.\n",
1280 msg("The ENTIRE dump is aborted.\n");