From 43ef843b59f89bb96ebec8647aa23ad43ae6789c Mon Sep 17 00:00:00 2001 From: Stelian Pop Date: Tue, 20 Mar 2001 09:14:57 +0000 Subject: [PATCH] Another set of cleanups from Andreas Dilger (time_t cleanups, libext2 version etc). --- CHANGES | 5 ++-- compat/include/bsdcompat.h | 5 ++-- dump/itime.c | 10 +------ dump/main.c | 60 ++++++++++++-------------------------- dump/optr.c | 27 +++++------------ dump/tape.c | 51 +++++++++----------------------- dump/traverse.c | 32 ++++++++++---------- restore/main.c | 14 +++++++-- restore/tape.c | 14 +-------- 9 files changed, 74 insertions(+), 144 deletions(-) diff --git a/CHANGES b/CHANGES index 934328d..8710d0b 100644 --- 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 . + ext2fs COMPAT flags, time_t cleanups, added libext2 version + in dump usage text) by Andreas Dilger . Changes between versions 0.4b20 and 0.4b21 (released January 13, 2001) ====================================================================== diff --git a/compat/include/bsdcompat.h b/compat/include/bsdcompat.h index 71ba0e2..96ce8b4 100644 --- a/compat/include/bsdcompat.h +++ b/compat/include/bsdcompat.h @@ -5,7 +5,7 @@ * Stelian Pop , 1999-2000 * Stelian Pop - AlcĂ´ve , 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 @@ -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 diff --git a/dump/itime.c b/dump/itime.c index 836b6ae..0a81d98 100644 --- a/dump/itime.c +++ b/dump/itime.c @@ -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 @@ -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 diff --git a/dump/main.c b/dump/main.c index 60f2bb4..04ec6f0 100644 --- a/dump/main.c +++ b/dump/main.c @@ -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 @@ -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 @@ -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) { diff --git a/dump/tape.c b/dump/tape.c index f43c3a2..8cf9ce1 100644 --- a/dump/tape.c +++ b/dump/tape.c @@ -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 @@ -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); diff --git a/dump/traverse.c b/dump/traverse.c index 038c96f..3da18d3 100644 --- a/dump/traverse.c +++ b/dump/traverse.c @@ -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 @@ -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; diff --git a/restore/main.c b/restore/main.c index 1843d4b..703266c 100644 --- a/restore/main.c +++ b/restore/main.c @@ -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 @@ -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]", diff --git a/restore/tape.c b/restore/tape.c index d7471a3..1bb6d8c 100644 --- a/restore/tape.c +++ b/restore/tape.c @@ -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 @@ -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", -- 2.39.2