Source-Changes-HG archive

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

[src/trunk]: src Add new accessors for the d_type and d_namlen fields of stru...



details:   https://anonhg.NetBSD.org/src/rev/1eeb914cfb83
branches:  trunk
changeset: 340346:1eeb914cfb83
user:      dholland <dholland%NetBSD.org@localhost>
date:      Tue Sep 01 06:16:58 2015 +0000

description:
Add new accessors for the d_type and d_namlen fields of struct lfs_direct.
Napalm the old byteswap access logic for these.

diffstat:

 libexec/lfs_cleanerd/cleaner.h      |    3 +-
 libexec/lfs_cleanerd/lfs_cleanerd.c |    4 +-
 sbin/fsck_lfs/dir.c                 |   34 ++++---
 sbin/fsck_lfs/inode.c               |    7 +-
 sbin/fsck_lfs/pass2.c               |   68 ++++++++-------
 sbin/newfs_lfs/make_lfs.c           |   67 ++++++++++++---
 sys/lib/libsa/ufs.c                 |    8 +-
 sys/ufs/lfs/lfs.h                   |   28 +-----
 sys/ufs/lfs/lfs_accessors.h         |  153 +++++++++++++++++++++++++++++++++++-
 sys/ufs/lfs/lfs_rename.c            |   30 ++----
 sys/ufs/lfs/lfs_vfsops.c            |    7 +-
 sys/ufs/lfs/lfs_vnops.c             |   19 +---
 sys/ufs/lfs/ulfs_dirhash.c          |   49 ++++++----
 sys/ufs/lfs/ulfs_extern.h           |    4 +-
 sys/ufs/lfs/ulfs_inode.c            |    6 +-
 sys/ufs/lfs/ulfs_lookup.c           |  126 +++++++++++-----------------
 sys/ufs/lfs/ulfs_vfsops.c           |    5 +-
 sys/ufs/lfs/ulfs_vnops.c            |   33 ++-----
 18 files changed, 399 insertions(+), 252 deletions(-)

diffs (truncated from 1509 to 300 lines):

diff -r 216bb04fb236 -r 1eeb914cfb83 libexec/lfs_cleanerd/cleaner.h
--- a/libexec/lfs_cleanerd/cleaner.h    Tue Sep 01 06:16:03 2015 +0000
+++ b/libexec/lfs_cleanerd/cleaner.h    Tue Sep 01 06:16:58 2015 +0000
@@ -21,7 +21,8 @@
                struct dlfs64 u_64;
        } lfs_dlfs_u;
        unsigned lfs_is64 : 1,
-               lfs_dobyteswap : 1;
+               lfs_dobyteswap : 1,
+               lfs_hasolddirfmt : 1;
 
        /* Ifile */
        int clfs_ifilefd;          /* Ifile file descriptor */
diff -r 216bb04fb236 -r 1eeb914cfb83 libexec/lfs_cleanerd/lfs_cleanerd.c
--- a/libexec/lfs_cleanerd/lfs_cleanerd.c       Tue Sep 01 06:16:03 2015 +0000
+++ b/libexec/lfs_cleanerd/lfs_cleanerd.c       Tue Sep 01 06:16:58 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lfs_cleanerd.c,v 1.52 2015/09/01 06:12:04 dholland Exp $    */
+/* $NetBSD: lfs_cleanerd.c,v 1.53 2015/09/01 06:16:58 dholland Exp $    */
 
 /*-
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -270,6 +270,8 @@
        }
        fs->lfs_is64 = 0; /* XXX notyet */
        fs->lfs_dobyteswap = 0; /* XXX notyet */
