[Midnightbsd-cvs] src [10010] trunk/sys/geom/part/g_part_pc98.c: sync with freebsd

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun May 27 17:30:33 EDT 2018


Revision: 10010
          http://svnweb.midnightbsd.org/src/?rev=10010
Author:   laffer1
Date:     2018-05-27 17:30:33 -0400 (Sun, 27 May 2018)
Log Message:
-----------
sync with freebsd

Modified Paths:
--------------
    trunk/sys/geom/part/g_part_pc98.c

Modified: trunk/sys/geom/part/g_part_pc98.c
===================================================================
--- trunk/sys/geom/part/g_part_pc98.c	2018-05-27 21:28:59 UTC (rev 10009)
+++ trunk/sys/geom/part/g_part_pc98.c	2018-05-27 21:30:33 UTC (rev 10010)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*-
  * Copyright (c) 2008 Marcel Moolenaar
  * All rights reserved.
@@ -25,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
+__FBSDID("$FreeBSD: stable/10/sys/geom/part/g_part_pc98.c 267156 2014-06-06 12:37:56Z ae $");
 
 #include <sys/param.h>
 #include <sys/bio.h>
@@ -42,6 +43,7 @@
 #include <sys/systm.h>
 #include <sys/sysctl.h>
 #include <geom/geom.h>
+#include <geom/geom_int.h>
 #include <geom/part/g_part.h>
 
 #include "g_part_if.h"
@@ -109,8 +111,8 @@
 	g_part_pc98_methods,
 	sizeof(struct g_part_pc98_table),
 	.gps_entrysz = sizeof(struct g_part_pc98_entry),
-	.gps_minent = NDOSPART,
-	.gps_maxent = NDOSPART,
+	.gps_minent = PC98_NPARTS,
+	.gps_maxent = PC98_NPARTS,
 	.gps_bootcodesz = BOOTSIZE,
 };
 G_PART_SCHEME_DECLARE(g_part_pc98);
@@ -175,32 +177,37 @@
 }
 
 static int
+pc98_align(struct g_part_table *basetable, uint32_t *start, uint32_t *size)
+{
+	uint32_t cyl;
+
+	cyl = basetable->gpt_heads * basetable->gpt_sectors;
+	if (*size < cyl)
+		return (EINVAL);
+	if (start != NULL && (*start % cyl)) {
+		*size += (*start % cyl) - cyl;
+		*start -= (*start % cyl) - cyl;
+	}
+	if (*size % cyl)
+		*size -= (*size % cyl);
+	if (*size < cyl)
+		return (EINVAL);
+	return (0);
+}
+
+static int
 g_part_pc98_add(struct g_part_table *basetable, struct g_part_entry *baseentry,
     struct g_part_parms *gpp)
 {
 	struct g_part_pc98_entry *entry;
-	struct g_part_pc98_table *table;
-	uint32_t cyl, start, size;
+	uint32_t start, size;
 	int error;
 
-	cyl = basetable->gpt_heads * basetable->gpt_sectors;
-
 	entry = (struct g_part_pc98_entry *)baseentry;
-	table = (struct g_part_pc98_table *)basetable;
-
 	start = gpp->gpp_start;
 	size = gpp->gpp_size;
-	if (size < cyl)
+	if (pc98_align(basetable, &start, &size) != 0)
 		return (EINVAL);
-	if (start % cyl) {
-		size = size - cyl + (start % cyl);
-		start = start - (start % cyl) + cyl;
-	}
-	if (size % cyl)
-		size = size - (size % cyl);
-	if (size < cyl)
-		return (EINVAL);
-
 	if (baseentry->gpe_deleted)
 		bzero(&entry->ent, sizeof(entry->ent));
 	else
@@ -259,7 +266,7 @@
 	basetable->gpt_last = MIN(pp->mediasize / SECSIZE, UINT32_MAX) - 1;
 
 	table = (struct g_part_pc98_table *)basetable;
-	le16enc(table->boot + DOSMAGICOFFSET, DOSMAGIC);
+	le16enc(table->boot + PC98_MAGICOFS, PC98_MAGIC);
 	return (0);
 }
 
