]>
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 <pop@noos.fr>, 1999-2000
6 * Stelian Pop <pop@noos.fr> - AlcĂ´ve <www.alcove.fr>, 2000
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.56 2001/08/13 16:17:52 stelian Exp $";
48 #include <compatlfs.h>
50 #include <compaterr.h>
59 #include <sys/param.h>
63 #ifdef HAVE_EXT2FS_EXT2_FS_H
64 #include <ext2fs/ext2_fs.h>
66 #include <linux/ext2_fs.h>
68 #include <ext2fs/ext2fs.h>
70 #include <bsdcompat.h>
72 #include <sys/vnode.h>
74 #include <ufs/inode.h>
77 #include <ufs/ufs/dinode.h>
78 #include <ufs/ffs/fs.h>
81 #include <protocols/dumprestore.h>
84 #include "pathnames.h"
88 #define SBOFF (SBLOCK * DEV_BSIZE)
92 * Dump maps used to describe what is to be dumped.
94 int mapsize
; /* size of the state maps */
95 char *usedinomap
; /* map of allocated inodes */
96 char *dumpdirmap
; /* map of directories to be dumped */
97 char *dumpinomap
; /* map of files to be dumped */
99 const char *disk
; /* name of the disk file */
100 char tape
[MAXPATHLEN
];/* name of the tape file */
101 char *tapeprefix
; /* prefix of the tape file */
102 char *dumpdates
; /* name of the file containing dump date information*/
103 char lastlevel
; /* dump level of previous dump */
104 char level
; /* dump level of this dump */
105 int uflag
; /* update flag */
106 int Mflag
; /* multi-volume flag */
107 char *eot_script
; /* end of volume script fiag */
108 int diskfd
; /* disk file descriptor */
109 int tapefd
; /* tape file descriptor */
110 int pipeout
; /* true => output to standard output */
111 int fifoout
; /* true => output to fifo */
112 dump_ino_t curino
; /* current inumber; used globally */
113 int newtape
; /* new tape flag */
114 int density
; /* density in 0.1" units */
115 long tapesize
; /* estimated tape size, blocks */
116 long tsize
; /* tape size in 0.1" units */
117 long asize
; /* number of 0.1" units written on current tape */
118 int etapes
; /* estimated number of tapes */
119 int nonodump
; /* if set, do not honor UF_NODUMP user flags */
120 int unlimited
; /* if set, write to end of medium */
121 int compressed
; /* if set, dump is to be compressed */
122 long long bytes_written
;/* total bytes written to tape */
123 long uncomprblks
; /* uncompressed blocks written to tape */
124 int notify
; /* notify operator flag */
125 int blockswritten
; /* number of blocks written on current tape */
126 int tapeno
; /* current tape number */
127 time_t tstart_writing
; /* when started writing the first tape block */
128 time_t tend_writing
; /* after writing the last tape block */
132 struct fs
*sblock
; /* the file system super block */
133 char sblock_buf
[MAXBSIZE
];
135 long xferrate
; /* averaged transfer rate of all volumes */
136 long dev_bsize
; /* block size of underlying disk device */
137 int dev_bshift
; /* log2(dev_bsize) */
138 int tp_bshift
; /* log2(TP_BSIZE) */
144 int32_t gThisDumpDate
;
147 struct dumptime
*dthead
; /* head of the list version */
148 int nddates
; /* number of records (might be zero) */
149 int ddates_in
; /* we have read the increment file */
150 struct dumpdates
**ddatev
; /* the arrayfied version */
152 int notify
= 0; /* notify operator flag */
153 int blockswritten
= 0; /* number of blocks written on current tape */
154 int tapeno
= 0; /* current tape number */
155 int density
= 0; /* density in bytes/0.1" " <- this is for hilit19 */
156 int ntrec
= NTREC
; /* # tape blocks in each tape record */
157 int cartridge
= 0; /* Assume non-cartridge tape */
159 int tapepos
= 0; /* assume no QFA tapeposition needed by user */
161 int dokerberos
= 0; /* Use Kerberos authentication */
162 long dev_bsize
= 1; /* recalculated below */
163 long blocksperfile
; /* output blocks per file */
164 char *host
= NULL
; /* remote host (if any) */
165 int sizest
= 0; /* return size estimate only */
166 int compressed
= 0; /* use zlib to compress the output, compress level 1-9 */
167 long long bytes_written
= 0; /* total bytes written */
168 long uncomprblks
= 0;/* uncompressed blocks written */
174 int maxbsize
= 64*1024; /* XXX MAXBSIZE from sys/param.h */
175 static long numarg
__P((const char *, long, long));
176 static void obsolete
__P((int *, char **[]));
177 static void usage
__P((void));
178 static void do_exclude_from_file
__P((char *));
179 static void do_exclude_ino_str
__P((char *));
181 static dump_ino_t iexclude_list
[IEXCLUDE_MAXNUM
];/* the inode exclude list */
182 static int iexclude_num
= 0; /* number of elements in the list */
185 main(int argc
, char *argv
[])
187 register dump_ino_t ino
;
189 register struct dinode
*dp
;
190 register struct fstab
*dt
;
193 int i
, anydirskipped
, bflag
= 0, Tflag
= 0, honorlevel
= 1;
199 char directory
[MAXPATHLEN
];
200 char pathname
[MAXPATHLEN
];
205 spcl
.c_label
[0] = '\0';
206 spcl
.c_date
= time(NULL
);
209 __progname
= argv
[0];
211 initialize_ext2_error_table();
214 tsize
= 0; /* Default later, based on 'c' option for cart tapes */
217 if ((tapeprefix
= getenv("TAPE")) == NULL
)
218 tapeprefix
= _PATH_DEFTAPE
;
219 dumpdates
= _PATH_DUMPDATES
;
220 if (TP_BSIZE
/ DEV_BSIZE
== 0 || TP_BSIZE
% DEV_BSIZE
!= 0)
221 quit("TP_BSIZE must be a multiple of DEV_BSIZE\n");
227 obsolete(&argc
, &argv
);
233 while ((ch
= getopt(argc
, argv
,
234 "0123456789aB:b:cd:e:E:f:F:h:L:"
249 case '0': case '1': case '2': case '3': case '4':
250 case '5': case '6': case '7': case '8': case '9':
254 case 'a': /* `auto-size', Write to EOM. */
258 case 'B': /* blocks per output file */
260 blocksperfile
= numarg("number of blocks per file",
264 case 'b': /* blocks per tape write */
265 ntrec
= numarg("number of blocks per write",
267 if (ntrec
> maxbsize
/1024) {
268 msg("Please choose a blocksize <= %dkB\n",
270 msg("The ENTIRE dump is aborted.\n");
276 case 'c': /* Tape is cart. not 9-track */
281 case 'd': /* density, in bits per inch */
283 density
= numarg("density", 10L, 327670L) / 10;
284 if (density
>= 625 && !bflag
)
285 ntrec
= HIGHDENSITYTREC
;
289 case 'e': /* exclude an inode */
291 char *p
= optarg
, *q
;
292 while ((q
= strchr(p
, ','))) {
294 do_exclude_ino_str(p
);
297 do_exclude_ino_str(p
);
301 case 'E': /* exclude inodes read from file */
302 do_exclude_from_file(optarg
);
305 case 'f': /* output file */
309 case 'F': /* end of tape script */
314 honorlevel
= numarg("honor level", 0L, 10L);
325 * Note that although there are LBLSIZE characters,
326 * the last must be '\0', so the limit on strlen()
327 * is really LBLSIZE-1.
329 strncpy(spcl
.c_label
, optarg
, LBLSIZE
);
330 spcl
.c_label
[LBLSIZE
-1] = '\0';
331 if (strlen(optarg
) > LBLSIZE
-1) {
333 "WARNING Label `%s' is larger than limit of %d characters.\n",
335 msg("WARNING: Using truncated label `%s'.\n",
340 case 'M': /* multi-volume flag */
344 case 'n': /* notify operators */
349 case 'Q': /* create tapeposfile */
350 gTapeposfile
= optarg
;
355 case 's': /* tape size, feet */
357 tsize
= numarg("tape size", 1L, 0L) * 12 * 10;
361 sizest
= 1; /* return size estimate only */
364 case 'T': /* time of last dump */
365 spcl
.c_ddate
= unctime(optarg
);
366 if (spcl
.c_ddate
< 0) {
367 msg("bad time \"%s\"\n", optarg
);
368 msg("The ENTIRE dump is aborted.\n");
375 case 'u': /* update dumpdates */
379 case 'W': /* what to do */
382 exit(X_FINOK
); /* do nothing else */
387 compressed
= numarg("compress level", 1L, 9L);
389 #endif /* HAVE_ZLIB */
398 msg("Must specify disk or filesystem\n");
399 msg("The ENTIRE dump is aborted.\n");
403 if (strlen(diskparam
) >= MAXPATHLEN
) {
404 msg("Disk or filesystem name too long: %s\n", diskparam
);
405 msg("The ENTIRE dump is aborted.\n");
409 if (Tflag
&& uflag
) {
410 msg("You cannot use the T and u flags together.\n");
411 msg("The ENTIRE dump is aborted.\n");
414 if (strcmp(tapeprefix
, "-") == 0) {
416 tapeprefix
= "standard output";
419 if (blocksperfile
&& !compressed
)
420 blocksperfile
= blocksperfile
/ ntrec
* ntrec
; /* round down */
421 else if (!unlimited
) {
423 * Determine how to default tape size and density
426 * 9-track 1600 bpi (160 bytes/.1") 2300 ft.
427 * 9-track 6250 bpi (625 bytes/.1") 2300 ft.
428 * cartridge 8000 bpi (100 bytes/.1") 1700 ft.
430 * hilit19 hits again: "
433 density
= cartridge
? 100 : 160;
435 tsize
= cartridge
? 1700L*120L : 2300L*120L;
438 if (strchr(tapeprefix
, ':')) {
440 tapeprefix
= strchr(host
, ':');
441 *tapeprefix
++ = '\0';
443 if (index(tapeprefix
, '\n')) {
444 msg("invalid characters in tape\n");
445 msg("The ENTIRE dump is aborted.\n");
448 if (rmthost(host
) == 0)
451 msg("remote dump not enabled\n");
452 msg("The ENTIRE dump is aborted.\n");
456 (void)setuid(getuid()); /* rmthost() is the only reason to be setuid */
458 if (signal(SIGHUP
, SIG_IGN
) != SIG_IGN
)
460 if (signal(SIGTRAP
, SIG_IGN
) != SIG_IGN
)
461 signal(SIGTRAP
, sig
);
462 if (signal(SIGFPE
, SIG_IGN
) != SIG_IGN
)
464 if (signal(SIGBUS
, SIG_IGN
) != SIG_IGN
)
466 if (signal(SIGSEGV
, SIG_IGN
) != SIG_IGN
)
467 signal(SIGSEGV
, sig
);
468 if (signal(SIGTERM
, SIG_IGN
) != SIG_IGN
)
469 signal(SIGTERM
, sig
);
470 if (signal(SIGINT
, interrupt
) == SIG_IGN
)
471 signal(SIGINT
, SIG_IGN
);
472 set_operators(); /* /etc/group snarfed */
473 getfstab(); /* /etc/fstab snarfed */
476 * disk may end in / and this can confuse
479 i
= strlen(diskparam
) - 1;
480 if (i
> 1 && diskparam
[i
] == '/')
483 disk
= get_device_name(diskparam
);
484 if (!disk
) { /* null means the disk is some form
485 of LABEL= or UID= but it was not
487 msg("Cannot find a disk having %s\n", diskparam
);
488 msg("The ENTIRE dump is aborted.\n");
492 * disk can be either the full special file name,
493 * the suffix of the special file name,
494 * the special name missing the leading '/',
495 * the file system name with or without the leading '/'.
497 if ((dt
= fstabsearch(disk
)) != NULL
) {
498 /* if found then only one parameter (i.e. partition)
501 (void)fprintf(stderr
, "Unknown arguments to dump:");
503 (void)fprintf(stderr
, " %s", *argv
++);
504 (void)fprintf(stderr
, "\n");
505 msg("The ENTIRE dump is aborted.\n");
508 disk
= rawname(dt
->fs_spec
);
509 (void)strncpy(spcl
.c_dev
, dt
->fs_spec
, NAMELEN
);
510 (void)strncpy(spcl
.c_filesys
, dt
->fs_file
, NAMELEN
);
514 if (realpath(disk
, pathname
) == NULL
)
516 strcpy(pathname
, disk
);
518 * The argument could be now a mountpoint of
519 * a filesystem specified in fstab. Search for it.
521 if ((dt
= fstabsearch(pathname
)) != NULL
) {
522 disk
= rawname(dt
->fs_spec
);
523 (void)strncpy(spcl
.c_dev
, dt
->fs_spec
, NAMELEN
);
524 (void)strncpy(spcl
.c_filesys
, dt
->fs_file
, NAMELEN
);
527 * The argument was not found in the fstab
528 * assume that this is a subtree and search for it
530 dt
= fstabsearchdir(pathname
, directory
);
532 char name
[MAXPATHLEN
];
533 (void)strncpy(spcl
.c_dev
, dt
->fs_spec
, NAMELEN
);
534 (void)snprintf(name
, sizeof(name
), "%s (dir %s)",
535 dt
->fs_file
, directory
);
536 (void)strncpy(spcl
.c_filesys
, name
, NAMELEN
);
537 disk
= rawname(dt
->fs_spec
);
539 (void)strncpy(spcl
.c_dev
, disk
, NAMELEN
);
540 (void)strncpy(spcl
.c_filesys
, "an unlisted file system",
545 (void)strncpy(spcl
.c_dev
, disk
, NAMELEN
);
546 (void)strncpy(spcl
.c_filesys
, "an unlisted file system",
551 if (directory
[0] != 0) {
553 msg("Only level 0 dumps are allowed on a subdirectory\n");
554 msg("The ENTIRE dump is aborted.\n");
558 msg("You can't update the dumpdates file when dumping a subdirectory\n");
559 msg("The ENTIRE dump is aborted.\n");
563 spcl
.c_dev
[NAMELEN
-1] = '\0';
564 spcl
.c_filesys
[NAMELEN
-1] = '\0';
565 (void)gethostname(spcl
.c_host
, NAMELEN
);
566 spcl
.c_host
[NAMELEN
-1] = '\0';
567 spcl
.c_level
= level
- '0';
568 spcl
.c_type
= TS_TAPE
;
570 getdumptime(uflag
); /* dumpdates snarfed */
572 if (spcl
.c_ddate
== 0 && spcl
.c_level
) {
573 msg("WARNING: There is no inferior level dump on this filesystem\n");
574 msg("WARNING: Assuming a level 0 dump by default\n");
580 snprintf(tape
, MAXPATHLEN
, "%s%03d", tapeprefix
, tapeno
+ 1);
582 strncpy(tape
, tapeprefix
, MAXPATHLEN
);
583 tape
[MAXPATHLEN
- 1] = '\0';
586 if (STAT(tape
, &statbuf
) != -1)
587 fifoout
= statbuf
.st_mode
& S_IFIFO
;
592 msg("Date of this level %c dump: %s", level
,
593 ctime4(&spcl
.c_date
));
595 gThisDumpDate
= spcl
.c_date
;
598 msg("Date of last level %c dump: %s", lastlevel
,
599 ctime4(&spcl
.c_ddate
));
600 msg("Dumping %s (%s) ", disk
, spcl
.c_filesys
);
602 msgtail("to %s on host %s\n", tape
, host
);
604 msgtail("to %s\n", tape
);
605 } /* end of size estimate */
608 retval
= dump_fs_open(disk
, &fs
);
610 com_err(disk
, retval
, "while opening filesystem");
611 if (retval
== EXT2_ET_REV_TOO_HIGH
)
612 msg("Get a newer version of dump!\n");
613 msg("The ENTIRE dump is aborted.\n");
616 if (fs
->super
->s_rev_level
> DUMP_CURRENT_REV
) {
617 com_err(disk
, retval
, "while opening filesystem");
618 msg("Get a newer version of dump!\n");
619 msg("The ENTIRE dump is aborted.\n");
622 if ((diskfd
= OPEN(disk
, O_RDONLY
)) < 0) {
623 msg("Cannot open %s\n", disk
);
624 msg("The ENTIRE dump is aborted.\n");
627 /* if no user label specified, use ext2 filesystem label if available */
628 if (spcl
.c_label
[0] == '\0') {
630 if ( (lbl
= get_device_label(disk
)) != NULL
) {
631 strncpy(spcl
.c_label
, lbl
, LBLSIZE
);
632 spcl
.c_label
[LBLSIZE
-1] = '\0';
635 strcpy(spcl
.c_label
, "none"); /* safe strcpy. */
638 dev_bsize
= DEV_BSIZE
;
639 dev_bshift
= ffs(dev_bsize
) - 1;
640 if (dev_bsize
!= (1 << dev_bshift
))
641 quit("dev_bsize (%d) is not a power of 2", dev_bsize
);
642 tp_bshift
= ffs(TP_BSIZE
) - 1;
643 if (TP_BSIZE
!= (1 << tp_bshift
))
644 quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE
);
645 maxino
= fs
->super
->s_inodes_count
;
647 spcl
.c_flags
|= DR_NEWINODEFMT
;
649 #else /* __linux __*/
650 if ((diskfd
= open(disk
, O_RDONLY
)) < 0) {
651 msg("Cannot open %s\n", disk
);
652 msg("The ENTIRE dump is aborted.\n");
656 sblock
= (struct fs
*)sblock_buf
;
657 bread(SBOFF
, (char *) sblock
, SBSIZE
);
658 if (sblock
->fs_magic
!= FS_MAGIC
)
659 quit("bad sblock magic number\n");
660 dev_bsize
= sblock
->fs_fsize
/ fsbtodb(sblock
, 1);
661 dev_bshift
= ffs(dev_bsize
) - 1;
662 if (dev_bsize
!= (1 << dev_bshift
))
663 quit("dev_bsize (%d) is not a power of 2", dev_bsize
);
664 tp_bshift
= ffs(TP_BSIZE
) - 1;
665 if (TP_BSIZE
!= (1 << tp_bshift
))
666 quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE
);
668 if (sblock
->fs_inodefmt
>= FS_44INODEFMT
)
669 spcl
.c_flags
|= DR_NEWINODEFMT
;
671 maxino
= sblock
->fs_ipg
* sblock
->fs_ncg
;
672 #endif /* __linux__ */
673 mapsize
= roundup(howmany(maxino
, NBBY
), TP_BSIZE
);
674 usedinomap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
675 dumpdirmap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
676 dumpinomap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
677 if (usedinomap
== NULL
|| dumpdirmap
== NULL
|| dumpinomap
== NULL
)
678 quit("out of memory allocating inode maps\n");
679 tapesize
= 2 * (howmany(mapsize
* sizeof(char), TP_BSIZE
) + 1);
681 nonodump
= spcl
.c_level
< honorlevel
;
684 msg("Label: %s\n", spcl
.c_label
);
687 msg("Compressing output at compression level %d\n",
692 (void)signal(SIGINFO
, statussig
);
696 msg("mapping (Pass I) [regular files]\n");
698 if (directory
[0] == 0)
699 anydirskipped
= mapfiles(maxino
, &tapesize
);
701 if (STAT(pathname
, &statbuf
) == -1) {
702 msg("File cannot be accessed (%s).\n", pathname
);
703 msg("The ENTIRE dump is aborted.\n");
706 filedev
= statbuf
.st_dev
;
707 if (!(statbuf
.st_mode
& S_IFDIR
)) /* is a file */
708 anydirskipped
= maponefile(maxino
, &tapesize
,
711 anydirskipped
= mapfilesfromdir(maxino
, &tapesize
,
717 /* check if file is available */
718 if (STAT(p
, &statbuf
) == -1) {
719 msg("File cannot be accessed (%s).\n", p
);
720 msg("The ENTIRE dump is aborted.\n");
723 /* check if file is on same unix partiton as the first
725 if (statbuf
.st_dev
!= filedev
) {
726 msg("Files are not on same file system (%s).\n", p
);
727 msg("The ENTIRE dump is aborted.\n");
730 /* check if file is a directory */
731 if (!(statbuf
.st_mode
& S_IFDIR
))
732 anydirskipped2
= maponefile(maxino
, &tapesize
,
733 p
+strlen(dt
->fs_file
));
735 /* read directory inodes.
736 * NOTE: nested directories are not recognized
737 * so inodes may be umped twice!
739 anydirskipped2
= mapfilesfromdir(maxino
, &tapesize
,
740 p
+strlen(dt
->fs_file
));
742 anydirskipped
= anydirskipped2
;
746 anydirskipped
= mapfiles(maxino
, &tapesize
);
750 msg("mapping (Pass II) [directories]\n");
751 while (anydirskipped
) {
752 anydirskipped
= mapdirs(maxino
, &tapesize
);
756 printf("%.0f\n", ((double)tapesize
+ 1 + ntrec
) * TP_BSIZE
);
758 } /* stop here for size estimate */
760 if (pipeout
|| unlimited
) {
761 tapesize
+= 1 + ntrec
; /* 1 map header + trailer blocks */
762 msg("estimated %ld tape blocks.\n", tapesize
);
767 fetapes
= (double) tapesize
/ blocksperfile
;
768 else if (cartridge
) {
769 /* Estimate number of tapes, assuming streaming stops at
770 the end of each block written, and not in mid-block.
771 Assume no erroneous blocks; this can be compensated
772 for with an artificially low tape size. */
774 ( (double) tapesize
/* blocks */
775 * TP_BSIZE
/* bytes/block */
776 * (1.0/density
) /* 0.1" / byte " */
778 (double) tapesize
/* blocks */
779 * (1.0/ntrec
) /* streaming-stops per block */
780 * 15.48 /* 0.1" / streaming-stop " */
781 ) * (1.0 / tsize
); /* tape / 0.1" " */
783 /* Estimate number of tapes, for old fashioned 9-track
785 int tenthsperirg
= (density
== 625) ? 3 : 7;
787 ( (double) tapesize
/* blocks */
788 * TP_BSIZE
/* bytes / block */
789 * (1.0/density
) /* 0.1" / byte " */
791 (double) tapesize
/* blocks */
792 * (1.0/ntrec
) /* IRG's / block */
793 * tenthsperirg
/* 0.1" / IRG " */
794 ) * (1.0 / tsize
); /* tape / 0.1" " */
796 etapes
= fetapes
; /* truncating assignment */
798 /* count the dumped inodes map on each additional tape */
799 tapesize
+= (etapes
- 1) *
800 (howmany(mapsize
* sizeof(char), TP_BSIZE
) + 1);
801 tapesize
+= etapes
+ ntrec
; /* headers + trailer blks */
802 msg("estimated %ld tape blocks on %3.2f tape(s).\n",
808 msg("writing QFA positions to %s\n", gTapeposfile
);
809 if ((gTapeposfd
= open(gTapeposfile
, O_RDWR
|O_CREAT
, S_IRUSR
| S_IWUSR
)) < 0)
810 quit("can't open tapeposfile\n");
811 /* print QFA-file header */
812 sprintf(gTps
, "%s\n%s\n%ld\n\n", QFA_MAGIC
, QFA_VERSION
, (unsigned long)spcl
.c_date
);
813 if (write(gTapeposfd
, gTps
, strlen(gTps
)) != strlen(gTps
))
814 quit("can't write tapeposfile\n");
815 sprintf(gTps
, "ino\ttapeno\ttapepos\n");
816 if (write(gTapeposfd
, gTps
, strlen(gTps
)) != strlen(gTps
))
817 quit("can't write tapeposfile\n");
822 * Allocate tape buffer.
826 "can't allocate tape buffers - try a smaller blocking factor.\n");
829 tstart_writing
= time(NULL
);
830 dumpmap(usedinomap
, TS_CLRI
, maxino
- 1);
832 msg("dumping (Pass III) [directories]\n");
833 dirty
= 0; /* XXX just to get gcc to shut up */
834 for (map
= dumpdirmap
, ino
= 1; ino
< maxino
; ino
++) {
835 if (((ino
- 1) % NBBY
) == 0) /* map is offset by 1 */
839 if ((dirty
& 1) == 0)
842 * Skip directory inodes deleted and maybe reallocated
845 if ((dp
->di_mode
& IFMT
) != IFDIR
)
849 * Skip directory inodes deleted and not yes reallocated...
851 if (dp
->di_nlink
== 0 || dp
->di_dtime
!= 0)
853 (void)dumpdirino(dp
, ino
);
855 (void)dumpino(dp
, ino
);
859 msg("dumping (Pass IV) [regular files]\n");
860 for (map
= dumpinomap
, ino
= 1; ino
< maxino
; ino
++) {
861 if (((ino
- 1) % NBBY
) == 0) /* map is offset by 1 */
865 if ((dirty
& 1) == 0)
868 * Skip inodes deleted and reallocated as directories.
871 if ((dp
->di_mode
& IFMT
) == IFDIR
)
875 * No need to check here for deleted and not yet reallocated
876 * inodes since this is done in dumpino().
879 (void)dumpino(dp
, ino
);
882 tend_writing
= time(NULL
);
883 spcl
.c_type
= TS_END
;
885 * Finish off the current tape record with trailer blocks, to ensure
886 * at least the data in the last partial record makes it to tape.
887 * Also make sure we write at least 1 trailer block.
889 for (i
= ntrec
- (spcl
.c_tapea
% ntrec
); i
; --i
)
890 writeheader(maxino
- 1);
894 if (pipeout
|| fifoout
)
895 msg("%ld tape blocks (%.2fMB)\n", spcl
.c_tapea
,
896 ((double)spcl
.c_tapea
* TP_BSIZE
/ 1048576));
898 msg("%ld tape blocks (%.2fMB) on %d volume(s)\n",
900 ((double)spcl
.c_tapea
* TP_BSIZE
/ 1048576),
903 /* report dump performance, avoid division by zero */
904 if (tend_writing
- tstart_writing
== 0)
905 msg("finished in less than a second\n");
907 msg("finished in %d seconds, throughput %d kBytes/sec\n",
908 tend_writing
- tstart_writing
,
909 spcl
.c_tapea
/ (tend_writing
- tstart_writing
));
912 msg("Date of this level %c dump: %s", level
,
913 spcl
.c_date
== 0 ? "the epoch\n" : ctime4(&spcl
.c_date
));
914 msg("Date this dump completed: %s", ctime(&tnow
));
916 msg("Average transfer rate: %ld kB/s\n", xferrate
/ tapeno
);
918 long tapekb
= bytes_written
/ 1024;
919 double rate
= .0005 + (double) spcl
.c_tapea
/ tapekb
;
920 msg("Wrote %ldkB uncompressed, %ldkB compressed, %1.3f:1\n",
921 spcl
.c_tapea
, tapekb
, rate
);
924 broadcast("DUMP IS DONE!\7\7\n");
925 msg("DUMP IS DONE\n");
928 return 0; /* gcc - shut up */
934 char white
[MAXPATHLEN
];
935 const char *ext2ver
, *ext2date
;
937 memset(white
, ' ', MAXPATHLEN
);
938 white
[MIN(strlen(__progname
), MAXPATHLEN
- 1)] = '\0';
941 ext2fs_get_library_version(&ext2ver
, &ext2date
);
942 fprintf(stderr
, "%s %s (using libext2fs %s of %s)\n",
943 __progname
, _DUMP_VERSION
, ext2ver
, ext2date
);
945 fprintf(stderr
, "%s %s\n", __progname
, _DUMP_VERSION
);
948 "usage:\t%s [-0123456789ac"
953 "] [-B records] [-b blocksize] [-d density]\n"
954 "\t%s [-e inode#,inode#,...] [-E file] [-f file] [-h level] "
958 "\n\t%s [-s feet] [-T date] "
964 __progname
, white
, white
, __progname
);
969 * Pick up a numeric argument. It must be nonnegative and in the given
970 * range (except that a vmax of 0 means unlimited).
973 numarg(const char *meaning
, long vmin
, long vmax
)
978 val
= strtol(optarg
, &p
, 10);
980 errx(X_STARTUP
, "illegal %s -- %s", meaning
, optarg
);
981 if (val
< vmin
|| (vmax
&& val
> vmax
))
982 errx(X_STARTUP
, "%s must be between %ld and %ld", meaning
, vmin
, vmax
);
996 if (pipeout
|| fifoout
)
997 quit("Signal on pipe: cannot recover\n");
998 msg("Rewriting attempted as response to unknown signal: %d.\n", signo
);
999 (void)fflush(stderr
);
1000 (void)fflush(stdout
);
1005 msg("SIGSEGV: ABORTING!\n");
1006 (void)signal(SIGSEGV
, SIG_DFL
);
1007 (void)kill(0, SIGSEGV
);
1013 rawname(const char *cp
)
1017 #else /* __linux__ */
1018 static char rawbuf
[MAXPATHLEN
];
1019 char *dp
= strrchr(cp
, '/');
1023 (void)strncpy(rawbuf
, cp
, min(dp
-cp
, MAXPATHLEN
- 1));
1024 rawbuf
[min(dp
-cp
, MAXPATHLEN
-1)] = '\0';
1025 (void)strncat(rawbuf
, "/r", MAXPATHLEN
- 1 - strlen(rawbuf
));
1026 (void)strncat(rawbuf
, dp
+ 1, MAXPATHLEN
- 1 - strlen(rawbuf
));
1028 #endif /* __linux__ */
1033 * Change set of key letters and ordered arguments into something
1034 * getopt(3) will like.
1037 obsolete(int *argcp
, char **argvp
[])
1040 char *ap
, **argv
, *flagsp
=NULL
, **nargv
, *p
=NULL
;
1046 /* Return if no arguments or first argument has leading dash. */
1048 if (argc
== 1 || *ap
== '-')
1051 /* Allocate space for new arguments. */
1052 if ((*argvp
= nargv
= malloc((argc
+ 1) * sizeof(char *))) == NULL
||
1053 (p
= flagsp
= malloc(strlen(ap
) + 2)) == NULL
)
1054 err(X_STARTUP
, "malloc new args");
1059 for (flags
= 0; *ap
; ++ap
) {
1073 if (*argv
== NULL
) {
1074 warnx("option requires an argument -- %c", *ap
);
1077 if ((nargv
[0] = malloc(strlen(*argv
) + 2 + 1)) == NULL
)
1078 err(X_STARTUP
, "malloc arg");
1081 (void)strcpy(&nargv
[0][2], *argv
);
1095 /* Terminate flags. */
1101 /* Copy remaining arguments. */
1102 while ((*nargv
++ = *argv
++));
1104 /* Update argument count. */
1105 *argcp
= nargv
- *argvp
- 1;
1109 * This tests whether an inode is in the exclude list
1112 exclude_ino(dump_ino_t ino
)
1115 if (iexclude_num
) { /* if there are inodes in the exclude list */
1116 int idx
; /* then check this inode against it */
1117 for (idx
= 0; idx
< iexclude_num
; idx
++)
1118 if (ino
== iexclude_list
[idx
])
1125 * This tests adds an inode to the exclusion list if it isn't already there
1128 do_exclude_ino(dump_ino_t ino
, const char *reason
)
1130 if (!exclude_ino(ino
)) {
1131 if (iexclude_num
== IEXCLUDE_MAXNUM
) {
1132 msg("Too many exclude options\n");
1133 msg("The ENTIRE dump is aborted.\n");
1137 msg("Added inode %u to exclude list (%s)\n",
1140 msg("Added inode %u to exclude list\n", ino
);
1141 iexclude_list
[iexclude_num
++] = ino
;
1146 do_exclude_ino_str(char * ino
) {
1150 inod
= strtoul(ino
, &r
, 10);
1151 if (*r
!= '\0' || inod
<= ROOTINO
) {
1152 msg("Invalid inode argument %s\n", ino
);
1153 msg("The ENTIRE dump is aborted.\n");
1156 do_exclude_ino(inod
, NULL
);
1160 * This reads a file containing one inode number per line and exclude them all
1163 do_exclude_from_file(char *file
) {
1165 char *p
, fname
[MAXPATHLEN
];
1168 if (!( f
= fopen(file
, "r")) ) {
1169 msg("Cannot open file for reading: %s\n", file
);
1170 msg("The ENTIRE dump is aborted.\n");
1173 while (( p
= fgets(fname
, MAXPATHLEN
, f
))) {
1174 if ( *p
&& *(p
+ strlen(p
) - 1) == '\n' ) /* possible null string */
1175 *(p
+ strlen(p
) - 1) = '\0';
1176 if ( !*p
) /* skip empty lines */
1178 do_exclude_ino_str(p
);