Module Name:    src
Committed By:   dholland
Date:           Tue Sep  1 06:10:16 UTC 2015

Modified Files:
        src/libexec/lfs_cleanerd: cleaner.h lfs_cleanerd.c
        src/sbin/fsck_lfs: lfs.c
        src/sbin/newfs_lfs: make_lfs.c
        src/sys/ufs/lfs: lfs.h lfs_accessors.h lfs_vfsops.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/libexec/lfs_cleanerd/cleaner.h
cvs rdiff -u -r1.50 -r1.51 src/libexec/lfs_cleanerd/lfs_cleanerd.c
cvs rdiff -u -r1.58 -r1.59 src/sbin/fsck_lfs/lfs.c
cvs rdiff -u -r1.44 -r1.45 src/sbin/newfs_lfs/make_lfs.c
cvs rdiff -u -r1.180 -r1.181 src/sys/ufs/lfs/lfs.h
cvs rdiff -u -r1.16 -r1.17 src/sys/ufs/lfs/lfs_accessors.h
cvs rdiff -u -r1.342 -r1.343 src/sys/ufs/lfs/lfs_vfsops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/libexec/lfs_cleanerd/cleaner.h
diff -u src/libexec/lfs_cleanerd/cleaner.h:1.13 src/libexec/lfs_cleanerd/cleaner.h:1.14
--- src/libexec/lfs_cleanerd/cleaner.h:1.13	Wed Aug 12 18:25:03 2015
+++ src/libexec/lfs_cleanerd/cleaner.h	Tue Sep  1 06:10:16 2015
@@ -20,7 +20,8 @@ struct clfs {
 		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 */

Index: src/libexec/lfs_cleanerd/lfs_cleanerd.c
diff -u src/libexec/lfs_cleanerd/lfs_cleanerd.c:1.50 src/libexec/lfs_cleanerd/lfs_cleanerd.c:1.51
--- src/libexec/lfs_cleanerd/lfs_cleanerd.c:1.50	Wed Aug 12 18:28:00 2015
+++ src/libexec/lfs_cleanerd/lfs_cleanerd.c	Tue Sep  1 06:10:16 2015
@@ -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 @@ init_fs(struct clfs *fs, char *fsname)
 		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) {

Index: src/sbin/fsck_lfs/lfs.c
diff -u src/sbin/fsck_lfs/lfs.c:1.58 src/sbin/fsck_lfs/lfs.c:1.59
--- src/sbin/fsck_lfs/lfs.c:1.58	Tue Sep  1 06:08:37 2015
+++ src/sbin/fsck_lfs/lfs.c	Tue Sep  1 06:10:16 2015
@@ -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 @@ lfs_vget(void *vfs, ino_t ino)
 	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 @@ check_sb(struct lfs *fs)
 		       (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) {

Index: src/sbin/newfs_lfs/make_lfs.c
diff -u src/sbin/newfs_lfs/make_lfs.c:1.44 src/sbin/newfs_lfs/make_lfs.c:1.45
--- src/sbin/newfs_lfs/make_lfs.c:1.44	Wed Aug 19 20:33:29 2015
+++ src/sbin/newfs_lfs/make_lfs.c	Tue Sep  1 06:10:16 2015
@@ -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 @@ make_lfs(int devfd, uint secsize, struct
 	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 @@ make_lfs(int devfd, uint secsize, struct
 		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;
 

Index: src/sys/ufs/lfs/lfs.h
diff -u src/sys/ufs/lfs/lfs.h:1.180 src/sys/ufs/lfs/lfs.h:1.181
--- src/sys/ufs/lfs/lfs.h:1.180	Wed Aug 12 18:28:01 2015
+++ src/sys/ufs/lfs/lfs.h	Tue Sep  1 06:10:16 2015
@@ -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 @@ struct lfs {
 	} 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 */

Index: src/sys/ufs/lfs/lfs_accessors.h
diff -u src/sys/ufs/lfs/lfs_accessors.h:1.16 src/sys/ufs/lfs/lfs_accessors.h:1.17
--- src/sys/ufs/lfs/lfs_accessors.h:1.16	Tue Sep  1 06:08:37 2015
+++ src/sys/ufs/lfs/lfs_accessors.h	Tue Sep  1 06:10:16 2015
@@ -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_copy_dinode(STRUCT_LFS *fs,
 	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 @@ lfs_copy_dinode(STRUCT_LFS *fs,
 		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); \
 		}						\
 	}							\
 

Index: src/sys/ufs/lfs/lfs_vfsops.c
diff -u src/sys/ufs/lfs/lfs_vfsops.c:1.342 src/sys/ufs/lfs/lfs_vfsops.c:1.343
--- src/sys/ufs/lfs/lfs_vfsops.c:1.342	Tue Sep  1 06:08:37 2015
+++ src/sys/ufs/lfs/lfs_vfsops.c	Tue Sep  1 06:10:16 2015
@@ -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 @@ lfs_mountfs(struct vnode *devvp, struct 
 	/* 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) {

Reply via email to