From 29dd6b6c01295222fee5ef2fc70692b2ecb12504 Mon Sep 17 00:00:00 2001 From: Johan Harvyl Date: Mon, 8 Aug 2016 12:37:56 +0200 Subject: Format formattable partitions if mount fails If mount fails and the partition has the formattable flag set in fstab it is formatted and another attempt at the mount is made. Change-Id: I44edafac7d7ff663489072c66b7e210466316b14 --- roots.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'roots.cpp') diff --git a/roots.cpp b/roots.cpp index b06b9c616..b113d9ac5 100644 --- a/roots.cpp +++ b/roots.cpp @@ -102,7 +102,20 @@ int ensure_path_mounted_at(const char* path, const char* mount_point) { if (strcmp(v->fs_type, "ext4") == 0 || strcmp(v->fs_type, "squashfs") == 0 || strcmp(v->fs_type, "vfat") == 0) { - if (mount(v->blk_device, mount_point, v->fs_type, v->flags, v->fs_options) == -1) { + int result = mount(v->blk_device, mount_point, v->fs_type, v->flags, v->fs_options); + if (result == -1 && fs_mgr_is_formattable(v)) { + LOGE("failed to mount %s (%s), formatting ...\n", + mount_point, strerror(errno)); + bool crypt_footer = fs_mgr_is_encryptable(v) && !strcmp(v->key_loc, "footer"); + if (fs_mgr_do_format(v, crypt_footer) == 0) { + result = mount(v->blk_device, mount_point, v->fs_type, v->flags, v->fs_options); + } else { + LOGE("failed to format %s (%s)\n", mount_point, strerror(errno)); + return -1; + } + } + + if (result == -1) { LOGE("failed to mount %s (%s)\n", mount_point, strerror(errno)); return -1; } -- cgit v1.2.3