Lines Matching +full:data +full:- +full:bits
1 // SPDX-License-Identifier: GPL-2.0-only
30 * d = # data bits
31 * p = # parity bits
32 * c = # total code bits (d + p)
38 * offset in the data buffer. Since the hamming code reserves all
39 * power-of-two bits for parity, the data bit number and the code bit
40 * number are offset by all the parity bits beforehand.
42 * Recall that bit numbers in hamming code are 1-based. This function
43 * takes the 0-based data bit from the caller.
45 * An example. Take bit 1 of the data buffer. 1 is a power of two (2^0),
47 * 3 is not a power of two. So bit 1 of the data buffer ends up as bit 3
51 * number of parity bits added. This allows the function to start the
59 * Data bits are 0-based, but we're talking code bits, which in calc_code_bit()
60 * are 1-based. in calc_code_bit()
88 * multiple hunks just like the crc32 code. 'd' is the number of bits
97 u32 ocfs2_hamming_encode(u32 parity, void *data, unsigned int d, unsigned int nr) in ocfs2_hamming_encode() argument
105 * 1-based array, but C uses 0-based. So 'i' is for C, and 'b' is in ocfs2_hamming_encode()
112 for (i = 0; (i = ocfs2_find_next_bit(data, d, i)) < d; i++) in ocfs2_hamming_encode()
121 * Data bits in the resultant code are checked by in ocfs2_hamming_encode()
122 * parity bits that are part of the bit number in ocfs2_hamming_encode()
127 * checks bits in positions having bit k set in in ocfs2_hamming_encode()
130 * bits 1000(2) = 8, 0100(2)=4 and 0001(2) = 1. in ocfs2_hamming_encode()
139 /* While the data buffer was treated as little endian, the in ocfs2_hamming_encode()
144 u32 ocfs2_hamming_encode_block(void *data, unsigned int blocksize) in ocfs2_hamming_encode_block() argument
146 return ocfs2_hamming_encode(0, data, blocksize * 8, 0); in ocfs2_hamming_encode_block()
156 void ocfs2_hamming_fix(void *data, unsigned int d, unsigned int nr, in ocfs2_hamming_fix() argument
171 * nr + d is the bit right past the data hunk we're looking at. in ocfs2_hamming_fix()
178 * nr is the offset in the data hunk we're starting at. Let's in ocfs2_hamming_fix()
189 /* Skip past parity bits */ in ocfs2_hamming_fix()
194 * i is the offset in this data hunk. in ocfs2_hamming_fix()
195 * nr + i is the offset in the total data buffer. in ocfs2_hamming_fix()
203 if (ocfs2_test_bit(i, data)) in ocfs2_hamming_fix()
204 ocfs2_clear_bit(i, data); in ocfs2_hamming_fix()
206 ocfs2_set_bit(i, data); in ocfs2_hamming_fix()
212 void ocfs2_hamming_fix_block(void *data, unsigned int blocksize, in ocfs2_hamming_fix_block() argument
215 ocfs2_hamming_fix(data, blocksize * 8, 0, fix); in ocfs2_hamming_fix_block()
225 static int blockcheck_u64_get(void *data, u64 *val) in blockcheck_u64_get() argument
227 *val = *(u64 *)data; in blockcheck_u64_get()
235 debugfs_remove_recursive(stats->b_debug_dir); in ocfs2_blockcheck_debug_remove()
236 stats->b_debug_dir = NULL; in ocfs2_blockcheck_debug_remove()
246 stats->b_debug_dir = dir; in ocfs2_blockcheck_debug_install()
249 &stats->b_check_count, &blockcheck_fops); in ocfs2_blockcheck_debug_install()
252 &stats->b_failure_count, &blockcheck_fops); in ocfs2_blockcheck_debug_install()
255 &stats->b_recover_count, &blockcheck_fops); in ocfs2_blockcheck_debug_install()
269 /* Always-called wrappers for starting and stopping the debugfs files */
288 spin_lock(&stats->b_lock); in ocfs2_blockcheck_inc_check()
289 stats->b_check_count++; in ocfs2_blockcheck_inc_check()
290 new_count = stats->b_check_count; in ocfs2_blockcheck_inc_check()
291 spin_unlock(&stats->b_lock); in ocfs2_blockcheck_inc_check()
304 spin_lock(&stats->b_lock); in ocfs2_blockcheck_inc_failure()
305 stats->b_failure_count++; in ocfs2_blockcheck_inc_failure()
306 new_count = stats->b_failure_count; in ocfs2_blockcheck_inc_failure()
307 spin_unlock(&stats->b_lock); in ocfs2_blockcheck_inc_failure()
320 spin_lock(&stats->b_lock); in ocfs2_blockcheck_inc_recover()
321 stats->b_recover_count++; in ocfs2_blockcheck_inc_recover()
322 new_count = stats->b_recover_count; in ocfs2_blockcheck_inc_recover()
323 spin_unlock(&stats->b_lock); in ocfs2_blockcheck_inc_recover()
332 * These are the low-level APIs for using the ocfs2_block_check structure.
337 * data is the block to be checked. bc is a pointer to the
340 * bc should be a pointer inside data, as the function will
342 * bc does not point inside data, the caller must make sure any inline
345 * The data buffer must be in on-disk endian (little endian for ocfs2).
346 * bc will be filled with little-endian values and will be ready to go to
349 void ocfs2_block_check_compute(void *data, size_t blocksize, in ocfs2_block_check_compute() argument
357 crc = crc32_le(~0, data, blocksize); in ocfs2_block_check_compute()
358 ecc = ocfs2_hamming_encode_block(data, blocksize); in ocfs2_block_check_compute()
362 * larger than 16 bits. in ocfs2_block_check_compute()
366 bc->bc_crc32e = cpu_to_le32(crc); in ocfs2_block_check_compute()
367 bc->bc_ecc = cpu_to_le16((u16)ecc); in ocfs2_block_check_compute()
373 * If bc is not a pointer inside data, the caller must have zeroed any
376 * Again, the data passed in should be the on-disk endian.
378 int ocfs2_block_check_validate(void *data, size_t blocksize, in ocfs2_block_check_validate() argument
389 bc_crc32e = le32_to_cpu(bc->bc_crc32e); in ocfs2_block_check_validate()
390 bc_ecc = le16_to_cpu(bc->bc_ecc); in ocfs2_block_check_validate()
394 /* Fast path - if the crc32 validates, we're good to go */ in ocfs2_block_check_validate()
395 crc = crc32_le(~0, data, blocksize); in ocfs2_block_check_validate()
405 ecc = ocfs2_hamming_encode_block(data, blocksize); in ocfs2_block_check_validate()
406 ocfs2_hamming_fix_block(data, blocksize, ecc ^ bc_ecc); in ocfs2_block_check_validate()
409 crc = crc32_le(~0, data, blocksize); in ocfs2_block_check_validate()
418 rc = -EIO; in ocfs2_block_check_validate()
421 bc->bc_crc32e = cpu_to_le32(bc_crc32e); in ocfs2_block_check_validate()
422 bc->bc_ecc = cpu_to_le16(bc_ecc); in ocfs2_block_check_validate()
432 * bc should be a pointer inside data, as the function will
434 * bc does not point inside data, the caller must make sure any inline
437 * The data buffer must be in on-disk endian (little endian for ocfs2).
438 * bc will be filled with little-endian values and will be ready to go to
455 crc = crc32_le(crc, bhs[i]->b_data, bhs[i]->b_size); in ocfs2_block_check_compute_bhs()
457 * The number of bits in a buffer is obviously b_size*8. in ocfs2_block_check_compute_bhs()
461 ecc = (u16)ocfs2_hamming_encode(ecc, bhs[i]->b_data, in ocfs2_block_check_compute_bhs()
462 bhs[i]->b_size * 8, in ocfs2_block_check_compute_bhs()
463 bhs[i]->b_size * 8 * i); in ocfs2_block_check_compute_bhs()
468 * larger than 16 bits. in ocfs2_block_check_compute_bhs()
472 bc->bc_crc32e = cpu_to_le32(crc); in ocfs2_block_check_compute_bhs()
473 bc->bc_ecc = cpu_to_le16((u16)ecc); in ocfs2_block_check_compute_bhs()
480 * inside data, the caller must have zeroed any inline
483 * Again, the data passed in should be the on-disk endian.
501 bc_crc32e = le32_to_cpu(bc->bc_crc32e); in ocfs2_block_check_validate_bhs()
502 bc_ecc = le16_to_cpu(bc->bc_ecc); in ocfs2_block_check_validate_bhs()
506 /* Fast path - if the crc32 validates, we're good to go */ in ocfs2_block_check_validate_bhs()
508 crc = crc32_le(crc, bhs[i]->b_data, bhs[i]->b_size); in ocfs2_block_check_validate_bhs()
520 * The number of bits in a buffer is obviously b_size*8. in ocfs2_block_check_validate_bhs()
524 ecc = (u16)ocfs2_hamming_encode(ecc, bhs[i]->b_data, in ocfs2_block_check_validate_bhs()
525 bhs[i]->b_size * 8, in ocfs2_block_check_validate_bhs()
526 bhs[i]->b_size * 8 * i); in ocfs2_block_check_validate_bhs()
534 ocfs2_hamming_fix(bhs[i]->b_data, bhs[i]->b_size * 8, in ocfs2_block_check_validate_bhs()
535 bhs[i]->b_size * 8 * i, fix); in ocfs2_block_check_validate_bhs()
540 crc = crc32_le(crc, bhs[i]->b_data, bhs[i]->b_size); in ocfs2_block_check_validate_bhs()
549 rc = -EIO; in ocfs2_block_check_validate_bhs()
552 bc->bc_crc32e = cpu_to_le32(bc_crc32e); in ocfs2_block_check_validate_bhs()
553 bc->bc_ecc = cpu_to_le16(bc_ecc); in ocfs2_block_check_validate_bhs()
564 void ocfs2_compute_meta_ecc(struct super_block *sb, void *data, in ocfs2_compute_meta_ecc() argument
568 ocfs2_block_check_compute(data, sb->s_blocksize, bc); in ocfs2_compute_meta_ecc()
571 int ocfs2_validate_meta_ecc(struct super_block *sb, void *data, in ocfs2_validate_meta_ecc() argument
578 rc = ocfs2_block_check_validate(data, sb->s_blocksize, bc, in ocfs2_validate_meta_ecc()
579 &osb->osb_ecc_stats); in ocfs2_validate_meta_ecc()
601 &osb->osb_ecc_stats); in ocfs2_validate_meta_ecc_bhs()