Module Name:    src
Committed By:   christos
Date:           Thu Apr  4 20:19:07 UTC 2019

Modified Files:
        src/sys/kern: files.kern subr_disk.c
Added Files:
        src/sys/kern: subr_disklabel.c

Log Message:
move setdisklabel(9) into a separate file.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/kern/files.kern
cvs rdiff -u -r1.126 -r1.127 src/sys/kern/subr_disk.c
cvs rdiff -u -r0 -r1.1 src/sys/kern/subr_disklabel.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/files.kern
diff -u src/sys/kern/files.kern:1.33 src/sys/kern/files.kern:1.34
--- src/sys/kern/files.kern:1.33	Fri Feb 22 22:10:06 2019
+++ src/sys/kern/files.kern	Thu Apr  4 16:19:07 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: files.kern,v 1.33 2019/02/23 03:10:06 kamil Exp $
+#	$NetBSD: files.kern,v 1.34 2019/04/04 20:19:07 christos Exp $
 
 #
 # kernel sources
@@ -109,6 +109,7 @@ file	kern/subr_debug.c		debug
 file	kern/subr_device.c		kern
 file	kern/subr_devsw.c		kern
 file	kern/subr_disk.c		kern
+file	kern/subr_disklabel.c		kern
 file	kern/subr_disk_open.c		kern
 file	kern/subr_emul.c		kern
 file	kern/subr_evcnt.c		kern

Index: src/sys/kern/subr_disk.c
diff -u src/sys/kern/subr_disk.c:1.126 src/sys/kern/subr_disk.c:1.127
--- src/sys/kern/subr_disk.c:1.126	Thu Apr  4 07:49:06 2019
+++ src/sys/kern/subr_disk.c	Thu Apr  4 16:19:07 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_disk.c,v 1.126 2019/04/04 11:49:06 christos Exp $	*/
+/*	$NetBSD: subr_disk.c,v 1.127 2019/04/04 20:19:07 christos Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1999, 2000, 2009 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_disk.c,v 1.126 2019/04/04 11:49:06 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_disk.c,v 1.127 2019/04/04 20:19:07 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -740,75 +740,3 @@ disk_set_info(device_t dev, struct disk 
 	if (odisk_info)
 		prop_object_release(odisk_info);
 }
-
-#ifndef __HAVE_SETDISKLABEL
-
-#ifdef DEBUG
-#define DPRINTF(a, ...) printf(a, ##__VA_ARGS__)
-#else
-#define DPRINTF(a, ...) __nothing
-#endif
-
-/*
- * Check new disk label for sensibility
- * before setting it.
- */
-int
-setdisklabel(struct disklabel *olp, struct disklabel *nlp, u_long openmask,
-    struct cpu_disklabel *osdep)
-{
-	int i;
-	struct partition *opp, *npp;
-
-	/* sanity clause */
-	if (nlp->d_secpercyl == 0 || nlp->d_secsize == 0
-		|| (nlp->d_secsize % DEV_BSIZE) != 0) {
-		DPRINTF("%s: secpercyl/secsize %u/%u\n", __func__,
-		    nlp->d_secpercyl, nlp->d_secsize);
-		return EINVAL;
-	}
-
-	/* special case to allow disklabel to be invalidated */
-	if (nlp->d_magic == 0xffffffff) {
-		*olp = *nlp;
-		return 0;
-	}
-
-	if (nlp->d_magic != DISKMAGIC || nlp->d_magic2 != DISKMAGIC ||
-	    nlp->d_npartitions > MAXPARTITIONS || dkcksum(nlp) != 0) {
-		DPRINTF("%s: bad magic %#x/%#x != %#x, partitions %u != %u"
-		    ", bad sum=%#x\n", __func__,
-		    nlp->d_magic, nlp->d_magic2, DISKMAGIC,
-		    nlp->d_npartitions, MAXPARTITIONS, dkcksum(nlp));
-		return EINVAL;
-	}
-
-	while (openmask != 0) {
-		i = ffs(openmask) - 1;
-		openmask &= ~(1 << i);
-		if (i >= nlp->d_npartitions) {
-			DPRINTF("%s: partition not found\n", __func__);
-			return EBUSY;
-		}
-		opp = &olp->d_partitions[i];
-		npp = &nlp->d_partitions[i];
-		/*
-		 * Copy internally-set partition information
-		 * if new label doesn't include it.		XXX
-		 */
-		if (npp->p_fstype == FS_UNUSED && opp->p_fstype != FS_UNUSED) {
-			*npp = *opp;
-			continue;
-		}
-		if (npp->p_offset != opp->p_offset || npp->p_size < opp->p_size)
-		{
-			DPRINTF("%s: mismatched offset/size", __func__);
-			return EBUSY;
-		}
-	}
- 	nlp->d_checksum = 0;
- 	nlp->d_checksum = dkcksum(nlp);
-	*olp = *nlp;
-	return 0;
-}
-#endif

