From 43be698cb64f49af1657d8d5b417ff74ddfd961d Mon Sep 17 00:00:00 2001 From: Bruce Evans Date: Mon, 17 Jun 1996 14:43:54 +0000 Subject: [PATCH] Moved initialization of defaults for the label for the whole disk from disklabel(8) to the kernel (dsopen()). Drivers should initialize the hardware values (rpm, interleave, skews). Drivers currently don't do this, but it usually doesn't matter since rotational position stuff is normally disabled. --- sbin/bsdlabel/bsdlabel.c | 14 ++++---------- sbin/disklabel/disklabel.c | 14 ++++---------- sys/kern/subr_diskslice.c | 22 +++++++++++++++++++++- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/sbin/bsdlabel/bsdlabel.c b/sbin/bsdlabel/bsdlabel.c index 3de7004e0f41..5fcd1cdb7056 100644 --- a/sbin/bsdlabel/bsdlabel.c +++ b/sbin/bsdlabel/bsdlabel.c @@ -1329,26 +1329,20 @@ getvirginlabel(void) if (dkname[0] == '/') { fprintf(stderr, "\"auto\" requires the usage of a canonical disk name.\n"); - return 0; + return (NULL); } (void)snprintf(namebuf, BBSIZE, "%sr%s", _PATH_DEV, dkname); if ((f = open(namebuf, O_RDONLY, 0)) == -1) { Perror("open()"); - return 0; + return (NULL); } if (ioctl(f, DIOCGDINFO, &lab) < 0) { Perror("ioctl DIOCGDINFO"); close(f); - return 0; + return (NULL); } close(f); - /* insert reasonable defaults where necessary */ - if (lab.d_npartitions < 8) lab.d_npartitions = 8; - if (lab.d_bbsize == 0) lab.d_bbsize = BBSIZE; - if (lab.d_sbsize == 0) lab.d_sbsize = SBSIZE; - if (lab.d_rpm == 0) lab.d_rpm = 3600; - if (lab.d_interleave == 0) lab.d_interleave = 1; - return &lab; + return (&lab); } diff --git a/sbin/disklabel/disklabel.c b/sbin/disklabel/disklabel.c index 3de7004e0f41..5fcd1cdb7056 100644 --- a/sbin/disklabel/disklabel.c +++ b/sbin/disklabel/disklabel.c @@ -1329,26 +1329,20 @@ getvirginlabel(void) if (dkname[0] == '/') { fprintf(stderr, "\"auto\" requires the usage of a canonical disk name.\n"); - return 0; + return (NULL); } (void)snprintf(namebuf, BBSIZE, "%sr%s", _PATH_DEV, dkname); if ((f = open(namebuf, O_RDONLY, 0)) == -1) { Perror("open()"); - return 0; + return (NULL); } if (ioctl(f, DIOCGDINFO, &lab) < 0) { Perror("ioctl DIOCGDINFO"); close(f); - return 0; + return (NULL); } close(f); - /* insert reasonable defaults where necessary */ - if (lab.d_npartitions < 8) lab.d_npartitions = 8; - if (lab.d_bbsize == 0) lab.d_bbsize = BBSIZE; - if (lab.d_sbsize == 0) lab.d_sbsize = SBSIZE; - if (lab.d_rpm == 0) lab.d_rpm = 3600; - if (lab.d_interleave == 0) lab.d_interleave = 1; - return &lab; + return (&lab); } diff --git a/sys/kern/subr_diskslice.c b/sys/kern/subr_diskslice.c index 4b95b07fcd5a..1fece2935886 100644 --- a/sys/kern/subr_diskslice.c +++ b/sys/kern/subr_diskslice.c @@ -43,7 +43,7 @@ * from: wd.c,v 1.55 1994/10/22 01:57:12 phk Exp $ * from: @(#)ufs_disksubr.c 7.16 (Berkeley) 5/4/91 * from: ufs_disksubr.c,v 1.8 1994/06/07 01:21:39 phk Exp $ - * $Id: subr_diskslice.c,v 1.25 1996/04/19 19:22:29 bde Exp $ + * $Id: subr_diskslice.c,v 1.26 1996/06/12 05:07:31 gpalmer Exp $ */ #include @@ -62,6 +62,8 @@ #include #include +#include + #define b_cylinder b_resid #define TRACE(str) do { if (ds_debug) printf str; } while (0) @@ -642,6 +644,24 @@ dsopen(dname, dev, mode, sspp, lp, strat, setgeom, bdevsw, cdevsw) lp1 = malloc(sizeof *lp1, M_DEVBUF, M_WAITOK); *lp1 = *lp; + + /* + * Initialize defaults for the label for the whole disk so + * that it can be used as a template for disklabel(8). + * d_rpm = 3600 is unlikely to be correct for a modern + * disk, but d_rpm is normally irrelevant. + */ + if (lp1->d_rpm == 0) + lp1->d_rpm = 3600; + if (lp1->d_interleave == 0) + lp1->d_interleave = 1; + if (lp1->d_npartitions == 0) + lp1->d_npartitions = MAXPARTITIONS; + if (lp1->d_bbsize == 0) + lp1->d_bbsize = BBSIZE; + if (lp1->d_sbsize == 0) + lp1->d_sbsize = SBSIZE; + ssp->dss_slices[WHOLE_DISK_SLICE].ds_label = lp1; ssp->dss_slices[WHOLE_DISK_SLICE].ds_wlabel = TRUE; if (setgeom != NULL) {