]>
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.83 2003/03/26 10:58:22 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
= -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 */
185 int maxbsize
= 1024*1024; /* XXX MAXBSIZE from sys/param.h */
186 static long numarg
__P((const char *, long, long));
187 static void obsolete
__P((int *, char **[]));
188 static void usage
__P((void));
189 static void do_exclude_from_file
__P((char *));
190 static void do_exclude_ino_str
__P((char *));
191 static void incompat_flags
__P((int, char, char));
193 static dump_ino_t iexclude_list
[IEXCLUDE_MAXNUM
];/* the inode exclude list */
194 static int iexclude_num
= 0; /* number of elements in the list */
197 main(int argc
, char *argv
[])
205 int i
, anydirskipped
;
206 int aflag
= 0, bflag
= 0, Tflag
= 0, honorlevel
= 1;
212 char directory
[MAXPATHLEN
];
213 char pathname
[MAXPATHLEN
];
219 spcl
.c_label
[0] = '\0';
220 spcl
.c_date
= time(NULL
);
223 __progname
= argv
[0];
225 initialize_ext2_error_table();
228 tsize
= 0; /* Default later, based on 'c' option for cart tapes */
231 if ((tapeprefix
= getenv("TAPE")) == NULL
)
232 tapeprefix
= _PATH_DEFTAPE
;
233 dumpdates
= _PATH_DUMPDATES
;
234 if (TP_BSIZE
/ DEV_BSIZE
== 0 || TP_BSIZE
% DEV_BSIZE
!= 0)
235 quit("TP_BSIZE must be a multiple of DEV_BSIZE\n");
241 obsolete(&argc
, &argv
);
247 while ((ch
= getopt(argc
, argv
,
248 "0123456789A:aB:b:cd:D:e:E:f:F:h:I:"
267 case '0': case '1': case '2': case '3': case '4':
268 case '5': case '6': case '7': case '8': case '9':
272 case 'A': /* archive file */
276 case 'a': /* `auto-size', Write to EOM. */
281 case 'B': /* blocks per output file */
283 blocksperfile
= numarg("number of blocks per file",
287 case 'b': /* blocks per tape write */
288 ntrec
= numarg("number of blocks per write",
290 if (ntrec
> maxbsize
/1024) {
291 msg("Please choose a blocksize <= %dkB\n",
293 msg("The ENTIRE dump is aborted.\n");
299 case 'c': /* Tape is cart. not 9-track */
304 case 'd': /* density, in bits per inch */
306 density
= numarg("density", 10L, 327670L) / 10;
307 if (density
>= 625 && !bflag
)
308 ntrec
= HIGHDENSITYTREC
;
311 case 'D': /* path of dumpdates file */
316 case 'e': /* exclude an inode */
318 char *p
= optarg
, *q
;
319 while ((q
= strchr(p
, ','))) {
321 do_exclude_ino_str(p
);
324 do_exclude_ino_str(p
);
328 case 'E': /* exclude inodes read from file */
329 do_exclude_from_file(optarg
);
332 case 'f': /* output file */
336 case 'F': /* end of tape script */
341 honorlevel
= numarg("honor level", 0L, 10L);
349 compressed
= numarg("compress level", 1L, 9L);
351 #endif /* HAVE_BZLIB */
355 numarg ("number of errors to ignore", 0L, 0L);
366 * Note that although there are LBLSIZE characters,
367 * the last must be '\0', so the limit on strlen()
368 * is really LBLSIZE-1.
370 strncpy(spcl
.c_label
, optarg
, LBLSIZE
);
371 spcl
.c_label
[LBLSIZE
-1] = '\0';
372 if (strlen(optarg
) > LBLSIZE
-1) {
374 "WARNING Label `%s' is larger than limit of %d characters.\n",
376 msg("WARNING: Using truncated label `%s'.\n",
381 case 'm': /* metadata only flag */
385 case 'M': /* multi-volume flag */
389 case 'n': /* notify operators */
398 case 'Q': /* create tapeposfile */
399 gTapeposfile
= optarg
;
404 case 's': /* tape size, feet */
406 tsize
= numarg("tape size", 1L, 0L) * 12 * 10;
410 sizest
= 1; /* return size estimate only */
413 case 'T': /* time of last dump */
414 spcl
.c_ddate
= unctime(optarg
);
415 if (spcl
.c_ddate
< 0) {
416 msg("bad time \"%s\"\n", optarg
);
417 msg("The ENTIRE dump is aborted.\n");
424 case 'u': /* update dumpdates */
428 case 'v': /* verbose */
432 case 'W': /* what to do */
435 exit(X_FINOK
); /* do nothing else */
440 compressed
= numarg("compress level", 1L, 9L);
442 #endif /* HAVE_ZLIB */
451 msg("Must specify disk or filesystem\n");
452 msg("The ENTIRE dump is aborted.\n");
456 if (strlen(diskparam
) >= MAXPATHLEN
) {
457 msg("Disk or filesystem name too long: %s\n", diskparam
);
458 msg("The ENTIRE dump is aborted.\n");
462 incompat_flags(Tflag
&& uflag
, 'T', 'u');
463 incompat_flags(aflag
&& blocksperfile
, 'a', 'B');
464 incompat_flags(aflag
&& cartridge
, 'a', 'c');
465 incompat_flags(aflag
&& density
, 'a', 'd');
466 incompat_flags(aflag
&& tsize
, 'a', 's');
468 if (strcmp(tapeprefix
, "-") == 0) {
470 tapeprefix
= "standard output";
473 if (blocksperfile
&& !compressed
)
474 blocksperfile
= blocksperfile
/ ntrec
* ntrec
; /* round down */
475 else if (!unlimited
) {
477 * Determine how to default tape size and density
480 * 9-track 1600 bpi (160 bytes/.1") 2300 ft.
481 * 9-track 6250 bpi (625 bytes/.1") 2300 ft.
482 * cartridge 8000 bpi (100 bytes/.1") 1700 ft.
484 * hilit19 hits again: "
487 density
= cartridge
? 100 : 160;
489 tsize
= cartridge
? 1700L*120L : 2300L*120L;
492 if (strchr(tapeprefix
, ':')) {
494 tapeprefix
= strchr(host
, ':');
495 *tapeprefix
++ = '\0';
497 if (index(tapeprefix
, '\n')) {
498 msg("invalid characters in tape\n");
499 msg("The ENTIRE dump is aborted.\n");
502 if (rmthost(host
) == 0)
505 msg("remote dump not enabled\n");
506 msg("The ENTIRE dump is aborted.\n");
510 (void)setuid(getuid()); /* rmthost() is the only reason to be setuid */
511 if (Apath
&& (Afile
= open(Apath
, O_WRONLY
|O_CREAT
|O_TRUNC
,
512 S_IRUSR
| S_IWUSR
| S_IRGRP
|
513 S_IWGRP
| S_IROTH
| S_IWOTH
)) < 0) {
514 msg("Cannot open %s for writing: %s\n",
515 optarg
, strerror(errno
));
516 msg("The ENTIRE dump is aborted.\n");
520 if (signal(SIGHUP
, SIG_IGN
) != SIG_IGN
)
522 if (signal(SIGTRAP
, SIG_IGN
) != SIG_IGN
)
523 signal(SIGTRAP
, sig
);
524 if (signal(SIGFPE
, SIG_IGN
) != SIG_IGN
)
526 if (signal(SIGBUS
, SIG_IGN
) != SIG_IGN
)
528 if (signal(SIGSEGV
, SIG_IGN
) != SIG_IGN
)
529 signal(SIGSEGV
, sig
);
530 if (signal(SIGTERM
, SIG_IGN
) != SIG_IGN
)
531 signal(SIGTERM
, sig
);
532 if (signal(SIGINT
, interrupt
) == SIG_IGN
)
533 signal(SIGINT
, SIG_IGN
);
535 signal(SIGXCPU
, SIG_IGN
);
538 signal(SIGXFSZ
, SIG_IGN
);
541 set_operators(); /* /etc/group snarfed */
542 getfstab(); /* /etc/fstab snarfed */
545 * disk may end in / and this can confuse
548 i
= strlen(diskparam
) - 1;
549 if (i
> 1 && diskparam
[i
] == '/')
550 if (!(i
== 6 && !strcmp(diskparam
, "LABEL=/")))
553 disk
= get_device_name(diskparam
);
554 if (!disk
) { /* null means the disk is some form
555 of LABEL= or UID= but it was not
557 msg("Cannot find a disk having %s\n", diskparam
);
558 msg("The ENTIRE dump is aborted.\n");
562 * disk can be either the full special file name,
563 * the suffix of the special file name,
564 * the special name missing the leading '/',
565 * the file system name with or without the leading '/'.
567 if ((dt
= fstabsearch(disk
)) != NULL
) {
568 /* if found then only one parameter (i.e. partition)
571 (void)fprintf(stderr
, "Unknown arguments to dump:");
573 (void)fprintf(stderr
, " %s", *argv
++);
574 (void)fprintf(stderr
, "\n");
575 msg("The ENTIRE dump is aborted.\n");
578 disk
= rawname(dt
->mnt_fsname
);
579 (void)strncpy(spcl
.c_dev
, dt
->mnt_fsname
, NAMELEN
);
580 (void)strncpy(spcl
.c_filesys
, dt
->mnt_dir
, NAMELEN
);
584 if (realpath(disk
, pathname
) == NULL
)
586 strcpy(pathname
, disk
);
588 * The argument could be now a mountpoint of
589 * a filesystem specified in fstab. Search for it.
591 if ((dt
= fstabsearch(pathname
)) != NULL
) {
592 disk
= rawname(dt
->mnt_fsname
);
593 (void)strncpy(spcl
.c_dev
, dt
->mnt_fsname
, NAMELEN
);
594 (void)strncpy(spcl
.c_filesys
, dt
->mnt_dir
, NAMELEN
);
597 * The argument was not found in the fstab
598 * assume that this is a subtree and search for it
600 dt
= fstabsearchdir(pathname
, directory
);
602 char name
[MAXPATHLEN
];
603 (void)strncpy(spcl
.c_dev
, dt
->mnt_fsname
, NAMELEN
);
604 (void)snprintf(name
, sizeof(name
), "%s (dir %s)",
605 dt
->mnt_dir
, directory
);
606 (void)strncpy(spcl
.c_filesys
, name
, NAMELEN
);
607 disk
= rawname(dt
->mnt_fsname
);
609 (void)strncpy(spcl
.c_dev
, disk
, NAMELEN
);
610 (void)strncpy(spcl
.c_filesys
, "an unlisted file system",
615 (void)strncpy(spcl
.c_dev
, disk
, NAMELEN
);
616 (void)strncpy(spcl
.c_filesys
, "an unlisted file system",
621 if (directory
[0] != 0) {
623 msg("Only level 0 dumps are allowed on a subdirectory\n");
624 msg("The ENTIRE dump is aborted.\n");
628 msg("You can't update the dumpdates file when dumping a subdirectory\n");
629 msg("The ENTIRE dump is aborted.\n");
633 spcl
.c_dev
[NAMELEN
-1] = '\0';
634 spcl
.c_filesys
[NAMELEN
-1] = '\0';
635 (void)gethostname(spcl
.c_host
, NAMELEN
);
636 spcl
.c_host
[NAMELEN
-1] = '\0';
637 spcl
.c_level
= level
- '0';
638 spcl
.c_type
= TS_TAPE
;
640 getdumptime(uflag
); /* dumpdates snarfed */
642 if (spcl
.c_ddate
== 0 && spcl
.c_level
) {
643 msg("WARNING: There is no inferior level dump on this filesystem\n");
644 msg("WARNING: Assuming a level 0 dump by default\n");
650 snprintf(tape
, MAXPATHLEN
, "%s%03d", tapeprefix
, tapeno
+ 1);
652 strncpy(tape
, tapeprefix
, MAXPATHLEN
);
653 tape
[MAXPATHLEN
- 1] = '\0';
656 if (STAT(tape
, &statbuf
) != -1)
657 fifoout
= statbuf
.st_mode
& S_IFIFO
;
662 msg("Date of this level %c dump: %s", level
,
663 ctime4(&spcl
.c_date
));
665 gThisDumpDate
= spcl
.c_date
;
668 msg("Date of last level %c dump: %s", lastlevel
,
669 ctime4(&spcl
.c_ddate
));
670 msg("Dumping %s (%s) ", disk
, spcl
.c_filesys
);
672 msgtail("to %s on host %s\n", tape
, host
);
674 msgtail("to %s\n", tape
);
675 } /* end of size estimate */
678 if ((diskfd
= OPEN(disk
, O_RDONLY
)) < 0) {
679 msg("Cannot open %s\n", disk
);
680 msg("The ENTIRE dump is aborted.\n");
684 (void)ioctl(diskfd
, BLKFLSBUF
);
686 retval
= dump_fs_open(disk
, &fs
);
688 com_err(disk
, retval
, "while opening filesystem");
689 if (retval
== EXT2_ET_REV_TOO_HIGH
)
690 msg("Get a newer version of dump!\n");
691 msg("The ENTIRE dump is aborted.\n");
694 if (fs
->super
->s_rev_level
> DUMP_CURRENT_REV
) {
695 com_err(disk
, retval
, "while opening filesystem");
696 msg("Get a newer version of dump!\n");
697 msg("The ENTIRE dump is aborted.\n");
700 /* if no user label specified, use ext2 filesystem label if available */
701 if (spcl
.c_label
[0] == '\0') {
703 if ( (lbl
= get_device_label(disk
)) != NULL
) {
704 strncpy(spcl
.c_label
, lbl
, LBLSIZE
);
705 spcl
.c_label
[LBLSIZE
-1] = '\0';
708 strcpy(spcl
.c_label
, "none"); /* safe strcpy. */
711 dev_bsize
= DEV_BSIZE
;
712 dev_bshift
= ffs(dev_bsize
) - 1;
713 if (dev_bsize
!= (1 << dev_bshift
))
714 quit("dev_bsize (%d) is not a power of 2", dev_bsize
);
715 tp_bshift
= ffs(TP_BSIZE
) - 1;
716 if (TP_BSIZE
!= (1 << tp_bshift
))
717 quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE
);
718 maxino
= fs
->super
->s_inodes_count
+ 1;
719 spcl
.c_flags
|= DR_NEWINODEFMT
;
720 #else /* __linux __*/
721 if ((diskfd
= open(disk
, O_RDONLY
)) < 0) {
722 msg("Cannot open %s\n", disk
);
723 msg("The ENTIRE dump is aborted.\n");
727 sblock
= (struct fs
*)sblock_buf
;
728 bread(SBOFF
, (char *) sblock
, SBSIZE
);
729 if (sblock
->fs_magic
!= FS_MAGIC
)
730 quit("bad sblock magic number\n");
731 dev_bsize
= sblock
->fs_fsize
/ fsbtodb(sblock
, 1);
732 dev_bshift
= ffs(dev_bsize
) - 1;
733 if (dev_bsize
!= (1 << dev_bshift
))
734 quit("dev_bsize (%d) is not a power of 2", dev_bsize
);
735 tp_bshift
= ffs(TP_BSIZE
) - 1;
736 if (TP_BSIZE
!= (1 << tp_bshift
))
737 quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE
);
739 if (sblock
->fs_inodefmt
>= FS_44INODEFMT
)
740 spcl
.c_flags
|= DR_NEWINODEFMT
;
742 maxino
= sblock
->fs_ipg
* sblock
->fs_ncg
;
743 #endif /* __linux__ */
744 mapsize
= roundup(howmany(maxino
, NBBY
), TP_BSIZE
);
745 usedinomap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
746 dumpdirmap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
747 dumpinomap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
748 metainomap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
749 if (usedinomap
== NULL
|| dumpdirmap
== NULL
||
750 dumpinomap
== NULL
|| metainomap
== NULL
)
751 quit("out of memory allocating inode maps\n");
752 tapesize
= 2 * (howmany(mapsize
* sizeof(char), TP_BSIZE
) + 1);
754 nonodump
= spcl
.c_level
< honorlevel
;
757 msg("Label: %s\n", spcl
.c_label
);
759 msg("Writing %d Kilobyte records\n", ntrec
);
762 msg("Compressing output at compression level %d (%s)\n",
763 compressed
, bzipflag
? "bzlib" : "zlib");
767 (void)signal(SIGINFO
, statussig
);
771 msg("mapping (Pass I) [regular files]\n");
773 if (directory
[0] == 0)
774 anydirskipped
= mapfiles(maxino
, &tapesize
);
776 if (LSTAT(pathname
, &statbuf
) == -1) {
777 msg("File cannot be accessed (%s).\n", pathname
);
778 msg("The ENTIRE dump is aborted.\n");
781 filedev
= statbuf
.st_dev
;
782 if (!(statbuf
.st_mode
& S_IFDIR
)) /* is a file */
783 anydirskipped
= maponefile(maxino
, &tapesize
,
786 anydirskipped
= mapfilesfromdir(maxino
, &tapesize
,
792 /* check if file is available */
793 if (LSTAT(p
, &statbuf
) == -1) {
794 msg("File cannot be accessed (%s).\n", p
);
795 msg("The ENTIRE dump is aborted.\n");
798 /* check if file is on same unix partiton as the first
800 if (statbuf
.st_dev
!= filedev
) {
801 msg("Files are not on same file system (%s).\n", p
);
802 msg("The ENTIRE dump is aborted.\n");
805 /* check if file is a directory */
806 if (!(statbuf
.st_mode
& S_IFDIR
))
807 anydirskipped2
= maponefile(maxino
, &tapesize
,
808 p
+strlen(dt
->mnt_dir
));
810 /* read directory inodes.
811 * NOTE: nested directories are not recognized
812 * so inodes may be umped twice!
814 anydirskipped2
= mapfilesfromdir(maxino
, &tapesize
,
815 p
+strlen(dt
->mnt_dir
));
817 anydirskipped
= anydirskipped2
;
821 anydirskipped
= mapfiles(maxino
, &tapesize
);
825 msg("mapping (Pass II) [directories]\n");
826 while (anydirskipped
) {
827 anydirskipped
= mapdirs(maxino
, &tapesize
);
831 printf("%.0f\n", ((double)tapesize
+ 1 + ntrec
) * TP_BSIZE
);
833 } /* stop here for size estimate */
835 if (pipeout
|| unlimited
) {
836 tapesize
+= 1 + ntrec
; /* 1 map header + trailer blocks */
837 msg("estimated %ld blocks.\n", tapesize
);
842 fetapes
= (double) tapesize
/ blocksperfile
;
843 else if (cartridge
) {
844 /* Estimate number of tapes, assuming streaming stops at
845 the end of each block written, and not in mid-block.
846 Assume no erroneous blocks; this can be compensated
847 for with an artificially low tape size. */
849 ( (double) tapesize
/* blocks */
850 * TP_BSIZE
/* bytes/block */
851 * (1.0/density
) /* 0.1" / byte " */
853 (double) tapesize
/* blocks */
854 * (1.0/ntrec
) /* streaming-stops per block */
855 * 15.48 /* 0.1" / streaming-stop " */
856 ) * (1.0 / tsize
); /* tape / 0.1" " */
858 /* Estimate number of tapes, for old fashioned 9-track
860 int tenthsperirg
= (density
== 625) ? 3 : 7;
862 ( (double) tapesize
/* blocks */
863 * TP_BSIZE
/* bytes / block */
864 * (1.0/density
) /* 0.1" / byte " */
866 (double) tapesize
/* blocks */
867 * (1.0/ntrec
) /* IRG's / block */
868 * tenthsperirg
/* 0.1" / IRG " */
869 ) * (1.0 / tsize
); /* tape / 0.1" " */
871 etapes
= fetapes
; /* truncating assignment */
873 /* count the dumped inodes map on each additional tape */
874 tapesize
+= (etapes
- 1) *
875 (howmany(mapsize
* sizeof(char), TP_BSIZE
) + 1);
876 tapesize
+= etapes
+ ntrec
; /* headers + trailer blks */
877 msg("estimated %ld blocks on %3.2f tape(s).\n",
883 msg("writing QFA positions to %s\n", gTapeposfile
);
884 if ((gTapeposfd
= open(gTapeposfile
,
885 O_WRONLY
|O_CREAT
|O_TRUNC
,
886 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
887 | S_IROTH
| S_IWOTH
)) < 0)
888 quit("can't open tapeposfile\n");
889 /* print QFA-file header */
890 snprintf(gTps
, sizeof(gTps
), "%s\n%s\n%ld\n\n", QFA_MAGIC
, QFA_VERSION
, (unsigned long)spcl
.c_date
);
891 gTps
[sizeof(gTps
) - 1] = '\0';
892 if (write(gTapeposfd
, gTps
, strlen(gTps
)) != (ssize_t
)strlen(gTps
))
893 quit("can't write tapeposfile\n");
894 sprintf(gTps
, "ino\ttapeno\ttapepos\n");
895 if (write(gTapeposfd
, gTps
, strlen(gTps
)) != (ssize_t
)strlen(gTps
))
896 quit("can't write tapeposfile\n");
901 * Allocate tape buffer.
905 "can't allocate tape buffers - try a smaller blocking factor.\n");
908 tstart_writing
= time(NULL
);
909 dumpmap(usedinomap
, TS_CLRI
, maxino
- 1);
911 msg("dumping (Pass III) [directories]\n");
912 dirty
= 0; /* XXX just to get gcc to shut up */
913 for (map
= dumpdirmap
, ino
= 1; ino
< maxino
; ino
++) {
914 if (((ino
- 1) % NBBY
) == 0) /* map is offset by 1 */
918 if ((dirty
& 1) == 0)
921 * Skip directory inodes deleted and maybe reallocated
924 if ((dp
->di_mode
& IFMT
) != IFDIR
)
928 * Skip directory inodes deleted and not yes reallocated...
930 if (dp
->di_nlink
== 0 || dp
->di_dtime
!= 0)
933 msg("dumping directory inode %lu\n", ino
);
934 (void)dumpdirino(dp
, ino
);
936 (void)dumpino(dp
, ino
);
940 msg("dumping (Pass IV) [regular files]\n");
941 for (map
= dumpinomap
, ino
= 1; ino
< maxino
; ino
++) {
942 if (((ino
- 1) % NBBY
) == 0) /* map is offset by 1 */
946 if ((dirty
& 1) == 0)
949 * Skip inodes deleted and reallocated as directories.
952 if ((dp
->di_mode
& IFMT
) == IFDIR
)
956 * No need to check here for deleted and not yet reallocated
957 * inodes since this is done in dumpino().
961 if (mflag
&& TSTINO(ino
, metainomap
))
962 msg("dumping regular inode %lu (meta only)\n", ino
);
964 msg("dumping regular inode %lu\n", ino
);
966 (void)dumpino(dp
, ino
, mflag
&& TSTINO(ino
, metainomap
));
969 tend_writing
= time(NULL
);
970 spcl
.c_type
= TS_END
;
973 volinfo
[1] = ROOTINO
;
974 memcpy(spcl
.c_inos
, volinfo
, TP_NINOS
* sizeof(dump_ino_t
));
975 spcl
.c_flags
|= DR_INODEINFO
;
979 * Finish off the current tape record with trailer blocks, to ensure
980 * at least the data in the last partial record makes it to tape.
981 * Also make sure we write at least 1 trailer block.
983 for (i
= ntrec
- (spcl
.c_tapea
% ntrec
); i
; --i
)
984 writeheader(maxino
- 1);
988 if (pipeout
|| fifoout
)
989 msg("%ld blocks (%.2fMB)\n", spcl
.c_tapea
,
990 ((double)spcl
.c_tapea
* TP_BSIZE
/ 1048576));
992 msg("%ld blocks (%.2fMB) on %d volume(s)\n",
994 ((double)spcl
.c_tapea
* TP_BSIZE
/ 1048576),
997 /* report dump performance, avoid division by zero */
998 if (tend_writing
- tstart_writing
== 0)
999 msg("finished in less than a second\n");
1001 msg("finished in %d seconds, throughput %d kBytes/sec\n",
1002 tend_writing
- tstart_writing
,
1003 spcl
.c_tapea
/ (tend_writing
- tstart_writing
));
1006 msg("Date of this level %c dump: %s", level
,
1007 spcl
.c_date
== 0 ? "the epoch\n" : ctime4(&spcl
.c_date
));
1008 msg("Date this dump completed: %s", ctime(&tnow
));
1010 msg("Average transfer rate: %ld kB/s\n", xferrate
/ tapeno
);
1012 long tapekb
= bytes_written
/ 1024;
1013 double rate
= .0005 + (double) spcl
.c_tapea
/ tapekb
;
1014 msg("Wrote %ldkB uncompressed, %ldkB compressed, %1.3f:1\n",
1015 spcl
.c_tapea
, tapekb
, rate
);
1019 msg("Archiving dump to %s\n", Apath
);
1021 broadcast("DUMP IS DONE!\7\7\n");
1022 msg("DUMP IS DONE\n");
1025 return 0; /* gcc - shut up */
1031 char white
[MAXPATHLEN
];
1032 const char *ext2ver
, *ext2date
;
1034 memset(white
, ' ', MAXPATHLEN
);
1035 white
[MIN(strlen(__progname
), MAXPATHLEN
- 1)] = '\0';
1038 ext2fs_get_library_version(&ext2ver
, &ext2date
);
1039 fprintf(stderr
, "%s %s (using libext2fs %s of %s)\n",
1040 __progname
, _DUMP_VERSION
, ext2ver
, ext2date
);
1042 fprintf(stderr
, "%s %s\n", __progname
, _DUMP_VERSION
);
1045 "usage:\t%s [-0123456789ac"
1050 "] [-A file] [-B records] [-b blocksize]\n"
1051 "\t%s [-d density] [-D file] [-e inode#,inode#,...] [-E file]\n"
1052 "\t%s [-f file] [-h level] [-I nr errors] "
1066 __progname
, white
, white
, white
, __progname
);
1071 * Pick up a numeric argument. It must be nonnegative and in the given
1072 * range (except that a vmax of 0 means unlimited).
1075 numarg(const char *meaning
, long vmin
, long vmax
)
1080 val
= strtol(optarg
, &p
, 10);
1082 errx(X_STARTUP
, "illegal %s -- %s", meaning
, optarg
);
1083 if (val
< vmin
|| (vmax
&& val
> vmax
))
1084 errx(X_STARTUP
, "%s must be between %ld and %ld", meaning
, vmin
, vmax
);
1098 if (pipeout
|| fifoout
)
1099 quit("Signal on pipe: cannot recover\n");
1100 msg("Rewriting attempted as response to unknown signal: %d.\n", signo
);
1101 (void)fflush(stderr
);
1102 (void)fflush(stdout
);
1107 msg("SIGSEGV: ABORTING!\n");
1108 (void)signal(SIGSEGV
, SIG_DFL
);
1109 (void)kill(0, SIGSEGV
);
1115 rawname(const char *cp
)
1119 #else /* __linux__ */
1120 static char rawbuf
[MAXPATHLEN
];
1121 char *dp
= strrchr(cp
, '/');
1125 (void)strncpy(rawbuf
, cp
, min(dp
-cp
, MAXPATHLEN
- 1));
1126 rawbuf
[min(dp
-cp
, MAXPATHLEN
-1)] = '\0';
1127 (void)strncat(rawbuf
, "/r", MAXPATHLEN
- 1 - strlen(rawbuf
));
1128 (void)strncat(rawbuf
, dp
+ 1, MAXPATHLEN
- 1 - strlen(rawbuf
));
1130 #endif /* __linux__ */
1135 * Change set of key letters and ordered arguments into something
1136 * getopt(3) will like.
1139 obsolete(int *argcp
, char **argvp
[])
1142 char *ap
, **argv
, *flagsp
=NULL
, **nargv
, *p
=NULL
;
1148 /* Return if no arguments or first argument has leading dash. */
1150 if (argc
== 1 || *ap
== '-')
1153 /* Allocate space for new arguments. */
1154 if ((*argvp
= nargv
= malloc((argc
+ 1) * sizeof(char *))) == NULL
||
1155 (p
= flagsp
= malloc(strlen(ap
) + 2)) == NULL
)
1156 err(X_STARTUP
, "malloc new args");
1161 for (flags
= 0; *ap
; ++ap
) {
1177 if (*argv
== NULL
) {
1178 warnx("option requires an argument -- %c", *ap
);
1181 if ((nargv
[0] = malloc(strlen(*argv
) + 2 + 1)) == NULL
)
1182 err(X_STARTUP
, "malloc arg");
1185 (void)strcpy(&nargv
[0][2], *argv
);
1199 /* Terminate flags. */
1205 /* Copy remaining arguments. */
1206 while ((*nargv
++ = *argv
++));
1208 /* Update argument count. */
1209 *argcp
= nargv
- *argvp
- 1;
1213 * This tests whether an inode is in the exclude list
1216 exclude_ino(dump_ino_t ino
)
1219 if (iexclude_num
) { /* if there are inodes in the exclude list */
1220 int idx
; /* then check this inode against it */
1221 for (idx
= 0; idx
< iexclude_num
; idx
++)
1222 if (ino
== iexclude_list
[idx
])
1229 * This tests adds an inode to the exclusion list if it isn't already there
1232 do_exclude_ino(dump_ino_t ino
, const char *reason
)
1234 if (!exclude_ino(ino
)) {
1235 if (iexclude_num
== IEXCLUDE_MAXNUM
) {
1236 msg("Too many exclude options\n");
1237 msg("The ENTIRE dump is aborted.\n");
1241 msg("Excluding inode %u (%s) from dump\n",
1244 msg("Excluding inode %u from dump\n", ino
);
1245 iexclude_list
[iexclude_num
++] = ino
;
1250 do_exclude_ino_str(char * ino
) {
1254 inod
= strtoul(ino
, &r
, 10);
1255 if (( *r
!= '\0' && !isspace(*r
) ) || inod
<= ROOTINO
) {
1256 msg("Invalid inode argument %s\n", ino
);
1257 msg("The ENTIRE dump is aborted.\n");
1260 do_exclude_ino(inod
, NULL
);
1264 * This reads a file containing one inode number per line and exclude them all
1267 do_exclude_from_file(char *file
) {
1269 char *p
, fname
[MAXPATHLEN
];
1272 if (!( f
= fopen(file
, "r")) ) {
1273 msg("Cannot open file for reading: %s\n", file
);
1274 msg("The ENTIRE dump is aborted.\n");
1277 while (( p
= fgets(fname
, MAXPATHLEN
, f
))) {
1278 if ( *p
&& *(p
+ strlen(p
) - 1) == '\n' ) /* possible null string */
1279 *(p
+ strlen(p
) - 1) = '\0';
1280 if ( !*p
) /* skip empty lines */
1282 do_exclude_ino_str(p
);
1287 static void incompat_flags(int cond
, char flag1
, char flag2
) {
1289 msg("You cannot use the %c and %c flags together.\n",
1291 msg("The ENTIRE dump is aborted.\n");