Extend make_ext4fs() interface to allow callers to pass selabel_handle.

Extend make_ext4fs() to allow callers to pass an selabel_handle for
labeling files in the ext4 image.  Previously, this was only done
via the _internal() function.  This extends the library interface
so that it can be used by the recovery and updater code for labeling
files from OTA and update packages.

Change-Id: I4f6755fe7c65b69587276d17ef5b971ebec0161f
diff --git a/ext4_utils/make_ext4fs.c b/ext4_utils/make_ext4fs.c
index 26068e6..af05eb3 100644
--- a/ext4_utils/make_ext4fs.c
+++ b/ext4_utils/make_ext4fs.c
@@ -266,15 +266,17 @@
     free_data_blocks();
 }
 
-int make_ext4fs(const char *filename, s64 len)
+int make_ext4fs(const char *filename, s64 len,
+                const char *mountpoint, struct selabel_handle *sehnd)
 {
     reset_ext4fs_info();
     info.len = len;
-    return make_ext4fs_internal(filename, NULL, NULL, 0, 0, 0, 0, 1, 0, 0);
+    return make_ext4fs_internal(filename, NULL, mountpoint, 0, 0, 0, 0, 1, 0, sehnd);
 }
 
 int make_ext4fs_internal(const char *filename, const char *directory,
-                         char *mountpoint, int android, int gzip, int sparse,
+                         const char *mountpoint,
+                         int android, int gzip, int sparse,
                          int crc, int wipe, int init_itabs,
                          struct selabel_handle *sehnd)
 {
@@ -374,7 +376,13 @@
 	if (sehnd) {
 		char *sepath = NULL;
 		char *secontext = NULL;
-		asprintf(&sepath, "/%s", mountpoint);
+
+		if (mountpoint[0] == '/')
+			sepath = strdup(mountpoint);
+		else
+			asprintf(&sepath, "/%s", mountpoint);
+		if (!sepath)
+			critical_error_errno("malloc");
 		if (selabel_lookup(sehnd, &secontext, sepath, S_IFDIR) < 0) {
 			error("cannot lookup security context for %s", sepath);
 		}
diff --git a/ext4_utils/make_ext4fs.h b/ext4_utils/make_ext4fs.h
index 1f10bbf..53ff840 100644
--- a/ext4_utils/make_ext4fs.h
+++ b/ext4_utils/make_ext4fs.h
@@ -28,9 +28,11 @@
 #endif
 
 void reset_ext4fs_info();
-int make_ext4fs(const char *filename, s64 len);
+int make_ext4fs(const char *filename, s64 len,
+                const char *mountpoint, struct selabel_handle *sehnd);
 int make_ext4fs_internal(const char *filename, const char *directory,
-                         char *mountpoint, int android, int gzip, int sparse,
+                         const char *mountpoint,
+                         int android, int gzip, int sparse,
                          int crc, int wipe, int init_itabs,
                          struct selabel_handle *sehnd);