Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 125893
b: refs/heads/master
c: e798b3f
h: refs/heads/master
i:
  125891: befa0be
v: v3
  • Loading branch information
Joel Becker authored and Mark Fasheh committed Jan 5, 2009
1 parent bd3745c commit f5ceb82
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 48 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 9d28cfb73f3abccce001daf2d247b16bf20e2248
refs/heads/master: e798b3f8a920c82a8e556dd54df97f0d3d0f9144
67 changes: 20 additions & 47 deletions trunk/fs/ocfs2/blockcheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,13 @@
#include "blockcheck.h"



/*
* We use the following conventions:
*
* d = # data bits
* p = # parity bits
* c = # total code bits (d + p)
*/
static int calc_parity_bits(unsigned int d)
{
unsigned int p;

/*
* Bits required for Single Error Correction is as follows:
*
* d + p + 1 <= 2^p
*
* We're restricting ourselves to 31 bits of parity, that should be
* sufficient.
*/
for (p = 1; p < 32; p++)
{
if ((d + p + 1) <= (1 << p))
return p;
}

return 0;
}

/*
* Calculate the bit offset in the hamming code buffer based on the bit's
Expand Down Expand Up @@ -109,10 +88,9 @@ static unsigned int calc_code_bit(unsigned int i)
*/
u32 ocfs2_hamming_encode(u32 parity, void *data, unsigned int d, unsigned int nr)
{
unsigned int p = calc_parity_bits(nr + d);
unsigned int i, j, b;
unsigned int i, b;

BUG_ON(!p);
BUG_ON(!d);

/*
* b is the hamming code bit number. Hamming code specifies a
Expand All @@ -131,27 +109,23 @@ u32 ocfs2_hamming_encode(u32 parity, void *data, unsigned int d, unsigned int nr
*/
b = calc_code_bit(nr + i);

for (j = 0; j < p; j++)
{
/*
* Data bits in the resultant code are checked by
* parity bits that are part of the bit number
* representation. Huh?
*
* <wikipedia href="http://en.wikipedia.org/wiki/Hamming_code">
* In other words, the parity bit at position 2^k
* checks bits in positions having bit k set in
* their binary representation. Conversely, for
* instance, bit 13, i.e. 1101(2), is checked by
* bits 1000(2) = 8, 0100(2)=4 and 0001(2) = 1.
* </wikipedia>
*
* Note that 'k' is the _code_ bit number. 'b' in
* our loop.
*/
if (b & (1 << j))
parity ^= (1 << j);
}
/*
* Data bits in the resultant code are checked by
* parity bits that are part of the bit number
* representation. Huh?
*
* <wikipedia href="http://en.wikipedia.org/wiki/Hamming_code">
* In other words, the parity bit at position 2^k
* checks bits in positions having bit k set in
* their binary representation. Conversely, for
* instance, bit 13, i.e. 1101(2), is checked by
* bits 1000(2) = 8, 0100(2)=4 and 0001(2) = 1.
* </wikipedia>
*
* Note that 'k' is the _code_ bit number. 'b' in
* our loop.
*/
parity ^= b;
}

/* While the data buffer was treated as little endian, the
Expand All @@ -174,10 +148,9 @@ u32 ocfs2_hamming_encode_block(void *data, unsigned int blocksize)
void ocfs2_hamming_fix(void *data, unsigned int d, unsigned int nr,
unsigned int fix)
{
unsigned int p = calc_parity_bits(nr + d);
unsigned int i, b;

BUG_ON(!p);
BUG_ON(!d);

/*
* If the bit to fix has an hweight of 1, it's a parity bit. One
Expand Down

0 comments on commit f5ceb82

Please sign in to comment.