Home | History | Annotate | Line # | Download | only in gpt
remove.c revision 1.23.12.1
      1        1.1  christos /*-
      2        1.1  christos  * Copyright (c) 2004 Marcel Moolenaar
      3        1.1  christos  * All rights reserved.
      4        1.1  christos  *
      5        1.1  christos  * Redistribution and use in source and binary forms, with or without
      6        1.1  christos  * modification, are permitted provided that the following conditions
      7        1.1  christos  * are met:
      8        1.1  christos  *
      9        1.1  christos  * 1. Redistributions of source code must retain the above copyright
     10        1.1  christos  *    notice, this list of conditions and the following disclaimer.
     11        1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     12        1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     13        1.1  christos  *    documentation and/or other materials provided with the distribution.
     14        1.1  christos  *
     15        1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     16        1.1  christos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     17        1.1  christos  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     18        1.1  christos  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     19        1.1  christos  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     20        1.1  christos  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     21        1.1  christos  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     22        1.1  christos  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23        1.1  christos  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     24        1.1  christos  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25        1.1  christos  */
     26        1.1  christos 
     27       1.14  christos #if HAVE_NBTOOL_CONFIG_H
     28       1.14  christos #include "nbtool_config.h"
     29       1.14  christos #endif
     30       1.14  christos 
     31        1.1  christos #include <sys/cdefs.h>
     32        1.2  christos #ifdef __FBSDID
     33        1.1  christos __FBSDID("$FreeBSD: src/sbin/gpt/remove.c,v 1.10 2006/10/04 18:20:25 marcel Exp $");
     34        1.2  christos #endif
     35        1.2  christos #ifdef __RCSID
     36  1.23.12.1  perseant __RCSID("$NetBSD: remove.c,v 1.23.12.1 2025/08/02 05:55:06 perseant Exp $");
     37        1.2  christos #endif
     38        1.1  christos 
     39        1.1  christos #include <sys/types.h>
     40        1.1  christos 
     41        1.1  christos #include <err.h>
     42        1.1  christos #include <stddef.h>
     43        1.1  christos #include <stdio.h>
     44        1.1  christos #include <stdlib.h>
     45        1.1  christos #include <string.h>
     46        1.1  christos #include <unistd.h>
     47        1.1  christos 
     48        1.1  christos #include "map.h"
     49        1.1  christos #include "gpt.h"
     50       1.18  christos #include "gpt_private.h"
     51        1.1  christos 
     52       1.19  christos static int cmd_remove(gpt_t, int, char *[]);
     53        1.4       riz 
     54       1.19  christos static const char *removehelp[] = {
     55       1.21  christos 	"-a",
     56       1.21  christos 	"[-b blocknr] [-i index] [-L label] [-s sectors] [-t type]",
     57       1.19  christos };
     58       1.19  christos 
     59  1.23.12.1  perseant const struct gpt_cmd c_remove = {
     60       1.19  christos 	"remove",
     61       1.19  christos 	cmd_remove,
     62       1.19  christos 	removehelp, __arraycount(removehelp),
     63       1.22   jnemeth 	GPT_SYNC,
     64       1.19  christos };
     65        1.1  christos 
     66       1.19  christos #define usage() gpt_usage(NULL, &c_remove)
     67        1.1  christos 
     68       1.20  christos static void
     69  1.23.12.1  perseant change(struct gpt_ent *ent, void *v __unused, int backup __unused)
     70        1.1  christos {
     71       1.20  christos 	/* Remove the primary entry by clearing the partition type. */
     72       1.20  christos 	gpt_uuid_copy(ent->ent_type, gpt_uuid_nil);
     73        1.1  christos }
     74        1.1  christos 
     75       1.19  christos static int
     76       1.18  christos cmd_remove(gpt_t gpt, int argc, char *argv[])
     77        1.1  christos {
     78       1.18  christos 	int ch;
     79       1.20  christos 	struct gpt_find find;
     80       1.20  christos 
     81       1.20  christos 	memset(&find, 0, sizeof(find));
     82       1.20  christos 	find.msg = "removed";
     83        1.1  christos 
     84        1.1  christos 	/* Get the remove options */
     85       1.20  christos 	while ((ch = getopt(argc, argv, GPT_FIND)) != -1)
     86       1.20  christos 		if (gpt_add_find(gpt, &find, ch) == -1)
     87       1.19  christos 			return usage();
     88        1.1  christos 
     89       1.18  christos 	if (argc != optind)
     90       1.19  christos 		return usage();
     91        1.1  christos 
     92       1.20  christos 	return gpt_change_ent(gpt, &find, change, NULL);
     93        1.1  christos }
     94