Date: Sun, 26 May 2002 13:56:47 -0700 (PDT) From: Marcel Moolenaar <marcel@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 11924 for review Message-ID: <200205262056.g4QKulc25372@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://people.freebsd.org/~peter/p4db/chv.cgi?CH=11924 Change 11924 by marcel@marcel_nfs on 2002/05/26 13:55:58 o Migrate EFI partitions along with FreeBSD partitions. The EFI shell maps the GPT based system partition: Shell> map Device mapping table fs0 : VenHw(Unknown Device:80)/HD(Part1,Sig27A9B525-70AE-11D6-8F67-00D0B7ABFBAB) blk0 : Acpi(PNP0A03,0)/Pci(3|1)/Ata(Primary,Master) blk1 : VenHw(Unknown Device:80) blk2 : VenHw(Unknown Device:80)/HD(Part1,Sig27A9B525-70AE-11D6-8F67-00D0B7ABFBAB) blk3 : VenHw(Unknown Device:80)/HD(Part2,Sig27A9B55D-70AE-11D6-8F67-00D0B7ABFBAB) blk4 : Acpi(PNP0A03,0)/Pci(3|1)/Ata(Primary,Slave) While here, fix a couple of nits: o Respect the GPT entry size recorded in the GPT header when we scan the GPT table. o Rename maxparts to parts. Only migration will (probably) treat it as a maximum. Everywhere else it should (is expected to) be treated as *the* number of partitions. Time to create a GEOM class... Affected files ... ... //depot/projects/ia64/sbin/gpt/gpt.c#5 edit Differences ... ==== //depot/projects/ia64/sbin/gpt/gpt.c#5 (text+ko) ==== @@ -93,7 +93,7 @@ off_t mediasz; -u_int maxparts; +u_int parts; u_int secsz; int readonly, verbose; @@ -172,7 +172,7 @@ usage(void) { - fprintf(stderr, "usage: gpt [-rv] [-p maxparts] device\n"); + fprintf(stderr, "usage: gpt [-rv] [-p nparts] device\n"); exit(1); } @@ -195,7 +195,7 @@ return (-1); found: - fd = open(device_name, ((readonly) ? O_RDONLY : O_RDWR)|O_EXCL); + fd = open(device_name, (readonly) ? O_RDONLY : O_RDWR|O_EXCL); if (fd == -1) return (-1); @@ -281,6 +281,7 @@ { struct gpt_ent *ent; struct gpt_hdr *hdr; + char *p; map_t *m; size_t blocks, tblsz; unsigned int i; @@ -304,11 +305,13 @@ tblsz = hdr->hdr_entries * hdr->hdr_entsz; blocks = tblsz / secsz + ((tblsz % secsz) ? 1 : 0); - ent = gpt_read(fd, hdr->hdr_lba_table, blocks); - if (ent == NULL) + + /* Use generic pointer to deal with hdr->hdr_entsz != sizeof(*ent). */ + p = gpt_read(fd, hdr->hdr_lba_table, blocks); + if (p == NULL) return (-1); - if (crc32(ent, tblsz) != hdr->hdr_crc_table) { + if (crc32(p, tblsz) != hdr->hdr_crc_table) { if (verbose) warnx("%s: Bad CRC in GPT table at sector %llu", device_name, (long long)hdr->hdr_lba_table); @@ -323,7 +326,7 @@ if (m == NULL) return (-1); m = map_add(hdr->hdr_lba_table, blocks, (lba == 1) - ? MAP_TYPE_GPT_TBL : MAP_TYPE_TPG_TBL, ent); + ? MAP_TYPE_GPT_TBL : MAP_TYPE_TPG_TBL, p); if (m == NULL) return (-1); @@ -332,10 +335,12 @@ for (i = 0; i < hdr->hdr_entries; i++) { uuid_t unused = GPT_ENT_TYPE_UNUSED; - if (!memcmp(&ent[i].ent_type, &unused, sizeof(uuid_t))) + + ent = (void*)(p + i * hdr->hdr_entsz); + if (!memcmp(&ent->ent_type, &unused, sizeof(uuid_t))) continue; - m = map_add(ent[i].ent_lba_start, - ent[i].ent_lba_end - ent[i].ent_lba_start + 1LL, + m = map_add(ent->ent_lba_start, + ent->ent_lba_end - ent->ent_lba_start + 1LL, MAP_TYPE_GPT_PART, NULL); if (m == NULL) return (-1); @@ -343,7 +348,7 @@ return (0); fail_ent: - free(ent); + free(p); fail_hdr: free(hdr); @@ -441,11 +446,10 @@ return; } - /* Don't create more than maxparts entries. */ - if ((uint64_t)(blocks - 1) * secsz > - maxparts * sizeof(struct gpt_ent)) { - blocks = (maxparts * sizeof(struct gpt_ent)) / secsz; - if ((maxparts * sizeof(struct gpt_ent)) % secsz) + /* Don't create more than parts entries. */ + if ((uint64_t)(blocks - 1) * secsz > parts * sizeof(struct gpt_ent)) { + blocks = (parts * sizeof(struct gpt_ent)) / secsz; + if ((parts * sizeof(struct gpt_ent)) % secsz) blocks++; blocks++; /* Don't forget the header itself */ } @@ -491,8 +495,8 @@ uuidgen(&hdr->hdr_uuid, 1); hdr->hdr_lba_table = tbl->map_start; hdr->hdr_entries = (blocks * secsz) / sizeof(struct gpt_ent); - if (hdr->hdr_entries > maxparts) - hdr->hdr_entries = maxparts; + if (hdr->hdr_entries > parts) + hdr->hdr_entries = parts; hdr->hdr_entsz = sizeof(struct gpt_ent); ent = tbl->map_data; @@ -505,8 +509,16 @@ case 165: { /* FreeBSD */ uuid_t freebsd_slice = GPT_ENT_TYPE_FREEBSD_SLICE; ent->ent_type = freebsd_slice; + unicode16(ent->ent_name, + L"FreeBSD disklabel partition", 36); break; } + case 239: { /* EFI */ + uuid_t efi_slice = GPT_ENT_TYPE_EFI; + ent->ent_type = efi_slice; + unicode16(ent->ent_name, L"EFI system partition", 36); + break; + } default: continue; } @@ -516,7 +528,6 @@ size = (size << 16) + mbr->mbr_part[i].part_size_lo; ent->ent_lba_start = start; ent->ent_lba_end = start + size - 1LL; - unicode16(ent->ent_name, L"FreeBSD slice", 36); ent++; } ent = tbl->map_data; @@ -557,10 +568,10 @@ while ((ch = getopt(argc, argv, "p:rv")) != -1) { switch(ch) { case 'p': - if (maxparts > 0) + if (parts > 0) usage(); - maxparts = strtol(optarg, &p, 10); - if (*p != 0 || maxparts < 1) + parts = strtol(optarg, &p, 10); + if (*p != 0 || parts < 1) usage(); break; case 'r': @@ -573,8 +584,8 @@ usage(); } } - if (!maxparts) - maxparts = 128; + if (!parts) + parts = 128; argc -= optind; argv += optind; To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe p4-projects" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200205262056.g4QKulc25372>