diff options
author | des <des@FreeBSD.org> | 2005-04-24 20:08:29 +0000 |
---|---|---|
committer | des <des@FreeBSD.org> | 2005-04-24 20:08:29 +0000 |
commit | e669069b43c7e2eed5fff4775fd3c6c18283165d (patch) | |
tree | dbcede987d92edb2ff66ad74e2a604408a2dd44c /sbin | |
parent | 00d3abec3bb9c46bd452d05af3fe8c1919d14992 (diff) | |
download | FreeBSD-src-e669069b43c7e2eed5fff4775fd3c6c18283165d.zip FreeBSD-src-e669069b43c7e2eed5fff4775fd3c6c18283165d.tar.gz |
- 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
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/gpt/add.c | 2 | ||||
-rw-r--r-- | sbin/gpt/gpt.8 | 13 | ||||
-rw-r--r-- | sbin/gpt/gpt.c | 26 | ||||
-rw-r--r-- | sbin/gpt/gpt.h | 2 | ||||
-rw-r--r-- | sbin/gpt/remove.c | 19 |
5 files changed, 45 insertions, 17 deletions
diff --git a/sbin/gpt/add.c b/sbin/gpt/add.c index 195f6ad..0bba7f9 100644 --- a/sbin/gpt/add.c +++ b/sbin/gpt/add.c @@ -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 diff --git a/sbin/gpt/gpt.8 b/sbin/gpt/gpt.8 index 8b85a6a..a6f444b 100644 --- a/sbin/gpt/gpt.8 +++ b/sbin/gpt/gpt.8 @@ -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 diff --git a/sbin/gpt/gpt.c b/sbin/gpt/gpt.c index a4d5685..23a36be 100644 --- a/sbin/gpt/gpt.c +++ b/sbin/gpt/gpt.c @@ -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)); + mode = readonly ? O_RDONLY : O_RDWR|O_EXCL; + + strlcpy(device_path, dev, sizeof(device_path)); + device_name = device_path; + + if ((fd = open(device_path, mode)) != -1) goto found; - } - snprintf(device_name, sizeof(device_name), "/dev/%s", dev); - if (!stat(device_name, &sb)) + 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 || diff --git a/sbin/gpt/gpt.h b/sbin/gpt/gpt.h index edbb082..b6a4c80 100644 --- a/sbin/gpt/gpt.h +++ b/sbin/gpt/gpt.h @@ -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; diff --git a/sbin/gpt/remove.c b/sbin/gpt/remove.c index 42e1128..9949d00 100644 --- a/sbin/gpt/remove.c +++ b/sbin/gpt/remove.c @@ -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(); |