From a3123c2868dc2b6fbf29cd0b30b1f98c4f345090 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Sun, 14 Feb 2010 10:57:27 -0800 Subject: [PATCH] kernel - disklabel64 - Adjust partition base to be physically aligned * When creating a new pristine label the kernel will align the partition base to the physical drive instead of to the logical slice. This is to accomodate fdisk/slice setups which do not align the slice properly (which is nearly all of them). --- sys/kern/subr_disklabel64.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sys/kern/subr_disklabel64.c b/sys/kern/subr_disklabel64.c index 85e9ec6bec..0ad757ab1f 100644 --- a/sys/kern/subr_disklabel64.c +++ b/sys/kern/subr_disklabel64.c @@ -429,8 +429,19 @@ l64_makevirginlabel(disklabel_t lpx, struct diskslices *ssp, ressize = offsetof(struct disklabel64, d_partitions[RESPARTITIONS64]); ressize = (ressize + (uint32_t)blkmask) & ~blkmask; + /* + * NOTE: When calculating pbase take into account the slice offset + * so the partitions are at least 32K-aligned relative to the + * start of the physical disk. This will accomodate efficient + * access to 4096 byte physical sector drives. + */ lp->d_bbase = ressize; lp->d_pbase = lp->d_bbase + ((32768 + blkmask) & ~blkmask); + lp->d_pbase = (lp->d_pbase + 32767) & ~(uint64_t)32767; + + /* adjust for slice offset so we are physically aligned */ + lp->d_pbase += 32768 - (sp->ds_offset * info->d_media_blksize) % 32768; + lp->d_pstop = (lp->d_total_size - lp->d_bbase) & ~blkmask; lp->d_abase = lp->d_pstop; -- 2.41.0