Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern move setdisklabel(9) into a separate file.



details:   https://anonhg.NetBSD.org/src/rev/781a21ad3b35
branches:  trunk
changeset: 997998:781a21ad3b35
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Apr 04 20:19:07 2019 +0000

description:
move setdisklabel(9) into a separate file.

diffstat:

 sys/kern/files.kern       |    3 +-
 sys/kern/subr_disk.c      |   76 +------------------------------
 sys/kern/subr_disklabel.c |  111 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 115 insertions(+), 75 deletions(-)

diffs (226 lines):

diff -r 914625d941b8 -r 781a21ad3b35 sys/kern/files.kern
--- a/sys/kern/files.kern       Thu Apr 04 19:50:47 2019 +0000
+++ b/sys/kern/files.kern       Thu Apr 04 20:19:07 2019 +0000
@@ -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_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
diff -r 914625d941b8 -r 781a21ad3b35 sys/kern/subr_disk.c
--- a/sys/kern/subr_disk.c      Thu Apr 04 19:50:47 2019 +0000
+++ b/sys/kern/subr_disk.c      Thu Apr 04 20:19:07 2019 +0000
@@ -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 @@
        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
diff -r 914625d941b8 -r 781a21ad3b35 sys/kern/subr_disklabel.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/kern/subr_disklabel.c Thu Apr 04 20:19:07 2019 +0000
@@ -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



Home | Main Index | Thread Index | Old Index