diff --git a/sys/kern/subr_diskslice.c b/sys/kern/subr_diskslice.c index c4ecdc54e271..869694111a1a 100644 --- a/sys/kern/subr_diskslice.c +++ b/sys/kern/subr_diskslice.c @@ -342,6 +342,7 @@ dsioctl(dev, cmd, data, flags, sspp) int slice; struct diskslice *sp; struct diskslices *ssp; + struct partition *pp; slice = dkslice(dev); ssp = *sspp; @@ -349,6 +350,39 @@ dsioctl(dev, cmd, data, flags, sspp) lp = sp->ds_label; switch (cmd) { + case DIOCGDVIRGIN: + lp = (struct disklabel *)data; + if (ssp->dss_slices[WHOLE_DISK_SLICE].ds_label) { + *lp = *ssp->dss_slices[WHOLE_DISK_SLICE].ds_label; + } else { + bzero(lp, sizeof(struct disklabel)); + } + + lp->d_magic = DISKMAGIC; + lp->d_magic2 = DISKMAGIC; + pp = &lp->d_partitions[RAW_PART]; + pp->p_offset = 0; + pp->p_size = sp->ds_size; + + lp->d_npartitions = MAXPARTITIONS; + if (lp->d_interleave == 0) + lp->d_interleave = 1; + if (lp->d_rpm == 0) + lp->d_rpm = 3600; + if (lp->d_nsectors == 0) + lp->d_nsectors = 32; + if (lp->d_ntracks == 0) + lp->d_ntracks = 64; + + lp->d_bbsize = BBSIZE; + lp->d_sbsize = SBSIZE; + lp->d_secpercyl = lp->d_nsectors * lp->d_ntracks; + lp->d_ncylinders = sp->ds_size / lp->d_secpercyl; + lp->d_secperunit = sp->ds_size; + lp->d_checksum = 0; + lp->d_checksum = dkcksum(lp); + return (0); + case DIOCGDINFO: if (lp == NULL) return (EINVAL); diff --git a/sys/sys/disklabel.h b/sys/sys/disklabel.h index ea3e41e7b767..1c9a8be82986 100644 --- a/sys/sys/disklabel.h +++ b/sys/sys/disklabel.h @@ -401,6 +401,7 @@ struct dos_partition { #define DIOCSDINFO _IOW('d', 102, struct disklabel)/* set */ #define DIOCWDINFO _IOW('d', 103, struct disklabel)/* set, update disk */ #define DIOCGPART _IOW('d', 104, struct partinfo) /* get partition */ +#define DIOCGDVIRGIN _IOR('d', 105, struct disklabel) /* get virgin label */ #define DIOCWLABEL _IOW('d', 109, int) /* write en/disable label */ diff --git a/sys/sys/diskmbr.h b/sys/sys/diskmbr.h index ea3e41e7b767..1c9a8be82986 100644 --- a/sys/sys/diskmbr.h +++ b/sys/sys/diskmbr.h @@ -401,6 +401,7 @@ struct dos_partition { #define DIOCSDINFO _IOW('d', 102, struct disklabel)/* set */ #define DIOCWDINFO _IOW('d', 103, struct disklabel)/* set, update disk */ #define DIOCGPART _IOW('d', 104, struct partinfo) /* get partition */ +#define DIOCGDVIRGIN _IOR('d', 105, struct disklabel) /* get virgin label */ #define DIOCWLABEL _IOW('d', 109, int) /* write en/disable label */ diff --git a/sys/sys/diskpc98.h b/sys/sys/diskpc98.h index ea3e41e7b767..1c9a8be82986 100644 --- a/sys/sys/diskpc98.h +++ b/sys/sys/diskpc98.h @@ -401,6 +401,7 @@ struct dos_partition { #define DIOCSDINFO _IOW('d', 102, struct disklabel)/* set */ #define DIOCWDINFO _IOW('d', 103, struct disklabel)/* set, update disk */ #define DIOCGPART _IOW('d', 104, struct partinfo) /* get partition */ +#define DIOCGDVIRGIN _IOR('d', 105, struct disklabel) /* get virgin label */ #define DIOCWLABEL _IOW('d', 109, int) /* write en/disable label */