do not have to have alternate superblock if -b is specified
[unix-history] / usr / src / sbin / fsck / dir.c
index 02f4119..52119d1 100644 (file)
@@ -2,29 +2,21 @@
  * 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[] = "@(#)dir.c      5.16 (Berkeley) %G%";
+static char sccsid[] = "@(#)dir.c      5.20 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
-#include <ufs/dinode.h>
-#include <ufs/fs.h>
+#include <ufs/ufs/dinode.h>
 #define KERNEL
 #define KERNEL
-#include <ufs/dir.h>
+#include <ufs/ufs/dir.h>
 #undef KERNEL
 #undef KERNEL
+#include <ufs/ffs/fs.h>
+#include <stdlib.h>
+#include <string.h>
 #include "fsck.h"
 
 char   *lfname = "lost+found";
 #include "fsck.h"
 
 char   *lfname = "lost+found";
@@ -85,12 +77,12 @@ dirscan(idesc)
        idesc->id_loc = 0;
        for (dp = fsck_readdir(idesc); dp != NULL; dp = fsck_readdir(idesc)) {
                dsize = dp->d_reclen;
        idesc->id_loc = 0;
        for (dp = fsck_readdir(idesc); dp != NULL; dp = fsck_readdir(idesc)) {
                dsize = dp->d_reclen;
-               bcopy((char *)dp, dbuf, dsize);
+               bcopy((char *)dp, dbuf, (size_t)dsize);
                idesc->id_dirp = (struct direct *)dbuf;
                if ((n = (*idesc->id_func)(idesc)) & ALTERED) {
                        bp = getdirblk(idesc->id_blkno, blksiz);
                        bcopy(dbuf, bp->b_un.b_buf + idesc->id_loc - dsize,
                idesc->id_dirp = (struct direct *)dbuf;
                if ((n = (*idesc->id_func)(idesc)) & ALTERED) {
                        bp = getdirblk(idesc->id_blkno, blksiz);
                        bcopy(dbuf, bp->b_un.b_buf + idesc->id_loc - dsize,
-                           dsize);
+                           (size_t)dsize);
                        dirty(bp);
                        sbdirty();
                }
                        dirty(bp);
                        sbdirty();
                }
@@ -269,7 +261,7 @@ mkentry(idesc)
        dirp->d_ino = idesc->id_parent; /* ino to be entered is in id_parent */
        dirp->d_reclen = newent.d_reclen;
        dirp->d_namlen = newent.d_namlen;
        dirp->d_ino = idesc->id_parent; /* ino to be entered is in id_parent */
        dirp->d_reclen = newent.d_reclen;
        dirp->d_namlen = newent.d_namlen;
-       bcopy(idesc->id_name, dirp->d_name, (int)dirp->d_namlen + 1);
+       bcopy(idesc->id_name, dirp->d_name, (size_t)dirp->d_namlen + 1);
        return (ALTERED|STOP);
 }
 
        return (ALTERED|STOP);
 }
 
@@ -374,14 +366,14 @@ linkup(orphan, parentdir)
        if (lostdir) {
                if ((changeino(orphan, "..", lfdir) & ALTERED) == 0 &&
                    parentdir != (ino_t)-1)
        if (lostdir) {
                if ((changeino(orphan, "..", lfdir) & ALTERED) == 0 &&
                    parentdir != (ino_t)-1)
-                       makeentry(orphan, lfdir, "..");
+                       (void)makeentry(orphan, lfdir, "..");
                dp = ginode(lfdir);
                dp->di_nlink++;
                inodirty();
                lncntp[lfdir]++;
                dp = ginode(lfdir);
                dp->di_nlink++;
                inodirty();
                lncntp[lfdir]++;
-               pwarn("DIR I=%u CONNECTED. ", orphan);
+               pwarn("DIR I=%lu CONNECTED. ", orphan);
                if (parentdir != (ino_t)-1)
                if (parentdir != (ino_t)-1)
-                       printf("PARENT WAS I=%u\n", parentdir);
+                       printf("PARENT WAS I=%lu\n", parentdir);
                if (preen == 0)
                        printf("\n");
        }
                if (preen == 0)
                        printf("\n");
        }
@@ -464,7 +456,7 @@ expanddir(dp, name)
        dp->di_size += sblock.fs_bsize;
        dp->di_blocks += btodb(sblock.fs_bsize);
        bp = getdirblk(dp->di_db[lastbn + 1],
        dp->di_size += sblock.fs_bsize;
        dp->di_blocks += btodb(sblock.fs_bsize);
        bp = getdirblk(dp->di_db[lastbn + 1],
-               dblksize(&sblock, dp, lastbn + 1));
+               (long)dblksize(&sblock, dp, lastbn + 1));
        if (bp->b_errs)
                goto bad;
        bcopy(bp->b_un.b_buf, firstblk, DIRBLKSIZ);
        if (bp->b_errs)
                goto bad;
        bcopy(bp->b_un.b_buf, firstblk, DIRBLKSIZ);
@@ -478,7 +470,7 @@ expanddir(dp, name)
                bcopy((char *)&emptydir, cp, sizeof emptydir);
        dirty(bp);
        bp = getdirblk(dp->di_db[lastbn + 1],
                bcopy((char *)&emptydir, cp, sizeof emptydir);
        dirty(bp);
        bp = getdirblk(dp->di_db[lastbn + 1],
-               dblksize(&sblock, dp, lastbn + 1));
+               (long)dblksize(&sblock, dp, lastbn + 1));
        if (bp->b_errs)
                goto bad;
        bcopy((char *)&emptydir, bp->b_un.b_buf, sizeof emptydir);
        if (bp->b_errs)
                goto bad;
        bcopy((char *)&emptydir, bp->b_un.b_buf, sizeof emptydir);
@@ -530,12 +522,14 @@ allocdir(parent, request, mode)
        inodirty();
        if (ino == ROOTINO) {
                lncntp[ino] = dp->di_nlink;
        inodirty();
        if (ino == ROOTINO) {
                lncntp[ino] = dp->di_nlink;
+               cacheino(dp, ino);
                return(ino);
        }
        if (statemap[parent] != DSTATE && statemap[parent] != DFOUND) {
                freeino(ino);
                return (0);
        }
                return(ino);
        }
        if (statemap[parent] != DSTATE && statemap[parent] != DFOUND) {
                freeino(ino);
                return (0);
        }
+       cacheino(dp, ino);
        statemap[ino] = statemap[parent];
        if (statemap[ino] == DSTATE) {
                lncntp[ino] = dp->di_nlink;
        statemap[ino] = statemap[parent];
        if (statemap[ino] == DSTATE) {
                lncntp[ino] = dp->di_nlink;