PERFORCE change 130296 for review

Marcel Moolenaar marcel at FreeBSD.org
Wed Dec 5 15:44:49 PST 2007


http://perforce.freebsd.org/chv.cgi?CH=130296

Change 130296 by marcel at marcel_xcllnt on 2007/12/05 23:44:35

	o  Properly deal with the raw partition. We create a partition
	   list entry for it and mark it internal. This allows us to
	   skip it as part of partition overlap tests. It also allows
	   us to not create a device special file for it.
	o  Calculate the checksum upon write.

Affected files ...

.. //depot/projects/ia64/sys/geom/part/g_part.c#7 edit
.. //depot/projects/ia64/sys/geom/part/g_part.h#6 edit
.. //depot/projects/ia64/sys/geom/part/g_part_bsd.c#2 edit

Differences ...

==== //depot/projects/ia64/sys/geom/part/g_part.c#7 (text+ko) ====

@@ -453,6 +453,8 @@
 			index = entry->gpe_index + 1;
 			last = entry;
 		}
+		if (entry->gpe_internal)
+			continue;
 		if (gpp->gpp_start >= entry->gpe_start &&
 		    gpp->gpp_start <= entry->gpe_end) {
 			gctl_error(req, "%d start '%jd'", ENOSPC,
@@ -750,13 +752,16 @@
 	}
 
 	pp = entry->gpe_pp;
-	if (pp->acr > 0 || pp->acw > 0 || pp->ace > 0) {
-		gctl_error(req, "%d", EBUSY);
-		return (EBUSY);
+	if (pp != NULL) {
+		if (pp->acr > 0 || pp->acw > 0 || pp->ace > 0) {
+			gctl_error(req, "%d", EBUSY);
+			return (EBUSY);
+		}
+
+		pp->private = NULL;
+		entry->gpe_pp = NULL;
 	}
 
-	pp->private = NULL;
-	entry->gpe_pp = NULL;
 	if (entry->gpe_created) {
 		LIST_REMOVE(entry, gpe_entry);
 		g_free(entry);
@@ -764,7 +769,9 @@
 		entry->gpe_modified = 0;
 		entry->gpe_deleted = 1;
 	}
-	g_wither_provider(pp, ENXIO);
+
+	if (pp != NULL)
+		g_wither_provider(pp, ENXIO);
 
 	/* Provide feedback if so requested. */
 	if (gpp->gpp_parms & G_PART_PARM_OUTPUT) {
@@ -927,9 +934,11 @@
 		entry->gpe_modified = 0;
 		if (entry->gpe_created) {
 			pp = entry->gpe_pp;
-			pp->private = NULL;
-			entry->gpe_pp = NULL;
-			g_wither_provider(pp, ENXIO);
+			if (pp != NULL) {
+				pp->private = NULL;
+				entry->gpe_pp = NULL;
+				g_wither_provider(pp, ENXIO);
+			}
 			entry->gpe_deleted = 1;
 		}
 		if (entry->gpe_deleted) {
@@ -964,8 +973,10 @@
 
 	g_topology_lock();
 
-	LIST_FOREACH(entry, &table->gpt_entry, gpe_entry)
-		g_part_new_provider(gp, table, entry);
+	LIST_FOREACH(entry, &table->gpt_entry, gpe_entry) {
+		if (!entry->gpe_internal)
+			g_part_new_provider(gp, table, entry);
+	}
 
 	table->gpt_opened = 0;
 	g_access(cp, -1, -1, -1);
@@ -1361,8 +1372,10 @@
 		goto fail;
 
 	g_topology_lock();
-	LIST_FOREACH(entry, &table->gpt_entry, gpe_entry)
-		g_part_new_provider(gp, table, entry);
+	LIST_FOREACH(entry, &table->gpt_entry, gpe_entry) {
+		if (!entry->gpe_internal)
+			g_part_new_provider(gp, table, entry);
+	}
 
 	g_access(cp, -1, 0, 0);
 	return (gp);

==== //depot/projects/ia64/sys/geom/part/g_part.h#6 (text+ko) ====

@@ -69,6 +69,7 @@
 	int		gpe_created:1;	/* Entry is newly created. */
 	int		gpe_deleted:1;	/* Entry has been deleted. */
 	int		gpe_modified:1;	/* Entry has been modified. */
+	int		gpe_internal:1;	/* Entry is not a used entry. */
 };
 
 /* G_PART table (KOBJ instance). */

==== //depot/projects/ia64/sys/geom/part/g_part_bsd.c#2 (text+ko) ====

@@ -172,6 +172,8 @@
 {
 	struct g_consumer *cp;
 	struct g_provider *pp;
+	struct g_part_entry *baseentry;
+	struct g_part_bsd_entry *entry;
 	struct g_part_bsd_table *table;
 	u_char *ptr;
 	uint64_t msize;
@@ -205,6 +207,14 @@
 	basetable->gpt_first = 0;
 	basetable->gpt_last = ncyls * secpercyl - 1;
 	basetable->gpt_isleaf = 1;
+
+	baseentry = g_part_new_entry(basetable, RAW_PART + 1,
+	    basetable->gpt_first, basetable->gpt_last);
+	baseentry->gpe_internal = 1;
+	entry = (struct g_part_bsd_entry *)baseentry;
+	entry->part.p_size = basetable->gpt_last + 1;
+	entry->part.p_offset = basetable->gpt_offset;
+
 	return (0);
 }
 
@@ -282,6 +292,7 @@
 {
 	struct g_provider *pp;
 	struct g_part_bsd_table *table;
+	struct g_part_entry *baseentry;
 	struct g_part_bsd_entry *entry;
 	struct partition part;
 	u_char *buf, *p;
@@ -342,14 +353,19 @@
 		part.p_fstype = p[12];
 		part.p_frag = p[13];
 		part.p_cpg = le16dec(p + 14);
-		if (part.p_fstype == FS_UNUSED || part.p_size == 0)
+		if (part.p_size == 0)
+			continue;
+		if (part.p_fstype == FS_UNUSED && index != RAW_PART)
 			continue;
 		if (part.p_offset < basetable->gpt_offset)
 			continue;
-		entry = (struct g_part_bsd_entry *)g_part_new_entry(basetable,
-		    index + 1, part.p_offset - basetable->gpt_offset,
+		baseentry = g_part_new_entry(basetable, index + 1,
+		    part.p_offset - basetable->gpt_offset,
 		    part.p_offset - basetable->gpt_offset + part.p_size - 1);
+		entry = (struct g_part_bsd_entry *)baseentry;
 		entry->part = part;
+		if (part.p_fstype == FS_UNUSED)
+			baseentry->gpe_internal = 1;
 	}
 
 	return (0);
@@ -386,7 +402,8 @@
 	struct g_part_entry *baseentry;
 	struct g_part_bsd_entry *entry;
 	struct g_part_bsd_table *table;
-	u_char *p;
+	uint16_t sum;
+	u_char *p, *pe;
 	int error, index;
 
 	pp = cp->provider;
@@ -410,6 +427,14 @@
 			baseentry = LIST_NEXT(baseentry, gpe_entry);
 	}
 
+	/* Calculate checksum. */
+	le16enc(table->label + 136, 0);
+	pe = table->label + 148 + basetable->gpt_entries * 16;
+	sum = 0;
+	for (p = table->label; p < pe; p += 2)
+		sum ^= le16dec(p);
+	le16enc(table->label + 136, sum);
+
 	error = g_write_data(cp, pp->sectorsize, table->label, pp->sectorsize);
 	return (error);
 }


More information about the p4-projects mailing list