- distinguish between the device name (what the user called it on the
command line) and the device path (what we passed to open()). Use the former in diagnostics. - when adding or removing partitions, print a single line to stdout for each partition that was added or removed, indicating its name. - add an -a option to 'gpt remove' which must be explicitly specified to remove all partitions. Approved by: marcel (in prinicple) MFC after: 2 weeks
This commit is contained in:
parent
90d5800df2
commit
8a399540fa
@ -147,6 +147,8 @@ add(int fd)
|
||||
|
||||
gpt_write(fd, lbt);
|
||||
gpt_write(fd, tpg);
|
||||
|
||||
printf("%sp%u added\n", device_name, i + 1);
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -206,6 +206,11 @@ the GPT equivalent of a slice.
|
||||
.It Xo
|
||||
.Nm
|
||||
.Ic remove
|
||||
.Op Fl a
|
||||
.Xc
|
||||
.It Xo
|
||||
.Nm
|
||||
.Ic remove
|
||||
.Op Fl b Ar number
|
||||
.Op Fl i Ar index
|
||||
.Op Fl s Ar count
|
||||
@ -215,8 +220,12 @@ the GPT equivalent of a slice.
|
||||
The
|
||||
.Ic remove
|
||||
command allows the user to remove any partitions that match the selection.
|
||||
BEWARE: when no options are given, all GPT partitions will match and thus
|
||||
will be deleted.
|
||||
At least one option must be specified.
|
||||
.Pp
|
||||
The
|
||||
.Fl a
|
||||
option specifies that all partitions should be removed.
|
||||
It is mutually exclusive with all other options.
|
||||
.Pp
|
||||
The
|
||||
.Fl b Ar number
|
||||
|
@ -37,6 +37,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <paths.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -46,7 +47,8 @@ __FBSDID("$FreeBSD$");
|
||||
#include "map.h"
|
||||
#include "gpt.h"
|
||||
|
||||
char device_name[MAXPATHLEN];
|
||||
char device_path[MAXPATHLEN];
|
||||
char *device_name;
|
||||
|
||||
off_t mediasz;
|
||||
|
||||
@ -374,24 +376,26 @@ int
|
||||
gpt_open(const char *dev)
|
||||
{
|
||||
struct stat sb;
|
||||
int fd;
|
||||
int fd, mode;
|
||||
|
||||
if (!stat(dev, &sb)) {
|
||||
strlcpy(device_name, dev, sizeof(device_name));
|
||||
goto found;
|
||||
}
|
||||
mode = readonly ? O_RDONLY : O_RDWR|O_EXCL;
|
||||
|
||||
snprintf(device_name, sizeof(device_name), "/dev/%s", dev);
|
||||
if (!stat(device_name, &sb))
|
||||
strlcpy(device_path, dev, sizeof(device_path));
|
||||
device_name = device_path;
|
||||
|
||||
if ((fd = open(device_path, mode)) != -1)
|
||||
goto found;
|
||||
|
||||
snprintf(device_path, sizeof(device_path), "%s%s", _PATH_DEV, dev);
|
||||
device_name = device_path + strlen(_PATH_DEV);
|
||||
if ((fd = open(device_path, mode)) != -1)
|
||||
goto found;
|
||||
|
||||
strlcpy(device_name, dev, sizeof(device_name));
|
||||
return (-1);
|
||||
|
||||
found:
|
||||
fd = open(device_name, (readonly) ? O_RDONLY : O_RDWR|O_EXCL);
|
||||
if (fd == -1)
|
||||
return (-1);
|
||||
if (fstat(fd, &sb) == -1)
|
||||
goto close;
|
||||
|
||||
if ((sb.st_mode & S_IFMT) != S_IFREG) {
|
||||
if (ioctl(fd, DIOCGSECTORSIZE, &secsz) == -1 ||
|
||||
|
@ -59,7 +59,7 @@ struct mbr {
|
||||
#define MBR_SIG 0xAA55
|
||||
};
|
||||
|
||||
extern char device_name[];
|
||||
extern char *device_name;
|
||||
extern off_t mediasz;
|
||||
extern u_int parts;
|
||||
extern u_int secsz;
|
||||
|
@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include "map.h"
|
||||
#include "gpt.h"
|
||||
|
||||
static int all;
|
||||
static uuid_t type;
|
||||
static off_t block, size;
|
||||
static unsigned int entry;
|
||||
@ -48,8 +49,9 @@ usage_remove(void)
|
||||
{
|
||||
|
||||
fprintf(stderr,
|
||||
"usage: %s [-b lba] [-i index] [-s lba] [-t uuid] device\n",
|
||||
getprogname());
|
||||
"usage: %s -a device\n"
|
||||
" %s [-b lba] [-i index] [-s lba] [-t uuid] device\n",
|
||||
getprogname(), getprogname());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@ -130,6 +132,8 @@ rem(int fd)
|
||||
gpt_write(fd, lbt);
|
||||
gpt_write(fd, tpg);
|
||||
|
||||
printf("%sp%u removed\n", device_name, m->map_index);
|
||||
|
||||
removed++;
|
||||
}
|
||||
|
||||
@ -144,8 +148,13 @@ cmd_remove(int argc, char *argv[])
|
||||
uint32_t status;
|
||||
|
||||
/* Get the remove options */
|
||||
while ((ch = getopt(argc, argv, "b:i:s:t:")) != -1) {
|
||||
while ((ch = getopt(argc, argv, "ab:i:s:t:")) != -1) {
|
||||
switch(ch) {
|
||||
case 'a':
|
||||
if (all > 0)
|
||||
usage_remove();
|
||||
all = 1;
|
||||
break;
|
||||
case 'b':
|
||||
if (block > 0)
|
||||
usage_remove();
|
||||
@ -194,6 +203,10 @@ cmd_remove(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
if (!all ^
|
||||
(block > 0 || entry > 0 || size > 0 || !uuid_is_nil(&type, NULL)))
|
||||
usage_remove();
|
||||
|
||||
if (argc == optind)
|
||||
usage_remove();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user