]>
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.85 2003/03/31 09:42:58 stelian Exp $";
44 #include <compatlfs.h>
46 #include <compaterr.h>
56 #include <sys/param.h>
60 #ifdef HAVE_EXT2FS_EXT2_FS_H
61 #include <ext2fs/ext2_fs.h>
63 #include <linux/ext2_fs.h>
65 #include <ext2fs/ext2fs.h>
67 #include <bsdcompat.h>
69 #include <sys/vnode.h>
71 #include <ufs/inode.h>
74 #include <ufs/ufs/dinode.h>
75 #include <ufs/ffs/fs.h>
78 #include <protocols/dumprestore.h>
81 #include "pathnames.h"
85 #define SBOFF (SBLOCK * DEV_BSIZE)
89 * Dump maps used to describe what is to be dumped.
91 int mapsize
; /* size of the state maps */
92 char *usedinomap
; /* map of allocated inodes */
93 char *dumpdirmap
; /* map of directories to be dumped */
94 char *dumpinomap
; /* map of files to be dumped */
95 char *metainomap
; /* which of the inodes in dumpinomap will get
96 only their metadata dumped */
98 const char *disk
; /* name of the disk file */
99 char tape
[MAXPATHLEN
];/* name of the tape file */
100 char *tapeprefix
; /* prefix of the tape file */
101 char *dumpdates
; /* name of the file containing dump date information*/
102 char lastlevel
; /* dump level of previous dump */
103 char level
; /* dump level of this dump */
104 int zipflag
; /* which compression method */
105 int Afile
= -1; /* archive file descriptor */
106 int AfileActive
= 1;/* Afile flag */
107 int uflag
; /* update flag */
108 int mflag
; /* dump metadata only if possible */
109 int Mflag
; /* multi-volume flag */
110 int qflag
; /* quit on errors flag */
111 int vflag
; /* verbose flag */
112 int breademax
= 32; /* maximum number of bread errors before we quit */
113 char *eot_script
; /* end of volume script fiag */
114 int diskfd
; /* disk file descriptor */
115 int tapefd
; /* tape file descriptor */
116 int pipeout
; /* true => output to standard output */
117 int fifoout
; /* true => output to fifo */
118 dump_ino_t curino
; /* current inumber; used globally */
119 int newtape
; /* new tape flag */
120 int density
; /* density in 0.1" units */
121 long tapesize
; /* estimated tape size, blocks */
122 long tsize
; /* tape size in 0.1" units */
123 long asize
; /* number of 0.1" units written on current tape */
124 int etapes
; /* estimated number of tapes */
125 int nonodump
; /* if set, do not honor UF_NODUMP user flags */
126 int unlimited
; /* if set, write to end of medium */
127 int compressed
; /* if set, dump is to be compressed */
128 long long bytes_written
;/* total bytes written to tape */
129 long uncomprblks
; /* uncompressed blocks written to tape */
130 int notify
; /* notify operator flag */
131 int blockswritten
; /* number of blocks written on current tape */
132 int tapeno
; /* current tape number */
133 time_t tstart_writing
; /* when started writing the first tape block */
134 time_t tend_writing
; /* after writing the last tape block */
138 struct fs
*sblock
; /* the file system super block */
139 char sblock_buf
[MAXBSIZE
];
141 long xferrate
; /* averaged transfer rate of all volumes */
142 long dev_bsize
; /* block size of underlying disk device */
143 int dev_bshift
; /* log2(dev_bsize) */
144 int tp_bshift
; /* log2(TP_BSIZE) */
145 dump_ino_t volinfo
[TP_NINOS
];/* which inode on which volume archive info */
151 int32_t gThisDumpDate
;
154 struct dumptime
*dthead
; /* head of the list version */
155 int nddates
; /* number of records (might be zero) */
156 int ddates_in
; /* we have read the increment file */
157 struct dumpdates
**ddatev
; /* the arrayfied version */
159 int notify
= 0; /* notify operator flag */
160 int blockswritten
= 0; /* number of blocks written on current tape */
161 int tapeno
= 0; /* current tape number */
162 int density
= 0; /* density in bytes/0.1" " <- this is for hilit19 */
163 int ntrec
= NTREC
; /* # blocks in each tape record */
164 int cartridge
= 0; /* Assume non-cartridge tape */
166 int tapepos
= 0; /* assume no QFA tapeposition needed by user */
168 int dokerberos
= 0; /* Use Kerberos authentication */
169 long dev_bsize
= 1; /* recalculated below */
170 long blocksperfile
; /* output blocks per file */
171 char *host
= NULL
; /* remote host (if any) */
172 int sizest
= 0; /* return size estimate only */
173 int compressed
= 0; /* use zlib to compress the output, compress level 1-9 */
174 long long bytes_written
= 0; /* total bytes written */
175 long uncomprblks
= 0;/* uncompressed blocks written */
181 int maxbsize
= 1024*1024; /* XXX MAXBSIZE from sys/param.h */
182 static long numarg
__P((const char *, long, long));
183 static void obsolete
__P((int *, char **[]));
184 static void usage
__P((void));
185 static void do_exclude_from_file
__P((char *));
186 static void do_exclude_ino_str
__P((char *));
187 static void incompat_flags
__P((int, char, char));
189 static dump_ino_t iexclude_list
[IEXCLUDE_MAXNUM
];/* the inode exclude list */
190 static int iexclude_num
= 0; /* number of elements in the list */
193 main(int argc
, char *argv
[])
201 int i
, anydirskipped
;
202 int aflag
= 0, bflag
= 0, Tflag
= 0, honorlevel
= 1;
208 char directory
[MAXPATHLEN
];
209 char pathname
[MAXPATHLEN
];
215 spcl
.c_label
[0] = '\0';
216 spcl
.c_date
= time(NULL
);
219 __progname
= argv
[0];
221 initialize_ext2_error_table();
224 tsize
= 0; /* Default later, based on 'c' option for cart tapes */
227 if ((tapeprefix
= getenv("TAPE")) == NULL
)
228 tapeprefix
= _PATH_DEFTAPE
;
229 dumpdates
= _PATH_DUMPDATES
;
230 if (TP_BSIZE
/ DEV_BSIZE
== 0 || TP_BSIZE
% DEV_BSIZE
!= 0)
231 quit("TP_BSIZE must be a multiple of DEV_BSIZE\n");
237 obsolete(&argc
, &argv
);
243 while ((ch
= getopt(argc
, argv
,
244 "0123456789A:aB:b:cd:D:e:E:f:F:h:I:"
266 case '0': case '1': case '2': case '3': case '4':
267 case '5': case '6': case '7': case '8': case '9':
271 case 'A': /* archive file */
275 case 'a': /* `auto-size', Write to EOM. */
280 case 'B': /* blocks per output file */
282 blocksperfile
= numarg("number of blocks per file",
286 case 'b': /* blocks per tape write */
287 ntrec
= numarg("number of blocks per write",
289 if (ntrec
> maxbsize
/1024) {
290 msg("Please choose a blocksize <= %dkB\n",
292 msg("The ENTIRE dump is aborted.\n");
298 case 'c': /* Tape is cart. not 9-track */
303 case 'd': /* density, in bits per inch */
305 density
= numarg("density", 10L, 327670L) / 10;
306 if (density
>= 625 && !bflag
)
307 ntrec
= HIGHDENSITYTREC
;
310 case 'D': /* path of dumpdates file */
315 case 'e': /* exclude an inode */
317 char *p
= optarg
, *q
;
318 while ((q
= strchr(p
, ','))) {
320 do_exclude_ino_str(p
);
323 do_exclude_ino_str(p
);
327 case 'E': /* exclude inodes read from file */
328 do_exclude_from_file(optarg
);
331 case 'f': /* output file */
335 case 'F': /* end of tape script */
340 honorlevel
= numarg("honor level", 0L, 10L);
346 zipflag
= COMPRESS_BZLIB
;
348 compressed
= numarg("compress level", 1L, 9L);
350 #endif /* HAVE_BZLIB */
354 numarg ("number of errors to ignore", 0L, 0L);
365 * Note that although there are LBLSIZE characters,
366 * the last must be '\0', so the limit on strlen()
367 * is really LBLSIZE-1.
369 strncpy(spcl
.c_label
, optarg
, LBLSIZE
);
370 spcl
.c_label
[LBLSIZE
-1] = '\0';
371 if (strlen(optarg
) > LBLSIZE
-1) {
373 "WARNING Label `%s' is larger than limit of %d characters.\n",
375 msg("WARNING: Using truncated label `%s'.\n",
380 case 'm': /* metadata only flag */
384 case 'M': /* multi-volume flag */
388 case 'n': /* notify operators */
397 case 'Q': /* create tapeposfile */
398 gTapeposfile
= optarg
;
403 case 's': /* tape size, feet */
405 tsize
= numarg("tape size", 1L, 0L) * 12 * 10;
409 sizest
= 1; /* return size estimate only */
412 case 'T': /* time of last dump */
413 spcl
.c_ddate
= unctime(optarg
);
414 if (spcl
.c_ddate
< 0) {
415 msg("bad time \"%s\"\n", optarg
);
416 msg("The ENTIRE dump is aborted.\n");
423 case 'u': /* update dumpdates */
427 case 'v': /* verbose */
431 case 'W': /* what to do */
434 exit(X_FINOK
); /* do nothing else */
438 zipflag
= COMPRESS_LZO
;
440 #endif /* HAVE_LZO */
445 zipflag
= COMPRESS_ZLIB
;
447 compressed
= numarg("compress level", 1L, 9L);
449 #endif /* HAVE_ZLIB */
458 msg("Must specify disk or filesystem\n");
459 msg("The ENTIRE dump is aborted.\n");
463 if (strlen(diskparam
) >= MAXPATHLEN
) {
464 msg("Disk or filesystem name too long: %s\n", diskparam
);
465 msg("The ENTIRE dump is aborted.\n");
469 incompat_flags(Tflag
&& uflag
, 'T', 'u');
470 incompat_flags(aflag
&& blocksperfile
, 'a', 'B');
471 incompat_flags(aflag
&& cartridge
, 'a', 'c');
472 incompat_flags(aflag
&& density
, 'a', 'd');
473 incompat_flags(aflag
&& tsize
, 'a', 's');
475 if (strcmp(tapeprefix
, "-") == 0) {
477 tapeprefix
= "standard output";
480 if (blocksperfile
&& !compressed
)
481 blocksperfile
= blocksperfile
/ ntrec
* ntrec
; /* round down */
482 else if (!unlimited
) {
484 * Determine how to default tape size and density
487 * 9-track 1600 bpi (160 bytes/.1") 2300 ft.
488 * 9-track 6250 bpi (625 bytes/.1") 2300 ft.
489 * cartridge 8000 bpi (100 bytes/.1") 1700 ft.
491 * hilit19 hits again: "
494 density
= cartridge
? 100 : 160;
496 tsize
= cartridge
? 1700L*120L : 2300L*120L;
499 if (strchr(tapeprefix
, ':')) {
501 tapeprefix
= strchr(host
, ':');
502 *tapeprefix
++ = '\0';
504 if (index(tapeprefix
, '\n')) {
505 msg("invalid characters in tape\n");
506 msg("The ENTIRE dump is aborted.\n");
509 if (rmthost(host
) == 0)
512 msg("remote dump not enabled\n");
513 msg("The ENTIRE dump is aborted.\n");
517 (void)setuid(getuid()); /* rmthost() is the only reason to be setuid */
518 if (Apath
&& (Afile
= open(Apath
, O_WRONLY
|O_CREAT
|O_TRUNC
,
519 S_IRUSR
| S_IWUSR
| S_IRGRP
|
520 S_IWGRP
| S_IROTH
| S_IWOTH
)) < 0) {
521 msg("Cannot open %s for writing: %s\n",
522 optarg
, strerror(errno
));
523 msg("The ENTIRE dump is aborted.\n");
527 if (signal(SIGHUP
, SIG_IGN
) != SIG_IGN
)
529 if (signal(SIGTRAP
, SIG_IGN
) != SIG_IGN
)
530 signal(SIGTRAP
, sig
);
531 if (signal(SIGFPE
, SIG_IGN
) != SIG_IGN
)
533 if (signal(SIGBUS
, SIG_IGN
) != SIG_IGN
)
535 if (signal(SIGSEGV
, SIG_IGN
) != SIG_IGN
)
536 signal(SIGSEGV
, sig
);
537 if (signal(SIGTERM
, SIG_IGN
) != SIG_IGN
)
538 signal(SIGTERM
, sig
);
539 if (signal(SIGINT
, interrupt
) == SIG_IGN
)
540 signal(SIGINT
, SIG_IGN
);
542 signal(SIGXCPU
, SIG_IGN
);
545 signal(SIGXFSZ
, SIG_IGN
);
548 set_operators(); /* /etc/group snarfed */
549 getfstab(); /* /etc/fstab snarfed */
552 * disk may end in / and this can confuse
555 i
= strlen(diskparam
) - 1;
556 if (i
> 1 && diskparam
[i
] == '/')
557 if (!(i
== 6 && !strcmp(diskparam
, "LABEL=/")))
560 disk
= get_device_name(diskparam
);
561 if (!disk
) { /* null means the disk is some form
562 of LABEL= or UID= but it was not
564 msg("Cannot find a disk having %s\n", diskparam
);
565 msg("The ENTIRE dump is aborted.\n");
569 * disk can be either the full special file name,
570 * the suffix of the special file name,
571 * the special name missing the leading '/',
572 * the file system name with or without the leading '/'.
574 if ((dt
= fstabsearch(disk
)) != NULL
) {
575 /* if found then only one parameter (i.e. partition)
578 (void)fprintf(stderr
, "Unknown arguments to dump:");
580 (void)fprintf(stderr
, " %s", *argv
++);
581 (void)fprintf(stderr
, "\n");
582 msg("The ENTIRE dump is aborted.\n");
585 disk
= rawname(dt
->mnt_fsname
);
586 (void)strncpy(spcl
.c_dev
, dt
->mnt_fsname
, NAMELEN
);
587 (void)strncpy(spcl
.c_filesys
, dt
->mnt_dir
, NAMELEN
);
591 if (realpath(disk
, pathname
) == NULL
)
593 strcpy(pathname
, disk
);
595 * The argument could be now a mountpoint of
596 * a filesystem specified in fstab. Search for it.
598 if ((dt
= fstabsearch(pathname
)) != NULL
) {
599 disk
= rawname(dt
->mnt_fsname
);
600 (void)strncpy(spcl
.c_dev
, dt
->mnt_fsname
, NAMELEN
);
601 (void)strncpy(spcl
.c_filesys
, dt
->mnt_dir
, NAMELEN
);
604 * The argument was not found in the fstab
605 * assume that this is a subtree and search for it
607 dt
= fstabsearchdir(pathname
, directory
);
609 char name
[MAXPATHLEN
];
610 (void)strncpy(spcl
.c_dev
, dt
->mnt_fsname
, NAMELEN
);
611 (void)snprintf(name
, sizeof(name
), "%s (dir %s)",
612 dt
->mnt_dir
, directory
);
613 (void)strncpy(spcl
.c_filesys
, name
, NAMELEN
);
614 disk
= rawname(dt
->mnt_fsname
);
616 (void)strncpy(spcl
.c_dev
, disk
, NAMELEN
);
617 (void)strncpy(spcl
.c_filesys
, "an unlisted file system",
622 (void)strncpy(spcl
.c_dev
, disk
, NAMELEN
);
623 (void)strncpy(spcl
.c_filesys
, "an unlisted file system",
628 if (directory
[0] != 0) {
630 msg("Only level 0 dumps are allowed on a subdirectory\n");
631 msg("The ENTIRE dump is aborted.\n");
635 msg("You can't update the dumpdates file when dumping a subdirectory\n");
636 msg("The ENTIRE dump is aborted.\n");
640 spcl
.c_dev
[NAMELEN
-1] = '\0';
641 spcl
.c_filesys
[NAMELEN
-1] = '\0';
642 (void)gethostname(spcl
.c_host
, NAMELEN
);
643 spcl
.c_host
[NAMELEN
-1] = '\0';
644 spcl
.c_level
= level
- '0';
645 spcl
.c_type
= TS_TAPE
;
647 getdumptime(uflag
); /* dumpdates snarfed */
649 if (spcl
.c_ddate
== 0 && spcl
.c_level
) {
650 msg("WARNING: There is no inferior level dump on this filesystem\n");
651 msg("WARNING: Assuming a level 0 dump by default\n");
657 snprintf(tape
, MAXPATHLEN
, "%s%03d", tapeprefix
, tapeno
+ 1);
659 strncpy(tape
, tapeprefix
, MAXPATHLEN
);
660 tape
[MAXPATHLEN
- 1] = '\0';
663 if (STAT(tape
, &statbuf
) != -1)
664 fifoout
= statbuf
.st_mode
& S_IFIFO
;
669 msg("Date of this level %c dump: %s", level
,
670 ctime4(&spcl
.c_date
));
672 gThisDumpDate
= spcl
.c_date
;
675 msg("Date of last level %c dump: %s", lastlevel
,
676 ctime4(&spcl
.c_ddate
));
677 msg("Dumping %s (%s) ", disk
, spcl
.c_filesys
);
679 msgtail("to %s on host %s\n", tape
, host
);
681 msgtail("to %s\n", tape
);
682 } /* end of size estimate */
685 if ((diskfd
= OPEN(disk
, O_RDONLY
)) < 0) {
686 msg("Cannot open %s\n", disk
);
687 msg("The ENTIRE dump is aborted.\n");
691 (void)ioctl(diskfd
, BLKFLSBUF
);
693 retval
= dump_fs_open(disk
, &fs
);
695 com_err(disk
, retval
, "while opening filesystem");
696 if (retval
== EXT2_ET_REV_TOO_HIGH
)
697 msg("Get a newer version of dump!\n");
698 msg("The ENTIRE dump is aborted.\n");
701 if (fs
->super
->s_rev_level
> DUMP_CURRENT_REV
) {
702 com_err(disk
, retval
, "while opening filesystem");
703 msg("Get a newer version of dump!\n");
704 msg("The ENTIRE dump is aborted.\n");
707 /* if no user label specified, use ext2 filesystem label if available */
708 if (spcl
.c_label
[0] == '\0') {
710 if ( (lbl
= get_device_label(disk
)) != NULL
) {
711 strncpy(spcl
.c_label
, lbl
, LBLSIZE
);
712 spcl
.c_label
[LBLSIZE
-1] = '\0';
715 strcpy(spcl
.c_label
, "none"); /* safe strcpy. */
718 dev_bsize
= DEV_BSIZE
;
719 dev_bshift
= ffs(dev_bsize
) - 1;
720 if (dev_bsize
!= (1 << dev_bshift
))
721 quit("dev_bsize (%d) is not a power of 2", dev_bsize
);
722 tp_bshift
= ffs(TP_BSIZE
) - 1;
723 if (TP_BSIZE
!= (1 << tp_bshift
))
724 quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE
);
725 maxino
= fs
->super
->s_inodes_count
+ 1;
726 spcl
.c_flags
|= DR_NEWINODEFMT
;
727 #else /* __linux __*/
728 if ((diskfd
= open(disk
, O_RDONLY
)) < 0) {
729 msg("Cannot open %s\n", disk
);
730 msg("The ENTIRE dump is aborted.\n");
734 sblock
= (struct fs
*)sblock_buf
;
735 bread(SBOFF
, (char *) sblock
, SBSIZE
);
736 if (sblock
->fs_magic
!= FS_MAGIC
)
737 quit("bad sblock magic number\n");
738 dev_bsize
= sblock
->fs_fsize
/ fsbtodb(sblock
, 1);
739 dev_bshift
= ffs(dev_bsize
) - 1;
740 if (dev_bsize
!= (1 << dev_bshift
))
741 quit("dev_bsize (%d) is not a power of 2", dev_bsize
);
742 tp_bshift
= ffs(TP_BSIZE
) - 1;
743 if (TP_BSIZE
!= (1 << tp_bshift
))
744 quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE
);
746 if (sblock
->fs_inodefmt
>= FS_44INODEFMT
)
747 spcl
.c_flags
|= DR_NEWINODEFMT
;
749 maxino
= sblock
->fs_ipg
* sblock
->fs_ncg
;
750 #endif /* __linux__ */
751 mapsize
= roundup(howmany(maxino
, NBBY
), TP_BSIZE
);
752 usedinomap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
753 dumpdirmap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
754 dumpinomap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
755 metainomap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
756 if (usedinomap
== NULL
|| dumpdirmap
== NULL
||
757 dumpinomap
== NULL
|| metainomap
== NULL
)
758 quit("out of memory allocating inode maps\n");
759 tapesize
= 2 * (howmany(mapsize
* sizeof(char), TP_BSIZE
) + 1);
761 nonodump
= spcl
.c_level
< honorlevel
;
764 msg("Label: %s\n", spcl
.c_label
);
766 msg("Writing %d Kilobyte records\n", ntrec
);
769 if (zipflag
== COMPRESS_LZO
)
770 msg("Compressing output (lzo)\n");
772 msg("Compressing output at compression level %d (%s)\n",
773 compressed
, zipflag
== COMPRESS_ZLIB
? "zlib" : "bzlib");
778 (void)signal(SIGINFO
, statussig
);
782 msg("mapping (Pass I) [regular files]\n");
784 if (directory
[0] == 0)
785 anydirskipped
= mapfiles(maxino
, &tapesize
);
787 if (LSTAT(pathname
, &statbuf
) == -1) {
788 msg("File cannot be accessed (%s).\n", pathname
);
789 msg("The ENTIRE dump is aborted.\n");
792 filedev
= statbuf
.st_dev
;
793 if (!(statbuf
.st_mode
& S_IFDIR
)) /* is a file */
794 anydirskipped
= maponefile(maxino
, &tapesize
,
797 anydirskipped
= mapfilesfromdir(maxino
, &tapesize
,
803 /* check if file is available */
804 if (LSTAT(p
, &statbuf
) == -1) {
805 msg("File cannot be accessed (%s).\n", p
);
806 msg("The ENTIRE dump is aborted.\n");
809 /* check if file is on same unix partiton as the first
811 if (statbuf
.st_dev
!= filedev
) {
812 msg("Files are not on same file system (%s).\n", p
);
813 msg("The ENTIRE dump is aborted.\n");
816 /* check if file is a directory */
817 if (!(statbuf
.st_mode
& S_IFDIR
))
818 anydirskipped2
= maponefile(maxino
, &tapesize
,
819 p
+strlen(dt
->mnt_dir
));
821 /* read directory inodes.
822 * NOTE: nested directories are not recognized
823 * so inodes may be umped twice!
825 anydirskipped2
= mapfilesfromdir(maxino
, &tapesize
,
826 p
+strlen(dt
->mnt_dir
));
828 anydirskipped
= anydirskipped2
;
832 anydirskipped
= mapfiles(maxino
, &tapesize
);
836 msg("mapping (Pass II) [directories]\n");
837 while (anydirskipped
) {
838 anydirskipped
= mapdirs(maxino
, &tapesize
);
842 printf("%.0f\n", ((double)tapesize
+ 1 + ntrec
) * TP_BSIZE
);
844 } /* stop here for size estimate */
846 if (pipeout
|| unlimited
) {
847 tapesize
+= 1 + ntrec
; /* 1 map header + trailer blocks */
848 msg("estimated %ld blocks.\n", tapesize
);
853 fetapes
= (double) tapesize
/ blocksperfile
;
854 else if (cartridge
) {
855 /* Estimate number of tapes, assuming streaming stops at
856 the end of each block written, and not in mid-block.
857 Assume no erroneous blocks; this can be compensated
858 for with an artificially low tape size. */
860 ( (double) tapesize
/* blocks */
861 * TP_BSIZE
/* bytes/block */
862 * (1.0/density
) /* 0.1" / byte " */
864 (double) tapesize
/* blocks */
865 * (1.0/ntrec
) /* streaming-stops per block */
866 * 15.48 /* 0.1" / streaming-stop " */
867 ) * (1.0 / tsize
); /* tape / 0.1" " */
869 /* Estimate number of tapes, for old fashioned 9-track
871 int tenthsperirg
= (density
== 625) ? 3 : 7;
873 ( (double) tapesize
/* blocks */
874 * TP_BSIZE
/* bytes / block */
875 * (1.0/density
) /* 0.1" / byte " */
877 (double) tapesize
/* blocks */
878 * (1.0/ntrec
) /* IRG's / block */
879 * tenthsperirg
/* 0.1" / IRG " */
880 ) * (1.0 / tsize
); /* tape / 0.1" " */
882 etapes
= fetapes
; /* truncating assignment */
884 /* count the dumped inodes map on each additional tape */
885 tapesize
+= (etapes
- 1) *
886 (howmany(mapsize
* sizeof(char), TP_BSIZE
) + 1);
887 tapesize
+= etapes
+ ntrec
; /* headers + trailer blks */
888 msg("estimated %ld blocks on %3.2f tape(s).\n",
894 msg("writing QFA positions to %s\n", gTapeposfile
);
895 if ((gTapeposfd
= open(gTapeposfile
,
896 O_WRONLY
|O_CREAT
|O_TRUNC
,
897 S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
898 | S_IROTH
| S_IWOTH
)) < 0)
899 quit("can't open tapeposfile\n");
900 /* print QFA-file header */
901 snprintf(gTps
, sizeof(gTps
), "%s\n%s\n%ld\n\n", QFA_MAGIC
, QFA_VERSION
, (unsigned long)spcl
.c_date
);
902 gTps
[sizeof(gTps
) - 1] = '\0';
903 if (write(gTapeposfd
, gTps
, strlen(gTps
)) != (ssize_t
)strlen(gTps
))
904 quit("can't write tapeposfile\n");
905 sprintf(gTps
, "ino\ttapeno\ttapepos\n");
906 if (write(gTapeposfd
, gTps
, strlen(gTps
)) != (ssize_t
)strlen(gTps
))
907 quit("can't write tapeposfile\n");
912 * Allocate tape buffer.
916 "can't allocate tape buffers - try a smaller blocking factor.\n");
919 tstart_writing
= time(NULL
);
920 dumpmap(usedinomap
, TS_CLRI
, maxino
- 1);
922 msg("dumping (Pass III) [directories]\n");
923 dirty
= 0; /* XXX just to get gcc to shut up */
924 for (map
= dumpdirmap
, ino
= 1; ino
< maxino
; ino
++) {
925 if (((ino
- 1) % NBBY
) == 0) /* map is offset by 1 */
929 if ((dirty
& 1) == 0)
932 * Skip directory inodes deleted and maybe reallocated
935 if ((dp
->di_mode
& IFMT
) != IFDIR
)
939 * Skip directory inodes deleted and not yes reallocated...
941 if (dp
->di_nlink
== 0 || dp
->di_dtime
!= 0)
944 msg("dumping directory inode %lu\n", ino
);
945 (void)dumpdirino(dp
, ino
);
947 (void)dumpino(dp
, ino
);
951 msg("dumping (Pass IV) [regular files]\n");
952 for (map
= dumpinomap
, ino
= 1; ino
< maxino
; ino
++) {
953 if (((ino
- 1) % NBBY
) == 0) /* map is offset by 1 */
957 if ((dirty
& 1) == 0)
960 * Skip inodes deleted and reallocated as directories.
963 if ((dp
->di_mode
& IFMT
) == IFDIR
)
967 * No need to check here for deleted and not yet reallocated
968 * inodes since this is done in dumpino().
972 if (mflag
&& TSTINO(ino
, metainomap
))
973 msg("dumping regular inode %lu (meta only)\n", ino
);
975 msg("dumping regular inode %lu\n", ino
);
977 (void)dumpino(dp
, ino
, mflag
&& TSTINO(ino
, metainomap
));
980 tend_writing
= time(NULL
);
981 spcl
.c_type
= TS_END
;
984 volinfo
[1] = ROOTINO
;
985 memcpy(spcl
.c_inos
, volinfo
, TP_NINOS
* sizeof(dump_ino_t
));
986 spcl
.c_flags
|= DR_INODEINFO
;
990 * Finish off the current tape record with trailer blocks, to ensure
991 * at least the data in the last partial record makes it to tape.
992 * Also make sure we write at least 1 trailer block.
994 for (i
= ntrec
- (spcl
.c_tapea
% ntrec
); i
; --i
)
995 writeheader(maxino
- 1);
999 if (pipeout
|| fifoout
)
1000 msg("%ld blocks (%.2fMB)\n", spcl
.c_tapea
,
1001 ((double)spcl
.c_tapea
* TP_BSIZE
/ 1048576));
1003 msg("%ld blocks (%.2fMB) on %d volume(s)\n",
1005 ((double)spcl
.c_tapea
* TP_BSIZE
/ 1048576),
1008 /* report dump performance, avoid division by zero */
1009 if (tend_writing
- tstart_writing
== 0)
1010 msg("finished in less than a second\n");
1012 msg("finished in %d seconds, throughput %d kBytes/sec\n",
1013 tend_writing
- tstart_writing
,
1014 spcl
.c_tapea
/ (tend_writing
- tstart_writing
));
1017 msg("Date of this level %c dump: %s", level
,
1018 spcl
.c_date
== 0 ? "the epoch\n" : ctime4(&spcl
.c_date
));
1019 msg("Date this dump completed: %s", ctime(&tnow
));
1021 msg("Average transfer rate: %ld kB/s\n", xferrate
/ tapeno
);
1023 long tapekb
= bytes_written
/ 1024;
1024 double rate
= .0005 + (double) spcl
.c_tapea
/ tapekb
;
1025 msg("Wrote %ldkB uncompressed, %ldkB compressed, %1.3f:1\n",
1026 spcl
.c_tapea
, tapekb
, rate
);
1030 msg("Archiving dump to %s\n", Apath
);
1032 broadcast("DUMP IS DONE!\7\7\n");
1033 msg("DUMP IS DONE\n");
1036 return 0; /* gcc - shut up */
1042 char white
[MAXPATHLEN
];
1043 const char *ext2ver
, *ext2date
;
1045 memset(white
, ' ', MAXPATHLEN
);
1046 white
[MIN(strlen(__progname
), MAXPATHLEN
- 1)] = '\0';
1049 ext2fs_get_library_version(&ext2ver
, &ext2date
);
1050 fprintf(stderr
, "%s %s (using libext2fs %s of %s)\n",
1051 __progname
, _DUMP_VERSION
, ext2ver
, ext2date
);
1053 fprintf(stderr
, "%s %s\n", __progname
, _DUMP_VERSION
);
1056 "usage:\t%s [-0123456789ac"
1061 "] [-A file] [-B records] [-b blocksize]\n"
1062 "\t%s [-d density] [-D file] [-e inode#,inode#,...] [-E file]\n"
1063 "\t%s [-f file] [-h level] [-I nr errors] "
1080 __progname
, white
, white
, white
, __progname
);
1085 * Pick up a numeric argument. It must be nonnegative and in the given
1086 * range (except that a vmax of 0 means unlimited).
1089 numarg(const char *meaning
, long vmin
, long vmax
)
1094 val
= strtol(optarg
, &p
, 10);
1096 errx(X_STARTUP
, "illegal %s -- %s", meaning
, optarg
);
1097 if (val
< vmin
|| (vmax
&& val
> vmax
))
1098 errx(X_STARTUP
, "%s must be between %ld and %ld", meaning
, vmin
, vmax
);
1112 if (pipeout
|| fifoout
)
1113 quit("Signal on pipe: cannot recover\n");
1114 msg("Rewriting attempted as response to unknown signal: %d.\n", signo
);
1115 (void)fflush(stderr
);
1116 (void)fflush(stdout
);
1121 msg("SIGSEGV: ABORTING!\n");
1122 (void)signal(SIGSEGV
, SIG_DFL
);
1123 (void)kill(0, SIGSEGV
);
1129 rawname(const char *cp
)
1133 #else /* __linux__ */
1134 static char rawbuf
[MAXPATHLEN
];
1135 char *dp
= strrchr(cp
, '/');
1139 (void)strncpy(rawbuf
, cp
, min(dp
-cp
, MAXPATHLEN
- 1));
1140 rawbuf
[min(dp
-cp
, MAXPATHLEN
-1)] = '\0';
1141 (void)strncat(rawbuf
, "/r", MAXPATHLEN
- 1 - strlen(rawbuf
));
1142 (void)strncat(rawbuf
, dp
+ 1, MAXPATHLEN
- 1 - strlen(rawbuf
));
1144 #endif /* __linux__ */
1149 * Change set of key letters and ordered arguments into something
1150 * getopt(3) will like.
1153 obsolete(int *argcp
, char **argvp
[])
1156 char *ap
, **argv
, *flagsp
=NULL
, **nargv
, *p
=NULL
;
1162 /* Return if no arguments or first argument has leading dash. */
1164 if (argc
== 1 || *ap
== '-')
1167 /* Allocate space for new arguments. */
1168 if ((*argvp
= nargv
= malloc((argc
+ 1) * sizeof(char *))) == NULL
||
1169 (p
= flagsp
= malloc(strlen(ap
) + 2)) == NULL
)
1170 err(X_STARTUP
, "malloc new args");
1175 for (flags
= 0; *ap
; ++ap
) {
1191 if (*argv
== NULL
) {
1192 warnx("option requires an argument -- %c", *ap
);
1195 if ((nargv
[0] = malloc(strlen(*argv
) + 2 + 1)) == NULL
)
1196 err(X_STARTUP
, "malloc arg");
1199 (void)strcpy(&nargv
[0][2], *argv
);
1213 /* Terminate flags. */
1219 /* Copy remaining arguments. */
1220 while ((*nargv
++ = *argv
++));
1222 /* Update argument count. */
1223 *argcp
= nargv
- *argvp
- 1;
1227 * This tests whether an inode is in the exclude list
1230 exclude_ino(dump_ino_t ino
)
1233 if (iexclude_num
) { /* if there are inodes in the exclude list */
1234 int idx
; /* then check this inode against it */
1235 for (idx
= 0; idx
< iexclude_num
; idx
++)
1236 if (ino
== iexclude_list
[idx
])
1243 * This tests adds an inode to the exclusion list if it isn't already there
1246 do_exclude_ino(dump_ino_t ino
, const char *reason
)
1248 if (!exclude_ino(ino
)) {
1249 if (iexclude_num
== IEXCLUDE_MAXNUM
) {
1250 msg("Too many exclude options\n");
1251 msg("The ENTIRE dump is aborted.\n");
1255 msg("Excluding inode %u (%s) from dump\n",
1258 msg("Excluding inode %u from dump\n", ino
);
1259 iexclude_list
[iexclude_num
++] = ino
;
1264 do_exclude_ino_str(char * ino
) {
1268 inod
= strtoul(ino
, &r
, 10);
1269 if (( *r
!= '\0' && !isspace(*r
) ) || inod
<= ROOTINO
) {
1270 msg("Invalid inode argument %s\n", ino
);
1271 msg("The ENTIRE dump is aborted.\n");
1274 do_exclude_ino(inod
, NULL
);
1278 * This reads a file containing one inode number per line and exclude them all
1281 do_exclude_from_file(char *file
) {
1283 char *p
, fname
[MAXPATHLEN
];
1286 if (!( f
= fopen(file
, "r")) ) {
1287 msg("Cannot open file for reading: %s\n", file
);
1288 msg("The ENTIRE dump is aborted.\n");
1291 while (( p
= fgets(fname
, MAXPATHLEN
, f
))) {
1292 if ( *p
&& *(p
+ strlen(p
) - 1) == '\n' ) /* possible null string */
1293 *(p
+ strlen(p
) - 1) = '\0';
1294 if ( !*p
) /* skip empty lines */
1296 do_exclude_ino_str(p
);
1301 static void incompat_flags(int cond
, char flag1
, char flag2
) {
1303 msg("You cannot use the %c and %c flags together.\n",
1305 msg("The ENTIRE dump is aborted.\n");