summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>2001-09-18 00:06:22 +0000
committerArtur Grabowski <art@cvs.openbsd.org>2001-09-18 00:06:22 +0000
commitbfc583fea3340e5d99cc6bc8edf2e5ef983cc8c1 (patch)
tree15205efbf3f60bc1a4ae5566cf770009b34f22eb
parent59ce3076ca4eff18167bfea79b7ce37b22b57fa5 (diff)
More cleanups from NetBSD and a bunch of endianness fixes.
The file ext2fs_bswap.c contains some functions to aid bigendian machines.
-rw-r--r--sys/ufs/ext2fs/ext2fs.h68
-rw-r--r--sys/ufs/ext2fs/ext2fs_bswap.c125
-rw-r--r--sys/ufs/ext2fs/ext2fs_dinode.h48
3 files changed, 190 insertions, 51 deletions
diff --git a/sys/ufs/ext2fs/ext2fs.h b/sys/ufs/ext2fs/ext2fs.h
index a5d683b137d..6e97a0684ee 100644
--- a/sys/ufs/ext2fs/ext2fs.h
+++ b/sys/ufs/ext2fs/ext2fs.h
@@ -1,5 +1,5 @@
-/* $OpenBSD: ext2fs.h,v 1.4 2000/04/26 23:24:39 jasoni Exp $ */
-/* $NetBSD: ext2fs.h,v 1.1 1997/06/11 09:33:37 bouyer Exp $ */
+/* $OpenBSD: ext2fs.h,v 1.5 2001/09/18 00:06:21 art Exp $ */
+/* $NetBSD: ext2fs.h,v 1.10 2000/01/28 16:00:23 bouyer Exp $ */
/*
* Copyright (c) 1997 Manuel Bouyer.
@@ -38,6 +38,8 @@
* Modified for ext2fs by Manuel Bouyer.
*/
+#include <machine/endian.h>
+
/*
* Each disk drive contains some number of file systems.
* A file system consists of a number of cylinder groups.
@@ -57,8 +59,8 @@
#define SBSIZE 1024
#define BBOFF ((off_t)(0))
#define SBOFF ((off_t)(BBOFF + BBSIZE))
-#define BBLOCK ((daddr_t)(0))
-#define SBLOCK ((daddr_t)(BBLOCK + BBSIZE / DEV_BSIZE))
+#define BBLOCK ((ufs_daddr_t)(0))
+#define SBLOCK ((ufs_daddr_t)(BBLOCK + BBSIZE / DEV_BSIZE))
/*
* Addresses stored in inodes are capable of addressing blocks
@@ -147,18 +149,18 @@ struct ext2fs {
struct m_ext2fs {
struct ext2fs e2fs;
u_char e2fs_fsmnt[MAXMNTLEN]; /* name mounted on */
- int8_t e2fs_ronly; /* mounted read-only flag */
- int8_t e2fs_fmod; /* super block modified flag */
- int32_t e2fs_bsize; /* block size */
- int32_t e2fs_bshift; /* ``lblkno'' calc of logical blkno */
- int32_t e2fs_bmask; /* ``blkoff'' calc of blk offsets */
- int64_t e2fs_qbmask; /* ~fs_bmask - for use with quad size */
- int32_t e2fs_fsbtodb; /* fsbtodb and dbtofsb shift constant */
- int32_t e2fs_ncg; /* number of cylinder groups */
- int32_t e2fs_ngdb; /* number of group descriptor block */
- int32_t e2fs_ipb; /* number of inodes per block */
- int32_t e2fs_itpg; /* number of inode table per group */
- struct ext2_gd *e2fs_gd; /* group descripors */
+ int8_t e2fs_ronly; /* mounted read-only flag */
+ int8_t e2fs_fmod; /* super block modified flag */
+ int32_t e2fs_bsize; /* block size */
+ int32_t e2fs_bshift; /* ``lblkno'' calc of logical blkno */
+ int32_t e2fs_bmask; /* ``blkoff'' calc of blk offsets */
+ int64_t e2fs_qbmask; /* ~fs_bmask - for use with quad size */
+ int32_t e2fs_fsbtodb; /* fsbtodb and dbtofsb shift constant */
+ int32_t e2fs_ncg; /* number of cylinder groups */
+ int32_t e2fs_ngdb; /* number of group descriptor block */
+ int32_t e2fs_ipb; /* number of inodes per block */
+ int32_t e2fs_itpg; /* number of inode table per group */
+ struct ext2_gd *e2fs_gd; /* group descripors */
};
@@ -167,8 +169,8 @@ struct m_ext2fs {
* Filesystem identification
*/
#define E2FS_MAGIC 0xef53 /* the ext2fs magic number */
-#define E2FS_REV0 0 /* revision level */
-#define E2FS_REV1 1 /* revision level */
+#define E2FS_REV0 0 /* revision levels */
+#define E2FS_REV1 1 /* revision levels */
/* compatible/imcompatible features */
#define EXT2F_COMPAT_PREALLOC 0x0001
@@ -235,17 +237,27 @@ cg_has_sb(i)
}
/*
- * EXT2FS metadatas are stored in little-endian byte order. These macros
- * should aide in support for big-endian machines.
+ * EXT2FS metadatas are stored in little-endian byte order. These macros
+ * helps reading theses metadatas
*/
-#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));
+
+#define h2fs16(x) htole16(x)
+#define h2fs32(x) htole32(x)
+#define fs2h16(x) letoh16(x)
+#define fs2h32(x) letoh32(x)
+#if BYTE_ORDER == LITTLE_ENDIAN
+#define e2fs_sbload(old, new) memcpy((new), (old), SBSIZE);
+#define e2fs_cgload(old, new, size) memcpy((new), (old), (size));
+#define e2fs_sbsave(old, new) memcpy((new), (old), SBSIZE);
+#define e2fs_cgsave(old, new, size) memcpy((new), (old), (size));
+#else
+void e2fs_sb_bswap __P((struct ext2fs *, struct ext2fs *));
+void e2fs_cg_bswap __P((struct ext2_gd *, struct ext2_gd *, int));
+#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.
diff --git a/sys/ufs/ext2fs/ext2fs_bswap.c b/sys/ufs/ext2fs/ext2fs_bswap.c
new file mode 100644
index 00000000000..201de733e8a
--- /dev/null
+++ b/sys/ufs/ext2fs/ext2fs_bswap.c
@@ -0,0 +1,125 @@
+/* $OpenBSD: ext2fs_bswap.c,v 1.1 2001/09/18 00:06:21 art Exp $ */
+/* $NetBSD: ext2fs_bswap.c,v 1.6 2000/07/24 00:23:10 mycroft 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 AUTHOR ``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 AUTHOR 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>
+
+#if !defined(_KERNEL)
+#include <string.h>
+#endif
+
+/* 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 = swap32(old->e2fs_icount);
+ new->e2fs_bcount = swap32(old->e2fs_bcount);
+ new->e2fs_rbcount = swap32(old->e2fs_rbcount);
+ new->e2fs_fbcount = swap32(old->e2fs_fbcount);
+ new->e2fs_ficount = swap32(old->e2fs_ficount);
+ new->e2fs_first_dblock = swap32(old->e2fs_first_dblock);
+ new->e2fs_log_bsize = swap32(old->e2fs_log_bsize);
+ new->e2fs_fsize = swap32(old->e2fs_fsize);
+ new->e2fs_bpg = swap32(old->e2fs_bpg);
+ new->e2fs_fpg = swap32(old->e2fs_fpg);
+ new->e2fs_ipg = swap32(old->e2fs_ipg);
+ new->e2fs_mtime = swap32(old->e2fs_mtime);
+ new->e2fs_wtime = swap32(old->e2fs_wtime);
+ new->e2fs_mnt_count = swap16(old->e2fs_mnt_count);
+ new->e2fs_max_mnt_count = swap16(old->e2fs_max_mnt_count);
+ new->e2fs_magic = swap16(old->e2fs_magic);
+ new->e2fs_state = swap16(old->e2fs_state);
+ new->e2fs_beh = swap16(old->e2fs_beh);
+ new->e2fs_minrev = swap16(old->e2fs_minrev);
+ new->e2fs_lastfsck = swap32(old->e2fs_lastfsck);
+ new->e2fs_fsckintv = swap32(old->e2fs_fsckintv);
+ new->e2fs_creator = swap32(old->e2fs_creator);
+ new->e2fs_rev = swap32(old->e2fs_rev);
+ new->e2fs_ruid = swap16(old->e2fs_ruid);
+ new->e2fs_rgid = swap16(old->e2fs_rgid);
+ new->e2fs_first_ino = swap32(old->e2fs_first_ino);
+ new->e2fs_inode_size = swap16(old->e2fs_inode_size);
+ new->e2fs_block_group_nr = swap16(old->e2fs_block_group_nr);
+ new->e2fs_features_compat = swap32(old->e2fs_features_compat);
+ new->e2fs_features_incompat = swap32(old->e2fs_features_incompat);
+ new->e2fs_features_rocompat = swap32(old->e2fs_features_rocompat);
+ new->e2fs_algo = swap32(old->e2fs_algo);
+}
+
+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 = swap32(old[i].ext2bgd_b_bitmap);
+ new[i].ext2bgd_i_bitmap = swap32(old[i].ext2bgd_i_bitmap);
+ new[i].ext2bgd_i_tables = swap32(old[i].ext2bgd_i_tables);
+ new[i].ext2bgd_nbfree = swap16(old[i].ext2bgd_nbfree);
+ new[i].ext2bgd_nifree = swap16(old[i].ext2bgd_nifree);
+ new[i].ext2bgd_ndirs = swap16(old[i].ext2bgd_ndirs);
+ }
+}
+
+void
+e2fs_i_bswap(old, new)
+ struct ext2fs_dinode *old, *new;
+{
+ new->e2di_mode = swap16(old->e2di_mode);
+ new->e2di_uid = swap16(old->e2di_uid);
+ new->e2di_gid = swap16(old->e2di_gid);
+ new->e2di_nlink = swap16(old->e2di_nlink);
+ new->e2di_size = swap32(old->e2di_size);
+ new->e2di_atime = swap32(old->e2di_atime);
+ new->e2di_ctime = swap32(old->e2di_ctime);
+ new->e2di_mtime = swap32(old->e2di_mtime);
+ new->e2di_dtime = swap32(old->e2di_dtime);
+ new->e2di_nblock = swap32(old->e2di_nblock);
+ new->e2di_flags = swap32(old->e2di_flags);
+ new->e2di_gen = swap32(old->e2di_gen);
+ new->e2di_facl = swap32(old->e2di_facl);
+ new->e2di_dacl = swap32(old->e2di_dacl);
+ new->e2di_faddr = swap32(old->e2di_faddr);
+ memcpy(&new->e2di_blocks[0], &old->e2di_blocks[0],
+ (NDADDR+NIADDR) * sizeof(int));
+}
+#endif
diff --git a/sys/ufs/ext2fs/ext2fs_dinode.h b/sys/ufs/ext2fs/ext2fs_dinode.h
index fe5c280f497..e18fb0fb10b 100644
--- a/sys/ufs/ext2fs/ext2fs_dinode.h
+++ b/sys/ufs/ext2fs/ext2fs_dinode.h
@@ -1,5 +1,4 @@
-/* $OpenBSD: ext2fs_dinode.h,v 1.4 2000/04/26 23:24:40 jasoni Exp $ */
-/* $NetBSD: ext2fs_dinode.h,v 1.1 1997/06/11 09:33:48 bouyer Exp $ */
+/* $NetBSD: ext2fs_dinode.h,v 1.6 2000/01/26 16:21:33 bouyer Exp $ */
/*
* Copyright (c) 1997 Manuel Bouyer.
@@ -15,17 +14,17 @@
* 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.
+ * 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.
+ * 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:
+ * 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.
+ * 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
@@ -76,16 +75,16 @@ struct ext2fs_dinode {
u_int32_t e2di_dtime; /* 20: Deletion time */
u_int16_t e2di_gid; /* 24: Owner GID */
u_int16_t e2di_nlink; /* 26: File link count */
- u_int32_t e2di_nblock;/* 28: Blocks count */
+ u_int32_t e2di_nblock; /* 28: Blocks count */
u_int32_t e2di_flags; /* 32: Status flags (chflags) */
u_int32_t e2di_linux_reserved1; /* 36 */
u_int32_t e2di_blocks[NDADDR+NIADDR]; /* 40: disk blocks */
- u_int32_t e2di_gen; /* 100: generation number (file version) */
- u_int32_t e2di_facl; /* 104: file ACL (not implemented) */
- u_int32_t e2di_dacl; /* 108: dir ACL (not implemented) */
- u_int32_t e2di_faddr; /* 112: fragment address */
- u_int8_t e2di_nfrag; /* 116: fragment number */
- u_int8_t e2di_fsize; /* 117: fragment size */
+ u_int32_t e2di_gen; /* 100: generation number */
+ u_int32_t e2di_facl; /* 104: file ACL (not implemented) */
+ u_int32_t e2di_dacl; /* 108: dir ACL (not implemented) */
+ u_int32_t e2di_faddr; /* 112: fragment address */
+ u_int8_t e2di_nfrag; /* 116: fragment number */
+ u_int8_t e2di_fsize; /* 117: fragment size */
u_int16_t e2di_linux_reserved2; /* 118 */
u_int32_t e2di_linux_reserved3[2]; /* 120 */
};
@@ -117,7 +116,7 @@ struct ext2fs_dinode {
#define EXT2_UNRM 0x00000002 /* Undelete */
#define EXT2_COMPR 0x00000004 /* Compress file */
#define EXT2_SYNC 0x00000008 /* Synchronous updates */
-#define EXT2_IMMUTABLE 0x00000010 /* Immutable file */
+#define EXT2_IMMUTABLE 0x00000010 /* Immutable file */
#define EXT2_APPEND 0x00000020 /* writes to file may only append */
#define EXT2_NODUMP 0x00000040 /* do not dump file */
@@ -133,11 +132,14 @@ struct ext2fs_dinode {
*/
#define e2di_rdev e2di_blocks[0]
-#define e2di_shortlink e2di_blocks
+#define e2di_shortlink e2di_blocks
-/*
- * e2fs needs byte swapping on big-endian systems. Use macros here to
- * aide in big-endian support.
- */
-#define e2fs_iload(old, new) bcopy((old),(new),sizeof(struct ext2fs_dinode))
-#define e2fs_isave(old, new) bcopy((old),(new),sizeof(struct ext2fs_dinode))
+/* e2fs needs byte swapping on big-endian systems */
+#if BYTE_ORDER == LITTLE_ENDIAN
+# define e2fs_iload(old, new) memcpy((new),(old),sizeof(struct ext2fs_dinode))
+# define e2fs_isave(old, new) memcpy((new),(old),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