+       /* XXX: can this ever need to be set? does the cleaner even care? */
+       fs->lfs_hasolddirfmt = 0;
 
        /* If this is not a version 2 filesystem, complain and exit */
        if (lfs_sb_getversion(fs) != 2) {
diff -r 216bb04fb236 -r 1eeb914cfb83 sbin/fsck_lfs/dir.c
--- a/sbin/fsck_lfs/dir.c       Tue Sep 01 06:16:03 2015 +0000
+++ b/sbin/fsck_lfs/dir.c       Tue Sep 01 06:16:58 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dir.c,v 1.37 2015/09/01 06:08:37 dholland Exp $     */
+/* $NetBSD: dir.c,v 1.38 2015/09/01 06:16:58 dholland Exp $     */
 
 /*
  * Copyright (c) 1980, 1986, 1993
@@ -70,6 +70,7 @@
        .dotdot_namlen = 2,
        .dotdot_name = ".."
 };
+#if 0
 struct lfs_odirtemplate odirhead = {
        .dot_ino = 0,
        .dot_reclen = 12,
@@ -80,6 +81,7 @@
        .dotdot_namlen = 2,
        .dotdot_name = ".."
 };
+#endif
 
 static int expanddir(struct uvnode *, union lfs_dinode *, char *);
 static void freedir(ino_t, ino_t);
@@ -193,8 +195,8 @@
                dp = (struct lfs_direct *) (bp->b_data + idesc->id_loc);
                dp->d_reclen = LFS_DIRBLKSIZ;
                dp->d_ino = 0;
-               dp->d_type = 0;
-               dp->d_namlen = 0;
+               lfs_dir_settype(fs, dp, LFS_DT_UNKNOWN);
+               lfs_dir_setnamlen(fs, dp, 0);
                dp->d_name[0] = '\0';
                if (fix)
                        VOP_BWRITE(bp);
@@ -266,9 +268,9 @@
        }
        if (dp->d_ino == 0)
                return (1);
-       size = LFS_DIRSIZ(0, dp, 0);
-       namlen = dp->d_namlen;
-       type = dp->d_type;
+       size = LFS_DIRSIZ(fs, dp);
+       namlen = lfs_dir_getnamlen(fs, dp);
+       type = lfs_dir_gettype(fs, dp);
        if (dp->d_reclen < size ||
            idesc->id_filesize < size ||
        /* namlen > MAXNAMLEN || */
@@ -366,12 +368,14 @@
 {
        struct lfs_direct *dirp = idesc->id_dirp;
        struct lfs_direct newent;
+       unsigned namlen;
        int newlen, oldlen;
 
-       newent.d_namlen = strlen(idesc->id_name);
-       newlen = LFS_DIRSIZ(0, &newent, 0);
+       namlen = strlen(idesc->id_name);
+       lfs_dir_setnamlen(fs, &newent, namlen);
+       newlen = LFS_DIRSIZ(fs, &newent);
        if (dirp->d_ino != 0)
-               oldlen = LFS_DIRSIZ(0, dirp, 0);
+               oldlen = LFS_DIRSIZ(fs, dirp);
        else
                oldlen = 0;
        if (dirp->d_reclen - oldlen < newlen)
@@ -381,9 +385,9 @@
        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;
-       dirp->d_type = typemap[idesc->id_parent];
-       dirp->d_namlen = newent.d_namlen;
-       memcpy(dirp->d_name, idesc->id_name, (size_t) dirp->d_namlen + 1);
+       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);
        return (ALTERED | STOP);
 }
 
@@ -391,11 +395,13 @@
 chgino(struct inodesc *idesc)
 {
        struct lfs_direct *dirp = idesc->id_dirp;
+       int namlen;
 
-       if (memcmp(dirp->d_name, idesc->id_name, (int) dirp->d_namlen + 1))
+       namlen = lfs_dir_getnamlen(fs, dirp);
+       if (memcmp(dirp->d_name, idesc->id_name, namlen + 1))
                return (KEEPON);
        dirp->d_ino = idesc->id_parent;
-       dirp->d_type = typemap[idesc->id_parent];
+       lfs_dir_settype(fs, dirp, typemap[idesc->id_parent]);
        return (ALTERED | STOP);
 }
 
diff -r 216bb04fb236 -r 1eeb914cfb83 sbin/fsck_lfs/inode.c
--- a/sbin/fsck_lfs/inode.c     Tue Sep 01 06:16:03 2015 +0000
+++ b/sbin/fsck_lfs/inode.c     Tue Sep 01 06:16:58 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: inode.c,v 1.62 2015/09/01 06:15:02 dholland Exp $   */
+/* $NetBSD: inode.c,v 1.63 2015/09/01 06:16:58 dholland Exp $   */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -507,8 +507,11 @@
 
        if (dirp->d_ino != idesc->id_parent)
                return (KEEPON);
