1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include "raid6.h"
22
23
24void raid6_2data_recov(int disks, size_t bytes, int faila, int failb,
25 void **ptrs)
26{
27 u8 *p, *q, *dp, *dq;
28 u8 px, qx, db;
29 const u8 *pbmul;
30 const u8 *qmul;
31
32 p = (u8 *)ptrs[disks-2];
33 q = (u8 *)ptrs[disks-1];
34
35
36
37
38 dp = (u8 *)ptrs[faila];
39 ptrs[faila] = (void *)raid6_empty_zero_page;
40 ptrs[disks-2] = dp;
41 dq = (u8 *)ptrs[failb];
42 ptrs[failb] = (void *)raid6_empty_zero_page;
43 ptrs[disks-1] = dq;
44
45 raid6_call.gen_syndrome(disks, bytes, ptrs);
46
47
48 ptrs[faila] = dp;
49 ptrs[failb] = dq;
50 ptrs[disks-2] = p;
51 ptrs[disks-1] = q;
52
53
54 pbmul = raid6_gfmul[raid6_gfexi[failb-faila]];
55 qmul = raid6_gfmul[raid6_gfinv[raid6_gfexp[faila]^raid6_gfexp[failb]]];
56
57
58 while ( bytes-- ) {
59 px = *p ^ *dp;
60 qx = qmul[*q ^ *dq];
61 *dq++ = db = pbmul[px] ^ qx;
62 *dp++ = db ^ px;
63 p++; q++;
64 }
65}
66
67
68
69
70
71void raid6_datap_recov(int disks, size_t bytes, int faila, void **ptrs)
72{
73 u8 *p, *q, *dq;
74 const u8 *qmul;
75
76 p = (u8 *)ptrs[disks-2];
77 q = (u8 *)ptrs[disks-1];
78
79
80
81 dq = (u8 *)ptrs[faila];
82 ptrs[faila] = (void *)raid6_empty_zero_page;
83 ptrs[disks-1] = dq;
84
85 raid6_call.gen_syndrome(disks, bytes, ptrs);
86
87
88 ptrs[faila] = dq;
89 ptrs[disks-1] = q;
90
91
92 qmul = raid6_gfmul[raid6_gfinv[raid6_gfexp[faila]]];
93
94
95 while ( bytes-- ) {
96 *p++ ^= *dq = qmul[*q ^ *dq];
97 q++; dq++;
98 }
99}
100
101
102#ifndef __KERNEL__
103
104
105void raid6_dual_recov(int disks, size_t bytes, int faila, int failb, void **ptrs)
106{
107 if ( faila > failb ) {
108 int tmp = faila;
109 faila = failb;
110 failb = tmp;
111 }
112
113 if ( failb == disks-1 ) {
114 if ( faila == disks-2 ) {
115
116 raid6_call.gen_syndrome(disks, bytes, ptrs);
117 } else {
118
119
120
121 }
122 } else {
123 if ( failb == disks-2 ) {
124
125 raid6_datap_recov(disks, bytes, faila, ptrs);
126 } else {
127
128 raid6_2data_recov(disks, bytes, faila, failb, ptrs);
129 }
130 }
131}
132
133#endif
134