diff options
author | Geoff Levand <geoff@infradead.org> | 2012-03-16 22:06:03 -0700 |
---|---|---|
committer | Geoff Levand <geoff@infradead.org> | 2012-03-16 22:16:41 -0700 |
commit | 7c5e552c210b38a06ed9fbb99418b62e20978666 (patch) | |
tree | d8973628338cb604eb3032c7b6d36daca70d8435 | |
parent | 54f94570b65095c5b9251981956102d3f2864f90 (diff) | |
download | talos-petitboot-7c5e552c210b38a06ed9fbb99418b62e20978666.tar.gz talos-petitboot-7c5e552c210b38a06ed9fbb99418b62e20978666.zip |
Use static array for parsers
Change the parser structure array implementation from using an
array in a seperate parsers section to a static array of pointers
in parser.c. Parser priority is now set by the position in the
new parsers array.
Signed-off-by: Geoff Levand <geoff@infradead.org>
-rw-r--r-- | discover/kboot-parser.c | 2 | ||||
-rw-r--r-- | discover/native-parser.c | 2 | ||||
-rw-r--r-- | discover/parser-utils.h | 5 | ||||
-rw-r--r-- | discover/parser.c | 36 | ||||
-rw-r--r-- | discover/yaboot-parser.c | 2 |
5 files changed, 19 insertions, 28 deletions
diff --git a/discover/kboot-parser.c b/discover/kboot-parser.c index 429ae09..025f13b 100644 --- a/discover/kboot-parser.c +++ b/discover/kboot-parser.c @@ -153,4 +153,4 @@ static int kboot_parse(struct discover_context *dc) return rc; } -define_parser(kboot, 98, kboot_parse); +define_parser(kboot, kboot_parse); diff --git a/discover/native-parser.c b/discover/native-parser.c index a8429ec..08309d1 100644 --- a/discover/native-parser.c +++ b/discover/native-parser.c @@ -128,4 +128,4 @@ static int native_parse(const char *device) return 1; } -define_parser(native, 100, native_parse); +define_parser(native, native_parse); diff --git a/discover/parser-utils.h b/discover/parser-utils.h index 781867c..fe28b7b 100644 --- a/discover/parser-utils.h +++ b/discover/parser-utils.h @@ -8,16 +8,13 @@ #define artwork_pathname(file) (PKG_SHARE_DIR "/artwork/" file) -#define define_parser(__name, __priority, __parse_fn) \ +#define define_parser(__name, __parse_fn) \ struct parser \ - __attribute__((unused, section("parsers"))) \ __ ## __name ## _parser = { \ .name = #__name, \ - .priority = __priority, \ .parse = __parse_fn, \ }; - void device_add_boot_option(struct device *device, struct boot_option *boot_option); diff --git a/discover/parser.c b/discover/parser.c index 8f2735c..c106dec 100644 --- a/discover/parser.c +++ b/discover/parser.c @@ -8,39 +8,33 @@ #include "parser.h" #include "parser-utils.h" -extern struct parser __start_parsers[], __stop_parsers[]; +struct parser __native_parser; +struct parser __yaboot_parser; +struct parser __kboot_parser; +struct parser __grub2_parser; + +static const struct parser *const parsers[] = { +// &__native_parser, + &__yaboot_parser, + &__kboot_parser, + NULL +}; void iterate_parsers(struct discover_context *ctx) { - struct parser *parser; + int i; unsigned int count = 0; pb_log("trying parsers for %s\n", ctx->device_path); - for (parser = __start_parsers; parser < __stop_parsers; parser++) { - pb_log("\ttrying parser '%s'\n", parser->name); - count += parser->parse(ctx); + for (i = 0; parsers[i]; i++) { + pb_log("\ttrying parser '%s'\n", parsers[i]->name); + count += parsers[i]->parse(ctx); } if (!count) pb_log("\tno boot_options found\n"); } -static int compare_parsers(const void *a, const void *b) -{ - const struct parser *parser_a = a, *parser_b = b; - - if (parser_a->priority > parser_b->priority) - return -1; - - if (parser_a->priority < parser_b->priority) - return 1; - - return 0; -} - void parser_init(void) { - /* sort our parsers into descending priority order */ - qsort(__start_parsers, __stop_parsers - __start_parsers, - sizeof(struct parser), compare_parsers); } diff --git a/discover/yaboot-parser.c b/discover/yaboot-parser.c index 6101cd8..ace9945 100644 --- a/discover/yaboot-parser.c +++ b/discover/yaboot-parser.c @@ -318,4 +318,4 @@ static int yaboot_parse(struct discover_context *dc) return rc; } -define_parser(yaboot, 99, yaboot_parse); +define_parser(yaboot, yaboot_parse); |