g_part_gpt.c (292788) | g_part_gpt.c (298649) |
---|---|
1/*- 2 * Copyright (c) 2002, 2005-2007, 2011 Marcel Moolenaar 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * --- 11 unchanged lines hidden (view full) --- 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2002, 2005-2007, 2011 Marcel Moolenaar 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * --- 11 unchanged lines hidden (view full) --- 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: head/sys/geom/part/g_part_gpt.c 292788 2015-12-27 18:12:13Z allanjude $"); | 28__FBSDID("$FreeBSD: head/sys/geom/part/g_part_gpt.c 298649 2016-04-26 15:38:17Z pfg $"); |
29 30#include <sys/param.h> 31#include <sys/bio.h> 32#include <sys/diskmbr.h> 33#include <sys/endian.h> 34#include <sys/gpt.h> 35#include <sys/kernel.h> 36#include <sys/kobj.h> --- 430 unchanged lines hidden (view full) --- 467 goto fail; 468 hdr->hdr_lba_table = le64toh(buf->hdr_lba_table); 469 if (hdr->hdr_lba_table < 2 || hdr->hdr_lba_table >= last) 470 goto fail; 471 if (hdr->hdr_lba_table >= hdr->hdr_lba_start && 472 hdr->hdr_lba_table <= hdr->hdr_lba_end) 473 goto fail; 474 lba = hdr->hdr_lba_table + | 29 30#include <sys/param.h> 31#include <sys/bio.h> 32#include <sys/diskmbr.h> 33#include <sys/endian.h> 34#include <sys/gpt.h> 35#include <sys/kernel.h> 36#include <sys/kobj.h> --- 430 unchanged lines hidden (view full) --- 467 goto fail; 468 hdr->hdr_lba_table = le64toh(buf->hdr_lba_table); 469 if (hdr->hdr_lba_table < 2 || hdr->hdr_lba_table >= last) 470 goto fail; 471 if (hdr->hdr_lba_table >= hdr->hdr_lba_start && 472 hdr->hdr_lba_table <= hdr->hdr_lba_end) 473 goto fail; 474 lba = hdr->hdr_lba_table + |
475 (hdr->hdr_entries * hdr->hdr_entsz + pp->sectorsize - 1) / 476 pp->sectorsize - 1; | 475 howmany(hdr->hdr_entries * hdr->hdr_entsz, pp->sectorsize) - 1; |
477 if (lba >= last) 478 goto fail; 479 if (lba >= hdr->hdr_lba_start && lba <= hdr->hdr_lba_end) 480 goto fail; 481 482 table->state[elt] = GPT_STATE_OK; 483 le_uuid_dec(&buf->hdr_uuid, &hdr->hdr_uuid); 484 hdr->hdr_crc_table = le32toh(buf->hdr_crc_table); --- 25 unchanged lines hidden (view full) --- 510 if (hdr == NULL) 511 return (NULL); 512 513 pp = cp->provider; 514 table->lba[elt] = hdr->hdr_lba_table; 515 516 table->state[elt] = GPT_STATE_MISSING; 517 tblsz = hdr->hdr_entries * hdr->hdr_entsz; | 476 if (lba >= last) 477 goto fail; 478 if (lba >= hdr->hdr_lba_start && lba <= hdr->hdr_lba_end) 479 goto fail; 480 481 table->state[elt] = GPT_STATE_OK; 482 le_uuid_dec(&buf->hdr_uuid, &hdr->hdr_uuid); 483 hdr->hdr_crc_table = le32toh(buf->hdr_crc_table); --- 25 unchanged lines hidden (view full) --- 509 if (hdr == NULL) 510 return (NULL); 511 512 pp = cp->provider; 513 table->lba[elt] = hdr->hdr_lba_table; 514 515 table->state[elt] = GPT_STATE_MISSING; 516 tblsz = hdr->hdr_entries * hdr->hdr_entsz; |
518 sectors = (tblsz + pp->sectorsize - 1) / pp->sectorsize; | 517 sectors = howmany(tblsz, pp->sectorsize); |
519 buf = g_malloc(sectors * pp->sectorsize, M_WAITOK | M_ZERO); 520 for (idx = 0; idx < sectors; idx += MAXPHYS / pp->sectorsize) { 521 size = (sectors - idx > MAXPHYS / pp->sectorsize) ? MAXPHYS: 522 (sectors - idx) * pp->sectorsize; 523 p = g_read_data(cp, (table->lba[elt] + idx) * pp->sectorsize, 524 size, &error); 525 if (p == NULL) { 526 g_free(buf); --- 121 unchanged lines hidden (view full) --- 648 size_t tblsz; 649 650 /* We don't nest, which means that our depth should be 0. */ 651 if (basetable->gpt_depth != 0) 652 return (ENXIO); 653 654 table = (struct g_part_gpt_table *)basetable; 655 pp = gpp->gpp_provider; | 518 buf = g_malloc(sectors * pp->sectorsize, M_WAITOK | M_ZERO); 519 for (idx = 0; idx < sectors; idx += MAXPHYS / pp->sectorsize) { 520 size = (sectors - idx > MAXPHYS / pp->sectorsize) ? MAXPHYS: 521 (sectors - idx) * pp->sectorsize; 522 p = g_read_data(cp, (table->lba[elt] + idx) * pp->sectorsize, 523 size, &error); 524 if (p == NULL) { 525 g_free(buf); --- 121 unchanged lines hidden (view full) --- 647 size_t tblsz; 648 649 /* We don't nest, which means that our depth should be 0. */ 650 if (basetable->gpt_depth != 0) 651 return (ENXIO); 652 653 table = (struct g_part_gpt_table *)basetable; 654 pp = gpp->gpp_provider; |
656 tblsz = (basetable->gpt_entries * sizeof(struct gpt_ent) + 657 pp->sectorsize - 1) / pp->sectorsize; | 655 tblsz = howmany(basetable->gpt_entries * sizeof(struct gpt_ent), 656 pp->sectorsize); |
658 if (pp->sectorsize < MBRSIZE || 659 pp->mediasize < (3 + 2 * tblsz + basetable->gpt_entries) * 660 pp->sectorsize) 661 return (ENOSPC); 662 663 gpt_create_pmbr(table, pp); 664 665 /* Allocate space for the header */ --- 463 unchanged lines hidden (view full) --- 1129 struct g_part_gpt_entry *entry; 1130 struct g_part_gpt_table *table; 1131 size_t tblsz; 1132 uint32_t crc; 1133 int error, index; 1134 1135 pp = cp->provider; 1136 table = (struct g_part_gpt_table *)basetable; | 657 if (pp->sectorsize < MBRSIZE || 658 pp->mediasize < (3 + 2 * tblsz + basetable->gpt_entries) * 659 pp->sectorsize) 660 return (ENOSPC); 661 662 gpt_create_pmbr(table, pp); 663 664 /* Allocate space for the header */ --- 463 unchanged lines hidden (view full) --- 1128 struct g_part_gpt_entry *entry; 1129 struct g_part_gpt_table *table; 1130 size_t tblsz; 1131 uint32_t crc; 1132 int error, index; 1133 1134 pp = cp->provider; 1135 table = (struct g_part_gpt_table *)basetable; |
1137 tblsz = (table->hdr->hdr_entries * table->hdr->hdr_entsz + 1138 pp->sectorsize - 1) / pp->sectorsize; | 1136 tblsz = howmany(table->hdr->hdr_entries * table->hdr->hdr_entsz, 1137 pp->sectorsize); |
1139 1140 /* Reconstruct the MBR from the GPT if under Boot Camp. */ 1141 if (table->bootcamp) 1142 gpt_update_bootcamp(basetable, pp); 1143 1144 /* Write the PMBR */ 1145 buf = g_malloc(pp->sectorsize, M_WAITOK | M_ZERO); 1146 bcopy(table->mbr, buf, MBRSIZE); --- 87 unchanged lines hidden (view full) --- 1234 struct g_part_gpt_entry *entry; 1235 struct g_part_gpt_table *table; 1236 quad_t start, end, min, max; 1237 quad_t lba, last; 1238 size_t spb, tblsz; 1239 1240 table = (struct g_part_gpt_table *)basetable; 1241 last = pp->mediasize / pp->sectorsize - 1; | 1138 1139 /* Reconstruct the MBR from the GPT if under Boot Camp. */ 1140 if (table->bootcamp) 1141 gpt_update_bootcamp(basetable, pp); 1142 1143 /* Write the PMBR */ 1144 buf = g_malloc(pp->sectorsize, M_WAITOK | M_ZERO); 1145 bcopy(table->mbr, buf, MBRSIZE); --- 87 unchanged lines hidden (view full) --- 1233 struct g_part_gpt_entry *entry; 1234 struct g_part_gpt_table *table; 1235 quad_t start, end, min, max; 1236 quad_t lba, last; 1237 size_t spb, tblsz; 1238 1239 table = (struct g_part_gpt_table *)basetable; 1240 last = pp->mediasize / pp->sectorsize - 1; |
1242 tblsz = (basetable->gpt_entries * sizeof(struct gpt_ent) + 1243 pp->sectorsize - 1) / pp->sectorsize; | 1241 tblsz = howmany(basetable->gpt_entries * sizeof(struct gpt_ent), 1242 pp->sectorsize); |
1244 1245 table->lba[GPT_ELT_PRIHDR] = 1; 1246 table->lba[GPT_ELT_PRITBL] = 2; 1247 table->lba[GPT_ELT_SECHDR] = last; 1248 table->lba[GPT_ELT_SECTBL] = last - tblsz; 1249 table->state[GPT_ELT_PRIHDR] = GPT_STATE_OK; 1250 table->state[GPT_ELT_PRITBL] = GPT_STATE_OK; 1251 table->state[GPT_ELT_SECHDR] = GPT_STATE_OK; --- 141 unchanged lines hidden --- | 1243 1244 table->lba[GPT_ELT_PRIHDR] = 1; 1245 table->lba[GPT_ELT_PRITBL] = 2; 1246 table->lba[GPT_ELT_SECHDR] = last; 1247 table->lba[GPT_ELT_SECTBL] = last - tblsz; 1248 table->state[GPT_ELT_PRIHDR] = GPT_STATE_OK; 1249 table->state[GPT_ELT_PRITBL] = GPT_STATE_OK; 1250 table->state[GPT_ELT_SECHDR] = GPT_STATE_OK; --- 141 unchanged lines hidden --- |