]>
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.50 2001/07/18 09:12:05 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)
91 int notify
= 0; /* notify operator flag */
92 int blockswritten
= 0; /* number of blocks written on current tape */
93 int tapeno
= 0; /* current tape number */
94 int density
= 0; /* density in bytes/0.1" " <- this is for hilit19 */
95 int ntrec
= NTREC
; /* # tape blocks in each tape record */
96 int cartridge
= 0; /* Assume non-cartridge tape */
98 int tapepos
= 0; /* assume no QFA tapeposition needed by user */
100 int dokerberos
= 0; /* Use Kerberos authentication */
101 long dev_bsize
= 1; /* recalculated below */
102 long blocksperfile
; /* output blocks per file */
103 char *host
= NULL
; /* remote host (if any) */
104 int sizest
= 0; /* return size estimate only */
105 int compressed
= 0; /* use zlib to compress the output, compress level 1-9 */
106 long long bytes_written
= 0; /* total bytes written */
107 long uncomprblks
= 0;/* uncompressed blocks written */
113 int maxbsize
= 64*1024; /* XXX MAXBSIZE from sys/param.h */
114 static long numarg
__P((const char *, long, long));
115 static void obsolete
__P((int *, char **[]));
116 static void usage
__P((void));
118 dump_ino_t iexclude_list
[IEXCLUDE_MAXNUM
];/* the inode exclude list */
119 int iexclude_num
= 0; /* number of elements in the list */
122 main(int argc
, char *argv
[])
124 register dump_ino_t ino
;
126 register struct dinode
*dp
;
127 register struct fstab
*dt
;
130 int i
, anydirskipped
, bflag
= 0, Tflag
= 0, honorlevel
= 1;
136 char directory
[MAXPATHLEN
];
137 char pathname
[MAXPATHLEN
];
142 spcl
.c_label
[0] = '\0';
143 spcl
.c_date
= time(NULL
);
146 __progname
= argv
[0];
148 initialize_ext2_error_table();
151 tsize
= 0; /* Default later, based on 'c' option for cart tapes */
154 if ((tapeprefix
= getenv("TAPE")) == NULL
)
155 tapeprefix
= _PATH_DEFTAPE
;
156 dumpdates
= _PATH_DUMPDATES
;
157 if (TP_BSIZE
/ DEV_BSIZE
== 0 || TP_BSIZE
% DEV_BSIZE
!= 0)
158 quit("TP_BSIZE must be a multiple of DEV_BSIZE\n");
164 obsolete(&argc
, &argv
);
170 while ((ch
= getopt(argc
, argv
,
171 "0123456789aB:b:cd:e:f:F:h:L:"
186 case '0': case '1': case '2': case '3': case '4':
187 case '5': case '6': case '7': case '8': case '9':
191 case 'a': /* `auto-size', Write to EOM. */
195 case 'B': /* blocks per output file */
197 blocksperfile
= numarg("number of blocks per file",
201 case 'b': /* blocks per tape write */
202 ntrec
= numarg("number of blocks per write",
204 if (ntrec
> maxbsize
/1024) {
205 msg("Please choose a blocksize <= %dkB\n",
207 msg("The ENTIRE dump is aborted.\n");
213 case 'c': /* Tape is cart. not 9-track */
218 case 'd': /* density, in bits per inch */
220 density
= numarg("density", 10L, 327670L) / 10;
221 if (density
>= 625 && !bflag
)
222 ntrec
= HIGHDENSITYTREC
;
226 case 'e': /* exclude an inode */
227 if (iexclude_num
== IEXCLUDE_MAXNUM
) {
228 msg("Too many -e options\n");
229 msg("The ENTIRE dump is aborted.\n");
232 iexclude_list
[iexclude_num
++] = numarg("inode to exclude",0L,0L);
233 if (iexclude_list
[iexclude_num
-1] <= ROOTINO
) {
234 msg("Cannot exclude inode %ld\n", (long)iexclude_list
[iexclude_num
-1]);
235 msg("The ENTIRE dump is aborted.\n");
238 msg("Added %d to exclude list\n",
239 iexclude_list
[iexclude_num
-1]);
242 case 'f': /* output file */
246 case 'F': /* end of tape script */
251 honorlevel
= numarg("honor level", 0L, 10L);
262 * Note that although there are LBLSIZE characters,
263 * the last must be '\0', so the limit on strlen()
264 * is really LBLSIZE-1.
266 strncpy(spcl
.c_label
, optarg
, LBLSIZE
);
267 spcl
.c_label
[LBLSIZE
-1] = '\0';
268 if (strlen(optarg
) > LBLSIZE
-1) {
270 "WARNING Label `%s' is larger than limit of %d characters.\n",
272 msg("WARNING: Using truncated label `%s'.\n",
277 case 'M': /* multi-volume flag */
281 case 'n': /* notify operators */
286 case 'Q': /* create tapeposfile */
287 gTapeposfile
= optarg
;
292 case 's': /* tape size, feet */
294 tsize
= numarg("tape size", 1L, 0L) * 12 * 10;
298 sizest
= 1; /* return size estimate only */
301 case 'T': /* time of last dump */
302 spcl
.c_ddate
= unctime(optarg
);
303 if (spcl
.c_ddate
< 0) {
304 msg("bad time \"%s\"\n", optarg
);
305 msg("The ENTIRE dump is aborted.\n");
312 case 'u': /* update dumpdates */
316 case 'W': /* what to do */
319 exit(X_FINOK
); /* do nothing else */
324 compressed
= numarg("compress level", 1L, 9L);
326 #endif /* HAVE_ZLIB */
335 msg("Must specify disk or filesystem\n");
336 msg("The ENTIRE dump is aborted.\n");
340 if (strlen(diskparam
) >= MAXPATHLEN
) {
341 msg("Disk or filesystem name too long: %s\n", diskparam
);
342 msg("The ENTIRE dump is aborted.\n");
346 if (Tflag
&& uflag
) {
347 msg("You cannot use the T and u flags together.\n");
348 msg("The ENTIRE dump is aborted.\n");
351 if (strcmp(tapeprefix
, "-") == 0) {
353 tapeprefix
= "standard output";
357 blocksperfile
= blocksperfile
/ ntrec
* ntrec
; /* round down */
358 else if (!unlimited
) {
360 * Determine how to default tape size and density
363 * 9-track 1600 bpi (160 bytes/.1") 2300 ft.
364 * 9-track 6250 bpi (625 bytes/.1") 2300 ft.
365 * cartridge 8000 bpi (100 bytes/.1") 1700 ft.
367 * hilit19 hits again: "
370 density
= cartridge
? 100 : 160;
372 tsize
= cartridge
? 1700L*120L : 2300L*120L;
375 if (strchr(tapeprefix
, ':')) {
377 tapeprefix
= strchr(host
, ':');
378 *tapeprefix
++ = '\0';
380 if (index(tapeprefix
, '\n')) {
381 msg("invalid characters in tape\n");
382 msg("The ENTIRE dump is aborted.\n");
385 if (rmthost(host
) == 0)
388 msg("remote dump not enabled\n");
389 msg("The ENTIRE dump is aborted.\n");
393 (void)setuid(getuid()); /* rmthost() is the only reason to be setuid */
395 if (signal(SIGHUP
, SIG_IGN
) != SIG_IGN
)
397 if (signal(SIGTRAP
, SIG_IGN
) != SIG_IGN
)
398 signal(SIGTRAP
, sig
);
399 if (signal(SIGFPE
, SIG_IGN
) != SIG_IGN
)
401 if (signal(SIGBUS
, SIG_IGN
) != SIG_IGN
)
403 if (signal(SIGSEGV
, SIG_IGN
) != SIG_IGN
)
404 signal(SIGSEGV
, sig
);
405 if (signal(SIGTERM
, SIG_IGN
) != SIG_IGN
)
406 signal(SIGTERM
, sig
);
407 if (signal(SIGINT
, interrupt
) == SIG_IGN
)
408 signal(SIGINT
, SIG_IGN
);
409 set_operators(); /* /etc/group snarfed */
410 getfstab(); /* /etc/fstab snarfed */
413 * disk may end in / and this can confuse
416 i
= strlen(diskparam
) - 1;
417 if (i
> 1 && diskparam
[i
] == '/')
420 disk
= get_device_name(diskparam
);
421 if (!disk
) { /* null means the disk is some form
422 of LABEL= or UID= but it was not
424 msg("Cannot find a disk having %s\n", diskparam
);
425 msg("The ENTIRE dump is aborted.\n");
429 * disk can be either the full special file name,
430 * the suffix of the special file name,
431 * the special name missing the leading '/',
432 * the file system name with or without the leading '/'.
434 if ((dt
= fstabsearch(disk
)) != NULL
) {
435 /* if found then only one parameter (i.e. partition)
438 (void)fprintf(stderr
, "Unknown arguments to dump:");
440 (void)fprintf(stderr
, " %s", *argv
++);
441 (void)fprintf(stderr
, "\n");
442 msg("The ENTIRE dump is aborted.\n");
445 disk
= rawname(dt
->fs_spec
);
446 (void)strncpy(spcl
.c_dev
, dt
->fs_spec
, NAMELEN
);
447 (void)strncpy(spcl
.c_filesys
, dt
->fs_file
, NAMELEN
);
451 if (realpath(disk
, pathname
) == NULL
)
453 strcpy(pathname
, disk
);
455 * The argument could be now a mountpoint of
456 * a filesystem specified in fstab. Search for it.
458 if ((dt
= fstabsearch(pathname
)) != NULL
) {
459 disk
= rawname(dt
->fs_spec
);
460 (void)strncpy(spcl
.c_dev
, dt
->fs_spec
, NAMELEN
);
461 (void)strncpy(spcl
.c_filesys
, dt
->fs_file
, NAMELEN
);
464 * The argument was not found in the fstab
465 * assume that this is a subtree and search for it
467 dt
= fstabsearchdir(pathname
, directory
);
469 char name
[MAXPATHLEN
];
470 (void)strncpy(spcl
.c_dev
, dt
->fs_spec
, NAMELEN
);
471 (void)snprintf(name
, sizeof(name
), "%s (dir %s)",
472 dt
->fs_file
, directory
);
473 (void)strncpy(spcl
.c_filesys
, name
, NAMELEN
);
474 disk
= rawname(dt
->fs_spec
);
476 (void)strncpy(spcl
.c_dev
, disk
, NAMELEN
);
477 (void)strncpy(spcl
.c_filesys
, "an unlisted file system",
482 (void)strncpy(spcl
.c_dev
, disk
, NAMELEN
);
483 (void)strncpy(spcl
.c_filesys
, "an unlisted file system",
488 if (directory
[0] != 0) {
490 msg("Only level 0 dumps are allowed on a subdirectory\n");
491 msg("The ENTIRE dump is aborted.\n");
495 msg("You can't update the dumpdates file when dumping a subdirectory\n");
496 msg("The ENTIRE dump is aborted.\n");
500 spcl
.c_dev
[NAMELEN
-1] = '\0';
501 spcl
.c_filesys
[NAMELEN
-1] = '\0';
502 (void)gethostname(spcl
.c_host
, NAMELEN
);
503 spcl
.c_host
[NAMELEN
-1] = '\0';
504 spcl
.c_level
= level
- '0';
505 spcl
.c_type
= TS_TAPE
;
507 getdumptime(uflag
); /* dumpdates snarfed */
509 if (spcl
.c_ddate
== 0 && spcl
.c_level
) {
510 msg("WARNING: There is no inferior level dump on this filesystem\n");
511 msg("WARNING: Assuming a level 0 dump by default\n");
517 snprintf(tape
, MAXPATHLEN
, "%s%03d", tapeprefix
, tapeno
+ 1);
519 strncpy(tape
, tapeprefix
, MAXPATHLEN
);
520 tape
[MAXPATHLEN
- 1] = '\0';
524 msg("Date of this level %c dump: %s", level
,
525 ctime4(&spcl
.c_date
));
527 msg("Date of last level %c dump: %s", lastlevel
,
528 ctime4(&spcl
.c_ddate
));
529 msg("Dumping %s (%s) ", disk
, spcl
.c_filesys
);
531 msgtail("to %s on host %s\n", tape
, host
);
533 msgtail("to %s\n", tape
);
534 } /* end of size estimate */
537 retval
= dump_fs_open(disk
, &fs
);
539 com_err(disk
, retval
, "while opening filesystem");
540 if (retval
== EXT2_ET_REV_TOO_HIGH
)
541 msg("Get a newer version of dump!\n");
542 msg("The ENTIRE dump is aborted.\n");
545 if (fs
->super
->s_rev_level
> DUMP_CURRENT_REV
) {
546 com_err(disk
, retval
, "while opening filesystem");
547 msg("Get a newer version of dump!\n");
548 msg("The ENTIRE dump is aborted.\n");
551 if ((diskfd
= OPEN(disk
, O_RDONLY
)) < 0) {
552 msg("Cannot open %s\n", disk
);
553 msg("The ENTIRE dump is aborted.\n");
556 /* if no user label specified, use ext2 filesystem label if available */
557 if (spcl
.c_label
[0] == '\0') {
559 if ( (lbl
= get_device_label(disk
)) != NULL
) {
560 strncpy(spcl
.c_label
, lbl
, LBLSIZE
);
561 spcl
.c_label
[LBLSIZE
-1] = '\0';
564 strcpy(spcl
.c_label
, "none"); /* safe strcpy. */
567 dev_bsize
= DEV_BSIZE
;
568 dev_bshift
= ffs(dev_bsize
) - 1;
569 if (dev_bsize
!= (1 << dev_bshift
))
570 quit("dev_bsize (%d) is not a power of 2", dev_bsize
);
571 tp_bshift
= ffs(TP_BSIZE
) - 1;
572 if (TP_BSIZE
!= (1 << tp_bshift
))
573 quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE
);
574 maxino
= fs
->super
->s_inodes_count
;
576 spcl
.c_flags
|= DR_NEWINODEFMT
;
578 #else /* __linux __*/
579 if ((diskfd
= open(disk
, O_RDONLY
)) < 0) {
580 msg("Cannot open %s\n", disk
);
581 msg("The ENTIRE dump is aborted.\n");
585 sblock
= (struct fs
*)sblock_buf
;
586 bread(SBOFF
, (char *) sblock
, SBSIZE
);
587 if (sblock
->fs_magic
!= FS_MAGIC
)
588 quit("bad sblock magic number\n");
589 dev_bsize
= sblock
->fs_fsize
/ fsbtodb(sblock
, 1);
590 dev_bshift
= ffs(dev_bsize
) - 1;
591 if (dev_bsize
!= (1 << dev_bshift
))
592 quit("dev_bsize (%d) is not a power of 2", dev_bsize
);
593 tp_bshift
= ffs(TP_BSIZE
) - 1;
594 if (TP_BSIZE
!= (1 << tp_bshift
))
595 quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE
);
597 if (sblock
->fs_inodefmt
>= FS_44INODEFMT
)
598 spcl
.c_flags
|= DR_NEWINODEFMT
;
600 maxino
= sblock
->fs_ipg
* sblock
->fs_ncg
;
601 #endif /* __linux__ */
602 mapsize
= roundup(howmany(maxino
, NBBY
), TP_BSIZE
);
603 usedinomap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
604 dumpdirmap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
605 dumpinomap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
606 if (usedinomap
== NULL
|| dumpdirmap
== NULL
|| dumpinomap
== NULL
)
607 quit("out of memory allocating inode maps\n");
608 tapesize
= 2 * (howmany(mapsize
* sizeof(char), TP_BSIZE
) + 1);
610 nonodump
= spcl
.c_level
< honorlevel
;
613 msg("Label: %s\n", spcl
.c_label
);
616 msg("Compressing output at compression level %d\n",
621 (void)signal(SIGINFO
, statussig
);
625 msg("mapping (Pass I) [regular files]\n");
627 if (directory
[0] == 0)
628 anydirskipped
= mapfiles(maxino
, &tapesize
);
630 if (STAT(pathname
, &statbuf
) == -1) {
631 msg("File cannot be accessed (%s).\n", pathname
);
632 msg("The ENTIRE dump is aborted.\n");
635 filedev
= statbuf
.st_dev
;
636 if (!(statbuf
.st_mode
& S_IFDIR
)) /* is a file */
637 anydirskipped
= maponefile(maxino
, &tapesize
,
640 anydirskipped
= mapfilesfromdir(maxino
, &tapesize
,
646 /* check if file is available */
647 if (STAT(p
, &statbuf
) == -1) {
648 msg("File cannot be accessed (%s).\n", p
);
649 msg("The ENTIRE dump is aborted.\n");
652 /* check if file is on same unix partiton as the first
654 if (statbuf
.st_dev
!= filedev
) {
655 msg("Files are not on same file system (%s).\n", p
);
656 msg("The ENTIRE dump is aborted.\n");
659 /* check if file is a directory */
660 if (!(statbuf
.st_mode
& S_IFDIR
))
661 anydirskipped2
= maponefile(maxino
, &tapesize
,
662 p
+strlen(dt
->fs_file
));
664 /* read directory inodes.
665 * NOTE: nested directories are not recognized
666 * so inodes may be umped twice!
668 anydirskipped2
= mapfilesfromdir(maxino
, &tapesize
,
669 p
+strlen(dt
->fs_file
));
671 anydirskipped
= anydirskipped2
;
675 anydirskipped
= mapfiles(maxino
, &tapesize
);
679 msg("mapping (Pass II) [directories]\n");
680 while (anydirskipped
) {
681 anydirskipped
= mapdirs(maxino
, &tapesize
);
685 printf("%.0f\n", ((double)tapesize
+ 1 + ntrec
) * TP_BSIZE
);
687 } /* stop here for size estimate */
689 if (pipeout
|| unlimited
) {
690 tapesize
+= 1 + ntrec
; /* 1 map header + trailer blocks */
691 msg("estimated %ld tape blocks.\n", tapesize
);
696 fetapes
= (double) tapesize
/ blocksperfile
;
697 else if (cartridge
) {
698 /* Estimate number of tapes, assuming streaming stops at
699 the end of each block written, and not in mid-block.
700 Assume no erroneous blocks; this can be compensated
701 for with an artificially low tape size. */
703 ( (double) tapesize
/* blocks */
704 * TP_BSIZE
/* bytes/block */
705 * (1.0/density
) /* 0.1" / byte " */
707 (double) tapesize
/* blocks */
708 * (1.0/ntrec
) /* streaming-stops per block */
709 * 15.48 /* 0.1" / streaming-stop " */
710 ) * (1.0 / tsize
); /* tape / 0.1" " */
712 /* Estimate number of tapes, for old fashioned 9-track
714 int tenthsperirg
= (density
== 625) ? 3 : 7;
716 ( (double) tapesize
/* blocks */
717 * TP_BSIZE
/* bytes / block */
718 * (1.0/density
) /* 0.1" / byte " */
720 (double) tapesize
/* blocks */
721 * (1.0/ntrec
) /* IRG's / block */
722 * tenthsperirg
/* 0.1" / IRG " */
723 ) * (1.0 / tsize
); /* tape / 0.1" " */
725 etapes
= fetapes
; /* truncating assignment */
727 /* count the dumped inodes map on each additional tape */
728 tapesize
+= (etapes
- 1) *
729 (howmany(mapsize
* sizeof(char), TP_BSIZE
) + 1);
730 tapesize
+= etapes
+ ntrec
; /* headers + trailer blks */
731 msg("estimated %ld tape blocks on %3.2f tape(s).\n",
737 msg("writing QFA positions to %s\n", gTapeposfile
);
738 if ((gTapeposfd
= open(gTapeposfile
, O_RDWR
|O_CREAT
)) < 0)
739 quit("can't open tapeposfile\n");
740 /* print QFA-file header */
741 sprintf(gTps
, "%s\n%s\n%ld\n\n", QFA_MAGIC
, QFA_VERSION
, (unsigned long)spcl
.c_date
);
742 if (write(gTapeposfd
, gTps
, strlen(gTps
)) != strlen(gTps
))
743 quit("can't write tapeposfile\n");
744 sprintf(gTps
, "ino\ttapeno\ttapepos\n");
745 if (write(gTapeposfd
, gTps
, strlen(gTps
)) != strlen(gTps
))
746 quit("can't write tapeposfile\n");
751 * Allocate tape buffer.
755 "can't allocate tape buffers - try a smaller blocking factor.\n");
758 tstart_writing
= time(NULL
);
759 dumpmap(usedinomap
, TS_CLRI
, maxino
- 1);
761 msg("dumping (Pass III) [directories]\n");
762 dirty
= 0; /* XXX just to get gcc to shut up */
763 for (map
= dumpdirmap
, ino
= 1; ino
< maxino
; ino
++) {
764 if (((ino
- 1) % NBBY
) == 0) /* map is offset by 1 */
768 if ((dirty
& 1) == 0)
771 * Skip directory inodes deleted and maybe reallocated
774 if ((dp
->di_mode
& IFMT
) != IFDIR
)
778 * Skip directory inodes deleted and not yes reallocated...
780 if (dp
->di_nlink
== 0 || dp
->di_dtime
!= 0)
782 (void)dumpdirino(dp
, ino
);
784 (void)dumpino(dp
, ino
);
788 msg("dumping (Pass IV) [regular files]\n");
789 for (map
= dumpinomap
, ino
= 1; ino
< maxino
; ino
++) {
790 if (((ino
- 1) % NBBY
) == 0) /* map is offset by 1 */
794 if ((dirty
& 1) == 0)
797 * Skip inodes deleted and reallocated as directories.
800 if ((dp
->di_mode
& IFMT
) == IFDIR
)
804 * No need to check here for deleted and not yet reallocated
805 * inodes since this is done in dumpino().
808 (void)dumpino(dp
, ino
);
811 tend_writing
= time(NULL
);
812 spcl
.c_type
= TS_END
;
814 * Finish off the current tape record with trailer blocks, to ensure
815 * at least the data in the last partial record makes it to tape.
816 * Also make sure we write at least 1 trailer block.
818 for (i
= ntrec
- (spcl
.c_tapea
% ntrec
); i
; --i
)
819 writeheader(maxino
- 1);
824 msg("%ld tape blocks (%.2fMB)\n", spcl
.c_tapea
,
825 ((double)spcl
.c_tapea
* TP_BSIZE
/ 1048576));
827 msg("%ld tape blocks (%.2fMB) on %d volume(s)\n",
829 ((double)spcl
.c_tapea
* TP_BSIZE
/ 1048576),
832 /* report dump performance, avoid division by zero */
833 if (tend_writing
- tstart_writing
== 0)
834 msg("finished in less than a second\n");
836 msg("finished in %d seconds, throughput %d kBytes/sec\n",
837 tend_writing
- tstart_writing
,
838 spcl
.c_tapea
/ (tend_writing
- tstart_writing
));
841 msg("Date of this level %c dump: %s", level
,
842 spcl
.c_date
== 0 ? "the epoch\n" : ctime4(&spcl
.c_date
));
843 msg("Date this dump completed: %s", ctime(&tnow
));
845 msg("Average transfer rate: %ld kB/s\n", xferrate
/ tapeno
);
847 long tapekb
= bytes_written
/ 1024;
848 double rate
= .0005 + (double) spcl
.c_tapea
/ tapekb
;
849 msg("Wrote %ldkB uncompressed, %ldkB compressed, %1.3f:1\n",
850 spcl
.c_tapea
, tapekb
, rate
);
853 broadcast("DUMP IS DONE!\7\7\n");
854 msg("DUMP IS DONE\n");
857 return 0; /* gcc - shut up */
863 char white
[MAXPATHLEN
];
864 const char *ext2ver
, *ext2date
;
866 memset(white
, ' ', MAXPATHLEN
);
867 white
[MIN(strlen(__progname
), MAXPATHLEN
- 1)] = '\0';
870 ext2fs_get_library_version(&ext2ver
, &ext2date
);
871 fprintf(stderr
, "%s %s (using libext2fs %s of %s)\n",
872 __progname
, _DUMP_VERSION
, ext2ver
, ext2date
);
874 fprintf(stderr
, "%s %s\n", __progname
, _DUMP_VERSION
);
877 "usage:\t%s [-0123456789ac"
882 "] [-B records] [-b blocksize] [-d density]\n"
883 "\t%s [-e inode#] [-f file] [-h level] "
894 __progname
, white
, white
, __progname
);
899 * Pick up a numeric argument. It must be nonnegative and in the given
900 * range (except that a vmax of 0 means unlimited).
903 numarg(const char *meaning
, long vmin
, long vmax
)
908 val
= strtol(optarg
, &p
, 10);
910 errx(X_STARTUP
, "illegal %s -- %s", meaning
, optarg
);
911 if (val
< vmin
|| (vmax
&& val
> vmax
))
912 errx(X_STARTUP
, "%s must be between %ld and %ld", meaning
, vmin
, vmax
);
927 quit("Signal on pipe: cannot recover\n");
928 msg("Rewriting attempted as response to unknown signal: %d.\n", signo
);
929 (void)fflush(stderr
);
930 (void)fflush(stdout
);
935 msg("SIGSEGV: ABORTING!\n");
936 (void)signal(SIGSEGV
, SIG_DFL
);
937 (void)kill(0, SIGSEGV
);
943 rawname(const char *cp
)
947 #else /* __linux__ */
948 static char rawbuf
[MAXPATHLEN
];
949 char *dp
= strrchr(cp
, '/');
953 (void)strncpy(rawbuf
, cp
, min(dp
-cp
, MAXPATHLEN
- 1));
954 rawbuf
[min(dp
-cp
, MAXPATHLEN
-1)] = '\0';
955 (void)strncat(rawbuf
, "/r", MAXPATHLEN
- 1 - strlen(rawbuf
));
956 (void)strncat(rawbuf
, dp
+ 1, MAXPATHLEN
- 1 - strlen(rawbuf
));
958 #endif /* __linux__ */
963 * Change set of key letters and ordered arguments into something
964 * getopt(3) will like.
967 obsolete(int *argcp
, char **argvp
[])
970 char *ap
, **argv
, *flagsp
=NULL
, **nargv
, *p
=NULL
;
976 /* Return if no arguments or first argument has leading dash. */
978 if (argc
== 1 || *ap
== '-')
981 /* Allocate space for new arguments. */
982 if ((*argvp
= nargv
= malloc((argc
+ 1) * sizeof(char *))) == NULL
||
983 (p
= flagsp
= malloc(strlen(ap
) + 2)) == NULL
)
984 err(X_STARTUP
, "malloc new args");
989 for (flags
= 0; *ap
; ++ap
) {
1002 if (*argv
== NULL
) {
1003 warnx("option requires an argument -- %c", *ap
);
1006 if ((nargv
[0] = malloc(strlen(*argv
) + 2 + 1)) == NULL
)
1007 err(X_STARTUP
, "malloc arg");
1010 (void)strcpy(&nargv
[0][2], *argv
);
1024 /* Terminate flags. */
1030 /* Copy remaining arguments. */
1031 while ((*nargv
++ = *argv
++));
1033 /* Update argument count. */
1034 *argcp
= nargv
- *argvp
- 1;