Source-Changes-HG archive

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

[src/trunk]: src Add and use accessor functions for more of the directory ent...



details:   https://anonhg.NetBSD.org/src/rev/1fe7312e1f53
branches:  trunk
changeset: 810726:1fe7312e1f53
user:      dholland <dholland%NetBSD.org@localhost>
date:      Tue Sep 15 14:58:05 2015 +0000

description:
Add and use accessor functions for more of the directory entry fields.

diffstat:

 sbin/fsck_lfs/dir.c         |   50 +++++++++--------
 sbin/fsck_lfs/inode.c       |   12 ++-
 sbin/fsck_lfs/pass2.c       |  114 +++++++++++++++++++++-------------------
 sbin/newfs_lfs/make_lfs.c   |   16 +++--
 sys/ufs/lfs/lfs.h           |   15 ++++-
 sys/ufs/lfs/lfs_accessors.h |   29 ++++++++++-
 sys/ufs/lfs/lfs_rename.c    |   13 +--
 sys/ufs/lfs/ulfs_dirhash.c  |   55 ++++++++++---------
 sys/ufs/lfs/ulfs_lookup.c   |  122 ++++++++++++++++++-------------------------
 sys/ufs/lfs/ulfs_vnops.c    |   24 +++----
 10 files changed, 238 insertions(+), 212 deletions(-)

diffs (truncated from 1217 to 300 lines):

