Indentation fix, cleanup.
[AROS.git] / arch / all-pc / boot / grub2-aros / grub-core / partmap / plan.c
blob83db2241c3cc7b1b77dfab8759f395bd210b6ccc
1 /*
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>
21 #include <grub/mm.h>
22 #include <grub/misc.h>
23 #include <grub/dl.h>
24 #include <grub/symbol.h>
25 #include <grub/types.h>
26 #include <grub/err.h>
28 GRUB_MOD_LICENSE ("GPLv3+");
30 static struct grub_partition_map grub_plan_partition_map;
32 static grub_err_t
33 plan_partition_map_iterate (grub_disk_t disk,
34 grub_partition_iterate_hook_t hook,
35 void *hook_data)
37 struct grub_partition p;
38 int ptr = 0;
39 grub_err_t err;
41 p.partmap = &grub_plan_partition_map;
42 p.msdostype = 0;
44 for (p.number = 0; ; p.number++)
46 char sig[sizeof ("part ") - 1];
47 char c;
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);
53 if (err)
54 return err;
55 if (grub_memcmp (sig, "part ", sizeof ("part ") - 1) != 0)
56 break;
57 ptr += sizeof (sig);
60 err = grub_disk_read (disk, 1, ptr, 1, &c);
61 if (err)
62 return err;
63 ptr++;
65 while (grub_isdigit (c) || grub_isalpha (c));
66 if (c != ' ')
67 break;
68 p.start = 0;
69 while (1)
71 err = grub_disk_read (disk, 1, ptr, 1, &c);
72 if (err)
73 return err;
74 ptr++;
75 if (!grub_isdigit (c))
76 break;
77 p.start = p.start * 10 + (c - '0');
79 if (c != ' ')
80 break;
81 p.len = 0;
82 while (1)
84 err = grub_disk_read (disk, 1, ptr, 1, &c);
85 if (err)
86 return err;
87 ptr++;
88 if (!grub_isdigit (c))
89 break;
90 p.len = p.len * 10 + (c - '0');
92 if (c != '\n')
93 break;
94 p.len -= p.start;
95 if (hook (disk, &p, hook_data))
96 return grub_errno;
98 if (p.number == 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 =
107 .name = "plan",
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);