]> git.wh0rd.org - dump.git/commitdiff
Another set of cleanups from Andreas Dilger (time_t cleanups, libext2 version etc).
authorStelian Pop <stelian@popies.net>
Tue, 20 Mar 2001 09:14:57 +0000 (09:14 +0000)
committerStelian Pop <stelian@popies.net>
Tue, 20 Mar 2001 09:14:57 +0000 (09:14 +0000)
CHANGES
compat/include/bsdcompat.h
dump/itime.c
dump/main.c
dump/optr.c
dump/tape.c
dump/traverse.c
restore/main.c
restore/tape.c

diff --git a/CHANGES b/CHANGES
index 934328d171f7f2e61f16003c5f77c8f121dd3a71..8710d0b7a213a2bfed61ed613133793b60208f41 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,4 +1,4 @@
-$Id: CHANGES,v 1.106 2001/03/19 13:22:48 stelian Exp $
+$Id: CHANGES,v 1.107 2001/03/20 09:14:57 stelian Exp $
 
 Changes between versions 0.4b21 and 0.4b22 (released ????????????????)
 ======================================================================
@@ -27,7 +27,8 @@ Changes between versions 0.4b21 and 0.4b22 (released ????????????????)
        it upstream.
 
 5.     Many cleanups (CPP defines, const char warnings, check of
-       ext2fs COMPAT flags) by Andreas Dilger <adilger@turbolinux.com>.
+       ext2fs COMPAT flags, time_t cleanups, added libext2 version
+       in dump usage text) by Andreas Dilger <adilger@turbolinux.com>.
 
 Changes between versions 0.4b20 and 0.4b21 (released January 13, 2001)
 ======================================================================
index 71ba0e2b1ff23c539ae5eafab27be63c9cbeee25..96ce8b43ba62b2c565d6801088f7dce5d326cfa6 100644 (file)
@@ -5,7 +5,7 @@
  *     Stelian Pop <pop@noos.fr>, 1999-2000
  *     Stelian Pop <pop@noos.fr> - AlcĂ´ve <www.alcove.fr>, 2000
  *
- *     $Id: bsdcompat.h,v 1.13 2000/12/21 11:14:53 stelian Exp $
+ *     $Id: bsdcompat.h,v 1.14 2001/03/20 09:14:58 stelian Exp $
  */
 
 #include <config.h>
@@ -60,10 +60,9 @@ typedef __u64                u_quad_t;
 /*
  * The BSD dump format reserves 4 bytes for a time_t, but other architectures
  * (notably axp) have larger time_t.  ctime4() is a modified ctime() which
- * always accepts short 4-byte times.  time4() is a similarly modified time().
+ * always accepts short 4-byte times.
  */
 #define ctime4(timep) ({ time_t t = *(timep); ctime(&t); })
-#define time4(timep) ({time_t t; t = time(0); if (timep) *timep=t; t; })
 
 /*
  * This is the ext2_inode structure but the fields have been renamed
index 836b6ae09bb7b4710069c16a68406e55b84d5bce..0a81d9801e07fec93fa16a11a95330773de1c9e4 100644 (file)
@@ -41,7 +41,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-       "$Id: itime.c,v 1.16 2001/03/19 13:22:48 stelian Exp $";
+       "$Id: itime.c,v 1.17 2001/03/20 09:14:58 stelian Exp $";
 #endif /* not lint */
 
 #include <config.h>
@@ -182,11 +182,7 @@ getdumptime(int createdumpdates)
                        continue;
                if (ddp->dd_level >= level)
                        continue;
-#ifdef __linux__
                if (ddp->dd_ddate <= (time_t)spcl.c_ddate)
-#else
-               if (ddp->dd_ddate <= spcl.c_ddate)
-#endif
                        continue;
                spcl.c_ddate = ddp->dd_ddate;
                lastlevel = ddp->dd_level;
