| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: partitions.c,v 1.9 2020/01/27 21:21:22 martin Exp $ */ | | 1 | /* $NetBSD: partitions.c,v 1.10 2020/01/28 07:43:42 martin Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright 2018 The NetBSD Foundation, Inc. | | 4 | * Copyright 2018 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -31,51 +31,67 @@ | | | @@ -31,51 +31,67 @@ |
31 | #include "mbr.h" | | 31 | #include "mbr.h" |
32 | #include <assert.h> | | 32 | #include <assert.h> |
33 | | | 33 | |
34 | /* | | 34 | /* |
35 | * A list of partitioning schemes, so we can iterate over everything | | 35 | * A list of partitioning schemes, so we can iterate over everything |
36 | * supported (e.g. when partitioning a new disk). NULL terminated. | | 36 | * supported (e.g. when partitioning a new disk). NULL terminated. |
37 | */ | | 37 | */ |
38 | const struct disk_partitioning_scheme **available_part_schemes; | | 38 | const struct disk_partitioning_scheme **available_part_schemes; |
39 | /* | | 39 | /* |
40 | * The number of valid entries on above list | | 40 | * The number of valid entries on above list |
41 | */ | | 41 | */ |
42 | size_t num_available_part_schemes; | | 42 | size_t num_available_part_schemes; |
43 | | | 43 | |
| | | 44 | extern const struct disk_partitioning_scheme disklabel_parts; |
| | | 45 | |
44 | /* | | 46 | /* |
45 | * Generic reader - query a disk device and read all partitions from it. | | 47 | * Generic reader - query a disk device and read all partitions from it. |
46 | * disk_size is in units of physical sector size, which is passe as | | 48 | * disk_size is in units of physical sector size, which is passe as |
47 | * bytes_per_sec. | | 49 | * bytes_per_sec. |
48 | */ | | 50 | */ |
49 | struct disk_partitions * | | 51 | struct disk_partitions * |
50 | partitions_read_disk(const char *dev, daddr_t disk_size, size_t bytes_per_sec, | | 52 | partitions_read_disk(const char *dev, daddr_t disk_size, size_t bytes_per_sec, |
51 | bool no_mbr) | | 53 | bool no_mbr) |
52 | { | | 54 | { |
53 | const struct disk_partitioning_scheme **ps; | | 55 | const struct disk_partitioning_scheme **ps; |
| | | 56 | #ifdef HAVE_MBR |
| | | 57 | bool mbr_done = false, disklabel_done = false; |
| | | 58 | #endif |
54 | | | 59 | |
55 | if (!available_part_schemes) | | 60 | if (!available_part_schemes) |
56 | return NULL; | | 61 | return NULL; |
57 | | | 62 | |
58 | for (ps = available_part_schemes; *ps; ps++) { | | 63 | for (ps = available_part_schemes; *ps; ps++) { |
59 | #ifdef HAVE_MBR | | 64 | #ifdef HAVE_MBR |
| | | 65 | if (!no_mbr && (*ps) == &disklabel_parts && !mbr_done) |
| | | 66 | continue; |
60 | if (no_mbr && (*ps)->name == MSG_parttype_mbr) | | 67 | if (no_mbr && (*ps)->name == MSG_parttype_mbr) |
61 | continue; | | 68 | continue; |
| | | 69 | if ((*ps)->name == MSG_parttype_mbr) |
| | | 70 | mbr_done = true; |
| | | 71 | if ((*ps)->read_from_disk == disklabel_parts.read_from_disk) |
| | | 72 | disklabel_done = true; |
62 | #endif | | 73 | #endif |
63 | struct disk_partitions *parts = | | 74 | struct disk_partitions *parts = |
64 | (*ps)->read_from_disk(dev, 0, disk_size, bytes_per_sec, | | 75 | (*ps)->read_from_disk(dev, 0, disk_size, bytes_per_sec, |
65 | *ps); | | 76 | *ps); |
66 | if (parts) | | 77 | if (parts) |
67 | return parts; | | 78 | return parts; |
68 | } | | 79 | } |
| | | 80 | #ifdef HAVE_MBR |
| | | 81 | if (!disklabel_done) |
| | | 82 | return disklabel_parts.read_from_disk(dev, 0, disk_size, |
| | | 83 | bytes_per_sec, &disklabel_parts); |
| | | 84 | #endif |
69 | return NULL; | | 85 | return NULL; |
70 | } | | 86 | } |
71 | | | 87 | |
72 | bool | | 88 | bool |
73 | generic_adapt_foreign_part_info(const struct disk_partitions *myself, | | 89 | generic_adapt_foreign_part_info(const struct disk_partitions *myself, |
74 | struct disk_part_info *dest, | | 90 | struct disk_part_info *dest, |
75 | const struct disk_partitioning_scheme *src_scheme, | | 91 | const struct disk_partitioning_scheme *src_scheme, |
76 | const struct disk_part_info *src) | | 92 | const struct disk_part_info *src) |
77 | { | | 93 | { |
78 | *dest = *src; | | 94 | *dest = *src; |
79 | if (myself->pscheme == src_scheme) | | 95 | if (myself->pscheme == src_scheme) |
80 | return true; /* no conversion needed */ | | 96 | return true; /* no conversion needed */ |
81 | | | 97 | |
| @@ -107,27 +123,26 @@ generic_adapt_foreign_part_info(const st | | | @@ -107,27 +123,26 @@ generic_adapt_foreign_part_info(const st |
107 | struct part_scheme_desc { | | 123 | struct part_scheme_desc { |
108 | bool (*is_available)(void); | | 124 | bool (*is_available)(void); |
109 | const struct disk_partitioning_scheme *ps; | | 125 | const struct disk_partitioning_scheme *ps; |
110 | }; | | 126 | }; |
111 | | | 127 | |
112 | #ifdef HAVE_GPT | | 128 | #ifdef HAVE_GPT |
113 | bool gpt_parts_check(void); | | 129 | bool gpt_parts_check(void); |
114 | extern const struct disk_partitioning_scheme gpt_parts; | | 130 | extern const struct disk_partitioning_scheme gpt_parts; |
115 | #endif | | 131 | #endif |
116 | #ifdef HAVE_MBR | | 132 | #ifdef HAVE_MBR |
117 | extern const struct disk_partitioning_scheme mbr_parts; | | 133 | extern const struct disk_partitioning_scheme mbr_parts; |
118 | #endif | | 134 | #endif |
119 | | | 135 | |
120 | extern const struct disk_partitioning_scheme disklabel_parts; | | | |
121 | #if RAW_PART != 2 | | 136 | #if RAW_PART != 2 |
122 | static struct disk_partitioning_scheme only_disklabel_parts; | | 137 | static struct disk_partitioning_scheme only_disklabel_parts; |
123 | | | 138 | |
124 | /* | | 139 | /* |
125 | * If not overriden by MD code, we can not boot from plain | | 140 | * If not overriden by MD code, we can not boot from plain |
126 | * disklabel disks (w/o MBR). | | 141 | * disklabel disks (w/o MBR). |
127 | */ | | 142 | */ |
128 | static bool have_only_disklabel_boot_support(const char *disk) | | 143 | static bool have_only_disklabel_boot_support(const char *disk) |
129 | { | | 144 | { |
130 | #ifdef HAVE_PLAIN_DISKLABEL_BOOT | | 145 | #ifdef HAVE_PLAIN_DISKLABEL_BOOT |
131 | return HAVE_PLAIN_DISKLABEL_BOOT(disk); | | 146 | return HAVE_PLAIN_DISKLABEL_BOOT(disk); |
132 | #else | | 147 | #else |
133 | return false; | | 148 | return false; |