style fix
[grub2/phcoder.git] / kern / partition.c
blob4d5c63a95cbceb0afb90b39a68d028675bf8f0c1
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2004,2007 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/misc.h>
20 #include <grub/partition.h>
21 #include <grub/disk.h>
23 static grub_partition_map_t grub_partition_map_list;
25 void
26 grub_partition_map_register (grub_partition_map_t partmap)
28 partmap->next = grub_partition_map_list;
29 grub_partition_map_list = partmap;
32 void
33 grub_partition_map_unregister (grub_partition_map_t partmap)
35 grub_partition_map_t *p, q;
37 for (p = &grub_partition_map_list, q = *p; q; p = &(q->next), q = q->next)
38 if (q == partmap)
40 *p = q->next;
41 break;
45 int
46 grub_partition_map_iterate (int (*hook) (const grub_partition_map_t partmap))
48 grub_partition_map_t p;
50 for (p = grub_partition_map_list; p; p = p->next)
51 if (hook (p))
52 return 1;
54 return 0;
57 grub_partition_t
58 grub_partition_probe (struct grub_disk *disk, const char *str)
60 grub_partition_t part = 0;
62 auto int part_map_probe (const grub_partition_map_t partmap);
64 int part_map_probe (const grub_partition_map_t partmap)
66 part = partmap->probe (disk, str);
67 if (part)
68 return 1;
70 if (grub_errno == GRUB_ERR_BAD_PART_TABLE)
72 /* Continue to next partition map type. */
73 grub_errno = GRUB_ERR_NONE;
74 return 0;
77 return 1;
80 /* Use the first partition map type found. */
81 grub_partition_map_iterate (part_map_probe);
83 return part;
86 int
87 grub_partition_iterate (struct grub_disk *disk,
88 int (*hook) (grub_disk_t disk,
89 const grub_partition_t partition))
91 grub_partition_map_t partmap = 0;
92 int ret = 0;
94 auto int part_map_iterate (const grub_partition_map_t p);
95 auto int part_map_iterate_hook (grub_disk_t d,
96 const grub_partition_t partition);
98 int part_map_iterate_hook (grub_disk_t d __attribute__ ((unused)),
99 const grub_partition_t partition __attribute__ ((unused)))
101 return 1;
104 int part_map_iterate (const grub_partition_map_t p)
106 grub_dprintf ("partition", "Detecting %s...\n", p->name);
107 p->iterate (disk, part_map_iterate_hook);
109 if (grub_errno != GRUB_ERR_NONE)
111 /* Continue to next partition map type. */
112 grub_dprintf ("partition", "%s detection failed.\n", p->name);
113 grub_errno = GRUB_ERR_NONE;
114 return 0;
117 grub_dprintf ("partition", "%s detection succeeded.\n", p->name);
118 partmap = p;
119 return 1;
122 grub_partition_map_iterate (part_map_iterate);
123 if (partmap)
124 ret = partmap->iterate (disk, hook);
126 return ret;
129 char *
130 grub_partition_get_name (const grub_partition_t partition)
132 return partition->partmap->get_name (partition);