2
* GRUB -- GRand Unified Bootloader
3
* Copyright (C) 2010 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
static struct grub_partition_map grub_plan_partition_map;
33
plan_partition_map_iterate (grub_disk_t disk,
34
int (*hook) (grub_disk_t disk,
35
const grub_partition_t partition))
37
struct grub_partition p;
41
p.partmap = &grub_plan_partition_map;
44
for (p.number = 0; ; p.number++)
46
char sig[sizeof ("part ") - 1];
49
p.offset = (ptr >> GRUB_DISK_SECTOR_BITS) + 1;
50
p.index = ptr & (GRUB_DISK_SECTOR_SIZE - 1);
52
err = grub_disk_read (disk, 1, ptr, sizeof (sig), sig);
55
if (grub_memcmp (sig, "part ", sizeof ("part ") - 1) != 0)
60
err = grub_disk_read (disk, 1, ptr, 1, &c);
65
while (grub_isdigit (c) || grub_isalpha (c));
71
err = grub_disk_read (disk, 1, ptr, 1, &c);
75
if (!grub_isdigit (c))
77
p.start = p.start * 10 + (c - '0');
84
err = grub_disk_read (disk, 1, ptr, 1, &c);
88
if (!grub_isdigit (c))
90
p.len = p.len * 10 + (c - '0');
99
return grub_error (GRUB_ERR_BAD_PART_TABLE, "not a plan partition table");
101
return GRUB_ERR_NONE;
104
/* Partition map type. */
105
static struct grub_partition_map grub_plan_partition_map =
108
.iterate = plan_partition_map_iterate,
111
GRUB_MOD_INIT(part_plan)
113
grub_partition_map_register (&grub_plan_partition_map);
116
GRUB_MOD_FINI(part_plan)
118
grub_partition_map_unregister (&grub_plan_partition_map);