salvage the correct part of the directory
[unix-history] / usr / src / sbin / fsck / dir.c
index 3943f4b..1500365 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)dir.c      5.22 (Berkeley) %G%";
+static char sccsid[] = "@(#)dir.c      5.24 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -137,8 +137,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 +147,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 +304,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 +322,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);
 }