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
37 } __attribute__ ((packed
));
42 grub_uint8_t unused
[308];
43 struct grub_dvh_partition_descriptor parts
[16];
44 grub_uint32_t checksum
;
45 grub_uint32_t unused2
;
46 } __attribute__ ((packed
));
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);
66 dvh_partition_map_iterate (grub_disk_t disk
,
67 int (*hook
) (grub_disk_t disk
,
68 const grub_partition_t partition
))
70 struct grub_partition p
;
73 struct grub_dvh_block dvh
;
79 p
.partmap
= &grub_dvh_partition_map
;
80 err
= grub_disk_read (disk
, 0, 0, sizeof (struct grub_dvh_block
),
85 if (DVH_MAGIC
!= grub_be_to_cpu32 (block
.dvh
.magic
))
86 return grub_error (GRUB_ERR_BAD_PART_TABLE
, "not a dvh partition table");
88 if (! grub_dvh_is_valid (block
.raw
))
89 return grub_error (GRUB_ERR_BAD_PART_TABLE
, "invalid checksum");
91 /* Maybe another error value would be better, because partition
92 table _is_ recognized but invalid. */
93 for (partnum
= 0; partnum
< ARRAY_SIZE (block
.dvh
.parts
); partnum
++)
95 if (block
.dvh
.parts
[partnum
].length
== 0)
101 p
.start
= grub_be_to_cpu32 (block
.dvh
.parts
[partnum
].start
);
102 p
.len
= grub_be_to_cpu32 (block
.dvh
.parts
[partnum
].length
);
103 p
.number
= p
.index
= partnum
;
112 /* Partition map type. */
113 static struct grub_partition_map grub_dvh_partition_map
=
116 .iterate
= dvh_partition_map_iterate
,
119 GRUB_MOD_INIT(part_dvh
)
121 grub_partition_map_register (&grub_dvh_partition_map
);
124 GRUB_MOD_FINI(part_dvh
)
126 grub_partition_map_unregister (&grub_dvh_partition_map
);