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.
This commit is contained in:
dholland 2015-09-01 06:10:16 +00:00
parent d7cf929e20
commit 4d398b859d
7 changed files with 69 additions and 16 deletions

View File

@ -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 */

View File

@ -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) {

View File

@ -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) {

View File

@ -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 dkwedge_info *dkw, int minfree,
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 dkwedge_info *dkw, int minfree,
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;

View File

@ -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 */

View File

@ -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
@ -160,6 +166,41 @@
#define STRUCT_LFS struct lfs
#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); \
} \
} \

View File

@ -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 mount *mp, struct lwp *l)
/* 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) {