Merge "ext4_utils: allow passing flash block sizes to make_ext4fs_sparse functions" am: b1ebb81b46 am: 17b1613366
am: bd62055335

Change-Id: Icd4dc0e00977c69e5fe0b48a90e19304cd578187
diff --git a/ext4_utils/include/ext4_utils/make_ext4fs.h b/ext4_utils/include/ext4_utils/make_ext4fs.h
index c558b87..44e9481 100644
--- a/ext4_utils/include/ext4_utils/make_ext4fs.h
+++ b/ext4_utils/include/ext4_utils/make_ext4fs.h
@@ -37,6 +37,12 @@
 int make_ext4fs_sparse_fd_directory(int fd, long long len,
                 const char *mountpoint, struct selabel_handle *sehnd,
                 const char *directory);
+int make_ext4fs_sparse_fd_align(int fd, long long len,
+                const char *mountpoint, struct selabel_handle *sehnd,
+                unsigned eraseblk, unsigned logicalblk);
+int make_ext4fs_sparse_fd_directory_align(int fd, long long len,
+                const char *mountpoint, struct selabel_handle *sehnd,
+                const char *directory, unsigned eraseblk, unsigned logicalblk);
 
 #ifdef __cplusplus
 }
diff --git a/ext4_utils/make_ext4fs.c b/ext4_utils/make_ext4fs.c
index ec093f8..b84db9b 100644
--- a/ext4_utils/make_ext4fs.c
+++ b/ext4_utils/make_ext4fs.c
@@ -426,15 +426,32 @@
 int make_ext4fs_sparse_fd(int fd, long long len,
 				const char *mountpoint, struct selabel_handle *sehnd)
 {
-	return make_ext4fs_sparse_fd_directory(fd, len, mountpoint, sehnd, NULL);
+	return make_ext4fs_sparse_fd_align(fd, len, mountpoint, sehnd, 0, 0);
+}
+
+int make_ext4fs_sparse_fd_align(int fd, long long len,
+				const char *mountpoint, struct selabel_handle *sehnd,
+				unsigned eraseblk, unsigned logicalblk)
+{
+	return make_ext4fs_sparse_fd_directory_align(fd, len, mountpoint, sehnd, NULL,
+								eraseblk, logicalblk);
 }
 
 int make_ext4fs_sparse_fd_directory(int fd, long long len,
 				const char *mountpoint, struct selabel_handle *sehnd,
 				const char *directory)
 {
+	return make_ext4fs_sparse_fd_directory_align(fd, len, mountpoint, sehnd, directory, 0, 0);
+}
+
+int make_ext4fs_sparse_fd_directory_align(int fd, long long len,
+				const char *mountpoint, struct selabel_handle *sehnd,
+				const char *directory, unsigned eraseblk, unsigned logicalblk)
+{
 	reset_ext4fs_info();
 	info.len = len;
+	info.flash_erase_block_size = eraseblk;
+	info.flash_logical_block_size = logicalblk;
 
 	return make_ext4fs_internal(fd, directory, NULL, mountpoint, NULL,
 								0, 1, 0, 0, 0,
@@ -447,6 +464,13 @@
 	return make_ext4fs_directory(filename, len, mountpoint, sehnd, NULL);
 }
 
+int make_ext4fs_directory(const char *filename, long long len,
+						  const char *mountpoint, struct selabel_handle *sehnd,
+						  const char *directory)
+{
+	return make_ext4fs_directory_align(filename, len, mountpoint, sehnd, directory, 0, 0);
+}
+
 int make_ext4fs_directory_align(const char *filename, long long len,
 						  const char *mountpoint, struct selabel_handle *sehnd,
 						  const char *directory, unsigned eraseblk,
@@ -474,30 +498,6 @@
 	return status;
 }
 
-int make_ext4fs_directory(const char *filename, long long len,
-						  const char *mountpoint, struct selabel_handle *sehnd,
-						  const char *directory)
-{
-	int fd;
-	int status;
-
-	reset_ext4fs_info();
-	info.len = len;
-
-	fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
-	if (fd < 0) {
-		error_errno("open");
-		return EXIT_FAILURE;
-	}
-
-	status = make_ext4fs_internal(fd, directory, NULL, mountpoint, NULL,
-								  0, 0, 0, 1, 0,
-								  sehnd, 0, -1, NULL, NULL, NULL);
-	close(fd);
-
-	return status;
-}
-
 /* return a newly-malloc'd string that is a copy of str.  The new string
    is guaranteed to have a trailing slash.  If absolute is true, the new string
    is also guaranteed to have a leading slash.