From 43460f04f3920ae39f345a2fb39d000a890a4283 Mon Sep 17 00:00:00 2001 From: Stelian Pop Date: Mon, 19 Mar 2001 13:22:48 +0000 Subject: [PATCH] Andreas Dilger fixes (CPP, ext2 features, const char etc). --- CHANGES | 5 +- compat/include/fstab.h | 4 +- compat/lib/bylabel.c | 11 ++-- compat/lib/fstab.c | 4 +- dump/dump.h | 6 +-- dump/itime.c | 39 ++++++-------- dump/main.c | 79 +++++++++++++---------------- dump/optr.c | 4 +- dump/tape.c | 39 +++++++------- dump/traverse.c | 112 ++++++++++++++++++++++------------------- restore/tape.c | 23 ++++----- restore/utilities.c | 19 +++---- 12 files changed, 167 insertions(+), 178 deletions(-) diff --git a/CHANGES b/CHANGES index 246adb0..934328d 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,4 @@ -$Id: CHANGES,v 1.105 2001/03/18 15:35:43 stelian Exp $ +$Id: CHANGES,v 1.106 2001/03/19 13:22:48 stelian Exp $ Changes between versions 0.4b21 and 0.4b22 (released ????????????????) ====================================================================== @@ -26,6 +26,9 @@ Changes between versions 0.4b21 and 0.4b22 (released ????????????????) the patch and to Bdale Garbee for forwarding it upstream. +5. Many cleanups (CPP defines, const char warnings, check of + ext2fs COMPAT flags) by Andreas Dilger . + Changes between versions 0.4b20 and 0.4b21 (released January 13, 2001) ====================================================================== diff --git a/compat/include/fstab.h b/compat/include/fstab.h index fa93f04..8386e8d 100644 --- a/compat/include/fstab.h +++ b/compat/include/fstab.h @@ -5,7 +5,7 @@ * Stelian Pop , 1999-2000 * Stelian Pop - Alcôve , 2000 * - * $Id: fstab.h,v 1.10 2000/12/21 11:14:53 stelian Exp $ + * $Id: fstab.h,v 1.11 2001/03/19 13:22:48 stelian Exp $ */ /* @@ -75,7 +75,7 @@ #define FSTAB_XX "ignore" /* ignore totally */ struct fstab { - char *fs_spec; /* block special device name */ + const char *fs_spec; /* block special device name */ char *fs_file; /* file system path prefix */ char *fs_vfstype; /* File system type, ufs, nfs */ char *fs_mntops; /* Mount options ala -o */ diff --git a/compat/lib/bylabel.c b/compat/lib/bylabel.c index 31bdd0d..065d529 100644 --- a/compat/lib/bylabel.c +++ b/compat/lib/bylabel.c @@ -24,7 +24,10 @@ #define PROC_PARTITIONS "/proc/partitions" #define DEVLABELDIR "/dev" -#define EXT2_SUPER_MAGIC 0xEF53 +#define EXT2_SUPER_OFFSET 1024 +#define EXT2_SUPER_SIZE sizeof(struct ext2_super_block) +#define EXT2_SUPER_MAGIC 0xEF53 + struct ext2_super_block { unsigned char s_dummy1[56]; unsigned char s_magic[2]; @@ -56,9 +59,9 @@ get_label_uuid(const char *device, char **label, char *uuid) { if (fd < 0) return 1; - if (lseek(fd, 1024, SEEK_SET) != 1024 - || read(fd, (char *) &e2sb, sizeof(e2sb)) != sizeof(e2sb) - || (ext2magic(e2sb) != EXT2_SUPER_MAGIC)) { + if (lseek(fd, EXT2_SUPER_OFFSET, SEEK_SET) != EXT2_SUPER_OFFSET || + read(fd, (char *) &e2sb, EXT2_SUPER_SIZE) != EXT2_SUPER_SIZE || + ext2magic(e2sb) != EXT2_SUPER_MAGIC) { close(fd); return 1; } diff --git a/compat/lib/fstab.c b/compat/lib/fstab.c index aa23462..9f11a65 100644 --- a/compat/lib/fstab.c +++ b/compat/lib/fstab.c @@ -41,7 +41,7 @@ #ifndef lint static const char rcsid[] = - "$Id: fstab.c,v 1.10 2000/12/21 11:14:53 stelian Exp $"; + "$Id: fstab.c,v 1.11 2001/03/19 13:22:48 stelian Exp $"; #endif /* not lint */ #include @@ -70,9 +70,9 @@ int fstabscan(void) int typexx; #define MAXLINELENGTH 1024 char subline[MAXLINELENGTH]; - char *device_name; for (;;) { + const char *device_name; if (!(mnt = getmntent(_fs_fp))) return 0; diff --git a/dump/dump.h b/dump/dump.h index c32631b..4e3fada 100644 --- a/dump/dump.h +++ b/dump/dump.h @@ -5,7 +5,7 @@ * Stelian Pop , 1999-2000 * Stelian Pop - Alcôve , 2000 * - * $Id: dump.h,v 1.20 2001/02/21 16:13:05 stelian Exp $ + * $Id: dump.h,v 1.21 2001/03/19 13:22:48 stelian Exp $ */ /*- @@ -66,7 +66,7 @@ char *dumpinomap; /* map of files to be dumped */ /* * All calculations done in 0.1" units! */ -char *disk; /* name of the disk file */ +const char *disk; /* name of the disk file */ char tape[MAXPATHLEN]; /* name of the tape file */ char *tapeprefix; /* prefix of the tape file */ char *dumpdates; /* name of the file containing dump date information*/ @@ -157,7 +157,7 @@ void Exit __P((int status)); void dumpabort __P((int signo)); void getfstab __P((void)); -char *rawname __P((char *cp)); +const char *rawname __P((const char *cp)); struct dinode *getino __P((ino_t inum)); /* rdump routines */ diff --git a/dump/itime.c b/dump/itime.c index 6eebd2c..836b6ae 100644 --- a/dump/itime.c +++ b/dump/itime.c @@ -41,20 +41,28 @@ #ifndef lint static const char rcsid[] = - "$Id: itime.c,v 1.15 2001/02/22 10:57:40 stelian Exp $"; + "$Id: itime.c,v 1.16 2001/03/19 13:22:48 stelian Exp $"; #endif /* not lint */ #include +#include +#include +#include +#ifdef __STDC__ +#include +#include +#endif + #include #include #ifdef __linux__ #include +#include #include #include #include #include -#else -#ifdef sunos +#elif defined sunos #include #include @@ -63,22 +71,9 @@ static const char rcsid[] = #else #include #endif -#endif #include -#include -#include -#include -#ifdef __STDC__ -#include -#include -#endif - -#ifdef __linux__ -#include -#endif - #include "dump.h" struct dumpdates **ddatev; @@ -161,12 +156,10 @@ getdumptime(int createdumpdates) { register struct dumpdates *ddp; register int i; - char *fname; - fname = disk; #ifdef FDEBUG msg("Looking for name %s in dumpdates = %s for level = %c\n", - fname, dumpdates, level); + disk, dumpdates, level); #endif spcl.c_ddate = 0; lastlevel = '0'; @@ -185,7 +178,7 @@ getdumptime(int createdumpdates) * and older date */ ITITERATE(i, ddp) { - if (strncmp(fname, ddp->dd_name, sizeof (ddp->dd_name)) != 0) + if (strncmp(disk, ddp->dd_name, sizeof (ddp->dd_name)) != 0) continue; if (ddp->dd_level >= level) continue; @@ -207,7 +200,6 @@ putdumptime(void) register struct dumpdates *dtwalk; register int i; int fd; - char *fname; if(uflag == 0) return; @@ -215,7 +207,6 @@ putdumptime(void) quit("cannot rewrite %s: %s\n", dumpdates, strerror(errno)); fd = fileno(df); (void) flock(fd, LOCK_EX); - fname = disk; free((char *)ddatev); ddatev = 0; nddates = 0; @@ -226,7 +217,7 @@ putdumptime(void) quit("fseek: %s\n", strerror(errno)); spcl.c_ddate = 0; ITITERATE(i, dtwalk) { - if (strncmp(fname, dtwalk->dd_name, + if (strncmp(disk, dtwalk->dd_name, sizeof (dtwalk->dd_name)) != 0) continue; if (dtwalk->dd_level != level) @@ -241,7 +232,7 @@ putdumptime(void) (struct dumpdates *)calloc(1, sizeof (struct dumpdates)); nddates += 1; found: - (void) strncpy(dtwalk->dd_name, fname, sizeof (dtwalk->dd_name)); + (void) strncpy(dtwalk->dd_name, disk, sizeof (dtwalk->dd_name)); dtwalk->dd_level = level; dtwalk->dd_ddate = spcl.c_date; diff --git a/dump/main.c b/dump/main.c index b292222..60f2bb4 100644 --- a/dump/main.c +++ b/dump/main.c @@ -41,19 +41,29 @@ #ifndef lint static const char rcsid[] = - "$Id: main.c,v 1.34 2001/02/22 10:57:40 stelian Exp $"; + "$Id: main.c,v 1.35 2001/03/19 13:22:48 stelian Exp $"; #endif /* not lint */ #include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include #include #ifdef __linux__ #include +#include #include #include #include -#else -#ifdef sunos +#elif defined sunos #include #include @@ -62,24 +72,9 @@ static const char rcsid[] = #include #include #endif -#endif #include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef __linux__ -#include -#endif - #include "dump.h" #include "pathnames.h" #include "bylabel.h" @@ -162,20 +157,17 @@ main(int argc, char *argv[]) usage(); obsolete(&argc, &argv); + + while ((ch = getopt(argc, argv, + "0123456789aB:b:cd:e:f:F:h:L:" #ifdef KERBEROS + "k" +#endif + "Mns:ST:uWw" #ifdef HAVE_ZLIB -#define optstring "0123456789aB:b:cd:e:f:F:h:kL:Mns:ST:uWwz" -#else -#define optstring "0123456789aB:b:cd:e:f:F:h:kL:Mns:ST:uWw" -#endif /* HAVE_ZLIB */ -#else -#ifdef HAVE_ZLIB -#define optstring "0123456789aB:b:cd:e:f:F:h:L:Mns:ST:uWwz" -#else -#define optstring "0123456789aB:b:cd:e:f:F:h:L:Mns:ST:uWw" -#endif /* HAVE_ZLIB */ -#endif /* KERBEROS */ - while ((ch = getopt(argc, argv, optstring)) != -1) + "z" +#endif + )) != -1) #undef optstring switch (ch) { /* dump level */ @@ -321,7 +313,8 @@ main(int argc, char *argv[]) } diskparam = *argv++; if (strlen(diskparam) >= MAXPATHLEN) { - (void)fprintf(stderr, "Disk or filesystem name too long: %s\n", diskparam); + (void)fprintf(stderr, "Disk or filesystem name too long: %s\n", + diskparam); exit(X_STARTUP); } argc--; @@ -396,6 +389,14 @@ main(int argc, char *argv[]) set_operators(); /* /etc/group snarfed */ getfstab(); /* /etc/fstab snarfed */ + /* + * disk may end in / and this can confuse + * fstabsearch. + */ + i = strlen(diskparam) - 1; + if (i > 1 && diskparam[i] == '/') + diskparam[i] = '\0'; + disk = get_device_name(diskparam); if (!disk) { /* null means the disk is some form of LABEL= or UID= but it was not @@ -403,12 +404,6 @@ main(int argc, char *argv[]) msg("Cannot find a disk having %s\n", diskparam); exit(X_STARTUP); } - /* - * disk may end in / and this can confuse - * fstabsearch. - */ - if (strlen(disk) > 1 && disk[strlen(disk) - 1] == '/') - disk[strlen(disk) - 1] = '\0'; /* * disk can be either the full special file name, * the suffix of the special file name, @@ -849,8 +844,8 @@ sig(int signo) } } -char * -rawname(char *cp) +const char * +rawname(const char *cp) { #ifdef __linux__ return cp; @@ -860,10 +855,8 @@ rawname(char *cp) if (dp == NULL) return (NULL); - *dp = '\0'; - (void)strncpy(rawbuf, cp, MAXPATHLEN - 1); - rawbuf[MAXPATHLEN-1] = '\0'; - *dp = '/'; + (void)strncpy(rawbuf, cp, min(dp-cp, MAXPATHLEN - 1)); + rawbuf[min(dp-cp, MAXPATHLEN-1)] = '\0'; (void)strncat(rawbuf, "/r", MAXPATHLEN - 1 - strlen(rawbuf)); (void)strncat(rawbuf, dp + 1, MAXPATHLEN - 1 - strlen(rawbuf)); return (rawbuf); diff --git a/dump/optr.c b/dump/optr.c index f0be80b..b8e6ff5 100644 --- a/dump/optr.c +++ b/dump/optr.c @@ -41,7 +41,7 @@ #ifndef lint static const char rcsid[] = - "$Id: optr.c,v 1.20 2001/02/22 10:57:40 stelian Exp $"; + "$Id: optr.c,v 1.21 2001/03/19 13:22:48 stelian Exp $"; #endif /* not lint */ #include @@ -505,7 +505,7 @@ fstabsearch(const char *key) { register struct pfstab *pf; register struct fstab *fs; - char *rn; + const char *rn; for (pf = table; pf != NULL; pf = pf->pf_next) { fs = pf->pf_fstab; diff --git a/dump/tape.c b/dump/tape.c index ae2fe1c..f43c3a2 100644 --- a/dump/tape.c +++ b/dump/tape.c @@ -41,10 +41,24 @@ #ifndef lint static const char rcsid[] = - "$Id: tape.c,v 1.33 2001/03/18 15:35:44 stelian Exp $"; + "$Id: tape.c,v 1.34 2001/03/19 13:22:48 stelian Exp $"; #endif /* not lint */ #include +#include +#include +#include +#include +#include +#include +#ifdef __STDC__ +#include +#include +#include +#else +int write(), read(); +#endif + #ifdef __linux__ #include #include @@ -56,9 +70,9 @@ static const char rcsid[] = #include #ifdef __linux__ #include +#include #include -#else /* __linux__ */ -#ifdef sunos +#elif defined sunos #include #include @@ -66,29 +80,10 @@ static const char rcsid[] = #else #include #include -#endif #endif /* __linux__ */ #include -#include -#include -#include -#include -#include -#include -#ifdef __STDC__ -#include -#include -#include -#else -int write(), read(); -#endif - -#ifdef __linux__ -#include -#endif - #ifdef HAVE_ZLIB #include #endif /* HAVE_ZLIB */ diff --git a/dump/traverse.c b/dump/traverse.c index 5833da7..038c96f 100644 --- a/dump/traverse.c +++ b/dump/traverse.c @@ -41,21 +41,26 @@ #ifndef lint static const char rcsid[] = - "$Id: traverse.c,v 1.25 2000/12/21 11:14:54 stelian Exp $"; + "$Id: traverse.c,v 1.26 2001/03/19 13:22:49 stelian Exp $"; #endif /* not lint */ #include +#include +#include +#ifdef __STDC__ +#include +#include +#endif + #include #include #ifdef __linux__ #include +#include #include #include #include -#define swab32(x) ext2fs_swab32(x) -#else /* __linux__ */ -#define swab32(x) x -#ifdef sunos +#elif defined sunos #include #include @@ -65,22 +70,10 @@ static const char rcsid[] = #include #include #include -#endif #endif /* __linux__ */ #include -#include -#include -#ifdef __STDC__ -#include -#include -#endif - -#ifdef __linux__ -#include -#endif - #include "dump.h" #define HASDUMPEDFILE 0x1 @@ -106,36 +99,66 @@ static int searchdir __P((ino_t ino, daddr_t blkno, long size, long filesize)); #endif static void mapfileino __P((ino_t ino, struct dinode const *dp, long *tapesize, int *dirskipped)); static int exclude_ino __P((ino_t ino)); +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 -/* #define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004 */ -#ifdef EXT3_FEATURE_INCOMPAT_RECOVER +#ifndef EXT3_FEATURE_COMPAT_HAS_JOURNAL +#define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004 +#endif +#ifndef EXT2_FEATURE_INCOMPAT_FILETYPE +#define EXT2_FEATURE_INCOMPAT_FILETYPE 0x0002 +#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 +#endif + +#ifndef EXT2_LIB_FEATURE_INCOMPAT_SUPP +#define EXT2_LIB_FEATURE_INCOMPAT_SUPP (EXT3_FEATURE_INCOMPAT_RECOVER | \ + EXT2_FEATURE_INCOMPAT_FILETYPE) #endif int dump_fs_open(const char *disk, ext2_filsys *fs) { int retval; - struct ext2fs_sb *s; retval = ext2fs_open(disk, FORCE_OPEN, 0, 0, unix_io_manager, fs); -#if defined(EXT2_LIB_FEATURE_COMPAT_SUPP) && defined(EXT2_LIB_FEATURE_INCOMPAT_SUPP) && defined(EXT2_LIB_FEATURE_RO_COMPAT_SUPP) && defined(EXT2_ET_UNSUPP_FEATURE) && defined(EXT2_ET_RO_UNSUPP_FEATURE) if (!retval) { - s = (struct ext2fs_sb *) (*fs)->super; - if ((s->s_feature_compat & ~EXT2_LIB_FEATURE_COMPAT_SUPP) || -#ifdef EXT3_FEATURE_INCOMPAT_RECOVER - (s->s_feature_incompat & ~(EXT3_FEATURE_INCOMPAT_RECOVER | EXT2_LIB_FEATURE_INCOMPAT_SUPP))) { -#else - (s->s_feature_incompat & ~EXT2_LIB_FEATURE_INCOMPAT_SUPP)) { -#endif + 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; + ext2fs_close(*fs); } - else if (s->s_feature_ro_compat & ~EXT2_LIB_FEATURE_RO_COMPAT_SUPP) { - retval = EXT2_ET_RO_UNSUPP_FEATURE; + else if ((retval = es->s_feature_incompat & + ~(EXT2_LIB_FEATURE_INCOMPAT_SUPP | + EXT3_FEATURE_INCOMPAT_RECOVER))) { + fprintf(stderr, + "Unsupported feature(s) 0x%x in filesystem\n", + retval); + retval = EXT2_ET_UNSUPP_FEATURE; + ext2fs_close(*fs); + } + else if (es->s_feature_compat & + 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); } } -#endif /* defined && defined && defined... */ return retval; } @@ -189,9 +212,6 @@ blockest(struct dinode const *dp) return (blkest + 1); } -extern ino_t iexclude_list[IEXCLUDE_MAXNUM]; /* the inode exclude list */ -extern int iexclude_num; /* number of elements in the list */ - /* * This tests whether an inode is in the exclude list */ @@ -1022,16 +1042,15 @@ dmpindir(ino_t ino, daddr_t blk, int ind_level, fsizeT *size) */ #if defined(EXT2_FLAG_SWAP_BYTES) if ((fs->flags & EXT2_FLAG_SWAP_BYTES) || - (fs->flags & EXT2_FLAG_SWAP_BYTES_READ)) { + (fs->flags & EXT2_FLAG_SWAP_BYTES_READ)) #endif + { max = sblock->fs_bsize >> 2; swapme = (blk_t *) idblk; for (i = 0; i < max; i++, swapme++) - *swapme = swab32(*swapme); -#if defined(EXT2_FLAG_SWAP_BYTES) + *swapme = ext2fs_swab32(*swapme); } -#endif -#endif +#endif /* __linux__ */ else memset(idblk, 0, (int)sblock->fs_bsize); if (ind_level <= 0) { @@ -1111,29 +1130,20 @@ dumpmap(char *map, int type, ino_t ino) /* * Write a header record to the dump tape. */ +#if defined __linux__ && !defined(int32_t) +#define int32_t __s32 +#endif void writeheader(ino_t ino) { -#ifdef __linux__ - register __s32 sum, cnt, *lp; -#else register int32_t sum, cnt, *lp; -#endif spcl.c_inumber = ino; spcl.c_magic = NFS_MAGIC; spcl.c_checksum = 0; -#ifdef __linux__ - lp = (__s32 *)&spcl; -#else lp = (int32_t *)&spcl; -#endif sum = 0; -#ifdef __linux__ - cnt = sizeof(union u_spcl) / (4 * sizeof(__s32)); -#else cnt = sizeof(union u_spcl) / (4 * sizeof(int32_t)); -#endif while (--cnt >= 0) { sum += *lp++; sum += *lp++; diff --git a/restore/tape.c b/restore/tape.c index 27a98d3..d7471a3 100644 --- a/restore/tape.c +++ b/restore/tape.c @@ -46,10 +46,18 @@ #ifndef lint static const char rcsid[] = - "$Id: tape.c,v 1.26 2001/03/18 15:35:44 stelian Exp $"; + "$Id: tape.c,v 1.27 2001/03/19 13:22:49 stelian Exp $"; #endif /* not lint */ #include +#include +#include +#include +#include +#include +#include +#include + #include #include #include @@ -59,28 +67,17 @@ static const char rcsid[] = #include #include #include +#include #include #else /* __linux__ */ #include #endif /* __linux__ */ #include -#include -#include -#include -#include -#include -#include -#include - #ifdef HAVE_ZLIB #include #endif /* HAVE_ZLIB */ -#ifdef __linux__ -#include -#endif - #include "restore.h" #include "extern.h" #include "pathnames.h" diff --git a/restore/utilities.c b/restore/utilities.c index c616872..a7164fb 100644 --- a/restore/utilities.c +++ b/restore/utilities.c @@ -41,32 +41,29 @@ #ifndef lint static const char rcsid[] = - "$Id: utilities.c,v 1.11 2000/12/21 11:14:54 stelian Exp $"; + "$Id: utilities.c,v 1.12 2001/03/19 13:22:49 stelian Exp $"; #endif /* not lint */ #include +#include +#include +#include +#include +#include + #include #include #ifdef __linux__ #include #include +#include #include #else /* __linux__ */ #include #include #endif /* __linux__ */ -#include -#include -#include -#include -#include - -#ifdef __linux__ -#include -#endif - #include "restore.h" #include "extern.h" -- 2.39.2