]>
git.wh0rd.org - dump.git/blob - dump/main.c
d7462c89fc6030c9c8c8cae93115297aaa17ad69
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.54 2001/07/19 09:49:35 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));
117 static void do_exclude_from_file
__P((char *));
118 static void do_exclude_ino_str
__P((char *));
120 static dump_ino_t iexclude_list
[IEXCLUDE_MAXNUM
];/* the inode exclude list */
121 static int iexclude_num
= 0; /* number of elements in the list */
124 main(int argc
, char *argv
[])
126 register dump_ino_t ino
;
128 register struct dinode
*dp
;
129 register struct fstab
*dt
;
132 int i
, anydirskipped
, bflag
= 0, Tflag
= 0, honorlevel
= 1;
138 char directory
[MAXPATHLEN
];
139 char pathname
[MAXPATHLEN
];
144 spcl
.c_label
[0] = '\0';
145 spcl
.c_date
= time(NULL
);
148 __progname
= argv
[0];
150 initialize_ext2_error_table();
153 tsize
= 0; /* Default later, based on 'c' option for cart tapes */
156 if ((tapeprefix
= getenv("TAPE")) == NULL
)
157 tapeprefix
= _PATH_DEFTAPE
;
158 dumpdates
= _PATH_DUMPDATES
;
159 if (TP_BSIZE
/ DEV_BSIZE
== 0 || TP_BSIZE
% DEV_BSIZE
!= 0)
160 quit("TP_BSIZE must be a multiple of DEV_BSIZE\n");
166 obsolete(&argc
, &argv
);
172 while ((ch
= getopt(argc
, argv
,
173 "0123456789aB:b:cd:e:E:f:F:h:L:"
188 case '0': case '1': case '2': case '3': case '4':
189 case '5': case '6': case '7': case '8': case '9':
193 case 'a': /* `auto-size', Write to EOM. */
197 case 'B': /* blocks per output file */
199 blocksperfile
= numarg("number of blocks per file",
203 case 'b': /* blocks per tape write */
204 ntrec
= numarg("number of blocks per write",
206 if (ntrec
> maxbsize
/1024) {
207 msg("Please choose a blocksize <= %dkB\n",
209 msg("The ENTIRE dump is aborted.\n");
215 case 'c': /* Tape is cart. not 9-track */
220 case 'd': /* density, in bits per inch */
222 density
= numarg("density", 10L, 327670L) / 10;
223 if (density
>= 625 && !bflag
)
224 ntrec
= HIGHDENSITYTREC
;
228 case 'e': /* exclude an inode */
230 char *p
= optarg
, *q
;
231 while ((q
= strchr(p
, ','))) {
233 do_exclude_ino_str(p
);
236 do_exclude_ino_str(p
);
240 case 'E': /* exclude inodes read from file */
241 do_exclude_from_file(optarg
);
244 case 'f': /* output file */
248 case 'F': /* end of tape script */
253 honorlevel
= numarg("honor level", 0L, 10L);
264 * Note that although there are LBLSIZE characters,
265 * the last must be '\0', so the limit on strlen()
266 * is really LBLSIZE-1.
268 strncpy(spcl
.c_label
, optarg
, LBLSIZE
);
269 spcl
.c_label
[LBLSIZE
-1] = '\0';
270 if (strlen(optarg
) > LBLSIZE
-1) {
272 "WARNING Label `%s' is larger than limit of %d characters.\n",
274 msg("WARNING: Using truncated label `%s'.\n",
279 case 'M': /* multi-volume flag */
283 case 'n': /* notify operators */
288 case 'Q': /* create tapeposfile */
289 gTapeposfile
= optarg
;
294 case 's': /* tape size, feet */
296 tsize
= numarg("tape size", 1L, 0L) * 12 * 10;
300 sizest
= 1; /* return size estimate only */
303 case 'T': /* time of last dump */
304 spcl
.c_ddate
= unctime(optarg
);
305 if (spcl
.c_ddate
< 0) {
306 msg("bad time \"%s\"\n", optarg
);
307 msg("The ENTIRE dump is aborted.\n");
314 case 'u': /* update dumpdates */
318 case 'W': /* what to do */
321 exit(X_FINOK
); /* do nothing else */
326 compressed
= numarg("compress level", 1L, 9L);
328 #endif /* HAVE_ZLIB */
337 msg("Must specify disk or filesystem\n");
338 msg("The ENTIRE dump is aborted.\n");
342 if (strlen(diskparam
) >= MAXPATHLEN
) {
343 msg("Disk or filesystem name too long: %s\n", diskparam
);
344 msg("The ENTIRE dump is aborted.\n");
348 if (Tflag
&& uflag
) {
349 msg("You cannot use the T and u flags together.\n");
350 msg("The ENTIRE dump is aborted.\n");
353 if (strcmp(tapeprefix
, "-") == 0) {
355 tapeprefix
= "standard output";
358 if (blocksperfile
&& !compressed
)
359 blocksperfile
= blocksperfile
/ ntrec
* ntrec
; /* round down */
360 else if (!unlimited
) {
362 * Determine how to default tape size and density
365 * 9-track 1600 bpi (160 bytes/.1") 2300 ft.
366 * 9-track 6250 bpi (625 bytes/.1") 2300 ft.
367 * cartridge 8000 bpi (100 bytes/.1") 1700 ft.
369 * hilit19 hits again: "
372 density
= cartridge
? 100 : 160;
374 tsize
= cartridge
? 1700L*120L : 2300L*120L;
377 if (strchr(tapeprefix
, ':')) {
379 tapeprefix
= strchr(host
, ':');
380 *tapeprefix
++ = '\0';
382 if (index(tapeprefix
, '\n')) {
383 msg("invalid characters in tape\n");
384 msg("The ENTIRE dump is aborted.\n");
387 if (rmthost(host
) == 0)
390 msg("remote dump not enabled\n");
391 msg("The ENTIRE dump is aborted.\n");
395 (void)setuid(getuid()); /* rmthost() is the only reason to be setuid */
397 if (signal(SIGHUP
, SIG_IGN
) != SIG_IGN
)
399 if (signal(SIGTRAP
, SIG_IGN
) != SIG_IGN
)
400 signal(SIGTRAP
, sig
);
401 if (signal(SIGFPE
, SIG_IGN
) != SIG_IGN
)
403 if (signal(SIGBUS
, SIG_IGN
) != SIG_IGN
)
405 if (signal(SIGSEGV
, SIG_IGN
) != SIG_IGN
)
406 signal(SIGSEGV
, sig
);
407 if (signal(SIGTERM
, SIG_IGN
) != SIG_IGN
)
408 signal(SIGTERM
, sig
);
409 if (signal(SIGINT
, interrupt
) == SIG_IGN
)
410 signal(SIGINT
, SIG_IGN
);
411 set_operators(); /* /etc/group snarfed */
412 getfstab(); /* /etc/fstab snarfed */
415 * disk may end in / and this can confuse
418 i
= strlen(diskparam
) - 1;
419 if (i
> 1 && diskparam
[i
] == '/')
422 disk
= get_device_name(diskparam
);
423 if (!disk
) { /* null means the disk is some form
424 of LABEL= or UID= but it was not
426 msg("Cannot find a disk having %s\n", diskparam
);
427 msg("The ENTIRE dump is aborted.\n");
431 * disk can be either the full special file name,
432 * the suffix of the special file name,
433 * the special name missing the leading '/',
434 * the file system name with or without the leading '/'.
436 if ((dt
= fstabsearch(disk
)) != NULL
) {
437 /* if found then only one parameter (i.e. partition)
440 (void)fprintf(stderr
, "Unknown arguments to dump:");
442 (void)fprintf(stderr
, " %s", *argv
++);
443 (void)fprintf(stderr
, "\n");
444 msg("The ENTIRE dump is aborted.\n");
447 disk
= rawname(dt
->fs_spec
);
448 (void)strncpy(spcl
.c_dev
, dt
->fs_spec
, NAMELEN
);
449 (void)strncpy(spcl
.c_filesys
, dt
->fs_file
, NAMELEN
);
453 if (realpath(disk
, pathname
) == NULL
)
455 strcpy(pathname
, disk
);
457 * The argument could be now a mountpoint of
458 * a filesystem specified in fstab. Search for it.
460 if ((dt
= fstabsearch(pathname
)) != NULL
) {
461 disk
= rawname(dt
->fs_spec
);
462 (void)strncpy(spcl
.c_dev
, dt
->fs_spec
, NAMELEN
);
463 (void)strncpy(spcl
.c_filesys
, dt
->fs_file
, NAMELEN
);
466 * The argument was not found in the fstab
467 * assume that this is a subtree and search for it
469 dt
= fstabsearchdir(pathname
, directory
);
471 char name
[MAXPATHLEN
];
472 (void)strncpy(spcl
.c_dev
, dt
->fs_spec
, NAMELEN
);
473 (void)snprintf(name
, sizeof(name
), "%s (dir %s)",
474 dt
->fs_file
, directory
);
475 (void)strncpy(spcl
.c_filesys
, name
, NAMELEN
);
476 disk
= rawname(dt
->fs_spec
);
478 (void)strncpy(spcl
.c_dev
, disk
, NAMELEN
);
479 (void)strncpy(spcl
.c_filesys
, "an unlisted file system",
484 (void)strncpy(spcl
.c_dev
, disk
, NAMELEN
);
485 (void)strncpy(spcl
.c_filesys
, "an unlisted file system",
490 if (directory
[0] != 0) {
492 msg("Only level 0 dumps are allowed on a subdirectory\n");
493 msg("The ENTIRE dump is aborted.\n");
497 msg("You can't update the dumpdates file when dumping a subdirectory\n");
498 msg("The ENTIRE dump is aborted.\n");
502 spcl
.c_dev
[NAMELEN
-1] = '\0';
503 spcl
.c_filesys
[NAMELEN
-1] = '\0';
504 (void)gethostname(spcl
.c_host
, NAMELEN
);
505 spcl
.c_host
[NAMELEN
-1] = '\0';
506 spcl
.c_level
= level
- '0';
507 spcl
.c_type
= TS_TAPE
;
509 getdumptime(uflag
); /* dumpdates snarfed */
511 if (spcl
.c_ddate
== 0 && spcl
.c_level
) {
512 msg("WARNING: There is no inferior level dump on this filesystem\n");
513 msg("WARNING: Assuming a level 0 dump by default\n");
519 snprintf(tape
, MAXPATHLEN
, "%s%03d", tapeprefix
, tapeno
+ 1);
521 strncpy(tape
, tapeprefix
, MAXPATHLEN
);
522 tape
[MAXPATHLEN
- 1] = '\0';
525 if (STAT(tape
, &statbuf
) != -1)
526 fifoout
= statbuf
.st_mode
& S_IFIFO
;
531 msg("Date of this level %c dump: %s", level
,
532 ctime4(&spcl
.c_date
));
534 gThisDumpDate
= spcl
.c_date
;
537 msg("Date of last level %c dump: %s", lastlevel
,
538 ctime4(&spcl
.c_ddate
));
539 msg("Dumping %s (%s) ", disk
, spcl
.c_filesys
);
541 msgtail("to %s on host %s\n", tape
, host
);
543 msgtail("to %s\n", tape
);
544 } /* end of size estimate */
547 retval
= dump_fs_open(disk
, &fs
);
549 com_err(disk
, retval
, "while opening filesystem");
550 if (retval
== EXT2_ET_REV_TOO_HIGH
)
551 msg("Get a newer version of dump!\n");
552 msg("The ENTIRE dump is aborted.\n");
555 if (fs
->super
->s_rev_level
> DUMP_CURRENT_REV
) {
556 com_err(disk
, retval
, "while opening filesystem");
557 msg("Get a newer version of dump!\n");
558 msg("The ENTIRE dump is aborted.\n");
561 if ((diskfd
= OPEN(disk
, O_RDONLY
)) < 0) {
562 msg("Cannot open %s\n", disk
);
563 msg("The ENTIRE dump is aborted.\n");
566 /* if no user label specified, use ext2 filesystem label if available */
567 if (spcl
.c_label
[0] == '\0') {
569 if ( (lbl
= get_device_label(disk
)) != NULL
) {
570 strncpy(spcl
.c_label
, lbl
, LBLSIZE
);
571 spcl
.c_label
[LBLSIZE
-1] = '\0';
574 strcpy(spcl
.c_label
, "none"); /* safe strcpy. */
577 dev_bsize
= DEV_BSIZE
;
578 dev_bshift
= ffs(dev_bsize
) - 1;
579 if (dev_bsize
!= (1 << dev_bshift
))
580 quit("dev_bsize (%d) is not a power of 2", dev_bsize
);
581 tp_bshift
= ffs(TP_BSIZE
) - 1;
582 if (TP_BSIZE
!= (1 << tp_bshift
))
583 quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE
);
584 maxino
= fs
->super
->s_inodes_count
;
586 spcl
.c_flags
|= DR_NEWINODEFMT
;
588 #else /* __linux __*/
589 if ((diskfd
= open(disk
, O_RDONLY
)) < 0) {
590 msg("Cannot open %s\n", disk
);
591 msg("The ENTIRE dump is aborted.\n");
595 sblock
= (struct fs
*)sblock_buf
;
596 bread(SBOFF
, (char *) sblock
, SBSIZE
);
597 if (sblock
->fs_magic
!= FS_MAGIC
)
598 quit("bad sblock magic number\n");
599 dev_bsize
= sblock
->fs_fsize
/ fsbtodb(sblock
, 1);
600 dev_bshift
= ffs(dev_bsize
) - 1;
601 if (dev_bsize
!= (1 << dev_bshift
))
602 quit("dev_bsize (%d) is not a power of 2", dev_bsize
);
603 tp_bshift
= ffs(TP_BSIZE
) - 1;
604 if (TP_BSIZE
!= (1 << tp_bshift
))
605 quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE
);
607 if (sblock
->fs_inodefmt
>= FS_44INODEFMT
)
608 spcl
.c_flags
|= DR_NEWINODEFMT
;
610 maxino
= sblock
->fs_ipg
* sblock
->fs_ncg
;
611 #endif /* __linux__ */
612 mapsize
= roundup(howmany(maxino
, NBBY
), TP_BSIZE
);
613 usedinomap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
614 dumpdirmap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
615 dumpinomap
= (char *)calloc((unsigned) mapsize
, sizeof(char));
616 if (usedinomap
== NULL
|| dumpdirmap
== NULL
|| dumpinomap
== NULL
)
617 quit("out of memory allocating inode maps\n");
618 tapesize
= 2 * (howmany(mapsize
* sizeof(char), TP_BSIZE
) + 1);
620 nonodump
= spcl
.c_level
< honorlevel
;
623 msg("Label: %s\n", spcl
.c_label
);
626 msg("Compressing output at compression level %d\n",
631 (void)signal(SIGINFO
, statussig
);
635 msg("mapping (Pass I) [regular files]\n");
637 if (directory
[0] == 0)
638 anydirskipped
= mapfiles(maxino
, &tapesize
);
640 if (STAT(pathname
, &statbuf
) == -1) {
641 msg("File cannot be accessed (%s).\n", pathname
);
642 msg("The ENTIRE dump is aborted.\n");
645 filedev
= statbuf
.st_dev
;
646 if (!(statbuf
.st_mode
& S_IFDIR
)) /* is a file */
647 anydirskipped
= maponefile(maxino
, &tapesize
,
650 anydirskipped
= mapfilesfromdir(maxino
, &tapesize
,
656 /* check if file is available */
657 if (STAT(p
, &statbuf
) == -1) {
658 msg("File cannot be accessed (%s).\n", p
);
659 msg("The ENTIRE dump is aborted.\n");
662 /* check if file is on same unix partiton as the first
664 if (statbuf
.st_dev
!= filedev
) {
665 msg("Files are not on same file system (%s).\n", p
);
666 msg("The ENTIRE dump is aborted.\n");
669 /* check if file is a directory */
670 if (!(statbuf
.st_mode
& S_IFDIR
))
671 anydirskipped2
= maponefile(maxino
, &tapesize
,
672 p
+strlen(dt
->fs_file
));
674 /* read directory inodes.
675 * NOTE: nested directories are not recognized
676 * so inodes may be umped twice!
678 anydirskipped2
= mapfilesfromdir(maxino
, &tapesize
,
679 p
+strlen(dt
->fs_file
));
681 anydirskipped
= anydirskipped2
;
685 anydirskipped
= mapfiles(maxino
, &tapesize
);
689 msg("mapping (Pass II) [directories]\n");
690 while (anydirskipped
) {
691 anydirskipped
= mapdirs(maxino
, &tapesize
);
695 printf("%.0f\n", ((double)tapesize
+ 1 + ntrec
) * TP_BSIZE
);
697 } /* stop here for size estimate */
699 if (pipeout
|| unlimited
) {
700 tapesize
+= 1 + ntrec
; /* 1 map header + trailer blocks */
701 msg("estimated %ld tape blocks.\n", tapesize
);
706 fetapes
= (double) tapesize
/ blocksperfile
;
707 else if (cartridge
) {
708 /* Estimate number of tapes, assuming streaming stops at
709 the end of each block written, and not in mid-block.
710 Assume no erroneous blocks; this can be compensated
711 for with an artificially low tape size. */
713 ( (double) tapesize
/* blocks */
714 * TP_BSIZE
/* bytes/block */
715 * (1.0/density
) /* 0.1" / byte " */
717 (double) tapesize
/* blocks */
718 * (1.0/ntrec
) /* streaming-stops per block */
719 * 15.48 /* 0.1" / streaming-stop " */
720 ) * (1.0 / tsize
); /* tape / 0.1" " */
722 /* Estimate number of tapes, for old fashioned 9-track
724 int tenthsperirg
= (density
== 625) ? 3 : 7;
726 ( (double) tapesize
/* blocks */
727 * TP_BSIZE
/* bytes / block */
728 * (1.0/density
) /* 0.1" / byte " */
730 (double) tapesize
/* blocks */
731 * (1.0/ntrec
) /* IRG's / block */
732 * tenthsperirg
/* 0.1" / IRG " */
733 ) * (1.0 / tsize
); /* tape / 0.1" " */
735 etapes
= fetapes
; /* truncating assignment */
737 /* count the dumped inodes map on each additional tape */
738 tapesize
+= (etapes
- 1) *
739 (howmany(mapsize
* sizeof(char), TP_BSIZE
) + 1);
740 tapesize
+= etapes
+ ntrec
; /* headers + trailer blks */
741 msg("estimated %ld tape blocks on %3.2f tape(s).\n",
747 msg("writing QFA positions to %s\n", gTapeposfile
);
748 if ((gTapeposfd
= open(gTapeposfile
, O_RDWR
|O_CREAT
)) < 0)
749 quit("can't open tapeposfile\n");
750 /* print QFA-file header */
751 sprintf(gTps
, "%s\n%s\n%ld\n\n", QFA_MAGIC
, QFA_VERSION
, (unsigned long)spcl
.c_date
);
752 if (write(gTapeposfd
, gTps
, strlen(gTps
)) != strlen(gTps
))
753 quit("can't write tapeposfile\n");
754 sprintf(gTps
, "ino\ttapeno\ttapepos\n");
755 if (write(gTapeposfd
, gTps
, strlen(gTps
)) != strlen(gTps
))
756 quit("can't write tapeposfile\n");
761 * Allocate tape buffer.
765 "can't allocate tape buffers - try a smaller blocking factor.\n");
768 tstart_writing
= time(NULL
);
769 dumpmap(usedinomap
, TS_CLRI
, maxino
- 1);
771 msg("dumping (Pass III) [directories]\n");
772 dirty
= 0; /* XXX just to get gcc to shut up */
773 for (map
= dumpdirmap
, ino
= 1; ino
< maxino
; ino
++) {
774 if (((ino
- 1) % NBBY
) == 0) /* map is offset by 1 */
778 if ((dirty
& 1) == 0)
781 * Skip directory inodes deleted and maybe reallocated
784 if ((dp
->di_mode
& IFMT
) != IFDIR
)
788 * Skip directory inodes deleted and not yes reallocated...
790 if (dp
->di_nlink
== 0 || dp
->di_dtime
!= 0)
792 (void)dumpdirino(dp
, ino
);
794 (void)dumpino(dp
, ino
);
798 msg("dumping (Pass IV) [regular files]\n");
799 for (map
= dumpinomap
, ino
= 1; ino
< maxino
; ino
++) {
800 if (((ino
- 1) % NBBY
) == 0) /* map is offset by 1 */
804 if ((dirty
& 1) == 0)
807 * Skip inodes deleted and reallocated as directories.
810 if ((dp
->di_mode
& IFMT
) == IFDIR
)
814 * No need to check here for deleted and not yet reallocated
815 * inodes since this is done in dumpino().
818 (void)dumpino(dp
, ino
);
821 tend_writing
= time(NULL
);
822 spcl
.c_type
= TS_END
;
824 * Finish off the current tape record with trailer blocks, to ensure
825 * at least the data in the last partial record makes it to tape.
826 * Also make sure we write at least 1 trailer block.
828 for (i
= ntrec
- (spcl
.c_tapea
% ntrec
); i
; --i
)
829 writeheader(maxino
- 1);
833 if (pipeout
|| fifoout
)
834 msg("%ld tape blocks (%.2fMB)\n", spcl
.c_tapea
,
835 ((double)spcl
.c_tapea
* TP_BSIZE
/ 1048576));
837 msg("%ld tape blocks (%.2fMB) on %d volume(s)\n",
839 ((double)spcl
.c_tapea
* TP_BSIZE
/ 1048576),
842 /* report dump performance, avoid division by zero */
843 if (tend_writing
- tstart_writing
== 0)
844 msg("finished in less than a second\n");
846 msg("finished in %d seconds, throughput %d kBytes/sec\n",
847 tend_writing
- tstart_writing
,
848 spcl
.c_tapea
/ (tend_writing
- tstart_writing
));
851 msg("Date of this level %c dump: %s", level
,
852 spcl
.c_date
== 0 ? "the epoch\n" : ctime4(&spcl
.c_date
));
853 msg("Date this dump completed: %s", ctime(&tnow
));
855 msg("Average transfer rate: %ld kB/s\n", xferrate
/ tapeno
);
857 long tapekb
= bytes_written
/ 1024;
858 double rate
= .0005 + (double) spcl
.c_tapea
/ tapekb
;
859 msg("Wrote %ldkB uncompressed, %ldkB compressed, %1.3f:1\n",
860 spcl
.c_tapea
, tapekb
, rate
);
863 broadcast("DUMP IS DONE!\7\7\n");
864 msg("DUMP IS DONE\n");
867 return 0; /* gcc - shut up */
873 char white
[MAXPATHLEN
];
874 const char *ext2ver
, *ext2date
;
876 memset(white
, ' ', MAXPATHLEN
);
877 white
[MIN(strlen(__progname
), MAXPATHLEN
- 1)] = '\0';
880 ext2fs_get_library_version(&ext2ver
, &ext2date
);
881 fprintf(stderr
, "%s %s (using libext2fs %s of %s)\n",
882 __progname
, _DUMP_VERSION
, ext2ver
, ext2date
);
884 fprintf(stderr
, "%s %s\n", __progname
, _DUMP_VERSION
);
887 "usage:\t%s [-0123456789ac"
892 "] [-B records] [-b blocksize] [-d density]\n"
893 "\t%s [-e inode#,inode#,...] [-E file] [-f file] [-h level] "
897 "\n\t%s [-s feet] [-T date] "
903 __progname
, white
, white
, __progname
);
908 * Pick up a numeric argument. It must be nonnegative and in the given
909 * range (except that a vmax of 0 means unlimited).
912 numarg(const char *meaning
, long vmin
, long vmax
)
917 val
= strtol(optarg
, &p
, 10);
919 errx(X_STARTUP
, "illegal %s -- %s", meaning
, optarg
);
920 if (val
< vmin
|| (vmax
&& val
> vmax
))
921 errx(X_STARTUP
, "%s must be between %ld and %ld", meaning
, vmin
, vmax
);
935 if (pipeout
|| fifoout
)
936 quit("Signal on pipe: cannot recover\n");
937 msg("Rewriting attempted as response to unknown signal: %d.\n", signo
);
938 (void)fflush(stderr
);
939 (void)fflush(stdout
);
944 msg("SIGSEGV: ABORTING!\n");
945 (void)signal(SIGSEGV
, SIG_DFL
);
946 (void)kill(0, SIGSEGV
);
952 rawname(const char *cp
)
956 #else /* __linux__ */
957 static char rawbuf
[MAXPATHLEN
];
958 char *dp
= strrchr(cp
, '/');
962 (void)strncpy(rawbuf
, cp
, min(dp
-cp
, MAXPATHLEN
- 1));
963 rawbuf
[min(dp
-cp
, MAXPATHLEN
-1)] = '\0';
964 (void)strncat(rawbuf
, "/r", MAXPATHLEN
- 1 - strlen(rawbuf
));
965 (void)strncat(rawbuf
, dp
+ 1, MAXPATHLEN
- 1 - strlen(rawbuf
));
967 #endif /* __linux__ */
972 * Change set of key letters and ordered arguments into something
973 * getopt(3) will like.
976 obsolete(int *argcp
, char **argvp
[])
979 char *ap
, **argv
, *flagsp
=NULL
, **nargv
, *p
=NULL
;
985 /* Return if no arguments or first argument has leading dash. */
987 if (argc
== 1 || *ap
== '-')
990 /* Allocate space for new arguments. */
991 if ((*argvp
= nargv
= malloc((argc
+ 1) * sizeof(char *))) == NULL
||
992 (p
= flagsp
= malloc(strlen(ap
) + 2)) == NULL
)
993 err(X_STARTUP
, "malloc new args");
998 for (flags
= 0; *ap
; ++ap
) {
1012 if (*argv
== NULL
) {
1013 warnx("option requires an argument -- %c", *ap
);
1016 if ((nargv
[0] = malloc(strlen(*argv
) + 2 + 1)) == NULL
)
1017 err(X_STARTUP
, "malloc arg");
1020 (void)strcpy(&nargv
[0][2], *argv
);
1034 /* Terminate flags. */
1040 /* Copy remaining arguments. */
1041 while ((*nargv
++ = *argv
++));
1043 /* Update argument count. */
1044 *argcp
= nargv
- *argvp
- 1;
1048 * This tests whether an inode is in the exclude list
1051 exclude_ino(dump_ino_t ino
)
1054 if (iexclude_num
) { /* if there are inodes in the exclude list */
1055 int idx
; /* then check this inode against it */
1056 for (idx
= 0; idx
< iexclude_num
; idx
++)
1057 if (ino
== iexclude_list
[idx
])
1064 * This tests adds an inode to the exclusion list if it isn't already there
1067 do_exclude_ino(dump_ino_t ino
, const char *reason
)
1069 if (!exclude_ino(ino
)) {
1070 if (iexclude_num
== IEXCLUDE_MAXNUM
) {
1071 msg("Too many exclude options\n");
1072 msg("The ENTIRE dump is aborted.\n");
1076 msg("Added inode %u to exclude list (%s)\n",
1079 msg("Added inode %u to exclude list\n", ino
);
1080 iexclude_list
[iexclude_num
++] = ino
;
1085 do_exclude_ino_str(char * ino
) {
1089 inod
= strtoul(ino
, &r
, 10);
1090 if (*r
!= '\0' || inod
<= ROOTINO
) {
1091 msg("Invalid inode argument %s\n", ino
);
1092 msg("The ENTIRE dump is aborted.\n");
1095 do_exclude_ino(inod
, NULL
);
1099 * This reads a file containing one inode number per line and exclude them all
1102 do_exclude_from_file(char *file
) {
1104 char *p
, fname
[MAXPATHLEN
];
1107 if (!( f
= fopen(file
, "r")) ) {
1108 msg("Cannot open file for reading: %s\n", file
);
1109 msg("The ENTIRE dump is aborted.\n");
1112 while (( p
= fgets(fname
, MAXPATHLEN
, f
))) {
1113 if ( *p
&& *(p
+ strlen(p
) - 1) == '\n' ) /* possible null string */
1114 *(p
+ strlen(p
) - 1) = '\0';
1115 if ( !*p
) /* skip empty lines */
1117 do_exclude_ino_str(p
);