BSD 4_4_Lite2 release
[unix-history] / usr / src / sbin / restore / dirs.c
index 5a2651c..d6c12d3 100644 (file)
@@ -37,7 +37,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)dirs.c     8.2 (Berkeley) 1/21/94";
+static char sccsid[] = "@(#)dirs.c     8.7 (Berkeley) 5/1/95";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -45,9 +45,9 @@ static char sccsid[] = "@(#)dirs.c    8.2 (Berkeley) 1/21/94";
 #include <sys/stat.h>
 #include <sys/time.h>
 
 #include <sys/stat.h>
 #include <sys/time.h>
 
-#include <ufs/ffs/fs.h>
 #include <ufs/ufs/dinode.h>
 #include <ufs/ufs/dir.h>
 #include <ufs/ufs/dinode.h>
 #include <ufs/ufs/dir.h>
+#include <ufs/ffs/fs.h>
 #include <protocols/dumprestore.h>
 
 #include <errno.h>
 #include <protocols/dumprestore.h>
 
 #include <errno.h>
@@ -56,6 +56,8 @@ static char sccsid[] = "@(#)dirs.c    8.2 (Berkeley) 1/21/94";
 #include <string.h>
 #include <unistd.h>
 
 #include <string.h>
 #include <unistd.h>
 
+#include <machine/endian.h>
+
 #include "pathnames.h"
 #include "restore.h"
 #include "extern.h"
 #include "pathnames.h"
 #include "restore.h"
 #include "extern.h"
