blockcheck.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * blockcheck.h
  4. *
  5. * Checksum and ECC codes for the OCFS2 userspace library.
  6. *
  7. * Copyright (C) 2004, 2008 Oracle. All rights reserved.
  8. */
  9. #ifndef OCFS2_BLOCKCHECK_H
  10. #define OCFS2_BLOCKCHECK_H
  11. /* Count errors and error correction from blockcheck.c */
  12. struct ocfs2_blockcheck_stats {
  13. spinlock_t b_lock;
  14. u64 b_check_count; /* Number of blocks we've checked */
  15. u64 b_failure_count; /* Number of failed checksums */
  16. u64 b_recover_count; /* Number of blocks fixed by ecc */
  17. /*
  18. * debugfs entries, used if this is passed to
  19. * ocfs2_blockcheck_stats_debugfs_install()
  20. */
  21. struct dentry *b_debug_dir; /* Parent of the debugfs files */
  22. };
  23. /* High level block API */
  24. void ocfs2_compute_meta_ecc(struct super_block *sb, void *data,
  25. struct ocfs2_block_check *bc);
  26. int ocfs2_validate_meta_ecc(struct super_block *sb, void *data,
  27. struct ocfs2_block_check *bc);
  28. void ocfs2_compute_meta_ecc_bhs(struct super_block *sb,
  29. struct buffer_head **bhs, int nr,
  30. struct ocfs2_block_check *bc);
  31. int ocfs2_validate_meta_ecc_bhs(struct super_block *sb,
  32. struct buffer_head **bhs, int nr,
  33. struct ocfs2_block_check *bc);
  34. /* Lower level API */
  35. void ocfs2_block_check_compute(void *data, size_t blocksize,
  36. struct ocfs2_block_check *bc);
  37. int ocfs2_block_check_validate(void *data, size_t blocksize,
  38. struct ocfs2_block_check *bc,
  39. struct ocfs2_blockcheck_stats *stats);
  40. void ocfs2_block_check_compute_bhs(struct buffer_head **bhs, int nr,
  41. struct ocfs2_block_check *bc);
  42. int ocfs2_block_check_validate_bhs(struct buffer_head **bhs, int nr,
  43. struct ocfs2_block_check *bc,
  44. struct ocfs2_blockcheck_stats *stats);
  45. /* Debug Initialization */
  46. void ocfs2_blockcheck_stats_debugfs_install(struct ocfs2_blockcheck_stats *stats,
  47. struct dentry *parent);
  48. void ocfs2_blockcheck_stats_debugfs_remove(struct ocfs2_blockcheck_stats *stats);
  49. /*
  50. * Hamming code functions
  51. */
  52. /*
  53. * Encoding hamming code parity bits for a buffer.
  54. *
  55. * This is the low level encoder function. It can be called across
  56. * multiple hunks just like the crc32 code. 'd' is the number of bits
  57. * _in_this_hunk_. nr is the bit offset of this hunk. So, if you had
  58. * two 512B buffers, you would do it like so:
  59. *
  60. * parity = ocfs2_hamming_encode(0, buf1, 512 * 8, 0);
  61. * parity = ocfs2_hamming_encode(parity, buf2, 512 * 8, 512 * 8);
  62. *
  63. * If you just have one buffer, use ocfs2_hamming_encode_block().
  64. */
  65. u32 ocfs2_hamming_encode(u32 parity, void *data, unsigned int d,
  66. unsigned int nr);
  67. /*
  68. * Fix a buffer with a bit error. The 'fix' is the original parity
  69. * xor'd with the parity calculated now.
  70. *
  71. * Like ocfs2_hamming_encode(), this can handle hunks. nr is the bit
  72. * offset of the current hunk. If bit to be fixed is not part of the
  73. * current hunk, this does nothing.
  74. *
  75. * If you only have one buffer, use ocfs2_hamming_fix_block().
  76. */
  77. void ocfs2_hamming_fix(void *data, unsigned int d, unsigned int nr,
  78. unsigned int fix);
  79. /* Convenience wrappers for a single buffer of data */
  80. extern u32 ocfs2_hamming_encode_block(void *data, unsigned int blocksize);
  81. extern void ocfs2_hamming_fix_block(void *data, unsigned int blocksize,
  82. unsigned int fix);
  83. #endif