blockcheck.h 3.3 KB

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