Ejemplo n.º 1
0
/*
 * uuid_compare() - compare two UUIDs.
 * See also:
 *	http://www.opengroup.org/onlinepubs/009629399/uuid_compare.htm
 *
 * NOTE: Either UUID can be NULL, meaning a nil UUID. nil UUIDs are smaller
 *	 than any non-nil UUID.
 */
int32_t
uuid_compare(const uuid_t *a, const uuid_t *b, uint32_t *status)
{
	int	res;

	if (status != NULL)
		*status = uuid_s_ok;

	/* Deal with NULL or equal pointers. */
	if (a == b)
		return (0);
	if (a == NULL)
		return ((uuid_is_nil(b, NULL)) ? 0 : -1);
	if (b == NULL)
		return ((uuid_is_nil(a, NULL)) ? 0 : 1);

	/* We have to compare the hard way. */
	DIFF_RETURN(a, b, time_low);
	DIFF_RETURN(a, b, time_mid);
	DIFF_RETURN(a, b, time_hi_and_version);
	DIFF_RETURN(a, b, clock_seq_hi_and_reserved);
	DIFF_RETURN(a, b, clock_seq_low);

	res = memcmp(a->node, b->node, sizeof(a->node));
	if (res)
		return ((res < 0) ? -1 : 1);
	return (0);
}
Ejemplo n.º 2
0
int
uuid_table_insert(uuid_t *uuid)
{
	int	i, hole;

	mutex_lock(&uuid_monitor, PVFS);
	for (i = 0, hole = -1; i < uuid_table_size; i++) {
		if (uuid_is_nil(&uuid_table[i])) {
			hole = i;
			continue;
		}
		if (uuid_equal(uuid, &uuid_table[i])) {
			mutex_unlock(&uuid_monitor);
			return 0;
		}
	}
	if (hole < 0) {
		uuid_table = kmem_realloc(uuid_table,
			(uuid_table_size + 1) * sizeof(*uuid_table),
			uuid_table_size  * sizeof(*uuid_table),
			KM_SLEEP);
		hole = uuid_table_size++;
	}
	uuid_table[hole] = *uuid;
	mutex_unlock(&uuid_monitor);
	return 1;
}
Ejemplo n.º 3
0
/*
 * uuid_equal() - compare for equality.
 * See also:
 *	http://www.opengroup.org/onlinepubs/009629399/uuid_equal.htm
 */
