]> git.ozlabs.org Git - petitboot/commitdiff
lib: Define autoboot_options, device_type helpers
authorSamuel Mendoza-Jonas <sam.mj@au1.ibm.com>
Mon, 15 Dec 2014 03:57:35 +0000 (14:57 +1100)
committerSamuel Mendoza-Jonas <sam.mj@au1.ibm.com>
Tue, 5 May 2015 05:02:43 +0000 (15:02 +1000)
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 <sam.mj@au1.ibm.com>
discover/platform.c
lib/Makefile.am
lib/types/types.c [new file with mode: 0644]
lib/types/types.h

index 04798ac8a4912e12e1f81a601f4eaaae8b1012c5..445158991fcef7cfc2b2846b0154d7bb45f97625 100644 (file)
@@ -17,23 +17,6 @@ static struct config *config;
 
 static const char *kernel_cmdline_debug = "petitboot.debug";
 
-static 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";
-       }
-}
-
 static void dump_config(struct config *config)
 {
        unsigned int i;
index fbf2ee2db9371b64dc49a5fefb32b1741dbb4978..b39cc9bebef9f0bd5e9a3ae43dc739441394ce11 100644 (file)
@@ -38,6 +38,7 @@ lib_libpbcore_la_SOURCES = \
        lib/pb-config/pb-config.h \
        lib/process/process.c \
        lib/process/process.h \
+       lib/types/types.c \
        lib/types/types.h \
        lib/talloc/talloc.c \
        lib/talloc/talloc.h \
diff --git a/lib/types/types.c b/lib/types/types.c
new file mode 100644 (file)
index 0000000..059e52a
--- /dev/null
@@ -0,0 +1,51 @@
+#include <string.h>
+#include <types/types.h>
+#include <i18n/i18n.h>
+
+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;
+}
index f543b7f7ea3295d39a91783897663152e5350f5d..e22dbc307d478389047ad32de52076c57ad955b7 100644 (file)
@@ -13,6 +13,10 @@ enum device_type {
        DEVICE_TYPE_UNKNOWN,
 };
 
+const char *device_type_display_name(enum device_type type);
+const char *device_type_name(enum device_type type);
+enum device_type find_device_type(const char *str);
+
 struct device {
        char            *id;
        enum device_type type;
@@ -118,6 +122,17 @@ struct boot_priority {
        enum device_type        type;
 };
 
+struct autoboot_option {
+       enum {
+               BOOT_DEVICE_TYPE,
+               BOOT_DEVICE_UUID
+       } boot_type;
+       union {
+               enum device_type        type;
+               char                    *uuid;
+       };
+};
+
 struct config {
        bool                    autoboot_enabled;
        unsigned int            autoboot_timeout_sec;