Skip to content
Snippets Groups Projects
Commit 1fee0d8d authored by Andrew Walbran's avatar Andrew Walbran
Browse files

Support multiple files per partition.

Bug: 190503456
Test: Ran microdroid
Change-Id: I0461120a3eb9c7e8c70ebc61a170d686f9f8b0ea
parent 3eca16ce
No related branches found
No related tags found
No related merge requests found
......@@ -50,13 +50,20 @@ const DISK_SIZE_SHIFT: u8 = 16;
const LINUX_FILESYSTEM_GUID: Uuid = Uuid::from_u128(0x0FC63DAF_8483_4772_8E79_3D69D8477DE4);
const EFI_SYSTEM_PARTITION_GUID: Uuid = Uuid::from_u128(0xC12A7328_F81F_11D2_BA4B_00A0C93EC93B);
/// Information about a single image file to be included in a partition.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct PartitionFileInfo {
path: PathBuf,
size: u64,
}
/// Information about a partition to create, including the set of image files which make it up.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct PartitionInfo {
label: String,
path: PathBuf,
files: Vec<PartitionFileInfo>,
partition_type: ImagePartitionType,
writable: bool,
size: u64,
}
/// Round `val` up to the next multiple of 2**`align_log`.
......@@ -67,7 +74,7 @@ fn align_to_power_of_2(val: u64, align_log: u8) -> u64 {
impl PartitionInfo {
fn aligned_size(&self) -> u64 {
align_to_power_of_2(self.size, PARTITION_SIZE_SHIFT)
align_to_power_of_2(self.files.iter().map(|file| file.size).sum(), PARTITION_SIZE_SHIFT)
}
}
......@@ -160,18 +167,26 @@ fn create_component_disks(
) -> Result<Vec<ComponentDisk>, Error> {
let aligned_size = partition.aligned_size();
let mut component_disks = vec![ComponentDisk {
offset,
file_path: partition.path.to_str().context("Invalid partition path")?.to_string(),
read_write_capability: if partition.writable {
ReadWriteCapability::READ_WRITE
} else {
ReadWriteCapability::READ_ONLY
},
..ComponentDisk::new()
}];
if partition.files.is_empty() {
bail!("No image files for partition {:?}", partition);
}
let mut file_size_sum = 0;
let mut component_disks = vec![];
for file in &partition.files {
component_disks.push(ComponentDisk {
offset: offset + file_size_sum,
file_path: file.path.to_str().context("Invalid partition path")?.to_string(),
read_write_capability: if partition.writable {
ReadWriteCapability::READ_WRITE
} else {
ReadWriteCapability::READ_ONLY
},
..ComponentDisk::new()
});
file_size_sum += file.size;
}
if partition.size != aligned_size {
if file_size_sum != aligned_size {
if partition.writable {
bail!(
"Read-write partition {:?} size is not a multiple of {}.",
......@@ -187,7 +202,7 @@ fn create_component_disks(
1 << PARTITION_SIZE_SHIFT
);
component_disks.push(ComponentDisk {
offset: offset + partition.size,
offset: offset + file_size_sum,
file_path: header_path.to_owned(),
read_write_capability: ReadWriteCapability::READ_ONLY,
..ComponentDisk::new()
......@@ -345,10 +360,12 @@ fn convert_partitions(partitions: &[Partition]) -> Result<(Vec<PartitionInfo>, V
Ok(PartitionInfo {
label: partition.label.to_owned(),
path: format!("/proc/self/fd/{}", fd).into(),
files: vec![PartitionFileInfo {
path: format!("/proc/self/fd/{}", fd).into(),
size,
}],
partition_type: ImagePartitionType::LinuxFilesystem,
writable: partition.writable,
size,
})
})
.collect::<Result<_, Error>>()?;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment