]> git.wh0rd.org - dump.git/commitdiff
Andreas Dilger fixes (CPP, ext2 features, const char etc).
authorStelian Pop <stelian@popies.net>
Mon, 19 Mar 2001 13:22:48 +0000 (13:22 +0000)
committerStelian Pop <stelian@popies.net>
Mon, 19 Mar 2001 13:22:48 +0000 (13:22 +0000)
12 files changed:
CHANGES
compat/include/fstab.h
compat/lib/bylabel.c
compat/lib/fstab.c
dump/dump.h
dump/itime.c
dump/main.c
dump/optr.c
dump/tape.c
dump/traverse.c
restore/tape.c
restore/utilities.c

diff --git a/CHANGES b/CHANGES
index 246adb08a4c64263658eae4e57518ecdc0aee8cd..934328d171f7f2e61f16003c5f77c8f121dd3a71 100644 (file)
--- 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 ????????????????)
 ======================================================================
 
 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 <bdale@gag.com> for forwarding
        it upstream.
 
        the patch and to Bdale Garbee <bdale@gag.com> for forwarding
        it upstream.
 
+5.     Many cleanups (CPP defines, const char warnings, check of
+       ext2fs COMPAT flags) by Andreas Dilger <adilger@turbolinux.com>.
+
 Changes between versions 0.4b20 and 0.4b21 (released January 13, 2001)
 ======================================================================
 
 Changes between versions 0.4b20 and 0.4b21 (released January 13, 2001)
 ======================================================================
 
index fa93f04a72cd95410b45cdf7ab69204d40fce179..8386e8d1ebec9fc92709ed5214adecda96847cea 100644 (file)
@@ -5,7 +5,7 @@
  *     Stelian Pop <pop@noos.fr>, 1999-2000
  *     Stelian Pop <pop@noos.fr> - Alcôve <www.alcove.fr>, 2000
  *
  *     Stelian Pop <pop@noos.fr>, 1999-2000
  *     Stelian Pop <pop@noos.fr> - Alcôve <www.alcove.fr>, 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 {
 #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 */
        char    *fs_file;               /* file system path prefix */
        char    *fs_vfstype;            /* File system type, ufs, nfs */
        char    *fs_mntops;             /* Mount options ala -o */
index 31bdd0d601746b66a31b477ff73461a040b18ed6..065d52985c5629ec810e53f2ae46953bf045b4c1 100644 (file)
 #define PROC_PARTITIONS "/proc/partitions"
 #define DEVLABELDIR    "/dev"
 
 #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];
 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 (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;
        }
                close(fd);
                return 1;
        }
index aa23462999d56a7836e9c999de84f22e9814834e..9f11a65d7bf3ee058a018a713c4c0e57a00d4f4b 100644 (file)
@@ -41,7 +41,7 @@
 
 #ifndef lint
 static const char rcsid[] =
 
 #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 <config.h>
 #endif /* not lint */
 
 #include <config.h>
@@ -70,9 +70,9 @@ int fstabscan(void)
        int typexx;
 #define        MAXLINELENGTH   1024
        char subline[MAXLINELENGTH];
        int typexx;
 #define        MAXLINELENGTH   1024
        char subline[MAXLINELENGTH];
-       char *device_name;
 
        for (;;) {
 
        for (;;) {
+               const char *device_name;
                if (!(mnt = getmntent(_fs_fp)))
                        return 0;
 
                if (!(mnt = getmntent(_fs_fp)))
                        return 0;
 
index c32631b5c8feb7c0ea914d9ef2332f2765bedc25..4e3fadaa50c0e3f9705482b16964982a08408956 100644 (file)
@@ -5,7 +5,7 @@
  *     Stelian Pop <pop@noos.fr>, 1999-2000
  *     Stelian Pop <pop@noos.fr> - Alcôve <www.alcove.fr>, 2000
  *
  *     Stelian Pop <pop@noos.fr>, 1999-2000
  *     Stelian Pop <pop@noos.fr> - Alcôve <www.alcove.fr>, 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!
  */
 /*
  *     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*/
 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));
 
 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 */
 struct dinode *getino __P((ino_t inum));
 
 /* rdump routines */