Added files:

Index: src/sys/kern/subr_disklabel.c
diff -u /dev/null src/sys/kern/subr_disklabel.c:1.1
--- /dev/null	Thu Apr  4 16:19:07 2019
+++ src/sys/kern/subr_disklabel.c	Thu Apr  4 16:19:07 2019
@@ -0,0 +1,111 @@
+/*	$NetBSD: subr_disklabel.c,v 1.1 2019/04/04 20:19:07 christos Exp $	*/
+
+/*
+ * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *	@(#)ufs_disksubr.c	7.16 (Berkeley) 5/4/91
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: subr_disklabel.c,v 1.1 2019/04/04 20:19:07 christos Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/disklabel.h>
+
+#ifndef __HAVE_SETDISKLABEL
+
+#ifdef DEBUG
+#define DPRINTF(a, ...) printf(a, ##__VA_ARGS__)
+#else
+#define DPRINTF(a, ...) __nothing
+#endif
+
+/*
+ * Check new disk label for sensibility
+ * before setting it.
+ */
+int
+setdisklabel(struct disklabel *olp, struct disklabel *nlp, u_long openmask,
+    struct cpu_disklabel *osdep)
+{
+	int i;
+	struct partition *opp, *npp;
+
+	/* sanity clause */
+	if (nlp->d_secpercyl == 0 || nlp->d_secsize == 0
+		|| (nlp->d_secsize % DEV_BSIZE) != 0) {
+		DPRINTF("%s: secpercyl/secsize %u/%u\n", __func__,
+		    nlp->d_secpercyl, nlp->d_secsize);
+		return EINVAL;
+	}
+
+	/* special case to allow disklabel to be invalidated */
+	if (nlp->d_magic == 0xffffffff) {
+		*olp = *nlp;
+		return 0;
+	}
+
+	if (nlp->d_magic != DISKMAGIC || nlp->d_magic2 != DISKMAGIC ||
+	    nlp->d_npartitions > MAXPARTITIONS || dkcksum(nlp) != 0) {
+		DPRINTF("%s: bad magic %#x/%#x != %#x, partitions %u != %u"
+		    ", bad sum=%#x\n", __func__,
+		    nlp->d_magic, nlp->d_magic2, DISKMAGIC,
+		    nlp->d_npartitions, MAXPARTITIONS, dkcksum(nlp));
+		return EINVAL;
+	}
+
+	while (openmask != 0) {
+		i = ffs(openmask) - 1;
+		openmask &= ~(1 << i);
+		if (i >= nlp->d_npartitions) {
+			DPRINTF("%s: partition not found\n", __func__);
+			return EBUSY;
+		}
+		opp = &olp->d_partitions[i];
+		npp = &nlp->d_partitions[i];
+		/*
+		 * Copy internally-set partition information
+		 * if new label doesn't include it.		XXX
+		 */
+		if (npp->p_fstype == FS_UNUSED && opp->p_fstype != FS_UNUSED) {
+			*npp = *opp;
+			continue;
+		}
+		if (npp->p_offset != opp->p_offset || npp->p_size < opp->p_size)
+		{
+			DPRINTF("%s: mismatched offset/size", __func__);
+			return EBUSY;
+		}
+	}
+ 	nlp->d_checksum = 0;
+ 	nlp->d_checksum = dkcksum(nlp);
+	*olp = *nlp;
+	return 0;
+}
+#endif

Reply via email to