2006-10-16 02:34:15 +04:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2004 Marcel Moolenaar
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2014-09-30 00:28:57 +04:00
|
|
|
#if HAVE_NBTOOL_CONFIG_H
|
|
|
|
#include "nbtool_config.h"
|
|
|
|
#endif
|
|
|
|
|
2006-10-16 02:34:15 +04:00
|
|
|
#include <sys/cdefs.h>
|
2006-10-16 02:36:29 +04:00
|
|
|
#ifdef __FBSDID
|
2006-10-16 02:34:15 +04:00
|
|
|
__FBSDID("$FreeBSD: src/sbin/gpt/remove.c,v 1.10 2006/10/04 18:20:25 marcel Exp $");
|
2006-10-16 02:36:29 +04:00
|
|
|
#endif
|
|
|
|
#ifdef __RCSID
|
2015-12-03 04:07:28 +03:00
|
|
|
__RCSID("$NetBSD: remove.c,v 1.21 2015/12/03 01:07:28 christos Exp $");
|
2006-10-16 02:36:29 +04:00
|
|
|
#endif
|
2006-10-16 02:34:15 +04:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <err.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "map.h"
|
|
|
|
#include "gpt.h"
|
2015-12-01 12:05:33 +03:00
|
|
|
#include "gpt_private.h"
|
2006-10-16 02:34:15 +04:00
|
|
|
|
2015-12-01 19:32:19 +03:00
|
|
|
static int cmd_remove(gpt_t, int, char *[]);
|
2007-12-19 00:46:45 +03:00
|
|
|
|
2015-12-01 19:32:19 +03:00
|
|
|
static const char *removehelp[] = {
|
2015-12-03 04:07:28 +03:00
|
|
|
"-a",
|
|
|
|
"[-b blocknr] [-i index] [-L label] [-s sectors] [-t type]",
|
2015-12-01 19:32:19 +03:00
|
|
|
};
|
2006-10-16 02:34:15 +04:00
|
|
|
|
2015-12-01 19:32:19 +03:00
|
|
|
struct gpt_cmd c_remove = {
|
|
|
|
"remove",
|
|
|
|
cmd_remove,
|
|
|
|
removehelp, __arraycount(removehelp),
|
|
|
|
0,
|
|
|
|
};
|
|
|
|
|
|
|
|
#define usage() gpt_usage(NULL, &c_remove)
|
2006-10-16 02:34:15 +04:00
|
|
|
|
2015-12-01 22:25:24 +03:00
|
|
|
static void
|
|
|
|
change(struct gpt_ent *ent, void *v)
|
2006-10-16 02:34:15 +04:00
|
|
|
{
|
2015-12-01 22:25:24 +03:00
|
|
|
/* Remove the primary entry by clearing the partition type. */
|
|
|
|
gpt_uuid_copy(ent->ent_type, gpt_uuid_nil);
|
2006-10-16 02:34:15 +04:00
|
|
|
}
|
|
|
|
|
2015-12-01 19:32:19 +03:00
|
|
|
static int
|
2015-12-01 12:05:33 +03:00
|
|
|
cmd_remove(gpt_t gpt, int argc, char *argv[])
|
2006-10-16 02:34:15 +04:00
|
|
|
{
|
2015-12-01 12:05:33 +03:00
|
|
|
int ch;
|
2015-12-01 22:25:24 +03:00
|
|
|
struct gpt_find find;
|
|
|
|
|
|
|
|
memset(&find, 0, sizeof(find));
|
|
|
|
find.msg = "removed";
|
2006-10-16 02:34:15 +04:00
|
|
|
|
|
|
|
/* Get the remove options */
|
2015-12-01 22:25:24 +03:00
|
|
|
while ((ch = getopt(argc, argv, GPT_FIND)) != -1)
|
|
|
|
if (gpt_add_find(gpt, &find, ch) == -1)
|
2015-12-01 19:32:19 +03:00
|
|
|
return usage();
|
2006-10-16 02:34:15 +04:00
|
|
|
|
2015-12-01 12:05:33 +03:00
|
|
|
if (argc != optind)
|
2015-12-01 19:32:19 +03:00
|
|
|
return usage();
|
2006-10-16 02:34:15 +04:00
|
|
|
|
2015-12-01 22:25:24 +03:00
|
|
|
return gpt_change_ent(gpt, &find, change, NULL);
|
2006-10-16 02:34:15 +04:00
|
|
|
}
|