diff options
author | Connor O'Brien <connoro@google.com> | 2017-02-06 14:52:10 -0800 |
---|---|---|
committer | Connor O'Brien <connoro@google.com> | 2017-02-06 15:14:45 -0800 |
commit | 7ba1e209f2c96b32bf023e24ff43a77d4f5341cb (patch) | |
tree | 3e60eee73ed8995596090b089d486da5bbc19b63 | |
parent | a355220f81348774ed391c77c4e7be042635ba66 (diff) | |
download | extras-7ba1e209f2c96b32bf023e24ff43a77d4f5341cb.tar.gz |
ext4_utils: allow passing flash block sizes to make_ext4fs_sparse functions
Add versions of make_ext4fs_sparse_fd() and
make_ext4fs_sparse_fd_directory() that accept flash erase & logical
block size as arguments. Refactor to avoid copied code in the new
aligned versions of each function.
Test: Pass block sizes to new functions using fastboot -w and check
that the new userdata has the correct stride and stripe-width values.
Bug: 33243520
Signed-off-by: Connor O'Brien <connoro@google.com>
Change-Id: I16da6e0ce699439c53d1a722c6d56eb3f9cd9bc5
-rw-r--r-- | ext4_utils/include/ext4_utils/make_ext4fs.h | 6 | ||||
-rw-r--r-- | ext4_utils/make_ext4fs.c | 50 |
2 files changed, 31 insertions, 25 deletions
diff --git a/ext4_utils/include/ext4_utils/make_ext4fs.h b/ext4_utils/include/ext4_utils/make_ext4fs.h index c558b87f..44e94810 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(int fd, long long len, 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 ec093f8d..b84db9b3 100644 --- a/ext4_utils/make_ext4fs.c +++ b/ext4_utils/make_ext4fs.c @@ -426,15 +426,32 @@ void reset_ext4fs_info() { 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 @@ int make_ext4fs(const char *filename, long long len, 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 @@ int make_ext4fs_directory_align(const char *filename, long long len, 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. |