Journal Checksums - e2fsprogs
PATCH 2/2 Journal Checksums - e2fsprogs
Hi,
This patch has been created on top of the e2fsprogs-1.39-WIP and number
of other patches sent to list. But as it contains changes to recovery part, should be able to apply safely on top of e2fsprogs-1.39-WIP.
Signed-off-by Andreas Dilger <[email protected]>
Signed-off-by Girish Shilamkar <[email protected]>
diffstat patches/e2fsprogs-journal_chksum.patch
e2fsck/recovery.c | 124 ++++++++++- lib/ext2fs/Makefile.in | 4 lib/ext2fs/crc32.c | 522 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/ext2fs/crc32.h | 30 ++ lib/ext2fs/crc32_user.h | 46 ++++ lib/ext2fs/crc32defs.h | 32 ++ lib/ext2fs/crc32table.h | 135 ++++++++++++ lib/ext2fs/kernel-jbd.h | 33 ++- 8 files changed, 916 insertions(+), 10 deletions(-)
lib/ext2fs/kernel-jbd.h +30 -3
@@ -108,7 +108,29 @@ typedef struct journal_header_s__u32 h_sequence; } journal_header_t; +/* +* Checksum types. +*/ +#define JFS_CRC32_CHKSUM 1 +#define JFS_MD5_CHKSUM 2 +#define JFS_SHA1_CHKSUM 3 + +#define JFS_CRC32_CHKSUM_SIZE 4 +#define JFS_CHECKSUM_BYTES (32 / sizeof(__u32)) +/* +* Commit block header for storing transactional checksums: +*/ +struct commit_header +{ +__u32 h_magic; +__u32 h_blocktype; +__u32 h_sequence; +unsigned char h_chksum_type; +unsigned char h_chksum_size; +unsigned char h_padding[2 ]; +__u32 h_chksum[JFS_CHECKSUM_BYTES ]; +};/* * The block tag: used to describe a single buffer in the journal */
@@ -194,12 +216,17 @@ typedef struct journal_superblock_s ((j)->j_format_version >=2 && \ ((j)->j_superblock->s_feature_incompat & cpu_to_be32((mask)))) -#define JFS_FEATURE_INCOMPAT_REVOKE 0x00000001 +#define JFS_FEATURE_COMPAT_CHECKSUM 0x00000001 + +#define JFS_FEATURE_INCOMPAT_REVOKE 0x00000001 +/*#define JFS_FEATURE_INCOMPAT_64BIT 0x00000002*/ +#define JFS_FEATURE_INCOMPAT_ASYNC_COMMIT 0x00000004/* Features known to this kernel version: */ -#define JFS_KNOWN_COMPAT_FEATURES 0 +#define JFS_KNOWN_COMPAT_FEATURES JFS_FEATURE_COMPAT_CHECKSUM#define JFS_KNOWN_ROCOMPAT_FEATURES 0 -#define JFS_KNOWN_INCOMPAT_FEATURES JFS_FEATURE_INCOMPAT_REVOKE +#define JFS_KNOWN_INCOMPAT_FEATURES (JFS_FEATURE_INCOMPAT_REVOKE| \ + JFS_FEATURE_INCOMPAT_ASYNC_COMMIT)#ifdef __KERNEL__
lib/ext2fs/crc32.h new file +30 -0
@@ -0,0 +1,30 @@ +/* +* crc32.h +* See crc32.c for license and changes +*/ +#ifndef _LINUX_CRC32_H +#define _LINUX_CRC32_H + +#include <linux/types.h> + +typedef unsigned int u32 ; +typedef unsigned char u8 ; + +extern u32 crc32_le (u32 crc,unsigned char const *p,size_t len); +extern u32 crc32_be (u32 crc,unsigned char const *p,size_t len); +extern u32 bitreverse (u32 in); + +#define crc32 (seed, data, length) crc32_le(seed, (unsigned char const *)data, length) + +/* +* Helpers for hash table generation of ethernet nics: +* +* Ethernet sends the least significant bit of a byte first, thus crc32_le +* is used. The output of crc32_le is bit reversed [most significant bit +* is in bit nr 0], thus it must be reversed before use. Except for +* nics that bit swap the result internally... +*/ +#define ether_crc (length, data) bitreverse(crc32_le(~0, data, length)) +#define ether_crc_le (length, data) crc32_le(~0, data, length) + +#endif /* _LINUX_CRC32_H */
lib/ext2fs/crc32.c new file +522 -0
522 lines not on this page · raw message
lib/ext2fs/crc32defs.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* There are multiple 16-bit CRC polynomials in common use, but this is +* *the* standard CRC-32 polynomial, first popularized by Ethernet. +* x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x^1+x^0 +*/ +#define CRCPOLY_LE 0xedb88320 +#define CRCPOLY_BE 0x04c11db7 + +/* How many bits at a time to use. Requires a table of 4<<CRC_xx_BITS bytes. */ +/* For less performance-sensitive, use 4 */ +#ifndef CRC_LE_BITS +# define CRC_LE_BITS 8 +#endif +#ifndef CRC_BE_BITS +# define CRC_BE_BITS 8 +#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 >8 ||CRC_LE_BITS <1 ||CRC_LE_BITS &CRC_LE_BITS -1 +# error CRC_LE_BITS must be a power of 2 between 1 and 8 +#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 >8 ||CRC_BE_BITS <1 ||CRC_BE_BITS &CRC_BE_BITS -1 +# error CRC_BE_BITS must be a power of 2 between 1 and 8 +#endif
lib/ext2fs/crc32table.h new file +135 -0
135 lines not on this page · raw message
lib/ext2fs/crc32_user.h new file +46 -0
46 lines not on this page · raw message
lib/ext2fs/Makefile.in +4 -0
@@ -67,6 +67,7 @@ OBJS= $(DEBUGFS_LIB_OBJS) $(RESIZE_LIB_O unlink.o \ valid_blk.o \ version.o \ + crc32.o \ crc16.o \ csum.o
@@ -139,6 +140,7 @@ SRCS= ext2_err.c \ $(srcdir)/tst_types.c \ $(srcdir)/tst_iscan.c \ $(srcdir)/tst_csum.c \ + $(srcdir)/crc32.c \ $(srcdir)/crc16.c \ $(srcdir)/csum.c
@@ -354,6 +356,8 @@ cmp_bitmaps.o: $(srcdir)/cmp_bitmaps.c $ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \ $(srcdir)/ext2_fs.h $(top_srcdir)/lib/et/com_err.h $(srcdir)/ext2_io.h \ $(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/bitops.h +crc32.o: $(srcdir)/crc32.c $(srcdir)/ext2_fs.h $(srcdir)/crc16.h \ + $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h $(srcdir)/ext2_fs.h crc16.o: $(srcdir)/crc16.c $(srcdir)/ext2_fs.h $(srcdir)/crc16.h \ $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h $(srcdir)/ext2_fs.h csum.o: $(srcdir)/csum.c $(srcdir)/ext2_fs.h \
e2fsck/recovery.c +117 -7
162 lines not on this page · raw message