[klibc] [PATCH] kinit: Split out do-mounts functionality

Mike Waychison mikew at google.com
Thu Jul 28 13:44:19 PDT 2011


If one wants to re-use the root fs mounting logic from kinit, but
perform additional operations on the root fs (like adding new
mountpoints conditionally), one has to currently make the changes
directly to the kinit binary.

In an effort to make the components of kinit reusable, this patch splits
out the root fs mounting code into a new binary, do-mounts.

do-mounts currently takes a list of kernel command line style arguments
via argv and processes them as kinit would.

[ not tested!!! ]

Signed-off-by: Mike Waychison <mikew at google.com>
---
 usr/kinit/Kbuild           |   33 +++++++++++++++++++++------------
 usr/kinit/do_mounts_main.c |   10 ++++++++++
 usr/kinit/fstype/Kbuild    |    6 +++---
 3 files changed, 34 insertions(+), 15 deletions(-)
 create mode 100644 usr/kinit/do_mounts_main.c

diff --git a/usr/kinit/Kbuild b/usr/kinit/Kbuild
index ff1d449..7ba346f 100644
--- a/usr/kinit/Kbuild
+++ b/usr/kinit/Kbuild
@@ -2,25 +2,33 @@
 # Kbuild file for kinit
 #
 
+static-y := kinit do-mounts
+shared-y := kinit.shared do-mounts.shared
+
 # library part of kinit. Is used by programs in sub-directories (resume et al)
 lib-y   := name_to_dev.o devname.o getarg.o
-# use lib for kinit
-kinit-y  := lib.a
+lib-y   += getintfile.o readfile.o xpio.o
 
-kinit-y  += kinit.o do_mounts.o ramdisk_load.o initrd.o
-kinit-y  += getintfile.o readfile.o xpio.o
-kinit-y  += do_mounts_md.o do_mounts_mtd.o nfsroot.o
+do-mounts-bits := do_mounts.o ramdisk_load.o initrd.o
+do-mounts-bits += do_mounts_md.o do_mounts_mtd.o nfsroot.o
+do-mounts-bits += fstype/
+do-mounts-bits += ipconfig/
+do-mounts-bits += nfsmount/
 
-kinit-y  += ipconfig/
-kinit-y  += nfsmount/
+kinit-y  := lib.a
+kinit-y  += $(do-mounts-bits)
+kinit-y  += kinit.o
 kinit-y  += run-init/
-kinit-y  += fstype/
 kinit-y  += resume/
 
-static-y := kinit
-shared-y := kinit.shared
 kinit.shared-y := $(kinit-y)
 
+do-mounts-y := lib.a
+do-mounts-y += $(do-mounts-bits)
+do-mounts-y += do_mounts_main.o
+
+do-mounts.shared-y := $(do-mounts-y)
+
 # Additional include paths files
 KLIBCCFLAGS += -I$(srctree)/$(src)/fstype \
 	       -I$(srctree)/$(src)/ipconfig \
@@ -29,9 +37,10 @@ KLIBCCFLAGS += -I$(srctree)/$(src)/fstype \
  	       -I$(srctree)/$(src)/run-init
 
 # Cleaning
-targets += kinit kinit.g kinit.shared kinit.shared.g
+targets += kinit kinit.g kinit.shared kinit.shared.g \
+	   do-mounts do-mounts.g do-mounts.shared do-mounts.shared.g
 subdir- := fstype ipconfig nfsmount resume run-init
 
 
 # install binary
-install-y := kinit kinit.shared
+install-y := kinit kinit.shared do-mounts do-mounts.shared
diff --git a/usr/kinit/do_mounts_main.c b/usr/kinit/do_mounts_main.c
new file mode 100644
index 0000000..b6a389f
--- /dev/null
+++ b/usr/kinit/do_mounts_main.c
@@ -0,0 +1,10 @@
+#include <stdio.h>
+#include "do_mounts.h"
+
+char *progname;
+
+int main(int argc, char **argv)
+{
+	progname = argv[0];
+	return do_mounts(argc, argv);
+}
diff --git a/usr/kinit/fstype/Kbuild b/usr/kinit/fstype/Kbuild
index 9b20db1..b0444cd 100644
--- a/usr/kinit/fstype/Kbuild
+++ b/usr/kinit/fstype/Kbuild
@@ -6,7 +6,7 @@ static-y := static/fstype
 shared-y := shared/fstype
 
 # common .o files
-objs := main.o fstype.o
+objs := fstype.o
 
 # TODO - do we want a stripped version
 # TODO - do we want the static.g + shared.g directories?
@@ -15,8 +15,8 @@ objs := main.o fstype.o
 lib-y := $(objs)
 
 # .o files used to built executables
-static/fstype-y := $(objs)
-shared/fstype-y := $(objs)
+static/fstype-y := $(objs) main.o
+shared/fstype-y := $(objs) main.o
 
 # Cleaning
 clean-dirs := static shared
-- 
1.7.3.1



More information about the klibc mailing list