X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=e2fsck%2Fjfs_user.h;h=4ad2005a89ec8292547a179f903a319d42c30a6a;hb=fdec633fd661e79b7b81e848b5699775328d70ae;hp=157ece18e1f72c5db583d075fea38d95191874e0;hpb=3de085dd4109e6a7049dd6b85abf0313167cab5b;p=tools%2Fe2fsprogs.git diff --git a/e2fsck/jfs_user.h b/e2fsck/jfs_user.h index 157ece1..4ad2005 100644 --- a/e2fsck/jfs_user.h +++ b/e2fsck/jfs_user.h @@ -8,80 +8,140 @@ * GNU General Public License version 2 or at your discretion * any later version. */ +#ifndef _JFS_USER_H +#define _JFS_USER_H +#ifdef DEBUGFS +#include +#include +#if EXT2_FLAT_INCLUDES +#include "ext2_fs.h" +#include "ext2fs.h" +#include "blkid.h" +#else +#include "ext2fs/ext2_fs.h" +#include "ext2fs/ext2fs.h" +#include "blkid/blkid.h" +#endif +#else /* * Pull in the definition of the e2fsck context structure */ +#include "config.h" #include "e2fsck.h" +#endif + +#if __STDC_VERSION__ < 199901L +# if __GNUC__ >= 2 || _MSC_VER >= 1300 +# define __func__ __FUNCTION__ +# else +# define __func__ "" +# endif +#endif struct buffer_head { - char b_data[8192]; +#ifdef DEBUGFS + ext2_filsys b_fs; +#else e2fsck_t b_ctx; - io_channel b_io; - int b_size; - blk_t b_blocknr; - int b_dirty; - int b_uptodate; - int b_err; +#endif + io_channel b_io; + int b_size; + int b_err; + unsigned int b_dirty:1; + unsigned int b_uptodate:1; + unsigned long long b_blocknr; + char b_data[4096]; }; struct inode { +#ifdef DEBUGFS + ext2_filsys i_fs; +#else e2fsck_t i_ctx; +#endif ext2_ino_t i_ino; struct ext2_inode i_ext2; }; struct kdev_s { +#ifdef DEBUGFS + ext2_filsys k_fs; +#else e2fsck_t k_ctx; +#endif int k_dev; }; #define K_DEV_FS 1 #define K_DEV_JOURNAL 2 -typedef struct kdev_s *kdev_t; - -#define fsync_no_super(dev) do {} while(0) -#define sync_blockdev(dev) do {} while(0) -#define lock_buffer(bh) do {} while(0) -#define unlock_buffer(bh) do {} while(0) +#define lock_buffer(bh) do {} while (0) +#define unlock_buffer(bh) do {} while (0) #define buffer_req(bh) 1 -#define do_readahead(journal, start) do {} while(0) - -extern e2fsck_t e2fsck_global_ctx; /* Try your very best not to use this! */ +#define do_readahead(journal, start) do {} while (0) -typedef struct { +typedef struct kmem_cache { int object_length; } kmem_cache_t; -#define kmem_cache_alloc(cache,flags) malloc((cache)->object_length) -#define kmem_cache_free(cache,obj) free(obj) -#define kmem_cache_create(name,len,a,b,c,d) do_cache_create(len) +#define kmem_cache_alloc(cache, flags) malloc((cache)->object_length) +#define kmem_cache_free(cache, obj) free(obj) +#define kmem_cache_create(name, len, a, b, c) do_cache_create(len) #define kmem_cache_destroy(cache) do_cache_destroy(cache) -#define kmalloc(len,flags) malloc(len) +#define kmalloc(len, flags) malloc(len) #define kfree(p) free(p) +#define cond_resched() do { } while (0) + +#define __init + +/* + * Now pull in the real linux/jfs.h definitions. + */ +#include + /* * We use the standard libext2fs portability tricks for inline - * functions. + * functions. */ -extern kmem_cache_t * do_cache_create(int len); +#ifdef NO_INLINE_FUNCS +extern kmem_cache_t *do_cache_create(int len); extern void do_cache_destroy(kmem_cache_t *cache); - +extern size_t journal_tag_bytes(journal_t *journal); +extern __u32 __hash_32(__u32 val); +extern __u32 hash_32(__u32 val, unsigned int bits); +extern __u32 hash_64(__u64 val, unsigned int bits); +extern void *kmalloc_array(unsigned n, unsigned size, int flags); +extern __u32 jbd2_chksum(journal_t *j, __u32 crc, const void *address, + unsigned int length); +extern void jbd2_descriptor_block_csum_set(journal_t *j, + struct buffer_head *bh); +#endif + #if (defined(E2FSCK_INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS)) #ifdef E2FSCK_INCLUDE_INLINE_FUNCS -#define _INLINE_ extern +#if (__STDC_VERSION__ >= 199901L) +#define _INLINE_ extern inline #else +#define _INLINE_ inline +#endif +#else /* !E2FSCK_INCLUDE_INLINE FUNCS */ +#if (__STDC_VERSION__ >= 199901L) +#define _INLINE_ inline +#else /* not C99 */ #ifdef __GNUC__ #define _INLINE_ extern __inline__ #else /* For Watcom C */ #define _INLINE_ extern inline -#endif -#endif +#endif /* __GNUC__ */ +#endif /* __STDC_VERSION__ >= 199901L */ +#endif /* E2FSCK_INCLUDE_INLINE_FUNCS */ -_INLINE_ kmem_cache_t * do_cache_create(int len) +_INLINE_ kmem_cache_t *do_cache_create(int len) { kmem_cache_t *new_cache; + new_cache = malloc(sizeof(*new_cache)); if (new_cache) new_cache->object_length = len; @@ -92,22 +152,75 @@ _INLINE_ void do_cache_destroy(kmem_cache_t *cache) { free(cache); } -#undef _INLINE_ -#endif -#define __init +/* generic hashing taken from the Linux kernel */ +#define GOLDEN_RATIO_32 0x61C88647 +#define GOLDEN_RATIO_64 0x61C8864680B583EBull -/* - * Now pull in the real linux/jfs.h definitions. - */ -#include +_INLINE_ __u32 __hash_32(__u32 val) +{ + return val * GOLDEN_RATIO_32; +} + +_INLINE_ __u32 hash_32(__u32 val, unsigned int bits) +{ + /* High bits are more random, so use them. */ + return __hash_32(val) >> (32 - bits); +} + +_INLINE_ __u32 hash_64(__u64 val, unsigned int bits) +{ + if (sizeof(long) >= 8) { + /* 64x64-bit multiply is efficient on all 64-bit processors */ + return val * GOLDEN_RATIO_64 >> (64 - bits); + } else { + /* Hash 64 bits using only 32x32-bit multiply. */ + return hash_32((__u32)val ^ __hash_32(val >> 32), bits); + } +} + +_INLINE_ void *kmalloc_array(unsigned n, unsigned size, + int flags EXT2FS_ATTR((unused))) +{ + if (n && (~0U)/n < size) + return NULL; + return malloc(n * size); +} + +_INLINE_ __u32 jbd2_chksum(journal_t *j EXT2FS_ATTR((unused)), + __u32 crc, const void *address, + unsigned int length) +{ + return ext2fs_crc32c_le(crc, address, length); +} + +_INLINE_ void jbd2_descriptor_block_csum_set(journal_t *j, + struct buffer_head *bh) +{ + struct jbd2_journal_block_tail *tail; + __u32 csum; + + if (!jbd2_journal_has_csum_v2or3(j)) + return; + + tail = (struct jbd2_journal_block_tail *)(bh->b_data + j->j_blocksize - + sizeof(struct jbd2_journal_block_tail)); + tail->t_checksum = 0; + csum = jbd2_chksum(j, j->j_csum_seed, bh->b_data, j->j_blocksize); + tail->t_checksum = cpu_to_be32(csum); +} +#undef _INLINE_ +#endif /* * Kernel compatibility functions are defined in journal.c */ -int journal_bmap(journal_t *journal, blk_t block, unsigned long *phys); -struct buffer_head *getblk(kdev_t ctx, blk_t blocknr, int blocksize); -void ll_rw_block(int rw, int dummy, struct buffer_head *bh[]); +int jbd2_journal_bmap(journal_t *journal, unsigned long block, + unsigned long long *phys); +struct buffer_head *getblk(kdev_t ctx, unsigned long long blocknr, + int blocksize); +int sync_blockdev(kdev_t kdev); +void ll_rw_block(int rw, int op_flags, int nr, struct buffer_head *bh[]); void mark_buffer_dirty(struct buffer_head *bh); void mark_buffer_uptodate(struct buffer_head *bh, int val); void brelse(struct buffer_head *bh); @@ -119,3 +232,51 @@ void wait_on_buffer(struct buffer_head *bh); */ #define __getblk(dev, blocknr, blocksize) getblk(dev, blocknr, blocksize) #define set_buffer_uptodate(bh) mark_buffer_uptodate(bh, 1) + +#ifdef DEBUGFS +#include +#undef J_ASSERT +#define J_ASSERT(x) assert(x) + +#define JSB_HAS_INCOMPAT_FEATURE(jsb, mask) \ + ((jsb)->s_header.h_blocktype == ext2fs_cpu_to_be32(JBD2_SUPERBLOCK_V2) && \ + ((jsb)->s_feature_incompat & ext2fs_cpu_to_be32((mask)))) +#else /* !DEBUGFS */ + +extern e2fsck_t e2fsck_global_ctx; /* Try your very best not to use this! */ + +#define J_ASSERT(assert) \ + do { if (!(assert)) { \ + printf ("Assertion failure in %s() at %s line %d: " \ + "\"%s\"\n", \ + __func__, __FILE__, __LINE__, # assert); \ + fatal_error(e2fsck_global_ctx, 0); \ + } } while (0) + +#endif /* DEBUGFS */ + +#ifndef EFSBADCRC +#define EFSBADCRC EXT2_ET_BAD_CRC +#endif +#ifndef EFSCORRUPTED +#define EFSCORRUPTED EXT2_ET_FILESYSTEM_CORRUPTED +#endif + +/* recovery.c */ +extern int jbd2_journal_recover (journal_t *journal); +extern int jbd2_journal_skip_recovery (journal_t *); + +/* revoke.c */ +extern int jbd2_journal_init_revoke(journal_t *, int); +extern void jbd2_journal_destroy_revoke(journal_t *); +extern void jbd2_journal_destroy_revoke_record_cache(void); +extern void jbd2_journal_destroy_revoke_table_cache(void); +extern int jbd2_journal_init_revoke_record_cache(void); +extern int jbd2_journal_init_revoke_table_cache(void); + + +extern int jbd2_journal_set_revoke(journal_t *, unsigned long long, tid_t); +extern int jbd2_journal_test_revoke(journal_t *, unsigned long long, tid_t); +extern void jbd2_journal_clear_revoke(journal_t *); + +#endif /* _JFS_USER_H */