Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Clean up struct lfs_dirtemplate.



details:   https://anonhg.NetBSD.org/src/rev/4f2f045e1e37
branches:  trunk
changeset: 340620:4f2f045e1e37
user:      dholland <dholland%NetBSD.org@localhost>
date:      Sun Sep 20 04:51:43 2015 +0000

description:
Clean up struct lfs_dirtemplate.

diffstat:

 sbin/fsck_lfs/dir.c         |  53 +++++++++++++++++++++++++------
 sys/ufs/lfs/lfs.h           |  21 ++++-------
 sys/ufs/lfs/lfs_accessors.h |  74 +--------------------------------------------
 sys/ufs/lfs/lfs_rename.c    |  55 ++++++++++----------------------
 sys/ufs/lfs/lfs_vnops.c     |  48 +++++++++++++++-------------
 5 files changed, 94 insertions(+), 157 deletions(-)

diffs (truncated from 457 to 300 lines):

diff -r 89f25f09efb1 -r 4f2f045e1e37 sbin/fsck_lfs/dir.c
--- a/sbin/fsck_lfs/dir.c       Sun Sep 20 04:50:58 2015 +0000
+++ b/sbin/fsck_lfs/dir.c       Sun Sep 20 04:51:43 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dir.c,v 1.43 2015/09/15 15:02:25 dholland Exp $     */
+/* $NetBSD: dir.c,v 1.44 2015/09/20 04:51:43 dholland Exp $     */
 
 /*
  * Copyright (c) 1980, 1986, 1993
@@ -54,6 +54,7 @@
 
 const char *lfname = "lost+found";
 int lfmode = 01700;
+#if 0
 struct lfs_dirtemplate emptydir = {
        .dot_ino = 0,
        .dot_reclen = LFS_DIRBLKSIZ,
@@ -70,7 +71,6 @@
        .dotdot_namlen = 2,
        .dotdot_name = ".."
 };
-#if 0
 struct lfs_odirtemplate odirhead = {
        .dot_ino = 0,
        .dot_reclen = 12,
@@ -587,6 +587,24 @@
 }
 
 /*
+ * Initialize a completely empty directory block.
+ * (block size is LFS_DIRBLKSIZ)
+ */
+static void
+zerodirblk(void *buf)
+{
+       struct lfs_dirheader *dirp;
+
+       dirp = buf;
+       lfs_dir_setino(fs, dirp, 0);
+       lfs_dir_setreclen(fs, dirp, LFS_DIRBLKSIZ);
+       lfs_dir_settype(fs, dirp, LFS_DT_UNKNOWN);
+       lfs_dir_setnamlen(fs, dirp, 0);
+       lfs_copydirname(fs, lfs_dir_nameptr(fs, dirp), "", 0,
+                       LFS_DIRBLKSIZ);
+}
+
+/*
  * Attempt to expand the size of a directory
  */
 static int
@@ -620,13 +638,13 @@
        for (cp = &bp->b_data[LFS_DIRBLKSIZ];
            cp < &bp->b_data[lfs_sb_getbsize(fs)];
            cp += LFS_DIRBLKSIZ)
-               memcpy(cp, &emptydir, sizeof emptydir);
+               zerodirblk(cp);
        VOP_BWRITE(bp);
        bread(vp, lfs_dino_getdb(fs, dp, lastbn + 1),
            (long) lfs_dblksize(fs, dp, lastbn + 1), 0, &bp);
        if (bp->b_flags & B_ERROR)
                goto bad;
-       memcpy(bp->b_data, &emptydir, sizeof emptydir);
+       zerodirblk(bp->b_data);
        pwarn("NO SPACE LEFT IN %s", name);
        if (preen)
                printf(" (EXPANDED)\n");
@@ -655,13 +673,10 @@
        char *cp;
        union lfs_dinode *dp;
        struct ubuf *bp;
-       struct lfs_dirtemplate *dirp;
+       struct lfs_dirheader *dirp;
        struct uvnode *vp;
 
        ino = allocino(request, LFS_IFDIR | mode);
-       dirp = &dirhead;
-       dirp->dot_ino = ino;
-       dirp->dotdot_ino = parent;
        vp = vget(fs, ino);
        dp = VTOD(vp);
        bread(vp, lfs_dino_getdb(fs, dp, 0), lfs_sb_getfsize(fs), 0, &bp);
@@ -670,11 +685,27 @@
                freeino(ino);
                return (0);
        }
