Add byte-swapping functions (bswap16, bswap32, bswap64) to libkern.
Only assembly version for i386 bswap16 and bswap32 for now (bswap64 uses bswap32). Contribution of assembly versions of these are welcome. Add byte-swapping of ext2fs metadata for big-endian systems. Tested on i386 and sparc.
This commit is contained in:
parent
daa885fdce
commit
6ab3092b11
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: endian.h,v 1.4 1997/04/06 08:47:24 cgd Exp $ */
|
||||
/* $NetBSD: endian.h,v 1.5 1997/10/09 15:42:19 bouyer Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1987, 1991, 1993
|
||||
@ -65,6 +65,9 @@ in_addr_t htonl __P((in_addr_t));
|
||||
in_port_t htons __P((in_port_t));
|
||||
in_addr_t ntohl __P((in_addr_t));
|
||||
in_port_t ntohs __P((in_port_t));
|
||||
u_int16_t bswap16 __P((u_int16_t));
|
||||
u_int32_t bswap32 __P((u_int32_t));
|
||||
u_int64_t bswap64 __P((u_int64_t));
|
||||
__END_DECLS
|
||||
|
||||
/*
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: endian.h,v 1.3 1996/10/13 02:57:47 christos Exp $ */
|
||||
/* $NetBSD: endian.h,v 1.4 1997/10/09 15:42:21 bouyer Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1987, 1991 Regents of the University of California.
|
||||
@ -66,6 +66,9 @@ in_addr_t htonl __P((in_addr_t));
|
||||
in_port_t htons __P((in_port_t));
|
||||
in_addr_t ntohl __P((in_addr_t));
|
||||
in_port_t ntohs __P((in_port_t));
|
||||
u_int16_t bswap16 __P((u_int16_t));
|
||||
u_int32_t bswap32 __P((u_int32_t));
|
||||
u_int64_t bswap64 __P((u_int64_t));
|
||||
__END_DECLS
|
||||
|
||||
/*
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: endian.h,v 1.20 1997/07/17 18:44:08 thorpej Exp $ */
|
||||
/* $NetBSD: endian.h,v 1.21 1997/10/09 15:42:22 bouyer Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1995 Charles M. Hannum. All rights reserved.
|
||||
@ -67,6 +67,9 @@ in_addr_t htonl __P((in_addr_t));
|
||||
in_port_t htons __P((in_port_t));
|
||||
in_addr_t ntohl __P((in_addr_t));
|
||||
in_port_t ntohs __P((in_port_t));
|
||||
u_int16_t bswap16 __P((u_int16_t));
|
||||
u_int32_t bswap32 __P((u_int32_t));
|
||||
u_int64_t bswap64 __P((u_int64_t));
|
||||
__END_DECLS
|
||||
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: endian.h,v 1.10 1996/10/13 02:59:55 christos Exp $ */
|
||||
/* $NetBSD: endian.h,v 1.11 1997/10/09 15:42:23 bouyer Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1987, 1991 Regents of the University of California.
|
||||
@ -65,6 +65,9 @@ in_addr_t htonl __P((in_addr_t));
|
||||
in_port_t htons __P((in_port_t));
|
||||
in_addr_t ntohl __P((in_addr_t));
|
||||
in_port_t ntohs __P((in_port_t));
|
||||
u_int16_t bswap16 __P((u_int16_t));
|
||||
u_int32_t bswap32 __P((u_int32_t));
|
||||
u_int64_t bswap64 __P((u_int64_t));
|
||||
__END_DECLS
|
||||
|
||||
/*
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: endian.h,v 1.8 1996/10/13 20:59:02 mhitch Exp $ */
|
||||
/* $NetBSD: endian.h,v 1.9 1997/10/09 15:42:24 bouyer Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1987, 1991, 1993
|
||||
@ -71,6 +71,9 @@ in_addr_t htonl __P((in_addr_t));
|
||||
in_port_t htons __P((in_port_t));
|
||||
in_addr_t ntohl __P((in_addr_t));
|
||||
in_port_t ntohs __P((in_port_t));
|
||||
u_int16_t bswap16 __P((u_int16_t));
|
||||
u_int32_t bswap32 __P((u_int32_t));
|
||||
u_int64_t bswap64 __P((u_int64_t));
|
||||
__END_DECLS
|
||||
|
||||
/*
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: endian.h,v 1.9 1996/10/13 03:12:38 christos Exp $ */
|
||||
/* $NetBSD: endian.h,v 1.10 1997/10/09 15:42:25 bouyer Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1987, 1991 Regents of the University of California.
|
||||
@ -65,6 +65,9 @@ in_addr_t htonl __P((in_addr_t));
|
||||
in_port_t htons __P((in_port_t));
|
||||
in_addr_t ntohl __P((in_addr_t));
|
||||
in_port_t ntohs __P((in_port_t));
|
||||
u_int16_t bswap16 __P((u_int16_t));
|
||||
u_int32_t bswap32 __P((u_int32_t));
|
||||
u_int64_t bswap64 __P((u_int64_t));
|
||||
__END_DECLS
|
||||
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: endian.h,v 1.2 1996/10/13 03:16:41 christos Exp $ */
|
||||
/* $NetBSD: endian.h,v 1.3 1997/10/09 15:42:26 bouyer Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (C) 1995 Wolfgang Solfrank.
|
||||
@ -59,6 +59,9 @@ in_addr_t htonl __P((in_addr_t));
|
||||
in_port_t htons __P((in_port_t));
|
||||
in_addr_t ntohl __P((in_addr_t));
|
||||
in_port_t ntohs __P((in_port_t));
|
||||
u_int16_t bswap16 __P((u_int16_t));
|
||||
u_int32_t bswap32 __P((u_int32_t));
|
||||
u_int64_t bswap64 __P((u_int64_t));
|
||||
__END_DECLS
|
||||
|
||||
/*
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: endian.h,v 1.6 1996/10/11 00:43:00 christos Exp $ */
|
||||
/* $NetBSD: endian.h,v 1.7 1997/10/09 15:42:28 bouyer Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1987, 1991 Regents of the University of California.
|
||||
@ -61,6 +61,9 @@ in_addr_t htonl __P((in_addr_t));
|
||||
in_port_t htons __P((in_port_t));
|
||||
in_addr_t ntohl __P((in_addr_t));
|
||||
in_port_t ntohs __P((in_port_t));
|
||||
u_int16_t bswap16 __P((u_int16_t));
|
||||
u_int32_t bswap32 __P((u_int32_t));
|
||||
u_int64_t bswap64 __P((u_int64_t));
|
||||
__END_DECLS
|
||||
|
||||
/*
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: endian.h,v 1.8 1996/10/13 03:28:00 christos Exp $ */
|
||||
/* $NetBSD: endian.h,v 1.9 1997/10/09 15:42:29 bouyer Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1987, 1991 Regents of the University of California.
|
||||
@ -63,6 +63,9 @@ in_addr_t htonl __P((in_addr_t));
|
||||
in_port_t htons __P((in_port_t));
|
||||
in_addr_t ntohl __P((in_addr_t));
|
||||
in_port_t ntohs __P((in_port_t));
|
||||
u_int16_t bswap16 __P((u_int16_t));
|
||||
u_int32_t bswap32 __P((u_int32_t));
|
||||
u_int64_t bswap64 __P((u_int64_t));
|
||||
__END_DECLS
|
||||
|
||||
#ifdef __GNUC__
|
||||
|
@ -1,4 +1,4 @@
|
||||
# $NetBSD: files,v 1.147 1997/10/07 16:15:30 gwr Exp $
|
||||
# $NetBSD: files,v 1.148 1997/10/09 15:42:31 bouyer Exp $
|
||||
|
||||
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
|
||||
|
||||
@ -448,6 +448,7 @@ file nfs/nfs_vnops.c nfs
|
||||
file ufs/ext2fs/ext2fs_alloc.c ext2fs
|
||||
file ufs/ext2fs/ext2fs_balloc.c ext2fs
|
||||
file ufs/ext2fs/ext2fs_bmap.c ext2fs
|
||||
file ufs/ext2fs/ext2fs_bswap.c ext2fs
|
||||
file ufs/ext2fs/ext2fs_inode.c ext2fs
|
||||
file ufs/ext2fs/ext2fs_lookup.c ext2fs
|
||||
file ufs/ext2fs/ext2fs_readwrite.c ext2fs
|
||||
|
@ -1,6 +1,7 @@
|
||||
# $NetBSD: Makefile.inc,v 1.10 1997/01/18 02:33:44 cgd Exp $
|
||||
# $NetBSD: Makefile.inc,v 1.11 1997/10/09 15:42:34 bouyer Exp $
|
||||
|
||||
SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \
|
||||
bswap16.S bswap32.S bswap64.c \
|
||||
bcmp.c bzero.S ffs.S strcat.c strcmp.c strcpy.c strlen.c strncmp.c \
|
||||
strncpy.c scanc.c skpc.c htonl.S htons.S ntohl.S ntohs.S \
|
||||
random.c strncasecmp.c __assert.c strchr.c
|
||||
|
@ -1,6 +1,7 @@
|
||||
# $NetBSD: Makefile.inc,v 1.6 1997/01/18 02:33:47 cgd Exp $
|
||||
# $NetBSD: Makefile.inc,v 1.7 1997/10/09 15:42:35 bouyer Exp $
|
||||
|
||||
SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \
|
||||
bswap16.c bswap32.c bswap64.c \
|
||||
bcmp.c bzero.c ffs.c strcat.c strcmp.c strcpy.c strlen.c strncmp.c \
|
||||
strncpy.c scanc.c skpc.c htonl.c htons.c ntohl.c ntohs.c \
|
||||
div.S random.c strncasecmp.c __assert.c strchr.c
|
||||
|
@ -1,6 +1,7 @@
|
||||
# $NetBSD: Makefile.inc,v 1.13 1997/01/18 02:33:50 cgd Exp $
|
||||
# $NetBSD: Makefile.inc,v 1.14 1997/10/09 15:42:36 bouyer Exp $
|
||||
|
||||
SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \
|
||||
bswap16.S bswap32.S bswap64.c \
|
||||
bcmp.S ffs.S strcat.S strcmp.S strcpy.S strlen.S strncmp.c \
|
||||
strncpy.c scanc.S skpc.S htonl.S htons.S ntohl.S ntohs.S \
|
||||
strncasecmp.c __assert.c strchr.c
|
||||
|
49
sys/lib/libkern/arch/i386/bswap16.S
Normal file
49
sys/lib/libkern/arch/i386/bswap16.S
Normal file
@ -0,0 +1,49 @@
|
||||
/*-
|
||||
* Copyright (c) 1990 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* from: @(#)htons.s 5.2 (Berkeley) 12/17/90
|
||||
* $Id: bswap16.S,v 1.1 1997/10/09 15:42:37 bouyer Exp $
|
||||
*/
|
||||
|
||||
#include <machine/asm.h>
|
||||
|
||||
#if defined(LIBC_SCCS)
|
||||
RCSID("$Id: bswap16.S,v 1.1 1997/10/09 15:42:37 bouyer Exp $")
|
||||
#endif
|
||||
|
||||
ENTRY(bswap16)
|
||||
movzwl 4(%esp),%eax
|
||||
rorw $8,%ax
|
||||
ret
|
51
sys/lib/libkern/arch/i386/bswap32.S
Normal file
51
sys/lib/libkern/arch/i386/bswap32.S
Normal file
@ -0,0 +1,51 @@
|
||||
/*-
|
||||
* Copyright (c) 1990 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* William Jolitz.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* from: @(#)htonl.s 5.3 (Berkeley) 12/17/90
|
||||
* $Id: bswap32.S,v 1.1 1997/10/09 15:42:38 bouyer Exp $
|
||||
*/
|
||||
|
||||
#include <machine/asm.h>
|
||||
|
||||
#if defined(LIBC_SCCS)
|
||||
RCSID("$Id: bswap32.S,v 1.1 1997/10/09 15:42:38 bouyer Exp $")
|
||||
#endif
|
||||
|
||||
ENTRY(bswap32)
|
||||
movl 4(%esp),%eax
|
||||
rorw $8,%ax
|
||||
roll $16,%eax
|
||||
rorw $8,%ax
|
||||
ret
|
@ -1,6 +1,7 @@
|
||||
# $NetBSD: Makefile.inc,v 1.12 1997/01/18 02:33:54 cgd Exp $
|
||||
# $NetBSD: Makefile.inc,v 1.13 1997/10/09 15:42:39 bouyer Exp $
|
||||
|
||||
SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \
|
||||
bswap16.c bswap32.c bswap64.c \
|
||||
bcmp.S bzero.S ffs.S strcat.S strcmp.S strcpy.S strlen.S strncmp.S \
|
||||
strncpy.S htonl.S htons.S ntohl.S ntohs.S scanc.S skpc.S \
|
||||
strncasecmp.c __assert.c strchr.c
|
||||
|
@ -1,6 +1,7 @@
|
||||
# $NetBSD: Makefile.inc,v 1.6 1997/01/18 02:33:57 cgd Exp $
|
||||
# $NetBSD: Makefile.inc,v 1.7 1997/10/09 15:42:40 bouyer Exp $
|
||||
#
|
||||
# There are likely more that we will notice when we go native
|
||||
|
||||
SRCS+= random.c scanc.c skpc.c strcat.c strcpy.c strncmp.c strncpy.c \
|
||||
bswap16.c bswap32.c bswap64.c \
|
||||
strncasecmp.c __assert.c strchr.c
|
||||
|
@ -1,6 +1,7 @@
|
||||
# $NetBSD: Makefile.inc,v 1.11 1997/01/18 02:34:02 cgd Exp $
|
||||
# $NetBSD: Makefile.inc,v 1.12 1997/10/09 15:42:41 bouyer Exp $
|
||||
|
||||
SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \
|
||||
bswap16.c bswap32.c bswap64.c \
|
||||
bcmp.S bcopy.S bzero.S ffs.S strcat.S strcmp.S strcpy.S strlen.S \
|
||||
strncmp.S strncpy.S htonl.S htons.S ntohl.S ntohs.S \
|
||||
scanc.c skpc.c strncasecmp.c __assert.c strchr.c
|
||||
|
@ -1,6 +1,7 @@
|
||||
# $NetBSD: Makefile.inc,v 1.2 1997/01/18 02:34:04 cgd Exp $
|
||||
# $NetBSD: Makefile.inc,v 1.3 1997/10/09 15:42:42 bouyer Exp $
|
||||
|
||||
SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \
|
||||
bswap16.c bswap32.c bswap64.c \
|
||||
bcmp.c bzero.c ffs.c scanc.c skpc.c \
|
||||
strcat.c strcmp.c strcpy.c strlen.c strncmp.c strncpy.c \
|
||||
random.c __assert.c strchr.c
|
||||
|
@ -1,6 +1,7 @@
|
||||
# $NetBSD: Makefile.inc,v 1.15 1997/01/18 02:34:07 cgd Exp $
|
||||
# $NetBSD: Makefile.inc,v 1.16 1997/10/09 15:42:43 bouyer Exp $
|
||||
|
||||
SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \
|
||||
bswap16.c bswap32.c bswap64.c \
|
||||
bcmp.c bzero.S strcat.c strcmp.c strcpy.c strlen.S strncmp.c \
|
||||
strncpy.c htonl.S htons.S ntohl.S ntohs.S scanc.c skpc.c \
|
||||
strncasecmp.c __assert.c strchr.c
|
||||
|
@ -1,5 +1,6 @@
|
||||
# $NetBSD: Makefile.inc,v 1.5 1997/01/18 02:34:10 cgd Exp $
|
||||
# $NetBSD: Makefile.inc,v 1.6 1997/10/09 15:42:44 bouyer Exp $
|
||||
|
||||
SRCS+= __main.c imax.c imin.c lmax.c lmin.c max.c min.c ulmax.c ulmin.c \
|
||||
bswap16.c bswap32.c bswap64.c \
|
||||
strcat.c strcmp.c strcpy.c strlen.c strncmp.c \
|
||||
strncpy.c scanc.c skpc.c strncasecmp.c __assert.c strchr.c
|
||||
|
21
sys/lib/libkern/bswap16.c
Normal file
21
sys/lib/libkern/bswap16.c
Normal file
@ -0,0 +1,21 @@
|
||||
/* $NetBSD: bswap16.c,v 1.1 1997/10/09 15:42:32 bouyer Exp $ */
|
||||
|
||||
/*
|
||||
* Written by Manuel Bouyer <bouyer@netbsd.org>.
|
||||
* Public domain.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char *rcsid = "$NetBSD: bswap16.c,v 1.1 1997/10/09 15:42:32 bouyer Exp $";
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#undef bswap16
|
||||
|
||||
u_int16_t
|
||||
bswap16(x)
|
||||
u_int16_t x;
|
||||
{
|
||||
return ((x << 8) & 0xff00) | ((x >> 8) & 0x00ff);
|
||||
}
|
25
sys/lib/libkern/bswap32.c
Normal file
25
sys/lib/libkern/bswap32.c
Normal file
@ -0,0 +1,25 @@
|
||||
/* $NetBSD: bswap32.c,v 1.1 1997/10/09 15:42:33 bouyer Exp $ */
|
||||
|
||||
/*
|
||||
* Written by Manuel Bouyer <bouyer@netbsd.org>.
|
||||
* Public domain.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char *rcsid = "$NetBSD: bswap32.c,v 1.1 1997/10/09 15:42:33 bouyer Exp $";
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#undef bswap32
|
||||
|
||||
u_int32_t
|
||||
bswap32(x)
|
||||
u_int32_t x;
|
||||
{
|
||||
return ((x << 24) & 0xff000000 ) |
|
||||
((x << 8) & 0x00ff0000 ) |
|
||||
((x >> 8) & 0x0000ff00 ) |
|
||||
((x >> 24) & 0x000000ff );
|
||||
}
|
||||
|
27
sys/lib/libkern/bswap64.c
Normal file
27
sys/lib/libkern/bswap64.c
Normal file
@ -0,0 +1,27 @@
|
||||
/* $NetBSD: bswap64.c,v 1.1 1997/10/09 15:42:33 bouyer Exp $ */
|
||||
|
||||
/*
|
||||
* Written by Manuel Bouyer <bouyer@netbsd.org>.
|
||||
* Public domain.
|
||||
*/
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static char *rcsid = "$NetBSD: bswap64.c,v 1.1 1997/10/09 15:42:33 bouyer Exp $";
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#undef bswap64
|
||||
|
||||
u_int64_t
|
||||
bswap64(x)
|
||||
u_int64_t x;
|
||||
{
|
||||
u_int32_t *p = (u_int32_t*)&x;
|
||||
u_int32_t t;
|
||||
t = bswap32(p[0]);
|
||||
p[0] = bswap32(p[1]);
|
||||
p[1] = t;
|
||||
return x;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: ext2fs.h,v 1.1 1997/06/11 09:33:37 bouyer Exp $ */
|
||||
/* $NetBSD: ext2fs.h,v 1.2 1997/10/09 15:42:45 bouyer Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 Manuel Bouyer.
|
||||
@ -181,6 +181,32 @@ struct ext2_gd {
|
||||
|
||||
};
|
||||
|
||||
/* EXT2FS metadatas are stored in little-endian byte order. These macros
|
||||
* helps reading theses metadatas
|
||||
*/
|
||||
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
# define h2fs16(x) (x)
|
||||
# define h2fs32(x) (x)
|
||||
# define fs2h16(x) (x)
|
||||
# define fs2h32(x) (x)
|
||||
# define e2fs_sbload(old, new) bcopy((old), (new), SBSIZE);
|
||||
# define e2fs_cgload(old, new, size) bcopy((old), (new), (size));
|
||||
# define e2fs_sbsave(old, new) bcopy((old), (new), SBSIZE);
|
||||
# define e2fs_cgsave(old, new, size) bcopy((old), (new), (size));
|
||||
#else
|
||||
void e2fs_sb_bswap __P((struct ext2fs *, struct ext2fs *));
|
||||
void e2fs_cg_bswap __P((struct ext2_gd *, struct ext2_gd *, int));
|
||||
# define h2fs16(x) bswap16(x)
|
||||
# define h2fs32(x) bswap32(x)
|
||||
# define fs2h16(x) bswap16(x)
|
||||
# define fs2h32(x) bswap32(x)
|
||||
# define e2fs_sbload(old, new) e2fs_sb_bswap((old), (new))
|
||||
# define e2fs_cgload(old, new, size) e2fs_cg_bswap((old), (new), (size));
|
||||
# define e2fs_sbsave(old, new) e2fs_sb_bswap((old), (new))
|
||||
# define e2fs_cgsave(old, new, size) e2fs_cg_bswap((old), (new), (size));
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Turn file system block numbers into disk block addresses.
|
||||
* This maps file system blocks to device size blocks.
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: ext2fs_alloc.c,v 1.1 1997/06/11 09:33:41 bouyer Exp $ */
|
||||
/* $NetBSD: ext2fs_alloc.c,v 1.2 1997/10/09 15:42:46 bouyer Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 Manuel Bouyer.
|
||||
@ -263,7 +263,7 @@ ext2fs_blkpref(ip, lbn, indx, bap)
|
||||
if (bap) {
|
||||
for (i = indx; i >= 0 ; i--) {
|
||||
if (bap[i]) {
|
||||
return bap[i] + 1;
|
||||
return fs2h32(bap[i]) + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -403,7 +403,7 @@ gotit:
|
||||
if (isset(bbp, (long)bno)) {
|
||||
printf("ext2fs_alloccgblk: cg=%d bno=%d fs=%s\n",
|
||||
cg, bno, fs->e2fs_fsmnt);
|
||||
panic("ext2fs_valloc: dup alloc");
|
||||
panic("ext2fs_alloccg: dup alloc");
|
||||
}
|
||||
#endif
|
||||
setbit(bbp, (long)bno);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: ext2fs_balloc.c,v 1.1 1997/06/11 09:33:44 bouyer Exp $ */
|
||||
/* $NetBSD: ext2fs_balloc.c,v 1.2 1997/10/09 15:42:47 bouyer Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 Manuel Bouyer.
|
||||
@ -85,7 +85,7 @@ ext2fs_balloc(ip, bn, size, cred, bpp, flags)
|
||||
* The first NDADDR blocks are direct blocks
|
||||
*/
|
||||
if (bn < NDADDR) {
|
||||
nb = ip->i_e2fs_blocks[bn];
|
||||
nb = fs2h32(ip->i_e2fs_blocks[bn]);
|
||||
if (nb != 0) {
|
||||
error = bread(vp, bn, fs->e2fs_bsize, NOCRED, &bp);
|
||||
if (error) {
|
||||
@ -107,7 +107,7 @@ ext2fs_balloc(ip, bn, size, cred, bpp, flags)
|
||||
if (flags & B_CLRBUF)
|
||||
clrbuf(bp);
|
||||
}
|
||||
ip->i_e2fs_blocks[bn] = dbtofsb(fs, bp->b_blkno);
|
||||
ip->i_e2fs_blocks[bn] = h2fs32(dbtofsb(fs, bp->b_blkno));
|
||||
ip->i_flag |= IN_CHANGE | IN_UPDATE;
|
||||
*bpp = bp;
|
||||
return (0);
|
||||
@ -126,7 +126,7 @@ ext2fs_balloc(ip, bn, size, cred, bpp, flags)
|
||||
* Fetch the first indirect block allocating if necessary.
|
||||
*/
|
||||
--num;
|
||||
nb = ip->i_e2fs_blocks[NDADDR + indirs[0].in_off];
|
||||
nb = fs2h32(ip->i_e2fs_blocks[NDADDR + indirs[0].in_off]);
|
||||
if (nb == 0) {
|
||||
pref = ext2fs_blkpref(ip, lbn, 0, (daddr_t *)0);
|
||||
error = ext2fs_alloc(ip, lbn, pref,
|
||||
@ -146,7 +146,7 @@ ext2fs_balloc(ip, bn, size, cred, bpp, flags)
|
||||
ext2fs_blkfree(ip, nb);
|
||||
return (error);
|
||||
}
|
||||
ip->i_e2fs_blocks[NDADDR + indirs[0].in_off] = newb;
|
||||
ip->i_e2fs_blocks[NDADDR + indirs[0].in_off] = h2fs32(newb);
|
||||
ip->i_flag |= IN_CHANGE | IN_UPDATE;
|
||||
}
|
||||
/*
|
||||
@ -160,7 +160,7 @@ ext2fs_balloc(ip, bn, size, cred, bpp, flags)
|
||||
return (error);
|
||||
}
|
||||
bap = (daddr_t *)bp->b_data;
|
||||
nb = bap[indirs[i].in_off];
|
||||
nb = fs2h32(bap[indirs[i].in_off]);
|
||||
if (i == num)
|
||||
break;
|
||||
i += 1;
|
||||
@ -189,7 +189,7 @@ ext2fs_balloc(ip, bn, size, cred, bpp, flags)
|
||||
brelse(bp);
|
||||
return (error);
|
||||
}
|
||||
bap[indirs[i - 1].in_off] = nb;
|
||||
bap[indirs[i - 1].in_off] = h2fs32(nb);
|
||||
/*
|
||||
* If required, write synchronously, otherwise use
|
||||
* delayed write.
|
||||
@ -218,7 +218,7 @@ ext2fs_balloc(ip, bn, size, cred, bpp, flags)
|
||||
nbp->b_blkno = fsbtodb(fs, nb);
|
||||
if (flags & B_CLRBUF)
|
||||
clrbuf(nbp);
|
||||
bap[indirs[i].in_off] = nb;
|
||||
bap[indirs[i].in_off] = h2fs32(nb);
|
||||
/*
|
||||
* If required, write synchronously, otherwise use
|
||||
* delayed write.
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: ext2fs_bmap.c,v 1.2 1997/07/24 17:18:03 bouyer Exp $ */
|
||||
/* $NetBSD: ext2fs_bmap.c,v 1.3 1997/10/09 15:42:48 bouyer Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 Manuel Bouyer.
|
||||
@ -57,6 +57,7 @@
|
||||
#include <ufs/ufs/inode.h>
|
||||
#include <ufs/ufs/ufsmount.h>
|
||||
#include <ufs/ufs/ufs_extern.h>
|
||||
#include <ufs/ext2fs/ext2fs.h>
|
||||
#include <ufs/ext2fs/ext2fs_extern.h>
|
||||
|
||||
static int ext2fs_bmaparray __P((struct vnode *, daddr_t, daddr_t *,
|
||||
@ -151,20 +152,20 @@ ext2fs_bmaparray(vp, bn, bnp, ap, nump, runp)
|
||||
|
||||
num = *nump;
|
||||
if (num == 0) {
|
||||
*bnp = blkptrtodb(ump, ip->i_e2fs_blocks[bn]);
|
||||
*bnp = blkptrtodb(ump, fs2h32(ip->i_e2fs_blocks[bn]));
|
||||
if (*bnp == 0)
|
||||
*bnp = -1;
|
||||
else if (runp)
|
||||
for (++bn; bn < NDADDR && *runp < maxrun &&
|
||||
is_sequential(ump, ip->i_e2fs_blocks[bn - 1],
|
||||
ip->i_e2fs_blocks[bn]);
|
||||
is_sequential(ump, fs2h32(ip->i_e2fs_blocks[bn - 1]),
|
||||
fs2h32(ip->i_e2fs_blocks[bn]));
|
||||
++bn, ++*runp);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/* Get disk address out of indirect block array */
|
||||
daddr = ip->i_e2fs_blocks[NDADDR + xap->in_off];
|
||||
daddr = fs2h32(ip->i_e2fs_blocks[NDADDR + xap->in_off]);
|
||||
|
||||
devvp = VFSTOUFS(vp->v_mount)->um_devvp;
|
||||
|
||||
@ -212,7 +213,7 @@ ext2fs_bmaparray(vp, bn, bnp, ap, nump, runp)
|
||||
}
|
||||
}
|
||||
|
||||
daddr = ((daddr_t *)bp->b_data)[xap->in_off];
|
||||
daddr = fs2h32(((daddr_t *)bp->b_data)[xap->in_off]);
|
||||
if (num == 1 && daddr && runp)
|
||||
for (bn = xap->in_off + 1;
|
||||
bn < MNINDIR(ump) && *runp < maxrun &&
|
||||
|
111
sys/ufs/ext2fs/ext2fs_bswap.c
Normal file
111
sys/ufs/ext2fs/ext2fs_bswap.c
Normal file
@ -0,0 +1,111 @@
|
||||
/* $NetBSD: ext2fs_bswap.c,v 1.1 1997/10/09 15:42:49 bouyer Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 Manuel Bouyer.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/systm.h>
|
||||
#include <ufs/ext2fs/ext2fs.h>
|
||||
#include <ufs/ext2fs/ext2fs_dinode.h>
|
||||
|
||||
/* These functions are only needed if native byte order is not big endian */
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
void
|
||||
e2fs_sb_bswap(old, new)
|
||||
struct ext2fs *old, *new;
|
||||
{
|
||||
/* preserve unused fields */
|
||||
memcpy(new, old, sizeof(struct ext2fs));
|
||||
new->e2fs_icount = bswap32(old->e2fs_icount);
|
||||
new->e2fs_bcount = bswap32(old->e2fs_bcount);
|
||||
new->e2fs_rbcount = bswap32(old->e2fs_rbcount);
|
||||
new->e2fs_fbcount = bswap32(old->e2fs_fbcount);
|
||||
new->e2fs_ficount = bswap32(old->e2fs_ficount);
|
||||
new->e2fs_first_dblock = bswap32(old->e2fs_first_dblock);
|
||||
new->e2fs_log_bsize = bswap32(old->e2fs_log_bsize);
|
||||
new->e2fs_fsize = bswap32(old->e2fs_fsize);
|
||||
new->e2fs_bpg = bswap32(old->e2fs_bpg);
|
||||
new->e2fs_fpg = bswap32(old->e2fs_fpg);
|
||||
new->e2fs_ipg = bswap32(old->e2fs_ipg);
|
||||
new->e2fs_mtime = bswap32(old->e2fs_mtime);
|
||||
new->e2fs_wtime = bswap32(old->e2fs_wtime);
|
||||
new->e2fs_lastfsck = bswap32(old->e2fs_lastfsck);
|
||||
new->e2fs_fsckintv = bswap32(old->e2fs_fsckintv);
|
||||
new->e2fs_creator = bswap32(old->e2fs_creator);
|
||||
new->e2fs_rev = bswap32(old->e2fs_rev);
|
||||
new->e2fs_mnt_count = bswap16(old->e2fs_mnt_count);
|
||||
new->e2fs_max_mnt_count = bswap16(old->e2fs_max_mnt_count);
|
||||
new->e2fs_magic = bswap16(old->e2fs_magic);
|
||||
new->e2fs_state = bswap16(old->e2fs_state);
|
||||
new->e2fs_beh = bswap16(old->e2fs_beh);
|
||||
new->e2fs_ruid = bswap16(old->e2fs_ruid);
|
||||
new->e2fs_rgid = bswap16(old->e2fs_rgid);
|
||||
}
|
||||
|
||||
void e2fs_cg_bswap(old, new, size)
|
||||
struct ext2_gd *old, *new;
|
||||
int size;
|
||||
{
|
||||
int i;
|
||||
for (i=0; i < (size / sizeof(struct ext2_gd)); i++) {
|
||||
new[i].ext2bgd_b_bitmap = bswap32(old[i].ext2bgd_b_bitmap);
|
||||
new[i].ext2bgd_i_bitmap = bswap32(old[i].ext2bgd_i_bitmap);
|
||||
new[i].ext2bgd_i_tables = bswap32(old[i].ext2bgd_i_tables);
|
||||
new[i].ext2bgd_nbfree = bswap16(old[i].ext2bgd_nbfree);
|
||||
new[i].ext2bgd_nifree = bswap16(old[i].ext2bgd_nifree);
|
||||
new[i].ext2bgd_ndirs = bswap16(old[i].ext2bgd_ndirs);
|
||||
}
|
||||
}
|
||||
|
||||
void e2fs_i_bswap(old, new)
|
||||
struct ext2fs_dinode *old, *new;
|
||||
{
|
||||
new->e2di_mode = bswap16(old->e2di_mode);
|
||||
new->e2di_uid = bswap16(old->e2di_uid);
|
||||
new->e2di_gid = bswap16(old->e2di_gid);
|
||||
new->e2di_nlink = bswap16(old->e2di_nlink);
|
||||
new->e2di_size = bswap32(old->e2di_size);
|
||||
new->e2di_atime = bswap32(old->e2di_atime);
|
||||
new->e2di_ctime = bswap32(old->e2di_ctime);
|
||||
new->e2di_mtime = bswap32(old->e2di_mtime);
|
||||
new->e2di_dtime = bswap32(old->e2di_dtime);
|
||||
new->e2di_nblock = bswap32(old->e2di_nblock);
|
||||
new->e2di_flags = bswap32(old->e2di_flags);
|
||||
new->e2di_gen = bswap32(old->e2di_gen);
|
||||
new->e2di_facl = bswap32(old->e2di_facl);
|
||||
new->e2di_dacl = bswap32(old->e2di_dacl);
|
||||
new->e2di_faddr = bswap32(old->e2di_faddr);
|
||||
bcopy(&old->e2di_blocks[0], &new->e2di_blocks[0],
|
||||
(NDADDR+NIADDR) * sizeof(int));
|
||||
}
|
||||
#endif
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: ext2fs_dinode.h,v 1.1 1997/06/11 09:33:48 bouyer Exp $ */
|
||||
/* $NetBSD: ext2fs_dinode.h,v 1.2 1997/10/09 15:42:49 bouyer Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 Manuel Bouyer.
|
||||
@ -130,3 +130,13 @@ struct ext2fs_dinode {
|
||||
|
||||
#define e2di_rdev e2di_blocks[0]
|
||||
#define e2di_shortlink e2di_blocks
|
||||
|
||||
/* e2fs needs byte swapping on big-endian systems */
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
# define e2fs_iload(old, new) bcopy((old),(new),sizeof(struct ext2fs_dinode))
|
||||
# define e2fs_isave(old, new) bcopy((old),(new),sizeof(struct ext2fs_dinode))
|
||||
#else
|
||||
void e2fs_i_bswap __P((struct ext2fs_dinode *, struct ext2fs_dinode *));
|
||||
# define e2fs_iload(old, new) e2fs_i_bswap((old), (new))
|
||||
# define e2fs_isave(old, new) e2fs_i_bswap((old), (new))
|
||||
#endif
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: ext2fs_inode.c,v 1.2 1997/07/04 20:22:13 drochner Exp $ */
|
||||
/* $NetBSD: ext2fs_inode.c,v 1.3 1997/10/09 15:42:50 bouyer Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 Manuel Bouyer.
|
||||
@ -172,9 +172,8 @@ ext2fs_update(v)
|
||||
brelse(bp);
|
||||
return (error);
|
||||
}
|
||||
bcopy(&ip->i_din.e2fs_din,
|
||||
((struct ext2fs_dinode *)bp->b_data + ino_to_fsbo(fs, ip->i_number)),
|
||||
sizeof(struct ext2fs_dinode));
|
||||
e2fs_isave(&ip->i_din.e2fs_din,
|
||||
(struct ext2fs_dinode *)bp->b_data + ino_to_fsbo(fs, ip->i_number));
|
||||
if (ap->a_waitfor)
|
||||
return (bwrite(bp));
|
||||
else {
|
||||
@ -346,7 +345,7 @@ ext2fs_truncate(v)
|
||||
indir_lbn[DOUBLE] = indir_lbn[SINGLE] - NINDIR(fs) -1;
|
||||
indir_lbn[TRIPLE] = indir_lbn[DOUBLE] - NINDIR(fs) * NINDIR(fs) - 1;
|
||||
for (level = TRIPLE; level >= SINGLE; level--) {
|
||||
bn = oip->i_e2fs_blocks[NDADDR + level];
|
||||
bn = fs2h32(oip->i_e2fs_blocks[NDADDR + level]);
|
||||
if (bn != 0) {
|
||||
error = ext2fs_indirtrunc(oip, indir_lbn[level],
|
||||
fsbtodb(fs, bn), lastiblock[level], level, &count);
|
||||
@ -367,7 +366,7 @@ ext2fs_truncate(v)
|
||||
* All whole direct blocks or frags.
|
||||
*/
|
||||
for (i = NDADDR - 1; i > lastblock; i--) {
|
||||
bn = oip->i_e2fs_blocks[i];
|
||||
bn = fs2h32(oip->i_e2fs_blocks[i]);
|
||||
if (bn == 0)
|
||||
continue;
|
||||
oip->i_e2fs_blocks[i] = 0;
|
||||
@ -380,10 +379,11 @@ ext2fs_truncate(v)
|
||||
done:
|
||||
#ifdef DIAGNOSTIC
|
||||
for (level = SINGLE; level <= TRIPLE; level++)
|
||||
if (newblks[NDADDR + level] != oip->i_e2fs_blocks[NDADDR + level])
|
||||
if (newblks[NDADDR + level] !=
|
||||
fs2h32(oip->i_e2fs_blocks[NDADDR + level]))
|
||||
panic("itrunc1");
|
||||
for (i = 0; i < NDADDR; i++)
|
||||
if (newblks[i] != oip->i_e2fs_blocks[i])
|
||||
if (newblks[i] != fs2h32(oip->i_e2fs_blocks[i]))
|
||||
panic("itrunc2");
|
||||
if (length == 0 &&
|
||||
(ovp->v_dirtyblkhd.lh_first || ovp->v_cleanblkhd.lh_first))
|
||||
@ -486,7 +486,7 @@ ext2fs_indirtrunc(ip, lbn, dbn, lastbn, level, countp)
|
||||
for (i = NINDIR(fs) - 1,
|
||||
nlbn = lbn + 1 - i * factor; i > last;
|
||||
i--, nlbn += factor) {
|
||||
nb = bap[i];
|
||||
nb = fs2h32(bap[i]);
|
||||
if (nb == 0)
|
||||
continue;
|
||||
if (level > SINGLE) {
|
||||
@ -506,7 +506,7 @@ ext2fs_indirtrunc(ip, lbn, dbn, lastbn, level, countp)
|
||||
*/
|
||||
if (level > SINGLE && lastbn >= 0) {
|
||||
last = lastbn % factor;
|
||||
nb = bap[i];
|
||||
nb = fs2h32(bap[i]);
|
||||
if (nb != 0) {
|
||||
error = ext2fs_indirtrunc(ip, nlbn, fsbtodb(fs, nb),
|
||||
last, level - 1, &blkcount);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: ext2fs_lookup.c,v 1.2 1997/08/04 09:11:00 bouyer Exp $ */
|
||||
/* $NetBSD: ext2fs_lookup.c,v 1.3 1997/10/09 15:42:51 bouyer Exp $ */
|
||||
|
||||
/*
|
||||
* Modified for NetBSD 1.2E
|
||||
@ -94,8 +94,8 @@ ext2fs_dirconv2ffs( e2dir, ffsdir)
|
||||
struct dirent *ffsdir;
|
||||
{
|
||||
bzero(ffsdir, sizeof(struct dirent));
|
||||
ffsdir->d_fileno = e2dir->e2d_ino;
|
||||
ffsdir->d_namlen = e2dir->e2d_namlen;
|
||||
ffsdir->d_fileno = fs2h32(e2dir->e2d_ino);
|
||||
ffsdir->d_namlen = fs2h16(e2dir->e2d_namlen);
|
||||
|
||||
ffsdir->d_type = DT_UNKNOWN; /* don't know more here */
|
||||
#ifdef DIAGNOSTIC
|
||||
@ -103,7 +103,8 @@ ext2fs_dirconv2ffs( e2dir, ffsdir)
|
||||
* XXX Rigth now this can't happen, but if one day
|
||||
* MAXNAMLEN != E2FS_MAXNAMLEN we should handle this more gracefully !
|
||||
*/
|
||||
if (e2dir->e2d_namlen > MAXNAMLEN) panic("ext2fs: e2dir->e2d_namlen\n");
|
||||
if (fs2h16(e2dir->e2d_namlen) > MAXNAMLEN)
|
||||
panic("ext2fs: e2dir->e2d_namlen\n");
|
||||
#endif
|
||||
strncpy(ffsdir->d_name, e2dir->e2d_name, ffsdir->d_namlen);
|
||||
|
||||
@ -150,6 +151,7 @@ ext2fs_readdir(v)
|
||||
off_t off = uio->uio_offset;
|
||||
u_long *cookies = ap->a_cookies;
|
||||
int ncookies = ap->a_ncookies;
|
||||
int e2d_reclen;
|
||||
|
||||
e2fs_count = uio->uio_resid;
|
||||
/* Make sure we don't return partial entries. */
|
||||
@ -172,7 +174,8 @@ ext2fs_readdir(v)
|
||||
readcnt = e2fs_count - auio.uio_resid;
|
||||
for (dp = (struct ext2fs_direct *)dirbuf;
|
||||
(char *)dp < (char *)dirbuf + readcnt; ) {
|
||||
if (dp->e2d_reclen <= 0) {
|
||||
e2d_reclen = fs2h16(dp->e2d_reclen);
|
||||
if (e2d_reclen == 0) {
|
||||
error = EIO;
|
||||
break;
|
||||
}
|
||||
@ -183,7 +186,7 @@ ext2fs_readdir(v)
|
||||
if ((error = uiomove((caddr_t)&dstd, dstd.d_reclen, uio)) != 0) {
|
||||
break;
|
||||
}
|
||||
off = off + dp->e2d_reclen;
|
||||
off = off + e2d_reclen;
|
||||
if (cookies != NULL) {
|
||||
*cookies++ = off;
|
||||
if (--ncookies <= 0){
|
||||
@ -191,7 +194,7 @@ ext2fs_readdir(v)
|
||||
}
|
||||
}
|
||||
/* advance dp */
|
||||
dp = (struct ext2fs_direct *) ((char *)dp + dp->e2d_reclen);
|
||||
dp = (struct ext2fs_direct *) ((char *)dp + e2d_reclen);
|
||||
}
|
||||
/* we need to correct uio_offset */
|
||||
uio->uio_offset = off;
|
||||
@ -426,15 +429,15 @@ searchloop:
|
||||
* compaction is viable.
|
||||
*/
|
||||
if (slotstatus != FOUND) {
|
||||
int size = ep->e2d_reclen;
|
||||
int size = fs2h16(ep->e2d_reclen);
|
||||
|
||||
if (ep->e2d_ino != 0)
|
||||
size -= EXT2FS_DIRSIZ(ep->e2d_namlen);
|
||||
size -= EXT2FS_DIRSIZ(fs2h16(ep->e2d_namlen));
|
||||
if (size > 0) {
|
||||
if (size >= slotneeded) {
|
||||
slotstatus = FOUND;
|
||||
slotoffset = dp->i_offset;
|
||||
slotsize = ep->e2d_reclen;
|
||||
slotsize = fs2h16(ep->e2d_reclen);
|
||||
} else if (slotstatus == NONE) {
|
||||
slotfreespace += size;
|
||||
if (slotoffset == -1)
|
||||
@ -442,7 +445,7 @@ searchloop:
|
||||
if (slotfreespace >= slotneeded) {
|
||||
slotstatus = COMPACT;
|
||||
slotsize = dp->i_offset +
|
||||
ep->e2d_reclen - slotoffset;
|
||||
fs2h16(ep->e2d_reclen) - slotoffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -452,7 +455,7 @@ searchloop:
|
||||
* Check for a name match.
|
||||
*/
|
||||
if (ep->e2d_ino) {
|
||||
namlen = ep->e2d_namlen;
|
||||
namlen = fs2h16(ep->e2d_namlen);
|
||||
if (namlen == cnp->cn_namelen &&
|
||||
!bcmp(cnp->cn_nameptr, ep->e2d_name,
|
||||
(unsigned)namlen)) {
|
||||
@ -461,15 +464,15 @@ searchloop:
|
||||
* reclen in ndp->ni_ufs area, and release
|
||||
* directory buffer.
|
||||
*/
|
||||
dp->i_ino = ep->e2d_ino;
|
||||
dp->i_reclen = ep->e2d_reclen;
|
||||
dp->i_ino = fs2h32(ep->e2d_ino);
|
||||
dp->i_reclen = fs2h16(ep->e2d_reclen);
|
||||
brelse(bp);
|
||||
goto found;
|
||||
}
|
||||
}
|
||||
prevoff = dp->i_offset;
|
||||
dp->i_offset += ep->e2d_reclen;
|
||||
entryoffsetinblock += ep->e2d_reclen;
|
||||
dp->i_offset += fs2h16(ep->e2d_reclen);
|
||||
entryoffsetinblock += fs2h16(ep->e2d_reclen);
|
||||
if (ep->e2d_ino)
|
||||
enduseful = dp->i_offset;
|
||||
}
|
||||
@ -556,10 +559,11 @@ found:
|
||||
* Check that directory length properly reflects presence
|
||||
* of this entry.
|
||||
*/
|
||||
if (entryoffsetinblock + EXT2FS_DIRSIZ(ep->e2d_namlen)
|
||||
if (entryoffsetinblock + EXT2FS_DIRSIZ(fs2h16(ep->e2d_namlen))
|
||||
> dp->i_e2fs_size) {
|
||||
ufs_dirbad(dp, dp->i_offset, "i_size too small");
|
||||
dp->i_e2fs_size = entryoffsetinblock+EXT2FS_DIRSIZ(ep->e2d_namlen);
|
||||
dp->i_e2fs_size = entryoffsetinblock +
|
||||
EXT2FS_DIRSIZ(fs2h16(ep->e2d_namlen));
|
||||
dp->i_flag |= IN_CHANGE | IN_UPDATE;
|
||||
}
|
||||
|
||||
@ -716,23 +720,25 @@ ext2fs_dirbadentry(dp, de, entryoffsetinblock)
|
||||
int dirblksize = VTOI(dp)->i_e2fs->e2fs_bsize;
|
||||
|
||||
char * error_msg = NULL;
|
||||
int reclen = fs2h16(de->e2d_reclen);
|
||||
int namlen = fs2h16(de->e2d_namlen);
|
||||
|
||||
if (de->e2d_reclen < EXT2FS_DIRSIZ(1)) /* e2d_namlen = 1 */
|
||||
if (reclen < EXT2FS_DIRSIZ(1)) /* e2d_namlen = 1 */
|
||||
error_msg = "rec_len is smaller than minimal";
|
||||
else if (de->e2d_reclen % 4 != 0)
|
||||
else if (reclen % 4 != 0)
|
||||
error_msg = "rec_len % 4 != 0";
|
||||
else if (de->e2d_reclen < EXT2FS_DIRSIZ(de->e2d_namlen))
|
||||
else if (reclen < EXT2FS_DIRSIZ(namlen))
|
||||
error_msg = "reclen is too small for name_len";
|
||||
else if (entryoffsetinblock + de->e2d_reclen > dirblksize)
|
||||
else if (entryoffsetinblock + reclen > dirblksize)
|
||||
error_msg = "directory entry across blocks";
|
||||
else if (de->e2d_ino > VTOI(dp)->i_e2fs->e2fs.e2fs_icount)
|
||||
else if (fs2h32(de->e2d_ino) > VTOI(dp)->i_e2fs->e2fs.e2fs_icount)
|
||||
error_msg = "inode out of bounds";
|
||||
|
||||
if (error_msg != NULL) {
|
||||
printf( "bad directory entry: %s\n"
|
||||
"offset=%d, inode=%lu, rec_len=%d, name_len=%d \n",
|
||||
error_msg, entryoffsetinblock,
|
||||
(unsigned long) de->e2d_ino, de->e2d_reclen, de->e2d_namlen);
|
||||
(unsigned long) fs2h32(de->e2d_ino), reclen, namlen);
|
||||
panic("ext2fs_dirbadentry");
|
||||
}
|
||||
return error_msg == NULL ? 0 : 1;
|
||||
@ -769,10 +775,10 @@ ext2fs_direnter(ip, dvp, cnp)
|
||||
panic("direnter: missing name");
|
||||
#endif
|
||||
dp = VTOI(dvp);
|
||||
newdir.e2d_ino = ip->i_number;
|
||||
newdir.e2d_namlen = cnp->cn_namelen;
|
||||
newdir.e2d_ino = h2fs32(ip->i_number);
|
||||
newdir.e2d_namlen = h2fs16(cnp->cn_namelen);
|
||||
bcopy(cnp->cn_nameptr, newdir.e2d_name, (unsigned)cnp->cn_namelen + 1);
|
||||
newentrysize = EXT2FS_DIRSIZ(newdir.e2d_namlen);
|
||||
newentrysize = EXT2FS_DIRSIZ(cnp->cn_namelen);
|
||||
if (dp->i_count == 0) {
|
||||
/*
|
||||
* If dp->i_count is 0, then namei could find no
|
||||
@ -783,7 +789,7 @@ ext2fs_direnter(ip, dvp, cnp)
|
||||
if (dp->i_offset & (dirblksize - 1))
|
||||
panic("ext2fs_direnter: newblk");
|
||||
auio.uio_offset = dp->i_offset;
|
||||
newdir.e2d_reclen = dirblksize;
|
||||
newdir.e2d_reclen = h2fs16(dirblksize);
|
||||
auio.uio_resid = newentrysize;
|
||||
aiov.iov_len = newentrysize;
|
||||
aiov.iov_base = (caddr_t)&newdir;
|
||||
@ -826,21 +832,21 @@ ext2fs_direnter(ip, dvp, cnp)
|
||||
* space.
|
||||
*/
|
||||
ep = (struct ext2fs_direct *)dirbuf;
|
||||
dsize = EXT2FS_DIRSIZ(ep->e2d_namlen);
|
||||
spacefree = ep->e2d_reclen - dsize;
|
||||
for (loc = ep->e2d_reclen; loc < dp->i_count; ) {
|
||||
dsize = EXT2FS_DIRSIZ(fs2h16(ep->e2d_namlen));
|
||||
spacefree = fs2h16(ep->e2d_reclen) - dsize;
|
||||
for (loc = fs2h16(ep->e2d_reclen); loc < dp->i_count; ) {
|
||||
nep = (struct ext2fs_direct *)(dirbuf + loc);
|
||||
if (ep->e2d_ino) {
|
||||
/* trim the existing slot */
|
||||
ep->e2d_reclen = dsize;
|
||||
ep->e2d_reclen = h2fs16(dsize);
|
||||
ep = (struct ext2fs_direct *)((char *)ep + dsize);
|
||||
} else {
|
||||
/* overwrite; nothing there; header is ours */
|
||||
spacefree += dsize;
|
||||
}
|
||||
dsize = EXT2FS_DIRSIZ(nep->e2d_namlen);
|
||||
spacefree += nep->e2d_reclen - dsize;
|
||||
loc += nep->e2d_reclen;
|
||||
dsize = EXT2FS_DIRSIZ(fs2h16(nep->e2d_namlen));
|
||||
spacefree += fs2h16(nep->e2d_reclen) - dsize;
|
||||
loc += fs2h16(nep->e2d_reclen);
|
||||
bcopy((caddr_t)nep, (caddr_t)ep, dsize);
|
||||
}
|
||||
/*
|
||||
@ -852,7 +858,7 @@ ext2fs_direnter(ip, dvp, cnp)
|
||||
if (spacefree + dsize < newentrysize)
|
||||
panic("ext2fs_direnter: compact1");
|
||||
#endif
|
||||
newdir.e2d_reclen = spacefree + dsize;
|
||||
newdir.e2d_reclen = h2fs16(spacefree + dsize);
|
||||
} else {
|
||||
#ifdef DIAGNOSTIC
|
||||
if (spacefree < newentrysize) {
|
||||
@ -861,8 +867,8 @@ ext2fs_direnter(ip, dvp, cnp)
|
||||
panic("ext2fs_direnter: compact2");
|
||||
}
|
||||
#endif
|
||||
newdir.e2d_reclen = spacefree;
|
||||
ep->e2d_reclen = dsize;
|
||||
newdir.e2d_reclen = h2fs16(spacefree);
|
||||
ep->e2d_reclen = h2fs16(dsize);
|
||||
ep = (struct ext2fs_direct *)((char *)ep + dsize);
|
||||
}
|
||||
bcopy((caddr_t)&newdir, (caddr_t)ep, (u_int)newentrysize);
|
||||
@ -916,7 +922,7 @@ ext2fs_dirremove(dvp, cnp)
|
||||
(char **)&ep, &bp);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
ep->e2d_reclen += dp->i_reclen;
|
||||
ep->e2d_reclen = h2fs16(fs2h16(ep->e2d_reclen) + dp->i_reclen);
|
||||
error = VOP_BWRITE(bp);
|
||||
dp->i_flag |= IN_CHANGE | IN_UPDATE;
|
||||
return (error);
|
||||
@ -940,7 +946,7 @@ ext2fs_dirrewrite(dp, ip, cnp)
|
||||
error = VOP_BLKATOFF(vdp, (off_t)dp->i_offset, (char **)&ep, &bp);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
ep->e2d_ino = ip->i_number;
|
||||
ep->e2d_ino = h2fs32(ip->i_number);
|
||||
error = VOP_BWRITE(bp);
|
||||
dp->i_flag |= IN_CHANGE | IN_UPDATE;
|
||||
return (error);
|
||||
@ -968,7 +974,7 @@ ext2fs_dirempty(ip, parentino, cred)
|
||||
|
||||
#define MINDIRSIZ (sizeof (struct ext2fs_dirtemplate) / 2)
|
||||
|
||||
for (off = 0; off < ip->i_e2fs_size; off += dp->e2d_reclen) {
|
||||
for (off = 0; off < ip->i_e2fs_size; off += fs2h16(dp->e2d_reclen)) {
|
||||
error = vn_rdwr(UIO_READ, ITOV(ip), (caddr_t)dp, MINDIRSIZ, off,
|
||||
UIO_SYSSPACE, IO_NODELOCKED, cred, &count, (struct proc *)0);
|
||||
/*
|
||||
@ -984,7 +990,7 @@ ext2fs_dirempty(ip, parentino, cred)
|
||||
if (dp->e2d_ino == 0)
|
||||
continue;
|
||||
/* accept only "." and ".." */
|
||||
namlen = dp->e2d_namlen;
|
||||
namlen = fs2h16(dp->e2d_namlen);
|
||||
if (namlen > 2)
|
||||
return (0);
|
||||
if (dp->e2d_name[0] != '.')
|
||||
@ -996,7 +1002,7 @@ ext2fs_dirempty(ip, parentino, cred)
|
||||
*/
|
||||
if (namlen == 1)
|
||||
continue;
|
||||
if (dp->e2d_name[1] == '.' && dp->e2d_ino == parentino)
|
||||
if (dp->e2d_name[1] == '.' && fs2h32(dp->e2d_ino) == parentino)
|
||||
continue;
|
||||
return (0);
|
||||
}
|
||||
@ -1016,6 +1022,7 @@ ext2fs_checkpath(source, target, cred)
|
||||
struct vnode *vp;
|
||||
int error, rootino, namlen;
|
||||
struct ext2fs_dirtemplate dirbuf;
|
||||
u_int32_t ino;
|
||||
|
||||
vp = ITOV(target);
|
||||
if (target->i_number == source->i_number) {
|
||||
@ -1037,21 +1044,22 @@ ext2fs_checkpath(source, target, cred)
|
||||
IO_NODELOCKED, cred, (int *)0, (struct proc *)0);
|
||||
if (error != 0)
|
||||
break;
|
||||
namlen = dirbuf.dotdot_namlen;
|
||||
namlen = fs2h16(dirbuf.dotdot_namlen);
|
||||
if (namlen != 2 ||
|
||||
dirbuf.dotdot_name[0] != '.' ||
|
||||
dirbuf.dotdot_name[1] != '.') {
|
||||
error = ENOTDIR;
|
||||
break;
|
||||
}
|
||||
if (dirbuf.dotdot_ino == source->i_number) {
|
||||
ino = fs2h32(dirbuf.dotdot_ino);
|
||||
if (ino == source->i_number) {
|
||||
error = EINVAL;
|
||||
break;
|
||||
}
|
||||
if (dirbuf.dotdot_ino == rootino)
|
||||
if (ino == rootino)
|
||||
break;
|
||||
vput(vp);
|
||||
error = VFS_VGET(vp->v_mount, dirbuf.dotdot_ino, &vp);
|
||||
error = VFS_VGET(vp->v_mount, ino, &vp);
|
||||
if (error != 0) {
|
||||
vp = NULL;
|
||||
break;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: ext2fs_vfsops.c,v 1.3 1997/07/17 16:56:44 bouyer Exp $ */
|
||||
/* $NetBSD: ext2fs_vfsops.c,v 1.4 1997/10/09 15:42:53 bouyer Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 Manuel Bouyer.
|
||||
@ -388,20 +388,21 @@ ext2fs_reload(mountp, cred, p)
|
||||
if (error)
|
||||
return (error);
|
||||
newfs = (struct ext2fs *)bp->b_data;
|
||||
if (newfs->e2fs_magic != E2FS_MAGIC || newfs->e2fs_rev != E2FS_REV) {
|
||||
if (fs2h16(newfs->e2fs_magic) != E2FS_MAGIC ||
|
||||
fs2h32(newfs->e2fs_rev) != E2FS_REV) {
|
||||
#ifdef DIAGNOSTIC
|
||||
printf("Wrong magic number: %x (expected %x for ext2 fs)",
|
||||
newfs->e2fs_magic, E2FS_MAGIC);
|
||||
fs2h16(newfs->e2fs_magic), E2FS_MAGIC);
|
||||
printf("or wrong revision number: %x (expected %x for ext2 fs)",
|
||||
newfs->e2fs_rev, E2FS_REV);
|
||||
fs2h32(newfs->e2fs_rev), E2FS_REV);
|
||||
#endif
|
||||
brelse(bp);
|
||||
return (EIO); /* XXX needs translation */
|
||||
}
|
||||
if (newfs->e2fs_log_bsize > 2) { /* block size = 1024|2048|4096 */
|
||||
if (fs2h32(newfs->e2fs_log_bsize) > 2) { /* block size = 1024|2048|4096 */
|
||||
#ifdef DIAGNOSTIC
|
||||
printf("wrong block size: %d (expected <=2 for ext2 fs)\n",
|
||||
newfs->e2fs_log_bsize);
|
||||
fs2h32(newfs->e2fs_log_bsize));
|
||||
#endif
|
||||
brelse(bp);
|
||||
return (EIO); /* XXX needs translation */
|
||||
@ -412,7 +413,7 @@ ext2fs_reload(mountp, cred, p)
|
||||
/*
|
||||
* copy in new superblock, and compute in-memory values
|
||||
*/
|
||||
bcopy(newfs, &fs->e2fs, SBSIZE);
|
||||
e2fs_sbload(newfs, &fs->e2fs);
|
||||
fs->e2fs_ncg = howmany(fs->e2fs.e2fs_bcount - fs->e2fs.e2fs_first_dblock,
|
||||
fs->e2fs.e2fs_bpg);
|
||||
/* XXX assume hw bsize = 512 */
|
||||
@ -435,7 +436,7 @@ ext2fs_reload(mountp, cred, p)
|
||||
fs->e2fs_bsize, NOCRED, &bp);
|
||||
if (error)
|
||||
return (error);
|
||||
bcopy(bp->b_data,
|
||||
e2fs_cgload((struct ext2_gd*)bp->b_data,
|
||||
&fs->e2fs_gd[i* fs->e2fs_bsize / sizeof(struct ext2_gd)],
|
||||
fs->e2fs_bsize);
|
||||
brelse(bp);
|
||||
@ -468,9 +469,9 @@ loop:
|
||||
vput(vp);
|
||||
return (error);
|
||||
}
|
||||
bcopy((struct ext2fs_dinode *)bp->b_data +
|
||||
e2fs_iload((struct ext2fs_dinode *)bp->b_data +
|
||||
ino_to_fsbo(fs, ip->i_number),
|
||||
&ip->i_din.e2fs_din, sizeof(struct ext2fs_dinode));
|
||||
&ip->i_din.e2fs_din);
|
||||
brelse(bp);
|
||||
vput(vp);
|
||||
if (vp->v_mount != mountp)
|
||||
@ -533,21 +534,22 @@ ext2fs_mountfs(devvp, mp, p)
|
||||
if (error)
|
||||
goto out;
|
||||
fs = (struct ext2fs *)bp->b_data;
|
||||
if (fs->e2fs_magic != E2FS_MAGIC || fs->e2fs_rev != E2FS_REV) {
|
||||
if (fs2h16(fs->e2fs_magic) != E2FS_MAGIC ||
|
||||
fs2h32(fs->e2fs_rev) != E2FS_REV) {
|
||||
#ifdef DIAGNOSTIC
|
||||
printf("Wrong magic number: %x (expected %x for ext2 fs)",
|
||||
fs->e2fs_magic, E2FS_MAGIC);
|
||||
fs2h16(fs->e2fs_magic), E2FS_MAGIC);
|
||||
printf(" or wrong revision number: %x (expected %x for ext2 fs)\n",
|
||||
fs->e2fs_rev, E2FS_REV);
|
||||
fs2h32(fs->e2fs_rev), E2FS_REV);
|
||||
#endif
|
||||
error = EINVAL; /* XXX needs translation */
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (fs->e2fs_log_bsize > 2) { /* block size = 1024|2048|4096 */
|
||||
if (fs2h32(fs->e2fs_log_bsize) > 2) { /* block size = 1024|2048|4096 */
|
||||
#ifdef DIAGNOSTIC
|
||||
printf("wrong block size: %d (expected <2 for ext2 fs)\n",
|
||||
fs->e2fs_log_bsize);
|
||||
fs2h32(fs->e2fs_log_bsize));
|
||||
#endif
|
||||
error = EINVAL; /* XXX needs translation */
|
||||
goto out;
|
||||
@ -556,7 +558,7 @@ ext2fs_mountfs(devvp, mp, p)
|
||||
ump = malloc(sizeof *ump, M_UFSMNT, M_WAITOK);
|
||||
bzero((caddr_t)ump, sizeof *ump);
|
||||
ump->um_e2fs = malloc(sizeof(struct m_ext2fs), M_UFSMNT, M_WAITOK);
|
||||
bcopy(bp->b_data, ump->um_e2fs, SBSIZE);
|
||||
e2fs_sbload((struct ext2fs*)bp->b_data, &ump->um_e2fs->e2fs);
|
||||
brelse(bp);
|
||||
bp = NULL;
|
||||
m_fs = ump->um_e2fs;
|
||||
@ -593,7 +595,7 @@ ext2fs_mountfs(devvp, mp, p)
|
||||
free(m_fs->e2fs_gd, M_UFSMNT);
|
||||
goto out;
|
||||
}
|
||||
bcopy(bp->b_data,
|
||||
e2fs_cgload((struct ext2_gd*)bp->b_data,
|
||||
&m_fs->e2fs_gd[i* m_fs->e2fs_bsize / sizeof(struct ext2_gd)],
|
||||
m_fs->e2fs_bsize);
|
||||
brelse(bp);
|
||||
@ -869,9 +871,8 @@ ext2fs_vget(mp, ino, vpp)
|
||||
*vpp = NULL;
|
||||
return (error);
|
||||
}
|
||||
bcopy(((struct ext2fs_dinode*)bp->b_data + ino_to_fsbo(fs, ino)),
|
||||
&ip->i_din, sizeof(struct ext2fs_dinode));
|
||||
|
||||
e2fs_iload((struct ext2fs_dinode*)bp->b_data + ino_to_fsbo(fs, ino),
|
||||
&ip->i_din.e2fs_din);
|
||||
brelse(bp);
|
||||
|
||||
/*
|
||||
@ -968,7 +969,7 @@ ext2fs_sbupdate(mp, waitfor)
|
||||
int error = 0;
|
||||
|
||||
bp = getblk(mp->um_devvp, SBLOCK, SBSIZE, 0, 0);
|
||||
bcopy((caddr_t)(&fs->e2fs), bp->b_data, SBSIZE);
|
||||
e2fs_sbsave(&fs->e2fs, (struct ext2fs*)bp->b_data);
|
||||
if (waitfor == MNT_WAIT)
|
||||
error = bwrite(bp);
|
||||
else
|
||||
@ -989,8 +990,8 @@ ext2fs_cgupdate(mp, waitfor)
|
||||
for (i = 0; i < fs->e2fs_ngdb; i++) {
|
||||
bp = getblk(mp->um_devvp, fsbtodb(fs, ((fs->e2fs_bsize>1024)?0:1)+i+1),
|
||||
fs->e2fs_bsize, 0, 0);
|
||||
bcopy(&fs->e2fs_gd[i* fs->e2fs_bsize / sizeof(struct ext2_gd)],
|
||||
bp->b_data, fs->e2fs_bsize);
|
||||
e2fs_cgsave(&fs->e2fs_gd[i* fs->e2fs_bsize / sizeof(struct ext2_gd)],
|
||||
(struct ext2_gd*)bp->b_data, fs->e2fs_bsize);
|
||||
if (waitfor == MNT_WAIT)
|
||||
error = bwrite(bp);
|
||||
else
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: ext2fs_vnops.c,v 1.3 1997/07/01 07:34:03 bouyer Exp $ */
|
||||
/* $NetBSD: ext2fs_vnops.c,v 1.4 1997/10/09 15:42:54 bouyer Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 Manuel Bouyer.
|
||||
@ -144,7 +144,7 @@ ext2fs_mknod(v)
|
||||
* Want to be able to use this to make badblock
|
||||
* inodes, so don't truncate the dev number.
|
||||
*/
|
||||
ip->i_din.e2fs_din.e2di_rdev = vap->va_rdev;
|
||||
ip->i_din.e2fs_din.e2di_rdev = h2fs32(vap->va_rdev);
|
||||
}
|
||||
/*
|
||||
* Remove inode so that it will be reloaded by VFS_VGET and
|
||||
@ -240,7 +240,7 @@ ext2fs_getattr(v)
|
||||
vap->va_nlink = ip->i_e2fs_nlink;
|
||||
vap->va_uid = ip->i_e2fs_uid;
|
||||
vap->va_gid = ip->i_e2fs_gid;
|
||||
vap->va_rdev = (dev_t)ip->i_din.e2fs_din.e2di_rdev;
|
||||
vap->va_rdev = (dev_t)fs2h32(ip->i_din.e2fs_din.e2di_rdev);
|
||||
vap->va_size = ip->i_e2fs_size;
|
||||
vap->va_atime.tv_sec = ip->i_e2fs_atime;
|
||||
vap->va_atime.tv_nsec = 0;
|
||||
@ -892,14 +892,14 @@ abortit:
|
||||
UIO_SYSSPACE, IO_NODELOCKED,
|
||||
tcnp->cn_cred, (int *)0, (struct proc *)0);
|
||||
if (error == 0) {
|
||||
namlen = dirbuf.dotdot_namlen;
|
||||
namlen = fs2h16(dirbuf.dotdot_namlen);
|
||||
if (namlen != 2 ||
|
||||
dirbuf.dotdot_name[0] != '.' ||
|
||||
dirbuf.dotdot_name[1] != '.') {
|
||||
ufs_dirbad(xp, (doff_t)12,
|
||||
"ext2fs_rename: mangled dir");
|
||||
} else {
|
||||
dirbuf.dotdot_ino = newparent;
|
||||
dirbuf.dotdot_ino = h2fs32(newparent);
|
||||
(void) vn_rdwr(UIO_WRITE, fvp,
|
||||
(caddr_t)&dirbuf,
|
||||
sizeof (struct dirtemplate),
|
||||
@ -941,14 +941,6 @@ out:
|
||||
return (error);
|
||||
}
|
||||
|
||||
/*
|
||||
* A virgin directory (no blushing please).
|
||||
*/
|
||||
static struct ext2fs_dirtemplate mastertemplate = {
|
||||
0, 12, 1, ".",
|
||||
0, - 12, 2, ".." /* XXX -12 should be e2fs_bsize-12 */
|
||||
};
|
||||
|
||||
/*
|
||||
* Mkdir system call
|
||||
*/
|
||||
@ -967,7 +959,7 @@ ext2fs_mkdir(v)
|
||||
register struct componentname *cnp = ap->a_cnp;
|
||||
register struct inode *ip, *dp;
|
||||
struct vnode *tvp;
|
||||
struct ext2fs_dirtemplate dirtemplate, *dtp;
|
||||
struct ext2fs_dirtemplate dirtemplate;
|
||||
struct timespec ts;
|
||||
int error, dmode;
|
||||
|
||||
@ -1011,12 +1003,15 @@ ext2fs_mkdir(v)
|
||||
goto bad;
|
||||
|
||||
/* Initialize directory with "." and ".." from static template. */
|
||||
dtp = &mastertemplate;
|
||||
dirtemplate = *dtp;
|
||||
dirtemplate.dot_ino = ip->i_number;
|
||||
dirtemplate.dotdot_ino = dp->i_number;
|
||||
/* Correct reclen of second entry */
|
||||
dirtemplate.dotdot_reclen = VTOI(dvp)->i_e2fs->e2fs_bsize - 12;
|
||||
bzero(&dirtemplate, sizeof(dirtemplate));
|
||||
dirtemplate.dot_ino = h2fs32(ip->i_number);
|
||||
dirtemplate.dot_reclen = h2fs16(12);
|
||||
dirtemplate.dot_namlen = h2fs16(1);
|
||||
dirtemplate.dot_name[0] = '.';
|
||||
dirtemplate.dotdot_ino = h2fs32(dp->i_number);
|
||||
dirtemplate.dotdot_reclen = h2fs16(VTOI(dvp)->i_e2fs->e2fs_bsize - 12);
|
||||
dirtemplate.dotdot_namlen = h2fs16(2);
|
||||
dirtemplate.dotdot_name[0] = dirtemplate.dotdot_name[1] = '.';
|
||||
error = vn_rdwr(UIO_WRITE, tvp, (caddr_t)&dirtemplate,
|
||||
sizeof (dirtemplate), (off_t)0, UIO_SYSSPACE,
|
||||
IO_NODELOCKED|IO_SYNC, cnp->cn_cred, (int *)0, (struct proc *)0);
|
||||
@ -1239,7 +1234,7 @@ ext2fs_vinit(mntp, specops, fifoops, vpp)
|
||||
case VCHR:
|
||||
case VBLK:
|
||||
vp->v_op = specops;
|
||||
if ((nvp = checkalias(vp, ip->i_din.e2fs_din.e2di_rdev, mntp))
|
||||
if ((nvp = checkalias(vp, fs2h32(ip->i_din.e2fs_din.e2di_rdev), mntp))
|
||||
!= NULL) {
|
||||
/*
|
||||
* Discard unneeded vnode, but save its inode.
|
||||
|
Loading…
Reference in New Issue
Block a user