Source-Changes-HG archive

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

[src/trunk]: src Add byteswapping to the dinode accessors.



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

description:
Add byteswapping to the dinode accessors.

This prevents regressions in the ulfs code when switching to the new
accessors. Note that while adding byteswapping to the other accessors
is straightforward, I haven't done it yet; and that also is not enough
to make LFS_EI work, because there are places lying around that bypass
the accessors for one reason and another and all of them need to be
updated. That is going to have to wait for a later day as LFS_EI is
not on the critical path right now.

diffstat:

 libexec/lfs_cleanerd/cleaner.h      |   3 +-
 libexec/lfs_cleanerd/lfs_cleanerd.c |   3 +-
 sbin/fsck_lfs/lfs.c                 |  10 +++++-
 sbin/newfs_lfs/make_lfs.c           |   6 ++-
 sys/ufs/lfs/lfs.h                   |   5 ++-
 sys/ufs/lfs/lfs_accessors.h         |  51 +++++++++++++++++++++++++++++++++---
 sys/ufs/lfs/lfs_vfsops.c            |   7 ++--
 7 files changed, 69 insertions(+), 16 deletions(-)

diffs (232 lines):

diff -r 92366173a99d -r d34dd10894b6 libexec/lfs_cleanerd/cleaner.h
--- a/libexec/lfs_cleanerd/cleaner.h    Tue Sep 01 06:09:23 2015 +0000
+++ b/libexec/lfs_cleanerd/cleaner.h    Tue Sep 01 06:10:16 2015 +0000
@@ -20,7 +20,8 @@
                struct dlfs u_32;
                struct dlfs64 u_64;
        } lfs_dlfs_u;
-       unsigned lfs_is64 : 1;
+       unsigned lfs_is64 : 1,
+               lfs_dobyteswap : 1;
 
        /* Ifile */
        int clfs_ifilefd;          /* Ifile file descriptor */
diff -r 92366173a99d -r d34dd10894b6 libexec/lfs_cleanerd/lfs_cleanerd.c
--- a/libexec/lfs_cleanerd/lfs_cleanerd.c       Tue Sep 01 06:09:23 2015 +0000
+++ b/libexec/lfs_cleanerd/lfs_cleanerd.c       Tue Sep 01 06:10:16 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lfs_cleanerd.c,v 1.50 2015/08/12 18:28:00 dholland Exp $    */
+/* $NetBSD: lfs_cleanerd.c,v 1.51 2015/09/01 06:10:16 dholland Exp $    */
 
 /*-
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -269,6 +269,7 @@
                return -1;
        }
        fs->lfs_is64 = 0; /* XXX notyet */
+       fs->lfs_dobyteswap = 0; /* XXX notyet */
 
        /* If this is not a version 2 filesystem, complain and exit */
        if (lfs_sb_getversion(fs) != 2) {
diff -r 92366173a99d -r d34dd10894b6 sbin/fsck_lfs/lfs.c
--- a/sbin/fsck_lfs/lfs.c       Tue Sep 01 06:09:23 2015 +0000
+++ b/sbin/fsck_lfs/lfs.c       Tue Sep 01 06:10:16 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lfs.c,v 1.58 2015/09/01 06:08:37 dholland Exp $ */
+/* $NetBSD: lfs.c,v 1.59 2015/09/01 06:10:16 dholland Exp $ */
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -424,7 +424,10 @@
        return lfs_raw_vget(fs, ino, fs->lfs_ivnode->v_fd, daddr);
 }
 
-/* Check superblock magic number and checksum */
+/*
+ * Check superblock magic number and checksum.
+ * Sets lfs_is64 and lfs_dobyteswap.
+ */
 static int
 check_sb(struct lfs *fs)
 {
@@ -440,6 +443,9 @@
                       (unsigned long) LFS_MAGIC);
                return 1;
        }