@@ -79,9 +81,10 @@ static struct inotab *inotab[HASHSIZE];
 struct modeinfo {
        ino_t ino;
        struct timeval timep[2];
 struct modeinfo {
        ino_t ino;
        struct timeval timep[2];
-       short mode;
-       short uid;
-       short gid;
+       mode_t mode;
+       uid_t uid;
+       gid_t gid;
+       int flags;
 };
 
 /*
 };
 
 /*
@@ -256,7 +259,7 @@ treescan(pname, ino, todo)
        /*
         * a zero inode signals end of directory
         */
        /*
         * a zero inode signals end of directory
         */
-       while (dp != NULL && dp->d_ino != 0) {
+       while (dp != NULL) {
                locname[namelen] = '\0';
                if (namelen + dp->d_namlen >= MAXPATHLEN) {
                        fprintf(stderr, "%s%s: name exceeds %d char\n",
                locname[namelen] = '\0';
                if (namelen + dp->d_namlen >= MAXPATHLEN) {
                        fprintf(stderr, "%s%s: name exceeds %d char\n",
@@ -269,8 +272,6 @@ treescan(pname, ino, todo)
                dp = rst_readdir(dirp);
                bpt = rst_telldir(dirp);
        }
                dp = rst_readdir(dirp);
                bpt = rst_telldir(dirp);
        }
-       if (dp == NULL)
-               fprintf(stderr, "corrupted directory: %s.\n", locname);
 }
 
 /*
 }
 
 /*
@@ -318,7 +319,7 @@ searchdir(inum, name)
        len = strlen(name);
        do {
                dp = rst_readdir(dirp);
        len = strlen(name);
        do {
                dp = rst_readdir(dirp);
-               if (dp == NULL || dp->d_ino == 0)
+               if (dp == NULL)
                        return (NULL);
        } while (dp->d_namlen != len || strncmp(dp->d_name, name, len) != 0);
        return (dp);
                        return (NULL);
        } while (dp->d_namlen != len || strncmp(dp->d_name, name, len) != 0);
        return (dp);
@@ -348,14 +349,17 @@ putdir(buf, size)
        } else {
                for (loc = 0; loc < size; ) {
                        dp = (struct direct *)(buf + loc);
        } else {
                for (loc = 0; loc < size; ) {
                        dp = (struct direct *)(buf + loc);
-                       if (oldinofmt) {
-                               if (Bcvt) {
-                                       swabst((u_char *)"l2s", (u_char *) dp);
-                               }
-                       } else {
-                               if (Bcvt) {
-                                       swabst((u_char *)"ls", (u_char *) dp);
-                               }
+                       if (Bcvt)
+                               swabst((u_char *)"ls", (u_char *) dp);
+                       if (oldinofmt && dp->d_ino != 0) {
+#                              if BYTE_ORDER == BIG_ENDIAN
+                                       if (Bcvt)
+                                               dp->d_namlen = dp->d_type;
+#                              else
+                                       if (!Bcvt)
+                                               dp->d_namlen = dp->d_type;
+#                              endif
+                               dp->d_type = DT_UNKNOWN;
                        }
                        i = DIRBLKSIZ - (loc & (DIRBLKSIZ - 1));
                        if ((dp->d_reclen & 0x3) != 0 ||
                        }
                        i = DIRBLKSIZ - (loc & (DIRBLKSIZ - 1));
                        if ((dp->d_reclen & 0x3) != 0 ||
@@ -407,7 +411,7 @@ putent(dp)
                (void) fwrite(dirbuf, 1, DIRBLKSIZ, df);
                dirloc = 0;
        }
                (void) fwrite(dirbuf, 1, DIRBLKSIZ, df);
                dirloc = 0;
        }
-       bcopy((char *)dp, dirbuf + dirloc, (long)dp->d_reclen);
+       memmove(dirbuf + dirloc, dp, (long)dp->d_reclen);
        prev = dirloc;
        dirloc += dp->d_reclen;
 }
        prev = dirloc;
        dirloc += dp->d_reclen;
 }
@@ -430,7 +434,7 @@ dcvt(odp, ndp)
        register struct direct *ndp;
 {
 
        register struct direct *ndp;
 {
 
-       bzero((char *)ndp, (long)(sizeof *ndp));
+       memset(ndp, 0, (long)(sizeof *ndp));
        ndp->d_ino =  odp->d_ino;
        ndp->d_type = DT_UNKNOWN;
        (void) strncpy(ndp->d_name, odp->d_name, ODIRSIZ);
        ndp->d_ino =  odp->d_ino;
        ndp->d_type = DT_UNKNOWN;
        (void) strncpy(ndp->d_name, odp->d_name, ODIRSIZ);
@@ -492,8 +496,8 @@ rst_readdir(dirp)
                        return (NULL);
                }
                dirp->dd_loc += dp->d_reclen;
                        return (NULL);
                }
                dirp->dd_loc += dp->d_reclen;
-               if (dp->d_ino == 0 && strcmp(dp->d_name, "/") != 0)
-                       continue;
+               if (dp->d_ino == 0 && strcmp(dp->d_name, "/") == 0)
+                       return (NULL);
                if (dp->d_ino >= maxino) {
                        dprintf(stderr, "corrupted directory: bad inum %d\n",
                                dp->d_ino);
                if (dp->d_ino >= maxino) {
                        dprintf(stderr, "corrupted directory: bad inum %d\n",
                                dp->d_ino);
@@ -612,6 +616,7 @@ setdirmodes(flags)
                        cp = myname(ep);
                        (void) chown(cp, node.uid, node.gid);
                        (void) chmod(cp, node.mode);
                        cp = myname(ep);
                        (void) chown(cp, node.uid, node.gid);
                        (void) chmod(cp, node.mode);
+                       (void) chflags(cp, node.flags);
                        utimes(cp, node.timep);
                        ep->e_flags &= ~NEW;
                }
                        utimes(cp, node.timep);
                        ep->e_flags &= ~NEW;
                }
@@ -636,7 +641,7 @@ genliteraldir(name, ino)
        itp = inotablookup(ino);
        if (itp == NULL)
                panic("Cannot find directory inode %d named %s\n", ino, name);
        itp = inotablookup(ino);
        if (itp == NULL)
                panic("Cannot find directory inode %d named %s\n", ino, name);
-       if ((ofile = creat(name, 0666)) < 0) {
+       if ((ofile = open(name, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) {
                fprintf(stderr, "%s: ", name);
                (void) fflush(stderr);
                fprintf(stderr, "cannot create file: %s\n", strerror(errno));
                fprintf(stderr, "%s: ", name);
                (void) fflush(stderr);
                fprintf(stderr, "cannot create file: %s\n", strerror(errno));
@@ -704,11 +709,12 @@ allocinotab(ino, dip, seekpt)
        if (mf == NULL)
                return (itp);
        node.ino = ino;
        if (mf == NULL)
                return (itp);
        node.ino = ino;
-       node.timep[0].tv_sec = dip->di_atime.ts_sec;
-       node.timep[0].tv_usec = dip->di_atime.ts_nsec / 1000;
-       node.timep[1].tv_sec = dip->di_mtime.ts_sec;
-       node.timep[1].tv_usec = dip->di_mtime.ts_nsec / 1000;
+       node.timep[0].tv_sec = dip->di_atime;
+       node.timep[0].tv_usec = dip->di_atimensec / 1000;
+       node.timep[1].tv_sec = dip->di_mtime;
+       node.timep[1].tv_usec = dip->di_mtimensec / 1000;
        node.mode = dip->di_mode;
        node.mode = dip->di_mode;
+       node.flags = dip->di_flags;
        node.uid = dip->di_uid;
        node.gid = dip->di_gid;
        (void) fwrite((char *)&node, 1, sizeof(struct modeinfo), mf);
        node.uid = dip->di_uid;
        node.gid = dip->di_gid;
        (void) fwrite((char *)&node, 1, sizeof(struct modeinfo), mf);