Project

General

Profile

0002-kern-disklabel64-Fix-physically-alignment-to-1-MiB-f.patch

liweitianux, 11/08/2017 07:07 AM

Download (4.83 KB)

View differences:

sys/kern/subr_disklabel64.c
1 1
/*
2 2
 * Copyright (c) 2007 The DragonFly Project.  All rights reserved.
3
 * 
3
 *
4 4
 * This code is derived from software contributed to The DragonFly Project
5 5
 * by Matthew Dillon <dillon@backplane.com>
6
 * 
6
 *
7 7
 * Redistribution and use in source and binary forms, with or without
8 8
 * modification, are permitted provided that the following conditions
9 9
 * are met:
10
 * 
10
 *
11 11
 * 1. Redistributions of source code must retain the above copyright
12 12
 *    notice, this list of conditions and the following disclaimer.
13 13
 * 2. Redistributions in binary form must reproduce the above copyright
......
17 17
 * 3. Neither the name of The DragonFly Project nor the names of its
18 18
 *    contributors may be used to endorse or promote products derived
19 19
 *    from this software without specific, prior written permission.
20
 * 
20
 *
21 21
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 22
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 23
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
......
119 119

  
120 120
/*
121 121
 * Attempt to read a disk label from a device.  64 bit disklabels are
122
 * sector-agnostic and begin at offset 0 on the device.  64 bit disklabels
123
 * may only be used with GPT partitioning schemes.
122
 * sector-agnostic and begin at offset 0 on the device.
124 123
 *
125 124
 * Returns NULL on sucess, and an error string on failure.
126 125
 */
......
208 207
		return (EINVAL);
209 208
	savecrc = nlp->d_crc;
210 209
	nlp->d_crc = 0;
211
	nlpcrcsize = offsetof(struct disklabel64, 
210
	nlpcrcsize = offsetof(struct disklabel64,
212 211
			      d_partitions[nlp->d_npartitions]) -
213 212
		     offsetof(struct disklabel64, d_magic);
214 213
	if (crc32(&nlp->d_magic, nlpcrcsize) != savecrc) {
......
414 413
 * Create a virgin disklabel64 suitable for writing to the media.
415 414
 *
416 415
 * disklabel64 always reserves 32KB for a boot area and leaves room
417
 * for up to RESPARTITIONS64 partitions.  
416
 * for up to RESPARTITIONS64 partitions.
418 417
 */
419 418
static void
420 419
l64_makevirginlabel(disklabel_t lpx, struct diskslices *ssp,
......
425 424
	uint32_t blksize;
426 425
	uint32_t ressize;
427 426
	uint64_t blkmask;	/* 64 bits so we can ~ */
427
	uint64_t doffset;
428 428
	size_t lpcrcsize;
429 429

  
430
	doffset = sp->ds_offset * info->d_media_blksize;
431

  
430 432
	/*
431 433
	 * Setup the initial label.  Use of a block size of at least 4KB
432 434
	 * for calculating the initial reserved areas to allow some degree
......
453 455
	ressize = offsetof(struct disklabel64, d_partitions[RESPARTITIONS64]);
454 456
	ressize = (ressize + (uint32_t)blkmask) & ~blkmask;
455 457

  
456
	/*
457
	 * NOTE: When calculating pbase take into account the slice offset
458
	 *	 so the partitions are at least 32K-aligned relative to the
459
	 *	 start of the physical disk.  This will accomodate efficient
460
	 *	 access to 4096 byte physical sector drives.
461
	 */
458
	/* Reserve space for the stage2 boot code */
462 459
	lp->d_bbase = ressize;
463
	lp->d_pbase = (lp->d_pbase + PALIGN_MASK) & ~(uint64_t)PALIGN_MASK;
464 460
	lp->d_pbase = lp->d_bbase + ((BOOT2SIZE64 + blkmask) & ~blkmask);
465 461

  
466
	/* adjust for slice offset so we are physically aligned */
467
	lp->d_pbase += 32768 - (sp->ds_offset * info->d_media_blksize) % 32768;
462
	/* Reserve space for the backup label at the slice end */
463
	lp->d_abase = lp->d_total_size - ressize;
468 464

  
469
	lp->d_pstop = (lp->d_total_size - lp->d_bbase) & ~blkmask;
470
	lp->d_abase = lp->d_pstop;
465
	/*
466
	 * NOTE: The pbase and pstop are calculated to align to PALIGN_SIZE
467
	 *	 and adjusted with the slice offset, so the partitions are
468
	 *	 aligned relative to the start of the physical disk.
469
	 */
470
	lp->d_pbase = ((doffset + lp->d_pbase + PALIGN_MASK) &
471
		       ~(uint64_t)PALIGN_MASK) - doffset;
472
	lp->d_pstop = ((lp->d_abase - lp->d_pbase) &
473
		       ~(uint64_t)PALIGN_MASK) + lp->d_pbase;
471 474

  
472 475
	/*
473 476
	 * All partitions are left empty unless DSO_COMPATPARTA is set
474
-