+       fs->lfs_is64 = 0; /* XXX notyet */
+       fs->lfs_dobyteswap = 0; /* XXX notyet */
+
        /* checksum */
        checksum = lfs_sb_cksum(fs);
        if (lfs_sb_getcksum(fs) != checksum) {
diff -r 92366173a99d -r d34dd10894b6 sbin/newfs_lfs/make_lfs.c
--- a/sbin/newfs_lfs/make_lfs.c Tue Sep 01 06:09:23 2015 +0000
+++ b/sbin/newfs_lfs/make_lfs.c Tue Sep 01 06:10:16 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make_lfs.c,v 1.44 2015/08/19 20:33:29 dholland Exp $   */
+/*     $NetBSD: make_lfs.c,v 1.45 2015/09/01 06:10:16 dholland Exp $   */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
 #if 0
 static char sccsid[] = "@(#)lfs.c      8.5 (Berkeley) 5/24/95";
 #else
-__RCSID("$NetBSD: make_lfs.c,v 1.44 2015/08/19 20:33:29 dholland Exp $");
+__RCSID("$NetBSD: make_lfs.c,v 1.45 2015/09/01 06:10:16 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -397,6 +397,7 @@
        u_int64_t tsepb, tnseg;
        time_t stamp;
        bool is64 = false; /* XXX notyet */
+       bool dobyteswap = false; /* XXX notyet */
 
        /*
         * Initialize buffer cache.  Use a ballpark guess of the length of
@@ -420,6 +421,7 @@
                fs->lfs_dlfs_u.u_32 = dlfs32_default;
        }
        fs->lfs_is64 = is64;
+       fs->lfs_dobyteswap = dobyteswap;
        fs->lfs_ivnode = vp;
        fs->lfs_devvp = save_devvp;
 
diff -r 92366173a99d -r d34dd10894b6 sys/ufs/lfs/lfs.h
--- a/sys/ufs/lfs/lfs.h Tue Sep 01 06:09:23 2015 +0000
+++ b/sys/ufs/lfs/lfs.h Tue Sep 01 06:10:16 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs.h,v 1.180 2015/08/12 18:28:01 dholland Exp $       */
+/*     $NetBSD: lfs.h,v 1.181 2015/09/01 06:10:16 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  */
@@ -873,7 +873,8 @@
        } lfs_dlfs_u;
 
 /* These fields are set at mount time and are meaningless on disk. */
-       unsigned lfs_is64 : 1;          /* are we lfs64 or lfs32? */
+       unsigned lfs_is64 : 1,          /* are we lfs64 or lfs32? */
+               lfs_dobyteswap : 1;     /* are we opposite-endian? */
 
        struct segment *lfs_sp;         /* current segment being written */
        struct vnode *lfs_ivnode;       /* vnode for the ifile */
diff -r 92366173a99d -r d34dd10894b6 sys/ufs/lfs/lfs_accessors.h
--- a/sys/ufs/lfs/lfs_accessors.h       Tue Sep 01 06:09:23 2015 +0000
+++ b/sys/ufs/lfs/lfs_accessors.h       Tue Sep 01 06:10:16 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_accessors.h,v 1.16 2015/09/01 06:08:37 dholland Exp $      */
+/*     $NetBSD: lfs_accessors.h,v 1.17 2015/09/01 06:10:16 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  */
@@ -145,6 +145,12 @@
 #ifndef _UFS_LFS_LFS_ACCESSORS_H_
 #define _UFS_LFS_LFS_ACCESSORS_H_
 
+#if defined(_KERNEL_OPT)
+#include "opt_lfs.h"
+#endif
+
+#include <sys/bswap.h>
+
 #if !defined(_KERNEL) && !defined(_STANDALONE)
 #include <assert.h>
 #define KASSERT assert
@@ -161,6 +167,41 @@
 #endif
 
 /*
+ * byte order
+ */
+
+/*
+ * For now at least, the bootblocks shall not be endian-independent.
+ * We can see later if it fits in the size budget. Also disable the
+ * byteswapping if LFS_EI is off.
+ *
+ * Caution: these functions "know" that bswap16/32/64 are unsigned,
+ * and if that changes will likely break silently.
+ */
+
+#if defined(_STANDALONE) || (defined(_KERNEL) && !defined(LFS_EI))
+#define LFS_SWAP_int16_t(fs, val) (val)
+#define LFS_SWAP_int32_t(fs, val) (val)
+#define LFS_SWAP_int64_t(fs, val) (val)
+#define LFS_SWAP_uint16_t(fs, val) (val)
+#define LFS_SWAP_uint32_t(fs, val) (val)
+#define LFS_SWAP_uint64_t(fs, val) (val)
+#else
+#define LFS_SWAP_int16_t(fs, val) \
+       ((fs)->lfs_dobyteswap ? (int16_t)bswap16(val) : (val))
+#define LFS_SWAP_int32_t(fs, val) \
+       ((fs)->lfs_dobyteswap ? (int32_t)bswap32(val) : (val))
+#define LFS_SWAP_int64_t(fs, val) \
+       ((fs)->lfs_dobyteswap ? (int64_t)bswap64(val) : (val))
+#define LFS_SWAP_uint16_t(fs, val) \
+       ((fs)->lfs_dobyteswap ? bswap16(val) : (val))
+#define LFS_SWAP_uint32_t(fs, val) \
+       ((fs)->lfs_dobyteswap ? bswap32(val) : (val))
+#define LFS_SWAP_uint64_t(fs, val) \
+       ((fs)->lfs_dobyteswap ? bswap64(val) : (val))
+#endif
+
+/*
  * dinodes
  */
 
@@ -201,9 +242,9 @@
        lfs_dino_get##field(STRUCT_LFS *fs, union lfs_dinode *dip) \
        {                                                       \
                if (fs->lfs_is64) {                             \
-                       return dip->u_64.di_##field;            \
+                       return LFS_SWAP_##type(fs, dip->u_64.di_##field); \
                } else {                                        \
-                       return dip->u_32.di_##field;            \
+                       return LFS_SWAP_##type32(fs, dip->u_32.di_##field); \
                }                                               \
        }                                                       \
        static __unused inline void                             \
@@ -212,11 +253,11 @@
                if (fs->lfs_is64) {                             \
                        type *p = &dip->u_64.di_##field;        \
                        (void)p;                                \
-                       dip->u_64.di_##field = val;             \
+                       dip->u_64.di_##field = LFS_SWAP_##type(fs, val); \
                } else {                                        \
                        type32 *p = &dip->u_32.di_##field;      \
                        (void)p;                                \
-                       dip->u_32.di_##field = val;             \
+                       dip->u_32.di_##field = LFS_SWAP_##type32(fs, val); \
                }                                               \
        }                                                       \
 