index 6eebd2c524b00343234328e505f56a747eef4355..836b6ae09bb7b4710069c16a68406e55b84d5bce 100644 (file)
 
 #ifndef lint
 static const char rcsid[] =
 
 #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 <config.h>
 #endif /* not lint */
 
 #include <config.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#ifdef __STDC__
+#include <stdlib.h>
+#include <string.h>
+#endif
+
 #include <sys/param.h>
 #include <sys/time.h>
 #ifdef __linux__
 #include <linux/ext2_fs.h>
 #include <sys/param.h>
 #include <sys/time.h>
 #ifdef __linux__
 #include <linux/ext2_fs.h>
+#include <ext2fs/ext2fs.h>
 #include <time.h>
 #include <bsdcompat.h>
 #include <sys/file.h>
 #include <unistd.h>
 #include <time.h>
 #include <bsdcompat.h>
 #include <sys/file.h>
 #include <unistd.h>
-#else
-#ifdef sunos
+#elif defined sunos
 #include <sys/vnode.h>
 
 #include <ufs/fsdir.h>
 #include <sys/vnode.h>
 
 #include <ufs/fsdir.h>
@@ -63,22 +71,9 @@ static const char rcsid[] =
 #else
 #include <ufs/ufs/dinode.h>
 #endif
 #else
 #include <ufs/ufs/dinode.h>
 #endif
-#endif
 
 #include <protocols/dumprestore.h>
 
 
 #include <protocols/dumprestore.h>
 
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#ifdef __STDC__
-#include <stdlib.h>
-#include <string.h>
-#endif
-
-#ifdef __linux__
-#include <ext2fs/ext2fs.h>
-#endif
-
 #include "dump.h"
 
 struct dumpdates **ddatev;
 #include "dump.h"
 
 struct dumpdates **ddatev;
