summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshok Mutyala <quic_amutyala@quicinc.com>2024-05-28 09:31:44 +0000
committerAshok Mutyala <quic_amutyala@quicinc.com>2024-06-28 18:08:46 +0530
commit8a398788e40a780727709986dcdee3032d3dc813 (patch)
treefec5cf38bd2f96b0bd072ad0373b590d661b63fd
parent59cb8b37d07cd68e6896627d1015f97c59be0b21 (diff)
downloadvold-8a398788e40a780727709986dcdee3032d3dc813.tar.gz
Add length parameter to format /data f2fs filesystem
With metadata encryption, if partition is wiped (or) cryptfs failed , it will do format without length which make partition size is grown large to occupy remaining space instead of restricting the Android defined partition size. Bug: 343159184 Test: Add length flag in fstab && fastboot erase userdata && fastboot reboot && df -h /data Change-Id: Iad041e960c9337ab1b9d51b115db3c5f3f1f75e2 Signed-off-by: Ashok Mutyala <quic_amutyala@quicinc.com>
-rw-r--r--MetadataCrypt.cpp8
-rw-r--r--MetadataCrypt.h2
-rw-r--r--VoldNativeService.cpp7
-rw-r--r--VoldNativeService.h3
-rw-r--r--binder/android/os/IVold.aidl2
-rw-r--r--fs/F2fs.cpp7
-rw-r--r--fs/F2fs.h2
-rw-r--r--vdc.cpp16
8 files changed, 29 insertions, 18 deletions
diff --git a/MetadataCrypt.cpp b/MetadataCrypt.cpp
index a1106fdd..38dd1126 100644
--- a/MetadataCrypt.cpp
+++ b/MetadataCrypt.cpp
@@ -247,10 +247,12 @@ static bool parse_options(const std::string& options_string, CryptoOptions* opti
bool fscrypt_mount_metadata_encrypted(const std::string& blk_device, const std::string& mount_point,
bool needs_encrypt, bool should_format,
const std::string& fs_type, bool is_zoned,
- const std::vector<std::string>& user_devices) {
+ const std::vector<std::string>& user_devices,
+ int64_t length) {
LOG(DEBUG) << "fscrypt_mount_metadata_encrypted: " << mount_point
<< " encrypt: " << needs_encrypt << " format: " << should_format << " with "
- << fs_type << " block device: " << blk_device << " with zoned " << is_zoned;
+ << fs_type << " block device: " << blk_device << " with zoned " << is_zoned
+ << " length: " << length;
for (auto& device : user_devices) {
LOG(DEBUG) << " - user devices: " << device;
@@ -338,7 +340,7 @@ bool fscrypt_mount_metadata_encrypted(const std::string& blk_device, const std::
if (fs_type == "ext4") {
error = ext4::Format(crypto_blkdev, 0, mount_point);
} else if (fs_type == "f2fs") {
- error = f2fs::Format(crypto_blkdev, is_zoned, crypto_user_blkdev);
+ error = f2fs::Format(crypto_blkdev, is_zoned, crypto_user_blkdev, length);
} else {
LOG(ERROR) << "Unknown filesystem type: " << fs_type;
return false;
diff --git a/MetadataCrypt.h b/MetadataCrypt.h
index 2c07a143..a0914433 100644
--- a/MetadataCrypt.h
+++ b/MetadataCrypt.h
@@ -29,7 +29,7 @@ void defaultkey_precreate_dm_device();
bool fscrypt_mount_metadata_encrypted(const std::string& block_device,
const std::string& mount_point, bool needs_encrypt,
bool should_format, const std::string& fs_type, bool is_zoned,
- const std::vector<std::string>& user_devices);
+ const std::vector<std::string>& user_devices, int64_t length);
bool defaultkey_volume_keygen(KeyGeneration* gen);
diff --git a/VoldNativeService.cpp b/VoldNativeService.cpp
index a70639c6..98dec667 100644
--- a/VoldNativeService.cpp
+++ b/VoldNativeService.cpp
@@ -594,18 +594,19 @@ binder::Status VoldNativeService::mountFstab(const std::string& blkDevice,
ACQUIRE_LOCK;
return translateBool(fscrypt_mount_metadata_encrypted(blkDevice, mountPoint, false, false,
- "null", isZoned, userDevices));
+ "null", isZoned, userDevices, 0));
}
binder::Status VoldNativeService::encryptFstab(const std::string& blkDevice,
const std::string& mountPoint, bool shouldFormat,
const std::string& fsType, bool isZoned,
- const std::vector<std::string>& userDevices) {
+ const std::vector<std::string>& userDevices,
+ int64_t length) {
ENFORCE_SYSTEM_OR_ROOT;
ACQUIRE_LOCK;
return translateBool(fscrypt_mount_metadata_encrypted(blkDevice, mountPoint, true, shouldFormat,
- fsType, isZoned, userDevices));
+ fsType, isZoned, userDevices, length));
}
binder::Status VoldNativeService::setStorageBindingSeed(const std::vector<uint8_t>& seed) {
diff --git a/VoldNativeService.h b/VoldNativeService.h
index 619c7202..bd37ac76 100644
--- a/VoldNativeService.h
+++ b/VoldNativeService.h
@@ -107,9 +107,10 @@ class VoldNativeService : public BinderService<VoldNativeService>, public os::Bn
binder::Status initUser0();
binder::Status mountFstab(const std::string& blkDevice, const std::string& mountPoint,
bool isZoned, const std::vector<std::string>& userDevices);
+
binder::Status encryptFstab(const std::string& blkDevice, const std::string& mountPoint,
bool shouldFormat, const std::string& fsType, bool isZoned,
- const std::vector<std::string>& userDevices);
+ const std::vector<std::string>& userDevices, int64_t length);
binder::Status setStorageBindingSeed(const std::vector<uint8_t>& seed);
diff --git a/binder/android/os/IVold.aidl b/binder/android/os/IVold.aidl
index 919369b6..a8cce94a 100644
--- a/binder/android/os/IVold.aidl
+++ b/binder/android/os/IVold.aidl
@@ -84,7 +84,7 @@ interface IVold {
void initUser0();
void mountFstab(@utf8InCpp String blkDevice, @utf8InCpp String mountPoint, boolean isZoned, in @utf8InCpp String[] userDevices);
- void encryptFstab(@utf8InCpp String blkDevice, @utf8InCpp String mountPoint, boolean shouldFormat, @utf8InCpp String fsType, boolean isZoned, in @utf8InCpp String[] userDevices);
+ void encryptFstab(@utf8InCpp String blkDevice, @utf8InCpp String mountPoint, boolean shouldFormat, @utf8InCpp String fsType, boolean isZoned, in @utf8InCpp String[] userDevices, long length);
void setStorageBindingSeed(in byte[] seed);
diff --git a/fs/F2fs.cpp b/fs/F2fs.cpp
index 99afc32a..3cdf5740 100644
--- a/fs/F2fs.cpp
+++ b/fs/F2fs.cpp
@@ -72,8 +72,10 @@ status_t Mount(const std::string& source, const std::string& target) {
}
status_t Format(const std::string& source, bool is_zoned,
- const std::vector<std::string>& user_devices) {
+ const std::vector<std::string>& user_devices, int64_t length) {
std::vector<char const*> cmd;
+ /* '-g android' parameter passed here which defaults the sector size to 4096 */
+ static constexpr int kSectorSize = 4096;
cmd.emplace_back(kMkfsPath);
cmd.emplace_back("-f");
@@ -110,6 +112,9 @@ status_t Format(const std::string& source, bool is_zoned,
cmd.emplace_back(source.c_str());
+ if (length) {
+ cmd.emplace_back(std::to_string(length / kSectorSize).c_str());
+ }
return logwrap_fork_execvp(cmd.size(), cmd.data(), nullptr, false, LOG_KLOG,
false, nullptr);
}
diff --git a/fs/F2fs.h b/fs/F2fs.h
index a0218f26..73913102 100644
--- a/fs/F2fs.h
+++ b/fs/F2fs.h
@@ -31,7 +31,7 @@ bool IsSupported();
status_t Check(const std::string& source);
status_t Mount(const std::string& source, const std::string& target);
status_t Format(const std::string& source, const bool is_zoned,
- const std::vector<std::string>& user_devices);
+ const std::vector<std::string>& user_devices, int64_t length = 0);
} // namespace f2fs
} // namespace vold
diff --git a/vdc.cpp b/vdc.cpp
index ee8cf9ee..9764b1af 100644
--- a/vdc.cpp
+++ b/vdc.cpp
@@ -109,13 +109,15 @@ static void encryptFstab(std::vector<std::string>& args,
if (isZoned == android::base::ParseBoolResult::kError) exit(EINVAL);
std::vector<std::string> userDevices = {};
- if (args[7] != "") {
- userDevices = android::base::Split(args[7], " ");
+ int64_t length;
+ if (!android::base::ParseInt(args[7], &length)) exit(EINVAL);
+ if (args[8] != "") {
+ userDevices = android::base::Split(args[8], " ");
}
- checkStatus(args,
- vold->encryptFstab(args[2], args[3],
- shouldFormat == android::base::ParseBoolResult::kTrue, args[5],
- isZoned == android::base::ParseBoolResult::kTrue, userDevices));
+ checkStatus(args, vold->encryptFstab(args[2], args[3],
+ shouldFormat == android::base::ParseBoolResult::kTrue,
+ args[5], isZoned == android::base::ParseBoolResult::kTrue,
+ userDevices, length));
}
int main(int argc, char** argv) {
@@ -162,7 +164,7 @@ int main(int argc, char** argv) {
bindkeys(args, vold);
} else if (args[0] == "cryptfs" && args[1] == "mountFstab" && args.size() == 6) {
mountFstab(args, vold);
- } else if (args[0] == "cryptfs" && args[1] == "encryptFstab" && args.size() == 8) {
+ } else if (args[0] == "cryptfs" && args[1] == "encryptFstab" && args.size() == 9) {
encryptFstab(args, vold);
} else if (args[0] == "checkpoint" && args[1] == "supportsCheckpoint" && args.size() == 2) {
bool supported = false;