raid5_recover.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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.
  5. *
  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.
  10. *
  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.
  15. *
  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/>.
  18. */
  19. #include <grub/dl.h>
  20. #include <grub/disk.h>
  21. #include <grub/mm.h>
  22. #include <grub/err.h>
  23. #include <grub/misc.h>
  24. #include <grub/raid.h>
  25. static grub_err_t
  26. grub_raid5_recover (struct grub_raid_array *array, int disknr,
  27. char *buf, grub_disk_addr_t sector, int size)
  28. {
  29. char *buf2;
  30. int i;
  31. size <<= GRUB_DISK_SECTOR_BITS;
  32. buf2 = grub_malloc (size);
  33. if (!buf2)
  34. return grub_errno;
  35. grub_memset (buf, 0, size);
  36. for (i = 0; i < (int) array->total_devs; i++)
  37. {
  38. grub_err_t err;
  39. if (i == disknr)
  40. continue;
  41. err = grub_disk_read (array->device[i], sector, 0, size, buf2);
  42. if (err)
  43. {
  44. grub_free (buf2);
  45. return err;
  46. }
  47. grub_raid_block_xor (buf, buf2, size);
  48. }
  49. grub_free (buf2);
  50. return GRUB_ERR_NONE;
  51. }
  52. GRUB_MOD_INIT(raid5rec)
  53. {
  54. grub_raid5_recover_func = grub_raid5_recover;
  55. }
  56. GRUB_MOD_FINI(raid5rec)
  57. {
  58. grub_raid5_recover_func = 0;
  59. }