int32_t
uuid_equal(const uuid_t *a, const uuid_t *b, uint32_t *status)
{
	if (status != NULL)
		*status = uuid_s_ok;

	/* Deal with equal or NULL pointers. */
	if (a == b)
		return (1);
	if (a == NULL)
		return (uuid_is_nil(b, NULL));
	if (b == NULL)
		return (uuid_is_nil(a, NULL));

	/* Do a byte for byte comparison. */
	return ((memcmp(a, b, sizeof(uuid_t))) ? 0 : 1);
}
Ejemplo n.º 4
0
int uuuid_is_nil(struct uuuid_t* uuuid, int* status)
{
	uint32_t st;
	int ret;

	ret = uuid_is_nil(&uuuid->uuid, &st);

	if (st != uuid_s_ok) {
		*status = UUUID_ERR;
		return -1;
	}

	*status = UUUID_OK;

	return ret;
}
Ejemplo n.º 5
0
void
uuid_table_remove(uuid_t *uuid)
{
	int	i;

	mutex_lock(&uuid_monitor, PVFS);
	for (i = 0; i < uuid_table_size; i++) {
		if (uuid_is_nil(&uuid_table[i]))
			continue;
		if (!uuid_equal(uuid, &uuid_table[i]))
			continue;
		uuid_create_nil(&uuid_table[i]);
		break;
	}
	ASSERT(i < uuid_table_size);
	mutex_unlock(&uuid_monitor);
}
Ejemplo n.º 6
0
static int ps3disk_open_gpt(struct ps3_devdesc *dev, struct open_dev *od)
{
	char buf[512];
	struct gpt_hdr *hdr;
	struct gpt_ent *ent;
	daddr_t slba, elba, lba;
	int nparts, eps, i, part, err;

	od->od_gpt_nparts = 0;
	od->od_gpt_parts = NULL;

	err = ps3stor_read_sectors(&stor_dev, dev->d_unit, 0, 1, 0, buf);
	if (err) {
		err = EIO;
		goto out;
	}

	if (le16toh(*((uint16_t *) (buf + DOSMAGICOFFSET))) != DOSMAGIC) {
		err = ENXIO;
		goto out;
	}

	err = ps3stor_read_sectors(&stor_dev, dev->d_unit, 1, 1, 0, buf);
	if (err) {
		err = EIO;
		goto out;
	}

	hdr = (struct gpt_hdr *) buf;

	if (bcmp(hdr->hdr_sig, GPT_HDR_SIG, sizeof(hdr->hdr_sig)) ||
		le64toh(hdr->hdr_lba_self) != 1 || le32toh(hdr->hdr_revision) < 0x00010000 ||
		le32toh(hdr->hdr_entsz) < sizeof(struct gpt_ent) ||
		stor_dev.sd_blksize % le32toh(hdr->hdr_entsz) != 0) {
		err = ENXIO;
		goto out;
	}

	nparts = 0;
	eps = stor_dev.sd_blksize / le32toh(hdr->hdr_entsz);
	slba = le64toh(hdr->hdr_lba_table);
	elba = slba + le32toh(hdr->hdr_entries) / eps;

	for (lba = slba; lba < elba; lba++) {
		err = ps3stor_read_sectors(&stor_dev, dev->d_unit, lba, 1, 0, buf);
		if (err) {
			err = EIO;
			goto out;
		}

		ent = (struct gpt_ent *) buf;

		for (i = 0; i < eps; i++) {
			if (uuid_is_nil(&ent[i].ent_type, NULL) ||
				le64toh(ent[i].ent_lba_start) == 0 ||
				le64toh(ent[i].ent_lba_end) < le64toh(ent[i].ent_lba_start))
				continue;

			nparts++;
		}
	}

	if (nparts) {
		od->od_gpt_nparts = nparts;

		od->od_gpt_parts = malloc(nparts * sizeof(struct gpt_part));
		if (!od->od_gpt_parts) {
			err = ENOMEM;
			goto out;
		}

		for (lba = slba, part = 0; lba < elba; lba++) {
			err = ps3stor_read_sectors(&stor_dev, dev->d_unit, lba, 1, 0, buf);
			if (err) {
				err = EIO;
				goto out;
			}

			ent = (struct gpt_ent *) buf;

			for (i = 0; i < eps; i++) {
				if (uuid_is_nil(&ent[i].ent_type, NULL) ||
					le64toh(ent[i].ent_lba_start) == 0 ||
					le64toh(ent[i].ent_lba_end) < le64toh(ent[i].ent_lba_start))
					continue;

				od->od_gpt_parts[part].gp_index = (lba - slba) * eps + i + 1;
				od->od_gpt_parts[part].gp_type = ent[i].ent_type;
				od->od_gpt_parts[part].gp_start = le64toh(ent[i].ent_lba_start);
				od->od_gpt_parts[part].gp_end = le64toh(ent[i].ent_lba_end);
				ps3disk_uuid_letoh(&od->od_gpt_parts[part].gp_type);
				part++;
			}
		}
	}

	dev->d_disk.ptype = PTYPE_GPT;

	if (od->od_gpt_nparts && !dev->d_disk.pnum)
		dev->d_disk.pnum = od->od_gpt_parts[0].gp_index;

	for (i = 0; i < od->od_gpt_nparts; i++)
		if (od->od_gpt_parts[i].gp_index == dev->d_disk.pnum)
			od->od_start = od->od_gpt_parts[i].gp_start;

	err = 0;

out:

	if (err && od->od_gpt_parts)
		free(od->od_gpt_parts);

	return err;
}
Ejemplo n.º 7
0
int libxl_uuid_is_nil(const libxl_uuid *uuid)
{
    uint32_t status;

    return uuid_is_nil(&uuid->uuid, &status);
}
Ejemplo n.º 8
0
static void
rem(gd_t gd)
{
	uuid_t uuid;
	map_t m;
	struct gpt_hdr *hdr;
	struct gpt_ent *ent;
	unsigned int i;

	if ((hdr = gpt_gethdr(gd)) == NULL)
		return;

	/* Remove all matching entries in the map. */
	for (m = map_first(gd); m != NULL; m = m->map_next) {
		if (m->map_type != MAP_TYPE_GPT_PART || m->map_index < 1)
			continue;
		if (entry > 0 && entry != m->map_index)
			continue;
		if (block > 0 && block != m->map_start)
			continue;
		if (size > 0 && size != m->map_size)
			continue;

		i = m->map_index - 1;

		hdr = gd->gpt->map_data;
		ent = (void*)((char*)gd->tbl->map_data + i *
		    le32toh(hdr->hdr_entsz));
		uuid_dec_le(&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, NULL);
		uuid_enc_le(&ent->ent_type, &uuid);

		hdr->hdr_crc_table = htole32(crc32(gd->tbl->map_data,
		    le32toh(hdr->hdr_entries) * le32toh(hdr->hdr_entsz)));
		hdr->hdr_crc_self = 0;
		hdr->hdr_crc_self = htole32(crc32(hdr, le32toh(hdr->hdr_size)));

		gpt_write(gd, gd->gpt);
		gpt_write(gd, gd->tbl);

		hdr = gd->tpg->map_data;
		ent = (void*)((char*)gd->lbt->map_data + i *
		    le32toh(hdr->hdr_entsz));

		/* Remove the secondary entry. */
		uuid_enc_le(&ent->ent_type, &uuid);

		hdr->hdr_crc_table = htole32(crc32(gd->lbt->map_data,
		    le32toh(hdr->hdr_entries) * le32toh(hdr->hdr_entsz)));
		hdr->hdr_crc_self = 0;
		hdr->hdr_crc_self = htole32(crc32(hdr, le32toh(hdr->hdr_size)));

		gpt_write(gd, gd->lbt);
		gpt_write(gd, gd->tpg);

		gpt_status(gd, m->map_index, "removed");
	}
}
Ejemplo n.º 9
0
int
cmd_remove(int argc, char *argv[])
{
	char *p;
	int ch;
	int flags = 0;
	gd_t gd;

	/* Get the remove options */
	while ((ch = getopt(argc, argv, "ab:i:s:t:")) != -1) {
		switch(ch) {
		case 'a':
			if (all > 0)
				usage_remove();
			all = 1;
			break;
		case 'b':
			if (block > 0)
				usage_remove();
			block = strtoll(optarg, &p, 10);
			if (*p != 0 || block < 1)
				usage_remove();
			break;
		case 'i':
			if (entry > 0)
				usage_remove();
			entry = strtol(optarg, &p, 10);
			if (*p != 0 || entry < 1)
				usage_remove();
			break;
		case 's':
			if (size > 0)
				usage_remove();
			size = strtoll(optarg, &p, 10);
			if (*p != 0 || size < 1)
				usage_remove();
			break;
		case 't':
			if (!uuid_is_nil(&type, NULL))
				usage_remove();
			if (parse_uuid(optarg, &type) != 0)
				usage_remove();
			break;
		default:
			usage_remove();
		}
	}

	if (!all ^
	    (block > 0 || entry > 0 || size > 0 || !uuid_is_nil(&type, NULL)))
		usage_remove();

	if (argc == optind)
		usage_remove();

	while (optind < argc) {
		gd = gpt_open(argv[optind++], flags);
		if (gd == NULL) {
			continue;
		}

		rem(gd);

		gpt_close(gd);
	}

	return (0);
}
Ejemplo n.º 10
0
static void
rem(int fd)
{
	uuid_t uuid;
	map_t *gpt, *tpg;
	map_t *tbl, *lbt;
	map_t *m;
	struct gpt_hdr *hdr;
	struct gpt_ent *ent;
	unsigned int i;

	gpt = map_find(MAP_TYPE_PRI_GPT_HDR);
	if (gpt == NULL) {
		warnx("%s: error: no primary GPT header; run create or recover",
		    device_name);
		return;
	}

	tpg = map_find(MAP_TYPE_SEC_GPT_HDR);
	if (tpg == NULL) {
		warnx("%s: error: no secondary GPT header; run recover",
		    device_name);
		return;
	}

	tbl = map_find(MAP_TYPE_PRI_GPT_TBL);
	lbt = map_find(MAP_TYPE_SEC_GPT_TBL);
	if (tbl == NULL || lbt == NULL) {
		warnx("%s: error: run recover -- trust me", device_name);
		return;
	}

	/* Remove all matching entries in the map. */
	for (m = map_first(); m != NULL; m = m->map_next) {
		if (m->map_type != MAP_TYPE_GPT_PART || m->map_index == NOENTRY)
			continue;
		if (entry != NOENTRY && entry != m->map_index)
			continue;
		if (block > 0 && block != m->map_start)
			continue;
		if (size > 0 && size != m->map_size)
			continue;

		i = m->map_index;

		hdr = gpt->map_data;
		ent = (void*)((char*)tbl->map_data + i *
		    le32toh(hdr->hdr_entsz));
		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(&ent->ent_type, NULL);

		hdr->hdr_crc_table = htole32(crc32(tbl->map_data,
		    le32toh(hdr->hdr_entries) * le32toh(hdr->hdr_entsz)));
		hdr->hdr_crc_self = 0;
		hdr->hdr_crc_self = htole32(crc32(hdr, le32toh(hdr->hdr_size)));

		gpt_write(fd, gpt);
		gpt_write(fd, tbl);

		hdr = tpg->map_data;
		ent = (void*)((char*)lbt->map_data + i *
		    le32toh(hdr->hdr_entsz));

		/* Remove the secundary entry. */
		uuid_create_nil(&ent->ent_type, NULL);

		hdr->hdr_crc_table = htole32(crc32(lbt->map_data,
		    le32toh(hdr->hdr_entries) * le32toh(hdr->hdr_entsz)));
		hdr->hdr_crc_self = 0;
		hdr->hdr_crc_self = htole32(crc32(hdr, le32toh(hdr->hdr_size)));

		gpt_write(fd, lbt);
		gpt_write(fd, tpg);

		printf("%ss%u removed\n", device_name, m->map_index);
	}
}
Ejemplo n.º 11
0
int
cmd_remove(int argc, char *argv[])
{
	char *p;
	int ch, fd;

	/* Get the remove options */
	while ((ch = getopt(argc, argv, "ab:i:s:t:")) != -1) {
		switch(ch) {
		case 'a':
			if (all > 0)
				usage_remove();
			all = 1;
			break;
		case 'b':
			if (block > 0)
				usage_remove();
			block = strtoll(optarg, &p, 10);
			if (*p != 0 || block < 1)
				usage_remove();
			break;
		case 'i':
			if (entry != NOENTRY)
				usage_remove();
			entry = strtoul(optarg, &p, 10);
			if (*p != 0 || entry == NOENTRY)
				usage_remove();
			break;
		case 's':
			if (size > 0)
				usage_remove();
			size = strtoll(optarg, &p, 10);
			if (*p != 0 || size < 1)
				usage_remove();
			break;
		case 't':
			if (!uuid_is_nil(&type, NULL))
				usage_remove();
			if (parse_uuid(optarg, &type) != 0)
				usage_remove();
			break;
		default:
			usage_remove();
		}
	}

	if (!all ^
	    (block > 0 || entry != NOENTRY || size > 0 ||
	     !uuid_is_nil(&type, NULL)))
		usage_remove();

	if (argc == optind)
		usage_remove();

	while (optind < argc) {
		fd = gpt_open(argv[optind++]);
		if (fd == -1) {
			warn("unable to open device '%s'", device_name);
			continue;
		}

		rem(fd);

		gpt_close(fd);
	}

	return (0);
}
Ejemplo n.º 12
0
static void
add(int fd)
{
	map_t *gpt, *tpg;
	map_t *tbl, *lbt;
	map_t *map;
	struct gpt_hdr *hdr;
	struct gpt_ent *ent;
	unsigned int i;

	gpt = map_find(MAP_TYPE_PRI_GPT_HDR);
	if (gpt == NULL) {
		warnx("%s: error: no primary GPT header; run create or recover",
		    device_name);
		return;
	}

	tpg = map_find(MAP_TYPE_SEC_GPT_HDR);
	if (tpg == NULL) {
		warnx("%s: error: no secondary GPT header; run recover",
		    device_name);
		return;
	}

	tbl = map_find(MAP_TYPE_PRI_GPT_TBL);
	lbt = map_find(MAP_TYPE_SEC_GPT_TBL);
	if (tbl == NULL || lbt == NULL) {
		warnx("%s: error: run recover -- trust me", device_name);
		return;
	}

	hdr = gpt->map_data;
	if (entry != NOENTRY && entry > le32toh(hdr->hdr_entries)) {
		warnx("%s: error: index %u out of range (%u max)", device_name,
		    entry, le32toh(hdr->hdr_entries));
		return;
	}

	if (entry != NOENTRY) {
		i = entry;
		ent = (void*)((char*)tbl->map_data + i *
		    le32toh(hdr->hdr_entsz));
		if (!uuid_is_nil(&ent->ent_type, NULL)) {
			warnx("%s: error: entry at index %u is not free",
			    device_name, entry);
			return;
		}
	} else {
		/* Find empty slot in GPT table. */
		ent = NULL;
		for (i = 0; i < le32toh(hdr->hdr_entries); i++) {
			ent = (void*)((char*)tbl->map_data + i *
			    le32toh(hdr->hdr_entsz));
			if (uuid_is_nil(&ent->ent_type, NULL))
				break;
		}
		if (i == le32toh(hdr->hdr_entries)) {
			warnx("%s: error: no available table entries",
			    device_name);
			return;
		}
	}

	map = map_alloc(block, size);
	if (map == NULL) {
		warnx("%s: error: no space available on device", device_name);
		return;
	}

	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);

	hdr->hdr_crc_table = htole32(crc32(tbl->map_data,
	    le32toh(hdr->hdr_entries) * le32toh(hdr->hdr_entsz)));
	hdr->hdr_crc_self = 0;
	hdr->hdr_crc_self = htole32(crc32(hdr, le32toh(hdr->hdr_size)));

	gpt_write(fd, gpt);
	gpt_write(fd, tbl);

	hdr = tpg->map_data;
	ent = (void*)((char*)lbt->map_data + i * le32toh(hdr->hdr_entsz));

	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);

	hdr->hdr_crc_table = htole32(crc32(lbt->map_data,
	    le32toh(hdr->hdr_entries) * le32toh(hdr->hdr_entsz)));
	hdr->hdr_crc_self = 0;
	hdr->hdr_crc_self = htole32(crc32(hdr, le32toh(hdr->hdr_size)));

	gpt_write(fd, lbt);
	gpt_write(fd, tpg);

	printf("%ss%u added\n", device_name, i);
}
Ejemplo n.º 13
0
int
cmd_add(int argc, char *argv[])
{
	char *p;
	int ch, fd;

	/* Get the migrate options */
	while ((ch = getopt(argc, argv, "b:i:s:t:")) != -1) {
		switch(ch) {
		case 'b':
			if (block > 0)
				usage_add();
			block = strtoll(optarg, &p, 10);
			if (*p != 0 || block < 1)
				usage_add();
			break;
		case 'i':
			if (entry != NOENTRY)
				usage_add();
			entry = strtoul(optarg, &p, 10);
			if (*p != 0 || entry == NOENTRY)
				usage_add();
			break;
		case 's':
			if (size > 0)
				usage_add();
			size = strtoll(optarg, &p, 10);
			if (*p != 0 || size < 1)
				usage_add();
			break;
		case 't':
			if (!uuid_is_nil(&type, NULL))
				usage_add();
			if (parse_uuid(optarg, &type) != 0)
				usage_add();
			break;
		default:
			usage_add();
		}
	}

	if (argc == optind)
		usage_add();

	/* Create DragonFly 64 bit label partitions by default. */
	if (uuid_is_nil(&type, NULL)) {
		uint32_t status;

		uuid_name_lookup(&type, "DragonFly Label64", &status);
		if (status != uuid_s_ok)
			err(1, "unable to find uuid for 'DragonFly Label64'");
	}

	while (optind < argc) {
		fd = gpt_open(argv[optind++]);
		if (fd == -1) {
			warn("unable to open device '%s'", device_name);
			continue;
		}

		add(fd);

		gpt_close(fd);
	}

	return (0);
}
Ejemplo n.º 14
0
static void
bootset(int fd)
{
	uuid_t uuid;
	off_t  block;
	off_t  size;
	unsigned int entry;
	map_t *gpt, *tpg;
	map_t *tbl, *lbt;
	map_t *map;
	u_int32_t status;
	struct gpt_hdr *hdr;
	struct gpt_ent *ent;
	struct mbr *mbr;
	int bfd;

	/*
	 * Paramters for boot partition
	 */
	uuid_name_lookup(&uuid, "DragonFly Label32", &status);
	if (status != uuid_s_ok)
		err(1, "unable to find uuid for 'DragonFly Label32'");
	entry = 0;
	block = 0;
	size = 768 * 1024 * 1024 / 512;

	gpt = map_find(MAP_TYPE_PRI_GPT_HDR);
	if (gpt == NULL)
		errx(1, "%s: error: no primary GPT header", device_name);
	tpg = map_find(MAP_TYPE_SEC_GPT_HDR);
	if (tpg == NULL)
		errx(1, "%s: error: no secondary GPT header", device_name);
	tbl = map_find(MAP_TYPE_PRI_GPT_TBL);
	lbt = map_find(MAP_TYPE_SEC_GPT_TBL);
	if (tbl == NULL || lbt == NULL) {
		errx(1, "%s: error: no primary or secondary gpt table",
		     device_name);
	}

	hdr = gpt->map_data;
	if (entry > le32toh(hdr->hdr_entries)) {
		errx(1, "%s: error: index %u out of range (%u max)",
		     device_name, entry, le32toh(hdr->hdr_entries));
	}

	ent = (void *)((char *)tbl->map_data + entry *
		       le32toh(hdr->hdr_entsz));
	if (!uuid_is_nil(&ent->ent_type, NULL)) {
		errx(1, "%s: error: entry at index %d is not free",
		     device_name, entry);
	}
	map = map_alloc(block, size);
	if (map == NULL)
		errx(1, "%s: error: no space available on device", device_name);
	block = map->map_start;
	size  = map->map_size;

	le_uuid_enc(&ent->ent_type, &uuid);
	ent->ent_lba_start = htole64(map->map_start);
	ent->ent_lba_end = htole64(map->map_start + map->map_size - 1LL);

	hdr->hdr_crc_table = htole32(crc32(tbl->map_data,
				     le32toh(hdr->hdr_entries) *
				     le32toh(hdr->hdr_entsz)));
	hdr->hdr_crc_self = 0;
	hdr->hdr_crc_self = htole32(crc32(hdr, le32toh(hdr->hdr_size)));

	gpt_write(fd, gpt);
	gpt_write(fd, tbl);

	hdr = tpg->map_data;
	ent = (void*)((char*)lbt->map_data + entry * le32toh(hdr->hdr_entsz));
	le_uuid_enc(&ent->ent_type, &uuid);
	ent->ent_lba_start = htole64(map->map_start);
	ent->ent_lba_end = htole64(map->map_start + map->map_size - 1LL);

	hdr->hdr_crc_table = htole32(crc32(lbt->map_data,
				     le32toh(hdr->hdr_entries) *
				     le32toh(hdr->hdr_entsz)));
	hdr->hdr_crc_self = 0;
	hdr->hdr_crc_self = htole32(crc32(hdr, le32toh(hdr->hdr_size)));

	gpt_write(fd, lbt);
	gpt_write(fd, tpg);

	/*
	 * Create a dummy partition
	 */
	map = map_find(MAP_TYPE_PMBR);
	if (map == NULL)
		errx(1, "I can't find the PMBR!");
	mbr = map->map_data;
	if (mbr == NULL)
		errx(1, "I can't find the PMBR's data!");

	/*
	 * Copy in real boot code
	 */
	bfd = open("/boot/boot0", O_RDONLY);
	if (bfd < 0 ||
	    read(bfd, mbr->mbr_code, sizeof(mbr->mbr_code)) !=
	    sizeof(mbr->mbr_code)) {
		errx(1, "Cannot read /boot/boot0");
	}
	close(bfd);

	/*
	 * Generate partition #1
	 */
	mbr->mbr_part[1].part_shd = 0xff;
	mbr->mbr_part[1].part_ssect = 0xff;
	mbr->mbr_part[1].part_scyl = 0xff;
	mbr->mbr_part[1].part_ehd = 0xff;
	mbr->mbr_part[1].part_esect = 0xff;
	mbr->mbr_part[1].part_ecyl = 0xff;
	mbr->mbr_part[1].part_start_lo = htole16(block);
	mbr->mbr_part[1].part_start_hi = htole16((block) >> 16);
	mbr->mbr_part[1].part_size_lo = htole16(size);
	mbr->mbr_part[1].part_size_hi = htole16(size >> 16);

	mbr->mbr_part[1].part_typ = 165;
	mbr->mbr_part[1].part_flag = 0x80;

	gpt_write(fd, map);
}
Ejemplo n.º 15
0
int libxl_uuid_is_nil(libxl_uuid *uuid)
{
    uint32_t status;
    return uuid_is_nil((uuid_t *)uuid->uuid, &status);
}
Ejemplo n.º 16
0
int
main(int argc, char **argv)
{
  uint8_t anuuid[16];
  uint8_t anuuid2[16];
  
  uuid_str2bin(NOT_NIL_UUID_STR, anuuid);
  fprintf(stderr, "%s cmp %02x%02x%02x%02x-%02x%02x-%02x%02x-"
          "%02x%02x-%02x%02x%02x%02x%02x%02x\n", NOT_NIL_UUID_STR,
          anuuid[0], anuuid[1], anuuid[2], anuuid[3], 
          anuuid[4], anuuid[5], anuuid[6], anuuid[7], 
          anuuid[8], anuuid[9], anuuid[10], anuuid[11], 
          anuuid[12], anuuid[13], anuuid[14], anuuid[15]);
  uuid_str2bin(NOT_NIL_UUID_STR2, anuuid2);
  fprintf(stderr, "%s cmp %02x%02x%02x%02x-%02x%02x-%02x%02x-"
          "%02x%02x-%02x%02x%02x%02x%02x%02x\n", NOT_NIL_UUID_STR2,
          anuuid2[0], anuuid2[1], anuuid2[2], anuuid2[3], 
          anuuid2[4], anuuid2[5], anuuid2[6], anuuid2[7], 
          anuuid2[8], anuuid2[9], anuuid2[10], anuuid2[11], 
          anuuid2[12], anuuid2[13], anuuid2[14], anuuid2[15]);
  

  /*
   * uuid_is_nil with nil UUID
   */
  uint8_t nilUUID[16] = NIL_UUID;
  char nilUUIDstr[40];
  n_tests++;
  if (uuid_bin2str(nilUUID, nilUUIDstr, 40) < 0)
    {
      fprintf(stderr, "Failure\n");
      goto skip1;
    }
  char isnil = uuid_is_nil(nilUUID);
  if (isnil) 
    n_tests_passed++;
  else
    n_tests_failed++;
  printf("%s is nil? %s <%s>\n", 
	 nilUUIDstr, isnil ? "YES" : "NO", isnil ? "passed" : "failed" );

 skip1:
  {
    /*
     * uuid_is_nil with not nil UUID
     */
    uint8_t notNilUUID[16] = NOT_NIL_UUID;
    char notNilUUIDstr[40];
    n_tests++;
    if (uuid_bin2str(notNilUUID, notNilUUIDstr, 40) < 0)
      {
	fprintf(stderr, "Failure\n");
	goto skip2;
      }
    char isnil = uuid_is_nil(notNilUUID);
    if (!isnil) 
      n_tests_passed++;
    else
      n_tests_failed++;
    printf("%s is nil? %s <%s>\n", 
	   notNilUUIDstr, isnil ? "YES" : "NO", isnil ? "failed" : "passed" );
  }

 skip2:
  {
    /*
     * uuid_cmp with one nil UUID
     */
    uint8_t nilUUID[16] = NIL_UUID;
    char nilUUIDstr[40];
    uint8_t notNilUUID[16] = NOT_NIL_UUID;
    char notNilUUIDstr[40];
    n_tests++;
    if (uuid_bin2str(nilUUID, nilUUIDstr, 40) < 0)
      {
	fprintf(stderr, "Failure\n");
	goto skip3;
      }
    n_tests++;
    if (uuid_bin2str(notNilUUID, notNilUUIDstr, 40) < 0)
      {
	fprintf(stderr, "Failure\n");
	goto skip3;
      }
    int8_t cmpval1 = uuid_cmp(notNilUUID, nilUUID);
    int8_t cmpval2 = uuid_cmp(nilUUID, notNilUUID);
    if (cmpval1 + cmpval2 == 0 && cmpval1 != 0)
      n_tests_passed+=2;
    else
      n_tests_failed+=2;
    printf("%s cmp %s = %d <%s>\n", 
	   notNilUUIDstr, nilUUIDstr, cmpval1, cmpval1 ? "passed" : "failed" );
    printf("%s cmp %s = %d <%s>\n", 
	   nilUUIDstr, notNilUUIDstr, cmpval2, cmpval2 ? "passed" : "failed" );
    
  }

 skip3:
  {
    /*
     * uuid_cmp with both nil UUID
     */
    uint8_t nilUUID1[16] = NIL_UUID;
    char nilUUID1str[40];
    uint8_t nilUUID2[16] = NIL_UUID;
    char nilUUID2str[40];
    n_tests++;
    if (uuid_bin2str(nilUUID1, nilUUID1str, 40) < 0)
      {
	fprintf(stderr, "Failure\n");
	goto skip4;
      }
    n_tests++;
    if (uuid_bin2str(nilUUID2, nilUUID2str, 40) < 0)
      {
	fprintf(stderr, "Failure\n");
	goto skip4;
      }
    int8_t cmpval1 = uuid_cmp(nilUUID1, nilUUID2);
    int8_t cmpval2 = uuid_cmp(nilUUID2, nilUUID1);
    if (cmpval1 == cmpval2 && cmpval1 == 0)
      n_tests_passed+=2;
    else
      n_tests_failed+=2;
    printf("%s cmp %s = %d <%s>\n", 
	   nilUUID1str, nilUUID2str, cmpval1, cmpval1 ? "failed" : "passed" );
    printf("%s cmp %s = %d <%s>\n", 
	   nilUUID2str, nilUUID1str, cmpval2, cmpval2 ? "failed" : "passed" );
  }

 skip4:
  {
    /*
     * uuid_cmp with both not nil UUID
     */
    uint8_t notNilUUID1[16] = NOT_NIL_UUID;
    char notNilUUID1str[40];
    uint8_t notNilUUID2[16] = NOT_NIL_UUID;
    char notNilUUID2str[40];
    n_tests++;
    if (uuid_bin2str(notNilUUID1, notNilUUID1str, 40) < 0)
      {
	fprintf(stderr, "Failure\n");
	goto skip5;
      }
    n_tests++;
    if (uuid_bin2str(notNilUUID2, notNilUUID2str, 40) < 0)
      {
	fprintf(stderr, "Failure\n");
	goto skip5;
      }
    int8_t cmpval1 = uuid_cmp(notNilUUID1, notNilUUID2);
    int8_t cmpval2 = uuid_cmp(notNilUUID2, notNilUUID1);
    if (cmpval1 == cmpval2 && cmpval1 == 0)
      n_tests_passed+=2;
    else
      n_tests_failed+=2;
    printf("%s cmp %s = %d <%s>\n", 
	   notNilUUID1str, notNilUUID2str, cmpval1, cmpval1 ? "failed" : "passed" );
    printf("%s cmp %s = %d <%s>\n", 
	   notNilUUID2str, notNilUUID1str, cmpval2, cmpval2 ? "failed" : "passed" );
    
  }

 skip5:
  {
    /*
     * uuid_cmp with both not nil UUID
     */
    uint8_t notNilUUID1[16] = NOT_NIL_UUID;
    char notNilUUID1str[40];
    uint8_t notNilUUID2[16] = NOT_NIL_UUID2;
    char notNilUUID2str[40];
    n_tests++;
    if (uuid_bin2str(notNilUUID1, notNilUUID1str, 40) < 0)
      {
	fprintf(stderr, "Failure\n");
	goto skip6;
      }
    n_tests++;
    if (uuid_bin2str(notNilUUID2, notNilUUID2str, 40) < 0)
      {
	fprintf(stderr, "Failure\n");
	goto skip6;
      }
    int8_t cmpval1 = uuid_cmp(notNilUUID1, notNilUUID2);
    int8_t cmpval2 = uuid_cmp(notNilUUID2, notNilUUID1);
    if (cmpval1 + cmpval2 == 0 && cmpval1 != 0)
      n_tests_passed+=2;
    else
      n_tests_failed+=2;
    printf("%s cmp %s = %d <%s>\n", 
	   notNilUUID1str, notNilUUID2str, cmpval1, cmpval1 ? "passed" : "failed" );
    printf("%s cmp %s = %d <%s>\n", 
	   notNilUUID2str, notNilUUID1str, cmpval2, cmpval2 ? "passed" : "failed" );
    
  }

 skip6:
  {
    /*
     * uuid_cmp with one nil UUID
     */
    uint8_t nilUUID[16];
    char nilUUIDstr[40] = NIL_UUID_STR;
    uint8_t notNilUUID[16];
    char notNilUUIDstr[40] = NOT_NIL_UUID_STR;
    n_tests++;
    if (uuid_str2bin(nilUUIDstr, nilUUID) < 0)
      {
	fprintf(stderr, "Failure\n");
	goto skip7;
      }
    n_tests++;
    if (uuid_str2bin(notNilUUIDstr, notNilUUID) < 0)
      {
	fprintf(stderr, "Failure\n");
	goto skip7;
      }
    int8_t cmpval1 = uuid_cmp(notNilUUID, nilUUID);
    int8_t cmpval2 = uuid_cmp(nilUUID, notNilUUID);
    if (cmpval1 + cmpval2 == 0 && cmpval1 != 0)
      n_tests_passed+=2;
    else
      n_tests_failed+=2;
    printf("%s cmp %s = %d <%s>\n", 
	   notNilUUIDstr, nilUUIDstr, cmpval1, cmpval1 ? "passed" : "failed" );
    printf("%s cmp %s = %d <%s>\n", 
	   nilUUIDstr, notNilUUIDstr, cmpval2, cmpval2 ? "passed" : "failed" );
    
  }

 skip7:
  {
    /*
     * uuid_cmp with both nil UUID
     */
    uint8_t nilUUID1[16];
    char nilUUID1str[40] = NIL_UUID_STR;
    uint8_t nilUUID2[16];
    char nilUUID2str[40] = NIL_UUID_STR;
    n_tests++;
    if (uuid_str2bin(nilUUID1str, nilUUID1) < 0)
      {
	fprintf(stderr, "Failure\n");
	goto skip8;
      }
    n_tests++;
    if (uuid_str2bin(nilUUID2str, nilUUID2) < 0)
      {
	fprintf(stderr, "Failure\n");
	goto skip8;
      }
    int8_t cmpval1 = uuid_cmp(nilUUID1, nilUUID2);
    int8_t cmpval2 = uuid_cmp(nilUUID2, nilUUID1);
    if (cmpval1 == cmpval2 && cmpval1 == 0)
      n_tests_passed+=2;
    else
      n_tests_failed+=2;
    printf("%s cmp %s = %d <%s>\n", 
	   nilUUID1str, nilUUID2str, cmpval1, cmpval1 ? "failed" : "passed" );
    printf("%s cmp %s = %d <%s>\n", 
	   nilUUID2str, nilUUID1str, cmpval2, cmpval2 ? "failed" : "passed" );
  }

 skip8:
  {
    /*
     * uuid_cmp with both not nil UUID
     */
    uint8_t notNilUUID1[16];
    char notNilUUID1str[40] = NOT_NIL_UUID_STR;
    uint8_t notNilUUID2[16];
    char notNilUUID2str[40] = NOT_NIL_UUID_STR;
    n_tests++;
    if (uuid_str2bin(notNilUUID1str, notNilUUID1) < 0)
      {
	fprintf(stderr, "Failure\n");
	goto skip9;
      }
    n_tests++;
    if (uuid_str2bin(notNilUUID2str, notNilUUID2) < 0)
      {
	fprintf(stderr, "Failure\n");
	goto skip9;
      }
    int8_t cmpval1 = uuid_cmp(notNilUUID1, notNilUUID2);
    int8_t cmpval2 = uuid_cmp(notNilUUID2, notNilUUID1);
    if (cmpval1 == cmpval2 && cmpval1 == 0)
      n_tests_passed+=2;
    else
      n_tests_failed+=2;
    printf("%s cmp %s = %d <%s>\n", 
	   notNilUUID1str, notNilUUID2str, cmpval1, cmpval1 ? "failed" : "passed" );
    printf("%s cmp %s = %d <%s>\n", 
	   notNilUUID2str, notNilUUID1str, cmpval2, cmpval2 ? "failed" : "passed" );
    
  }

 skip9:
  {
    /*
     * uuid_cmp with both not nil UUID
     */
    uint8_t notNilUUID1[16];
    char notNilUUID1str[40] = NOT_NIL_UUID_STR;
    uint8_t notNilUUID2[16];
    char notNilUUID2str[40] = NOT_NIL_UUID_STR2;
    n_tests++;
    if (uuid_str2bin(notNilUUID1str, notNilUUID1) < 0)
      {
	fprintf(stderr, "Failure\n");
	goto skip10;
      }
    n_tests++;
    if (uuid_str2bin(notNilUUID2str, notNilUUID2) < 0)
      {
	fprintf(stderr, "Failure\n");
	goto skip10;
      }
    int8_t cmpval1 = uuid_cmp(notNilUUID1, notNilUUID2);
    int8_t cmpval2 = uuid_cmp(notNilUUID2, notNilUUID1);
    if (cmpval1 + cmpval2 == 0 && cmpval1 != 0)
      n_tests_passed+=2;
    else
      n_tests_failed+=2;
    printf("%s cmp %s = %d <%s>\n", 
	   notNilUUID1str, notNilUUID2str, cmpval1, cmpval1 ? "passed" : "failed" );
    printf("%s cmp %s = %d <%s>\n", 
	   notNilUUID2str, notNilUUID1str, cmpval2, cmpval2 ? "passed" : "failed" );
    
  }

 skip10:
 summary:
  {
    fprintf(stderr, 
	    "\n\n********************************************************\n"
	    "Number of tests: %d / passed: %d / failed: %d / skipped: %d\n", 
	    n_tests, n_tests_passed, n_tests_failed, 
	    n_tests - (n_tests_passed+n_tests_failed));
  }

  return 0;
}