]> git.wh0rd.org - dump.git/blob - dump/main.c
Some corrections from Uwe Gohlke.
[dump.git] / dump / main.c
1 /*
2 * Ported to Linux's Second Extended File System as part of the
3 * dump and restore backup suit
4 * Remy Card <card@Linux.EU.Org>, 1994-1997
5 * Stelian Pop <stelian@popies.net>, 1999-2000
6 * Stelian Pop <stelian@popies.net> - AlcĂ´ve <www.alcove.com>, 2000-2002
7 */
8
9 /*-
10 * Copyright (c) 1980, 1991, 1993, 1994
11 * The Regents of the University of California. All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 */
37
38 #ifndef lint
39 static const char rcsid[] =
40 "$Id: main.c,v 1.88 2003/11/22 16:52:16 stelian Exp $";
41 #endif /* not lint */
42
43 #include <config.h>
44 #include <compatlfs.h>
45 #include <ctype.h>
46 #include <compaterr.h>
47 #include <fcntl.h>
48 #include <fstab.h>
49 #include <signal.h>
50 #include <stdio.h>
51 #include <stdlib.h>
52 #include <string.h>
53 #include <unistd.h>
54 #include <errno.h>
55 #include <mntent.h>
56
57 #include <sys/param.h>
58 #include <sys/time.h>
59 #include <time.h>
60 #ifdef __linux__
61 #ifdef HAVE_EXT2FS_EXT2_FS_H
62 #include <ext2fs/ext2_fs.h>
63 #else
64 #include <linux/ext2_fs.h>
65 #endif
66 #include <ext2fs/ext2fs.h>
67 #include <sys/stat.h>
68 #include <bsdcompat.h>
69 #include <linux/fs.h> /* for definition of BLKFLSBUF */
70 #elif defined sunos
71 #include <sys/vnode.h>
72
73 #include <ufs/inode.h>
74 #include <ufs/fs.h>
75 #else
76 #include <ufs/ufs/dinode.h>
77 #include <ufs/ffs/fs.h>
78 #endif
79
80 #include <protocols/dumprestore.h>
81
82 #include "dump.h"
83 #include "pathnames.h"
84 #include "bylabel.h"
85
86 #ifndef SBOFF
87 #define SBOFF (SBLOCK * DEV_BSIZE)
88 #endif
89
90 int abortifconnerr = 1; /* set to 1 if lib dumprmt.o should exit on connection errors
91 otherwise just print a message using msg */
92 /*
93 * Dump maps used to describe what is to be dumped.
94 */
95 int mapsize; /* size of the state maps */
96 char *usedinomap; /* map of allocated inodes */
97 char *dumpdirmap; /* map of directories to be dumped */
98 char *dumpinomap; /* map of files to be dumped */
99 char *metainomap; /* which of the inodes in dumpinomap will get
100 only their metadata dumped */
101
102 const char *disk; /* name of the disk file */
103 char tape[MAXPATHLEN];/* name of the tape file */
104 char *tapeprefix; /* prefix of the tape file */
105 char *dumpdates; /* name of the file containing dump date information*/
106 char lastlevel; /* dump level of previous dump */
107 char level; /* dump level of this dump */
108 int zipflag; /* which compression method */
109 int Afile = -1; /* archive file descriptor */
110 int AfileActive = 1;/* Afile flag */
111 int uflag; /* update flag */
112 int mflag; /* dump metadata only if possible */
113 int Mflag; /* multi-volume flag */
114 int qflag; /* quit on errors flag */
115 int vflag; /* verbose flag */
116 int breademax = 32; /* maximum number of bread errors before we quit */
117 char *eot_script; /* end of volume script fiag */
118 int diskfd; /* disk file descriptor */
119 int tapefd; /* tape file descriptor */
120 int pipeout; /* true => output to standard output */
121 int fifoout; /* true => output to fifo */
122 dump_ino_t curino; /* current inumber; used globally */
123 int newtape; /* new tape flag */
124 int density; /* density in 0.1" units */
125 long tapesize; /* estimated tape size, blocks */
126 long tsize; /* tape size in 0.1" units */
127 long asize; /* number of 0.1" units written on current tape */
128 int etapes; /* estimated number of tapes */
129 int nonodump; /* if set, do not honor UF_NODUMP user flags */
130 int unlimited; /* if set, write to end of medium */
131 int compressed; /* if set, dump is to be compressed */
132 long long bytes_written;/* total bytes written to tape */
133 long uncomprblks; /* uncompressed blocks written to tape */
134 int notify; /* notify operator flag */
135 int blockswritten; /* number of blocks written on current tape */
136 int tapeno; /* current tape number */
137 time_t tstart_writing; /* when started writing the first tape block */
138 time_t tend_writing; /* after writing the last tape block */
139 #ifdef __linux__
140 ext2_filsys fs;
141 #else
142 struct fs *sblock; /* the file system super block */
143 char sblock_buf[MAXBSIZE];
144 #endif
145 long xferrate; /* averaged transfer rate of all volumes */
146 long dev_bsize; /* block size of underlying disk device */
147 int dev_bshift; /* log2(dev_bsize) */
148 int tp_bshift; /* log2(TP_BSIZE) */
149 dump_ino_t volinfo[TP_NINOS];/* which inode on which volume archive info */
150
151 #ifdef USE_QFA
152 int gTapeposfd;
153 char *gTapeposfile;
154 char gTps[255];
155 int32_t gThisDumpDate;
156 #endif /* USE_QFA */
157
158 struct dumptime *dthead; /* head of the list version */
159 int nddates; /* number of records (might be zero) */
160 int ddates_in; /* we have read the increment file */
161 struct dumpdates **ddatev; /* the arrayfied version */
162
163 int notify = 0; /* notify operator flag */
164 int blockswritten = 0; /* number of blocks written on current tape */
165 int tapeno = 0; /* current tape number */
166 int density = 0; /* density in bytes/0.1" " <- this is for hilit19 */
167 int ntrec = NTREC; /* # blocks in each tape record */
168 int cartridge = 0; /* Assume non-cartridge tape */
169 #ifdef USE_QFA
170 int tapepos = 0; /* assume no QFA tapeposition needed by user */
171 #endif /* USE_QFA */
172 int dokerberos = 0; /* Use Kerberos authentication */
173 long dev_bsize = 1; /* recalculated below */
174 long blocksperfile; /* output blocks per file */
175 char *host = NULL; /* remote host (if any) */
176 int sizest = 0; /* return size estimate only */
177 int compressed = 0; /* use zlib to compress the output, compress level 1-9 */
178 long long bytes_written = 0; /* total bytes written */
179 long uncomprblks = 0;/* uncompressed blocks written */
180
181 long smtc_errno;
182
183 #ifdef __linux__
184 char *__progname;
185 #endif
186
187 int maxbsize = 1024*1024; /* XXX MAXBSIZE from sys/param.h */
188 static long numarg __P((const char *, long, long));
189 static void obsolete __P((int *, char **[]));
190 static void usage __P((void));
191 static void do_exclude_from_file __P((char *));
192 static void do_exclude_ino_str __P((char *));
193 static void incompat_flags __P((int, char, char));
194
195 static char* iexclude_bitmap = NULL; /* the inode exclude bitmap */
196 static unsigned int iexclude_bitmap_bytes = 0; /* size of bitmap in bytes */
197
198 int
199 main(int argc, char *argv[])
200 {
201 dump_ino_t ino;
202 int dirty;
203 struct dinode *dp;
204 struct mntent *dt;
205 char *map;
206 int ch;
207 int i, anydirskipped;
208 int aflag = 0, bflag = 0, Tflag = 0, honorlevel = 1;
209 dump_ino_t maxino;
210 struct STAT statbuf;
211 dev_t filedev = 0;
212 #ifdef __linux__
213 errcode_t retval;
214 char directory[MAXPATHLEN];
215 char pathname[MAXPATHLEN];
216 #endif
217 time_t tnow;
218 char *diskparam;
219 char *Apath = NULL;
220
221 spcl.c_label[0] = '\0';
222 spcl.c_date = time(NULL);
223
224 #ifdef __linux__
225 __progname = argv[0];
226 directory[0] = 0;
227 initialize_ext2_error_table();
228 #endif
229
230 tsize = 0; /* Default later, based on 'c' option for cart tapes */
231 unlimited = 1;
232 eot_script = NULL;
233 if ((tapeprefix = getenv("TAPE")) == NULL)
234 tapeprefix = _PATH_DEFTAPE;
235 dumpdates = _PATH_DUMPDATES;
236 if (TP_BSIZE / DEV_BSIZE == 0 || TP_BSIZE % DEV_BSIZE != 0)
237 quit("TP_BSIZE must be a multiple of DEV_BSIZE\n");
238 level = '0';
239
240 if (argc < 2)
241 usage();
242
243 obsolete(&argc, &argv);
244
245 #ifdef USE_QFA
246 gTapeposfd = -1;
247 #endif /* USE_QFA */
248
249 while ((ch = getopt(argc, argv,
250 "0123456789A:aB:b:cd:D:e:E:f:F:h:I:"
251 #ifdef HAVE_BZLIB
252 "j::"
253 #endif
254 "L:"
255 #ifdef KERBEROS
256 "k"
257 #endif
258 "mMnq"
259 #ifdef USE_QFA
260 "Q:"
261 #endif
262 "s:ST:uvWw"
263 #ifdef HAVE_LZO
264 "y"
265 #endif
266 #ifdef HAVE_ZLIB
267 "z::"
268 #endif
269 )) != -1)
270 switch (ch) {
271 /* dump level */
272 case '0': case '1': case '2': case '3': case '4':
273 case '5': case '6': case '7': case '8': case '9':
274 level = ch;
275 break;
276
277 case 'A': /* archive file */
278 Apath = optarg;
279 break;
280
281 case 'a': /* `auto-size', Write to EOM. */
282 unlimited = 1;
283 aflag = 1;
284 break;
285
286 case 'B': /* blocks per output file */
287 unlimited = 0;
288 blocksperfile = numarg("number of blocks per file",
289 1L, 0L);
290 break;
291
292 case 'b': /* blocks per tape write */
293 ntrec = numarg("number of blocks per write",
294 1L, 1048576L);
295 if (ntrec > maxbsize/1024) {
296 msg("Please choose a blocksize <= %dkB\n",
297 maxbsize/1024);
298 msg("The ENTIRE dump is aborted.\n");
299 exit(X_STARTUP);
300 }
301 bflag = 1;
302 break;
303
304 case 'c': /* Tape is cart. not 9-track */
305 unlimited = 0;
306 cartridge = 1;
307 break;
308
309 case 'd': /* density, in bits per inch */
310 unlimited = 0;
311 density = numarg("density", 10L, 327670L) / 10;
312 if (density >= 625 && !bflag)
313 ntrec = HIGHDENSITYTREC;
314 break;
315
316 case 'D': /* path of dumpdates file */
317 dumpdates = optarg;
318 break;
319
320 /* 04-Feb-00 ILC */
321 case 'e': /* exclude an inode */
322 {
323 char *p = optarg, *q;
324 while ((q = strchr(p, ','))) {
325 *q = '\0';
326 do_exclude_ino_str(p);
327 p = q + 1;
328 }
329 do_exclude_ino_str(p);
330 }
331 break;
332
333 case 'E': /* exclude inodes read from file */
334 do_exclude_from_file(optarg);
335 break;
336
337 case 'f': /* output file */
338 tapeprefix = optarg;
339 break;
340
341 case 'F': /* end of tape script */
342 eot_script = optarg;
343 break;
344
345 case 'h':
346 honorlevel = numarg("honor level", 0L, 10L);
347 break;
348
349 #ifdef HAVE_BZLIB
350 case 'j':
351 compressed = 2;
352 zipflag = COMPRESS_BZLIB;
353 if (optarg)
354 compressed = numarg("compress level", 1L, 9L);
355 break;
356 #endif /* HAVE_BZLIB */
357
358 case 'I':
359 breademax =
360 numarg ("number of errors to ignore", 0L, 0L);
361 break;
362
363 #ifdef KERBEROS
364 case 'k':
365 dokerberos = 1;
366 break;
367 #endif
368
369 case 'L':
370 /*
371 * Note that although there are LBLSIZE characters,
372 * the last must be '\0', so the limit on strlen()
373 * is really LBLSIZE-1.
374 */
375 strncpy(spcl.c_label, optarg, LBLSIZE);
376 spcl.c_label[LBLSIZE-1] = '\0';
377 if (strlen(optarg) > LBLSIZE-1) {
378 msg(
379 "WARNING Label `%s' is larger than limit of %d characters.\n",
380 optarg, LBLSIZE-1);
381 msg("WARNING: Using truncated label `%s'.\n",
382 spcl.c_label);
383 }
384 break;
385
386 case 'm': /* metadata only flag */
387 mflag = 1;
388 break;
389
390 case 'M': /* multi-volume flag */
391 Mflag = 1;
392 break;
393
394 case 'n': /* notify operators */
395 notify = 1;
396 break;
397
398 case 'q':
399 qflag = 1;
400 break;
401
402 #ifdef USE_QFA
403 case 'Q': /* create tapeposfile */
404 gTapeposfile = optarg;
405 tapepos = 1;
406 break;
407 #endif /* USE_QFA */
408
409 case 's': /* tape size, feet */
410 unlimited = 0;
411 tsize = numarg("tape size", 1L, 0L) * 12 * 10;
412 break;
413
414 case 'S':
415 sizest = 1; /* return size estimate only */
416 break;
417
418 case 'T': /* time of last dump */
419 spcl.c_ddate = unctime(optarg);
420 if (spcl.c_ddate < 0) {
421 msg("bad time \"%s\"\n", optarg);
422 msg("The ENTIRE dump is aborted.\n");
423 exit(X_STARTUP);
424 }
425 Tflag = 1;
426 lastlevel = '?';
427 break;
428
429 case 'u': /* update dumpdates */
430 uflag = 1;
431 break;
432
433 case 'v': /* verbose */
434 vflag = 1;
435 break;
436
437 case 'W': /* what to do */
438 case 'w':
439 lastdump(ch);
440 exit(X_FINOK); /* do nothing else */
441 #ifdef HAVE_LZO
442 case 'y':
443 compressed = 2;
444 zipflag = COMPRESS_LZO;
445 break;
446 #endif /* HAVE_LZO */
447
448 #ifdef HAVE_ZLIB
449 case 'z':
450 compressed = 2;
451 zipflag = COMPRESS_ZLIB;
452 if (optarg)
453 compressed = numarg("compress level", 1L, 9L);
454 break;
455 #endif /* HAVE_ZLIB */
456
457 default:
458 usage();
459 }
460 argc -= optind;
461 argv += optind;
462
463 if (argc < 1) {
464 msg("Must specify disk or filesystem\n");
465 msg("The ENTIRE dump is aborted.\n");
466 exit(X_STARTUP);
467 }
468 diskparam = *argv++;
469 if (strlen(diskparam) >= MAXPATHLEN) {
470 msg("Disk or filesystem name too long: %s\n", diskparam);
471 msg("The ENTIRE dump is aborted.\n");
472 exit(X_STARTUP);
473 }
474 argc--;
475 incompat_flags(Tflag && uflag, 'T', 'u');
476 incompat_flags(aflag && blocksperfile, 'a', 'B');
477 incompat_flags(aflag && cartridge, 'a', 'c');
478 incompat_flags(aflag && density, 'a', 'd');
479 incompat_flags(aflag && tsize, 'a', 's');
480
481 if (strcmp(tapeprefix, "-") == 0) {
482 pipeout++;
483 tapeprefix = "standard output";
484 }
485
486 if (blocksperfile && !compressed)
487 blocksperfile = blocksperfile / ntrec * ntrec; /* round down */
488 else if (!unlimited) {
489 /*
490 * Determine how to default tape size and density
491 *
492 * density tape size
493 * 9-track 1600 bpi (160 bytes/.1") 2300 ft.
494 * 9-track 6250 bpi (625 bytes/.1") 2300 ft.
495 * cartridge 8000 bpi (100 bytes/.1") 1700 ft.
496 * (450*4 - slop)
497 * hilit19 hits again: "
498 */
499 if (density == 0)
500 density = cartridge ? 100 : 160;
501 if (tsize == 0)
502 tsize = cartridge ? 1700L*120L : 2300L*120L;
503 }
504
505 {
506 int i;
507 char *n;
508
509 if ((n = strchr(tapeprefix, ':'))) {
510 for (i = 0; i < (n - tapeprefix); i++) {
511 if (tapeprefix[i] == '/')
512 break;
513 }
514 if (tapeprefix[i] != '/') {
515 host = tapeprefix;
516 tapeprefix = strchr(host, ':');
517 *tapeprefix++ = '\0';
518 #ifdef RDUMP
519 if (index(tapeprefix, '\n')) {
520 msg("invalid characters in tape\n");
521 msg("The ENTIRE dump is aborted.\n");
522 exit(X_STARTUP);
523 }
524 if (rmthost(host) == 0)
525 exit(X_STARTUP);
526 #else
527 msg("remote dump not enabled\n");
528 msg("The ENTIRE dump is aborted.\n");
529 exit(X_STARTUP);
530 #endif
531 }
532 }
533 }
534
535 (void)setuid(getuid()); /* rmthost() is the only reason to be setuid */
536 if (Apath && (Afile = open(Apath, O_WRONLY|O_CREAT|O_TRUNC,
537 S_IRUSR | S_IWUSR | S_IRGRP |
538 S_IWGRP | S_IROTH | S_IWOTH)) < 0) {
539 msg("Cannot open %s for writing: %s\n",
540 optarg, strerror(errno));
541 msg("The ENTIRE dump is aborted.\n");
542 exit(X_STARTUP);
543 }
544
545 if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
546 signal(SIGHUP, sig);
547 if (signal(SIGTRAP, SIG_IGN) != SIG_IGN)
548 signal(SIGTRAP, sig);
549 if (signal(SIGFPE, SIG_IGN) != SIG_IGN)
550 signal(SIGFPE, sig);
551 if (signal(SIGBUS, SIG_IGN) != SIG_IGN)
552 signal(SIGBUS, sig);
553 if (signal(SIGSEGV, SIG_IGN) != SIG_IGN)
554 signal(SIGSEGV, sig);
555 if (signal(SIGTERM, SIG_IGN) != SIG_IGN)
556 signal(SIGTERM, sig);
557 if (signal(SIGINT, interrupt) == SIG_IGN)
558 signal(SIGINT, SIG_IGN);
559 #ifdef SIGXCPU
560 signal(SIGXCPU, SIG_IGN);
561 #endif /* SIGXCPU */
562 #ifdef SIGXFSZ
563 signal(SIGXFSZ, SIG_IGN);
564 #endif /* SIGXFSZ */
565
566 set_operators(); /* /etc/group snarfed */
567 getfstab(); /* /etc/fstab snarfed */
568
569 /*
570 * disk may end in / and this can confuse
571 * fstabsearch.
572 */
573 i = strlen(diskparam) - 1;
574 if (i > 1 && diskparam[i] == '/')
575 if (!(i == 6 && !strcmp(diskparam, "LABEL=/")))
576 diskparam[i] = '\0';
577
578 disk = get_device_name(diskparam);
579 if (!disk) { /* null means the disk is some form
580 of LABEL= or UID= but it was not
581 found */
582 msg("Cannot find a disk having %s\n", diskparam);
583 msg("The ENTIRE dump is aborted.\n");
584 exit(X_STARTUP);
585 }
586 /*
587 * disk can be either the full special file name,
588 * the suffix of the special file name,
589 * the special name missing the leading '/',
590 * the file system name with or without the leading '/'.
591 */
592 if ((dt = fstabsearch(disk)) != NULL) {
593 /* if found then only one parameter (i.e. partition)
594 * is allowed */
595 if (argc >= 1) {
596 (void)fprintf(stderr, "Unknown arguments to dump:");
597 while (argc--)
598 (void)fprintf(stderr, " %s", *argv++);
599 (void)fprintf(stderr, "\n");
600 msg("The ENTIRE dump is aborted.\n");
601 exit(X_STARTUP);
602 }
603 disk = rawname(dt->mnt_fsname);
604 (void)strncpy(spcl.c_dev, dt->mnt_fsname, NAMELEN);
605 (void)strncpy(spcl.c_filesys, dt->mnt_dir, NAMELEN);
606 } else {
607 #ifdef __linux__
608 #ifdef HAVE_REALPATH
609 if (realpath(disk, pathname) == NULL)
610 #endif
611 strcpy(pathname, disk);
612 /*
613 * The argument could be now a mountpoint of
614 * a filesystem specified in fstab. Search for it.
615 */
616 if ((dt = fstabsearch(pathname)) != NULL) {
617 disk = rawname(dt->mnt_fsname);
618 (void)strncpy(spcl.c_dev, dt->mnt_fsname, NAMELEN);
619 (void)strncpy(spcl.c_filesys, dt->mnt_dir, NAMELEN);
620 } else {
621 /*
622 * The argument was not found in the fstab
623 * assume that this is a subtree and search for it
624 */
625 dt = fstabsearchdir(pathname, directory);
626 if (dt != NULL) {
627 char name[MAXPATHLEN];
628 (void)strncpy(spcl.c_dev, dt->mnt_fsname, NAMELEN);
629 (void)snprintf(name, sizeof(name), "%s (dir %s)",
630 dt->mnt_dir, directory);
631 (void)strncpy(spcl.c_filesys, name, NAMELEN);
632 disk = rawname(dt->mnt_fsname);
633 } else {
634 (void)strncpy(spcl.c_dev, disk, NAMELEN);
635 (void)strncpy(spcl.c_filesys, "an unlisted file system",
636 NAMELEN);
637 }
638 }
639 #else
640 (void)strncpy(spcl.c_dev, disk, NAMELEN);
641 (void)strncpy(spcl.c_filesys, "an unlisted file system",
642 NAMELEN);
643 #endif
644 }
645
646 if (directory[0] != 0) {
647 if (level != '0') {
648 msg("Only level 0 dumps are allowed on a subdirectory\n");
649 msg("The ENTIRE dump is aborted.\n");
650 exit(X_STARTUP);
651 }
652 if (uflag) {
653 msg("You can't update the dumpdates file when dumping a subdirectory\n");
654 msg("The ENTIRE dump is aborted.\n");
655 exit(X_STARTUP);
656 }
657 }
658 spcl.c_dev[NAMELEN-1] = '\0';
659 spcl.c_filesys[NAMELEN-1] = '\0';
660 (void)gethostname(spcl.c_host, NAMELEN);
661 spcl.c_host[NAMELEN-1] = '\0';
662 spcl.c_level = level - '0';
663 spcl.c_type = TS_TAPE;
664 if (!Tflag)
665 getdumptime(uflag); /* dumpdates snarfed */
666
667 if (spcl.c_ddate == 0 && spcl.c_level) {
668 msg("WARNING: There is no inferior level dump on this filesystem\n");
669 msg("WARNING: Assuming a level 0 dump by default\n");
670 level = '0';
671 spcl.c_level = 0;
672 }
673
674 if (Mflag)
675 snprintf(tape, MAXPATHLEN, "%s%03d", tapeprefix, tapeno + 1);
676 else
677 strncpy(tape, tapeprefix, MAXPATHLEN);
678 tape[MAXPATHLEN - 1] = '\0';
679
680 if (!pipeout) {
681 if (STAT(tape, &statbuf) != -1)
682 fifoout= statbuf.st_mode & S_IFIFO;
683 }
684
685 if (!sizest) {
686
687 msg("Date of this level %c dump: %s", level,
688 ctime4(&spcl.c_date));
689 #ifdef USE_QFA
690 gThisDumpDate = spcl.c_date;
691 #endif
692 if (spcl.c_ddate)
693 msg("Date of last level %c dump: %s", lastlevel,
694 ctime4(&spcl.c_ddate));
695 msg("Dumping %s (%s) ", disk, spcl.c_filesys);
696 if (host)
697 msgtail("to %s on host %s\n", tape, host);
698 else
699 msgtail("to %s\n", tape);
700 } /* end of size estimate */
701
702 #ifdef __linux__
703 if ((diskfd = OPEN(disk, O_RDONLY)) < 0) {
704 msg("Cannot open %s\n", disk);
705 msg("The ENTIRE dump is aborted.\n");
706 exit(X_STARTUP);
707 }
708 #ifdef BLKFLSBUF
709 (void)ioctl(diskfd, BLKFLSBUF, 0);
710 #endif
711 retval = dump_fs_open(disk, &fs);
712 if (retval) {
713 com_err(disk, retval, "while opening filesystem");
714 if (retval == EXT2_ET_REV_TOO_HIGH)
715 msg("Get a newer version of dump!\n");
716 msg("The ENTIRE dump is aborted.\n");
717 exit(X_STARTUP);
718 }
719 if (fs->super->s_rev_level > DUMP_CURRENT_REV) {
720 com_err(disk, retval, "while opening filesystem");
721 msg("Get a newer version of dump!\n");
722 msg("The ENTIRE dump is aborted.\n");
723 exit(X_STARTUP);
724 }
725 /* if no user label specified, use ext2 filesystem label if available */
726 if (spcl.c_label[0] == '\0') {
727 const char *lbl;
728 if ( (lbl = get_device_label(disk)) != NULL) {
729 strncpy(spcl.c_label, lbl, LBLSIZE);
730 spcl.c_label[LBLSIZE-1] = '\0';
731 }
732 else
733 strcpy(spcl.c_label, "none"); /* safe strcpy. */
734 }
735 sync();
736 dev_bsize = DEV_BSIZE;
737 dev_bshift = ffs(dev_bsize) - 1;
738 if (dev_bsize != (1 << dev_bshift))
739 quit("dev_bsize (%d) is not a power of 2", dev_bsize);
740 tp_bshift = ffs(TP_BSIZE) - 1;
741 if (TP_BSIZE != (1 << tp_bshift))
742 quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE);
743 maxino = fs->super->s_inodes_count + 1;
744 spcl.c_flags |= DR_NEWINODEFMT;
745 #else /* __linux __*/
746 if ((diskfd = open(disk, O_RDONLY)) < 0) {
747 msg("Cannot open %s\n", disk);
748 msg("The ENTIRE dump is aborted.\n");
749 exit(X_STARTUP);
750 }
751 sync();
752 sblock = (struct fs *)sblock_buf;
753 bread(SBOFF, (char *) sblock, SBSIZE);
754 if (sblock->fs_magic != FS_MAGIC)
755 quit("bad sblock magic number\n");
756 dev_bsize = sblock->fs_fsize / fsbtodb(sblock, 1);
757 dev_bshift = ffs(dev_bsize) - 1;
758 if (dev_bsize != (1 << dev_bshift))
759 quit("dev_bsize (%d) is not a power of 2", dev_bsize);
760 tp_bshift = ffs(TP_BSIZE) - 1;
761 if (TP_BSIZE != (1 << tp_bshift))
762 quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE);
763 #ifdef FS_44INODEFMT
764 if (sblock->fs_inodefmt >= FS_44INODEFMT)
765 spcl.c_flags |= DR_NEWINODEFMT;
766 #endif
767 maxino = sblock->fs_ipg * sblock->fs_ncg;
768 #endif /* __linux__ */
769 mapsize = roundup(howmany(maxino, NBBY), TP_BSIZE);
770 usedinomap = (char *)calloc((unsigned) mapsize, sizeof(char));
771 dumpdirmap = (char *)calloc((unsigned) mapsize, sizeof(char));
772 dumpinomap = (char *)calloc((unsigned) mapsize, sizeof(char));
773 metainomap = (char *)calloc((unsigned) mapsize, sizeof(char));
774 if (usedinomap == NULL || dumpdirmap == NULL ||
775 dumpinomap == NULL || metainomap == NULL)
776 quit("out of memory allocating inode maps\n");
777 tapesize = 2 * (howmany(mapsize * sizeof(char), TP_BSIZE) + 1);
778
779 nonodump = spcl.c_level < honorlevel;
780
781 if (!sizest) {
782 msg("Label: %s\n", spcl.c_label);
783
784 msg("Writing %d Kilobyte records\n", ntrec);
785
786 if (compressed) {
787 if (zipflag == COMPRESS_LZO)
788 msg("Compressing output (lzo)\n");
789 else
790 msg("Compressing output at compression level %d (%s)\n",
791 compressed, zipflag == COMPRESS_ZLIB ? "zlib" : "bzlib");
792 }
793 }
794
795 #if defined(SIGINFO)
796 (void)signal(SIGINFO, statussig);
797 #endif
798
799 if (!sizest)
800 msg("mapping (Pass I) [regular files]\n");
801 #ifdef __linux__
802 if (directory[0] == 0)
803 anydirskipped = mapfiles(maxino, &tapesize);
804 else {
805 if (LSTAT(pathname, &statbuf) == -1) {
806 msg("File cannot be accessed (%s).\n", pathname);
807 msg("The ENTIRE dump is aborted.\n");
808 exit(X_STARTUP);
809 }
810 filedev = statbuf.st_dev;
811 if (!(statbuf.st_mode & S_IFDIR)) /* is a file */
812 anydirskipped = maponefile(maxino, &tapesize,
813 directory);
814 else
815 anydirskipped = mapfilesfromdir(maxino, &tapesize,
816 directory);
817 }
818 while (argc--) {
819 int anydirskipped2;
820 char *p = *argv;
821 /* check if file is available */
822 if (LSTAT(p, &statbuf) == -1) {
823 msg("File cannot be accessed (%s).\n", p);
824 msg("The ENTIRE dump is aborted.\n");
825 exit(X_STARTUP);
826 }
827 /* check if file is on same unix partiton as the first
828 * argument */
829 if (statbuf.st_dev != filedev) {
830 msg("Files are not on same file system (%s).\n", p);
831 msg("The ENTIRE dump is aborted.\n");
832 exit(X_STARTUP);
833 }
834 /* check if file is a directory */
835 if (!(statbuf.st_mode & S_IFDIR))
836 anydirskipped2 = maponefile(maxino, &tapesize,
837 p+strlen(dt->mnt_dir));
838 else
839 /* read directory inodes.
840 * NOTE: nested directories are not recognized
841 * so inodes may be umped twice!
842 */
843 anydirskipped2 = mapfilesfromdir(maxino, &tapesize,
844 p+strlen(dt->mnt_dir));
845 if (!anydirskipped)
846 anydirskipped = anydirskipped2;
847 argv++;
848 }
849 #else
850 anydirskipped = mapfiles(maxino, &tapesize);
851 #endif
852
853 if (!sizest)
854 msg("mapping (Pass II) [directories]\n");
855 while (anydirskipped) {
856 anydirskipped = mapdirs(maxino, &tapesize);
857 }
858
859 if (sizest) {
860 printf("%.0f\n", ((double)tapesize + 1 + ntrec) * TP_BSIZE);
861 exit(X_FINOK);
862 } /* stop here for size estimate */
863
864 if (pipeout || unlimited) {
865 tapesize += 1 + ntrec; /* 1 map header + trailer blocks */
866 msg("estimated %ld blocks.\n", tapesize);
867 } else {
868 double fetapes;
869
870 if (blocksperfile)
871 fetapes = (double) tapesize / blocksperfile;
872 else if (cartridge) {
873 /* Estimate number of tapes, assuming streaming stops at
874 the end of each block written, and not in mid-block.
875 Assume no erroneous blocks; this can be compensated
876 for with an artificially low tape size. */
877 fetapes =
878 ( (double) tapesize /* blocks */
879 * TP_BSIZE /* bytes/block */
880 * (1.0/density) /* 0.1" / byte " */
881 +
882 (double) tapesize /* blocks */
883 * (1.0/ntrec) /* streaming-stops per block */
884 * 15.48 /* 0.1" / streaming-stop " */
885 ) * (1.0 / tsize ); /* tape / 0.1" " */
886 } else {
887 /* Estimate number of tapes, for old fashioned 9-track
888 tape */
889 int tenthsperirg = (density == 625) ? 3 : 7;
890 fetapes =
891 ( (double) tapesize /* blocks */
892 * TP_BSIZE /* bytes / block */
893 * (1.0/density) /* 0.1" / byte " */
894 +
895 (double) tapesize /* blocks */
896 * (1.0/ntrec) /* IRG's / block */
897 * tenthsperirg /* 0.1" / IRG " */
898 ) * (1.0 / tsize ); /* tape / 0.1" " */
899 }
900 etapes = fetapes; /* truncating assignment */
901 etapes++;
902 /* count the dumped inodes map on each additional tape */
903 tapesize += (etapes - 1) *
904 (howmany(mapsize * sizeof(char), TP_BSIZE) + 1);
905 tapesize += etapes + ntrec; /* headers + trailer blks */
906 msg("estimated %ld blocks on %3.2f tape(s).\n",
907 tapesize, fetapes);
908 }
909
910 #ifdef USE_QFA
911 if (tapepos) {
912 msg("writing QFA positions to %s\n", gTapeposfile);
913 if ((gTapeposfd = open(gTapeposfile,
914 O_WRONLY|O_CREAT|O_TRUNC,
915 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP
916 | S_IROTH | S_IWOTH)) < 0)
917 quit("can't open tapeposfile\n");
918 /* print QFA-file header */
919 snprintf(gTps, sizeof(gTps), "%s\n%s\n%ld\n\n", QFA_MAGIC, QFA_VERSION, (unsigned long)spcl.c_date);
920 gTps[sizeof(gTps) - 1] = '\0';
921 if (write(gTapeposfd, gTps, strlen(gTps)) != (ssize_t)strlen(gTps))
922 quit("can't write tapeposfile\n");
923 sprintf(gTps, "ino\ttapeno\ttapepos\n");
924 if (write(gTapeposfd, gTps, strlen(gTps)) != (ssize_t)strlen(gTps))
925 quit("can't write tapeposfile\n");
926 }
927 #endif /* USE_QFA */
928
929 /*
930 * Allocate tape buffer.
931 */
932 if (!alloctape())
933 quit(
934 "can't allocate tape buffers - try a smaller blocking factor.\n");
935
936 startnewtape(1);
937 tstart_writing = time(NULL);
938 dumpmap(usedinomap, TS_CLRI, maxino - 1);
939
940 msg("dumping (Pass III) [directories]\n");
941 dirty = 0; /* XXX just to get gcc to shut up */
942 for (map = dumpdirmap, ino = 1; ino < maxino; ino++) {
943 if (((ino - 1) % NBBY) == 0) /* map is offset by 1 */
944 dirty = *map++;
945 else
946 dirty >>= 1;
947 if ((dirty & 1) == 0)
948 continue;
949 /*
950 * Skip directory inodes deleted and maybe reallocated
951 */
952 dp = getino(ino);
953 if ((dp->di_mode & IFMT) != IFDIR)
954 continue;
955 #ifdef __linux__
956 /*
957 * Skip directory inodes deleted and not yes reallocated...
958 */
959 if (dp->di_nlink == 0 || dp->di_dtime != 0)
960 continue;
961 if (vflag)
962 msg("dumping directory inode %lu\n", ino);
963 (void)dumpdirino(dp, ino);
964 #else
965 (void)dumpino(dp, ino);
966 #endif
967 }
968
969 msg("dumping (Pass IV) [regular files]\n");
970 for (map = dumpinomap, ino = 1; ino < maxino; ino++) {
971 if (((ino - 1) % NBBY) == 0) /* map is offset by 1 */
972 dirty = *map++;
973 else
974 dirty >>= 1;
975 if ((dirty & 1) == 0)
976 continue;
977 /*
978 * Skip inodes deleted and reallocated as directories.
979 */
980 dp = getino(ino);
981 if ((dp->di_mode & IFMT) == IFDIR)
982 continue;
983 #ifdef __linux__
984 /*
985 * No need to check here for deleted and not yet reallocated
986 * inodes since this is done in dumpino().
987 */
988 #endif
989 if (vflag) {
990 if (mflag && TSTINO(ino, metainomap))
991 msg("dumping regular inode %lu (meta only)\n", ino);
992 else
993 msg("dumping regular inode %lu\n", ino);
994 }
995 (void)dumpino(dp, ino, mflag && TSTINO(ino, metainomap));
996 }
997
998 tend_writing = time(NULL);
999 spcl.c_type = TS_END;
1000
1001 if (Afile >= 0) {
1002 volinfo[1] = ROOTINO;
1003 memcpy(spcl.c_inos, volinfo, TP_NINOS * sizeof(dump_ino_t));
1004 spcl.c_flags |= DR_INODEINFO;
1005 }
1006
1007 /*
1008 * Finish off the current tape record with trailer blocks, to ensure
1009 * at least the data in the last partial record makes it to tape.
1010 * Also make sure we write at least 1 trailer block.
1011 */
1012 for (i = ntrec - (spcl.c_tapea % ntrec); i; --i)
1013 writeheader(maxino - 1);
1014
1015 tnow = trewind();
1016
1017 if (pipeout || fifoout)
1018 msg("%ld blocks (%.2fMB)\n", spcl.c_tapea,
1019 ((double)spcl.c_tapea * TP_BSIZE / 1048576));
1020 else
1021 msg("%ld blocks (%.2fMB) on %d volume(s)\n",
1022 spcl.c_tapea,
1023 ((double)spcl.c_tapea * TP_BSIZE / 1048576),
1024 spcl.c_volume);
1025
1026 /* report dump performance, avoid division by zero */
1027 if (tend_writing - tstart_writing == 0)
1028 msg("finished in less than a second\n");
1029 else
1030 msg("finished in %d seconds, throughput %d kBytes/sec\n",
1031 tend_writing - tstart_writing,
1032 spcl.c_tapea / (tend_writing - tstart_writing));
1033
1034 putdumptime();
1035 msg("Date of this level %c dump: %s", level,
1036 spcl.c_date == 0 ? "the epoch\n" : ctime4(&spcl.c_date));
1037 msg("Date this dump completed: %s", ctime(&tnow));
1038
1039 msg("Average transfer rate: %ld kB/s\n", xferrate / tapeno);
1040 if (compressed) {
1041 long tapekb = bytes_written / 1024;
1042 double rate = .0005 + (double) spcl.c_tapea / tapekb;
1043 msg("Wrote %ldkB uncompressed, %ldkB compressed, %1.3f:1\n",
1044 spcl.c_tapea, tapekb, rate);
1045 }
1046
1047 if (Afile >= 0)
1048 msg("Archiving dump to %s\n", Apath);
1049
1050 broadcast("DUMP IS DONE!\7\7\n");
1051 msg("DUMP IS DONE\n");
1052 Exit(X_FINOK);
1053 /* NOTREACHED */
1054 return 0; /* gcc - shut up */
1055 }
1056
1057 static void
1058 usage(void)
1059 {
1060 char white[MAXPATHLEN];
1061 const char *ext2ver, *ext2date;
1062
1063 memset(white, ' ', MAXPATHLEN);
1064 white[MIN(strlen(__progname), MAXPATHLEN - 1)] = '\0';
1065
1066 #ifdef __linux__
1067 ext2fs_get_library_version(&ext2ver, &ext2date);
1068 fprintf(stderr, "%s %s (using libext2fs %s of %s)\n",
1069 __progname, _DUMP_VERSION, ext2ver, ext2date);
1070 #else
1071 fprintf(stderr, "%s %s\n", __progname, _DUMP_VERSION);
1072 #endif
1073 fprintf(stderr,
1074 "usage:\t%s [-0123456789ac"
1075 #ifdef KERBEROS
1076 "k"
1077 #endif
1078 "mMnqSuv"
1079 "] [-A file] [-B records] [-b blocksize]\n"
1080 "\t%s [-d density] [-D file] [-e inode#,inode#,...] [-E file]\n"
1081 "\t%s [-f file] [-h level] [-I nr errors] "
1082 #ifdef HAVE_BZLIB
1083 "[-j zlevel] "
1084 #endif
1085 #ifdef USE_QFA
1086 "[-Q file]\n"
1087 #endif
1088 "\t%s [-s feet] "
1089 "[-T date] "
1090 #ifdef HAVE_LZO
1091 "[-y] "
1092 #endif
1093 #ifdef HAVE_ZLIB
1094 "[-z zlevel] "
1095 #endif
1096 "filesystem\n"
1097 "\t%s [-W | -w]\n",
1098 __progname, white, white, white, __progname);
1099 exit(X_STARTUP);
1100 }
1101
1102 /*
1103 * Pick up a numeric argument. It must be nonnegative and in the given
1104 * range (except that a vmax of 0 means unlimited).
1105 */
1106 static long
1107 numarg(const char *meaning, long vmin, long vmax)
1108 {
1109 char *p;
1110 long val;
1111
1112 val = strtol(optarg, &p, 10);
1113 if (*p)
1114 errx(X_STARTUP, "illegal %s -- %s", meaning, optarg);
1115 if (val < vmin || (vmax && val > vmax))
1116 errx(X_STARTUP, "%s must be between %ld and %ld", meaning, vmin, vmax);
1117 return (val);
1118 }
1119
1120 void
1121 sig(int signo)
1122 {
1123 switch(signo) {
1124 case SIGALRM:
1125 case SIGBUS:
1126 case SIGFPE:
1127 case SIGHUP:
1128 case SIGTERM:
1129 case SIGTRAP:
1130 if (pipeout || fifoout)
1131 quit("Signal on pipe: cannot recover\n");
1132 msg("Rewriting attempted as response to unknown signal: %d.\n", signo);
1133 (void)fflush(stderr);
1134 (void)fflush(stdout);
1135 close_rewind();
1136 exit(X_REWRITE);
1137 /* NOTREACHED */
1138 case SIGSEGV:
1139 msg("SIGSEGV: ABORTING!\n");
1140 (void)signal(SIGSEGV, SIG_DFL);
1141 (void)kill(0, SIGSEGV);
1142 /* NOTREACHED */
1143 }
1144 }
1145
1146 const char *
1147 rawname(const char *cp)
1148 {
1149 #ifdef __linux__
1150 return cp;
1151 #else /* __linux__ */
1152 static char rawbuf[MAXPATHLEN];
1153 char *dp = strrchr(cp, '/');
1154
1155 if (dp == NULL)
1156 return (NULL);
1157 (void)strncpy(rawbuf, cp, min(dp-cp, MAXPATHLEN - 1));
1158 rawbuf[min(dp-cp, MAXPATHLEN-1)] = '\0';
1159 (void)strncat(rawbuf, "/r", MAXPATHLEN - 1 - strlen(rawbuf));
1160 (void)strncat(rawbuf, dp + 1, MAXPATHLEN - 1 - strlen(rawbuf));
1161 return (rawbuf);
1162 #endif /* __linux__ */
1163 }
1164
1165 /*
1166 * obsolete --
1167 * Change set of key letters and ordered arguments into something
1168 * getopt(3) will like.
1169 */
1170 static void
1171 obsolete(int *argcp, char **argvp[])
1172 {
1173 int argc, flags;
1174 char *ap, **argv, *flagsp=NULL, **nargv, *p=NULL;
1175
1176 /* Setup. */
1177 argv = *argvp;
1178 argc = *argcp;
1179
1180 /* Return if no arguments or first argument has leading dash. */
1181 ap = argv[1];
1182 if (argc == 1 || *ap == '-')
1183 return;
1184
1185 /* Allocate space for new arguments. */
1186 if ((*argvp = nargv = malloc((argc + 1) * sizeof(char *))) == NULL ||
1187 (p = flagsp = malloc(strlen(ap) + 2)) == NULL)
1188 err(X_STARTUP, "malloc new args");
1189
1190 *nargv++ = *argv;
1191 argv += 2;
1192
1193 for (flags = 0; *ap; ++ap) {
1194 switch (*ap) {
1195 case 'A':
1196 case 'B':
1197 case 'b':
1198 case 'd':
1199 case 'D':
1200 case 'e':
1201 case 'E':
1202 case 'f':
1203 case 'F':
1204 case 'h':
1205 case 'L':
1206 case 'Q':
1207 case 's':
1208 case 'T':
1209 if (*argv == NULL) {
1210 warnx("option requires an argument -- %c", *ap);
1211 usage();
1212 }
1213 if ((nargv[0] = malloc(strlen(*argv) + 2 + 1)) == NULL)
1214 err(X_STARTUP, "malloc arg");
1215 nargv[0][0] = '-';
1216 nargv[0][1] = *ap;
1217 (void)strcpy(&nargv[0][2], *argv);
1218 ++argv;
1219 ++nargv;
1220 break;
1221 default:
1222 if (!flags) {
1223 *p++ = '-';
1224 flags = 1;
1225 }
1226 *p++ = *ap;
1227 break;
1228 }
1229 }
1230
1231 /* Terminate flags. */
1232 if (flags) {
1233 *p = '\0';
1234 *nargv++ = flagsp;
1235 }
1236
1237 /* Copy remaining arguments. */
1238 while ((*nargv++ = *argv++));
1239
1240 /* Update argument count. */
1241 *argcp = nargv - *argvp - 1;
1242 }
1243
1244 /*
1245 * This tests whether an inode is in the exclude bitmap
1246 */
1247 int
1248 exclude_ino(dump_ino_t ino)
1249 {
1250 /* if the inode exclude bitmap exists and covers given inode */
1251 if (iexclude_bitmap && iexclude_bitmap_bytes > ino / 8) {
1252 /* then check this inode against it */
1253 int idx = iexclude_bitmap[ino / 8];
1254 if (idx & (1 << (ino % 8)))
1255 return 1;
1256 }
1257 return 0;
1258 }
1259
1260 /*
1261 * This adds an inode to the exclusion bitmap if it isn't already there
1262 */
1263 void
1264 do_exclude_ino(dump_ino_t ino, const char *reason)
1265 {
1266 if (exclude_ino(ino))
1267 return;
1268
1269 if (vflag) {
1270 if (reason)
1271 msg("Excluding inode %u (%s) from dump\n", ino, reason);
1272 else
1273 msg("Excluding inode %u from dump\n", ino);
1274 }
1275
1276 /* check for enough mem; initialize */
1277 if ((ino/8 + 1) > iexclude_bitmap_bytes) {
1278 if (iexclude_bitmap_bytes == 0) {
1279 iexclude_bitmap_bytes = 2 * (ino/8 + 1);
1280 iexclude_bitmap = (char*) malloc(iexclude_bitmap_bytes);
1281 if (iexclude_bitmap == NULL) {
1282 msg("allocating memory failed\n");
1283 exit(X_STARTUP);
1284 }
1285 unsigned int j;
1286 for (j = 0; j < iexclude_bitmap_bytes; j++)
1287 iexclude_bitmap[j] = 0;
1288 }
1289 else {
1290 unsigned int oldsize = iexclude_bitmap_bytes;
1291 iexclude_bitmap_bytes *=
1292 (ino / 8 + 1) / iexclude_bitmap_bytes + 1;
1293 iexclude_bitmap = (char*) realloc(iexclude_bitmap,
1294 iexclude_bitmap_bytes);
1295 if (iexclude_bitmap == NULL) {
1296 msg("allocating memory failed\n");
1297 exit(X_STARTUP);
1298 }
1299 for( ; oldsize < iexclude_bitmap_bytes; oldsize++)
1300 iexclude_bitmap[oldsize] = 0;
1301 }
1302 }
1303
1304 iexclude_bitmap[ino / 8] |= 1 << (ino % 8);
1305 }
1306
1307 static void
1308 do_exclude_ino_str(char * ino) {
1309 char *r;
1310 unsigned long inod;
1311
1312 inod = strtoul(ino, &r, 10);
1313 if (( *r != '\0' && !isspace(*r) ) || inod <= ROOTINO) {
1314 msg("Invalid inode argument %s\n", ino);
1315 msg("The ENTIRE dump is aborted.\n");
1316 exit(X_STARTUP);
1317 }
1318 do_exclude_ino(inod, NULL);
1319 }
1320
1321 /*
1322 * This reads a file containing one inode number per line and exclude them all
1323 */
1324 static void
1325 do_exclude_from_file(char *file) {
1326 FILE *f;
1327 char *p, fname[MAXPATHLEN];
1328
1329
1330 if (!( f = fopen(file, "r")) ) {
1331 msg("Cannot open file for reading: %s\n", file);
1332 msg("The ENTIRE dump is aborted.\n");
1333 exit(X_STARTUP);
1334 }
1335 while (( p = fgets(fname, MAXPATHLEN, f))) {
1336 if ( *p && *(p + strlen(p) - 1) == '\n' ) /* possible null string */
1337 *(p + strlen(p) - 1) = '\0';
1338 if ( !*p ) /* skip empty lines */
1339 continue;
1340 do_exclude_ino_str(p);
1341 }
1342 fclose(f);
1343 }
1344
1345 static void incompat_flags(int cond, char flag1, char flag2) {
1346 if (cond) {
1347 msg("You cannot use the %c and %c flags together.\n",
1348 flag1, flag2);
1349 msg("The ENTIRE dump is aborted.\n");
1350 exit(X_STARTUP);
1351 }
1352 }