From f7dbefaaf3bce775a01372ab00ecf1ed02bf290a Mon Sep 17 00:00:00 2001 From: pelikan Date: Sun, 13 Jul 2014 16:59:35 +0000 Subject: [PATCH] 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". Some KNF while there. ok guenther --- sys/ufs/ext2fs/ext2fs.h | 11 ++-- sys/ufs/ext2fs/ext2fs_alloc.c | 21 ++++---- sys/ufs/ext2fs/ext2fs_balloc.c | 16 +++--- sys/ufs/ext2fs/ext2fs_bmap.c | 16 +++--- sys/ufs/ext2fs/ext2fs_inode.c | 10 ++-- sys/ufs/ext2fs/ext2fs_lookup.c | 97 ++++++++++++++++------------------ sys/ufs/ext2fs/ext2fs_subr.c | 4 +- sys/ufs/ext2fs/ext2fs_vnops.c | 16 +++--- 8 files changed, 92 insertions(+), 99 deletions(-) diff --git a/sys/ufs/ext2fs/ext2fs.h b/sys/ufs/ext2fs/ext2fs.h index cfe3dd93eac..cbf68e25f98 100644 --- a/sys/ufs/ext2fs/ext2fs.h +++ b/sys/ufs/ext2fs/ext2fs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ext2fs.h,v 1.19 2014/07/13 13:28:26 pelikan Exp $ */ +/* $OpenBSD: ext2fs.h,v 1.20 2014/07/13 16:59:35 pelikan Exp $ */ /* $NetBSD: ext2fs.h,v 1.10 2000/01/28 16:00:23 bouyer Exp $ */ /* @@ -265,14 +265,9 @@ cg_has_sb(i) } /* - * EXT2FS metadatas are stored in little-endian byte order. These macros - * helps reading theses metadatas + * Ext2 metadata is stored in little-endian byte order. + * JBD2 journal used in ext3 and ext4 is big-endian! */ - -#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)); diff --git a/sys/ufs/ext2fs/ext2fs_alloc.c b/sys/ufs/ext2fs/ext2fs_alloc.c index 1fea6705444..0a77b5e45a1 100644 --- a/sys/ufs/ext2fs/ext2fs_alloc.c +++ b/sys/ufs/ext2fs/ext2fs_alloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ext2fs_alloc.c,v 1.31 2014/05/27 14:31:24 krw Exp $ */ +/* $OpenBSD: ext2fs_alloc.c,v 1.32 2014/07/13 16:59:35 pelikan Exp $ */ /* $NetBSD: ext2fs_alloc.c,v 1.10 2001/07/05 08:38:27 toshii Exp $ */ /* @@ -163,7 +163,8 @@ ext2fs_inode_alloc(struct inode *pip, mode_t mode, struct ucred *cred, ip = VTOI(*vpp); if (ip->i_e2fs_mode && ip->i_e2fs_nlink != 0) { printf("mode = 0%o, nlinks %u, inum = %u, fs = %s\n", - ip->i_e2fs_mode, ip->i_e2fs_nlink, ip->i_number, fs->e2fs_fsmnt); + ip->i_e2fs_mode, ip->i_e2fs_nlink, ip->i_number, + fs->e2fs_fsmnt); panic("ext2fs_valloc: dup alloc"); } @@ -242,7 +243,7 @@ ext2fs_blkpref(struct inode *ip, int32_t lbn, int indx, int32_t *bap) if (bap) { for (i = indx; i >= 0 ; i--) { if (bap[i]) { - return fs2h32(bap[i]) + 1; + return letoh32(bap[i]) + 1; } } } @@ -323,8 +324,7 @@ ext2fs_alloccg(struct inode *ip, int cg, int32_t bpref, int size) if (fs->e2fs_gd[cg].ext2bgd_nbfree == 0) return (0); error = bread(ip->i_devvp, fsbtodb(fs, - fs->e2fs_gd[cg].ext2bgd_b_bitmap), - (int)fs->e2fs_bsize, &bp); + fs->e2fs_gd[cg].ext2bgd_b_bitmap), (int)fs->e2fs_bsize, &bp); if (error || fs->e2fs_gd[cg].ext2bgd_nbfree == 0) { brelse(bp); return (0); @@ -408,8 +408,7 @@ ext2fs_nodealloccg(struct inode *ip, int cg, int32_t ipref, int mode) if (fs->e2fs_gd[cg].ext2bgd_nifree == 0) return (0); error = bread(ip->i_devvp, fsbtodb(fs, - fs->e2fs_gd[cg].ext2bgd_i_bitmap), - (int)fs->e2fs_bsize, &bp); + fs->e2fs_gd[cg].ext2bgd_i_bitmap), (int)fs->e2fs_bsize, &bp); if (error) { brelse(bp); return (0); @@ -516,11 +515,11 @@ ext2fs_inode_free(struct inode *pip, ufsino_t ino, mode_t mode) fs = pip->i_e2fs; if ((u_int)ino > fs->e2fs.e2fs_icount || (u_int)ino < EXT2_FIRSTINO) panic("ifree: range: dev = 0x%x, ino = %d, fs = %s", - pip->i_dev, ino, fs->e2fs_fsmnt); + pip->i_dev, ino, fs->e2fs_fsmnt); cg = ino_to_cg(fs, ino); error = bread(pip->i_devvp, - fsbtodb(fs, fs->e2fs_gd[cg].ext2bgd_i_bitmap), - (int)fs->e2fs_bsize, &bp); + fsbtodb(fs, fs->e2fs_gd[cg].ext2bgd_i_bitmap), + (int)fs->e2fs_bsize, &bp); if (error) { brelse(bp); return (0); @@ -529,7 +528,7 @@ ext2fs_inode_free(struct inode *pip, ufsino_t ino, mode_t mode) ino = (ino - 1) % fs->e2fs.e2fs_ipg; if (isclr(ibp, ino)) { printf("dev = 0x%x, ino = %d, fs = %s\n", - pip->i_dev, ino, fs->e2fs_fsmnt); + pip->i_dev, ino, fs->e2fs_fsmnt); if (fs->e2fs_ronly == 0) panic("ifree: freeing free inode"); } diff --git a/sys/ufs/ext2fs/ext2fs_balloc.c b/sys/ufs/ext2fs/ext2fs_balloc.c index ed372437c57..dcd6cab908f 100644 --- a/sys/ufs/ext2fs/ext2fs_balloc.c +++ b/sys/ufs/ext2fs/ext2fs_balloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ext2fs_balloc.c,v 1.21 2014/07/08 17:19:26 deraadt Exp $ */ +/* $OpenBSD: ext2fs_balloc.c,v 1.22 2014/07/13 16:59:35 pelikan Exp $ */ /* $NetBSD: ext2fs_balloc.c,v 1.10 2001/07/04 21:16:01 chs Exp $ */ /* @@ -78,7 +78,7 @@ ext2fs_buf_alloc(struct inode *ip, daddr_t bn, int size, struct ucred *cred, * The first NDADDR blocks are direct blocks */ if (bn < NDADDR) { - nb = fs2h32(ip->i_e2fs_blocks[bn]); + nb = letoh32(ip->i_e2fs_blocks[bn]); if (nb != 0) { error = bread(vp, bn, fs->e2fs_bsize, &bp); if (error) { @@ -99,7 +99,7 @@ ext2fs_buf_alloc(struct inode *ip, daddr_t bn, int size, struct ucred *cred, return (error); ip->i_e2fs_last_lblk = lbn; ip->i_e2fs_last_blk = newb; - ip->i_e2fs_blocks[bn] = h2fs32(newb); + ip->i_e2fs_blocks[bn] = htole32(newb); ip->i_flag |= IN_CHANGE | IN_UPDATE; bp = getblk(vp, bn, fs->e2fs_bsize, 0, 0); bp->b_blkno = fsbtodb(fs, newb); @@ -122,7 +122,7 @@ ext2fs_buf_alloc(struct inode *ip, daddr_t bn, int size, struct ucred *cred, * Fetch the first indirect block allocating if necessary. */ --num; - nb = fs2h32(ip->i_e2fs_blocks[NDADDR + indirs[0].in_off]); + nb = letoh32(ip->i_e2fs_blocks[NDADDR + indirs[0].in_off]); allocib = NULL; allocblk = allociblk; if (nb == 0) { @@ -144,7 +144,7 @@ ext2fs_buf_alloc(struct inode *ip, daddr_t bn, int size, struct ucred *cred, goto fail; unwindidx = 0; allocib = &ip->i_e2fs_blocks[NDADDR + indirs[0].in_off]; - *allocib = h2fs32(newb); + *allocib = htole32(newb); ip->i_flag |= IN_CHANGE | IN_UPDATE; } /* @@ -157,7 +157,7 @@ ext2fs_buf_alloc(struct inode *ip, daddr_t bn, int size, struct ucred *cred, goto fail; } bap = (int32_t *)bp->b_data; - nb = fs2h32(bap[indirs[i].in_off]); + nb = letoh32(bap[indirs[i].in_off]); if (i == num) break; i++; @@ -187,7 +187,7 @@ ext2fs_buf_alloc(struct inode *ip, daddr_t bn, int size, struct ucred *cred, } if (unwindidx < 0) unwindidx = i - 1; - bap[indirs[i - 1].in_off] = h2fs32(nb); + bap[indirs[i - 1].in_off] = htole32(nb); /* * If required, write synchronously, otherwise use * delayed write. @@ -212,7 +212,7 @@ ext2fs_buf_alloc(struct inode *ip, daddr_t bn, int size, struct ucred *cred, *allocblk++ = nb; ip->i_e2fs_last_lblk = lbn; ip->i_e2fs_last_blk = newb; - bap[indirs[num].in_off] = h2fs32(nb); + bap[indirs[num].in_off] = htole32(nb); /* * If required, write synchronously, otherwise use * delayed write. diff --git a/sys/ufs/ext2fs/ext2fs_bmap.c b/sys/ufs/ext2fs/ext2fs_bmap.c index 66f73e3e98d..364a030bd3b 100644 --- a/sys/ufs/ext2fs/ext2fs_bmap.c +++ b/sys/ufs/ext2fs/ext2fs_bmap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ext2fs_bmap.c,v 1.23 2014/07/13 13:28:26 pelikan Exp $ */ +/* $OpenBSD: ext2fs_bmap.c,v 1.24 2014/07/13 16:59:35 pelikan Exp $ */ /* $NetBSD: ext2fs_bmap.c,v 1.5 2000/03/30 12:41:11 augustss Exp $ */ /* @@ -173,20 +173,22 @@ ext2fs_bmaparray(struct vnode *vp, daddr_t bn, daddr_t *bnp, num = *nump; if (num == 0) { - *bnp = blkptrtodb(ump, fs2h32(ip->i_e2fs_blocks[bn])); + *bnp = blkptrtodb(ump, letoh32(ip->i_e2fs_blocks[bn])); if (*bnp == 0) *bnp = -1; else if (runp) for (++bn; bn < NDADDR && *runp < maxrun && - is_sequential(ump, fs2h32(ip->i_e2fs_blocks[bn - 1]), - fs2h32(ip->i_e2fs_blocks[bn])); - ++bn, ++*runp); + is_sequential(ump, + letoh32(ip->i_e2fs_blocks[bn - 1]), + letoh32(ip->i_e2fs_blocks[bn])); + ++bn, ++*runp) + /* nothing */; return (0); } /* Get disk address out of indirect block array */ - daddr = fs2h32(ip->i_e2fs_blocks[NDADDR + xap->in_off]); + daddr = letoh32(ip->i_e2fs_blocks[NDADDR + xap->in_off]); devvp = VFSTOUFS(vp->v_mount)->um_devvp; @@ -234,7 +236,7 @@ ext2fs_bmaparray(struct vnode *vp, daddr_t bn, daddr_t *bnp, } } - daddr = fs2h32(((int32_t *)bp->b_data)[xap->in_off]); + daddr = letoh32(((int32_t *)bp->b_data)[xap->in_off]); if (num == 1 && daddr && runp) for (bn = xap->in_off + 1; bn < MNINDIR(ump) && *runp < maxrun && diff --git a/sys/ufs/ext2fs/ext2fs_inode.c b/sys/ufs/ext2fs/ext2fs_inode.c index a008d43d806..6f883499d29 100644 --- a/sys/ufs/ext2fs/ext2fs_inode.c +++ b/sys/ufs/ext2fs/ext2fs_inode.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ext2fs_inode.c,v 1.53 2014/07/13 15:07:01 pelikan Exp $ */ +/* $OpenBSD: ext2fs_inode.c,v 1.54 2014/07/13 16:59:35 pelikan Exp $ */ /* $NetBSD: ext2fs_inode.c,v 1.24 2001/06/19 12:59:18 wiz Exp $ */ /* @@ -354,7 +354,7 @@ ext2fs_truncate(struct inode *oip, off_t length, int flags, struct ucred *cred) 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 = fs2h32(oip->i_e2fs_blocks[NDADDR + level]); + bn = letoh32(oip->i_e2fs_blocks[NDADDR + level]); if (bn != 0) { error = ext2fs_indirtrunc(oip, indir_lbn[level], fsbtodb(fs, bn), lastiblock[level], level, &count); @@ -375,7 +375,7 @@ ext2fs_truncate(struct inode *oip, off_t length, int flags, struct ucred *cred) * All whole direct blocks or frags. */ for (i = NDADDR - 1; i > lastblock; i--) { - bn = fs2h32(oip->i_e2fs_blocks[i]); + bn = letoh32(oip->i_e2fs_blocks[i]); if (bn == 0) continue; oip->i_e2fs_blocks[i] = 0; @@ -488,7 +488,7 @@ ext2fs_indirtrunc(struct inode *ip, int32_t lbn, int32_t dbn, int32_t lastbn, in for (i = NINDIR(fs) - 1, nlbn = lbn + 1 - i * factor; i > last; i--, nlbn += factor) { - nb = fs2h32(bap[i]); + nb = letoh32(bap[i]); if (nb == 0) continue; if (level > SINGLE) { @@ -508,7 +508,7 @@ ext2fs_indirtrunc(struct inode *ip, int32_t lbn, int32_t dbn, int32_t lastbn, in */ if (level > SINGLE && lastbn >= 0) { last = lastbn % factor; - nb = fs2h32(bap[i]); + nb = letoh32(bap[i]); if (nb != 0) { error = ext2fs_indirtrunc(ip, nlbn, fsbtodb(fs, nb), last, level - 1, &blkcount); diff --git a/sys/ufs/ext2fs/ext2fs_lookup.c b/sys/ufs/ext2fs/ext2fs_lookup.c index 98de4ecdc92..df080241f85 100644 --- a/sys/ufs/ext2fs/ext2fs_lookup.c +++ b/sys/ufs/ext2fs/ext2fs_lookup.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ext2fs_lookup.c,v 1.36 2014/07/13 15:07:01 pelikan Exp $ */ +/* $OpenBSD: ext2fs_lookup.c,v 1.37 2014/07/13 16:59:35 pelikan Exp $ */ /* $NetBSD: ext2fs_lookup.c,v 1.16 2000/08/03 20:29:26 thorpej Exp $ */ /* @@ -91,7 +91,7 @@ static void ext2fs_dirconv2ffs(struct ext2fs_direct *e2dir, struct dirent *ffsdir) { memset(ffsdir, 0, sizeof(struct dirent)); - ffsdir->d_fileno = fs2h32(e2dir->e2d_ino); + ffsdir->d_fileno = letoh32(e2dir->e2d_ino); ffsdir->d_namlen = e2dir->e2d_namlen; ffsdir->d_type = DT_UNKNOWN; /* don't know more here */ @@ -168,7 +168,7 @@ ext2fs_readdir(void *v) readcnt = e2fs_count - auio.uio_resid; dp = (struct ext2fs_direct *) dirbuf; while ((char *) dp < (char *) dirbuf + readcnt) { - e2d_reclen = fs2h16(dp->e2d_reclen); + e2d_reclen = letoh16(dp->e2d_reclen); if (e2d_reclen == 0) { error = EIO; break; @@ -357,8 +357,8 @@ searchloop: ep = (struct ext2fs_direct *) ((char *)bp->b_data + (entryoffsetinblock & bmask)); /* foundentry: */ - dp->i_ino = fs2h32(ep->e2d_ino); - dp->i_reclen = fs2h16(ep->e2d_reclen); + dp->i_ino = letoh32(ep->e2d_ino); + dp->i_reclen = letoh16(ep->e2d_reclen); goto found; } } @@ -643,7 +643,7 @@ ext2fs_search_dirblock(struct inode *ip, void *data, int *foundp, * compaction is viable. */ if (ssp->slotstatus != FOUND) { - int size = fs2h16(ep->e2d_reclen); + int size = letoh16(ep->e2d_reclen); if (ep->e2d_ino != 0) size -= EXT2FS_DIRSIZ(ep->e2d_namlen); @@ -651,7 +651,7 @@ ext2fs_search_dirblock(struct inode *ip, void *data, int *foundp, if (size >= ssp->slotneeded) { ssp->slotstatus = FOUND; ssp->slotoffset = ip->i_offset; - ssp->slotsize = fs2h16(ep->e2d_reclen); + ssp->slotsize = letoh16(ep->e2d_reclen); } else if (ssp->slotstatus == NONE) { ssp->slotfreespace += size; if (ssp->slotoffset == -1) @@ -659,7 +659,7 @@ ext2fs_search_dirblock(struct inode *ip, void *data, int *foundp, if (ssp->slotfreespace >= ssp->slotneeded) { ssp->slotstatus = COMPACT; ssp->slotsize = ip->i_offset + - fs2h16(ep->e2d_reclen) - ssp->slotoffset; + letoh16(ep->e2d_reclen) - ssp->slotoffset; } } } @@ -682,8 +682,8 @@ ext2fs_search_dirblock(struct inode *ip, void *data, int *foundp, } } *prevoffp = ip->i_offset; - ip->i_offset += fs2h16(ep->e2d_reclen); - offset += fs2h16(ep->e2d_reclen); + ip->i_offset += letoh16(ep->e2d_reclen); + offset += letoh16(ep->e2d_reclen); *entryoffsetinblockp = offset; if (ep->e2d_ino) *endusefulp = ip->i_offset; @@ -712,33 +712,30 @@ static int ext2fs_dirbadentry(struct vnode *dp, struct ext2fs_direct *de, int entryoffsetinblock) { - int dirblksize = VTOI(dp)->i_e2fs->e2fs_bsize; + int dirblksize = VTOI(dp)->i_e2fs->e2fs_bsize; + char *error_msg = NULL; + int reclen = letoh16(de->e2d_reclen); + int namlen = de->e2d_namlen; - char * error_msg = NULL; - int reclen = fs2h16(de->e2d_reclen); - int namlen = de->e2d_namlen; + if (reclen < EXT2FS_DIRSIZ(1)) /* e2d_namlen = 1 */ + error_msg = "rec_len is smaller than minimal"; + else if (reclen % 4 != 0) + error_msg = "rec_len % 4 != 0"; + else if (reclen < EXT2FS_DIRSIZ(namlen)) + error_msg = "reclen is too small for name_len"; + else if (entryoffsetinblock + reclen > dirblksize) + error_msg = "directory entry across blocks"; + else if (letoh32(de->e2d_ino) > VTOI(dp)->i_e2fs->e2fs.e2fs_icount) + error_msg = "inode out of bounds"; - if (reclen < EXT2FS_DIRSIZ(1)) /* e2d_namlen = 1 */ - error_msg = "rec_len is smaller than minimal"; - else if (reclen % 4 != 0) - error_msg = "rec_len % 4 != 0"; - else if (reclen < EXT2FS_DIRSIZ(namlen)) - error_msg = "reclen is too small for name_len"; - else if (entryoffsetinblock + reclen > dirblksize) - error_msg = "directory entry across blocks"; - 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) fs2h32(de->e2d_ino), - reclen, namlen); - panic("ext2fs_dirbadentry"); - } - return error_msg == NULL ? 0 : 1; + if (error_msg != NULL) { + printf("bad directory entry: %s\n" + "offset=%d, inode=%u, rec_len=%d, name_len=%d \n", + error_msg, entryoffsetinblock, letoh32(de->e2d_ino), + reclen, namlen); + panic(__func__); + } + return (0); } /* @@ -770,7 +767,7 @@ ext2fs_direnter(struct inode *ip, struct vnode *dvp, panic("direnter: missing name"); #endif dp = VTOI(dvp); - newdir.e2d_ino = h2fs32(ip->i_number); + newdir.e2d_ino = htole32(ip->i_number); newdir.e2d_namlen = cnp->cn_namelen; if (ip->i_e2fs->e2fs.e2fs_rev > E2FS_REV0 && (ip->i_e2fs->e2fs.e2fs_features_incompat & EXT2F_INCOMPAT_FTYPE)) { @@ -790,7 +787,7 @@ ext2fs_direnter(struct inode *ip, struct vnode *dvp, if (dp->i_offset & (dirblksize - 1)) panic("ext2fs_direnter: newblk"); auio.uio_offset = dp->i_offset; - newdir.e2d_reclen = h2fs16(dirblksize); + newdir.e2d_reclen = htole16(dirblksize); auio.uio_resid = newentrysize; aiov.iov_len = newentrysize; aiov.iov_base = (caddr_t)&newdir; @@ -838,20 +835,20 @@ ext2fs_direnter(struct inode *ip, struct vnode *dvp, */ ep = (struct ext2fs_direct *)dirbuf; dsize = EXT2FS_DIRSIZ(ep->e2d_namlen); - spacefree = fs2h16(ep->e2d_reclen) - dsize; - for (loc = fs2h16(ep->e2d_reclen); loc < dp->i_count; ) { + spacefree = letoh16(ep->e2d_reclen) - dsize; + for (loc = letoh16(ep->e2d_reclen); loc < dp->i_count; ) { nep = (struct ext2fs_direct *)(dirbuf + loc); if (ep->e2d_ino) { /* trim the existing slot */ - ep->e2d_reclen = h2fs16(dsize); + ep->e2d_reclen = htole16(dsize); ep = (struct ext2fs_direct *)((char *)ep + dsize); } else { /* overwrite; nothing there; header is ours */ spacefree += dsize; } dsize = EXT2FS_DIRSIZ(nep->e2d_namlen); - spacefree += fs2h16(nep->e2d_reclen) - dsize; - loc += fs2h16(nep->e2d_reclen); + spacefree += letoh16(nep->e2d_reclen) - dsize; + loc += letoh16(nep->e2d_reclen); memcpy(ep, nep, dsize); } /* @@ -863,7 +860,7 @@ ext2fs_direnter(struct inode *ip, struct vnode *dvp, if (spacefree + dsize < newentrysize) panic("ext2fs_direnter: compact1"); #endif - newdir.e2d_reclen = h2fs16(spacefree + dsize); + newdir.e2d_reclen = htole16(spacefree + dsize); } else { #ifdef DIAGNOSTIC if (spacefree < newentrysize) { @@ -872,8 +869,8 @@ ext2fs_direnter(struct inode *ip, struct vnode *dvp, panic("ext2fs_direnter: compact2"); } #endif - newdir.e2d_reclen = h2fs16(spacefree); - ep->e2d_reclen = h2fs16(dsize); + newdir.e2d_reclen = htole16(spacefree); + ep->e2d_reclen = htole16(dsize); ep = (struct ext2fs_direct *)((char *)ep + dsize); } memcpy(ep, &newdir, newentrysize); @@ -926,7 +923,7 @@ ext2fs_dirremove(struct vnode *dvp, struct componentname *cnp) (char **)&ep, &bp); if (error != 0) return (error); - ep->e2d_reclen = h2fs16(fs2h16(ep->e2d_reclen) + dp->i_reclen); + ep->e2d_reclen = htole16(letoh16(ep->e2d_reclen) + dp->i_reclen); error = VOP_BWRITE(bp); dp->i_flag |= IN_CHANGE | IN_UPDATE; return (error); @@ -948,7 +945,7 @@ ext2fs_dirrewrite(struct inode *dp, struct inode *ip, error = ext2fs_bufatoff(dp, (off_t)dp->i_offset, (char **)&ep, &bp); if (error != 0) return (error); - ep->e2d_ino = h2fs32(ip->i_number); + ep->e2d_ino = htole32(ip->i_number); if (ip->i_e2fs->e2fs.e2fs_rev > E2FS_REV0 && (ip->i_e2fs->e2fs.e2fs_features_incompat & EXT2F_INCOMPAT_FTYPE)) { ep->e2d_type = inot2ext2dt(IFTODT(ip->i_e2fs_mode)); @@ -980,7 +977,7 @@ ext2fs_dirempty(struct inode *ip, ufsino_t parentino, struct ucred *cred) #define MINDIRSIZ (sizeof (struct ext2fs_dirtemplate) / 2) - for (off = 0; off < ext2fs_size(ip); off += fs2h16(dp->e2d_reclen)) { + for (off = 0; off < ext2fs_size(ip); off += letoh16(dp->e2d_reclen)) { error = vn_rdwr(UIO_READ, ITOV(ip), (caddr_t)dp, MINDIRSIZ, off, UIO_SYSSPACE, IO_NODELOCKED, cred, &count, curproc); /* @@ -1008,7 +1005,7 @@ ext2fs_dirempty(struct inode *ip, ufsino_t parentino, struct ucred *cred) */ if (namlen == 1) continue; - if (dp->e2d_name[1] == '.' && fs2h32(dp->e2d_ino) == parentino) + if (dp->e2d_name[1] == '.' && letoh32(dp->e2d_ino) == parentino) continue; return (0); } @@ -1057,7 +1054,7 @@ ext2fs_checkpath(struct inode *source, struct inode *target, error = ENOTDIR; break; } - ino = fs2h32(dirbuf.dotdot_ino); + ino = letoh32(dirbuf.dotdot_ino); if (ino == source->i_number) { error = EINVAL; break; diff --git a/sys/ufs/ext2fs/ext2fs_subr.c b/sys/ufs/ext2fs/ext2fs_subr.c index cd4f22e9908..57823855a56 100644 --- a/sys/ufs/ext2fs/ext2fs_subr.c +++ b/sys/ufs/ext2fs/ext2fs_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ext2fs_subr.c,v 1.31 2014/07/13 13:28:26 pelikan Exp $ */ +/* $OpenBSD: ext2fs_subr.c,v 1.32 2014/07/13 16:59:35 pelikan Exp $ */ /* $NetBSD: ext2fs_subr.c,v 1.1 1997/06/11 09:34:03 bouyer Exp $ */ /* @@ -182,7 +182,7 @@ ext2fs_vinit(struct mount *mp, struct vops *specops, case VBLK: vp->v_op = specops; - nvp = checkalias(vp, fs2h32(ip->i_e2din->e2di_rdev), mp); + nvp = checkalias(vp, letoh32(ip->i_e2din->e2di_rdev), mp); if (nvp != NULL) { /* * Discard unneeded vnode, but save its inode. Note diff --git a/sys/ufs/ext2fs/ext2fs_vnops.c b/sys/ufs/ext2fs/ext2fs_vnops.c index 5f3ffee498a..73d914964e2 100644 --- a/sys/ufs/ext2fs/ext2fs_vnops.c +++ b/sys/ufs/ext2fs/ext2fs_vnops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ext2fs_vnops.c,v 1.66 2014/07/08 17:19:26 deraadt Exp $ */ +/* $OpenBSD: ext2fs_vnops.c,v 1.67 2014/07/13 16:59:35 pelikan Exp $ */ /* $NetBSD: ext2fs_vnops.c,v 1.1 1997/06/11 09:34:09 bouyer Exp $ */ /* @@ -107,7 +107,7 @@ ext2fs_mknod(void *v) * Want to be able to use this to make badblock * inodes, so don't truncate the dev number. */ - ip->i_e2din->e2di_rdev = h2fs32(vap->va_rdev); + ip->i_e2din->e2di_rdev = htole32(vap->va_rdev); } /* * Remove inode so that it will be reloaded by VFS_VGET and @@ -176,7 +176,7 @@ ext2fs_getattr(void *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)fs2h32(ip->i_e2din->e2di_rdev); + vap->va_rdev = (dev_t) letoh32(ip->i_e2din->e2di_rdev); vap->va_size = ext2fs_size(ip); vap->va_atime.tv_sec = ip->i_e2fs_atime; vap->va_atime.tv_nsec = 0; @@ -836,7 +836,7 @@ abortit: ufs_dirbad(xp, (doff_t)12, "ext2fs_rename: mangled dir"); } else { - dirbuf.dotdot_ino = h2fs32(newparent); + dirbuf.dotdot_ino = htole32(newparent); (void) vn_rdwr(UIO_WRITE, fvp, (caddr_t)&dirbuf, sizeof (struct dirtemplate), @@ -933,16 +933,16 @@ ext2fs_mkdir(void *v) /* Initialize directory with "." and ".." from static template. */ memset(&dirtemplate, 0, sizeof(dirtemplate)); - dirtemplate.dot_ino = h2fs32(ip->i_number); - dirtemplate.dot_reclen = h2fs16(12); + dirtemplate.dot_ino = htole32(ip->i_number); + dirtemplate.dot_reclen = htole16(12); dirtemplate.dot_namlen = 1; if (ip->i_e2fs->e2fs.e2fs_rev > E2FS_REV0 && (ip->i_e2fs->e2fs.e2fs_features_incompat & EXT2F_INCOMPAT_FTYPE)) { dirtemplate.dot_type = EXT2_FT_DIR; } dirtemplate.dot_name[0] = '.'; - dirtemplate.dotdot_ino = h2fs32(dp->i_number); - dirtemplate.dotdot_reclen = h2fs16(VTOI(dvp)->i_e2fs->e2fs_bsize - 12); + dirtemplate.dotdot_ino = htole32(dp->i_number); + dirtemplate.dotdot_reclen = htole16(VTOI(dvp)->i_e2fs->e2fs_bsize - 12); dirtemplate.dotdot_namlen = 2; if (ip->i_e2fs->e2fs.e2fs_rev > E2FS_REV0 && (ip->i_e2fs->e2fs.e2fs_features_incompat & EXT2F_INCOMPAT_FTYPE)) { -- 2.20.1