Update for proplib(3) API changes.
This commit is contained in:
parent
b3d9a749d9
commit
d147ce2226
@ -33,7 +33,7 @@
|
|||||||
__FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $");
|
__FBSDID("$FreeBSD: src/sbin/gpt/show.c,v 1.14 2006/06/22 22:22:32 marcel Exp $");
|
||||||
#endif
|
#endif
|
||||||
#ifdef __RCSID
|
#ifdef __RCSID
|
||||||
__RCSID("$NetBSD: backup.c,v 1.18 2017/09/07 10:23:33 christos Exp $");
|
__RCSID("$NetBSD: backup.c,v 1.19 2020/06/07 05:42:25 thorpej Exp $");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <sys/bootblock.h>
|
#include <sys/bootblock.h>
|
||||||
@ -68,79 +68,46 @@ struct gpt_cmd c_backup = {
|
|||||||
|
|
||||||
#define PROP_ERR(x) if (!(x)) goto cleanup
|
#define PROP_ERR(x) if (!(x)) goto cleanup
|
||||||
|
|
||||||
#define prop_uint(a) prop_number_create_unsigned_integer(a)
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
store_mbr(gpt_t gpt, unsigned int i, const struct mbr *mbr,
|
store_mbr(gpt_t gpt, unsigned int i, const struct mbr *mbr,
|
||||||
prop_array_t *mbr_array)
|
prop_array_t *mbr_array)
|
||||||
{
|
{
|
||||||
prop_dictionary_t mbr_dict;
|
prop_dictionary_t mbr_dict;
|
||||||
prop_number_t propnum;
|
|
||||||
const struct mbr_part *par = &mbr->mbr_part[i];
|
const struct mbr_part *par = &mbr->mbr_part[i];
|
||||||
bool rc;
|
|
||||||
|
|
||||||
if (mbr->mbr_part[i].part_typ == MBR_PTYPE_UNUSED)
|
if (mbr->mbr_part[i].part_typ == MBR_PTYPE_UNUSED)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
mbr_dict = prop_dictionary_create();
|
mbr_dict = prop_dictionary_create();
|
||||||
PROP_ERR(mbr_dict);
|
PROP_ERR(mbr_dict);
|
||||||
propnum = prop_number_create_integer(i);
|
PROP_ERR(prop_dictionary_set_uint(mbr_dict, "index", i));
|
||||||
PROP_ERR(propnum);
|
PROP_ERR(prop_dictionary_set_uint(mbr_dict, "flag", par->part_flag));
|
||||||
rc = prop_dictionary_set(mbr_dict, "index", propnum);
|
PROP_ERR(prop_dictionary_set_uint(mbr_dict, "start_head",
|
||||||
PROP_ERR(rc);
|
par->part_shd));
|
||||||
propnum = prop_uint(par->part_flag);
|
PROP_ERR(prop_dictionary_set_uint(mbr_dict, "start_sector",
|
||||||
PROP_ERR(propnum);
|
par->part_ssect));
|
||||||
rc = prop_dictionary_set(mbr_dict, "flag", propnum);
|
PROP_ERR(prop_dictionary_set_uint(mbr_dict, "start_cylinder",
|
||||||
PROP_ERR(rc);
|
par->part_scyl));
|
||||||
propnum = prop_uint(par->part_shd);
|
PROP_ERR(prop_dictionary_set_uint(mbr_dict, "type", par->part_typ));
|
||||||
PROP_ERR(propnum);
|
PROP_ERR(prop_dictionary_set_uint(mbr_dict, "end_head", par->part_ehd));
|
||||||
rc = prop_dictionary_set(mbr_dict, "start_head", propnum);
|
PROP_ERR(prop_dictionary_set_uint(mbr_dict, "end_sector",
|
||||||
PROP_ERR(rc);
|
par->part_esect));
|
||||||
propnum = prop_uint(par->part_ssect);
|
PROP_ERR(prop_dictionary_set_uint(mbr_dict, "end_cylinder",
|
||||||
PROP_ERR(propnum);
|
par->part_ecyl));
|
||||||
rc = prop_dictionary_set(mbr_dict, "start_sector", propnum);
|
PROP_ERR(prop_dictionary_set_uint(mbr_dict, "lba_start_low",
|
||||||
PROP_ERR(rc);
|
le16toh(par->part_start_lo)));
|
||||||
propnum = prop_uint(par->part_scyl);
|
PROP_ERR(prop_dictionary_set_uint(mbr_dict, "lba_start_high",
|
||||||
PROP_ERR(propnum);
|
le16toh(par->part_start_hi)));
|
||||||
rc = prop_dictionary_set(mbr_dict, "start_cylinder", propnum);
|
PROP_ERR(prop_dictionary_set_uint(mbr_dict, "lba_size_low",
|
||||||
PROP_ERR(rc);
|
le16toh(par->part_size_lo)));
|
||||||
propnum = prop_uint(par->part_typ);
|
PROP_ERR(prop_dictionary_set_uint(mbr_dict, "lba_size_high",
|
||||||
PROP_ERR(propnum);
|
le16toh(par->part_size_hi)));
|
||||||
rc = prop_dictionary_set(mbr_dict, "type", propnum);
|
|
||||||
PROP_ERR(rc);
|
|
||||||
propnum = prop_uint(par->part_ehd);
|
|
||||||
PROP_ERR(propnum);
|
|
||||||
rc = prop_dictionary_set(mbr_dict, "end_head", propnum);
|
|
||||||
PROP_ERR(rc);
|
|
||||||
propnum = prop_uint(par->part_esect);
|
|
||||||
PROP_ERR(propnum);
|
|
||||||
rc = prop_dictionary_set(mbr_dict, "end_sector", propnum);
|
|
||||||
PROP_ERR(rc);
|
|
||||||
propnum = prop_uint(par->part_ecyl);
|
|
||||||
PROP_ERR(propnum);
|
|
||||||
rc = prop_dictionary_set(mbr_dict, "end_cylinder", propnum);
|
|
||||||
PROP_ERR(rc);
|
|
||||||
propnum = prop_uint(le16toh(par->part_start_lo));
|
|
||||||
PROP_ERR(propnum);
|
|
||||||
rc = prop_dictionary_set(mbr_dict, "lba_start_low", propnum);
|
|
||||||
PROP_ERR(rc);
|
|
||||||
propnum = prop_uint(le16toh(par->part_start_hi));
|
|
||||||
PROP_ERR(propnum);
|
|
||||||
rc = prop_dictionary_set(mbr_dict, "lba_start_high", propnum);
|
|
||||||
PROP_ERR(rc);
|
|
||||||
propnum = prop_uint(le16toh(par->part_size_lo));
|
|
||||||
PROP_ERR(propnum);
|
|
||||||
rc = prop_dictionary_set(mbr_dict, "lba_size_low", propnum);
|
|
||||||
PROP_ERR(rc);
|
|
||||||
propnum = prop_uint(le16toh(par->part_size_hi));
|
|
||||||
PROP_ERR(propnum);
|
|
||||||
rc = prop_dictionary_set(mbr_dict, "lba_size_high", propnum);
|
|
||||||
if (*mbr_array == NULL) {
|
if (*mbr_array == NULL) {
|
||||||
*mbr_array = prop_array_create();
|
*mbr_array = prop_array_create();
|
||||||
PROP_ERR(*mbr_array);
|
PROP_ERR(*mbr_array);
|
||||||
}
|
}
|
||||||
rc = prop_array_add(*mbr_array, mbr_dict);
|
PROP_ERR(prop_array_add_and_rel(*mbr_array, mbr_dict));
|
||||||
PROP_ERR(rc);
|
|
||||||
return 0;
|
return 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
if (mbr_dict)
|
if (mbr_dict)
|
||||||
@ -152,26 +119,16 @@ cleanup:
|
|||||||
static int
|
static int
|
||||||
store_gpt(gpt_t gpt, const struct gpt_hdr *hdr, prop_dictionary_t *type_dict)
|
store_gpt(gpt_t gpt, const struct gpt_hdr *hdr, prop_dictionary_t *type_dict)
|
||||||
{
|
{
|
||||||
prop_number_t propnum;
|
|
||||||
prop_string_t propstr;
|
|
||||||
char buf[128];
|
char buf[128];
|
||||||
bool rc;
|
|
||||||
|
|
||||||
*type_dict = prop_dictionary_create();
|
*type_dict = prop_dictionary_create();
|
||||||
PROP_ERR(type_dict);
|
PROP_ERR(type_dict);
|
||||||
propnum = prop_uint(le32toh(hdr->hdr_revision));
|
PROP_ERR(prop_dictionary_set_uint(*type_dict, "revision",
|
||||||
PROP_ERR(propnum);
|
le32toh(hdr->hdr_revision)));
|
||||||
rc = prop_dictionary_set(*type_dict, "revision", propnum);
|
|
||||||
PROP_ERR(rc);
|
|
||||||
gpt_uuid_snprintf(buf, sizeof(buf), "%d", hdr->hdr_guid);
|
gpt_uuid_snprintf(buf, sizeof(buf), "%d", hdr->hdr_guid);
|
||||||
propstr = prop_string_create_cstring(buf);
|
PROP_ERR(prop_dictionary_set_string(*type_dict, "guid", buf));
|
||||||
PROP_ERR(propstr);
|
PROP_ERR(prop_dictionary_set_uint(*type_dict, "entries",
|
||||||
rc = prop_dictionary_set(*type_dict, "guid", propstr);
|
le32toh(hdr->hdr_entries)));
|
||||||
PROP_ERR(rc);
|
|
||||||
propnum = prop_number_create_integer(le32toh(hdr->hdr_entries));
|
|
||||||
PROP_ERR(propnum);
|
|
||||||
rc = prop_dictionary_set(*type_dict, "entries", propnum);
|
|
||||||
PROP_ERR(rc);
|
|
||||||
return 0;
|
return 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
if (*type_dict)
|
if (*type_dict)
|
||||||
@ -186,8 +143,6 @@ store_tbl(gpt_t gpt, const map_t m, prop_dictionary_t *type_dict)
|
|||||||
unsigned int i;
|
unsigned int i;
|
||||||
prop_dictionary_t gpt_dict;
|
prop_dictionary_t gpt_dict;
|
||||||
prop_array_t gpt_array;
|
prop_array_t gpt_array;
|
||||||
prop_number_t propnum;
|
|
||||||
prop_string_t propstr;
|
|
||||||
char buf[128];
|
char buf[128];
|
||||||
uint8_t utfbuf[__arraycount(ent->ent_name) * 3 + 1];
|
uint8_t utfbuf[__arraycount(ent->ent_name) * 3 + 1];
|
||||||
bool rc;
|
bool rc;
|
||||||
@ -206,45 +161,28 @@ store_tbl(gpt_t gpt, const map_t m, prop_dictionary_t *type_dict)
|
|||||||
m->map_size * gpt->secsz; i++, ent++) {
|
m->map_size * gpt->secsz; i++, ent++) {
|
||||||
gpt_dict = prop_dictionary_create();
|
gpt_dict = prop_dictionary_create();
|
||||||
PROP_ERR(gpt_dict);
|
PROP_ERR(gpt_dict);
|
||||||
propnum = prop_number_create_integer(i);
|
PROP_ERR(prop_dictionary_set_uint(gpt_dict, "index", i));
|
||||||
PROP_ERR(propnum);
|
|
||||||
rc = prop_dictionary_set(gpt_dict, "index", propnum);
|
|
||||||
PROP_ERR(propnum);
|
|
||||||
gpt_uuid_snprintf(buf, sizeof(buf), "%d", ent->ent_type);
|
gpt_uuid_snprintf(buf, sizeof(buf), "%d", ent->ent_type);
|
||||||
propstr = prop_string_create_cstring(buf);
|
PROP_ERR(prop_dictionary_set_string(gpt_dict, "type", buf));
|
||||||
PROP_ERR(propstr);
|
|
||||||
rc = prop_dictionary_set(gpt_dict, "type", propstr);
|
|
||||||
gpt_uuid_snprintf(buf, sizeof(buf), "%d", ent->ent_guid);
|
gpt_uuid_snprintf(buf, sizeof(buf), "%d", ent->ent_guid);
|
||||||
propstr = prop_string_create_cstring(buf);
|
PROP_ERR(prop_dictionary_set_string(gpt_dict, "guid", buf));
|
||||||
PROP_ERR(propstr);
|
PROP_ERR(prop_dictionary_set_uint64(gpt_dict, "start",
|
||||||
rc = prop_dictionary_set(gpt_dict, "guid", propstr);
|
le64toh(ent->ent_lba_start)));
|
||||||
PROP_ERR(propstr);
|
PROP_ERR(prop_dictionary_set_uint64(gpt_dict, "end",
|
||||||
propnum = prop_uint(le64toh(ent->ent_lba_start));
|
le64toh(ent->ent_lba_end)));
|
||||||
PROP_ERR(propnum);
|
PROP_ERR(prop_dictionary_set_uint64(gpt_dict, "attributes",
|
||||||
rc = prop_dictionary_set(gpt_dict, "start", propnum);
|
le64toh(ent->ent_attr)));
|
||||||
PROP_ERR(rc);
|
|
||||||
propnum = prop_uint(le64toh(ent->ent_lba_end));
|
|
||||||
PROP_ERR(rc);
|
|
||||||
rc = prop_dictionary_set(gpt_dict, "end", propnum);
|
|
||||||
PROP_ERR(rc);
|
|
||||||
propnum = prop_uint(le64toh(ent->ent_attr));
|
|
||||||
PROP_ERR(propnum);
|
|
||||||
rc = prop_dictionary_set(gpt_dict, "attributes", propnum);
|
|
||||||
PROP_ERR(rc);
|
|
||||||
utf16_to_utf8(ent->ent_name, __arraycount(ent->ent_name),
|
utf16_to_utf8(ent->ent_name, __arraycount(ent->ent_name),
|
||||||
utfbuf, __arraycount(utfbuf));
|
utfbuf, __arraycount(utfbuf));
|
||||||
if (utfbuf[0] != '\0') {
|
if (utfbuf[0] != '\0') {
|
||||||
propstr = prop_string_create_cstring((char *)utfbuf);
|
PROP_ERR(prop_dictionary_set_string(gpt_dict, "name",
|
||||||
PROP_ERR(propstr);
|
(char *)utfbuf));
|
||||||
rc = prop_dictionary_set(gpt_dict, "name", propstr);
|
|
||||||
PROP_ERR(rc);
|
|
||||||
}
|
}
|
||||||
rc = prop_array_add(gpt_array, gpt_dict);
|
rc = prop_array_add(gpt_array, gpt_dict);
|
||||||
PROP_ERR(rc);
|
PROP_ERR(rc);
|
||||||
}
|
}
|
||||||
rc = prop_dictionary_set(*type_dict, "gpt_array", gpt_array);
|
rc = prop_dictionary_set_and_rel(*type_dict, "gpt_array", gpt_array);
|
||||||
PROP_ERR(rc);
|
PROP_ERR(rc);
|
||||||
prop_object_release(gpt_array);
|
|
||||||
return 0;
|
return 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
if (*type_dict)
|
if (*type_dict)
|
||||||
@ -262,18 +200,13 @@ backup(gpt_t gpt, const char *outfile)
|
|||||||
unsigned int i;
|
unsigned int i;
|
||||||
prop_dictionary_t props, type_dict;
|
prop_dictionary_t props, type_dict;
|
||||||
prop_array_t mbr_array;
|
prop_array_t mbr_array;
|
||||||
prop_data_t propdata;
|
|
||||||
prop_number_t propnum;
|
|
||||||
char *propext;
|
char *propext;
|
||||||
bool rc;
|
bool rc;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
props = prop_dictionary_create();
|
props = prop_dictionary_create();
|
||||||
PROP_ERR(props);
|
PROP_ERR(props);
|
||||||
propnum = prop_number_create_integer(gpt->secsz);
|
PROP_ERR(prop_dictionary_set_uint(props, "sector_size", gpt->secsz));
|
||||||
PROP_ERR(propnum);
|
|
||||||
rc = prop_dictionary_set(props, "sector_size", propnum);
|
|
||||||
PROP_ERR(rc);
|
|
||||||
m = map_first(gpt);
|
m = map_first(gpt);
|
||||||
while (m != NULL) {
|
while (m != NULL) {
|
||||||
switch (m->map_type) {
|
switch (m->map_type) {
|
||||||
@ -282,40 +215,36 @@ backup(gpt_t gpt, const char *outfile)
|
|||||||
type_dict = prop_dictionary_create();
|
type_dict = prop_dictionary_create();
|
||||||
PROP_ERR(type_dict);
|
PROP_ERR(type_dict);
|
||||||
mbr = m->map_data;
|
mbr = m->map_data;
|
||||||
propdata = prop_data_create_data_nocopy(mbr->mbr_code,
|
PROP_ERR(prop_dictionary_set_data_nocopy(type_dict,
|
||||||
sizeof(mbr->mbr_code));
|
"code", mbr->mbr_code, sizeof(mbr->mbr_code)));
|
||||||
PROP_ERR(propdata);
|
|
||||||
rc = prop_dictionary_set(type_dict, "code", propdata);
|
|
||||||
PROP_ERR(rc);
|
|
||||||
mbr_array = NULL;
|
mbr_array = NULL;
|
||||||
for (i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
if (store_mbr(gpt, i, mbr, &mbr_array) == -1)
|
if (store_mbr(gpt, i, mbr, &mbr_array) == -1)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
if (mbr_array != NULL) {
|
if (mbr_array != NULL) {
|
||||||
rc = prop_dictionary_set(type_dict,
|
rc = prop_dictionary_set_and_rel(type_dict,
|
||||||
"mbr_array", mbr_array);
|
"mbr_array", mbr_array);
|
||||||
PROP_ERR(rc);
|
PROP_ERR(rc);
|
||||||
prop_object_release(mbr_array);
|
|
||||||
}
|
}
|
||||||
rc = prop_dictionary_set(props, "MBR", type_dict);
|
rc = prop_dictionary_set_and_rel(props, "MBR",
|
||||||
|
type_dict);
|
||||||
PROP_ERR(rc);
|
PROP_ERR(rc);
|
||||||
prop_object_release(type_dict);
|
|
||||||
break;
|
break;
|
||||||
case MAP_TYPE_PRI_GPT_HDR:
|
case MAP_TYPE_PRI_GPT_HDR:
|
||||||
if (store_gpt(gpt, m->map_data, &type_dict) == -1)
|
if (store_gpt(gpt, m->map_data, &type_dict) == -1)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
rc = prop_dictionary_set(props, "GPT_HDR", type_dict);
|
rc = prop_dictionary_set_and_rel(props, "GPT_HDR",
|
||||||
|
type_dict);
|
||||||
PROP_ERR(rc);
|
PROP_ERR(rc);
|
||||||
prop_object_release(type_dict);
|
|
||||||
break;
|
break;
|
||||||
case MAP_TYPE_PRI_GPT_TBL:
|
case MAP_TYPE_PRI_GPT_TBL:
|
||||||
if (store_tbl(gpt, m, &type_dict) == -1)
|
if (store_tbl(gpt, m, &type_dict) == -1)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
rc = prop_dictionary_set(props, "GPT_TBL", type_dict);
|
rc = prop_dictionary_set_and_rel(props, "GPT_TBL",
|
||||||
|
type_dict);
|
||||||
PROP_ERR(rc);
|
PROP_ERR(rc);
|
||||||
prop_object_release(type_dict);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
m = m->map_next;
|
m = m->map_next;
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
__FBSDID("$FreeBSD: src/sbin/gpt/create.c,v 1.11 2005/08/31 01:47:19 marcel Exp $");
|
__FBSDID("$FreeBSD: src/sbin/gpt/create.c,v 1.11 2005/08/31 01:47:19 marcel Exp $");
|
||||||
#endif
|
#endif
|
||||||
#ifdef __RCSID
|
#ifdef __RCSID
|
||||||
__RCSID("$NetBSD: restore.c,v 1.19 2020/05/14 08:34:17 msaitoh Exp $");
|
__RCSID("$NetBSD: restore.c,v 1.20 2020/06/07 05:42:25 thorpej Exp $");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -72,53 +72,37 @@ struct gpt_cmd c_restore = {
|
|||||||
return -1; \
|
return -1; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define prop_uint(a) (u_int)prop_number_unsigned_integer_value(a)
|
|
||||||
#define prop_uint16_t(a) (uint16_t)prop_number_unsigned_integer_value(a)
|
|
||||||
#define prop_uint8_t(a) (uint8_t)prop_number_unsigned_integer_value(a)
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
restore_mbr(gpt_t gpt, struct mbr *mbr, prop_dictionary_t mbr_dict, off_t last)
|
restore_mbr(gpt_t gpt, struct mbr *mbr, prop_dictionary_t mbr_dict, off_t last)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
prop_number_t propnum;
|
|
||||||
struct mbr_part *part;
|
struct mbr_part *part;
|
||||||
|
|
||||||
propnum = prop_dictionary_get(mbr_dict, "index");
|
PROP_ERR(prop_dictionary_get_uint(mbr_dict, "index", &i));
|
||||||
PROP_ERR(propnum);
|
|
||||||
|
|
||||||
i = prop_uint(propnum);
|
|
||||||
propnum = prop_dictionary_get(mbr_dict, "flag");
|
|
||||||
PROP_ERR(propnum);
|
|
||||||
part = &mbr->mbr_part[i];
|
part = &mbr->mbr_part[i];
|
||||||
|
|
||||||
part->part_flag = prop_uint8_t(propnum);
|
PROP_ERR(prop_dictionary_get_uint8(mbr_dict, "flag", &part->part_flag));
|
||||||
propnum = prop_dictionary_get(mbr_dict, "start_head");
|
PROP_ERR(prop_dictionary_get_uint8(mbr_dict, "start_head",
|
||||||
PROP_ERR(propnum);
|
&part->part_shd));
|
||||||
part->part_shd = prop_uint8_t(propnum);
|
PROP_ERR(prop_dictionary_get_uint8(mbr_dict, "start_sector",
|
||||||
propnum = prop_dictionary_get(mbr_dict, "start_sector");
|
&part->part_ssect ));
|
||||||
PROP_ERR(propnum);
|
PROP_ERR(prop_dictionary_get_uint8(mbr_dict, "start_cylinder",
|
||||||
part->part_ssect = prop_uint8_t(propnum);
|
&part->part_scyl));
|
||||||
propnum = prop_dictionary_get(mbr_dict, "start_cylinder");
|
PROP_ERR(prop_dictionary_get_uint8(mbr_dict, "type",
|
||||||
PROP_ERR(propnum);
|
&part->part_typ));
|
||||||
part->part_scyl = prop_uint8_t(propnum);
|
PROP_ERR(prop_dictionary_get_uint8(mbr_dict, "end_head",
|
||||||
propnum = prop_dictionary_get(mbr_dict, "type");
|
&part->part_ehd));
|
||||||
PROP_ERR(propnum);
|
PROP_ERR(prop_dictionary_get_uint8(mbr_dict, "end_sector",
|
||||||
part->part_typ = prop_uint8_t(propnum);
|
&part->part_esect));
|
||||||
propnum = prop_dictionary_get(mbr_dict, "end_head");
|
PROP_ERR(prop_dictionary_get_uint8(mbr_dict, "end_cylinder",
|
||||||
PROP_ERR(propnum);
|
&part->part_ecyl));
|
||||||
part->part_ehd = prop_uint8_t(propnum);
|
PROP_ERR(prop_dictionary_get_uint16(mbr_dict, "lba_start_low",
|
||||||
propnum = prop_dictionary_get(mbr_dict, "end_sector");
|
&part->part_start_lo));
|
||||||
PROP_ERR(propnum);
|
part->part_start_lo = htole16(part->part_start_lo);
|
||||||
part->part_esect = prop_uint8_t(propnum);
|
PROP_ERR(prop_dictionary_get_uint16(mbr_dict, "lba_start_high",
|
||||||
propnum = prop_dictionary_get(mbr_dict, "end_cylinder");
|
&part->part_start_hi));
|
||||||
PROP_ERR(propnum);
|
part->part_start_hi = htole16(part->part_start_hi);
|
||||||
part->part_ecyl = prop_uint8_t(propnum);
|
|
||||||
propnum = prop_dictionary_get(mbr_dict, "lba_start_low");
|
|
||||||
PROP_ERR(propnum);
|
|
||||||
part->part_start_lo = htole16(prop_uint16_t(propnum));
|
|
||||||
propnum = prop_dictionary_get(mbr_dict, "lba_start_high");
|
|
||||||
PROP_ERR(propnum);
|
|
||||||
part->part_start_hi = htole16(prop_uint16_t(propnum));
|
|
||||||
/* adjust PMBR size to size of device */
|
/* adjust PMBR size to size of device */
|
||||||
if (part->part_typ == MBR_PTYPE_PMBR) {
|
if (part->part_typ == MBR_PTYPE_PMBR) {
|
||||||
if (last > 0xffffffff) {
|
if (last > 0xffffffff) {
|
||||||
@ -130,12 +114,12 @@ restore_mbr(gpt_t gpt, struct mbr *mbr, prop_dictionary_t mbr_dict, off_t last)
|
|||||||
(uint16_t)(last >> 16));
|
(uint16_t)(last >> 16));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
propnum = prop_dictionary_get(mbr_dict, "lba_size_low");
|
PROP_ERR(prop_dictionary_get_uint16(mbr_dict, "lba_size_low",
|
||||||
PROP_ERR(propnum);
|
&part->part_size_lo));
|
||||||
part->part_size_lo = htole16(prop_uint16_t(propnum));
|
part->part_size_lo = htole16(part->part_size_lo);
|
||||||
propnum = prop_dictionary_get(mbr_dict, "lba_size_high");
|
PROP_ERR(prop_dictionary_get_uint16(mbr_dict, "lba_size_high",
|
||||||
PROP_ERR(propnum);
|
&part->part_size_hi));
|
||||||
part->part_size_hi = htole16(prop_uint16_t(propnum));
|
part->part_size_hi = htole16(part->part_size_hi);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -147,42 +131,33 @@ restore_ent(gpt_t gpt, prop_dictionary_t gpt_dict, void *secbuf, u_int gpt_size,
|
|||||||
unsigned int i;
|
unsigned int i;
|
||||||
struct gpt_ent ent;
|
struct gpt_ent ent;
|
||||||
const char *s;
|
const char *s;
|
||||||
prop_string_t propstr;
|
|
||||||
prop_number_t propnum;
|
|
||||||
|
|
||||||
memset(&ent, 0, sizeof(ent));
|
memset(&ent, 0, sizeof(ent));
|
||||||
propstr = prop_dictionary_get(gpt_dict, "type");
|
PROP_ERR(prop_dictionary_get_string(gpt_dict, "type", &s));
|
||||||
PROP_ERR(propstr);
|
|
||||||
s = prop_string_cstring_nocopy(propstr);
|
|
||||||
if (gpt_uuid_parse(s, ent.ent_type) != 0) {
|
if (gpt_uuid_parse(s, ent.ent_type) != 0) {
|
||||||
gpt_warnx(gpt, "%s: not able to convert to an UUID", s);
|
gpt_warnx(gpt, "%s: not able to convert to an UUID", s);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
propstr = prop_dictionary_get(gpt_dict, "guid");
|
PROP_ERR(prop_dictionary_get_string(gpt_dict, "guid", &s));
|
||||||
PROP_ERR(propstr);
|
|
||||||
s = prop_string_cstring_nocopy(propstr);
|
|
||||||
if (gpt_uuid_parse(s, ent.ent_guid) != 0) {
|
if (gpt_uuid_parse(s, ent.ent_guid) != 0) {
|
||||||
gpt_warnx(gpt, "%s: not able to convert to an UUID", s);
|
gpt_warnx(gpt, "%s: not able to convert to an UUID", s);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
propnum = prop_dictionary_get(gpt_dict, "start");
|
PROP_ERR(prop_dictionary_get_uint64(gpt_dict, "start",
|
||||||
PROP_ERR(propnum);
|
&ent.ent_lba_start));
|
||||||
ent.ent_lba_start = htole64(prop_uint(propnum));
|
ent.ent_lba_start = htole64(ent.ent_lba_start);
|
||||||
propnum = prop_dictionary_get(gpt_dict, "end");
|
PROP_ERR(prop_dictionary_get_uint64(gpt_dict, "end",
|
||||||
PROP_ERR(propnum);
|
&ent.ent_lba_end));
|
||||||
ent.ent_lba_end = htole64(prop_uint(propnum));
|
ent.ent_lba_end = htole64(ent.ent_lba_end);
|
||||||
propnum = prop_dictionary_get(gpt_dict, "attributes");
|
PROP_ERR(prop_dictionary_get_uint64(gpt_dict, "attributes",
|
||||||
PROP_ERR(propnum);
|
&ent.ent_attr));
|
||||||
ent.ent_attr = htole64(prop_uint(propnum));
|
ent.ent_attr = htole64(ent.ent_attr);
|
||||||
propstr = prop_dictionary_get(gpt_dict, "name");
|
|
||||||
if (propstr != NULL) {
|
if (prop_dictionary_get_string(gpt_dict, "name", &s)) {
|
||||||
s = prop_string_cstring_nocopy(propstr);
|
|
||||||
utf8_to_utf16((const uint8_t *)s, ent.ent_name,
|
utf8_to_utf16((const uint8_t *)s, ent.ent_name,
|
||||||
__arraycount(ent.ent_name));
|
__arraycount(ent.ent_name));
|
||||||
}
|
}
|
||||||
propnum = prop_dictionary_get(gpt_dict, "index");
|
PROP_ERR(prop_dictionary_get_uint(gpt_dict, "index", &i));
|
||||||
PROP_ERR(propnum);
|
|
||||||
i = prop_uint(propnum);
|
|
||||||
if (i > entries) {
|
if (i > entries) {
|
||||||
gpt_warnx(gpt, "Entity index out of bounds %u > %u\n",
|
gpt_warnx(gpt, "Entity index out of bounds %u > %u\n",
|
||||||
i, entries);
|
i, entries);
|
||||||
@ -207,7 +182,6 @@ restore(gpt_t gpt, const char *infile, int force)
|
|||||||
prop_data_t propdata;
|
prop_data_t propdata;
|
||||||
prop_array_t mbr_array, gpt_array;
|
prop_array_t mbr_array, gpt_array;
|
||||||
prop_number_t propnum;
|
prop_number_t propnum;
|
||||||
prop_string_t propstr;
|
|
||||||
unsigned int entries;
|
unsigned int entries;
|
||||||
const char *s;
|
const char *s;
|
||||||
void *secbuf = NULL;
|
void *secbuf = NULL;
|
||||||
@ -241,7 +215,7 @@ restore(gpt_t gpt, const char *infile, int force)
|
|||||||
|
|
||||||
propnum = prop_dictionary_get(props, "sector_size");
|
propnum = prop_dictionary_get(props, "sector_size");
|
||||||
PROP_ERR(propnum);
|
PROP_ERR(propnum);
|
||||||
if (!prop_number_equals_integer(propnum, gpt->secsz)) {
|
if (!prop_number_equals_signed(propnum, gpt->secsz)) {
|
||||||
gpt_warnx(gpt, "Sector size does not match backup");
|
gpt_warnx(gpt, "Sector size does not match backup");
|
||||||
prop_object_release(props);
|
prop_object_release(props);
|
||||||
return -1;
|
return -1;
|
||||||
@ -252,23 +226,20 @@ restore(gpt_t gpt, const char *infile, int force)
|
|||||||
|
|
||||||
propnum = prop_dictionary_get(gpt_dict, "revision");
|
propnum = prop_dictionary_get(gpt_dict, "revision");
|
||||||
PROP_ERR(propnum);
|
PROP_ERR(propnum);
|
||||||
if (!prop_number_equals_unsigned_integer(propnum, 0x10000)) {
|
if (!prop_number_equals_unsigned(propnum, 0x10000)) {
|
||||||
gpt_warnx(gpt, "backup is not revision 1.0");
|
gpt_warnx(gpt, "backup is not revision 1.0");
|
||||||
prop_object_release(gpt_dict);
|
prop_object_release(gpt_dict);
|
||||||
prop_object_release(props);
|
prop_object_release(props);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
propnum = prop_dictionary_get(gpt_dict, "entries");
|
PROP_ERR(prop_dictionary_get_uint(gpt_dict, "entries", &entries));
|
||||||
PROP_ERR(propnum);
|
|
||||||
entries = prop_uint(propnum);
|
|
||||||
gpt_size = (u_int)(entries * sizeof(struct gpt_ent) / gpt->secsz);
|
gpt_size = (u_int)(entries * sizeof(struct gpt_ent) / gpt->secsz);
|
||||||
if (gpt_size * sizeof(struct gpt_ent) % gpt->secsz)
|
if (gpt_size * sizeof(struct gpt_ent) % gpt->secsz)
|
||||||
gpt_size++;
|
gpt_size++;
|
||||||
|
|
||||||
propstr = prop_dictionary_get(gpt_dict, "guid");
|
PROP_ERR(prop_dictionary_get_string(gpt_dict, "guid", &s));
|
||||||
PROP_ERR(propstr);
|
|
||||||
s = prop_string_cstring_nocopy(propstr);
|
|
||||||
if (gpt_uuid_parse(s, gpt_guid) != 0) {
|
if (gpt_uuid_parse(s, gpt_guid) != 0) {
|
||||||
gpt_warnx(gpt, "%s: not able to convert to an UUID", s);
|
gpt_warnx(gpt, "%s: not able to convert to an UUID", s);
|
||||||
goto out;
|
goto out;
|
||||||
@ -283,21 +254,17 @@ restore(gpt_t gpt, const char *infile, int force)
|
|||||||
propiter = prop_array_iterator(gpt_array);
|
propiter = prop_array_iterator(gpt_array);
|
||||||
PROP_ERR(propiter);
|
PROP_ERR(propiter);
|
||||||
while ((gpt_dict = prop_object_iterator_next(propiter)) != NULL) {
|
while ((gpt_dict = prop_object_iterator_next(propiter)) != NULL) {
|
||||||
propstr = prop_dictionary_get(gpt_dict, "type");
|
PROP_ERR(prop_dictionary_get_string(gpt_dict, "type", &s));
|
||||||
PROP_ERR(propstr);
|
|
||||||
s = prop_string_cstring_nocopy(propstr);
|
|
||||||
if (gpt_uuid_parse(s, uuid) != 0) {
|
if (gpt_uuid_parse(s, uuid) != 0) {
|
||||||
gpt_warnx(gpt, "%s: not able to convert to an UUID", s);
|
gpt_warnx(gpt, "%s: not able to convert to an UUID", s);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (gpt_uuid_is_nil(uuid))
|
if (gpt_uuid_is_nil(uuid))
|
||||||
continue;
|
continue;
|
||||||
propnum = prop_dictionary_get(gpt_dict, "start");
|
PROP_ERR(prop_dictionary_get_int64(gpt_dict, "start",
|
||||||
PROP_ERR(propnum);
|
&gpe_start));
|
||||||
gpe_start = prop_uint(propnum);
|
PROP_ERR(prop_dictionary_get_int64(gpt_dict, "end",
|
||||||
propnum = prop_dictionary_get(gpt_dict, "end");
|
&gpe_end));
|
||||||
PROP_ERR(propnum);
|
|
||||||
gpe_end = prop_uint(propnum);
|
|
||||||
if (gpe_start < firstdata || gpe_end > lastdata) {
|
if (gpe_start < firstdata || gpe_end > lastdata) {
|
||||||
gpt_warnx(gpt, "Backup GPT doesn't fit");
|
gpt_warnx(gpt, "Backup GPT doesn't fit");
|
||||||
goto out;
|
goto out;
|
||||||
@ -337,7 +304,7 @@ restore(gpt_t gpt, const char *infile, int force)
|
|||||||
PROP_ERR(type_dict);
|
PROP_ERR(type_dict);
|
||||||
propdata = prop_dictionary_get(type_dict, "code");
|
propdata = prop_dictionary_get(type_dict, "code");
|
||||||
PROP_ERR(propdata);
|
PROP_ERR(propdata);
|
||||||
memcpy(mbr->mbr_code, prop_data_data_nocopy(propdata),
|
memcpy(mbr->mbr_code, prop_data_value(propdata),
|
||||||
sizeof(mbr->mbr_code));
|
sizeof(mbr->mbr_code));
|
||||||
mbr_array = prop_dictionary_get(type_dict, "mbr_array");
|
mbr_array = prop_dictionary_get(type_dict, "mbr_array");
|
||||||
PROP_ERR(mbr_array);
|
PROP_ERR(mbr_array);
|
||||||
@ -355,7 +322,7 @@ restore(gpt_t gpt, const char *infile, int force)
|
|||||||
gpt_warn(gpt, "Unable to seek/write MBR");
|
gpt_warn(gpt, "Unable to seek/write MBR");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
propiter = prop_array_iterator(gpt_array);
|
propiter = prop_array_iterator(gpt_array);
|
||||||
PROP_ERR(propiter);
|
PROP_ERR(propiter);
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: main.c,v 1.17 2016/09/05 01:09:57 sevan Exp $ */
|
/* $NetBSD: main.c,v 1.18 2020/06/07 05:49:05 thorpej Exp $ */
|
||||||
|
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 2008 The NetBSD Foundation, Inc.
|
* Copyright (c) 2008 The NetBSD Foundation, Inc.
|
||||||
@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
__RCSID("$NetBSD: main.c,v 1.17 2016/09/05 01:09:57 sevan Exp $");
|
__RCSID("$NetBSD: main.c,v 1.18 2020/06/07 05:49:05 thorpej Exp $");
|
||||||
#endif /* !lint */
|
#endif /* !lint */
|
||||||
|
|
||||||
#include <sys/module.h>
|
#include <sys/module.h>
|
||||||
@ -184,7 +184,6 @@ parse_bool_param(prop_dictionary_t props, const char *name,
|
|||||||
const char *value)
|
const char *value)
|
||||||
{
|
{
|
||||||
bool boolvalue;
|
bool boolvalue;
|
||||||
prop_object_t po;
|
|
||||||
|
|
||||||
assert(name != NULL);
|
assert(name != NULL);
|
||||||
assert(value != NULL);
|
assert(value != NULL);
|
||||||
@ -200,10 +199,8 @@ parse_bool_param(prop_dictionary_t props, const char *name,
|
|||||||
else
|
else
|
||||||
errx(EXIT_FAILURE, "Invalid boolean value `%s'", value);
|
errx(EXIT_FAILURE, "Invalid boolean value `%s'", value);
|
||||||
|
|
||||||
po = prop_bool_create(boolvalue);
|
if (!prop_dictionary_set_bool(props, name, boolvalue))
|
||||||
if (po == NULL)
|
err(EXIT_FAILURE, "prop_dictionary_set_bool");
|
||||||
err(EXIT_FAILURE, "prop_bool_create");
|
|
||||||
prop_dictionary_set(props, name, po);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -211,7 +208,6 @@ parse_int_param(prop_dictionary_t props, const char *name,
|
|||||||
const char *value)
|
const char *value)
|
||||||
{
|
{
|
||||||
int64_t intvalue;
|
int64_t intvalue;
|
||||||
prop_object_t po;
|
|
||||||
|
|
||||||
assert(name != NULL);
|
assert(name != NULL);
|
||||||
assert(value != NULL);
|
assert(value != NULL);
|
||||||
@ -219,10 +215,8 @@ parse_int_param(prop_dictionary_t props, const char *name,
|
|||||||
if (dehumanize_number(value, &intvalue) != 0)
|
if (dehumanize_number(value, &intvalue) != 0)
|
||||||
err(EXIT_FAILURE, "Invalid integer value `%s'", value);
|
err(EXIT_FAILURE, "Invalid integer value `%s'", value);
|
||||||
|
|
||||||
po = prop_number_create_integer(intvalue);
|
if (!prop_dictionary_set_int64(props, name, intvalue))
|
||||||
if (po == NULL)
|
err(EXIT_FAILURE, "prop_dictionary_set_int64");
|
||||||
err(EXIT_FAILURE, "prop_number_create_integer");
|
|
||||||
prop_dictionary_set(props, name, po);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -249,15 +243,12 @@ static void
|
|||||||
parse_string_param(prop_dictionary_t props, const char *name,
|
parse_string_param(prop_dictionary_t props, const char *name,
|
||||||
const char *value)
|
const char *value)
|
||||||
{
|
{
|
||||||
prop_object_t po;
|
|
||||||
|
|
||||||
assert(name != NULL);
|
assert(name != NULL);
|
||||||
assert(value != NULL);
|
assert(value != NULL);
|
||||||
|
|
||||||
po = prop_string_create_cstring(value);
|
if (!prop_dictionary_set_string(props, name, value))
|
||||||
if (po == NULL)
|
err(EXIT_FAILURE, "prop_dictionary_set_string");
|
||||||
err(EXIT_FAILURE, "prop_string_create_cstring");
|
|
||||||
prop_dictionary_set(props, name, po);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -288,7 +279,7 @@ merge_dicts(prop_dictionary_t existing_dict, const prop_dictionary_t new_dict)
|
|||||||
|
|
||||||
while ((props_obj = prop_object_iterator_next(props_iter)) != NULL) {
|
while ((props_obj = prop_object_iterator_next(props_iter)) != NULL) {
|
||||||
props_keysym = (prop_dictionary_keysym_t)props_obj;
|
props_keysym = (prop_dictionary_keysym_t)props_obj;
|
||||||
props_key = prop_dictionary_keysym_cstring_nocopy(props_keysym);
|
props_key = prop_dictionary_keysym_value(props_keysym);
|
||||||
props_obj = prop_dictionary_get_keysym(new_dict, props_keysym);
|
props_obj = prop_dictionary_get_keysym(new_dict, props_keysym);
|
||||||
if ((props_obj == NULL) || !prop_dictionary_set(existing_dict,
|
if ((props_obj == NULL) || !prop_dictionary_set(existing_dict,
|
||||||
props_key, props_obj)) {
|
props_key, props_obj)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user