#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
#include <sys/cdefs.h>
#ifdef __FBSDID
__FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $");
#endif
#ifdef __RCSID
__RCSID("$NetBSD: unset.c,v 1.16 2025/02/23 20:47:19 christos Exp $");
#endif
#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"
#include "gpt_private.h"
static int cmd_unset(gpt_t, int, char *[]);
static const char *unsethelp[] = {
"-a attribute -i index",
"-a attribute -b startsec",
"-l",
};
const struct gpt_cmd c_unset = {
"unset",
cmd_unset,
unsethelp, __arraycount(unsethelp),
GPT_OPTDEV,
};
#define usage() gpt_usage(NULL, &c_unset)
static int
cmd_unset(gpt_t gpt, int argc, char *argv[])
{
int ch;
unsigned int entry = 0;
uint64_t attributes = 0;
off_t start = 0;
map_t m;
while ((ch = getopt(argc, argv, "a:b:i:l")) != -1) {
switch(ch) {
case 'a':
if (gpt == NULL || gpt_attr_get(gpt, &attributes) == -1)
return usage();
break;
case 'b':
if (gpt == NULL || gpt_human_get(gpt, &start) == -1)
return usage();
break;
case 'i':
if (gpt == NULL || gpt_uint_get(gpt, &entry) == -1)
return usage();
break;
case 'l':
gpt_attr_help("\t");
return 0;
default:
return usage();
}
}
if (start > 0) {
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 (start != m->map_start)
continue;
entry = m->map_index;
break;
}
}
if (gpt == NULL || argc != optind)
return usage();
return gpt_attr_update(gpt, entry, 0, attributes);
}