blockcheck.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * blockcheck.h
  5. *
  6. * Checksum and ECC codes for the OCFS2 userspace library.
  7. *
  8. * Copyright (C) 2004, 2008 Oracle. All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public
  12. * License, version 2, as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. */
  19. #ifndef OCFS2_BLOCKCHECK_H
  20. #define OCFS2_BLOCKCHECK_H
  21. /* High level block API */
  22. void ocfs2_compute_meta_ecc(struct super_block *sb, void *data,
  23. struct ocfs2_block_check *bc);
  24. int ocfs2_validate_meta_ecc(struct super_block *sb, void *data,
  25. struct ocfs2_block_check *bc);
  26. void ocfs2_compute_meta_ecc_bhs(struct super_block *sb,
  27. struct buffer_head **bhs, int nr,
  28. struct ocfs2_block_check *bc);
  29. int ocfs2_validate_meta_ecc_bhs(struct super_block *sb,
  30. struct buffer_head **bhs, int nr,
  31. struct ocfs2_block_check *bc);
  32. /* Lower level API */
  33. void ocfs2_block_check_compute(void *data, size_t blocksize,
  34. struct ocfs2_block_check *bc);
  35. int ocfs2_block_check_validate(void *data, size_t blocksize,
  36. struct ocfs2_block_check *bc);
  37. void ocfs2_block_check_compute_bhs(struct buffer_head **bhs, int nr,
  38. struct ocfs2_block_check *bc);
  39. int ocfs2_block_check_validate_bhs(struct buffer_head **bhs, int nr,
  40. struct ocfs2_block_check *bc);
  41. /*
  42. * Hamming code functions
  43. */
  44. /*
  45. * Encoding hamming code parity bits for a buffer.
  46. *
  47. * This is the low level encoder function. It can be called across
  48. * multiple hunks just like the crc32 code. 'd' is the number of bits
  49. * _in_this_hunk_. nr is the bit offset of this hunk. So, if you had
  50. * two 512B buffers, you would do it like so:
  51. *
  52. * parity = ocfs2_hamming_encode(0, buf1, 512 * 8, 0);
  53. * parity = ocfs2_hamming_encode(parity, buf2, 512 * 8, 512 * 8);
  54. *
  55. * If you just have one buffer, use ocfs2_hamming_encode_block().
  56. */
  57. u32 ocfs2_hamming_encode(u32 parity, void *data, unsigned int d,
  58. unsigned int nr);
  59. /*
  60. * Fix a buffer with a bit error. The 'fix' is the original parity
  61. * xor'd with the parity calculated now.
  62. *
  63. * Like ocfs2_hamming_encode(), this can handle hunks. nr is the bit
  64. * offset of the current hunk. If bit to be fixed is not part of the
  65. * current hunk, this does nothing.
  66. *
  67. * If you only have one buffer, use ocfs2_hamming_fix_block().
  68. */
  69. void ocfs2_hamming_fix(void *data, unsigned int d, unsigned int nr,
  70. unsigned int fix);
  71. /* Convenience wrappers for a single buffer of data */
  72. extern u32 ocfs2_hamming_encode_block(void *data, unsigned int blocksize);
  73. extern void ocfs2_hamming_fix_block(void *data, unsigned int blocksize,
  74. unsigned int fix);
  75. #endif