xref: /freebsd/sys/geom/part/g_part_mbr.c (revision 3ef51c5fb9163f2aafb1c14729e06a8bf0c4d113)
1 /*-
2  * Copyright (c) 2007, 2008 Marcel Moolenaar
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29 
30 #include <sys/param.h>
31 #include <sys/bio.h>
32 #include <sys/diskmbr.h>
33 #include <sys/endian.h>
34 #include <sys/kernel.h>
35 #include <sys/kobj.h>
36 #include <sys/limits.h>
37 #include <sys/lock.h>
38 #include <sys/malloc.h>
39 #include <sys/mutex.h>
40 #include <sys/queue.h>
41 #include <sys/sbuf.h>
42 #include <sys/systm.h>
43 #include <sys/sysctl.h>
44 #include <geom/geom.h>
45 #include <geom/part/g_part.h>
46 
47 #include "g_part_if.h"
48 
49 FEATURE(geom_part_mbr, "GEOM partitioning class for MBR support");
50 
51 #define	MBRSIZE		512
52 
53 struct g_part_mbr_table {
54 	struct g_part_table	base;
55 	u_char		mbr[MBRSIZE];
56 };
57 
58 struct g_part_mbr_entry {
59 	struct g_part_entry	base;
60 	struct dos_partition ent;
61 };
62 
63 static int g_part_mbr_add(struct g_part_table *, struct g_part_entry *,
64     struct g_part_parms *);
65 static int g_part_mbr_bootcode(struct g_part_table *, struct g_part_parms *);
66 static int g_part_mbr_create(struct g_part_table *, struct g_part_parms *);
67 static int g_part_mbr_destroy(struct g_part_table *, struct g_part_parms *);
68 static void g_part_mbr_dumpconf(struct g_part_table *, struct g_part_entry *,
69     struct sbuf *, const char *);
70 static int g_part_mbr_dumpto(struct g_part_table *, struct g_part_entry *);
71 static int g_part_mbr_modify(struct g_part_table *, struct g_part_entry *,
72     struct g_part_parms *);
73 static const char *g_part_mbr_name(struct g_part_table *, struct g_part_entry *,
74     char *, size_t);
75 static int g_part_mbr_probe(struct g_part_table *, struct g_consumer *);
76 static int g_part_mbr_read(struct g_part_table *, struct g_consumer *);
77 static int g_part_mbr_setunset(struct g_part_table *, struct g_part_entry *,
78     const char *, unsigned int);
79 static const char *g_part_mbr_type(struct g_part_table *, struct g_part_entry *,
80     char *, size_t);
81 static int g_part_mbr_write(struct g_part_table *, struct g_consumer *);
82 static int g_part_mbr_resize(struct g_part_table *, struct g_part_entry *,
83     struct g_part_parms *);
84 
85 static kobj_method_t g_part_mbr_methods[] = {
86 	KOBJMETHOD(g_part_add,		g_part_mbr_add),
87 	KOBJMETHOD(g_part_bootcode,	g_part_mbr_bootcode),
88 	KOBJMETHOD(g_part_create,	g_part_mbr_create),
89 	KOBJMETHOD(g_part_destroy,	g_part_mbr_destroy),
90 	KOBJMETHOD(g_part_dumpconf,	g_part_mbr_dumpconf),
91 	KOBJMETHOD(g_part_dumpto,	g_part_mbr_dumpto),
92 	KOBJMETHOD(g_part_modify,	g_part_mbr_modify),
93 	KOBJMETHOD(g_part_resize,	g_part_mbr_resize),
94 	KOBJMETHOD(g_part_name,		g_part_mbr_name),
95 	KOBJMETHOD(g_part_probe,	g_part_mbr_probe),
96 	KOBJMETHOD(g_part_read,		g_part_mbr_read),
97 	KOBJMETHOD(g_part_setunset,	g_part_mbr_setunset),
98 	KOBJMETHOD(g_part_type,		g_part_mbr_type),
99 	KOBJMETHOD(g_part_write,	g_part_mbr_write),
100 	{ 0, 0 }
101 };
102 
103 static struct g_part_scheme g_part_mbr_scheme = {
104 	"MBR",
105 	g_part_mbr_methods,
106 	sizeof(struct g_part_mbr_table),
107 	.gps_entrysz = sizeof(struct g_part_mbr_entry),
108 	.gps_minent = NDOSPART,
109 	.gps_maxent = NDOSPART,
110 	.gps_bootcodesz = MBRSIZE,
111 };
112 G_PART_SCHEME_DECLARE(g_part_mbr);
113 
114 static struct g_part_mbr_alias {
115 	u_char		typ;
116 	int		alias;
117 } mbr_alias_match[] = {
118 	{ DOSPTYP_386BSD,	G_PART_ALIAS_FREEBSD },
119 	{ DOSPTYP_EXT,		G_PART_ALIAS_EBR },
120 	{ DOSPTYP_NTFS,		G_PART_ALIAS_MS_NTFS },
121 	{ DOSPTYP_FAT32,	G_PART_ALIAS_MS_FAT32 },
122 	{ DOSPTYP_EXTLBA,	G_PART_ALIAS_EBR },
123 	{ DOSPTYP_LDM,		G_PART_ALIAS_MS_LDM_DATA },
124 	{ DOSPTYP_LINSWP,	G_PART_ALIAS_LINUX_SWAP },
125 	{ DOSPTYP_LINUX,	G_PART_ALIAS_LINUX_DATA },
126 	{ DOSPTYP_LINLVM,	G_PART_ALIAS_LINUX_LVM },
127 	{ DOSPTYP_LINRAID,	G_PART_ALIAS_LINUX_RAID },
128 	{ DOSPTYP_PPCBOOT,	G_PART_ALIAS_FREEBSD_BOOT },
129 };
130 
131 static int
132 mbr_parse_type(const char *type, u_char *dp_typ)
133 {
134 	const char *alias;
135 	char *endp;
136 	long lt;
137 	int i;
138 
139 	if (type[0] == '!') {
140 		lt = strtol(type + 1, &endp, 0);
141 		if (type[1] == '\0' || *endp != '\0' || lt <= 0 || lt >= 256)
142 			return (EINVAL);
143 		*dp_typ = (u_char)lt;
144 		return (0);
145 	}
146 	for (i = 0;
147 	    i < sizeof(mbr_alias_match) / sizeof(mbr_alias_match[0]); i++) {
148 		alias = g_part_alias_name(mbr_alias_match[i].alias);
149 		if (strcasecmp(type, alias) == 0) {
150 			*dp_typ = mbr_alias_match[i].typ;
151 			return (0);
152 		}
153 	}
154 	return (EINVAL);
155 }
156 
157 static int
158 mbr_probe_bpb(u_char *bpb)
159 {
160 	uint16_t secsz;
161 	uint8_t clstsz;
162 
163 #define PO2(x)	((x & (x - 1)) == 0)
164 	secsz = le16dec(bpb);
165 	if (secsz < 512 || secsz > 4096 || !PO2(secsz))
166 		return (0);
167 	clstsz = bpb[2];
168 	if (clstsz < 1 || clstsz > 128 || !PO2(clstsz))
169 		return (0);
170 #undef PO2
171 
172 	return (1);
173 }
174 
175 static void
176 mbr_set_chs(struct g_part_table *table, uint32_t lba, u_char *cylp, u_char *hdp,
177     u_char *secp)
178 {
179 	uint32_t cyl, hd, sec;
180 
181 	sec = lba % table->gpt_sectors + 1;
182 	lba /= table->gpt_sectors;
183 	hd = lba % table->gpt_heads;
184 	lba /= table->gpt_heads;
185 	cyl = lba;
186 	if (cyl > 1023)
187 		sec = hd = cyl = ~0;
188 
189 	*cylp = cyl & 0xff;
190 	*hdp = hd & 0xff;
191 	*secp = (sec & 0x3f) | ((cyl >> 2) & 0xc0);
192 }
193 
194 static int
195 g_part_mbr_add(struct g_part_table *basetable, struct g_part_entry *baseentry,
196     struct g_part_parms *gpp)
197 {
198 	struct g_part_mbr_entry *entry;
199 	struct g_part_mbr_table *table;
200 	uint32_t start, size, sectors;
201 
202 	if (gpp->gpp_parms & G_PART_PARM_LABEL)
203 		return (EINVAL);
204 
205 	sectors = basetable->gpt_sectors;
206 
207 	entry = (struct g_part_mbr_entry *)baseentry;
208 	table = (struct g_part_mbr_table *)basetable;
209 
210 	start = gpp->gpp_start;
211 	size = gpp->gpp_size;
212 	if (size < sectors)
213 		return (EINVAL);
214 	if (start % sectors) {
215 		size = size - sectors + (start % sectors);
216 		start = start - (start % sectors) + sectors;
217 	}
218 	if (size % sectors)
219 		size = size - (size % sectors);
220 	if (size < sectors)
221 		return (EINVAL);
222 
223 	if (baseentry->gpe_deleted)
224 		bzero(&entry->ent, sizeof(entry->ent));
225 
226 	KASSERT(baseentry->gpe_start <= start, ("%s", __func__));
227 	KASSERT(baseentry->gpe_end >= start + size - 1, ("%s", __func__));
228 	baseentry->gpe_start = start;
229 	baseentry->gpe_end = start + size - 1;
230 	entry->ent.dp_start = start;
231 	entry->ent.dp_size = size;
232 	mbr_set_chs(basetable, baseentry->gpe_start, &entry->ent.dp_scyl,
233 	    &entry->ent.dp_shd, &entry->ent.dp_ssect);
234 	mbr_set_chs(basetable, baseentry->gpe_end, &entry->ent.dp_ecyl,
235 	    &entry->ent.dp_ehd, &entry->ent.dp_esect);
236 	return (mbr_parse_type(gpp->gpp_type, &entry->ent.dp_typ));
237 }
238 
239 static int
240 g_part_mbr_bootcode(struct g_part_table *basetable, struct g_part_parms *gpp)
241 {
242 	struct g_part_mbr_table *table;
243 	uint32_t dsn;
244 
245 	if (gpp->gpp_codesize != MBRSIZE)
246 		return (ENODEV);
247 
248 	table = (struct g_part_mbr_table *)basetable;
249 	dsn = *(uint32_t *)(table->mbr + DOSDSNOFF);
250 	bcopy(gpp->gpp_codeptr, table->mbr, DOSPARTOFF);
251 	if (dsn != 0)
252 		*(uint32_t *)(table->mbr + DOSDSNOFF) = dsn;
253 	return (0);
254 }
255 
256 static int
257 g_part_mbr_create(struct g_part_table *basetable, struct g_part_parms *gpp)
258 {
259 	struct g_provider *pp;
260 	struct g_part_mbr_table *table;
261 
262 	pp = gpp->gpp_provider;
263 	if (pp->sectorsize < MBRSIZE)
264 		return (ENOSPC);
265 
266 	basetable->gpt_first = basetable->gpt_sectors;
267 	basetable->gpt_last = MIN(pp->mediasize / pp->sectorsize,
268 	    UINT32_MAX) - 1;
269 
270 	table = (struct g_part_mbr_table *)basetable;
271 	le16enc(table->mbr + DOSMAGICOFFSET, DOSMAGIC);
272 	return (0);
273 }
274 
275 static int
276 g_part_mbr_destroy(struct g_part_table *basetable, struct g_part_parms *gpp)
277 {
278 
279 	/* Wipe the first sector to clear the partitioning. */
280 	basetable->gpt_smhead |= 1;
281 	return (0);
282 }
283 
284 static void
285 g_part_mbr_dumpconf(struct g_part_table *table, struct g_part_entry *baseentry,
286     struct sbuf *sb, const char *indent)
287 {
288 	struct g_part_mbr_entry *entry;
289 
290 	entry = (struct g_part_mbr_entry *)baseentry;
291 	if (indent == NULL) {
292 		/* conftxt: libdisk compatibility */
293 		sbuf_printf(sb, " xs MBR xt %u", entry->ent.dp_typ);
294 	} else if (entry != NULL) {
295 		/* confxml: partition entry information */
296 		sbuf_printf(sb, "%s<rawtype>%u</rawtype>\n", indent,
297 		    entry->ent.dp_typ);
298 		if (entry->ent.dp_flag & 0x80)
299 			sbuf_printf(sb, "%s<attrib>active</attrib>\n", indent);
300 	} else {
301 		/* confxml: scheme information */
302 	}
303 }
304 
305 static int
306 g_part_mbr_dumpto(struct g_part_table *table, struct g_part_entry *baseentry)
307 {
308 	struct g_part_mbr_entry *entry;
309 
310 	/* Allow dumping to a FreeBSD partition or Linux swap partition only. */
311 	entry = (struct g_part_mbr_entry *)baseentry;
312 	return ((entry->ent.dp_typ == DOSPTYP_386BSD ||
313 	    entry->ent.dp_typ == DOSPTYP_LINSWP) ? 1 : 0);
314 }
315 
316 static int
317 g_part_mbr_modify(struct g_part_table *basetable,
318     struct g_part_entry *baseentry, struct g_part_parms *gpp)
319 {
320 	struct g_part_mbr_entry *entry;
321 
322 	if (gpp->gpp_parms & G_PART_PARM_LABEL)
323 		return (EINVAL);
324 
325 	entry = (struct g_part_mbr_entry *)baseentry;
326 	if (gpp->gpp_parms & G_PART_PARM_TYPE)
327 		return (mbr_parse_type(gpp->gpp_type, &entry->ent.dp_typ));
328 	return (0);
329 }
330 
331 static int
332 g_part_mbr_resize(struct g_part_table *basetable,
333     struct g_part_entry *baseentry, struct g_part_parms *gpp)
334 {
335 	struct g_part_mbr_entry *entry;
336 	uint32_t size, sectors;
337 
338 	sectors = basetable->gpt_sectors;
339 	size = gpp->gpp_size;
340 
341 	if (size < sectors)
342 		return (EINVAL);
343 	if (size % sectors)
344 		size = size - (size % sectors);
345 	if (size < sectors)
346 		return (EINVAL);
347 
348 	entry = (struct g_part_mbr_entry *)baseentry;
349 	baseentry->gpe_end = baseentry->gpe_start + size - 1;
350 	entry->ent.dp_size = size;
351 	mbr_set_chs(basetable, baseentry->gpe_end, &entry->ent.dp_ecyl,
352 	    &entry->ent.dp_ehd, &entry->ent.dp_esect);
353 	return (0);
354 }
355 
356 static const char *
357 g_part_mbr_name(struct g_part_table *table, struct g_part_entry *baseentry,
358     char *buf, size_t bufsz)
359 {
360 
361 	snprintf(buf, bufsz, "s%d", baseentry->gpe_index);
362 	return (buf);
363 }
364 
365 static int
366 g_part_mbr_probe(struct g_part_table *table, struct g_consumer *cp)
367 {
368 	char psn[8];
369 	struct g_provider *pp;
370 	u_char *buf, *p;
371 	int error, index, res, sum;
372 	uint16_t magic;
373 
374 	pp = cp->provider;
375 
376 	/* Sanity-check the provider. */
377 	if (pp->sectorsize < MBRSIZE || pp->mediasize < pp->sectorsize)
378 		return (ENOSPC);
379 	if (pp->sectorsize > 4096)
380 		return (ENXIO);
381 
382 	/* We don't nest under an MBR (see EBR instead). */
383 	error = g_getattr("PART::scheme", cp, &psn);
384 	if (error == 0 && strcmp(psn, g_part_mbr_scheme.name) == 0)
385 		return (ELOOP);
386 
387 	/* Check that there's a MBR. */
388 	buf = g_read_data(cp, 0L, pp->sectorsize, &error);
389 	if (buf == NULL)
390 		return (error);
391 
392 	/* We goto out on mismatch. */
393 	res = ENXIO;
394 
395 	magic = le16dec(buf + DOSMAGICOFFSET);
396 	if (magic != DOSMAGIC)
397 		goto out;
398 
399 	for (index = 0; index < NDOSPART; index++) {
400 		p = buf + DOSPARTOFF + index * DOSPARTSIZE;
401 		if (p[0] != 0 && p[0] != 0x80)
402 			goto out;
403 	}
404 
405 	/*
406 	 * If the partition table does not consist of all zeroes,
407 	 * assume we have a MBR. If it's all zeroes, we could have
408 	 * a boot sector. For example, a boot sector that doesn't
409 	 * have boot code -- common on non-i386 hardware. In that
410 	 * case we check if we have a possible BPB. If so, then we
411 	 * assume we have a boot sector instead.
412 	 */
413 	sum = 0;
414 	for (index = 0; index < NDOSPART * DOSPARTSIZE; index++)
415 		sum += buf[DOSPARTOFF + index];
416 	if (sum != 0 || !mbr_probe_bpb(buf + 0x0b))
417 		res = G_PART_PROBE_PRI_NORM;
418 
419  out:
420 	g_free(buf);
421 	return (res);
422 }
423 
424 static int
425 g_part_mbr_read(struct g_part_table *basetable, struct g_consumer *cp)
426 {
427 	struct dos_partition ent;
428 	struct g_provider *pp;
429 	struct g_part_mbr_table *table;
430 	struct g_part_mbr_entry *entry;
431 	u_char *buf, *p;
432 	off_t chs, msize, first;
433 	u_int sectors, heads;
434 	int error, index;
435 
436 	pp = cp->provider;
437 	table = (struct g_part_mbr_table *)basetable;
438 	first = basetable->gpt_sectors;
439 	msize = MIN(pp->mediasize / pp->sectorsize, UINT32_MAX);
440 
441 	buf = g_read_data(cp, 0L, pp->sectorsize, &error);
442 	if (buf == NULL)
443 		return (error);
444 
445 	bcopy(buf, table->mbr, sizeof(table->mbr));
446 	for (index = NDOSPART - 1; index >= 0; index--) {
447 		p = buf + DOSPARTOFF + index * DOSPARTSIZE;
448 		ent.dp_flag = p[0];
449 		ent.dp_shd = p[1];
450 		ent.dp_ssect = p[2];
451 		ent.dp_scyl = p[3];
452 		ent.dp_typ = p[4];
453 		ent.dp_ehd = p[5];
454 		ent.dp_esect = p[6];
455 		ent.dp_ecyl = p[7];
456 		ent.dp_start = le32dec(p + 8);
457 		ent.dp_size = le32dec(p + 12);
458 		if (ent.dp_typ == 0 || ent.dp_typ == DOSPTYP_PMBR)
459 			continue;
460 		if (ent.dp_start == 0 || ent.dp_size == 0)
461 			continue;
462 		sectors = ent.dp_esect & 0x3f;
463 		if (sectors > basetable->gpt_sectors &&
464 		    !basetable->gpt_fixgeom) {
465 			g_part_geometry_heads(msize, sectors, &chs, &heads);
466 			if (chs != 0) {
467 				basetable->gpt_sectors = sectors;
468 				basetable->gpt_heads = heads;
469 			}
470 		}
471 		if (ent.dp_start < first)
472 			first = ent.dp_start;
473 		entry = (struct g_part_mbr_entry *)g_part_new_entry(basetable,
474 		    index + 1, ent.dp_start, ent.dp_start + ent.dp_size - 1);
475 		entry->ent = ent;
476 	}
477 
478 	basetable->gpt_entries = NDOSPART;
479 	basetable->gpt_first = basetable->gpt_sectors;
480 	basetable->gpt_last = msize - 1;
481 
482 	if (first < basetable->gpt_first)
483 		basetable->gpt_first = 1;
484 
485 	g_free(buf);
486 	return (0);
487 }
488 
489 static int
490 g_part_mbr_setunset(struct g_part_table *table, struct g_part_entry *baseentry,
491     const char *attrib, unsigned int set)
492 {
493 	struct g_part_entry *iter;
494 	struct g_part_mbr_entry *entry;
495 	int changed;
496 
497 	if (strcasecmp(attrib, "active") != 0)
498 		return (EINVAL);
499 
500 	/* Only one entry can have the active attribute. */
501 	LIST_FOREACH(iter, &table->gpt_entry, gpe_entry) {
502 		if (iter->gpe_deleted)
503 			continue;
504 		changed = 0;
505 		entry = (struct g_part_mbr_entry *)iter;
506 		if (iter == baseentry) {
507 			if (set && (entry->ent.dp_flag & 0x80) == 0) {
508 				entry->ent.dp_flag |= 0x80;
509 				changed = 1;
510 			} else if (!set && (entry->ent.dp_flag & 0x80)) {
511 				entry->ent.dp_flag &= ~0x80;
512 				changed = 1;
513 			}
514 		} else {
515 			if (set && (entry->ent.dp_flag & 0x80)) {
516 				entry->ent.dp_flag &= ~0x80;
517 				changed = 1;
518 			}
519 		}
520 		if (changed && !iter->gpe_created)
521 			iter->gpe_modified = 1;
522 	}
523 	return (0);
524 }
525 
526 static const char *
527 g_part_mbr_type(struct g_part_table *basetable, struct g_part_entry *baseentry,
528     char *buf, size_t bufsz)
529 {
530 	struct g_part_mbr_entry *entry;
531 	int i;
532 
533 	entry = (struct g_part_mbr_entry *)baseentry;
534 	for (i = 0;
535 	    i < sizeof(mbr_alias_match) / sizeof(mbr_alias_match[0]); i++) {
536 		if (mbr_alias_match[i].typ == entry->ent.dp_typ)
537 			return (g_part_alias_name(mbr_alias_match[i].alias));
538 	}
539 	snprintf(buf, bufsz, "!%d", entry->ent.dp_typ);
540 	return (buf);
541 }
542 
543 static int
544 g_part_mbr_write(struct g_part_table *basetable, struct g_consumer *cp)
545 {
546 	struct g_part_entry *baseentry;
547 	struct g_part_mbr_entry *entry;
548 	struct g_part_mbr_table *table;
549 	u_char *p;
550 	int error, index;
551 
552 	table = (struct g_part_mbr_table *)basetable;
553 	baseentry = LIST_FIRST(&basetable->gpt_entry);
554 	for (index = 1; index <= basetable->gpt_entries; index++) {
555 		p = table->mbr + DOSPARTOFF + (index - 1) * DOSPARTSIZE;
556 		entry = (baseentry != NULL && index == baseentry->gpe_index)
557 		    ? (struct g_part_mbr_entry *)baseentry : NULL;
558 		if (entry != NULL && !baseentry->gpe_deleted) {
559 			p[0] = entry->ent.dp_flag;
560 			p[1] = entry->ent.dp_shd;
561 			p[2] = entry->ent.dp_ssect;
562 			p[3] = entry->ent.dp_scyl;
563 			p[4] = entry->ent.dp_typ;
564 			p[5] = entry->ent.dp_ehd;
565 			p[6] = entry->ent.dp_esect;
566 			p[7] = entry->ent.dp_ecyl;
567 			le32enc(p + 8, entry->ent.dp_start);
568 			le32enc(p + 12, entry->ent.dp_size);
569 		} else
570 			bzero(p, DOSPARTSIZE);
571 
572 		if (entry != NULL)
573 			baseentry = LIST_NEXT(baseentry, gpe_entry);
574 	}
575 
576 	error = g_write_data(cp, 0, table->mbr, cp->provider->sectorsize);
577 	return (error);
578 }
579