Upgraded GRUB2 to 2.00 release.
[AROS.git] / arch / all-pc / boot / grub2-aros / grub-core / disk / raid5_recover.c
blob4ace9172e7ff68d75ad1508f85b8db775a891adf
1 /* raid5_recover.c - module to recover from faulty RAID4/5 arrays. */
2 /*
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2006,2007,2008 Free Software Foundation, Inc.
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20 #include <grub/dl.h>
21 #include <grub/disk.h>
22 #include <grub/mm.h>
23 #include <grub/err.h>
24 #include <grub/misc.h>
25 #include <grub/diskfilter.h>
26 #include <grub/crypto.h>
28 GRUB_MOD_LICENSE ("GPLv3+");
30 static grub_err_t
31 grub_raid5_recover (struct grub_diskfilter_segment *array, int disknr,
32 char *buf, grub_disk_addr_t sector, grub_size_t size)
34 char *buf2;
35 int i;
37 size <<= GRUB_DISK_SECTOR_BITS;
38 buf2 = grub_malloc (size);
39 if (!buf2)
40 return grub_errno;
42 grub_memset (buf, 0, size);
44 for (i = 0; i < (int) array->node_count; i++)
46 grub_err_t err;
48 if (i == disknr)
49 continue;
51 err = grub_diskfilter_read_node (&array->nodes[i], sector,
52 size >> GRUB_DISK_SECTOR_BITS, buf2);
54 if (err)
56 grub_free (buf2);
57 return err;
60 grub_crypto_xor (buf, buf, buf2, size);
63 grub_free (buf2);
65 return GRUB_ERR_NONE;
68 GRUB_MOD_INIT(raid5rec)
70 grub_raid5_recover_func = grub_raid5_recover;
73 GRUB_MOD_FINI(raid5rec)
75 grub_raid5_recover_func = 0;