2 * ----------------------------------------------------------------------------
3 * "THE BEER-WARE LICENSE" (Revision 42):
4 * <phk@FreeBSD.org> wrote this file. As long as you retain this notice you
5 * can do whatever you want with this stuff. If we meet some day, and you think
6 * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
7 * ----------------------------------------------------------------------------
10 #include <sys/cdefs.h>
11 __FBSDID("$FreeBSD$");
20 #include <sys/sysctl.h>
21 #include <sys/stdint.h>
22 #include <sys/types.h>
24 #include <sys/ioctl.h>
25 #include <sys/disklabel.h>
35 #define DPRINT(x) warn x
36 #define DPRINTX(x) warnx x
43 Int_Open_Disk(const char *name, char *conftxt)
47 char *p, *q, *r, *a, *b, *n, *t, *sn;
49 u_int l, s, ty, sc, hd, alt;
52 for (p = conftxt; p != NULL && *p; p = strchr(p, '\n')) {
60 if (strcmp(a, "DISK"))
73 d = (struct disk *)calloc(sizeof *d, 1);
77 d->name = strdup(name);
79 a = strsep(&p, " "); /* length in bytes */
80 len = strtoimax(a, &r, 0);
82 printf("BARF %d <%d>\n", __LINE__, *r);
86 a = strsep(&p, " "); /* sectorsize */
87 s = strtoul(a, &r, 0);
89 printf("BARF %d <%d>\n", __LINE__, *r);
96 len /= s; /* media size in number of sectors. */
98 if (Add_Chunk(d, 0, len, name, whole, 0, 0, "-")) {
99 DPRINT(("Failed to add 'whole' chunk"));
107 o = strtoimax(b, &r, 0);
109 printf("BARF %d <%d>\n", __LINE__, *r);
112 if (!strcmp(a, "hd"))
114 else if (!strcmp(a, "sc"))
117 printf("HUH ? <%s> <%s>\n", a, b);
121 * Calculate the number of cylinders this disk must have. If we have
122 * an obvious insanity, we set the number of cylinders to zero.
124 o = d->bios_hd * d->bios_sect;
125 d->bios_cyl = (o != 0) ? len / o : 0;
130 for (; p != NULL && *p; p = q) {
135 a = strsep(&p, " "); /* Index */
138 l = strtoimax(a, &r, 0);
140 printf("BARF %d <%d>\n", __LINE__, *r);
143 t = strsep(&p, " "); /* Type {SUN, BSD, MBR, PC98, GPT} */
144 n = strsep(&p, " "); /* name */
145 a = strsep(&p, " "); /* len */
146 len = strtoimax(a, &r, 0);
148 printf("BARF %d <%d>\n", __LINE__, *r);
151 a = strsep(&p, " "); /* secsize */
152 s = strtoimax(a, &r, 0);
154 printf("BARF %d <%d>\n", __LINE__, *r);
161 /* XXX: Slice name may include a space. */
162 if (!strcmp(a, "sn")) {
167 o = strtoimax(b, &r, 0);
168 /* APPLE have ty as a string */
169 if ((*r) && (strcmp(t, "APPLE") && strcmp(t, "GPT"))) {
170 printf("BARF %d <%d>\n", __LINE__, *r);
175 else if (!strcmp(a, "i"))
177 else if (!strcmp(a, "ty"))
179 else if (!strcmp(a, "sc"))
181 else if (!strcmp(a, "hd"))
183 else if (!strcmp(a, "alt"))
187 /* PLATFORM POLICY BEGIN ----------------------------------- */
188 if (platform == p_sparc64 && !strcmp(t, "SUN") && i == 2)
190 if (platform == p_sparc64 && !strcmp(t, "SUN") &&
191 d->chunks->part->part == NULL) {
194 o = d->chunks->size / (hd * sc);
197 if (Add_Chunk(d, 0, o, name, freebsd, 0, 0, "-")) {
198 DPRINT(("Failed to add 'freebsd' chunk"));
201 if (platform == p_alpha && !strcmp(t, "BSD") &&
202 d->chunks->part->part == NULL) {
203 if (Add_Chunk(d, 0, d->chunks->size, name, freebsd,
205 DPRINT(("Failed to add 'freebsd' chunk"));
208 if (!strcmp(t, "BSD") && i == RAW_PART)
210 /* PLATFORM POLICY END ------------------------------------- */
216 if (!strcmp(t, "SUN"))
217 i = Add_Chunk(d, off, len, n, part, 0, 0, 0);
218 else if (!strncmp(t, "MBR", 3)) {
221 i = Add_Chunk(d, off, len, n, freebsd, ty, 0, 0);
229 i = Add_Chunk(d, off, len, n, fat, ty, 0, 0);
232 i = Add_Chunk(d, off, len, n, efi, ty, 0, 0);
235 i = Add_Chunk(d, off, len, n, mbr, ty, 0, 0);
238 } else if (!strcmp(t, "BSD"))
239 i = Add_Chunk(d, off, len, n, part, ty, 0, 0);
240 else if (!strcmp(t, "PC98")) {
243 i = Add_Chunk(d, off, len, n, freebsd, ty, 0,
251 i = Add_Chunk(d, off, len, n, fat, ty, 0, sn);
254 i = Add_Chunk(d, off, len, n, pc98, ty, 0, sn);
257 } else if (!strcmp(t, "GPT"))
258 i = Add_Chunk(d, off, len, n, gpt, 0, 0, b);
259 else if (!strcmp(t, "APPLE"))
260 i = Add_Chunk(d, off, len, n, apple, 0, 0, sn);
262 ; /* Ignore unknown classes. */
264 /* PLATFORM POLICY BEGIN ------------------------------------- */
265 /* We have a chance to do things on a blank disk here */
266 if (platform == p_sparc64 && d->chunks->part->part == NULL) {
269 o = d->chunks->size / (hd * sc);
272 if (Add_Chunk(d, 0, o, name, freebsd, 0, 0, "-")) {
273 DPRINT(("Failed to add 'freebsd' chunk"));
276 /* PLATFORM POLICY END --------------------------------------- */