Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sbin/gpt/remove.c,v rcsdiff: /ftp/cvs/cvsroot/src/sbin/gpt/remove.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.19 retrieving revision 1.20 diff -u -p -r1.19 -r1.20 --- src/sbin/gpt/remove.c 2015/12/01 16:32:19 1.19 +++ src/sbin/gpt/remove.c 2015/12/01 19:25:24 1.20 @@ -33,7 +33,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.19 2015/12/01 16:32:19 christos Exp $"); +__RCSID("$NetBSD: remove.c,v 1.20 2015/12/01 19:25:24 christos Exp $"); #endif #include @@ -49,12 +49,6 @@ __RCSID("$NetBSD: remove.c,v 1.19 2015/1 #include "gpt.h" #include "gpt_private.h" -static int all; -static gpt_uuid_t type; -static off_t block, size; -static unsigned int entry; -static uint8_t *label; - static int cmd_remove(gpt_t, int, char *[]); static const char *removehelp[] = { @@ -71,119 +65,29 @@ struct gpt_cmd c_remove = { #define usage() gpt_usage(NULL, &c_remove) -static int -rem(gpt_t gpt) +static void +change(struct gpt_ent *ent, void *v) { - map_t m; - struct gpt_ent *ent; - unsigned int i; - - if (gpt_hdr(gpt) == NULL) - return -1; - - /* Remove all matching entries in the map. */ - for (m = map_first(gpt); 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; - - ent = gpt_ent_primary(gpt, i); - - if (label != NULL) - if (strcmp((char *)label, - (char *)utf16_to_utf8(ent->ent_name)) != 0) - continue; - - if (!gpt_uuid_is_nil(type) && - !gpt_uuid_equal(type, ent->ent_type)) - continue; - - /* Remove the primary entry by clearing the partition type. */ - gpt_uuid_copy(ent->ent_type, gpt_uuid_nil); - - if (gpt_write_primary(gpt) == -1) - return -1; - - ent = gpt_ent_backup(gpt, i); - - /* Remove the secondary entry. */ - gpt_uuid_copy(ent->ent_type, gpt_uuid_nil); - - if (gpt_write_backup(gpt) == -1) - return -1; - gpt_msg(gpt, "partition %d removed", m->map_index); - } - return 0; + /* Remove the primary entry by clearing the partition type. */ + gpt_uuid_copy(ent->ent_type, gpt_uuid_nil); } static int cmd_remove(gpt_t gpt, int argc, char *argv[]) { - char *p; int ch; - int64_t human_num; + struct gpt_find find; + + memset(&find, 0, sizeof(find)); + find.msg = "removed"; /* Get the remove options */ - while ((ch = getopt(argc, argv, "ab:i:L:s:t:")) != -1) { - switch(ch) { - case 'a': - if (all > 0) - return usage(); - all = 1; - break; - case 'b': - if (block > 0) - return usage(); - if (dehumanize_number(optarg, &human_num) < 0) - return usage(); - block = human_num; - if (block < 1) - return usage(); - break; - case 'i': - if (entry > 0) - return usage(); - entry = strtoul(optarg, &p, 10); - if (*p != 0 || entry < 1) - return usage(); - break; - case 'L': - if (label != NULL) - return usage(); - label = (uint8_t *)strdup(optarg); - break; - case 's': - if (size > 0) - usage(); - size = strtoll(optarg, &p, 10); - if (*p != 0 || size < 1) - return usage(); - break; - case 't': - if (!gpt_uuid_is_nil(type)) - return usage(); - if (gpt_uuid_parse(optarg, type) != 0) - return usage(); - break; - default: + while ((ch = getopt(argc, argv, GPT_FIND)) != -1) + if (gpt_add_find(gpt, &find, ch) == -1) return usage(); - } - } - - if (!all ^ - (block > 0 || entry > 0 || label != NULL || size > 0 || - !gpt_uuid_is_nil(type))) - return usage(); if (argc != optind) return usage(); - return rem(gpt); + return gpt_change_ent(gpt, &find, change, NULL); }