mirror of
https://github.com/holub/mame
synced 2025-06-03 11:26:56 +03:00
[Imgtool] Consolidated logic for default implementation of imgtool::image::list_partitions()
This commit is contained in:
parent
ab9fd24fbb
commit
12fa7aecd9
@ -502,12 +502,25 @@ done:
|
|||||||
|
|
||||||
imgtoolerr_t imgtool::image::list_partitions(std::vector<imgtool::partition_info> &partitions)
|
imgtoolerr_t imgtool::image::list_partitions(std::vector<imgtool::partition_info> &partitions)
|
||||||
{
|
{
|
||||||
/* implemented? */
|
imgtoolerr_t err;
|
||||||
if (!module().list_partitions)
|
|
||||||
return (imgtoolerr_t)(IMGTOOLERR_UNIMPLEMENTED | IMGTOOLERR_SRC_FUNCTIONALITY);
|
|
||||||
|
|
||||||
|
// clear out partitions first
|
||||||
partitions.clear();
|
partitions.clear();
|
||||||
return module().list_partitions(*this, partitions);
|
|
||||||
|
// implemented?
|
||||||
|
if (module().list_partitions)
|
||||||
|
{
|
||||||
|
// if so, call the module's callback
|
||||||
|
err = module().list_partitions(*this, partitions);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// default implementation
|
||||||
|
partitions.emplace_back(unknown_partition_get_info, 0, ~0);
|
||||||
|
}
|
||||||
|
return IMGTOOLERR_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -627,34 +640,20 @@ imgtoolerr_t imgtool::partition::open(imgtool::image &image, int partition_index
|
|||||||
uint64_t base_block, block_count;
|
uint64_t base_block, block_count;
|
||||||
imgtoolerr_t (*open_partition)(imgtool::partition &partition, uint64_t first_block, uint64_t block_count);
|
imgtoolerr_t (*open_partition)(imgtool::partition &partition, uint64_t first_block, uint64_t block_count);
|
||||||
|
|
||||||
if (image.module().list_partitions)
|
// list the partitions
|
||||||
{
|
err = image.list_partitions(partitions);
|
||||||
// this image supports partitions - retrieve the info on the partitions
|
if (err)
|
||||||
err = image.module().list_partitions(image, partitions);
|
return err;
|
||||||
if (err)
|
|
||||||
return err;
|
|
||||||
|
|
||||||
// is this an invalid index?
|
// is this an invalid index?
|
||||||
if ((partition_index < 0) || (partition_index >= partitions.size()) || !partitions[partition_index].get_info())
|
if ((partition_index < 0) || (partition_index >= partitions.size()) || !partitions[partition_index].get_info())
|
||||||
return IMGTOOLERR_INVALIDPARTITION;
|
return IMGTOOLERR_INVALIDPARTITION;
|
||||||
|
|
||||||
// use this partition
|
// use this partition
|
||||||
memset(&imgclass, 0, sizeof(imgclass));
|
memset(&imgclass, 0, sizeof(imgclass));
|
||||||
imgclass.get_info = partitions[partition_index].get_info();
|
imgclass.get_info = partitions[partition_index].get_info();
|
||||||
base_block = partitions[partition_index].base_block();
|
base_block = partitions[partition_index].base_block();
|
||||||
block_count = partitions[partition_index].block_count();
|
block_count = partitions[partition_index].block_count();
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// this image does not support partitions
|
|
||||||
if (partition_index != 0)
|
|
||||||
return IMGTOOLERR_INVALIDPARTITION;
|
|
||||||
|
|
||||||
// identify the image class
|
|
||||||
imgclass = image.module().imgclass;
|
|
||||||
base_block = 0;
|
|
||||||
block_count = ~0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// allocate the new partition object
|
// allocate the new partition object
|
||||||
try { p = std::make_unique<imgtool::partition>(image, imgclass, partition_index, base_block, block_count); }
|
try { p = std::make_unique<imgtool::partition>(image, imgclass, partition_index, base_block, block_count); }
|
||||||
@ -664,7 +663,6 @@ imgtoolerr_t imgtool::partition::open(imgtool::image &image, int partition_index
|
|||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// call the partition open function, if present
|
// call the partition open function, if present
|
||||||
open_partition = (imgtoolerr_t (*)(imgtool::partition &, uint64_t, uint64_t)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_OPEN_PARTITION);
|
open_partition = (imgtoolerr_t (*)(imgtool::partition &, uint64_t, uint64_t)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_OPEN_PARTITION);
|
||||||
if (open_partition)
|
if (open_partition)
|
||||||
|
Loading…
Reference in New Issue
Block a user