diff -r a666524de158 -r 1fe7312e1f53 sbin/fsck_lfs/dir.c
--- a/sbin/fsck_lfs/dir.c       Tue Sep 15 14:57:34 2015 +0000
+++ b/sbin/fsck_lfs/dir.c       Tue Sep 15 14:58:05 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dir.c,v 1.38 2015/09/01 06:16:58 dholland Exp $     */
+/* $NetBSD: dir.c,v 1.39 2015/09/15 14:58:05 dholland Exp $     */
 
 /*
  * Copyright (c) 1980, 1986, 1993
@@ -154,7 +154,7 @@
        vp = vget(fs, idesc->id_number);
        for (dp = fsck_readdir(vp, idesc); dp != NULL;
            dp = fsck_readdir(vp, idesc)) {
-               dsize = dp->d_reclen;
+               dsize = lfs_dir_getreclen(fs, dp);
                memcpy(dbuf, dp, (size_t) dsize);
                idesc->id_dirp = (struct lfs_direct *) dbuf;
                if ((n = (*idesc->id_func) (idesc)) & ALTERED) {
@@ -193,8 +193,8 @@
                fix = dofix(idesc, "DIRECTORY CORRUPTED");
                bread(vp, idesc->id_lblkno, blksiz, 0, &bp);
                dp = (struct lfs_direct *) (bp->b_data + idesc->id_loc);
-               dp->d_reclen = LFS_DIRBLKSIZ;
-               dp->d_ino = 0;
+               lfs_dir_setreclen(fs, dp, LFS_DIRBLKSIZ);
+               lfs_dir_setino(fs, dp, 0);
                lfs_dir_settype(fs, dp, LFS_DT_UNKNOWN);
                lfs_dir_setnamlen(fs, dp, 0);
                dp->d_name[0] = '\0';
@@ -213,8 +213,8 @@
        }
        dploc = idesc->id_loc;
        dp = (struct lfs_direct *) (bp->b_data + dploc);
-       idesc->id_loc += dp->d_reclen;
-       idesc->id_filesize -= dp->d_reclen;
+       idesc->id_loc += lfs_dir_getreclen(fs, dp);
+       idesc->id_filesize -= lfs_dir_getreclen(fs, dp);
        if ((idesc->id_loc % LFS_DIRBLKSIZ) == 0) {
                brelse(bp, 0);
                return dp;
@@ -231,7 +231,7 @@
                fix = dofix(idesc, "DIRECTORY CORRUPTED");
                bread(vp, idesc->id_lblkno, blksiz, 0, &bp);
                dp = (struct lfs_direct *) (bp->b_data + dploc);
-               dp->d_reclen += size;
+               lfs_dir_setreclen(fs, dp, lfs_dir_getreclen(fs, dp) + size);
                if (fix)
                        VOP_BWRITE(bp);
                else
@@ -255,23 +255,24 @@
        int spaceleft;
 
        spaceleft = LFS_DIRBLKSIZ - (idesc->id_loc % LFS_DIRBLKSIZ);
-       if (dp->d_ino >= maxino ||
-           dp->d_reclen == 0 ||
-           dp->d_reclen > spaceleft ||
-           (dp->d_reclen & 0x3) != 0) {
+       if (lfs_dir_getino(fs, dp) >= maxino ||
+           lfs_dir_getreclen(fs, dp) == 0 ||
+           lfs_dir_getreclen(fs, dp) > spaceleft ||
+           (lfs_dir_getreclen(fs, dp) & 0x3) != 0) {
                pwarn("ino too large, reclen=0, reclen>space, or reclen&3!=0\n");
-               pwarn("dp->d_ino = 0x%x\tdp->d_reclen = 0x%x\n",
-                   dp->d_ino, dp->d_reclen);
-               pwarn("maxino = %llu\tspaceleft = 0x%x\n",
-                   (unsigned long long)maxino, spaceleft);
+               pwarn("dp->d_ino = 0x%jx\tdp->d_reclen = 0x%x\n",
+                   (uintmax_t)lfs_dir_getino(fs, dp),
+                   lfs_dir_getreclen(fs, dp));
+               pwarn("maxino = %ju\tspaceleft = 0x%x\n",
+                   (uintmax_t)maxino, spaceleft);
                return (0);
        }
-       if (dp->d_ino == 0)
+       if (lfs_dir_getino(fs, dp) == 0)
                return (1);
        size = LFS_DIRSIZ(fs, dp);
        namlen = lfs_dir_getnamlen(fs, dp);
        type = lfs_dir_gettype(fs, dp);
-       if (dp->d_reclen < size ||
+       if (lfs_dir_getreclen(fs, dp) < size ||
            idesc->id_filesize < size ||
        /* namlen > MAXNAMLEN || */
            type > 15) {
@@ -374,17 +375,18 @@
        namlen = strlen(idesc->id_name);
        lfs_dir_setnamlen(fs, &newent, namlen);
        newlen = LFS_DIRSIZ(fs, &newent);
-       if (dirp->d_ino != 0)
+       if (lfs_dir_getino(fs, dirp) != 0)
                oldlen = LFS_DIRSIZ(fs, dirp);
        else
                oldlen = 0;
-       if (dirp->d_reclen - oldlen < newlen)
+       if (lfs_dir_getreclen(fs, dirp) - oldlen < newlen)
                return (KEEPON);
-       newent.d_reclen = dirp->d_reclen - oldlen;
-       dirp->d_reclen = oldlen;
+       lfs_dir_setreclen(fs, &newent, lfs_dir_getreclen(fs, dirp) - oldlen);
+       lfs_dir_setreclen(fs, dirp, oldlen);
        dirp = (struct lfs_direct *) (((char *) dirp) + oldlen);
-       dirp->d_ino = idesc->id_parent; /* ino to be entered is in id_parent */
-       dirp->d_reclen = newent.d_reclen;
+       /* ino to be entered is in id_parent */
+       lfs_dir_setino(fs, dirp, idesc->id_parent);
+       lfs_dir_setreclen(fs, dirp, lfs_dir_getreclen(fs, &newent));
        lfs_dir_settype(fs, dirp, typemap[idesc->id_parent]);
        lfs_dir_setnamlen(fs, dirp, namlen);
        memcpy(dirp->d_name, idesc->id_name, (size_t)namlen + 1);
@@ -400,7 +402,7 @@
        namlen = lfs_dir_getnamlen(fs, dirp);
        if (memcmp(dirp->d_name, idesc->id_name, namlen + 1))
                return (KEEPON);
-       dirp->d_ino = idesc->id_parent;
+       lfs_dir_setino(fs, dirp, idesc->id_parent);
        lfs_dir_settype(fs, dirp, typemap[idesc->id_parent]);
        return (ALTERED | STOP);
 }
diff -r a666524de158 -r 1fe7312e1f53 sbin/fsck_lfs/inode.c
--- a/sbin/fsck_lfs/inode.c     Tue Sep 15 14:57:34 2015 +0000
+++ b/sbin/fsck_lfs/inode.c     Tue Sep 15 14:58:05 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: inode.c,v 1.63 2015/09/01 06:16:58 dholland Exp $   */
+/* $NetBSD: inode.c,v 1.64 2015/09/15 14:58:05 dholland Exp $   */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -505,7 +505,7 @@
        size_t len;
        char *buf;
 
-       if (dirp->d_ino != idesc->id_parent)
+       if (lfs_dir_getino(fs, dirp) != idesc->id_parent)
                return (KEEPON);
        len = lfs_dir_getnamlen(fs, dirp) + 1;
        /* XXX this is wrong: namlen+1 can be up to MAXPATHLEN+1 */
