aboutsummaryrefslogtreecommitdiffstats
path: root/include/grub/raid.h
blob: d5853639d53edda619f8829fe5ac8b0afa727335 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* raid.h - On disk structures for RAID. */
/*
 *  GRUB  --  GRand Unified Bootloader
 *  Copyright (C) 2006,2007,2008,2010  Free Software Foundation, Inc.
 *
 *  GRUB 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 3 of the License, or
 *  (at your option) any later version.
 *
 *  GRUB 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 GRUB.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef GRUB_RAID_H
#define GRUB_RAID_H	1

#include <grub/types.h>

#define GRUB_RAID_LAYOUT_LEFT_ASYMMETRIC	0
#define GRUB_RAID_LAYOUT_RIGHT_ASYMMETRIC	1
#define GRUB_RAID_LAYOUT_LEFT_SYMMETRIC		2
#define GRUB_RAID_LAYOUT_RIGHT_SYMMETRIC	3

#define GRUB_RAID_LAYOUT_RIGHT_MASK		1
#define GRUB_RAID_LAYOUT_SYMMETRIC_MASK		2

struct grub_raid_member
{
  grub_disk_t device;  /* Array of total_devs devices. */
  grub_disk_addr_t start_sector;
  /* Start of each device, in 512 byte sectors. */
};

struct grub_raid_array
{
  int number;              /* The device number, taken from md_minor so we
			      are consistent with the device name in
			      Linux. */
  int level;               /* RAID levels, only 0, 1 or 5 at the moment. */
  int layout;              /* Layout for RAID 5/6.  */
  unsigned int total_devs; /* Total number of devices in the array. */
  grub_size_t chunk_size;  /* The size of a chunk, in 512 byte sectors. */
  grub_uint64_t disk_size; /* Size of an individual disk, in 512 byte
			      sectors. */
  unsigned int index;               /* Index of current device.  */
  int uuid_len;            /* The length of uuid.  */
  char *uuid;              /* The UUID of the device. */

  /* The following field is setup by the caller.  */
  char *name;              /* That will be "md<number>". */
  unsigned int nr_devs;    /* The number of devices we've found so far. */
  unsigned int allocated_devs;
  struct grub_raid_member *members;
  struct grub_raid_array *next;

#ifdef GRUB_UTIL
  struct grub_raid *driver;
#endif
};

struct grub_raid
{
  const char *name;

  grub_err_t (*detect) (grub_disk_t disk, struct grub_raid_array *array,
                        grub_disk_addr_t *start_sector);

  struct grub_raid *next;
};
typedef struct grub_raid *grub_raid_t;

void grub_raid_register (grub_raid_t raid);
void grub_raid_unregister (grub_raid_t raid);

void grub_raid_block_xor (char *buf1, const char *buf2, int size);

typedef grub_err_t (*grub_raid5_recover_func_t) (struct grub_raid_array *array,
                                                 int disknr, char *buf,
                                                 grub_disk_addr_t sector,
                                                 int size);

typedef grub_err_t (*grub_raid6_recover_func_t) (struct grub_raid_array *array,
                                                 int disknr, int p, char *buf,
                                                 grub_disk_addr_t sector,
                                                 int size);

extern grub_raid5_recover_func_t grub_raid5_recover_func;
extern grub_raid6_recover_func_t grub_raid6_recover_func;

#endif /* ! GRUB_RAID_H */