@@ -245,11 +241,7 @@ putdumptime(void)
                quit("ftruncate (%s): %s\n", dumpdates, strerror(errno));
        (void) fclose(df);
        msg("level %c dump on %s", level,
-#ifdef __linux__
                spcl.c_date == 0 ? "the epoch\n" : ctime4(&spcl.c_date));
-#else
-               spcl.c_date == 0 ? "the epoch\n" : ctime(&spcl.c_date));
-#endif
 }
 
 static void
index 60f2bb4b7a4f9d145ac70f89c2addfb14fe6598f..04ec6f033e6bd7a7a8e62672f12d32dc013ec0e1 100644 (file)
@@ -41,7 +41,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-       "$Id: main.c,v 1.35 2001/03/19 13:22:48 stelian Exp $";
+       "$Id: main.c,v 1.36 2001/03/20 09:14:58 stelian Exp $";
 #endif /* not lint */
 
 #include <config.h>
@@ -130,12 +130,7 @@ main(int argc, char *argv[])
        char *diskparam;
 
        spcl.c_label[0] = '\0';
-       spcl.c_date = 0;
-#ifdef __linux__
-       (void)time4(&spcl.c_date);
-#else
-       (void)time((time_t *)&spcl.c_date);
-#endif
+       spcl.c_date = time(NULL);
 
 #ifdef __linux__
        __progname = argv[0];
@@ -489,17 +484,10 @@ main(int argc, char *argv[])
        if (!sizest) {
 
                msg("Date of this level %c dump: %s", level,
-#ifdef __linux__
-                       spcl.c_date == 0 ? "the epoch\n" : ctime4(&spcl.c_date));
-#else
-                       spcl.c_date == 0 ? "the epoch\n" : ctime(&spcl.c_date));
-#endif
-               msg("Date of last level %c dump: %s", lastlevel,
-#ifdef __linux__
-                       spcl.c_ddate == 0 ? "the epoch\n" : ctime4(&spcl.c_ddate));
-#else
-                       spcl.c_ddate == 0 ? "the epoch\n" : ctime(&spcl.c_ddate));
-#endif
+                   ctime4(&spcl.c_date));
+               if (spcl.c_ddate)
+                       msg("Date of last level %c dump: %s", lastlevel,
+                           ctime4(&spcl.c_ddate));
                msg("Dumping %s (%s) ", disk, spcl.c_filesys);
                if (host)
                        msgtail("to %s on host %s\n", tape, host);
@@ -661,11 +649,7 @@ main(int argc, char *argv[])
        "can't allocate tape buffers - try a smaller blocking factor.\n");
 
        startnewtape(1);
-#ifdef __linux__
-       (void)time4(&(tstart_writing));
-#else
-       (void)time((time_t *)&(tstart_writing));
-#endif
+       tstart_writing = time(NULL);
        dumpmap(usedinomap, TS_CLRI, maxino - 1);
 
        msg("dumping (Pass III) [directories]\n");
@@ -718,11 +702,7 @@ main(int argc, char *argv[])
                (void)dumpino(dp, ino);
        }
 
-#ifdef __linux__
-       (void)time4(&(tend_writing));
-#else
-       (void)time((time_t *)&(tend_writing));
-#endif
+       tend_writing = time(NULL);
        spcl.c_type = TS_END;
        for (i = 0; i < ntrec; i++)
                writeheader(maxino - 1);
@@ -747,13 +727,8 @@ main(int argc, char *argv[])
                    spcl.c_tapea / (tend_writing - tstart_writing));
 
        putdumptime();
-#ifdef __linux__
        msg("Date of this level %c dump: %s", level,
                spcl.c_date == 0 ? "the epoch\n" : ctime4(&spcl.c_date));
-#else
-       msg("Date of this level %c dump: %s", level,
-               spcl.c_date == 0 ? "the epoch\n" : ctime(&spcl.c_date));
-#endif
        msg("Date this dump completed:  %s", ctime(&tnow));
 
        msg("Average transfer rate: %ld KB/s\n", xferrate / tapeno);
