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
;
26 grub_partition_map_register (grub_partition_map_t partmap
)
28 partmap
->next
= grub_partition_map_list
;
29 grub_partition_map_list
= partmap
;
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
)
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
)
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
);
70 if (grub_errno
== GRUB_ERR_BAD_PART_TABLE
)
72 /* Continue to next partition map type. */
73 grub_errno
= GRUB_ERR_NONE
;
80 /* Use the first partition map type found. */
81 grub_partition_map_iterate (part_map_probe
);
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;
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
)))
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
;
117 grub_dprintf ("partition", "%s detection succeeded.\n", p
->name
);
122 grub_partition_map_iterate (part_map_iterate
);
124 ret
= partmap
->iterate (disk
, hook
);
130 grub_partition_get_name (const grub_partition_t partition
)
132 return partition
->partmap
->get_name (partition
);