-       memcpy(bp->b_data, dirp, sizeof(struct lfs_dirtemplate));
+       dirp = (struct lfs_dirheader *)bp->b_data;
+       /* . */
+       lfs_dir_setino(fs, dirp, ino);
+       lfs_dir_setreclen(fs, dirp, LFS_DIRECTSIZ(1));
+       lfs_dir_settype(fs, dirp, LFS_DT_DIR);
+       lfs_dir_setnamlen(fs, dirp, 1);
+       lfs_copydirname(fs, lfs_dir_nameptr(fs, dirp), ".", 1,
+                       LFS_DIRECTSIZ(1));
+       /* .. */
+       dirp = LFS_NEXTDIR(fs, dirp);
+       lfs_dir_setino(fs, dirp, parent);
+       lfs_dir_setreclen(fs, dirp, LFS_DIRBLKSIZ - LFS_DIRECTSIZ(1));
+       lfs_dir_settype(fs, dirp, LFS_DT_DIR);
+       lfs_dir_setnamlen(fs, dirp, 2);
+       lfs_copydirname(fs, lfs_dir_nameptr(fs, dirp), "..", 2,
+                       LFS_DIRBLKSIZ - LFS_DIRECTSIZ(1));
        for (cp = &bp->b_data[LFS_DIRBLKSIZ];
            cp < &bp->b_data[lfs_sb_getfsize(fs)];
-           cp += LFS_DIRBLKSIZ)
-               memcpy(cp, &emptydir, sizeof emptydir);
+           cp += LFS_DIRBLKSIZ) {
+               zerodirblk(cp);
+       }
        VOP_BWRITE(bp);
        lfs_dino_setnlink(fs, dp, 2);
        inodirty(VTOI(vp));
diff -r 89f25f09efb1 -r 4f2f045e1e37 sys/ufs/lfs/lfs.h
--- a/sys/ufs/lfs/lfs.h Sun Sep 20 04:50:58 2015 +0000
+++ b/sys/ufs/lfs/lfs.h Sun Sep 20 04:51:43 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs.h,v 1.189 2015/09/15 15:02:40 dholland Exp $       */
+/*     $NetBSD: lfs.h,v 1.190 2015/09/20 04:51:43 dholland Exp $       */
 
 /*  from NetBSD: dinode.h,v 1.22 2013/01/22 09:39:18 dholland Exp  */
 /*  from NetBSD: dir.h,v 1.21 2009/07/22 04:49:19 dholland Exp  */
@@ -356,22 +356,16 @@
 };
 
 /*
- * Template for manipulating directories.  Should use struct lfs_direct's,
- * but the name field is LFS_MAXNAMLEN - 1, and this just won't do.
+ * Template for manipulating directories.
  */
 struct lfs_dirtemplate {
-       u_int32_t       dot_ino;
-       int16_t         dot_reclen;
-       u_int8_t        dot_type;
-       u_int8_t        dot_namlen;
-       char            dot_name[4];    /* must be multiple of 4 */
-       u_int32_t       dotdot_ino;
-       int16_t         dotdot_reclen;
-       u_int8_t        dotdot_type;
-       u_int8_t        dotdot_namlen;
-       char            dotdot_name[4]; /* ditto */
+       struct lfs_dirheader    dot_header;
+       char                    dot_name[4];    /* must be multiple of 4 */
+       struct lfs_dirheader    dotdot_header;
+       char                    dotdot_name[4]; /* ditto */
 };
 
+#if 0
 /*
  * This is the old format of directories, sans type element.
  */
@@ -385,6 +379,7 @@
        u_int16_t       dotdot_namlen;
        char            dotdot_name[4]; /* ditto */
 };
+#endif
 
 /*
  * Inodes
diff -r 89f25f09efb1 -r 4f2f045e1e37 sys/ufs/lfs/lfs_accessors.h
--- a/sys/ufs/lfs/lfs_accessors.h       Sun Sep 20 04:50:58 2015 +0000
+++ b/sys/ufs/lfs/lfs_accessors.h       Sun Sep 20 04:51:43 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_accessors.h,v 1.28 2015/09/20 04:50:58 dholland Exp $      */
+/*     $NetBSD: lfs_accessors.h,v 1.29 2015/09/20 04:51:43 dholland Exp $      */
 
 /*  from NetBSD: lfs.h,v 1.165 2015/07/24 06:59:32 dholland Exp  */
 /*  from NetBSD: dinode.h,v 1.22 2013/01/22 09:39:18 dholland Exp  */
