Module Name: src Committed By: jakllsch Date: Sat Apr 13 18:04:33 UTC 2013
Modified Files: src/sbin/gpt: add.c create.c gpt.c gpt.h label.c migrate.c remove.c show.c Log Message: Clean up gpt(8) a bit more uuid_create_nil(3) and uuid_is_nil(3) take a uuid_t*, not a pointer to an array of bytes merely casted to compatible type. Additonally, there no need for extra casts and address-of operations when using le_uuid_*() functions. Furthermore, le_uuid_*() are identical to uuid_*_le functions in libc/libuuid, so use those instead on NetBSD. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/sbin/gpt/add.c cvs rdiff -u -r1.5 -r1.6 src/sbin/gpt/create.c src/sbin/gpt/gpt.h \ src/sbin/gpt/migrate.c cvs rdiff -u -r1.18 -r1.19 src/sbin/gpt/gpt.c cvs rdiff -u -r1.9 -r1.10 src/sbin/gpt/label.c cvs rdiff -u -r1.7 -r1.8 src/sbin/gpt/remove.c cvs rdiff -u -r1.8 -r1.9 src/sbin/gpt/show.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sbin/gpt/add.c diff -u src/sbin/gpt/add.c:1.11 src/sbin/gpt/add.c:1.12 --- src/sbin/gpt/add.c:1.11 Sat Aug 27 17:38:16 2011 +++ src/sbin/gpt/add.c Sat Apr 13 18:04:33 2013 @@ -29,7 +29,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: add.c,v 1.11 2011/08/27 17:38:16 joerg Exp $"); +__RCSID("$NetBSD: add.c,v 1.12 2013/04/13 18:04:33 jakllsch Exp $"); #endif #include <sys/types.h> @@ -65,6 +65,7 @@ usage_add(void) static void add(int fd) { + uuid_t uuid; map_t *gpt, *tpg; map_t *tbl, *lbt; map_t *map; @@ -105,7 +106,8 @@ add(int fd) i = entry - 1; ent = (void*)((char*)tbl->map_data + i * le32toh(hdr->hdr_entsz)); - if (!uuid_is_nil((uuid_t *)&ent->ent_type, NULL)) { + le_uuid_dec(ent->ent_type, &uuid); + if (!uuid_is_nil(&uuid, NULL)) { warnx("%s: error: entry at index %u is not free", device_name, entry); return; @@ -115,7 +117,8 @@ add(int fd) for (i = 0; i < le32toh(hdr->hdr_entries); i++) { ent = (void*)((char*)tbl->map_data + i * le32toh(hdr->hdr_entsz)); - if (uuid_is_nil((uuid_t *)&ent->ent_type, NULL)) + le_uuid_dec(ent->ent_type, &uuid); + if (uuid_is_nil(&uuid, NULL)) break; } if (i == le32toh(hdr->hdr_entries)) { @@ -131,7 +134,7 @@ add(int fd) return; } - le_uuid_enc((uuid_t *)&ent->ent_type, &type); + le_uuid_enc(ent->ent_type, &type); ent->ent_lba_start = htole64(map->map_start); ent->ent_lba_end = htole64(map->map_start + map->map_size - 1LL); @@ -146,7 +149,7 @@ add(int fd) hdr = tpg->map_data; ent = (void*)((char*)lbt->map_data + i * le32toh(hdr->hdr_entsz)); - le_uuid_enc(&ent->ent_type, &type); + le_uuid_enc(ent->ent_type, &type); ent->ent_lba_start = htole64(map->map_start); ent->ent_lba_end = htole64(map->map_start + map->map_size - 1LL); Index: src/sbin/gpt/create.c diff -u src/sbin/gpt/create.c:1.5 src/sbin/gpt/create.c:1.6 --- src/sbin/gpt/create.c:1.5 Sat Aug 27 17:38:16 2011 +++ src/sbin/gpt/create.c Sat Apr 13 18:04:33 2013 @@ -29,7 +29,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/create.c,v 1.11 2005/08/31 01:47:19 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: create.c,v 1.5 2011/08/27 17:38:16 joerg Exp $"); +__RCSID("$NetBSD: create.c,v 1.6 2013/04/13 18:04:33 jakllsch Exp $"); #endif #include <sys/types.h> @@ -171,7 +171,7 @@ create(int fd) hdr->hdr_lba_start = htole64(tbl->map_start + blocks); hdr->hdr_lba_end = htole64(last - blocks - 1LL); uuid_create(&uuid, NULL); - le_uuid_enc((uuid_t *)&hdr->hdr_uuid, &uuid); + le_uuid_enc(hdr->hdr_uuid, &uuid); hdr->hdr_lba_table = htole64(tbl->map_start); hdr->hdr_entries = htole32((blocks * secsz) / sizeof(struct gpt_ent)); if (le32toh(hdr->hdr_entries) > parts) @@ -181,7 +181,7 @@ create(int fd) ent = tbl->map_data; for (i = 0; i < le32toh(hdr->hdr_entries); i++) { uuid_create(&uuid, NULL); - le_uuid_enc((uuid_t *)&ent[i].ent_uuid, &uuid); + le_uuid_enc(ent[i].ent_uuid, &uuid); } hdr->hdr_crc_table = htole32(crc32(ent, le32toh(hdr->hdr_entries) * Index: src/sbin/gpt/gpt.h diff -u src/sbin/gpt/gpt.h:1.5 src/sbin/gpt/gpt.h:1.6 --- src/sbin/gpt/gpt.h:1.5 Thu Jan 6 01:08:48 2011 +++ src/sbin/gpt/gpt.h Sat Apr 13 18:04:33 2013 @@ -47,8 +47,13 @@ #include <uuid.h> +#ifdef __NetBSD__ +#define le_uuid_dec uuid_dec_le +#define le_uuid_enc uuid_enc_le +#else void le_uuid_dec(void const *, uuid_t *); void le_uuid_enc(void *, uuid_t const *); +#endif int parse_uuid(const char *, uuid_t *); struct mbr_part { Index: src/sbin/gpt/migrate.c diff -u src/sbin/gpt/migrate.c:1.5 src/sbin/gpt/migrate.c:1.6 --- src/sbin/gpt/migrate.c:1.5 Sat Aug 27 17:38:16 2011 +++ src/sbin/gpt/migrate.c Sat Apr 13 18:04:33 2013 @@ -29,7 +29,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/migrate.c,v 1.16 2005/09/01 02:42:52 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: migrate.c,v 1.5 2011/08/27 17:38:16 joerg Exp $"); +__RCSID("$NetBSD: migrate.c,v 1.6 2013/04/13 18:04:33 jakllsch Exp $"); #endif #include <sys/types.h> @@ -107,21 +107,21 @@ migrate_disklabel(int fd, off_t start, s continue; case FS_SWAP: { uuid_t swap = GPT_ENT_TYPE_FREEBSD_SWAP; - le_uuid_enc(&ent->ent_type, &swap); + le_uuid_enc(ent->ent_type, &swap); utf8_to_utf16((const uint8_t *)"FreeBSD swap partition", ent->ent_name, 36); break; } case FS_BSDFFS: { uuid_t ufs = GPT_ENT_TYPE_FREEBSD_UFS; - le_uuid_enc(&ent->ent_type, &ufs); + le_uuid_enc(ent->ent_type, &ufs); utf8_to_utf16((const uint8_t *)"FreeBSD UFS partition", ent->ent_name, 36); break; } case FS_VINUM: { uuid_t vinum = GPT_ENT_TYPE_FREEBSD_VINUM; - le_uuid_enc(&ent->ent_type, &vinum); + le_uuid_enc(ent->ent_type, &vinum); utf8_to_utf16((const uint8_t *)"FreeBSD vinum partition", ent->ent_name, 36); break; @@ -234,7 +234,7 @@ migrate(int fd) hdr->hdr_lba_start = htole64(tbl->map_start + blocks); hdr->hdr_lba_end = htole64(lbt->map_start - 1LL); uuid_create(&uuid, NULL); - le_uuid_enc(&hdr->hdr_uuid, &uuid); + le_uuid_enc(hdr->hdr_uuid, &uuid); hdr->hdr_lba_table = htole64(tbl->map_start); hdr->hdr_entries = htole32((blocks * secsz) / sizeof(struct gpt_ent)); if (le32toh(hdr->hdr_entries) > parts) @@ -244,7 +244,7 @@ migrate(int fd) ent = tbl->map_data; for (i = 0; i < le32toh(hdr->hdr_entries); i++) { uuid_create(&uuid, NULL); - le_uuid_enc(&ent[i].ent_uuid, &uuid); + le_uuid_enc(ent[i].ent_uuid, &uuid); } /* Mirror partitions. */ @@ -260,7 +260,7 @@ migrate(int fd) case 165: { /* FreeBSD */ if (slice) { uuid_t freebsd = GPT_ENT_TYPE_FREEBSD; - le_uuid_enc(&ent->ent_type, &freebsd); + le_uuid_enc(ent->ent_type, &freebsd); ent->ent_lba_start = htole64((uint64_t)start); ent->ent_lba_end = htole64(start + size - 1LL); utf8_to_utf16((const uint8_t *)"FreeBSD disklabel partition", @@ -272,7 +272,7 @@ migrate(int fd) } case 239: { /* EFI */ uuid_t efi_slice = GPT_ENT_TYPE_EFI; - le_uuid_enc(&ent->ent_type, &efi_slice); + le_uuid_enc(ent->ent_type, &efi_slice); ent->ent_lba_start = htole64((uint64_t)start); ent->ent_lba_end = htole64(start + size - 1LL); utf8_to_utf16((const uint8_t *)"EFI system partition", Index: src/sbin/gpt/gpt.c diff -u src/sbin/gpt/gpt.c:1.18 src/sbin/gpt/gpt.c:1.19 --- src/sbin/gpt/gpt.c:1.18 Fri Jan 18 17:58:15 2013 +++ src/sbin/gpt/gpt.c Sat Apr 13 18:04:33 2013 @@ -31,7 +31,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/gpt.c,v 1.16 2006/07/07 02:44:23 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: gpt.c,v 1.18 2013/01/18 17:58:15 jakllsch Exp $"); +__RCSID("$NetBSD: gpt.c,v 1.19 2013/04/13 18:04:33 jakllsch Exp $"); #endif #include <sys/param.h> @@ -241,6 +241,7 @@ utf8_to_utf16(const uint8_t *s8, uint16_ } while (c != 0); } +#ifndef __NetBSD__ void le_uuid_dec(void const *buf, uuid_t *uuid) { @@ -273,6 +274,7 @@ le_uuid_enc(void *buf, uuid_t const *uui p[10 + i] = uuid->node[i]; } +#endif int parse_uuid(const char *s, uuid_t *uuid) { Index: src/sbin/gpt/label.c diff -u src/sbin/gpt/label.c:1.9 src/sbin/gpt/label.c:1.10 --- src/sbin/gpt/label.c:1.9 Sat Apr 13 16:48:03 2013 +++ src/sbin/gpt/label.c Sat Apr 13 18:04:33 2013 @@ -29,7 +29,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/label.c,v 1.3 2006/10/04 18:20:25 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: label.c,v 1.9 2013/04/13 16:48:03 jakllsch Exp $"); +__RCSID("$NetBSD: label.c,v 1.10 2013/04/13 18:04:33 jakllsch Exp $"); #endif #include <sys/types.h> @@ -113,7 +113,7 @@ label(int fd) hdr = gpt->map_data; ent = (void*)((char*)tbl->map_data + i * le32toh(hdr->hdr_entsz)); - le_uuid_dec(&ent->ent_type, &uuid); + le_uuid_dec(ent->ent_type, &uuid); if (!uuid_is_nil(&type, NULL) && !uuid_equal(&type, &uuid, NULL)) continue; Index: src/sbin/gpt/remove.c diff -u src/sbin/gpt/remove.c:1.7 src/sbin/gpt/remove.c:1.8 --- src/sbin/gpt/remove.c:1.7 Sat Apr 13 16:48:03 2013 +++ src/sbin/gpt/remove.c Sat Apr 13 18:04:33 2013 @@ -29,7 +29,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/remove.c,v 1.10 2006/10/04 18:20:25 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: remove.c,v 1.7 2013/04/13 16:48:03 jakllsch Exp $"); +__RCSID("$NetBSD: remove.c,v 1.8 2013/04/13 18:04:33 jakllsch Exp $"); #endif #include <sys/types.h> @@ -112,13 +112,14 @@ rem(int fd) hdr = gpt->map_data; ent = (void*)((char*)tbl->map_data + i * le32toh(hdr->hdr_entsz)); - le_uuid_dec(&ent->ent_type, &uuid); + le_uuid_dec(ent->ent_type, &uuid); if (!uuid_is_nil(&type, NULL) && !uuid_equal(&type, &uuid, NULL)) continue; /* Remove the primary entry by clearing the partition type. */ - uuid_create_nil((uuid_t *)&ent->ent_type, NULL); + uuid_create_nil(&uuid, NULL); + le_uuid_enc(ent->ent_type, &uuid); hdr->hdr_crc_table = htole32(crc32(tbl->map_data, le32toh(hdr->hdr_entries) * le32toh(hdr->hdr_entsz))); @@ -133,7 +134,7 @@ rem(int fd) le32toh(hdr->hdr_entsz)); /* Remove the secondary entry. */ - uuid_create_nil((uuid_t *)&ent->ent_type, NULL); + le_uuid_enc(ent->ent_type, &uuid); hdr->hdr_crc_table = htole32(crc32(lbt->map_data, le32toh(hdr->hdr_entries) * le32toh(hdr->hdr_entsz))); Index: src/sbin/gpt/show.c diff -u src/sbin/gpt/show.c:1.8 src/sbin/gpt/show.c:1.9 --- src/sbin/gpt/show.c:1.8 Fri Jan 18 17:58:15 2013 +++ src/sbin/gpt/show.c Sat Apr 13 18:04:33 2013 @@ -29,7 +29,7 @@ __FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $"); #endif #ifdef __RCSID -__RCSID("$NetBSD: show.c,v 1.8 2013/01/18 17:58:15 jakllsch Exp $"); +__RCSID("$NetBSD: show.c,v 1.9 2013/04/13 18:04:33 jakllsch Exp $"); #endif #include <sys/types.h> @@ -193,7 +193,7 @@ show(int fd __unused) printf("- \"%s\"", utf16_to_utf8(ent->ent_name)); } else { - le_uuid_dec(&ent->ent_type, &type); + le_uuid_dec(ent->ent_type, &type); printf("- %s", friendly(&type)); } break;