libfstools: extroot: support builtin block
[project/fstools.git] / libfstools / extroot.c
index 2ed9b37..ca38ce1 100644 (file)
 #include <sys/stat.h>
 #include <sys/wait.h>
 
-#include "../fs-state.h"
+#include "libfstools.h"
 
 char const *extroot_prefix = NULL;
 
-static int mount_extroot(void)
+/*
+ * This will execute "block extroot" and make use of mounted extroot or return
+ * an error.
+ */
+int mount_extroot(void)
 {
+       char ldlib_path[32];
        char block_path[32];
        char kmod_loader[64];
        struct stat s;
@@ -34,10 +39,14 @@ static int mount_extroot(void)
        if (!extroot_prefix)
                return -1;
 
+       sprintf(ldlib_path, "%s/lib", extroot_prefix);
        sprintf(block_path, "%s/sbin/block", extroot_prefix);
 
-       if (stat(block_path, &s))
-               return -1;
+       if (stat(block_path, &s)) {
+               sprintf(block_path, "/sbin/block");
+               if (stat(block_path, &s))
+                       return -1;
+       }
 
        sprintf(kmod_loader, "/sbin/kmodloader %s/etc/modules-boot.d/ %s", extroot_prefix, extroot_prefix);
        system(kmod_loader);
@@ -45,6 +54,7 @@ static int mount_extroot(void)
        pid = fork();
        if (!pid) {
                mkdir("/tmp/extroot", 0755);
+               setenv("LD_LIBRARY_PATH", ldlib_path, 1);
                execl(block_path, block_path, "extroot", NULL);
                exit(-1);
        } else if (pid > 0) {
@@ -93,9 +103,3 @@ static int mount_extroot(void)
        }
        return -1;
 }
-
-static struct backend extroot_backend = {
-       .name = "extroot",
-       .mount = mount_extroot,
-};
-BACKEND(extroot_backend);