]>
git.wh0rd.org - dump.git/blob - dump/main.c
1bb5ca3abc3c2512ba76b1cf169173aed7842fd9
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.87 2003/10/26 16:05:47 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
; /* dump level of previous dump */
107 char level
; /* 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 blocksperfile
; /* output blocks per file */
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 void obsolete
__P((int *, char **[]));
190 static void usage
__P((void));
191 static void do_exclude_from_file
__P((char *));
192 static void do_exclude_ino_str
__P((char *));
193 static void incompat_flags
__P((int, char, char));
195 static char* iexclude_bitmap
= NULL
; /* the inode exclude bitmap */
196 static int iexclude_bitmap_bytes
= 0; /* size of bitmap in bytes */
199 main(int argc
, char *argv
[])
207 int i
, anydirskipped
;
208 int aflag
= 0, bflag
= 0, Tflag
= 0, honorlevel
= 1;
214 char directory
[MAXPATHLEN
];
215 char pathname
[MAXPATHLEN
];
221 spcl
.c_label
[0] = '\0';
222 spcl
.c_date
= time(NULL
);
225 __progname
= argv
[0];
227 initialize_ext2_error_table();
230 tsize
= 0; /* Default later, based on 'c' option for cart tapes */
233 if ((tapeprefix
= getenv("TAPE")) == NULL
)
234 tapeprefix
= _PATH_DEFTAPE
;
235 dumpdates
= _PATH_DUMPDATES
;
236 if (TP_BSIZE
/ DEV_BSIZE
== 0 || TP_BSIZE
% DEV_BSIZE
!= 0)
237 quit("TP_BSIZE must be a multiple of DEV_BSIZE\n");
243 obsolete(&argc
, &argv
);
249 while ((ch
= getopt(argc
, argv
,
250 "0123456789A:aB:b:cd:D:e:E:f:F:h:I:"
272 case '0': case '1': case '2': case '3': case '4':
273 case '5': case '6': case '7': case '8': case '9':
277 case 'A': /* archive file */
281 case 'a': /* `auto-size', Write to EOM. */
286 case 'B': /* blocks per output file */
288 blocksperfile
= numarg("number of blocks per file",
292 case 'b': /* blocks per tape write */
293 ntrec
= numarg("number of blocks per write",
295 if (ntrec
> maxbsize
/1024) {
296 msg("Please choose a blocksize <= %dkB\n",
298 msg("The ENTIRE dump is aborted.\n");
304 case 'c': /* Tape is cart. not 9-track */
309 case 'd': /* density, in bits per inch */
311 density
= numarg("density", 10L, 327670L) / 10;
312 if (density
>= 625 && !bflag
)
313 ntrec
= HIGHDENSITYTREC
;
316 case 'D': /* path of dumpdates file */
321 case 'e': /* exclude an inode */
323 char *p
= optarg
, *q
;
324 while ((q
= strchr(p
, ','))) {
326 do_exclude_ino_str(p
);
329 do_exclude_ino_str(p
);
333 case 'E': /* exclude inodes read from file */
334 do_exclude_from_file(optarg
);
337 case 'f': /* output file */
341 case 'F': /* end of tape script */
346 honorlevel
= numarg("honor level", 0L, 10L);
352 zipflag
= COMPRESS_BZLIB
;
354 compressed
= numarg("compress level", 1L, 9L);
356 #endif /* HAVE_BZLIB */
360 numarg ("number of errors to ignore", 0L, 0L);
371 * Note that although there are LBLSIZE characters,
372 * the last must be '\0', so the limit on strlen()
373 * is really LBLSIZE-1.
375 strncpy(spcl
.c_label
, optarg
, LBLSIZE
);
376 spcl
.c_label
[LBLSIZE
-1] = '\0';
377 if (strlen(optarg
) > LBLSIZE
-1) {
379 "WARNING Label `%s' is larger than limit of %d characters.\n",
381 msg("WARNING: Using truncated label `%s'.\n",
386 case 'm': /* metadata only flag */
390 case 'M': /* multi-volume flag */
394 case 'n': /* notify operators */
403 case 'Q': /* create tapeposfile */
404 gTapeposfile
= optarg
;
409 case 's': /* tape size, feet */
411 tsize
= numarg("tape size", 1L, 0L) * 12 * 10;
415 sizest
= 1; /* return size estimate only */
418 case 'T': /* time of last dump */
419 spcl
.c_ddate
= unctime(optarg
);
420 if (spcl
.c_ddate
< 0) {
421 msg("bad time \"%s\"\n", optarg
);
422 msg("The ENTIRE dump is aborted.\n");
429 case 'u': /* update dumpdates */
433 case 'v': /* verbose */
437 case 'W': /* what to do */
440 exit(X_FINOK
); /* do nothing else */
444 zipflag
= COMPRESS_LZO
;
446 #endif /* HAVE_LZO */
451 zipflag
= COMPRESS_ZLIB
;
453 compressed
= numarg("compress level", 1L, 9L);
455 #endif /* HAVE_ZLIB */
464 msg("Must specify disk or filesystem\n");
465 msg("The ENTIRE dump is aborted.\n");
469 if (strlen(diskparam
) >= MAXPATHLEN
) {
470 msg("Disk or filesystem name too long: %s\n", diskparam
);
471 msg("The ENTIRE dump is aborted.\n");
475 incompat_flags(Tflag
&& uflag
, 'T', 'u');
476 incompat_flags(aflag
&& blocksperfile
, 'a', 'B');
477 incompat_flags(aflag
&& cartridge
, 'a', 'c');
478 incompat_flags(aflag
&& density
, 'a', 'd');
479 incompat_flags(aflag
&& tsize
, 'a', 's');
481 if (strcmp(tapeprefix
, "-") == 0) {
483 tapeprefix
= "standard output";
486 if (blocksperfile
&& !compressed
)
487 blocksperfile
= blocksperfile
/ ntrec
* ntrec
; /* round down */
488 else if (!unlimited
) {
490 * Determine how to default tape size and density
493 * 9-track 1600 bpi (160 bytes/.1") 2300 ft.
494 * 9-track 6250 bpi (625 bytes/.1") 2300 ft.
495 * cartridge 8000 bpi (100 bytes/.1") 1700 ft.
497 * hilit19 hits again: "
500 density
= cartridge
? 100 : 160;
502 tsize
= cartridge
? 1700L*120L : 2300L*120L;
509 if ((n
= strchr(tapeprefix
, ':'))) {
510 for (i
= 0; i
< (n
- tapeprefix
); i
++) {
511 if (tapeprefix
[i
] == '/')
514 if (tapeprefix
[i
] != '/') {
516 tapeprefix
= strchr(host
, ':');
517 *tapeprefix
++ = '\0';
519 if (index(tapeprefix
, '\n')) {
520 msg("invalid characters in tape\n");
521 msg("The ENTIRE dump is aborted.\n");
524 if (rmthost(host
) == 0)
527 msg("remote dump not enabled\n");
528 msg("The ENTIRE dump is aborted.\n");
535 (void)setuid(getuid()); /* rmthost() is the only reason to be setuid */
536 if (Apath
&& (Afile
= open(Apath
, O_WRONLY
|O_CREAT
|O_TRUNC
,
537 S_IRUSR
| S_IWUSR
| S_IRGRP
|
538 S_IWGRP
| S_IROTH
| S_IWOTH
)) < 0) {
539 msg("Cannot open %s for writing: %s\n",
540 optarg
, strerror(errno
));
541 msg("The ENTIRE dump is aborted.\n");
545 if (signal(SIGHUP
, SIG_IGN
) != SIG_IGN
)
547 if (signal(SIGTRAP
, SIG_IGN
) != SIG_IGN
)
548 signal(SIGTRAP
, sig
);
549 if (signal(SIGFPE
, SIG_IGN
) != SIG_IGN
)
551 if (signal(SIGBUS
, SIG_IGN
) != SIG_IGN
)
553 if (signal(SIGSEGV
, SIG_IGN
) != SIG_IGN
)
554 signal(SIGSEGV
, sig
);
555 if (signal(SIGTERM
, SIG_IGN
) != SIG_IGN
)
556 signal(SIGTERM
, sig
);
557 if (signal(SIGINT
, interrupt
) == SIG_IGN
)
558 signal(SIGINT
, SIG_IGN
);
560 signal(SIGXCPU
, SIG_IGN
);
563 signal(SIGXFSZ
, SIG_IGN
);
566 set_operators(); /* /etc/group snarfed */
567 getfstab(); /* /etc/fstab snarfed */
570 * disk may end in / and this can confuse
573 i
= strlen(diskparam
) - 1;
574 if (i
> 1 && diskparam
[i
] == '/')
575 if (!(i
== 6 && !strcmp(diskparam
, "LABEL=/")))
578 disk
= get_device_name(diskparam
);
579 if (!disk
) { /* null means the disk is some form
580 of LABEL= or UID= but it was not
582 msg("Cannot find a disk having %s\n", diskparam
);
583 msg("The ENTIRE dump is aborted.\n");
587 * disk can be either the full special file name,
588 * the suffix of the special file name,
589 * the special name missing the leading '/',
590 * the file system name with or without the leading '/'.
592 if ((dt
= fstabsearch(disk
)) != NULL
) {
593 /* if found then only one parameter (i.e. partition)
596 (void)fprintf(stderr
, "Unknown arguments to dump:");
598 (void)fprintf(stderr
, " %s", *argv
++);
599 (void)fprintf(stderr
, "\n");
600 msg("The ENTIRE dump is aborted.\n");
603 disk
= rawname(dt
->mnt_fsname
);
604 (void)strncpy(spcl
.c_dev
, dt
->mnt_fsname
, NAMELEN
);
605 (void)strncpy(spcl
.c_filesys
, dt
->mnt_dir
, NAMELEN
);
609 if (realpath(disk
, pathname
) == NULL
)
611 strcpy(pathname
, disk
);
613 * The argument could be now a mountpoint of
614 * a filesystem specified in fstab. Search for it.
616 if ((dt
= fstabsearch(pathname
)) != NULL
) {
617 disk
= rawname(dt
->mnt_fsname
);
618 (void)strncpy(spcl
.c_dev
, dt
->mnt_fsname
, NAMELEN
);
619 (void)strncpy(spcl
.c_filesys
, dt
->mnt_dir
, NAMELEN
);
622 * The argument was not found in the fstab
623 * assume that this is a subtree and search for it
625 dt
= fstabsearchdir(pathname
, directory
);
627 char name
[MAXPATHLEN
];
628 (void)strncpy(spcl
.c_dev
, dt
->mnt_fsname
, NAMELEN
);
629 (void)snprintf(name
, sizeof(name
), "%s (dir %s)",
630 dt
->mnt_dir
, directory
);
631 (void)strncpy(spcl
.c_filesys
, name
, NAMELEN
);
632 disk
= rawname(dt
->mnt_fsname
);
634 (void)strncpy(spcl
.c_dev
, disk
, NAMELEN
);
635 (void)strncpy(spcl
.c_filesys
, "an unlisted file system",
640 (void)strncpy(spcl
.c_dev
, disk
, NAMELEN
);
641 (void)strncpy(spcl
.c_filesys
, "an unlisted file system",
646 if (directory
[0] != 0) {
648 msg("Only level 0 dumps are allowed on a subdirectory\n");
649 msg("The ENTIRE dump is aborted.\n");
653 msg("You can't update the dumpdates file when dumping a subdirectory\n");
654 msg("The ENTIRE dump is aborted.\n");
658 spcl
.c_dev
[NAMELEN
-1] = '\0';
659 spcl
.c_filesys
[NAMELEN
-1] = '\0';
660 (void)gethostname(spcl
.c_host
, NAMELEN
);
661 spcl
.c_host
[NAMELEN
-1] = '\0';
662 spcl
.c_level
= level
- '0';
663 spcl
.c_type
= TS_TAPE
;
665 getdumptime(uflag
); /* dumpdates snarfed */
667 if (spcl
.c_ddate
== 0 && spcl
.c_level
) {
668 msg("WARNING: There is no inferior level dump on this filesystem\n");
669 msg("WARNING: Assuming a level 0 dump by default\n");
675 snprintf(tape
, MAXPATHLEN
, "%s%03d", tapeprefix
, tapeno
+ 1);
677 strncpy(tape
, tapeprefix
, MAXPATHLEN
);
678 tape
[MAXPATHLEN
- 1] = '\0';
681 if (STAT(tape
, &statbuf
) != -1)
682 fifoout
= statbuf
.st_mode
& S_IFIFO
;
687 msg("Date of this level %c dump: %s", level
,
688 ctime4(&spcl
.c_date
));
690 gThisDumpDate
= spcl
.c_date
;
693 msg("Date of last level %c dump: %s", lastlevel
,
694 ctime4(&spcl
.c_ddate
));
695 msg("Dumping %s (%s) ", disk
, spcl
.c_filesys
);
697 msgtail("to %s on host %s\n", tape
, host
);
699 msgtail("to %s\n", tape
);
700 } /* end of size estimate */
703 if ((diskfd
= OPEN(disk
, O_RDONLY
)) < 0) {
704 msg("Cannot open %s\n", disk
);
705 msg("The ENTIRE dump is aborted.\n");
709 (void)ioctl(diskfd
, BLKFLSBUF
, 0);
711 retval
= dump_fs_open(disk
, &fs
);
713 com_err(disk
, retval
, "while opening filesystem");
714 if (retval
== EXT2_ET_REV_TOO_HIGH
)
715 msg("Get a newer version of dump!\n");
716 msg("The ENTIRE dump is aborted.\n");
719 if (fs
->super
->s_rev_level
> DUMP_CURRENT_REV
) {
720 com_err(disk
, retval
, "while opening filesystem");
721 msg("Get a newer version of dump!\n");
722 msg("The ENTIRE dump is aborted.\n");
725 /* if no user label specified, use ext2 filesystem label if available */
726 if (spcl
.c_label
[0] == '\0') {
728 if ( (lbl
= get_device_label(disk
)) != NULL
) {
729 strncpy(spcl
.c_label
, lbl
, LBLSIZE
);
730 spcl
.c_label
[LBLSIZE
-1] = '\0';
733 strcpy(spcl
.c_label
, "none"); /* safe strcpy. */
736 dev_bsize
= DEV_BSIZE
;
737 dev_bshift
= ffs(dev_bsize
) - 1;
738 if (dev_bsize
!= (1 << dev_bshift
))
739 quit("dev_bsize (%d) is not a power of 2", dev_bsize
);
740 tp_bshift
= ffs(TP_BSIZE
) - 1;
741 if (TP_BSIZE
!= (1 << tp_bshift
))
742 quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE
);
743 maxino
= fs
->super
->s_inodes_count
+ 1;
744 spcl
.c_flags
|= DR_NEWINODEFMT
;
745 #else /* __linux __*/
746 if ((diskfd
= open(disk
, O_RDONLY
)) < 0) {
747 msg("Cannot open %s\n", disk
);
748 msg("The ENTIRE dump is aborted.\n");
752 sblock
= (struct fs
*)sblock_buf
;
753 bread(SBOFF
, (char *) sblock
, SBSIZE
);
754 if (sblock
->fs_magic
!= FS_MAGIC
)
755 quit("bad sblock magic number\n");
756 dev_bsize
= sblock
->fs_fsize
/ fsbtodb(sblock
, 1);
757 dev_bshift
= ffs(dev_bsize
) - 1;
758 if (dev_bsize
!= (1 << dev_bshift
))
759 quit("dev_bsize (%d) is not a power of 2", dev_bsize
);
760 tp_bshift
= ffs(TP_BSIZE
) - 1;
761 if (TP_BSIZE
!= (1 << tp_bshift
))
762 quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE
);
764 if (sblock
->fs_inodefmt
>= FS_44INODEFMT
)
765 spcl
.c_flags
|= DR_NEWINODEFMT
;
767 maxino
= sblock
->fs_ipg
* sblock
->fs_ncg
;
768 #endif /* __linux__ */
769 mapsize
= roundup(howmany(maxino
, NBBY
), TP_BSIZE
);
770 usedinomap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
771 dumpdirmap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
772 dumpinomap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
773 metainomap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
774 if (usedinomap
== NULL
|| dumpdirmap
== NULL
||
775 dumpinomap
== NULL
|| metainomap
== NULL
)
776 quit("out of memory allocating inode maps\n");
777 tapesize
= 2 * (howmany(mapsize
* sizeof(char), TP_BSIZE
) + 1);
779 nonodump
= spcl
.c_level
< honorlevel
;
782 msg("Label: %s\n", spcl
.c_label
);
784 msg("Writing %d Kilobyte records\n", ntrec
);
787 if (zipflag
== COMPRESS_LZO
)
788 msg("Compressing output (lzo)\n");
790 msg("Compressing output at compression level %d (%s)\n",
791 compressed
, zipflag
== COMPRESS_ZLIB
? "zlib" : "bzlib");
796 (void)signal(SIGINFO
, statussig
);
800 msg("mapping (Pass I) [regular files]\n");
802 if (directory
[0] == 0)
803 anydirskipped
= mapfiles(maxino
, &tapesize
);
805 if (LSTAT(pathname
, &statbuf
) == -1) {
806 msg("File cannot be accessed (%s).\n", pathname
);
807 msg("The ENTIRE dump is aborted.\n");
810 filedev
= statbuf
.st_dev
;
811 if (!(statbuf
.st_mode
& S_IFDIR
)) /* is a file */
812 anydirskipped
= maponefile(maxino
, &tapesize
,
815 anydirskipped
= mapfilesfromdir(maxino
, &tapesize
,
821 /* check if file is available */
822 if (LSTAT(p
, &statbuf
) == -1) {
823 msg("File cannot be accessed (%s).\n", p
);
824 msg("The ENTIRE dump is aborted.\n");
827 /* check if file is on same unix partiton as the first
829 if (statbuf
.st_dev
!= filedev
) {
830 msg("Files are not on same file system (%s).\n", p
);
831 msg("The ENTIRE dump is aborted.\n");
834 /* check if file is a directory */
835 if (!(statbuf
.st_mode
& S_IFDIR
))
836 anydirskipped2
= maponefile(maxino
, &tapesize
,
837 p
+strlen(dt
->mnt_dir
));
839 /* read directory inodes.
840 * NOTE: nested directories are not recognized
841 * so inodes may be umped twice!
843 anydirskipped2
= mapfilesfromdir(maxino
, &tapesize
,
844 p
+strlen(dt
->mnt_dir
));
846 anydirskipped
= anydirskipped2
;
850 anydirskipped
= mapfiles(maxino
, &tapesize
);
854 msg("mapping (Pass II) [directories]\n");
855 while (anydirskipped
) {
856 anydirskipped
= mapdirs(maxino
, &tapesize
);
860 printf("%.0f\n", ((double)tapesize
+ 1 + ntrec
) * TP_BSIZE
);
862 } /* stop here for size estimate */
864 if (pipeout
|| unlimited
) {
865 tapesize
+= 1 + ntrec
; /* 1 map header + trailer blocks */
866 msg("estimated %ld blocks.\n", tapesize
);
871 fetapes
= (double) tapesize
/ blocksperfile
;
872 else if (cartridge
) {
873 /* Estimate number of tapes, assuming streaming stops at
874 the end of each block written, and not in mid-block.
875 Assume no erroneous blocks; this can be compensated
876 for with an artificially low tape size. */
878 ( (double) tapesize
/* blocks */
879 * TP_BSIZE
/* bytes/block */
880 * (1.0/density
) /* 0.1" / byte " */
882 (double) tapesize
/* blocks */
883 * (1.0/ntrec
) /* streaming-stops per block */
884 * 15.48 /* 0.1" / streaming-stop " */
885 ) * (1.0 / tsize
); /* tape / 0.1" " */
887 /* Estimate number of tapes, for old fashioned 9-track
889 int tenthsperirg
= (density
== 625) ? 3 : 7;
891 ( (double) tapesize
/* blocks */
892 * TP_BSIZE
/* bytes / block */
893 * (1.0/density
) /* 0.1" / byte " */
895 (double) tapesize
/* blocks */
896 * (1.0/ntrec
) /* IRG's / block */
897 * tenthsperirg
/* 0.1" / IRG " */
898 ) * (1.0 / tsize
); /* tape / 0.1" " */
900 etapes
= fetapes
; /* truncating assignment */
902 /* count the dumped inodes map on each additional tape */
903 tapesize
+= (etapes
- 1) *
904 (howmany(mapsize
* sizeof(char), TP_BSIZE
) + 1);
905 tapesize
+= etapes
+ ntrec
; /* headers + trailer blks */
906 msg("estimated %ld blocks on %3.2f tape(s).\n",
912 msg("writing QFA positions to %s\n", gTapeposfile
);
913 if ((gTapeposfd
= open(gTapeposfile
,
914 O_WRONLY
|O_CREAT
|O_TRUNC
,
915 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
916 | S_IROTH
| S_IWOTH
)) < 0)
917 quit("can't open tapeposfile\n");
918 /* print QFA-file header */
919 snprintf(gTps
, sizeof(gTps
), "%s\n%s\n%ld\n\n", QFA_MAGIC
, QFA_VERSION
, (unsigned long)spcl
.c_date
);
920 gTps
[sizeof(gTps
) - 1] = '\0';
921 if (write(gTapeposfd
, gTps
, strlen(gTps
)) != (ssize_t
)strlen(gTps
))
922 quit("can't write tapeposfile\n");
923 sprintf(gTps
, "ino\ttapeno\ttapepos\n");
924 if (write(gTapeposfd
, gTps
, strlen(gTps
)) != (ssize_t
)strlen(gTps
))
925 quit("can't write tapeposfile\n");
930 * Allocate tape buffer.
934 "can't allocate tape buffers - try a smaller blocking factor.\n");
937 tstart_writing
= time(NULL
);
938 dumpmap(usedinomap
, TS_CLRI
, maxino
- 1);
940 msg("dumping (Pass III) [directories]\n");
941 dirty
= 0; /* XXX just to get gcc to shut up */
942 for (map
= dumpdirmap
, ino
= 1; ino
< maxino
; ino
++) {
943 if (((ino
- 1) % NBBY
) == 0) /* map is offset by 1 */
947 if ((dirty
& 1) == 0)
950 * Skip directory inodes deleted and maybe reallocated
953 if ((dp
->di_mode
& IFMT
) != IFDIR
)
957 * Skip directory inodes deleted and not yes reallocated...
959 if (dp
->di_nlink
== 0 || dp
->di_dtime
!= 0)
962 msg("dumping directory inode %lu\n", ino
);
963 (void)dumpdirino(dp
, ino
);
965 (void)dumpino(dp
, ino
);
969 msg("dumping (Pass IV) [regular files]\n");
970 for (map
= dumpinomap
, ino
= 1; ino
< maxino
; ino
++) {
971 if (((ino
- 1) % NBBY
) == 0) /* map is offset by 1 */
975 if ((dirty
& 1) == 0)
978 * Skip inodes deleted and reallocated as directories.
981 if ((dp
->di_mode
& IFMT
) == IFDIR
)
985 * No need to check here for deleted and not yet reallocated
986 * inodes since this is done in dumpino().
990 if (mflag
&& TSTINO(ino
, metainomap
))
991 msg("dumping regular inode %lu (meta only)\n", ino
);
993 msg("dumping regular inode %lu\n", ino
);
995 (void)dumpino(dp
, ino
, mflag
&& TSTINO(ino
, metainomap
));
998 tend_writing
= time(NULL
);
999 spcl
.c_type
= TS_END
;
1002 volinfo
[1] = ROOTINO
;
1003 memcpy(spcl
.c_inos
, volinfo
, TP_NINOS
* sizeof(dump_ino_t
));
1004 spcl
.c_flags
|= DR_INODEINFO
;
1008 * Finish off the current tape record with trailer blocks, to ensure
1009 * at least the data in the last partial record makes it to tape.
1010 * Also make sure we write at least 1 trailer block.
1012 for (i
= ntrec
- (spcl
.c_tapea
% ntrec
); i
; --i
)
1013 writeheader(maxino
- 1);
1017 if (pipeout
|| fifoout
)
1018 msg("%ld blocks (%.2fMB)\n", spcl
.c_tapea
,
1019 ((double)spcl
.c_tapea
* TP_BSIZE
/ 1048576));
1021 msg("%ld blocks (%.2fMB) on %d volume(s)\n",
1023 ((double)spcl
.c_tapea
* TP_BSIZE
/ 1048576),
1026 /* report dump performance, avoid division by zero */
1027 if (tend_writing
- tstart_writing
== 0)
1028 msg("finished in less than a second\n");
1030 msg("finished in %d seconds, throughput %d kBytes/sec\n",
1031 tend_writing
- tstart_writing
,
1032 spcl
.c_tapea
/ (tend_writing
- tstart_writing
));
1035 msg("Date of this level %c dump: %s", level
,
1036 spcl
.c_date
== 0 ? "the epoch\n" : ctime4(&spcl
.c_date
));
1037 msg("Date this dump completed: %s", ctime(&tnow
));
1039 msg("Average transfer rate: %ld kB/s\n", xferrate
/ tapeno
);
1041 long tapekb
= bytes_written
/ 1024;
1042 double rate
= .0005 + (double) spcl
.c_tapea
/ tapekb
;
1043 msg("Wrote %ldkB uncompressed, %ldkB compressed, %1.3f:1\n",
1044 spcl
.c_tapea
, tapekb
, rate
);
1048 msg("Archiving dump to %s\n", Apath
);
1050 broadcast("DUMP IS DONE!\7\7\n");
1051 msg("DUMP IS DONE\n");
1054 return 0; /* gcc - shut up */
1060 char white
[MAXPATHLEN
];
1061 const char *ext2ver
, *ext2date
;
1063 memset(white
, ' ', MAXPATHLEN
);
1064 white
[MIN(strlen(__progname
), MAXPATHLEN
- 1)] = '\0';
1067 ext2fs_get_library_version(&ext2ver
, &ext2date
);
1068 fprintf(stderr
, "%s %s (using libext2fs %s of %s)\n",
1069 __progname
, _DUMP_VERSION
, ext2ver
, ext2date
);
1071 fprintf(stderr
, "%s %s\n", __progname
, _DUMP_VERSION
);
1074 "usage:\t%s [-0123456789ac"
1079 "] [-A file] [-B records] [-b blocksize]\n"
1080 "\t%s [-d density] [-D file] [-e inode#,inode#,...] [-E file]\n"
1081 "\t%s [-f file] [-h level] [-I nr errors] "
1098 __progname
, white
, white
, white
, __progname
);
1103 * Pick up a numeric argument. It must be nonnegative and in the given
1104 * range (except that a vmax of 0 means unlimited).
1107 numarg(const char *meaning
, long vmin
, long vmax
)
1112 val
= strtol(optarg
, &p
, 10);
1114 errx(X_STARTUP
, "illegal %s -- %s", meaning
, optarg
);
1115 if (val
< vmin
|| (vmax
&& val
> vmax
))
1116 errx(X_STARTUP
, "%s must be between %ld and %ld", meaning
, vmin
, vmax
);
1130 if (pipeout
|| fifoout
)
1131 quit("Signal on pipe: cannot recover\n");
1132 msg("Rewriting attempted as response to unknown signal: %d.\n", signo
);
1133 (void)fflush(stderr
);
1134 (void)fflush(stdout
);
1139 msg("SIGSEGV: ABORTING!\n");
1140 (void)signal(SIGSEGV
, SIG_DFL
);
1141 (void)kill(0, SIGSEGV
);
1147 rawname(const char *cp
)
1151 #else /* __linux__ */
1152 static char rawbuf
[MAXPATHLEN
];
1153 char *dp
= strrchr(cp
, '/');
1157 (void)strncpy(rawbuf
, cp
, min(dp
-cp
, MAXPATHLEN
- 1));
1158 rawbuf
[min(dp
-cp
, MAXPATHLEN
-1)] = '\0';
1159 (void)strncat(rawbuf
, "/r", MAXPATHLEN
- 1 - strlen(rawbuf
));
1160 (void)strncat(rawbuf
, dp
+ 1, MAXPATHLEN
- 1 - strlen(rawbuf
));
1162 #endif /* __linux__ */
1167 * Change set of key letters and ordered arguments into something
1168 * getopt(3) will like.
1171 obsolete(int *argcp
, char **argvp
[])
1174 char *ap
, **argv
, *flagsp
=NULL
, **nargv
, *p
=NULL
;
1180 /* Return if no arguments or first argument has leading dash. */
1182 if (argc
== 1 || *ap
== '-')
1185 /* Allocate space for new arguments. */
1186 if ((*argvp
= nargv
= malloc((argc
+ 1) * sizeof(char *))) == NULL
||
1187 (p
= flagsp
= malloc(strlen(ap
) + 2)) == NULL
)
1188 err(X_STARTUP
, "malloc new args");
1193 for (flags
= 0; *ap
; ++ap
) {
1209 if (*argv
== NULL
) {
1210 warnx("option requires an argument -- %c", *ap
);
1213 if ((nargv
[0] = malloc(strlen(*argv
) + 2 + 1)) == NULL
)
1214 err(X_STARTUP
, "malloc arg");
1217 (void)strcpy(&nargv
[0][2], *argv
);
1231 /* Terminate flags. */
1237 /* Copy remaining arguments. */
1238 while ((*nargv
++ = *argv
++));
1240 /* Update argument count. */
1241 *argcp
= nargv
- *argvp
- 1;
1245 * This tests whether an inode is in the exclude bitmap
1248 exclude_ino(dump_ino_t ino
)
1250 /* if the inode exclude bitmap exists and covers given inode */
1251 if (iexclude_bitmap
&& iexclude_bitmap_bytes
> ino
/ 8) {
1252 /* then check this inode against it */
1253 int idx
= iexclude_bitmap
[ino
/ 8];
1254 if (idx
& (1 << (ino
% 8)))
1261 * This adds an inode to the exclusion bitmap if it isn't already there
1264 do_exclude_ino(dump_ino_t ino
, const char *reason
)
1266 if (exclude_ino(ino
))
1271 msg("Excluding inode %u (%s) from dump\n", ino
, reason
);
1273 msg("Excluding inode %u from dump\n", ino
);
1276 /* check for enough mem; initialize */
1277 if ((ino
/8 + 1) > iexclude_bitmap_bytes
) {
1278 if (iexclude_bitmap_bytes
== 0) {
1279 iexclude_bitmap_bytes
= 2 * (ino
/8 + 1);
1280 iexclude_bitmap
= (char*) malloc(iexclude_bitmap_bytes
);
1281 if (iexclude_bitmap
== NULL
) {
1282 msg("allocating memory failed\n");
1286 for (j
= 0; j
< iexclude_bitmap_bytes
; j
++)
1287 iexclude_bitmap
[j
] = 0;
1290 int oldsize
= iexclude_bitmap_bytes
;
1291 iexclude_bitmap_bytes
*=
1292 (ino
/ 8 + 1) / iexclude_bitmap_bytes
+ 1;
1293 iexclude_bitmap
= (char*) realloc(iexclude_bitmap
,
1294 iexclude_bitmap_bytes
);
1295 if (iexclude_bitmap
== NULL
) {
1296 msg("allocating memory failed\n");
1299 for( ; oldsize
< iexclude_bitmap_bytes
; oldsize
++)
1300 iexclude_bitmap
[oldsize
] = 0;
1304 iexclude_bitmap
[ino
/ 8] |= 1 << (ino
% 8);
1308 do_exclude_ino_str(char * ino
) {
1312 inod
= strtoul(ino
, &r
, 10);
1313 if (( *r
!= '\0' && !isspace(*r
) ) || inod
<= ROOTINO
) {
1314 msg("Invalid inode argument %s\n", ino
);
1315 msg("The ENTIRE dump is aborted.\n");
1318 do_exclude_ino(inod
, NULL
);
1322 * This reads a file containing one inode number per line and exclude them all
1325 do_exclude_from_file(char *file
) {
1327 char *p
, fname
[MAXPATHLEN
];
1330 if (!( f
= fopen(file
, "r")) ) {
1331 msg("Cannot open file for reading: %s\n", file
);
1332 msg("The ENTIRE dump is aborted.\n");
1335 while (( p
= fgets(fname
, MAXPATHLEN
, f
))) {
1336 if ( *p
&& *(p
+ strlen(p
) - 1) == '\n' ) /* possible null string */
1337 *(p
+ strlen(p
) - 1) = '\0';
1338 if ( !*p
) /* skip empty lines */
1340 do_exclude_ino_str(p
);
1345 static void incompat_flags(int cond
, char flag1
, char flag2
) {
1347 msg("You cannot use the %c and %c flags together.\n",
1349 msg("The ENTIRE dump is aborted.\n");