summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorMartin Pelikan <pelikan@cvs.openbsd.org>2014-07-13 16:44:21 +0000
committerMartin Pelikan <pelikan@cvs.openbsd.org>2014-07-13 16:44:21 +0000
commitfac5e312f958cb4168ececee6eee14f31d82d3cf (patch)
tree884132e37ed30c9f2e7f736a1a83f48f8fd68cfc /sbin
parent5e65892f6338d56618a656d83106f948e9497732 (diff)
kill fs2hXX/h2fsXX macros with letohXX/htoleXX
The reason being that ext2 structures are little-endian but JBD2 journal is big-endian. Don't confuse readers by talking about "file system endian". While here, nuke the copy of bswap.c and link it against the kernel's like fsck_ext2fs has done, for better maintainability. ok guenther
Diffstat (limited to 'sbin')
-rw-r--r--sbin/newfs_ext2fs/Makefile3
-rw-r--r--sbin/newfs_ext2fs/ext2fs_bswap.c125
-rw-r--r--sbin/newfs_ext2fs/mke2fs.c22
3 files changed, 13 insertions, 137 deletions
diff --git a/sbin/newfs_ext2fs/Makefile b/sbin/newfs_ext2fs/Makefile
index 15017598ae2..bc0fc94ba69 100644
--- a/sbin/newfs_ext2fs/Makefile
+++ b/sbin/newfs_ext2fs/Makefile
@@ -1,8 +1,9 @@
-# $OpenBSD: Makefile,v 1.2 2010/02/17 19:26:48 otto Exp $
+# $OpenBSD: Makefile,v 1.3 2014/07/13 16:44:20 pelikan Exp $
PROG= newfs_ext2fs
SRCS= newfs_ext2fs.c mke2fs.c ext2fs_bswap.c
MAN= newfs_ext2fs.8
+.PATH: ${.CURDIR}/../../sys/ufs/ext2fs
DPADD+= ${LIBUTIL}
LDADD+= -lutil
diff --git a/sbin/newfs_ext2fs/ext2fs_bswap.c b/sbin/newfs_ext2fs/ext2fs_bswap.c
deleted file mode 100644
index 4ca700a6c54..00000000000
--- a/sbin/newfs_ext2fs/ext2fs_bswap.c
+++ /dev/null
@@ -1,125 +0,0 @@
-/* $OpenBSD: ext2fs_bswap.c,v 1.3 2014/07/13 13:37:22 pelikan 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>
-#if defined(_KERNEL)
-#include <sys/systm.h>
-#endif
-#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(struct ext2fs *old, struct ext2fs *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_log_fsize = swap32(old->e2fs_log_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(struct ext2_gd *old, struct ext2_gd *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(struct ext2fs_dinode *old, struct ext2fs_dinode *new)
-{
- new->e2di_mode = swap16(old->e2di_mode);
- new->e2di_uid_low = swap16(old->e2di_uid_low);
- new->e2di_gid_low = swap16(old->e2di_gid_low);
- new->e2di_uid_high = swap16(old->e2di_uid_high);
- new->e2di_gid_high = swap16(old->e2di_gid_high);
- 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_size_hi = swap32(old->e2di_size_hi);
- new->e2di_faddr = swap32(old->e2di_faddr);
- memcpy(&new->e2di_blocks[0], &old->e2di_blocks[0],
- (NDADDR+NIADDR) * sizeof(int));
-}
-#endif
diff --git a/sbin/newfs_ext2fs/mke2fs.c b/sbin/newfs_ext2fs/mke2fs.c
index d57f1d551e5..db8deae935e 100644
--- a/sbin/newfs_ext2fs/mke2fs.c
+++ b/sbin/newfs_ext2fs/mke2fs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mke2fs.c,v 1.9 2014/07/13 13:37:22 pelikan Exp $ */
+/* $OpenBSD: mke2fs.c,v 1.10 2014/07/13 16:44:20 pelikan Exp $ */
/* $NetBSD: mke2fs.c,v 1.13 2009/10/19 18:41:08 bouyer Exp $ */
/*-
@@ -747,8 +747,8 @@ initcg(uint cylno)
for (i = 0; i < sblock.e2fs_itpg; i++) {
for (j = 0; j < sblock.e2fs_ipb; j++) {
dp = (struct ext2fs_dinode *)(buf + inodesize * j);
- /* h2fs32() just for consistency */
- dp->e2di_gen = h2fs32(arc4random());
+ /* If there is some bias in arc4random(), keep it. */
+ dp->e2di_gen = htole32(arc4random());
}
wtfs(fsbtodb(&sblock, gd[cylno].ext2bgd_i_tables + i),
sblock.e2fs_bsize, buf);
@@ -1020,8 +1020,8 @@ copy_dir(struct ext2fs_direct *dir, struct ext2fs_direct *dbuf)
{
memcpy(dbuf, dir, EXT2FS_DIRSIZ(dir->e2d_namlen));
- dbuf->e2d_ino = h2fs32(dir->e2d_ino);
- dbuf->e2d_reclen = h2fs16(dir->e2d_reclen);
+ dbuf->e2d_ino = htole32(dir->e2d_ino);
+ dbuf->e2d_reclen = htole16(dir->e2d_reclen);
}
/*
@@ -1176,7 +1176,7 @@ init_resizeino(const struct timeval *tv)
"group descriptors (%u) for resize inode",
__func__, sblock.e2fs.e2fs_reserved_ngdb);
dindir_block[i] =
- h2fs32(cgbase(&sblock, 0) + NBLOCK_SUPERBLOCK + i);
+ htole32(cgbase(&sblock, 0) + NBLOCK_SUPERBLOCK + i);
/*
* Setup block entries in the second dindirect blocks
@@ -1197,7 +1197,7 @@ init_resizeino(const struct timeval *tv)
* These blocks are already reserved in
* initcg() so no need to use alloc() here.
*/
- reserved_gdb[n++] = h2fs32(cgbase(&sblock, cylno) +
+ reserved_gdb[n++] = htole32(cgbase(&sblock, cylno) +
NBLOCK_SUPERBLOCK + i);
nblock += fsbtodb(&sblock, 1);
}
@@ -1205,7 +1205,7 @@ init_resizeino(const struct timeval *tv)
reserved_gdb[n] = 0;
/* write group descriptor block as the second dindirect refs */
- wtfs(fsbtodb(&sblock, fs2h32(dindir_block[i])),
+ wtfs(fsbtodb(&sblock, letoh32(dindir_block[i])),
sblock.e2fs_bsize, reserved_gdb);
nblock += fsbtodb(&sblock, 1);
}
@@ -1351,10 +1351,10 @@ iput(struct ext2fs_dinode *ip, ino_t ino)
/* e2fs_i_bswap() doesn't swap e2di_blocks addrs */
if ((ip->e2di_mode & EXT2_IFMT) != EXT2_IFLNK) {
for (i = 0; i < NDADDR + NIADDR; i++)
- dp->e2di_blocks[i] = h2fs32(ip->e2di_blocks[i]);
+ dp->e2di_blocks[i] = htole32(ip->e2di_blocks[i]);
}
- /* h2fs32() just for consistency */
- dp->e2di_gen = h2fs32(arc4random());
+ /* If there is some bias in arc4random(), keep it. */
+ dp->e2di_gen = htole32(arc4random());
wtfs(d, sblock.e2fs_bsize, bp);
free(bp);