diff options
author | marcel <marcel@FreeBSD.org> | 2006-06-22 22:05:28 +0000 |
---|---|---|
committer | marcel <marcel@FreeBSD.org> | 2006-06-22 22:05:28 +0000 |
commit | abc600ba4a75d7918d64625ca7168554f70954c3 (patch) | |
tree | 94ab9df66aa5beecf79a7ed903be4215f4dbb8b3 /sbin | |
parent | 4cca3a410b7ece20b78248a1a83fc11b140bb7fd (diff) | |
download | FreeBSD-src-abc600ba4a75d7918d64625ca7168554f70954c3.zip FreeBSD-src-abc600ba4a75d7918d64625ca7168554f70954c3.tar.gz |
Move the duplicated logic of parsing partition types into a new
function called parse_uuid().
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/gpt/add.c | 21 | ||||
-rw-r--r-- | sbin/gpt/gpt.c | 49 | ||||
-rw-r--r-- | sbin/gpt/gpt.h | 1 | ||||
-rw-r--r-- | sbin/gpt/label.c | 21 | ||||
-rw-r--r-- | sbin/gpt/remove.c | 21 |
5 files changed, 56 insertions, 57 deletions
diff --git a/sbin/gpt/add.c b/sbin/gpt/add.c index 3b60720..37c6bc9 100644 --- a/sbin/gpt/add.c +++ b/sbin/gpt/add.c @@ -156,7 +156,6 @@ cmd_add(int argc, char *argv[]) { char *p; int ch, fd; - uint32_t status; /* Get the migrate options */ while ((ch = getopt(argc, argv, "b:i:s:t:")) != -1) { @@ -185,24 +184,8 @@ cmd_add(int argc, char *argv[]) case 't': if (!uuid_is_nil(&type, NULL)) usage_add(); - uuid_from_string(optarg, &type, &status); - if (status != uuid_s_ok) { - if (strcmp(optarg, "efi") == 0) { - uuid_t efi = GPT_ENT_TYPE_EFI; - type = efi; - } else if (strcmp(optarg, "swap") == 0) { - uuid_t sw = GPT_ENT_TYPE_FREEBSD_SWAP; - type = sw; - } else if (strcmp(optarg, "ufs") == 0) { - uuid_t ufs = GPT_ENT_TYPE_FREEBSD_UFS; - type = ufs; - } else if (strcmp(optarg, "linux") == 0 || - strcmp(optarg, "windows") == 0) { - uuid_t m = GPT_ENT_TYPE_MS_BASIC_DATA; - type = m; - } else - usage_add(); - } + if (parse_uuid(optarg, &type) != 0) + usage_add(); break; default: usage_add(); diff --git a/sbin/gpt/gpt.c b/sbin/gpt/gpt.c index 79b2893..569c923 100644 --- a/sbin/gpt/gpt.c +++ b/sbin/gpt/gpt.c @@ -258,6 +258,55 @@ le_uuid_enc(void *buf, uuid_t const *uuid) p[10 + i] = uuid->node[i]; } +int +parse_uuid(const char *s, uuid_t *uuid) +{ + uint32_t status; + + uuid_from_string(s, uuid, &status); + if (status == uuid_s_ok) + return (0); + + switch (*s) { + case 'e': + if (strcmp(optarg, "efi") == 0) { + uuid_t efi = GPT_ENT_TYPE_EFI; + *uuid = efi; + return (0); + } + break; + case 'l': + if (strcmp(optarg, "linux") == 0) { + uuid_t lnx = GPT_ENT_TYPE_MS_BASIC_DATA; + *uuid = lnx; + return (0); + } + break; + case 's': + if (strcmp(optarg, "swap") == 0) { + uuid_t sw = GPT_ENT_TYPE_FREEBSD_SWAP; + *uuid = sw; + return (0); + } + break; + case 'u': + if (strcmp(optarg, "ufs") == 0) { + uuid_t ufs = GPT_ENT_TYPE_FREEBSD_UFS; + *uuid = ufs; + return (0); + } + break; + case 'w': + if (strcmp(optarg, "windows") == 0) { + uuid_t win = GPT_ENT_TYPE_MS_BASIC_DATA; + *uuid = win; + return (0); + } + break; + } + return (EINVAL); +} + void* gpt_read(int fd, off_t lba, size_t count) { diff --git a/sbin/gpt/gpt.h b/sbin/gpt/gpt.h index fc9e2d5..6b1b1a2 100644 --- a/sbin/gpt/gpt.h +++ b/sbin/gpt/gpt.h @@ -36,6 +36,7 @@ void le_uuid_dec(void const *, uuid_t *); void le_uuid_enc(void *, uuid_t const *); +int parse_uuid(const char *, uuid_t *); struct mbr_part { uint8_t part_flag; /* bootstrap flags */ diff --git a/sbin/gpt/label.c b/sbin/gpt/label.c index 59beb35..98cbcc7 100644 --- a/sbin/gpt/label.c +++ b/sbin/gpt/label.c @@ -172,7 +172,6 @@ cmd_label(int argc, char *argv[]) { char *p; int ch, fd; - uint32_t status; /* Get the label options */ while ((ch = getopt(argc, argv, "ab:f:i:l:s:t:")) != -1) { @@ -216,24 +215,8 @@ cmd_label(int argc, char *argv[]) case 't': if (!uuid_is_nil(&type, NULL)) usage_label(); - uuid_from_string(optarg, &type, &status); - if (status != uuid_s_ok) { - if (strcmp(optarg, "efi") == 0) { - uuid_t efi = GPT_ENT_TYPE_EFI; - type = efi; - } else if (strcmp(optarg, "swap") == 0) { - uuid_t sw = GPT_ENT_TYPE_FREEBSD_SWAP; - type = sw; - } else if (strcmp(optarg, "ufs") == 0) { - uuid_t ufs = GPT_ENT_TYPE_FREEBSD_UFS; - type = ufs; - } else if (strcmp(optarg, "linux") == 0 || - strcmp(optarg, "windows") == 0) { - uuid_t m = GPT_ENT_TYPE_MS_BASIC_DATA; - type = m; - } else - usage_label(); - } + if (parse_uuid(optarg, &type) != 0) + usage_label(); break; default: usage_label(); diff --git a/sbin/gpt/remove.c b/sbin/gpt/remove.c index 500dd4d..0515fc1 100644 --- a/sbin/gpt/remove.c +++ b/sbin/gpt/remove.c @@ -143,7 +143,6 @@ cmd_remove(int argc, char *argv[]) { char *p; int ch, fd; - uint32_t status; /* Get the remove options */ while ((ch = getopt(argc, argv, "ab:i:s:t:")) != -1) { @@ -177,24 +176,8 @@ cmd_remove(int argc, char *argv[]) case 't': if (!uuid_is_nil(&type, NULL)) usage_remove(); - uuid_from_string(optarg, &type, &status); - if (status != uuid_s_ok) { - if (strcmp(optarg, "efi") == 0) { - uuid_t efi = GPT_ENT_TYPE_EFI; - type = efi; - } else if (strcmp(optarg, "swap") == 0) { - uuid_t sw = GPT_ENT_TYPE_FREEBSD_SWAP; - type = sw; - } else if (strcmp(optarg, "ufs") == 0) { - uuid_t ufs = GPT_ENT_TYPE_FREEBSD_UFS; - type = ufs; - } else if (strcmp(optarg, "linux") == 0 || - strcmp(optarg, "windows") == 0) { - uuid_t m = GPT_ENT_TYPE_MS_BASIC_DATA; - type = m; - } else - usage_remove(); - } + if (parse_uuid(optarg, &type) != 0) + usage_remove(); break; default: usage_remove(); |