]>
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. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 static const char rcsid
[] =
40 "$Id: main.c,v 1.92 2004/04/21 08:55:51 stelian Exp $";
44 #include <compatlfs.h>
46 #include <compaterr.h>
57 #include <sys/param.h>
61 #ifdef HAVE_EXT2FS_EXT2_FS_H
62 #include <ext2fs/ext2_fs.h>
64 #include <linux/ext2_fs.h>
66 #include <ext2fs/ext2fs.h>
68 #include <bsdcompat.h>
69 #include <linux/fs.h> /* for definition of BLKFLSBUF */
71 #include <sys/vnode.h>
73 #include <ufs/inode.h>
76 #include <ufs/ufs/dinode.h>
77 #include <ufs/ffs/fs.h>
80 #include <protocols/dumprestore.h>
83 #include "pathnames.h"
87 #define SBOFF (SBLOCK * DEV_BSIZE)
90 int abortifconnerr
= 1; /* set to 1 if lib dumprmt.o should exit on connection errors
91 otherwise just print a message using msg */
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
[NUM_STR_SIZE
];/* dump level of previous dump */
107 char level
[NUM_STR_SIZE
];/* dump level of this dump */
108 int zipflag
; /* which compression method */
109 int Afile
= -1; /* archive file descriptor */
110 int AfileActive
= 1;/* Afile flag */
111 int uflag
; /* update flag */
112 int mflag
; /* dump metadata only if possible */
113 int Mflag
; /* multi-volume flag */
114 int qflag
; /* quit on errors flag */
115 int vflag
; /* verbose flag */
116 int breademax
= 32; /* maximum number of bread errors before we quit */
117 char *eot_script
; /* end of volume script fiag */
118 int diskfd
; /* disk file descriptor */
119 int tapefd
; /* tape file descriptor */
120 int pipeout
; /* true => output to standard output */
121 int fifoout
; /* true => output to fifo */
122 dump_ino_t curino
; /* current inumber; used globally */
123 int newtape
; /* new tape flag */
124 int density
; /* density in 0.1" units */
125 long tapesize
; /* estimated tape size, blocks */
126 long tsize
; /* tape size in 0.1" units */
127 long asize
; /* number of 0.1" units written on current tape */
128 int etapes
; /* estimated number of tapes */
129 int nonodump
; /* if set, do not honor UF_NODUMP user flags */
130 int unlimited
; /* if set, write to end of medium */
131 int compressed
; /* if set, dump is to be compressed */
132 long long bytes_written
;/* total bytes written to tape */
133 long uncomprblks
; /* uncompressed blocks written to tape */
134 int notify
; /* notify operator flag */
135 int blockswritten
; /* number of blocks written on current tape */
136 int tapeno
; /* current tape number */
137 time_t tstart_writing
; /* when started writing the first tape block */
138 time_t tend_writing
; /* after writing the last tape block */
142 struct fs
*sblock
; /* the file system super block */
143 char sblock_buf
[MAXBSIZE
];
145 long xferrate
; /* averaged transfer rate of all volumes */
146 long dev_bsize
; /* block size of underlying disk device */
147 int dev_bshift
; /* log2(dev_bsize) */
148 int tp_bshift
; /* log2(TP_BSIZE) */
149 dump_ino_t volinfo
[TP_NINOS
];/* which inode on which volume archive info */
155 int32_t gThisDumpDate
;
158 struct dumptime
*dthead
; /* head of the list version */
159 int nddates
; /* number of records (might be zero) */
160 int ddates_in
; /* we have read the increment file */
161 struct dumpdates
**ddatev
; /* the arrayfied version */
163 int notify
= 0; /* notify operator flag */
164 int blockswritten
= 0; /* number of blocks written on current tape */
165 int tapeno
= 0; /* current tape number */
166 int density
= 0; /* density in bytes/0.1" " <- this is for hilit19 */
167 int ntrec
= NTREC
; /* # blocks in each tape record */
168 int cartridge
= 0; /* Assume non-cartridge tape */
170 int tapepos
= 0; /* assume no QFA tapeposition needed by user */
172 int dokerberos
= 0; /* Use Kerberos authentication */
173 long dev_bsize
= 1; /* recalculated below */
174 long *blocksperfiles
= NULL
; /* output blocks per file(s) */
175 char *host
= NULL
; /* remote host (if any) */
176 int sizest
= 0; /* return size estimate only */
177 int compressed
= 0; /* use zlib to compress the output, compress level 1-9 */
178 long long bytes_written
= 0; /* total bytes written */
179 long uncomprblks
= 0;/* uncompressed blocks written */
187 int maxbsize
= 1024*1024; /* XXX MAXBSIZE from sys/param.h */
188 static long numarg
__P((const char *, long, long));
189 static long *numlistarg
__P((const char *, long, long));
190 static void obsolete
__P((int *, char **[]));
191 static void usage
__P((void));
192 static void do_exclude_from_file
__P((char *));
193 static void do_exclude_ino_str
__P((char *));
194 static void incompat_flags
__P((int, char, char));
196 static char* iexclude_bitmap
= NULL
; /* the inode exclude bitmap */
197 static unsigned int iexclude_bitmap_bytes
= 0; /* size of bitmap in bytes */
200 main(int argc
, char *argv
[])
208 int i
, anydirskipped
;
209 int aflag
= 0, bflag
= 0, Tflag
= 0, honorlevel
= 1;
215 char directory
[MAXPATHLEN
];
216 char pathname
[MAXPATHLEN
];
222 spcl
.c_label
[0] = '\0';
223 spcl
.c_date
= time(NULL
);
226 __progname
= argv
[0];
228 initialize_ext2_error_table();
231 tsize
= 0; /* Default later, based on 'c' option for cart tapes */
234 if ((tapeprefix
= getenv("TAPE")) == NULL
)
235 tapeprefix
= _PATH_DEFTAPE
;
236 dumpdates
= _PATH_DUMPDATES
;
237 if (TP_BSIZE
/ DEV_BSIZE
== 0 || TP_BSIZE
% DEV_BSIZE
!= 0)
238 quit("TP_BSIZE must be a multiple of DEV_BSIZE\n");
239 memset(&lastlevel
, 0, NUM_STR_SIZE
);
240 memset(&level
, 0, NUM_STR_SIZE
);
245 obsolete(&argc
, &argv
);
251 while ((ch
= getopt(argc
, argv
,
252 "0123456789A:aB:b:cd:D:e:E:f:F:h:I:"
274 case '0': case '1': case '2': case '3': case '4':
275 case '5': case '6': case '7': case '8': case '9':
276 if ((pch
>= '0') && (pch
<= '9') && (strlen(level
) < NUM_STR_SIZE
))
277 level
[strlen(level
)] = ch
;
283 case 'A': /* archive file */
287 case 'a': /* `auto-size', Write to EOM. */
292 case 'B': /* blocks per output file */
294 blocksperfiles
= numlistarg("number of blocks per file",
298 case 'b': /* blocks per tape write */
299 ntrec
= numarg("number of blocks per write",
301 if (ntrec
> maxbsize
/1024) {
302 msg("Please choose a blocksize <= %dkB\n",
304 msg("The ENTIRE dump is aborted.\n");
310 case 'c': /* Tape is cart. not 9-track */
315 case 'd': /* density, in bits per inch */
317 density
= numarg("density", 10L, 327670L) / 10;
318 if (density
>= 625 && !bflag
)
319 ntrec
= HIGHDENSITYTREC
;
322 case 'D': /* path of dumpdates file */
327 case 'e': /* exclude an inode */
329 char *p
= optarg
, *q
;
330 while ((q
= strchr(p
, ','))) {
332 do_exclude_ino_str(p
);
335 do_exclude_ino_str(p
);
339 case 'E': /* exclude inodes read from file */
340 do_exclude_from_file(optarg
);
343 case 'f': /* output file */
347 case 'F': /* end of tape script */
352 honorlevel
= numarg("honor level", 0L, 10L);
358 zipflag
= COMPRESS_BZLIB
;
360 compressed
= numarg("compress level", 1L, 9L);
362 #endif /* HAVE_BZLIB */
366 numarg ("number of errors to ignore", 0L, 0L);
377 * Note that although there are LBLSIZE characters,
378 * the last must be '\0', so the limit on strlen()
379 * is really LBLSIZE-1.
381 strncpy(spcl
.c_label
, optarg
, LBLSIZE
);
382 spcl
.c_label
[LBLSIZE
-1] = '\0';
383 if (strlen(optarg
) > LBLSIZE
-1) {
385 "WARNING Label `%s' is larger than limit of %d characters.\n",
387 msg("WARNING: Using truncated label `%s'.\n",
392 case 'm': /* metadata only flag */
396 case 'M': /* multi-volume flag */
400 case 'n': /* notify operators */
409 case 'Q': /* create tapeposfile */
410 gTapeposfile
= optarg
;
415 case 's': /* tape size, feet */
417 tsize
= numarg("tape size", 1L, 0L) * 12 * 10;
421 sizest
= 1; /* return size estimate only */
424 case 'T': /* time of last dump */
425 spcl
.c_ddate
= unctime(optarg
);
426 if (spcl
.c_ddate
< 0) {
427 msg("bad time \"%s\"\n", optarg
);
428 msg("The ENTIRE dump is aborted.\n");
432 lastlevel
[0] = '?'; lastlevel
[1] = '\0';
435 case 'u': /* update dumpdates */
439 case 'v': /* verbose */
443 case 'W': /* what to do */
446 exit(X_FINOK
); /* do nothing else */
450 zipflag
= COMPRESS_LZO
;
452 #endif /* HAVE_LZO */
457 zipflag
= COMPRESS_ZLIB
;
459 compressed
= numarg("compress level", 1L, 9L);
461 #endif /* HAVE_ZLIB */
470 msg("Must specify disk or filesystem\n");
471 msg("The ENTIRE dump is aborted.\n");
475 if (strlen(diskparam
) >= MAXPATHLEN
) {
476 msg("Disk or filesystem name too long: %s\n", diskparam
);
477 msg("The ENTIRE dump is aborted.\n");
481 incompat_flags(Tflag
&& uflag
, 'T', 'u');
482 incompat_flags(aflag
&& blocksperfiles
, 'a', 'B');
483 incompat_flags(aflag
&& cartridge
, 'a', 'c');
484 incompat_flags(aflag
&& density
, 'a', 'd');
485 incompat_flags(aflag
&& tsize
, 'a', 's');
487 if (strcmp(tapeprefix
, "-") == 0) {
489 tapeprefix
= "standard output";
492 if (blocksperfiles
&& !compressed
)
493 for (i
= 1; i
<= *blocksperfiles
; i
++)
494 blocksperfiles
[i
] = blocksperfiles
[i
] / ntrec
* ntrec
; /* round down */
495 else if (!unlimited
) {
497 * Determine how to default tape size and density
500 * 9-track 1600 bpi (160 bytes/.1") 2300 ft.
501 * 9-track 6250 bpi (625 bytes/.1") 2300 ft.
502 * cartridge 8000 bpi (100 bytes/.1") 1700 ft.
504 * hilit19 hits again: "
507 density
= cartridge
? 100 : 160;
509 tsize
= cartridge
? 1700L*120L : 2300L*120L;
516 if ((n
= strchr(tapeprefix
, ':'))) {
517 for (i
= 0; i
< (n
- tapeprefix
); i
++) {
518 if (tapeprefix
[i
] == '/')
521 if (tapeprefix
[i
] != '/') {
523 tapeprefix
= strchr(host
, ':');
524 *tapeprefix
++ = '\0';
526 if (index(tapeprefix
, '\n')) {
527 msg("invalid characters in tape\n");
528 msg("The ENTIRE dump is aborted.\n");
531 if (rmthost(host
) == 0)
534 msg("remote dump not enabled\n");
535 msg("The ENTIRE dump is aborted.\n");
542 (void)setuid(getuid()); /* rmthost() is the only reason to be setuid */
543 if (Apath
&& (Afile
= open(Apath
, O_WRONLY
|O_CREAT
|O_TRUNC
,
544 S_IRUSR
| S_IWUSR
| S_IRGRP
|
545 S_IWGRP
| S_IROTH
| S_IWOTH
)) < 0) {
546 msg("Cannot open %s for writing: %s\n",
547 optarg
, strerror(errno
));
548 msg("The ENTIRE dump is aborted.\n");
552 if (signal(SIGHUP
, SIG_IGN
) != SIG_IGN
)
554 if (signal(SIGTRAP
, SIG_IGN
) != SIG_IGN
)
555 signal(SIGTRAP
, sig
);
556 if (signal(SIGFPE
, SIG_IGN
) != SIG_IGN
)
558 if (signal(SIGBUS
, SIG_IGN
) != SIG_IGN
)
560 if (signal(SIGSEGV
, SIG_IGN
) != SIG_IGN
)
561 signal(SIGSEGV
, sig
);
562 if (signal(SIGTERM
, SIG_IGN
) != SIG_IGN
)
563 signal(SIGTERM
, sig
);
564 if (signal(SIGINT
, interrupt
) == SIG_IGN
)
565 signal(SIGINT
, SIG_IGN
);
567 signal(SIGXCPU
, SIG_IGN
);
570 signal(SIGXFSZ
, SIG_IGN
);
573 set_operators(); /* /etc/group snarfed */
574 getfstab(); /* /etc/fstab snarfed */
577 * disk may end in / and this can confuse
580 i
= strlen(diskparam
) - 1;
581 if (i
> 1 && diskparam
[i
] == '/')
582 if (!(i
== 6 && !strcmp(diskparam
, "LABEL=/")))
585 disk
= get_device_name(diskparam
);
586 if (!disk
) { /* null means the disk is some form
587 of LABEL= or UID= but it was not
589 msg("Cannot find a disk having %s\n", diskparam
);
590 msg("The ENTIRE dump is aborted.\n");
594 * disk can be either the full special file name,
595 * the suffix of the special file name,
596 * the special name missing the leading '/',
597 * the file system name with or without the leading '/'.
599 if ((dt
= fstabsearch(disk
)) != NULL
) {
600 /* if found then only one parameter (i.e. partition)
603 (void)fprintf(stderr
, "Unknown arguments to dump:");
605 (void)fprintf(stderr
, " %s", *argv
++);
606 (void)fprintf(stderr
, "\n");
607 msg("The ENTIRE dump is aborted.\n");
610 disk
= rawname(dt
->mnt_fsname
);
611 (void)strncpy(spcl
.c_dev
, dt
->mnt_fsname
, NAMELEN
);
612 (void)strncpy(spcl
.c_filesys
, dt
->mnt_dir
, NAMELEN
);
616 if (realpath(disk
, pathname
) == NULL
)
618 strcpy(pathname
, disk
);
620 * The argument could be now a mountpoint of
621 * a filesystem specified in fstab. Search for it.
623 if ((dt
= fstabsearch(pathname
)) != NULL
) {
624 disk
= rawname(dt
->mnt_fsname
);
625 (void)strncpy(spcl
.c_dev
, dt
->mnt_fsname
, NAMELEN
);
626 (void)strncpy(spcl
.c_filesys
, dt
->mnt_dir
, NAMELEN
);
629 * The argument was not found in the fstab
630 * assume that this is a subtree and search for it
632 dt
= fstabsearchdir(pathname
, directory
);
634 char name
[MAXPATHLEN
];
635 (void)strncpy(spcl
.c_dev
, dt
->mnt_fsname
, NAMELEN
);
636 (void)snprintf(name
, sizeof(name
), "%s (dir %s)",
637 dt
->mnt_dir
, directory
);
638 (void)strncpy(spcl
.c_filesys
, name
, NAMELEN
);
639 disk
= rawname(dt
->mnt_fsname
);
641 (void)strncpy(spcl
.c_dev
, disk
, NAMELEN
);
642 (void)strncpy(spcl
.c_filesys
, "an unlisted file system",
647 (void)strncpy(spcl
.c_dev
, disk
, NAMELEN
);
648 (void)strncpy(spcl
.c_filesys
, "an unlisted file system",
653 if (directory
[0] != 0) {
654 if (atoi(level
) != 0) {
655 msg("Only level 0 dumps are allowed on a subdirectory\n");
656 msg("The ENTIRE dump is aborted.\n");
660 msg("You can't update the dumpdates file when dumping a subdirectory\n");
661 msg("The ENTIRE dump is aborted.\n");
665 spcl
.c_dev
[NAMELEN
-1] = '\0';
666 spcl
.c_filesys
[NAMELEN
-1] = '\0';
667 (void)gethostname(spcl
.c_host
, NAMELEN
);
668 spcl
.c_host
[NAMELEN
-1] = '\0';
669 spcl
.c_level
= atoi(level
);
670 spcl
.c_type
= TS_TAPE
;
672 getdumptime(uflag
); /* dumpdates snarfed */
674 if (spcl
.c_ddate
== 0 && spcl
.c_level
) {
675 msg("WARNING: There is no inferior level dump on this filesystem\n");
676 msg("WARNING: Assuming a level 0 dump by default\n");
677 level
[0] = '0'; level
[1] = '\0';
682 snprintf(tape
, MAXPATHLEN
, "%s%03d", tapeprefix
, tapeno
+ 1);
684 strncpy(tape
, tapeprefix
, MAXPATHLEN
);
685 tape
[MAXPATHLEN
- 1] = '\0';
688 if (STAT(tape
, &statbuf
) != -1)
689 fifoout
= statbuf
.st_mode
& S_IFIFO
;
694 msg("Date of this level %s dump: %s", level
,
695 ctime4(&spcl
.c_date
));
697 gThisDumpDate
= spcl
.c_date
;
700 msg("Date of last level %s dump: %s", lastlevel
,
701 ctime4(&spcl
.c_ddate
));
702 msg("Dumping %s (%s) ", disk
, spcl
.c_filesys
);
704 msgtail("to %s on host %s\n", tape
, host
);
706 msgtail("to %s\n", tape
);
707 } /* end of size estimate */
710 if ((diskfd
= OPEN(disk
, O_RDONLY
)) < 0) {
711 msg("Cannot open %s\n", disk
);
712 msg("The ENTIRE dump is aborted.\n");
716 (void)ioctl(diskfd
, BLKFLSBUF
, 0);
718 retval
= dump_fs_open(disk
, &fs
);
720 com_err(disk
, retval
, "while opening filesystem");
721 if (retval
== EXT2_ET_REV_TOO_HIGH
)
722 msg("Get a newer version of dump!\n");
723 msg("The ENTIRE dump is aborted.\n");
726 if (fs
->super
->s_rev_level
> DUMP_CURRENT_REV
) {
727 com_err(disk
, retval
, "while opening filesystem");
728 msg("Get a newer version of dump!\n");
729 msg("The ENTIRE dump is aborted.\n");
732 /* if no user label specified, use ext2 filesystem label if available */
733 if (spcl
.c_label
[0] == '\0') {
735 if ( (lbl
= get_device_label(disk
)) != NULL
) {
736 strncpy(spcl
.c_label
, lbl
, LBLSIZE
);
737 spcl
.c_label
[LBLSIZE
-1] = '\0';
740 strcpy(spcl
.c_label
, "none"); /* safe strcpy. */
743 dev_bsize
= DEV_BSIZE
;
744 dev_bshift
= ffs(dev_bsize
) - 1;
745 if (dev_bsize
!= (1 << dev_bshift
))
746 quit("dev_bsize (%d) is not a power of 2", dev_bsize
);
747 tp_bshift
= ffs(TP_BSIZE
) - 1;
748 if (TP_BSIZE
!= (1 << tp_bshift
))
749 quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE
);
750 maxino
= fs
->super
->s_inodes_count
+ 1;
751 spcl
.c_flags
|= DR_NEWINODEFMT
;
752 #else /* __linux __*/
753 if ((diskfd
= open(disk
, O_RDONLY
)) < 0) {
754 msg("Cannot open %s\n", disk
);
755 msg("The ENTIRE dump is aborted.\n");
759 sblock
= (struct fs
*)sblock_buf
;
760 bread(SBOFF
, (char *) sblock
, SBSIZE
);
761 if (sblock
->fs_magic
!= FS_MAGIC
)
762 quit("bad sblock magic number\n");
763 dev_bsize
= sblock
->fs_fsize
/ fsbtodb(sblock
, 1);
764 dev_bshift
= ffs(dev_bsize
) - 1;
765 if (dev_bsize
!= (1 << dev_bshift
))
766 quit("dev_bsize (%d) is not a power of 2", dev_bsize
);
767 tp_bshift
= ffs(TP_BSIZE
) - 1;
768 if (TP_BSIZE
!= (1 << tp_bshift
))
769 quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE
);
771 if (sblock
->fs_inodefmt
>= FS_44INODEFMT
)
772 spcl
.c_flags
|= DR_NEWINODEFMT
;
774 maxino
= sblock
->fs_ipg
* sblock
->fs_ncg
;
775 #endif /* __linux__ */
776 mapsize
= roundup(howmany(maxino
, NBBY
), TP_BSIZE
);
777 usedinomap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
778 dumpdirmap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
779 dumpinomap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
780 metainomap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
781 if (usedinomap
== NULL
|| dumpdirmap
== NULL
||
782 dumpinomap
== NULL
|| metainomap
== NULL
)
783 quit("out of memory allocating inode maps\n");
784 tapesize
= 2 * (howmany(mapsize
* sizeof(char), TP_BSIZE
) + 1);
786 nonodump
= spcl
.c_level
< honorlevel
;
789 msg("Label: %s\n", spcl
.c_label
);
791 msg("Writing %d Kilobyte records\n", ntrec
);
794 if (zipflag
== COMPRESS_LZO
)
795 msg("Compressing output (lzo)\n");
797 msg("Compressing output at compression level %d (%s)\n",
798 compressed
, zipflag
== COMPRESS_ZLIB
? "zlib" : "bzlib");
803 (void)signal(SIGINFO
, statussig
);
807 msg("mapping (Pass I) [regular files]\n");
809 if (directory
[0] == 0)
810 anydirskipped
= mapfiles(maxino
, &tapesize
);
812 if (LSTAT(pathname
, &statbuf
) == -1) {
813 msg("File cannot be accessed (%s).\n", pathname
);
814 msg("The ENTIRE dump is aborted.\n");
817 filedev
= statbuf
.st_dev
;
818 if (!(statbuf
.st_mode
& S_IFDIR
)) /* is a file */
819 anydirskipped
= maponefile(maxino
, &tapesize
,
822 anydirskipped
= mapfilesfromdir(maxino
, &tapesize
,
828 /* check if file is available */
829 if (LSTAT(p
, &statbuf
) == -1) {
830 msg("File cannot be accessed (%s).\n", p
);
831 msg("The ENTIRE dump is aborted.\n");
834 /* check if file is on same unix partiton as the first
836 if (statbuf
.st_dev
!= filedev
) {
837 msg("Files are not on same file system (%s).\n", p
);
838 msg("The ENTIRE dump is aborted.\n");
841 /* check if file is a directory */
842 if (!(statbuf
.st_mode
& S_IFDIR
))
843 anydirskipped2
= maponefile(maxino
, &tapesize
,
844 p
+strlen(dt
->mnt_dir
));
846 /* read directory inodes.
847 * NOTE: nested directories are not recognized
848 * so inodes may be umped twice!
850 anydirskipped2
= mapfilesfromdir(maxino
, &tapesize
,
851 p
+strlen(dt
->mnt_dir
));
853 anydirskipped
= anydirskipped2
;
857 anydirskipped
= mapfiles(maxino
, &tapesize
);
861 msg("mapping (Pass II) [directories]\n");
862 while (anydirskipped
) {
863 anydirskipped
= mapdirs(maxino
, &tapesize
);
867 printf("%.0f\n", ((double)tapesize
+ 1 + ntrec
) * TP_BSIZE
);
869 } /* stop here for size estimate */
871 if (pipeout
|| unlimited
) {
872 tapesize
+= 1 + ntrec
; /* 1 map header + trailer blocks */
873 msg("estimated %ld blocks.\n", tapesize
);
877 if (blocksperfiles
) {
880 tapesize_left
= tapesize
;
882 for (i
= 1; i
< *blocksperfiles
&& tapesize_left
; i
++) {
884 if (tapesize_left
> blocksperfiles
[i
])
885 tapesize_left
-= blocksperfiles
[i
];
890 fetapes
+= (double)tapesize_left
/ blocksperfiles
[*blocksperfiles
];
891 } else if (cartridge
) {
892 /* Estimate number of tapes, assuming streaming stops at
893 the end of each block written, and not in mid-block.
894 Assume no erroneous blocks; this can be compensated
895 for with an artificially low tape size. */
897 ( (double) tapesize
/* blocks */
898 * TP_BSIZE
/* bytes/block */
899 * (1.0/density
) /* 0.1" / byte " */
901 (double) tapesize
/* blocks */
902 * (1.0/ntrec
) /* streaming-stops per block */
903 * 15.48 /* 0.1" / streaming-stop " */
904 ) * (1.0 / tsize
); /* tape / 0.1" " */
906 /* Estimate number of tapes, for old fashioned 9-track
908 int tenthsperirg
= (density
== 625) ? 3 : 7;
910 ( (double) tapesize
/* blocks */
911 * TP_BSIZE
/* bytes / block */
912 * (1.0/density
) /* 0.1" / byte " */
914 (double) tapesize
/* blocks */
915 * (1.0/ntrec
) /* IRG's / block */
916 * tenthsperirg
/* 0.1" / IRG " */
917 ) * (1.0 / tsize
); /* tape / 0.1" " */
919 etapes
= fetapes
; /* truncating assignment */
921 /* count the dumped inodes map on each additional tape */
922 tapesize
+= (etapes
- 1) *
923 (howmany(mapsize
* sizeof(char), TP_BSIZE
) + 1);
924 tapesize
+= etapes
+ ntrec
; /* headers + trailer blks */
925 msg("estimated %ld blocks on %3.2f tape(s).\n",
931 msg("writing QFA positions to %s\n", gTapeposfile
);
932 if ((gTapeposfd
= open(gTapeposfile
,
933 O_WRONLY
|O_CREAT
|O_TRUNC
,
934 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
935 | S_IROTH
| S_IWOTH
)) < 0)
936 quit("can't open tapeposfile\n");
937 /* print QFA-file header */
938 snprintf(gTps
, sizeof(gTps
), "%s\n%s\n%ld\n\n", QFA_MAGIC
, QFA_VERSION
, (unsigned long)spcl
.c_date
);
939 gTps
[sizeof(gTps
) - 1] = '\0';
940 if (write(gTapeposfd
, gTps
, strlen(gTps
)) != (ssize_t
)strlen(gTps
))
941 quit("can't write tapeposfile\n");
942 sprintf(gTps
, "ino\ttapeno\ttapepos\n");
943 if (write(gTapeposfd
, gTps
, strlen(gTps
)) != (ssize_t
)strlen(gTps
))
944 quit("can't write tapeposfile\n");
949 * Allocate tape buffer.
953 "can't allocate tape buffers - try a smaller blocking factor.\n");
956 tstart_writing
= time(NULL
);
957 dumpmap(usedinomap
, TS_CLRI
, maxino
- 1);
959 msg("dumping (Pass III) [directories]\n");
960 dirty
= 0; /* XXX just to get gcc to shut up */
961 for (map
= dumpdirmap
, ino
= 1; ino
< maxino
; ino
++) {
962 if (((ino
- 1) % NBBY
) == 0) /* map is offset by 1 */
966 if ((dirty
& 1) == 0)
969 * Skip directory inodes deleted and maybe reallocated
972 if ((dp
->di_mode
& IFMT
) != IFDIR
)
976 * Skip directory inodes deleted and not yes reallocated...
978 if (dp
->di_nlink
== 0 || dp
->di_dtime
!= 0)
981 msg("dumping directory inode %lu\n", ino
);
982 (void)dumpdirino(dp
, ino
);
984 (void)dumpino(dp
, ino
);
988 msg("dumping (Pass IV) [regular files]\n");
989 for (map
= dumpinomap
, ino
= 1; ino
< maxino
; ino
++) {
990 if (((ino
- 1) % NBBY
) == 0) /* map is offset by 1 */
994 if ((dirty
& 1) == 0)
997 * Skip inodes deleted and reallocated as directories.
1000 if ((dp
->di_mode
& IFMT
) == IFDIR
)
1004 * No need to check here for deleted and not yet reallocated
1005 * inodes since this is done in dumpino().
1009 if (mflag
&& TSTINO(ino
, metainomap
))
1010 msg("dumping regular inode %lu (meta only)\n", ino
);
1012 msg("dumping regular inode %lu\n", ino
);
1014 (void)dumpino(dp
, ino
, mflag
&& TSTINO(ino
, metainomap
));
1017 tend_writing
= time(NULL
);
1018 spcl
.c_type
= TS_END
;
1021 volinfo
[1] = ROOTINO
;
1022 memcpy(spcl
.c_inos
, volinfo
, TP_NINOS
* sizeof(dump_ino_t
));
1023 spcl
.c_flags
|= DR_INODEINFO
;
1027 * Finish off the current tape record with trailer blocks, to ensure
1028 * at least the data in the last partial record makes it to tape.
1029 * Also make sure we write at least 1 trailer block.
1031 for (i
= ntrec
- (spcl
.c_tapea
% ntrec
); i
; --i
)
1032 writeheader(maxino
- 1);
1036 if (pipeout
|| fifoout
)
1037 msg("%ld blocks (%.2fMB)\n", spcl
.c_tapea
,
1038 ((double)spcl
.c_tapea
* TP_BSIZE
/ 1048576));
1040 msg("%ld blocks (%.2fMB) on %d volume(s)\n",
1042 ((double)spcl
.c_tapea
* TP_BSIZE
/ 1048576),
1045 /* report dump performance, avoid division by zero */
1046 if (tend_writing
- tstart_writing
== 0)
1047 msg("finished in less than a second\n");
1049 msg("finished in %d seconds, throughput %d kBytes/sec\n",
1050 tend_writing
- tstart_writing
,
1051 spcl
.c_tapea
/ (tend_writing
- tstart_writing
));
1054 msg("Date of this level %s dump: %s", level
,
1055 spcl
.c_date
== 0 ? "the epoch\n" : ctime4(&spcl
.c_date
));
1056 msg("Date this dump completed: %s", ctime(&tnow
));
1058 msg("Average transfer rate: %ld kB/s\n", xferrate
/ tapeno
);
1060 long tapekb
= bytes_written
/ 1024;
1061 double rate
= .0005 + (double) spcl
.c_tapea
/ tapekb
;
1062 msg("Wrote %ldkB uncompressed, %ldkB compressed, %1.3f:1\n",
1063 spcl
.c_tapea
, tapekb
, rate
);
1067 msg("Archiving dump to %s\n", Apath
);
1069 broadcast("DUMP IS DONE!\7\7\n");
1070 msg("DUMP IS DONE\n");
1073 return 0; /* gcc - shut up */
1079 char white
[MAXPATHLEN
];
1080 const char *ext2ver
, *ext2date
;
1082 memset(white
, ' ', MAXPATHLEN
);
1083 white
[MIN(strlen(__progname
), MAXPATHLEN
- 1)] = '\0';
1086 ext2fs_get_library_version(&ext2ver
, &ext2date
);
1087 fprintf(stderr
, "%s %s (using libext2fs %s of %s)\n",
1088 __progname
, _DUMP_VERSION
, ext2ver
, ext2date
);
1090 fprintf(stderr
, "%s %s\n", __progname
, _DUMP_VERSION
);
1093 "usage:\t%s [-level#] [-ac"
1098 "] [-A file] [-B records] [-b blocksize]\n"
1099 "\t%s [-d density] [-D file] [-e inode#,inode#,...] [-E file]\n"
1100 "\t%s [-f file] [-h level] [-I nr errors] "
1117 __progname
, white
, white
, white
, __progname
);
1122 * Pick up a numeric argument. It must be nonnegative and in the given
1123 * range (except that a vmax of 0 means unlimited).
1126 numarg(const char *meaning
, long vmin
, long vmax
)
1131 val
= strtol(optarg
, &p
, 10);
1133 errx(X_STARTUP
, "illegal %s -- %s", meaning
, optarg
);
1134 if (val
< vmin
|| (vmax
&& val
> vmax
))
1135 errx(X_STARTUP
, "%s must be between %ld and %ld", meaning
, vmin
, vmax
);
1140 * The same as numarg, just that it expects a comma separated list of numbers
1141 * and returns an array of longs with the first element containing the number
1142 * values in that array.
1145 numlistarg(const char *meaning
, long vmin
, long vmax
)
1156 if ( !(vals
= realloc(vals
, (valnum
+ 1) * sizeof(*vals
))) )
1157 errx(X_STARTUP
, "allocating memory failed");
1158 curval
= vals
+ valnum
;
1159 *curval
= strtol(p
, &p
, 10);
1161 errx(X_STARTUP
, "illegal %s -- %s", meaning
, optarg
);
1162 if (*curval
< vmin
|| (vmax
&& *curval
> vmax
))
1163 errx(X_STARTUP
, "%s must be between %ld and %ld", meaning
, vmin
, vmax
);
1180 if (pipeout
|| fifoout
)
1181 quit("Signal on pipe: cannot recover\n");
1182 msg("Rewriting attempted as response to unknown signal: %d.\n", signo
);
1183 (void)fflush(stderr
);
1184 (void)fflush(stdout
);
1189 msg("SIGSEGV: ABORTING!\n");
1190 (void)signal(SIGSEGV
, SIG_DFL
);
1191 (void)kill(0, SIGSEGV
);
1197 rawname(const char *cp
)
1201 #else /* __linux__ */
1202 static char rawbuf
[MAXPATHLEN
];
1203 char *dp
= strrchr(cp
, '/');
1207 (void)strncpy(rawbuf
, cp
, min(dp
-cp
, MAXPATHLEN
- 1));
1208 rawbuf
[min(dp
-cp
, MAXPATHLEN
-1)] = '\0';
1209 (void)strncat(rawbuf
, "/r", MAXPATHLEN
- 1 - strlen(rawbuf
));
1210 (void)strncat(rawbuf
, dp
+ 1, MAXPATHLEN
- 1 - strlen(rawbuf
));
1212 #endif /* __linux__ */
1217 * Change set of key letters and ordered arguments into something
1218 * getopt(3) will like.
1221 obsolete(int *argcp
, char **argvp
[])
1224 char *ap
, **argv
, *flagsp
=NULL
, **nargv
, *p
=NULL
;
1230 /* Return if no arguments or first argument has leading dash. */
1232 if (argc
== 1 || *ap
== '-')
1235 /* Allocate space for new arguments. */
1236 if ((*argvp
= nargv
= malloc((argc
+ 1) * sizeof(char *))) == NULL
||
1237 (p
= flagsp
= malloc(strlen(ap
) + 2)) == NULL
)
1238 err(X_STARTUP
, "malloc new args");
1243 for (flags
= 0; *ap
; ++ap
) {
1259 if (*argv
== NULL
) {
1260 warnx("option requires an argument -- %c", *ap
);
1263 if ((nargv
[0] = malloc(strlen(*argv
) + 2 + 1)) == NULL
)
1264 err(X_STARTUP
, "malloc arg");
1267 (void)strcpy(&nargv
[0][2], *argv
);
1281 /* Terminate flags. */
1287 /* Copy remaining arguments. */
1288 while ((*nargv
++ = *argv
++));
1290 /* Update argument count. */
1291 *argcp
= nargv
- *argvp
- 1;
1295 * This tests whether an inode is in the exclude bitmap
1298 exclude_ino(dump_ino_t ino
)
1300 /* if the inode exclude bitmap exists and covers given inode */
1301 if (iexclude_bitmap
&& iexclude_bitmap_bytes
> ino
/ 8) {
1302 /* then check this inode against it */
1303 int idx
= iexclude_bitmap
[ino
/ 8];
1304 if (idx
& (1 << (ino
% 8)))
1311 * This adds an inode to the exclusion bitmap if it isn't already there
1314 do_exclude_ino(dump_ino_t ino
, const char *reason
)
1316 if (exclude_ino(ino
))
1321 msg("Excluding inode %u (%s) from dump\n", ino
, reason
);
1323 msg("Excluding inode %u from dump\n", ino
);
1326 /* check for enough mem; initialize */
1327 if ((ino
/8 + 1) > iexclude_bitmap_bytes
) {
1328 if (iexclude_bitmap_bytes
== 0) {
1330 iexclude_bitmap_bytes
= 2 * (ino
/8 + 1);
1331 iexclude_bitmap
= (char*) malloc(iexclude_bitmap_bytes
);
1332 if (iexclude_bitmap
== NULL
) {
1333 msg("allocating memory failed\n");
1336 for (j
= 0; j
< iexclude_bitmap_bytes
; j
++)
1337 iexclude_bitmap
[j
] = 0;
1340 unsigned int oldsize
= iexclude_bitmap_bytes
;
1341 iexclude_bitmap_bytes
*=
1342 (ino
/ 8 + 1) / iexclude_bitmap_bytes
+ 1;
1343 iexclude_bitmap
= (char*) realloc(iexclude_bitmap
,
1344 iexclude_bitmap_bytes
);
1345 if (iexclude_bitmap
== NULL
) {
1346 msg("allocating memory failed\n");
1349 for( ; oldsize
< iexclude_bitmap_bytes
; oldsize
++)
1350 iexclude_bitmap
[oldsize
] = 0;
1354 iexclude_bitmap
[ino
/ 8] |= 1 << (ino
% 8);
1358 do_exclude_ino_str(char * ino
) {
1362 inod
= strtoul(ino
, &r
, 10);
1363 if (( *r
!= '\0' && !isspace(*r
) ) || inod
<= ROOTINO
) {
1364 msg("Invalid inode argument %s\n", ino
);
1365 msg("The ENTIRE dump is aborted.\n");
1368 do_exclude_ino(inod
, NULL
);
1372 * This reads a file containing one inode number per line and exclude them all
1375 do_exclude_from_file(char *file
) {
1377 char *p
, fname
[MAXPATHLEN
];
1380 if (!( f
= fopen(file
, "r")) ) {
1381 msg("Cannot open file for reading: %s\n", file
);
1382 msg("The ENTIRE dump is aborted.\n");
1385 while (( p
= fgets(fname
, MAXPATHLEN
, f
))) {
1386 if ( *p
&& *(p
+ strlen(p
) - 1) == '\n' ) /* possible null string */
1387 *(p
+ strlen(p
) - 1) = '\0';
1388 if ( !*p
) /* skip empty lines */
1390 do_exclude_ino_str(p
);
1395 static void incompat_flags(int cond
, char flag1
, char flag2
) {
1397 msg("You cannot use the %c and %c flags together.\n",
1399 msg("The ENTIRE dump is aborted.\n");