Erase data before initializeWritablePartition
initializeWritablePartition should erase data so that even when VM user
app passes an existing file it can be initialized properly.
Bug: 204073443
Test: compos_cmd with existing instance.img
Change-Id: Ie019eef780e7362e55843f863512d9bee0e7146d
diff --git a/virtualizationservice/src/aidl.rs b/virtualizationservice/src/aidl.rs
index 2f901b4..caf815e 100644
--- a/virtualizationservice/src/aidl.rs
+++ b/virtualizationservice/src/aidl.rs
@@ -250,7 +250,13 @@
)
})?;
let image = clone_file(image_fd)?;
-
+ // initialize the file. Any data in the file will be erased.
+ image.set_len(0).map_err(|e| {
+ new_binder_exception(
+ ExceptionCode::SERVICE_SPECIFIC,
+ format!("Failed to reset a file: {}", e),
+ )
+ })?;
let mut part = QcowFile::new(image, size).map_err(|e| {
new_binder_exception(
ExceptionCode::SERVICE_SPECIFIC,