Move the duplicated logic of parsing partition types into a new
function called parse_uuid().
This commit is contained in:
parent
1fca3e7045
commit
ba0e2f9971
@ -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();
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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 */
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user