X-Git-Url: https://git.wh0rd.org/?p=dump.git;a=blobdiff_plain;f=dump%2Fmain.c;h=45e525bbd165632c3de8f9d34fcd363b0504df0c;hp=ee6717272dc5dd661455eb7b7075f1472278d73a;hb=c92d83ae0460e58d019fa9922a68ed87732b5583;hpb=633963a251fb12a63e43a7f6f2391dc9507972a7 diff --git a/dump/main.c b/dump/main.c index ee67172..45e525b 100644 --- a/dump/main.c +++ b/dump/main.c @@ -41,7 +41,7 @@ #ifndef lint static const char rcsid[] = - "$Id: main.c,v 1.69 2002/01/31 10:49:17 stelian Exp $"; + "$Id: main.c,v 1.81 2003/01/21 10:42:27 stelian Exp $"; #endif /* not lint */ #include @@ -49,19 +49,18 @@ static const char rcsid[] = #include #include #include -#include #include #include #include #include #include #include +#include #include #include #include #ifdef __linux__ -#include #ifdef HAVE_EXT2FS_EXT2_FS_H #include #else @@ -97,6 +96,8 @@ int mapsize; /* size of the state maps */ char *usedinomap; /* map of allocated inodes */ char *dumpdirmap; /* map of directories to be dumped */ char *dumpinomap; /* map of files to be dumped */ +char *metainomap; /* which of the inodes in dumpinomap will get + only their metadata dumped */ const char *disk; /* name of the disk file */ char tape[MAXPATHLEN];/* name of the tape file */ @@ -107,8 +108,10 @@ char level; /* dump level of this dump */ int bzipflag; /* compression is done using bzlib */ int Afile = 0; /* archive file descriptor */ int uflag; /* update flag */ +int mflag; /* dump metadata only if possible */ int Mflag; /* multi-volume flag */ int qflag; /* quit on errors flag */ +int vflag; /* verbose flag */ int breademax = 32; /* maximum number of bread errors before we quit */ char *eot_script; /* end of volume script fiag */ int diskfd; /* disk file descriptor */ @@ -160,7 +163,7 @@ int notify = 0; /* notify operator flag */ int blockswritten = 0; /* number of blocks written on current tape */ int tapeno = 0; /* current tape number */ int density = 0; /* density in bytes/0.1" " <- this is for hilit19 */ -int ntrec = NTREC; /* # tape blocks in each tape record */ +int ntrec = NTREC; /* # blocks in each tape record */ int cartridge = 0; /* Assume non-cartridge tape */ #ifdef USE_QFA int tapepos = 0; /* assume no QFA tapeposition needed by user */ @@ -178,7 +181,7 @@ long uncomprblks = 0;/* uncompressed blocks written */ char *__progname; #endif -int maxbsize = 64*1024; /* XXX MAXBSIZE from sys/param.h */ +int maxbsize = 1024*1024; /* XXX MAXBSIZE from sys/param.h */ static long numarg __P((const char *, long, long)); static void obsolete __P((int *, char **[])); static void usage __P((void)); @@ -195,7 +198,7 @@ main(int argc, char *argv[]) dump_ino_t ino; int dirty; struct dinode *dp; - struct fstab *dt; + struct mntent *dt; char *map; int ch; int i, anydirskipped; @@ -241,7 +244,7 @@ main(int argc, char *argv[]) #endif /* USE_QFA */ while ((ch = getopt(argc, argv, - "0123456789A:aB:b:cd:e:E:f:F:h:I:" + "0123456789A:aB:b:cd:D:e:E:f:F:h:I:" #ifdef HAVE_BZLIB "j::" #endif @@ -249,11 +252,11 @@ main(int argc, char *argv[]) #ifdef KERBEROS "k" #endif - "Mnq" + "mMnq" #ifdef USE_QFA "Q:" #endif - "s:ST:uWw" + "s:ST:uvWw" #ifdef HAVE_ZLIB "z::" #endif @@ -290,7 +293,7 @@ main(int argc, char *argv[]) case 'b': /* blocks per tape write */ ntrec = numarg("number of blocks per write", - 1L, 1000L); + 1L, 1048576L); if (ntrec > maxbsize/1024) { msg("Please choose a blocksize <= %dkB\n", maxbsize/1024); @@ -310,6 +313,10 @@ main(int argc, char *argv[]) density = numarg("density", 10L, 327670L) / 10; if (density >= 625 && !bflag) ntrec = HIGHDENSITYTREC; + break; + + case 'D': /* path of dumpdates file */ + dumpdates = optarg; break; /* 04-Feb-00 ILC */ @@ -352,7 +359,7 @@ main(int argc, char *argv[]) case 'I': breademax = - numarg ("number of errors to ignore", 1L, 0L); + numarg ("number of errors to ignore", 0L, 0L); break; #ifdef KERBEROS @@ -378,6 +385,10 @@ main(int argc, char *argv[]) } break; + case 'm': /* metadata only flag */ + mflag = 1; + break; + case 'M': /* multi-volume flag */ Mflag = 1; break; @@ -421,6 +432,10 @@ main(int argc, char *argv[]) uflag = 1; break; + case 'v': /* verbose */ + vflag = 1; + break; + case 'W': /* what to do */ case 'w': lastdump(ch); @@ -559,9 +574,9 @@ main(int argc, char *argv[]) msg("The ENTIRE dump is aborted.\n"); exit(X_STARTUP); } - disk = rawname(dt->fs_spec); - (void)strncpy(spcl.c_dev, dt->fs_spec, NAMELEN); - (void)strncpy(spcl.c_filesys, dt->fs_file, NAMELEN); + disk = rawname(dt->mnt_fsname); + (void)strncpy(spcl.c_dev, dt->mnt_fsname, NAMELEN); + (void)strncpy(spcl.c_filesys, dt->mnt_dir, NAMELEN); } else { #ifdef __linux__ #ifdef HAVE_REALPATH @@ -573,9 +588,9 @@ main(int argc, char *argv[]) * a filesystem specified in fstab. Search for it. */ if ((dt = fstabsearch(pathname)) != NULL) { - disk = rawname(dt->fs_spec); - (void)strncpy(spcl.c_dev, dt->fs_spec, NAMELEN); - (void)strncpy(spcl.c_filesys, dt->fs_file, NAMELEN); + disk = rawname(dt->mnt_fsname); + (void)strncpy(spcl.c_dev, dt->mnt_fsname, NAMELEN); + (void)strncpy(spcl.c_filesys, dt->mnt_dir, NAMELEN); } else { /* * The argument was not found in the fstab @@ -584,11 +599,11 @@ main(int argc, char *argv[]) dt = fstabsearchdir(pathname, directory); if (dt != NULL) { char name[MAXPATHLEN]; - (void)strncpy(spcl.c_dev, dt->fs_spec, NAMELEN); + (void)strncpy(spcl.c_dev, dt->mnt_fsname, NAMELEN); (void)snprintf(name, sizeof(name), "%s (dir %s)", - dt->fs_file, directory); + dt->mnt_dir, directory); (void)strncpy(spcl.c_filesys, name, NAMELEN); - disk = rawname(dt->fs_spec); + disk = rawname(dt->mnt_fsname); } else { (void)strncpy(spcl.c_dev, disk, NAMELEN); (void)strncpy(spcl.c_filesys, "an unlisted file system", @@ -700,9 +715,7 @@ main(int argc, char *argv[]) if (TP_BSIZE != (1 << tp_bshift)) quit("TP_BSIZE (%d) is not a power of 2", TP_BSIZE); maxino = fs->super->s_inodes_count + 1; -#if 0 spcl.c_flags |= DR_NEWINODEFMT; -#endif #else /* __linux __*/ if ((diskfd = open(disk, O_RDONLY)) < 0) { msg("Cannot open %s\n", disk); @@ -731,7 +744,9 @@ main(int argc, char *argv[]) usedinomap = (char *)calloc((unsigned) mapsize, sizeof(char)); dumpdirmap = (char *)calloc((unsigned) mapsize, sizeof(char)); dumpinomap = (char *)calloc((unsigned) mapsize, sizeof(char)); - if (usedinomap == NULL || dumpdirmap == NULL || dumpinomap == NULL) + metainomap = (char *)calloc((unsigned) mapsize, sizeof(char)); + if (usedinomap == NULL || dumpdirmap == NULL || + dumpinomap == NULL || metainomap == NULL) quit("out of memory allocating inode maps\n"); tapesize = 2 * (howmany(mapsize * sizeof(char), TP_BSIZE) + 1); @@ -739,6 +754,8 @@ main(int argc, char *argv[]) if (!sizest) { msg("Label: %s\n", spcl.c_label); + + msg("Writing %d Kilobyte records\n", ntrec); if (compressed) msg("Compressing output at compression level %d (%s)\n", @@ -787,14 +804,14 @@ main(int argc, char *argv[]) /* check if file is a directory */ if (!(statbuf.st_mode & S_IFDIR)) anydirskipped2 = maponefile(maxino, &tapesize, - p+strlen(dt->fs_file)); + p+strlen(dt->mnt_dir)); else /* read directory inodes. * NOTE: nested directories are not recognized * so inodes may be umped twice! */ anydirskipped2 = mapfilesfromdir(maxino, &tapesize, - p+strlen(dt->fs_file)); + p+strlen(dt->mnt_dir)); if (!anydirskipped) anydirskipped = anydirskipped2; argv++; @@ -816,7 +833,7 @@ main(int argc, char *argv[]) if (pipeout || unlimited) { tapesize += 1 + ntrec; /* 1 map header + trailer blocks */ - msg("estimated %ld tape blocks.\n", tapesize); + msg("estimated %ld blocks.\n", tapesize); } else { double fetapes; @@ -856,7 +873,7 @@ main(int argc, char *argv[]) tapesize += (etapes - 1) * (howmany(mapsize * sizeof(char), TP_BSIZE) + 1); tapesize += etapes + ntrec; /* headers + trailer blks */ - msg("estimated %ld tape blocks on %3.2f tape(s).\n", + msg("estimated %ld blocks on %3.2f tape(s).\n", tapesize, fetapes); } @@ -868,10 +885,10 @@ main(int argc, char *argv[]) /* print QFA-file header */ snprintf(gTps, sizeof(gTps), "%s\n%s\n%ld\n\n", QFA_MAGIC, QFA_VERSION, (unsigned long)spcl.c_date); gTps[sizeof(gTps) - 1] = '\0'; - if (write(gTapeposfd, gTps, strlen(gTps)) != strlen(gTps)) + if (write(gTapeposfd, gTps, strlen(gTps)) != (ssize_t)strlen(gTps)) quit("can't write tapeposfile\n"); sprintf(gTps, "ino\ttapeno\ttapepos\n"); - if (write(gTapeposfd, gTps, strlen(gTps)) != strlen(gTps)) + if (write(gTapeposfd, gTps, strlen(gTps)) != (ssize_t)strlen(gTps)) quit("can't write tapeposfile\n"); } #endif /* USE_QFA */ @@ -908,6 +925,8 @@ main(int argc, char *argv[]) */ if (dp->di_nlink == 0 || dp->di_dtime != 0) continue; + if (vflag) + msg("dumping directory inode %lu\n", ino); (void)dumpdirino(dp, ino); #else (void)dumpino(dp, ino); @@ -934,7 +953,13 @@ main(int argc, char *argv[]) * inodes since this is done in dumpino(). */ #endif - (void)dumpino(dp, ino); + if (vflag) { + if (mflag && TSTINO(ino, metainomap)) + msg("dumping regular inode %lu (meta only)\n", ino); + else + msg("dumping regular inode %lu\n", ino); + } + (void)dumpino(dp, ino, mflag && TSTINO(ino, metainomap)); } tend_writing = time(NULL); @@ -957,10 +982,10 @@ main(int argc, char *argv[]) tnow = trewind(); if (pipeout || fifoout) - msg("%ld tape blocks (%.2fMB)\n", spcl.c_tapea, + msg("%ld blocks (%.2fMB)\n", spcl.c_tapea, ((double)spcl.c_tapea * TP_BSIZE / 1048576)); else - msg("%ld tape blocks (%.2fMB) on %d volume(s)\n", + msg("%ld blocks (%.2fMB) on %d volume(s)\n", spcl.c_tapea, ((double)spcl.c_tapea * TP_BSIZE / 1048576), spcl.c_volume); @@ -1017,10 +1042,10 @@ usage(void) #ifdef KERBEROS "k" #endif - "MnqSu" + "mMnqSuv" "] [-A file] [-B records] [-b blocksize]\n" - "\t%s [-d density] [-e inode#,inode#,...] [-E file] [-f file]\n" - "\t%s [-h level] [-I nr errors] " + "\t%s [-d density] [-D file] [-e inode#,inode#,...] [-E file]\n" + "\t%s [-f file] [-h level] [-I nr errors] " #ifdef HAVE_BZLIB "[-j zlevel] " #endif @@ -1135,6 +1160,7 @@ obsolete(int *argcp, char **argvp[]) case 'B': case 'b': case 'd': + case 'D': case 'e': case 'E': case 'f': @@ -1208,10 +1234,10 @@ do_exclude_ino(dump_ino_t ino, const char *reason) exit(X_STARTUP); } if (reason) - msg("Added inode %u to exclude list (%s)\n", + msg("Excluding inode %u (%s) from dump\n", ino, reason); else - msg("Added inode %u to exclude list\n", ino); + msg("Excluding inode %u from dump\n", ino); iexclude_list[iexclude_num++] = ino; } } @@ -1222,7 +1248,7 @@ do_exclude_ino_str(char * ino) { unsigned long inod; inod = strtoul(ino, &r, 10); - if (*r != '\0' || inod <= ROOTINO) { + if (( *r != '\0' && !isspace(*r) ) || inod <= ROOTINO) { msg("Invalid inode argument %s\n", ino); msg("The ENTIRE dump is aborted.\n"); exit(X_STARTUP);