From 2eb7466905b2273cd96297ab464c37de31d5ba90 Mon Sep 17 00:00:00 2001 From: kan Date: Tue, 23 Jul 2002 14:30:27 +0000 Subject: [PATCH] Fix DIOCGMEDIASIZE and DIOCGSECTORSIZE ioctls to work for all disk devices. This fixes the problem with these ioctls returning EINVAL for plain slice devices with no disklabel on them. The patch incorporates improvements and style fixes from BDE. Reviewed by: bde Approved by: obrien (mentor) --- sys/kern/subr_diskslice.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/sys/kern/subr_diskslice.c b/sys/kern/subr_diskslice.c index ec6099ecde9e..06c207bab4c5 100644 --- a/sys/kern/subr_diskslice.c +++ b/sys/kern/subr_diskslice.c @@ -365,6 +365,12 @@ dsioctl(dev, cmd, data, flags, sspp) lp = sp->ds_label; switch (cmd) { + case DIOCGDINFO: + if (lp == NULL) + return (EINVAL); + *(struct disklabel *)data = *lp; + return (0); + case DIOCGDVIRGIN: lp = (struct disklabel *)data; if (ssp->dss_slices[WHOLE_DISK_SLICE].ds_label) { @@ -398,23 +404,17 @@ dsioctl(dev, cmd, data, flags, sspp) lp->d_checksum = dkcksum(lp); return (0); - case DIOCGDINFO: + case DIOCGMEDIASIZE: if (lp == NULL) - return (EINVAL); - *(struct disklabel *)data = *lp; + *(off_t *)data = (off_t)sp->ds_size * ssp->dss_secsize; + else + *(off_t *)data = + (off_t)lp->d_partitions[dkpart(dev)].p_size * + lp->d_secsize; return (0); case DIOCGSECTORSIZE: - if (lp == NULL) - return (EINVAL); - *(u_int *)data = lp->d_secsize; - return (0); - - case DIOCGMEDIASIZE: - if (lp == NULL) - return (EINVAL); - *(off_t *)data = (off_t)lp->d_partitions[dkpart(dev)].p_size * - lp->d_secsize; + *(u_int *)data = ssp->dss_secsize; return (0); case DIOCGSLICEINFO: