2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2002,2005,2006,2007,2011 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19 #include <grub/partition.h>
20 #include <grub/disk.h>
22 #include <grub/misc.h>
24 #include <grub/symbol.h>
25 #include <grub/types.h>
28 GRUB_MOD_LICENSE ("GPLv3+");
30 #define DVH_MAGIC 0x0be5a941
32 struct grub_dvh_partition_descriptor
42 grub_uint8_t unused
[308];
43 struct grub_dvh_partition_descriptor parts
[16];
44 grub_uint32_t checksum
;
45 grub_uint32_t unused2
;
48 static struct grub_partition_map grub_dvh_partition_map
;
50 /* Verify checksum (true=ok). */
52 grub_dvh_is_valid (grub_uint32_t
*label
)
55 grub_uint32_t sum
= 0;
58 pos
< (label
+ sizeof (struct grub_dvh_block
) / 4);
60 sum
+= grub_be_to_cpu32 (*pos
);
66 dvh_partition_map_iterate (grub_disk_t disk
,
67 grub_partition_iterate_hook_t hook
, void *hook_data
)
69 struct grub_partition p
;
72 struct grub_dvh_block dvh
;
78 p
.partmap
= &grub_dvh_partition_map
;
79 err
= grub_disk_read (disk
, 0, 0, sizeof (struct grub_dvh_block
),
84 if (DVH_MAGIC
!= grub_be_to_cpu32 (block
.dvh
.magic
))
85 return grub_error (GRUB_ERR_BAD_PART_TABLE
, "not a dvh partition table");
87 if (! grub_dvh_is_valid (block
.raw
))
88 return grub_error (GRUB_ERR_BAD_PART_TABLE
, "invalid checksum");
90 /* Maybe another error value would be better, because partition
91 table _is_ recognized but invalid. */
92 for (partnum
= 0; partnum
< ARRAY_SIZE (block
.dvh
.parts
); partnum
++)
94 if (block
.dvh
.parts
[partnum
].length
== 0)
100 p
.start
= grub_be_to_cpu32 (block
.dvh
.parts
[partnum
].start
);
101 p
.len
= grub_be_to_cpu32 (block
.dvh
.parts
[partnum
].length
);
102 p
.number
= p
.index
= partnum
;
103 if (hook (disk
, &p
, hook_data
))
111 /* Partition map type. */
112 static struct grub_partition_map grub_dvh_partition_map
=
115 .iterate
= dvh_partition_map_iterate
,
118 GRUB_MOD_INIT(part_dvh
)
120 grub_partition_map_register (&grub_dvh_partition_map
);
123 GRUB_MOD_FINI(part_dvh
)
125 grub_partition_map_unregister (&grub_dvh_partition_map
);