From 366ff957d2900eae6d26ad2f002b735302e7eb41 Mon Sep 17 00:00:00 2001 From: Samuel Mendoza-Jonas Date: Mon, 15 Dec 2014 14:57:35 +1100 Subject: lib: Define autoboot_options, device_type helpers Add the new autoboot_option struct, and helper functions for working with device_type enums. device_type_name() returns exact strings as used by platform code to read/write nvram params, so device_type_display_name() is added for use in user-visible strings. Signed-off-by: Samuel Mendoza-Jonas --- lib/types/types.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 lib/types/types.c (limited to 'lib/types/types.c') diff --git a/lib/types/types.c b/lib/types/types.c new file mode 100644 index 0000000..059e52a --- /dev/null +++ b/lib/types/types.c @@ -0,0 +1,51 @@ +#include +#include +#include + +const char *device_type_display_name(enum device_type type) +{ + switch (type) { + case DEVICE_TYPE_DISK: + return _("Disk"); + case DEVICE_TYPE_OPTICAL: + return _("Optical"); + case DEVICE_TYPE_NETWORK: + return _("Network"); + case DEVICE_TYPE_ANY: + return _("Any"); + case DEVICE_TYPE_UNKNOWN: + default: + return _("Unknown"); + } +} + +const char *device_type_name(enum device_type type) +{ + switch (type) { + case DEVICE_TYPE_DISK: + return "disk"; + case DEVICE_TYPE_OPTICAL: + return "optical"; + case DEVICE_TYPE_NETWORK: + return "network"; + case DEVICE_TYPE_ANY: + return "any"; + case DEVICE_TYPE_UNKNOWN: + default: + return "unknown"; + } +} + +enum device_type find_device_type(const char *str) +{ + if (!strncmp(str, "disk", strlen("disk"))) + return DEVICE_TYPE_DISK; + if (!strncmp(str, "optical", strlen("optical"))) + return DEVICE_TYPE_OPTICAL; + if (!strncmp(str, "network", strlen("network"))) + return DEVICE_TYPE_NETWORK; + if (!strncmp(str, "any", strlen("any"))) + return DEVICE_TYPE_ANY; + + return DEVICE_TYPE_UNKNOWN; +} -- cgit v1.2.1