From owner-svn-src-all@freebsd.org Sun May 17 14:52:56 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 0E6F32DBB96; Sun, 17 May 2020 14:52:56 +0000 (UTC) (envelope-from fsu@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 49Q4rR6v2Fz4RkT; Sun, 17 May 2020 14:52:55 +0000 (UTC) (envelope-from fsu@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id CD407121FB; Sun, 17 May 2020 14:52:55 +0000 (UTC) (envelope-from fsu@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 04HEqtrv063894; Sun, 17 May 2020 14:52:55 GMT (envelope-from fsu@FreeBSD.org) Received: (from fsu@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 04HEqs7b063888; Sun, 17 May 2020 14:52:54 GMT (envelope-from fsu@FreeBSD.org) Message-Id: <202005171452.04HEqs7b063888@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: fsu set sender to fsu@FreeBSD.org using -f From: Fedor Uporov Date: Sun, 17 May 2020 14:52:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r361136 - head/sys/fs/ext2fs X-SVN-Group: head X-SVN-Commit-Author: fsu X-SVN-Commit-Paths: head/sys/fs/ext2fs X-SVN-Commit-Revision: 361136 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 May 2020 14:52:56 -0000 Author: fsu Date: Sun May 17 14:52:54 2020 New Revision: 361136 URL: https://svnweb.freebsd.org/changeset/base/361136 Log: Add BE architectures support. Author of most initial version: pfg (https://reviews.freebsd.org/D23259) Reviewed by: pfg MFC after: 3 months Differential Revision: https://reviews.freebsd.org/D24685 Modified: head/sys/fs/ext2fs/ext2_alloc.c head/sys/fs/ext2fs/ext2_balloc.c head/sys/fs/ext2fs/ext2_bmap.c head/sys/fs/ext2fs/ext2_csum.c head/sys/fs/ext2fs/ext2_extattr.c head/sys/fs/ext2fs/ext2_extents.c head/sys/fs/ext2fs/ext2_extents.h head/sys/fs/ext2fs/ext2_htree.c head/sys/fs/ext2fs/ext2_inode.c head/sys/fs/ext2fs/ext2_inode_cnv.c head/sys/fs/ext2fs/ext2_lookup.c head/sys/fs/ext2fs/ext2_subr.c head/sys/fs/ext2fs/ext2_vfsops.c head/sys/fs/ext2fs/ext2_vnops.c head/sys/fs/ext2fs/ext2fs.h head/sys/fs/ext2fs/fs.h Modified: head/sys/fs/ext2fs/ext2_alloc.c ============================================================================== --- head/sys/fs/ext2fs/ext2_alloc.c Sun May 17 14:10:46 2020 (r361135) +++ head/sys/fs/ext2fs/ext2_alloc.c Sun May 17 14:52:54 2020 (r361136) @@ -397,7 +397,7 @@ ext2_valloc(struct vnode *pvp, int mode, struct ucred ump = pip->i_ump; EXT2_LOCK(ump); - if (fs->e2fs->e2fs_ficount == 0) + if (fs->e2fs_ficount == 0) goto noinodes; /* * If it is a directory then obtain a cylinder group based on @@ -413,7 +413,7 @@ ext2_valloc(struct vnode *pvp, int mode, struct ucred if (fs->e2fs_contigdirs[cg] > 0) fs->e2fs_contigdirs[cg]--; } - ipref = cg * fs->e2fs->e2fs_ipg + 1; + ipref = cg * fs->e2fs_ipg + 1; ino = (ino_t)ext2_hashalloc(pip, cg, (long)ipref, mode, ext2_nodealloccg); if (ino == 0) goto noinodes; @@ -501,87 +501,87 @@ uint64_t e2fs_gd_get_b_bitmap(struct ext2_gd *gd) { - return (((uint64_t)(gd->ext4bgd_b_bitmap_hi) << 32) | - gd->ext2bgd_b_bitmap); + return (((uint64_t)(le32toh(gd->ext4bgd_b_bitmap_hi)) << 32) | + le32toh(gd->ext2bgd_b_bitmap)); } uint64_t e2fs_gd_get_i_bitmap(struct ext2_gd *gd) { - return (((uint64_t)(gd->ext4bgd_i_bitmap_hi) << 32) | - gd->ext2bgd_i_bitmap); + return (((uint64_t)(le32toh(gd->ext4bgd_i_bitmap_hi)) << 32) | + le32toh(gd->ext2bgd_i_bitmap)); } uint64_t e2fs_gd_get_i_tables(struct ext2_gd *gd) { - return (((uint64_t)(gd->ext4bgd_i_tables_hi) << 32) | - gd->ext2bgd_i_tables); + return (((uint64_t)(le32toh(gd->ext4bgd_i_tables_hi)) << 32) | + le32toh(gd->ext2bgd_i_tables)); } static uint32_t e2fs_gd_get_nbfree(struct ext2_gd *gd) { - return (((uint32_t)(gd->ext4bgd_nbfree_hi) << 16) | - gd->ext2bgd_nbfree); + return (((uint32_t)(le16toh(gd->ext4bgd_nbfree_hi)) << 16) | + le16toh(gd->ext2bgd_nbfree)); } static void e2fs_gd_set_nbfree(struct ext2_gd *gd, uint32_t val) { - gd->ext2bgd_nbfree = val & 0xffff; - gd->ext4bgd_nbfree_hi = val >> 16; + gd->ext2bgd_nbfree = htole16(val & 0xffff); + gd->ext4bgd_nbfree_hi = htole16(val >> 16); } static uint32_t e2fs_gd_get_nifree(struct ext2_gd *gd) { - return (((uint32_t)(gd->ext4bgd_nifree_hi) << 16) | - gd->ext2bgd_nifree); + return (((uint32_t)(le16toh(gd->ext4bgd_nifree_hi)) << 16) | + le16toh(gd->ext2bgd_nifree)); } static void e2fs_gd_set_nifree(struct ext2_gd *gd, uint32_t val) { - gd->ext2bgd_nifree = val & 0xffff; - gd->ext4bgd_nifree_hi = val >> 16; + gd->ext2bgd_nifree = htole16(val & 0xffff); + gd->ext4bgd_nifree_hi = htole16(val >> 16); } uint32_t e2fs_gd_get_ndirs(struct ext2_gd *gd) { - return (((uint32_t)(gd->ext4bgd_ndirs_hi) << 16) | - gd->ext2bgd_ndirs); + return (((uint32_t)(le16toh(gd->ext4bgd_ndirs_hi)) << 16) | + le16toh(gd->ext2bgd_ndirs)); } static void e2fs_gd_set_ndirs(struct ext2_gd *gd, uint32_t val) { - gd->ext2bgd_ndirs = val & 0xffff; - gd->ext4bgd_ndirs_hi = val >> 16; + gd->ext2bgd_ndirs = htole16(val & 0xffff); + gd->ext4bgd_ndirs_hi = htole16(val >> 16); } static uint32_t e2fs_gd_get_i_unused(struct ext2_gd *gd) { - return (((uint32_t)(gd->ext4bgd_i_unused_hi) << 16) | - gd->ext4bgd_i_unused); + return ((uint32_t)(le16toh(gd->ext4bgd_i_unused_hi) << 16) | + le16toh(gd->ext4bgd_i_unused)); } static void e2fs_gd_set_i_unused(struct ext2_gd *gd, uint32_t val) { - gd->ext4bgd_i_unused = val & 0xffff; - gd->ext4bgd_i_unused_hi = val >> 16; + gd->ext4bgd_i_unused = htole16(val & 0xffff); + gd->ext4bgd_i_unused_hi = htole16(val >> 16); } /* @@ -612,7 +612,7 @@ ext2_dirpref(struct inode *pip) mtx_assert(EXT2_MTX(pip->i_ump), MA_OWNED); fs = pip->i_e2fs; - avgifree = fs->e2fs->e2fs_ficount / fs->e2fs_gcount; + avgifree = fs->e2fs_ficount / fs->e2fs_gcount; avgbfree = fs->e2fs_fbcount / fs->e2fs_gcount; avgndir = fs->e2fs_total_dir / fs->e2fs_gcount; @@ -653,7 +653,8 @@ ext2_dirpref(struct inode *pip) minbfree = 1; cgsize = fs->e2fs_fsize * fs->e2fs_fpg; dirsize = AVGDIRSIZE; - curdirsize = avgndir ? (cgsize - avgbfree * fs->e2fs_bsize) / avgndir : 0; + curdirsize = avgndir ? + (cgsize - avgbfree * fs->e2fs_bsize) / avgndir : 0; if (dirsize < curdirsize) dirsize = curdirsize; maxcontigdirs = min((avgbfree * fs->e2fs_bsize) / dirsize, 255); @@ -731,7 +732,7 @@ ext2_blkpref(struct inode *ip, e2fs_lbn_t lbn, int ind if (bap) for (tmp = indx - 1; tmp >= 0; tmp--) if (bap[tmp]) - return bap[tmp]; + return (le32toh(bap[tmp])); /* * Else lets fall back to the blocknr or, if there is none, follow @@ -739,7 +740,7 @@ ext2_blkpref(struct inode *ip, e2fs_lbn_t lbn, int ind */ return (blocknr ? blocknr : (e2fs_daddr_t)(ip->i_block_group * - EXT2_BLOCKS_PER_GROUP(fs)) + fs->e2fs->e2fs_first_dblock); + EXT2_BLOCKS_PER_GROUP(fs)) + le32toh(fs->e2fs->e2fs_first_dblock)); } /* @@ -802,7 +803,7 @@ ext2_cg_number_gdb_nometa(struct m_ext2fs *fs, int cg) return (0); if (EXT2_HAS_INCOMPAT_FEATURE(fs, EXT2F_INCOMPAT_META_BG)) - return (fs->e2fs->e3fs_first_meta_bg); + return (le32toh(fs->e2fs->e3fs_first_meta_bg)); return ((fs->e2fs_gcount + EXT2_DESCS_PER_BLOCK(fs) - 1) / EXT2_DESCS_PER_BLOCK(fs)); @@ -829,7 +830,7 @@ ext2_cg_number_gdb(struct m_ext2fs *fs, int cg) { unsigned long first_meta_bg, metagroup; - first_meta_bg = fs->e2fs->e3fs_first_meta_bg; + first_meta_bg = le32toh(fs->e2fs->e3fs_first_meta_bg); metagroup = cg / EXT2_DESCS_PER_BLOCK(fs); if (!EXT2_HAS_INCOMPAT_FEATURE(fs, EXT2F_INCOMPAT_META_BG) || @@ -847,10 +848,11 @@ ext2_number_base_meta_blocks(struct m_ext2fs *fs, int number = ext2_cg_has_sb(fs, cg); if (!EXT2_HAS_INCOMPAT_FEATURE(fs, EXT2F_INCOMPAT_META_BG) || - cg < fs->e2fs->e3fs_first_meta_bg * EXT2_DESCS_PER_BLOCK(fs)) { + cg < le32toh(fs->e2fs->e3fs_first_meta_bg) * + EXT2_DESCS_PER_BLOCK(fs)) { if (number) { number += ext2_cg_number_gdb(fs, cg); - number += fs->e2fs->e2fs_reserved_ngdb; + number += le16toh(fs->e2fs->e2fs_reserved_ngdb); } } else { number += ext2_cg_number_gdb(fs, cg); @@ -877,7 +879,8 @@ static int ext2_get_group_number(struct m_ext2fs *fs, e4fs_daddr_t block) { - return ((block - fs->e2fs->e2fs_first_dblock) / fs->e2fs_bsize); + return ((block - le32toh(fs->e2fs->e2fs_first_dblock)) / + fs->e2fs_bsize); } static int @@ -893,7 +896,7 @@ ext2_cg_block_bitmap_init(struct m_ext2fs *fs, int cg, int bit, bit_max, inodes_per_block; uint64_t start, tmp; - if (!(fs->e2fs_gd[cg].ext4bgd_flags & EXT2_BG_BLOCK_UNINIT)) + if (!(le16toh(fs->e2fs_gd[cg].ext4bgd_flags) & EXT2_BG_BLOCK_UNINIT)) return (0); memset(bp->b_data, 0, fs->e2fs_bsize); @@ -905,7 +908,8 @@ ext2_cg_block_bitmap_init(struct m_ext2fs *fs, int cg, for (bit = 0; bit < bit_max; bit++) setbit(bp->b_data, bit); - start = (uint64_t)cg * fs->e2fs->e2fs_bpg + fs->e2fs->e2fs_first_dblock; + start = (uint64_t)cg * fs->e2fs_bpg + + le32toh(fs->e2fs->e2fs_first_dblock); /* Set bits for block and inode bitmaps, and inode table. */ tmp = e2fs_gd_get_b_bitmap(&fs->e2fs_gd[cg]); @@ -921,7 +925,7 @@ ext2_cg_block_bitmap_init(struct m_ext2fs *fs, int cg, tmp = e2fs_gd_get_i_tables(&fs->e2fs_gd[cg]); inodes_per_block = fs->e2fs_bsize/EXT2_INODE_SIZE(fs); while( tmp < e2fs_gd_get_i_tables(&fs->e2fs_gd[cg]) + - fs->e2fs->e2fs_ipg / inodes_per_block ) { + fs->e2fs_ipg / inodes_per_block ) { if (!EXT2_HAS_INCOMPAT_FEATURE(fs, EXT2F_INCOMPAT_FLEX_BG) || ext2_block_in_group(fs, tmp, cg)) setbit(bp->b_data, tmp - start); @@ -933,11 +937,12 @@ ext2_cg_block_bitmap_init(struct m_ext2fs *fs, int cg, * the blocksize * 8 ( which is the size of bitmap ), set rest * of the block bitmap to 1 */ - ext2_mark_bitmap_end(fs->e2fs->e2fs_bpg, fs->e2fs_bsize * 8, + ext2_mark_bitmap_end(fs->e2fs_bpg, fs->e2fs_bsize * 8, bp->b_data); /* Clean the flag */ - fs->e2fs_gd[cg].ext4bgd_flags &= ~EXT2_BG_BLOCK_UNINIT; + fs->e2fs_gd[cg].ext4bgd_flags = htole16(le16toh( + fs->e2fs_gd[cg].ext4bgd_flags) & ~EXT2_BG_BLOCK_UNINIT); return (0); } @@ -951,8 +956,8 @@ ext2_b_bitmap_validate(struct m_ext2fs *fs, struct buf if (EXT2_HAS_INCOMPAT_FEATURE(fs, EXT2F_INCOMPAT_FLEX_BG)) { /* - * It is not possible to check block bitmap in case of this feature, - * because the inode and block bitmaps and inode table + * It is not possible to check block bitmap in case of this + * feature, because the inode and block bitmaps and inode table * blocks may not be in the group at all. * So, skip check in this case. */ @@ -961,8 +966,8 @@ ext2_b_bitmap_validate(struct m_ext2fs *fs, struct buf gd = &fs->e2fs_gd[cg]; max_bit = fs->e2fs_fpg; - group_first_block = ((uint64_t)cg) * fs->e2fs->e2fs_fpg + - fs->e2fs->e2fs_first_dblock; + group_first_block = ((uint64_t)cg) * fs->e2fs_fpg + + le32toh(fs->e2fs->e2fs_first_dblock); /* Check block bitmap block number */ offset = e2fs_gd_get_b_bitmap(gd) - group_first_block; @@ -1036,8 +1041,8 @@ ext2_alloccg(struct inode *ip, int cg, daddr_t bpref, goto fail; /* - * Check, that another thread did not not allocate the last block in this - * group while we were waiting for the buffer. + * Check, that another thread did not not allocate the last block in + * this group while we were waiting for the buffer. */ if (e2fs_gd_get_nbfree(&fs->e2fs_gd[cg]) == 0) goto fail; @@ -1066,7 +1071,7 @@ ext2_alloccg(struct inode *ip, int cg, daddr_t bpref, start = dtogd(fs, bpref) / NBBY; else start = 0; - end = howmany(fs->e2fs->e2fs_fpg, NBBY) - start; + end = howmany(fs->e2fs_fpg, NBBY) - start; retry: runlen = 0; runstart = 0; @@ -1135,7 +1140,8 @@ gotit: EXT2_UNLOCK(ump); ext2_gd_b_bitmap_csum_set(fs, cg, bp); bdwrite(bp); - return (((uint64_t)cg) * fs->e2fs->e2fs_fpg + fs->e2fs->e2fs_first_dblock + bno); + return (((uint64_t)cg) * fs->e2fs_fpg + + le32toh(fs->e2fs->e2fs_first_dblock) + bno); fail: brelse(bp); @@ -1203,7 +1209,7 @@ ext2_clusteralloc(struct inode *ip, int cg, daddr_t bp bpref = dtogd(fs, bpref); loc = bpref / NBBY; bit = 1 << (bpref % NBBY); - for (run = 0, got = bpref; got < fs->e2fs->e2fs_fpg; got++) { + for (run = 0, got = bpref; got < fs->e2fs_fpg; got++) { if ((bbp[loc] & bit) != 0) run = 0; else { @@ -1219,7 +1225,7 @@ ext2_clusteralloc(struct inode *ip, int cg, daddr_t bp } } - if (got >= fs->e2fs->e2fs_fpg) + if (got >= fs->e2fs_fpg) goto fail_lock; /* Allocate the cluster that we found. */ @@ -1228,7 +1234,7 @@ ext2_clusteralloc(struct inode *ip, int cg, daddr_t bp panic("ext2_clusteralloc: map mismatch"); bno = got - run + 1; - if (bno >= fs->e2fs->e2fs_fpg) + if (bno >= fs->e2fs_fpg) panic("ext2_clusteralloc: allocated out of group"); EXT2_LOCK(ump); @@ -1243,7 +1249,8 @@ ext2_clusteralloc(struct inode *ip, int cg, daddr_t bp EXT2_UNLOCK(ump); bdwrite(bp); - return (cg * fs->e2fs->e2fs_fpg + fs->e2fs->e2fs_first_dblock + bno); + return (cg * fs->e2fs_fpg + le32toh(fs->e2fs->e2fs_first_dblock) + + bno); fail_lock: EXT2_LOCK(ump); @@ -1261,13 +1268,13 @@ ext2_zero_inode_table(struct inode *ip, int cg) fs = ip->i_e2fs; - if (fs->e2fs_gd[cg].ext4bgd_flags & EXT2_BG_INODE_ZEROED) + if (le16toh(fs->e2fs_gd[cg].ext4bgd_flags) & EXT2_BG_INODE_ZEROED) return (0); - all_blks = fs->e2fs->e2fs_inode_size * fs->e2fs->e2fs_ipg / + all_blks = le16toh(fs->e2fs->e2fs_inode_size) * fs->e2fs_ipg / fs->e2fs_bsize; - used_blks = howmany(fs->e2fs->e2fs_ipg - + used_blks = howmany(fs->e2fs_ipg - e2fs_gd_get_i_unused(&fs->e2fs_gd[cg]), fs->e2fs_bsize / EXT2_INODE_SIZE(fs)); @@ -1282,7 +1289,8 @@ ext2_zero_inode_table(struct inode *ip, int cg) bawrite(bp); } - fs->e2fs_gd[cg].ext4bgd_flags |= EXT2_BG_INODE_ZEROED; + fs->e2fs_gd[cg].ext4bgd_flags = htole16(le16toh( + fs->e2fs_gd[cg].ext4bgd_flags) | EXT2_BG_INODE_ZEROED); return (0); } @@ -1329,12 +1337,15 @@ ext2_nodealloccg(struct inode *ip, int cg, daddr_t ipr } if (EXT2_HAS_RO_COMPAT_FEATURE(fs, EXT2F_ROCOMPAT_GDT_CSUM) || EXT2_HAS_RO_COMPAT_FEATURE(fs, EXT2F_ROCOMPAT_METADATA_CKSUM)) { - if (fs->e2fs_gd[cg].ext4bgd_flags & EXT2_BG_INODE_UNINIT) { + if (le16toh(fs->e2fs_gd[cg].ext4bgd_flags) & + EXT2_BG_INODE_UNINIT) { ibytes = fs->e2fs_ipg / 8; memset(bp->b_data, 0, ibytes - 1); ext2_fix_bitmap_tail(bp->b_data, ibytes, fs->e2fs_bsize - 1); - fs->e2fs_gd[cg].ext4bgd_flags &= ~EXT2_BG_INODE_UNINIT; + fs->e2fs_gd[cg].ext4bgd_flags = htole16(le16toh( + fs->e2fs_gd[cg].ext4bgd_flags) & + ~EXT2_BG_INODE_UNINIT); } ext2_gd_i_bitmap_csum_set(fs, cg, bp); error = ext2_zero_inode_table(ip, cg); @@ -1361,20 +1372,21 @@ ext2_nodealloccg(struct inode *ip, int cg, daddr_t ipr } ibp = (char *)bp->b_data; if (ipref) { - ipref %= fs->e2fs->e2fs_ipg; + ipref %= fs->e2fs_ipg; if (isclr(ibp, ipref)) goto gotit; } start = ipref / NBBY; - len = howmany(fs->e2fs->e2fs_ipg - ipref, NBBY); + len = howmany(fs->e2fs_ipg - ipref, NBBY); loc = memcchr(&ibp[start], 0xff, len); if (loc == NULL) { len = start + 1; start = 0; loc = memcchr(&ibp[start], 0xff, len); if (loc == NULL) { - SDT_PROBE3(ext2fs, , alloc, ext2_nodealloccg_bmap_corrupted, - cg, ipref, fs->e2fs_fsmnt); + SDT_PROBE3(ext2fs, , alloc, + ext2_nodealloccg_bmap_corrupted, cg, ipref, + fs->e2fs_fsmnt); brelse(bp); EXT2_LOCK(ump); return (0); @@ -1388,12 +1400,12 @@ gotit: e2fs_gd_get_nifree(&fs->e2fs_gd[cg]) - 1); if (EXT2_HAS_RO_COMPAT_FEATURE(fs, EXT2F_ROCOMPAT_GDT_CSUM) || EXT2_HAS_RO_COMPAT_FEATURE(fs, EXT2F_ROCOMPAT_METADATA_CKSUM)) { - ifree = fs->e2fs->e2fs_ipg - e2fs_gd_get_i_unused(&fs->e2fs_gd[cg]); + ifree = fs->e2fs_ipg - e2fs_gd_get_i_unused(&fs->e2fs_gd[cg]); if (ipref + 1 > ifree) e2fs_gd_set_i_unused(&fs->e2fs_gd[cg], - fs->e2fs->e2fs_ipg - (ipref + 1)); + fs->e2fs_ipg - (ipref + 1)); } - fs->e2fs->e2fs_ficount--; + fs->e2fs_ficount--; fs->e2fs_fmod = 1; if ((mode & IFMT) == IFDIR) { e2fs_gd_set_ndirs(&fs->e2fs_gd[cg], @@ -1423,7 +1435,8 @@ ext2_blkfree(struct inode *ip, e4fs_daddr_t bno, long ump = ip->i_ump; cg = dtog(fs, bno); if (bno >= fs->e2fs_bcount) { - SDT_PROBE2(ext2fs, , alloc, ext2_blkfree_bad_block, ip->i_number, bno); + SDT_PROBE2(ext2fs, , alloc, ext2_blkfree_bad_block, + ip->i_number, bno); return; } error = bread(ip->i_devvp, @@ -1479,7 +1492,7 @@ ext2_vfree(struct vnode *pvp, ino_t ino, int mode) return (0); } ibp = (char *)bp->b_data; - ino = (ino - 1) % fs->e2fs->e2fs_ipg; + ino = (ino - 1) % fs->e2fs_ipg; if (isclr(ibp, ino)) { SDT_PROBE2(ext2fs, , alloc, ext2_vfree_doublefree, fs->e2fs_fsmnt, ino); @@ -1488,7 +1501,7 @@ ext2_vfree(struct vnode *pvp, ino_t ino, int mode) } clrbit(ibp, ino); EXT2_LOCK(ump); - fs->e2fs->e2fs_ficount++; + fs->e2fs_ficount++; e2fs_gd_set_nifree(&fs->e2fs_gd[cg], e2fs_gd_get_nifree(&fs->e2fs_gd[cg]) + 1); if ((mode & IFMT) == IFDIR) { @@ -1523,15 +1536,15 @@ ext2_mapsearch(struct m_ext2fs *fs, char *bbp, daddr_t start = dtogd(fs, bpref) / NBBY; else start = 0; - len = howmany(fs->e2fs->e2fs_fpg, NBBY) - start; + len = howmany(fs->e2fs_fpg, NBBY) - start; loc = memcchr(&bbp[start], 0xff, len); if (loc == NULL) { len = start + 1; start = 0; loc = memcchr(&bbp[start], 0xff, len); if (loc == NULL) { - panic("ext2_mapsearch: map corrupted: start=%d, len=%d, fs=%s", - start, len, fs->e2fs_fsmnt); + panic("ext2_mapsearch: map corrupted: start=%d, len=%d," + "fs=%s", start, len, fs->e2fs_fsmnt); /* NOTREACHED */ } } @@ -1547,8 +1560,8 @@ ext2_cg_has_sb(struct m_ext2fs *fs, int cg) return (1); if (EXT2_HAS_COMPAT_FEATURE(fs, EXT2F_COMPAT_SPARSESUPER2)) { - if (cg == fs->e2fs->e4fs_backup_bgs[0] || - cg == fs->e2fs->e4fs_backup_bgs[1]) + if (cg == le32toh(fs->e2fs->e4fs_backup_bgs[0]) || + cg == le32toh(fs->e2fs->e4fs_backup_bgs[1])) return (1); return (0); } Modified: head/sys/fs/ext2fs/ext2_balloc.c ============================================================================== --- head/sys/fs/ext2fs/ext2_balloc.c Sun May 17 14:10:46 2020 (r361135) +++ head/sys/fs/ext2fs/ext2_balloc.c Sun May 17 14:52:54 2020 (r361136) @@ -40,6 +40,7 @@ #include #include +#include #include #include #include @@ -220,7 +221,7 @@ ext2_balloc(struct inode *ip, e2fs_lbn_t lbn, int size return (error); } bap = (e2fs_daddr_t *)bp->b_data; - nb = bap[indirs[i].in_off]; + nb = le32toh(bap[indirs[i].in_off]); if (i == num) break; i += 1; @@ -252,7 +253,7 @@ ext2_balloc(struct inode *ip, e2fs_lbn_t lbn, int size brelse(bp); return (error); } - bap[indirs[i - 1].in_off] = nb; + bap[indirs[i - 1].in_off] = htole32(nb); /* * If required, write synchronously, otherwise use * delayed write. @@ -284,7 +285,7 @@ ext2_balloc(struct inode *ip, e2fs_lbn_t lbn, int size nbp->b_blkno = fsbtodb(fs, nb); if (flags & BA_CLRBUF) vfs_bio_clrbuf(nbp); - bap[indirs[i].in_off] = nb; + bap[indirs[i].in_off] = htole32(nb); /* * If required, write synchronously, otherwise use * delayed write. Modified: head/sys/fs/ext2fs/ext2_bmap.c ============================================================================== --- head/sys/fs/ext2fs/ext2_bmap.c Sun May 17 14:10:46 2020 (r361135) +++ head/sys/fs/ext2fs/ext2_bmap.c Sun May 17 14:52:54 2020 (r361136) @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -108,7 +109,7 @@ ext4_bmapext(struct vnode *vp, int32_t bn, int64_t *bn ump = VFSTOEXT2(mp); lbn = bn; ehp = (struct ext4_extent_header *)ip->i_data; - depth = ehp->eh_depth; + depth = le16toh(ehp->eh_depth); bsize = EXT2_BLOCK_SIZE(ump->um_e2fs); *bnp = -1; @@ -125,22 +126,26 @@ ext4_bmapext(struct vnode *vp, int32_t bn, int64_t *bn ep = path[depth].ep_ext; if(ep) { - if (lbn < ep->e_blk) { + if (lbn < le32toh(ep->e_blk)) { if (runp != NULL) { - *runp = min(maxrun, ep->e_blk - lbn - 1); + *runp = min(maxrun, le32toh(ep->e_blk) - lbn - 1); } - } else if (ep->e_blk <= lbn && lbn < ep->e_blk + ep->e_len) { - *bnp = fsbtodb(fs, lbn - ep->e_blk + - (ep->e_start_lo | (daddr_t)ep->e_start_hi << 32)); + } else if (le32toh(ep->e_blk) <= lbn && + lbn < le32toh(ep->e_blk) + le16toh(ep->e_len)) { + *bnp = fsbtodb(fs, lbn - le32toh(ep->e_blk) + + (le32toh(ep->e_start_lo) | + (daddr_t)le16toh(ep->e_start_hi) << 32)); if (runp != NULL) { *runp = min(maxrun, - ep->e_len - (lbn - ep->e_blk) - 1); + le16toh(ep->e_len) - + (lbn - le32toh(ep->e_blk)) - 1); } if (runb != NULL) - *runb = min(maxrun, lbn - ep->e_blk); + *runb = min(maxrun, lbn - le32toh(ep->e_blk)); } else { if (runb != NULL) - *runb = min(maxrun, ep->e_blk + lbn - ep->e_len); + *runb = min(maxrun, le32toh(ep->e_blk) + lbn - + le16toh(ep->e_len)); } } @@ -283,7 +288,7 @@ ext2_bmaparray(struct vnode *vp, daddr_t bn, daddr_t * if (error != 0) return (error); - daddr = ((e2fs_daddr_t *)bp->b_data)[ap->in_off]; + daddr = le32toh(((e2fs_daddr_t *)bp->b_data)[ap->in_off]); if (num == 1 && daddr && runp) { for (bn = ap->in_off + 1; bn < MNINDIR(ump) && *runp < maxrun && @@ -395,7 +400,7 @@ ext2_bmap_seekdata(struct vnode *vp, off_t *offp) */ off = ap->in_off; do { - daddr = ((e2fs_daddr_t *)bp->b_data)[off]; + daddr = le32toh(((e2fs_daddr_t *)bp->b_data)[off]); } while (daddr == 0 && ++off < MNINDIR(ump)); nextbn += off * lbn_count(ump, num - 1); Modified: head/sys/fs/ext2fs/ext2_csum.c ============================================================================== --- head/sys/fs/ext2fs/ext2_csum.c Sun May 17 14:10:46 2020 (r361135) +++ head/sys/fs/ext2fs/ext2_csum.c Sun May 17 14:52:54 2020 (r361136) @@ -77,7 +77,7 @@ ext2_sb_csum_set_seed(struct m_ext2fs *fs) { if (EXT2_HAS_INCOMPAT_FEATURE(fs, EXT2F_INCOMPAT_CSUM_SEED)) - fs->e2fs_csum_seed = fs->e2fs->e4fs_chksum_seed; + fs->e2fs_csum_seed = le32toh(fs->e2fs->e4fs_chksum_seed); else if (EXT2_HAS_RO_COMPAT_FEATURE(fs, EXT2F_ROCOMPAT_METADATA_CKSUM)) { fs->e2fs_csum_seed = calculate_crc32c(~0, fs->e2fs->e2fs_uuid, sizeof(fs->e2fs->e2fs_uuid)); @@ -95,13 +95,14 @@ ext2_sb_csum_verify(struct m_ext2fs *fs) "WARNING: mount of %s denied due bad sb csum type\n", fs->e2fs_fsmnt); return (EINVAL); } - if (fs->e2fs->e4fs_sbchksum != + if (le32toh(fs->e2fs->e4fs_sbchksum) != calculate_crc32c(~0, (const char *)fs->e2fs, offsetof(struct ext2fs, e4fs_sbchksum))) { printf( "WARNING: mount of %s denied due bad sb csum=0x%x, expected=0x%x - run fsck\n", - fs->e2fs_fsmnt, fs->e2fs->e4fs_sbchksum, calculate_crc32c(~0, - (const char *)fs->e2fs, offsetof(struct ext2fs, e4fs_sbchksum))); + fs->e2fs_fsmnt, le32toh(fs->e2fs->e4fs_sbchksum), + calculate_crc32c(~0, (const char *)fs->e2fs, + offsetof(struct ext2fs, e4fs_sbchksum))); return (EINVAL); } @@ -112,8 +113,9 @@ void ext2_sb_csum_set(struct m_ext2fs *fs) { - fs->e2fs->e4fs_sbchksum = calculate_crc32c(~0, (const char *)fs->e2fs, - offsetof(struct ext2fs, e4fs_sbchksum)); + fs->e2fs->e4fs_sbchksum = + htole32(calculate_crc32c(~0, (const char *)fs->e2fs, + offsetof(struct ext2fs, e4fs_sbchksum))); } static uint32_t @@ -121,18 +123,22 @@ ext2_extattr_blk_csum(struct inode *ip, uint64_t facl, struct ext2fs_extattr_header *header) { struct m_ext2fs *fs; - uint32_t crc, old_crc; + uint32_t crc, dummy_crc = 0; + uint64_t facl_bn = htole64(facl); + int offset = offsetof(struct ext2fs_extattr_header, h_checksum); fs = ip->i_e2fs; - old_crc = header->h_checksum; + crc = calculate_crc32c(fs->e2fs_csum_seed, (uint8_t *)&facl_bn, + sizeof(facl_bn)); + crc = calculate_crc32c(crc, (uint8_t *)header, offset); + crc = calculate_crc32c(crc, (uint8_t *)&dummy_crc, + sizeof(dummy_crc)); + offset += sizeof(dummy_crc); + crc = calculate_crc32c(crc, (uint8_t *)header + offset, + fs->e2fs_bsize - offset); - header->h_checksum = 0; - crc = calculate_crc32c(fs->e2fs_csum_seed, (uint8_t *)&facl, sizeof(facl)); - crc = calculate_crc32c(crc, (uint8_t *)header, fs->e2fs_bsize); - header->h_checksum = old_crc; - - return (crc); + return (htole32(crc)); } int @@ -167,7 +173,7 @@ void ext2_init_dirent_tail(struct ext2fs_direct_tail *tp) { memset(tp, 0, sizeof(struct ext2fs_direct_tail)); - tp->e2dt_rec_len = sizeof(struct ext2fs_direct_tail); + tp->e2dt_rec_len = le16toh(sizeof(struct ext2fs_direct_tail)); tp->e2dt_reserved_ft = EXT2_FT_DIR_CSUM; } @@ -184,7 +190,7 @@ ext2_is_dirent_tail(struct inode *ip, struct ext2fs_di tp = (struct ext2fs_direct_tail *)ep; if (tp->e2dt_reserved_zero1 == 0 && - tp->e2dt_rec_len == sizeof(struct ext2fs_direct_tail) && + le16toh(tp->e2dt_rec_len) == sizeof(struct ext2fs_direct_tail) && tp->e2dt_reserved_zero2 == 0 && tp->e2dt_reserved_ft == EXT2_FT_DIR_CSUM) return (1); @@ -201,13 +207,13 @@ ext2_dirent_get_tail(struct inode *ip, struct ext2fs_d dep = ep; top = EXT2_DIRENT_TAIL(ep, ip->i_e2fs->e2fs_bsize); - rec_len = dep->e2d_reclen; + rec_len = le16toh(dep->e2d_reclen); while (rec_len && !(rec_len & 0x3)) { dep = (struct ext2fs_direct_2 *)(((char *)dep) + rec_len); if ((void *)dep >= top) break; - rec_len = dep->e2d_reclen; + rec_len = le16toh(dep->e2d_reclen); } if (dep != top) @@ -230,8 +236,8 @@ ext2_dirent_csum(struct inode *ip, struct ext2fs_direc buf = (char *)ep; - inum = ip->i_number; - gen = ip->i_gen; + inum = htole32(ip->i_number); + gen = htole32(ip->i_gen); crc = calculate_crc32c(fs->e2fs_csum_seed, (uint8_t *)&inum, sizeof(inum)); crc = calculate_crc32c(crc, (uint8_t *)&gen, sizeof(gen)); crc = calculate_crc32c(crc, (uint8_t *)buf, size); @@ -250,7 +256,7 @@ ext2_dirent_csum_verify(struct inode *ip, struct ext2f return (0); calculated = ext2_dirent_csum(ip, ep, (char *)tp - (char *)ep); - if (calculated != tp->e2dt_checksum) + if (calculated != le32toh(tp->e2dt_checksum)) return (EIO); return (0); @@ -263,11 +269,11 @@ ext2_get_dx_count(struct inode *ip, struct ext2fs_dire struct ext2fs_htree_root_info *root; int count_offset; - if (ep->e2d_reclen == EXT2_BLOCK_SIZE(ip->i_e2fs)) + if (le16toh(ep->e2d_reclen) == EXT2_BLOCK_SIZE(ip->i_e2fs)) count_offset = 8; - else if (ep->e2d_reclen == 12) { + else if (le16toh(ep->e2d_reclen) == 12) { dp = (struct ext2fs_direct_2 *)(((char *)ep) + 12); - if (dp->e2d_reclen != EXT2_BLOCK_SIZE(ip->i_e2fs) - 12) + if (le16toh(dp->e2d_reclen) != EXT2_BLOCK_SIZE(ip->i_e2fs) - 12) return (NULL); root = (struct ext2fs_htree_root_info *)(((char *)dp + 12)); @@ -302,15 +308,15 @@ ext2_dx_csum(struct inode *ip, struct ext2fs_direct_2 old_csum = tp->ht_checksum; tp->ht_checksum = 0; - inum = ip->i_number; - gen = ip->i_gen; + inum = htole32(ip->i_number); + gen = htole32(ip->i_gen); crc = calculate_crc32c(fs->e2fs_csum_seed, (uint8_t *)&inum, sizeof(inum)); crc = calculate_crc32c(crc, (uint8_t *)&gen, sizeof(gen)); crc = calculate_crc32c(crc, (uint8_t *)buf, size); crc = calculate_crc32c(crc, (uint8_t *)tp, sizeof(struct ext2fs_htree_tail)); tp->ht_checksum = old_csum; - return (crc); + return htole32(crc); } int @@ -325,8 +331,8 @@ ext2_dx_csum_verify(struct inode *ip, struct ext2fs_di if (cp == NULL) return (0); - limit = cp->h_entries_max; - count = cp->h_entries_num; + limit = le16toh(cp->h_entries_max); + count = le16toh(cp->h_entries_num); if (count_offset + (limit * sizeof(struct ext2fs_htree_entry)) > ip->i_e2fs->e2fs_bsize - sizeof(struct ext2fs_htree_tail)) return (EIO); @@ -381,7 +387,7 @@ ext2_dirent_csum_set(struct inode *ip, struct ext2fs_d return; tp->e2dt_checksum = - ext2_dirent_csum(ip, ep, (char *)tp - (char *)ep); + htole32(ext2_dirent_csum(ip, ep, (char *)tp - (char *)ep)); } void @@ -401,8 +407,8 @@ ext2_dx_csum_set(struct inode *ip, struct ext2fs_direc if (cp == NULL) return; - limit = cp->h_entries_max; - count = cp->h_entries_num; + limit = le16toh(cp->h_entries_max); + count = le16toh(cp->h_entries_num); if (count_offset + (limit * sizeof(struct ext2fs_htree_entry)) > ip->i_e2fs->e2fs_bsize - sizeof(struct ext2fs_htree_tail)) return; @@ -423,8 +429,8 @@ ext2_extent_blk_csum(struct inode *ip, struct ext4_ext size = EXT4_EXTENT_TAIL_OFFSET(ehp) + offsetof(struct ext4_extent_tail, et_checksum); - inum = ip->i_number; - gen = ip->i_gen; + inum = htole32(ip->i_number); + gen = htole32(ip->i_gen); crc = calculate_crc32c(fs->e2fs_csum_seed, (uint8_t *)&inum, sizeof(inum)); crc = calculate_crc32c(crc, (uint8_t *)&gen, sizeof(gen)); crc = calculate_crc32c(crc, (uint8_t *)ehp, size); @@ -449,7 +455,7 @@ ext2_extent_blk_csum_verify(struct inode *ip, void *da etp = (struct ext4_extent_tail *)(((char *)ehp) + EXT4_EXTENT_TAIL_OFFSET(ehp)); - provided = etp->et_checksum; + provided = le32toh(etp->et_checksum); calculated = ext2_extent_blk_csum(ip, ehp); if (provided != calculated) { @@ -476,8 +482,8 @@ ext2_extent_blk_csum_set(struct inode *ip, void *data) etp = (struct ext4_extent_tail *)(((char *)data) + EXT4_EXTENT_TAIL_OFFSET(ehp)); - etp->et_checksum = ext2_extent_blk_csum(ip, - (struct ext4_extent_header *)data); + etp->et_checksum = htole32(ext2_extent_blk_csum(ip, + (struct ext4_extent_header *)data)); } int @@ -488,11 +494,12 @@ ext2_gd_i_bitmap_csum_verify(struct m_ext2fs *fs, int if (!EXT2_HAS_RO_COMPAT_FEATURE(fs, EXT2F_ROCOMPAT_METADATA_CKSUM)) return (0); - provided = fs->e2fs_gd[cg].ext4bgd_i_bmap_csum; + provided = le16toh(fs->e2fs_gd[cg].ext4bgd_i_bmap_csum); calculated = calculate_crc32c(fs->e2fs_csum_seed, bp->b_data, - fs->e2fs->e2fs_ipg / 8); - if (fs->e2fs->e3fs_desc_size >= EXT2_BG_INODE_BITMAP_CSUM_HI_END) { - hi = fs->e2fs_gd[cg].ext4bgd_i_bmap_csum_hi; + fs->e2fs_ipg / 8); + if (le16toh(fs->e2fs->e3fs_desc_size) >= + EXT2_BG_INODE_BITMAP_CSUM_HI_END) { + hi = le16toh(fs->e2fs_gd[cg].ext4bgd_i_bmap_csum_hi); provided |= (hi << 16); } else calculated &= 0xFFFF; @@ -514,10 +521,10 @@ ext2_gd_i_bitmap_csum_set(struct m_ext2fs *fs, int cg, return; csum = calculate_crc32c(fs->e2fs_csum_seed, bp->b_data, - fs->e2fs->e2fs_ipg / 8); - fs->e2fs_gd[cg].ext4bgd_i_bmap_csum = csum & 0xFFFF; - if (fs->e2fs->e3fs_desc_size >= EXT2_BG_INODE_BITMAP_CSUM_HI_END) - fs->e2fs_gd[cg].ext4bgd_i_bmap_csum_hi = csum >> 16; + fs->e2fs_ipg / 8); + fs->e2fs_gd[cg].ext4bgd_i_bmap_csum = htole16(csum & 0xFFFF); + if (le16toh(fs->e2fs->e3fs_desc_size) >= EXT2_BG_INODE_BITMAP_CSUM_HI_END) + fs->e2fs_gd[cg].ext4bgd_i_bmap_csum_hi = htole16(csum >> 16); } int @@ -529,10 +536,11 @@ ext2_gd_b_bitmap_csum_verify(struct m_ext2fs *fs, int return (0); size = fs->e2fs_fpg / 8; - provided = fs->e2fs_gd[cg].ext4bgd_b_bmap_csum; + provided = le16toh(fs->e2fs_gd[cg].ext4bgd_b_bmap_csum); calculated = calculate_crc32c(fs->e2fs_csum_seed, bp->b_data, size); - if (fs->e2fs->e3fs_desc_size >= EXT2_BG_BLOCK_BITMAP_CSUM_HI_LOCATION) { - hi = fs->e2fs_gd[cg].ext4bgd_b_bmap_csum_hi; + if (le16toh(fs->e2fs->e3fs_desc_size) >= + EXT2_BG_BLOCK_BITMAP_CSUM_HI_LOCATION) { + hi = le16toh(fs->e2fs_gd[cg].ext4bgd_b_bmap_csum_hi); provided |= (hi << 16); } else calculated &= 0xFFFF; @@ -555,9 +563,9 @@ ext2_gd_b_bitmap_csum_set(struct m_ext2fs *fs, int cg, size = fs->e2fs_fpg / 8; csum = calculate_crc32c(fs->e2fs_csum_seed, bp->b_data, size); - fs->e2fs_gd[cg].ext4bgd_b_bmap_csum = csum & 0xFFFF; - if (fs->e2fs->e3fs_desc_size >= EXT2_BG_BLOCK_BITMAP_CSUM_HI_LOCATION) - fs->e2fs_gd[cg].ext4bgd_b_bmap_csum_hi = csum >> 16; + fs->e2fs_gd[cg].ext4bgd_b_bmap_csum = htole16(csum & 0xFFFF); + if (le16toh(fs->e2fs->e3fs_desc_size) >= EXT2_BG_BLOCK_BITMAP_CSUM_HI_LOCATION) + fs->e2fs_gd[cg].ext4bgd_b_bmap_csum_hi = htole16(csum >> 16); } static uint32_t @@ -571,10 +579,10 @@ ext2_ei_csum(struct inode *ip, struct ext2fs_dinode *e fs = ip->i_e2fs; offset = offsetof(struct ext2fs_dinode, e2di_chksum_lo); csum_size = sizeof(dummy_csum); - inum = ip->i_number; + inum = htole32(ip->i_number); crc = calculate_crc32c(fs->e2fs_csum_seed, (uint8_t *)&inum, sizeof(inum)); - gen = ip->i_gen; + gen = htole32(ip->i_gen); inode_csum_seed = calculate_crc32c(crc, (uint8_t *)&gen, sizeof(gen)); @@ -590,7 +598,8 @@ ext2_ei_csum(struct inode *ip, struct ext2fs_dinode *e E2FS_REV0_INODE_SIZE, offset - E2FS_REV0_INODE_SIZE); if ((EXT2_INODE_SIZE(ip->i_e2fs) > E2FS_REV0_INODE_SIZE && - ei->e2di_extra_isize >= EXT2_INODE_CSUM_HI_EXTRA_END)) { + le16toh(ei->e2di_extra_isize) >= + EXT2_INODE_CSUM_HI_EXTRA_END)) { crc = calculate_crc32c(crc, (uint8_t *)&dummy_csum, csum_size); offset += csum_size; @@ -615,12 +624,12 @@ ext2_ei_csum_verify(struct inode *ip, struct ext2fs_di if (!EXT2_HAS_RO_COMPAT_FEATURE(fs, EXT2F_ROCOMPAT_METADATA_CKSUM)) return (0); - provided = ei->e2di_chksum_lo; + provided = le16toh(ei->e2di_chksum_lo); calculated = ext2_ei_csum(ip, ei); if ((EXT2_INODE_SIZE(fs) > E2FS_REV0_INODE_SIZE && - ei->e2di_extra_isize >= EXT2_INODE_CSUM_HI_EXTRA_END)) { - hi = ei->e2di_chksum_hi; + le16toh(ei->e2di_extra_isize) >= EXT2_INODE_CSUM_HI_EXTRA_END)) { + hi = le16toh(ei->e2di_chksum_hi); provided |= hi << 16; } else calculated &= 0xFFFF; @@ -655,10 +664,10 @@ ext2_ei_csum_set(struct inode *ip, struct ext2fs_dinod crc = ext2_ei_csum(ip, ei); - ei->e2di_chksum_lo = crc & 0xFFFF; + ei->e2di_chksum_lo = htole16(crc & 0xFFFF); if ((EXT2_INODE_SIZE(fs) > E2FS_REV0_INODE_SIZE && - ei->e2di_extra_isize >= EXT2_INODE_CSUM_HI_EXTRA_END)) - ei->e2di_chksum_hi = crc >> 16; + le16toh(ei->e2di_extra_isize) >= EXT2_INODE_CSUM_HI_EXTRA_END)) + ei->e2di_chksum_hi = htole16(crc >> 16); } static uint16_t @@ -716,6 +725,8 @@ ext2_gd_csum(struct m_ext2fs *fs, uint32_t block_group offset = offsetof(struct ext2_gd, ext4bgd_csum); + block_group = htole32(block_group); + if (EXT2_HAS_RO_COMPAT_FEATURE(fs, EXT2F_ROCOMPAT_METADATA_CKSUM)) { csum32 = calculate_crc32c(fs->e2fs_csum_seed, (uint8_t *)&block_group, sizeof(block_group)); @@ -724,12 +735,12 @@ ext2_gd_csum(struct m_ext2fs *fs, uint32_t block_group csum32 = calculate_crc32c(csum32, (uint8_t *)&dummy_csum, sizeof(dummy_csum)); offset += sizeof(dummy_csum); - if (offset < fs->e2fs->e3fs_desc_size) + if (offset < le16toh(fs->e2fs->e3fs_desc_size)) csum32 = calculate_crc32c(csum32, (uint8_t *)gd + offset, - fs->e2fs->e3fs_desc_size - offset); + le16toh(fs->e2fs->e3fs_desc_size) - offset); crc = csum32 & 0xFFFF; - return (crc); + return (htole16(crc)); } else if (EXT2_HAS_RO_COMPAT_FEATURE(fs, EXT2F_ROCOMPAT_GDT_CSUM)) { crc = ext2_crc16(~0, fs->e2fs->e2fs_uuid, sizeof(fs->e2fs->e2fs_uuid)); @@ -738,10 +749,10 @@ ext2_gd_csum(struct m_ext2fs *fs, uint32_t block_group crc = ext2_crc16(crc, (uint8_t *)gd, offset); offset += sizeof(gd->ext4bgd_csum); /* skip checksum */ if (EXT2_HAS_INCOMPAT_FEATURE(fs, EXT2F_INCOMPAT_64BIT) && - offset < fs->e2fs->e3fs_desc_size) + offset < le16toh(fs->e2fs->e3fs_desc_size)) crc = ext2_crc16(crc, (uint8_t *)gd + offset, - fs->e2fs->e3fs_desc_size - offset); - return (crc); + le16toh(fs->e2fs->e3fs_desc_size) - offset); + return (htole16(crc)); } return (0); @@ -774,6 +785,5 @@ ext2_gd_csum_set(struct m_ext2fs *fs) unsigned int i; for (i = 0; i < fs->e2fs_gcount; i++) - fs->e2fs_gd[i].ext4bgd_csum = - ext2_gd_csum(fs, i, &fs->e2fs_gd[i]); + fs->e2fs_gd[i].ext4bgd_csum = ext2_gd_csum(fs, i, &fs->e2fs_gd[i]); } Modified: head/sys/fs/ext2fs/ext2_extattr.c ============================================================================== --- head/sys/fs/ext2fs/ext2_extattr.c Sun May 17 14:10:46 2020 (r361135) +++ head/sys/fs/ext2fs/ext2_extattr.c Sun May 17 14:52:54 2020 (r361136) @@ -216,9 +216,9 @@ ext2_extattr_inode_list(struct inode *ip, int attrname /* Check attributes magic value */ header = (struct ext2fs_extattr_dinode_header *)((char *)dinode + - E2FS_REV0_INODE_SIZE + dinode->e2di_extra_isize); + E2FS_REV0_INODE_SIZE + le16toh(dinode->e2di_extra_isize)); - if (header->h_magic != EXTATTR_MAGIC) { + if (le32toh(header->h_magic) != EXTATTR_MAGIC) { brelse(bp); return (0); } @@ -285,7 +285,8 @@ ext2_extattr_block_list(struct inode *ip, int attrname /* Check attributes magic value */ header = EXT2_HDR(bp); - if (header->h_magic != EXTATTR_MAGIC || header->h_blocks != 1) { + if (le32toh(header->h_magic) != EXTATTR_MAGIC || + le32toh(header->h_blocks) != 1) { brelse(bp); return (EINVAL); *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***