-       if ((len = dirp->d_namlen + 1) > MAXPATHLEN) {
+       len = lfs_dir_getnamlen(fs, dirp) + 1;
+       /* XXX this is wrong: namlen+1 can be up to MAXPATHLEN+1 */
+       if (len > MAXPATHLEN) {
                /* Truncate it but don't overflow the buffer */
+               /* XXX: this case doesn't null-terminate the result */
                len = MAXPATHLEN;
        }
        /* this is namebuf with utils.h */
diff -r 216bb04fb236 -r 1eeb914cfb83 sbin/fsck_lfs/pass2.c
--- a/sbin/fsck_lfs/pass2.c     Tue Sep 01 06:16:03 2015 +0000
+++ b/sbin/fsck_lfs/pass2.c     Tue Sep 01 06:16:58 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pass2.c,v 1.26 2015/08/12 18:28:00 dholland Exp $   */
+/* $NetBSD: pass2.c,v 1.27 2015/09/01 06:16:58 dholland Exp $   */
 
 /*
  * Copyright (c) 1980, 1986, 1993
@@ -229,24 +229,26 @@
        if (dirp->d_ino != 0 && strcmp(dirp->d_name, ".") == 0) {
                if (dirp->d_ino != idesc->id_number) {
                        direrror(idesc->id_number, "BAD INODE NUMBER FOR '.'");
-                       dirp->d_ino = idesc->id_number;
-                       if (reply("FIX") == 1)
+                       if (reply("FIX") == 1) {
+                               dirp->d_ino = idesc->id_number;
                                ret |= ALTERED;
+                       }
                }
-               if (dirp->d_type != LFS_DT_DIR) {
+               if (lfs_dir_gettype(fs, dirp) != LFS_DT_DIR) {
                        direrror(idesc->id_number, "BAD TYPE VALUE FOR '.'");
-                       dirp->d_type = LFS_DT_DIR;
-                       if (reply("FIX") == 1)
+                       if (reply("FIX") == 1) {
+                               lfs_dir_settype(fs, dirp, LFS_DT_DIR);
                                ret |= ALTERED;
+                       }
                }
                goto chk1;
        }
        direrror(idesc->id_number, "MISSING '.'");
        proto.d_ino = idesc->id_number;
-       proto.d_type = LFS_DT_DIR;
-       proto.d_namlen = 1;
+       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(0, &proto, 0);
+       entrysize = LFS_DIRSIZ(fs, &proto);
        if (dirp->d_ino != 0 && strcmp(dirp->d_name, "..") != 0) {
                pfatal("CANNOT FIX, FIRST ENTRY IN DIRECTORY CONTAINS %s\n",
                    dirp->d_name);
@@ -274,12 +276,12 @@
                goto chk2;
        inp = getinoinfo(idesc->id_number);
        proto.d_ino = inp->i_parent;
-       proto.d_type = LFS_DT_DIR;
-       proto.d_namlen = 2;
+       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(0, &proto, 0);
+       entrysize = LFS_DIRSIZ(fs, &proto);
        if (idesc->id_entryno == 0) {
-               n = LFS_DIRSIZ(0, dirp, 0);
+               n = LFS_DIRSIZ(fs, dirp);
                if (dirp->d_reclen < n + entrysize)
                        goto chk2;
                proto.d_reclen = dirp->d_reclen - n;
@@ -292,9 +294,9 @@
        }
        if (dirp->d_ino != 0 && strcmp(dirp->d_name, "..") == 0) {
                inp->i_dotdot = dirp->d_ino;
-               if (dirp->d_type != LFS_DT_DIR) {
+               if (lfs_dir_gettype(fs, dirp) != LFS_DT_DIR) {
                        direrror(idesc->id_number, "BAD TYPE VALUE FOR '..'");
-                       dirp->d_type = LFS_DT_DIR;
+                       lfs_dir_settype(fs, dirp, LFS_DT_DIR);
                        if (reply("FIX") == 1)
                                ret |= ALTERED;
                }
@@ -327,21 +329,23 @@
 chk2:
        if (dirp->d_ino == 0)
                return (ret | KEEPON);
-       if (dirp->d_namlen <= 2 &&
+       if (lfs_dir_getnamlen(fs, dirp) <= 2 &&
            dirp->d_name[0] == '.' &&
            idesc->id_entryno >= 2) {
-               if (dirp->d_namlen == 1) {
+               if (lfs_dir_getnamlen(fs, dirp) == 1) {
                        direrror(idesc->id_number, "EXTRA '.' ENTRY");
-                       dirp->d_ino = 0;
-                       if (reply("FIX") == 1)
+                       if (reply("FIX") == 1) {
+                               dirp->d_ino = 0;
                                ret |= ALTERED;
+                       }
                        return (KEEPON | ret);
                }
                if (dirp->d_name[1] == '.') {
                        direrror(idesc->id_number, "EXTRA '..' ENTRY");
-                       dirp->d_ino = 0;
-                       if (reply("FIX") == 1)
+                       if (reply("FIX") == 1) {
+                               dirp->d_ino = 0;
                                ret |= ALTERED;
+                       }
                        return (KEEPON | ret);
                }
        }
@@ -352,20 +356,22 @@
                n = reply("REMOVE");
        } else if (dirp->d_ino == LFS_IFILE_INUM &&
            idesc->id_number == ULFS_ROOTINO) {
-               if (dirp->d_type != LFS_DT_REG) {
+               if (lfs_dir_gettype(fs, dirp) != LFS_DT_REG) {
                        fileerror(idesc->id_number, dirp->d_ino,
                            "BAD TYPE FOR IFILE");
-                       dirp->d_type = LFS_DT_REG;
-                       if (reply("FIX") == 1)
+                       if (reply("FIX") == 1) {
+                               lfs_dir_settype(fs, dirp, LFS_DT_REG);
                                ret |= ALTERED;
+                       }
                }
-       } else if (((dirp->d_ino == ULFS_WINO && (dirp->d_type != LFS_DT_WHT)) ||
-               (dirp->d_ino != ULFS_WINO && dirp->d_type == LFS_DT_WHT))) {
+       } else if (((dirp->d_ino == ULFS_WINO && lfs_dir_gettype(fs, dirp) != LFS_DT_WHT) ||
+               (dirp->d_ino != ULFS_WINO && lfs_dir_gettype(fs, dirp) == LFS_DT_WHT))) {
                fileerror(idesc->id_number, dirp->d_ino, "BAD WHITEOUT ENTRY");
                dirp->d_ino = ULFS_WINO;
-               dirp->d_type = LFS_DT_WHT;
-               if (reply("FIX") == 1)
+               if (reply("FIX") == 1) {
+                       lfs_dir_settype(fs, dirp, LFS_DT_WHT);
                        ret |= ALTERED;
+               }
        } else {
 again:
                switch (statemap[dirp->d_ino]) {
@@ -418,13 +424,13 @@
                        /* fall through */
 
                case FSTATE:
-                       if (dirp->d_type != typemap[dirp->d_ino]) {
+                       if (lfs_dir_gettype(fs, dirp) != typemap[dirp->d_ino]) {
                                fileerror(idesc->id_number, dirp->d_ino,
                                    "BAD TYPE VALUE");
                                if (debug)
                                        pwarn("dir has %d, typemap has %d\n",
-                                               dirp->d_type, typemap[dirp->d_ino]);
-                               dirp->d_type = typemap[dirp->d_ino];
+                                               lfs_dir_gettype(fs, dirp), typemap[dirp->d_ino]);
+                               lfs_dir_settype(fs, dirp, typemap[dirp->d_ino]);
                                if (reply("FIX") == 1)
                                        ret |= ALTERED;
                        }
diff -r 216bb04fb236 -r 1eeb914cfb83 sbin/newfs_lfs/make_lfs.c



Home | Main Index | Thread Index | Old Index