]>
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.57 2001/08/16 09:37:59 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 int qflag
; /* quit on errors flag */
108 char *eot_script
; /* end of volume script fiag */
109 int diskfd
; /* disk file descriptor */
110 int tapefd
; /* tape file descriptor */
111 int pipeout
; /* true => output to standard output */
112 int fifoout
; /* true => output to fifo */
113 dump_ino_t curino
; /* current inumber; used globally */
114 int newtape
; /* new tape flag */
115 int density
; /* density in 0.1" units */
116 long tapesize
; /* estimated tape size, blocks */
117 long tsize
; /* tape size in 0.1" units */
118 long asize
; /* number of 0.1" units written on current tape */
119 int etapes
; /* estimated number of tapes */
120 int nonodump
; /* if set, do not honor UF_NODUMP user flags */
121 int unlimited
; /* if set, write to end of medium */
122 int compressed
; /* if set, dump is to be compressed */
123 long long bytes_written
;/* total bytes written to tape */
124 long uncomprblks
; /* uncompressed blocks written to tape */
125 int notify
; /* notify operator flag */
126 int blockswritten
; /* number of blocks written on current tape */
127 int tapeno
; /* current tape number */
128 time_t tstart_writing
; /* when started writing the first tape block */
129 time_t tend_writing
; /* after writing the last tape block */
133 struct fs
*sblock
; /* the file system super block */
134 char sblock_buf
[MAXBSIZE
];
136 long xferrate
; /* averaged transfer rate of all volumes */
137 long dev_bsize
; /* block size of underlying disk device */
138 int dev_bshift
; /* log2(dev_bsize) */
139 int tp_bshift
; /* log2(TP_BSIZE) */
145 int32_t gThisDumpDate
;
148 struct dumptime
*dthead
; /* head of the list version */
149 int nddates
; /* number of records (might be zero) */
150 int ddates_in
; /* we have read the increment file */
151 struct dumpdates
**ddatev
; /* the arrayfied version */
153 int notify
= 0; /* notify operator flag */
154 int blockswritten
= 0; /* number of blocks written on current tape */
155 int tapeno
= 0; /* current tape number */
156 int density
= 0; /* density in bytes/0.1" " <- this is for hilit19 */
157 int ntrec
= NTREC
; /* # tape blocks in each tape record */
158 int cartridge
= 0; /* Assume non-cartridge tape */
160 int tapepos
= 0; /* assume no QFA tapeposition needed by user */
162 int dokerberos
= 0; /* Use Kerberos authentication */
163 long dev_bsize
= 1; /* recalculated below */
164 long blocksperfile
; /* output blocks per file */
165 char *host
= NULL
; /* remote host (if any) */
166 int sizest
= 0; /* return size estimate only */
167 int compressed
= 0; /* use zlib to compress the output, compress level 1-9 */
168 long long bytes_written
= 0; /* total bytes written */
169 long uncomprblks
= 0;/* uncompressed blocks written */
175 int maxbsize
= 64*1024; /* XXX MAXBSIZE from sys/param.h */
176 static long numarg
__P((const char *, long, long));
177 static void obsolete
__P((int *, char **[]));
178 static void usage
__P((void));
179 static void do_exclude_from_file
__P((char *));
180 static void do_exclude_ino_str
__P((char *));
182 static dump_ino_t iexclude_list
[IEXCLUDE_MAXNUM
];/* the inode exclude list */
183 static int iexclude_num
= 0; /* number of elements in the list */
186 main(int argc
, char *argv
[])
188 register dump_ino_t ino
;
190 register struct dinode
*dp
;
191 register struct fstab
*dt
;
194 int i
, anydirskipped
, bflag
= 0, Tflag
= 0, honorlevel
= 1;
200 char directory
[MAXPATHLEN
];
201 char pathname
[MAXPATHLEN
];
206 spcl
.c_label
[0] = '\0';
207 spcl
.c_date
= time(NULL
);
210 __progname
= argv
[0];
212 initialize_ext2_error_table();
215 tsize
= 0; /* Default later, based on 'c' option for cart tapes */
218 if ((tapeprefix
= getenv("TAPE")) == NULL
)
219 tapeprefix
= _PATH_DEFTAPE
;
220 dumpdates
= _PATH_DUMPDATES
;
221 if (TP_BSIZE
/ DEV_BSIZE
== 0 || TP_BSIZE
% DEV_BSIZE
!= 0)
222 quit("TP_BSIZE must be a multiple of DEV_BSIZE\n");
228 obsolete(&argc
, &argv
);
234 while ((ch
= getopt(argc
, argv
,
235 "0123456789aB:b:cd:e:E:f:F:h:L:"
250 case '0': case '1': case '2': case '3': case '4':
251 case '5': case '6': case '7': case '8': case '9':
255 case 'a': /* `auto-size', Write to EOM. */
259 case 'B': /* blocks per output file */
261 blocksperfile
= numarg("number of blocks per file",
265 case 'b': /* blocks per tape write */
266 ntrec
= numarg("number of blocks per write",
268 if (ntrec
> maxbsize
/1024) {
269 msg("Please choose a blocksize <= %dkB\n",
271 msg("The ENTIRE dump is aborted.\n");
277 case 'c': /* Tape is cart. not 9-track */
282 case 'd': /* density, in bits per inch */
284 density
= numarg("density", 10L, 327670L) / 10;
285 if (density
>= 625 && !bflag
)
286 ntrec
= HIGHDENSITYTREC
;
290 case 'e': /* exclude an inode */
292 char *p
= optarg
, *q
;
293 while ((q
= strchr(p
, ','))) {
295 do_exclude_ino_str(p
);
298 do_exclude_ino_str(p
);
302 case 'E': /* exclude inodes read from file */
303 do_exclude_from_file(optarg
);
306 case 'f': /* output file */
310 case 'F': /* end of tape script */
315 honorlevel
= numarg("honor level", 0L, 10L);
326 * Note that although there are LBLSIZE characters,
327 * the last must be '\0', so the limit on strlen()
328 * is really LBLSIZE-1.
330 strncpy(spcl
.c_label
, optarg
, LBLSIZE
);
331 spcl
.c_label
[LBLSIZE
-1] = '\0';
332 if (strlen(optarg
) > LBLSIZE
-1) {
334 "WARNING Label `%s' is larger than limit of %d characters.\n",
336 msg("WARNING: Using truncated label `%s'.\n",
341 case 'M': /* multi-volume flag */
345 case 'n': /* notify operators */
354 case 'Q': /* create tapeposfile */
355 gTapeposfile
= optarg
;
360 case 's': /* tape size, feet */
362 tsize
= numarg("tape size", 1L, 0L) * 12 * 10;
366 sizest
= 1; /* return size estimate only */
369 case 'T': /* time of last dump */
370 spcl
.c_ddate
= unctime(optarg
);
371 if (spcl
.c_ddate
< 0) {
372 msg("bad time \"%s\"\n", optarg
);
373 msg("The ENTIRE dump is aborted.\n");
380 case 'u': /* update dumpdates */
384 case 'W': /* what to do */
387 exit(X_FINOK
); /* do nothing else */
392 compressed
= numarg("compress level", 1L, 9L);
394 #endif /* HAVE_ZLIB */
403 msg("Must specify disk or filesystem\n");
404 msg("The ENTIRE dump is aborted.\n");
408 if (strlen(diskparam
) >= MAXPATHLEN
) {
409 msg("Disk or filesystem name too long: %s\n", diskparam
);
410 msg("The ENTIRE dump is aborted.\n");
414 if (Tflag
&& uflag
) {
415 msg("You cannot use the T and u flags together.\n");
416 msg("The ENTIRE dump is aborted.\n");
419 if (strcmp(tapeprefix
, "-") == 0) {
421 tapeprefix
= "standard output";
424 if (blocksperfile
&& !compressed
)
425 blocksperfile
= blocksperfile
/ ntrec
* ntrec
; /* round down */
426 else if (!unlimited
) {
428 * Determine how to default tape size and density
431 * 9-track 1600 bpi (160 bytes/.1") 2300 ft.
432 * 9-track 6250 bpi (625 bytes/.1") 2300 ft.
433 * cartridge 8000 bpi (100 bytes/.1") 1700 ft.
435 * hilit19 hits again: "
438 density
= cartridge
? 100 : 160;
440 tsize
= cartridge
? 1700L*120L : 2300L*120L;
443 if (strchr(tapeprefix
, ':')) {
445 tapeprefix
= strchr(host
, ':');
446 *tapeprefix
++ = '\0';
448 if (index(tapeprefix
, '\n')) {
449 msg("invalid characters in tape\n");
450 msg("The ENTIRE dump is aborted.\n");
453 if (rmthost(host
) == 0)
456 msg("remote dump not enabled\n");
457 msg("The ENTIRE dump is aborted.\n");
461 (void)setuid(getuid()); /* rmthost() is the only reason to be setuid */
463 if (signal(SIGHUP
, SIG_IGN
) != SIG_IGN
)
465 if (signal(SIGTRAP
, SIG_IGN
) != SIG_IGN
)
466 signal(SIGTRAP
, sig
);
467 if (signal(SIGFPE
, SIG_IGN
) != SIG_IGN
)
469 if (signal(SIGBUS
, SIG_IGN
) != SIG_IGN
)
471 if (signal(SIGSEGV
, SIG_IGN
) != SIG_IGN
)
472 signal(SIGSEGV
, sig
);
473 if (signal(SIGTERM
, SIG_IGN
) != SIG_IGN
)
474 signal(SIGTERM
, sig
);
475 if (signal(SIGINT
, interrupt
) == SIG_IGN
)
476 signal(SIGINT
, SIG_IGN
);
477 set_operators(); /* /etc/group snarfed */
478 getfstab(); /* /etc/fstab snarfed */
481 * disk may end in / and this can confuse
484 i
= strlen(diskparam
) - 1;
485 if (i
> 1 && diskparam
[i
] == '/')
488 disk
= get_device_name(diskparam
);
489 if (!disk
) { /* null means the disk is some form
490 of LABEL= or UID= but it was not
492 msg("Cannot find a disk having %s\n", diskparam
);
493 msg("The ENTIRE dump is aborted.\n");
497 * disk can be either the full special file name,
498 * the suffix of the special file name,
499 * the special name missing the leading '/',
500 * the file system name with or without the leading '/'.
502 if ((dt
= fstabsearch(disk
)) != NULL
) {
503 /* if found then only one parameter (i.e. partition)
506 (void)fprintf(stderr
, "Unknown arguments to dump:");
508 (void)fprintf(stderr
, " %s", *argv
++);
509 (void)fprintf(stderr
, "\n");
510 msg("The ENTIRE dump is aborted.\n");
513 disk
= rawname(dt
->fs_spec
);
514 (void)strncpy(spcl
.c_dev
, dt
->fs_spec
, NAMELEN
);
515 (void)strncpy(spcl
.c_filesys
, dt
->fs_file
, NAMELEN
);
519 if (realpath(disk
, pathname
) == NULL
)
521 strcpy(pathname
, disk
);
523 * The argument could be now a mountpoint of
524 * a filesystem specified in fstab. Search for it.
526 if ((dt
= fstabsearch(pathname
)) != NULL
) {
527 disk
= rawname(dt
->fs_spec
);
528 (void)strncpy(spcl
.c_dev
, dt
->fs_spec
, NAMELEN
);
529 (void)strncpy(spcl
.c_filesys
, dt
->fs_file
, NAMELEN
);
532 * The argument was not found in the fstab
533 * assume that this is a subtree and search for it
535 dt
= fstabsearchdir(pathname
, directory
);
537 char name
[MAXPATHLEN
];
538 (void)strncpy(spcl
.c_dev
, dt
->fs_spec
, NAMELEN
);
539 (void)snprintf(name
, sizeof(name
), "%s (dir %s)",
540 dt
->fs_file
, directory
);
541 (void)strncpy(spcl
.c_filesys
, name
, NAMELEN
);
542 disk
= rawname(dt
->fs_spec
);
544 (void)strncpy(spcl
.c_dev
, disk
, NAMELEN
);
545 (void)strncpy(spcl
.c_filesys
, "an unlisted file system",
550 (void)strncpy(spcl
.c_dev
, disk
, NAMELEN
);
551 (void)strncpy(spcl
.c_filesys
, "an unlisted file system",
556 if (directory
[0] != 0) {
558 msg("Only level 0 dumps are allowed on a subdirectory\n");
559 msg("The ENTIRE dump is aborted.\n");
563 msg("You can't update the dumpdates file when dumping a subdirectory\n");
564 msg("The ENTIRE dump is aborted.\n");
568 spcl
.c_dev
[NAMELEN
-1] = '\0';
569 spcl
.c_filesys
[NAMELEN
-1] = '\0';
570 (void)gethostname(spcl
.c_host
, NAMELEN
);
571 spcl
.c_host
[NAMELEN
-1] = '\0';
572 spcl
.c_level
= level
- '0';
573 spcl
.c_type
= TS_TAPE
;
575 getdumptime(uflag
); /* dumpdates snarfed */
577 if (spcl
.c_ddate
== 0 && spcl
.c_level
) {
578 msg("WARNING: There is no inferior level dump on this filesystem\n");
579 msg("WARNING: Assuming a level 0 dump by default\n");
585 snprintf(tape
, MAXPATHLEN
, "%s%03d", tapeprefix
, tapeno
+ 1);
587 strncpy(tape
, tapeprefix
, MAXPATHLEN
);
588 tape
[MAXPATHLEN
- 1] = '\0';
591 if (STAT(tape
, &statbuf
) != -1)
592 fifoout
= statbuf
.st_mode
& S_IFIFO
;
597 msg("Date of this level %c dump: %s", level
,
598 ctime4(&spcl
.c_date
));
600 gThisDumpDate
= spcl
.c_date
;
603 msg("Date of last level %c dump: %s", lastlevel
,
604 ctime4(&spcl
.c_ddate
));
605 msg("Dumping %s (%s) ", disk
, spcl
.c_filesys
);
607 msgtail("to %s on host %s\n", tape
, host
);
609 msgtail("to %s\n", tape
);
610 } /* end of size estimate */
613 retval
= dump_fs_open(disk
, &fs
);
615 com_err(disk
, retval
, "while opening filesystem");
616 if (retval
== EXT2_ET_REV_TOO_HIGH
)
617 msg("Get a newer version of dump!\n");
618 msg("The ENTIRE dump is aborted.\n");
621 if (fs
->super
->s_rev_level
> DUMP_CURRENT_REV
) {
622 com_err(disk
, retval
, "while opening filesystem");
623 msg("Get a newer version of dump!\n");
624 msg("The ENTIRE dump is aborted.\n");
627 if ((diskfd
= OPEN(disk
, O_RDONLY
)) < 0) {
628 msg("Cannot open %s\n", disk
);
629 msg("The ENTIRE dump is aborted.\n");
632 /* if no user label specified, use ext2 filesystem label if available */
633 if (spcl
.c_label
[0] == '\0') {
635 if ( (lbl
= get_device_label(disk
)) != NULL
) {
636 strncpy(spcl
.c_label
, lbl
, LBLSIZE
);
637 spcl
.c_label
[LBLSIZE
-1] = '\0';
640 strcpy(spcl
.c_label
, "none"); /* safe strcpy. */
643 dev_bsize
= DEV_BSIZE
;
644 dev_bshift
= ffs(dev_bsize
) - 1;
645 if (dev_bsize
!= (1 << dev_bshift
))
646 quit("dev_bsize (%d) is not a power of 2", dev_bsize
);
647 tp_bshift
= ffs(TP_BSIZE
) - 1;
648 if (TP_BSIZE
!= (1 << tp_bshift
))
649 quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE
);
650 maxino
= fs
->super
->s_inodes_count
;
652 spcl
.c_flags
|= DR_NEWINODEFMT
;
654 #else /* __linux __*/
655 if ((diskfd
= open(disk
, O_RDONLY
)) < 0) {
656 msg("Cannot open %s\n", disk
);
657 msg("The ENTIRE dump is aborted.\n");
661 sblock
= (struct fs
*)sblock_buf
;
662 bread(SBOFF
, (char *) sblock
, SBSIZE
);
663 if (sblock
->fs_magic
!= FS_MAGIC
)
664 quit("bad sblock magic number\n");
665 dev_bsize
= sblock
->fs_fsize
/ fsbtodb(sblock
, 1);
666 dev_bshift
= ffs(dev_bsize
) - 1;
667 if (dev_bsize
!= (1 << dev_bshift
))
668 quit("dev_bsize (%d) is not a power of 2", dev_bsize
);
669 tp_bshift
= ffs(TP_BSIZE
) - 1;
670 if (TP_BSIZE
!= (1 << tp_bshift
))
671 quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE
);
673 if (sblock
->fs_inodefmt
>= FS_44INODEFMT
)
674 spcl
.c_flags
|= DR_NEWINODEFMT
;
676 maxino
= sblock
->fs_ipg
* sblock
->fs_ncg
;
677 #endif /* __linux__ */
678 mapsize
= roundup(howmany(maxino
, NBBY
), TP_BSIZE
);
679 usedinomap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
680 dumpdirmap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
681 dumpinomap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
682 if (usedinomap
== NULL
|| dumpdirmap
== NULL
|| dumpinomap
== NULL
)
683 quit("out of memory allocating inode maps\n");
684 tapesize
= 2 * (howmany(mapsize
* sizeof(char), TP_BSIZE
) + 1);
686 nonodump
= spcl
.c_level
< honorlevel
;
689 msg("Label: %s\n", spcl
.c_label
);
692 msg("Compressing output at compression level %d\n",
697 (void)signal(SIGINFO
, statussig
);
701 msg("mapping (Pass I) [regular files]\n");
703 if (directory
[0] == 0)
704 anydirskipped
= mapfiles(maxino
, &tapesize
);
706 if (STAT(pathname
, &statbuf
) == -1) {
707 msg("File cannot be accessed (%s).\n", pathname
);
708 msg("The ENTIRE dump is aborted.\n");
711 filedev
= statbuf
.st_dev
;
712 if (!(statbuf
.st_mode
& S_IFDIR
)) /* is a file */
713 anydirskipped
= maponefile(maxino
, &tapesize
,
716 anydirskipped
= mapfilesfromdir(maxino
, &tapesize
,
722 /* check if file is available */
723 if (STAT(p
, &statbuf
) == -1) {
724 msg("File cannot be accessed (%s).\n", p
);
725 msg("The ENTIRE dump is aborted.\n");
728 /* check if file is on same unix partiton as the first
730 if (statbuf
.st_dev
!= filedev
) {
731 msg("Files are not on same file system (%s).\n", p
);
732 msg("The ENTIRE dump is aborted.\n");
735 /* check if file is a directory */
736 if (!(statbuf
.st_mode
& S_IFDIR
))
737 anydirskipped2
= maponefile(maxino
, &tapesize
,
738 p
+strlen(dt
->fs_file
));
740 /* read directory inodes.
741 * NOTE: nested directories are not recognized
742 * so inodes may be umped twice!
744 anydirskipped2
= mapfilesfromdir(maxino
, &tapesize
,
745 p
+strlen(dt
->fs_file
));
747 anydirskipped
= anydirskipped2
;
751 anydirskipped
= mapfiles(maxino
, &tapesize
);
755 msg("mapping (Pass II) [directories]\n");
756 while (anydirskipped
) {
757 anydirskipped
= mapdirs(maxino
, &tapesize
);
761 printf("%.0f\n", ((double)tapesize
+ 1 + ntrec
) * TP_BSIZE
);
763 } /* stop here for size estimate */
765 if (pipeout
|| unlimited
) {
766 tapesize
+= 1 + ntrec
; /* 1 map header + trailer blocks */
767 msg("estimated %ld tape blocks.\n", tapesize
);
772 fetapes
= (double) tapesize
/ blocksperfile
;
773 else if (cartridge
) {
774 /* Estimate number of tapes, assuming streaming stops at
775 the end of each block written, and not in mid-block.
776 Assume no erroneous blocks; this can be compensated
777 for with an artificially low tape size. */
779 ( (double) tapesize
/* blocks */
780 * TP_BSIZE
/* bytes/block */
781 * (1.0/density
) /* 0.1" / byte " */
783 (double) tapesize
/* blocks */
784 * (1.0/ntrec
) /* streaming-stops per block */
785 * 15.48 /* 0.1" / streaming-stop " */
786 ) * (1.0 / tsize
); /* tape / 0.1" " */
788 /* Estimate number of tapes, for old fashioned 9-track
790 int tenthsperirg
= (density
== 625) ? 3 : 7;
792 ( (double) tapesize
/* blocks */
793 * TP_BSIZE
/* bytes / block */
794 * (1.0/density
) /* 0.1" / byte " */
796 (double) tapesize
/* blocks */
797 * (1.0/ntrec
) /* IRG's / block */
798 * tenthsperirg
/* 0.1" / IRG " */
799 ) * (1.0 / tsize
); /* tape / 0.1" " */
801 etapes
= fetapes
; /* truncating assignment */
803 /* count the dumped inodes map on each additional tape */
804 tapesize
+= (etapes
- 1) *
805 (howmany(mapsize
* sizeof(char), TP_BSIZE
) + 1);
806 tapesize
+= etapes
+ ntrec
; /* headers + trailer blks */
807 msg("estimated %ld tape blocks on %3.2f tape(s).\n",
813 msg("writing QFA positions to %s\n", gTapeposfile
);
814 if ((gTapeposfd
= open(gTapeposfile
, O_RDWR
|O_CREAT
, S_IRUSR
| S_IWUSR
)) < 0)
815 quit("can't open tapeposfile\n");
816 /* print QFA-file header */
817 sprintf(gTps
, "%s\n%s\n%ld\n\n", QFA_MAGIC
, QFA_VERSION
, (unsigned long)spcl
.c_date
);
818 if (write(gTapeposfd
, gTps
, strlen(gTps
)) != strlen(gTps
))
819 quit("can't write tapeposfile\n");
820 sprintf(gTps
, "ino\ttapeno\ttapepos\n");
821 if (write(gTapeposfd
, gTps
, strlen(gTps
)) != strlen(gTps
))
822 quit("can't write tapeposfile\n");
827 * Allocate tape buffer.
831 "can't allocate tape buffers - try a smaller blocking factor.\n");
834 tstart_writing
= time(NULL
);
835 dumpmap(usedinomap
, TS_CLRI
, maxino
- 1);
837 msg("dumping (Pass III) [directories]\n");
838 dirty
= 0; /* XXX just to get gcc to shut up */
839 for (map
= dumpdirmap
, ino
= 1; ino
< maxino
; ino
++) {
840 if (((ino
- 1) % NBBY
) == 0) /* map is offset by 1 */
844 if ((dirty
& 1) == 0)
847 * Skip directory inodes deleted and maybe reallocated
850 if ((dp
->di_mode
& IFMT
) != IFDIR
)
854 * Skip directory inodes deleted and not yes reallocated...
856 if (dp
->di_nlink
== 0 || dp
->di_dtime
!= 0)
858 (void)dumpdirino(dp
, ino
);
860 (void)dumpino(dp
, ino
);
864 msg("dumping (Pass IV) [regular files]\n");
865 for (map
= dumpinomap
, ino
= 1; ino
< maxino
; ino
++) {
866 if (((ino
- 1) % NBBY
) == 0) /* map is offset by 1 */
870 if ((dirty
& 1) == 0)
873 * Skip inodes deleted and reallocated as directories.
876 if ((dp
->di_mode
& IFMT
) == IFDIR
)
880 * No need to check here for deleted and not yet reallocated
881 * inodes since this is done in dumpino().
884 (void)dumpino(dp
, ino
);
887 tend_writing
= time(NULL
);
888 spcl
.c_type
= TS_END
;
890 * Finish off the current tape record with trailer blocks, to ensure
891 * at least the data in the last partial record makes it to tape.
892 * Also make sure we write at least 1 trailer block.
894 for (i
= ntrec
- (spcl
.c_tapea
% ntrec
); i
; --i
)
895 writeheader(maxino
- 1);
899 if (pipeout
|| fifoout
)
900 msg("%ld tape blocks (%.2fMB)\n", spcl
.c_tapea
,
901 ((double)spcl
.c_tapea
* TP_BSIZE
/ 1048576));
903 msg("%ld tape blocks (%.2fMB) on %d volume(s)\n",
905 ((double)spcl
.c_tapea
* TP_BSIZE
/ 1048576),
908 /* report dump performance, avoid division by zero */
909 if (tend_writing
- tstart_writing
== 0)
910 msg("finished in less than a second\n");
912 msg("finished in %d seconds, throughput %d kBytes/sec\n",
913 tend_writing
- tstart_writing
,
914 spcl
.c_tapea
/ (tend_writing
- tstart_writing
));
917 msg("Date of this level %c dump: %s", level
,
918 spcl
.c_date
== 0 ? "the epoch\n" : ctime4(&spcl
.c_date
));
919 msg("Date this dump completed: %s", ctime(&tnow
));
921 msg("Average transfer rate: %ld kB/s\n", xferrate
/ tapeno
);
923 long tapekb
= bytes_written
/ 1024;
924 double rate
= .0005 + (double) spcl
.c_tapea
/ tapekb
;
925 msg("Wrote %ldkB uncompressed, %ldkB compressed, %1.3f:1\n",
926 spcl
.c_tapea
, tapekb
, rate
);
929 broadcast("DUMP IS DONE!\7\7\n");
930 msg("DUMP IS DONE\n");
933 return 0; /* gcc - shut up */
939 char white
[MAXPATHLEN
];
940 const char *ext2ver
, *ext2date
;
942 memset(white
, ' ', MAXPATHLEN
);
943 white
[MIN(strlen(__progname
), MAXPATHLEN
- 1)] = '\0';
946 ext2fs_get_library_version(&ext2ver
, &ext2date
);
947 fprintf(stderr
, "%s %s (using libext2fs %s of %s)\n",
948 __progname
, _DUMP_VERSION
, ext2ver
, ext2date
);
950 fprintf(stderr
, "%s %s\n", __progname
, _DUMP_VERSION
);
953 "usage:\t%s [-0123456789ac"
958 "] [-B records] [-b blocksize] [-d density]\n"
959 "\t%s [-e inode#,inode#,...] [-E file] [-f file] [-h level] "
963 "\n\t%s [-s feet] [-T date] "
969 __progname
, white
, white
, __progname
);
974 * Pick up a numeric argument. It must be nonnegative and in the given
975 * range (except that a vmax of 0 means unlimited).
978 numarg(const char *meaning
, long vmin
, long vmax
)
983 val
= strtol(optarg
, &p
, 10);
985 errx(X_STARTUP
, "illegal %s -- %s", meaning
, optarg
);
986 if (val
< vmin
|| (vmax
&& val
> vmax
))
987 errx(X_STARTUP
, "%s must be between %ld and %ld", meaning
, vmin
, vmax
);
1001 if (pipeout
|| fifoout
)
1002 quit("Signal on pipe: cannot recover\n");
1003 msg("Rewriting attempted as response to unknown signal: %d.\n", signo
);
1004 (void)fflush(stderr
);
1005 (void)fflush(stdout
);
1010 msg("SIGSEGV: ABORTING!\n");
1011 (void)signal(SIGSEGV
, SIG_DFL
);
1012 (void)kill(0, SIGSEGV
);
1018 rawname(const char *cp
)
1022 #else /* __linux__ */
1023 static char rawbuf
[MAXPATHLEN
];
1024 char *dp
= strrchr(cp
, '/');
1028 (void)strncpy(rawbuf
, cp
, min(dp
-cp
, MAXPATHLEN
- 1));
1029 rawbuf
[min(dp
-cp
, MAXPATHLEN
-1)] = '\0';
1030 (void)strncat(rawbuf
, "/r", MAXPATHLEN
- 1 - strlen(rawbuf
));
1031 (void)strncat(rawbuf
, dp
+ 1, MAXPATHLEN
- 1 - strlen(rawbuf
));
1033 #endif /* __linux__ */
1038 * Change set of key letters and ordered arguments into something
1039 * getopt(3) will like.
1042 obsolete(int *argcp
, char **argvp
[])
1045 char *ap
, **argv
, *flagsp
=NULL
, **nargv
, *p
=NULL
;
1051 /* Return if no arguments or first argument has leading dash. */
1053 if (argc
== 1 || *ap
== '-')
1056 /* Allocate space for new arguments. */
1057 if ((*argvp
= nargv
= malloc((argc
+ 1) * sizeof(char *))) == NULL
||
1058 (p
= flagsp
= malloc(strlen(ap
) + 2)) == NULL
)
1059 err(X_STARTUP
, "malloc new args");
1064 for (flags
= 0; *ap
; ++ap
) {
1078 if (*argv
== NULL
) {
1079 warnx("option requires an argument -- %c", *ap
);
1082 if ((nargv
[0] = malloc(strlen(*argv
) + 2 + 1)) == NULL
)
1083 err(X_STARTUP
, "malloc arg");
1086 (void)strcpy(&nargv
[0][2], *argv
);
1100 /* Terminate flags. */
1106 /* Copy remaining arguments. */
1107 while ((*nargv
++ = *argv
++));
1109 /* Update argument count. */
1110 *argcp
= nargv
- *argvp
- 1;
1114 * This tests whether an inode is in the exclude list
1117 exclude_ino(dump_ino_t ino
)
1120 if (iexclude_num
) { /* if there are inodes in the exclude list */
1121 int idx
; /* then check this inode against it */
1122 for (idx
= 0; idx
< iexclude_num
; idx
++)
1123 if (ino
== iexclude_list
[idx
])
1130 * This tests adds an inode to the exclusion list if it isn't already there
1133 do_exclude_ino(dump_ino_t ino
, const char *reason
)
1135 if (!exclude_ino(ino
)) {
1136 if (iexclude_num
== IEXCLUDE_MAXNUM
) {
1137 msg("Too many exclude options\n");
1138 msg("The ENTIRE dump is aborted.\n");
1142 msg("Added inode %u to exclude list (%s)\n",
1145 msg("Added inode %u to exclude list\n", ino
);
1146 iexclude_list
[iexclude_num
++] = ino
;
1151 do_exclude_ino_str(char * ino
) {
1155 inod
= strtoul(ino
, &r
, 10);
1156 if (*r
!= '\0' || inod
<= ROOTINO
) {
1157 msg("Invalid inode argument %s\n", ino
);
1158 msg("The ENTIRE dump is aborted.\n");
1161 do_exclude_ino(inod
, NULL
);
1165 * This reads a file containing one inode number per line and exclude them all
1168 do_exclude_from_file(char *file
) {
1170 char *p
, fname
[MAXPATHLEN
];
1173 if (!( f
= fopen(file
, "r")) ) {
1174 msg("Cannot open file for reading: %s\n", file
);
1175 msg("The ENTIRE dump is aborted.\n");
1178 while (( p
= fgets(fname
, MAXPATHLEN
, f
))) {
1179 if ( *p
&& *(p
+ strlen(p
) - 1) == '\n' ) /* possible null string */
1180 *(p
+ strlen(p
) - 1) = '\0';
1181 if ( !*p
) /* skip empty lines */
1183 do_exclude_ino_str(p
);