new copyright notice
[unix-history] / usr / src / sbin / fsck / pass2.c
index 4823557..557295a 100644 (file)
@@ -2,21 +2,11 @@
  * Copyright (c) 1980, 1986 The Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1980, 1986 The Regents of the University of California.
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * %sccs.include.redist.c%
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)pass2.c    5.10 (Berkeley) %G%";
+static char sccsid[] = "@(#)pass2.c    5.13 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -25,7 +15,7 @@ static char sccsid[] = "@(#)pass2.c   5.10 (Berkeley) %G%";
 #define KERNEL
 #include <ufs/dir.h>
 #undef KERNEL
 #define KERNEL
 #include <ufs/dir.h>
 #undef KERNEL
-#include <strings.h>
+#include <string.h>
 #include "fsck.h"
 
 #define MINDIRSIZE     (sizeof (struct dirtemplate))
 #include "fsck.h"
 
 #define MINDIRSIZE     (sizeof (struct dirtemplate))
@@ -101,6 +91,8 @@ pass2()
        inpend = &inpsort[inplast];
        for (inpp = inpsort; inpp < inpend; inpp++) {
                inp = *inpp;
        inpend = &inpsort[inplast];
        for (inpp = inpsort; inpp < inpend; inpp++) {
                inp = *inpp;
+               if (inp->i_isize == 0)
+                       continue;
                if (inp->i_isize < MINDIRSIZE) {
                        direrror(inp->i_number, "DIRECTORY TOO SHORT");
                        inp->i_isize = MINDIRSIZE;
                if (inp->i_isize < MINDIRSIZE) {
                        direrror(inp->i_number, "DIRECTORY TOO SHORT");
                        inp->i_isize = MINDIRSIZE;
@@ -138,7 +130,7 @@ pass2()
         */
        for (inpp = inpsort; inpp < inpend; inpp++) {
                inp = *inpp;
         */
        for (inpp = inpsort; inpp < inpend; inpp++) {
                inp = *inpp;
-               if (inp->i_parent == 0)
+               if (inp->i_parent == 0 || inp->i_isize == 0)
                        continue;
                if (statemap[inp->i_parent] == DFOUND &&
                    statemap[inp->i_number] == DSTATE)
                        continue;
                if (statemap[inp->i_parent] == DFOUND &&
                    statemap[inp->i_number] == DSTATE)
@@ -177,6 +169,7 @@ pass2check(idesc)
        register struct inoinfo *inp;
        int n, entrysize, ret = 0;
        struct dinode *dp;
        register struct inoinfo *inp;
        int n, entrysize, ret = 0;
        struct dinode *dp;
+       char *errmsg;
        struct direct proto;
        char namebuf[MAXPATHLEN + 1];
        char pathbuf[MAXPATHLEN + 1];
        struct direct proto;
        char namebuf[MAXPATHLEN + 1];
        char pathbuf[MAXPATHLEN + 1];
@@ -310,7 +303,11 @@ again:
                case FCLEAR:
                        if (idesc->id_entryno <= 2)
                                break;
                case FCLEAR:
                        if (idesc->id_entryno <= 2)
                                break;
-                       fileerror(idesc->id_number, dirp->d_ino, "DUP/BAD");
+                       if (statemap[dirp->d_ino] == DCLEAR)
+                               errmsg = "ZERO LENGTH DIRECTORY";
+                       else
+                               errmsg = "DUP/BAD";
+                       fileerror(idesc->id_number, dirp->d_ino, errmsg);
                        if ((n = reply("REMOVE")) == 1)
                                break;
                        dp = ginode(dirp->d_ino);
                        if ((n = reply("REMOVE")) == 1)
                                break;
                        dp = ginode(dirp->d_ino);
@@ -326,13 +323,6 @@ again:
 
                case DFOUND:
                        inp = getinoinfo(dirp->d_ino);
 
                case DFOUND:
                        inp = getinoinfo(dirp->d_ino);
-                       if (inp->i_isize == 0) {
-                               direrror(dirp->d_ino, "ZERO LENGTH DIRECTORY");
-                               if ((n = reply("REMOVE")) == 1) {
-                                       statemap[dirp->d_ino] = DCLEAR;
-                                       break;
-                               }
-                       }
                        if (inp->i_parent != 0 && idesc->id_entryno > 2) {
                                getpathname(pathbuf, idesc->id_number,
                                    idesc->id_number);
                        if (inp->i_parent != 0 && idesc->id_entryno > 2) {
                                getpathname(pathbuf, idesc->id_number,
                                    idesc->id_number);