@@ -294,7 +301,9 @@
 		sbuf_printf(sb, " xs PC98 xt %u sn %s", type, name);
 	} else {
 		/* confxml: partition entry information */
-		sbuf_printf(sb, "%s<label>%s</label>\n", indent, name);
+		sbuf_printf(sb, "%s<label>", indent);
+		g_conf_printf_escaped(sb, "%s", name);
+		sbuf_printf(sb, "</label>\n");
 		if (entry->ent.dp_mid & PC98_MID_BOOTABLE)
 			sbuf_printf(sb, "%s<attrib>bootable</attrib>\n",
 			    indent);
@@ -343,18 +352,23 @@
     struct g_part_entry *baseentry, struct g_part_parms *gpp)
 {
 	struct g_part_pc98_entry *entry;
-	uint32_t size, cyl;
+	struct g_provider *pp;
+	uint32_t size;
 
-	cyl = basetable->gpt_heads * basetable->gpt_sectors;
+	if (baseentry == NULL) {
+		pp = LIST_FIRST(&basetable->gpt_gp->consumer)->provider;
+		basetable->gpt_last = MIN(pp->mediasize / SECSIZE,
+		    UINT32_MAX) - 1;
+		return (0);
+	}
 	size = gpp->gpp_size;
-
-	if (size < cyl)
+	if (pc98_align(basetable, NULL, &size) != 0)
 		return (EINVAL);
-	if (size % cyl)
-		size = size - (size % cyl);
-	if (size < cyl)
-		return (EINVAL);
-
+	/* XXX: prevent unexpected shrinking. */
+	pp = baseentry->gpe_pp;
+	if ((g_debugflags & 0x10) == 0 && size < gpp->gpp_size &&
+	    pp->mediasize / pp->sectorsize > size)
+		return (EBUSY);
 	entry = (struct g_part_pc98_entry *)baseentry;
 	baseentry->gpe_end = baseentry->gpe_start + size - 1;
 	pc98_set_chs(basetable, baseentry->gpe_end, &entry->ent.dp_ecyl,
@@ -396,8 +410,8 @@
 	/* We goto out on mismatch. */
 	res = ENXIO;
 
-	magic = le16dec(buf + DOSMAGICOFFSET);
-	if (magic != DOSMAGIC)
+	magic = le16dec(buf + PC98_MAGICOFS);
+	if (magic != PC98_MAGIC)
 		goto out;
 
 	sum = 0;
@@ -408,8 +422,8 @@
 		goto out;
 	}
 
-	for (index = 0; index < NDOSPART; index++) {
-		p = buf + SECSIZE + index * DOSPARTSIZE;
+	for (index = 0; index < PC98_NPARTS; index++) {
+		p = buf + SECSIZE + index * PC98_PARTSIZE;
 		if (p[0] == 0 || p[1] == 0)	/* !dp_mid || !dp_sid */
 			continue;
 		scyl = le16dec(p + 10);
@@ -456,8 +470,8 @@
 	bcopy(buf + SECSIZE, table->table, sizeof(table->table));
 	bcopy(buf + SECSIZE*2, table->menu, sizeof(table->menu));
 
-	for (index = NDOSPART - 1; index >= 0; index--) {
-		p = buf + SECSIZE + index * DOSPARTSIZE;
+	for (index = PC98_NPARTS - 1; index >= 0; index--) {
+		p = buf + SECSIZE + index * PC98_PARTSIZE;
 		ent.dp_mid = p[0];
 		ent.dp_sid = p[1];
 		ent.dp_dum1 = p[2];
@@ -482,7 +496,7 @@
 		entry->ent = ent;
 	}
 
-	basetable->gpt_entries = NDOSPART;
+	basetable->gpt_entries = PC98_NPARTS;
 	basetable->gpt_first = cyl;
 	basetable->gpt_last = msize - 1;
 
@@ -498,6 +512,9 @@
 	struct g_part_pc98_entry *entry;
 	int changed, mid, sid;
 
+	if (baseentry == NULL)
+		return (ENODEV);
+
 	mid = sid = 0;
 	if (strcasecmp(attrib, "active") == 0)
 		sid = 1;
@@ -566,7 +583,7 @@
 	table = (struct g_part_pc98_table *)basetable;
 	baseentry = LIST_FIRST(&basetable->gpt_entry);
 	for (index = 1; index <= basetable->gpt_entries; index++) {
-		p = table->table + (index - 1) * DOSPARTSIZE;
+		p = table->table + (index - 1) * PC98_PARTSIZE;
 		entry = (baseentry != NULL && index == baseentry->gpe_index)
 		    ? (struct g_part_pc98_entry *)baseentry : NULL;
 		if (entry != NULL && !baseentry->gpe_deleted) {
@@ -586,7 +603,7 @@
 			bcopy(entry->ent.dp_name, p + 16,
 			    sizeof(entry->ent.dp_name));
 		} else
-			bzero(p, DOSPARTSIZE);
+			bzero(p, PC98_PARTSIZE);
 
 		if (entry != NULL)
 			baseentry = LIST_NEXT(baseentry, gpe_entry);



More information about the Midnightbsd-cvs mailing list