X-Git-Url: https://git.wh0rd.org/?p=dump.git;a=blobdiff_plain;f=dump%2Foptr.c;h=056a6a6c123f9e7f3cd6164be37c451499139a3b;hp=5f275ed5b75487ac68454f7ce4ef3e54db9d0338;hb=c43794b1b0a6115b1d12f0dc2ad2135d2a36fdc9;hpb=c92d83ae0460e58d019fa9922a68ed87732b5583 diff --git a/dump/optr.c b/dump/optr.c index 5f275ed..056a6a6 100644 --- a/dump/optr.c +++ b/dump/optr.c @@ -18,11 +18,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -41,7 +37,7 @@ #ifndef lint static const char rcsid[] = - "$Id: optr.c,v 1.34 2003/01/21 10:42:27 stelian Exp $"; + "$Id: optr.c,v 1.40 2006/03/14 11:09:51 stelian Exp $"; #endif /* not lint */ #include @@ -448,7 +444,7 @@ allocfsent(struct mntent *fs) /* Translade UUID=, LABEL= ... */ disk = get_device_name(fs->mnt_fsname); if (disk == NULL) - quit("Cannot find a disk having %s\n", fs->mnt_fsname); + disk = strdup(fs->mnt_fsname); /* Discard non block devices */ if (stat(disk, &buf) != 0 || !S_ISBLK(buf.st_mode)) { @@ -464,6 +460,15 @@ allocfsent(struct mntent *fs) quit("Cannot access %s\n", tabfs->mnt_fsname); if (tabbuf.st_rdev == buf.st_rdev) { free(new); + /* Copy passno and freq from /etc/fstab because + * /etc/mtab does always have them as 0 0 */ + if (!tabfs->mnt_passno) + tabfs->mnt_passno = fs->mnt_passno; + if (!tabfs->mnt_freq) + tabfs->mnt_freq = fs->mnt_freq; + if (tabfs->mnt_freq > 3659) + quit("Dump frequency in fstab/mtab for %s is too big: %d > 3659\n", + tabfs->mnt_fsname, tabfs->mnt_freq); return NULL; } } @@ -477,6 +482,9 @@ allocfsent(struct mntent *fs) quit("%s\n", strerror(errno)); new->mnt_passno = fs->mnt_passno; new->mnt_freq = fs->mnt_freq; + if (new->mnt_freq > 3659) + quit("Dump frequency in fstab/mtab for %s %s is too big: %d > 3659\n", + new->mnt_dir, new->mnt_fsname, new->mnt_freq); return (new); } @@ -487,7 +495,7 @@ getfstab(void) struct pfstab *pf; struct pfstab *pfold = NULL; FILE *mntfp; - char *mnttables[] = { _PATH_MNTTAB, _PATH_MOUNTED, 0 }; + char *mnttables[] = { _PATH_MOUNTED, _PATH_MNTTAB, 0 }; int i; for (i = 0; mnttables[i]; i++) { @@ -612,13 +620,13 @@ print_wmsg(char arg, int dumpme, const char *dev, int level, * Check ddate > 365 to avoid issues with fs in stab but not dumpdates. * Not a problem, because ddate is in seconds since the epoch anyways. */ - if (ddate > 365) { + if (level >= 0 && ddate > 365) { char *date, *d; date = (char *)ctime(&ddate); d = strchr(date, '\n'); if (d) *d = '\0'; - printf("Level %c, Date %s\n", level, date); + printf("Level %d, Date %s\n", level, date); } else printf("never\n"); } @@ -667,13 +675,25 @@ lastdump(char arg) /* w ==> just what to do; W ==> most recent dumps */ * change struct fstab format. * A positive fs_freq means this * filesystem needs to be dumped. + * + * UGLY HACK: values in 0-3659 range indicate + * original value from /etc/fstab (maximum + * 10 years...) + * + * Values bigger than 3659 indicate that + * the fs is to be dumped, and the latest + * dump level was x-3660 + * + * Negative values indicate that the fs is + * not to be dumped, and the latest dump + * level was -x-1 */ dt->mnt_passno = dtwalk->dd_ddate; if (dt->mnt_freq > 0 && (dtwalk->dd_ddate < tnow - (dt->mnt_freq * 86400))) - dt->mnt_freq = dtwalk->dd_level; + dt->mnt_freq = 3660 + dtwalk->dd_level; else - dt->mnt_freq = -dtwalk->dd_level; + dt->mnt_freq = -dtwalk->dd_level - 1; #ifdef FDEBUG printf("%s fs_freq set to %d\n", lastname, dt->mnt_freq); @@ -693,8 +713,9 @@ lastdump(char arg) /* w ==> just what to do; W ==> most recent dumps */ const char *disk = get_device_name(dt->mnt_fsname); print_wmsg(arg, dt->mnt_freq > 0, disk ? disk : dt->mnt_fsname, - dt->mnt_freq < 0 ? -dt->mnt_freq : - dt->mnt_freq, + (dt->mnt_freq < 0 ? -dt->mnt_freq - 1 : + dt->mnt_freq < 3660 ? -1 : + dt->mnt_freq - 3660), dt->mnt_dir, dt->mnt_passno); }