@@ -776,15 +751,18 @@ static void
 usage(void)
 {
        char white[MAXPATHLEN];
-       int i;
-       
-       strncpy(white, __progname, MAXPATHLEN-1);
-       white[MAXPATHLEN-1] = '\0';
-       for (i=0; i<MAXPATHLEN; ++i)
-               if (white[i] != '\0') white[i] = ' ';
+       const char *ext2ver, *ext2date;
 
-       fprintf(stderr,
-               "%s %s\n", __progname, _DUMP_VERSION);
+       memset(white, ' ', MAXPATHLEN);
+       white[MIN(strlen(__progname), MAXPATHLEN - 1)] = '\0';
+
+#ifdef __linux__
+       ext2fs_get_library_version(&ext2ver, &ext2date);
+       fprintf(stderr, "%s %s (using libext2fs %s of %s)\n",
+               __progname, _DUMP_VERSION, ext2ver, ext2date);
+#else
+       fprintf(stderr, "%s %s\n", __progname, _DUMP_VERSION);
+#endif
        fprintf(stderr,
                "usage:\t%s [-0123456789ac"
 #ifdef KERBEROS
index b8e6ff5e28cdeaf756b95c41572ba9007a2cd7dd..c9c9239f6eaf74d38cba84e460e0b6ee8573847c 100644 (file)
@@ -41,7 +41,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-       "$Id: optr.c,v 1.21 2001/03/19 13:22:48 stelian Exp $";
+       "$Id: optr.c,v 1.22 2001/03/20 09:14:58 stelian Exp $";
 #endif /* not lint */
 
 #include <config.h>
@@ -101,11 +101,7 @@ query(const char *question)
        FILE    *mytty;
        time_t  firstprompt, when_answered;
 
-#ifdef __linux__
-       (void)time4(&(firstprompt));
-#else
-       (void)time((time_t *)&(firstprompt));
-#endif
+       firstprompt = time(NULL);
 
        if ((mytty = fopen(_PATH_TTY, "r")) == NULL)
                quit("fopen on %s fails: %s\n", _PATH_TTY, strerror(errno));
@@ -138,16 +134,12 @@ query(const char *question)
        if (signal(SIGALRM, sig) == SIG_IGN)
                signal(SIGALRM, SIG_IGN);
        (void) fclose(mytty);
-#ifdef __linux__
-       (void)time4(&(when_answered));
-#else
-       (void)time((time_t *)&(when_answered));
-#endif
+       when_answered = time(NULL);
        /*
         * Adjust the base for time estimates to ignore time we spent waiting
         * for operator input.
         */
-       if ((tstart_writing != 0) && (when_answered != (time_t)-1) && (firstprompt != (time_t)-1))
+       if (tstart_writing != 0)
                tstart_writing += (when_answered - firstprompt);
        return(back);
 }
@@ -247,7 +239,7 @@ broadcast(const char *message)
                return;
        }
 
