fs_mgr: format f2fs with length=xx fstab

Change-Id: Icce29ad918f20b16c9908e7fa3ae19eb8c96760b
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
This commit is contained in:
Jaegeuk Kim 2017-06-12 16:57:56 -07:00
parent 477b08d7ee
commit a367430734

View file

@ -34,23 +34,35 @@
#include "fs_mgr_priv.h"
#include "cryptfs.h"
static int format_ext4(char *fs_blkdev, char *fs_mnt_point, bool crypt_footer)
static int get_dev_sz(char *fs_blkdev, uint64_t *dev_sz)
{
uint64_t dev_sz;
int fd, rc = 0;
int fd;
if ((fd = open(fs_blkdev, O_WRONLY)) < 0) {
if ((fd = open(fs_blkdev, O_RDONLY)) < 0) {
PERROR << "Cannot open block device";
return -1;
}
if ((ioctl(fd, BLKGETSIZE64, &dev_sz)) == -1) {
if ((ioctl(fd, BLKGETSIZE64, dev_sz)) == -1) {
PERROR << "Cannot get block device size";
close(fd);
return -1;
}
close(fd);
return 0;
}
static int format_ext4(char *fs_blkdev, char *fs_mnt_point, bool crypt_footer)
{
uint64_t dev_sz;
int rc = 0;
int status;
rc = get_dev_sz(fs_blkdev, &dev_sz);
if (rc) {
return rc;
}
/* Format the partition using the calculated length */
if (crypt_footer) {
@ -85,9 +97,25 @@ static int format_ext4(char *fs_blkdev, char *fs_mnt_point, bool crypt_footer)
return rc;
}
static int format_f2fs(char *fs_blkdev)
static int format_f2fs(char *fs_blkdev, uint64_t dev_sz, bool crypt_footer)
{
const char* const args[] = {"/system/bin/make_f2fs", "-f", "-O encrypt", fs_blkdev, nullptr};
int status;
if (!dev_sz) {
int rc = get_dev_sz(fs_blkdev, &dev_sz);
if (rc) {
return rc;
}
}
/* Format the partition using the calculated length */
if (crypt_footer) {
dev_sz -= CRYPT_FOOTER_OFFSET;
}
std::string size_str = std::to_string(dev_sz / 4096);
const char* const args[] = {
"/system/bin/make_f2fs", "-f", "-O", "encrypt", fs_blkdev, size_str.c_str(), nullptr};
return android_fork_execvp_ext(arraysize(args), const_cast<char**>(args), NULL, true,
LOG_KLOG, true, nullptr, nullptr, 0);
@ -101,7 +129,7 @@ int fs_mgr_do_format(struct fstab_rec *fstab, bool crypt_footer)
<< " as '" << fstab->fs_type << "'";
if (!strncmp(fstab->fs_type, "f2fs", 4)) {
rc = format_f2fs(fstab->blk_device);
rc = format_f2fs(fstab->blk_device, fstab->length, crypt_footer);
} else if (!strncmp(fstab->fs_type, "ext4", 4)) {
rc = format_ext4(fstab->blk_device, fstab->mount_point, crypt_footer);
} else {