]> git.wh0rd.org - dump.git/blobdiff - restore/dirs.c
New compression patches from Jerry Peters.
[dump.git] / restore / dirs.c
index abc618148d54fda14cd5795dd949c9df82b69cf7..eb90558ef7369819fa66eaaef4da5d86d2a3d5a1 100644 (file)
@@ -2,7 +2,8 @@
  *     Ported to Linux's Second Extended File System as part of the
  *     dump and restore backup suit
  *     Remy Card <card@Linux.EU.Org>, 1994-1997
- *     Stelian Pop <pop@cybercable.fr>, 1999 
+ *     Stelian Pop <pop@noos.fr>, 1999-2000
+ *     Stelian Pop <pop@noos.fr> - AlcĂ´ve <www.alcove.fr>, 2000
  */
 
 /*
 
 #ifndef lint
 static const char rcsid[] =
-       "$Id: dirs.c,v 1.6 1999/10/13 09:57:20 stelian Exp $";
+       "$Id: dirs.c,v 1.13 2000/12/21 11:14:54 stelian Exp $";
 #endif /* not lint */
 
+#include <config.h>
 #include <sys/param.h>
 #include <sys/file.h>
 #include <sys/stat.h>
@@ -207,12 +209,13 @@ extractdirs(int genmode)
                curfile.action = USING;
                ip = curfile.dip;
                if (ip == NULL || (ip->di_mode & IFMT) != IFDIR) {
-                       (void) fclose(df);
+                       if ( fclose(df) == EOF )
+                               err(1, "cannot write to file %s", dirfile);
                        dirp = opendirfile(dirfile);
                        if (dirp == NULL)
                                warn("opendirfile");
-                       if (mf != NULL)
-                               (void) fclose(mf);
+                       if (mf != NULL && fclose(mf) == EOF )
+                               err(1, "cannot write to file %s", dirfile);
                        i = dirlookup(dot);
                        if (i == 0)
                                panic("Root directory is not on tape\n");
@@ -379,10 +382,6 @@ putdir(char *buf, size_t size)
                        if (Bcvt)
                                swabst((u_char *)"is", (u_char *) dp);
                        if (oldinofmt && dp->d_ino != 0) {
-#ifdef __linux__
-                               if (Bcvt)
-                                       swabst((u_char *)"s", (u_char *)&dp->d_namlen);
-#else
 #                              if BYTE_ORDER == BIG_ENDIAN
                                        if (Bcvt)
                                                dp->d_namlen = dp->d_type;
@@ -390,16 +389,8 @@ putdir(char *buf, size_t size)
                                        if (!Bcvt)
                                                dp->d_namlen = dp->d_type;
 #                              endif
-#endif /* __linux__ */
                                dp->d_type = DT_UNKNOWN;
                        }
-#ifdef __linux__
-                       /*
-                        * Horrible hack to read FreeBSD 2.0 dumps
-                        */
-                       if (!oldinofmt)
-                               swabst((u_char *)"6bs", (u_char *) dp);
-#endif /* __linux__ */
 #ifdef DIRDEBUG
                        printf ("reclen = %d, namlen = %d, type = %d\n",
                                dp->d_reclen, dp->d_namlen, dp->d_type);
@@ -408,7 +399,7 @@ putdir(char *buf, size_t size)
                        if ((dp->d_reclen & 0x3) != 0 ||
                            dp->d_reclen > i ||
                            dp->d_reclen < DIRSIZ(0, dp) ||
-                           dp->d_namlen > NAME_MAX) {
+                           dp->d_namlen > MAXNAMLEN) {
                                Vprintf(stdout, "Mangled directory: ");
                                if ((dp->d_reclen & 0x3) != 0)
                                        Vprintf(stdout,
@@ -417,10 +408,10 @@ putdir(char *buf, size_t size)
                                        Vprintf(stdout,
                                           "reclen less than DIRSIZ (%d < %d) ",
                                           dp->d_reclen, DIRSIZ(0, dp));
-                               if (dp->d_namlen > NAME_MAX)
+                               if (dp->d_namlen > MAXNAMLEN)
                                        Vprintf(stdout,
                                           "reclen name too big (%d > %d) ",
-                                          dp->d_namlen, NAME_MAX);
+                                          dp->d_namlen, MAXNAMLEN);
                                Vprintf(stdout, "\n");
                                loc += i;
                                continue;
@@ -450,7 +441,8 @@ putent(struct direct *dp)
        if (dirloc + dp->d_reclen > DIRBLKSIZ) {
                ((struct direct *)(dirbuf + prev))->d_reclen =
                    DIRBLKSIZ - prev;
-               (void) fwrite(dirbuf, 1, DIRBLKSIZ, df);
+               if ( fwrite(dirbuf, 1, DIRBLKSIZ, df) != DIRBLKSIZ )
+                       err(1,"cannot write to file %s", dirfile);
                dirloc = 0;
        }
        memmove(dirbuf + dirloc, dp, (size_t)dp->d_reclen);
@@ -465,8 +457,11 @@ static void
 flushent(void)
 {
        ((struct direct *)(dirbuf + prev))->d_reclen = DIRBLKSIZ - prev;
-       (void) fwrite(dirbuf, (int)dirloc, 1, df);
+       if ( fwrite(dirbuf, (int)dirloc, 1, df) != 1 )
+               err(1, "cannot write to file %s", dirfile);
        seekpt = ftell(df);
+       if (seekpt == -1)
+               err(1, "cannot write to file %s", dirfile);
        dirloc = 0;
 }
 
@@ -759,7 +754,8 @@ allocinotab(ino_t ino, struct dinode *dip, long seekpt)
        node.flags = dip->di_flags;
        node.uid = dip->di_uid;
        node.gid = dip->di_gid;
-       (void) fwrite((char *)&node, 1, sizeof(struct modeinfo), mf);
+       if ( fwrite((char *)&node, 1, sizeof(struct modeinfo), mf) != sizeof(struct modeinfo) )
+               err(1,"cannot write to file %s", modefile);
        return (itp);
 }