/* * Copyright (C) 2013 Andrea Mazzoleni * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /* * Copyright notes: * * The RAID5 and RAID6 support was originally derived from the * H. Peter Anvin paper "The mathematics of RAID-6" [1] and the * libraid6 library, also by H. Peter Anvin, released with license * "GPLv2 or any later version" inside the Linux Kernel 2.6.38. * * This support was later completely rewritten (many times), but * the H. Peter Anvin's Copyright may still apply. * * The others RAID levels and the recovering based on matrix * inversion is original work implemented from scratch. */ /* * The RAID5 and RAID6 support is implemented using the Galois Field * GF(2^8) with the primitive polynomial x^8 + x^4 + x^3 + x^2 + 1 * (285 decimal). * * The parity P and Q of a set of N disk Di with 0<=i RAID_PARITY_MAX); raid_par_ptr[np - 1](nd, size, v); } /** * Inverts the square matrix M of size nxn into V. * We use Gauss elimination to invert. */ void raid_invert(uint8_t* M, uint8_t* V, int n) { int i,j,k; /* set the identity matrix in V */ for(i=0;i nd); /* if failed data is present */ if (nr != 0) { raid_rec_ptr[nr - 1](nr, id, ip, nd, size, v); } } void raid_recpar(int nrd, const int* id, int nrp, int* ip, int np, int nd, size_t size, void** v) { BUG_ON(nrd > nd); BUG_ON(nrd + nrp > np); /* if failed data is present */ if (nrd != 0) { int iu[RAID_PARITY_MAX]; int i, j, k; /* setup the vector of parities to use */ for(i=0,j=0,k=0;i