Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * blockcheck.h
0004  *
0005  * Checksum and ECC codes for the OCFS2 userspace library.
0006  *
0007  * Copyright (C) 2004, 2008 Oracle.  All rights reserved.
0008  */
0009 
0010 #ifndef OCFS2_BLOCKCHECK_H
0011 #define OCFS2_BLOCKCHECK_H
0012 
0013 
0014 /* Count errors and error correction from blockcheck.c */
0015 struct ocfs2_blockcheck_stats {
0016     spinlock_t b_lock;
0017     u64 b_check_count;  /* Number of blocks we've checked */
0018     u64 b_failure_count;    /* Number of failed checksums */
0019     u64 b_recover_count;    /* Number of blocks fixed by ecc */
0020 
0021     /*
0022      * debugfs entries, used if this is passed to
0023      * ocfs2_blockcheck_stats_debugfs_install()
0024      */
0025     struct dentry *b_debug_dir; /* Parent of the debugfs  files */
0026 };
0027 
0028 
0029 /* High level block API */
0030 void ocfs2_compute_meta_ecc(struct super_block *sb, void *data,
0031                 struct ocfs2_block_check *bc);
0032 int ocfs2_validate_meta_ecc(struct super_block *sb, void *data,
0033                 struct ocfs2_block_check *bc);
0034 void ocfs2_compute_meta_ecc_bhs(struct super_block *sb,
0035                 struct buffer_head **bhs, int nr,
0036                 struct ocfs2_block_check *bc);
0037 int ocfs2_validate_meta_ecc_bhs(struct super_block *sb,
0038                 struct buffer_head **bhs, int nr,
0039                 struct ocfs2_block_check *bc);
0040 
0041 /* Lower level API */
0042 void ocfs2_block_check_compute(void *data, size_t blocksize,
0043                    struct ocfs2_block_check *bc);
0044 int ocfs2_block_check_validate(void *data, size_t blocksize,
0045                    struct ocfs2_block_check *bc,
0046                    struct ocfs2_blockcheck_stats *stats);
0047 void ocfs2_block_check_compute_bhs(struct buffer_head **bhs, int nr,
0048                    struct ocfs2_block_check *bc);
0049 int ocfs2_block_check_validate_bhs(struct buffer_head **bhs, int nr,
0050                    struct ocfs2_block_check *bc,
0051                    struct ocfs2_blockcheck_stats *stats);
0052 
0053 /* Debug Initialization */
0054 void ocfs2_blockcheck_stats_debugfs_install(struct ocfs2_blockcheck_stats *stats,
0055                         struct dentry *parent);
0056 void ocfs2_blockcheck_stats_debugfs_remove(struct ocfs2_blockcheck_stats *stats);
0057 
0058 /*
0059  * Hamming code functions
0060  */
0061 
0062 /*
0063  * Encoding hamming code parity bits for a buffer.
0064  *
0065  * This is the low level encoder function.  It can be called across
0066  * multiple hunks just like the crc32 code.  'd' is the number of bits
0067  * _in_this_hunk_.  nr is the bit offset of this hunk.  So, if you had
0068  * two 512B buffers, you would do it like so:
0069  *
0070  * parity = ocfs2_hamming_encode(0, buf1, 512 * 8, 0);
0071  * parity = ocfs2_hamming_encode(parity, buf2, 512 * 8, 512 * 8);
0072  *
0073  * If you just have one buffer, use ocfs2_hamming_encode_block().
0074  */
0075 u32 ocfs2_hamming_encode(u32 parity, void *data, unsigned int d,
0076              unsigned int nr);
0077 /*
0078  * Fix a buffer with a bit error.  The 'fix' is the original parity
0079  * xor'd with the parity calculated now.
0080  *
0081  * Like ocfs2_hamming_encode(), this can handle hunks.  nr is the bit
0082  * offset of the current hunk.  If bit to be fixed is not part of the
0083  * current hunk, this does nothing.
0084  *
0085  * If you only have one buffer, use ocfs2_hamming_fix_block().
0086  */
0087 void ocfs2_hamming_fix(void *data, unsigned int d, unsigned int nr,
0088                unsigned int fix);
0089 
0090 /* Convenience wrappers for a single buffer of data */
0091 extern u32 ocfs2_hamming_encode_block(void *data, unsigned int blocksize);
0092 extern void ocfs2_hamming_fix_block(void *data, unsigned int blocksize,
0093                     unsigned int fix);
0094 #endif