@@ -524,12 +524,14 @@
 findino(struct inodesc * idesc)
 {
        struct lfs_direct *dirp = idesc->id_dirp;
+       ino_t ino;
 
-       if (dirp->d_ino == 0)
+       ino = lfs_dir_getino(fs, dirp);
+       if (ino == 0)
                return (KEEPON);
        if (strcmp(dirp->d_name, idesc->id_name) == 0 &&
-           dirp->d_ino >= ULFS_ROOTINO && dirp->d_ino < maxino) {
-               idesc->id_parent = dirp->d_ino;
+           ino >= ULFS_ROOTINO && ino < maxino) {
+               idesc->id_parent = ino;
                return (STOP | FOUND);
        }
        return (KEEPON);
diff -r a666524de158 -r 1fe7312e1f53 sbin/fsck_lfs/pass2.c
--- a/sbin/fsck_lfs/pass2.c     Tue Sep 15 14:57:34 2015 +0000
+++ b/sbin/fsck_lfs/pass2.c     Tue Sep 15 14:58:05 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pass2.c,v 1.27 2015/09/01 06:16:58 dholland Exp $   */
+/* $NetBSD: pass2.c,v 1.28 2015/09/15 14:58:05 dholland Exp $   */
 
 /*
  * Copyright (c) 1980, 1986, 1993
@@ -226,11 +226,11 @@
         */
        if (idesc->id_entryno != 0)
                goto chk1;
-       if (dirp->d_ino != 0 && strcmp(dirp->d_name, ".") == 0) {
-               if (dirp->d_ino != idesc->id_number) {
+       if (lfs_dir_getino(fs, dirp) != 0 && strcmp(dirp->d_name, ".") == 0) {
+               if (lfs_dir_getino(fs, dirp) != idesc->id_number) {
                        direrror(idesc->id_number, "BAD INODE NUMBER FOR '.'");
                        if (reply("FIX") == 1) {
-                               dirp->d_ino = idesc->id_number;
+                               lfs_dir_setino(fs, dirp, idesc->id_number);
                                ret |= ALTERED;
                        }
                }
@@ -244,30 +244,30 @@
                goto chk1;
        }
        direrror(idesc->id_number, "MISSING '.'");
-       proto.d_ino = idesc->id_number;
+       lfs_dir_setino(fs, &proto, idesc->id_number);
        lfs_dir_settype(fs, &proto, LFS_DT_DIR);
        lfs_dir_setnamlen(fs, &proto, 1);
        (void) strlcpy(proto.d_name, ".", sizeof(proto.d_name));
        entrysize = LFS_DIRSIZ(fs, &proto);
-       if (dirp->d_ino != 0 && strcmp(dirp->d_name, "..") != 0) {
+       if (lfs_dir_getino(fs, dirp) != 0 && strcmp(dirp->d_name, "..") != 0) {
                pfatal("CANNOT FIX, FIRST ENTRY IN DIRECTORY CONTAINS %s\n",
                    dirp->d_name);
-       } else if (dirp->d_reclen < entrysize) {
+       } else if (lfs_dir_getreclen(fs, dirp) < entrysize) {
                pfatal("CANNOT FIX, INSUFFICIENT SPACE TO ADD '.'\n");
-       } else if (dirp->d_reclen < 2 * entrysize) {
-               proto.d_reclen = dirp->d_reclen;
+       } else if (lfs_dir_getreclen(fs, dirp) < 2 * entrysize) {
+               lfs_dir_setreclen(fs, &proto, lfs_dir_getreclen(fs, dirp));
                memcpy(dirp, &proto, (size_t) entrysize);
                if (reply("FIX") == 1)
                        ret |= ALTERED;
        } else {
-               n = dirp->d_reclen - entrysize;
-               proto.d_reclen = entrysize;
+               n = lfs_dir_getreclen(fs, dirp) - entrysize;
+               lfs_dir_setreclen(fs, &proto, entrysize);
                memcpy(dirp, &proto, (size_t) entrysize);
                idesc->id_entryno++;
-               lncntp[dirp->d_ino]--;
+               lncntp[lfs_dir_getino(fs, dirp)]--;
                dirp = (struct lfs_direct *) ((char *) (dirp) + entrysize);
                memset(dirp, 0, (size_t) n);
-               dirp->d_reclen = n;
+               lfs_dir_setreclen(fs, dirp, n);
                if (reply("FIX") == 1)
                        ret |= ALTERED;
        }
@@ -275,25 +275,25 @@
        if (idesc->id_entryno > 1)
                goto chk2;
        inp = getinoinfo(idesc->id_number);
-       proto.d_ino = inp->i_parent;
+       lfs_dir_setino(fs, &proto, inp->i_parent);
        lfs_dir_settype(fs, &proto, LFS_DT_DIR);
        lfs_dir_setnamlen(fs, &proto, 2);
        (void) strlcpy(proto.d_name, "..", sizeof(proto.d_name));
        entrysize = LFS_DIRSIZ(fs, &proto);
        if (idesc->id_entryno == 0) {
                n = LFS_DIRSIZ(fs, dirp);
-               if (dirp->d_reclen < n + entrysize)
+               if (lfs_dir_getreclen(fs, dirp) < n + entrysize)
                        goto chk2;
-               proto.d_reclen = dirp->d_reclen - n;
-               dirp->d_reclen = n;
+               lfs_dir_setreclen(fs, &proto, lfs_dir_getreclen(fs, dirp) - n);
+               lfs_dir_setreclen(fs, dirp, n);
                idesc->id_entryno++;
-               lncntp[dirp->d_ino]--;
+               lncntp[lfs_dir_getino(fs, dirp)]--;
                dirp = (struct lfs_direct *) ((char *) (dirp) + n);
-               memset(dirp, 0, (size_t) proto.d_reclen);
-               dirp->d_reclen = proto.d_reclen;
+               memset(dirp, 0, lfs_dir_getreclen(fs, &proto));
+               lfs_dir_setreclen(fs, dirp, lfs_dir_getreclen(fs, &proto));
        }
-       if (dirp->d_ino != 0 && strcmp(dirp->d_name, "..") == 0) {
-               inp->i_dotdot = dirp->d_ino;
+       if (lfs_dir_getino(fs, dirp) != 0 && strcmp(dirp->d_name, "..") == 0) {
+               inp->i_dotdot = lfs_dir_getino(fs, dirp);
                if (lfs_dir_gettype(fs, dirp) != LFS_DT_DIR) {
                        direrror(idesc->id_number, "BAD TYPE VALUE FOR '..'");
                        lfs_dir_settype(fs, dirp, LFS_DT_DIR);
@@ -302,12 +302,12 @@
                }
                goto chk2;
        }
-       if (dirp->d_ino != 0 && strcmp(dirp->d_name, ".") != 0) {
+       if (lfs_dir_getino(fs, dirp) != 0 && strcmp(dirp->d_name, ".") != 0) {
                fileerror(inp->i_parent, idesc->id_number, "MISSING '..'");
                pfatal("CANNOT FIX, SECOND ENTRY IN DIRECTORY CONTAINS %s\n",
                    dirp->d_name);
                inp->i_dotdot = (ino_t) - 1;
-       } else if (dirp->d_reclen < entrysize) {
+       } else if (lfs_dir_getreclen(fs, dirp) < entrysize) {
                fileerror(inp->i_parent, idesc->id_number, "MISSING '..'");
                pfatal("CANNOT FIX, INSUFFICIENT SPACE TO ADD '..'\n");
                inp->i_dotdot = (ino_t) - 1;
@@ -317,17 +317,17 @@
                 */
                inp->i_dotdot = inp->i_parent;
                fileerror(inp->i_parent, idesc->id_number, "MISSING '..'");
-               proto.d_reclen = dirp->d_reclen;
+               lfs_dir_setreclen(fs, &proto, lfs_dir_getreclen(fs, dirp));
                memcpy(dirp, &proto, (size_t) entrysize);
                if (reply("FIX") == 1)
                        ret |= ALTERED;
        }
        idesc->id_entryno++;
-       if (dirp->d_ino != 0)
-               lncntp[dirp->d_ino]--;
+       if (lfs_dir_getino(fs, dirp) != 0)
+               lncntp[lfs_dir_getino(fs, dirp)]--;
        return (ret | KEEPON);
 chk2:
-       if (dirp->d_ino == 0)
+       if (lfs_dir_getino(fs, dirp) == 0)
                return (ret | KEEPON);
        if (lfs_dir_getnamlen(fs, dirp) <= 2 &&
            dirp->d_name[0] == '.' &&
@@ -335,7 +335,7 @@
                if (lfs_dir_getnamlen(fs, dirp) == 1) {
                        direrror(idesc->id_number, "EXTRA '.' ENTRY");
                        if (reply("FIX") == 1) {
-                               dirp->d_ino = 0;
+                               lfs_dir_setino(fs, dirp, 0);
                                ret |= ALTERED;
                        }
                        return (KEEPON | ret);
@@ -343,7 +343,7 @@



Home | Main Index | Thread Index | Old Index