summaryrefslogtreecommitdiffstats
path: root/sbin/gpt/create.c
diff options
context:
space:
mode:
authormarcel <marcel@FreeBSD.org>2004-10-25 02:23:39 +0000
committermarcel <marcel@FreeBSD.org>2004-10-25 02:23:39 +0000
commit187f216c0281b56ad14214c790708d11290f7360 (patch)
treecadc96972af3a5d1dde1d727fbd3378b44397e02 /sbin/gpt/create.c
parent774f792baecfaf8f7e8641695f5fc9e63e3119f5 (diff)
downloadFreeBSD-src-187f216c0281b56ad14214c790708d11290f7360.zip
FreeBSD-src-187f216c0281b56ad14214c790708d11290f7360.tar.gz
Add byte swapping and UUID encoding/decoding to allow gpt to be compiled
on big-endian machines. Obtained from: Dan Markarian <markarian at apple dot com>
Diffstat (limited to 'sbin/gpt/create.c')
-rw-r--r--sbin/gpt/create.c59
1 files changed, 31 insertions, 28 deletions
diff --git a/sbin/gpt/create.c b/sbin/gpt/create.c
index a80714c..e02e8a6 100644
--- a/sbin/gpt/create.c
+++ b/sbin/gpt/create.c
@@ -28,7 +28,6 @@
__FBSDID("$FreeBSD$");
#include <sys/types.h>
-#include <sys/gpt.h>
#include <err.h>
#include <stddef.h>
@@ -36,7 +35,6 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include <uuid.h>
#include "map.h"
#include "gpt.h"
@@ -55,6 +53,7 @@ usage_create(void)
static void
create(int fd)
{
+ uuid_t uuid;
off_t blocks, last;
map_t *gpt, *tpg;
map_t *tbl, *lbt;
@@ -84,7 +83,7 @@ create(int fd)
}
mbr = gpt_read(fd, 0LL, 1);
bzero(mbr, sizeof(*mbr));
- mbr->mbr_sig = MBR_SIG;
+ mbr->mbr_sig = htole16(MBR_SIG);
mbr->mbr_part[0].part_shd = 0xff;
mbr->mbr_part[0].part_ssect = 0xff;
mbr->mbr_part[0].part_scyl = 0xff;
@@ -92,13 +91,13 @@ create(int fd)
mbr->mbr_part[0].part_ehd = 0xff;
mbr->mbr_part[0].part_esect = 0xff;
mbr->mbr_part[0].part_ecyl = 0xff;
- mbr->mbr_part[0].part_start_lo = 1;
+ mbr->mbr_part[0].part_start_lo = htole16(1);
if (mediasz > 0xffffffff) {
- mbr->mbr_part[0].part_size_lo = 0xffff;
- mbr->mbr_part[0].part_size_hi = 0xffff;
+ mbr->mbr_part[0].part_size_lo = htole16(0xffff);
+ mbr->mbr_part[0].part_size_hi = htole16(0xffff);
} else {
- mbr->mbr_part[0].part_size_lo = mediasz & 0xffff;
- mbr->mbr_part[0].part_size_hi = mediasz >> 16;
+ mbr->mbr_part[0].part_size_lo = htole16(mediasz);
+ mbr->mbr_part[0].part_size_hi = htole16(mediasz >> 16);
}
map = map_add(0LL, 1LL, MAP_TYPE_PMBR, mbr);
gpt_write(fd, map);
@@ -151,29 +150,33 @@ create(int fd)
hdr = gpt->map_data;
memcpy(hdr->hdr_sig, GPT_HDR_SIG, sizeof(hdr->hdr_sig));
- hdr->hdr_revision = GPT_HDR_REVISION;
+ hdr->hdr_revision = htole32(GPT_HDR_REVISION);
/*
* XXX struct gpt_hdr is not a multiple of 8 bytes in size and thus
* contains padding we must not include in the size.
*/
- hdr->hdr_size = offsetof(struct gpt_hdr, padding);
- hdr->hdr_lba_self = gpt->map_start;
- hdr->hdr_lba_alt = last;
- hdr->hdr_lba_start = tbl->map_start + blocks;
- hdr->hdr_lba_end = last - blocks - 1LL;
- uuid_create(&hdr->hdr_uuid, NULL);
- hdr->hdr_lba_table = tbl->map_start;
- hdr->hdr_entries = (blocks * secsz) / sizeof(struct gpt_ent);
- if (hdr->hdr_entries > parts)
- hdr->hdr_entries = parts;
- hdr->hdr_entsz = sizeof(struct gpt_ent);
+ hdr->hdr_size = htole32(offsetof(struct gpt_hdr, padding));
+ hdr->hdr_lba_self = htole64(gpt->map_start);
+ hdr->hdr_lba_alt = htole64(last);
+ hdr->hdr_lba_start = htole64(tbl->map_start + blocks);
+ hdr->hdr_lba_end = htole64(last - blocks - 1LL);
+ uuid_create(&uuid, NULL);
+ 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)
+ hdr->hdr_entries = htole32(parts);
+ hdr->hdr_entsz = htole32(sizeof(struct gpt_ent));
ent = tbl->map_data;
- for (i = 0; i < hdr->hdr_entries; i++)
- uuid_create(&ent[i].ent_uuid, NULL);
+ for (i = 0; i < le32toh(hdr->hdr_entries); i++) {
+ uuid_create(&uuid, NULL);
+ le_uuid_enc(&ent[i].ent_uuid, &uuid);
+ }
- hdr->hdr_crc_table = crc32(ent, hdr->hdr_entries * hdr->hdr_entsz);
- hdr->hdr_crc_self = crc32(hdr, hdr->hdr_size);
+ hdr->hdr_crc_table = htole32(crc32(ent, le32toh(hdr->hdr_entries) *
+ le32toh(hdr->hdr_entsz)));
+ hdr->hdr_crc_self = htole32(crc32(hdr, le32toh(hdr->hdr_size)));
gpt_write(fd, gpt);
gpt_write(fd, tbl);
@@ -188,11 +191,11 @@ create(int fd)
tbl->map_data);
memcpy(tpg->map_data, gpt->map_data, secsz);
hdr = tpg->map_data;
- hdr->hdr_lba_self = tpg->map_start;
- hdr->hdr_lba_alt = gpt->map_start;
- hdr->hdr_lba_table = lbt->map_start;
+ hdr->hdr_lba_self = htole64(tpg->map_start);
+ hdr->hdr_lba_alt = htole64(gpt->map_start);
+ hdr->hdr_lba_table = htole64(lbt->map_start);
hdr->hdr_crc_self = 0; /* Don't ever forget this! */
- hdr->hdr_crc_self = crc32(hdr, hdr->hdr_size);
+ hdr->hdr_crc_self = htole32(crc32(hdr, le32toh(hdr->hdr_size)));
gpt_write(fd, lbt);
gpt_write(fd, tpg);
}
OpenPOWER on IntegriCloud