diff -r 92366173a99d -r d34dd10894b6 sys/ufs/lfs/lfs_vfsops.c
--- a/sys/ufs/lfs/lfs_vfsops.c  Tue Sep 01 06:09:23 2015 +0000
+++ b/sys/ufs/lfs/lfs_vfsops.c  Tue Sep 01 06:10:16 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lfs_vfsops.c,v 1.342 2015/09/01 06:08:37 dholland Exp $        */
+/*     $NetBSD: lfs_vfsops.c,v 1.343 2015/09/01 06:10:16 dholland Exp $        */
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007, 2007
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.342 2015/09/01 06:08:37 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.343 2015/09/01 06:10:16 dholland Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_lfs.h"
@@ -953,7 +953,8 @@
        /* Allocate the mount structure, copy the superblock into it. */
        fs = kmem_zalloc(sizeof(struct lfs), KM_SLEEP);
        memcpy(&fs->lfs_dlfs_u.u_32, tdfs, sizeof(struct dlfs));
-       fs->lfs_is64 = false;
+       fs->lfs_is64 = false; /* XXX notyet */
+       fs->lfs_dobyteswap = false; /* XXX notyet */
 
        /* Compatibility */
        if (lfs_sb_getversion(fs) < 2) {



Home | Main Index | Thread Index | Old Index