]> git.ozlabs.org Git - petitboot/blobdiff - discover/grub2/blscfg.c
discover/grub: Reverse BLS entries sorting to match Petitboot's boot order
[petitboot] / discover / grub2 / blscfg.c
index 0f69f7e291060550df492785cf402e83b6ead78f..d20dde20bb9c3a51d6152dc89d21a34117470021 100644 (file)
@@ -162,7 +162,7 @@ static int bls_filter(const struct dirent *ent)
 
 static int bls_sort(const struct dirent **ent_a, const struct dirent **ent_b)
 {
-       return strverscmp((*ent_b)->d_name, (*ent_a)->d_name);
+       return strverscmp((*ent_a)->d_name, (*ent_b)->d_name);
 }
 
 int builtin_blscfg(struct grub2_script *script,
@@ -180,6 +180,7 @@ int builtin_blscfg(struct grub2_script *script,
        struct conf_context *conf;
        struct bls_state *state;
        char *buf, *filename;
+       const char *blsdir;
        int n, len, rc = -1;
 
        conf = talloc_zero(dc, struct conf_context);
@@ -191,12 +192,16 @@ int builtin_blscfg(struct grub2_script *script,
        conf->process_pair = bls_process_pair;
        conf->finish = bls_finish;
 
-       n = parser_scandir(dc, BLS_DIR, &bls_entries, bls_filter, bls_sort);
+       blsdir = script_env_get(script, "blsdir");
+       if (!blsdir)
+               blsdir = BLS_DIR;
+
+       n = parser_scandir(dc, blsdir, &bls_entries, bls_filter, bls_sort);
        if (n <= 0)
                goto err;
 
        while (n--) {
-               filename = talloc_asprintf(dc, BLS_DIR"/%s",
+               filename = talloc_asprintf(dc, "%s/%s", blsdir,
                                           bls_entries[n]->d_name);
                if (!filename)
                        break;