BSD 4_4 release
[unix-history] / usr / src / sbin / fsck / dir.c
index 3943f4b..ee5d095 100644 (file)
@@ -1,12 +1,38 @@
 /*
 /*
- * Copyright (c) 1980, 1986 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1980, 1986, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)dir.c      5.22 (Berkeley) %G%";
+static char sccsid[] = "@(#)dir.c      8.1 (Berkeley) 6/5/93";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -137,8 +163,6 @@ fsck_readdir(idesc)
                dp = (struct direct *)(bp->b_un.b_buf + idesc->id_loc);
                if (dircheck(idesc, dp))
                        goto dpok;
                dp = (struct direct *)(bp->b_un.b_buf + idesc->id_loc);
                if (dircheck(idesc, dp))
                        goto dpok;
-               idesc->id_loc += DIRBLKSIZ;
-               idesc->id_filesize -= DIRBLKSIZ;
                fix = dofix(idesc, "DIRECTORY CORRUPTED");
                bp = getdirblk(idesc->id_blkno, blksiz);
                dp = (struct direct *)(bp->b_un.b_buf + idesc->id_loc);
                fix = dofix(idesc, "DIRECTORY CORRUPTED");
                bp = getdirblk(idesc->id_blkno, blksiz);
                dp = (struct direct *)(bp->b_un.b_buf + idesc->id_loc);
@@ -149,6 +173,8 @@ fsck_readdir(idesc)
                dp->d_name[0] = '\0';
                if (fix)
                        dirty(bp);
                dp->d_name[0] = '\0';
                if (fix)
                        dirty(bp);
+               idesc->id_loc += DIRBLKSIZ;
+               idesc->id_filesize -= DIRBLKSIZ;
                return (dp);
        }
 dpok:
                return (dp);
        }
 dpok:
@@ -304,6 +330,8 @@ mkentry(idesc)
        dirp->d_ino = idesc->id_parent; /* ino to be entered is in id_parent */
        if (newinofmt)
                dirp->d_type = typemap[idesc->id_parent];
        dirp->d_ino = idesc->id_parent; /* ino to be entered is in id_parent */
        if (newinofmt)
                dirp->d_type = typemap[idesc->id_parent];
+       else
+               dirp->d_type = 0;
        dirp->d_reclen = newent.d_reclen;
        dirp->d_namlen = newent.d_namlen;
        bcopy(idesc->id_name, dirp->d_name, (size_t)dirp->d_namlen + 1);
        dirp->d_reclen = newent.d_reclen;
        dirp->d_namlen = newent.d_namlen;
        bcopy(idesc->id_name, dirp->d_name, (size_t)dirp->d_namlen + 1);
@@ -320,6 +348,8 @@ chgino(idesc)
        dirp->d_ino = idesc->id_parent;
        if (newinofmt)
                dirp->d_type = typemap[idesc->id_parent];
        dirp->d_ino = idesc->id_parent;
        if (newinofmt)
                dirp->d_type = typemap[idesc->id_parent];
+       else
+               dirp->d_type = 0;
        return (ALTERED|STOP);
 }
 
        return (ALTERED|STOP);
 }