@@ -161,12 +156,10 @@ getdumptime(int createdumpdates)
 {
        register struct dumpdates *ddp;
        register int i;
 {
        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",
 #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';
 #endif
        spcl.c_ddate = 0;
        lastlevel = '0';
@@ -185,7 +178,7 @@ getdumptime(int createdumpdates)
         *      and older date
         */
        ITITERATE(i, ddp) {
         *      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;
                        continue;
                if (ddp->dd_level >= level)
                        continue;
@@ -207,7 +200,6 @@ putdumptime(void)
        register struct dumpdates *dtwalk;
        register int i;
        int fd;
        register struct dumpdates *dtwalk;
        register int i;
        int fd;
-       char *fname;
 
        if(uflag == 0)
                return;
 
        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);
                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;
        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) {
                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)
                                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:
                (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;
 
        dtwalk->dd_level = level;
        dtwalk->dd_ddate = spcl.c_date;
 
index b2922223de3d51b433602f9f1c30127e8f79903e..60f2bb4b7a4f9d145ac70f89c2addfb14fe6598f 100644 (file)
 
 #ifndef lint
 static const char rcsid[] =
 
 #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 <config.h>
 #endif /* not lint */
 
 #include <config.h>
+#include <ctype.h>
+#include <compaterr.h>
+#include <fcntl.h>
+#include <fstab.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
 #include <sys/param.h>
 #include <sys/time.h>
 #ifdef __linux__
 #include <linux/ext2_fs.h>
 #include <sys/param.h>
 #include <sys/time.h>
 #ifdef __linux__
 #include <linux/ext2_fs.h>
+#include <ext2fs/ext2fs.h>
 #include <time.h>
 #include <sys/stat.h>
 #include <bsdcompat.h>
 #include <time.h>
 #include <sys/stat.h>
 #include <bsdcompat.h>
-#else
-#ifdef sunos
+#elif defined sunos
 #include <sys/vnode.h>
 
 #include <ufs/inode.h>
 #include <sys/vnode.h>
 
 #include <ufs/inode.h>
@@ -62,24 +72,9 @@ static const char rcsid[] =
 #include <ufs/ufs/dinode.h>
 #include <ufs/ffs/fs.h>
 #endif
 #include <ufs/ufs/dinode.h>
 #include <ufs/ffs/fs.h>
 #endif
-#endif
 
 #include <protocols/dumprestore.h>
 
 
 #include <protocols/dumprestore.h>
 
-#include <ctype.h>
-#include <compaterr.h>
-#include <fcntl.h>
-#include <fstab.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#ifdef __linux__
-#include <ext2fs/ext2fs.h>
-#endif
-
 #include "dump.h"
 #include "pathnames.h"
 #include "bylabel.h"
 #include "dump.h"
 #include "pathnames.h"
 #include "bylabel.h"
@@ -162,20 +157,17 @@ main(int argc, char *argv[])
                usage();
 
        obsolete(&argc, &argv);
                usage();
 
        obsolete(&argc, &argv);
+
+       while ((ch = getopt(argc, argv,
+                           "0123456789aB:b:cd:e:f:F:h:L:"
 #ifdef KERBEROS
 #ifdef KERBEROS
+                           "k"
+#endif
+                           "Mns:ST:uWw"
 #ifdef HAVE_ZLIB
 #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 */
 #undef optstring
                switch (ch) {
                /* dump level */
@@ -321,7 +313,8 @@ main(int argc, char *argv[])
        }
        diskparam = *argv++;
        if (strlen(diskparam) >= MAXPATHLEN) {
        }
        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--;
                exit(X_STARTUP);
        }
        argc--;
@@ -396,6 +389,14 @@ main(int argc, char *argv[])
        set_operators();        /* /etc/group snarfed */
        getfstab();             /* /etc/fstab snarfed */
 
        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
        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);
        }
                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,
        /*
         *      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;
 {
 #ifdef __linux__
        return cp;
@@ -860,10 +855,8 @@ rawname(char *cp)
 
        if (dp == NULL)
                return (NULL);
 
        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);
        (void)strncat(rawbuf, "/r", MAXPATHLEN - 1 - strlen(rawbuf));
        (void)strncat(rawbuf, dp + 1, MAXPATHLEN - 1 - strlen(rawbuf));
        return (rawbuf);
index f0be80bc263c59ae0f3c779049e6226b897052ed..b8e6ff5e28cdeaf756b95c41572ba9007a2cd7dd 100644 (file)
@@ -41,7 +41,7 @@
 
 #ifndef lint
 static const char rcsid[] =
 
 #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 <config.h>
 #endif /* not lint */
 
 #include <config.h>
@@ -505,7 +505,7 @@ fstabsearch(const char *key)
 {
        register struct pfstab *pf;
        register struct fstab *fs;
 {
        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;
 
        for (pf = table; pf != NULL; pf = pf->pf_next) {
                fs = pf->pf_fstab;
index ae2fe1c6cc51255b6f38c37f534a979b3137cce5..f43c3a20a9b3d4aae071afcb90ca90bd3641ebac 100644 (file)
 
 #ifndef lint
 static const char rcsid[] =
 
 #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 <config.h>
 #endif /* not lint */
 
 #include <config.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <setjmp.h>
+#include <signal.h>
+#include <stdio.h>
+#include <compaterr.h>
+#ifdef __STDC__
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#else
+int    write(), read();
+#endif
+
 #ifdef __linux__
 #include <sys/types.h>
 #include <time.h>
 #ifdef __linux__
 #include <sys/types.h>
 #include <time.h>
@@ -56,9 +70,9 @@ static const char rcsid[] =
 #include <sys/wait.h>
 #ifdef __linux__
 #include <linux/ext2_fs.h>
 #include <sys/wait.h>
 #ifdef __linux__
 #include <linux/ext2_fs.h>
+#include <ext2fs/ext2fs.h>
 #include <bsdcompat.h>
 #include <bsdcompat.h>
-#else  /* __linux__ */
-#ifdef sunos
+#elif defined sunos
 #include <sys/vnode.h>
 
 #include <ufs/fs.h>
 #include <sys/vnode.h>
 
 #include <ufs/fs.h>
@@ -66,29 +80,10 @@ static const char rcsid[] =
 #else
 #include <ufs/ufs/dinode.h>
 #include <ufs/ffs/fs.h>
 #else
 #include <ufs/ufs/dinode.h>
 #include <ufs/ffs/fs.h>
-#endif
 #endif /* __linux__ */
 
 #include <protocols/dumprestore.h>
 
 #endif /* __linux__ */
 
 #include <protocols/dumprestore.h>
 
-#include <errno.h>
-#include <fcntl.h>
-#include <setjmp.h>
-#include <signal.h>
-#include <stdio.h>
-#include <compaterr.h>
-#ifdef __STDC__
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#else
-int    write(), read();
-#endif
-
-#ifdef __linux__
-#include <ext2fs/ext2fs.h>
-#endif
-
 #ifdef HAVE_ZLIB
 #include <zlib.h>
 #endif /* HAVE_ZLIB */
 #ifdef HAVE_ZLIB
 #include <zlib.h>
 #endif /* HAVE_ZLIB */
index 5833da7a4cdf8739b35d528b4ef528f74d1ac336..038c96f1d3c35676620d055dc72fa19e734d0e8e 100644 (file)
 
 #ifndef lint
 static const char rcsid[] =
 
 #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 <config.h>
 #endif /* not lint */
 
 #include <config.h>
+#include <ctype.h>
+#include <stdio.h>
+#ifdef __STDC__
+#include <string.h>
+#include <unistd.h>
+#endif
+
 #include <sys/param.h>
 #include <sys/stat.h>
 #ifdef __linux__
 #include <linux/ext2_fs.h>
 #include <sys/param.h>
 #include <sys/stat.h>
 #ifdef __linux__
 #include <linux/ext2_fs.h>
+#include <ext2fs/ext2fs.h>
 #include <bsdcompat.h>
 #include <compaterr.h>
 #include <stdlib.h>
 #include <bsdcompat.h>
 #include <compaterr.h>
 #include <stdlib.h>
-#define swab32(x) ext2fs_swab32(x)
-#else  /* __linux__ */
-#define swab32(x) x
-#ifdef sunos
+#elif defined sunos
 #include <sys/vnode.h>
 
 #include <ufs/fs.h>
 #include <sys/vnode.h>
 
 #include <ufs/fs.h>
@@ -65,22 +70,10 @@ static const char rcsid[] =
 #include <ufs/ufs/dir.h>
 #include <ufs/ufs/dinode.h>
 #include <ufs/ffs/fs.h>
 #include <ufs/ufs/dir.h>
 #include <ufs/ufs/dinode.h>
 #include <ufs/ffs/fs.h>
-#endif
 #endif /* __linux__ */
 
 #include <protocols/dumprestore.h>
 
 #endif /* __linux__ */
 
 #include <protocols/dumprestore.h>
 
-#include <ctype.h>
-#include <stdio.h>
-#ifdef __STDC__
-#include <string.h>
-#include <unistd.h>
-#endif
-
-#ifdef __linux__
-#include <ext2fs/ext2fs.h>
-#endif
-
 #include "dump.h"
 
 #define        HASDUMPEDFILE   0x1
 #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));
 #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 FORCE_OPEN     EXT2_FLAG_FORCE
+#define ext2_journal_ino(sb)   (*((__u32 *)sb + 0x38))
 #else
 #define FORCE_OPEN     0
 #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;
 #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);
 
        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) {
        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;
                        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;
 }
 
        return retval;
 }
 
@@ -189,9 +212,6 @@ blockest(struct dinode const *dp)
        return (blkest + 1);
 }
 
        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 
  */
 /*
  * 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) ||
         */
 #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
 #endif
+       {
                max = sblock->fs_bsize >> 2;
                swapme = (blk_t *) idblk;
                for (i = 0; i < max; i++, swapme++)
                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) {
        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.
  */
 /*
  * Write a header record to the dump tape.
  */
+#if defined __linux__ && !defined(int32_t)
+#define int32_t __s32
+#endif
 void
 writeheader(ino_t ino)
 {
 void
 writeheader(ino_t ino)
 {
-#ifdef __linux__
-       register __s32 sum, cnt, *lp;
-#else
        register int32_t sum, cnt, *lp;
        register int32_t sum, cnt, *lp;
-#endif
 
        spcl.c_inumber = ino;
        spcl.c_magic = NFS_MAGIC;
        spcl.c_checksum = 0;
 
        spcl.c_inumber = ino;
        spcl.c_magic = NFS_MAGIC;
        spcl.c_checksum = 0;
-#ifdef __linux__
-       lp = (__s32 *)&spcl;
-#else
        lp = (int32_t *)&spcl;
        lp = (int32_t *)&spcl;
-#endif
        sum = 0;
        sum = 0;
-#ifdef __linux__
-       cnt = sizeof(union u_spcl) / (4 * sizeof(__s32));
-#else
        cnt = sizeof(union u_spcl) / (4 * sizeof(int32_t));
        cnt = sizeof(union u_spcl) / (4 * sizeof(int32_t));
-#endif
        while (--cnt >= 0) {
                sum += *lp++;
                sum += *lp++;
        while (--cnt >= 0) {
                sum += *lp++;
                sum += *lp++;
index 27a98d32bfabe9de89aba4a3d512f8f2c49898ca..d7471a39b6513e9228c75b7d5959a3fb2a7c640f 100644 (file)
 
 #ifndef lint
 static const char rcsid[] =
 
 #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 <config.h>
 #endif /* not lint */
 
 #include <config.h>
+#include <errno.h>
+#include <compaterr.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
 #include <sys/param.h>
 #include <sys/file.h>
 #include <sys/mtio.h>
 #include <sys/param.h>
 #include <sys/file.h>
 #include <sys/mtio.h>
@@ -59,28 +67,17 @@ static const char rcsid[] =
 #include <sys/time.h>
 #include <time.h>
 #include <linux/ext2_fs.h>
 #include <sys/time.h>
 #include <time.h>
 #include <linux/ext2_fs.h>
+#include <ext2fs/ext2fs.h>
 #include <bsdcompat.h>
 #else  /* __linux__ */
 #include <ufs/ufs/dinode.h>
 #endif /* __linux__ */
 #include <protocols/dumprestore.h>
 
 #include <bsdcompat.h>
 #else  /* __linux__ */
 #include <ufs/ufs/dinode.h>
 #endif /* __linux__ */
 #include <protocols/dumprestore.h>
 
-#include <errno.h>
-#include <compaterr.h>
-#include <setjmp.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
 #ifdef HAVE_ZLIB
 #include <zlib.h>
 #endif /* HAVE_ZLIB */
 
 #ifdef HAVE_ZLIB
 #include <zlib.h>
 #endif /* HAVE_ZLIB */
 
-#ifdef __linux__
-#include <ext2fs/ext2fs.h>
-#endif
-
 #include "restore.h"
 #include "extern.h"
 #include "pathnames.h"
 #include "restore.h"
 #include "extern.h"
 #include "pathnames.h"
index c6168724d95e65c1eea2e9d8867a102f41ce0198..a7164fb134697d34bd13231d9d7a6f8ae57e01ca 100644 (file)
 
 #ifndef lint
 static const char rcsid[] =
 
 #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 <config.h>
 #endif /* not lint */
 
 #include <config.h>
+#include <errno.h>
+#include <compaterr.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
 #include <sys/param.h>
 #include <sys/stat.h>
 
 #ifdef __linux__
 #include <sys/time.h>
 #include <linux/ext2_fs.h>
 #include <sys/param.h>
 #include <sys/stat.h>
 
 #ifdef __linux__
 #include <sys/time.h>
 #include <linux/ext2_fs.h>
+#include <ext2fs/ext2fs.h>
 #include <bsdcompat.h>
 #else  /* __linux__ */
 #include <ufs/ufs/dinode.h>
 #include <ufs/ufs/dir.h>
 #endif /* __linux__ */
 
 #include <bsdcompat.h>
 #else  /* __linux__ */
 #include <ufs/ufs/dinode.h>
 #include <ufs/ufs/dir.h>
 #endif /* __linux__ */
 
-#include <errno.h>
-#include <compaterr.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#ifdef __linux__
-#include <ext2fs/ext2fs.h>
-#endif
-
 #include "restore.h"
 #include "extern.h"
 
 #include "restore.h"
 #include "extern.h"