diff --git a/libcustomext2fs/include/ext2.h b/libcustomext2fs/include/ext2.h index 059e18be..7b6bc868 100644 --- a/libcustomext2fs/include/ext2.h +++ b/libcustomext2fs/include/ext2.h @@ -1,22 +1,22 @@ - /** - * ext2.h - devoptab file routines for EXT2/3/4-based devices. - * - * Copyright (c) 2010 Dimok - * - * This program/include file is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program/include file is distributed in the hope that it will be - * useful, but WITHOUT ANY WARRANTY; without even the implied warranty - * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ +/******************************************************************************** + * ext2.h - devoptab file routines for EXT2/3/4-based devices. * + * * + * Copyright (c) 2010 Dimok * + * * + * This program/include file is free software; you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as published * + * by the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program/include file is distributed in the hope that it will be * + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty * + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software Foundation, * + * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * + ********************************************************************************/ #ifndef __EXT2_H_ #define __EXT2_H_ @@ -28,17 +28,24 @@ extern "C" { #include #include -/* EXT2 cache options */ -#define CACHE_DEFAULT_PAGE_COUNT 8 /* The default number of pages in the cache */ -#define CACHE_DEFAULT_PAGE_SIZE 128 /* The default number of sectors per cache page */ +/** + * EXT2 cache options + * + * It is recommended to use more pages instead of large page sizes for cache due to the sporadic write behaviour of ext file system. + * It will significantly increase the speed. A page size of 32 is mostly suffiecient. The larger the page count the faster the + * read/write between smaller files will be. Larger page sizes result in faster read/write of single big files. + */ +#define EXT2_CACHE_DEFAULT_PAGE_COUNT 64 /* The default number of pages in the cache */ +#define EXT2_CACHE_DEFAULT_PAGE_SIZE 32 /* The default number of sectors per cache page */ /* EXT2 mount flags */ -#define EXT2_FLAG_RW 0x00001 /* Open the filesystem for reading and writing. Without this flag, the filesystem is opened for reading only. */ -#define EXT2_FLAG_FORCE 0x00400 /* Open the filesystem regardless of the feature sets listed in the superblock */ -#define EXT2_FLAG_JOURNAL_DEV_OK 0x01000 /* Only open external journal devices if this flag is set (e.g. ext3/ext4) */ -#define EXT2_FLAG_64BITS 0x20000 /* Use the new style 64-Bit bitmaps. For more information see gen_bitmap64.c */ -#define EXT2_FLAG_PRINT_PROGRESS 0x40000 /* If this flag is set the progress of file operations will be printed to stdout */ -#define EXT2_FLAG_DEFAULT (EXT2_FLAG_RW | EXT2_FLAG_64BITS | EXT2_FLAG_JOURNAL_DEV_OK) +#define EXT2_FLAG_RW 0x00001 /* Open the filesystem for reading and writing. Without this flag, the filesystem is opened for reading only. */ +#define EXT2_FLAG_FORCE 0x00400 /* Open the filesystem regardless of the feature sets listed in the superblock */ +#define EXT2_FLAG_JOURNAL_DEV_OK 0x01000 /* Only open external journal devices if this flag is set (e.g. ext3/ext4) */ +#define EXT2_FLAG_64BITS 0x20000 /* Use the new style 64-Bit bitmaps. For more information see gen_bitmap64.c */ +#define EXT2_FLAG_PRINT_PROGRESS 0x40000 /* If this flag is set the progress of file operations will be printed to stdout */ +#define EXT2_FLAG_SKIP_MMP 0x100000 /* Open without multi-mount protection check. */ +#define EXT2_FLAG_DEFAULT (EXT2_FLAG_RW | EXT2_FLAG_64BITS | EXT2_FLAG_JOURNAL_DEV_OK | EXT2_FLAG_SKIP_MMP) /** * Find all EXT2/3/4 partitions on a block device. diff --git a/libcustomext2fs/source/Makefile b/libcustomext2fs/source/Makefile index c2fabaa2..93fb8aa0 100644 --- a/libcustomext2fs/source/Makefile +++ b/libcustomext2fs/source/Makefile @@ -28,9 +28,7 @@ LIBDIR := ../lib #--------------------------------------------------------------------------------- # options for code generation #--------------------------------------------------------------------------------- -CFLAGS = -O3 -Wall $(MACHDEP) $(INCLUDE) -DGEKKO \ - -DHAVE_UNISTD_H -DHAVE_SYS_STAT_H -DHAVE_SYS_TYPES_H -DHAVE_UTIME_H -DWORDS_BIGENDIAN \ - -DHAVE_ERRNO_H -DHAVE_STRDUP -DHAVE_SYS_RESOURCE_H +CFLAGS = -Os -Wall -Wno-unused $(MACHDEP) $(INCLUDE) -DGEKKO -DWORDS_BIGENDIAN CXXFLAGS = $(CFLAGS) ASFLAGS := -g export EXT2BIN := $(LIBDIR)/$(PLATFORM)/libext2fs.a diff --git a/libcustomext2fs/source/alloc.c b/libcustomext2fs/source/alloc.c index 3a8f3328..948a0ecb 100644 --- a/libcustomext2fs/source/alloc.c +++ b/libcustomext2fs/source/alloc.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #if HAVE_UNISTD_H #include @@ -52,6 +53,11 @@ static void check_block_uninit(ext2_filsys fs, ext2fs_block_bitmap map, else old_desc_blocks = fs->desc_blocks + fs->super->s_reserved_gdt_blocks; + for (i=0; i < fs->super->s_blocks_per_group; i++, blk++) + ext2fs_fast_unmark_block_bitmap2(map, blk); + + blk = (group * fs->super->s_blocks_per_group) + + fs->super->s_first_data_block; for (i=0; i < fs->super->s_blocks_per_group; i++, blk++) { if ((blk == super_blk) || (old_desc_blk && old_desc_blocks && @@ -64,8 +70,6 @@ static void check_block_uninit(ext2_filsys fs, ext2fs_block_bitmap map, (blk < ext2fs_inode_table_loc(fs, group) + fs->inode_blocks_per_group))) ext2fs_fast_mark_block_bitmap2(map, blk); - else - ext2fs_fast_unmark_block_bitmap2(map, blk); } ext2fs_bg_flags_clear(fs, group, EXT2_BG_BLOCK_UNINIT); ext2fs_group_desc_csum_set(fs, group); @@ -149,6 +153,7 @@ errcode_t ext2fs_new_block2(ext2_filsys fs, blk64_t goal, ext2fs_block_bitmap map, blk64_t *ret) { blk64_t i; + int c_ratio; EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); @@ -159,6 +164,9 @@ errcode_t ext2fs_new_block2(ext2_filsys fs, blk64_t goal, if (!goal || (goal >= ext2fs_blocks_count(fs->super))) goal = fs->super->s_first_data_block; i = goal; + c_ratio = 1 << ext2fs_get_bitmap_granularity(map); + if (c_ratio > 1) + goal &= ~EXT2FS_CLUSTER_MASK(fs); check_block_uninit(fs, map, (i - fs->super->s_first_data_block) / EXT2_BLOCKS_PER_GROUP(fs->super)); @@ -173,7 +181,7 @@ errcode_t ext2fs_new_block2(ext2_filsys fs, blk64_t goal, *ret = i; return 0; } - i++; + i = (i + c_ratio) & ~(c_ratio - 1); if (i >= ext2fs_blocks_count(fs->super)) i = fs->super->s_first_data_block; } while (i != goal); @@ -254,6 +262,7 @@ errcode_t ext2fs_get_free_blocks2(ext2_filsys fs, blk64_t start, blk64_t finish, int num, ext2fs_block_bitmap map, blk64_t *ret) { blk64_t b = start; + int c_ratio; EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); @@ -267,6 +276,9 @@ errcode_t ext2fs_get_free_blocks2(ext2_filsys fs, blk64_t start, blk64_t finish, finish = start; if (!num) num = 1; + c_ratio = 1 << ext2fs_get_bitmap_granularity(map); + b &= ~(c_ratio - 1); + finish &= ~(c_ratio -1); do { if (b+num-1 > ext2fs_blocks_count(fs->super)) b = fs->super->s_first_data_block; @@ -274,7 +286,7 @@ errcode_t ext2fs_get_free_blocks2(ext2_filsys fs, blk64_t start, blk64_t finish, *ret = b; return 0; } - b++; + b += c_ratio; } while (b != finish); return EXT2_ET_BLOCK_ALLOC_FAIL; } diff --git a/libcustomext2fs/source/alloc_sb.c b/libcustomext2fs/source/alloc_sb.c index d5fca3b2..0d1c0000 100644 --- a/libcustomext2fs/source/alloc_sb.c +++ b/libcustomext2fs/source/alloc_sb.c @@ -10,6 +10,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H @@ -59,6 +60,9 @@ int ext2fs_reserve_super_and_bgd(ext2_filsys fs, if (super_blk || (group == 0)) ext2fs_mark_block_bitmap2(bmap, super_blk); + if ((group == 0) && (fs->blocksize == 1024) && + EXT2FS_CLUSTER_RATIO(fs) > 1) + ext2fs_mark_block_bitmap2(bmap, 0); if (old_desc_blk) { if (fs->super->s_reserved_gdt_blocks && fs->block_map == bmap) @@ -71,15 +75,7 @@ int ext2fs_reserve_super_and_bgd(ext2_filsys fs, if (new_desc_blk) ext2fs_mark_block_bitmap2(bmap, new_desc_blk); - if (group == fs->group_desc_count-1) { - num_blocks = (ext2fs_blocks_count(fs->super) - - fs->super->s_first_data_block) % - fs->super->s_blocks_per_group; - if (!num_blocks) - num_blocks = fs->super->s_blocks_per_group; - } else - num_blocks = fs->super->s_blocks_per_group; - + num_blocks = ext2fs_group_blocks_count(fs, group); num_blocks -= 2 + fs->inode_blocks_per_group + used_blks; return num_blocks ; diff --git a/libcustomext2fs/source/alloc_stats.c b/libcustomext2fs/source/alloc_stats.c index 0f276659..adec3636 100644 --- a/libcustomext2fs/source/alloc_stats.c +++ b/libcustomext2fs/source/alloc_stats.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #include "ext2_fs.h" @@ -77,7 +78,8 @@ void ext2fs_block_alloc_stats2(ext2_filsys fs, blk64_t blk, int inuse) ext2fs_bg_flags_clear(fs, group, EXT2_BG_BLOCK_UNINIT); ext2fs_group_desc_csum_set(fs, group); - ext2fs_free_blocks_count_add(fs->super, -inuse); + ext2fs_free_blocks_count_add(fs->super, + -inuse * EXT2FS_CLUSTER_RATIO(fs)); ext2fs_mark_super_dirty(fs); ext2fs_mark_bb_dirty(fs); if (fs->block_alloc_stats) diff --git a/libcustomext2fs/source/alloc_tables.c b/libcustomext2fs/source/alloc_tables.c index 1c4532b6..9f3d4e04 100644 --- a/libcustomext2fs/source/alloc_tables.c +++ b/libcustomext2fs/source/alloc_tables.c @@ -10,6 +10,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H @@ -35,45 +36,45 @@ * tables can be allocated continously and in order. */ static blk64_t flexbg_offset(ext2_filsys fs, dgrp_t group, blk64_t start_blk, - ext2fs_block_bitmap bmap, int offset, int size, + ext2fs_block_bitmap bmap, int rem_grp, int elem_size) { - int flexbg, flexbg_size; + int flexbg, flexbg_size, size; blk64_t last_blk, first_free = 0; dgrp_t last_grp; flexbg_size = 1 << fs->super->s_log_groups_per_flex; flexbg = group / flexbg_size; + size = rem_grp * elem_size; if (size > (int) (fs->super->s_blocks_per_group / 8)) size = (int) fs->super->s_blocks_per_group / 8; - if (offset) - offset -= 1; - /* * Don't do a long search if the previous block * search is still valid. */ - if (start_blk && group % flexbg_size) { - if (ext2fs_test_block_bitmap_range2(bmap, start_blk + elem_size, - size)) - return start_blk + elem_size; - } + if (start_blk && ext2fs_test_block_bitmap_range2(bmap, start_blk, + elem_size)) + return start_blk; start_blk = ext2fs_group_first_block2(fs, flexbg_size * flexbg); last_grp = group | (flexbg_size - 1); - if (last_grp > fs->group_desc_count) - last_grp = fs->group_desc_count; + if (last_grp > fs->group_desc_count-1) + last_grp = fs->group_desc_count-1; last_blk = ext2fs_group_last_block2(fs, last_grp); /* Find the first available block */ - if (ext2fs_get_free_blocks2(fs, start_blk, last_blk, 1, bmap, - &first_free)) + if (ext2fs_get_free_blocks2(fs, start_blk, last_blk, size, + bmap, &first_free) == 0) return first_free; - if (ext2fs_get_free_blocks2(fs, first_free + offset, last_blk, size, - bmap, &first_free)) + if (ext2fs_get_free_blocks2(fs, start_blk, last_blk, elem_size, + bmap, &first_free) == 0) + return first_free; + + if (ext2fs_get_free_blocks2(fs, 0, last_blk, elem_size, bmap, + &first_free) == 0) return first_free; return first_free; @@ -82,10 +83,11 @@ static blk64_t flexbg_offset(ext2_filsys fs, dgrp_t group, blk64_t start_blk, errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group, ext2fs_block_bitmap bmap) { + unsigned int j; errcode_t retval; blk64_t group_blk, start_blk, last_blk, new_blk, blk; dgrp_t last_grp = 0; - int j, rem_grps = 0, flexbg_size = 0; + int rem_grps = 0, flexbg_size = 0; group_blk = ext2fs_group_first_block2(fs, group); last_blk = ext2fs_group_last_block2(fs, group); @@ -98,9 +100,9 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group, fs->super->s_log_groups_per_flex) { flexbg_size = 1 << fs->super->s_log_groups_per_flex; last_grp = group | (flexbg_size - 1); - rem_grps = last_grp - group; - if (last_grp > fs->group_desc_count) - last_grp = fs->group_desc_count; + if (last_grp > fs->group_desc_count-1) + last_grp = fs->group_desc_count-1; + rem_grps = last_grp - group + 1; } /* @@ -122,10 +124,10 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group, if (flexbg_size) { blk64_t prev_block = 0; - if (group && ext2fs_block_bitmap_loc(fs, group - 1)) - prev_block = ext2fs_block_bitmap_loc(fs, group - 1); + if (group % flexbg_size) + prev_block = ext2fs_block_bitmap_loc(fs, group - 1) + 1; start_blk = flexbg_offset(fs, group, prev_block, bmap, - 0, rem_grps, 1); + rem_grps, 1); last_blk = ext2fs_group_last_block2(fs, last_grp); } @@ -150,10 +152,13 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group, if (flexbg_size) { blk64_t prev_block = 0; - if (group && ext2fs_inode_bitmap_loc(fs, group - 1)) - prev_block = ext2fs_inode_bitmap_loc(fs, group - 1); + if (group % flexbg_size) + prev_block = ext2fs_inode_bitmap_loc(fs, group - 1) + 1; + else + prev_block = ext2fs_block_bitmap_loc(fs, group) + + flexbg_size; start_blk = flexbg_offset(fs, group, prev_block, bmap, - flexbg_size, rem_grps, 1); + rem_grps, 1); last_blk = ext2fs_group_last_block2(fs, last_grp); } @@ -181,15 +186,16 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group, */ if (flexbg_size) { blk64_t prev_block = 0; - if (group && ext2fs_inode_table_loc(fs, group - 1)) - prev_block = ext2fs_inode_table_loc(fs, group - 1); - if (last_grp == fs->group_desc_count) - rem_grps = last_grp - group; + + if (group % flexbg_size) + prev_block = ext2fs_inode_table_loc(fs, group - 1) + + fs->inode_blocks_per_group; + else + prev_block = ext2fs_inode_bitmap_loc(fs, group) + + flexbg_size; + group_blk = flexbg_offset(fs, group, prev_block, bmap, - flexbg_size * 2, - fs->inode_blocks_per_group * - rem_grps, - fs->inode_blocks_per_group); + rem_grps, fs->inode_blocks_per_group); last_blk = ext2fs_group_last_block2(fs, last_grp); } diff --git a/libcustomext2fs/source/badblocks.c b/libcustomext2fs/source/badblocks.c index 5eb28b78..0f23983b 100644 --- a/libcustomext2fs/source/badblocks.c +++ b/libcustomext2fs/source/badblocks.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H @@ -177,7 +178,7 @@ int ext2fs_u32_list_find(ext2_u32_list bb, __u32 blk) return high; while (low < high) { - mid = (low+high)/2; + mid = ((unsigned)low + (unsigned)high)/2; if (mid == low || mid == high) break; if (blk == bb->list[mid]) diff --git a/libcustomext2fs/source/bb_compat.c b/libcustomext2fs/source/bb_compat.c index a94e3e48..373792a2 100644 --- a/libcustomext2fs/source/bb_compat.c +++ b/libcustomext2fs/source/bb_compat.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H diff --git a/libcustomext2fs/source/bb_inode.c b/libcustomext2fs/source/bb_inode.c index 0b6c3dd2..268eecf8 100644 --- a/libcustomext2fs/source/bb_inode.c +++ b/libcustomext2fs/source/bb_inode.c @@ -13,6 +13,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H diff --git a/libcustomext2fs/source/bitmaps.c b/libcustomext2fs/source/bitmaps.c index c53d61ec..e518295d 100644 --- a/libcustomext2fs/source/bitmaps.c +++ b/libcustomext2fs/source/bitmaps.c @@ -10,6 +10,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H @@ -27,6 +28,7 @@ #include "ext2_fs.h" #include "ext2fs.h" #include "ext2fsP.h" +#include "bmap64.h" void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap) { @@ -90,9 +92,9 @@ errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs, fs->write_bitmaps = ext2fs_write_bitmaps; - start = fs->super->s_first_data_block; - end = ext2fs_blocks_count(fs->super)-1; - real_end = ((__u64) EXT2_BLOCKS_PER_GROUP(fs->super) + start = EXT2FS_B2C(fs, fs->super->s_first_data_block); + end = EXT2FS_B2C(fs, ext2fs_blocks_count(fs->super)-1); + real_end = ((__u64) EXT2_CLUSTERS_PER_GROUP(fs->super) * (__u64) fs->group_desc_count)-1 + start; if (fs->flags & EXT2_FLAG_64BITS) @@ -110,6 +112,56 @@ errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs, (ext2fs_generic_bitmap *) ret)); } +/* + * ext2fs_allocate_block_bitmap() really allocates a per-cluster + * bitmap for backwards compatibility. This function allocates a + * block bitmap which is truly per-block, even if clusters/bigalloc + * are enabled. mke2fs and e2fsck need this for tracking the + * allocation of the file system metadata blocks. + */ +errcode_t ext2fs_allocate_subcluster_bitmap(ext2_filsys fs, + const char *descr, + ext2fs_block_bitmap *ret) +{ + __u64 start, end, real_end; + ext2fs_generic_bitmap bmap; + errcode_t retval; + + EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); + + fs->write_bitmaps = ext2fs_write_bitmaps; + + if (!fs->cluster_ratio_bits) + return ext2fs_allocate_block_bitmap(fs, descr, ret); + + if ((fs->flags & EXT2_FLAG_64BITS) == 0) + return EXT2_ET_CANT_USE_LEGACY_BITMAPS; + + start = fs->super->s_first_data_block; + end = ext2fs_blocks_count(fs->super)-1; + real_end = ((__u64) EXT2_BLOCKS_PER_GROUP(fs->super) + * (__u64) fs->group_desc_count)-1 + start; + + retval = ext2fs_alloc_generic_bmap(fs, EXT2_ET_MAGIC_BLOCK_BITMAP64, + EXT2FS_BMAP64_BITARRAY, start, + end, real_end, descr, &bmap); + if (retval) + return retval; + bmap->cluster_bits = 0; + *ret = bmap; + return 0; +} + +int ext2fs_get_bitmap_granularity(ext2fs_block_bitmap bitmap) +{ + ext2fs_generic_bitmap bmap = bitmap; + + if (!EXT2FS_IS_64_BITMAP(bmap)) + return 0; + + return bmap->cluster_bits; +} + errcode_t ext2fs_fudge_inode_bitmap_end(ext2fs_inode_bitmap bitmap, ext2_ino_t end, ext2_ino_t *oend) { diff --git a/libcustomext2fs/source/bitops.c b/libcustomext2fs/source/bitops.c index a3f72c31..9322a353 100644 --- a/libcustomext2fs/source/bitops.c +++ b/libcustomext2fs/source/bitops.c @@ -10,6 +10,7 @@ * %End-Header% */ +#include "config.h" #include #if HAVE_SYS_TYPES_H #include diff --git a/libcustomext2fs/source/bitops.h b/libcustomext2fs/source/bitops.h index bf6ee82a..a7412833 100644 --- a/libcustomext2fs/source/bitops.h +++ b/libcustomext2fs/source/bitops.h @@ -12,6 +12,8 @@ #ifndef _BITOPS_H_ #define _BITOPS_H_ +#include "config.h" + extern int ext2fs_set_bit(unsigned int nr,void * addr); extern int ext2fs_clear_bit(unsigned int nr, void * addr); extern int ext2fs_test_bit(unsigned int nr, const void * addr); @@ -33,6 +35,8 @@ extern __u64 ext2fs_swab64(__u64 val); #define ext2fs_le32_to_cpu(x) ext2fs_swab32((x)) #define ext2fs_cpu_to_le16(x) ext2fs_swab16((x)) #define ext2fs_le16_to_cpu(x) ext2fs_swab16((x)) +#define ext2fs_cpu_to_be64(x) ((__u64)(x)) +#define ext2fs_be64_to_cpu(x) ((__u64)(x)) #define ext2fs_cpu_to_be32(x) ((__u32)(x)) #define ext2fs_be32_to_cpu(x) ((__u32)(x)) #define ext2fs_cpu_to_be16(x) ((__u16)(x)) @@ -44,6 +48,8 @@ extern __u64 ext2fs_swab64(__u64 val); #define ext2fs_le32_to_cpu(x) ((__u32)(x)) #define ext2fs_cpu_to_le16(x) ((__u16)(x)) #define ext2fs_le16_to_cpu(x) ((__u16)(x)) +#define ext2fs_cpu_to_be64(x) ext2fs_swab64((x)) +#define ext2fs_be64_to_cpu(x) ext2fs_swab64((x)) #define ext2fs_cpu_to_be32(x) ext2fs_swab32((x)) #define ext2fs_be32_to_cpu(x) ext2fs_swab32((x)) #define ext2fs_cpu_to_be16(x) ext2fs_swab16((x)) @@ -634,5 +640,4 @@ _INLINE_ void ext2fs_fast_unmark_block_bitmap_range2(ext2fs_block_bitmap bitmap, #undef _INLINE_ #endif - #endif diff --git a/libcustomext2fs/source/blkmap64_ba.c b/libcustomext2fs/source/blkmap64_ba.c index 395aba97..9253af20 100644 --- a/libcustomext2fs/source/blkmap64_ba.c +++ b/libcustomext2fs/source/blkmap64_ba.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H diff --git a/libcustomext2fs/source/blknum.c b/libcustomext2fs/source/blknum.c index b3e6dcad..33da7d6f 100644 --- a/libcustomext2fs/source/blknum.c +++ b/libcustomext2fs/source/blknum.c @@ -11,6 +11,7 @@ * %End-Header% */ +#include "config.h" #include "ext2fs.h" /* @@ -42,6 +43,25 @@ blk64_t ext2fs_group_last_block2(ext2_filsys fs, dgrp_t group) (fs->super->s_blocks_per_group - 1)); } +/* + * Return the number of blocks in a group + */ +int ext2fs_group_blocks_count(ext2_filsys fs, dgrp_t group) +{ + int num_blocks; + + if (group == fs->group_desc_count - 1) { + num_blocks = (ext2fs_blocks_count(fs->super) - + fs->super->s_first_data_block) % + fs->super->s_blocks_per_group; + if (!num_blocks) + num_blocks = fs->super->s_blocks_per_group; + } else + num_blocks = fs->super->s_blocks_per_group; + + return num_blocks; +} + /* * Return the inode data block count */ @@ -455,23 +475,24 @@ void ext2fs_bg_checksum_set(ext2_filsys fs, dgrp_t group, __u16 checksum) /* * Get the acl block of a file - * - * XXX Ignoring 64-bit file system flag - most places where this is - * called don't have access to the fs struct, and the high bits should - * be 0 in the non-64-bit case anyway. */ -blk64_t ext2fs_file_acl_block(const struct ext2_inode *inode) +blk64_t ext2fs_file_acl_block(ext2_filsys fs, const struct ext2_inode *inode) { - return (inode->i_file_acl | - (__u64) inode->osd2.linux2.l_i_file_acl_high << 32); + blk64_t blk = inode->i_file_acl; + + if (fs && fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) + blk |= ((__u64) inode->osd2.linux2.l_i_file_acl_high) << 32; + return blk; } /* * Set the acl block of a file */ -void ext2fs_file_acl_block_set(struct ext2_inode *inode, blk64_t blk) +void ext2fs_file_acl_block_set(ext2_filsys fs, struct ext2_inode *inode, + blk64_t blk) { inode->i_file_acl = blk; - inode->osd2.linux2.l_i_file_acl_high = (__u64) blk >> 32; + if (fs && fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) + inode->osd2.linux2.l_i_file_acl_high = (__u64) blk >> 32; } diff --git a/libcustomext2fs/source/block.c b/libcustomext2fs/source/block.c index 0e4ec775..6a5c10df 100644 --- a/libcustomext2fs/source/block.c +++ b/libcustomext2fs/source/block.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H @@ -453,6 +454,17 @@ errcode_t ext2fs_block_iterate3(ext2_filsys fs, uninit = 0; if (extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT) uninit = EXT2_EXTENT_SET_BMAP_UNINIT; +#if 0 + printf("lblk %llu pblk %llu len %d blockcnt %llu\n", + extent.e_lblk, extent.e_pblk, + extent.e_len, blockcnt); +#endif + if (extent.e_lblk + extent.e_len <= blockcnt) + continue; + if (extent.e_lblk > blockcnt) + blockcnt = extent.e_lblk; + j = blockcnt - extent.e_lblk; + blk += j; for (blockcnt = extent.e_lblk, j = 0; j < extent.e_len; blk++, blockcnt++, j++) { diff --git a/libcustomext2fs/source/bmap.c b/libcustomext2fs/source/bmap.c index fbcb3753..16d51e0b 100644 --- a/libcustomext2fs/source/bmap.c +++ b/libcustomext2fs/source/bmap.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H @@ -129,6 +130,106 @@ static _BMAP_INLINE_ errcode_t block_tind_bmap(ext2_filsys fs, int flags, return retval; } +static errcode_t extent_bmap(ext2_filsys fs, ext2_ino_t ino, + struct ext2_inode *inode, + ext2_extent_handle_t handle, + char *block_buf, int bmap_flags, blk64_t block, + int *ret_flags, int *blocks_alloc, + blk64_t *phys_blk); + +static errcode_t implied_cluster_alloc(ext2_filsys fs, ext2_ino_t ino, + struct ext2_inode *inode, + ext2_extent_handle_t handle, + blk64_t block, blk64_t *phys_blk) +{ + blk64_t base_block, pblock = 0; + int i; + + if (!EXT2_HAS_RO_COMPAT_FEATURE(fs->super, + EXT4_FEATURE_RO_COMPAT_BIGALLOC)) + return 0; + + base_block = block & ~EXT2FS_CLUSTER_MASK(fs); + for (i = 0; i < EXT2FS_CLUSTER_RATIO(fs); i++) { + if (block == base_block) + return 0; + extent_bmap(fs, ino, inode, handle, 0, 0, + base_block + i, 0, 0, &pblock); + if (pblock) + break; + } + if (pblock == 0) + return 0; + *phys_blk = pblock - i + (block - base_block); + return 0; +} + +static errcode_t extent_bmap(ext2_filsys fs, ext2_ino_t ino, + struct ext2_inode *inode, + ext2_extent_handle_t handle, + char *block_buf, int bmap_flags, blk64_t block, + int *ret_flags, int *blocks_alloc, + blk64_t *phys_blk) +{ + struct ext2fs_extent extent; + unsigned int offset; + errcode_t retval = 0; + blk64_t blk64 = 0; + int alloc = 0; + + if (bmap_flags & BMAP_SET) { + retval = ext2fs_extent_set_bmap(handle, block, + *phys_blk, 0); + return retval; + } + retval = ext2fs_extent_goto(handle, block); + if (retval) { + /* If the extent is not found, return phys_blk = 0 */ + if (retval == EXT2_ET_EXTENT_NOT_FOUND) + goto got_block; + return retval; + } + retval = ext2fs_extent_get(handle, EXT2_EXTENT_CURRENT, &extent); + if (retval) + return retval; + offset = block - extent.e_lblk; + if (block >= extent.e_lblk && (offset <= extent.e_len)) { + *phys_blk = extent.e_pblk + offset; + if (ret_flags && extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT) + *ret_flags |= BMAP_RET_UNINIT; + } +got_block: + if ((*phys_blk == 0) && (bmap_flags & BMAP_ALLOC)) { + implied_cluster_alloc(fs, ino, inode, handle, block, &blk64); + if (blk64) + goto set_extent; + retval = extent_bmap(fs, ino, inode, handle, block_buf, + 0, block-1, 0, blocks_alloc, &blk64); + if (retval) + blk64 = 0; + retval = ext2fs_alloc_block2(fs, blk64, block_buf, + &blk64); + if (retval) + return retval; + blk64 &= ~EXT2FS_CLUSTER_MASK(fs); + blk64 += EXT2FS_CLUSTER_MASK(fs) & block; + alloc++; + set_extent: + retval = ext2fs_extent_set_bmap(handle, block, + blk64, 0); + if (retval) + return retval; + /* Update inode after setting extent */ + retval = ext2fs_read_inode(fs, ino, inode); + if (retval) + return retval; + *blocks_alloc += alloc; + *phys_blk = blk64; + } + return 0; +} + + errcode_t ext2fs_bmap2(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode *inode, char *block_buf, int bmap_flags, blk64_t block, int *ret_flags, blk64_t *phys_blk) @@ -156,54 +257,6 @@ errcode_t ext2fs_bmap2(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode *inode, } addr_per_block = (blk_t) fs->blocksize >> 2; - if (inode->i_flags & EXT4_EXTENTS_FL) { - struct ext2fs_extent extent; - unsigned int offset; - - retval = ext2fs_extent_open2(fs, ino, inode, &handle); - if (retval) - goto done; - if (bmap_flags & BMAP_SET) { - retval = ext2fs_extent_set_bmap(handle, block, - *phys_blk, 0); - goto done; - } - retval = ext2fs_extent_goto(handle, block); - if (retval) { - /* If the extent is not found, return phys_blk = 0 */ - if (retval == EXT2_ET_EXTENT_NOT_FOUND) - goto got_block; - goto done; - } - retval = ext2fs_extent_get(handle, EXT2_EXTENT_CURRENT, &extent); - if (retval) - goto done; - offset = block - extent.e_lblk; - if (block >= extent.e_lblk && (offset <= extent.e_len)) { - *phys_blk = extent.e_pblk + offset; - if (ret_flags && extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT) - *ret_flags |= BMAP_RET_UNINIT; - } - got_block: - if ((*phys_blk == 0) && (bmap_flags & BMAP_ALLOC)) { - retval = ext2fs_alloc_block(fs, b, block_buf, &b); - if (retval) - goto done; - retval = ext2fs_extent_set_bmap(handle, block, - (blk64_t) b, 0); - if (retval) - goto done; - /* Update inode after setting extent */ - retval = ext2fs_read_inode(fs, ino, inode); - if (retval) - return retval; - blocks_alloc++; - *phys_blk = b; - } - retval = 0; - goto done; - } - if (!block_buf) { retval = ext2fs_get_array(2, fs->blocksize, &buf); if (retval) @@ -211,6 +264,16 @@ errcode_t ext2fs_bmap2(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode *inode, block_buf = buf; } + if (inode->i_flags & EXT4_EXTENTS_FL) { + retval = ext2fs_extent_open2(fs, ino, inode, &handle); + if (retval) + goto done; + retval = extent_bmap(fs, ino, inode, handle, block_buf, + bmap_flags, block, ret_flags, + &blocks_alloc, phys_blk); + goto done; + } + if (block < EXT2_NDIR_BLOCKS) { if (bmap_flags & BMAP_SET) { b = *phys_blk; diff --git a/libcustomext2fs/source/bmap64.h b/libcustomext2fs/source/bmap64.h index b0aa84c1..30565440 100644 --- a/libcustomext2fs/source/bmap64.h +++ b/libcustomext2fs/source/bmap64.h @@ -16,6 +16,7 @@ struct ext2fs_struct_generic_bitmap { int flags; __u64 start, end; __u64 real_end; + int cluster_bits; char *description; void *private; errcode_t base_error_code; diff --git a/libcustomext2fs/source/bmove.c b/libcustomext2fs/source/bmove.c index deabf38c..e2ea405a 100644 --- a/libcustomext2fs/source/bmove.c +++ b/libcustomext2fs/source/bmove.c @@ -10,6 +10,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H @@ -140,7 +141,7 @@ errcode_t ext2fs_move_blocks(ext2_filsys fs, while (ino) { if ((inode.i_links_count == 0) || - !ext2fs_inode_has_valid_blocks(&inode)) + !ext2fs_inode_has_valid_blocks2(fs, &inode)) goto next; pb.ino = ino; diff --git a/libcustomext2fs/source/brel_ma.c b/libcustomext2fs/source/brel_ma.c index 1a55702b..e8a8280e 100644 --- a/libcustomext2fs/source/brel_ma.c +++ b/libcustomext2fs/source/brel_ma.c @@ -12,6 +12,7 @@ * %End-Header% */ +#include "config.h" #include #include #include diff --git a/libcustomext2fs/source/check_desc.c b/libcustomext2fs/source/check_desc.c index 7929cd95..a6fcc454 100644 --- a/libcustomext2fs/source/check_desc.c +++ b/libcustomext2fs/source/check_desc.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H @@ -37,11 +38,11 @@ errcode_t ext2fs_check_desc(ext2_filsys fs) blk64_t first_block = fs->super->s_first_data_block; blk64_t last_block = ext2fs_blocks_count(fs->super)-1; blk64_t blk, b; - int j; + unsigned int j; EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); - retval = ext2fs_allocate_block_bitmap(fs, "check_desc map", &bmap); + retval = ext2fs_allocate_subcluster_bitmap(fs, "check_desc map", &bmap); if (retval) return retval; @@ -53,8 +54,6 @@ errcode_t ext2fs_check_desc(ext2_filsys fs) EXT4_FEATURE_INCOMPAT_FLEX_BG)) { first_block = ext2fs_group_first_block2(fs, i); last_block = ext2fs_group_last_block2(fs, i); - if (i == (fs->group_desc_count - 1)) - last_block = ext2fs_blocks_count(fs->super)-1; } /* diff --git a/libcustomext2fs/source/closefs.c b/libcustomext2fs/source/closefs.c index 8242622b..103fca89 100644 --- a/libcustomext2fs/source/closefs.c +++ b/libcustomext2fs/source/closefs.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #if HAVE_UNISTD_H #include @@ -73,6 +74,8 @@ errcode_t ext2fs_super_and_bgd_loc2(ext2_filsys fs, int has_super; group_block = ext2fs_group_first_block2(fs, group); + if (group_block == 0 && fs->blocksize == 1024) + group_block = 1; /* Deal with 1024 blocksize && bigalloc */ if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) old_desc_blocks = fs->super->s_first_meta_bg; @@ -150,14 +153,7 @@ int ext2fs_super_and_bgd_loc(ext2_filsys fs, &ret_new_desc_blk2, &ret_used_blks); - if (group == fs->group_desc_count-1) { - numblocks = (ext2fs_blocks_count(fs->super) - - (blk64_t) fs->super->s_first_data_block) % - (blk64_t) fs->super->s_blocks_per_group; - if (!numblocks) - numblocks = fs->super->s_blocks_per_group; - } else - numblocks = fs->super->s_blocks_per_group; + numblocks = ext2fs_group_blocks_count(fs, group); if (ret_super_blk) *ret_super_blk = (blk_t)ret_super_blk2; @@ -265,6 +261,11 @@ static errcode_t write_backup_super(ext2_filsys fs, dgrp_t group, } errcode_t ext2fs_flush(ext2_filsys fs) +{ + return ext2fs_flush2(fs, 0); +} + +errcode_t ext2fs_flush2(ext2_filsys fs, int flags) { dgrp_t i; errcode_t retval; @@ -406,14 +407,16 @@ write_primary_superblock_only: ext2fs_swap_super(super_shadow); #endif - retval = io_channel_flush(fs->io); + if (!(flags & EXT2_FLAG_FLUSH_NO_SYNC)) + retval = io_channel_flush(fs->io); retval = write_primary_superblock(fs, super_shadow); if (retval) goto errout; fs->flags &= ~EXT2_FLAG_DIRTY; - retval = io_channel_flush(fs->io); + if (!(flags & EXT2_FLAG_FLUSH_NO_SYNC)) + retval = io_channel_flush(fs->io); errout: fs->super->s_state = fs_state; #ifdef WORDS_BIGENDIAN @@ -426,6 +429,11 @@ errout: } errcode_t ext2fs_close(ext2_filsys fs) +{ + return ext2fs_close2(fs, 0); +} + +errcode_t ext2fs_close2(ext2_filsys fs, int flags) { errcode_t retval; int meta_blks; @@ -451,10 +459,15 @@ errcode_t ext2fs_close(ext2_filsys fs) fs->flags |= EXT2_FLAG_SUPER_ONLY | EXT2_FLAG_DIRTY; } if (fs->flags & EXT2_FLAG_DIRTY) { - retval = ext2fs_flush(fs); + retval = ext2fs_flush2(fs, flags); if (retval) return retval; } + + retval = ext2fs_mmp_stop(fs); + if (retval) + return retval; + ext2fs_free(fs); return 0; } diff --git a/libcustomext2fs/source/config.h b/libcustomext2fs/source/config.h index be09663b..e21896f8 100644 --- a/libcustomext2fs/source/config.h +++ b/libcustomext2fs/source/config.h @@ -1,10 +1,603 @@ +/* lib/config.h. Generated from config.h.in by configure. */ +/* lib/config.h.in. Generated from configure.in by autoheader. */ +#ifndef __CONFIG_H_ +#define __CONFIG_H_ -#define HAVE_UNISTD_H 1 -#define HAVE_SYS_STAT_H 1 -#define HAVE_SYS_TYPES_H 1 -#define HAVE_UTIME_H 1 -#define WORDS_BIGENDIAN 1 +/* Define if building universal (internal helper macro) */ +/* #undef AC_APPLE_UNIVERSAL_BUILD */ + +/* Define to 1 if debugging the blkid library */ +/* #undef CONFIG_BLKID_DEBUG */ + +/* Define to 1 to compile findfs */ +/* #undef CONFIG_BUILD_FINDFS 1 */ + +/* Define to 1 if debugging ext3/4 journal code */ +/* #undef CONFIG_JBD_DEBUG */ + +/* Define to 1 if the testio I/O manager should be enabled */ +/* #undef CONFIG_TESTIO_DEBUG 1 */ + +/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP + systems. This function is required for `alloca.c' support on those systems. + */ +/* #undef CRAY_STACKSEG_END */ + +/* Define to 1 if using `alloca.c'. */ +/* #undef C_ALLOCA */ + +/* Define to 1 if ext2 compression enabled */ +/* #undef ENABLE_COMPRESSION */ + +/* Define to 1 if ext3/4 htree support enabled */ +#define ENABLE_HTREE 1 + +/* Define to 1 if translation of program messages to the user's native + language is requested. */ +#define ENABLE_NLS 1 + +/* Define to 1 if you have `alloca', as a function or macro. */ +#define HAVE_ALLOCA 1 + +/* Define to 1 if you have and it should be used (not on Ultrix). + */ +#define HAVE_ALLOCA_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_ARGZ_H 1 + +/* Define to 1 if you have the `asprintf' function. */ +#define HAVE_ASPRINTF 1 + +/* Define to 1 if you have the `backtrace' function. */ +/* #undef HAVE_BACKTRACE 1 */ + +/* Define to 1 if you have the `blkid_probe_get_topology' function. */ +/* #undef HAVE_BLKID_PROBE_GET_TOPOLOGY */ + +/* Define to 1 if you have the `chflags' function. */ +/* #undef HAVE_CHFLAGS */ + +/* Define if the GNU dcgettext() function is already present or preinstalled. + */ +/* #undef HAVE_DCGETTEXT 1 */ + +/* Define to 1 if you have the declaration of `feof_unlocked', and to 0 if you + don't. */ +/* #undef HAVE_DECL_FEOF_UNLOCKED 1 */ + +/* Define to 1 if you have the declaration of `fgets_unlocked', and to 0 if + you don't. */ +/* #undef HAVE_DECL_FGETS_UNLOCKED 0 */ + +/* Define to 1 if you have the declaration of `getc_unlocked', and to 0 if you + don't. */ +/* #undef HAVE_DECL_GETC_UNLOCKED 1 */ + +/* Define to 1 if you have the declaration of `_snprintf', and to 0 if you + don't. */ +/* #undef HAVE_DECL__SNPRINTF 0 */ + +/* Define to 1 if you have the declaration of `_snwprintf', and to 0 if you + don't. */ +/* #undef HAVE_DECL__SNWPRINTF 0 */ + +/* Define to 1 if you have the header file. */ +#define HAVE_DIRENT_H 1 + +/* Define to 1 if dlopen/libdl exists */ +/* #undef HAVE_DLOPEN 1 */ + +/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */ +/* #undef HAVE_DOPRNT */ + +/* Define to 1 if you have the header file. */ #define HAVE_ERRNO_H 1 -#define EXT2_FLAT_INCLUDES 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_EXECINFO_H 1 */ + +/* Define to 1 if Ext2 ioctls present */ +/* #undef HAVE_EXT2_IOCTLS 1 */ + +/* Define to 1 if you have the `fallocate' function. */ +/* #undef HAVE_FALLOCATE 1 */ + +/* Define to 1 if you have the `fallocate64' function. */ +/* #undef HAVE_FALLOCATE64 1 */ + +/* Define to 1 if you have the `fchown' function. */ +/* #undef HAVE_FCHOWN 1 */ + +/* Define to 1 if you have the `fdatasync' function. */ +/* #undef HAVE_FDATASYNC 1 */ + +/* Define to 1 if you have the `fstat64' function. */ +/* #undef HAVE_FSTAT64 1 */ + +/* Define to 1 if you have the `ftruncate64' function. */ +/* #undef HAVE_FTRUNCATE64 1 */ + +/* Define to 1 if you have the `fwprintf' function. */ +/* #undef HAVE_FWPRINTF 1 */ + +/* Define to 1 if you have the `getcwd' function. */ +/* #undef HAVE_GETCWD 1 */ + +/* Define to 1 if you have the `getdtablesize' function. */ +/* #undef HAVE_GETDTABLESIZE 1 */ + +/* Define to 1 if you have the `getegid' function. */ +/* #undef HAVE_GETEGID 1 */ + +/* Define to 1 if you have the `geteuid' function. */ +/* #undef HAVE_GETEUID 1 */ + +/* Define to 1 if you have the `getgid' function. */ +/* #undef HAVE_GETGID 1 */ + +/* Define to 1 if you have the `getmntinfo' function. */ +/* #undef HAVE_GETMNTINFO */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_GETOPT_H 1 */ + +/* Define to 1 if you have the `getpagesize' function. */ +/* #undef HAVE_GETPAGESIZE 1 */ + +/* Define to 1 if you have the `getrlimit' function. */ +/* #undef HAVE_GETRLIMIT 1 */ + +/* Define to 1 if you have the `getrusage' function. */ +/* #undef HAVE_GETRUSAGE 1 */ + +/* Define if the GNU gettext() function is already present or preinstalled. */ +/* #undef HAVE_GETTEXT 1 */ + +/* Define to 1 if you have the `getuid' function. */ +/* #undef HAVE_GETUID 1 */ + +/* Define if you have the iconv() function. */ +/* #undef HAVE_ICONV 1 */ + +/* Define if you have the 'intmax_t' type in or . */ +#define HAVE_INTMAX_T 1 + +/* Define to 1 if the system has the type `intptr_t'. */ +#define HAVE_INTPTR_T 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define if exists, doesn't clash with , and + declares uintmax_t. */ +#define HAVE_INTTYPES_H_WITH_UINTMAX 1 + +/* Define to 1 if you have the `jrand48' function. */ +/* #undef HAVE_JRAND48 1 */ + +/* Define if you have and nl_langinfo(CODESET). */ +/* #undef HAVE_LANGINFO_CODESET 1 */ + +/* Define if your file defines LC_MESSAGES. */ +#define HAVE_LC_MESSAGES 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_LIMITS_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_LINUX_FALLOC_H 1 */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_LINUX_FD_H 1 */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_LINUX_MAJOR_H 1 */ + +/* Define to 1 if you have the `llseek' function. */ +/* #undef HAVE_LLSEEK 1 */ + +/* Define to 1 if llseek declared in unistd.h */ +/* #undef HAVE_LLSEEK_PROTOTYPE */ + +/* Define to 1 if you have the header file. */ +#define HAVE_LOCALE_H 1 + +/* Define if you have the 'long double' type. */ +#define HAVE_LONG_DOUBLE 1 + +/* Define if you have the 'long long' type. */ +#define HAVE_LONG_LONG 1 + +/* Define to 1 if you have the `lseek64' function. */ +/* #undef HAVE_LSEEK64 1 */ + +/* Define to 1 if lseek64 declared in unistd.h */ +#define HAVE_LSEEK64_PROTOTYPE 1 + +/* Define to 1 if you have the `mallinfo' function. */ +/* #undef HAVE_MALLINFO 1 */ + +/* Define to 1 if you have the header file. */ +#define HAVE_MALLOC_H 1 + +/* Define to 1 if you have the `mbstowcs' function. */ +#define HAVE_MBSTOWCS 1 + +/* Define to 1 if you have the `memalign' function. */ +#define HAVE_MEMALIGN 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_MEMORY_H 1 */ + +/* Define to 1 if you have the `mempcpy' function. */ +/* #undef HAVE_MEMPCPY 1 */ + +/* Define to 1 if you have the `mmap' function. */ +/* #undef HAVE_MMAP 1 */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_MNTENT_H 1 */ + +/* Define to 1 if you have the `munmap' function. */ +/* #undef HAVE_MUNMAP 1 */ + +/* Define to 1 if you have the `nanosleep' function. */ +#define HAVE_NANOSLEEP 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_NETINET_IN_H 1 */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_NET_IF_DL_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_NET_IF_H 1 */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_NL_TYPES_H 1 */ + +/* Define to 1 if you have the `open64' function. */ +/* #undef HAVE_OPEN64 1 */ + +/* Define to 1 if optreset for getopt is present */ +/* #undef HAVE_OPTRESET */ + +/* Define to 1 if you have the `pathconf' function. */ +/* #undef HAVE_PATHCONF 1 */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_PATHS_H 1 */ + +/* Define to 1 if you have the `posix_fadvise' function. */ +/* #undef HAVE_POSIX_FADVISE 1 */ + +/* Define to 1 if you have the `posix_memalign' function. */ +/* #undef HAVE_POSIX_MEMALIGN 1 */ + +/* Define if your printf() function supports format strings with positions. */ +#define HAVE_POSIX_PRINTF 1 + +/* Define to 1 if you have the `prctl' function. */ +/* #undef HAVE_PRCTL 1 */ + +/* Define to 1 if you have the `putenv' function. */ +/* #undef HAVE_PUTENV 1 */ + +/* Define to 1 if you have the `quotactl' function. */ +/* #undef HAVE_QUOTACTL 1 */ + +/* Define to 1 if dirent has d_reclen */ +/* #undef HAVE_RECLEN_DIRENT 1 */ + +/* Define to 1 if if struct sockaddr contains sa_len */ +/* #undef HAVE_SA_LEN */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SEMAPHORE_H 1 */ + +/* Define to 1 if sem_init() exists */ +/* #undef HAVE_SEM_INIT 1 */ + +/* Define to 1 if you have the `setenv' function. */ +/* #undef HAVE_SETENV 1 */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SETJMP_H 1 */ + +/* Define to 1 if you have the `setlocale' function. */ +#define HAVE_SETLOCALE 1 + +/* Define to 1 if you have the `setresgid' function. */ +/* #undef HAVE_SETRESGID 1 */ + +/* Define to 1 if you have the `setresuid' function. */ +/* #undef HAVE_SETRESUID 1*/ + +/* Define to 1 if you have the header file. */ +#define HAVE_SIGNAL_H 1 + +/* Define to 1 if you have the `snprintf' function. */ +#define HAVE_SNPRINTF 1 + +/* Define to 1 if you have the `srandom' function. */ +/* #undef HAVE_SRANDOM 1 */ + +/* Define to 1 if struct stat has st_flags */ +/* #undef HAVE_STAT_FLAGS */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STDARG_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDDEF_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDINT_H 1 + +/* Define if exists, doesn't clash with , and declares + uintmax_t. */ +#define HAVE_STDINT_H_WITH_UINTMAX 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the `stpcpy' function. */ +#define HAVE_STPCPY 1 + +/* Define to 1 if you have the `strcasecmp' function. */ +#define HAVE_STRCASECMP 1 + +/* Define to 1 if you have the `strdup' function. */ #define HAVE_STRDUP 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_STRINGS_H 1 */ + +/* Define to 1 if you have the header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the `strnlen' function. */ +#define HAVE_STRNLEN 1 + +/* Define to 1 if you have the `strptime' function. */ +#define HAVE_STRPTIME 1 + +/* Define to 1 if you have the `strtoul' function. */ +#define HAVE_STRTOUL 1 + +/* Define to 1 if you have the `strtoull' function. */ +#define HAVE_STRTOULL 1 + +/* Define to 1 if you have the `sync_file_range' function. */ +/* #undef HAVE_SYNC_FILE_RANGE 1 */ + +/* Define to 1 if you have the `sysconf' function. */ +/* #undef HAVE_SYSCONF 1 */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_DISKLABEL_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_DISK_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_FILE_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_IOCTL_H 1 */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_MKDEV_H */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_MMAN_H 1 */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_MOUNT_H 1 */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_PARAM_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_PRCTL_H 1 */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_QUEUE_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_QUOTA_H 1 */ + +/* Define to 1 if you have the header file. */ #define HAVE_SYS_RESOURCE_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_SELECT_H 1 */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_SOCKET_H 1 */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_SOCKIO_H */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_SYSCALL_H 1 */ + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_SYSMACROS_H 1 */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TIME_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_UN_H 1 */ + +/* Define to 1 if you have the header file. */ +#define HAVE_SYS_WAIT_H 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_TERMIOS_H 1 + +/* Define to 1 if you have the header file. */ +/* #undef HAVE_TERMIO_H 1 */ + +/* Define to 1 if you have the `tsearch' function. */ +/* #undef HAVE_TSEARCH 1 */ + +/* Define to 1 if ssize_t declared */ +#define HAVE_TYPE_SSIZE_T 1 + +/* Define if you have the 'uintmax_t' type in or . */ +#define HAVE_UINTMAX_T 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_UNISTD_H 1 + +/* Define if you have the 'unsigned long long' type. */ +#define HAVE_UNSIGNED_LONG_LONG 1 + +/* Define to 1 if you have the `usleep' function. */ +#define HAVE_USLEEP 1 + +/* Define to 1 if you have the `utime' function. */ +/* #undef HAVE_UTIME 1 */ + +/* Define to 1 if you have the header file. */ +#define HAVE_UTIME_H 1 + +/* Define to 1 if you have the `valloc' function. */ +/* #undef HAVE_VALLOC 1 */ + +/* Define to 1 if you have the `vprintf' function. */ +#define HAVE_VPRINTF 1 + +/* Define if you have the 'wchar_t' type. */ +#define HAVE_WCHAR_T 1 + +/* Define to 1 if you have the `wcslen' function. */ +#define HAVE_WCSLEN 1 + +/* Define if you have the 'wint_t' type. */ +#define HAVE_WINT_T 1 + +/* Define to 1 if you have the `__argz_count' function. */ +/* #undef HAVE___ARGZ_COUNT 1 */ + +/* Define to 1 if you have the `__argz_next' function. */ +/* #undef HAVE___ARGZ_NEXT 1 */ + +/* Define to 1 if you have the `__argz_stringify' function. */ +/* #undef HAVE___ARGZ_STRINGIFY 1 */ + +/* Define to 1 if you have the `__fsetlocking' function. */ +/* #undef HAVE___FSETLOCKING 1 */ + +/* Define to 1 if you have the `__secure_getenv' function. */ +/* #undef HAVE___SECURE_GETENV 1 */ + +/* Define as const if the declaration of iconv() needs const. */ +/* #undef ICONV_CONST */ + +/* Define if integer division by zero raises signal SIGFPE. */ +/* #undef INTDIV0_RAISES_SIGFPE 1 */ + +/* package name for gettext */ +#define PACKAGE "e2fsprogs" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "" + +/* Define to the home page for this package. */ +#define PACKAGE_URL "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "" + +/* Define if exists and defines unusable PRI* macros. */ +/* #undef PRI_MACROS_BROKEN */ + +/* The size of `int', as computed by sizeof. */ +#define SIZEOF_INT 4 + +/* The size of `long', as computed by sizeof. */ +#define SIZEOF_LONG 4 + +/* The size of `long long', as computed by sizeof. */ +#define SIZEOF_LONG_LONG 8 + +/* The size of `short', as computed by sizeof. */ +#define SIZEOF_SHORT 2 + +/* Define as the maximum value of type 'size_t', if the system doesn't define + it. */ +/* #undef SIZE_MAX */ + +/* If using the C implementation of alloca, define if you know the + direction of stack growth for your system; otherwise it will be + automatically deduced at runtime. + STACK_DIRECTION > 0 => grows toward higher addresses + STACK_DIRECTION < 0 => grows toward lower addresses + STACK_DIRECTION = 0 => direction of growth unknown */ +/* #undef STACK_DIRECTION */ + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* If the compiler supports a TLS storage class define it to that here */ +/* #undef TLS __thread */ + +/* Define to 1 to build uuidd */ +/* #undef USE_UUIDD 1 */ + +/* version for gettext */ +#define VERSION "0.14.1" + +/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most + significant byte first (like Motorola and SPARC, unlike Intel). */ +#define WORDS_BIGENDIAN 1 + +/* Define to 1 if Apple Darwin libintl workaround is needed */ +/* #undef _INTL_REDIRECT_MACROS */ + +/* Define to empty if `const' does not conform to ANSI C. */ +/* #undef const */ + +/* Define to `__inline__' or `__inline' if that's what the C compiler + calls it, or to nothing if 'inline' is not supported under any name. */ +#ifndef __cplusplus +/* #undef inline */ +#endif + +/* Define to `long int' if does not define. */ +/* #undef off_t */ + +/* Define as the type of the result of subtracting two pointers, if the system + doesn't define it. */ +/* #undef ptrdiff_t */ + +/* Define to empty if the C compiler doesn't support this keyword. */ +/* #undef signed */ + +/* Define to `unsigned int' if does not define. */ +/* #undef size_t */ + +/* Define to unsigned long or unsigned long long if and + don't define. */ +/* #undef uintmax_t */ + +#endif diff --git a/libcustomext2fs/source/crc16.c b/libcustomext2fs/source/crc16.c index 02d81e44..4176b268 100644 --- a/libcustomext2fs/source/crc16.c +++ b/libcustomext2fs/source/crc16.c @@ -5,6 +5,7 @@ * Version 2. See the file COPYING for more details. */ +#include "config.h" #if HAVE_SYS_TYPES_H #include #endif diff --git a/libcustomext2fs/source/crc32c.c b/libcustomext2fs/source/crc32c.c new file mode 100644 index 00000000..6be43369 --- /dev/null +++ b/libcustomext2fs/source/crc32c.c @@ -0,0 +1,1144 @@ +/* + * crc32c.c + * + * August 26, 2011 Darrick J. Wong + * Reuse Bob Pearson's slice-by-8 implementation for e2fsprogs. + * + * July 20, 2011 Bob Pearson + * added slice by 8 algorithm to the existing conventional and + * slice by 4 algorithms. + * + * Oct 15, 2000 Matt Domsch + * Nicer crc32 functions/docs submitted by linux@horizon.com. Thanks! + * Code was from the public domain, copyright abandoned. Code was + * subsequently included in the kernel, thus was re-licensed under the + * GNU GPL v2. + * + * Oct 12, 2000 Matt Domsch + * Same crc32 function was used in 5 other places in the kernel. + * I made one version, and deleted the others. + * There are various incantations of crc32(). Some use a seed of 0 or ~0. + * Some xor at the end with ~0. The generic crc32() function takes + * seed as an argument, and doesn't xor at the end. Then individual + * users can do whatever they need. + * drivers/net/smc9194.c uses seed ~0, doesn't xor with ~0. + * fs/jffs2 uses seed 0, doesn't xor with ~0. + * fs/partitions/efi.c uses seed ~0, xor's with ~0. + * + * This source code is licensed under the GNU General Public License, + * Version 2. See the file COPYING for more details. + */ +#include "config.h" +#include +#include +#include +#define __force +#define min(x, y) ((x) > (y) ? (y) : (x)) +#define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask)) +#define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (typeof(x))(a) - 1) +#define ALIGN(x, a) __ALIGN_KERNEL((x), (a)) +#define PTR_ALIGN(p, a) ((typeof(p))ALIGN((unsigned long)(p), (a))) +#include "crc32c_defs.h" + +#include "ext2fs.h" +#ifdef WORDS_BIGENDIAN +#define __constant_cpu_to_le32(x) ___constant_swab32((x)) +#define __constant_cpu_to_be32(x) (x) +#define __be32_to_cpu(x) (x) +#define __cpu_to_be32(x) (x) +#define __cpu_to_le32(x) (ext2fs_cpu_to_le32((x))) +#define __le32_to_cpu(x) (ext2fs_le32_to_cpu((x))) +#else +#define __constant_cpu_to_le32(x) (x) +#define __constant_cpu_to_be32(x) ___constant_swab32((x)) +#define __be32_to_cpu(x) (ext2fs_be32_to_cpu((x))) +#define __cpu_to_be32(x) (ext2fs_cpu_to_be32((x))) +#define __cpu_to_le32(x) (x) +#define __le32_to_cpu(x) (x) +#endif + +#if CRC_LE_BITS > 8 +# define tole(x) (__force uint32_t) __constant_cpu_to_le32(x) +#else +# define tole(x) (x) +#endif + +#if CRC_BE_BITS > 8 +# define tobe(x) (__force uint32_t) __constant_cpu_to_be32(x) +#else +# define tobe(x) (x) +#endif + +#include "crc32c_table.h" + +#if CRC_LE_BITS == 32 +/* slice by 4 algorithm */ +static uint32_t crc32c_le_body(uint32_t crc, uint8_t const *buf, size_t len) +{ + const uint8_t *p8; + const uint32_t *p32; + size_t init_bytes; + size_t words; + size_t end_bytes; + size_t i; + uint32_t q; + uint8_t i0, i1, i2, i3; + + crc = (__force uint32_t) __cpu_to_le32(crc); + + /* unroll loop into 'init_bytes' odd bytes followed by + * 'words' aligned 4 byte words followed by + * 'end_bytes' odd bytes at the end */ + p8 = buf; + p32 = (uint32_t *)PTR_ALIGN(p8, 4); + init_bytes = min((uintptr_t)p32 - (uintptr_t)p8, len); + words = (len - init_bytes) >> 2; + end_bytes = (len - init_bytes) & 3; + + for (i = 0; i < init_bytes; i++) { +#ifndef WORDS_BIGENDIAN + i0 = *p8++ ^ crc; + crc = t0_le[i0] ^ (crc >> 8); +#else + i0 = *p8++ ^ (crc >> 24); + crc = t0_le[i0] ^ (crc << 8); +#endif + } + + /* using pre-increment below slightly faster */ + p32--; + + for (i = 0; i < words; i++) { +#ifndef WORDS_BIGENDIAN + q = *++p32 ^ crc; + i3 = q; + i2 = q >> 8; + i1 = q >> 16; + i0 = q >> 24; + crc = t3_le[i3] ^ t2_le[i2] ^ t1_le[i1] ^ t0_le[i0]; +#else + q = *++p32 ^ crc; + i3 = q >> 24; + i2 = q >> 16; + i1 = q >> 8; + i0 = q; + crc = t3_le[i3] ^ t2_le[i2] ^ t1_le[i1] ^ t0_le[i0]; +#endif + } + + p8 = (uint8_t *)(++p32); + + for (i = 0; i < end_bytes; i++) { +#ifndef WORDS_BIGENDIAN + i0 = *p8++ ^ crc; + crc = t0_le[i0] ^ (crc >> 8); +#else + i0 = *p8++ ^ (crc >> 24); + crc = t0_le[i0] ^ (crc << 8); +#endif + } + + return __le32_to_cpu((__force __le32)crc); +} +#endif + +#if CRC_BE_BITS == 32 +static uint32_t crc32c_be_body(uint32_t crc, uint8_t const *buf, size_t len) +{ + const uint8_t *p8; + const uint32_t *p32; + size_t init_bytes; + size_t words; + size_t end_bytes; + size_t i; + uint32_t q; + uint8_t i0, i1, i2, i3; + + crc = (__force uint32_t) __cpu_to_be32(crc); + + p8 = buf; + p32 = (uint32_t *)PTR_ALIGN(p8, 4); + init_bytes = min((uintptr_t)p32 - (uintptr_t)p8, len); + words = (len - init_bytes) >> 2; + end_bytes = (len - init_bytes) & 3; + + for (i = 0; i < init_bytes; i++) { +#ifndef WORDS_BIGENDIAN + i0 = *p8++ ^ crc; + crc = t0_be[i0] ^ (crc >> 8); +#else + i0 = *p8++ ^ (crc >> 24); + crc = t0_be[i0] ^ (crc << 8); +#endif + } + + p32--; + + for (i = 0; i < words; i++) { +#ifndef WORDS_BIGENDIAN + q = *++p32 ^ crc; + i3 = q; + i2 = q >> 8; + i1 = q >> 16; + i0 = q >> 24; + crc = t3_be[i3] ^ t2_be[i2] ^ t1_be[i1] ^ t0_be[i0]; +#else + q = *++p32 ^ crc; + i3 = q >> 24; + i2 = q >> 16; + i1 = q >> 8; + i0 = q; + crc = t3_be[i3] ^ t2_be[i2] ^ t1_be[i1] ^ t0_be[i0]; +#endif + } + + p8 = (uint8_t *)(++p32); + + for (i = 0; i < end_bytes; i++) { +#ifndef WORDS_BIGENDIAN + i0 = *p8++ ^ crc; + crc = t0_be[i0] ^ (crc >> 8); +#else + i0 = *p8++ ^ (crc >> 24); + crc = t0_be[i0] ^ (crc << 8); +#endif + } + + return __be32_to_cpu((__force __be32)crc); +} +#endif + +#if CRC_LE_BITS == 64 +/* slice by 8 algorithm */ +static uint32_t crc32c_le_body(uint32_t crc, uint8_t const *buf, size_t len) +{ + const uint8_t *p8; + const uint32_t *p32; + size_t init_bytes; + size_t words; + size_t end_bytes; + size_t i; + uint32_t q; + uint8_t i0, i1, i2, i3; + + crc = (__force uint32_t) __cpu_to_le32(crc); + + p8 = buf; + p32 = (uint32_t *)PTR_ALIGN(p8, 8); + init_bytes = min((uintptr_t)p32 - (uintptr_t)p8, len); + words = (len - init_bytes) >> 3; + end_bytes = (len - init_bytes) & 7; + + for (i = 0; i < init_bytes; i++) { +#ifndef WORDS_BIGENDIAN + i0 = *p8++ ^ crc; + crc = t0_le[i0] ^ (crc >> 8); +#else + i0 = *p8++ ^ (crc >> 24); + crc = t0_le[i0] ^ (crc << 8); +#endif + } + + p32--; + + for (i = 0; i < words; i++) { +#ifndef WORDS_BIGENDIAN + q = *++p32 ^ crc; + i3 = q; + i2 = q >> 8; + i1 = q >> 16; + i0 = q >> 24; + crc = t7_le[i3] ^ t6_le[i2] ^ t5_le[i1] ^ t4_le[i0]; + + q = *++p32; + i3 = q; + i2 = q >> 8; + i1 = q >> 16; + i0 = q >> 24; + crc ^= t3_le[i3] ^ t2_le[i2] ^ t1_le[i1] ^ t0_le[i0]; +#else + q = *++p32 ^ crc; + i3 = q >> 24; + i2 = q >> 16; + i1 = q >> 8; + i0 = q; + crc = t7_le[i3] ^ t6_le[i2] ^ t5_le[i1] ^ t4_le[i0]; + + q = *++p32; + i3 = q >> 24; + i2 = q >> 16; + i1 = q >> 8; + i0 = q; + crc ^= t3_le[i3] ^ t2_le[i2] ^ t1_le[i1] ^ t0_le[i0]; +#endif + } + + p8 = (uint8_t *)(++p32); + + for (i = 0; i < end_bytes; i++) { +#ifndef WORDS_BIGENDIAN + i0 = *p8++ ^ crc; + crc = t0_le[i0] ^ (crc >> 8); +#else + i0 = *p8++ ^ (crc >> 24); + crc = t0_le[i0] ^ (crc << 8); +#endif + } + + return __le32_to_cpu(crc); +} +#endif + +#if CRC_BE_BITS == 64 +static uint32_t crc32c_be_body(uint32_t crc, uint8_t const *buf, size_t len) +{ + const uint8_t *p8; + const uint32_t *p32; + size_t init_bytes; + size_t words; + size_t end_bytes; + size_t i; + uint32_t q; + uint8_t i0, i1, i2, i3; + + crc = (__force uint32_t) __cpu_to_be32(crc); + + p8 = buf; + p32 = (uint32_t *)PTR_ALIGN(p8, 8); + init_bytes = min((uintptr_t)p32 - (uintptr_t)p8, len); + words = (len - init_bytes) >> 3; + end_bytes = (len - init_bytes) & 7; + + for (i = 0; i < init_bytes; i++) { +#ifndef WORDS_BIGENDIAN + i0 = *p8++ ^ crc; + crc = t0_be[i0] ^ (crc >> 8); +#else + i0 = *p8++ ^ (crc >> 24); + crc = t0_be[i0] ^ (crc << 8); +#endif + } + + p32--; + + for (i = 0; i < words; i++) { +#ifndef WORDS_BIGENDIAN + q = *++p32 ^ crc; + i3 = q; + i2 = q >> 8; + i1 = q >> 16; + i0 = q >> 24; + crc = t7_be[i3] ^ t6_be[i2] ^ t5_be[i1] ^ t4_be[i0]; + + q = *++p32; + i3 = q; + i2 = q >> 8; + i1 = q >> 16; + i0 = q >> 24; + crc ^= t3_be[i3] ^ t2_be[i2] ^ t1_be[i1] ^ t0_be[i0]; +#else + q = *++p32 ^ crc; + i3 = q >> 24; + i2 = q >> 16; + i1 = q >> 8; + i0 = q; + crc = t7_be[i3] ^ t6_be[i2] ^ t5_be[i1] ^ t4_be[i0]; + + q = *++p32; + i3 = q >> 24; + i2 = q >> 16; + i1 = q >> 8; + i0 = q; + crc ^= t3_be[i3] ^ t2_be[i2] ^ t1_be[i1] ^ t0_be[i0]; +#endif + } + + p8 = (uint8_t *)(++p32); + + for (i = 0; i < end_bytes; i++) { +#ifndef WORDS_BIGENDIAN + i0 = *p8++ ^ crc; + crc = t0_be[i0] ^ (crc >> 8); +#else + i0 = *p8++ ^ (crc >> 24); + crc = t0_be[i0] ^ (crc << 8); +#endif + } + + return __be32_to_cpu(crc); +} +#endif + +/** + * crc32c_le() - Calculate bitwise little-endian CRC32c. + * @crc: seed value for computation. ~0 for ext4, sometimes 0 for + * other uses, or the previous crc32c value if computing incrementally. + * @p: pointer to buffer over which CRC is run + * @len: length of buffer @p + */ +uint32_t ext2fs_crc32c_le(uint32_t crc, unsigned char const *p, size_t len) +{ +#if CRC_LE_BITS == 1 + int i; + while (len--) { + crc ^= *p++; + for (i = 0; i < 8; i++) + crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0); + } +# elif CRC_LE_BITS == 2 + while (len--) { + crc ^= *p++; + crc = (crc >> 2) ^ t0_le[crc & 0x03]; + crc = (crc >> 2) ^ t0_le[crc & 0x03]; + crc = (crc >> 2) ^ t0_le[crc & 0x03]; + crc = (crc >> 2) ^ t0_le[crc & 0x03]; + } +# elif CRC_LE_BITS == 4 + while (len--) { + crc ^= *p++; + crc = (crc >> 4) ^ t0_le[crc & 0x0f]; + crc = (crc >> 4) ^ t0_le[crc & 0x0f]; + } +# elif CRC_LE_BITS == 8 + while (len--) { + crc ^= *p++; + crc = (crc >> 8) ^ t0_le[crc & 0xff]; + } +# else + crc = crc32c_le_body(crc, p, len); +# endif + return crc; +} + +/** + * crc32c_be() - Calculate bitwise big-endian CRC32c. + * @crc: seed value for computation. ~0 for ext4, sometimes 0 for + * other uses, or the previous crc32c value if computing incrementally. + * @p: pointer to buffer over which CRC is run + * @len: length of buffer @p + */ +uint32_t ext2fs_crc32c_be(uint32_t crc, unsigned char const *p, size_t len) +{ +#if CRC_BE_BITS == 1 + int i; + while (len--) { + crc ^= *p++ << 24; + for (i = 0; i < 8; i++) + crc = (crc << 1) ^ + ((crc & 0x80000000) ? CRCPOLY_BE : 0); + } +# elif CRC_BE_BITS == 2 + while (len--) { + crc ^= *p++ << 24; + crc = (crc << 2) ^ t0_be[crc >> 30]; + crc = (crc << 2) ^ t0_be[crc >> 30]; + crc = (crc << 2) ^ t0_be[crc >> 30]; + crc = (crc << 2) ^ t0_be[crc >> 30]; + } +# elif CRC_BE_BITS == 4 + while (len--) { + crc ^= *p++ << 24; + crc = (crc << 4) ^ t0_be[crc >> 28]; + crc = (crc << 4) ^ t0_be[crc >> 28]; + } +# elif CRC_BE_BITS == 8 + while (len--) { + crc ^= *p++ << 24; + crc = (crc << 8) ^ t0_be[crc >> 24]; + } +# else + crc = crc32c_be_body(crc, p, len); +# endif + return crc; +} + +#ifdef UNITTEST +static uint8_t test_buf[] = { + 0xd9, 0xd7, 0x6a, 0x13, 0x3a, 0xb1, 0x05, 0x48, + 0xda, 0xad, 0x14, 0xbd, 0x03, 0x3a, 0x58, 0x5e, + 0x6e, 0xd1, 0x56, 0xc9, 0x2e, 0xc4, 0xcb, 0x6b, + 0xe8, 0x77, 0x52, 0x37, 0x4e, 0x0f, 0x55, 0xd2, + 0x12, 0x65, 0x90, 0xc2, 0x41, 0x49, 0x81, 0x01, + 0xf5, 0x01, 0xeb, 0x2d, 0x78, 0x74, 0x23, 0x5d, + 0x84, 0x5c, 0x81, 0x92, 0x21, 0xe9, 0x8d, 0x1d, + 0x89, 0xf2, 0x4a, 0xac, 0xdd, 0xf9, 0xaf, 0xee, + 0x44, 0xe7, 0x6e, 0xed, 0xfb, 0xd8, 0x89, 0x0e, + 0x96, 0x62, 0xcd, 0xa4, 0x4b, 0xa9, 0xe5, 0x45, + 0xb1, 0x29, 0x9b, 0x0f, 0xfc, 0xbd, 0x83, 0xab, + 0xa8, 0x54, 0x96, 0x44, 0x2c, 0x7f, 0xbb, 0xe7, + 0x52, 0x29, 0x08, 0xee, 0x14, 0xc5, 0xc2, 0xec, + 0x5a, 0xeb, 0x40, 0x40, 0xea, 0xd1, 0x3d, 0x15, + 0x73, 0xaa, 0x8c, 0x73, 0xfc, 0xf2, 0x2b, 0x49, + 0x0b, 0x13, 0x96, 0xd9, 0x8e, 0x4b, 0xbc, 0xe0, + 0xf4, 0xd2, 0xe0, 0x2e, 0x7a, 0xf0, 0x5d, 0x1f, + 0xd2, 0x92, 0x97, 0xe0, 0xaa, 0x59, 0xab, 0xc9, + 0x5c, 0xa6, 0x51, 0x1a, 0xe3, 0xd6, 0x06, 0xb9, + 0xae, 0xb8, 0x76, 0x36, 0x79, 0x37, 0x52, 0xf6, + 0x34, 0xaf, 0x27, 0x19, 0xe1, 0xc0, 0x2b, 0xdd, + 0x01, 0x15, 0xcd, 0xce, 0x44, 0xf6, 0x4c, 0x18, + 0x92, 0x69, 0xbe, 0x8a, 0x76, 0x23, 0x52, 0x13, + 0x3f, 0xf9, 0xe0, 0xf5, 0x06, 0x28, 0x7c, 0xc7, + 0xf3, 0x42, 0x0f, 0xdd, 0x40, 0x33, 0xf7, 0x99, + 0xe2, 0xad, 0x26, 0xd9, 0x53, 0x10, 0x72, 0x0c, + 0x4e, 0x43, 0x4c, 0x61, 0xfe, 0xd9, 0xc1, 0x16, + 0xa1, 0x93, 0xca, 0x3c, 0x75, 0x7f, 0x07, 0x7a, + 0x65, 0xb3, 0x53, 0x2a, 0x52, 0x00, 0xa0, 0x62, + 0xe0, 0xa3, 0x1f, 0xad, 0xd7, 0xbb, 0xc0, 0x83, + 0x5d, 0x54, 0x87, 0x5f, 0xc8, 0x2f, 0xc8, 0xbf, + 0x69, 0x04, 0x91, 0xc8, 0xa6, 0x1d, 0x4d, 0x46, + 0x91, 0xfc, 0x26, 0xf4, 0x16, 0xd1, 0xa4, 0xbf, + 0x5c, 0xa2, 0x6c, 0xdd, 0xb4, 0x40, 0xf2, 0x2e, + 0xa2, 0xad, 0xf7, 0xf4, 0xa5, 0x8a, 0x3e, 0x23, + 0x64, 0x08, 0xc8, 0xa1, 0xa0, 0xf0, 0x5d, 0x70, + 0xd2, 0x77, 0xfd, 0xc8, 0x50, 0x83, 0x0f, 0xd6, + 0x2b, 0xe4, 0x1f, 0x52, 0x34, 0x33, 0x68, 0xfd, + 0x92, 0xbe, 0x9f, 0x97, 0x6b, 0x8d, 0x81, 0x91, + 0x0f, 0xef, 0x65, 0xc8, 0x0d, 0x15, 0x01, 0x77, + 0x58, 0xb2, 0xf4, 0x1b, 0x06, 0x7e, 0xf5, 0xca, + 0x15, 0x2e, 0x38, 0xd8, 0x81, 0x1c, 0x1c, 0xa0, + 0xb6, 0x13, 0x6a, 0x2b, 0x71, 0x34, 0x52, 0xd7, + 0x1d, 0xbd, 0x37, 0x59, 0xbc, 0x86, 0x25, 0x2b, + 0xa8, 0x93, 0xce, 0x1a, 0x03, 0x16, 0xfe, 0x01, + 0x57, 0x99, 0x24, 0x25, 0x2c, 0xb3, 0xab, 0x1e, + 0x2d, 0x65, 0x20, 0x89, 0x17, 0x02, 0x0e, 0x0a, + 0xf5, 0x1e, 0xc7, 0xff, 0x1f, 0x61, 0xa9, 0x54, + 0x18, 0xd4, 0xba, 0x50, 0x57, 0x02, 0xa1, 0xab, + 0x22, 0x2e, 0x07, 0xea, 0xa9, 0xa3, 0x83, 0x4f, + 0x27, 0xf5, 0xc5, 0xee, 0x3c, 0x3b, 0x10, 0xad, + 0x32, 0x2b, 0x1c, 0x03, 0xcb, 0xaf, 0x98, 0x83, + 0x54, 0xc3, 0x68, 0x63, 0xd4, 0xe0, 0x0e, 0x3c, + 0x1a, 0x4e, 0xc0, 0x81, 0xd0, 0xe8, 0x6a, 0x62, + 0x6b, 0x3e, 0x6f, 0xc4, 0xc6, 0x33, 0x4e, 0x26, + 0x21, 0xf5, 0x04, 0xdf, 0xfa, 0xce, 0x45, 0xaf, + 0xdc, 0x5e, 0x1b, 0xad, 0x93, 0xca, 0xf5, 0xcf, + 0xd7, 0xee, 0x0c, 0x5c, 0x5e, 0xb4, 0xf0, 0x92, + 0xd2, 0xf2, 0xf0, 0xa9, 0x1e, 0xab, 0x80, 0x68, + 0x46, 0xef, 0xcc, 0x26, 0x0c, 0x5c, 0xdd, 0x4e, + 0x83, 0xb8, 0xb9, 0x53, 0x6e, 0xf8, 0x93, 0x38, + 0x67, 0xa4, 0x41, 0x87, 0x72, 0xe7, 0x7e, 0x86, + 0xc9, 0x49, 0x00, 0x33, 0xb1, 0x38, 0x6c, 0x71, + 0xd7, 0x1d, 0x8e, 0x61, 0x01, 0xb6, 0x57, 0xa9, + 0xf1, 0xac, 0x15, 0xc2, 0x83, 0x77, 0xca, 0x64, + 0xca, 0x7b, 0x6c, 0xa1, 0x10, 0x1b, 0x13, 0xd0, + 0xd3, 0x9e, 0x9e, 0x10, 0x70, 0xc8, 0x1a, 0xbb, + 0x3f, 0x19, 0x86, 0xab, 0x01, 0x0e, 0xea, 0x34, + 0x22, 0xea, 0xe2, 0x15, 0xb7, 0xed, 0x21, 0x21, + 0x75, 0xa5, 0xe7, 0x08, 0xa1, 0x38, 0xe0, 0x91, + 0x05, 0x60, 0xea, 0xa7, 0x50, 0x27, 0x18, 0x07, + 0x9d, 0xe0, 0x18, 0x2b, 0xd4, 0x07, 0x59, 0x00, + 0xe6, 0x45, 0x18, 0x2a, 0x30, 0x6e, 0xf3, 0xb4, + 0xd0, 0xef, 0xa6, 0x5b, 0x71, 0xa2, 0x5a, 0x3b, + 0x89, 0x4c, 0xaf, 0x3f, 0xcb, 0x9f, 0x03, 0xfb, + 0x43, 0x7c, 0x6b, 0xd3, 0x6a, 0xea, 0xce, 0x4a, + 0x5f, 0x64, 0xb5, 0x62, 0xda, 0x5d, 0x27, 0xb7, + 0xb8, 0x11, 0xca, 0x33, 0x30, 0xec, 0x70, 0xf0, + 0x1b, 0x03, 0x50, 0xff, 0x5e, 0xa6, 0x08, 0xde, + 0x37, 0x70, 0xc0, 0x81, 0x55, 0x60, 0x17, 0xa1, + 0x85, 0xae, 0x26, 0x44, 0xe4, 0x67, 0x3c, 0x91, + 0xfd, 0xc4, 0x3d, 0x97, 0x72, 0x23, 0xf3, 0x3c, + 0x8f, 0xe0, 0xe2, 0xf2, 0x09, 0x96, 0x10, 0x67, + 0xb5, 0xfe, 0xff, 0x3d, 0x4a, 0xc8, 0x62, 0x11, + 0xa5, 0x98, 0xc1, 0x2d, 0x40, 0x82, 0x88, 0x8b, + 0xe5, 0xb0, 0x75, 0xbf, 0x2f, 0xa8, 0x6a, 0x55, + 0x49, 0x2e, 0x9c, 0x29, 0xd2, 0x7c, 0xbf, 0xf3, + 0xaa, 0x3a, 0x16, 0x4a, 0xa4, 0x15, 0xf3, 0x48, + 0xde, 0x38, 0x13, 0x44, 0x26, 0x02, 0xe6, 0xe9, + 0xa8, 0x24, 0x89, 0xb5, 0x43, 0x95, 0xe4, 0x4c, + 0xc3, 0xa0, 0xdf, 0xcc, 0x42, 0xf8, 0x8d, 0xb0, + 0x3b, 0xea, 0x10, 0xb7, 0xe1, 0x40, 0x54, 0xb9, + 0xa3, 0x2d, 0xfb, 0xb4, 0x91, 0xc0, 0x3e, 0x94, + 0xf1, 0xa1, 0x3c, 0xbe, 0xef, 0xb8, 0x70, 0x55, + 0x0a, 0x26, 0x93, 0xbf, 0xe6, 0x21, 0x92, 0x32, + 0x3c, 0x39, 0x27, 0x6a, 0x23, 0x48, 0x02, 0x35, + 0x3c, 0xd4, 0xcc, 0x04, 0xc0, 0x4e, 0xa7, 0x02, + 0x63, 0x37, 0xc2, 0xb8, 0x56, 0x1d, 0x57, 0x57, + 0x42, 0x04, 0x8d, 0xee, 0xcf, 0x8b, 0xc9, 0xc3, + 0xba, 0x3b, 0x15, 0xd7, 0xaf, 0xbf, 0x9e, 0xcd, + 0x44, 0xcf, 0xf0, 0x00, 0xb7, 0x3a, 0xfc, 0xa8, + 0x12, 0xab, 0x3a, 0x62, 0x01, 0x21, 0x46, 0xe9, + 0x1e, 0x48, 0x37, 0xfc, 0x13, 0x4d, 0xf6, 0x2a, + 0x72, 0x40, 0x75, 0x38, 0x71, 0xf2, 0x17, 0x20, + 0x2c, 0xdd, 0xc0, 0x49, 0xbc, 0x63, 0x33, 0xea, + 0x06, 0x75, 0x41, 0xe7, 0x5c, 0x1f, 0xfb, 0xf9, + 0x68, 0x83, 0xc2, 0x5a, 0x4a, 0x1e, 0x61, 0x08, + 0x57, 0xf3, 0x00, 0xba, 0x77, 0x92, 0x63, 0xa5, + 0xb7, 0xfe, 0x97, 0x22, 0xda, 0x5e, 0xd3, 0xaf, + 0xbc, 0x89, 0x0d, 0x4c, 0x37, 0xa9, 0x27, 0x4a, + 0x7f, 0xdb, 0x81, 0x39, 0x11, 0x86, 0x12, 0xf9, + 0x10, 0x50, 0xe4, 0xdb, 0x72, 0xf9, 0xae, 0x10, + 0x7c, 0xed, 0x50, 0x5c, 0x61, 0xeb, 0x42, 0x1e, + 0xa4, 0xf4, 0xf0, 0xfa, 0x45, 0x4d, 0x95, 0x2b, + 0xd4, 0x67, 0x4a, 0xe3, 0x8a, 0x15, 0x55, 0x92, + 0x77, 0x64, 0x8c, 0x51, 0x38, 0xf9, 0x26, 0x3e, + 0x68, 0xe2, 0xac, 0xbb, 0x64, 0x77, 0xe2, 0x82, + 0xa4, 0x42, 0x41, 0x38, 0xa0, 0xf0, 0xc9, 0xd8, + 0x6c, 0xe0, 0xef, 0x4c, 0xda, 0xb4, 0x92, 0xef, + 0x1b, 0xe3, 0x9b, 0xc1, 0x44, 0x3c, 0xb9, 0xb7, + 0x39, 0xac, 0x5c, 0x32, 0x39, 0xb4, 0x21, 0x85, + 0x93, 0xbc, 0xf2, 0x51, 0x43, 0xb7, 0xae, 0x1e, + 0x61, 0x9c, 0x38, 0x9c, 0xaa, 0xff, 0xde, 0xfc, + 0xbf, 0x85, 0xef, 0x17, 0x34, 0x36, 0x71, 0x5f, + 0x04, 0x16, 0xa6, 0x9e, 0xfd, 0x3a, 0x03, 0xd8, + 0xbf, 0x71, 0x70, 0x20, 0x8f, 0x7c, 0xfb, 0xff, + 0x61, 0xe0, 0xe2, 0x60, 0xa7, 0xb1, 0xc0, 0xe0, + 0xd9, 0x3f, 0xdc, 0x8d, 0x4a, 0xa4, 0x52, 0x61, + 0xaf, 0x9d, 0xdf, 0x8a, 0x0d, 0x41, 0xc0, 0x25, + 0x68, 0x12, 0x7b, 0xd5, 0xc7, 0xdb, 0x68, 0x70, + 0x2d, 0x7d, 0x95, 0x12, 0x03, 0x23, 0x0c, 0xe8, + 0x14, 0x41, 0x11, 0x28, 0xec, 0x9d, 0xd3, 0x28, + 0x77, 0x7a, 0x3c, 0x93, 0x8e, 0x5c, 0x7e, 0xb3, + 0x42, 0x9a, 0x18, 0x25, 0x93, 0xc8, 0xea, 0x43, + 0x1b, 0xbe, 0xd5, 0x27, 0xf1, 0xd4, 0xe0, 0x1e, + 0xce, 0xc7, 0xc7, 0x2c, 0x25, 0x35, 0x58, 0xb8, + 0x6c, 0xf3, 0xa2, 0xad, 0xe7, 0x58, 0x49, 0x47, + 0xf7, 0xca, 0xde, 0x8b, 0x81, 0xb7, 0x75, 0xf4, + 0x95, 0xa7, 0x5c, 0xc3, 0x2c, 0x0e, 0x1c, 0x52, + 0x9a, 0xc3, 0x2a, 0x00, 0x21, 0xa7, 0x51, 0x6b, + 0xf0, 0x05, 0x87, 0x8c, 0x42, 0x1b, 0xc3, 0x2e, + 0xa3, 0x76, 0x22, 0xd5, 0x7f, 0x56, 0x10, 0xef, + 0x98, 0x85, 0x65, 0x86, 0x71, 0x87, 0xd2, 0x8c, + 0xc0, 0x47, 0x20, 0xe8, 0xb5, 0x1c, 0xe3, 0xdd, + 0x3c, 0x5c, 0x03, 0xbb, 0x0e, 0x97, 0x3b, 0xe1, + 0x56, 0x9a, 0xd5, 0x0a, 0x63, 0xd5, 0x33, 0xaf, + 0x36, 0xca, 0xcf, 0x8f, 0x00, 0x28, 0xa3, 0x45, + 0xb8, 0xcd, 0xde, 0x73, 0xd4, 0xfa, 0x2d, 0x6f, + 0xdb, 0x93, 0xaa, 0xdd, 0x7f, 0xd2, 0x22, 0x9c, + 0x96, 0x48, 0x1e, 0xa8, 0x63, 0xbe, 0xbc, 0x0d, + 0x14, 0x3c, 0x2e, 0x11, 0x1f, 0xd2, 0xf4, 0x57, + 0xb3, 0x47, 0xf8, 0xa6, 0x1b, 0xc3, 0xa7, 0x95, + 0x2d, 0xd4, 0xca, 0xb8, 0x0d, 0xfb, 0x06, 0x85, + 0xda, 0x63, 0xf0, 0x3e, 0x9d, 0x5e, 0xee, 0xce, + 0xed, 0x74, 0x1d, 0x2c, 0x97, 0x3f, 0x71, 0x95, + 0x12, 0x03, 0xc5, 0x92, 0x46, 0x84, 0x1b, 0x07, + 0xe6, 0xb4, 0x1d, 0x3a, 0xf1, 0x89, 0x90, 0x50, + 0x10, 0x29, 0x34, 0xc0, 0x90, 0xbe, 0x4a, 0xa9, + 0x0d, 0xb0, 0x7b, 0xfb, 0x35, 0xee, 0x4e, 0x34, + 0xec, 0x5a, 0x58, 0xbc, 0xb8, 0xda, 0x38, 0x88, + 0x8c, 0x74, 0x1e, 0xc9, 0xab, 0x78, 0x2e, 0x2a, + 0x17, 0x8a, 0x43, 0x3d, 0xa1, 0x2a, 0x41, 0xb5, + 0xd6, 0xe8, 0x5b, 0xc5, 0x4a, 0x1c, 0x3c, 0x9f, + 0x8d, 0x3a, 0x69, 0x88, 0xf8, 0x80, 0xd2, 0x11, + 0xfc, 0x7e, 0x80, 0x8e, 0x7f, 0x85, 0x64, 0x9c, + 0x46, 0x58, 0xc8, 0x48, 0x98, 0x4b, 0xf5, 0x73, + 0x3f, 0x49, 0xce, 0x53, 0x2c, 0xd5, 0xfc, 0x33, + 0xf1, 0x6f, 0xd8, 0xe9, 0x2e, 0x70, 0x2e, 0xdc, + 0xe5, 0x43, 0x80, 0x38, 0xf2, 0x87, 0xed, 0x85, + 0xe4, 0x3e, 0x45, 0x14, 0x20, 0xcf, 0xa0, 0x61, + 0x4f, 0xe8, 0xd7, 0x5b, 0xb3, 0x0d, 0x0e, 0x4e, + 0x4d, 0xce, 0xbe, 0xba, 0xaa, 0x90, 0x09, 0xcb, + 0x4b, 0x5d, 0x08, 0xff, 0x52, 0xd5, 0x23, 0xbc, + 0xad, 0x8d, 0xd3, 0x06, 0x4a, 0xa0, 0x51, 0x56, + 0xa7, 0xd8, 0x33, 0xab, 0xbc, 0xd0, 0xdf, 0x92, + 0x87, 0x20, 0x2d, 0x7b, 0x5e, 0xfa, 0x30, 0xa7, + 0x06, 0x06, 0xe5, 0x4f, 0x2c, 0xb5, 0x61, 0xd7, + 0x54, 0xd3, 0xdf, 0xd0, 0x0a, 0xb0, 0x06, 0xce, + 0xf6, 0x86, 0xb7, 0x8e, 0xaa, 0x7b, 0x78, 0xd5, + 0xb9, 0xeb, 0x07, 0xac, 0x5f, 0xc5, 0xd2, 0x8c, + 0x40, 0xe0, 0x7f, 0x98, 0xd4, 0xe5, 0x4b, 0xca, + 0xfb, 0x47, 0xef, 0xef, 0xb9, 0x4d, 0x6d, 0x8f, + 0x82, 0x68, 0x74, 0x84, 0xe0, 0x0a, 0x93, 0x0f, + 0xb2, 0x01, 0xa9, 0x9f, 0x68, 0x6a, 0xe8, 0xf7, + 0xfb, 0x0b, 0xde, 0x17, 0xe0, 0x30, 0x38, 0x51, + 0xbc, 0x07, 0xb8, 0x2c, 0x91, 0x0f, 0xc1, 0x0e, + 0xa6, 0xf9, 0xf0, 0xd5, 0x48, 0x76, 0x8a, 0xde, + 0x74, 0xe3, 0x30, 0x65, 0x56, 0xb3, 0x5c, 0xe2, + 0x89, 0x8d, 0xda, 0x80, 0xad, 0x0f, 0x22, 0xfb, + 0x24, 0x1d, 0x16, 0xdd, 0x34, 0x4b, 0x90, 0x58, + 0x4e, 0x0c, 0x13, 0x28, 0xcf, 0x1d, 0xa4, 0xaa, + 0xb7, 0xf3, 0xb1, 0x66, 0xad, 0x3b, 0xcf, 0x79, + 0x12, 0x04, 0xd7, 0x79, 0xd9, 0x5f, 0xdf, 0x89, + 0xb2, 0x5b, 0xa7, 0x9a, 0x26, 0x1e, 0x67, 0x46, + 0x7c, 0x66, 0x95, 0x67, 0xe6, 0x45, 0x8b, 0x1f, + 0x65, 0x79, 0x9f, 0x6d, 0x11, 0x81, 0x17, 0x0d, + 0x11, 0xb0, 0x5c, 0xb4, 0xc7, 0x27, 0x87, 0xab, + 0x5d, 0x0a, 0x18, 0xae, 0x4e, 0x06, 0xa3, 0x3d, + 0xc7, 0xb0, 0x22, 0xba, 0x03, 0xa4, 0x0f, 0xe5, + 0x1c, 0x72, 0x2a, 0x04, 0xce, 0x83, 0xe9, 0xf3, + 0xd7, 0xc9, 0x67, 0x6c, 0x1e, 0x6b, 0x3c, 0x9b, + 0x0b, 0x5e, 0x6a, 0xa6, 0x79, 0x0a, 0xf1, 0xbe, + 0xd7, 0xb4, 0x6f, 0x45, 0x1e, 0xfb, 0x78, 0x97, + 0xaf, 0x34, 0x76, 0x95, 0x52, 0xf7, 0x3d, 0x5d, + 0x07, 0x28, 0x57, 0x9c, 0x4a, 0x0f, 0xcf, 0x0b, + 0x1b, 0xc4, 0xc2, 0x72, 0xd7, 0x72, 0x38, 0x9b, + 0xea, 0xeb, 0xee, 0xae, 0x34, 0xc8, 0x01, 0xd7, + 0xa5, 0xe3, 0xce, 0x41, 0xad, 0x02, 0x60, 0x23, + 0x18, 0x36, 0xba, 0x17, 0xfa, 0xcf, 0xe4, 0xda, + 0xdc, 0xfc, 0x82, 0xdc, 0x7c, 0x11, 0xf4, 0xb8, + 0x52, 0x5d, 0xf7, 0x2f, 0xc8, 0xfe, 0x4a, 0xe6, + 0xb9, 0xaf, 0x4b, 0x17, 0x18, 0x91, 0xc2, 0xfe, + 0xd7, 0x3a, 0x77, 0x0c, 0xa0, 0x43, 0x9c, 0x6f, + 0x13, 0x06, 0xbe, 0x6e, 0xe0, 0x1a, 0x3c, 0xf3, + 0xf5, 0xcc, 0x78, 0xfb, 0x5d, 0xd5, 0xda, 0xb7, + 0x58, 0xea, 0x86, 0x42, 0x6b, 0x32, 0xff, 0xb2, + 0xe2, 0xee, 0x03, 0x1f, 0xf4, 0xef, 0xdb, 0x53, + 0x79, 0xd5, 0x4e, 0xaf, 0x60, 0x8e, 0x02, 0xc2, + 0xcc, 0x39, 0x97, 0x7b, 0xfd, 0xa1, 0xf8, 0x7a, + 0x26, 0xe8, 0x55, 0xd6, 0xa4, 0x8b, 0xa0, 0x1b, + 0x2d, 0x63, 0xaa, 0x73, 0x71, 0x6e, 0xbf, 0x8b, + 0x3b, 0xe3, 0x1b, 0x0d, 0xbb, 0x2e, 0x44, 0x09, + 0x64, 0xac, 0xc7, 0x9e, 0xb5, 0xc6, 0x77, 0xb0, + 0x79, 0xb3, 0xaa, 0xfc, 0x67, 0x57, 0x9a, 0x50, + 0x81, 0x37, 0x14, 0x7c, 0xd7, 0xa0, 0xd4, 0x6a, + 0x79, 0x84, 0x51, 0x0e, 0x95, 0x0a, 0x30, 0xa3, + 0x60, 0x55, 0x48, 0x05, 0x16, 0xae, 0x43, 0x90, + 0xdc, 0x8e, 0x09, 0xbe, 0x79, 0xf6, 0x90, 0x74, + 0xf8, 0x20, 0x96, 0x4d, 0xa7, 0xf5, 0x1a, 0x2b, + 0xc7, 0x15, 0x9d, 0x18, 0xf7, 0x94, 0x87, 0xf7, + 0xf4, 0xfb, 0x0d, 0x61, 0xb6, 0xd7, 0xbe, 0x10, + 0x8e, 0x47, 0x3c, 0x10, 0x44, 0x90, 0x52, 0x21, + 0x83, 0xc0, 0xf5, 0x99, 0xaa, 0xbc, 0xf6, 0x55, + 0xae, 0xf5, 0xb2, 0xa4, 0xcd, 0x4d, 0xb9, 0x38, + 0x6c, 0xbc, 0x80, 0xc3, 0xad, 0xf4, 0x46, 0x31, + 0x01, 0x58, 0x2d, 0x88, 0x57, 0xc3, 0x23, 0xd1, + 0x64, 0xc9, 0xa3, 0x21, 0x6b, 0x8b, 0x8a, 0x23, + 0x2c, 0x4f, 0xa9, 0xcd, 0x67, 0xfa, 0x77, 0xad, + 0xa3, 0x16, 0xa2, 0xe5, 0x19, 0x14, 0x70, 0x41, + 0x5b, 0xda, 0x14, 0xde, 0xe3, 0xe5, 0xc1, 0x15, + 0xb4, 0x77, 0xa4, 0x9b, 0xb8, 0xb1, 0x28, 0x51, + 0x30, 0xb4, 0xf1, 0xf3, 0xf8, 0x6d, 0xd0, 0xc3, + 0x8c, 0x4c, 0x76, 0xb0, 0x9a, 0xdf, 0xc8, 0xbe, + 0xf8, 0x4a, 0x61, 0x6e, 0x3e, 0xd6, 0x3c, 0xe8, + 0xde, 0x56, 0xa0, 0x9c, 0x25, 0xbe, 0xce, 0x93, + 0x1f, 0x88, 0xfb, 0x9a, 0x1a, 0xe2, 0xff, 0x88, + 0xad, 0x10, 0xcb, 0x6c, 0xd6, 0xe7, 0x39, 0x0b, + 0xe5, 0x1a, 0x06, 0x05, 0x64, 0x5b, 0x0a, 0xdf, + 0x22, 0x58, 0xd7, 0xfb, 0x88, 0x12, 0xdd, 0xb7, + 0x52, 0x3a, 0xc9, 0xbf, 0x49, 0xdf, 0x8c, 0x87, + 0x9f, 0x84, 0xb5, 0x0a, 0xf6, 0x00, 0x52, 0xae, + 0x67, 0x12, 0x1a, 0x8c, 0x71, 0x15, 0xf5, 0xa1, + 0x13, 0x39, 0xf0, 0x91, 0x7e, 0x88, 0x7c, 0xb3, + 0x95, 0x50, 0x02, 0xa6, 0x63, 0xb5, 0x64, 0xfb, + 0x90, 0x87, 0x61, 0xe2, 0x27, 0xaf, 0x11, 0x0c, + 0x73, 0x83, 0xef, 0xa9, 0x28, 0xfe, 0xc8, 0x85, + 0x1a, 0x3a, 0xde, 0xf2, 0xe5, 0x25, 0x64, 0x6d, + 0xaa, 0x41, 0x4c, 0x80, 0x2e, 0x84, 0xff, 0xc1, + 0xc0, 0x54, 0x0c, 0x29, 0x1b, 0xa3, 0x07, 0x7c, + 0x33, 0x4c, 0x10, 0xf6, 0x6f, 0x79, 0xdf, 0xd3, + 0xf0, 0x24, 0x57, 0xf1, 0x60, 0xe1, 0xf0, 0xbd, + 0xc4, 0x1f, 0xf4, 0x67, 0xd2, 0xd3, 0xcc, 0x6a, + 0x07, 0x72, 0x44, 0x16, 0x85, 0x46, 0xd0, 0x73, + 0x87, 0xa9, 0xc7, 0x2f, 0xd1, 0xf5, 0xec, 0xe3, + 0x28, 0xa3, 0x93, 0x4f, 0xd7, 0x76, 0xc1, 0x3c, + 0x0d, 0x13, 0x33, 0xcf, 0x5b, 0xbd, 0x6a, 0x52, + 0x4e, 0xee, 0xc8, 0x5e, 0xa1, 0x58, 0x4a, 0x08, + 0x81, 0xd9, 0x23, 0xcc, 0xfb, 0x1c, 0xb2, 0xd8, + 0xa3, 0xe4, 0x53, 0xfe, 0xf4, 0x4b, 0x48, 0xc1, + 0x20, 0xa4, 0x97, 0xf8, 0x38, 0xa3, 0x69, 0xc1, + 0x11, 0xf0, 0xa1, 0x3b, 0xa9, 0x9a, 0x12, 0x61, + 0xe8, 0x8d, 0x99, 0x44, 0x3f, 0x94, 0x72, 0x82, + 0x19, 0x96, 0x62, 0xb0, 0xa6, 0x64, 0x05, 0x19, + 0x8f, 0xd6, 0x5d, 0x05, 0xbf, 0x79, 0x9e, 0x9d, + 0xe4, 0x93, 0x4c, 0xad, 0x61, 0x8c, 0x18, 0xda, + 0xb6, 0x2e, 0xb3, 0xca, 0x14, 0x4d, 0x53, 0xa4, + 0x97, 0x27, 0x10, 0x56, 0xa2, 0x67, 0x5a, 0x5a, + 0x5e, 0x13, 0xc0, 0xdb, 0xa7, 0x9f, 0x45, 0x5b, + 0xeb, 0x1a, 0x14, 0x0c, 0x8c, 0x38, 0x5e, 0x77, + 0x9a, 0xec, 0x75, 0x68, 0x93, 0x65, 0x02, 0x9c, + 0xfb, 0x62, 0x60, 0x49, 0xdd, 0xb2, 0x2a, 0x67, + 0x86, 0xe3, 0x8a, 0x7d, 0x8c, 0x46, 0x78, 0x81, + 0x60, 0x69, 0xf2, 0x3f, 0x74, 0x11, 0x35, 0xff, + 0x77, 0xa3, 0x66, 0x20, 0xfc, 0x98, 0x4a, 0x35, + 0x7a, 0x52, 0xe4, 0x90, 0x13, 0x80, 0xb9, 0xa6, + 0x73, 0x7a, 0x7d, 0x66, 0x6e, 0x6b, 0xb6, 0x43, + 0x10, 0xd5, 0x91, 0x2b, 0x66, 0xdd, 0x89, 0x87, + 0xe3, 0x8c, 0x58, 0x53, 0x2f, 0x40, 0x74, 0x45, + 0x1b, 0x77, 0x7a, 0xa4, 0x44, 0x19, 0x78, 0xba, + 0x87, 0x10, 0x41, 0x31, 0x32, 0x5f, 0x87, 0x68, + 0xde, 0x43, 0x4a, 0xef, 0x33, 0xb3, 0x11, 0x83, + 0xa9, 0xc2, 0x6f, 0x8d, 0x34, 0xe2, 0x95, 0x84, + 0x3a, 0x4f, 0x6f, 0x8c, 0x31, 0x1d, 0xb6, 0xf5, + 0x95, 0x0d, 0x01, 0x11, 0x20, 0xdf, 0x72, 0xf3, + 0x3f, 0x9a, 0x33, 0xaa, 0xb1, 0x06, 0x6a, 0x63, + 0x47, 0x91, 0x01, 0xdf, 0xb3, 0x54, 0x36, 0xfd, + 0x06, 0x2d, 0xb8, 0x08, 0xe3, 0xd3, 0x65, 0xac, + 0x66, 0x03, 0xee, 0xa4, 0x63, 0xbd, 0xd4, 0xce, + 0xbd, 0x79, 0xa7, 0x48, 0x38, 0xc5, 0x7d, 0xb5, + 0x71, 0x9a, 0x3c, 0x11, 0x7c, 0x6c, 0xe2, 0x54, + 0x02, 0x5d, 0x42, 0xab, 0x25, 0x93, 0x66, 0x01, + 0x37, 0x78, 0x35, 0x4a, 0x8c, 0x19, 0x4d, 0x00, + 0x75, 0x4f, 0xcc, 0xc0, 0x26, 0x82, 0xc1, 0x35, + 0x8c, 0xc7, 0xc2, 0x59, 0x01, 0x3e, 0x98, 0x22, + 0x88, 0x9c, 0x90, 0x75, 0x05, 0x33, 0x07, 0xb9, + 0x39, 0x81, 0x38, 0x58, 0x10, 0x29, 0xcf, 0xc8, + 0x98, 0xb2, 0x03, 0xd7, 0x5b, 0xb3, 0x18, 0xba, + 0x34, 0x0c, 0x9f, 0xab, 0xd7, 0xed, 0x29, 0x82, + 0x41, 0xe0, 0x20, 0x97, 0x57, 0x92, 0xb2, 0xb8, + 0x10, 0x2d, 0x0b, 0xa2, 0xc5, 0x8f, 0x90, 0x6f, + 0xed, 0x12, 0x56, 0x25, 0xbe, 0xfd, 0x75, 0xf7, + 0xb6, 0xf8, 0x40, 0x67, 0x39, 0x11, 0xfa, 0x15, + 0xae, 0x6a, 0x54, 0x5f, 0x32, 0x2b, 0xf8, 0x48, + 0x55, 0xbe, 0x86, 0x2f, 0x69, 0x48, 0x5b, 0x5d, + 0x4d, 0xb7, 0x35, 0xaa, 0xb6, 0x91, 0x88, 0x19, + 0x96, 0x1c, 0x68, 0xf6, 0x85, 0x9e, 0xb3, 0xb2, + 0xa3, 0x32, 0xd4, 0x52, 0x70, 0xb7, 0x62, 0xe3, + 0x14, 0xb6, 0x78, 0x5f, 0x1b, 0x1d, 0x04, 0x9c, + 0x26, 0x0c, 0x33, 0x94, 0xb1, 0x97, 0x08, 0xdb, + 0x0b, 0x39, 0x29, 0xd4, 0xbc, 0x6d, 0xdf, 0x02, + 0xc6, 0x99, 0xab, 0x99, 0x32, 0xe5, 0xce, 0x51, + 0x4f, 0xae, 0xb8, 0x8b, 0xe0, 0xaf, 0x07, 0xc4, + 0xf9, 0x41, 0x7c, 0x59, 0xa0, 0xac, 0x74, 0x4d, + 0x7e, 0x43, 0x77, 0x9c, 0x06, 0x49, 0x79, 0x8a, + 0x14, 0x73, 0x93, 0xa8, 0x5b, 0x1b, 0x34, 0x29, + 0x78, 0x04, 0x2f, 0xd7, 0x1f, 0x13, 0x90, 0xe0, + 0xdd, 0x3b, 0x42, 0x6b, 0x79, 0x6e, 0x52, 0xc7, + 0x0f, 0x38, 0xda, 0x01, 0x2c, 0x8d, 0xe6, 0x94, + 0x5d, 0x59, 0x27, 0x1d, 0x10, 0x4e, 0x11, 0x36, + 0xfb, 0x53, 0x16, 0x05, 0x25, 0xf2, 0x64, 0xd8, + 0xf9, 0xcd, 0x5c, 0xfe, 0xb4, 0x18, 0x44, 0x80, + 0x10, 0xbc, 0x3d, 0xf3, 0x1d, 0x5a, 0xf0, 0xc1, + 0xc3, 0x55, 0xff, 0x41, 0x3e, 0xe3, 0xef, 0x44, + 0xb2, 0xc0, 0x01, 0x18, 0xa2, 0x49, 0x88, 0x78, + 0x0d, 0x4c, 0xc8, 0x73, 0xcf, 0x30, 0x85, 0x3a, + 0x88, 0x90, 0x01, 0xcf, 0x69, 0x53, 0xa3, 0x18, + 0x3f, 0xd6, 0xe7, 0x94, 0x14, 0xa7, 0xae, 0xcd, + 0x6f, 0x11, 0x72, 0xfe, 0x2b, 0xb0, 0x81, 0x53, + 0xea, 0x67, 0xd6, 0xe4, 0xca, 0x42, 0xa0, 0xf9, + 0xb1, 0xd4, 0xb5, 0x3b, 0xc9, 0xf0, 0x36, 0xc1, + 0x1c, 0xf4, 0xb1, 0xf6, 0x84, 0xd0, 0x86, 0x6c, + 0x76, 0x9a, 0x03, 0xc2, 0xb6, 0x2e, 0x9a, 0x46, + 0xf5, 0x5f, 0x2c, 0x38, 0xac, 0xad, 0x6f, 0x2e, + 0x7a, 0x18, 0x2d, 0x22, 0x95, 0x5e, 0x5e, 0xc9, + 0x7a, 0x0a, 0x56, 0xe1, 0xc7, 0x15, 0xfd, 0xbf, + 0xff, 0xf7, 0x7e, 0x85, 0x20, 0xa9, 0x8a, 0x9c, + 0xa9, 0x7d, 0xe8, 0xed, 0xfc, 0x7f, 0xbb, 0xf0, + 0x05, 0x3f, 0xce, 0x4f, 0x4c, 0xee, 0xa4, 0xa0, + 0xcc, 0x9c, 0x62, 0x1e, 0xd6, 0xd0, 0x30, 0x37, + 0xb8, 0x98, 0x56, 0x1d, 0xaa, 0xd6, 0x5e, 0x73, + 0x12, 0xe4, 0x88, 0x82, 0x48, 0x64, 0x06, 0xd7, + 0x2a, 0x31, 0x50, 0x7b, 0x10, 0x17, 0xb8, 0x4c, + 0x5a, 0x8d, 0xf1, 0xfc, 0xf1, 0x33, 0x3b, 0x98, + 0x42, 0x18, 0x5b, 0x35, 0x78, 0xca, 0x8e, 0x41, + 0x52, 0xae, 0x6d, 0xe1, 0xa2, 0x9d, 0x5b, 0xbd, + 0xf3, 0x5f, 0x49, 0xc1, 0x27, 0x06, 0xc1, 0xaf, + 0xc0, 0xa3, 0x9d, 0xf3, 0x1c, 0x8e, 0x90, 0x8a, + 0xb0, 0x69, 0xb0, 0xc5, 0x11, 0x0c, 0x91, 0x14, + 0x1f, 0x5e, 0x10, 0xe1, 0x1d, 0x14, 0x30, 0x54, + 0x1e, 0x17, 0x3d, 0x31, 0x7b, 0xbf, 0x2f, 0x9d, + 0x6d, 0x63, 0x32, 0xf0, 0x9d, 0x9f, 0x95, 0x3d, + 0x0b, 0xd2, 0x4d, 0x10, 0xe2, 0x3f, 0x67, 0x69, + 0x43, 0x9a, 0x4a, 0x2c, 0x54, 0x71, 0xa8, 0xa0, + 0x9e, 0x9f, 0x10, 0xaf, 0x1b, 0xce, 0x99, 0xe3, + 0x25, 0x32, 0x10, 0x54, 0x80, 0xfe, 0xda, 0x57, + 0xd0, 0xb2, 0x92, 0x7f, 0xbb, 0x5f, 0xe7, 0x4d, + 0x1b, 0x3d, 0x46, 0x4d, 0xe4, 0x4c, 0xd6, 0xaf, + 0x1a, 0x32, 0x12, 0x40, 0xb8, 0x84, 0x8e, 0xe4, + 0x80, 0xce, 0x7e, 0xc1, 0x13, 0x8b, 0xb0, 0xb7, + 0x6f, 0x24, 0xba, 0x85, 0x50, 0x83, 0xc3, 0xcf, + 0x19, 0xb3, 0xf0, 0xc7, 0xee, 0x68, 0xbe, 0x9e, + 0x6d, 0xb9, 0xfb, 0xd5, 0x29, 0xce, 0x82, 0xcd, + 0x69, 0x16, 0x68, 0x6b, 0x6a, 0xf4, 0x02, 0x32, + 0xce, 0x60, 0x37, 0x0c, 0xb9, 0x38, 0x92, 0x9c, + 0x42, 0xa9, 0x0b, 0x53, 0x96, 0xfe, 0x39, 0xc1, + 0x24, 0x65, 0x9b, 0xcd, 0xe7, 0x8d, 0x36, 0x07, + 0x9f, 0x1d, 0x35, 0x8e, 0xdc, 0x4c, 0xb5, 0x68, + 0xc5, 0xfd, 0x44, 0x19, 0xf2, 0x6c, 0x59, 0x1c, + 0xb1, 0x0b, 0x35, 0x48, 0x86, 0x1a, 0x05, 0x22, + 0x03, 0x0c, 0x0c, 0xa2, 0x92, 0x90, 0x35, 0xfb, + 0x37, 0x94, 0xc7, 0x15, 0x84, 0xae, 0xe8, 0x05, + 0xa0, 0xf7, 0x30, 0x11, 0x5c, 0xe4, 0x5d, 0x3e, + 0x12, 0x54, 0x80, 0x54, 0x6b, 0x09, 0x8c, 0xce, + 0x80, 0x5e, 0xa7, 0xc8, 0x6a, 0x0c, 0x56, 0xe1, + 0x18, 0x7d, 0xc9, 0x39, 0xc1, 0xef, 0xe3, 0x25, + 0xa0, 0x8b, 0x2f, 0x60, 0x3a, 0x43, 0x39, 0xa6, + 0x28, 0x28, 0x7b, 0x4c, 0x77, 0xd4, 0x49, 0x61, + 0x46, 0xe9, 0x1b, 0x45, 0xd6, 0xb1, 0x56, 0xe1, + 0x7d, 0x34, 0xcd, 0x06, 0xb6, 0x67, 0x8d, 0x7d, + 0x7a, 0xe2, 0xbe, 0x68, 0x35, 0xa6, 0x78, 0xe5, + 0x47, 0x48, 0xb7, 0xc7, 0xde, 0xcd, 0xc9, 0x05, + 0xb4, 0xe7, 0x50, 0x48, 0xe1, 0x4b, 0xfe, 0x76, + 0x77, 0xc6, 0xf7, 0x5f, 0xcb, 0xc2, 0xa8, 0xd7, + 0xd6, 0x8a, 0xe5, 0x49, 0xd9, 0xca, 0x45, 0xf4, + 0xda, 0xcd, 0x33, 0xd1, 0x59, 0x2d, 0x9e, 0xc1, + 0x5c, 0xe6, 0x01, 0x18, 0xb8, 0xf0, 0x5e, 0xb1, + 0x69, 0x95, 0x2f, 0x02, 0x2a, 0xe7, 0x4a, 0xd7, + 0xd1, 0xc3, 0xd5, 0x6f, 0x15, 0xc8, 0xdc, 0x29, + 0xde, 0xb9, 0x3f, 0x8b, 0xa6, 0xbc, 0xdd, 0x25, + 0x84, 0x35, 0x3c, 0x90, 0x2d, 0xc2, 0x1e, 0x98, + 0x8a, 0x50, 0x09, 0x77, 0x42, 0xe9, 0x35, 0x8a, + 0x7c, 0x97, 0xbf, 0xe8, 0xbf, 0x56, 0xd0, 0x8b, + 0x65, 0xd3, 0xaf, 0x1e, 0x05, 0x94, 0xfa, 0xac, + 0xa8, 0x2b, 0x28, 0xcb, 0x37, 0x3e, 0xe8, 0xbb, + 0x66, 0x3a, 0xed, 0xb2, 0x48, 0x10, 0x0f, 0x3a, + 0x5a, 0xc5, 0xdb, 0x26, 0x0e, 0xaa, 0x5e, 0x69, + 0x15, 0xd6, 0x81, 0xae, 0xbd, 0xe6, 0x03, 0xf1, + 0xf6, 0x37, 0xc8, 0xde, 0x70, 0x1f, 0x64, 0xb9, + 0x5e, 0xbf, 0x2e, 0x4f, 0xb1, 0xea, 0xa0, 0x17, + 0xe6, 0x7c, 0xf9, 0x2f, 0x1e, 0xd8, 0x58, 0xde, + 0xa7, 0xf0, 0x46, 0x52, 0x95, 0xdf, 0xa4, 0x96, + 0xd0, 0xc4, 0x97, 0x2b, 0x95, 0xcd, 0x5e, 0x40, + 0x23, 0x5c, 0x10, 0xee, 0xba, 0x72, 0x9b, 0xcf, + 0x0b, 0xe8, 0x18, 0x3a, 0x70, 0xd2, 0x5e, 0x07, + 0x68, 0x93, 0xef, 0x4a, 0x5b, 0x8d, 0x72, 0x41, + 0x4e, 0xea, 0x33, 0x6a, 0x0a, 0x5e, 0xfb, 0x02, + 0x3f, 0xd4, 0xed, 0x5b, 0xe0, 0x42, 0x84, 0xd4, + 0xaa, 0x85, 0xdc, 0x5b, 0x67, 0xee, 0x71, 0x67, + 0xba, 0x8e, 0xd2, 0xbe, 0x61, 0xdf, 0x5a, 0x26, + 0xb9, 0xf0, 0x77, 0x81, 0x53, 0x24, 0x16, 0xcb, + 0x8c, 0xb8, 0x06, 0x6e, 0x68, 0xda, 0xc8, 0x2d, + 0x17, 0x54, 0xdb, 0x46, 0xcb, 0xfd, 0x1f, 0x3d, + 0x94, 0x81, 0x09, 0x4b, 0xfa, 0xb1, 0x46, 0xd9, + 0x11, 0xa3, 0xb7, 0x31, 0x9c, 0xd2, 0x38, 0xd6, + 0xba, 0x3d, 0xa3, 0x74, 0xd8, 0xf1, 0x24, 0xe8, + 0x9c, 0xcb, 0x1d, 0xf9, 0x4a, 0xf7, 0xc8, 0x4b, + 0xfe, 0x97, 0x7c, 0xa1, 0x02, 0xeb, 0x40, 0xc3, + 0x89, 0x71, 0x01, 0xcd, 0x33, 0x2a, 0xc2, 0x82, + 0xce, 0x62, 0x8d, 0x53, 0x7c, 0xdf, 0xce, 0xd7, + 0xf5, 0xa8, 0x4f, 0xf2, 0xf2, 0x2e, 0xc1, 0xeb, + 0x97, 0x99, 0x37, 0x3c, 0x53, 0xa6, 0xb4, 0x46, + 0x05, 0x64, 0x92, 0x87, 0x08, 0x3c, 0x23, 0x4b, + 0x9d, 0x67, 0x18, 0xf9, 0xe2, 0x0b, 0x1c, 0x39, + 0xd3, 0x87, 0x70, 0xc0, 0xb9, 0x1e, 0x52, 0x0a, + 0x0f, 0x48, 0xe2, 0xe7, 0x51, 0x72, 0x94, 0xf7, + 0xa3, 0xdc, 0xe5, 0x66, 0x33, 0x39, 0x54, 0x06, + 0x55, 0x93, 0x30, 0xf9, 0x5e, 0x76, 0x8f, 0xe0, + 0x59, 0x4d, 0x0d, 0xa7, 0xf5, 0xbe, 0xdb, 0x20, + 0xad, 0x0d, 0x76, 0x88, 0x5f, 0x9c, 0x7c, 0x75, + 0x2f, 0x2a, 0x0b, 0x79, 0x6e, 0xd3, 0xe2, 0x66, + 0xf5, 0x4a, 0x2d, 0x87, 0x87, 0x49, 0x84, 0x17, + 0xa2, 0x62, 0x4c, 0xbb, 0xe4, 0x6e, 0x98, 0x10, + 0xc9, 0xfb, 0x8a, 0x04, 0x68, 0x8d, 0x22, 0x66, + 0xad, 0xea, 0x2a, 0xc9, 0x97, 0x2d, 0x3c, 0xbc, + 0xd0, 0x77, 0x5f, 0xe6, 0xb8, 0x7f, 0xe6, 0xf6, + 0x39, 0xbf, 0x56, 0x0e, 0x26, 0x6d, 0xc5, 0x3e, + 0x53, 0x19, 0xd6, 0xb4, 0x57, 0x36, 0xa3, 0xc6, + 0xd3, 0x3d, 0x66, 0x79, 0x30, 0x5c, 0x14, 0x0c, + 0x0f, 0x3e, 0x96, 0xae, 0x90, 0x97, 0xab, 0x0d, + 0x9f, 0xc3, 0xe7, 0x66, 0x3e, 0xe0, 0x31, 0x43, + 0x4b, 0x01, 0xb3, 0x0e, 0x9e, 0x8c, 0x82, 0x4a, + 0x8c, 0xc7, 0x79, 0x85, 0xdf, 0x75, 0x0d, 0xb4, + 0x2b, 0x03, 0x14, 0xef, 0x72, 0x58, 0xfd, 0x64, + 0xc8, 0xe3, 0x0d, 0x9a, 0x14, 0x6f, 0x76, 0xf9, + 0x46, 0xd1, 0xd2, 0x81, 0xb3, 0x16, 0x6e, 0xc7, + 0x76, 0x82, 0xce, 0xf4, 0xee, 0x33, 0x00, 0xe6, + 0x77, 0xc4, 0xad, 0x4f, 0x06, 0xa7, 0x48, 0x80, + 0x9e, 0x21, 0x66, 0xca, 0x75, 0x69, 0x57, 0xcb, + 0xf0, 0x67, 0x6a, 0xaa, 0x8f, 0x88, 0x14, 0xbd, + 0x65, 0x62, 0xe2, 0xad, 0xcc, 0x22, 0x88, 0x7b, + 0x94, 0xbd, 0x0e, 0xcd, 0xb6, 0x69, 0xa2, 0xcb, + 0x7d, 0x57, 0x5c, 0xb4, 0x92, 0x80, 0x13, 0x99, + 0x84, 0xf3, 0x79, 0x0a, 0x2d, 0x70, 0xa4, 0xe0, + 0xde, 0xc6, 0x32, 0xb0, 0x8a, 0x62, 0xb5, 0xcf, + 0xfa, 0x5e, 0x5a, 0x92, 0x32, 0x7d, 0x34, 0x07, + 0xb5, 0x52, 0x3a, 0xb5, 0x7d, 0x0f, 0xa1, 0xba, + 0x56, 0xd0, 0x07, 0x76, 0x11, 0xf2, 0xc3, 0x33, + 0x9d, 0xbd, 0x12, 0x35, 0x5e, 0xf7, 0x05, 0x88, + 0x76, 0x94, 0xa6, 0xbf, 0xed, 0xb8, 0xa4, 0xa2, + 0x0c, 0xbe, 0x0f, 0x6a, 0xaf, 0xf3, 0x1b, 0x33, + 0x4a, 0xb7, 0x68, 0x3f, 0xbe, 0x95, 0x13, 0x97, + 0x0f, 0x15, 0x17, 0x1b, 0x23, 0xaa, 0x08, 0x78, + 0xa6, 0x5b, 0x08, 0xa2, 0x9d, 0x03, 0xa8, 0xa7, + 0x39, 0xdc, 0xbc, 0x9a, 0x85, 0xf5, 0xe5, 0x55, + 0x59, 0x3c, 0xef, 0xf9, 0x3f, 0x22, 0x8e, 0xf8, + 0xd8, 0x3e, 0x02, 0x0b, 0xd8, 0x78, 0x4b, 0x15, + 0x7f, 0xaa, 0x2c, 0xff, 0xbe, 0x77, 0x33, 0xc7, + 0x6a, 0x12, 0xaa, 0xa4, 0xbe, 0xc0, 0x3b, 0xcb, + 0x13, 0x9d, 0x9c, 0x5a, 0x9f, 0x8a, 0x57, 0x36, + 0x4f, 0x02, 0x5a, 0xf8, 0x1d, 0x97, 0x77, 0x43, + 0xc8, 0xa5, 0xb7, 0x9b, 0x10, 0x98, 0xfd, 0x58, + 0xbf, 0x42, 0xf6, 0xbf, 0xff, 0x6c, 0x40, 0x18, + 0x18, 0xdf, 0xac, 0x57, 0x71, 0xea, 0xcc, 0x8e, + 0xfd, 0xfe, 0x10, 0xfb, 0xb9, 0xfe, 0xbc, 0x9a, + 0x9c, 0x27, 0xe4, 0x10, 0x15, 0x94, 0x41, 0xa1, + 0xcc, 0xf6, 0x25, 0x49, 0x4f, 0x96, 0xc1, 0x8c, + 0x9e, 0x3e, 0x18, 0x29, 0x49, 0x92, 0xe7, 0xfe, + 0x22, 0xff, 0xed, 0x02, 0x16, 0x90, 0xef, 0xac, + 0xec, 0x95, 0x1d, 0x5b, 0x94, 0x9c, 0xf6, 0x7c, + 0x1b, 0x5a, 0x9d, 0xb0, 0x9b, 0x05, 0x36, 0xbf, + 0xef, 0xec, 0x63, 0x35, 0x40, 0x24, 0x45, 0x40, + 0x30, 0x1a, 0x9b, 0x90, 0xc3, 0xc2, 0xf7, 0x37, + 0xfb, 0x08, 0x8e, 0x48, 0x19, 0x48, 0xed, 0xa8, + 0xa8, 0x04, 0x6f, 0xd0, 0x33, 0xe9, 0xb8, 0x8d, + 0xe7, 0x1e, 0x5c, 0x47, 0x74, 0xc0, 0x66, 0x30, + 0x4e, 0xa7, 0x86, 0x73, 0xf1, 0xe5, 0x78, 0xa6, + 0xe0, 0xc1, 0xda, 0x13, 0x72, 0x07, 0x85, 0x34, + 0x63, 0x95, 0x49, 0x30, 0x4b, 0x9d, 0x03, 0xf1, + 0x7a, 0x6b, 0x91, 0xa2, 0x85, 0x41, 0xf9, 0x4a, + 0xd6, 0xff, 0xff, 0x86, 0xf7, 0xf0, 0xce, 0xb9, + 0x07, 0xf1, 0x88, 0x04, 0x33, 0xaa, 0xeb, 0x54, + 0xb2, 0x1c, 0x8e, 0x2e, 0x7b, 0x04, 0xa8, 0xcc, + 0x2c, 0x7a, 0xb3, 0xad, 0x1a, 0x89, 0x38, 0x89, + 0xd7, 0x11, 0x3a, 0x8c, 0xcf, 0xe3, 0xc5, 0xba, + 0xb0, 0xcc, 0xc4, 0xe3, 0x33, 0xf3, 0x18, 0xba, + 0xec, 0x56, 0xd9, 0x1c, 0x40, 0x70, 0x0d, 0x4e, + 0x97, 0x01, 0x23, 0xf3, 0x5a, 0xdc, 0xbf, 0x68, + 0x93, 0xc2, 0x1d, 0x8a, 0x96, 0xb7, 0xac, 0x18, + 0x6f, 0xf7, 0x84, 0x71, 0x0d, 0x3d, 0xf8, 0xba, + 0xdf, 0xb6, 0x89, 0x1d, 0x78, 0x19, 0xf2, 0x59, + 0xe9, 0x15, 0x55, 0x29, 0x73, 0x50, 0x59, 0x14, + 0x02, 0x21, 0x16, 0x8f, 0x0f, 0xdf, 0xa5, 0xf0, +}; + +static struct crc_test { + uint32_t crc; /* random starting crc */ + uint32_t start; /* random offset in buf */ + uint32_t length; /* random length of test */ + uint32_t crc_le; /* expected crc32_le result */ + uint32_t crc_be; /* expected crc32_be result */ +} test[] = { + {0xffffffff, 0x00000000, 0x00001000, 0x13934bef, 0x14f3b75f}, + {0xfe7328ea, 0x00000763, 0x00000717, 0xed2c0d70, 0x57531214}, + {0x4c40684e, 0x00000721, 0x0000011e, 0xd7f46ccc, 0xedf12ec3}, + {0x6b487f90, 0x00000264, 0x000007bc, 0x759e9939, 0x9af8e387}, + {0x9f5810db, 0x00000afa, 0x00000255, 0x2685197f, 0x716de6ed}, + {0xb15c4755, 0x00000d5b, 0x000002a4, 0xd8fadcb5, 0xfc34ae3f}, + {0x06518253, 0x00000ffb, 0x00000004, 0xabee2433, 0xfa30ac9e}, + {0xd9e71c55, 0x00000a2a, 0x00000259, 0x96682af2, 0xe5907ea3}, + {0x0c1ae843, 0x00000ce4, 0x0000031b, 0x7b637c43, 0xe7f71b04}, + {0xec3cd517, 0x000002ff, 0x00000566, 0x5d719a77, 0xed16e045}, + {0x77828e95, 0x0000067f, 0x0000038f, 0x43ee5b6c, 0x35999927}, + {0xec87b4e3, 0x00000d1c, 0x000002e3, 0x2ddd2eee, 0x9452d3f8}, + {0x412158bb, 0x00000eee, 0x00000111, 0x67b38ba2, 0x177976d0}, + {0x2e52de3e, 0x00000c4a, 0x000003b5, 0xbcc5d61d, 0xf60fee71}, + {0x6ddaae8b, 0x00000d99, 0x00000266, 0x8b535544, 0x1dab8596}, + {0x049b6cb1, 0x000009c5, 0x000000b0, 0xfc22cabc, 0x47ebc954}, + {0x77d4b954, 0x0000028a, 0x000007fa, 0x71d00923, 0x905585ef}, + {0x5e192355, 0x00000ac1, 0x000001fa, 0xb966b81a, 0x33c12903}, + {0x7d80b71d, 0x00000213, 0x000001e0, 0x2bba371a, 0x5f4bd8d9}, + {0x01f6f1e4, 0x000001d6, 0x00000395, 0xb7e8a647, 0x2a7943a1}, + {0x1dfabb13, 0x00000e14, 0x000001eb, 0x53917fba, 0x8dee1e5d}, + {0xb00a4449, 0x00000bf6, 0x00000409, 0xedecb577, 0x628e087d}, + {0x7ecd3981, 0x0000083f, 0x0000016b, 0xefef62b9, 0xda4f94e6}, + {0xf8f330d2, 0x000004be, 0x00000757, 0x9357c9f3, 0x8e2d5c2f}, + {0x03c38af2, 0x00000d23, 0x000002dc, 0x360fa8c0, 0x6294c0d6}, + {0x687bb79b, 0x00000f3d, 0x000000c2, 0x448d3be2, 0x08f48f3a}, + {0x6710f550, 0x000009e9, 0x00000603, 0xdbfd1998, 0xc950ac29}, + {0x873171d1, 0x00000787, 0x000004d5, 0xab7f1b62, 0xe66896ab}, + {0x373b1314, 0x00000f0f, 0x000000f0, 0x184098ab, 0x4038e674}, + {0x90fad9cd, 0x00000ead, 0x00000152, 0x23ce52ff, 0x9eff3974}, + {0x19676fe7, 0x0000007d, 0x0000070d, 0xf8a76f1e, 0xfbc5c8a9}, + {0x89facd45, 0x000005f3, 0x00000473, 0x4331a006, 0xb8f0f0cc}, + {0x6f173747, 0x00000fc3, 0x0000003c, 0xb012f08e, 0x5126e378}, + {0x4b44a106, 0x0000075a, 0x0000008b, 0xf6f7ac38, 0xf9b1781b}, + {0xb620ad06, 0x00000774, 0x0000017e, 0xd34558e6, 0xb175edd3}, + {0x976f21e9, 0x000008d7, 0x0000034a, 0xe533aa3a, 0x1e4367b9}, + {0x687628c0, 0x000006c5, 0x0000061b, 0x3a840b15, 0xfb5989a0}, + {0xe24ac108, 0x00000cd0, 0x0000032f, 0x51010ae8, 0xcdd8f182}, + {0x361c44a3, 0x00000304, 0x00000719, 0xfd7bd481, 0x12de540f}, + {0xd93ff95e, 0x00000db7, 0x0000008e, 0xcfbbc304, 0x42eecd5a}, + {0xed752d12, 0x00000883, 0x00000091, 0x65a6c868, 0x9ebfa578}, + {0xb4ff4b54, 0x000003d3, 0x000001c1, 0xf82597e7, 0xa8ad2b19}, + {0x111b520f, 0x00000708, 0x000000eb, 0xc3e109f3, 0x323ace17}, + {0x62c806f2, 0x00000ba3, 0x0000045c, 0x874d3a72, 0xaf1a1360}, + {0x40d97470, 0x000005e1, 0x0000058d, 0x87a9684f, 0x524244a8}, + {0x4312179c, 0x00000056, 0x0000070e, 0x809a00f5, 0xf9e940b0}, + {0x13d5f84c, 0x00000a2d, 0x00000104, 0xf3d27578, 0x5d33341c}, + {0x1f302cb2, 0x00000151, 0x00000014, 0x1e162693, 0x53c3cfc3}, + {0xe491db24, 0x00000600, 0x000006f6, 0x7ff09615, 0xa300ecf7}, + {0xf9a98069, 0x000002ba, 0x000002ad, 0x01af7387, 0x31c0911e}, + {0xe9c477ad, 0x0000015f, 0x00000778, 0x6facf9a0, 0x1993b688}, + {0x353f32b2, 0x0000087c, 0x00000783, 0x6cc964ea, 0x418db561}, + {0x78e1b24f, 0x00000650, 0x000006a8, 0xb3bb7c27, 0xf2aad006}, + {0x61aa400e, 0x00000049, 0x00000254, 0xb8cd1681, 0x79150b15}, + {0xb84b10b0, 0x00000f73, 0x0000008c, 0x406a6450, 0x0c705222}, + {0x9fa99c9c, 0x00000a7c, 0x000004d7, 0xfb3d21b4, 0xe4e789df}, + {0x3fc9ebe3, 0x00000cd9, 0x000000d6, 0x43803f9c, 0x5a152be5}, + {0x529879cd, 0x000002f2, 0x00000595, 0x78b4c6a6, 0xf7236ec4}, + {0x3a933019, 0x00000516, 0x00000266, 0xdcb45436, 0x2c7935f5}, + {0x887b4977, 0x00000227, 0x0000038d, 0xc5f7c3d9, 0x0d6d7df6}, + {0x770745de, 0x000008c6, 0x00000739, 0xf69145e8, 0x47d5efc9}, + {0x28be3b47, 0x00000c46, 0x0000032b, 0x764c028f, 0x1eb70d64}, + {0x5013a050, 0x00000cf6, 0x00000309, 0xea8fe164, 0x186affa4}, + {0x2ec4c9ba, 0x000006e8, 0x0000078d, 0xa35557a9, 0xb41f49ec}, + {0xa9f950c9, 0x00000d33, 0x000002cc, 0x41ea8618, 0xab8dfae3}, + {0x5b520229, 0x000007b2, 0x00000484, 0x44569f1f, 0x607a8052}, + {0xd8dcbbfc, 0x0000002f, 0x0000048c, 0xdb88ab8b, 0xf1c411f1}, + {0x25529792, 0x00000d1d, 0x000002e2, 0x20cda404, 0x32683a2d}, + {0x9f3f6d71, 0x00000238, 0x0000079a, 0x0720443e, 0x4b8ba2ff}, + {0x64121215, 0x000007ff, 0x0000038f, 0x6aacff2c, 0x3b84233b}, + {0xfb6cdde0, 0x00000ef8, 0x00000107, 0xbd43a0f1, 0x926624d0}, + {0x221c9d6f, 0x000007b6, 0x0000014f, 0xb67f834b, 0x2bdedda4}, + {0x030e1de4, 0x00000836, 0x000004b4, 0x0d67d26a, 0x75a73b73}, + {0xb56fa6cf, 0x00000c07, 0x000003f8, 0x60601ac1, 0x10a43f35}, + {0xb55c89f5, 0x0000098e, 0x000001d4, 0x2400efbe, 0x006e28eb}, + {0x5e90b6d5, 0x0000070b, 0x000003ea, 0x3bb5d6ea, 0xb175fa6b}, + {0x2a7045ae, 0x00000961, 0x00000633, 0xfca89e4b, 0x962cd6d2}, + {0x8b374ea9, 0x000006ba, 0x00000780, 0xbce036ed, 0x4dc8279b}, + {0x8bd90bc9, 0x00000562, 0x00000369, 0xcb26a24b, 0x50dee743}, + {0x5b1b1762, 0x000000fd, 0x0000051a, 0x33cdda07, 0xee75ff7b}, + {0xa4153555, 0x0000058f, 0x000005c7, 0xbe50eeca, 0xe73fffcc}, + {0x0be1f931, 0x00000651, 0x00000672, 0x95a25753, 0x4ad6270f}, + {0xb7e78618, 0x00000a7f, 0x000002bb, 0xe06bcc1c, 0x1a35ee59}, + {0x4a9bc41b, 0x00000e51, 0x000001ae, 0x709e8d2c, 0x75080ca8}, + {0xfc359d13, 0x00000440, 0x000002f8, 0x0a58451f, 0x6fa3cfbf}, + {0x5aa48619, 0x000006d1, 0x00000284, 0x928ead83, 0xbd600efc}, + {0xa609afa8, 0x0000053e, 0x00000272, 0xb048c141, 0x184f80bb}, + {0x3f108afb, 0x00000949, 0x00000150, 0x9a6bb5bc, 0x0ea02be1}, + {0x79bec2d3, 0x000008ed, 0x00000712, 0x32692d57, 0x2eb13289}, + {0x9429e067, 0x00000bc3, 0x0000043c, 0x5295ceff, 0x8a9014a7}, + {0xae58b96a, 0x0000082d, 0x000007d2, 0xc2a681ba, 0x6af94089}, + {0x95df24be, 0x00000985, 0x000004c1, 0x3a287765, 0x379fcb42}, + {0x5e94976f, 0x00000596, 0x000004ed, 0xff00c489, 0x991fc1f5}, + {0xf5e5f1de, 0x00000d31, 0x000002ce, 0x35f28e91, 0x543def1a}, + {0xa2c219cf, 0x00000a3c, 0x00000374, 0x707d21eb, 0xa6d28bc1}, + {0xf21b6ceb, 0x00000919, 0x00000135, 0x0847fb8b, 0x224468c2}, + {0xaa988728, 0x00000787, 0x00000771, 0x885aeaa4, 0x814db00b}, + {0xaa5dfaac, 0x000003e5, 0x0000051b, 0x52c48ab7, 0x725bef8a}, + {0x0a053968, 0x00000d2a, 0x000002d5, 0x7a90256d, 0xc53b9402}, + {0x1421dc20, 0x00000eef, 0x00000110, 0x97d6da24, 0x10846935}, + {0xb47c2166, 0x00000a6a, 0x00000209, 0xcfd6cc52, 0x46e2797e}, + {0x77dd1955, 0x000000de, 0x00000266, 0xba74bcaa, 0x4fa3fe9c}, + {0x68a03cc2, 0x0000082f, 0x000007b0, 0x752bd5d8, 0x4f760c63}, + {0x0226b0a3, 0x00000a5f, 0x000005a0, 0x82de4970, 0x8ee1310e}, + {0x637bf3b1, 0x00000d93, 0x0000026c, 0x5c7115cb, 0x9f6a0ced}, + {0x3b120edf, 0x00000c13, 0x000003ec, 0x80d7d20f, 0x241657d5}, + {0xe2456780, 0x000002eb, 0x00000641, 0xc0a5d289, 0x74df96b4}, + {0x9b2e7125, 0x00000c0c, 0x000003f3, 0xcc15f57e, 0x03e290bf}, + {0x153033ef, 0x00000787, 0x000006b6, 0x3cde443b, 0x7bf1d121}, + {0x18458b3f, 0x0000066c, 0x00000561, 0x9a2bd8c6, 0x9d564bef}, + {0x4ff9d4b9, 0x00000c8f, 0x0000033a, 0xd0ee6d6d, 0xee00aa0b}, + {0xdf84b5d9, 0x00000802, 0x0000029a, 0xdab0d74a, 0xd0cb63dc}, + {0x81ee15df, 0x000003ce, 0x00000725, 0x9942e2de, 0xe48fb26b}, + {0x5c768e04, 0x00000afd, 0x00000160, 0x36110831, 0x8dc74483}, + {0xe5e18094, 0x00000b4b, 0x000000a0, 0xffa3e4a7, 0xc0145e1b}, + {0xed7263b6, 0x00000d0d, 0x000002f2, 0xb0006a35, 0x5468ae3a}, + {0x5bfde7d7, 0x000006fb, 0x00000554, 0xa4193b76, 0xb73d34b2}, + {0x67f4a743, 0x00000b85, 0x0000047a, 0xf05c8d8f, 0x4f843e49}, + {0xf13bdf22, 0x00000ff7, 0x00000008, 0x816351eb, 0x41f537f6}, + {0x08ecc608, 0x00000d5d, 0x00000098, 0x90492772, 0xf5172204}, + {0x296f52ba, 0x000004f9, 0x00000788, 0x5e5a4896, 0xe01d5b46}, + {0xbe4624c2, 0x00000427, 0x000004ef, 0xcd267b94, 0x7b9069f4}, + {0x906f7c7c, 0x00000a05, 0x0000003f, 0x03fcfc33, 0x7b6ff563}, + {0x8f7b323e, 0x00000458, 0x000004c7, 0xcd4969c8, 0xd4c22ada}, + {0x88d6593d, 0x00000597, 0x000005b5, 0xf199cd3b, 0x5c3e8ca2}, + {0x978a7768, 0x00000268, 0x000001d3, 0xb28c95bd, 0x49a2cc67}, + {0x857a621e, 0x000007a7, 0x000003a8, 0xf4bf84ab, 0xde26f369}, + {0xb0e121ef, 0x000005be, 0x00000644, 0x28747c14, 0x61d4dc6b}, + {0, 0, 0, 0, 0}, +}; + +static int test_crc32c(void) +{ + struct crc_test *t = test; + int failures = 0; + + while (t->length) { + uint32_t be, le; + le = ext2fs_crc32c_le(t->crc, test_buf + t->start, t->length); + be = ext2fs_crc32c_be(t->crc, test_buf + t->start, t->length); + if (le != t->crc_le) { + printf("Test %d LE fails, %x != %x\n", + (t - test), le, t->crc_le); + failures++; + } + if (be != t->crc_be) { + printf("Test %d BE fails, %x != %x\n", + (t - test), be, t->crc_be); + failures++; + } + t++; + } + + return failures; +} + +int main(int argc, char *argv[]) +{ + int ret; + + ret = test_crc32c(); + if (!ret) + printf("No failures.\n"); + + return ret; +} +#endif /* UNITTEST */ diff --git a/libcustomext2fs/source/crc32c_defs.h b/libcustomext2fs/source/crc32c_defs.h new file mode 100644 index 00000000..023f2c01 --- /dev/null +++ b/libcustomext2fs/source/crc32c_defs.h @@ -0,0 +1,51 @@ +/* + * This is the CRC32c polynomial, as outlined by Castagnoli. + * x^32+x^28+x^27+x^26+x^25+x^23+x^22+x^20+x^19+x^18+x^14+x^13+x^11+x^10+x^9+ + * x^8+x^6+x^0 + */ +#define CRCPOLY_LE 0x82F63B78 +#define CRCPOLY_BE 0x1EDC6F41 + +/* How many bits at a time to use. Valid values are 1, 2, 4, 8, 32 and 64. */ +/* For less performance-sensitive, use 4 */ +#ifndef CRC_LE_BITS +# define CRC_LE_BITS 64 +#endif +#ifndef CRC_BE_BITS +# define CRC_BE_BITS 64 +#endif + +/* + * Little-endian CRC computation. Used with serial bit streams sent + * lsbit-first. Be sure to use cpu_to_le32() to append the computed CRC. + */ +#if CRC_LE_BITS > 64 || CRC_LE_BITS < 1 || CRC_LE_BITS == 16 || \ + CRC_LE_BITS & CRC_LE_BITS-1 +# error "CRC_LE_BITS must be one of {1, 2, 4, 8, 32, 64}" +#endif + +/* + * Big-endian CRC computation. Used with serial bit streams sent + * msbit-first. Be sure to use cpu_to_be32() to append the computed CRC. + */ +#if CRC_BE_BITS > 64 || CRC_BE_BITS < 1 || CRC_BE_BITS == 16 || \ + CRC_BE_BITS & CRC_BE_BITS-1 +# error "CRC_BE_BITS must be one of {1, 2, 4, 8, 32, 64}" +#endif + + +#define ___constant_swab32(x) \ + ((uint32_t)( \ + (((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) | \ + (((uint32_t)(x) & (uint32_t)0x0000ff00UL) << 8) | \ + (((uint32_t)(x) & (uint32_t)0x00ff0000UL) >> 8) | \ + (((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24))) + + +#if (__GNUC__ >= 3) +#define likely(x) __builtin_expect(!!(x), 1) +#define unlikely(x) __builtin_expect(!!(x), 0) +#else +#define likely(x) (x) +#define unlikely(x) (x) +#endif diff --git a/libcustomext2fs/source/crc32c_table.h b/libcustomext2fs/source/crc32c_table.h new file mode 100644 index 00000000..b3e2ed09 --- /dev/null +++ b/libcustomext2fs/source/crc32c_table.h @@ -0,0 +1,1065 @@ +/* + * crc32ctable.h - CRC32c tables + * this file is generated - do not edit + * # gen_crc32ctable > crc32c_table.h + * with + * CRC_LE_BITS = 64 + * CRC_BE_BITS = 64 + */ +#include +static const uint32_t t0_le[] = { +tole(0x00000000L), tole(0xf26b8303L), tole(0xe13b70f7L), tole(0x1350f3f4L), +tole(0xc79a971fL), tole(0x35f1141cL), tole(0x26a1e7e8L), tole(0xd4ca64ebL), +tole(0x8ad958cfL), tole(0x78b2dbccL), tole(0x6be22838L), tole(0x9989ab3bL), +tole(0x4d43cfd0L), tole(0xbf284cd3L), tole(0xac78bf27L), tole(0x5e133c24L), +tole(0x105ec76fL), tole(0xe235446cL), tole(0xf165b798L), tole(0x030e349bL), +tole(0xd7c45070L), tole(0x25afd373L), tole(0x36ff2087L), tole(0xc494a384L), +tole(0x9a879fa0L), tole(0x68ec1ca3L), tole(0x7bbcef57L), tole(0x89d76c54L), +tole(0x5d1d08bfL), tole(0xaf768bbcL), tole(0xbc267848L), tole(0x4e4dfb4bL), +tole(0x20bd8edeL), tole(0xd2d60dddL), tole(0xc186fe29L), tole(0x33ed7d2aL), +tole(0xe72719c1L), tole(0x154c9ac2L), tole(0x061c6936L), tole(0xf477ea35L), +tole(0xaa64d611L), tole(0x580f5512L), tole(0x4b5fa6e6L), tole(0xb93425e5L), +tole(0x6dfe410eL), tole(0x9f95c20dL), tole(0x8cc531f9L), tole(0x7eaeb2faL), +tole(0x30e349b1L), tole(0xc288cab2L), tole(0xd1d83946L), tole(0x23b3ba45L), +tole(0xf779deaeL), tole(0x05125dadL), tole(0x1642ae59L), tole(0xe4292d5aL), +tole(0xba3a117eL), tole(0x4851927dL), tole(0x5b016189L), tole(0xa96ae28aL), +tole(0x7da08661L), tole(0x8fcb0562L), tole(0x9c9bf696L), tole(0x6ef07595L), +tole(0x417b1dbcL), tole(0xb3109ebfL), tole(0xa0406d4bL), tole(0x522bee48L), +tole(0x86e18aa3L), tole(0x748a09a0L), tole(0x67dafa54L), tole(0x95b17957L), +tole(0xcba24573L), tole(0x39c9c670L), tole(0x2a993584L), tole(0xd8f2b687L), +tole(0x0c38d26cL), tole(0xfe53516fL), tole(0xed03a29bL), tole(0x1f682198L), +tole(0x5125dad3L), tole(0xa34e59d0L), tole(0xb01eaa24L), tole(0x42752927L), +tole(0x96bf4dccL), tole(0x64d4cecfL), tole(0x77843d3bL), tole(0x85efbe38L), +tole(0xdbfc821cL), tole(0x2997011fL), tole(0x3ac7f2ebL), tole(0xc8ac71e8L), +tole(0x1c661503L), tole(0xee0d9600L), tole(0xfd5d65f4L), tole(0x0f36e6f7L), +tole(0x61c69362L), tole(0x93ad1061L), tole(0x80fde395L), tole(0x72966096L), +tole(0xa65c047dL), tole(0x5437877eL), tole(0x4767748aL), tole(0xb50cf789L), +tole(0xeb1fcbadL), tole(0x197448aeL), tole(0x0a24bb5aL), tole(0xf84f3859L), +tole(0x2c855cb2L), tole(0xdeeedfb1L), tole(0xcdbe2c45L), tole(0x3fd5af46L), +tole(0x7198540dL), tole(0x83f3d70eL), tole(0x90a324faL), tole(0x62c8a7f9L), +tole(0xb602c312L), tole(0x44694011L), tole(0x5739b3e5L), tole(0xa55230e6L), +tole(0xfb410cc2L), tole(0x092a8fc1L), tole(0x1a7a7c35L), tole(0xe811ff36L), +tole(0x3cdb9bddL), tole(0xceb018deL), tole(0xdde0eb2aL), tole(0x2f8b6829L), +tole(0x82f63b78L), tole(0x709db87bL), tole(0x63cd4b8fL), tole(0x91a6c88cL), +tole(0x456cac67L), tole(0xb7072f64L), tole(0xa457dc90L), tole(0x563c5f93L), +tole(0x082f63b7L), tole(0xfa44e0b4L), tole(0xe9141340L), tole(0x1b7f9043L), +tole(0xcfb5f4a8L), tole(0x3dde77abL), tole(0x2e8e845fL), tole(0xdce5075cL), +tole(0x92a8fc17L), tole(0x60c37f14L), tole(0x73938ce0L), tole(0x81f80fe3L), +tole(0x55326b08L), tole(0xa759e80bL), tole(0xb4091bffL), tole(0x466298fcL), +tole(0x1871a4d8L), tole(0xea1a27dbL), tole(0xf94ad42fL), tole(0x0b21572cL), +tole(0xdfeb33c7L), tole(0x2d80b0c4L), tole(0x3ed04330L), tole(0xccbbc033L), +tole(0xa24bb5a6L), tole(0x502036a5L), tole(0x4370c551L), tole(0xb11b4652L), +tole(0x65d122b9L), tole(0x97baa1baL), tole(0x84ea524eL), tole(0x7681d14dL), +tole(0x2892ed69L), tole(0xdaf96e6aL), tole(0xc9a99d9eL), tole(0x3bc21e9dL), +tole(0xef087a76L), tole(0x1d63f975L), tole(0x0e330a81L), tole(0xfc588982L), +tole(0xb21572c9L), tole(0x407ef1caL), tole(0x532e023eL), tole(0xa145813dL), +tole(0x758fe5d6L), tole(0x87e466d5L), tole(0x94b49521L), tole(0x66df1622L), +tole(0x38cc2a06L), tole(0xcaa7a905L), tole(0xd9f75af1L), tole(0x2b9cd9f2L), +tole(0xff56bd19L), tole(0x0d3d3e1aL), tole(0x1e6dcdeeL), tole(0xec064eedL), +tole(0xc38d26c4L), tole(0x31e6a5c7L), tole(0x22b65633L), tole(0xd0ddd530L), +tole(0x0417b1dbL), tole(0xf67c32d8L), tole(0xe52cc12cL), tole(0x1747422fL), +tole(0x49547e0bL), tole(0xbb3ffd08L), tole(0xa86f0efcL), tole(0x5a048dffL), +tole(0x8ecee914L), tole(0x7ca56a17L), tole(0x6ff599e3L), tole(0x9d9e1ae0L), +tole(0xd3d3e1abL), tole(0x21b862a8L), tole(0x32e8915cL), tole(0xc083125fL), +tole(0x144976b4L), tole(0xe622f5b7L), tole(0xf5720643L), tole(0x07198540L), +tole(0x590ab964L), tole(0xab613a67L), tole(0xb831c993L), tole(0x4a5a4a90L), +tole(0x9e902e7bL), tole(0x6cfbad78L), tole(0x7fab5e8cL), tole(0x8dc0dd8fL), +tole(0xe330a81aL), tole(0x115b2b19L), tole(0x020bd8edL), tole(0xf0605beeL), +tole(0x24aa3f05L), tole(0xd6c1bc06L), tole(0xc5914ff2L), tole(0x37faccf1L), +tole(0x69e9f0d5L), tole(0x9b8273d6L), tole(0x88d28022L), tole(0x7ab90321L), +tole(0xae7367caL), tole(0x5c18e4c9L), tole(0x4f48173dL), tole(0xbd23943eL), +tole(0xf36e6f75L), tole(0x0105ec76L), tole(0x12551f82L), tole(0xe03e9c81L), +tole(0x34f4f86aL), tole(0xc69f7b69L), tole(0xd5cf889dL), tole(0x27a40b9eL), +tole(0x79b737baL), tole(0x8bdcb4b9L), tole(0x988c474dL), tole(0x6ae7c44eL), +tole(0xbe2da0a5L), tole(0x4c4623a6L), tole(0x5f16d052L), tole(0xad7d5351L)}; + +static const uint32_t t1_le[] = { +tole(0x00000000L), tole(0x13a29877L), tole(0x274530eeL), tole(0x34e7a899L), +tole(0x4e8a61dcL), tole(0x5d28f9abL), tole(0x69cf5132L), tole(0x7a6dc945L), +tole(0x9d14c3b8L), tole(0x8eb65bcfL), tole(0xba51f356L), tole(0xa9f36b21L), +tole(0xd39ea264L), tole(0xc03c3a13L), tole(0xf4db928aL), tole(0xe7790afdL), +tole(0x3fc5f181L), tole(0x2c6769f6L), tole(0x1880c16fL), tole(0x0b225918L), +tole(0x714f905dL), tole(0x62ed082aL), tole(0x560aa0b3L), tole(0x45a838c4L), +tole(0xa2d13239L), tole(0xb173aa4eL), tole(0x859402d7L), tole(0x96369aa0L), +tole(0xec5b53e5L), tole(0xfff9cb92L), tole(0xcb1e630bL), tole(0xd8bcfb7cL), +tole(0x7f8be302L), tole(0x6c297b75L), tole(0x58ced3ecL), tole(0x4b6c4b9bL), +tole(0x310182deL), tole(0x22a31aa9L), tole(0x1644b230L), tole(0x05e62a47L), +tole(0xe29f20baL), tole(0xf13db8cdL), tole(0xc5da1054L), tole(0xd6788823L), +tole(0xac154166L), tole(0xbfb7d911L), tole(0x8b507188L), tole(0x98f2e9ffL), +tole(0x404e1283L), tole(0x53ec8af4L), tole(0x670b226dL), tole(0x74a9ba1aL), +tole(0x0ec4735fL), tole(0x1d66eb28L), tole(0x298143b1L), tole(0x3a23dbc6L), +tole(0xdd5ad13bL), tole(0xcef8494cL), tole(0xfa1fe1d5L), tole(0xe9bd79a2L), +tole(0x93d0b0e7L), tole(0x80722890L), tole(0xb4958009L), tole(0xa737187eL), +tole(0xff17c604L), tole(0xecb55e73L), tole(0xd852f6eaL), tole(0xcbf06e9dL), +tole(0xb19da7d8L), tole(0xa23f3fafL), tole(0x96d89736L), tole(0x857a0f41L), +tole(0x620305bcL), tole(0x71a19dcbL), tole(0x45463552L), tole(0x56e4ad25L), +tole(0x2c896460L), tole(0x3f2bfc17L), tole(0x0bcc548eL), tole(0x186eccf9L), +tole(0xc0d23785L), tole(0xd370aff2L), tole(0xe797076bL), tole(0xf4359f1cL), +tole(0x8e585659L), tole(0x9dface2eL), tole(0xa91d66b7L), tole(0xbabffec0L), +tole(0x5dc6f43dL), tole(0x4e646c4aL), tole(0x7a83c4d3L), tole(0x69215ca4L), +tole(0x134c95e1L), tole(0x00ee0d96L), tole(0x3409a50fL), tole(0x27ab3d78L), +tole(0x809c2506L), tole(0x933ebd71L), tole(0xa7d915e8L), tole(0xb47b8d9fL), +tole(0xce1644daL), tole(0xddb4dcadL), tole(0xe9537434L), tole(0xfaf1ec43L), +tole(0x1d88e6beL), tole(0x0e2a7ec9L), tole(0x3acdd650L), tole(0x296f4e27L), +tole(0x53028762L), tole(0x40a01f15L), tole(0x7447b78cL), tole(0x67e52ffbL), +tole(0xbf59d487L), tole(0xacfb4cf0L), tole(0x981ce469L), tole(0x8bbe7c1eL), +tole(0xf1d3b55bL), tole(0xe2712d2cL), tole(0xd69685b5L), tole(0xc5341dc2L), +tole(0x224d173fL), tole(0x31ef8f48L), tole(0x050827d1L), tole(0x16aabfa6L), +tole(0x6cc776e3L), tole(0x7f65ee94L), tole(0x4b82460dL), tole(0x5820de7aL), +tole(0xfbc3faf9L), tole(0xe861628eL), tole(0xdc86ca17L), tole(0xcf245260L), +tole(0xb5499b25L), tole(0xa6eb0352L), tole(0x920cabcbL), tole(0x81ae33bcL), +tole(0x66d73941L), tole(0x7575a136L), tole(0x419209afL), tole(0x523091d8L), +tole(0x285d589dL), tole(0x3bffc0eaL), tole(0x0f186873L), tole(0x1cbaf004L), +tole(0xc4060b78L), tole(0xd7a4930fL), tole(0xe3433b96L), tole(0xf0e1a3e1L), +tole(0x8a8c6aa4L), tole(0x992ef2d3L), tole(0xadc95a4aL), tole(0xbe6bc23dL), +tole(0x5912c8c0L), tole(0x4ab050b7L), tole(0x7e57f82eL), tole(0x6df56059L), +tole(0x1798a91cL), tole(0x043a316bL), tole(0x30dd99f2L), tole(0x237f0185L), +tole(0x844819fbL), tole(0x97ea818cL), tole(0xa30d2915L), tole(0xb0afb162L), +tole(0xcac27827L), tole(0xd960e050L), tole(0xed8748c9L), tole(0xfe25d0beL), +tole(0x195cda43L), tole(0x0afe4234L), tole(0x3e19eaadL), tole(0x2dbb72daL), +tole(0x57d6bb9fL), tole(0x447423e8L), tole(0x70938b71L), tole(0x63311306L), +tole(0xbb8de87aL), tole(0xa82f700dL), tole(0x9cc8d894L), tole(0x8f6a40e3L), +tole(0xf50789a6L), tole(0xe6a511d1L), tole(0xd242b948L), tole(0xc1e0213fL), +tole(0x26992bc2L), tole(0x353bb3b5L), tole(0x01dc1b2cL), tole(0x127e835bL), +tole(0x68134a1eL), tole(0x7bb1d269L), tole(0x4f567af0L), tole(0x5cf4e287L), +tole(0x04d43cfdL), tole(0x1776a48aL), tole(0x23910c13L), tole(0x30339464L), +tole(0x4a5e5d21L), tole(0x59fcc556L), tole(0x6d1b6dcfL), tole(0x7eb9f5b8L), +tole(0x99c0ff45L), tole(0x8a626732L), tole(0xbe85cfabL), tole(0xad2757dcL), +tole(0xd74a9e99L), tole(0xc4e806eeL), tole(0xf00fae77L), tole(0xe3ad3600L), +tole(0x3b11cd7cL), tole(0x28b3550bL), tole(0x1c54fd92L), tole(0x0ff665e5L), +tole(0x759baca0L), tole(0x663934d7L), tole(0x52de9c4eL), tole(0x417c0439L), +tole(0xa6050ec4L), tole(0xb5a796b3L), tole(0x81403e2aL), tole(0x92e2a65dL), +tole(0xe88f6f18L), tole(0xfb2df76fL), tole(0xcfca5ff6L), tole(0xdc68c781L), +tole(0x7b5fdfffL), tole(0x68fd4788L), tole(0x5c1aef11L), tole(0x4fb87766L), +tole(0x35d5be23L), tole(0x26772654L), tole(0x12908ecdL), tole(0x013216baL), +tole(0xe64b1c47L), tole(0xf5e98430L), tole(0xc10e2ca9L), tole(0xd2acb4deL), +tole(0xa8c17d9bL), tole(0xbb63e5ecL), tole(0x8f844d75L), tole(0x9c26d502L), +tole(0x449a2e7eL), tole(0x5738b609L), tole(0x63df1e90L), tole(0x707d86e7L), +tole(0x0a104fa2L), tole(0x19b2d7d5L), tole(0x2d557f4cL), tole(0x3ef7e73bL), +tole(0xd98eedc6L), tole(0xca2c75b1L), tole(0xfecbdd28L), tole(0xed69455fL), +tole(0x97048c1aL), tole(0x84a6146dL), tole(0xb041bcf4L), tole(0xa3e32483L)}; + +static const uint32_t t2_le[] = { +tole(0x00000000L), tole(0xa541927eL), tole(0x4f6f520dL), tole(0xea2ec073L), +tole(0x9edea41aL), tole(0x3b9f3664L), tole(0xd1b1f617L), tole(0x74f06469L), +tole(0x38513ec5L), tole(0x9d10acbbL), tole(0x773e6cc8L), tole(0xd27ffeb6L), +tole(0xa68f9adfL), tole(0x03ce08a1L), tole(0xe9e0c8d2L), tole(0x4ca15aacL), +tole(0x70a27d8aL), tole(0xd5e3eff4L), tole(0x3fcd2f87L), tole(0x9a8cbdf9L), +tole(0xee7cd990L), tole(0x4b3d4beeL), tole(0xa1138b9dL), tole(0x045219e3L), +tole(0x48f3434fL), tole(0xedb2d131L), tole(0x079c1142L), tole(0xa2dd833cL), +tole(0xd62de755L), tole(0x736c752bL), tole(0x9942b558L), tole(0x3c032726L), +tole(0xe144fb14L), tole(0x4405696aL), tole(0xae2ba919L), tole(0x0b6a3b67L), +tole(0x7f9a5f0eL), tole(0xdadbcd70L), tole(0x30f50d03L), tole(0x95b49f7dL), +tole(0xd915c5d1L), tole(0x7c5457afL), tole(0x967a97dcL), tole(0x333b05a2L), +tole(0x47cb61cbL), tole(0xe28af3b5L), tole(0x08a433c6L), tole(0xade5a1b8L), +tole(0x91e6869eL), tole(0x34a714e0L), tole(0xde89d493L), tole(0x7bc846edL), +tole(0x0f382284L), tole(0xaa79b0faL), tole(0x40577089L), tole(0xe516e2f7L), +tole(0xa9b7b85bL), tole(0x0cf62a25L), tole(0xe6d8ea56L), tole(0x43997828L), +tole(0x37691c41L), tole(0x92288e3fL), tole(0x78064e4cL), tole(0xdd47dc32L), +tole(0xc76580d9L), tole(0x622412a7L), tole(0x880ad2d4L), tole(0x2d4b40aaL), +tole(0x59bb24c3L), tole(0xfcfab6bdL), tole(0x16d476ceL), tole(0xb395e4b0L), +tole(0xff34be1cL), tole(0x5a752c62L), tole(0xb05bec11L), tole(0x151a7e6fL), +tole(0x61ea1a06L), tole(0xc4ab8878L), tole(0x2e85480bL), tole(0x8bc4da75L), +tole(0xb7c7fd53L), tole(0x12866f2dL), tole(0xf8a8af5eL), tole(0x5de93d20L), +tole(0x29195949L), tole(0x8c58cb37L), tole(0x66760b44L), tole(0xc337993aL), +tole(0x8f96c396L), tole(0x2ad751e8L), tole(0xc0f9919bL), tole(0x65b803e5L), +tole(0x1148678cL), tole(0xb409f5f2L), tole(0x5e273581L), tole(0xfb66a7ffL), +tole(0x26217bcdL), tole(0x8360e9b3L), tole(0x694e29c0L), tole(0xcc0fbbbeL), +tole(0xb8ffdfd7L), tole(0x1dbe4da9L), tole(0xf7908ddaL), tole(0x52d11fa4L), +tole(0x1e704508L), tole(0xbb31d776L), tole(0x511f1705L), tole(0xf45e857bL), +tole(0x80aee112L), tole(0x25ef736cL), tole(0xcfc1b31fL), tole(0x6a802161L), +tole(0x56830647L), tole(0xf3c29439L), tole(0x19ec544aL), tole(0xbcadc634L), +tole(0xc85da25dL), tole(0x6d1c3023L), tole(0x8732f050L), tole(0x2273622eL), +tole(0x6ed23882L), tole(0xcb93aafcL), tole(0x21bd6a8fL), tole(0x84fcf8f1L), +tole(0xf00c9c98L), tole(0x554d0ee6L), tole(0xbf63ce95L), tole(0x1a225cebL), +tole(0x8b277743L), tole(0x2e66e53dL), tole(0xc448254eL), tole(0x6109b730L), +tole(0x15f9d359L), tole(0xb0b84127L), tole(0x5a968154L), tole(0xffd7132aL), +tole(0xb3764986L), tole(0x1637dbf8L), tole(0xfc191b8bL), tole(0x595889f5L), +tole(0x2da8ed9cL), tole(0x88e97fe2L), tole(0x62c7bf91L), tole(0xc7862defL), +tole(0xfb850ac9L), tole(0x5ec498b7L), tole(0xb4ea58c4L), tole(0x11abcabaL), +tole(0x655baed3L), tole(0xc01a3cadL), tole(0x2a34fcdeL), tole(0x8f756ea0L), +tole(0xc3d4340cL), tole(0x6695a672L), tole(0x8cbb6601L), tole(0x29faf47fL), +tole(0x5d0a9016L), tole(0xf84b0268L), tole(0x1265c21bL), tole(0xb7245065L), +tole(0x6a638c57L), tole(0xcf221e29L), tole(0x250cde5aL), tole(0x804d4c24L), +tole(0xf4bd284dL), tole(0x51fcba33L), tole(0xbbd27a40L), tole(0x1e93e83eL), +tole(0x5232b292L), tole(0xf77320ecL), tole(0x1d5de09fL), tole(0xb81c72e1L), +tole(0xccec1688L), tole(0x69ad84f6L), tole(0x83834485L), tole(0x26c2d6fbL), +tole(0x1ac1f1ddL), tole(0xbf8063a3L), tole(0x55aea3d0L), tole(0xf0ef31aeL), +tole(0x841f55c7L), tole(0x215ec7b9L), tole(0xcb7007caL), tole(0x6e3195b4L), +tole(0x2290cf18L), tole(0x87d15d66L), tole(0x6dff9d15L), tole(0xc8be0f6bL), +tole(0xbc4e6b02L), tole(0x190ff97cL), tole(0xf321390fL), tole(0x5660ab71L), +tole(0x4c42f79aL), tole(0xe90365e4L), tole(0x032da597L), tole(0xa66c37e9L), +tole(0xd29c5380L), tole(0x77ddc1feL), tole(0x9df3018dL), tole(0x38b293f3L), +tole(0x7413c95fL), tole(0xd1525b21L), tole(0x3b7c9b52L), tole(0x9e3d092cL), +tole(0xeacd6d45L), tole(0x4f8cff3bL), tole(0xa5a23f48L), tole(0x00e3ad36L), +tole(0x3ce08a10L), tole(0x99a1186eL), tole(0x738fd81dL), tole(0xd6ce4a63L), +tole(0xa23e2e0aL), tole(0x077fbc74L), tole(0xed517c07L), tole(0x4810ee79L), +tole(0x04b1b4d5L), tole(0xa1f026abL), tole(0x4bdee6d8L), tole(0xee9f74a6L), +tole(0x9a6f10cfL), tole(0x3f2e82b1L), tole(0xd50042c2L), tole(0x7041d0bcL), +tole(0xad060c8eL), tole(0x08479ef0L), tole(0xe2695e83L), tole(0x4728ccfdL), +tole(0x33d8a894L), tole(0x96993aeaL), tole(0x7cb7fa99L), tole(0xd9f668e7L), +tole(0x9557324bL), tole(0x3016a035L), tole(0xda386046L), tole(0x7f79f238L), +tole(0x0b899651L), tole(0xaec8042fL), tole(0x44e6c45cL), tole(0xe1a75622L), +tole(0xdda47104L), tole(0x78e5e37aL), tole(0x92cb2309L), tole(0x378ab177L), +tole(0x437ad51eL), tole(0xe63b4760L), tole(0x0c158713L), tole(0xa954156dL), +tole(0xe5f54fc1L), tole(0x40b4ddbfL), tole(0xaa9a1dccL), tole(0x0fdb8fb2L), +tole(0x7b2bebdbL), tole(0xde6a79a5L), tole(0x3444b9d6L), tole(0x91052ba8L)}; + +static const uint32_t t3_le[] = { +tole(0x00000000L), tole(0xdd45aab8L), tole(0xbf672381L), tole(0x62228939L), +tole(0x7b2231f3L), tole(0xa6679b4bL), tole(0xc4451272L), tole(0x1900b8caL), +tole(0xf64463e6L), tole(0x2b01c95eL), tole(0x49234067L), tole(0x9466eadfL), +tole(0x8d665215L), tole(0x5023f8adL), tole(0x32017194L), tole(0xef44db2cL), +tole(0xe964b13dL), tole(0x34211b85L), tole(0x560392bcL), tole(0x8b463804L), +tole(0x924680ceL), tole(0x4f032a76L), tole(0x2d21a34fL), tole(0xf06409f7L), +tole(0x1f20d2dbL), tole(0xc2657863L), tole(0xa047f15aL), tole(0x7d025be2L), +tole(0x6402e328L), tole(0xb9474990L), tole(0xdb65c0a9L), tole(0x06206a11L), +tole(0xd725148bL), tole(0x0a60be33L), tole(0x6842370aL), tole(0xb5079db2L), +tole(0xac072578L), tole(0x71428fc0L), tole(0x136006f9L), tole(0xce25ac41L), +tole(0x2161776dL), tole(0xfc24ddd5L), tole(0x9e0654ecL), tole(0x4343fe54L), +tole(0x5a43469eL), tole(0x8706ec26L), tole(0xe524651fL), tole(0x3861cfa7L), +tole(0x3e41a5b6L), tole(0xe3040f0eL), tole(0x81268637L), tole(0x5c632c8fL), +tole(0x45639445L), tole(0x98263efdL), tole(0xfa04b7c4L), tole(0x27411d7cL), +tole(0xc805c650L), tole(0x15406ce8L), tole(0x7762e5d1L), tole(0xaa274f69L), +tole(0xb327f7a3L), tole(0x6e625d1bL), tole(0x0c40d422L), tole(0xd1057e9aL), +tole(0xaba65fe7L), tole(0x76e3f55fL), tole(0x14c17c66L), tole(0xc984d6deL), +tole(0xd0846e14L), tole(0x0dc1c4acL), tole(0x6fe34d95L), tole(0xb2a6e72dL), +tole(0x5de23c01L), tole(0x80a796b9L), tole(0xe2851f80L), tole(0x3fc0b538L), +tole(0x26c00df2L), tole(0xfb85a74aL), tole(0x99a72e73L), tole(0x44e284cbL), +tole(0x42c2eedaL), tole(0x9f874462L), tole(0xfda5cd5bL), tole(0x20e067e3L), +tole(0x39e0df29L), tole(0xe4a57591L), tole(0x8687fca8L), tole(0x5bc25610L), +tole(0xb4868d3cL), tole(0x69c32784L), tole(0x0be1aebdL), tole(0xd6a40405L), +tole(0xcfa4bccfL), tole(0x12e11677L), tole(0x70c39f4eL), tole(0xad8635f6L), +tole(0x7c834b6cL), tole(0xa1c6e1d4L), tole(0xc3e468edL), tole(0x1ea1c255L), +tole(0x07a17a9fL), tole(0xdae4d027L), tole(0xb8c6591eL), tole(0x6583f3a6L), +tole(0x8ac7288aL), tole(0x57828232L), tole(0x35a00b0bL), tole(0xe8e5a1b3L), +tole(0xf1e51979L), tole(0x2ca0b3c1L), tole(0x4e823af8L), tole(0x93c79040L), +tole(0x95e7fa51L), tole(0x48a250e9L), tole(0x2a80d9d0L), tole(0xf7c57368L), +tole(0xeec5cba2L), tole(0x3380611aL), tole(0x51a2e823L), tole(0x8ce7429bL), +tole(0x63a399b7L), tole(0xbee6330fL), tole(0xdcc4ba36L), tole(0x0181108eL), +tole(0x1881a844L), tole(0xc5c402fcL), tole(0xa7e68bc5L), tole(0x7aa3217dL), +tole(0x52a0c93fL), tole(0x8fe56387L), tole(0xedc7eabeL), tole(0x30824006L), +tole(0x2982f8ccL), tole(0xf4c75274L), tole(0x96e5db4dL), tole(0x4ba071f5L), +tole(0xa4e4aad9L), tole(0x79a10061L), tole(0x1b838958L), tole(0xc6c623e0L), +tole(0xdfc69b2aL), tole(0x02833192L), tole(0x60a1b8abL), tole(0xbde41213L), +tole(0xbbc47802L), tole(0x6681d2baL), tole(0x04a35b83L), tole(0xd9e6f13bL), +tole(0xc0e649f1L), tole(0x1da3e349L), tole(0x7f816a70L), tole(0xa2c4c0c8L), +tole(0x4d801be4L), tole(0x90c5b15cL), tole(0xf2e73865L), tole(0x2fa292ddL), +tole(0x36a22a17L), tole(0xebe780afL), tole(0x89c50996L), tole(0x5480a32eL), +tole(0x8585ddb4L), tole(0x58c0770cL), tole(0x3ae2fe35L), tole(0xe7a7548dL), +tole(0xfea7ec47L), tole(0x23e246ffL), tole(0x41c0cfc6L), tole(0x9c85657eL), +tole(0x73c1be52L), tole(0xae8414eaL), tole(0xcca69dd3L), tole(0x11e3376bL), +tole(0x08e38fa1L), tole(0xd5a62519L), tole(0xb784ac20L), tole(0x6ac10698L), +tole(0x6ce16c89L), tole(0xb1a4c631L), tole(0xd3864f08L), tole(0x0ec3e5b0L), +tole(0x17c35d7aL), tole(0xca86f7c2L), tole(0xa8a47efbL), tole(0x75e1d443L), +tole(0x9aa50f6fL), tole(0x47e0a5d7L), tole(0x25c22ceeL), tole(0xf8878656L), +tole(0xe1873e9cL), tole(0x3cc29424L), tole(0x5ee01d1dL), tole(0x83a5b7a5L), +tole(0xf90696d8L), tole(0x24433c60L), tole(0x4661b559L), tole(0x9b241fe1L), +tole(0x8224a72bL), tole(0x5f610d93L), tole(0x3d4384aaL), tole(0xe0062e12L), +tole(0x0f42f53eL), tole(0xd2075f86L), tole(0xb025d6bfL), tole(0x6d607c07L), +tole(0x7460c4cdL), tole(0xa9256e75L), tole(0xcb07e74cL), tole(0x16424df4L), +tole(0x106227e5L), tole(0xcd278d5dL), tole(0xaf050464L), tole(0x7240aedcL), +tole(0x6b401616L), tole(0xb605bcaeL), tole(0xd4273597L), tole(0x09629f2fL), +tole(0xe6264403L), tole(0x3b63eebbL), tole(0x59416782L), tole(0x8404cd3aL), +tole(0x9d0475f0L), tole(0x4041df48L), tole(0x22635671L), tole(0xff26fcc9L), +tole(0x2e238253L), tole(0xf36628ebL), tole(0x9144a1d2L), tole(0x4c010b6aL), +tole(0x5501b3a0L), tole(0x88441918L), tole(0xea669021L), tole(0x37233a99L), +tole(0xd867e1b5L), tole(0x05224b0dL), tole(0x6700c234L), tole(0xba45688cL), +tole(0xa345d046L), tole(0x7e007afeL), tole(0x1c22f3c7L), tole(0xc167597fL), +tole(0xc747336eL), tole(0x1a0299d6L), tole(0x782010efL), tole(0xa565ba57L), +tole(0xbc65029dL), tole(0x6120a825L), tole(0x0302211cL), tole(0xde478ba4L), +tole(0x31035088L), tole(0xec46fa30L), tole(0x8e647309L), tole(0x5321d9b1L), +tole(0x4a21617bL), tole(0x9764cbc3L), tole(0xf54642faL), tole(0x2803e842L)}; + +static const uint32_t t4_le[] = { +tole(0x00000000L), tole(0x38116facL), tole(0x7022df58L), tole(0x4833b0f4L), +tole(0xe045beb0L), tole(0xd854d11cL), tole(0x906761e8L), tole(0xa8760e44L), +tole(0xc5670b91L), tole(0xfd76643dL), tole(0xb545d4c9L), tole(0x8d54bb65L), +tole(0x2522b521L), tole(0x1d33da8dL), tole(0x55006a79L), tole(0x6d1105d5L), +tole(0x8f2261d3L), tole(0xb7330e7fL), tole(0xff00be8bL), tole(0xc711d127L), +tole(0x6f67df63L), tole(0x5776b0cfL), tole(0x1f45003bL), tole(0x27546f97L), +tole(0x4a456a42L), tole(0x725405eeL), tole(0x3a67b51aL), tole(0x0276dab6L), +tole(0xaa00d4f2L), tole(0x9211bb5eL), tole(0xda220baaL), tole(0xe2336406L), +tole(0x1ba8b557L), tole(0x23b9dafbL), tole(0x6b8a6a0fL), tole(0x539b05a3L), +tole(0xfbed0be7L), tole(0xc3fc644bL), tole(0x8bcfd4bfL), tole(0xb3debb13L), +tole(0xdecfbec6L), tole(0xe6ded16aL), tole(0xaeed619eL), tole(0x96fc0e32L), +tole(0x3e8a0076L), tole(0x069b6fdaL), tole(0x4ea8df2eL), tole(0x76b9b082L), +tole(0x948ad484L), tole(0xac9bbb28L), tole(0xe4a80bdcL), tole(0xdcb96470L), +tole(0x74cf6a34L), tole(0x4cde0598L), tole(0x04edb56cL), tole(0x3cfcdac0L), +tole(0x51eddf15L), tole(0x69fcb0b9L), tole(0x21cf004dL), tole(0x19de6fe1L), +tole(0xb1a861a5L), tole(0x89b90e09L), tole(0xc18abefdL), tole(0xf99bd151L), +tole(0x37516aaeL), tole(0x0f400502L), tole(0x4773b5f6L), tole(0x7f62da5aL), +tole(0xd714d41eL), tole(0xef05bbb2L), tole(0xa7360b46L), tole(0x9f2764eaL), +tole(0xf236613fL), tole(0xca270e93L), tole(0x8214be67L), tole(0xba05d1cbL), +tole(0x1273df8fL), tole(0x2a62b023L), tole(0x625100d7L), tole(0x5a406f7bL), +tole(0xb8730b7dL), tole(0x806264d1L), tole(0xc851d425L), tole(0xf040bb89L), +tole(0x5836b5cdL), tole(0x6027da61L), tole(0x28146a95L), tole(0x10050539L), +tole(0x7d1400ecL), tole(0x45056f40L), tole(0x0d36dfb4L), tole(0x3527b018L), +tole(0x9d51be5cL), tole(0xa540d1f0L), tole(0xed736104L), tole(0xd5620ea8L), +tole(0x2cf9dff9L), tole(0x14e8b055L), tole(0x5cdb00a1L), tole(0x64ca6f0dL), +tole(0xccbc6149L), tole(0xf4ad0ee5L), tole(0xbc9ebe11L), tole(0x848fd1bdL), +tole(0xe99ed468L), tole(0xd18fbbc4L), tole(0x99bc0b30L), tole(0xa1ad649cL), +tole(0x09db6ad8L), tole(0x31ca0574L), tole(0x79f9b580L), tole(0x41e8da2cL), +tole(0xa3dbbe2aL), tole(0x9bcad186L), tole(0xd3f96172L), tole(0xebe80edeL), +tole(0x439e009aL), tole(0x7b8f6f36L), tole(0x33bcdfc2L), tole(0x0badb06eL), +tole(0x66bcb5bbL), tole(0x5eadda17L), tole(0x169e6ae3L), tole(0x2e8f054fL), +tole(0x86f90b0bL), tole(0xbee864a7L), tole(0xf6dbd453L), tole(0xcecabbffL), +tole(0x6ea2d55cL), tole(0x56b3baf0L), tole(0x1e800a04L), tole(0x269165a8L), +tole(0x8ee76becL), tole(0xb6f60440L), tole(0xfec5b4b4L), tole(0xc6d4db18L), +tole(0xabc5decdL), tole(0x93d4b161L), tole(0xdbe70195L), tole(0xe3f66e39L), +tole(0x4b80607dL), tole(0x73910fd1L), tole(0x3ba2bf25L), tole(0x03b3d089L), +tole(0xe180b48fL), tole(0xd991db23L), tole(0x91a26bd7L), tole(0xa9b3047bL), +tole(0x01c50a3fL), tole(0x39d46593L), tole(0x71e7d567L), tole(0x49f6bacbL), +tole(0x24e7bf1eL), tole(0x1cf6d0b2L), tole(0x54c56046L), tole(0x6cd40feaL), +tole(0xc4a201aeL), tole(0xfcb36e02L), tole(0xb480def6L), tole(0x8c91b15aL), +tole(0x750a600bL), tole(0x4d1b0fa7L), tole(0x0528bf53L), tole(0x3d39d0ffL), +tole(0x954fdebbL), tole(0xad5eb117L), tole(0xe56d01e3L), tole(0xdd7c6e4fL), +tole(0xb06d6b9aL), tole(0x887c0436L), tole(0xc04fb4c2L), tole(0xf85edb6eL), +tole(0x5028d52aL), tole(0x6839ba86L), tole(0x200a0a72L), tole(0x181b65deL), +tole(0xfa2801d8L), tole(0xc2396e74L), tole(0x8a0ade80L), tole(0xb21bb12cL), +tole(0x1a6dbf68L), tole(0x227cd0c4L), tole(0x6a4f6030L), tole(0x525e0f9cL), +tole(0x3f4f0a49L), tole(0x075e65e5L), tole(0x4f6dd511L), tole(0x777cbabdL), +tole(0xdf0ab4f9L), tole(0xe71bdb55L), tole(0xaf286ba1L), tole(0x9739040dL), +tole(0x59f3bff2L), tole(0x61e2d05eL), tole(0x29d160aaL), tole(0x11c00f06L), +tole(0xb9b60142L), tole(0x81a76eeeL), tole(0xc994de1aL), tole(0xf185b1b6L), +tole(0x9c94b463L), tole(0xa485dbcfL), tole(0xecb66b3bL), tole(0xd4a70497L), +tole(0x7cd10ad3L), tole(0x44c0657fL), tole(0x0cf3d58bL), tole(0x34e2ba27L), +tole(0xd6d1de21L), tole(0xeec0b18dL), tole(0xa6f30179L), tole(0x9ee26ed5L), +tole(0x36946091L), tole(0x0e850f3dL), tole(0x46b6bfc9L), tole(0x7ea7d065L), +tole(0x13b6d5b0L), tole(0x2ba7ba1cL), tole(0x63940ae8L), tole(0x5b856544L), +tole(0xf3f36b00L), tole(0xcbe204acL), tole(0x83d1b458L), tole(0xbbc0dbf4L), +tole(0x425b0aa5L), tole(0x7a4a6509L), tole(0x3279d5fdL), tole(0x0a68ba51L), +tole(0xa21eb415L), tole(0x9a0fdbb9L), tole(0xd23c6b4dL), tole(0xea2d04e1L), +tole(0x873c0134L), tole(0xbf2d6e98L), tole(0xf71ede6cL), tole(0xcf0fb1c0L), +tole(0x6779bf84L), tole(0x5f68d028L), tole(0x175b60dcL), tole(0x2f4a0f70L), +tole(0xcd796b76L), tole(0xf56804daL), tole(0xbd5bb42eL), tole(0x854adb82L), +tole(0x2d3cd5c6L), tole(0x152dba6aL), tole(0x5d1e0a9eL), tole(0x650f6532L), +tole(0x081e60e7L), tole(0x300f0f4bL), tole(0x783cbfbfL), tole(0x402dd013L), +tole(0xe85bde57L), tole(0xd04ab1fbL), tole(0x9879010fL), tole(0xa0686ea3L)}; + +static const uint32_t t5_le[] = { +tole(0x00000000L), tole(0xef306b19L), tole(0xdb8ca0c3L), tole(0x34bccbdaL), +tole(0xb2f53777L), tole(0x5dc55c6eL), tole(0x697997b4L), tole(0x8649fcadL), +tole(0x6006181fL), tole(0x8f367306L), tole(0xbb8ab8dcL), tole(0x54bad3c5L), +tole(0xd2f32f68L), tole(0x3dc34471L), tole(0x097f8fabL), tole(0xe64fe4b2L), +tole(0xc00c303eL), tole(0x2f3c5b27L), tole(0x1b8090fdL), tole(0xf4b0fbe4L), +tole(0x72f90749L), tole(0x9dc96c50L), tole(0xa975a78aL), tole(0x4645cc93L), +tole(0xa00a2821L), tole(0x4f3a4338L), tole(0x7b8688e2L), tole(0x94b6e3fbL), +tole(0x12ff1f56L), tole(0xfdcf744fL), tole(0xc973bf95L), tole(0x2643d48cL), +tole(0x85f4168dL), tole(0x6ac47d94L), tole(0x5e78b64eL), tole(0xb148dd57L), +tole(0x370121faL), tole(0xd8314ae3L), tole(0xec8d8139L), tole(0x03bdea20L), +tole(0xe5f20e92L), tole(0x0ac2658bL), tole(0x3e7eae51L), tole(0xd14ec548L), +tole(0x570739e5L), tole(0xb83752fcL), tole(0x8c8b9926L), tole(0x63bbf23fL), +tole(0x45f826b3L), tole(0xaac84daaL), tole(0x9e748670L), tole(0x7144ed69L), +tole(0xf70d11c4L), tole(0x183d7addL), tole(0x2c81b107L), tole(0xc3b1da1eL), +tole(0x25fe3eacL), tole(0xcace55b5L), tole(0xfe729e6fL), tole(0x1142f576L), +tole(0x970b09dbL), tole(0x783b62c2L), tole(0x4c87a918L), tole(0xa3b7c201L), +tole(0x0e045bebL), tole(0xe13430f2L), tole(0xd588fb28L), tole(0x3ab89031L), +tole(0xbcf16c9cL), tole(0x53c10785L), tole(0x677dcc5fL), tole(0x884da746L), +tole(0x6e0243f4L), tole(0x813228edL), tole(0xb58ee337L), tole(0x5abe882eL), +tole(0xdcf77483L), tole(0x33c71f9aL), tole(0x077bd440L), tole(0xe84bbf59L), +tole(0xce086bd5L), tole(0x213800ccL), tole(0x1584cb16L), tole(0xfab4a00fL), +tole(0x7cfd5ca2L), tole(0x93cd37bbL), tole(0xa771fc61L), tole(0x48419778L), +tole(0xae0e73caL), tole(0x413e18d3L), tole(0x7582d309L), tole(0x9ab2b810L), +tole(0x1cfb44bdL), tole(0xf3cb2fa4L), tole(0xc777e47eL), tole(0x28478f67L), +tole(0x8bf04d66L), tole(0x64c0267fL), tole(0x507ceda5L), tole(0xbf4c86bcL), +tole(0x39057a11L), tole(0xd6351108L), tole(0xe289dad2L), tole(0x0db9b1cbL), +tole(0xebf65579L), tole(0x04c63e60L), tole(0x307af5baL), tole(0xdf4a9ea3L), +tole(0x5903620eL), tole(0xb6330917L), tole(0x828fc2cdL), tole(0x6dbfa9d4L), +tole(0x4bfc7d58L), tole(0xa4cc1641L), tole(0x9070dd9bL), tole(0x7f40b682L), +tole(0xf9094a2fL), tole(0x16392136L), tole(0x2285eaecL), tole(0xcdb581f5L), +tole(0x2bfa6547L), tole(0xc4ca0e5eL), tole(0xf076c584L), tole(0x1f46ae9dL), +tole(0x990f5230L), tole(0x763f3929L), tole(0x4283f2f3L), tole(0xadb399eaL), +tole(0x1c08b7d6L), tole(0xf338dccfL), tole(0xc7841715L), tole(0x28b47c0cL), +tole(0xaefd80a1L), tole(0x41cdebb8L), tole(0x75712062L), tole(0x9a414b7bL), +tole(0x7c0eafc9L), tole(0x933ec4d0L), tole(0xa7820f0aL), tole(0x48b26413L), +tole(0xcefb98beL), tole(0x21cbf3a7L), tole(0x1577387dL), tole(0xfa475364L), +tole(0xdc0487e8L), tole(0x3334ecf1L), tole(0x0788272bL), tole(0xe8b84c32L), +tole(0x6ef1b09fL), tole(0x81c1db86L), tole(0xb57d105cL), tole(0x5a4d7b45L), +tole(0xbc029ff7L), tole(0x5332f4eeL), tole(0x678e3f34L), tole(0x88be542dL), +tole(0x0ef7a880L), tole(0xe1c7c399L), tole(0xd57b0843L), tole(0x3a4b635aL), +tole(0x99fca15bL), tole(0x76ccca42L), tole(0x42700198L), tole(0xad406a81L), +tole(0x2b09962cL), tole(0xc439fd35L), tole(0xf08536efL), tole(0x1fb55df6L), +tole(0xf9fab944L), tole(0x16cad25dL), tole(0x22761987L), tole(0xcd46729eL), +tole(0x4b0f8e33L), tole(0xa43fe52aL), tole(0x90832ef0L), tole(0x7fb345e9L), +tole(0x59f09165L), tole(0xb6c0fa7cL), tole(0x827c31a6L), tole(0x6d4c5abfL), +tole(0xeb05a612L), tole(0x0435cd0bL), tole(0x308906d1L), tole(0xdfb96dc8L), +tole(0x39f6897aL), tole(0xd6c6e263L), tole(0xe27a29b9L), tole(0x0d4a42a0L), +tole(0x8b03be0dL), tole(0x6433d514L), tole(0x508f1eceL), tole(0xbfbf75d7L), +tole(0x120cec3dL), tole(0xfd3c8724L), tole(0xc9804cfeL), tole(0x26b027e7L), +tole(0xa0f9db4aL), tole(0x4fc9b053L), tole(0x7b757b89L), tole(0x94451090L), +tole(0x720af422L), tole(0x9d3a9f3bL), tole(0xa98654e1L), tole(0x46b63ff8L), +tole(0xc0ffc355L), tole(0x2fcfa84cL), tole(0x1b736396L), tole(0xf443088fL), +tole(0xd200dc03L), tole(0x3d30b71aL), tole(0x098c7cc0L), tole(0xe6bc17d9L), +tole(0x60f5eb74L), tole(0x8fc5806dL), tole(0xbb794bb7L), tole(0x544920aeL), +tole(0xb206c41cL), tole(0x5d36af05L), tole(0x698a64dfL), tole(0x86ba0fc6L), +tole(0x00f3f36bL), tole(0xefc39872L), tole(0xdb7f53a8L), tole(0x344f38b1L), +tole(0x97f8fab0L), tole(0x78c891a9L), tole(0x4c745a73L), tole(0xa344316aL), +tole(0x250dcdc7L), tole(0xca3da6deL), tole(0xfe816d04L), tole(0x11b1061dL), +tole(0xf7fee2afL), tole(0x18ce89b6L), tole(0x2c72426cL), tole(0xc3422975L), +tole(0x450bd5d8L), tole(0xaa3bbec1L), tole(0x9e87751bL), tole(0x71b71e02L), +tole(0x57f4ca8eL), tole(0xb8c4a197L), tole(0x8c786a4dL), tole(0x63480154L), +tole(0xe501fdf9L), tole(0x0a3196e0L), tole(0x3e8d5d3aL), tole(0xd1bd3623L), +tole(0x37f2d291L), tole(0xd8c2b988L), tole(0xec7e7252L), tole(0x034e194bL), +tole(0x8507e5e6L), tole(0x6a378effL), tole(0x5e8b4525L), tole(0xb1bb2e3cL)}; + +static const uint32_t t6_le[] = { +tole(0x00000000L), tole(0x68032cc8L), tole(0xd0065990L), tole(0xb8057558L), +tole(0xa5e0c5d1L), tole(0xcde3e919L), tole(0x75e69c41L), tole(0x1de5b089L), +tole(0x4e2dfd53L), tole(0x262ed19bL), tole(0x9e2ba4c3L), tole(0xf628880bL), +tole(0xebcd3882L), tole(0x83ce144aL), tole(0x3bcb6112L), tole(0x53c84ddaL), +tole(0x9c5bfaa6L), tole(0xf458d66eL), tole(0x4c5da336L), tole(0x245e8ffeL), +tole(0x39bb3f77L), tole(0x51b813bfL), tole(0xe9bd66e7L), tole(0x81be4a2fL), +tole(0xd27607f5L), tole(0xba752b3dL), tole(0x02705e65L), tole(0x6a7372adL), +tole(0x7796c224L), tole(0x1f95eeecL), tole(0xa7909bb4L), tole(0xcf93b77cL), +tole(0x3d5b83bdL), tole(0x5558af75L), tole(0xed5dda2dL), tole(0x855ef6e5L), +tole(0x98bb466cL), tole(0xf0b86aa4L), tole(0x48bd1ffcL), tole(0x20be3334L), +tole(0x73767eeeL), tole(0x1b755226L), tole(0xa370277eL), tole(0xcb730bb6L), +tole(0xd696bb3fL), tole(0xbe9597f7L), tole(0x0690e2afL), tole(0x6e93ce67L), +tole(0xa100791bL), tole(0xc90355d3L), tole(0x7106208bL), tole(0x19050c43L), +tole(0x04e0bccaL), tole(0x6ce39002L), tole(0xd4e6e55aL), tole(0xbce5c992L), +tole(0xef2d8448L), tole(0x872ea880L), tole(0x3f2bddd8L), tole(0x5728f110L), +tole(0x4acd4199L), tole(0x22ce6d51L), tole(0x9acb1809L), tole(0xf2c834c1L), +tole(0x7ab7077aL), tole(0x12b42bb2L), tole(0xaab15eeaL), tole(0xc2b27222L), +tole(0xdf57c2abL), tole(0xb754ee63L), tole(0x0f519b3bL), tole(0x6752b7f3L), +tole(0x349afa29L), tole(0x5c99d6e1L), tole(0xe49ca3b9L), tole(0x8c9f8f71L), +tole(0x917a3ff8L), tole(0xf9791330L), tole(0x417c6668L), tole(0x297f4aa0L), +tole(0xe6ecfddcL), tole(0x8eefd114L), tole(0x36eaa44cL), tole(0x5ee98884L), +tole(0x430c380dL), tole(0x2b0f14c5L), tole(0x930a619dL), tole(0xfb094d55L), +tole(0xa8c1008fL), tole(0xc0c22c47L), tole(0x78c7591fL), tole(0x10c475d7L), +tole(0x0d21c55eL), tole(0x6522e996L), tole(0xdd279cceL), tole(0xb524b006L), +tole(0x47ec84c7L), tole(0x2fefa80fL), tole(0x97eadd57L), tole(0xffe9f19fL), +tole(0xe20c4116L), tole(0x8a0f6ddeL), tole(0x320a1886L), tole(0x5a09344eL), +tole(0x09c17994L), tole(0x61c2555cL), tole(0xd9c72004L), tole(0xb1c40cccL), +tole(0xac21bc45L), tole(0xc422908dL), tole(0x7c27e5d5L), tole(0x1424c91dL), +tole(0xdbb77e61L), tole(0xb3b452a9L), tole(0x0bb127f1L), tole(0x63b20b39L), +tole(0x7e57bbb0L), tole(0x16549778L), tole(0xae51e220L), tole(0xc652cee8L), +tole(0x959a8332L), tole(0xfd99affaL), tole(0x459cdaa2L), tole(0x2d9ff66aL), +tole(0x307a46e3L), tole(0x58796a2bL), tole(0xe07c1f73L), tole(0x887f33bbL), +tole(0xf56e0ef4L), tole(0x9d6d223cL), tole(0x25685764L), tole(0x4d6b7bacL), +tole(0x508ecb25L), tole(0x388de7edL), tole(0x808892b5L), tole(0xe88bbe7dL), +tole(0xbb43f3a7L), tole(0xd340df6fL), tole(0x6b45aa37L), tole(0x034686ffL), +tole(0x1ea33676L), tole(0x76a01abeL), tole(0xcea56fe6L), tole(0xa6a6432eL), +tole(0x6935f452L), tole(0x0136d89aL), tole(0xb933adc2L), tole(0xd130810aL), +tole(0xccd53183L), tole(0xa4d61d4bL), tole(0x1cd36813L), tole(0x74d044dbL), +tole(0x27180901L), tole(0x4f1b25c9L), tole(0xf71e5091L), tole(0x9f1d7c59L), +tole(0x82f8ccd0L), tole(0xeafbe018L), tole(0x52fe9540L), tole(0x3afdb988L), +tole(0xc8358d49L), tole(0xa036a181L), tole(0x1833d4d9L), tole(0x7030f811L), +tole(0x6dd54898L), tole(0x05d66450L), tole(0xbdd31108L), tole(0xd5d03dc0L), +tole(0x8618701aL), tole(0xee1b5cd2L), tole(0x561e298aL), tole(0x3e1d0542L), +tole(0x23f8b5cbL), tole(0x4bfb9903L), tole(0xf3feec5bL), tole(0x9bfdc093L), +tole(0x546e77efL), tole(0x3c6d5b27L), tole(0x84682e7fL), tole(0xec6b02b7L), +tole(0xf18eb23eL), tole(0x998d9ef6L), tole(0x2188ebaeL), tole(0x498bc766L), +tole(0x1a438abcL), tole(0x7240a674L), tole(0xca45d32cL), tole(0xa246ffe4L), +tole(0xbfa34f6dL), tole(0xd7a063a5L), tole(0x6fa516fdL), tole(0x07a63a35L), +tole(0x8fd9098eL), tole(0xe7da2546L), tole(0x5fdf501eL), tole(0x37dc7cd6L), +tole(0x2a39cc5fL), tole(0x423ae097L), tole(0xfa3f95cfL), tole(0x923cb907L), +tole(0xc1f4f4ddL), tole(0xa9f7d815L), tole(0x11f2ad4dL), tole(0x79f18185L), +tole(0x6414310cL), tole(0x0c171dc4L), tole(0xb412689cL), tole(0xdc114454L), +tole(0x1382f328L), tole(0x7b81dfe0L), tole(0xc384aab8L), tole(0xab878670L), +tole(0xb66236f9L), tole(0xde611a31L), tole(0x66646f69L), tole(0x0e6743a1L), +tole(0x5daf0e7bL), tole(0x35ac22b3L), tole(0x8da957ebL), tole(0xe5aa7b23L), +tole(0xf84fcbaaL), tole(0x904ce762L), tole(0x2849923aL), tole(0x404abef2L), +tole(0xb2828a33L), tole(0xda81a6fbL), tole(0x6284d3a3L), tole(0x0a87ff6bL), +tole(0x17624fe2L), tole(0x7f61632aL), tole(0xc7641672L), tole(0xaf673abaL), +tole(0xfcaf7760L), tole(0x94ac5ba8L), tole(0x2ca92ef0L), tole(0x44aa0238L), +tole(0x594fb2b1L), tole(0x314c9e79L), tole(0x8949eb21L), tole(0xe14ac7e9L), +tole(0x2ed97095L), tole(0x46da5c5dL), tole(0xfedf2905L), tole(0x96dc05cdL), +tole(0x8b39b544L), tole(0xe33a998cL), tole(0x5b3fecd4L), tole(0x333cc01cL), +tole(0x60f48dc6L), tole(0x08f7a10eL), tole(0xb0f2d456L), tole(0xd8f1f89eL), +tole(0xc5144817L), tole(0xad1764dfL), tole(0x15121187L), tole(0x7d113d4fL)}; + +static const uint32_t t7_le[] = { +tole(0x00000000L), tole(0x493c7d27L), tole(0x9278fa4eL), tole(0xdb448769L), +tole(0x211d826dL), tole(0x6821ff4aL), tole(0xb3657823L), tole(0xfa590504L), +tole(0x423b04daL), tole(0x0b0779fdL), tole(0xd043fe94L), tole(0x997f83b3L), +tole(0x632686b7L), tole(0x2a1afb90L), tole(0xf15e7cf9L), tole(0xb86201deL), +tole(0x847609b4L), tole(0xcd4a7493L), tole(0x160ef3faL), tole(0x5f328eddL), +tole(0xa56b8bd9L), tole(0xec57f6feL), tole(0x37137197L), tole(0x7e2f0cb0L), +tole(0xc64d0d6eL), tole(0x8f717049L), tole(0x5435f720L), tole(0x1d098a07L), +tole(0xe7508f03L), tole(0xae6cf224L), tole(0x7528754dL), tole(0x3c14086aL), +tole(0x0d006599L), tole(0x443c18beL), tole(0x9f789fd7L), tole(0xd644e2f0L), +tole(0x2c1de7f4L), tole(0x65219ad3L), tole(0xbe651dbaL), tole(0xf759609dL), +tole(0x4f3b6143L), tole(0x06071c64L), tole(0xdd439b0dL), tole(0x947fe62aL), +tole(0x6e26e32eL), tole(0x271a9e09L), tole(0xfc5e1960L), tole(0xb5626447L), +tole(0x89766c2dL), tole(0xc04a110aL), tole(0x1b0e9663L), tole(0x5232eb44L), +tole(0xa86bee40L), tole(0xe1579367L), tole(0x3a13140eL), tole(0x732f6929L), +tole(0xcb4d68f7L), tole(0x827115d0L), tole(0x593592b9L), tole(0x1009ef9eL), +tole(0xea50ea9aL), tole(0xa36c97bdL), tole(0x782810d4L), tole(0x31146df3L), +tole(0x1a00cb32L), tole(0x533cb615L), tole(0x8878317cL), tole(0xc1444c5bL), +tole(0x3b1d495fL), tole(0x72213478L), tole(0xa965b311L), tole(0xe059ce36L), +tole(0x583bcfe8L), tole(0x1107b2cfL), tole(0xca4335a6L), tole(0x837f4881L), +tole(0x79264d85L), tole(0x301a30a2L), tole(0xeb5eb7cbL), tole(0xa262caecL), +tole(0x9e76c286L), tole(0xd74abfa1L), tole(0x0c0e38c8L), tole(0x453245efL), +tole(0xbf6b40ebL), tole(0xf6573dccL), tole(0x2d13baa5L), tole(0x642fc782L), +tole(0xdc4dc65cL), tole(0x9571bb7bL), tole(0x4e353c12L), tole(0x07094135L), +tole(0xfd504431L), tole(0xb46c3916L), tole(0x6f28be7fL), tole(0x2614c358L), +tole(0x1700aeabL), tole(0x5e3cd38cL), tole(0x857854e5L), tole(0xcc4429c2L), +tole(0x361d2cc6L), tole(0x7f2151e1L), tole(0xa465d688L), tole(0xed59abafL), +tole(0x553baa71L), tole(0x1c07d756L), tole(0xc743503fL), tole(0x8e7f2d18L), +tole(0x7426281cL), tole(0x3d1a553bL), tole(0xe65ed252L), tole(0xaf62af75L), +tole(0x9376a71fL), tole(0xda4ada38L), tole(0x010e5d51L), tole(0x48322076L), +tole(0xb26b2572L), tole(0xfb575855L), tole(0x2013df3cL), tole(0x692fa21bL), +tole(0xd14da3c5L), tole(0x9871dee2L), tole(0x4335598bL), tole(0x0a0924acL), +tole(0xf05021a8L), tole(0xb96c5c8fL), tole(0x6228dbe6L), tole(0x2b14a6c1L), +tole(0x34019664L), tole(0x7d3deb43L), tole(0xa6796c2aL), tole(0xef45110dL), +tole(0x151c1409L), tole(0x5c20692eL), tole(0x8764ee47L), tole(0xce589360L), +tole(0x763a92beL), tole(0x3f06ef99L), tole(0xe44268f0L), tole(0xad7e15d7L), +tole(0x572710d3L), tole(0x1e1b6df4L), tole(0xc55fea9dL), tole(0x8c6397baL), +tole(0xb0779fd0L), tole(0xf94be2f7L), tole(0x220f659eL), tole(0x6b3318b9L), +tole(0x916a1dbdL), tole(0xd856609aL), tole(0x0312e7f3L), tole(0x4a2e9ad4L), +tole(0xf24c9b0aL), tole(0xbb70e62dL), tole(0x60346144L), tole(0x29081c63L), +tole(0xd3511967L), tole(0x9a6d6440L), tole(0x4129e329L), tole(0x08159e0eL), +tole(0x3901f3fdL), tole(0x703d8edaL), tole(0xab7909b3L), tole(0xe2457494L), +tole(0x181c7190L), tole(0x51200cb7L), tole(0x8a648bdeL), tole(0xc358f6f9L), +tole(0x7b3af727L), tole(0x32068a00L), tole(0xe9420d69L), tole(0xa07e704eL), +tole(0x5a27754aL), tole(0x131b086dL), tole(0xc85f8f04L), tole(0x8163f223L), +tole(0xbd77fa49L), tole(0xf44b876eL), tole(0x2f0f0007L), tole(0x66337d20L), +tole(0x9c6a7824L), tole(0xd5560503L), tole(0x0e12826aL), tole(0x472eff4dL), +tole(0xff4cfe93L), tole(0xb67083b4L), tole(0x6d3404ddL), tole(0x240879faL), +tole(0xde517cfeL), tole(0x976d01d9L), tole(0x4c2986b0L), tole(0x0515fb97L), +tole(0x2e015d56L), tole(0x673d2071L), tole(0xbc79a718L), tole(0xf545da3fL), +tole(0x0f1cdf3bL), tole(0x4620a21cL), tole(0x9d642575L), tole(0xd4585852L), +tole(0x6c3a598cL), tole(0x250624abL), tole(0xfe42a3c2L), tole(0xb77edee5L), +tole(0x4d27dbe1L), tole(0x041ba6c6L), tole(0xdf5f21afL), tole(0x96635c88L), +tole(0xaa7754e2L), tole(0xe34b29c5L), tole(0x380faeacL), tole(0x7133d38bL), +tole(0x8b6ad68fL), tole(0xc256aba8L), tole(0x19122cc1L), tole(0x502e51e6L), +tole(0xe84c5038L), tole(0xa1702d1fL), tole(0x7a34aa76L), tole(0x3308d751L), +tole(0xc951d255L), tole(0x806daf72L), tole(0x5b29281bL), tole(0x1215553cL), +tole(0x230138cfL), tole(0x6a3d45e8L), tole(0xb179c281L), tole(0xf845bfa6L), +tole(0x021cbaa2L), tole(0x4b20c785L), tole(0x906440ecL), tole(0xd9583dcbL), +tole(0x613a3c15L), tole(0x28064132L), tole(0xf342c65bL), tole(0xba7ebb7cL), +tole(0x4027be78L), tole(0x091bc35fL), tole(0xd25f4436L), tole(0x9b633911L), +tole(0xa777317bL), tole(0xee4b4c5cL), tole(0x350fcb35L), tole(0x7c33b612L), +tole(0x866ab316L), tole(0xcf56ce31L), tole(0x14124958L), tole(0x5d2e347fL), +tole(0xe54c35a1L), tole(0xac704886L), tole(0x7734cfefL), tole(0x3e08b2c8L), +tole(0xc451b7ccL), tole(0x8d6dcaebL), tole(0x56294d82L), tole(0x1f1530a5L)}; + +static const uint32_t t0_be[] = { +tobe(0x00000000L), tobe(0x1edc6f41L), tobe(0x3db8de82L), tobe(0x2364b1c3L), +tobe(0x7b71bd04L), tobe(0x65add245L), tobe(0x46c96386L), tobe(0x58150cc7L), +tobe(0xf6e37a08L), tobe(0xe83f1549L), tobe(0xcb5ba48aL), tobe(0xd587cbcbL), +tobe(0x8d92c70cL), tobe(0x934ea84dL), tobe(0xb02a198eL), tobe(0xaef676cfL), +tobe(0xf31a9b51L), tobe(0xedc6f410L), tobe(0xcea245d3L), tobe(0xd07e2a92L), +tobe(0x886b2655L), tobe(0x96b74914L), tobe(0xb5d3f8d7L), tobe(0xab0f9796L), +tobe(0x05f9e159L), tobe(0x1b258e18L), tobe(0x38413fdbL), tobe(0x269d509aL), +tobe(0x7e885c5dL), tobe(0x6054331cL), tobe(0x433082dfL), tobe(0x5deced9eL), +tobe(0xf8e959e3L), tobe(0xe63536a2L), tobe(0xc5518761L), tobe(0xdb8de820L), +tobe(0x8398e4e7L), tobe(0x9d448ba6L), tobe(0xbe203a65L), tobe(0xa0fc5524L), +tobe(0x0e0a23ebL), tobe(0x10d64caaL), tobe(0x33b2fd69L), tobe(0x2d6e9228L), +tobe(0x757b9eefL), tobe(0x6ba7f1aeL), tobe(0x48c3406dL), tobe(0x561f2f2cL), +tobe(0x0bf3c2b2L), tobe(0x152fadf3L), tobe(0x364b1c30L), tobe(0x28977371L), +tobe(0x70827fb6L), tobe(0x6e5e10f7L), tobe(0x4d3aa134L), tobe(0x53e6ce75L), +tobe(0xfd10b8baL), tobe(0xe3ccd7fbL), tobe(0xc0a86638L), tobe(0xde740979L), +tobe(0x866105beL), tobe(0x98bd6affL), tobe(0xbbd9db3cL), tobe(0xa505b47dL), +tobe(0xef0edc87L), tobe(0xf1d2b3c6L), tobe(0xd2b60205L), tobe(0xcc6a6d44L), +tobe(0x947f6183L), tobe(0x8aa30ec2L), tobe(0xa9c7bf01L), tobe(0xb71bd040L), +tobe(0x19eda68fL), tobe(0x0731c9ceL), tobe(0x2455780dL), tobe(0x3a89174cL), +tobe(0x629c1b8bL), tobe(0x7c4074caL), tobe(0x5f24c509L), tobe(0x41f8aa48L), +tobe(0x1c1447d6L), tobe(0x02c82897L), tobe(0x21ac9954L), tobe(0x3f70f615L), +tobe(0x6765fad2L), tobe(0x79b99593L), tobe(0x5add2450L), tobe(0x44014b11L), +tobe(0xeaf73ddeL), tobe(0xf42b529fL), tobe(0xd74fe35cL), tobe(0xc9938c1dL), +tobe(0x918680daL), tobe(0x8f5aef9bL), tobe(0xac3e5e58L), tobe(0xb2e23119L), +tobe(0x17e78564L), tobe(0x093bea25L), tobe(0x2a5f5be6L), tobe(0x348334a7L), +tobe(0x6c963860L), tobe(0x724a5721L), tobe(0x512ee6e2L), tobe(0x4ff289a3L), +tobe(0xe104ff6cL), tobe(0xffd8902dL), tobe(0xdcbc21eeL), tobe(0xc2604eafL), +tobe(0x9a754268L), tobe(0x84a92d29L), tobe(0xa7cd9ceaL), tobe(0xb911f3abL), +tobe(0xe4fd1e35L), tobe(0xfa217174L), tobe(0xd945c0b7L), tobe(0xc799aff6L), +tobe(0x9f8ca331L), tobe(0x8150cc70L), tobe(0xa2347db3L), tobe(0xbce812f2L), +tobe(0x121e643dL), tobe(0x0cc20b7cL), tobe(0x2fa6babfL), tobe(0x317ad5feL), +tobe(0x696fd939L), tobe(0x77b3b678L), tobe(0x54d707bbL), tobe(0x4a0b68faL), +tobe(0xc0c1d64fL), tobe(0xde1db90eL), tobe(0xfd7908cdL), tobe(0xe3a5678cL), +tobe(0xbbb06b4bL), tobe(0xa56c040aL), tobe(0x8608b5c9L), tobe(0x98d4da88L), +tobe(0x3622ac47L), tobe(0x28fec306L), tobe(0x0b9a72c5L), tobe(0x15461d84L), +tobe(0x4d531143L), tobe(0x538f7e02L), tobe(0x70ebcfc1L), tobe(0x6e37a080L), +tobe(0x33db4d1eL), tobe(0x2d07225fL), tobe(0x0e63939cL), tobe(0x10bffcddL), +tobe(0x48aaf01aL), tobe(0x56769f5bL), tobe(0x75122e98L), tobe(0x6bce41d9L), +tobe(0xc5383716L), tobe(0xdbe45857L), tobe(0xf880e994L), tobe(0xe65c86d5L), +tobe(0xbe498a12L), tobe(0xa095e553L), tobe(0x83f15490L), tobe(0x9d2d3bd1L), +tobe(0x38288facL), tobe(0x26f4e0edL), tobe(0x0590512eL), tobe(0x1b4c3e6fL), +tobe(0x435932a8L), tobe(0x5d855de9L), tobe(0x7ee1ec2aL), tobe(0x603d836bL), +tobe(0xcecbf5a4L), tobe(0xd0179ae5L), tobe(0xf3732b26L), tobe(0xedaf4467L), +tobe(0xb5ba48a0L), tobe(0xab6627e1L), tobe(0x88029622L), tobe(0x96def963L), +tobe(0xcb3214fdL), tobe(0xd5ee7bbcL), tobe(0xf68aca7fL), tobe(0xe856a53eL), +tobe(0xb043a9f9L), tobe(0xae9fc6b8L), tobe(0x8dfb777bL), tobe(0x9327183aL), +tobe(0x3dd16ef5L), tobe(0x230d01b4L), tobe(0x0069b077L), tobe(0x1eb5df36L), +tobe(0x46a0d3f1L), tobe(0x587cbcb0L), tobe(0x7b180d73L), tobe(0x65c46232L), +tobe(0x2fcf0ac8L), tobe(0x31136589L), tobe(0x1277d44aL), tobe(0x0cabbb0bL), +tobe(0x54beb7ccL), tobe(0x4a62d88dL), tobe(0x6906694eL), tobe(0x77da060fL), +tobe(0xd92c70c0L), tobe(0xc7f01f81L), tobe(0xe494ae42L), tobe(0xfa48c103L), +tobe(0xa25dcdc4L), tobe(0xbc81a285L), tobe(0x9fe51346L), tobe(0x81397c07L), +tobe(0xdcd59199L), tobe(0xc209fed8L), tobe(0xe16d4f1bL), tobe(0xffb1205aL), +tobe(0xa7a42c9dL), tobe(0xb97843dcL), tobe(0x9a1cf21fL), tobe(0x84c09d5eL), +tobe(0x2a36eb91L), tobe(0x34ea84d0L), tobe(0x178e3513L), tobe(0x09525a52L), +tobe(0x51475695L), tobe(0x4f9b39d4L), tobe(0x6cff8817L), tobe(0x7223e756L), +tobe(0xd726532bL), tobe(0xc9fa3c6aL), tobe(0xea9e8da9L), tobe(0xf442e2e8L), +tobe(0xac57ee2fL), tobe(0xb28b816eL), tobe(0x91ef30adL), tobe(0x8f335fecL), +tobe(0x21c52923L), tobe(0x3f194662L), tobe(0x1c7df7a1L), tobe(0x02a198e0L), +tobe(0x5ab49427L), tobe(0x4468fb66L), tobe(0x670c4aa5L), tobe(0x79d025e4L), +tobe(0x243cc87aL), tobe(0x3ae0a73bL), tobe(0x198416f8L), tobe(0x075879b9L), +tobe(0x5f4d757eL), tobe(0x41911a3fL), tobe(0x62f5abfcL), tobe(0x7c29c4bdL), +tobe(0xd2dfb272L), tobe(0xcc03dd33L), tobe(0xef676cf0L), tobe(0xf1bb03b1L), +tobe(0xa9ae0f76L), tobe(0xb7726037L), tobe(0x9416d1f4L), tobe(0x8acabeb5L)}; + +static const uint32_t t1_be[] = { +tobe(0x00000000L), tobe(0x9f5fc3dfL), tobe(0x2063e8ffL), tobe(0xbf3c2b20L), +tobe(0x40c7d1feL), tobe(0xdf981221L), tobe(0x60a43901L), tobe(0xfffbfadeL), +tobe(0x818fa3fcL), tobe(0x1ed06023L), tobe(0xa1ec4b03L), tobe(0x3eb388dcL), +tobe(0xc1487202L), tobe(0x5e17b1ddL), tobe(0xe12b9afdL), tobe(0x7e745922L), +tobe(0x1dc328b9L), tobe(0x829ceb66L), tobe(0x3da0c046L), tobe(0xa2ff0399L), +tobe(0x5d04f947L), tobe(0xc25b3a98L), tobe(0x7d6711b8L), tobe(0xe238d267L), +tobe(0x9c4c8b45L), tobe(0x0313489aL), tobe(0xbc2f63baL), tobe(0x2370a065L), +tobe(0xdc8b5abbL), tobe(0x43d49964L), tobe(0xfce8b244L), tobe(0x63b7719bL), +tobe(0x3b865172L), tobe(0xa4d992adL), tobe(0x1be5b98dL), tobe(0x84ba7a52L), +tobe(0x7b41808cL), tobe(0xe41e4353L), tobe(0x5b226873L), tobe(0xc47dabacL), +tobe(0xba09f28eL), tobe(0x25563151L), tobe(0x9a6a1a71L), tobe(0x0535d9aeL), +tobe(0xface2370L), tobe(0x6591e0afL), tobe(0xdaadcb8fL), tobe(0x45f20850L), +tobe(0x264579cbL), tobe(0xb91aba14L), tobe(0x06269134L), tobe(0x997952ebL), +tobe(0x6682a835L), tobe(0xf9dd6beaL), tobe(0x46e140caL), tobe(0xd9be8315L), +tobe(0xa7cada37L), tobe(0x389519e8L), tobe(0x87a932c8L), tobe(0x18f6f117L), +tobe(0xe70d0bc9L), tobe(0x7852c816L), tobe(0xc76ee336L), tobe(0x583120e9L), +tobe(0x770ca2e4L), tobe(0xe853613bL), tobe(0x576f4a1bL), tobe(0xc83089c4L), +tobe(0x37cb731aL), tobe(0xa894b0c5L), tobe(0x17a89be5L), tobe(0x88f7583aL), +tobe(0xf6830118L), tobe(0x69dcc2c7L), tobe(0xd6e0e9e7L), tobe(0x49bf2a38L), +tobe(0xb644d0e6L), tobe(0x291b1339L), tobe(0x96273819L), tobe(0x0978fbc6L), +tobe(0x6acf8a5dL), tobe(0xf5904982L), tobe(0x4aac62a2L), tobe(0xd5f3a17dL), +tobe(0x2a085ba3L), tobe(0xb557987cL), tobe(0x0a6bb35cL), tobe(0x95347083L), +tobe(0xeb4029a1L), tobe(0x741fea7eL), tobe(0xcb23c15eL), tobe(0x547c0281L), +tobe(0xab87f85fL), tobe(0x34d83b80L), tobe(0x8be410a0L), tobe(0x14bbd37fL), +tobe(0x4c8af396L), tobe(0xd3d53049L), tobe(0x6ce91b69L), tobe(0xf3b6d8b6L), +tobe(0x0c4d2268L), tobe(0x9312e1b7L), tobe(0x2c2eca97L), tobe(0xb3710948L), +tobe(0xcd05506aL), tobe(0x525a93b5L), tobe(0xed66b895L), tobe(0x72397b4aL), +tobe(0x8dc28194L), tobe(0x129d424bL), tobe(0xada1696bL), tobe(0x32feaab4L), +tobe(0x5149db2fL), tobe(0xce1618f0L), tobe(0x712a33d0L), tobe(0xee75f00fL), +tobe(0x118e0ad1L), tobe(0x8ed1c90eL), tobe(0x31ede22eL), tobe(0xaeb221f1L), +tobe(0xd0c678d3L), tobe(0x4f99bb0cL), tobe(0xf0a5902cL), tobe(0x6ffa53f3L), +tobe(0x9001a92dL), tobe(0x0f5e6af2L), tobe(0xb06241d2L), tobe(0x2f3d820dL), +tobe(0xee1945c8L), tobe(0x71468617L), tobe(0xce7aad37L), tobe(0x51256ee8L), +tobe(0xaede9436L), tobe(0x318157e9L), tobe(0x8ebd7cc9L), tobe(0x11e2bf16L), +tobe(0x6f96e634L), tobe(0xf0c925ebL), tobe(0x4ff50ecbL), tobe(0xd0aacd14L), +tobe(0x2f5137caL), tobe(0xb00ef415L), tobe(0x0f32df35L), tobe(0x906d1ceaL), +tobe(0xf3da6d71L), tobe(0x6c85aeaeL), tobe(0xd3b9858eL), tobe(0x4ce64651L), +tobe(0xb31dbc8fL), tobe(0x2c427f50L), tobe(0x937e5470L), tobe(0x0c2197afL), +tobe(0x7255ce8dL), tobe(0xed0a0d52L), tobe(0x52362672L), tobe(0xcd69e5adL), +tobe(0x32921f73L), tobe(0xadcddcacL), tobe(0x12f1f78cL), tobe(0x8dae3453L), +tobe(0xd59f14baL), tobe(0x4ac0d765L), tobe(0xf5fcfc45L), tobe(0x6aa33f9aL), +tobe(0x9558c544L), tobe(0x0a07069bL), tobe(0xb53b2dbbL), tobe(0x2a64ee64L), +tobe(0x5410b746L), tobe(0xcb4f7499L), tobe(0x74735fb9L), tobe(0xeb2c9c66L), +tobe(0x14d766b8L), tobe(0x8b88a567L), tobe(0x34b48e47L), tobe(0xabeb4d98L), +tobe(0xc85c3c03L), tobe(0x5703ffdcL), tobe(0xe83fd4fcL), tobe(0x77601723L), +tobe(0x889bedfdL), tobe(0x17c42e22L), tobe(0xa8f80502L), tobe(0x37a7c6ddL), +tobe(0x49d39fffL), tobe(0xd68c5c20L), tobe(0x69b07700L), tobe(0xf6efb4dfL), +tobe(0x09144e01L), tobe(0x964b8ddeL), tobe(0x2977a6feL), tobe(0xb6286521L), +tobe(0x9915e72cL), tobe(0x064a24f3L), tobe(0xb9760fd3L), tobe(0x2629cc0cL), +tobe(0xd9d236d2L), tobe(0x468df50dL), tobe(0xf9b1de2dL), tobe(0x66ee1df2L), +tobe(0x189a44d0L), tobe(0x87c5870fL), tobe(0x38f9ac2fL), tobe(0xa7a66ff0L), +tobe(0x585d952eL), tobe(0xc70256f1L), tobe(0x783e7dd1L), tobe(0xe761be0eL), +tobe(0x84d6cf95L), tobe(0x1b890c4aL), tobe(0xa4b5276aL), tobe(0x3beae4b5L), +tobe(0xc4111e6bL), tobe(0x5b4eddb4L), tobe(0xe472f694L), tobe(0x7b2d354bL), +tobe(0x05596c69L), tobe(0x9a06afb6L), tobe(0x253a8496L), tobe(0xba654749L), +tobe(0x459ebd97L), tobe(0xdac17e48L), tobe(0x65fd5568L), tobe(0xfaa296b7L), +tobe(0xa293b65eL), tobe(0x3dcc7581L), tobe(0x82f05ea1L), tobe(0x1daf9d7eL), +tobe(0xe25467a0L), tobe(0x7d0ba47fL), tobe(0xc2378f5fL), tobe(0x5d684c80L), +tobe(0x231c15a2L), tobe(0xbc43d67dL), tobe(0x037ffd5dL), tobe(0x9c203e82L), +tobe(0x63dbc45cL), tobe(0xfc840783L), tobe(0x43b82ca3L), tobe(0xdce7ef7cL), +tobe(0xbf509ee7L), tobe(0x200f5d38L), tobe(0x9f337618L), tobe(0x006cb5c7L), +tobe(0xff974f19L), tobe(0x60c88cc6L), tobe(0xdff4a7e6L), tobe(0x40ab6439L), +tobe(0x3edf3d1bL), tobe(0xa180fec4L), tobe(0x1ebcd5e4L), tobe(0x81e3163bL), +tobe(0x7e18ece5L), tobe(0xe1472f3aL), tobe(0x5e7b041aL), tobe(0xc124c7c5L)}; + +static const uint32_t t2_be[] = { +tobe(0x00000000L), tobe(0xc2eee4d1L), tobe(0x9b01a6e3L), tobe(0x59ef4232L), +tobe(0x28df2287L), tobe(0xea31c656L), tobe(0xb3de8464L), tobe(0x713060b5L), +tobe(0x51be450eL), tobe(0x9350a1dfL), tobe(0xcabfe3edL), tobe(0x0851073cL), +tobe(0x79616789L), tobe(0xbb8f8358L), tobe(0xe260c16aL), tobe(0x208e25bbL), +tobe(0xa37c8a1cL), tobe(0x61926ecdL), tobe(0x387d2cffL), tobe(0xfa93c82eL), +tobe(0x8ba3a89bL), tobe(0x494d4c4aL), tobe(0x10a20e78L), tobe(0xd24ceaa9L), +tobe(0xf2c2cf12L), tobe(0x302c2bc3L), tobe(0x69c369f1L), tobe(0xab2d8d20L), +tobe(0xda1ded95L), tobe(0x18f30944L), tobe(0x411c4b76L), tobe(0x83f2afa7L), +tobe(0x58257b79L), tobe(0x9acb9fa8L), tobe(0xc324dd9aL), tobe(0x01ca394bL), +tobe(0x70fa59feL), tobe(0xb214bd2fL), tobe(0xebfbff1dL), tobe(0x29151bccL), +tobe(0x099b3e77L), tobe(0xcb75daa6L), tobe(0x929a9894L), tobe(0x50747c45L), +tobe(0x21441cf0L), tobe(0xe3aaf821L), tobe(0xba45ba13L), tobe(0x78ab5ec2L), +tobe(0xfb59f165L), tobe(0x39b715b4L), tobe(0x60585786L), tobe(0xa2b6b357L), +tobe(0xd386d3e2L), tobe(0x11683733L), tobe(0x48877501L), tobe(0x8a6991d0L), +tobe(0xaae7b46bL), tobe(0x680950baL), tobe(0x31e61288L), tobe(0xf308f659L), +tobe(0x823896ecL), tobe(0x40d6723dL), tobe(0x1939300fL), tobe(0xdbd7d4deL), +tobe(0xb04af6f2L), tobe(0x72a41223L), tobe(0x2b4b5011L), tobe(0xe9a5b4c0L), +tobe(0x9895d475L), tobe(0x5a7b30a4L), tobe(0x03947296L), tobe(0xc17a9647L), +tobe(0xe1f4b3fcL), tobe(0x231a572dL), tobe(0x7af5151fL), tobe(0xb81bf1ceL), +tobe(0xc92b917bL), tobe(0x0bc575aaL), tobe(0x522a3798L), tobe(0x90c4d349L), +tobe(0x13367ceeL), tobe(0xd1d8983fL), tobe(0x8837da0dL), tobe(0x4ad93edcL), +tobe(0x3be95e69L), tobe(0xf907bab8L), tobe(0xa0e8f88aL), tobe(0x62061c5bL), +tobe(0x428839e0L), tobe(0x8066dd31L), tobe(0xd9899f03L), tobe(0x1b677bd2L), +tobe(0x6a571b67L), tobe(0xa8b9ffb6L), tobe(0xf156bd84L), tobe(0x33b85955L), +tobe(0xe86f8d8bL), tobe(0x2a81695aL), tobe(0x736e2b68L), tobe(0xb180cfb9L), +tobe(0xc0b0af0cL), tobe(0x025e4bddL), tobe(0x5bb109efL), tobe(0x995fed3eL), +tobe(0xb9d1c885L), tobe(0x7b3f2c54L), tobe(0x22d06e66L), tobe(0xe03e8ab7L), +tobe(0x910eea02L), tobe(0x53e00ed3L), tobe(0x0a0f4ce1L), tobe(0xc8e1a830L), +tobe(0x4b130797L), tobe(0x89fde346L), tobe(0xd012a174L), tobe(0x12fc45a5L), +tobe(0x63cc2510L), tobe(0xa122c1c1L), tobe(0xf8cd83f3L), tobe(0x3a236722L), +tobe(0x1aad4299L), tobe(0xd843a648L), tobe(0x81ace47aL), tobe(0x434200abL), +tobe(0x3272601eL), tobe(0xf09c84cfL), tobe(0xa973c6fdL), tobe(0x6b9d222cL), +tobe(0x7e4982a5L), tobe(0xbca76674L), tobe(0xe5482446L), tobe(0x27a6c097L), +tobe(0x5696a022L), tobe(0x947844f3L), tobe(0xcd9706c1L), tobe(0x0f79e210L), +tobe(0x2ff7c7abL), tobe(0xed19237aL), tobe(0xb4f66148L), tobe(0x76188599L), +tobe(0x0728e52cL), tobe(0xc5c601fdL), tobe(0x9c2943cfL), tobe(0x5ec7a71eL), +tobe(0xdd3508b9L), tobe(0x1fdbec68L), tobe(0x4634ae5aL), tobe(0x84da4a8bL), +tobe(0xf5ea2a3eL), tobe(0x3704ceefL), tobe(0x6eeb8cddL), tobe(0xac05680cL), +tobe(0x8c8b4db7L), tobe(0x4e65a966L), tobe(0x178aeb54L), tobe(0xd5640f85L), +tobe(0xa4546f30L), tobe(0x66ba8be1L), tobe(0x3f55c9d3L), tobe(0xfdbb2d02L), +tobe(0x266cf9dcL), tobe(0xe4821d0dL), tobe(0xbd6d5f3fL), tobe(0x7f83bbeeL), +tobe(0x0eb3db5bL), tobe(0xcc5d3f8aL), tobe(0x95b27db8L), tobe(0x575c9969L), +tobe(0x77d2bcd2L), tobe(0xb53c5803L), tobe(0xecd31a31L), tobe(0x2e3dfee0L), +tobe(0x5f0d9e55L), tobe(0x9de37a84L), tobe(0xc40c38b6L), tobe(0x06e2dc67L), +tobe(0x851073c0L), tobe(0x47fe9711L), tobe(0x1e11d523L), tobe(0xdcff31f2L), +tobe(0xadcf5147L), tobe(0x6f21b596L), tobe(0x36cef7a4L), tobe(0xf4201375L), +tobe(0xd4ae36ceL), tobe(0x1640d21fL), tobe(0x4faf902dL), tobe(0x8d4174fcL), +tobe(0xfc711449L), tobe(0x3e9ff098L), tobe(0x6770b2aaL), tobe(0xa59e567bL), +tobe(0xce037457L), tobe(0x0ced9086L), tobe(0x5502d2b4L), tobe(0x97ec3665L), +tobe(0xe6dc56d0L), tobe(0x2432b201L), tobe(0x7dddf033L), tobe(0xbf3314e2L), +tobe(0x9fbd3159L), tobe(0x5d53d588L), tobe(0x04bc97baL), tobe(0xc652736bL), +tobe(0xb76213deL), tobe(0x758cf70fL), tobe(0x2c63b53dL), tobe(0xee8d51ecL), +tobe(0x6d7ffe4bL), tobe(0xaf911a9aL), tobe(0xf67e58a8L), tobe(0x3490bc79L), +tobe(0x45a0dcccL), tobe(0x874e381dL), tobe(0xdea17a2fL), tobe(0x1c4f9efeL), +tobe(0x3cc1bb45L), tobe(0xfe2f5f94L), tobe(0xa7c01da6L), tobe(0x652ef977L), +tobe(0x141e99c2L), tobe(0xd6f07d13L), tobe(0x8f1f3f21L), tobe(0x4df1dbf0L), +tobe(0x96260f2eL), tobe(0x54c8ebffL), tobe(0x0d27a9cdL), tobe(0xcfc94d1cL), +tobe(0xbef92da9L), tobe(0x7c17c978L), tobe(0x25f88b4aL), tobe(0xe7166f9bL), +tobe(0xc7984a20L), tobe(0x0576aef1L), tobe(0x5c99ecc3L), tobe(0x9e770812L), +tobe(0xef4768a7L), tobe(0x2da98c76L), tobe(0x7446ce44L), tobe(0xb6a82a95L), +tobe(0x355a8532L), tobe(0xf7b461e3L), tobe(0xae5b23d1L), tobe(0x6cb5c700L), +tobe(0x1d85a7b5L), tobe(0xdf6b4364L), tobe(0x86840156L), tobe(0x446ae587L), +tobe(0x64e4c03cL), tobe(0xa60a24edL), tobe(0xffe566dfL), tobe(0x3d0b820eL), +tobe(0x4c3be2bbL), tobe(0x8ed5066aL), tobe(0xd73a4458L), tobe(0x15d4a089L)}; + +static const uint32_t t3_be[] = { +tobe(0x00000000L), tobe(0xfc93054aL), tobe(0xe7fa65d5L), tobe(0x1b69609fL), +tobe(0xd128a4ebL), tobe(0x2dbba1a1L), tobe(0x36d2c13eL), tobe(0xca41c474L), +tobe(0xbc8d2697L), tobe(0x401e23ddL), tobe(0x5b774342L), tobe(0xa7e44608L), +tobe(0x6da5827cL), tobe(0x91368736L), tobe(0x8a5fe7a9L), tobe(0x76cce2e3L), +tobe(0x67c6226fL), tobe(0x9b552725L), tobe(0x803c47baL), tobe(0x7caf42f0L), +tobe(0xb6ee8684L), tobe(0x4a7d83ceL), tobe(0x5114e351L), tobe(0xad87e61bL), +tobe(0xdb4b04f8L), tobe(0x27d801b2L), tobe(0x3cb1612dL), tobe(0xc0226467L), +tobe(0x0a63a013L), tobe(0xf6f0a559L), tobe(0xed99c5c6L), tobe(0x110ac08cL), +tobe(0xcf8c44deL), tobe(0x331f4194L), tobe(0x2876210bL), tobe(0xd4e52441L), +tobe(0x1ea4e035L), tobe(0xe237e57fL), tobe(0xf95e85e0L), tobe(0x05cd80aaL), +tobe(0x73016249L), tobe(0x8f926703L), tobe(0x94fb079cL), tobe(0x686802d6L), +tobe(0xa229c6a2L), tobe(0x5ebac3e8L), tobe(0x45d3a377L), tobe(0xb940a63dL), +tobe(0xa84a66b1L), tobe(0x54d963fbL), tobe(0x4fb00364L), tobe(0xb323062eL), +tobe(0x7962c25aL), tobe(0x85f1c710L), tobe(0x9e98a78fL), tobe(0x620ba2c5L), +tobe(0x14c74026L), tobe(0xe854456cL), tobe(0xf33d25f3L), tobe(0x0fae20b9L), +tobe(0xc5efe4cdL), tobe(0x397ce187L), tobe(0x22158118L), tobe(0xde868452L), +tobe(0x81c4e6fdL), tobe(0x7d57e3b7L), tobe(0x663e8328L), tobe(0x9aad8662L), +tobe(0x50ec4216L), tobe(0xac7f475cL), tobe(0xb71627c3L), tobe(0x4b852289L), +tobe(0x3d49c06aL), tobe(0xc1dac520L), tobe(0xdab3a5bfL), tobe(0x2620a0f5L), +tobe(0xec616481L), tobe(0x10f261cbL), tobe(0x0b9b0154L), tobe(0xf708041eL), +tobe(0xe602c492L), tobe(0x1a91c1d8L), tobe(0x01f8a147L), tobe(0xfd6ba40dL), +tobe(0x372a6079L), tobe(0xcbb96533L), tobe(0xd0d005acL), tobe(0x2c4300e6L), +tobe(0x5a8fe205L), tobe(0xa61ce74fL), tobe(0xbd7587d0L), tobe(0x41e6829aL), +tobe(0x8ba746eeL), tobe(0x773443a4L), tobe(0x6c5d233bL), tobe(0x90ce2671L), +tobe(0x4e48a223L), tobe(0xb2dba769L), tobe(0xa9b2c7f6L), tobe(0x5521c2bcL), +tobe(0x9f6006c8L), tobe(0x63f30382L), tobe(0x789a631dL), tobe(0x84096657L), +tobe(0xf2c584b4L), tobe(0x0e5681feL), tobe(0x153fe161L), tobe(0xe9ace42bL), +tobe(0x23ed205fL), tobe(0xdf7e2515L), tobe(0xc417458aL), tobe(0x388440c0L), +tobe(0x298e804cL), tobe(0xd51d8506L), tobe(0xce74e599L), tobe(0x32e7e0d3L), +tobe(0xf8a624a7L), tobe(0x043521edL), tobe(0x1f5c4172L), tobe(0xe3cf4438L), +tobe(0x9503a6dbL), tobe(0x6990a391L), tobe(0x72f9c30eL), tobe(0x8e6ac644L), +tobe(0x442b0230L), tobe(0xb8b8077aL), tobe(0xa3d167e5L), tobe(0x5f4262afL), +tobe(0x1d55a2bbL), tobe(0xe1c6a7f1L), tobe(0xfaafc76eL), tobe(0x063cc224L), +tobe(0xcc7d0650L), tobe(0x30ee031aL), tobe(0x2b876385L), tobe(0xd71466cfL), +tobe(0xa1d8842cL), tobe(0x5d4b8166L), tobe(0x4622e1f9L), tobe(0xbab1e4b3L), +tobe(0x70f020c7L), tobe(0x8c63258dL), tobe(0x970a4512L), tobe(0x6b994058L), +tobe(0x7a9380d4L), tobe(0x8600859eL), tobe(0x9d69e501L), tobe(0x61fae04bL), +tobe(0xabbb243fL), tobe(0x57282175L), tobe(0x4c4141eaL), tobe(0xb0d244a0L), +tobe(0xc61ea643L), tobe(0x3a8da309L), tobe(0x21e4c396L), tobe(0xdd77c6dcL), +tobe(0x173602a8L), tobe(0xeba507e2L), tobe(0xf0cc677dL), tobe(0x0c5f6237L), +tobe(0xd2d9e665L), tobe(0x2e4ae32fL), tobe(0x352383b0L), tobe(0xc9b086faL), +tobe(0x03f1428eL), tobe(0xff6247c4L), tobe(0xe40b275bL), tobe(0x18982211L), +tobe(0x6e54c0f2L), tobe(0x92c7c5b8L), tobe(0x89aea527L), tobe(0x753da06dL), +tobe(0xbf7c6419L), tobe(0x43ef6153L), tobe(0x588601ccL), tobe(0xa4150486L), +tobe(0xb51fc40aL), tobe(0x498cc140L), tobe(0x52e5a1dfL), tobe(0xae76a495L), +tobe(0x643760e1L), tobe(0x98a465abL), tobe(0x83cd0534L), tobe(0x7f5e007eL), +tobe(0x0992e29dL), tobe(0xf501e7d7L), tobe(0xee688748L), tobe(0x12fb8202L), +tobe(0xd8ba4676L), tobe(0x2429433cL), tobe(0x3f4023a3L), tobe(0xc3d326e9L), +tobe(0x9c914446L), tobe(0x6002410cL), tobe(0x7b6b2193L), tobe(0x87f824d9L), +tobe(0x4db9e0adL), tobe(0xb12ae5e7L), tobe(0xaa438578L), tobe(0x56d08032L), +tobe(0x201c62d1L), tobe(0xdc8f679bL), tobe(0xc7e60704L), tobe(0x3b75024eL), +tobe(0xf134c63aL), tobe(0x0da7c370L), tobe(0x16cea3efL), tobe(0xea5da6a5L), +tobe(0xfb576629L), tobe(0x07c46363L), tobe(0x1cad03fcL), tobe(0xe03e06b6L), +tobe(0x2a7fc2c2L), tobe(0xd6ecc788L), tobe(0xcd85a717L), tobe(0x3116a25dL), +tobe(0x47da40beL), tobe(0xbb4945f4L), tobe(0xa020256bL), tobe(0x5cb32021L), +tobe(0x96f2e455L), tobe(0x6a61e11fL), tobe(0x71088180L), tobe(0x8d9b84caL), +tobe(0x531d0098L), tobe(0xaf8e05d2L), tobe(0xb4e7654dL), tobe(0x48746007L), +tobe(0x8235a473L), tobe(0x7ea6a139L), tobe(0x65cfc1a6L), tobe(0x995cc4ecL), +tobe(0xef90260fL), tobe(0x13032345L), tobe(0x086a43daL), tobe(0xf4f94690L), +tobe(0x3eb882e4L), tobe(0xc22b87aeL), tobe(0xd942e731L), tobe(0x25d1e27bL), +tobe(0x34db22f7L), tobe(0xc84827bdL), tobe(0xd3214722L), tobe(0x2fb24268L), +tobe(0xe5f3861cL), tobe(0x19608356L), tobe(0x0209e3c9L), tobe(0xfe9ae683L), +tobe(0x88560460L), tobe(0x74c5012aL), tobe(0x6fac61b5L), tobe(0x933f64ffL), +tobe(0x597ea08bL), tobe(0xa5eda5c1L), tobe(0xbe84c55eL), tobe(0x4217c014L)}; + +static const uint32_t t4_be[] = { +tobe(0x00000000L), tobe(0x3aab4576L), tobe(0x75568aecL), tobe(0x4ffdcf9aL), +tobe(0xeaad15d8L), tobe(0xd00650aeL), tobe(0x9ffb9f34L), tobe(0xa550da42L), +tobe(0xcb8644f1L), tobe(0xf12d0187L), tobe(0xbed0ce1dL), tobe(0x847b8b6bL), +tobe(0x212b5129L), tobe(0x1b80145fL), tobe(0x547ddbc5L), tobe(0x6ed69eb3L), +tobe(0x89d0e6a3L), tobe(0xb37ba3d5L), tobe(0xfc866c4fL), tobe(0xc62d2939L), +tobe(0x637df37bL), tobe(0x59d6b60dL), tobe(0x162b7997L), tobe(0x2c803ce1L), +tobe(0x4256a252L), tobe(0x78fde724L), tobe(0x370028beL), tobe(0x0dab6dc8L), +tobe(0xa8fbb78aL), tobe(0x9250f2fcL), tobe(0xddad3d66L), tobe(0xe7067810L), +tobe(0x0d7da207L), tobe(0x37d6e771L), tobe(0x782b28ebL), tobe(0x42806d9dL), +tobe(0xe7d0b7dfL), tobe(0xdd7bf2a9L), tobe(0x92863d33L), tobe(0xa82d7845L), +tobe(0xc6fbe6f6L), tobe(0xfc50a380L), tobe(0xb3ad6c1aL), tobe(0x8906296cL), +tobe(0x2c56f32eL), tobe(0x16fdb658L), tobe(0x590079c2L), tobe(0x63ab3cb4L), +tobe(0x84ad44a4L), tobe(0xbe0601d2L), tobe(0xf1fbce48L), tobe(0xcb508b3eL), +tobe(0x6e00517cL), tobe(0x54ab140aL), tobe(0x1b56db90L), tobe(0x21fd9ee6L), +tobe(0x4f2b0055L), tobe(0x75804523L), tobe(0x3a7d8ab9L), tobe(0x00d6cfcfL), +tobe(0xa586158dL), tobe(0x9f2d50fbL), tobe(0xd0d09f61L), tobe(0xea7bda17L), +tobe(0x1afb440eL), tobe(0x20500178L), tobe(0x6fadcee2L), tobe(0x55068b94L), +tobe(0xf05651d6L), tobe(0xcafd14a0L), tobe(0x8500db3aL), tobe(0xbfab9e4cL), +tobe(0xd17d00ffL), tobe(0xebd64589L), tobe(0xa42b8a13L), tobe(0x9e80cf65L), +tobe(0x3bd01527L), tobe(0x017b5051L), tobe(0x4e869fcbL), tobe(0x742ddabdL), +tobe(0x932ba2adL), tobe(0xa980e7dbL), tobe(0xe67d2841L), tobe(0xdcd66d37L), +tobe(0x7986b775L), tobe(0x432df203L), tobe(0x0cd03d99L), tobe(0x367b78efL), +tobe(0x58ade65cL), tobe(0x6206a32aL), tobe(0x2dfb6cb0L), tobe(0x175029c6L), +tobe(0xb200f384L), tobe(0x88abb6f2L), tobe(0xc7567968L), tobe(0xfdfd3c1eL), +tobe(0x1786e609L), tobe(0x2d2da37fL), tobe(0x62d06ce5L), tobe(0x587b2993L), +tobe(0xfd2bf3d1L), tobe(0xc780b6a7L), tobe(0x887d793dL), tobe(0xb2d63c4bL), +tobe(0xdc00a2f8L), tobe(0xe6abe78eL), tobe(0xa9562814L), tobe(0x93fd6d62L), +tobe(0x36adb720L), tobe(0x0c06f256L), tobe(0x43fb3dccL), tobe(0x795078baL), +tobe(0x9e5600aaL), tobe(0xa4fd45dcL), tobe(0xeb008a46L), tobe(0xd1abcf30L), +tobe(0x74fb1572L), tobe(0x4e505004L), tobe(0x01ad9f9eL), tobe(0x3b06dae8L), +tobe(0x55d0445bL), tobe(0x6f7b012dL), tobe(0x2086ceb7L), tobe(0x1a2d8bc1L), +tobe(0xbf7d5183L), tobe(0x85d614f5L), tobe(0xca2bdb6fL), tobe(0xf0809e19L), +tobe(0x35f6881cL), tobe(0x0f5dcd6aL), tobe(0x40a002f0L), tobe(0x7a0b4786L), +tobe(0xdf5b9dc4L), tobe(0xe5f0d8b2L), tobe(0xaa0d1728L), tobe(0x90a6525eL), +tobe(0xfe70ccedL), tobe(0xc4db899bL), tobe(0x8b264601L), tobe(0xb18d0377L), +tobe(0x14ddd935L), tobe(0x2e769c43L), tobe(0x618b53d9L), tobe(0x5b2016afL), +tobe(0xbc266ebfL), tobe(0x868d2bc9L), tobe(0xc970e453L), tobe(0xf3dba125L), +tobe(0x568b7b67L), tobe(0x6c203e11L), tobe(0x23ddf18bL), tobe(0x1976b4fdL), +tobe(0x77a02a4eL), tobe(0x4d0b6f38L), tobe(0x02f6a0a2L), tobe(0x385de5d4L), +tobe(0x9d0d3f96L), tobe(0xa7a67ae0L), tobe(0xe85bb57aL), tobe(0xd2f0f00cL), +tobe(0x388b2a1bL), tobe(0x02206f6dL), tobe(0x4ddda0f7L), tobe(0x7776e581L), +tobe(0xd2263fc3L), tobe(0xe88d7ab5L), tobe(0xa770b52fL), tobe(0x9ddbf059L), +tobe(0xf30d6eeaL), tobe(0xc9a62b9cL), tobe(0x865be406L), tobe(0xbcf0a170L), +tobe(0x19a07b32L), tobe(0x230b3e44L), tobe(0x6cf6f1deL), tobe(0x565db4a8L), +tobe(0xb15bccb8L), tobe(0x8bf089ceL), tobe(0xc40d4654L), tobe(0xfea60322L), +tobe(0x5bf6d960L), tobe(0x615d9c16L), tobe(0x2ea0538cL), tobe(0x140b16faL), +tobe(0x7add8849L), tobe(0x4076cd3fL), tobe(0x0f8b02a5L), tobe(0x352047d3L), +tobe(0x90709d91L), tobe(0xaadbd8e7L), tobe(0xe526177dL), tobe(0xdf8d520bL), +tobe(0x2f0dcc12L), tobe(0x15a68964L), tobe(0x5a5b46feL), tobe(0x60f00388L), +tobe(0xc5a0d9caL), tobe(0xff0b9cbcL), tobe(0xb0f65326L), tobe(0x8a5d1650L), +tobe(0xe48b88e3L), tobe(0xde20cd95L), tobe(0x91dd020fL), tobe(0xab764779L), +tobe(0x0e269d3bL), tobe(0x348dd84dL), tobe(0x7b7017d7L), tobe(0x41db52a1L), +tobe(0xa6dd2ab1L), tobe(0x9c766fc7L), tobe(0xd38ba05dL), tobe(0xe920e52bL), +tobe(0x4c703f69L), tobe(0x76db7a1fL), tobe(0x3926b585L), tobe(0x038df0f3L), +tobe(0x6d5b6e40L), tobe(0x57f02b36L), tobe(0x180de4acL), tobe(0x22a6a1daL), +tobe(0x87f67b98L), tobe(0xbd5d3eeeL), tobe(0xf2a0f174L), tobe(0xc80bb402L), +tobe(0x22706e15L), tobe(0x18db2b63L), tobe(0x5726e4f9L), tobe(0x6d8da18fL), +tobe(0xc8dd7bcdL), tobe(0xf2763ebbL), tobe(0xbd8bf121L), tobe(0x8720b457L), +tobe(0xe9f62ae4L), tobe(0xd35d6f92L), tobe(0x9ca0a008L), tobe(0xa60be57eL), +tobe(0x035b3f3cL), tobe(0x39f07a4aL), tobe(0x760db5d0L), tobe(0x4ca6f0a6L), +tobe(0xaba088b6L), tobe(0x910bcdc0L), tobe(0xdef6025aL), tobe(0xe45d472cL), +tobe(0x410d9d6eL), tobe(0x7ba6d818L), tobe(0x345b1782L), tobe(0x0ef052f4L), +tobe(0x6026cc47L), tobe(0x5a8d8931L), tobe(0x157046abL), tobe(0x2fdb03ddL), +tobe(0x8a8bd99fL), tobe(0xb0209ce9L), tobe(0xffdd5373L), tobe(0xc5761605L)}; + +static const uint32_t t5_be[] = { +tobe(0x00000000L), tobe(0x6bed1038L), tobe(0xd7da2070L), tobe(0xbc373048L), +tobe(0xb1682fa1L), tobe(0xda853f99L), tobe(0x66b20fd1L), tobe(0x0d5f1fe9L), +tobe(0x7c0c3003L), tobe(0x17e1203bL), tobe(0xabd61073L), tobe(0xc03b004bL), +tobe(0xcd641fa2L), tobe(0xa6890f9aL), tobe(0x1abe3fd2L), tobe(0x71532feaL), +tobe(0xf8186006L), tobe(0x93f5703eL), tobe(0x2fc24076L), tobe(0x442f504eL), +tobe(0x49704fa7L), tobe(0x229d5f9fL), tobe(0x9eaa6fd7L), tobe(0xf5477fefL), +tobe(0x84145005L), tobe(0xeff9403dL), tobe(0x53ce7075L), tobe(0x3823604dL), +tobe(0x357c7fa4L), tobe(0x5e916f9cL), tobe(0xe2a65fd4L), tobe(0x894b4fecL), +tobe(0xeeecaf4dL), tobe(0x8501bf75L), tobe(0x39368f3dL), tobe(0x52db9f05L), +tobe(0x5f8480ecL), tobe(0x346990d4L), tobe(0x885ea09cL), tobe(0xe3b3b0a4L), +tobe(0x92e09f4eL), tobe(0xf90d8f76L), tobe(0x453abf3eL), tobe(0x2ed7af06L), +tobe(0x2388b0efL), tobe(0x4865a0d7L), tobe(0xf452909fL), tobe(0x9fbf80a7L), +tobe(0x16f4cf4bL), tobe(0x7d19df73L), tobe(0xc12eef3bL), tobe(0xaac3ff03L), +tobe(0xa79ce0eaL), tobe(0xcc71f0d2L), tobe(0x7046c09aL), tobe(0x1babd0a2L), +tobe(0x6af8ff48L), tobe(0x0115ef70L), tobe(0xbd22df38L), tobe(0xd6cfcf00L), +tobe(0xdb90d0e9L), tobe(0xb07dc0d1L), tobe(0x0c4af099L), tobe(0x67a7e0a1L), +tobe(0xc30531dbL), tobe(0xa8e821e3L), tobe(0x14df11abL), tobe(0x7f320193L), +tobe(0x726d1e7aL), tobe(0x19800e42L), tobe(0xa5b73e0aL), tobe(0xce5a2e32L), +tobe(0xbf0901d8L), tobe(0xd4e411e0L), tobe(0x68d321a8L), tobe(0x033e3190L), +tobe(0x0e612e79L), tobe(0x658c3e41L), tobe(0xd9bb0e09L), tobe(0xb2561e31L), +tobe(0x3b1d51ddL), tobe(0x50f041e5L), tobe(0xecc771adL), tobe(0x872a6195L), +tobe(0x8a757e7cL), tobe(0xe1986e44L), tobe(0x5daf5e0cL), tobe(0x36424e34L), +tobe(0x471161deL), tobe(0x2cfc71e6L), tobe(0x90cb41aeL), tobe(0xfb265196L), +tobe(0xf6794e7fL), tobe(0x9d945e47L), tobe(0x21a36e0fL), tobe(0x4a4e7e37L), +tobe(0x2de99e96L), tobe(0x46048eaeL), tobe(0xfa33bee6L), tobe(0x91deaedeL), +tobe(0x9c81b137L), tobe(0xf76ca10fL), tobe(0x4b5b9147L), tobe(0x20b6817fL), +tobe(0x51e5ae95L), tobe(0x3a08beadL), tobe(0x863f8ee5L), tobe(0xedd29eddL), +tobe(0xe08d8134L), tobe(0x8b60910cL), tobe(0x3757a144L), tobe(0x5cbab17cL), +tobe(0xd5f1fe90L), tobe(0xbe1ceea8L), tobe(0x022bdee0L), tobe(0x69c6ced8L), +tobe(0x6499d131L), tobe(0x0f74c109L), tobe(0xb343f141L), tobe(0xd8aee179L), +tobe(0xa9fdce93L), tobe(0xc210deabL), tobe(0x7e27eee3L), tobe(0x15cafedbL), +tobe(0x1895e132L), tobe(0x7378f10aL), tobe(0xcf4fc142L), tobe(0xa4a2d17aL), +tobe(0x98d60cf7L), tobe(0xf33b1ccfL), tobe(0x4f0c2c87L), tobe(0x24e13cbfL), +tobe(0x29be2356L), tobe(0x4253336eL), tobe(0xfe640326L), tobe(0x9589131eL), +tobe(0xe4da3cf4L), tobe(0x8f372cccL), tobe(0x33001c84L), tobe(0x58ed0cbcL), +tobe(0x55b21355L), tobe(0x3e5f036dL), tobe(0x82683325L), tobe(0xe985231dL), +tobe(0x60ce6cf1L), tobe(0x0b237cc9L), tobe(0xb7144c81L), tobe(0xdcf95cb9L), +tobe(0xd1a64350L), tobe(0xba4b5368L), tobe(0x067c6320L), tobe(0x6d917318L), +tobe(0x1cc25cf2L), tobe(0x772f4ccaL), tobe(0xcb187c82L), tobe(0xa0f56cbaL), +tobe(0xadaa7353L), tobe(0xc647636bL), tobe(0x7a705323L), tobe(0x119d431bL), +tobe(0x763aa3baL), tobe(0x1dd7b382L), tobe(0xa1e083caL), tobe(0xca0d93f2L), +tobe(0xc7528c1bL), tobe(0xacbf9c23L), tobe(0x1088ac6bL), tobe(0x7b65bc53L), +tobe(0x0a3693b9L), tobe(0x61db8381L), tobe(0xddecb3c9L), tobe(0xb601a3f1L), +tobe(0xbb5ebc18L), tobe(0xd0b3ac20L), tobe(0x6c849c68L), tobe(0x07698c50L), +tobe(0x8e22c3bcL), tobe(0xe5cfd384L), tobe(0x59f8e3ccL), tobe(0x3215f3f4L), +tobe(0x3f4aec1dL), tobe(0x54a7fc25L), tobe(0xe890cc6dL), tobe(0x837ddc55L), +tobe(0xf22ef3bfL), tobe(0x99c3e387L), tobe(0x25f4d3cfL), tobe(0x4e19c3f7L), +tobe(0x4346dc1eL), tobe(0x28abcc26L), tobe(0x949cfc6eL), tobe(0xff71ec56L), +tobe(0x5bd33d2cL), tobe(0x303e2d14L), tobe(0x8c091d5cL), tobe(0xe7e40d64L), +tobe(0xeabb128dL), tobe(0x815602b5L), tobe(0x3d6132fdL), tobe(0x568c22c5L), +tobe(0x27df0d2fL), tobe(0x4c321d17L), tobe(0xf0052d5fL), tobe(0x9be83d67L), +tobe(0x96b7228eL), tobe(0xfd5a32b6L), tobe(0x416d02feL), tobe(0x2a8012c6L), +tobe(0xa3cb5d2aL), tobe(0xc8264d12L), tobe(0x74117d5aL), tobe(0x1ffc6d62L), +tobe(0x12a3728bL), tobe(0x794e62b3L), tobe(0xc57952fbL), tobe(0xae9442c3L), +tobe(0xdfc76d29L), tobe(0xb42a7d11L), tobe(0x081d4d59L), tobe(0x63f05d61L), +tobe(0x6eaf4288L), tobe(0x054252b0L), tobe(0xb97562f8L), tobe(0xd29872c0L), +tobe(0xb53f9261L), tobe(0xded28259L), tobe(0x62e5b211L), tobe(0x0908a229L), +tobe(0x0457bdc0L), tobe(0x6fbaadf8L), tobe(0xd38d9db0L), tobe(0xb8608d88L), +tobe(0xc933a262L), tobe(0xa2deb25aL), tobe(0x1ee98212L), tobe(0x7504922aL), +tobe(0x785b8dc3L), tobe(0x13b69dfbL), tobe(0xaf81adb3L), tobe(0xc46cbd8bL), +tobe(0x4d27f267L), tobe(0x26cae25fL), tobe(0x9afdd217L), tobe(0xf110c22fL), +tobe(0xfc4fddc6L), tobe(0x97a2cdfeL), tobe(0x2b95fdb6L), tobe(0x4078ed8eL), +tobe(0x312bc264L), tobe(0x5ac6d25cL), tobe(0xe6f1e214L), tobe(0x8d1cf22cL), +tobe(0x8043edc5L), tobe(0xebaefdfdL), tobe(0x5799cdb5L), tobe(0x3c74dd8dL)}; + +static const uint32_t t6_be[] = { +tobe(0x00000000L), tobe(0x2f7076afL), tobe(0x5ee0ed5eL), tobe(0x71909bf1L), +tobe(0xbdc1dabcL), tobe(0x92b1ac13L), tobe(0xe32137e2L), tobe(0xcc51414dL), +tobe(0x655fda39L), tobe(0x4a2fac96L), tobe(0x3bbf3767L), tobe(0x14cf41c8L), +tobe(0xd89e0085L), tobe(0xf7ee762aL), tobe(0x867eeddbL), tobe(0xa90e9b74L), +tobe(0xcabfb472L), tobe(0xe5cfc2ddL), tobe(0x945f592cL), tobe(0xbb2f2f83L), +tobe(0x777e6eceL), tobe(0x580e1861L), tobe(0x299e8390L), tobe(0x06eef53fL), +tobe(0xafe06e4bL), tobe(0x809018e4L), tobe(0xf1008315L), tobe(0xde70f5baL), +tobe(0x1221b4f7L), tobe(0x3d51c258L), tobe(0x4cc159a9L), tobe(0x63b12f06L), +tobe(0x8ba307a5L), tobe(0xa4d3710aL), tobe(0xd543eafbL), tobe(0xfa339c54L), +tobe(0x3662dd19L), tobe(0x1912abb6L), tobe(0x68823047L), tobe(0x47f246e8L), +tobe(0xeefcdd9cL), tobe(0xc18cab33L), tobe(0xb01c30c2L), tobe(0x9f6c466dL), +tobe(0x533d0720L), tobe(0x7c4d718fL), tobe(0x0dddea7eL), tobe(0x22ad9cd1L), +tobe(0x411cb3d7L), tobe(0x6e6cc578L), tobe(0x1ffc5e89L), tobe(0x308c2826L), +tobe(0xfcdd696bL), tobe(0xd3ad1fc4L), tobe(0xa23d8435L), tobe(0x8d4df29aL), +tobe(0x244369eeL), tobe(0x0b331f41L), tobe(0x7aa384b0L), tobe(0x55d3f21fL), +tobe(0x9982b352L), tobe(0xb6f2c5fdL), tobe(0xc7625e0cL), tobe(0xe81228a3L), +tobe(0x099a600bL), tobe(0x26ea16a4L), tobe(0x577a8d55L), tobe(0x780afbfaL), +tobe(0xb45bbab7L), tobe(0x9b2bcc18L), tobe(0xeabb57e9L), tobe(0xc5cb2146L), +tobe(0x6cc5ba32L), tobe(0x43b5cc9dL), tobe(0x3225576cL), tobe(0x1d5521c3L), +tobe(0xd104608eL), tobe(0xfe741621L), tobe(0x8fe48dd0L), tobe(0xa094fb7fL), +tobe(0xc325d479L), tobe(0xec55a2d6L), tobe(0x9dc53927L), tobe(0xb2b54f88L), +tobe(0x7ee40ec5L), tobe(0x5194786aL), tobe(0x2004e39bL), tobe(0x0f749534L), +tobe(0xa67a0e40L), tobe(0x890a78efL), tobe(0xf89ae31eL), tobe(0xd7ea95b1L), +tobe(0x1bbbd4fcL), tobe(0x34cba253L), tobe(0x455b39a2L), tobe(0x6a2b4f0dL), +tobe(0x823967aeL), tobe(0xad491101L), tobe(0xdcd98af0L), tobe(0xf3a9fc5fL), +tobe(0x3ff8bd12L), tobe(0x1088cbbdL), tobe(0x6118504cL), tobe(0x4e6826e3L), +tobe(0xe766bd97L), tobe(0xc816cb38L), tobe(0xb98650c9L), tobe(0x96f62666L), +tobe(0x5aa7672bL), tobe(0x75d71184L), tobe(0x04478a75L), tobe(0x2b37fcdaL), +tobe(0x4886d3dcL), tobe(0x67f6a573L), tobe(0x16663e82L), tobe(0x3916482dL), +tobe(0xf5470960L), tobe(0xda377fcfL), tobe(0xaba7e43eL), tobe(0x84d79291L), +tobe(0x2dd909e5L), tobe(0x02a97f4aL), tobe(0x7339e4bbL), tobe(0x5c499214L), +tobe(0x9018d359L), tobe(0xbf68a5f6L), tobe(0xcef83e07L), tobe(0xe18848a8L), +tobe(0x1334c016L), tobe(0x3c44b6b9L), tobe(0x4dd42d48L), tobe(0x62a45be7L), +tobe(0xaef51aaaL), tobe(0x81856c05L), tobe(0xf015f7f4L), tobe(0xdf65815bL), +tobe(0x766b1a2fL), tobe(0x591b6c80L), tobe(0x288bf771L), tobe(0x07fb81deL), +tobe(0xcbaac093L), tobe(0xe4dab63cL), tobe(0x954a2dcdL), tobe(0xba3a5b62L), +tobe(0xd98b7464L), tobe(0xf6fb02cbL), tobe(0x876b993aL), tobe(0xa81bef95L), +tobe(0x644aaed8L), tobe(0x4b3ad877L), tobe(0x3aaa4386L), tobe(0x15da3529L), +tobe(0xbcd4ae5dL), tobe(0x93a4d8f2L), tobe(0xe2344303L), tobe(0xcd4435acL), +tobe(0x011574e1L), tobe(0x2e65024eL), tobe(0x5ff599bfL), tobe(0x7085ef10L), +tobe(0x9897c7b3L), tobe(0xb7e7b11cL), tobe(0xc6772aedL), tobe(0xe9075c42L), +tobe(0x25561d0fL), tobe(0x0a266ba0L), tobe(0x7bb6f051L), tobe(0x54c686feL), +tobe(0xfdc81d8aL), tobe(0xd2b86b25L), tobe(0xa328f0d4L), tobe(0x8c58867bL), +tobe(0x4009c736L), tobe(0x6f79b199L), tobe(0x1ee92a68L), tobe(0x31995cc7L), +tobe(0x522873c1L), tobe(0x7d58056eL), tobe(0x0cc89e9fL), tobe(0x23b8e830L), +tobe(0xefe9a97dL), tobe(0xc099dfd2L), tobe(0xb1094423L), tobe(0x9e79328cL), +tobe(0x3777a9f8L), tobe(0x1807df57L), tobe(0x699744a6L), tobe(0x46e73209L), +tobe(0x8ab67344L), tobe(0xa5c605ebL), tobe(0xd4569e1aL), tobe(0xfb26e8b5L), +tobe(0x1aaea01dL), tobe(0x35ded6b2L), tobe(0x444e4d43L), tobe(0x6b3e3becL), +tobe(0xa76f7aa1L), tobe(0x881f0c0eL), tobe(0xf98f97ffL), tobe(0xd6ffe150L), +tobe(0x7ff17a24L), tobe(0x50810c8bL), tobe(0x2111977aL), tobe(0x0e61e1d5L), +tobe(0xc230a098L), tobe(0xed40d637L), tobe(0x9cd04dc6L), tobe(0xb3a03b69L), +tobe(0xd011146fL), tobe(0xff6162c0L), tobe(0x8ef1f931L), tobe(0xa1818f9eL), +tobe(0x6dd0ced3L), tobe(0x42a0b87cL), tobe(0x3330238dL), tobe(0x1c405522L), +tobe(0xb54ece56L), tobe(0x9a3eb8f9L), tobe(0xebae2308L), tobe(0xc4de55a7L), +tobe(0x088f14eaL), tobe(0x27ff6245L), tobe(0x566ff9b4L), tobe(0x791f8f1bL), +tobe(0x910da7b8L), tobe(0xbe7dd117L), tobe(0xcfed4ae6L), tobe(0xe09d3c49L), +tobe(0x2ccc7d04L), tobe(0x03bc0babL), tobe(0x722c905aL), tobe(0x5d5ce6f5L), +tobe(0xf4527d81L), tobe(0xdb220b2eL), tobe(0xaab290dfL), tobe(0x85c2e670L), +tobe(0x4993a73dL), tobe(0x66e3d192L), tobe(0x17734a63L), tobe(0x38033cccL), +tobe(0x5bb213caL), tobe(0x74c26565L), tobe(0x0552fe94L), tobe(0x2a22883bL), +tobe(0xe673c976L), tobe(0xc903bfd9L), tobe(0xb8932428L), tobe(0x97e35287L), +tobe(0x3eedc9f3L), tobe(0x119dbf5cL), tobe(0x600d24adL), tobe(0x4f7d5202L), +tobe(0x832c134fL), tobe(0xac5c65e0L), tobe(0xddccfe11L), tobe(0xf2bc88beL)}; + +static const uint32_t t7_be[] = { +tobe(0x00000000L), tobe(0x2669802cL), tobe(0x4cd30058L), tobe(0x6aba8074L), +tobe(0x99a600b0L), tobe(0xbfcf809cL), tobe(0xd57500e8L), tobe(0xf31c80c4L), +tobe(0x2d906e21L), tobe(0x0bf9ee0dL), tobe(0x61436e79L), tobe(0x472aee55L), +tobe(0xb4366e91L), tobe(0x925feebdL), tobe(0xf8e56ec9L), tobe(0xde8ceee5L), +tobe(0x5b20dc42L), tobe(0x7d495c6eL), tobe(0x17f3dc1aL), tobe(0x319a5c36L), +tobe(0xc286dcf2L), tobe(0xe4ef5cdeL), tobe(0x8e55dcaaL), tobe(0xa83c5c86L), +tobe(0x76b0b263L), tobe(0x50d9324fL), tobe(0x3a63b23bL), tobe(0x1c0a3217L), +tobe(0xef16b2d3L), tobe(0xc97f32ffL), tobe(0xa3c5b28bL), tobe(0x85ac32a7L), +tobe(0xb641b884L), tobe(0x902838a8L), tobe(0xfa92b8dcL), tobe(0xdcfb38f0L), +tobe(0x2fe7b834L), tobe(0x098e3818L), tobe(0x6334b86cL), tobe(0x455d3840L), +tobe(0x9bd1d6a5L), tobe(0xbdb85689L), tobe(0xd702d6fdL), tobe(0xf16b56d1L), +tobe(0x0277d615L), tobe(0x241e5639L), tobe(0x4ea4d64dL), tobe(0x68cd5661L), +tobe(0xed6164c6L), tobe(0xcb08e4eaL), tobe(0xa1b2649eL), tobe(0x87dbe4b2L), +tobe(0x74c76476L), tobe(0x52aee45aL), tobe(0x3814642eL), tobe(0x1e7de402L), +tobe(0xc0f10ae7L), tobe(0xe6988acbL), tobe(0x8c220abfL), tobe(0xaa4b8a93L), +tobe(0x59570a57L), tobe(0x7f3e8a7bL), tobe(0x15840a0fL), tobe(0x33ed8a23L), +tobe(0x725f1e49L), tobe(0x54369e65L), tobe(0x3e8c1e11L), tobe(0x18e59e3dL), +tobe(0xebf91ef9L), tobe(0xcd909ed5L), tobe(0xa72a1ea1L), tobe(0x81439e8dL), +tobe(0x5fcf7068L), tobe(0x79a6f044L), tobe(0x131c7030L), tobe(0x3575f01cL), +tobe(0xc66970d8L), tobe(0xe000f0f4L), tobe(0x8aba7080L), tobe(0xacd3f0acL), +tobe(0x297fc20bL), tobe(0x0f164227L), tobe(0x65acc253L), tobe(0x43c5427fL), +tobe(0xb0d9c2bbL), tobe(0x96b04297L), tobe(0xfc0ac2e3L), tobe(0xda6342cfL), +tobe(0x04efac2aL), tobe(0x22862c06L), tobe(0x483cac72L), tobe(0x6e552c5eL), +tobe(0x9d49ac9aL), tobe(0xbb202cb6L), tobe(0xd19aacc2L), tobe(0xf7f32ceeL), +tobe(0xc41ea6cdL), tobe(0xe27726e1L), tobe(0x88cda695L), tobe(0xaea426b9L), +tobe(0x5db8a67dL), tobe(0x7bd12651L), tobe(0x116ba625L), tobe(0x37022609L), +tobe(0xe98ec8ecL), tobe(0xcfe748c0L), tobe(0xa55dc8b4L), tobe(0x83344898L), +tobe(0x7028c85cL), tobe(0x56414870L), tobe(0x3cfbc804L), tobe(0x1a924828L), +tobe(0x9f3e7a8fL), tobe(0xb957faa3L), tobe(0xd3ed7ad7L), tobe(0xf584fafbL), +tobe(0x06987a3fL), tobe(0x20f1fa13L), tobe(0x4a4b7a67L), tobe(0x6c22fa4bL), +tobe(0xb2ae14aeL), tobe(0x94c79482L), tobe(0xfe7d14f6L), tobe(0xd81494daL), +tobe(0x2b08141eL), tobe(0x0d619432L), tobe(0x67db1446L), tobe(0x41b2946aL), +tobe(0xe4be3c92L), tobe(0xc2d7bcbeL), tobe(0xa86d3ccaL), tobe(0x8e04bce6L), +tobe(0x7d183c22L), tobe(0x5b71bc0eL), tobe(0x31cb3c7aL), tobe(0x17a2bc56L), +tobe(0xc92e52b3L), tobe(0xef47d29fL), tobe(0x85fd52ebL), tobe(0xa394d2c7L), +tobe(0x50885203L), tobe(0x76e1d22fL), tobe(0x1c5b525bL), tobe(0x3a32d277L), +tobe(0xbf9ee0d0L), tobe(0x99f760fcL), tobe(0xf34de088L), tobe(0xd52460a4L), +tobe(0x2638e060L), tobe(0x0051604cL), tobe(0x6aebe038L), tobe(0x4c826014L), +tobe(0x920e8ef1L), tobe(0xb4670eddL), tobe(0xdedd8ea9L), tobe(0xf8b40e85L), +tobe(0x0ba88e41L), tobe(0x2dc10e6dL), tobe(0x477b8e19L), tobe(0x61120e35L), +tobe(0x52ff8416L), tobe(0x7496043aL), tobe(0x1e2c844eL), tobe(0x38450462L), +tobe(0xcb5984a6L), tobe(0xed30048aL), tobe(0x878a84feL), tobe(0xa1e304d2L), +tobe(0x7f6fea37L), tobe(0x59066a1bL), tobe(0x33bcea6fL), tobe(0x15d56a43L), +tobe(0xe6c9ea87L), tobe(0xc0a06aabL), tobe(0xaa1aeadfL), tobe(0x8c736af3L), +tobe(0x09df5854L), tobe(0x2fb6d878L), tobe(0x450c580cL), tobe(0x6365d820L), +tobe(0x907958e4L), tobe(0xb610d8c8L), tobe(0xdcaa58bcL), tobe(0xfac3d890L), +tobe(0x244f3675L), tobe(0x0226b659L), tobe(0x689c362dL), tobe(0x4ef5b601L), +tobe(0xbde936c5L), tobe(0x9b80b6e9L), tobe(0xf13a369dL), tobe(0xd753b6b1L), +tobe(0x96e122dbL), tobe(0xb088a2f7L), tobe(0xda322283L), tobe(0xfc5ba2afL), +tobe(0x0f47226bL), tobe(0x292ea247L), tobe(0x43942233L), tobe(0x65fda21fL), +tobe(0xbb714cfaL), tobe(0x9d18ccd6L), tobe(0xf7a24ca2L), tobe(0xd1cbcc8eL), +tobe(0x22d74c4aL), tobe(0x04becc66L), tobe(0x6e044c12L), tobe(0x486dcc3eL), +tobe(0xcdc1fe99L), tobe(0xeba87eb5L), tobe(0x8112fec1L), tobe(0xa77b7eedL), +tobe(0x5467fe29L), tobe(0x720e7e05L), tobe(0x18b4fe71L), tobe(0x3edd7e5dL), +tobe(0xe05190b8L), tobe(0xc6381094L), tobe(0xac8290e0L), tobe(0x8aeb10ccL), +tobe(0x79f79008L), tobe(0x5f9e1024L), tobe(0x35249050L), tobe(0x134d107cL), +tobe(0x20a09a5fL), tobe(0x06c91a73L), tobe(0x6c739a07L), tobe(0x4a1a1a2bL), +tobe(0xb9069aefL), tobe(0x9f6f1ac3L), tobe(0xf5d59ab7L), tobe(0xd3bc1a9bL), +tobe(0x0d30f47eL), tobe(0x2b597452L), tobe(0x41e3f426L), tobe(0x678a740aL), +tobe(0x9496f4ceL), tobe(0xb2ff74e2L), tobe(0xd845f496L), tobe(0xfe2c74baL), +tobe(0x7b80461dL), tobe(0x5de9c631L), tobe(0x37534645L), tobe(0x113ac669L), +tobe(0xe22646adL), tobe(0xc44fc681L), tobe(0xaef546f5L), tobe(0x889cc6d9L), +tobe(0x5610283cL), tobe(0x7079a810L), tobe(0x1ac32864L), tobe(0x3caaa848L), +tobe(0xcfb6288cL), tobe(0xe9dfa8a0L), tobe(0x836528d4L), tobe(0xa50ca8f8L)}; + diff --git a/libcustomext2fs/source/csum.c b/libcustomext2fs/source/csum.c index 58e29710..596923e5 100644 --- a/libcustomext2fs/source/csum.c +++ b/libcustomext2fs/source/csum.c @@ -10,6 +10,7 @@ * %End-Header% */ +#include "config.h" #if HAVE_SYS_TYPES_H #include #endif @@ -46,7 +47,7 @@ STATIC __u16 ext2fs_group_desc_csum(ext2_filsys fs, dgrp_t group) desc = ext2fs_group_desc(fs, fs->group_desc, group); if (fs->super->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_GDT_CSUM) { - int offset = offsetof(struct ext2_group_desc, bg_checksum); + size_t offset = offsetof(struct ext2_group_desc, bg_checksum); #ifdef WORDS_BIGENDIAN struct ext4_group_desc swabdesc; @@ -127,10 +128,10 @@ errcode_t ext2fs_set_gdt_csum(ext2_filsys fs) return 0; for (i = 0; i < fs->group_desc_count; i++) { - unsigned int old_csum = ext2fs_bg_checksum(fs, i); - int old_unused = ext2fs_bg_itable_unused(fs, i); - unsigned int old_flags = ext2fs_bg_flags(fs, i); - int old_free_inodes_count = ext2fs_bg_free_inodes_count(fs, i); + __u32 old_csum = ext2fs_bg_checksum(fs, i); + __u32 old_unused = ext2fs_bg_itable_unused(fs, i); + __u32 old_flags = ext2fs_bg_flags(fs, i); + __u32 old_free_inodes_count = ext2fs_bg_free_inodes_count(fs, i); if (old_free_inodes_count == sb->s_inodes_per_group) { ext2fs_bg_flags_set(fs, i, EXT2_BG_INODE_UNINIT); diff --git a/libcustomext2fs/source/dblist.c b/libcustomext2fs/source/dblist.c index 8ee61b4c..80017921 100644 --- a/libcustomext2fs/source/dblist.c +++ b/libcustomext2fs/source/dblist.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #if HAVE_UNISTD_H #include @@ -60,7 +61,7 @@ static errcode_t make_dblist(ext2_filsys fs, ext2_ino_t size, struct ext2_db_entry2 *list, ext2_dblist *ret_dblist) { - ext2_dblist dblist; + ext2_dblist dblist = 0; errcode_t retval; ext2_ino_t num_dirs; size_t len; @@ -73,7 +74,7 @@ static errcode_t make_dblist(ext2_filsys fs, ext2_ino_t size, retval = ext2fs_get_mem(sizeof(struct ext2_struct_dblist), &dblist); if (retval) - return retval; + goto cleanup; memset(dblist, 0, sizeof(struct ext2_struct_dblist)); dblist->magic = EXT2_ET_MAGIC_DBLIST; @@ -172,7 +173,7 @@ errcode_t ext2fs_add_dir_block2(ext2_dblist dblist, ext2_ino_t ino, sizeof(struct ext2_db_entry2), &dblist->list); if (retval) { - dblist->size -= 100; + dblist->size = old_size / sizeof(struct ext2_db_entry2); return retval; } } diff --git a/libcustomext2fs/source/dblist_dir.c b/libcustomext2fs/source/dblist_dir.c index 07ed8afa..d4d51114 100644 --- a/libcustomext2fs/source/dblist_dir.c +++ b/libcustomext2fs/source/dblist_dir.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #if HAVE_UNISTD_H #include diff --git a/libcustomext2fs/source/dir_iterate.c b/libcustomext2fs/source/dir_iterate.c index 88f6b476..5125d199 100644 --- a/libcustomext2fs/source/dir_iterate.c +++ b/libcustomext2fs/source/dir_iterate.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H diff --git a/libcustomext2fs/source/dirblock.c b/libcustomext2fs/source/dirblock.c index 73e1f0ab..cb3a104c 100644 --- a/libcustomext2fs/source/dirblock.c +++ b/libcustomext2fs/source/dirblock.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #if HAVE_UNISTD_H #include diff --git a/libcustomext2fs/source/dirhash.c b/libcustomext2fs/source/dirhash.c index a0697069..c4ac94e0 100644 --- a/libcustomext2fs/source/dirhash.c +++ b/libcustomext2fs/source/dirhash.c @@ -11,6 +11,7 @@ * %End-Header% */ +#include "config.h" #include #include @@ -217,11 +218,13 @@ errcode_t ext2fs_dirhash(int version, const char *name, int len, switch (version) { case EXT2_HASH_LEGACY_UNSIGNED: unsigned_flag++; + /* fallthrough */ case EXT2_HASH_LEGACY: hash = dx_hack_hash(name, len, unsigned_flag); break; case EXT2_HASH_HALF_MD4_UNSIGNED: unsigned_flag++; + /* fallthrough */ case EXT2_HASH_HALF_MD4: p = name; while (len > 0) { @@ -235,6 +238,7 @@ errcode_t ext2fs_dirhash(int version, const char *name, int len, break; case EXT2_HASH_TEA_UNSIGNED: unsigned_flag++; + /* fallthrough */ case EXT2_HASH_TEA: p = name; while (len > 0) { diff --git a/libcustomext2fs/source/disc_cache.c b/libcustomext2fs/source/disc_cache.c index 2a9ad05c..00fa53b4 100644 --- a/libcustomext2fs/source/disc_cache.c +++ b/libcustomext2fs/source/disc_cache.c @@ -52,12 +52,12 @@ CACHE* cache_constructor (unsigned int numberOfPages, unsigned int sectorsPerPag if(numberOfPages==0 || sectorsPerPage==0) return NULL; - if (numberOfPages < 4) { - numberOfPages = 4; + if (numberOfPages < 32) { + numberOfPages = 32; } - if (sectorsPerPage < 32) { - sectorsPerPage = 32; + if (sectorsPerPage < 16) { + sectorsPerPage = 16; } cache = (CACHE*) mem_alloc (sizeof(CACHE)); diff --git a/libcustomext2fs/source/dupfs.c b/libcustomext2fs/source/dupfs.c index a9e2a976..64d31248 100644 --- a/libcustomext2fs/source/dupfs.c +++ b/libcustomext2fs/source/dupfs.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #if HAVE_UNISTD_H #include diff --git a/libcustomext2fs/source/e2image.h b/libcustomext2fs/source/e2image.h index 4de2c8d9..c918529e 100644 --- a/libcustomext2fs/source/e2image.h +++ b/libcustomext2fs/source/e2image.h @@ -12,6 +12,14 @@ * %End-Header% */ +/* Image types */ +#define E2IMAGE_RAW 1 +#define E2IMAGE_QCOW2 2 + +/* Image flags */ +#define E2IMAGE_INSTALL_FLAG 1 +#define E2IMAGE_SCRAMBLE_FLAG 2 +#define E2IMAGE_IS_QCOW2_FLAG 3 struct ext2_image_hdr { __u32 magic_number; /* This must be EXT2_ET_MAGIC_E2IMAGE */ @@ -36,16 +44,3 @@ struct ext2_image_hdr { __u32 offset_blockmap; /* Byte offset of the inode bitmaps */ __u32 offset_reserved[8]; }; - - - - - - - - - - - - - diff --git a/libcustomext2fs/source/expanddir.c b/libcustomext2fs/source/expanddir.c index 7673a3bd..41c40882 100644 --- a/libcustomext2fs/source/expanddir.c +++ b/libcustomext2fs/source/expanddir.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H @@ -21,6 +22,7 @@ struct expand_dir_struct { int done; int newblocks; + blk64_t goal; errcode_t err; }; @@ -33,18 +35,25 @@ static int expand_dir_proc(ext2_filsys fs, { struct expand_dir_struct *es = (struct expand_dir_struct *) priv_data; blk64_t new_blk; - static blk64_t last_blk = 0; char *block; errcode_t retval; if (*blocknr) { - last_blk = *blocknr; + if (blockcnt >= 0) + es->goal = *blocknr; return 0; } - retval = ext2fs_new_block2(fs, last_blk, 0, &new_blk); - if (retval) { - es->err = retval; - return BLOCK_ABORT; + if (blockcnt && + (EXT2FS_B2C(fs, es->goal) == EXT2FS_B2C(fs, es->goal+1))) + new_blk = es->goal+1; + else { + es->goal &= ~EXT2FS_CLUSTER_MASK(fs); + retval = ext2fs_new_block2(fs, es->goal, 0, &new_blk); + if (retval) { + es->err = retval; + return BLOCK_ABORT; + } + es->newblocks++; } if (blockcnt > 0) { retval = ext2fs_new_dir_block(fs, 0, 0, &block); @@ -63,6 +72,8 @@ static int expand_dir_proc(ext2_filsys fs, memset(block, 0, fs->blocksize); retval = io_channel_write_blk64(fs->io, new_blk, 1, block); } + if (blockcnt >= 0) + es->goal = new_blk; if (retval) { es->err = retval; return BLOCK_ABORT; @@ -70,7 +81,6 @@ static int expand_dir_proc(ext2_filsys fs, ext2fs_free_mem(&block); *blocknr = new_blk; ext2fs_block_alloc_stats2(fs, new_blk, +1); - es->newblocks++; if (es->done) return (BLOCK_CHANGED | BLOCK_ABORT); @@ -98,6 +108,7 @@ errcode_t ext2fs_expand_dir(ext2_filsys fs, ext2_ino_t dir) es.done = 0; es.err = 0; + es.goal = 0; es.newblocks = 0; retval = ext2fs_block_iterate3(fs, dir, BLOCK_FLAG_APPEND, diff --git a/libcustomext2fs/source/ext2.c b/libcustomext2fs/source/ext2.c index 7cff7f3c..02b94702 100644 --- a/libcustomext2fs/source/ext2.c +++ b/libcustomext2fs/source/ext2.c @@ -89,7 +89,7 @@ bool ext2Mount(const char *name, const DISC_INTERFACE *interface, sec_t startSec io_chan->private_data = fd; io_chan->flags = flags; - retval = ext2fs_open2(io_chan->name, 0, io_chan->flags, 0, 0, &io_chan, &fs); + retval = ext2fs_open2(io_chan->name, 0, io_chan->flags, 0, 0, io_chan, &fs); if(retval) { ext2_log_trace("error mounting %i\n", (int) retval); @@ -223,7 +223,7 @@ int ext2FindPartitions (const DISC_INTERFACE *interface, sec_t **out_partitions) int i; union { - u8 buffer[512]; + u8 buffer[MAX_SECTOR_SIZE]; MASTER_BOOT_RECORD mbr; EXTENDED_BOOT_RECORD ebr; } sector; @@ -249,27 +249,30 @@ int ext2FindPartitions (const DISC_INTERFACE *interface, sec_t **out_partitions) return 0; } - struct ext2_super_block * super = (struct ext2_super_block *) malloc(SUPERBLOCK_SIZE); //1024 bytes - if(!super) + // Allocate 4 x max sector size in case of 4096 sector size + u8 *buffer = (u8 *) mem_alloc(4 * MAX_SECTOR_SIZE); + if(!buffer) { ext2_log_trace("no memory for superblock"); errno = ENOMEM; return -1; } + // Super is always at offset SUPERBLOCK_OFFSET + struct ext2_super_block * super = (struct ext2_super_block *) (buffer + SUPERBLOCK_OFFSET); //1024 bytes partitions = (sec_t *) malloc(sizeof(sec_t)); if(!partitions) { ext2_log_trace("no memory for partitions"); errno = ENOMEM; - mem_free(super); + mem_free(buffer); return -1; } // Read the first sector on the device if (!interface->readSectors(0, 1, §or.buffer)) { errno = EIO; mem_free(partitions); - mem_free(super); + mem_free(buffer); return -1; } @@ -295,7 +298,7 @@ int ext2FindPartitions (const DISC_INTERFACE *interface, sec_t **out_partitions) case PARTITION_TYPE_LINUX: // Read and validate the EXT partition - if (interface->readSectors(part_lba+SUPERBLOCK_OFFSET/BYTES_PER_SECTOR, SUPERBLOCK_SIZE/BYTES_PER_SECTOR, super)) + if (interface->readSectors(part_lba, 4, buffer)) { if (ext2fs_le16_to_cpu(super->s_magic) == EXT2_SUPER_MAGIC) { @@ -334,7 +337,7 @@ int ext2FindPartitions (const DISC_INTERFACE *interface, sec_t **out_partitions) next_erb_lba = ext2fs_le32_to_cpu(sector.ebr.next_ebr.lba_start); // Check if this partition has a valid EXT boot record - if (interface->readSectors(part_lba+SUPERBLOCK_OFFSET/BYTES_PER_SECTOR, SUPERBLOCK_SIZE/BYTES_PER_SECTOR, super)) + if (interface->readSectors(part_lba, 4, buffer)) { if (ext2fs_le16_to_cpu(super->s_magic) == EXT2_SUPER_MAGIC) { @@ -361,7 +364,7 @@ int ext2FindPartitions (const DISC_INTERFACE *interface, sec_t **out_partitions) { // Check if this partition has a valid EXT boot record anyway, // it might be misrepresented due to a lazy partition editor - if (interface->readSectors(part_lba+SUPERBLOCK_OFFSET/BYTES_PER_SECTOR, SUPERBLOCK_SIZE/BYTES_PER_SECTOR, super)) + if (interface->readSectors(part_lba, 4, buffer)) { if (ext2fs_le16_to_cpu(super->s_magic) == EXT2_SUPER_MAGIC) { @@ -386,7 +389,7 @@ int ext2FindPartitions (const DISC_INTERFACE *interface, sec_t **out_partitions) // As a last-ditched effort, search the first 64 sectors of the device for stray EXT partitions for (i = 1; i < 64; i++) { - if (interface->readSectors(i+SUPERBLOCK_OFFSET/BYTES_PER_SECTOR, SUPERBLOCK_SIZE/BYTES_PER_SECTOR, super)) + if (interface->readSectors(i, 4, buffer)) { if (ext2fs_le16_to_cpu(super->s_magic) == EXT2_SUPER_MAGIC) { @@ -412,8 +415,8 @@ cleanup: if(partitions && partition_count == 0) mem_free(partitions); - if(super) - mem_free(super); + if(buffer) + mem_free(buffer); return ret; } diff --git a/libcustomext2fs/source/ext2_err.c b/libcustomext2fs/source/ext2_err.c new file mode 100644 index 00000000..0b45e958 --- /dev/null +++ b/libcustomext2fs/source/ext2_err.c @@ -0,0 +1,199 @@ +/* + * ext2_err.c: + * This file is automatically generated; please do not edit it. + */ + +#include + +#define N_(a) a + +static const char * const text[] = { + N_( "EXT2FS Library version 1.42-WIP"), + N_( "Wrong magic number for ext2_filsys structure"), + N_( "Wrong magic number for badblocks_list structure"), + N_( "Wrong magic number for badblocks_iterate structure"), + N_( "Wrong magic number for inode_scan structure"), + N_( "Wrong magic number for io_channel structure"), + N_( "Wrong magic number for unix io_channel structure"), + N_( "Wrong magic number for io_manager structure"), + N_( "Wrong magic number for block_bitmap structure"), + N_( "Wrong magic number for inode_bitmap structure"), + N_( "Wrong magic number for generic_bitmap structure"), + N_( "Wrong magic number for test io_channel structure"), + N_( "Wrong magic number for directory block list structure"), + N_( "Wrong magic number for icount structure"), + N_( "Wrong magic number for Powerquest io_channel structure"), + N_( "Wrong magic number for ext2 file structure"), + N_( "Wrong magic number for Ext2 Image Header"), + N_( "Wrong magic number for inode io_channel structure"), + N_( "Wrong magic number for ext4 extent handle"), + N_( "Bad magic number in super-block"), + N_( "Filesystem revision too high"), + N_( "Attempt to write to filesystem opened read-only"), + N_( "Can't read group descriptors"), + N_( "Can't write group descriptors"), + N_( "Corrupt group descriptor: bad block for block bitmap"), + N_( "Corrupt group descriptor: bad block for inode bitmap"), + N_( "Corrupt group descriptor: bad block for inode table"), + N_( "Can't write an inode bitmap"), + N_( "Can't read an inode bitmap"), + N_( "Can't write an block bitmap"), + N_( "Can't read an block bitmap"), + N_( "Can't write an inode table"), + N_( "Can't read an inode table"), + N_( "Can't read next inode"), + N_( "Filesystem has unexpected block size"), + N_( "EXT2 directory corrupted"), + N_( "Attempt to read block from filesystem resulted in short read"), + N_( "Attempt to write block to filesystem resulted in short write"), + N_( "No free space in the directory"), + N_( "Inode bitmap not loaded"), + N_( "Block bitmap not loaded"), + N_( "Illegal inode number"), + N_( "Illegal block number"), + N_( "Internal error in ext2fs_expand_dir"), + N_( "Not enough space to build proposed filesystem"), + N_( "Illegal block number passed to ext2fs_mark_block_bitmap"), + N_( "Illegal block number passed to ext2fs_unmark_block_bitmap"), + N_( "Illegal block number passed to ext2fs_test_block_bitmap"), + N_( "Illegal inode number passed to ext2fs_mark_inode_bitmap"), + N_( "Illegal inode number passed to ext2fs_unmark_inode_bitmap"), + N_( "Illegal inode number passed to ext2fs_test_inode_bitmap"), + N_( "Attempt to fudge end of block bitmap past the real end"), + N_( "Attempt to fudge end of inode bitmap past the real end"), + N_( "Illegal indirect block found" ), + N_( "Illegal doubly indirect block found" ), + N_( "Illegal triply indirect block found" ), + N_( "Block bitmaps are not the same"), + N_( "Inode bitmaps are not the same"), + N_( "Illegal or malformed device name"), + N_( "A block group is missing an inode table"), + N_( "The ext2 superblock is corrupt"), + N_( "Illegal generic bit number passed to ext2fs_mark_generic_bitmap"), + N_( "Illegal generic bit number passed to ext2fs_unmark_generic_bitmap"), + N_( "Illegal generic bit number passed to ext2fs_test_generic_bitmap"), + N_( "Too many symbolic links encountered."), + N_( "The callback function will not handle this case"), + N_( "The inode is from a bad block in the inode table"), + N_( "Filesystem has unsupported feature(s)"), + N_( "Filesystem has unsupported read-only feature(s)"), + N_( "IO Channel failed to seek on read or write"), + N_( "Memory allocation failed"), + N_( "Invalid argument passed to ext2 library"), + N_( "Could not allocate block in ext2 filesystem"), + N_( "Could not allocate inode in ext2 filesystem"), + N_( "Ext2 inode is not a directory"), + N_( "Too many references in table"), + N_( "File not found by ext2_lookup"), + N_( "File open read-only"), + N_( "Ext2 directory block not found"), + N_( "Ext2 directory already exists"), + N_( "Unimplemented ext2 library function"), + N_( "User cancel requested"), + N_( "Ext2 file too big"), + N_( "Supplied journal device not a block device"), + N_( "Journal superblock not found"), + N_( "Journal must be at least 1024 blocks"), + N_( "Unsupported journal version"), + N_( "Error loading external journal"), + N_( "Journal not found"), + N_( "Directory hash unsupported"), + N_( "Illegal extended attribute block number"), + N_( "Cannot create filesystem with requested number of inodes"), + N_( "E2image snapshot not in use"), + N_( "Too many reserved group descriptor blocks"), + N_( "Resize inode is corrupt"), + N_( "Tried to set block bmap with missing indirect block"), + N_( "TDB: Success"), + N_( "TDB: Corrupt database"), + N_( "TDB: IO Error"), + N_( "TDB: Locking error"), + N_( "TDB: Out of memory"), + N_( "TDB: Record exists"), + N_( "TDB: Lock exists on other keys"), + N_( "TDB: Invalid parameter"), + N_( "TDB: Record does not exist"), + N_( "TDB: Write not permitted"), + N_( "Ext2fs directory block list is empty"), + N_( "Attempt to modify a block mapping via a read-only block iterator"), + N_( "Wrong magic number for ext4 extent saved path"), + N_( "Wrong magic number for 64-bit generic bitmap"), + N_( "Wrong magic number for 64-bit block bitmap"), + N_( "Wrong magic number for 64-bit inode bitmap"), + N_( "Wrong magic number --- RESERVED_13"), + N_( "Wrong magic number --- RESERVED_14"), + N_( "Wrong magic number --- RESERVED_15"), + N_( "Wrong magic number --- RESERVED_16"), + N_( "Wrong magic number --- RESERVED_17"), + N_( "Wrong magic number --- RESERVED_18"), + N_( "Wrong magic number --- RESERVED_19"), + N_( "Corrupt extent header"), + N_( "Corrupt extent index"), + N_( "Corrupt extent"), + N_( "No free space in extent map"), + N_( "Inode does not use extents"), + N_( "No 'next' extent"), + N_( "No 'previous' extent"), + N_( "No 'up' extent"), + N_( "No 'down' extent"), + N_( "No current node"), + N_( "Ext2fs operation not supported"), + N_( "No room to insert extent in node"), + N_( "Splitting would result in empty node"), + N_( "Extent not found"), + N_( "Operation not supported for inodes containing extents"), + N_( "Extent length is invalid"), + N_( "I/O Channel does not support 64-bit block numbers"), + N_( "Can't check if filesystem is mounted due to missing mtab file"), + N_( "Filesystem too large to use legacy bitmaps"), + N_( "MMP: invalid magic number"), + N_( "MMP: device currently active"), + N_( "MMP: fsck being run"), + N_( "MMP: block number beyond filesystem range"), + N_( "MMP: undergoing an unknown operation"), + N_( "MMP: filesystem still in use"), + N_( "MMP: open with O_DIRECT failed"), + 0 +}; + +struct error_table { + char const * const * msgs; + long base; + int n_msgs; +}; +struct et_list { + struct et_list *next; + const struct error_table * table; +}; +extern struct et_list *_et_list; + +const struct error_table et_ext2_error_table = { text, 2133571328L, 145 }; + +static struct et_list link = { 0, 0 }; + +void initialize_ext2_error_table_r(struct et_list **list); +void initialize_ext2_error_table(void); + +void initialize_ext2_error_table(void) { + initialize_ext2_error_table_r(&_et_list); +} + +/* For Heimdal compatibility */ +void initialize_ext2_error_table_r(struct et_list **list) +{ + struct et_list *et, **end; + + for (end = list, et = *list; et; end = &et->next, et = et->next) + if (et->table->msgs == text) + return; + et = malloc(sizeof(struct et_list)); + if (et == 0) { + if (!link.table) + et = &link; + else + return; + } + et->table = &et_ext2_error_table; + et->next = 0; + *end = et; +} diff --git a/libcustomext2fs/source/ext2_err.h b/libcustomext2fs/source/ext2_err.h index 4f127443..5d794d2b 100644 --- a/libcustomext2fs/source/ext2_err.h +++ b/libcustomext2fs/source/ext2_err.h @@ -1,152 +1,169 @@ -// -// Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o. -// -// This file may be redistributed under the terms of the GNU Public -// License. +/* + * ext2_err.h: + * This file is automatically generated; please do not edit it. + */ #ifndef EXT2_ERR_H_ #define EXT2_ERR_H_ -#define EXT2_ET_OK 0 -#define EXT2_ET_BASE -1 -#define EXT2_ET_MAGIC_EXT2FS_FILSYS -2 -#define EXT2_ET_MAGIC_BADBLOCKS_LIST -3 -#define EXT2_ET_MAGIC_BADBLOCKS_ITERATE -4 -#define EXT2_ET_MAGIC_INODE_SCAN -5 -#define EXT2_ET_MAGIC_IO_CHANNEL -6 -#define EXT2_ET_MAGIC_UNIX_IO_CHANNEL -7 -#define EXT2_ET_MAGIC_IO_MANAGER -8 -#define EXT2_ET_MAGIC_BLOCK_BITMAP -9 -#define EXT2_ET_MAGIC_INODE_BITMAP -10 -#define EXT2_ET_MAGIC_GENERIC_BITMAP -11 -#define EXT2_ET_MAGIC_TEST_IO_CHANNEL -12 -#define EXT2_ET_MAGIC_DBLIST -13 -#define EXT2_ET_MAGIC_ICOUNT -14 -#define EXT2_ET_MAGIC_PQ_IO_CHANNEL -15 -#define EXT2_ET_MAGIC_EXT2_FILE -16 -#define EXT2_ET_MAGIC_E2IMAGE -17 -#define EXT2_ET_MAGIC_INODE_IO_CHANNEL -18 -#define EXT2_ET_MAGIC_EXTENT_HANDLE -19 -#define EXT2_ET_BAD_MAGIC -20 -#define EXT2_ET_REV_TOO_HIGH -21 -#define EXT2_ET_RO_FILSYS -22 -#define EXT2_ET_GDESC_READ -23 -#define EXT2_ET_GDESC_WRITE -24 -#define EXT2_ET_GDESC_BAD_BLOCK_MAP -25 -#define EXT2_ET_GDESC_BAD_INODE_MAP -26 -#define EXT2_ET_GDESC_BAD_INODE_TABLE -27 -#define EXT2_ET_INODE_BITMAP_WRITE -28 -#define EXT2_ET_INODE_BITMAP_READ -29 -#define EXT2_ET_BLOCK_BITMAP_WRITE -30 -#define EXT2_ET_BLOCK_BITMAP_READ -31 -#define EXT2_ET_INODE_TABLE_WRITE -32 -#define EXT2_ET_INODE_TABLE_READ -33 -#define EXT2_ET_NEXT_INODE_READ -34 -#define EXT2_ET_UNEXPECTED_BLOCK_SIZE -35 -#define EXT2_ET_DIR_CORRUPTED -36 -#define EXT2_ET_SHORT_READ -37 -#define EXT2_ET_SHORT_WRITE -38 -#define EXT2_ET_DIR_NO_SPACE -39 -#define EXT2_ET_NO_INODE_BITMAP -40 -#define EXT2_ET_NO_BLOCK_BITMAP -41 -#define EXT2_ET_BAD_INODE_NUM -42 -#define EXT2_ET_BAD_BLOCK_NUM -45 -#define EXT2_ET_EXPAND_DIR_ERR -46 -#define EXT2_ET_TOOSMALL -47 -#define EXT2_ET_BAD_BLOCK_MARK -48 -#define EXT2_ET_BAD_BLOCK_UNMARK -49 -#define EXT2_ET_BAD_BLOCK_TEST -50 -#define EXT2_ET_BAD_INODE_MARK -51 -#define EXT2_ET_BAD_INODE_UNMARK -52 -#define EXT2_ET_BAD_INODE_TEST -53 -#define EXT2_ET_FUDGE_BLOCK_BITMAP_END -54 -#define EXT2_ET_FUDGE_INODE_BITMAP_END -55 -#define EXT2_ET_BAD_IND_BLOCK -56 -#define EXT2_ET_BAD_DIND_BLOCK -57 -#define EXT2_ET_BAD_TIND_BLOCK -58 -#define EXT2_ET_NEQ_BLOCK_BITMAP -59 -#define EXT2_ET_NEQ_INODE_BITMAP -60 -#define EXT2_ET_BAD_DEVICE_NAME -61 -#define EXT2_ET_MISSING_INODE_TABLE -62 -#define EXT2_ET_CORRUPT_SUPERBLOCK -63 -#define EXT2_ET_BAD_GENERIC_MARK -64 -#define EXT2_ET_BAD_GENERIC_UNMARK -65 -#define EXT2_ET_BAD_GENERIC_TEST -66 -#define EXT2_ET_SYMLINK_LOOP -67 -#define EXT2_ET_CALLBACK_NOTHANDLED -68 -#define EXT2_ET_BAD_BLOCK_IN_INODE_TABLE -69 -#define EXT2_ET_UNSUPP_FEATURE -70 -#define EXT2_ET_RO_UNSUPP_FEATURE -71 -#define EXT2_ET_LLSEEK_FAILED -72 -#define EXT2_ET_NO_MEMORY -73 -#define EXT2_ET_INVALID_ARGUMENT -74 -#define EXT2_ET_BLOCK_ALLOC_FAIL -75 -#define EXT2_ET_INODE_ALLOC_FAIL -76 -#define EXT2_ET_NO_DIRECTORY -77 -#define EXT2_ET_TOO_MANY_REFS -78 -#define EXT2_ET_FILE_NOT_FOUND -79 -#define EXT2_ET_FILE_RO -80 -#define EXT2_ET_DB_NOT_FOUND -81 -#define EXT2_ET_DIR_EXISTS -82 -#define EXT2_ET_UNIMPLEMENTED -83 -#define EXT2_ET_CANCEL_REQUESTED -84 -#define EXT2_ET_FILE_TOO_BIG -85 -#define EXT2_ET_JOURNAL_NOT_BLOCK -86 -#define EXT2_ET_NO_JOURNAL_SB -87 -#define EXT2_ET_JOURNAL_TOO_SMALL -88 -#define EXT2_ET_JOURNAL_UNSUPP_VERSION -89 -#define EXT2_ET_LOAD_EXT_JOURNAL -90 -#define EXT2_ET_NO_JOURNAL -91 -#define EXT2_ET_DIRHASH_UNSUPP -92 -#define EXT2_ET_BAD_EA_BLOCK_NUM -93 -#define EXT2_ET_TOO_MANY_INODES -94 -#define EXT2_ET_NOT_IMAGE_FILE -95 -#define EXT2_ET_RES_GDT_BLOCKS -96 -#define EXT2_ET_RESIZE_INODE_CORRUPT -97 -#define EXT2_ET_SET_BMAP_NO_IND -98 -#define EXT2_ET_TDB_SUCCESS -99 -#define EXT2_ET_TDB_ERR_CORRUPT -100 -#define EXT2_ET_TDB_ERR_IO -101 -#define EXT2_ET_TDB_ERR_LOCK -102 -#define EXT2_ET_TDB_ERR_OOM -103 -#define EXT2_ET_TDB_ERR_EXISTS -104 -#define EXT2_ET_TDB_ERR_NOLOCK -105 -#define EXT2_ET_TDB_ERR_EINVAL -106 -#define EXT2_ET_TDB_ERR_NOEXIST -107 -#define EXT2_ET_TDB_ERR_RDONLY -108 -#define EXT2_ET_DBLIST_EMPTY -109 -#define EXT2_ET_RO_BLOCK_ITERATE -110 -#define EXT2_ET_MAGIC_EXTENT_PATH -111 -#define EXT2_ET_MAGIC_RESERVED_10 -112 -#define EXT2_ET_MAGIC_RESERVED_11 -113 -#define EXT2_ET_MAGIC_RESERVED_12 -114 -#define EXT2_ET_MAGIC_RESERVED_13 -115 -#define EXT2_ET_MAGIC_RESERVED_14 -116 -#define EXT2_ET_MAGIC_RESERVED_15 -117 -#define EXT2_ET_MAGIC_RESERVED_16 -118 -#define EXT2_ET_MAGIC_RESERVED_17 -119 -#define EXT2_ET_MAGIC_RESERVED_18 -120 -#define EXT2_ET_MAGIC_RESERVED_19 -121 -#define EXT2_ET_EXTENT_HEADER_BAD -122 -#define EXT2_ET_EXTENT_INDEX_BAD -123 -#define EXT2_ET_EXTENT_LEAF_BAD -124 -#define EXT2_ET_EXTENT_NO_SPACE -125 -#define EXT2_ET_INODE_NOT_EXTENT -126 -#define EXT2_ET_EXTENT_NO_NEXT -127 -#define EXT2_ET_EXTENT_NO_PREV -128 -#define EXT2_ET_EXTENT_NO_UP -129 -#define EXT2_ET_EXTENT_NO_DOWN -130 -#define EXT2_ET_NO_CURRENT_NODE -131 -#define EXT2_ET_OP_NOT_SUPPORTED -132 -#define EXT2_ET_CANT_INSERT_EXTENT -133 -#define EXT2_ET_CANT_SPLIT_EXTENT -134 -#define EXT2_ET_EXTENT_NOT_FOUND -135 -#define EXT2_ET_EXTENT_NOT_SUPPORTED -136 -#define EXT2_ET_EXTENT_INVALID_LENGTH -137 -#define EXT2_ET_IO_CHANNEL_NO_SUPPORT_64 -138 -#define EXT2_NO_MTAB_FILE -139 -#define EXT2_ET_MAGIC_GENERIC_BITMAP64 -140 -#define EXT2_ET_MAGIC_BLOCK_BITMAP64 -141 -#define EXT2_ET_MAGIC_INODE_BITMAP64 -142 -#define EXT2_ET_CANT_USE_LEGACY_BITMAPS -143 +#include "com_err.h" + +#define EXT2_ET_OK (0) +#define EXT2_ET_BASE (2133571328L) +#define EXT2_ET_MAGIC_EXT2FS_FILSYS (2133571329L) +#define EXT2_ET_MAGIC_BADBLOCKS_LIST (2133571330L) +#define EXT2_ET_MAGIC_BADBLOCKS_ITERATE (2133571331L) +#define EXT2_ET_MAGIC_INODE_SCAN (2133571332L) +#define EXT2_ET_MAGIC_IO_CHANNEL (2133571333L) +#define EXT2_ET_MAGIC_UNIX_IO_CHANNEL (2133571334L) +#define EXT2_ET_MAGIC_IO_MANAGER (2133571335L) +#define EXT2_ET_MAGIC_BLOCK_BITMAP (2133571336L) +#define EXT2_ET_MAGIC_INODE_BITMAP (2133571337L) +#define EXT2_ET_MAGIC_GENERIC_BITMAP (2133571338L) +#define EXT2_ET_MAGIC_TEST_IO_CHANNEL (2133571339L) +#define EXT2_ET_MAGIC_DBLIST (2133571340L) +#define EXT2_ET_MAGIC_ICOUNT (2133571341L) +#define EXT2_ET_MAGIC_PQ_IO_CHANNEL (2133571342L) +#define EXT2_ET_MAGIC_EXT2_FILE (2133571343L) +#define EXT2_ET_MAGIC_E2IMAGE (2133571344L) +#define EXT2_ET_MAGIC_INODE_IO_CHANNEL (2133571345L) +#define EXT2_ET_MAGIC_EXTENT_HANDLE (2133571346L) +#define EXT2_ET_BAD_MAGIC (2133571347L) +#define EXT2_ET_REV_TOO_HIGH (2133571348L) +#define EXT2_ET_RO_FILSYS (2133571349L) +#define EXT2_ET_GDESC_READ (2133571350L) +#define EXT2_ET_GDESC_WRITE (2133571351L) +#define EXT2_ET_GDESC_BAD_BLOCK_MAP (2133571352L) +#define EXT2_ET_GDESC_BAD_INODE_MAP (2133571353L) +#define EXT2_ET_GDESC_BAD_INODE_TABLE (2133571354L) +#define EXT2_ET_INODE_BITMAP_WRITE (2133571355L) +#define EXT2_ET_INODE_BITMAP_READ (2133571356L) +#define EXT2_ET_BLOCK_BITMAP_WRITE (2133571357L) +#define EXT2_ET_BLOCK_BITMAP_READ (2133571358L) +#define EXT2_ET_INODE_TABLE_WRITE (2133571359L) +#define EXT2_ET_INODE_TABLE_READ (2133571360L) +#define EXT2_ET_NEXT_INODE_READ (2133571361L) +#define EXT2_ET_UNEXPECTED_BLOCK_SIZE (2133571362L) +#define EXT2_ET_DIR_CORRUPTED (2133571363L) +#define EXT2_ET_SHORT_READ (2133571364L) +#define EXT2_ET_SHORT_WRITE (2133571365L) +#define EXT2_ET_DIR_NO_SPACE (2133571366L) +#define EXT2_ET_NO_INODE_BITMAP (2133571367L) +#define EXT2_ET_NO_BLOCK_BITMAP (2133571368L) +#define EXT2_ET_BAD_INODE_NUM (2133571369L) +#define EXT2_ET_BAD_BLOCK_NUM (2133571370L) +#define EXT2_ET_EXPAND_DIR_ERR (2133571371L) +#define EXT2_ET_TOOSMALL (2133571372L) +#define EXT2_ET_BAD_BLOCK_MARK (2133571373L) +#define EXT2_ET_BAD_BLOCK_UNMARK (2133571374L) +#define EXT2_ET_BAD_BLOCK_TEST (2133571375L) +#define EXT2_ET_BAD_INODE_MARK (2133571376L) +#define EXT2_ET_BAD_INODE_UNMARK (2133571377L) +#define EXT2_ET_BAD_INODE_TEST (2133571378L) +#define EXT2_ET_FUDGE_BLOCK_BITMAP_END (2133571379L) +#define EXT2_ET_FUDGE_INODE_BITMAP_END (2133571380L) +#define EXT2_ET_BAD_IND_BLOCK (2133571381L) +#define EXT2_ET_BAD_DIND_BLOCK (2133571382L) +#define EXT2_ET_BAD_TIND_BLOCK (2133571383L) +#define EXT2_ET_NEQ_BLOCK_BITMAP (2133571384L) +#define EXT2_ET_NEQ_INODE_BITMAP (2133571385L) +#define EXT2_ET_BAD_DEVICE_NAME (2133571386L) +#define EXT2_ET_MISSING_INODE_TABLE (2133571387L) +#define EXT2_ET_CORRUPT_SUPERBLOCK (2133571388L) +#define EXT2_ET_BAD_GENERIC_MARK (2133571389L) +#define EXT2_ET_BAD_GENERIC_UNMARK (2133571390L) +#define EXT2_ET_BAD_GENERIC_TEST (2133571391L) +#define EXT2_ET_SYMLINK_LOOP (2133571392L) +#define EXT2_ET_CALLBACK_NOTHANDLED (2133571393L) +#define EXT2_ET_BAD_BLOCK_IN_INODE_TABLE (2133571394L) +#define EXT2_ET_UNSUPP_FEATURE (2133571395L) +#define EXT2_ET_RO_UNSUPP_FEATURE (2133571396L) +#define EXT2_ET_LLSEEK_FAILED (2133571397L) +#define EXT2_ET_NO_MEMORY (2133571398L) +#define EXT2_ET_INVALID_ARGUMENT (2133571399L) +#define EXT2_ET_BLOCK_ALLOC_FAIL (2133571400L) +#define EXT2_ET_INODE_ALLOC_FAIL (2133571401L) +#define EXT2_ET_NO_DIRECTORY (2133571402L) +#define EXT2_ET_TOO_MANY_REFS (2133571403L) +#define EXT2_ET_FILE_NOT_FOUND (2133571404L) +#define EXT2_ET_FILE_RO (2133571405L) +#define EXT2_ET_DB_NOT_FOUND (2133571406L) +#define EXT2_ET_DIR_EXISTS (2133571407L) +#define EXT2_ET_UNIMPLEMENTED (2133571408L) +#define EXT2_ET_CANCEL_REQUESTED (2133571409L) +#define EXT2_ET_FILE_TOO_BIG (2133571410L) +#define EXT2_ET_JOURNAL_NOT_BLOCK (2133571411L) +#define EXT2_ET_NO_JOURNAL_SB (2133571412L) +#define EXT2_ET_JOURNAL_TOO_SMALL (2133571413L) +#define EXT2_ET_JOURNAL_UNSUPP_VERSION (2133571414L) +#define EXT2_ET_LOAD_EXT_JOURNAL (2133571415L) +#define EXT2_ET_NO_JOURNAL (2133571416L) +#define EXT2_ET_DIRHASH_UNSUPP (2133571417L) +#define EXT2_ET_BAD_EA_BLOCK_NUM (2133571418L) +#define EXT2_ET_TOO_MANY_INODES (2133571419L) +#define EXT2_ET_NOT_IMAGE_FILE (2133571420L) +#define EXT2_ET_RES_GDT_BLOCKS (2133571421L) +#define EXT2_ET_RESIZE_INODE_CORRUPT (2133571422L) +#define EXT2_ET_SET_BMAP_NO_IND (2133571423L) +#define EXT2_ET_TDB_SUCCESS (2133571424L) +#define EXT2_ET_TDB_ERR_CORRUPT (2133571425L) +#define EXT2_ET_TDB_ERR_IO (2133571426L) +#define EXT2_ET_TDB_ERR_LOCK (2133571427L) +#define EXT2_ET_TDB_ERR_OOM (2133571428L) +#define EXT2_ET_TDB_ERR_EXISTS (2133571429L) +#define EXT2_ET_TDB_ERR_NOLOCK (2133571430L) +#define EXT2_ET_TDB_ERR_EINVAL (2133571431L) +#define EXT2_ET_TDB_ERR_NOEXIST (2133571432L) +#define EXT2_ET_TDB_ERR_RDONLY (2133571433L) +#define EXT2_ET_DBLIST_EMPTY (2133571434L) +#define EXT2_ET_RO_BLOCK_ITERATE (2133571435L) +#define EXT2_ET_MAGIC_EXTENT_PATH (2133571436L) +#define EXT2_ET_MAGIC_GENERIC_BITMAP64 (2133571437L) +#define EXT2_ET_MAGIC_BLOCK_BITMAP64 (2133571438L) +#define EXT2_ET_MAGIC_INODE_BITMAP64 (2133571439L) +#define EXT2_ET_MAGIC_RESERVED_13 (2133571440L) +#define EXT2_ET_MAGIC_RESERVED_14 (2133571441L) +#define EXT2_ET_MAGIC_RESERVED_15 (2133571442L) +#define EXT2_ET_MAGIC_RESERVED_16 (2133571443L) +#define EXT2_ET_MAGIC_RESERVED_17 (2133571444L) +#define EXT2_ET_MAGIC_RESERVED_18 (2133571445L) +#define EXT2_ET_MAGIC_RESERVED_19 (2133571446L) +#define EXT2_ET_EXTENT_HEADER_BAD (2133571447L) +#define EXT2_ET_EXTENT_INDEX_BAD (2133571448L) +#define EXT2_ET_EXTENT_LEAF_BAD (2133571449L) +#define EXT2_ET_EXTENT_NO_SPACE (2133571450L) +#define EXT2_ET_INODE_NOT_EXTENT (2133571451L) +#define EXT2_ET_EXTENT_NO_NEXT (2133571452L) +#define EXT2_ET_EXTENT_NO_PREV (2133571453L) +#define EXT2_ET_EXTENT_NO_UP (2133571454L) +#define EXT2_ET_EXTENT_NO_DOWN (2133571455L) +#define EXT2_ET_NO_CURRENT_NODE (2133571456L) +#define EXT2_ET_OP_NOT_SUPPORTED (2133571457L) +#define EXT2_ET_CANT_INSERT_EXTENT (2133571458L) +#define EXT2_ET_CANT_SPLIT_EXTENT (2133571459L) +#define EXT2_ET_EXTENT_NOT_FOUND (2133571460L) +#define EXT2_ET_EXTENT_NOT_SUPPORTED (2133571461L) +#define EXT2_ET_EXTENT_INVALID_LENGTH (2133571462L) +#define EXT2_ET_IO_CHANNEL_NO_SUPPORT_64 (2133571463L) +#define EXT2_NO_MTAB_FILE (2133571464L) +#define EXT2_ET_CANT_USE_LEGACY_BITMAPS (2133571465L) +#define EXT2_ET_MMP_MAGIC_INVALID (2133571466L) +#define EXT2_ET_MMP_FAILED (2133571467L) +#define EXT2_ET_MMP_FSCK_ON (2133571468L) +#define EXT2_ET_MMP_BAD_BLOCK (2133571469L) +#define EXT2_ET_MMP_UNKNOWN_SEQ (2133571470L) +#define EXT2_ET_MMP_CHANGE_ABORT (2133571471L) +#define EXT2_ET_MMP_OPEN_DIRECT (2133571472L) +extern const struct error_table et_ext2_error_table; +extern void initialize_ext2_error_table(void); + +/* For compatibility with Heimdal */ +extern void initialize_ext2_error_table_r(struct et_list **list); + +#define ERROR_TABLE_BASE_ext2 (2133571328L) + +/* for compatibility with older versions... */ +#define init_ext2_err_tbl initialize_ext2_error_table +#define ext2_err_base ERROR_TABLE_BASE_ext2 #endif + diff --git a/libcustomext2fs/source/ext2_fs.h b/libcustomext2fs/source/ext2_fs.h index 8a58dd10..4d41992c 100644 --- a/libcustomext2fs/source/ext2_fs.h +++ b/libcustomext2fs/source/ext2_fs.h @@ -108,6 +108,18 @@ (s)->s_log_cluster_size) #define EXT2_CLUSTER_SIZE_BITS(s) ((s)->s_log_cluster_size + 10) +/* + * Macro-instructions used to manage fragments + * + * Note: for backwards compatibility only, for the dump program. + * Ext2/3/4 will never support fragments.... + */ +#define EXT2_MIN_FRAG_SIZE EXT2_MIN_BLOCK_SIZE +#define EXT2_MAX_FRAG_SIZE EXT2_MAX_BLOCK_SIZE +#define EXT2_MIN_FRAG_LOG_SIZE EXT2_MIN_BLOCK_LOG_SIZE +#define EXT2_FRAG_SIZE(s) EXT2_BLOCK_SIZE(s) +#define EXT2_FRAGS_PER_BLOCK(s) 1 + /* * ACL structures */ @@ -142,7 +154,9 @@ struct ext2_group_desc __u16 bg_free_inodes_count; /* Free inodes count */ __u16 bg_used_dirs_count; /* Directories count */ __u16 bg_flags; - __u32 bg_reserved[2]; + __u32 bg_exclude_bitmap_lo; /* Exclude bitmap for snapshots */ + __u16 bg_block_bitmap_csum_lo;/* crc32c(s_uuid+grp_num+bitmap) LSB */ + __u16 bg_inode_bitmap_csum_lo;/* crc32c(s_uuid+grp_num+bitmap) LSB */ __u16 bg_itable_unused; /* Unused inodes count */ __u16 bg_checksum; /* crc16(s_uuid+grouo_num+group_desc)*/ }; @@ -159,7 +173,9 @@ struct ext4_group_desc __u16 bg_free_inodes_count; /* Free inodes count */ __u16 bg_used_dirs_count; /* Directories count */ __u16 bg_flags; /* EXT4_BG_flags (INODE_UNINIT, etc) */ - __u32 bg_reserved[2]; /* Likely block/inode bitmap checksum */ + __u32 bg_exclude_bitmap_lo; /* Exclude bitmap for snapshots */ + __u16 bg_block_bitmap_csum_lo;/* crc32c(s_uuid+grp_num+bitmap) LSB */ + __u16 bg_inode_bitmap_csum_lo;/* crc32c(s_uuid+grp_num+bitmap) LSB */ __u16 bg_itable_unused; /* Unused inodes count */ __u16 bg_checksum; /* crc16(sb_uuid+group+desc) */ __u32 bg_block_bitmap_hi; /* Blocks bitmap block MSB */ @@ -169,7 +185,10 @@ struct ext4_group_desc __u16 bg_free_inodes_count_hi;/* Free inodes count MSB */ __u16 bg_used_dirs_count_hi; /* Directories count MSB */ __u16 bg_itable_unused_hi; /* Unused inodes count MSB */ - __u32 bg_reserved2[3]; + __u32 bg_exclude_bitmap_hi; /* Exclude bitmap block MSB */ + __u16 bg_block_bitmap_csum_hi;/* crc32c(s_uuid+grp_num+bitmap) MSB */ + __u16 bg_inode_bitmap_csum_hi;/* crc32c(s_uuid+grp_num+bitmap) MSB */ + __u32 bg_reserved; }; #define EXT2_BG_INODE_UNINIT 0x0001 /* Inode table/bitmap not initialized */ @@ -228,10 +247,15 @@ struct ext2_dx_countlimit { #define EXT2_BLOCKS_PER_GROUP(s) (EXT2_SB(s)->s_blocks_per_group) #define EXT2_INODES_PER_GROUP(s) (EXT2_SB(s)->s_inodes_per_group) +#define EXT2_CLUSTERS_PER_GROUP(s) (EXT2_SB(s)->s_clusters_per_group) #define EXT2_INODES_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s)/EXT2_INODE_SIZE(s)) /* limits imposed by 16-bit value gd_free_{blocks,inode}_count */ -#define EXT2_MAX_BLOCKS_PER_GROUP(s) ((1 << 16) - 8) -#define EXT2_MAX_INODES_PER_GROUP(s) ((1 << 16) - EXT2_INODES_PER_BLOCK(s)) +#define EXT2_MAX_BLOCKS_PER_GROUP(s) ((((unsigned) 1 << 16) - 8) * \ + (EXT2_CLUSTER_SIZE(s) / \ + EXT2_BLOCK_SIZE(s))) +#define EXT2_MAX_CLUSTERS_PER_GROUP(s) (((unsigned) 1 << 16) - 8) +#define EXT2_MAX_INODES_PER_GROUP(s) (((unsigned) 1 << 16) - \ + EXT2_INODES_PER_BLOCK(s)) #ifdef __KERNEL__ #define EXT2_DESC_PER_BLOCK(s) (EXT2_SB(s)->s_desc_per_block) #define EXT2_DESC_PER_BLOCK_BITS(s) (EXT2_SB(s)->s_desc_per_block_bits) @@ -322,6 +346,7 @@ struct ext4_new_group_input { #define EXT2_IOC_GROUP_EXTEND _IOW('f', 7, unsigned long) #define EXT2_IOC_GROUP_ADD _IOW('f', 8,struct ext2_new_group_input) #define EXT4_IOC_GROUP_ADD _IOW('f', 8,struct ext4_new_group_input) +#define EXT4_IOC_RESIZE_FS _IOW('f', 16, __u64) /* * Structure of an inode on the disk @@ -357,7 +382,8 @@ struct ext2_inode { __u16 l_i_file_acl_high; __u16 l_i_uid_high; /* these 2 fields */ __u16 l_i_gid_high; /* were reserved2[0] */ - __u32 l_i_reserved2; + __u16 l_i_checksum_lo; /* crc32c(uuid+inum+inode) */ + __u16 l_i_reserved; } linux2; struct { __u8 h_i_frag; /* Fragment number */ @@ -404,7 +430,8 @@ struct ext2_inode_large { __u16 l_i_file_acl_high; __u16 l_i_uid_high; /* these 2 fields */ __u16 l_i_gid_high; /* were reserved2[0] */ - __u32 l_i_reserved2; + __u16 l_i_checksum_lo; /* crc32c(uuid+inum+inode) */ + __u16 l_i_reserved; } linux2; struct { __u8 h_i_frag; /* Fragment number */ @@ -416,7 +443,7 @@ struct ext2_inode_large { } hurd2; } osd2; /* OS dependent 2 */ __u16 i_extra_isize; - __u16 i_pad1; + __u16 i_checksum_hi; /* crc32c(uuid+inum+inode) */ __u32 i_ctime_extra; /* extra Change time (nsec << 2 | epoch) */ __u32 i_mtime_extra; /* extra Modification time (nsec << 2 | epoch) */ __u32 i_atime_extra; /* extra Access time (nsec << 2 | epoch) */ @@ -435,7 +462,6 @@ struct ext2_inode_large { #define i_gid_low i_gid #define i_uid_high osd2.linux2.l_i_uid_high #define i_gid_high osd2.linux2.l_i_gid_high -#define i_reserved2 osd2.linux2.l_i_reserved2 #else #if defined(__GNU__) @@ -588,7 +614,7 @@ struct ext2_super_block { __u16 s_want_extra_isize; /* New inodes should reserve # bytes */ __u32 s_flags; /* Miscellaneous flags */ __u16 s_raid_stride; /* RAID stride */ - __u16 s_mmp_interval; /* # seconds to wait in MMP checking */ + __u16 s_mmp_update_interval; /* # seconds to wait in MMP checking */ __u64 s_mmp_block; /* Block for multi-mount protection */ __u32 s_raid_stripe_width; /* blocks on all data disks (N*stride)*/ __u8 s_log_groups_per_flex; /* FLEX_BG group size */ @@ -617,7 +643,8 @@ struct ext2_super_block { __u32 s_usr_quota_inum; /* inode number of user quota file */ __u32 s_grp_quota_inum; /* inode number of group quota file */ __u32 s_overhead_blocks; /* overhead blocks/clusters in fs */ - __u32 s_reserved[109]; /* Padding to the end of the block */ + __u32 s_reserved[108]; /* Padding to the end of the block */ + __u32 s_checksum; /* crc32c(superblock) */ }; #define EXT4_S_ERR_LEN (EXT4_S_ERR_END - EXT4_S_ERR_START) @@ -665,7 +692,9 @@ struct ext2_super_block { #define EXT2_FEATURE_COMPAT_RESIZE_INODE 0x0010 #define EXT2_FEATURE_COMPAT_DIR_INDEX 0x0020 #define EXT2_FEATURE_COMPAT_LAZY_BG 0x0040 -#define EXT2_FEATURE_COMPAT_EXCLUDE_INODE 0x0080 +/* #define EXT2_FEATURE_COMPAT_EXCLUDE_INODE 0x0080 not used, legacy */ +#define EXT2_FEATURE_COMPAT_EXCLUDE_BITMAP 0x0100 + #define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001 #define EXT2_FEATURE_RO_COMPAT_LARGE_FILE 0x0002 @@ -677,6 +706,7 @@ struct ext2_super_block { #define EXT4_FEATURE_RO_COMPAT_HAS_SNAPSHOT 0x0080 #define EXT4_FEATURE_RO_COMPAT_QUOTA 0x0100 #define EXT4_FEATURE_RO_COMPAT_BIGALLOC 0x0200 +#define EXT4_FEATURE_RO_COMPAT_METADATA_CSUM 0x0400 #define EXT2_FEATURE_INCOMPAT_COMPRESSION 0x0001 #define EXT2_FEATURE_INCOMPAT_FILETYPE 0x0002 @@ -691,7 +721,8 @@ struct ext2_super_block { #define EXT4_FEATURE_INCOMPAT_DIRDATA 0x1000 #define EXT2_FEATURE_COMPAT_SUPP 0 -#define EXT2_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE) +#define EXT2_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE| \ + EXT4_FEATURE_INCOMPAT_MMP) #define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \ EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \ EXT4_FEATURE_RO_COMPAT_DIR_NLINK| \ @@ -772,28 +803,52 @@ struct ext2_dir_entry_2 { ~EXT2_DIR_ROUND) /* - * This structure will be used for multiple mount protection. It will be - * written into the block number saved in the s_mmp_block field in the - * superblock. + * This structure is used for multiple mount protection. It is written + * into the block number saved in the s_mmp_block field in the superblock. + * Programs that check MMP should assume that if SEQ_FSCK (or any unknown + * code above SEQ_MAX) is present then it is NOT safe to use the filesystem, + * regardless of how old the timestamp is. + * + * The timestamp in the MMP structure will be updated by e2fsck at some + * arbitary intervals (start of passes, after every few groups of inodes + * in pass1 and pass1b). There is no guarantee that e2fsck is updating + * the MMP block in a timely manner, and the updates it does are purely + * for the convenience of the sysadmin and not for automatic validation. + * + * Note: Only the mmp_seq value is used to determine whether the MMP block + * is being updated. The mmp_time, mmp_nodename, and mmp_bdevname + * fields are only for informational purposes for the administrator, + * due to clock skew between nodes and hostname HA service takeover. */ -#define EXT2_MMP_MAGIC 0x004D4D50 /* ASCII for MMP */ -#define EXT2_MMP_CLEAN 0xFF4D4D50 /* Value of mmp_seq for clean unmount */ -#define EXT2_MMP_FSCK_ON 0xE24D4D50 /* Value of mmp_seq when being fscked */ +#define EXT4_MMP_MAGIC 0x004D4D50U /* ASCII for MMP */ +#define EXT4_MMP_SEQ_CLEAN 0xFF4D4D50U /* mmp_seq value for clean unmount */ +#define EXT4_MMP_SEQ_FSCK 0xE24D4D50U /* mmp_seq value when being fscked */ +#define EXT4_MMP_SEQ_MAX 0xE24D4D4FU /* maximum valid mmp_seq value */ struct mmp_struct { - __u32 mmp_magic; - __u32 mmp_seq; - __u64 mmp_time; - char mmp_nodename[64]; - char mmp_bdevname[32]; - __u16 mmp_interval; + __u32 mmp_magic; /* Magic number for MMP */ + __u32 mmp_seq; /* Sequence no. updated periodically */ + __u64 mmp_time; /* Time last updated */ + char mmp_nodename[64]; /* Node which last updated MMP block */ + char mmp_bdevname[32]; /* Bdev which last updated MMP block */ + __u16 mmp_check_interval; /* Changed mmp_check_interval */ __u16 mmp_pad1; - __u32 mmp_pad2; + __u32 mmp_pad2[227]; }; /* - * Interval in number of seconds to update the MMP sequence number. + * Default interval for MMP update in seconds. */ -#define EXT2_MMP_DEF_INTERVAL 5 +#define EXT4_MMP_UPDATE_INTERVAL 5 + +/* + * Maximum interval for MMP update in seconds. + */ +#define EXT4_MMP_MAX_UPDATE_INTERVAL 300 + +/* + * Minimum interval for MMP checking in seconds. + */ +#define EXT4_MMP_MIN_CHECK_INTERVAL 5 #endif /* _LINUX_EXT2_FS_H */ diff --git a/libcustomext2fs/source/ext2_internal.c b/libcustomext2fs/source/ext2_internal.c index d75133a7..ddb5f2a4 100644 --- a/libcustomext2fs/source/ext2_internal.c +++ b/libcustomext2fs/source/ext2_internal.c @@ -249,7 +249,7 @@ static ext2_ino_t ext2PathToInode(ext2_vd *vd, const char * path) filename[i] = '\0'; - errorcode = ext2fs_namei(vd->fs, vd->root, parent, filename, &ino); + errorcode = ext2fs_namei_follow(vd->fs, vd->root, parent, filename, &ino); if(errorcode != EXT2_ET_OK) return 0; @@ -389,7 +389,7 @@ static ext2_ino_t ext2CreateSymlink(ext2_vd *vd, const char *path, const char * if (!err) { inode.i_block[0] = blk; - inode.i_blocks = vd->fs->blocksize / BYTES_PER_SECTOR; + inode.i_blocks = vd->fs->blocksize / 512; vd->fs->io->manager->write_blk(vd->fs->io, blk, 1, buffer); ext2fs_block_alloc_stats(vd->fs, blk, +1); } diff --git a/libcustomext2fs/source/ext2_io.h b/libcustomext2fs/source/ext2_io.h index 9f84d996..289a34f9 100644 --- a/libcustomext2fs/source/ext2_io.h +++ b/libcustomext2fs/source/ext2_io.h @@ -26,8 +26,9 @@ typedef struct struct_io_manager *io_manager; typedef struct struct_io_channel *io_channel; typedef struct struct_io_stats *io_stats; -#define CHANNEL_FLAGS_WRITETHROUGH 0x01 +#define CHANNEL_FLAGS_WRITETHROUGH 0x01 #define CHANNEL_FLAGS_DISCARD_ZEROES 0x02 +#define CHANNEL_FLAGS_BLOCK_DEVICE 0x04 #define io_channel_discard_zeroes_data(i) (i->flags & CHANNEL_FLAGS_DISCARD_ZEROES) diff --git a/libcustomext2fs/source/ext2_types.h b/libcustomext2fs/source/ext2_types.h index 5f5f7a57..0912c4bc 100644 --- a/libcustomext2fs/source/ext2_types.h +++ b/libcustomext2fs/source/ext2_types.h @@ -1,18 +1,143 @@ -/* +/* * If linux/types.h is already been included, assume it has defined - * everything we need. (cross fingers) Other header files may have + * everything we need. (cross fingers) Other header files may have * also defined the types that we need. */ #ifndef _EXT2_TYPES_H #define _EXT2_TYPES_H -typedef unsigned char __u8; -typedef signed char __s8; -typedef unsigned short __u16; -typedef short __s16; -typedef unsigned int __u32; -typedef int __s32; -typedef unsigned long long __u64; -typedef signed long long __s64; +#define __S8_TYPEDEF __signed__ char +#define __U8_TYPEDEF unsigned char +#define __S16_TYPEDEF __signed__ short +#define __U16_TYPEDEF unsigned short +#define __S32_TYPEDEF __signed__ int +#define __U32_TYPEDEF unsigned int +#define __S64_TYPEDEF __signed__ long long +#define __U64_TYPEDEF unsigned long long -#endif /* _EXT2_TYPES_H */ +#ifdef __U8_TYPEDEF +typedef __U8_TYPEDEF __u8; +#else +typedef unsigned char __u8; +#endif + +#ifdef __S8_TYPEDEF +typedef __S8_TYPEDEF __s8; +#else +typedef signed char __s8; +#endif + +#ifdef __U16_TYPEDEF +typedef __U16_TYPEDEF __u16; +#else +#if (4 == 2) +typedef unsigned int __u16; +#else +#if (2 == 2) +typedef unsigned short __u16; +#else + ?==error: undefined 16 bit type +#endif /* SIZEOF_SHORT == 2 */ +#endif /* SIZEOF_INT == 2 */ +#endif /* __U16_TYPEDEF */ + +#ifdef __S16_TYPEDEF +typedef __S16_TYPEDEF __s16; +#else +#if (4 == 2) +typedef int __s16; +#else +#if (2 == 2) +typedef short __s16; +#else + ?==error: undefined 16 bit type +#endif /* SIZEOF_SHORT == 2 */ +#endif /* SIZEOF_INT == 2 */ +#endif /* __S16_TYPEDEF */ + + +#ifdef __U32_TYPEDEF +typedef __U32_TYPEDEF __u32; +#else +#if (4 == 4) +typedef unsigned int __u32; +#else +#if (4 == 4) +typedef unsigned long __u32; +#else +#if (2 == 4) +typedef unsigned short __u32; +#else + ?== error: undefined 32 bit type +#endif /* SIZEOF_SHORT == 4 */ +#endif /* SIZEOF_LONG == 4 */ +#endif /* SIZEOF_INT == 4 */ +#endif /* __U32_TYPEDEF */ + +#ifdef __S32_TYPEDEF +typedef __S32_TYPEDEF __s32; +#else +#if (4 == 4) +typedef int __s32; +#else +#if (4 == 4) +typedef long __s32; +#else +#if (2 == 4) +typedef short __s32; +#else + ?== error: undefined 32 bit type +#endif /* SIZEOF_SHORT == 4 */ +#endif /* SIZEOF_LONG == 4 */ +#endif /* SIZEOF_INT == 4 */ +#endif /* __S32_TYPEDEF */ + +#ifdef __U64_TYPEDEF +typedef __U64_TYPEDEF __u64; +#else +#if (4 == 8) +typedef unsigned int __u64; +#else +#if (4 == 8) +typedef unsigned long __u64; +#else +#if (8 == 8) +typedef unsigned long long __u64; +#endif /* SIZEOF_LONG_LONG == 8 */ +#endif /* SIZEOF_LONG == 8 */ +#endif /* SIZEOF_INT == 8 */ +#endif /* __U64_TYPEDEF */ + +#ifdef __S64_TYPEDEF +typedef __S64_TYPEDEF __s64; +#else +#if (4 == 8) +typedef int __s64; +#else +#if (4 == 8) +typedef long __s64; +#else +#if (8 == 8) +#if defined(__GNUC__) +typedef __signed__ long long __s64; +#else +typedef signed long long __s64; +#endif /* __GNUC__ */ +#endif /* SIZEOF_LONG_LONG == 8 */ +#endif /* SIZEOF_LONG == 8 */ +#endif /* SIZEOF_INT == 8 */ +#endif /* __S64_TYPEDEF */ + +#undef __S8_TYPEDEF +#undef __U8_TYPEDEF +#undef __S16_TYPEDEF +#undef __U16_TYPEDEF +#undef __S32_TYPEDEF +#undef __U32_TYPEDEF +#undef __S64_TYPEDEF +#undef __U64_TYPEDEF + +#endif /* _*_TYPES_H */ + +/* These defines are needed for the public ext2fs.h header file */ +#define HAVE_SYS_TYPES_H 1 diff --git a/libcustomext2fs/source/ext2file.c b/libcustomext2fs/source/ext2file.c index 6647466f..f2b77c19 100644 --- a/libcustomext2fs/source/ext2file.c +++ b/libcustomext2fs/source/ext2file.c @@ -41,11 +41,7 @@ void ext2CloseFile (ext2_file_state *file) // Sync the file (and its attributes) to disc if(file->write) - { - // Read in node changes before writing them - ext2fs_read_inode(file->vd->fs, file->ni->ino, &file->ni->ni); ext2UpdateTimes(file->vd, file->ni, EXT2_UPDATE_ACTIME); - } if (file->read) ext2UpdateTimes(file->vd, file->ni, EXT2_UPDATE_ATIME); @@ -243,11 +239,25 @@ ssize_t ext2_write_r (struct _reent *r, int fd, const char *ptr, size_t len) // Lock ext2Lock(file->vd); - u32 writen = 0; + errcode_t err = 0; + u32 written = 0; // Write to the files data atrribute - errcode_t err = ext2fs_file_write(file->fd, ptr, len, &writen); - if (writen <= 0 || err) { + while (len > 0) + { + u32 wrote = 0; + + err = ext2fs_file_write(file->fd, ptr, len, &wrote); + if (err) + break; + + len -= wrote; + ptr += wrote; + written += wrote; + } + + // Check for errors + if (err) { ext2Unlock(file->vd); r->_errno = errno; return (err ? err : -1); @@ -256,7 +266,7 @@ ssize_t ext2_write_r (struct _reent *r, int fd, const char *ptr, size_t len) // Unlock ext2Unlock(file->vd); - return (writen == 0 ? -1 : writen); + return (written == 0 ? -1 : written); } ssize_t ext2_read_r (struct _reent *r, int fd, char *ptr, size_t len) diff --git a/libcustomext2fs/source/ext2fs.h b/libcustomext2fs/source/ext2fs.h index 7016486c..703ff0c7 100644 --- a/libcustomext2fs/source/ext2fs.h +++ b/libcustomext2fs/source/ext2fs.h @@ -29,6 +29,10 @@ extern "C" { #define NO_INLINE_FUNCS #endif +#ifndef _XOPEN_SOURCE +#define _XOPEN_SOURCE 600 /* for posix_memalign() */ +#endif + /* * Where the master copy of the superblock is located, and how big * superblocks are supposed to be. We define SUPERBLOCK_SIZE because @@ -37,7 +41,7 @@ extern "C" { * 1032 bytes long). */ #define SUPERBLOCK_OFFSET 1024 -#define SUPERBLOCK_SIZE 1024 +#define SUPERBLOCK_SIZE 1024 /* * The last ext2fs revision level that this version of the library is @@ -53,9 +57,18 @@ extern "C" { #include #include #include +#include +#include +#include + +#ifndef __USE_XOPEN2K +/* If the "#define _XOPEN_SOURCE 600" didn't succeed in declaring + * posix_memalign(), maybe due to or included beforej + * _XOPEN_SOURCE, declare it here to avoid compiler warnings. */ +extern int posix_memalign(void **__memptr, size_t __alignment, size_t __size); +#endif #include "ext2_types.h" -#include "com_err.h" #include "ext2_fs.h" #include "ext3_extents.h" @@ -68,6 +81,7 @@ typedef __u64 ext2_off64_t; typedef __s64 e2_blkcnt_t; typedef __u32 ext2_dirhash_t; +#include "com_err.h" #include "ext2_io.h" #include "ext2_err.h" #include "ext2_ext_attr.h" @@ -171,6 +185,7 @@ typedef struct ext2_file *ext2_file_t; #define EXT2_FLAG_64BITS 0x20000 #define EXT2_FLAG_PRINT_PROGRESS 0x40000 #define EXT2_FLAG_DIRECT_IO 0x80000 +#define EXT2_FLAG_SKIP_MMP 0x100000 /* * Special flag in the ext2 inode i_flag field that means that this is @@ -180,10 +195,9 @@ typedef struct ext2_file *ext2_file_t; /* * Flags for mkjournal - * - * EXT2_MKJOURNAL_V1_SUPER Make a (deprecated) V1 journal superblock */ -#define EXT2_MKJOURNAL_V1_SUPER 0x0000001 +#define EXT2_MKJOURNAL_V1_SUPER 0x0000001 /* create V1 superblock (deprecated) */ +#define EXT2_MKJOURNAL_LAZYINIT 0x0000002 /* don't zero journal inode before use*/ struct opaque_ext2_group_desc; @@ -194,11 +208,11 @@ struct struct_ext2_filsys { char * device_name; struct ext2_super_block * super; unsigned int blocksize; - int clustersize; + int fragsize; dgrp_t group_desc_count; unsigned long desc_blocks; struct opaque_ext2_group_desc * group_desc; - int inode_blocks_per_group; + unsigned int inode_blocks_per_group; ext2fs_inode_bitmap inode_map; ext2fs_block_bitmap block_map; /* XXX FIXME-64: not 64-bit safe, but not used? */ @@ -216,10 +230,11 @@ struct struct_ext2_filsys { struct ext2_image_hdr * image_header; __u32 umask; time_t now; + int cluster_ratio_bits; /* * Reserved for future expansion */ - __u32 reserved[7]; + __u32 reserved[6]; /* * Reserved for the use of the calling application. @@ -232,6 +247,18 @@ struct struct_ext2_filsys { struct ext2_inode_cache *icache; io_channel image_io; + /* + * Buffers for Multiple mount protection(MMP) block. + */ + void *mmp_buf; + void *mmp_cmp; + int mmp_fd; + + /* + * Time at which e2fsck last updated the MMP block. + */ + long mmp_last_written; + /* * More callback functions */ @@ -519,6 +546,7 @@ typedef struct ext2_icount *ext2_icount_t; EXT3_FEATURE_INCOMPAT_RECOVER|\ EXT3_FEATURE_INCOMPAT_EXTENTS|\ EXT4_FEATURE_INCOMPAT_FLEX_BG|\ + EXT4_FEATURE_INCOMPAT_MMP|\ EXT4_FEATURE_INCOMPAT_64BIT) #else #define EXT2_LIB_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE|\ @@ -527,6 +555,7 @@ typedef struct ext2_icount *ext2_icount_t; EXT3_FEATURE_INCOMPAT_RECOVER|\ EXT3_FEATURE_INCOMPAT_EXTENTS|\ EXT4_FEATURE_INCOMPAT_FLEX_BG|\ + EXT4_FEATURE_INCOMPAT_MMP|\ EXT4_FEATURE_INCOMPAT_64BIT) #endif #define EXT2_LIB_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\ @@ -534,7 +563,9 @@ typedef struct ext2_icount *ext2_icount_t; EXT2_FEATURE_RO_COMPAT_LARGE_FILE|\ EXT4_FEATURE_RO_COMPAT_DIR_NLINK|\ EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE|\ - EXT4_FEATURE_RO_COMPAT_GDT_CSUM) + EXT4_FEATURE_RO_COMPAT_GDT_CSUM|\ + EXT4_FEATURE_RO_COMPAT_BIGALLOC|\ + EXT4_FEATURE_RO_COMPAT_QUOTA) /* * These features are only allowed if EXT2_FLAG_SOFTSUPP_FEATURES is passed @@ -543,6 +574,29 @@ typedef struct ext2_icount *ext2_icount_t; #define EXT2_LIB_SOFTSUPP_INCOMPAT (0) #define EXT2_LIB_SOFTSUPP_RO_COMPAT (EXT4_FEATURE_RO_COMPAT_BIGALLOC) + +/* Translate a block number to a cluster number */ +#define EXT2FS_CLUSTER_RATIO(fs) (1 << (fs)->cluster_ratio_bits) +#define EXT2FS_CLUSTER_MASK(fs) (EXT2FS_CLUSTER_RATIO(fs) - 1) +#define EXT2FS_B2C(fs, blk) ((blk) >> (fs)->cluster_ratio_bits) +/* Translate a cluster number to a block number */ +#define EXT2FS_C2B(fs, cluster) ((cluster) << (fs)->cluster_ratio_bits) +/* Translate # of blks to # of clusters */ +#define EXT2FS_NUM_B2C(fs, blks) (((blks) + EXT2FS_CLUSTER_MASK(fs)) >> \ + (fs)->cluster_ratio_bits) + +#if defined(HAVE_STAT64) && !defined(__OSX_AVAILABLE_BUT_DEPRECATED) +typedef struct stat64 ext2fs_struct_stat; +#else +typedef struct stat ext2fs_struct_stat; +#endif + +/* + * For ext2fs_close2() and ext2fs_flush2(), this flag allows you to + * avoid the fsync call. + */ +#define EXT2_FLAG_FLUSH_NO_SYNC 1 + /* * function prototypes */ @@ -656,6 +710,10 @@ extern errcode_t ext2fs_read_block_bitmap(ext2_filsys fs); extern errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs, const char *descr, ext2fs_block_bitmap *ret); +extern errcode_t ext2fs_allocate_subcluster_bitmap(ext2_filsys fs, + const char *descr, + ext2fs_block_bitmap *ret); +extern int ext2fs_get_bitmap_granularity(ext2fs_block_bitmap bitmap); extern errcode_t ext2fs_allocate_inode_bitmap(ext2_filsys fs, const char *descr, ext2fs_inode_bitmap *ret); @@ -712,6 +770,7 @@ extern errcode_t ext2fs_get_block_bitmap_range2(ext2fs_block_bitmap bmap, extern dgrp_t ext2fs_group_of_blk2(ext2_filsys fs, blk64_t); extern blk64_t ext2fs_group_first_block2(ext2_filsys fs, dgrp_t group); extern blk64_t ext2fs_group_last_block2(ext2_filsys fs, dgrp_t group); +extern int ext2fs_group_blocks_count(ext2_filsys fs, dgrp_t group); extern blk64_t ext2fs_inode_data_blocks2(ext2_filsys fs, struct ext2_inode *inode); extern blk64_t ext2fs_inode_i_blocks(ext2_filsys fs, @@ -763,8 +822,10 @@ extern void ext2fs_bg_flags_set(ext2_filsys fs, dgrp_t group, __u16 bg_flags); extern void ext2fs_bg_flags_clear(ext2_filsys fs, dgrp_t group, __u16 bg_flags); extern __u16 ext2fs_bg_checksum(ext2_filsys fs, dgrp_t group); extern void ext2fs_bg_checksum_set(ext2_filsys fs, dgrp_t group, __u16 checksum); -extern blk64_t ext2fs_file_acl_block(const struct ext2_inode *inode); -extern void ext2fs_file_acl_block_set(struct ext2_inode *inode, blk64_t blk); +extern blk64_t ext2fs_file_acl_block(ext2_filsys fs, + const struct ext2_inode *inode); +extern void ext2fs_file_acl_block_set(ext2_filsys fs, + struct ext2_inode *inode, blk64_t blk); /* block.c */ extern errcode_t ext2fs_block_iterate(ext2_filsys fs, @@ -822,7 +883,9 @@ extern errcode_t ext2fs_check_desc(ext2_filsys fs); /* closefs.c */ extern errcode_t ext2fs_close(ext2_filsys fs); +extern errcode_t ext2fs_close2(ext2_filsys fs, int flags); extern errcode_t ext2fs_flush(ext2_filsys fs); +extern errcode_t ext2fs_flush2(ext2_filsys fs, int flags); extern int ext2fs_bg_has_super(ext2_filsys fs, int group_block); extern errcode_t ext2fs_super_and_bgd_loc2(ext2_filsys fs, dgrp_t group, @@ -838,6 +901,10 @@ extern int ext2fs_super_and_bgd_loc(ext2_filsys fs, int *ret_meta_bg); extern void ext2fs_update_dynamic_rev(ext2_filsys fs); +/* crc32c.c */ +extern __u32 ext2fs_crc32c_be(__u32 crc, unsigned char const *p, size_t len); +extern __u32 ext2fs_crc32c_le(__u32 crc, unsigned char const *p, size_t len); + /* csum.c */ extern void ext2fs_group_desc_csum_set(ext2_filsys fs, dgrp_t group); extern int ext2fs_group_desc_csum_verify(ext2_filsys fs, dgrp_t group); @@ -1088,6 +1155,8 @@ errcode_t ext2fs_get_generic_bmap_range(ext2fs_generic_bitmap bmap, errcode_t ext2fs_set_generic_bmap_range(ext2fs_generic_bitmap bmap, __u64 start, unsigned int num, void *in); +errcode_t ext2fs_convert_subcluster_bitmap(ext2_filsys fs, + ext2fs_block_bitmap *bitmap); /* getsize.c */ extern errcode_t ext2fs_get_device_size(const char *file, int blocksize, @@ -1227,21 +1296,21 @@ extern errcode_t ext2fs_zero_blocks(ext2_filsys fs, blk_t blk, int num, extern errcode_t ext2fs_zero_blocks2(ext2_filsys fs, blk64_t blk, int num, blk64_t *ret_blk, int *ret_count); extern errcode_t ext2fs_create_journal_superblock(ext2_filsys fs, - __u32 size, int flags, + __u32 num_blocks, int flags, char **ret_jsb); extern errcode_t ext2fs_add_journal_device(ext2_filsys fs, ext2_filsys journal_dev); -extern errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t size, +extern errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t num_blocks, int flags); -extern int ext2fs_default_journal_size(__u64 blocks); +extern int ext2fs_default_journal_size(__u64 num_blocks); /* openfs.c */ extern errcode_t ext2fs_open(const char *name, int flags, int superblock, - unsigned int block_size, io_channel * chan, + unsigned int block_size, io_channel chan, ext2_filsys *ret_fs); extern errcode_t ext2fs_open2(const char *name, const char *io_options, int flags, int superblock, - unsigned int block_size, io_channel * chan, + unsigned int block_size, io_channel chan, ext2_filsys *ret_fs); extern blk64_t ext2fs_descriptor_block_loc2(ext2_filsys fs, blk64_t group_block, dgrp_t i); @@ -1261,6 +1330,16 @@ errcode_t ext2fs_link(ext2_filsys fs, ext2_ino_t dir, const char *name, errcode_t ext2fs_unlink(ext2_filsys fs, ext2_ino_t dir, const char *name, ext2_ino_t ino, int flags); +/* mmp.c */ +errcode_t ext2fs_mmp_read(ext2_filsys fs, blk64_t mmp_blk, void *buf); +errcode_t ext2fs_mmp_write(ext2_filsys fs, blk64_t mmp_blk, void *buf); +errcode_t ext2fs_mmp_clear(ext2_filsys fs); +errcode_t ext2fs_mmp_init(ext2_filsys fs); +errcode_t ext2fs_mmp_start(ext2_filsys fs); +errcode_t ext2fs_mmp_update(ext2_filsys fs); +errcode_t ext2fs_mmp_stop(ext2_filsys fs); +unsigned ext2fs_mmp_new_seq(void); + /* read_bb.c */ extern errcode_t ext2fs_read_bb_inode(ext2_filsys fs, ext2_badblocks_list *bb_list); @@ -1296,9 +1375,12 @@ extern void ext2fs_swap_inode_full(ext2_filsys fs, struct ext2_inode_large *t, int bufsize); extern void ext2fs_swap_inode(ext2_filsys fs,struct ext2_inode *t, struct ext2_inode *f, int hostorder); +extern void ext2fs_swap_mmp(struct mmp_struct *mmp); /* valid_blk.c */ extern int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode); +extern int ext2fs_inode_has_valid_blocks2(ext2_filsys fs, + struct ext2_inode *inode); /* version.c */ extern int ext2fs_parse_version_string(const char *ver_string); @@ -1315,6 +1397,11 @@ extern errcode_t ext2fs_write_bb_FILE(ext2_badblocks_list bb_list, extern errcode_t ext2fs_get_mem(unsigned long size, void *ptr); extern errcode_t ext2fs_get_memalign(unsigned long size, unsigned long align, void *ptr); +extern errcode_t ext2fs_get_memzero(unsigned long size, void *ptr); +extern errcode_t ext2fs_get_array(unsigned long count, + unsigned long size, void *ptr); +extern errcode_t ext2fs_get_arrayzero(unsigned long count, + unsigned long size, void *ptr); extern errcode_t ext2fs_free_mem(void *ptr); extern errcode_t ext2fs_resize_mem(unsigned long old_size, unsigned long size, void *ptr); @@ -1336,6 +1423,9 @@ extern blk_t ext2fs_inode_data_blocks(ext2_filsys fs, struct ext2_inode *inode); extern unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b); extern __u64 ext2fs_div64_ceil(__u64 a, __u64 b); +extern int ext2fs_open_file(const char *pathname, int flags, mode_t mode); +extern int ext2fs_stat(const char *path, ext2fs_struct_stat *buf); +extern int ext2fs_fstat(int fd, ext2fs_struct_stat *buf); /* * The actual inlined functions definitions themselves... @@ -1371,30 +1461,39 @@ _INLINE_ errcode_t ext2fs_get_mem(unsigned long size, void *ptr) return 0; } -_INLINE_ errcode_t ext2fs_get_memalign(unsigned long size, - unsigned long align, void *ptr) +_INLINE_ errcode_t ext2fs_get_memzero(unsigned long size, void *ptr) { void *pp; - #ifdef HWRVL - pp = mem_align(32, size); - #else pp = mem_alloc(size); - #endif if (!pp) return EXT2_ET_NO_MEMORY; - - memcpy(ptr, &pp, sizeof (pp)); + memset(pp, 0, size); + memcpy(ptr, &pp, sizeof(pp)); return 0; } _INLINE_ errcode_t ext2fs_get_array(unsigned long count, unsigned long size, void *ptr) { if (count && (-1UL)/count #if HAVE_UNISTD_H #include @@ -82,9 +83,9 @@ errcode_t ext2fs_write_ext_attr2(ext2_filsys fs, blk64_t block, void *inbuf) { errcode_t retval; char *write_buf; +#ifdef WORDS_BIGENDIAN char *buf = NULL; -#ifdef WORDS_BIGENDIAN retval = ext2fs_get_mem(fs->blocksize, &buf); if (retval) return retval; @@ -94,8 +95,9 @@ errcode_t ext2fs_write_ext_attr2(ext2_filsys fs, blk64_t block, void *inbuf) write_buf = (char *) inbuf; #endif retval = io_channel_write_blk64(fs->io, block, 1, write_buf); - if (buf) - ext2fs_free_mem(&buf); +#ifdef WORDS_BIGENDIAN + ext2fs_free_mem(&buf); +#endif if (!retval) ext2fs_mark_changed(fs); return retval; diff --git a/libcustomext2fs/source/extent.c b/libcustomext2fs/source/extent.c index 5e070925..eb096d6a 100644 --- a/libcustomext2fs/source/extent.c +++ b/libcustomext2fs/source/extent.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H @@ -253,9 +254,8 @@ extern errcode_t ext2fs_extent_open2(ext2_filsys fs, ext2_ino_t ino, handle->path[0].max_entries = ext2fs_le16_to_cpu(eh->eh_max); handle->path[0].curr = 0; handle->path[0].end_blk = - ((((__u64) handle->inode->i_size_high << 32) + - handle->inode->i_size + (fs->blocksize - 1)) - >> EXT2_BLOCK_SIZE_BITS(fs->super)); + (EXT2_I_SIZE(handle->inode) + fs->blocksize - 1) >> + EXT2_BLOCK_SIZE_BITS(fs->super); handle->path[0].visit_num = 1; handle->level = 0; handle->magic = EXT2_ET_MAGIC_EXTENT_HANDLE; @@ -374,9 +374,11 @@ retry: case EXT2_EXTENT_ROOT: handle->level = 0; path = handle->path + handle->level; + /* fallthrough */ case EXT2_EXTENT_FIRST_SIB: path->left = path->entries; path->curr = 0; + /* fallthrough */ case EXT2_EXTENT_NEXT_SIB: if (path->left <= 0) return EXT2_ET_EXTENT_NO_NEXT; diff --git a/libcustomext2fs/source/fileio.c b/libcustomext2fs/source/fileio.c index 44c859b9..193f72e5 100644 --- a/libcustomext2fs/source/fileio.c +++ b/libcustomext2fs/source/fileio.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H @@ -22,7 +23,7 @@ struct ext2_file { errcode_t magic; ext2_filsys fs; ext2_ino_t ino; - struct ext2_inode inode; + struct ext2_inode *inode; int flags; __u64 pos; blk64_t blockno; @@ -56,13 +57,9 @@ errcode_t ext2fs_file_open2(ext2_filsys fs, ext2_ino_t ino, file->fs = fs; file->ino = ino; file->flags = flags & EXT2_FILE_MASK; - - if (inode) { - memcpy(&file->inode, inode, sizeof(struct ext2_inode)); - } else { - retval = ext2fs_read_inode(fs, ino, &file->inode); - if (retval) - goto fail; + file->inode = inode; + if (!inode) { + goto fail; } retval = ext2fs_get_array(3, fs->blocksize, &file->buf); @@ -102,7 +99,7 @@ struct ext2_inode *ext2fs_file_get_inode(ext2_file_t file) { if (file->magic != EXT2_ET_MAGIC_EXT2_FILE) return NULL; - return &file->inode; + return file->inode; } /* @@ -121,15 +118,12 @@ errcode_t ext2fs_file_flush(ext2_file_t file) !(file->flags & EXT2_FILE_BUF_DIRTY)) return 0; - // Flushing out the new size - Dimok - ext2fs_write_inode(file->fs, file->ino, &file->inode); - /* * OK, the physical block hasn't been allocated yet. * Allocate it. */ if (!file->physblock) { - retval = ext2fs_bmap2(fs, file->ino, &file->inode, + retval = ext2fs_bmap2(fs, file->ino, file->inode, BMAP_BUFFER, file->ino ? BMAP_ALLOC : 0, file->blockno, 0, &file->physblock); if (retval) @@ -181,7 +175,7 @@ static errcode_t load_buffer(ext2_file_t file, int dontfill) errcode_t retval; if (!(file->flags & EXT2_FILE_BUF_VALID)) { - retval = ext2fs_bmap2(fs, file->ino, &file->inode, + retval = ext2fs_bmap2(fs, file->ino, file->inode, BMAP_BUFFER, 0, file->blockno, 0, &file->physblock); if (retval) @@ -230,7 +224,7 @@ errcode_t ext2fs_file_read(ext2_file_t file, void *buf, EXT2_CHECK_MAGIC(file, EXT2_ET_MAGIC_EXT2_FILE); fs = file->fs; - while ((file->pos < EXT2_I_SIZE(&file->inode)) && (wanted > 0)) { + while ((file->pos < EXT2_I_SIZE(file->inode)) && (wanted > 0)) { retval = sync_buffer_position(file); if (retval) goto fail; @@ -242,7 +236,7 @@ errcode_t ext2fs_file_read(ext2_file_t file, void *buf, c = fs->blocksize - start; if (c > wanted) c = wanted; - left = EXT2_I_SIZE(&file->inode) - file->pos ; + left = EXT2_I_SIZE(file->inode) - file->pos ; if (c > left) c = left; @@ -300,11 +294,11 @@ errcode_t ext2fs_file_write(ext2_file_t file, const void *buf, nbytes -= c; } - // I don't see why changing size is my duty - Dimok - if(EXT2_I_SIZE(&file->inode) < file->pos) + // Modify file size in inode if required + if(EXT2_I_SIZE(file->inode) < file->pos) { - file->inode.i_size = file->pos & 0xFFFFFFFF; - file->inode.i_size_high = (file->pos >> 32) & 0xFFFFFFFF; + file->inode->i_size = file->pos & 0xFFFFFFFF; + file->inode->i_size_high = (file->pos >> 32) & 0xFFFFFFFF; } fail: @@ -323,7 +317,7 @@ errcode_t ext2fs_file_llseek(ext2_file_t file, __u64 offset, else if (whence == EXT2_SEEK_CUR) file->pos += offset; else if (whence == EXT2_SEEK_END) - file->pos = EXT2_I_SIZE(&file->inode) + offset; + file->pos = EXT2_I_SIZE(file->inode) + offset; else return EXT2_ET_INVALID_ARGUMENT; @@ -336,7 +330,7 @@ errcode_t ext2fs_file_llseek(ext2_file_t file, __u64 offset, errcode_t ext2fs_file_lseek(ext2_file_t file, ext2_off_t offset, int whence, ext2_off_t *ret_pos) { - __u64 loffset, ret_loffset = 0; + __u64 loffset, ret_loffset; errcode_t retval; loffset = offset; @@ -354,7 +348,7 @@ errcode_t ext2fs_file_get_lsize(ext2_file_t file, __u64 *ret_size) { if (file->magic != EXT2_ET_MAGIC_EXT2_FILE) return EXT2_ET_MAGIC_EXT2_FILE; - *ret_size = EXT2_I_SIZE(&file->inode); + *ret_size = EXT2_I_SIZE(file->inode); return 0; } @@ -386,15 +380,14 @@ errcode_t ext2fs_file_set_size2(ext2_file_t file, ext2_off64_t size) truncate_block = ((size + file->fs->blocksize - 1) >> EXT2_BLOCK_SIZE_BITS(file->fs->super)) + 1; - old_size = file->inode.i_size + - (((blk64_t) file->inode.i_size_high) << 32); + old_size = EXT2_I_SIZE(file->inode); old_truncate = ((old_size + file->fs->blocksize - 1) >> EXT2_BLOCK_SIZE_BITS(file->fs->super)) + 1; - file->inode.i_size = size & 0xffffffff; - file->inode.i_size_high = (size >> 32); + file->inode->i_size = size & 0xffffffff; + file->inode->i_size_high = (size >> 32); if (file->ino) { - retval = ext2fs_write_inode(file->fs, file->ino, &file->inode); + retval = ext2fs_write_inode(file->fs, file->ino, file->inode); if (retval) return retval; } @@ -402,7 +395,7 @@ errcode_t ext2fs_file_set_size2(ext2_file_t file, ext2_off64_t size) if (truncate_block <= old_truncate) return 0; - return ext2fs_punch(file->fs, file->ino, &file->inode, 0, + return ext2fs_punch(file->fs, file->ino, file->inode, 0, truncate_block, ~0ULL); } diff --git a/libcustomext2fs/source/finddev.c b/libcustomext2fs/source/finddev.c index cc2029f2..13ef14bf 100644 --- a/libcustomext2fs/source/finddev.c +++ b/libcustomext2fs/source/finddev.c @@ -10,6 +10,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H diff --git a/libcustomext2fs/source/flushb.c b/libcustomext2fs/source/flushb.c index b6f161b6..ac8923cb 100644 --- a/libcustomext2fs/source/flushb.c +++ b/libcustomext2fs/source/flushb.c @@ -10,6 +10,7 @@ * %End-Header% */ +#include "config.h" #include #if HAVE_ERRNO_H #include @@ -65,9 +66,13 @@ errcode_t ext2fs_sync_device(int fd, int flushb) #ifdef BLKFLSBUF if (ioctl (fd, BLKFLSBUF, 0) == 0) return 0; +#elif defined(__linux__) +#warning BLKFLSBUF not defined #endif #ifdef FDFLUSH ioctl (fd, FDFLUSH, 0); /* In case this is a floppy */ +#elif defined(__linux__) +#warning FDFLUSH not defined #endif } return 0; diff --git a/libcustomext2fs/source/freefs.c b/libcustomext2fs/source/freefs.c index 5c35bb68..28c4132f 100644 --- a/libcustomext2fs/source/freefs.c +++ b/libcustomext2fs/source/freefs.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #if HAVE_UNISTD_H #include @@ -53,6 +54,11 @@ void ext2fs_free(ext2_filsys fs) if (fs->icache) ext2fs_free_inode_cache(fs->icache); + if (fs->mmp_buf) + ext2fs_free_mem(&fs->mmp_buf); + if (fs->mmp_cmp) + ext2fs_free_mem(&fs->mmp_cmp); + fs->magic = 0; ext2fs_free_mem(&fs); diff --git a/libcustomext2fs/source/gekko_io.c b/libcustomext2fs/source/gekko_io.c index 97da1d9f..ec6d93d2 100644 --- a/libcustomext2fs/source/gekko_io.c +++ b/libcustomext2fs/source/gekko_io.c @@ -47,6 +47,59 @@ static bool device_gekko_io_readsectors(io_channel dev, sec_t sector, sec_t numS static s64 device_gekko_io_writebytes(io_channel dev, s64 offset, s64 count, const void *buf); static bool device_gekko_io_writesectors(io_channel dev, sec_t sector, sec_t numSectors, const void* buffer); +/** + * Get the sector size of the device + */ +static int readSectorSize(const DISC_INTERFACE* interace) +{ + int counter1 = 0; + int counter2 = 0; + int i; + + u8 *memblock = (u8 *) mem_alloc(MAX_SECTOR_SIZE); + if(!memblock) + return 512; + + memset(memblock, 0x00, MAX_SECTOR_SIZE); + + if(!interace->readSectors(0, 1, memblock)) { + mem_free(memblock); + return 512; + } + + for(i = 0; i < MAX_SECTOR_SIZE; ++i) + { + if(memblock[i] != 0x00) + counter1++; + } + + memset(memblock, 0xFF, MAX_SECTOR_SIZE); + + if(!interace->readSectors(0, 1, memblock)) { + mem_free(memblock); + return 512; + } + + for(i = 0; i < MAX_SECTOR_SIZE; ++i) + { + if(memblock[i] != 0xFF) + counter2++; + } + + mem_free(memblock); + + if(counter1 <= 512 && counter2 <= 512) + return 512; + + if(counter1 <= 1024 && counter2 <= 1024) + return 1024; + + if(counter1 <= 2048 && counter2 <= 2048) + return 2048; + + return 4096; +} + /** * */ @@ -78,8 +131,9 @@ static errcode_t device_gekko_io_open(const char *name, int flags, io_channel *d return -1; } - struct ext2_super_block * super = (struct ext2_super_block *) mem_alloc(SUPERBLOCK_SIZE); //1024 bytes - if(!super) + // Allocate 4 x max sector size in case of 4096 sector size + u8 *buffer = (u8 *) mem_alloc(4 * MAX_SECTOR_SIZE); + if(!buffer) { ext2_log_trace("no memory for superblock"); errno = ENOMEM; @@ -87,44 +141,49 @@ static errcode_t device_gekko_io_open(const char *name, int flags, io_channel *d } // Check that there is a valid EXT boot sector at the start of the device - if (!interface->readSectors(fd->startSector+SUPERBLOCK_OFFSET/BYTES_PER_SECTOR, SUPERBLOCK_SIZE/BYTES_PER_SECTOR, super)) + if (!interface->readSectors(fd->startSector, 4, buffer)) { ext2_log_trace("read failure @ sector %d\n", fd->startSector); errno = EROFS; - mem_free(super); + mem_free(buffer); return -1; } + struct ext2_super_block * super = (struct ext2_super_block *) (buffer + SUPERBLOCK_OFFSET); + if(ext2fs_le16_to_cpu(super->s_magic) != EXT2_SUPER_MAGIC) { - mem_free(super); + ext2_log_trace("super mismatch: read %04X - expected %04X\n", ext2fs_le16_to_cpu(super->s_magic), EXT2_SUPER_MAGIC); + mem_free(buffer); errno = EROFS; return -1; } - // Parse the boot sector - fd->sectorSize = BYTES_PER_SECTOR; - fd->offset = 0; - fd->sectorCount = 0; - switch(ext2fs_le32_to_cpu(super->s_log_block_size)) { case 1: - fd->sectorCount = (sec_t) ((u64) ext2fs_le32_to_cpu(super->s_blocks_count) * (u64) 2048 / (u64) BYTES_PER_SECTOR); + (*dev)->block_size = 2048; break; case 2: - fd->sectorCount = (sec_t) ((u64) ext2fs_le32_to_cpu(super->s_blocks_count) * (u64) 4096 / (u64) BYTES_PER_SECTOR); + (*dev)->block_size = 4096; break; case 3: - fd->sectorCount = (sec_t) ((u64) ext2fs_le32_to_cpu(super->s_blocks_count) * (u64) 8192 / (u64) BYTES_PER_SECTOR); + (*dev)->block_size = 8192; break; default: case 0: - fd->sectorCount = (sec_t) ((u64) ext2fs_le32_to_cpu(super->s_blocks_count) * (u64) 1024 / (u64) BYTES_PER_SECTOR); + (*dev)->block_size = 1024; break; } - mem_free(super); + + // Parse the boot sector + fd->sectorSize = readSectorSize(interface); + fd->offset = 0; + fd->sectorCount = 0; + fd->sectorCount = (sec_t) ((u64) ext2fs_le32_to_cpu(super->s_blocks_count) * (u64) ((*dev)->block_size) / (u64) fd->sectorSize); + + mem_free(buffer); // Create the cache fd->cache = cache_constructor(fd->cachePageCount, fd->cachePageSize, interface, fd->startSector + fd->sectorCount, fd->sectorSize); diff --git a/libcustomext2fs/source/gekko_io.h b/libcustomext2fs/source/gekko_io.h index 16786c7c..6d5b4fb1 100644 --- a/libcustomext2fs/source/gekko_io.h +++ b/libcustomext2fs/source/gekko_io.h @@ -27,7 +27,7 @@ #include "disc_cache.h" #include "ext2fs.h" -#define BYTES_PER_SECTOR 512 +#define MAX_SECTOR_SIZE (4096) /** * gekko_fd - Gekko device driver descriptor diff --git a/libcustomext2fs/source/gen_bitmap.c b/libcustomext2fs/source/gen_bitmap.c index 2ef1d826..6679bffa 100644 --- a/libcustomext2fs/source/gen_bitmap.c +++ b/libcustomext2fs/source/gen_bitmap.c @@ -10,6 +10,7 @@ */ +#include "config.h" #include #include #if HAVE_UNISTD_H @@ -25,7 +26,6 @@ #endif #include "ext2_fs.h" -#include "ext2fs.h" #include "ext2fsP.h" struct ext2fs_struct_generic_bitmap { @@ -179,8 +179,8 @@ int ext2fs_test_generic_bitmap(ext2fs_generic_bitmap bitmap, #ifndef OMIT_COM_ERR com_err(0, EXT2_ET_MAGIC_GENERIC_BITMAP, "test_bitmap(%lu)", (unsigned long) bitno); - return 0; #endif + return 0; } if ((bitno < bitmap->start) || (bitno > bitmap->end)) { @@ -201,8 +201,8 @@ int ext2fs_mark_generic_bitmap(ext2fs_generic_bitmap bitmap, #ifndef OMIT_COM_ERR com_err(0, EXT2_ET_MAGIC_GENERIC_BITMAP, "mark_bitmap(%lu)", (unsigned long) bitno); - return 0; #endif + return 0; } if ((bitno < bitmap->start) || (bitno > bitmap->end)) { @@ -223,8 +223,8 @@ int ext2fs_unmark_generic_bitmap(ext2fs_generic_bitmap bitmap, #ifndef OMIT_COM_ERR com_err(0, EXT2_ET_MAGIC_GENERIC_BITMAP, "mark_bitmap(%lu)", (unsigned long) bitno); - return 0; #endif + return 0; } if ((bitno < bitmap->start) || (bitno > bitmap->end)) { @@ -244,8 +244,8 @@ __u32 ext2fs_get_generic_bitmap_start(ext2fs_generic_bitmap bitmap) #ifndef OMIT_COM_ERR com_err(0, EXT2_ET_MAGIC_GENERIC_BITMAP, "get_bitmap_start"); - return 0; #endif + return 0; } return bitmap->start; @@ -261,8 +261,8 @@ __u32 ext2fs_get_generic_bitmap_end(ext2fs_generic_bitmap bitmap) #ifndef OMIT_COM_ERR com_err(0, EXT2_ET_MAGIC_GENERIC_BITMAP, "get_bitmap_end"); - return 0; #endif + return 0; } return bitmap->end; } @@ -278,8 +278,8 @@ void ext2fs_clear_generic_bitmap(ext2fs_generic_bitmap bitmap) #ifndef OMIT_COM_ERR com_err(0, EXT2_ET_MAGIC_GENERIC_BITMAP, "clear_generic_bitmap"); - return; #endif + return; } memset(bitmap->bitmap, 0, diff --git a/libcustomext2fs/source/gen_bitmap64.c b/libcustomext2fs/source/gen_bitmap64.c index 9e7b2983..9dbbf9fb 100644 --- a/libcustomext2fs/source/gen_bitmap64.c +++ b/libcustomext2fs/source/gen_bitmap64.c @@ -10,6 +10,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H @@ -107,12 +108,14 @@ errcode_t ext2fs_alloc_generic_bmap(ext2_filsys fs, errcode_t magic, bitmap->end = end; bitmap->real_end = real_end; bitmap->bitmap_ops = ops; + bitmap->cluster_bits = 0; switch (magic) { case EXT2_ET_MAGIC_INODE_BITMAP64: bitmap->base_error_code = EXT2_ET_BAD_INODE_MARK; break; case EXT2_ET_MAGIC_BLOCK_BITMAP64: bitmap->base_error_code = EXT2_ET_BAD_BLOCK_MARK; + bitmap->cluster_bits = fs->cluster_ratio_bits; break; default: bitmap->base_error_code = EXT2_ET_BAD_GENERIC_MARK; @@ -191,6 +194,7 @@ errcode_t ext2fs_copy_generic_bmap(ext2fs_generic_bitmap src, new_bmap->real_end = src->real_end; new_bmap->bitmap_ops = src->bitmap_ops; new_bmap->base_error_code = src->base_error_code; + new_bmap->cluster_bits = src->cluster_bits; descr = src->description; if (descr) { @@ -315,6 +319,8 @@ int ext2fs_mark_generic_bmap(ext2fs_generic_bitmap bitmap, if (!EXT2FS_IS_64_BITMAP(bitmap)) return 0; + arg >>= bitmap->cluster_bits; + if ((arg < bitmap->start) || (arg > bitmap->end)) { warn_bitmap(bitmap, EXT2FS_MARK_ERROR, arg); return 0; @@ -341,6 +347,8 @@ int ext2fs_unmark_generic_bmap(ext2fs_generic_bitmap bitmap, if (!EXT2FS_IS_64_BITMAP(bitmap)) return 0; + arg >>= bitmap->cluster_bits; + if ((arg < bitmap->start) || (arg > bitmap->end)) { warn_bitmap(bitmap, EXT2FS_UNMARK_ERROR, arg); return 0; @@ -367,6 +375,8 @@ int ext2fs_test_generic_bmap(ext2fs_generic_bitmap bitmap, if (!EXT2FS_IS_64_BITMAP(bitmap)) return 0; + arg >>= bitmap->cluster_bits; + if ((arg < bitmap->start) || (arg > bitmap->end)) { warn_bitmap(bitmap, EXT2FS_TEST_ERROR, arg); return 0; @@ -383,7 +393,7 @@ errcode_t ext2fs_set_generic_bmap_range(ext2fs_generic_bitmap bmap, return EINVAL; if (EXT2FS_IS_32_BITMAP(bmap)) { - if ((start+num) & ~0xffffffffULL) { + if ((start+num-1) & ~0xffffffffULL) { ext2fs_warn_bitmap2(bmap, EXT2FS_UNMARK_ERROR, 0xffffffff); return EINVAL; @@ -406,7 +416,7 @@ errcode_t ext2fs_get_generic_bmap_range(ext2fs_generic_bitmap bmap, return EINVAL; if (EXT2FS_IS_32_BITMAP(bmap)) { - if ((start+num) & ~0xffffffffULL) { + if ((start+num-1) & ~0xffffffffULL) { ext2fs_warn_bitmap2(bmap, EXT2FS_UNMARK_ERROR, 0xffffffff); return EINVAL; @@ -477,7 +487,7 @@ int ext2fs_test_block_bitmap_range2(ext2fs_block_bitmap bmap, bmap, block); if (EXT2FS_IS_32_BITMAP(bmap)) { - if ((block+num) & ~0xffffffffULL) { + if ((block+num-1) & ~0xffffffffULL) { ext2fs_warn_bitmap2((ext2fs_generic_bitmap) bmap, EXT2FS_UNMARK_ERROR, 0xffffffff); return EINVAL; @@ -499,7 +509,7 @@ void ext2fs_mark_block_bitmap_range2(ext2fs_block_bitmap bmap, return; if (EXT2FS_IS_32_BITMAP(bmap)) { - if ((block+num) & ~0xffffffffULL) { + if ((block+num-1) & ~0xffffffffULL) { ext2fs_warn_bitmap2((ext2fs_generic_bitmap) bmap, EXT2FS_UNMARK_ERROR, 0xffffffff); return; @@ -527,7 +537,7 @@ void ext2fs_unmark_block_bitmap_range2(ext2fs_block_bitmap bmap, return; if (EXT2FS_IS_32_BITMAP(bmap)) { - if ((block+num) & ~0xffffffffULL) { + if ((block+num-1) & ~0xffffffffULL) { ext2fs_warn_bitmap2((ext2fs_generic_bitmap) bmap, EXT2FS_UNMARK_ERROR, 0xffffffff); return; @@ -548,7 +558,7 @@ void ext2fs_unmark_block_bitmap_range2(ext2fs_block_bitmap bmap, bmap->bitmap_ops->unmark_bmap_extent(bmap, block, num); } -int ext2fs_warn_bitmap32(ext2fs_generic_bitmap bitmap, const char *func) +void ext2fs_warn_bitmap32(ext2fs_generic_bitmap bitmap, const char *func) { #ifndef OMIT_COM_ERR if (bitmap && bitmap->description) @@ -559,5 +569,47 @@ int ext2fs_warn_bitmap32(ext2fs_generic_bitmap bitmap, const char *func) com_err(0, EXT2_ET_MAGIC_GENERIC_BITMAP, "called %s with 64-bit bitmap", func); #endif - return 0; +} + +errcode_t ext2fs_convert_subcluster_bitmap(ext2_filsys fs, + ext2fs_block_bitmap *bitmap) +{ + ext2fs_block_bitmap cmap, bmap; + errcode_t retval; + blk64_t i, b_end, c_end; + int n, ratio; + + bmap = *bitmap; + + if (fs->cluster_ratio_bits == ext2fs_get_bitmap_granularity(bmap)) + return 0; /* Nothing to do */ + + retval = ext2fs_allocate_block_bitmap(fs, "converted cluster bitmap", + &cmap); + if (retval) + return retval; + + i = bmap->start; + b_end = bmap->end; + bmap->end = bmap->real_end; + c_end = cmap->end; + cmap->end = cmap->real_end; + n = 0; + ratio = 1 << fs->cluster_ratio_bits; + while (i < bmap->real_end) { + if (ext2fs_test_block_bitmap2(bmap, i)) { + ext2fs_mark_block_bitmap2(cmap, i); + i += ratio - n; + n = 0; + continue; + } + i++; n++; + if (n >= ratio) + n = 0; + } + bmap->end = b_end; + cmap->end = c_end; + ext2fs_free_block_bitmap(bmap); + *bitmap = cmap; + return 0; } diff --git a/libcustomext2fs/source/get_pathname.c b/libcustomext2fs/source/get_pathname.c index 7ac14db2..e259eee7 100644 --- a/libcustomext2fs/source/get_pathname.c +++ b/libcustomext2fs/source/get_pathname.c @@ -21,6 +21,7 @@ * */ +#include "config.h" #include #include #if HAVE_UNISTD_H diff --git a/libcustomext2fs/source/getsectsize.c b/libcustomext2fs/source/getsectsize.c index 64f42a62..30faecc7 100644 --- a/libcustomext2fs/source/getsectsize.c +++ b/libcustomext2fs/source/getsectsize.c @@ -13,6 +13,7 @@ #define _LARGEFILE_SOURCE #define _LARGEFILE64_SOURCE +#include "config.h" #include #if HAVE_UNISTD_H #include @@ -45,11 +46,7 @@ errcode_t ext2fs_get_device_sectsize(const char *file, int *sectsize) { int fd; -#ifdef HAVE_OPEN64 - fd = open64(file, O_RDONLY); -#else - fd = open(file, O_RDONLY); -#endif + fd = ext2fs_open_file(file, O_RDONLY, 0); if (fd < 0) return errno; @@ -71,11 +68,7 @@ errcode_t ext2fs_get_device_phys_sectsize(const char *file, int *sectsize) { int fd; -#ifdef HAVE_OPEN64 - fd = open64(file, O_RDONLY); -#else - fd = open(file, O_RDONLY); -#endif + fd = ext2fs_open_file(file, O_RDONLY, 0); if (fd < 0) return errno; diff --git a/libcustomext2fs/source/getsize.c b/libcustomext2fs/source/getsize.c index 56ec4b69..1e0ed16f 100644 --- a/libcustomext2fs/source/getsize.c +++ b/libcustomext2fs/source/getsize.c @@ -15,6 +15,7 @@ #define _LARGEFILE_SOURCE #define _LARGEFILE64_SOURCE +#include "config.h" #include #if HAVE_UNISTD_H #include @@ -142,10 +143,12 @@ errcode_t ext2fs_get_device_size2(const char *file, int blocksize, blk64_t *retblocks) { int fd, rc = 0; + int valid_blkgetsize64 = 1; #ifdef __linux__ struct utsname ut; #endif unsigned long long size64; + unsigned long size; ext2_loff_t high, low; #ifdef FDGETPRM struct floppy_struct this_floppy; @@ -157,11 +160,7 @@ errcode_t ext2fs_get_device_size2(const char *file, int blocksize, char ch; #endif /* HAVE_SYS_DISKLABEL_H */ -#ifdef HAVE_OPEN64 - fd = open64(file, O_RDONLY); -#else - fd = open(file, O_RDONLY); -#endif + fd = ext2fs_open_file(file, O_RDONLY, 0); if (fd < 0) return errno; @@ -233,13 +232,9 @@ errcode_t ext2fs_get_device_size2(const char *file, int blocksize, #endif /* HAVE_SYS_DISKLABEL_H */ { -#ifdef HAVE_FSTAT64 - struct stat64 st; - if (fstat64(fd, &st) == 0) -#else - struct stat st; - if (fstat(fd, &st) == 0) -#endif + ext2fs_struct_stat st; + + if (ext2fs_fstat(fd, &st) == 0) if (S_ISREG(st.st_mode)) { *retblocks = st.st_size / blocksize; goto out; diff --git a/libcustomext2fs/source/i_block.c b/libcustomext2fs/source/i_block.c index 39d93eec..5ca57e49 100644 --- a/libcustomext2fs/source/i_block.c +++ b/libcustomext2fs/source/i_block.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #if HAVE_UNISTD_H #include @@ -38,6 +39,7 @@ errcode_t ext2fs_iblk_add_blocks(ext2_filsys fs, struct ext2_inode *inode, EXT4_FEATURE_RO_COMPAT_HUGE_FILE) || !(inode->i_flags & EXT4_HUGE_FILE_FL)) num_blocks *= fs->blocksize / 512; + num_blocks *= EXT2FS_CLUSTER_RATIO(fs); b += num_blocks; @@ -61,6 +63,7 @@ errcode_t ext2fs_iblk_sub_blocks(ext2_filsys fs, struct ext2_inode *inode, EXT4_FEATURE_RO_COMPAT_HUGE_FILE) || !(inode->i_flags & EXT4_HUGE_FILE_FL)) num_blocks *= fs->blocksize / 512; + num_blocks *= EXT2FS_CLUSTER_RATIO(fs); if (num_blocks > b) return EOVERFLOW; @@ -79,6 +82,7 @@ errcode_t ext2fs_iblk_set(ext2_filsys fs, struct ext2_inode *inode, blk64_t b) EXT4_FEATURE_RO_COMPAT_HUGE_FILE) || !(inode->i_flags & EXT4_HUGE_FILE_FL)) b *= fs->blocksize / 512; + b *= EXT2FS_CLUSTER_RATIO(fs); inode->i_blocks = b & 0xFFFFFFFF; if (fs->super->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_HUGE_FILE) diff --git a/libcustomext2fs/source/icount.c b/libcustomext2fs/source/icount.c index 43cc53e1..1a18b377 100644 --- a/libcustomext2fs/source/icount.c +++ b/libcustomext2fs/source/icount.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #if HAVE_UNISTD_H #include #endif @@ -363,31 +364,7 @@ static struct ext2_icount_el *get_icount_el(ext2_icount_t icount, low = 0; high = (int) icount->count-1; while (low <= high) { -#if 0 - mid = (low+high)/2; -#else - if (low == high) - mid = low; - else { - /* Interpolate for efficiency */ - lowval = icount->list[low].ino; - highval = icount->list[high].ino; - - if (ino < lowval) - range = 0; - else if (ino > highval) - range = 1; - else { - range = ((float) (ino - lowval)) / - (highval - lowval); - if (range > 0.9) - range = 0.9; - if (range < 0.1) - range = 0.1; - } - mid = low + ((int) (range * (high-low))); - } -#endif + mid = ((unsigned)low + (unsigned)high) >> 1; if (ino == icount->list[mid].ino) { icount->cursor = mid+1; return &icount->list[mid]; diff --git a/libcustomext2fs/source/imager.c b/libcustomext2fs/source/imager.c index 5a6d0b95..a0fb81e4 100644 --- a/libcustomext2fs/source/imager.c +++ b/libcustomext2fs/source/imager.c @@ -13,6 +13,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H diff --git a/libcustomext2fs/source/ind_block.c b/libcustomext2fs/source/ind_block.c index 722d3bdc..aa82ae6b 100644 --- a/libcustomext2fs/source/ind_block.c +++ b/libcustomext2fs/source/ind_block.c @@ -10,6 +10,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H diff --git a/libcustomext2fs/source/initialize.c b/libcustomext2fs/source/initialize.c index 4706773a..b050a0a9 100644 --- a/libcustomext2fs/source/initialize.c +++ b/libcustomext2fs/source/initialize.c @@ -10,6 +10,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H @@ -91,9 +92,11 @@ errcode_t ext2fs_initialize(const char *name, int flags, unsigned int overhead = 0; unsigned int ipg; dgrp_t i; + blk64_t free_blocks; blk_t numblocks; int rsv_gdt; int csum_flag; + int bigalloc_flag; int io_flags; char *buf = 0; char c; @@ -134,13 +137,26 @@ errcode_t ext2fs_initialize(const char *name, int flags, #define set_field(field, default) (super->field = param->field ? \ param->field : (default)) +#define assign_field(field) (super->field = param->field) super->s_magic = EXT2_SUPER_MAGIC; super->s_state = EXT2_VALID_FS; - set_field(s_log_block_size, 0); /* default blocksize: 1024 bytes */ - set_field(s_log_cluster_size, 0); - set_field(s_first_data_block, super->s_log_block_size ? 0 : 1); + bigalloc_flag = EXT2_HAS_RO_COMPAT_FEATURE(param, + EXT4_FEATURE_RO_COMPAT_BIGALLOC); + + assign_field(s_log_block_size); + + if (bigalloc_flag) { + set_field(s_log_cluster_size, super->s_log_block_size+4); + if (super->s_log_block_size > super->s_log_cluster_size) { + retval = EXT2_ET_INVALID_ARGUMENT; + goto cleanup; + } + } else + super->s_log_cluster_size = super->s_log_block_size; + + set_field(s_first_data_block, super->s_log_cluster_size ? 0 : 1); set_field(s_max_mnt_count, 0); set_field(s_errors, EXT2_ERRORS_DEFAULT); set_field(s_feature_compat, 0); @@ -181,16 +197,39 @@ errcode_t ext2fs_initialize(const char *name, int flags, super->s_creator_os = CREATOR_OS; - fs->blocksize = EXT2_BLOCK_SIZE(super); - fs->clustersize = EXT2_CLUSTER_SIZE(super); + fs->fragsize = fs->blocksize = EXT2_BLOCK_SIZE(super); + fs->cluster_ratio_bits = super->s_log_cluster_size - + super->s_log_block_size; - /* default: (fs->blocksize*8) blocks/group, up to 2^16 (GDT limit) */ - set_field(s_blocks_per_group, fs->blocksize * 8); - if (super->s_blocks_per_group > EXT2_MAX_BLOCKS_PER_GROUP(super)) - super->s_blocks_per_group = EXT2_MAX_BLOCKS_PER_GROUP(super); - super->s_clusters_per_group = super->s_blocks_per_group; + if (bigalloc_flag) { + if (param->s_blocks_per_group && + param->s_clusters_per_group && + ((param->s_clusters_per_group * EXT2FS_CLUSTER_RATIO(fs)) != + param->s_blocks_per_group)) { + retval = EXT2_ET_INVALID_ARGUMENT; + goto cleanup; + } + if (param->s_clusters_per_group) + assign_field(s_clusters_per_group); + else if (param->s_blocks_per_group) + super->s_clusters_per_group = + param->s_blocks_per_group / + EXT2FS_CLUSTER_RATIO(fs); + else + super->s_clusters_per_group = fs->blocksize * 8; + if (super->s_clusters_per_group > EXT2_MAX_CLUSTERS_PER_GROUP(super)) + super->s_clusters_per_group = EXT2_MAX_CLUSTERS_PER_GROUP(super); + super->s_blocks_per_group = EXT2FS_C2B(fs, + super->s_clusters_per_group); + } else { + set_field(s_blocks_per_group, fs->blocksize * 8); + if (super->s_blocks_per_group > EXT2_MAX_BLOCKS_PER_GROUP(super)) + super->s_blocks_per_group = EXT2_MAX_BLOCKS_PER_GROUP(super); + super->s_clusters_per_group = super->s_blocks_per_group; + } - ext2fs_blocks_count_set(super, ext2fs_blocks_count(param)); + ext2fs_blocks_count_set(super, ext2fs_blocks_count(param) & + ~((blk64_t) EXT2FS_CLUSTER_MASK(fs))); ext2fs_r_blocks_count_set(super, ext2fs_r_blocks_count(param)); if (ext2fs_r_blocks_count(super) >= ext2fs_blocks_count(param)) { retval = EXT2_ET_INVALID_ARGUMENT; @@ -209,7 +248,7 @@ errcode_t ext2fs_initialize(const char *name, int flags, } retry: - fs->group_desc_count = (blk_t) ext2fs_div64_ceil( + fs->group_desc_count = (dgrp_t) ext2fs_div64_ceil( ext2fs_blocks_count(super) - super->s_first_data_block, EXT2_BLOCKS_PER_GROUP(super)); if (fs->group_desc_count == 0) { @@ -246,7 +285,7 @@ retry: */ ipg = ext2fs_div_ceil(super->s_inodes_count, fs->group_desc_count); if (ipg > fs->blocksize * 8) { - if (super->s_blocks_per_group >= 256) { + if (!bigalloc_flag && super->s_blocks_per_group >= 256) { /* Try again with slightly different parameters */ super->s_blocks_per_group -= 8; ext2fs_blocks_count_set(super, @@ -364,7 +403,7 @@ ipg_retry: strcpy(buf, "block bitmap for "); strcat(buf, fs->device_name); - retval = ext2fs_allocate_block_bitmap(fs, buf, &fs->block_map); + retval = ext2fs_allocate_subcluster_bitmap(fs, buf, &fs->block_map); if (retval) goto cleanup; @@ -394,7 +433,7 @@ ipg_retry: * superblock and group descriptors (the inode tables and * bitmaps will be accounted for when allocated). */ - ext2fs_free_blocks_count_set(super, 0); + free_blocks = 0; csum_flag = EXT2_HAS_RO_COMPAT_FEATURE(fs->super, EXT4_FEATURE_RO_COMPAT_GDT_CSUM); for (i = 0; i < fs->group_desc_count; i++) { @@ -416,14 +455,14 @@ ipg_retry: if (fs->super->s_log_groups_per_flex) numblocks += 2 + fs->inode_blocks_per_group; - ext2fs_free_blocks_count_set(super, - ext2fs_free_blocks_count(super) + - numblocks); + free_blocks += numblocks; ext2fs_bg_free_blocks_count_set(fs, i, numblocks); ext2fs_bg_free_inodes_count_set(fs, i, fs->super->s_inodes_per_group); ext2fs_bg_used_dirs_count_set(fs, i, 0); ext2fs_group_desc_csum_set(fs, i); } + free_blocks &= ~EXT2FS_CLUSTER_MASK(fs); + ext2fs_free_blocks_count_set(super, free_blocks); c = (char) 255; if (((int) c) == -1) { diff --git a/libcustomext2fs/source/inline.c b/libcustomext2fs/source/inline.c index f9be368b..556e0d67 100644 --- a/libcustomext2fs/source/inline.c +++ b/libcustomext2fs/source/inline.c @@ -12,6 +12,7 @@ */ +#include "config.h" #include #include #if HAVE_UNISTD_H @@ -30,3 +31,42 @@ #define INCLUDE_INLINE_FUNCS #include "ext2fs.h" +#include "mem_allocate.h" + +/* + * We used to define this as an inline, but since we are now using + * autoconf-defined #ifdef's, we need to export this as a + * library-provided function exclusively. + */ +errcode_t ext2fs_get_memalign(unsigned long size, + unsigned long align, void *ptr) +{ + errcode_t retval; + + if (align == 0) + align = 8; +#ifdef HAVE_POSIX_MEMALIGN + retval = posix_memalign((void **) ptr, align, size); + if (retval) { + if (retval == ENOMEM) + return EXT2_ET_NO_MEMORY; + return retval; + } +#else +#ifdef HAVE_MEMALIGN + void *pp; + pp = mem_align(align, size); + if (pp == NULL) { + if (errno) + return errno; + else + return EXT2_ET_NO_MEMORY; + } + memcpy(ptr, &pp, sizeof (pp)); +#else +#error memalign or posix_memalign must be defined! +#endif +#endif + return 0; +} + diff --git a/libcustomext2fs/source/inode.c b/libcustomext2fs/source/inode.c index a762dbce..6c524ff2 100644 --- a/libcustomext2fs/source/inode.c +++ b/libcustomext2fs/source/inode.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H @@ -522,7 +523,8 @@ errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ext2_ino_t *ino, errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode * inode, int bufsize) { - unsigned long group, block, block_nr, offset; + blk64_t block_nr; + unsigned long group, block, offset; char *ptr; errcode_t retval; int clen, i, inodes_per_block, length; @@ -628,7 +630,8 @@ errcode_t ext2fs_read_inode(ext2_filsys fs, ext2_ino_t ino, errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino, struct ext2_inode * inode, int bufsize) { - unsigned long group, block, block_nr, offset; + blk64_t block_nr; + unsigned long group, block, offset; errcode_t retval = 0; struct ext2_inode_large temp_inode, *w_inode; char *ptr; @@ -669,8 +672,10 @@ errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino, if (length > (int) sizeof(struct ext2_inode_large)) { w_inode = malloc(length); - if (!w_inode) - return ENOMEM; + if (!w_inode) { + retval = ENOMEM; + goto errout; + } } else w_inode = &temp_inode; memset(w_inode, 0, length); diff --git a/libcustomext2fs/source/inode_io.c b/libcustomext2fs/source/inode_io.c index b3e7ce51..8e0944ef 100644 --- a/libcustomext2fs/source/inode_io.c +++ b/libcustomext2fs/source/inode_io.c @@ -10,6 +10,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H @@ -163,7 +164,7 @@ static errcode_t inode_open(const char *name, int flags, io_channel *channel) return 0; cleanup: - if (io->name) + if (io && io->name) ext2fs_free_mem(&io->name); if (data) ext2fs_free_mem(&data); diff --git a/libcustomext2fs/source/io_manager.c b/libcustomext2fs/source/io_manager.c index 80f9dfcb..25df59ec 100644 --- a/libcustomext2fs/source/io_manager.c +++ b/libcustomext2fs/source/io_manager.c @@ -2,6 +2,7 @@ * io_manager.c --- the I/O manager abstraction */ +#include "config.h" #include #include #if HAVE_UNISTD_H diff --git a/libcustomext2fs/source/irel_ma.c b/libcustomext2fs/source/irel_ma.c index b7eaf6b5..4cef0ac1 100644 --- a/libcustomext2fs/source/irel_ma.c +++ b/libcustomext2fs/source/irel_ma.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #include #include diff --git a/libcustomext2fs/source/link.c b/libcustomext2fs/source/link.c index 4cc8426a..2d03b573 100644 --- a/libcustomext2fs/source/link.c +++ b/libcustomext2fs/source/link.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H @@ -52,9 +53,9 @@ static int link_proc(struct ext2_dir_entry *dirent, * if so, absorb it into this one. */ next = (struct ext2_dir_entry *) (buf + offset + curr_rec_len); - if ((offset + curr_rec_len < blocksize - 8) && + if ((offset + (int) curr_rec_len < blocksize - 8) && (next->inode == 0) && - (offset + curr_rec_len + next->rec_len <= blocksize)) { + (offset + (int) curr_rec_len + (int) next->rec_len <= blocksize)) { curr_rec_len += next->rec_len; ls->err = ext2fs_set_rec_len(ls->fs, curr_rec_len, dirent); if (ls->err) diff --git a/libcustomext2fs/source/llseek.c b/libcustomext2fs/source/llseek.c index 3b919bef..6cf81b3e 100644 --- a/libcustomext2fs/source/llseek.c +++ b/libcustomext2fs/source/llseek.c @@ -12,6 +12,7 @@ #define _LARGEFILE_SOURCE #define _LARGEFILE64_SOURCE +#include "config.h" #if HAVE_SYS_TYPES_H #include #endif diff --git a/libcustomext2fs/source/lookup.c b/libcustomext2fs/source/lookup.c index 97aa0887..0e66e712 100644 --- a/libcustomext2fs/source/lookup.c +++ b/libcustomext2fs/source/lookup.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H diff --git a/libcustomext2fs/source/mem_allocate.h b/libcustomext2fs/source/mem_allocate.h index 4554b8b4..750ef0d3 100644 --- a/libcustomext2fs/source/mem_allocate.h +++ b/libcustomext2fs/source/mem_allocate.h @@ -8,6 +8,14 @@ extern __inline__ void* mem_alloc (size_t size) { return MEM2_alloc(size); } +extern __inline__ void* mem_calloc (size_t count, size_t size) { + void *p = MEM2_alloc(count * size); + if(p) { + memset(p, 0, count * size); + } + return p; +} + extern __inline__ void* mem_realloc (void *p, size_t size) { return MEM2_realloc(p, size); } diff --git a/libcustomext2fs/source/mkdir.c b/libcustomext2fs/source/mkdir.c index 86c65da9..b12bf2dd 100644 --- a/libcustomext2fs/source/mkdir.c +++ b/libcustomext2fs/source/mkdir.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H @@ -33,6 +34,7 @@ errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum, const char *name) { + ext2_extent_handle_t handle; errcode_t retval; struct ext2_inode parent_inode, inode; ext2_ino_t ino = inum; @@ -83,8 +85,10 @@ errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum, inode.i_mode = LINUX_S_IFDIR | (0777 & ~fs->umask); inode.i_uid = inode.i_gid = 0; ext2fs_iblk_set(fs, &inode, 1); - /* FIXME-64 */ - inode.i_block[0] = blk; + if (fs->super->s_feature_incompat & EXT3_FEATURE_INCOMPAT_EXTENTS) + inode.i_flags |= EXT4_EXTENTS_FL; + else + inode.i_block[0] = blk; inode.i_links_count = 2; inode.i_size = fs->blocksize; @@ -98,6 +102,16 @@ errcode_t ext2fs_mkdir(ext2_filsys fs, ext2_ino_t parent, ext2_ino_t inum, if (retval) goto cleanup; + if (fs->super->s_feature_incompat & EXT3_FEATURE_INCOMPAT_EXTENTS) { + retval = ext2fs_extent_open2(fs, ino, &inode, &handle); + if (retval) + goto cleanup; + retval = ext2fs_extent_set_bmap(handle, 0, blk, 0); + ext2fs_extent_free(handle); + if (retval) + goto cleanup; + } + /* * Link the directory into the filesystem hierarchy */ diff --git a/libcustomext2fs/source/mkjournal.c b/libcustomext2fs/source/mkjournal.c index 47fb92c2..81639ac6 100644 --- a/libcustomext2fs/source/mkjournal.c +++ b/libcustomext2fs/source/mkjournal.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H @@ -44,13 +45,13 @@ * returns it as an allocated block. */ errcode_t ext2fs_create_journal_superblock(ext2_filsys fs, - __u32 size, int flags, + __u32 num_blocks, int flags, char **ret_jsb) { errcode_t retval; journal_superblock_t *jsb; - if (size < 1024) + if (num_blocks < 1024) return EXT2_ET_JOURNAL_TOO_SMALL; if ((retval = ext2fs_get_mem(fs->blocksize, &jsb))) @@ -64,7 +65,7 @@ errcode_t ext2fs_create_journal_superblock(ext2_filsys fs, else jsb->s_header.h_blocktype = htonl(JFS_SUPERBLOCK_V2); jsb->s_blocksize = htonl(fs->blocksize); - jsb->s_maxlen = htonl(size); + jsb->s_maxlen = htonl(num_blocks); jsb->s_nr_users = htonl(1); jsb->s_first = htonl(1); jsb->s_sequence = htonl(1); @@ -92,20 +93,21 @@ errcode_t ext2fs_create_journal_superblock(ext2_filsys fs, * filesystems. */ static errcode_t write_journal_file(ext2_filsys fs, char *filename, - blk_t size, int flags) + blk_t num_blocks, int flags) { errcode_t retval; char *buf = 0; int fd, ret_size; blk_t i; - if ((retval = ext2fs_create_journal_superblock(fs, size, flags, &buf))) + if ((retval = ext2fs_create_journal_superblock(fs, num_blocks, flags, + &buf))) return retval; /* Open the device or journal file */ if ((fd = open(filename, O_WRONLY)) < 0) { retval = errno; - goto errout; + goto errfree; } /* Write the superblock out */ @@ -119,7 +121,10 @@ static errcode_t write_journal_file(ext2_filsys fs, char *filename, goto errout; memset(buf, 0, fs->blocksize); - for (i = 1; i < size; i++) { + if (flags & EXT2_MKJOURNAL_LAZYINIT) + goto success; + + for (i = 1; i < num_blocks; i++) { ret_size = write(fd, buf, fs->blocksize); if (ret_size < 0) { retval = errno; @@ -128,10 +133,12 @@ static errcode_t write_journal_file(ext2_filsys fs, char *filename, if (ret_size != (int) fs->blocksize) goto errout; } - close(fd); +success: retval = 0; errout: + close(fd); +errfree: ext2fs_free_mem(&buf); return retval; } @@ -215,6 +222,7 @@ struct mkjournal_struct { blk64_t goal; blk64_t blk_to_zero; int zero_count; + int flags; char *buf; errcode_t err; }; @@ -234,19 +242,25 @@ static int mkjournal_proc(ext2_filsys fs, es->goal = *blocknr; return 0; } - retval = ext2fs_new_block2(fs, es->goal, 0, &new_blk); - if (retval) { - es->err = retval; - return BLOCK_ABORT; + if (blockcnt && + (EXT2FS_B2C(fs, es->goal) == EXT2FS_B2C(fs, es->goal+1))) + new_blk = es->goal+1; + else { + es->goal &= ~EXT2FS_CLUSTER_MASK(fs); + retval = ext2fs_new_block2(fs, es->goal, 0, &new_blk); + if (retval) { + es->err = retval; + return BLOCK_ABORT; + } + es->newblocks++; } if (blockcnt >= 0) es->num_blocks--; - es->newblocks++; retval = 0; if (blockcnt <= 0) retval = io_channel_write_blk64(fs->io, new_blk, 1, es->buf); - else { + else if (!(es->flags & EXT2_MKJOURNAL_LAZYINIT)) { if (es->zero_count) { if ((es->blk_to_zero + es->zero_count == new_blk) && (es->zero_count < 1024)) @@ -286,15 +300,17 @@ static int mkjournal_proc(ext2_filsys fs, * This function creates a journal using direct I/O routines. */ static errcode_t write_journal_inode(ext2_filsys fs, ext2_ino_t journal_ino, - blk64_t size, int flags) + blk_t num_blocks, int flags) { char *buf; dgrp_t group, start, end, i, log_flex; errcode_t retval; struct ext2_inode inode; + unsigned long long inode_size; struct mkjournal_struct es; - if ((retval = ext2fs_create_journal_superblock(fs, size, flags, &buf))) + if ((retval = ext2fs_create_journal_superblock(fs, num_blocks, flags, + &buf))) return retval; if ((retval = ext2fs_read_bitmaps(fs))) @@ -306,10 +322,11 @@ static errcode_t write_journal_inode(ext2_filsys fs, ext2_ino_t journal_ino, if (inode.i_blocks > 0) return EEXIST; - es.num_blocks = size; + es.num_blocks = num_blocks; es.newblocks = 0; es.buf = buf; es.err = 0; + es.flags = flags; es.zero_count = 0; if (fs->super->s_feature_incompat & EXT3_FEATURE_INCOMPAT_EXTENTS) { @@ -362,7 +379,12 @@ static errcode_t write_journal_inode(ext2_filsys fs, ext2_ino_t journal_ino, if ((retval = ext2fs_read_inode(fs, journal_ino, &inode))) goto errout; - inode.i_size += fs->blocksize * size; + inode_size = (unsigned long long)fs->blocksize * num_blocks; + inode.i_size = inode_size & 0xFFFFFFFF; + inode.i_size_high = (inode_size >> 32) & 0xFFFFFFFF; + if (inode.i_size_high) + fs->super->s_feature_ro_compat |= + EXT2_FEATURE_RO_COMPAT_LARGE_FILE; ext2fs_iblk_add_blocks(fs, &inode, es.newblocks); inode.i_mtime = inode.i_ctime = fs->now ? fs->now : time(0); inode.i_links_count = 1; @@ -373,12 +395,13 @@ static errcode_t write_journal_inode(ext2_filsys fs, ext2_ino_t journal_ino, retval = 0; memcpy(fs->super->s_jnl_blocks, inode.i_block, EXT2_N_BLOCKS*4); + fs->super->s_jnl_blocks[15] = inode.i_size_high; fs->super->s_jnl_blocks[16] = inode.i_size; fs->super->s_jnl_backup_type = EXT3_JNL_BACKUP_BLOCKS; ext2fs_mark_super_dirty(fs); errout: - ext2fs_zero_blocks2(0, 0, 0, 0, 0); + ext2fs_zero_blocks2(0, 0, 0, 0, 0); ext2fs_free_mem(&buf); return retval; } @@ -388,17 +411,17 @@ errout: * in the filesystem. For very small filesystems, it is not reasonable to * have a journal that fills more than half of the filesystem. */ -int ext2fs_default_journal_size(__u64 blocks) +int ext2fs_default_journal_size(__u64 num_blocks) { - if (blocks < 2048) + if (num_blocks < 2048) return -1; - if (blocks < 32768) + if (num_blocks < 32768) return (1024); - if (blocks < 256*1024) + if (num_blocks < 256*1024) return (4096); - if (blocks < 512*1024) + if (num_blocks < 512*1024) return (8192); - if (blocks < 1024*1024) + if (num_blocks < 1024*1024) return (16384); return 32768; } @@ -469,13 +492,13 @@ errcode_t ext2fs_add_journal_device(ext2_filsys fs, ext2_filsys journal_dev) * POSIX routines if the filesystem is mounted, or using direct I/O * functions if it is not. */ -errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t size, int flags) +errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t num_blocks, int flags) { errcode_t retval; ext2_ino_t journal_ino; struct stat st; char jfile[1024]; - int mount_flags; + int mount_flags, f; int fd = -1; if ((retval = ext2fs_check_mount_point(fs->device_name, &mount_flags, @@ -506,7 +529,14 @@ errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t size, int flags) if ((fd = open(jfile, O_CREAT|O_WRONLY, 0600)) < 0) return errno; - if ((retval = write_journal_file(fs, jfile, size, flags))) + /* Note that we can't do lazy journal initialization for mounted + * filesystems, since the zero writing is also allocating the + * journal blocks. We could use fallocate, but not all kernels + * support that, and creating a journal on a mounted ext2 + * filesystems is extremely rare these days... Ignore it. */ + flags &= ~EXT2_MKJOURNAL_LAZYINIT; + + if ((retval = write_journal_file(fs, jfile, num_blocks, flags))) goto errout; /* Get inode number of the journal file */ @@ -546,7 +576,7 @@ errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t size, int flags) } journal_ino = EXT2_JOURNAL_INO; if ((retval = write_journal_inode(fs, journal_ino, - size, flags))) + num_blocks, flags))) return retval; } @@ -569,7 +599,7 @@ main(int argc, char **argv) { errcode_t retval; char *device_name; - ext2_filsys fs; + ext2_filsys fs; if (argc < 2) { fprintf(stderr, "Usage: %s filesystem\n", argv[0]); diff --git a/libcustomext2fs/source/mmp.c b/libcustomext2fs/source/mmp.c new file mode 100644 index 00000000..72c349e2 --- /dev/null +++ b/libcustomext2fs/source/mmp.c @@ -0,0 +1,417 @@ +/* + * Helper functions for multiple mount protection (MMP). + * + * Copyright (C) 2011 Whamcloud, Inc. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Public + * License. + * %End-Header% + */ + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#include "config.h" +#if HAVE_UNISTD_H +#include +#endif +#include + +#include +#include +#include + +#include "ext2_fs.h" +#include "ext2fs.h" + +#undef _SC_PAGESIZE + +static int mmp_pagesize(void) +{ +#ifdef _SC_PAGESIZE + int sysval = sysconf(_SC_PAGESIZE); + if (sysval > 0) + return sysval; +#endif /* _SC_PAGESIZE */ +#ifdef HAVE_GETPAGESIZE + return getpagesize(); +#else + return 4096; +#endif +} + +#ifndef O_DIRECT +#define O_DIRECT 0 +#endif + +errcode_t ext2fs_mmp_read(ext2_filsys fs, blk64_t mmp_blk, void *buf) +{ + struct mmp_struct *mmp_cmp; + errcode_t retval = 0; + + if ((mmp_blk <= fs->super->s_first_data_block) || + (mmp_blk >= fs->super->s_blocks_count)) + return EXT2_ET_MMP_BAD_BLOCK; + + if (fs->mmp_cmp == NULL) { + /* O_DIRECT in linux 2.4: page aligned + * O_DIRECT in linux 2.6: sector aligned + * A filesystem cannot be created with blocksize < sector size, + * or with blocksize > page_size. */ + int bufsize = fs->blocksize; + + if (bufsize < mmp_pagesize()) + bufsize = mmp_pagesize(); + retval = ext2fs_get_memalign(bufsize, bufsize, &fs->mmp_cmp); + if (retval) + return retval; + } + + /* ext2fs_open() reserves fd0,1,2 to avoid stdio collision, so checking + * mmp_fd <= 0 is OK to validate that the fd is valid. This opens its + * own fd to read the MMP block to ensure that it is using O_DIRECT, + * regardless of how the io_manager is doing reads, to avoid caching of + * the MMP block by the io_manager or the VM. It needs to be fresh. */ + if (fs->mmp_fd <= 0) { + fs->mmp_fd = open(fs->device_name, O_RDWR | O_DIRECT); + if (fs->mmp_fd < 0) { + retval = EXT2_ET_MMP_OPEN_DIRECT; + goto out; + } + } + + if (ext2fs_llseek(fs->mmp_fd, mmp_blk * fs->blocksize, SEEK_SET) != + mmp_blk * fs->blocksize) { + retval = EXT2_ET_LLSEEK_FAILED; + goto out; + } + + if (read(fs->mmp_fd, fs->mmp_cmp, fs->blocksize) != fs->blocksize) { + retval = EXT2_ET_SHORT_READ; + goto out; + } + + mmp_cmp = fs->mmp_cmp; +#ifdef WORDS_BIGENDIAN + ext2fs_swap_mmp(mmp_cmp); +#endif + + if (buf != NULL && buf != fs->mmp_cmp) + memcpy(buf, fs->mmp_cmp, fs->blocksize); + + if (mmp_cmp->mmp_magic != EXT4_MMP_MAGIC) { + retval = EXT2_ET_MMP_MAGIC_INVALID; + goto out; + } + +out: + return retval; +} + +errcode_t ext2fs_mmp_write(ext2_filsys fs, blk64_t mmp_blk, void *buf) +{ + struct mmp_struct *mmp_s = buf; + struct timeval tv; + errcode_t retval = 0; + + gettimeofday(&tv, 0); + mmp_s->mmp_time = tv.tv_sec; + fs->mmp_last_written = tv.tv_sec; + + if (fs->super->s_mmp_block < fs->super->s_first_data_block || + fs->super->s_mmp_block > ext2fs_blocks_count(fs->super)) + return EXT2_ET_MMP_BAD_BLOCK; + +#ifdef WORDS_BIGENDIAN + ext2fs_swap_mmp(mmp_s); +#endif + + /* I was tempted to make this use O_DIRECT and the mmp_fd, but + * this caused no end of grief, while leaving it as-is works. */ + retval = io_channel_write_blk64(fs->io, mmp_blk, -fs->blocksize, buf); + +#ifdef WORDS_BIGENDIAN + ext2fs_swap_mmp(mmp_s); +#endif + + /* Make sure the block gets to disk quickly */ + io_channel_flush(fs->io); + return retval; +} + +#ifdef HAVE_SRANDOM +#define srand(x) srandom(x) +#define rand() random() +#endif + +unsigned ext2fs_mmp_new_seq() +{ + unsigned new_seq; + struct timeval tv; + + gettimeofday(&tv, 0); + srand((getpid() << 16) /*^ getuid()*/ ^ tv.tv_sec ^ tv.tv_usec); + + gettimeofday(&tv, 0); + /* Crank the random number generator a few times */ + for (new_seq = (tv.tv_sec ^ tv.tv_usec) & 0x1F; new_seq > 0; new_seq--) + rand(); + + do { + new_seq = rand(); + } while (new_seq > EXT4_MMP_SEQ_MAX); + + return new_seq; +} + +static errcode_t ext2fs_mmp_reset(ext2_filsys fs) +{ + struct mmp_struct *mmp_s = NULL; + errcode_t retval = 0; + + if (fs->mmp_buf == NULL) { + retval = ext2fs_get_mem(fs->blocksize, &fs->mmp_buf); + if (retval) + goto out; + } + + memset(fs->mmp_buf, 0, fs->blocksize); + mmp_s = fs->mmp_buf; + + mmp_s->mmp_magic = EXT4_MMP_MAGIC; + mmp_s->mmp_seq = EXT4_MMP_SEQ_CLEAN; + mmp_s->mmp_time = 0; +#if (0 && (_BSD_SOURCE || _XOPEN_SOURCE >= 500)) + gethostname(mmp_s->mmp_nodename, sizeof(mmp_s->mmp_nodename)); +#else + mmp_s->mmp_nodename[0] = '\0'; +#endif + strncpy(mmp_s->mmp_bdevname, fs->device_name, + sizeof(mmp_s->mmp_bdevname)); + + mmp_s->mmp_check_interval = fs->super->s_mmp_update_interval; + if (mmp_s->mmp_check_interval < EXT4_MMP_MIN_CHECK_INTERVAL) + mmp_s->mmp_check_interval = EXT4_MMP_MIN_CHECK_INTERVAL; + + retval = ext2fs_mmp_write(fs, fs->super->s_mmp_block, fs->mmp_buf); +out: + return retval; +} + +errcode_t ext2fs_mmp_clear(ext2_filsys fs) +{ + errcode_t retval = 0; + + if (!(fs->flags & EXT2_FLAG_RW)) + return EXT2_ET_RO_FILSYS; + + retval = ext2fs_mmp_reset(fs); + + return retval; +} + +errcode_t ext2fs_mmp_init(ext2_filsys fs) +{ + struct ext2_super_block *sb = fs->super; + blk64_t mmp_block; + errcode_t retval; + + if (sb->s_mmp_update_interval == 0) + sb->s_mmp_update_interval = EXT4_MMP_UPDATE_INTERVAL; + /* This is probably excessively large, but who knows? */ + else if (sb->s_mmp_update_interval > EXT4_MMP_MAX_UPDATE_INTERVAL) + return EXT2_ET_INVALID_ARGUMENT; + + if (fs->mmp_buf == NULL) { + retval = ext2fs_get_mem(fs->blocksize, &fs->mmp_buf); + if (retval) + goto out; + } + + retval = ext2fs_alloc_block2(fs, 0, fs->mmp_buf, &mmp_block); + if (retval) + goto out; + + sb->s_mmp_block = mmp_block; + + retval = ext2fs_mmp_reset(fs); + if (retval) + goto out; + +out: + return retval; +} + +/* + * Make sure that the fs is not mounted or being fsck'ed while opening the fs. + */ +errcode_t ext2fs_mmp_start(ext2_filsys fs) +{ + struct mmp_struct *mmp_s; + unsigned seq; + unsigned int mmp_check_interval; + errcode_t retval = 0; + + if (fs->mmp_buf == NULL) { + retval = ext2fs_get_mem(fs->blocksize, &fs->mmp_buf); + if (retval) + goto mmp_error; + } + + retval = ext2fs_mmp_read(fs, fs->super->s_mmp_block, fs->mmp_buf); + if (retval) + goto mmp_error; + + mmp_s = fs->mmp_buf; + + mmp_check_interval = fs->super->s_mmp_update_interval; + if (mmp_check_interval < EXT4_MMP_MIN_CHECK_INTERVAL) + mmp_check_interval = EXT4_MMP_MIN_CHECK_INTERVAL; + + seq = mmp_s->mmp_seq; + if (seq == EXT4_MMP_SEQ_CLEAN) + goto clean_seq; + if (seq == EXT4_MMP_SEQ_FSCK) { + retval = EXT2_ET_MMP_FSCK_ON; + goto mmp_error; + } + + if (seq > EXT4_MMP_SEQ_FSCK) { + retval = EXT2_ET_MMP_UNKNOWN_SEQ; + goto mmp_error; + } + + /* + * If check_interval in MMP block is larger, use that instead of + * check_interval from the superblock. + */ + if (mmp_s->mmp_check_interval > mmp_check_interval) + mmp_check_interval = mmp_s->mmp_check_interval; + + sleep(2 * mmp_check_interval + 1); + + retval = ext2fs_mmp_read(fs, fs->super->s_mmp_block, fs->mmp_buf); + if (retval) + goto mmp_error; + + if (seq != mmp_s->mmp_seq) { + retval = EXT2_ET_MMP_FAILED; + goto mmp_error; + } + +clean_seq: + if (!(fs->flags & EXT2_FLAG_RW)) + goto mmp_error; + + mmp_s->mmp_seq = seq = ext2fs_mmp_new_seq(); +#if (0 && (_BSD_SOURCE || _XOPEN_SOURCE >= 500)) + gethostname(mmp_s->mmp_nodename, sizeof(mmp_s->mmp_nodename)); +#else + strcpy(mmp_s->mmp_nodename, "unknown host"); +#endif + strncpy(mmp_s->mmp_bdevname, fs->device_name, + sizeof(mmp_s->mmp_bdevname)); + + retval = ext2fs_mmp_write(fs, fs->super->s_mmp_block, fs->mmp_buf); + if (retval) + goto mmp_error; + + sleep(2 * mmp_check_interval + 1); + + retval = ext2fs_mmp_read(fs, fs->super->s_mmp_block, fs->mmp_buf); + if (retval) + goto mmp_error; + + if (seq != mmp_s->mmp_seq) { + retval = EXT2_ET_MMP_FAILED; + goto mmp_error; + } + + mmp_s->mmp_seq = EXT4_MMP_SEQ_FSCK; + retval = ext2fs_mmp_write(fs, fs->super->s_mmp_block, fs->mmp_buf); + if (retval) + goto mmp_error; + + return 0; + +mmp_error: + return retval; +} + +/* + * Clear the MMP usage in the filesystem. If this function returns an + * error EXT2_ET_MMP_CHANGE_ABORT it means the filesystem was modified + * by some other process while in use, and changes should be dropped, or + * risk filesystem corruption. + */ +errcode_t ext2fs_mmp_stop(ext2_filsys fs) +{ + struct mmp_struct *mmp, *mmp_cmp; + errcode_t retval = 0; + + if (!(fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_MMP) || + !(fs->flags & EXT2_FLAG_RW) || (fs->flags & EXT2_FLAG_SKIP_MMP)) + goto mmp_error; + + retval = ext2fs_mmp_read(fs, fs->super->s_mmp_block, fs->mmp_buf); + if (retval) + goto mmp_error; + + /* Check if the MMP block is not changed. */ + mmp = fs->mmp_buf; + mmp_cmp = fs->mmp_cmp; + if (memcmp(mmp, mmp_cmp, sizeof(*mmp_cmp))) { + retval = EXT2_ET_MMP_CHANGE_ABORT; + goto mmp_error; + } + + mmp_cmp->mmp_seq = EXT4_MMP_SEQ_CLEAN; + retval = ext2fs_mmp_write(fs, fs->super->s_mmp_block, fs->mmp_cmp); + +mmp_error: + if (fs->mmp_fd > 0) { + close(fs->mmp_fd); + fs->mmp_fd = -1; + } + + return retval; +} + +#define EXT2_MIN_MMP_UPDATE_INTERVAL 60 + +/* + * Update the on-disk mmp buffer, after checking that it hasn't been changed. + */ +errcode_t ext2fs_mmp_update(ext2_filsys fs) +{ + struct mmp_struct *mmp, *mmp_cmp; + struct timeval tv; + errcode_t retval = 0; + + if (!(fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_MMP) || + !(fs->flags & EXT2_FLAG_RW) || (fs->flags & EXT2_FLAG_SKIP_MMP)) + return 0; + + gettimeofday(&tv, 0); + if (tv.tv_sec - fs->mmp_last_written < EXT2_MIN_MMP_UPDATE_INTERVAL) + return 0; + + retval = ext2fs_mmp_read(fs, fs->super->s_mmp_block, NULL); + if (retval) + goto mmp_error; + + mmp = fs->mmp_buf; + mmp_cmp = fs->mmp_cmp; + + if (memcmp(mmp, mmp_cmp, sizeof(*mmp_cmp))) + return EXT2_ET_MMP_CHANGE_ABORT; + + mmp->mmp_time = tv.tv_sec; + mmp->mmp_seq = EXT4_MMP_SEQ_FSCK; + retval = ext2fs_mmp_write(fs, fs->super->s_mmp_block, fs->mmp_buf); + +mmp_error: + return retval; +} diff --git a/libcustomext2fs/source/namei.c b/libcustomext2fs/source/namei.c index bc0ae61d..6bbb1240 100644 --- a/libcustomext2fs/source/namei.c +++ b/libcustomext2fs/source/namei.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H diff --git a/libcustomext2fs/source/native.c b/libcustomext2fs/source/native.c index c71a95ee..ba3e0c8e 100644 --- a/libcustomext2fs/source/native.c +++ b/libcustomext2fs/source/native.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #include "ext2_fs.h" diff --git a/libcustomext2fs/source/newdir.c b/libcustomext2fs/source/newdir.c index 6bc57194..b0a1e476 100644 --- a/libcustomext2fs/source/newdir.c +++ b/libcustomext2fs/source/newdir.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H diff --git a/libcustomext2fs/source/openfs.c b/libcustomext2fs/source/openfs.c index eb04d025..e09952eb 100644 --- a/libcustomext2fs/source/openfs.c +++ b/libcustomext2fs/source/openfs.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H @@ -22,6 +23,9 @@ #if HAVE_SYS_TYPES_H #include #endif +#ifdef HAVE_ERRNO_H +#include +#endif #include "ext2_fs.h" @@ -65,7 +69,7 @@ blk_t ext2fs_descriptor_block_loc(ext2_filsys fs, blk_t group_block, dgrp_t i) } errcode_t ext2fs_open(const char *name, int flags, int superblock, - unsigned int block_size, io_channel * io, + unsigned int block_size, io_channel io, ext2_filsys *ret_fs) { return ext2fs_open2(name, 0, flags, superblock, block_size, @@ -82,18 +86,19 @@ errcode_t ext2fs_open(const char *name, int flags, int superblock, * EXT2_FLAG_FORCE - Open the filesystem even if some of the * features aren't supported. * EXT2_FLAG_JOURNAL_DEV_OK - Open an ext3 journal device + * EXT2_FLAG_SKIP_MMP - Open without multi-mount protection check. */ errcode_t ext2fs_open2(const char *name, const char *io_options, int flags, int superblock, - unsigned int block_size, io_channel * io, + unsigned int block_size, io_channel io, ext2_filsys *ret_fs) { ext2_filsys fs; - io_manager manager = (*io)->manager; + io_manager manager = io->manager; errcode_t retval; unsigned long i, first_meta_bg; __u32 features; - int groups_per_block, blocks_per_group, io_flags; + unsigned int groups_per_block, blocks_per_group, io_flags; blk64_t group_block, blk; char *dest, *cp; #ifdef WORDS_BIGENDIAN @@ -109,7 +114,7 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, memset(fs, 0, sizeof(struct struct_ext2_filsys)); fs->magic = EXT2_ET_MAGIC_EXT2FS_FILSYS; - fs->io = *io; + fs->io = io; fs->flags = flags; /* don't overwrite sb backups unless flag is explicitly cleared */ fs->flags |= EXT2_FLAG_MASTER_SB_ONLY; @@ -216,7 +221,7 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, features = fs->super->s_feature_incompat; #ifdef EXT2_LIB_SOFTSUPP_INCOMPAT if (flags & EXT2_FLAG_SOFTSUPP_FEATURES) - features &= !EXT2_LIB_SOFTSUPP_INCOMPAT; + features &= ~EXT2_LIB_SOFTSUPP_INCOMPAT; #endif if (features & ~EXT2_LIB_FEATURE_INCOMPAT_SUPP) { retval = EXT2_ET_UNSUPP_FEATURE; @@ -226,7 +231,7 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, features = fs->super->s_feature_ro_compat; #ifdef EXT2_LIB_SOFTSUPP_RO_COMPAT if (flags & EXT2_FLAG_SOFTSUPP_FEATURES) - features &= !EXT2_LIB_SOFTSUPP_RO_COMPAT; + features &= ~EXT2_LIB_SOFTSUPP_RO_COMPAT; #endif if ((flags & EXT2_FLAG_RW) && (features & ~EXT2_LIB_FEATURE_RO_COMPAT_SUPP)) { @@ -247,12 +252,24 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, retval = EXT2_ET_CORRUPT_SUPERBLOCK; goto cleanup; } - fs->blocksize = EXT2_BLOCK_SIZE(fs->super); + if (!EXT2_HAS_RO_COMPAT_FEATURE(fs->super, + EXT4_FEATURE_RO_COMPAT_BIGALLOC) && + (fs->super->s_log_block_size != fs->super->s_log_cluster_size)) { + retval = EXT2_ET_CORRUPT_SUPERBLOCK; + goto cleanup; + } + fs->fragsize = fs->blocksize = EXT2_BLOCK_SIZE(fs->super); if (EXT2_INODE_SIZE(fs->super) < EXT2_GOOD_OLD_INODE_SIZE) { retval = EXT2_ET_CORRUPT_SUPERBLOCK; goto cleanup; } - fs->clustersize = EXT2_CLUSTER_SIZE(fs->super); + fs->cluster_ratio_bits = fs->super->s_log_cluster_size - + fs->super->s_log_block_size; + if (EXT2_BLOCKS_PER_GROUP(fs->super) != + EXT2_CLUSTERS_PER_GROUP(fs->super) << fs->cluster_ratio_bits) { + retval = EXT2_ET_CORRUPT_SUPERBLOCK; + goto cleanup; + } fs->inode_blocks_per_group = ((EXT2_INODES_PER_GROUP(fs->super) * EXT2_INODE_SIZE(fs->super) + EXT2_BLOCK_SIZE(fs->super) - 1) / @@ -312,6 +329,8 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, goto cleanup; if (!group_block) group_block = fs->super->s_first_data_block; + if (group_block == 0 && fs->blocksize == 1024) + group_block = 1; /* Deal with 1024 blocksize && bigalloc */ dest = (char *) fs->group_desc; groups_per_block = EXT2_DESC_PER_BLOCK(fs->super); if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) @@ -367,6 +386,18 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, fs->flags &= ~EXT2_FLAG_NOFREE_ON_ERROR; *ret_fs = fs; + + if ((fs->super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_MMP) && + !(flags & EXT2_FLAG_SKIP_MMP) && + (flags & (EXT2_FLAG_RW | EXT2_FLAG_EXCLUSIVE))) { + retval = ext2fs_mmp_start(fs); + if (retval) { + fs->flags |= EXT2_FLAG_SKIP_MMP; /* just do cleanup */ + ext2fs_mmp_stop(fs); + goto cleanup; + } + } + return 0; cleanup: if (flags & EXT2_FLAG_NOFREE_ON_ERROR) diff --git a/libcustomext2fs/source/progress.c b/libcustomext2fs/source/progress.c index 335b98b5..37d15096 100644 --- a/libcustomext2fs/source/progress.c +++ b/libcustomext2fs/source/progress.c @@ -10,6 +10,7 @@ * %End-Header% */ +#include "config.h" #include "ext2fs.h" #include "ext2fsP.h" @@ -68,7 +69,7 @@ void ext2fs_numeric_progress_update(ext2_filsys fs, if (progress->skip_progress) return; - fprintf(stdout, "%*llu/%*llu", progress->log_max, val, + printf("%*llu/%*llu", progress->log_max, val, progress->log_max, progress->max); fprintf(stdout, "%.*s", (2*progress->log_max)+1, backspaces); } diff --git a/libcustomext2fs/source/punch.c b/libcustomext2fs/source/punch.c index 8c6ec549..b53653a0 100644 --- a/libcustomext2fs/source/punch.c +++ b/libcustomext2fs/source/punch.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H @@ -203,7 +204,7 @@ static errcode_t ext2fs_punch_extent(ext2_filsys fs, ext2_ino_t ino, if (start <= extent.e_lblk) { if (end < extent.e_lblk) goto next_extent; - dbg_printf("Case #1\n"); + dbg_printf("Case #%d\n", 1); /* Start of deleted region before extent; adjust beginning of extent */ free_start = extent.e_pblk; @@ -219,7 +220,7 @@ static errcode_t ext2fs_punch_extent(ext2_filsys fs, ext2_ino_t ino, break; /* End of deleted region after extent; adjust end of extent */ - dbg_printf("Case #2\n"); + dbg_printf("Case #%d\n", 2); newlen = start - extent.e_lblk; free_start = extent.e_pblk + newlen; free_count = extent.e_len - newlen; @@ -227,7 +228,7 @@ static errcode_t ext2fs_punch_extent(ext2_filsys fs, ext2_ino_t ino, } else { struct ext2fs_extent newex; - dbg_printf("Case #3\n"); + dbg_printf("Case #%d\n", 3); /* The hard case; we need to split the extent */ newex.e_pblk = extent.e_pblk + (end + 1 - extent.e_lblk); @@ -255,7 +256,7 @@ static errcode_t ext2fs_punch_extent(ext2_filsys fs, ext2_ino_t ino, dbg_print_extent("replacing", &extent); retval = ext2fs_extent_replace(handle, 0, &extent); } else { - dbg_printf("deleting current extent\n"); + dbg_printf("deleting current extent%s\n", ""); retval = ext2fs_extent_delete(handle, 0); } if (retval) diff --git a/libcustomext2fs/source/read_bb.c b/libcustomext2fs/source/read_bb.c index e5d63227..b5a0d7b4 100644 --- a/libcustomext2fs/source/read_bb.c +++ b/libcustomext2fs/source/read_bb.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H diff --git a/libcustomext2fs/source/read_bb_file.c b/libcustomext2fs/source/read_bb_file.c index 25454a87..7d7bb7aa 100644 --- a/libcustomext2fs/source/read_bb_file.c +++ b/libcustomext2fs/source/read_bb_file.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H diff --git a/libcustomext2fs/source/res_gdt.c b/libcustomext2fs/source/res_gdt.c index 0d988428..6449228c 100644 --- a/libcustomext2fs/source/res_gdt.c +++ b/libcustomext2fs/source/res_gdt.c @@ -10,6 +10,7 @@ * %End-Header% */ +#include "config.h" #include #include #include @@ -63,11 +64,11 @@ errcode_t ext2fs_create_resize_inode(ext2_filsys fs) errcode_t retval, retval2; struct ext2_super_block *sb; struct ext2_inode inode; - __u32 *dindir_buf = 0, *gdt_buf = 0; + __u32 *dindir_buf, *gdt_buf; unsigned long long apb, inode_size; /* FIXME-64 - can't deal with extents */ blk_t dindir_blk, rsv_off, gdt_off, gdt_blk; - int dindir_dirty = 0, inode_dirty = 0; + int dindir_dirty = 0, inode_dirty = 0, sb_blk = 0; EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); @@ -75,13 +76,22 @@ errcode_t ext2fs_create_resize_inode(ext2_filsys fs) retval = ext2fs_get_array(2, fs->blocksize, &dindir_buf); if (retval) - goto out_free; + return retval; gdt_buf = (__u32 *)((char *)dindir_buf + fs->blocksize); retval = ext2fs_read_inode(fs, EXT2_RESIZE_INO, &inode); if (retval) goto out_free; + /* + * File systems with a blocksize of 1024 and bigalloc have + * sb->s_first_data_block of 0; yet the superblock is still at + * block #1. We compensate for it here. + */ + sb_blk = sb->s_first_data_block; + if (fs->blocksize == 1024 && sb_blk == 0) + sb_blk = 1; + /* Maximum possible file size (we donly use the dindirect blocks) */ apb = EXT2_ADDR_PER_BLOCK(sb); if ((dindir_blk = inode.i_block[EXT2_DIND_BLOCK])) { @@ -92,7 +102,7 @@ errcode_t ext2fs_create_resize_inode(ext2_filsys fs) if (retval) goto out_inode; } else { - blk_t goal = sb->s_first_data_block + fs->desc_blocks + + blk_t goal = sb_blk + fs->desc_blocks + sb->s_reserved_gdt_blocks + 2 + fs->inode_blocks_per_group; @@ -120,7 +130,7 @@ errcode_t ext2fs_create_resize_inode(ext2_filsys fs) } for (rsv_off = 0, gdt_off = fs->desc_blocks, - gdt_blk = sb->s_first_data_block + 1 + fs->desc_blocks; + gdt_blk = sb_blk + 1 + fs->desc_blocks; rsv_off < sb->s_reserved_gdt_blocks; rsv_off++, gdt_off++, gdt_blk++) { unsigned int three = 1, five = 5, seven = 7; diff --git a/libcustomext2fs/source/rw_bitmaps.c b/libcustomext2fs/source/rw_bitmaps.c index 7b74b421..1d5f7b2b 100644 --- a/libcustomext2fs/source/rw_bitmaps.c +++ b/libcustomext2fs/source/rw_bitmaps.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H @@ -34,10 +35,10 @@ static errcode_t write_bitmaps(ext2_filsys fs, int do_inode, int do_block) int block_nbytes, inode_nbytes; unsigned int nbits; errcode_t retval; - char *block_buf = 0, *inode_buf = 0; + char *block_buf = NULL, *inode_buf = NULL; int csum_flag = 0; blk64_t blk; - blk64_t blk_itr = fs->super->s_first_data_block; + blk64_t blk_itr = EXT2FS_B2C(fs, fs->super->s_first_data_block); ext2_ino_t ino_itr = 1; EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); @@ -51,11 +52,11 @@ static errcode_t write_bitmaps(ext2_filsys fs, int do_inode, int do_block) inode_nbytes = block_nbytes = 0; if (do_block) { - block_nbytes = EXT2_BLOCKS_PER_GROUP(fs->super) / 8; + block_nbytes = EXT2_CLUSTERS_PER_GROUP(fs->super) / 8; retval = ext2fs_get_memalign(fs->blocksize, fs->blocksize, &block_buf); if (retval) - return retval; + goto errout; memset(block_buf, 0xff, fs->blocksize); } if (do_inode) { @@ -64,7 +65,7 @@ static errcode_t write_bitmaps(ext2_filsys fs, int do_inode, int do_block) retval = ext2fs_get_memalign(fs->blocksize, fs->blocksize, &inode_buf); if (retval) - return retval; + goto errout; memset(inode_buf, 0xff, fs->blocksize); } @@ -79,13 +80,14 @@ static errcode_t write_bitmaps(ext2_filsys fs, int do_inode, int do_block) retval = ext2fs_get_block_bitmap_range2(fs->block_map, blk_itr, block_nbytes << 3, block_buf); if (retval) - return retval; + goto errout; if (i == fs->group_desc_count - 1) { /* Force bitmap padding for the last group */ - nbits = ((ext2fs_blocks_count(fs->super) + nbits = EXT2FS_NUM_B2C(fs, + ((ext2fs_blocks_count(fs->super) - (__u64) fs->super->s_first_data_block) - % (__u64) EXT2_BLOCKS_PER_GROUP(fs->super)); + % (__u64) EXT2_BLOCKS_PER_GROUP(fs->super))); if (nbits) for (j = nbits; j < fs->blocksize * 8; j++) ext2fs_set_bit(j, block_buf); @@ -94,8 +96,10 @@ static errcode_t write_bitmaps(ext2_filsys fs, int do_inode, int do_block) if (blk) { retval = io_channel_write_blk64(fs->io, blk, 1, block_buf); - if (retval) - return EXT2_ET_BLOCK_BITMAP_WRITE; + if (retval) { + retval = EXT2_ET_BLOCK_BITMAP_WRITE; + goto errout; + } } skip_this_block_bitmap: blk_itr += block_nbytes << 3; @@ -111,14 +115,16 @@ static errcode_t write_bitmaps(ext2_filsys fs, int do_inode, int do_block) retval = ext2fs_get_inode_bitmap_range2(fs->inode_map, ino_itr, inode_nbytes << 3, inode_buf); if (retval) - return retval; + goto errout; blk = ext2fs_inode_bitmap_loc(fs, i); if (blk) { retval = io_channel_write_blk64(fs->io, blk, 1, inode_buf); - if (retval) - return EXT2_ET_INODE_BITMAP_WRITE; + if (retval) { + retval = EXT2_ET_INODE_BITMAP_WRITE; + goto errout; + } } skip_this_inode_bitmap: ino_itr += inode_nbytes << 3; @@ -133,6 +139,12 @@ static errcode_t write_bitmaps(ext2_filsys fs, int do_inode, int do_block) ext2fs_free_mem(&inode_buf); } return 0; +errout: + if (inode_buf) + ext2fs_free_mem(&inode_buf); + if (block_buf) + ext2fs_free_mem(&block_buf); + return retval; } static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block) @@ -141,13 +153,13 @@ static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block) char *block_bitmap = 0, *inode_bitmap = 0; char *buf; errcode_t retval; - int block_nbytes = EXT2_BLOCKS_PER_GROUP(fs->super) / 8; + int block_nbytes = EXT2_CLUSTERS_PER_GROUP(fs->super) / 8; int inode_nbytes = EXT2_INODES_PER_GROUP(fs->super) / 8; int csum_flag = 0; int do_image = fs->flags & EXT2_FLAG_IMAGE_FILE; unsigned int cnt; blk64_t blk; - blk64_t blk_itr = fs->super->s_first_data_block; + blk64_t blk_itr = EXT2FS_B2C(fs, fs->super->s_first_data_block); blk64_t blk_cnt; ext2_ino_t ino_itr = 1; ext2_ino_t ino_cnt; @@ -219,7 +231,7 @@ static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block) } blk = (fs->image_header->offset_blockmap / fs->blocksize); - blk_cnt = (blk64_t)EXT2_BLOCKS_PER_GROUP(fs->super) * + blk_cnt = (blk64_t)EXT2_CLUSTERS_PER_GROUP(fs->super) * fs->group_desc_count; while (block_nbytes > 0) { retval = io_channel_read_blk64(fs->image_io, blk++, diff --git a/libcustomext2fs/source/sparse.c b/libcustomext2fs/source/sparse.c index 15ded0ae..96b24178 100644 --- a/libcustomext2fs/source/sparse.c +++ b/libcustomext2fs/source/sparse.c @@ -10,6 +10,7 @@ * %End-Header% */ +#include "config.h" #include #include "ext2_fs.h" diff --git a/libcustomext2fs/source/swapfs.c b/libcustomext2fs/source/swapfs.c index b856a097..24441e0c 100644 --- a/libcustomext2fs/source/swapfs.c +++ b/libcustomext2fs/source/swapfs.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #if HAVE_UNISTD_H #include @@ -70,6 +71,8 @@ void ext2fs_swap_super(struct ext2_super_block * sb) sb->s_min_extra_isize = ext2fs_swab16(sb->s_min_extra_isize); sb->s_want_extra_isize = ext2fs_swab16(sb->s_want_extra_isize); sb->s_flags = ext2fs_swab32(sb->s_flags); + sb->s_mmp_update_interval = ext2fs_swab16(sb->s_mmp_update_interval); + sb->s_mmp_block = ext2fs_swab64(sb->s_mmp_block); sb->s_kbytes_written = ext2fs_swab64(sb->s_kbytes_written); sb->s_snapshot_inum = ext2fs_swab32(sb->s_snapshot_inum); sb->s_snapshot_id = ext2fs_swab32(sb->s_snapshot_id); @@ -78,21 +81,23 @@ void ext2fs_swap_super(struct ext2_super_block * sb) sb->s_snapshot_list = ext2fs_swab32(sb->s_snapshot_list); sb->s_usr_quota_inum = ext2fs_swab32(sb->s_usr_quota_inum); sb->s_grp_quota_inum = ext2fs_swab32(sb->s_grp_quota_inum); + sb->s_overhead_blocks = ext2fs_swab32(sb->s_overhead_blocks); + sb->s_checksum = ext2fs_swab32(sb->s_checksum); for (i=0; i < 4; i++) sb->s_hash_seed[i] = ext2fs_swab32(sb->s_hash_seed[i]); /* if journal backup is for a valid extent-based journal... */ - if (!ext2fs_extent_header_verify(sb->s_jnl_blocks, - sizeof(sb->s_jnl_blocks))) { - /* ... swap only the journal i_size */ - sb->s_jnl_blocks[16] = ext2fs_swab32(sb->s_jnl_blocks[16]); - /* and the extent data is not swapped on read */ - return; + if (ext2fs_extent_header_verify(sb->s_jnl_blocks, + sizeof(sb->s_jnl_blocks)) == 0) { + /* ... swap only the journal i_size and i_size_high, + * and the extent data is not swapped on read */ + i = 15; + } else { + /* direct/indirect journal: swap it all */ + i = 0; } - - /* direct/indirect journal: swap it all */ - for (i=0; i < 17; i++) + for (; i < 17; i++) sb->s_jnl_blocks[i] = ext2fs_swab32(sb->s_jnl_blocks[i]); } @@ -106,6 +111,11 @@ void ext2fs_swap_group_desc2(ext2_filsys fs, struct ext2_group_desc *gdp) gdp->bg_free_inodes_count = ext2fs_swab16(gdp->bg_free_inodes_count); gdp->bg_used_dirs_count = ext2fs_swab16(gdp->bg_used_dirs_count); gdp->bg_flags = ext2fs_swab16(gdp->bg_flags); + gdp->bg_exclude_bitmap_lo = ext2fs_swab32(gdp->bg_exclude_bitmap_lo); + gdp->bg_block_bitmap_csum_lo = + ext2fs_swab16(gdp->bg_block_bitmap_csum_lo); + gdp->bg_inode_bitmap_csum_lo = + ext2fs_swab16(gdp->bg_inode_bitmap_csum_lo); gdp->bg_itable_unused = ext2fs_swab16(gdp->bg_itable_unused); gdp->bg_checksum = ext2fs_swab16(gdp->bg_checksum); /* If we're 32-bit, we're done */ @@ -125,11 +135,16 @@ void ext2fs_swap_group_desc2(ext2_filsys fs, struct ext2_group_desc *gdp) gdp4->bg_used_dirs_count_hi = ext2fs_swab16(gdp4->bg_used_dirs_count_hi); gdp4->bg_itable_unused_hi = ext2fs_swab16(gdp4->bg_itable_unused_hi); + gdp4->bg_exclude_bitmap_hi = ext2fs_swab16(gdp4->bg_exclude_bitmap_hi); + gdp4->bg_block_bitmap_csum_hi = + ext2fs_swab16(gdp4->bg_block_bitmap_csum_hi); + gdp4->bg_inode_bitmap_csum_hi = + ext2fs_swab16(gdp4->bg_inode_bitmap_csum_hi); } void ext2fs_swap_group_desc(struct ext2_group_desc *gdp) { - return ext2fs_swap_group_desc2(0, gdp); + ext2fs_swap_group_desc2(0, gdp); } @@ -244,8 +259,8 @@ void ext2fs_swap_inode_full(ext2_filsys fs, struct ext2_inode_large *t, ext2fs_swab16 (f->osd2.linux2.l_i_uid_high); t->osd2.linux2.l_i_gid_high = ext2fs_swab16 (f->osd2.linux2.l_i_gid_high); - t->osd2.linux2.l_i_reserved2 = - ext2fs_swab32(f->osd2.linux2.l_i_reserved2); + t->osd2.linux2.l_i_checksum_lo = + ext2fs_swab16(f->osd2.linux2.l_i_checksum_lo); break; case EXT2_OS_HURD: t->osd1.hurd1.h_i_translator = @@ -279,6 +294,21 @@ void ext2fs_swap_inode_full(ext2_filsys fs, struct ext2_inode_large *t, return; } + if (extra_isize >= 4) + t->i_checksum_hi = ext2fs_swab16(f->i_checksum_hi); + if (extra_isize >= 8) + t->i_ctime_extra = ext2fs_swab32(f->i_ctime_extra); + if (extra_isize >= 12) + t->i_mtime_extra = ext2fs_swab32(f->i_mtime_extra); + if (extra_isize >= 16) + t->i_atime_extra = ext2fs_swab32(f->i_atime_extra); + if (extra_isize >= 20) + t->i_crtime = ext2fs_swab32(f->i_crtime); + if (extra_isize >= 24) + t->i_crtime_extra = ext2fs_swab32(f->i_crtime_extra); + if (extra_isize >= 28) + t->i_version_hi = ext2fs_swab32(f->i_version_hi); + i = sizeof(struct ext2_inode) + extra_isize + sizeof(__u32); if (bufsize < (int) i) return; /* no space for EA magic */ @@ -312,4 +342,12 @@ void ext2fs_swap_inode(ext2_filsys fs, struct ext2_inode *t, sizeof(struct ext2_inode)); } +void ext2fs_swap_mmp(struct mmp_struct *mmp) +{ + mmp->mmp_magic = ext2fs_swab32(mmp->mmp_magic); + mmp->mmp_seq = ext2fs_swab32(mmp->mmp_seq); + mmp->mmp_time = ext2fs_swab64(mmp->mmp_time); + mmp->mmp_check_interval = ext2fs_swab16(mmp->mmp_check_interval); +} + #endif diff --git a/libcustomext2fs/source/tdb.c b/libcustomext2fs/source/tdb.c index 0550f468..8fe66891 100644 --- a/libcustomext2fs/source/tdb.c +++ b/libcustomext2fs/source/tdb.c @@ -38,6 +38,7 @@ Last Changed Date: 2007-06-22 13:36:10 -0400 (Fri, 22 Jun 2007) #endif #define _XOPEN_SOURCE 600 +#include "config.h" #include #include #include diff --git a/libcustomext2fs/source/unlink.c b/libcustomext2fs/source/unlink.c index 7ffeb9e8..d2d31cc4 100644 --- a/libcustomext2fs/source/unlink.c +++ b/libcustomext2fs/source/unlink.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H diff --git a/libcustomext2fs/source/valid_blk.c b/libcustomext2fs/source/valid_blk.c index ec3edd88..895e36ef 100644 --- a/libcustomext2fs/source/valid_blk.c +++ b/libcustomext2fs/source/valid_blk.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #if HAVE_UNISTD_H #include @@ -23,7 +24,7 @@ * This function returns 1 if the inode's block entries actually * contain block entries. */ -int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode) +int ext2fs_inode_has_valid_blocks2(ext2_filsys fs, struct ext2_inode *inode) { /* * Only directories, regular files, and some symbolic links @@ -38,7 +39,7 @@ int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode) * target is stored in the block entries. */ if (LINUX_S_ISLNK (inode->i_mode)) { - if (ext2fs_file_acl_block(inode) == 0) { + if (ext2fs_file_acl_block(fs, inode) == 0) { /* With no EA block, we can rely on i_blocks */ if (inode->i_blocks == 0) return 0; @@ -53,3 +54,8 @@ int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode) } return 1; } + +int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode) +{ + return ext2fs_inode_has_valid_blocks2(NULL, inode); +} diff --git a/libcustomext2fs/source/version.c b/libcustomext2fs/source/version.c index e7f223bf..667c0c89 100644 --- a/libcustomext2fs/source/version.c +++ b/libcustomext2fs/source/version.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #if HAVE_UNISTD_H #include #endif @@ -19,6 +20,7 @@ #include "ext2_fs.h" #include "ext2fs.h" + static const char *lib_version = ""; static const char *lib_date = ""; diff --git a/libcustomext2fs/source/write_bb_file.c b/libcustomext2fs/source/write_bb_file.c index 70bcf08e..58343408 100644 --- a/libcustomext2fs/source/write_bb_file.c +++ b/libcustomext2fs/source/write_bb_file.c @@ -9,6 +9,7 @@ * %End-Header% */ +#include "config.h" #include #include "ext2_fs.h"