-       clock = time((time_t *)0);
+       clock = time(NULL);
        localclock = localtime(&clock);
 
        if ((f_utmp = fopen(_PATH_UTMP, "r")) == NULL) {
@@ -324,13 +316,8 @@ time_t     tschedule = 0;
 void
 timeest(void)
 {
-       time_t tnow;
+       time_t tnow = time(NULL);
 
-#ifdef __linux__
-       (void) time4(&tnow);
-#else
-       (void) time((time_t *) &tnow);
-#endif
        if (tnow >= tschedule) {
                char *buf = mktimeest(tnow);
                tschedule = tnow + 300;
@@ -601,7 +588,7 @@ lastdump(char arg) /* w ==> just what to do; W ==> most recent dumps */
        struct pfstab *pf;
        time_t tnow;
 
-       (void) time(&tnow);
+       tnow = time(NULL);
        getfstab();             /* /etc/fstab input */
        initdumptimes(0);       /* dumpdates input */
        if (ddatev == NULL && table == NULL) {
index f43c3a20a9b3d4aae071afcb90ca90bd3641ebac..8cf9ce18b9aab89ed0a95c0db2edbfafe604e83e 100644 (file)
@@ -41,7 +41,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-       "$Id: tape.c,v 1.34 2001/03/19 13:22:48 stelian Exp $";
+       "$Id: tape.c,v 1.35 2001/03/20 09:14:58 stelian Exp $";
 #endif /* not lint */
 
 #include <config.h>
@@ -285,19 +285,10 @@ do_stats(void)
        time_t tnow, ttaken;
        int blocks;
 
-#ifdef __linux__
-       (void)time4(&tnow);
-#else
-       (void)time(&tnow);
-#endif
+       tnow = time(NULL);
        ttaken = tnow - tstart_volume;
        blocks = spcl.c_tapea - tapea_volume;
-       msg("Volume %d completed at: %s", tapeno, 
-#ifdef __linux__
-                                         ctime4(&tnow));
-#else
-                                         ctime(&tnow));
-#endif
+       msg("Volume %d completed at: %s", tapeno, ctime(&tnow));
        if (! compressed)
                msg("Volume %d %ld tape blocks (%.2fMB)\n", tapeno, 
                        blocks, ((double)blocks * TP_BSIZE / 1048576));
@@ -356,16 +347,10 @@ mktimeest(time_t tnow)
 void
 statussig(int notused)
 {
-       time_t tnow;
        int save_errno = errno;
        char *buf;
 
-#ifdef __linux__
-       (void) time4(&tnow);
-#else
-       (void) time((time_t *) &tnow);
-#endif
-       buf = mktimeest(tnow);
+       buf = mktimeest(time(NULL));
        if (buf)
                write(STDERR_FILENO, buf, strlen(buf));
        errno = save_errno;
@@ -405,13 +390,13 @@ flushtape(void)
                        uncomprblks++;
                slp->sent = 0;
 
-               /* Check for errors */
-               if (got < 0)
-                       tperror(-got);
-               
-               /* Check for end of tape */
-               if (got == 0) {
-                       msg("End of tape detected\n");
+               /* Check for errors or end of tape */
+               if (got <= 0) {
+                       /* Check for errors */
+                       if (got < 0)
+                               tperror(-got);
+                       else
+                               msg("End of tape detected\n");
 
                        /*
                         * Drain the results, don't care what the values were.
@@ -769,11 +754,7 @@ startnewtape(int top)
        parentpid = getpid();
        tapea_volume = spcl.c_tapea;
        tapea_bytes = bytes_written;
-#ifdef __linux__
-       (void)time4(&tstart_volume);
-#else
-       (void)time((&tstart_volume);
-#endif
+       tstart_volume = time(NULL);
 
 restore_check_point:
 #ifdef __linux__
@@ -905,12 +886,8 @@ restore_check_point:
                        spcl.c_flags |= DR_COMPRESSED;
                writeheader((ino_t)slp->inode);
                spcl.c_flags &=~ DR_NEWHEADER;
-               msg("Volume %d started at: %s", tapeno, 
-#ifdef __linux__
-                                               ctime4(&tstart_volume));
-#else
-                                               ctime(&tstart_volume));
-#endif
+               msg("Volume %d started with block %ld at: %s", tapeno, 
+                   spcl.c_tapea, ctime(&tstart_volume));
                if (tapeno > 1)
                        msg("Volume %d begins with blocks from inode %d\n",
                                tapeno, slp->inode);
index 038c96f1d3c35676620d055dc72fa19e734d0e8e..3da18d39a628eaa47e4abf9223fd010a9be2bea3 100644 (file)
@@ -41,7 +41,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-       "$Id: traverse.c,v 1.26 2001/03/19 13:22:49 stelian Exp $";
+       "$Id: traverse.c,v 1.27 2001/03/20 09:14:58 stelian Exp $";
 #endif /* not lint */
 
 #include <config.h>
@@ -103,8 +103,12 @@ extern ino_t iexclude_list[IEXCLUDE_MAXNUM];       /* the inode exclude list */
 extern int iexclude_num;                       /* number of elements in list */
 
 /* Temporary fix waiting for Andreas fixes... */
-#define ext2_ino_t ino_t 
-#undef EXT3_FEATURE_INCOMPAT_RECOVER
+#ifdef HAS_EXT2FS_EXT2_FS
+#define ext2_journal_ino(sb) (sb->s_journal_inum)
+#else
+#define ext2_ino_t __u32
+#define ext2_journal_ino(sb) (*((__u32 *)sb + 0x38))
+#endif
 
 #ifndef EXT3_FEATURE_COMPAT_HAS_JOURNAL
 #define EXT3_FEATURE_COMPAT_HAS_JOURNAL                0x0004
@@ -114,14 +118,9 @@ extern int iexclude_num;                   /* number of elements in list */
 #endif
 #ifndef EXT3_FEATURE_INCOMPAT_RECOVER
 #define EXT3_FEATURE_INCOMPAT_RECOVER          0x0004
-#define FORCE_OPEN     EXT2_FLAG_FORCE
-#define ext2_journal_ino(sb)   (*((__u32 *)sb + 0x38))
-#else
-#define FORCE_OPEN     0
-#define ext2_journal_ino(sb)   (sb->s_journal_inum)
 #endif
 #ifndef EXT3_FEATURE_INCOMPAT_JOURNAL_DEV
-#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV      0x0008
+#define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV      0x0008
 #endif
 
 #ifndef EXT2_LIB_FEATURE_INCOMPAT_SUPP
@@ -133,10 +132,11 @@ int dump_fs_open(const char *disk, ext2_filsys *fs)
 {
        int retval;
 
-       retval = ext2fs_open(disk, FORCE_OPEN, 0, 0, unix_io_manager, fs);
+       retval = ext2fs_open(disk, EXT2_FLAG_FORCE, 0, 0, unix_io_manager, fs);
        if (!retval) {
                struct ext2_super_block *es = (*fs)->super;
                ext2_ino_t journal_ino = ext2_journal_ino(es);
+
                if (es->s_feature_incompat & EXT3_FEATURE_INCOMPAT_JOURNAL_DEV){
                        fprintf(stderr, "This an journal, not a filesystem!\n");
                        retval = EXT2_ET_UNSUPP_FEATURE;
@@ -152,11 +152,11 @@ int dump_fs_open(const char *disk, ext2_filsys *fs)
                        ext2fs_close(*fs);
                }
                else if (es->s_feature_compat &
-                               EXT3_FEATURE_COMPAT_HAS_JOURNAL && journal_ino &&
-                               !exclude_ino(journal_ino)) {
+                               EXT3_FEATURE_COMPAT_HAS_JOURNAL && 
+                               journal_ino && !exclude_ino(journal_ino)) {
                        iexclude_list[iexclude_num++] = journal_ino;
                        msg("Added ext3 journal inode %d to exclude list\n",
-                                       journal_ino);
+                           journal_ino);
                }
        }
        return retval;
@@ -302,7 +302,7 @@ mapfileino(ino_t ino, struct dinode const *dp, long *tapesize, int *dirskipped)
 int
 mapfiles(ino_t maxino, long *tapesize)
 {
-       ino_t ino;
+       ext2_ino_t ino;
        int anydirskipped = 0;
        ext2_inode_scan scan;
        errcode_t err;
@@ -374,7 +374,7 @@ mapfilesindir(struct ext2_dir_entry *dirent, int offset, int blocksize, char *bu
        register int mode;
        errcode_t retval;
        struct mapfile_context *mfc;
-       ino_t ino;
+       ext2_ino_t ino;
 
        ino = dirent->inode;
        mfc = (struct mapfile_context *)private;
@@ -408,7 +408,7 @@ mapfilesfromdir(ino_t maxino, long *tapesize, char *directory)
 {
        errcode_t retval;
        struct mapfile_context mfc;
-       ino_t dir_ino;
+       ext2_ino_t dir_ino;
        char dir_name [MAXPATHLEN];
        int i, anydirskipped = 0;
 
index 1843d4b431fe955439baf80427bd85b3810121f2..703266cd6bf05f48e7c2ef74496b5c3a9db60267 100644 (file)
@@ -41,7 +41,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-       "$Id: main.c,v 1.16 2001/02/21 16:13:05 stelian Exp $";
+       "$Id: main.c,v 1.17 2001/03/20 09:14:58 stelian Exp $";
 #endif /* not lint */
 
 #include <config.h>
@@ -401,13 +401,21 @@ main(int argc, char *argv[])
 static void
 usage(void)
 {
+#ifdef __linux__
+       const char *ext2ver, *ext2date;
+
+       ext2fs_get_library_version(&ext2ver, &ext2date);
+       (void)fprintf(stderr, "%s %s (using libext2fs %s of %s)\n", 
+                     __progname, _DUMP_VERSION, ext2ver, ext2date);
+#else
+       (void)fprintf(stderr, "%s %s\n", __progname, _DUMP_VERSION);
+#endif
+
 #ifdef KERBEROS
 #define kerbflag "k"
 #else
 #define kerbflag
 #endif
-       (void)fprintf(stderr, 
-         "%s %s\n", __progname, _DUMP_VERSION);
        (void)fprintf(stderr,
          "usage:\t%s%s\n\t%s%s\n\t%s%s\n\t%s%s\n\t%s%s\n",
          __progname, " -i [-ch" kerbflag "mMuvy] [-b blocksize] [-f file] [-s fileno]",
index d7471a39b6513e9228c75b7d5959a3fb2a7c640f..1bb6d8c2d45192a6e023e85fed08b2f6962bebc7 100644 (file)
@@ -46,7 +46,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-       "$Id: tape.c,v 1.27 2001/03/19 13:22:49 stelian Exp $";
+       "$Id: tape.c,v 1.28 2001/03/20 09:14:58 stelian Exp $";
 #endif /* not lint */
 
 #include <config.h>
@@ -488,15 +488,9 @@ gethdr:
                goto again;
        }
        if (tmpbuf.c_date != dumpdate || tmpbuf.c_ddate != dumptime) {
-#ifdef __linux__
                fprintf(stderr, "Wrong dump date\n\tgot: %s",
                        ctime4(&tmpbuf.c_date));
-               fprintf(stderr, "\twanted: %s", ctime4(&dumpdate));
-#else
-               fprintf(stderr, "Wrong dump date\n\tgot: %s",
-                       ctime(&tmpbuf.c_date));
                fprintf(stderr, "\twanted: %s", ctime(&dumpdate));
-#endif
                volno = 0;
                haderror = 1;
                goto again;
@@ -596,15 +590,9 @@ setdumpnum(void)
 void
 printdumpinfo(void)
 {
-#ifdef __linux__
        fprintf(stdout, "Dump   date: %s", ctime4(&spcl.c_date));
        fprintf(stdout, "Dumped from: %s",
            (spcl.c_ddate == 0) ? "the epoch\n" : ctime4(&spcl.c_ddate));
-#else
-       fprintf(stdout, "Dump   date: %s", ctime(&spcl.c_date));
-       fprintf(stdout, "Dumped from: %s",
-           (spcl.c_ddate == 0) ? "the epoch\n" : ctime(&spcl.c_ddate));
-#endif
        if (spcl.c_host[0] == '\0')
                return;
        fprintf(stdout, "Level %d dump of %s on %s:%s\n",