@@ -330,78 +330,6 @@
 }
 
 /*
- * These are called "dirt" because they ought to be cleaned up.
- */
-
-static __unused inline uint8_t
-lfs_dirt_getdottype(const STRUCT_LFS *fs, const struct lfs_dirtemplate *dp)
-{
-       if (fs->lfs_hasolddirfmt) {
-               return LFS_DT_UNKNOWN;
-       }
-       return dp->dot_type;
-}
-
-static __unused inline uint8_t
-lfs_dirt_getdotnamlen(const STRUCT_LFS *fs, const struct lfs_dirtemplate *dp)
-{
-       if (fs->lfs_hasolddirfmt && LFS_LITTLE_ENDIAN_ONDISK(fs)) {
-               /* low-order byte of old 16-bit namlen field */
-               return dp->dot_type;
-       }
-       return dp->dot_namlen;
-}
-
-static __unused inline uint8_t
-lfs_dirt_getdotdottype(const STRUCT_LFS *fs, const struct lfs_dirtemplate *dp)
-{
-       if (fs->lfs_hasolddirfmt) {
-               return LFS_DT_UNKNOWN;
-       }
-       return dp->dotdot_type;
-}
-
-static __unused inline uint8_t
-lfs_dirt_getdotdotnamlen(const STRUCT_LFS *fs, const struct lfs_dirtemplate *dp)
-{
-       if (fs->lfs_hasolddirfmt && LFS_LITTLE_ENDIAN_ONDISK(fs)) {
-               /* low-order byte of old 16-bit namlen field */
-               return dp->dotdot_type;
-       }
-       return dp->dotdot_namlen;
-}
-
-static __unused inline void
-lfs_dirt_settypes(const STRUCT_LFS *fs, struct lfs_dirtemplate *dtp,
-    unsigned dt1, unsigned dt2)
-{
-       if (fs->lfs_hasolddirfmt) {
-               /* do nothing */
-               return;
-       }
-       dtp->dot_type = dt1;
-       dtp->dotdot_type = dt2;
-}
-
-static __unused inline void
-lfs_dirt_setnamlens(const STRUCT_LFS *fs, struct lfs_dirtemplate *dtp,
-    unsigned len1, unsigned len2)
-{
-       if (fs->lfs_hasolddirfmt && LFS_LITTLE_ENDIAN_ONDISK(fs)) {
-               /* low-order bytes of old 16-bit namlen field */
-               dtp->dot_type = len1;
-               dtp->dotdot_type = len2;
-               /* clear the high-order bytes */
-               dtp->dot_namlen = 0;
-               dtp->dotdot_namlen = 0;
-               return;
-       }
-       dtp->dot_namlen = len1;
-       dtp->dotdot_namlen = len2;
-}
-
-
-/*
  * dinodes
  */
 
diff -r 89f25f09efb1 -r 4f2f045e1e37 sys/ufs/lfs/lfs_rename.c
--- a/sys/ufs/lfs/lfs_rename.c  Sun Sep 20 04:50:58 2015 +0000
+++ b/sys/ufs/lfs/lfs_rename.c  Sun Sep 20 04:51:43 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_rename.c,v 1.13 2015/09/15 15:02:25 dholland Exp $ */
+/*     $NetBSD: lfs_rename.c,v 1.14 2015/09/20 04:51:43 dholland Exp $ */
 /*  from NetBSD: ufs_rename.c,v 1.6 2013/01/22 09:39:18 dholland Exp  */
 
 /*-
@@ -89,7 +89,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_rename.c,v 1.13 2015/09/15 15:02:25 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_rename.c,v 1.14 2015/09/20 04:51:43 dholland Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -128,16 +128,6 @@
 #include <ufs/lfs/lfs_extern.h>
 
 /*
- * A virgin directory (no blushing please).
- *
- * XXX Copypasta from ulfs_vnops.c.  Kill!
- */
-static const struct lfs_dirtemplate mastertemplate = {
-       0,      12,                     LFS_DT_DIR,     1,      ".",
-       0,      LFS_DIRBLKSIZ - 12,     LFS_DT_DIR,     2,      ".."
-};
-
-/*
  * ulfs_gro_directory_empty_p: Return true if the directory vp is
  * empty.  dvp is its parent.
  *
@@ -584,33 +574,13 @@
 }
 
 /*
- * ulfs_dirbuf_dotdot_namlen: Return the namlen of the directory buffer
- * dirbuf that came from the directory vp.  Swap byte order if
- * necessary.
- */
-static int                     /* XXX int?  uint8_t?  */
-ulfs_dirbuf_dotdot_namlen(const struct lfs_dirtemplate *dirbuf,
-    const struct vnode *vp)
-{
-       struct lfs *fs;
-
-       KASSERT(dirbuf != NULL);
-       KASSERT(vp != NULL);
-       KASSERT(VTOI(vp) != NULL);
-       KASSERT(VTOI(vp)->i_ump != NULL);
-       KASSERT(VTOI(vp)->i_lfs != NULL);



Home | Main Index | Thread Index | Old Index