static void _uuuid_create(struct uuuid_t** uuuid, int* status, int nil) { struct uuuid_t* u; uint32_t st; u = uuuid_new(); if (!u) { *status = UUUID_ERR; return; } if (nil) uuid_create_nil(&u->uuid, &st); else uuid_create(&u->uuid, &st); if (st != uuid_s_ok) { uuuid_free(u); *status = UUUID_ERR; return; } *uuuid = u; *status = UUUID_OK; }
/* * uuid_to_string() - Convert a binary UUID into a string representation. * See also: * http://www.opengroup.org/onlinepubs/009629399/uuid_to_string.htm * * NOTE: The references given above do not have a status code for when * the string could not be allocated. The status code has been * taken from the Hewlett-Packard implementation. */ void uuid_to_string(const uuid_t *u, char **s, uint32_t *status) { uuid_t nil; if (status != NULL) *status = uuid_s_ok; /* Why allow a NULL-pointer here? */ if (s == NULL) return; if (u == NULL) { u = &nil; uuid_create_nil(&nil, NULL); } asprintf(s, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", u->time_low, u->time_mid, u->time_hi_and_version, u->clock_seq_hi_and_reserved, u->clock_seq_low, u->node[0], u->node[1], u->node[2], u->node[3], u->node[4], u->node[5]); if (*s == NULL && status != NULL) *status = uuid_s_no_memory; }
/* * uuid_from_string() - convert a string representation of an UUID into * a binary representation. * See also: * http://www.opengroup.org/onlinepubs/009629399/uuid_from_string.htm * * NOTE: The sequence field is in big-endian, while the time fields are in * native byte order. */ void uuid_from_string(const char *s, uuid_t *u, uint32_t *status) { int n; /* Short-circuit 2 special cases: NULL pointer and empty string. */ if (s == NULL || *s == '\0') { uuid_create_nil(u, status); return; } /* Assume the worst. */ if (status != NULL) *status = uuid_s_invalid_string_uuid; /* The UUID string representation has a fixed length. */ if (strlen(s) != 36) return; /* * We only work with "new" UUIDs. New UUIDs have the form: * 01234567-89ab-cdef-0123-456789abcdef * The so called "old" UUIDs, which we don't support, have the form: * 0123456789ab.cd.ef.01.23.45.67.89.ab */ if (s[8] != '-') return; n = sscanf(s, "%8x-%4hx-%4hx-%2hhx%2hhx-%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx", &u->time_low, &u->time_mid, &u->time_hi_and_version, &u->clock_seq_hi_and_reserved, &u->clock_seq_low, &u->node[0], &u->node[1], &u->node[2], &u->node[3], &u->node[4], &u->node[5]); /* Make sure we have all conversions. */ if (n != 11) return; /* We have a successful scan. Check semantics... */ n = u->clock_seq_hi_and_reserved; if ((n & 0x80) != 0x00 && /* variant 0? */ (n & 0xc0) != 0x80 && /* variant 1? */ (n & 0xe0) != 0xc0) { /* variant 2? */ if (status != NULL) *status = uuid_s_bad_version; } else { if (status != NULL) *status = uuid_s_ok; } }
/* * uuid_from_string() - convert a string representation of an UUID into * a binary representation. * See also: * http://www.opengroup.org/onlinepubs/009629399/uuid_from_string.htm * * NOTE: The sequence field is in big-endian, while the time fields are in * native byte order. * * 01234567-89ab-cdef-0123-456789abcdef * 000000000011111111112222222222333333 * 012345678901234567890123456789012345 * - - - - * hhhhhhhh-hhhh-hhhh-bbbb-bbbbbbbbbbbb * */ void uuid_from_string(const char *s, uuid_t *u, uint32_t *status) { int ok = 1; int n; if (s == NULL || *s == '\0') { uuid_create_nil(u, status); return; } if (status != NULL) *status = uuid_s_invalid_string_uuid; if (strlen(s) != 36) return; /* Only support new format, check for all the right dashes */ if (s[8] != '-' || s[13] != '-' || s[18] != '-' || s[23] != '-') return; /* native byte order */ u->time_low = fromhex(s , 8, &ok); u->time_mid = fromhex(s + 9, 4, &ok); u->time_hi_and_version = fromhex(s + 14, 4, &ok); /* Big endian, but presented as a whole number so decode as such */ u->clock_seq_hi_and_reserved = fromhex(s + 19, 2, &ok); u->clock_seq_low = fromhex(s + 21, 2, &ok); u->node[0] = fromhex(s + 24, 2, &ok); u->node[1] = fromhex(s + 26, 2, &ok); u->node[2] = fromhex(s + 28, 2, &ok); u->node[3] = fromhex(s + 30, 2, &ok); u->node[4] = fromhex(s + 32, 2, &ok); u->node[5] = fromhex(s + 34, 2, &ok); if (!ok) return; /* We have a successful scan. Check semantics... */ n = u->clock_seq_hi_and_reserved; if ((n & 0x80) != 0x00 && /* variant 0? */ (n & 0xc0) != 0x80 && /* variant 1? */ (n & 0xe0) != 0xc0) { /* variant 2? */ if (status != NULL) *status = uuid_s_bad_version; } else { if (status != NULL) *status = uuid_s_ok; } }
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); }
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"); } }
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); } }