diff --git a/src/tools/imgtool/filtbas.cpp b/src/tools/imgtool/filtbas.cpp index 0bcb40204e8..6a23256d98a 100644 --- a/src/tools/imgtool/filtbas.cpp +++ b/src/tools/imgtool/filtbas.cpp @@ -69,7 +69,7 @@ struct basictokens -------------------------------------------------*/ static imgtoolerr_t basic_readfile(const basictokens *tokens, - imgtool_partition *partition, const char *filename, + imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *destf) { imgtoolerr_t err; @@ -91,7 +91,7 @@ static imgtoolerr_t basic_readfile(const basictokens *tokens, } /* read actual file */ - err = imgtool_partition_read_file(partition, filename, fork, mem_stream, nullptr); + err = partition->read_file(filename, fork, mem_stream, nullptr); if (err) goto done; @@ -174,7 +174,7 @@ done: -------------------------------------------------*/ static imgtoolerr_t basic_writefile(const basictokens *tokens, - imgtool_partition *partition, const char *filename, + imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) { imgtoolerr_t err; @@ -343,7 +343,7 @@ static imgtoolerr_t basic_writefile(const basictokens *tokens, } /* write actual file */ - err = imgtool_partition_write_file(partition, filename, fork, mem_stream, opts, nullptr); + err = partition->write_file(filename, fork, mem_stream, opts, nullptr); if (err) goto done; @@ -2958,13 +2958,13 @@ static const basictokens cocobas_tokens = ARRAY_LENGTH(cocobas_tokenents) }; -static imgtoolerr_t cocobas_readfile(imgtool_partition *partition, const char *filename, +static imgtoolerr_t cocobas_readfile(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *destf) { return basic_readfile(&cocobas_tokens, partition, filename, fork, destf); } -static imgtoolerr_t cocobas_writefile(imgtool_partition *partition, const char *filename, +static imgtoolerr_t cocobas_writefile(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) { return basic_writefile(&cocobas_tokens, partition, filename, fork, sourcef, opts); @@ -3002,13 +3002,13 @@ static const basictokens dragonbas_tokens = ARRAY_LENGTH(dragonbas_tokenents) }; -static imgtoolerr_t dragonbas_readfile(imgtool_partition *partition, const char *filename, +static imgtoolerr_t dragonbas_readfile(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *destf) { return basic_readfile(&dragonbas_tokens, partition, filename, fork, destf); } -static imgtoolerr_t dragonbas_writefile(imgtool_partition *partition, const char *filename, +static imgtoolerr_t dragonbas_writefile(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) { return basic_writefile(&dragonbas_tokens, partition, filename, fork, sourcef, opts); @@ -3047,13 +3047,13 @@ static const basictokens vzbas_tokens = ARRAY_LENGTH(vzbas_tokenents) }; -static imgtoolerr_t vzbas_readfile(imgtool_partition *partition, const char *filename, +static imgtoolerr_t vzbas_readfile(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *destf) { return basic_readfile(&vzbas_tokens, partition, filename, fork, destf); } -static imgtoolerr_t vzbas_writefile(imgtool_partition *partition, const char *filename, +static imgtoolerr_t vzbas_writefile(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) { return basic_writefile(&vzbas_tokens, partition, filename, fork, sourcef, opts); @@ -3091,13 +3091,13 @@ static const basictokens bml3bas_tokens = ARRAY_LENGTH(bml3bas_tokenents) }; -static imgtoolerr_t bml3bas_readfile(imgtool_partition *partition, const char *filename, +static imgtoolerr_t bml3bas_readfile(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *destf) { return basic_readfile(&bml3bas_tokens, partition, filename, fork, destf); } -static imgtoolerr_t bml3bas_writefile(imgtool_partition *partition, const char *filename, +static imgtoolerr_t bml3bas_writefile(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) { return basic_writefile(&bml3bas_tokens, partition, filename, fork, sourcef, opts); diff --git a/src/tools/imgtool/filteoln.cpp b/src/tools/imgtool/filteoln.cpp index abc612ff6e8..1b4026c3af0 100644 --- a/src/tools/imgtool/filteoln.cpp +++ b/src/tools/imgtool/filteoln.cpp @@ -53,7 +53,7 @@ static imgtoolerr_t convert_stream_eolns(imgtool_stream *source, imgtool_stream -static imgtoolerr_t ascii_readfile(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *destf) +static imgtoolerr_t ascii_readfile(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *destf) { imgtoolerr_t err; imgtool_stream *mem_stream; @@ -65,7 +65,7 @@ static imgtoolerr_t ascii_readfile(imgtool_partition *partition, const char *fil goto done; } - err = imgtool_partition_read_file(partition, filename, fork, mem_stream, nullptr); + err = partition->read_file(filename, fork, mem_stream, nullptr); if (err) goto done; @@ -82,7 +82,7 @@ done: -static imgtoolerr_t ascii_writefile(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) +static imgtoolerr_t ascii_writefile(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) { imgtoolerr_t err; imgtool_stream *mem_stream = nullptr; @@ -96,14 +96,14 @@ static imgtoolerr_t ascii_writefile(imgtool_partition *partition, const char *fi goto done; } - eoln = imgtool_partition_get_info_string(partition, IMGTOOLINFO_STR_EOLN); + eoln = partition->get_info_string(IMGTOOLINFO_STR_EOLN); err = convert_stream_eolns(sourcef, mem_stream, eoln); if (err) goto done; stream_seek(mem_stream, SEEK_SET, 0); - err = imgtool_partition_write_file(partition, filename, fork, mem_stream, opts, nullptr); + err = partition->write_file(filename, fork, mem_stream, opts, nullptr); if (err) goto done; diff --git a/src/tools/imgtool/imgtool.cpp b/src/tools/imgtool/imgtool.cpp index 8141d2cb656..25b116c86e3 100644 --- a/src/tools/imgtool/imgtool.cpp +++ b/src/tools/imgtool/imgtool.cpp @@ -18,59 +18,6 @@ #include "pool.h" -/*************************************************************************** - TYPE DEFINITIONS -***************************************************************************/ - -struct imgtool_partition -{ - imgtool::image *image; - object_pool *pool; - int partition_index; - UINT64 base_block; - UINT64 block_count; - - imgtool_class imgclass; - size_t partition_extra_bytes; - size_t directory_extra_bytes; - - char path_separator; - char alternate_path_separator; - - unsigned int prefer_ucase : 1; - unsigned int supports_creation_time : 1; - unsigned int supports_lastmodified_time : 1; - unsigned int supports_bootblock : 1; /* this module supports loading/storing the boot block */ - - imgtoolerr_t (*begin_enum) (imgtool_directory *enumeration, const char *path); - imgtoolerr_t (*next_enum) (imgtool_directory *enumeration, imgtool_dirent *ent); - void (*close_enum) (imgtool_directory *enumeration); - imgtoolerr_t (*free_space) (imgtool_partition *partition, UINT64 *size); - imgtoolerr_t (*read_file) (imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *destf); - imgtoolerr_t (*write_file) (imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts); - imgtoolerr_t (*delete_file) (imgtool_partition *partition, const char *filename); - imgtoolerr_t (*list_forks) (imgtool_partition *partition, const char *path, imgtool_forkent *ents, size_t len); - imgtoolerr_t (*create_dir) (imgtool_partition *partition, const char *path); - imgtoolerr_t (*delete_dir) (imgtool_partition *partition, const char *path); - imgtoolerr_t (*list_attrs) (imgtool_partition *partition, const char *path, UINT32 *attrs, size_t len); - imgtoolerr_t (*get_attrs) (imgtool_partition *partition, const char *path, const UINT32 *attrs, imgtool_attribute *values); - imgtoolerr_t (*set_attrs) (imgtool_partition *partition, const char *path, const UINT32 *attrs, const imgtool_attribute *values); - imgtoolerr_t (*attr_name) (UINT32 attribute, const imgtool_attribute *attr, char *buffer, size_t buffer_len); - imgtoolerr_t (*get_iconinfo) (imgtool_partition *partition, const char *path, imgtool_iconinfo *iconinfo); - imgtoolerr_t (*suggest_transfer)(imgtool_partition *partition, const char *path, imgtool_transfer_suggestion *suggestions, size_t suggestions_length); - imgtoolerr_t (*get_chain) (imgtool_partition *partition, const char *path, imgtool_chainent *chain, size_t chain_size); - - const util::option_guide *writefile_optguide; - const char *writefile_optspec; -}; - -struct imgtool_directory -{ - imgtool_partition *partition; -}; - - - /*************************************************************************** GLOBALS ***************************************************************************/ @@ -176,19 +123,18 @@ static void internal_error(const imgtool_module *module, const char *message) // native format used by the module //------------------------------------------------- -static char *normalize_filename(imgtool_partition *partition, const char *src) +char *imgtool::partition::normalize_filename(const char *src) { imgtool_charset charset; - /* get charset from module */ - charset = (imgtool_charset) (int) imgtool_partition_get_info_int(partition, IMGTOOLINFO_INT_CHARSET); + // get charset from module + charset = (imgtool_charset) (int) get_info_int(IMGTOOLINFO_INT_CHARSET); - /* and dupe it */ + // and dupe it return native_from_utf8(charset, src); } - //------------------------------------------------- // imgtool_init - initializes the imgtool core //------------------------------------------------- @@ -296,8 +242,8 @@ static imgtoolerr_t evaluate_module(const char *fname, { imgtoolerr_t err; imgtool::image::ptr image; - imgtool_partition *partition = nullptr; - imgtool_directory *imageenum = nullptr; + imgtool::partition::ptr partition; + imgtool::directory::ptr imageenum; imgtool_dirent ent; float current_result; @@ -311,18 +257,18 @@ static imgtoolerr_t evaluate_module(const char *fname, { current_result = module->open_is_strict ? 0.9 : 0.5; - err = imgtool_partition_open(image.get(), 0, &partition); + err = imgtool::partition::open(*image, 0, partition); if (err) goto done; - err = imgtool_directory_open(partition, nullptr, &imageenum); + err = imgtool::directory::open(*partition, nullptr, imageenum); if (err) goto done; memset(&ent, 0, sizeof(ent)); do { - err = imgtool_directory_get_next(imageenum, &ent); + err = imageenum->get_next(ent); if (err) goto done; @@ -339,27 +285,10 @@ static imgtoolerr_t evaluate_module(const char *fname, done: if (ERRORCODE(err) == IMGTOOLERR_CORRUPTIMAGE) err = IMGTOOLERR_SUCCESS; - if (imageenum) - imgtool_directory_close(imageenum); - if (partition) - imgtool_partition_close(partition); return err; } - -//------------------------------------------------- -// imgtool_partition_image - retrieves the image -// associated with this partition -//------------------------------------------------- - -imgtool::image *imgtool_partition_image(imgtool_partition *partition) -{ - return partition->image; -} - - - //------------------------------------------------- // identify_file - attempts to determine the module // for any given image @@ -614,41 +543,107 @@ UINT64 imgtool::image::rand() ***************************************************************************/ -static char *pool_strdup_allow_null(object_pool *pool, char *s) +//------------------------------------------------- +// imgtool::partition ctor +//------------------------------------------------- + +imgtool::partition::partition(imgtool::image &image, imgtool_class &imgclass, int partition_index, UINT64 base_block, UINT64 block_count) + : m_image(image) + , m_partition_index(partition_index) + , m_base_block(base_block) + , m_block_count(block_count) + , m_imgclass(imgclass) { - return s ? pool_strdup_lib(pool, s) : nullptr; + // does this partition type have extra bytes? + size_t extra_bytes_size = imgtool_get_info_int(&imgclass, IMGTOOLINFO_INT_PARTITION_EXTRA_BYTES); + if (extra_bytes_size > 0) + { + m_extra_bytes = std::make_unique(extra_bytes_size); + memset(m_extra_bytes.get(), 0, sizeof(m_extra_bytes.get()[0]) * extra_bytes_size); + } + + m_directory_extra_bytes = imgtool_get_info_int(&imgclass, IMGTOOLINFO_INT_DIRECTORY_EXTRA_BYTES); + m_path_separator = (char)imgtool_get_info_int(&imgclass, IMGTOOLINFO_INT_PATH_SEPARATOR); + m_alternate_path_separator = (char)imgtool_get_info_int(&imgclass, IMGTOOLINFO_INT_ALTERNATE_PATH_SEPARATOR); + m_prefer_ucase = imgtool_get_info_int(&imgclass, IMGTOOLINFO_INT_PREFER_UCASE) ? 1 : 0; + m_supports_creation_time = imgtool_get_info_int(&imgclass, IMGTOOLINFO_INT_SUPPORTS_CREATION_TIME) ? 1 : 0; + m_supports_lastmodified_time = imgtool_get_info_int(&imgclass, IMGTOOLINFO_INT_SUPPORTS_LASTMODIFIED_TIME) ? 1 : 0; + m_supports_bootblock = imgtool_get_info_int(&imgclass, IMGTOOLINFO_INT_SUPPORTS_BOOTBLOCK) ? 1 : 0; + m_begin_enum = (imgtoolerr_t(*)(imgtool::directory *, const char *)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_BEGIN_ENUM); + m_next_enum = (imgtoolerr_t(*)(imgtool::directory *, imgtool_dirent *)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_NEXT_ENUM); + m_close_enum = (void(*)(imgtool::directory *)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_CLOSE_ENUM); + m_free_space = (imgtoolerr_t(*)(imgtool::partition *, UINT64 *)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_FREE_SPACE); + m_read_file = (imgtoolerr_t(*)(imgtool::partition *, const char *, const char *, imgtool_stream *)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_READ_FILE); + m_write_file = (imgtoolerr_t(*)(imgtool::partition *, const char *, const char *, imgtool_stream *, util::option_resolution *)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_WRITE_FILE); + m_delete_file = (imgtoolerr_t(*)(imgtool::partition *, const char *)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_DELETE_FILE); + m_list_forks = (imgtoolerr_t(*)(imgtool::partition *, const char *, imgtool_forkent *, size_t)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_LIST_FORKS); + m_create_dir = (imgtoolerr_t(*)(imgtool::partition *, const char *)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_CREATE_DIR); + m_delete_dir = (imgtoolerr_t(*)(imgtool::partition *, const char *)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_DELETE_DIR); + m_list_attrs = (imgtoolerr_t(*)(imgtool::partition *, const char *, UINT32 *, size_t)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_LIST_ATTRS); + m_get_attrs = (imgtoolerr_t(*)(imgtool::partition *, const char *, const UINT32 *, imgtool_attribute *)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_GET_ATTRS); + m_set_attrs = (imgtoolerr_t(*)(imgtool::partition *, const char *, const UINT32 *, const imgtool_attribute *)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_SET_ATTRS); + m_attr_name = (imgtoolerr_t(*)(UINT32, const imgtool_attribute *, char *, size_t)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_ATTR_NAME); + m_get_iconinfo = (imgtoolerr_t(*)(imgtool::partition *, const char *, imgtool_iconinfo *)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_GET_ICON_INFO); + m_suggest_transfer = (imgtoolerr_t(*)(imgtool::partition *, const char *, imgtool_transfer_suggestion *, size_t)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_SUGGEST_TRANSFER); + m_get_chain = (imgtoolerr_t(*)(imgtool::partition *, const char *, imgtool_chainent *, size_t)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_GET_CHAIN); + m_writefile_optguide = (const util::option_guide *) imgtool_get_info_ptr(&imgclass, IMGTOOLINFO_PTR_WRITEFILE_OPTGUIDE); + + const char *writefile_optspec = (const char *)imgtool_get_info_ptr(&imgclass, IMGTOOLINFO_STR_WRITEFILE_OPTSPEC); + if (writefile_optspec) + m_writefile_optspec.assign(writefile_optspec); + + // mask out if writing is untested + if (global_omit_untested && imgtool_get_info_int(&imgclass, IMGTOOLINFO_INT_WRITING_UNTESTED)) + { + m_write_file = nullptr; + m_delete_file = nullptr; + m_create_dir = nullptr; + m_delete_dir = nullptr; + m_writefile_optguide = nullptr; + m_writefile_optspec = nullptr; + } } +//------------------------------------------------- +// imgtool::partition dtor +//------------------------------------------------- -imgtoolerr_t imgtool_partition_open(imgtool::image *image, int partition_index, imgtool_partition **partition) +imgtool::partition::~partition() +{ +} + + +//------------------------------------------------- +// open - opens a partition +//------------------------------------------------- + +imgtoolerr_t imgtool::partition::open(imgtool::image &image, int partition_index, imgtool::partition::ptr &partition) { imgtoolerr_t err = (imgtoolerr_t)IMGTOOLERR_SUCCESS; - imgtool_partition *p = nullptr; + imgtool::partition::ptr p; imgtool_class imgclass; imgtool_partition_info partition_info[32]; UINT64 base_block, block_count; - size_t partition_extra_bytes; - object_pool *pool; - imgtoolerr_t (*open_partition)(imgtool_partition *partition, UINT64 first_block, UINT64 block_count); + imgtoolerr_t (*open_partition)(imgtool::partition *partition, UINT64 first_block, UINT64 block_count); - if (image->module().list_partitions) + if (image.module().list_partitions) { - /* this image supports partitions */ + // this image supports partitions if ((partition_index < 0) || (partition_index >= ARRAY_LENGTH(partition_info))) return IMGTOOLERR_INVALIDPARTITION; - /* retrieve the info on the partitions */ + // retrieve the info on the partitions memset(partition_info, '\0', sizeof(partition_info)); - err = image->module().list_partitions(image, partition_info, ARRAY_LENGTH(partition_info)); + err = image.module().list_partitions(&image, partition_info, ARRAY_LENGTH(partition_info)); if (err) return err; - /* is this a valid partition */ + // is this a valid partition if (!partition_info[partition_index].get_info) return IMGTOOLERR_INVALIDPARTITION; - /* use this partition */ + // use this partition memset(&imgclass, 0, sizeof(imgclass)); imgclass.get_info = partition_info[partition_index].get_info; base_block = partition_info[partition_index].base_block; @@ -656,117 +651,57 @@ imgtoolerr_t imgtool_partition_open(imgtool::image *image, int partition_index, } else { - /* this image does not support partitions */ + // this image does not support partitions if (partition_index != 0) return IMGTOOLERR_INVALIDPARTITION; - /* identify the image class */ - imgclass = image->module().imgclass; + // identify the image class + imgclass = image.module().imgclass; base_block = 0; block_count = ~0; } - /* does this partition type have extra bytes? */ - partition_extra_bytes = imgtool_get_info_int(&imgclass, IMGTOOLINFO_INT_PARTITION_EXTRA_BYTES); - - /* allocate the new memory pool */ - pool = pool_alloc_lib(nullptr); - if (!pool) + // allocate the new partition object + try { p = std::make_unique(image, imgclass, partition_index, base_block, block_count); } + catch (std::bad_alloc const &) { err = (imgtoolerr_t)IMGTOOLERR_OUTOFMEMORY; goto done; } - /* allocate the new partition object */ - p = (imgtool_partition *) pool_malloc_lib(pool, sizeof(*p) + partition_extra_bytes); - if (!p) - { - err = (imgtoolerr_t)IMGTOOLERR_OUTOFMEMORY; - goto done; - } - memset(p, 0, sizeof(*p) + partition_extra_bytes); - p->pool = pool; - /* fill out the structure */ - p->image = image; - p->partition_index = partition_index; - p->base_block = base_block; - p->block_count = block_count; - p->imgclass = imgclass; - p->partition_extra_bytes = partition_extra_bytes; - p->directory_extra_bytes = imgtool_get_info_int(&imgclass, IMGTOOLINFO_INT_DIRECTORY_EXTRA_BYTES); - p->path_separator = (char) imgtool_get_info_int(&imgclass, IMGTOOLINFO_INT_PATH_SEPARATOR); - p->alternate_path_separator = (char) imgtool_get_info_int(&imgclass, IMGTOOLINFO_INT_ALTERNATE_PATH_SEPARATOR); - p->prefer_ucase = imgtool_get_info_int(&imgclass, IMGTOOLINFO_INT_PREFER_UCASE) ? 1 : 0; - p->supports_creation_time = imgtool_get_info_int(&imgclass, IMGTOOLINFO_INT_SUPPORTS_CREATION_TIME) ? 1 : 0; - p->supports_lastmodified_time = imgtool_get_info_int(&imgclass, IMGTOOLINFO_INT_SUPPORTS_LASTMODIFIED_TIME) ? 1 : 0; - p->supports_bootblock = imgtool_get_info_int(&imgclass, IMGTOOLINFO_INT_SUPPORTS_BOOTBLOCK) ? 1 : 0; - p->begin_enum = (imgtoolerr_t (*)(imgtool_directory *, const char *)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_BEGIN_ENUM); - p->next_enum = (imgtoolerr_t (*)(imgtool_directory *, imgtool_dirent *)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_NEXT_ENUM); - p->free_space = (imgtoolerr_t (*)(imgtool_partition *, UINT64 *)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_FREE_SPACE); - p->read_file = (imgtoolerr_t (*)(imgtool_partition *, const char *, const char *, imgtool_stream *)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_READ_FILE); - p->write_file = (imgtoolerr_t (*)(imgtool_partition *, const char *, const char *, imgtool_stream *, util::option_resolution *)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_WRITE_FILE); - p->delete_file = (imgtoolerr_t (*)(imgtool_partition *, const char *)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_DELETE_FILE); - p->list_forks = (imgtoolerr_t (*)(imgtool_partition *, const char *, imgtool_forkent *, size_t)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_LIST_FORKS); - p->create_dir = (imgtoolerr_t (*)(imgtool_partition *, const char *)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_CREATE_DIR); - p->delete_dir = (imgtoolerr_t (*)(imgtool_partition *, const char *)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_DELETE_DIR); - p->list_attrs = (imgtoolerr_t (*)(imgtool_partition *, const char *, UINT32 *, size_t)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_LIST_ATTRS); - p->get_attrs = (imgtoolerr_t (*)(imgtool_partition *, const char *, const UINT32 *, imgtool_attribute *)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_GET_ATTRS); - p->set_attrs = (imgtoolerr_t (*)(imgtool_partition *, const char *, const UINT32 *, const imgtool_attribute *)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_SET_ATTRS); - p->attr_name = (imgtoolerr_t (*)(UINT32, const imgtool_attribute *, char *, size_t)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_ATTR_NAME); - p->get_iconinfo = (imgtoolerr_t (*)(imgtool_partition *, const char *, imgtool_iconinfo *)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_GET_ICON_INFO); - p->suggest_transfer = (imgtoolerr_t (*)(imgtool_partition *, const char *, imgtool_transfer_suggestion *, size_t)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_SUGGEST_TRANSFER); - p->get_chain = (imgtoolerr_t (*)(imgtool_partition *, const char *, imgtool_chainent *, size_t)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_GET_CHAIN); - p->writefile_optguide = (const util::option_guide *) imgtool_get_info_ptr(&imgclass, IMGTOOLINFO_PTR_WRITEFILE_OPTGUIDE); - p->writefile_optspec = pool_strdup_allow_null(p->pool, (char*)imgtool_get_info_ptr(&imgclass, IMGTOOLINFO_STR_WRITEFILE_OPTSPEC)); - - /* mask out if writing is untested */ - if (global_omit_untested && imgtool_get_info_int(&imgclass, IMGTOOLINFO_INT_WRITING_UNTESTED)) - { - p->write_file = nullptr; - p->delete_file = nullptr; - p->create_dir = nullptr; - p->delete_dir = nullptr; - p->writefile_optguide = nullptr; - p->writefile_optspec = nullptr; - } - - /* call the partition open function, if present */ - open_partition = (imgtoolerr_t (*)(imgtool_partition *, UINT64, UINT64)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_OPEN_PARTITION); + // call the partition open function, if present + open_partition = (imgtoolerr_t (*)(imgtool::partition *, UINT64, UINT64)) imgtool_get_info_fct(&imgclass, IMGTOOLINFO_PTR_OPEN_PARTITION); if (open_partition) { /* we have an open partition function */ - err = (*open_partition)(p, base_block, block_count); + err = (*open_partition)(p.get(), base_block, block_count); if (err) goto done; } done: - *partition = err ? nullptr : p; + if (!err) + partition = std::move(p); + else + partition.reset(); return err; } -void imgtool_partition_close(imgtool_partition *partition) -{ - pool_free_lib(partition->pool); -} - - - /*************************************************************************** Imgtool partition operations ***************************************************************************/ -/*------------------------------------------------- - imgtool_partition_get_attribute_name - retrieves the human readable - name for an attribute --------------------------------------------------*/ +//------------------------------------------------- +// get_attribute_name - retrieves the human readable +// name for an attribute +//------------------------------------------------- -void imgtool_partition_get_attribute_name(imgtool_partition *partition, UINT32 attribute, const imgtool_attribute *attr_value, +void imgtool::partition::get_attribute_name(UINT32 attribute, const imgtool_attribute *attr_value, char *buffer, size_t buffer_len) { imgtoolerr_t err = (imgtoolerr_t)IMGTOOLERR_UNIMPLEMENTED; @@ -775,8 +710,8 @@ void imgtool_partition_get_attribute_name(imgtool_partition *partition, UINT32 a if (attr_value) { - if (partition->attr_name) - err = partition->attr_name(attribute, attr_value, buffer, buffer_len); + if (m_attr_name) + err = m_attr_name(attribute, attr_value, buffer, buffer_len); if (err == (imgtoolerr_t)IMGTOOLERR_UNIMPLEMENTED) { @@ -1176,13 +1111,12 @@ imgtoolerr_t imgtool::image::info(char *string, size_t len) #define PATH_LEAVENULLALONE 0x00000002 #define PATH_CANBEBOOTBLOCK 0x00000004 -/*------------------------------------------------- - cannonicalize_path - normalizes a path string - into a NUL delimited list --------------------------------------------------*/ +//------------------------------------------------- +// partition::cannonicalize_path - normalizes a path string +// into a NUL delimited list +//------------------------------------------------- -static imgtoolerr_t cannonicalize_path(imgtool_partition *partition, UINT32 flags, - const char **path, char **alloc_path) +imgtoolerr_t imgtool::partition::cannonicalize_path(UINT32 flags, const char **path, char **alloc_path) { imgtoolerr_t err = (imgtoolerr_t)IMGTOOLERR_SUCCESS; char *new_path = nullptr; @@ -1190,8 +1124,8 @@ static imgtoolerr_t cannonicalize_path(imgtool_partition *partition, UINT32 flag const char *s; int in_path_separator, i, j; - path_separator = partition->path_separator; - alt_path_separator = partition->alternate_path_separator; + path_separator = m_path_separator; + alt_path_separator = m_alternate_path_separator; /* is this path NULL? if so, is that ignored? */ if (!*path && (flags & PATH_LEAVENULLALONE)) @@ -1202,7 +1136,7 @@ static imgtoolerr_t cannonicalize_path(imgtool_partition *partition, UINT32 flag { if (!(flags & PATH_CANBEBOOTBLOCK)) err = (imgtoolerr_t)IMGTOOLERR_UNEXPECTED; - else if (!partition->supports_bootblock) + else if (!m_supports_bootblock) err = (imgtoolerr_t)IMGTOOLERR_FILENOTFOUND; goto done; } @@ -1224,7 +1158,7 @@ static imgtoolerr_t cannonicalize_path(imgtool_partition *partition, UINT32 flag { s = *path ? *path : ""; - /* allocate space for a new cannonical path */ + // allocate space for a new cannonical path new_path = (char*)malloc(strlen(s) + 4); if (!new_path) { @@ -1260,19 +1194,22 @@ done: } +//------------------------------------------------- +// partition::cannonicalize_fork +//------------------------------------------------- -static imgtoolerr_t cannonicalize_fork(imgtool_partition *partition, const char **fork) +imgtoolerr_t imgtool::partition::cannonicalize_fork(const char **fork) { - /* does this module support forks? */ - if (partition->list_forks) + // does this module support forks? + if (m_list_forks) { - /* this module supports forks; make sure that fork is non-NULL */ + // this module supports forks; make sure that fork is non-NULL if (!*fork) *fork = ""; } else { - /* this module does not support forks; make sure that fork is NULL */ + // this module does not support forks; make sure that fork is NULL if (*fork) return IMGTOOLERR_NOFORKS; } @@ -1280,16 +1217,15 @@ static imgtoolerr_t cannonicalize_fork(imgtool_partition *partition, const char } +//------------------------------------------------- +// partition::get_directory_entry - retrieves +// the nth directory entry within a partition +//------------------------------------------------- -/*------------------------------------------------- - imgtool_partition_get_directory_entry - retrieves - the nth directory entry within a partition --------------------------------------------------*/ - -imgtoolerr_t imgtool_partition_get_directory_entry(imgtool_partition *partition, const char *path, int index, imgtool_dirent *ent) +imgtoolerr_t imgtool::partition::get_directory_entry(const char *path, int index, imgtool_dirent &ent) { imgtoolerr_t err; - imgtool_directory *imgenum = nullptr; + imgtool::directory::ptr imgenum; if (index < 0) { @@ -1297,17 +1233,17 @@ imgtoolerr_t imgtool_partition_get_directory_entry(imgtool_partition *partition, goto done; } - err = imgtool_directory_open(partition, path, &imgenum); + err = imgtool::directory::open(*this, path, imgenum); if (err) goto done; do { - err = imgtool_directory_get_next(imgenum, ent); + err = imgenum->get_next(ent); if (err) goto done; - if (ent->eof) + if (ent.eof) { err = (imgtoolerr_t)IMGTOOLERR_FILENOTFOUND; goto done; @@ -1317,44 +1253,41 @@ imgtoolerr_t imgtool_partition_get_directory_entry(imgtool_partition *partition, done: if (err) - memset(ent->filename, 0, sizeof(ent->filename)); - if (imgenum) - imgtool_directory_close(imgenum); + memset(ent.filename, 0, sizeof(ent.filename)); return err; } +//------------------------------------------------- +// partition::get_file_size - returns free +// space on a partition, in bytes +//------------------------------------------------- -/*------------------------------------------------- - imgtool_partition_get_file_size - returns free - space on a partition, in bytes --------------------------------------------------*/ - -imgtoolerr_t imgtool_partition_get_file_size(imgtool_partition *partition, const char *fname, UINT64 *filesize) +imgtoolerr_t imgtool::partition::get_file_size(const char *fname, UINT64 &filesize) { imgtoolerr_t err; - imgtool_directory *imgenum; + imgtool::directory::ptr imgenum; imgtool_dirent ent; const char *path; path = nullptr; /* TODO: Need to parse off the path */ - *filesize = -1; + filesize = ~((UINT64) 0); memset(&ent, 0, sizeof(ent)); - err = imgtool_directory_open(partition, path, &imgenum); + err = imgtool::directory::open(*this, path, imgenum); if (err) goto done; do { - err = imgtool_directory_get_next(imgenum, &ent); + err = imgenum->get_next(ent); if (err) goto done; if (!core_stricmp(fname, ent.filename)) { - *filesize = ent.filesize; + filesize = ent.filesize; goto done; } } @@ -1363,19 +1296,16 @@ imgtoolerr_t imgtool_partition_get_file_size(imgtool_partition *partition, const err = (imgtoolerr_t)IMGTOOLERR_FILENOTFOUND; done: - if (imgenum) - imgtool_directory_close(imgenum); return err; } +//------------------------------------------------- +// partition::list_file_attributes - identifies +// all attributes on a file +//------------------------------------------------- -/*------------------------------------------------- - imgtool_partition_list_file_attributes - identifies - all attributes on a file --------------------------------------------------*/ - -imgtoolerr_t imgtool_partition_list_file_attributes(imgtool_partition *partition, const char *path, UINT32 *attrs, size_t len) +imgtoolerr_t imgtool::partition::list_file_attributes(const char *path, UINT32 *attrs, size_t len) { imgtoolerr_t err; char *alloc_path = nullptr; @@ -1383,13 +1313,13 @@ imgtoolerr_t imgtool_partition_list_file_attributes(imgtool_partition *partition memset(attrs, 0, sizeof(*attrs) * len); - if (!partition->list_attrs) + if (!m_list_attrs) { err = (imgtoolerr_t)(IMGTOOLERR_UNIMPLEMENTED | IMGTOOLERR_SRC_FUNCTIONALITY); goto done; } - new_fname = normalize_filename(partition, path); + new_fname = normalize_filename(path); if (new_fname == nullptr) { err = (imgtoolerr_t)(IMGTOOLERR_BADFILENAME | IMGTOOLERR_SRC_FUNCTIONALITY); @@ -1398,12 +1328,12 @@ imgtoolerr_t imgtool_partition_list_file_attributes(imgtool_partition *partition path = new_fname; - /* cannonicalize path */ - err = cannonicalize_path(partition, PATH_LEAVENULLALONE, &path, &alloc_path); + // cannonicalize path + err = cannonicalize_path(PATH_LEAVENULLALONE, &path, &alloc_path); if (err) goto done; - err = partition->list_attrs(partition, path, attrs, len); + err = m_list_attrs(this, path, attrs, len); if (err) goto done; @@ -1416,25 +1346,24 @@ done: } +//------------------------------------------------- +// partition::get_file_attributes - retrieves +// attributes on a file +//------------------------------------------------- -/*------------------------------------------------- - imgtool_partition_get_file_attributes - retrieves - attributes on a file --------------------------------------------------*/ - -imgtoolerr_t imgtool_partition_get_file_attributes(imgtool_partition *partition, const char *path, const UINT32 *attrs, imgtool_attribute *values) +imgtoolerr_t imgtool::partition::get_file_attributes(const char *path, const UINT32 *attrs, imgtool_attribute *values) { imgtoolerr_t err; char *alloc_path = nullptr; char *new_fname = nullptr; - if (!partition->get_attrs) + if (!m_get_attrs) { err = (imgtoolerr_t)(IMGTOOLERR_UNIMPLEMENTED | IMGTOOLERR_SRC_FUNCTIONALITY); goto done; } - new_fname = normalize_filename(partition, path); + new_fname = normalize_filename(path); if (new_fname == nullptr) { err = (imgtoolerr_t)(IMGTOOLERR_BADFILENAME | IMGTOOLERR_SRC_FUNCTIONALITY); @@ -1443,12 +1372,12 @@ imgtoolerr_t imgtool_partition_get_file_attributes(imgtool_partition *partition, path = new_fname; - /* cannonicalize path */ - err = cannonicalize_path(partition, PATH_LEAVENULLALONE, &path, &alloc_path); + // cannonicalize path + err = cannonicalize_path(PATH_LEAVENULLALONE, &path, &alloc_path); if (err) goto done; - err = partition->get_attrs(partition, path, attrs, values); + err = m_get_attrs(this, path, attrs, values); if (err) goto done; @@ -1461,29 +1390,28 @@ done: } +//------------------------------------------------- +// imgtool::partition::put_file_attributes - sets +// attributes on a file +//------------------------------------------------- -/*------------------------------------------------- - imgtool_partition_put_file_attributes - sets - attributes on a file --------------------------------------------------*/ - -imgtoolerr_t imgtool_partition_put_file_attributes(imgtool_partition *partition, const char *path, const UINT32 *attrs, const imgtool_attribute *values) +imgtoolerr_t imgtool::partition::put_file_attributes(const char *path, const UINT32 *attrs, const imgtool_attribute *values) { imgtoolerr_t err; char *alloc_path = nullptr; - if (!partition->set_attrs) + if (!m_set_attrs) { err = (imgtoolerr_t)(IMGTOOLERR_UNIMPLEMENTED | IMGTOOLERR_SRC_FUNCTIONALITY); goto done; } - /* cannonicalize path */ - err = cannonicalize_path(partition, PATH_LEAVENULLALONE, &path, &alloc_path); + // cannonicalize path + err = cannonicalize_path(PATH_LEAVENULLALONE, &path, &alloc_path); if (err) goto done; - err = partition->set_attrs(partition, path, attrs, values); + err = m_set_attrs(this, path, attrs, values); if (err) goto done; @@ -1494,55 +1422,52 @@ done: } +//------------------------------------------------- +// partition::get_file_attribute - retrieves +// an attribute on a single file +//------------------------------------------------- -/*------------------------------------------------- - imgtool_partition_get_file_attributes - retrieves - an attribute on a single file --------------------------------------------------*/ - -imgtoolerr_t imgtool_partition_get_file_attribute(imgtool_partition *partition, const char *path, UINT32 attr, imgtool_attribute *value) +imgtoolerr_t imgtool::partition::get_file_attribute(const char *path, UINT32 attr, imgtool_attribute &value) { UINT32 attrs[2]; attrs[0] = attr; attrs[1] = 0; - return imgtool_partition_get_file_attributes(partition, path, attrs, value); + return get_file_attributes(path, attrs, &value); } +//------------------------------------------------- +// partition::put_file_attribute - sets +// attributes on a single file +//------------------------------------------------- -/*------------------------------------------------- - imgtool_partition_put_file_attribute - sets - attributes on a single file --------------------------------------------------*/ - -imgtoolerr_t imgtool_partition_put_file_attribute(imgtool_partition *partition, const char *path, UINT32 attr, imgtool_attribute value) +imgtoolerr_t imgtool::partition::put_file_attribute(const char *path, UINT32 attr, const imgtool_attribute &value) { UINT32 attrs[2]; attrs[0] = attr; attrs[1] = 0; - return imgtool_partition_put_file_attributes(partition, path, attrs, &value); + return put_file_attributes(path, attrs, &value); } +//------------------------------------------------- +// partition::get_icon_info - retrieves the +// icon for a file stored on a partition +//------------------------------------------------- -/*------------------------------------------------- - imgtool_partition_get_icon_info - retrieves the - icon for a file stored on a partition --------------------------------------------------*/ - -imgtoolerr_t imgtool_partition_get_icon_info(imgtool_partition *partition, const char *path, imgtool_iconinfo *iconinfo) +imgtoolerr_t imgtool::partition::get_icon_info(const char *path, imgtool_iconinfo *iconinfo) { imgtoolerr_t err; char *alloc_path = nullptr; char *new_fname = nullptr; - if (!partition->get_iconinfo) + if (!m_get_iconinfo) { err = (imgtoolerr_t)(IMGTOOLERR_UNIMPLEMENTED | IMGTOOLERR_SRC_FUNCTIONALITY); goto done; } - new_fname = normalize_filename(partition, path); + new_fname = normalize_filename(path); if (new_fname == nullptr) { err = (imgtoolerr_t)(IMGTOOLERR_BADFILENAME | IMGTOOLERR_SRC_FUNCTIONALITY); @@ -1551,13 +1476,13 @@ imgtoolerr_t imgtool_partition_get_icon_info(imgtool_partition *partition, const path = new_fname; - /* cannonicalize path */ - err = cannonicalize_path(partition, 0, &path, &alloc_path); + // cannonicalize path + err = cannonicalize_path(0, &path, &alloc_path); if (err) goto done; memset(iconinfo, 0, sizeof(*iconinfo)); - err = partition->get_iconinfo(partition, path, iconinfo); + err = m_get_iconinfo(this, path, iconinfo); if (err) goto done; @@ -1570,14 +1495,13 @@ done: } +//------------------------------------------------- +// partition::suggest_file_filters - suggests a +// list of filters appropriate for a file on a +// partition +//------------------------------------------------- -/*------------------------------------------------- - imgtool_partition_suggest_file_filters - suggests - a list of filters appropriate for a file on a - partition --------------------------------------------------*/ - -imgtoolerr_t imgtool_partition_suggest_file_filters(imgtool_partition *partition, const char *path, +imgtoolerr_t imgtool::partition::suggest_file_filters(const char *path, imgtool_stream *stream, imgtool_transfer_suggestion *suggestions, size_t suggestions_length) { imgtoolerr_t err; @@ -1586,29 +1510,28 @@ imgtoolerr_t imgtool_partition_suggest_file_filters(imgtool_partition *partition imgtoolerr_t (*check_stream)(imgtool_stream *stream, imgtool_suggestion_viability_t *viability); size_t position; - /* clear out buffer */ + // clear out buffer memset(suggestions, 0, sizeof(*suggestions) * suggestions_length); - if (!partition->suggest_transfer) + if (!m_suggest_transfer) { err = (imgtoolerr_t)(IMGTOOLERR_UNIMPLEMENTED | IMGTOOLERR_SRC_FUNCTIONALITY); goto done; } - /* cannonicalize path */ - err = cannonicalize_path(partition, PATH_LEAVENULLALONE, &path, &alloc_path); + // cannonicalize path + err = cannonicalize_path(PATH_LEAVENULLALONE, &path, &alloc_path); if (err) goto done; - /* invoke the module's suggest call */ - err = partition->suggest_transfer(partition, path, suggestions, suggestions_length); + // invoke the module's suggest call + err = m_suggest_transfer(this, path, suggestions, suggestions_length); if (err) goto done; - /* Loop on resulting suggestions, and do the following: - * 1. Call check_stream if present, and remove disqualified streams - * 2. Fill in missing descriptions - */ + // loop on resulting suggestions, and do the following: + // 1. Call check_stream if present, and remove disqualified streams + // 2. Fill in missing descriptions i = j = 0; while(suggestions[i].viability) { @@ -1654,40 +1577,38 @@ done: } +//------------------------------------------------- +// partition::get_chain - retrieves the block +// chain for a file or directory on a partition +//------------------------------------------------- -/*------------------------------------------------- - imgtool_partition_get_chain - retrieves the block - chain for a file or directory on a partition --------------------------------------------------*/ - -imgtoolerr_t imgtool_partition_get_chain(imgtool_partition *partition, const char *path, imgtool_chainent *chain, size_t chain_size) +imgtoolerr_t imgtool::partition::get_chain(const char *path, imgtool_chainent *chain, size_t chain_size) { size_t i; assert(chain_size > 0); - if (!partition->get_chain) + if (!m_get_chain) return (imgtoolerr_t)(IMGTOOLERR_UNIMPLEMENTED | IMGTOOLERR_SRC_FUNCTIONALITY); - /* initialize the chain array, so the module's get_chain function can be lazy */ + // initialize the chain array, so the module's get_chain function can be lazy for (i = 0; i < chain_size; i++) { chain[i].level = 0; chain[i].block = ~0; } - return partition->get_chain(partition, path, chain, chain_size - 1); + return m_get_chain(this, path, chain, chain_size - 1); } +//------------------------------------------------- +// partition::get_chain_string - retrieves +// the block chain for a file or directory on a +// partition +//------------------------------------------------- -/*------------------------------------------------- - imgtool_partition_get_chain_string - retrieves - the block chain for a file or directory on a - partition --------------------------------------------------*/ - -imgtoolerr_t imgtool_partition_get_chain_string(imgtool_partition *partition, const char *path, char *buffer, size_t buffer_len) +imgtoolerr_t imgtool::partition::get_chain_string(const char *path, char *buffer, size_t buffer_len) { imgtoolerr_t err; imgtool_chainent chain[512]; @@ -1696,11 +1617,11 @@ imgtoolerr_t imgtool_partition_get_chain_string(imgtool_partition *partition, co int len, i; int comma_needed = FALSE; - /* determine the last block identifier */ + // determine the last block identifier chain[0].block = ~0; last_block = chain[0].block; - err = imgtool_partition_get_chain(partition, path, chain, ARRAY_LENGTH(chain)); + err = get_chain(path, chain, ARRAY_LENGTH(chain)); if (err) return err; @@ -1751,43 +1672,38 @@ imgtoolerr_t imgtool_partition_get_chain_string(imgtool_partition *partition, co } +//------------------------------------------------- +// partition::get_free_space - returns the +// amount of free space on a partition +//------------------------------------------------- -/*------------------------------------------------- - imgtool_partition_get_free_space - returns the - amount of free space on a partition --------------------------------------------------*/ - -imgtoolerr_t imgtool_partition_get_free_space(imgtool_partition *partition, UINT64 *sz) +imgtoolerr_t imgtool::partition::get_free_space(UINT64 &sz) { imgtoolerr_t err; - UINT64 size; - if (!partition->free_space) + if (!m_free_space) return (imgtoolerr_t)(IMGTOOLERR_UNIMPLEMENTED | IMGTOOLERR_SRC_FUNCTIONALITY); - err = partition->free_space(partition, &size); + err = m_free_space(this, &sz); if (err) return (imgtoolerr_t)(err | IMGTOOLERR_SRC_IMAGEFILE); - if (sz) - *sz = size; return IMGTOOLERR_SUCCESS; } +//------------------------------------------------- +// partition::read_file - starts reading +// from a file on a partition with a stream +//------------------------------------------------- -/*------------------------------------------------- - imgtool_partition_read_file - starts reading - from a file on a partition with a stream --------------------------------------------------*/ - -imgtoolerr_t imgtool_partition_read_file(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *destf, filter_getinfoproc filter) +imgtoolerr_t imgtool::partition::read_file(const char *filename, const char *fork, imgtool_stream *destf, filter_getinfoproc filter) { imgtoolerr_t err; char *alloc_path = nullptr; union filterinfo u; - if (!partition->read_file) + if (!m_read_file) { err = (imgtoolerr_t)(IMGTOOLERR_UNIMPLEMENTED | IMGTOOLERR_SRC_FUNCTIONALITY); goto done; @@ -1795,7 +1711,7 @@ imgtoolerr_t imgtool_partition_read_file(imgtool_partition *partition, const cha if (filter) { - /* use a filter */ + // use a filter filter(FILTINFO_PTR_READFILE, &u); if (!u.read_file) { @@ -1803,7 +1719,7 @@ imgtoolerr_t imgtool_partition_read_file(imgtool_partition *partition, const cha goto done; } - err = u.read_file(partition, filename, fork, destf); + err = u.read_file(this, filename, fork, destf); if (err) { err = markerrorsource(err); @@ -1812,17 +1728,17 @@ imgtoolerr_t imgtool_partition_read_file(imgtool_partition *partition, const cha } else { - /* cannonicalize path */ - err = cannonicalize_path(partition, PATH_CANBEBOOTBLOCK, &filename, &alloc_path); + // cannonicalize path + err = cannonicalize_path(PATH_CANBEBOOTBLOCK, &filename, &alloc_path); if (err) goto done; - err = cannonicalize_fork(partition, &fork); + err = cannonicalize_fork(&fork); if (err) goto done; - /* invoke the actual module */ - err = partition->read_file(partition, filename, fork, destf); + // invoke the actual module + err = m_read_file(this, filename, fork, destf); if (err) { err = markerrorsource(err); @@ -1837,13 +1753,12 @@ done: } +//------------------------------------------------- +// partition::write_file - starts writing +// to a new file on an image with a stream +//------------------------------------------------- -/*------------------------------------------------- - imgtool_partition_write_file - starts writing - to a new file on an image with a stream --------------------------------------------------*/ - -imgtoolerr_t imgtool_partition_write_file(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts, filter_getinfoproc filter) +imgtoolerr_t imgtool::partition::write_file(const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts, filter_getinfoproc filter) { imgtoolerr_t err; char *buf = nullptr; @@ -1854,7 +1769,7 @@ imgtoolerr_t imgtool_partition_write_file(imgtool_partition *partition, const ch UINT64 file_size; union filterinfo u; - if (!partition->write_file) + if (!m_write_file) { err = (imgtoolerr_t)(IMGTOOLERR_UNIMPLEMENTED | IMGTOOLERR_SRC_FUNCTIONALITY); goto done; @@ -1862,7 +1777,7 @@ imgtoolerr_t imgtool_partition_write_file(imgtool_partition *partition, const ch if (filter) { - /* use a filter */ + // use a filter filter(FILTINFO_PTR_WRITEFILE, &u); if (!u.write_file) { @@ -1870,7 +1785,7 @@ imgtoolerr_t imgtool_partition_write_file(imgtool_partition *partition, const ch goto done; } - err = u.write_file(partition, filename, fork, sourcef, opts); + err = u.write_file(this, filename, fork, sourcef, opts); if (err) { err = markerrorsource(err); @@ -1879,8 +1794,8 @@ imgtoolerr_t imgtool_partition_write_file(imgtool_partition *partition, const ch } else { - /* does this partition prefer upper case file names? */ - if (partition->prefer_ucase) + // does this partition prefer upper case file names? + if (m_prefer_ucase) { buf = (char*)malloc(strlen(filename) + 1); if (!buf) @@ -1894,33 +1809,33 @@ imgtoolerr_t imgtool_partition_write_file(imgtool_partition *partition, const ch filename = buf; } - /* cannonicalize path */ - err = cannonicalize_path(partition, PATH_CANBEBOOTBLOCK, &filename, &alloc_path); + // cannonicalize path + err = cannonicalize_path(PATH_CANBEBOOTBLOCK, &filename, &alloc_path); if (err) goto done; - err = cannonicalize_fork(partition, &fork); + err = cannonicalize_fork(&fork); if (err) goto done; - /* allocate dummy options if necessary */ - if (!opts && partition->writefile_optguide) + // allocate dummy options if necessary + if (!opts && m_writefile_optguide) { - try { alloc_resolution.reset(new util::option_resolution(*partition->writefile_optguide)); } + try { alloc_resolution.reset(new util::option_resolution(*m_writefile_optguide)); } catch (...) { err = IMGTOOLERR_OUTOFMEMORY; goto done; } - if (partition->writefile_optspec) - alloc_resolution->set_specification(partition->writefile_optspec); + if (!m_writefile_optspec.empty()) + alloc_resolution->set_specification(m_writefile_optspec); opts = alloc_resolution.get(); } - /* if free_space is implemented; do a quick check to see if space is available */ - if (partition->free_space) + // if free_space is implemented; do a quick check to see if space is available + if (m_free_space) { - err = partition->free_space(partition, &free_space); + err = m_free_space(this, &free_space); if (err) { err = markerrorsource(err); @@ -1936,8 +1851,8 @@ imgtoolerr_t imgtool_partition_write_file(imgtool_partition *partition, const ch } } - /* actually invoke the write file handler */ - err = partition->write_file(partition, filename, fork, sourcef, opts); + // actually invoke the write file handler + err = m_write_file(this, filename, fork, sourcef, opts); if (err) { err = markerrorsource(err); @@ -1954,13 +1869,12 @@ done: } +//------------------------------------------------- +// partition::get_file - read a file from +// an image, storing it into a native file +//------------------------------------------------- -/*------------------------------------------------- - imgtool_partition_get_file - read a file from - an image, storing it into a native file --------------------------------------------------*/ - -imgtoolerr_t imgtool_partition_get_file(imgtool_partition *partition, const char *filename, const char *fork, +imgtoolerr_t imgtool::partition::get_file(const char *filename, const char *fork, const char *dest, filter_getinfoproc filter) { imgtoolerr_t err; @@ -1971,7 +1885,7 @@ imgtoolerr_t imgtool_partition_get_file(imgtool_partition *partition, const char if (!dest) { - /* determine the filter extension, if appropriate */ + // determine the filter extension, if appropriate if (filter != nullptr) filter_extension = filter_get_info_string(filter, FILTINFO_STR_EXTENSION); @@ -2000,14 +1914,14 @@ imgtoolerr_t imgtool_partition_get_file(imgtool_partition *partition, const char goto done; } - new_fname = normalize_filename(partition, filename); + new_fname = normalize_filename(filename); if (new_fname == nullptr) { err = (imgtoolerr_t)(IMGTOOLERR_BADFILENAME | IMGTOOLERR_SRC_FUNCTIONALITY); goto done; } - err = imgtool_partition_read_file(partition, new_fname, fork, f, filter); + err = read_file(new_fname, fork, f, filter); if (err) goto done; @@ -2022,13 +1936,12 @@ done: } +//------------------------------------------------- +// partition::put_file - read a native file +// and store it on a partition +//------------------------------------------------- -/*------------------------------------------------- - imgtool_partition_put_file - read a native file - and store it on a partition --------------------------------------------------*/ - -imgtoolerr_t imgtool_partition_put_file(imgtool_partition *partition, const char *newfname, const char *fork, +imgtoolerr_t imgtool::partition::put_file(const char *newfname, const char *fork, const char *source, util::option_resolution *opts, filter_getinfoproc filter) { imgtoolerr_t err; @@ -2043,7 +1956,7 @@ imgtoolerr_t imgtool_partition_put_file(imgtool_partition *partition, const char newfname = basename.c_str(); } - charset = (imgtool_charset) (int) imgtool_partition_get_info_int(partition, IMGTOOLINFO_INT_CHARSET); + charset = (imgtool_charset) (int) get_info_int(IMGTOOLINFO_INT_CHARSET); if (charset != IMGTOOL_CHARSET_UTF8) { /* convert to native format */ @@ -2059,7 +1972,7 @@ imgtoolerr_t imgtool_partition_put_file(imgtool_partition *partition, const char f = stream_open(source, OSD_FOPEN_READ); if (f) - err = imgtool_partition_write_file(partition, newfname, fork, f, opts, filter); + err = write_file(newfname, fork, f, opts, filter); else err = (imgtoolerr_t)(IMGTOOLERR_FILENOTFOUND | IMGTOOLERR_SRC_NATIVEFILE); @@ -2075,23 +1988,23 @@ done: /*------------------------------------------------- - imgtool_partition_delete_file - delete a file + imgtool::partition::delete_file - delete a file on a partition -------------------------------------------------*/ -imgtoolerr_t imgtool_partition_delete_file(imgtool_partition *partition, const char *fname) +imgtoolerr_t imgtool::partition::delete_file(const char *fname) { imgtoolerr_t err; char *alloc_path = nullptr; char *new_fname = nullptr; - if (!partition->delete_file) + if (!m_delete_file) { err = (imgtoolerr_t)(IMGTOOLERR_UNIMPLEMENTED | IMGTOOLERR_SRC_FUNCTIONALITY); goto done; } - new_fname = normalize_filename(partition, fname); + new_fname = normalize_filename(fname); if (new_fname == nullptr) { err = (imgtoolerr_t)(IMGTOOLERR_BADFILENAME | IMGTOOLERR_SRC_FUNCTIONALITY); @@ -2100,12 +2013,12 @@ imgtoolerr_t imgtool_partition_delete_file(imgtool_partition *partition, const c fname = new_fname; - /* cannonicalize path */ - err = cannonicalize_path(partition, 0, &fname, &alloc_path); + // cannonicalize path + err = cannonicalize_path(0, &fname, &alloc_path); if (err) goto done; - err = partition->delete_file(partition, fname); + err = m_delete_file(this, fname); if (err) { err = markerrorsource(err); @@ -2121,25 +2034,24 @@ done: } +//------------------------------------------------- +// partition::list_file_forks - lists all +// forks on an image +//------------------------------------------------- -/*------------------------------------------------- - imgtool_partition_list_file_forks - lists all - forks on an image --------------------------------------------------*/ - -imgtoolerr_t imgtool_partition_list_file_forks(imgtool_partition *partition, const char *path, imgtool_forkent *ents, size_t len) +imgtoolerr_t imgtool::partition::list_file_forks(const char *path, imgtool_forkent *ents, size_t len) { imgtoolerr_t err; char *alloc_path = nullptr; char *new_fname = nullptr; - if (!partition->list_forks) + if (!m_list_forks) { err = (imgtoolerr_t)(IMGTOOLERR_UNIMPLEMENTED | IMGTOOLERR_SRC_FUNCTIONALITY); goto done; } - new_fname = normalize_filename(partition, path); + new_fname = normalize_filename(path); if (new_fname == nullptr) { err = (imgtoolerr_t)(IMGTOOLERR_BADFILENAME | IMGTOOLERR_SRC_FUNCTIONALITY); @@ -2148,12 +2060,12 @@ imgtoolerr_t imgtool_partition_list_file_forks(imgtool_partition *partition, con path = new_fname; - /* cannonicalize path */ - err = cannonicalize_path(partition, 0, &path, &alloc_path); + // cannonicalize path + err = cannonicalize_path(0, &path, &alloc_path); if (err) goto done; - err = partition->list_forks(partition, path, ents, len); + err = m_list_forks(this, path, ents, len); if (err) goto done; @@ -2166,26 +2078,25 @@ done: } +//------------------------------------------------- +// partition::create_directory - creates a +// directory on a partition +//------------------------------------------------- -/*------------------------------------------------- - imgtool_partition_create_directory - creates a - directory on a partition --------------------------------------------------*/ - -imgtoolerr_t imgtool_partition_create_directory(imgtool_partition *partition, const char *path) +imgtoolerr_t imgtool::partition::create_directory(const char *path) { imgtoolerr_t err; char *alloc_path = nullptr; char *new_path = nullptr; - /* implemented? */ - if (!partition->create_dir) + // implemented? + if (!m_create_dir) { err = (imgtoolerr_t)(IMGTOOLERR_UNIMPLEMENTED | IMGTOOLERR_SRC_FUNCTIONALITY); goto done; } - new_path = normalize_filename(partition, path); + new_path = normalize_filename(path); if (new_path == nullptr) { err = (imgtoolerr_t)(IMGTOOLERR_BADFILENAME | IMGTOOLERR_SRC_FUNCTIONALITY); @@ -2194,12 +2105,12 @@ imgtoolerr_t imgtool_partition_create_directory(imgtool_partition *partition, co path = new_path; - /* cannonicalize path */ - err = cannonicalize_path(partition, PATH_MUSTBEDIR, &path, &alloc_path); + // cannonicalize path + err = cannonicalize_path(PATH_MUSTBEDIR, &path, &alloc_path); if (err) goto done; - err = partition->create_dir(partition, path); + err = m_create_dir(this, path); if (err) goto done; @@ -2212,26 +2123,25 @@ done: } +//------------------------------------------------- +// partition::delete_directory - deletes a +// directory on a partition +//------------------------------------------------- -/*------------------------------------------------- - imgtool_partition_delete_directory - deletes a - directory on a partition --------------------------------------------------*/ - -imgtoolerr_t imgtool_partition_delete_directory(imgtool_partition *partition, const char *path) +imgtoolerr_t imgtool::partition::delete_directory(const char *path) { imgtoolerr_t err; char *alloc_path = nullptr; char *new_path = nullptr; - /* implemented? */ - if (!partition->delete_dir) + // implemented? + if (!m_delete_dir) { err = (imgtoolerr_t)(IMGTOOLERR_UNIMPLEMENTED | IMGTOOLERR_SRC_FUNCTIONALITY); goto done; } - new_path = normalize_filename(partition, path); + new_path = normalize_filename(path); if (new_path == nullptr) { err = (imgtoolerr_t)(IMGTOOLERR_BADFILENAME | IMGTOOLERR_SRC_FUNCTIONALITY); @@ -2240,12 +2150,12 @@ imgtoolerr_t imgtool_partition_delete_directory(imgtool_partition *partition, co path = new_path; - /* cannonicalize path */ - err = cannonicalize_path(partition, PATH_MUSTBEDIR, &path, &alloc_path); + // cannonicalize path + err = cannonicalize_path(PATH_MUSTBEDIR, &path, &alloc_path); if (err) goto done; - err = partition->delete_dir(partition, path); + err = m_delete_dir(this, path); if (err) goto done; @@ -2258,75 +2168,91 @@ done: } +//------------------------------------------------- +// partition::get_block_size - gets the +// size of a standard block on a partition +//------------------------------------------------- -/*------------------------------------------------- - imgtool_partition_get_block_size - gets the - size of a standard block on a partition --------------------------------------------------*/ - -imgtoolerr_t imgtool_partition_get_block_size(imgtool_partition *partition, UINT32 &length) +imgtoolerr_t imgtool::partition::get_block_size(UINT32 &length) { - return partition->image->get_block_size(length); + return m_image.get_block_size(length); } +//------------------------------------------------- +// partition::is_block_in_range +//------------------------------------------------- -/*------------------------------------------------- - imgtool_partition_read_block - reads a standard - block on a partition --------------------------------------------------*/ - -imgtoolerr_t imgtool_partition_read_block(imgtool_partition *partition, UINT64 block, void *buffer) +imgtoolerr_t imgtool::partition::map_block_to_image_block(UINT64 partition_block, UINT64 &image_block) const { - if (block >= partition->block_count) + if (partition_block >= m_block_count) return IMGTOOLERR_SEEKERROR; - return partition->image->read_block(block + partition->base_block, buffer); + + image_block = m_base_block + partition_block; + return IMGTOOLERR_SUCCESS; } +//------------------------------------------------- +// partition::read_block - reads a standard +// block on a partition +//------------------------------------------------- -/*------------------------------------------------- - imgtool_partition_write_block - writes a - standard block on a partition --------------------------------------------------*/ - -imgtoolerr_t imgtool_partition_write_block(imgtool_partition *partition, UINT64 block, const void *buffer) +imgtoolerr_t imgtool::partition::read_block(UINT64 block, void *buffer) { - if (block >= partition->block_count) - return IMGTOOLERR_SEEKERROR; - return partition->image->write_block(block + partition->base_block, buffer); + UINT64 image_block; + imgtoolerr_t err = map_block_to_image_block(block, image_block); + if (err) + return err; + + return m_image.read_block(image_block, buffer); } +//------------------------------------------------- +// partition::write_block - writes a +// standard block on a partition +//------------------------------------------------- -/*------------------------------------------------- - imgtool_partition_get_features - retrieves a - structure identifying this partition's features - associated with an image --------------------------------------------------*/ +imgtoolerr_t imgtool::partition::write_block(UINT64 block, const void *buffer) +{ + UINT64 image_block; + imgtoolerr_t err = map_block_to_image_block(block, image_block); + if (err) + return err; -imgtool_partition_features imgtool_partition_get_features(imgtool_partition *partition) + return m_image.write_block(image_block, buffer); +} + + +//------------------------------------------------- +// partition::get_features - retrieves a +// structure identifying this partition's features +// associated with an image +//------------------------------------------------- + +imgtool_partition_features imgtool::partition::get_features() const { imgtool_partition_features features; memset(&features, 0, sizeof(features)); - if (partition->read_file) + if (m_read_file) features.supports_reading = 1; - if (partition->write_file) + if (m_write_file) features.supports_writing = 1; - if (partition->delete_file) + if (m_delete_file) features.supports_deletefile = 1; - if (partition->path_separator) + if (m_path_separator) features.supports_directories = 1; - if (partition->free_space) + if (m_free_space) features.supports_freespace = 1; - if (partition->create_dir) + if (m_create_dir) features.supports_createdir = 1; - if (partition->delete_dir) + if (m_delete_dir) features.supports_deletedir = 1; - if (partition->supports_creation_time) + if (m_supports_creation_time) features.supports_creation_time = 1; - if (partition->supports_lastmodified_time) + if (m_supports_lastmodified_time) features.supports_lastmodified_time = 1; if (!features.supports_writing && !features.supports_createdir && !features.supports_deletefile && !features.supports_deletedir) features.is_read_only = 1; @@ -2334,90 +2260,72 @@ imgtool_partition_features imgtool_partition_get_features(imgtool_partition *par } +//------------------------------------------------- +// partition::get_info_ptr - retrieves a +// pointer associated with a partition's format +//------------------------------------------------- -/*------------------------------------------------- - imgtool_partition_get_info_ptr - retrieves a - pointer associated with a partition's format --------------------------------------------------*/ - -void *imgtool_partition_get_info_ptr(imgtool_partition *partition, UINT32 state) +void *imgtool::partition::get_info_ptr(UINT32 state) { - return imgtool_get_info_ptr(&partition->imgclass, state); + return imgtool_get_info_ptr(&m_imgclass, state); } +//------------------------------------------------- +// partition::get_info_string - retrieves a +// string associated with a partition's format +//------------------------------------------------- -/*------------------------------------------------- - imgtool_partition_get_info_string - retrieves a - string associated with a partition's format --------------------------------------------------*/ - -const char *imgtool_partition_get_info_string(imgtool_partition *partition, UINT32 state) +const char *imgtool::partition::get_info_string(UINT32 state) { - return imgtool_get_info_string(&partition->imgclass, state); + return imgtool_get_info_string(&m_imgclass, state); } +//------------------------------------------------- +// partition::get_info_int - retrieves a +// pointer associated with a partition's format +//------------------------------------------------- -/*------------------------------------------------- - imgtool_partition_get_info_int - retrieves a - pointer associated with a partition's format --------------------------------------------------*/ - -UINT64 imgtool_partition_get_info_int(imgtool_partition *partition, UINT32 state) +UINT64 imgtool::partition::get_info_int(UINT32 state) { - return imgtool_get_info_int(&partition->imgclass, state); + return imgtool_get_info_int(&m_imgclass, state); } +//------------------------------------------------- +// partition::extra_bytes - returns extra +// bytes on a partition +//------------------------------------------------- -/*------------------------------------------------- - imgtool_partition_extra_bytes - returns extra - bytes on a partition --------------------------------------------------*/ - -void *imgtool_partition_extra_bytes(imgtool_partition *partition) +void *imgtool::partition::extra_bytes() { - void *ptr = nullptr; - if (partition->partition_extra_bytes > 0) - ptr = ((UINT8 *) partition) + sizeof(*partition); - assert(ptr); - return ptr; + if (!m_extra_bytes) + throw false; + return m_extra_bytes.get(); } - -/*------------------------------------------------- - imgtool_partition_rand - returns random number --------------------------------------------------*/ - -UINT64 imgtool_partition_rand(imgtool_partition *partition) -{ - return imgtool::image::rand(); -} - - - /*************************************************************************** Path handling functions ***************************************************************************/ -/*------------------------------------------------- - imgtool_partition_get_root_path - retrieves - the path root of this partition --------------------------------------------------*/ +//------------------------------------------------- +// partition::get_root_path - retrieves +// the path root of this partition +//------------------------------------------------- -const char *imgtool_partition_get_root_path(imgtool_partition *partition) +const char *imgtool::partition::get_root_path() { int initial_path_separator; char path_separator; char *buf; int pos = 0; - initial_path_separator = imgtool_partition_get_info_int(partition, IMGTOOLINFO_INT_INITIAL_PATH_SEPARATOR) ? 1 : 0; - path_separator = (char) imgtool_partition_get_info_int(partition, IMGTOOLINFO_INT_PATH_SEPARATOR); + initial_path_separator = get_info_int(IMGTOOLINFO_INT_INITIAL_PATH_SEPARATOR) ? 1 : 0; + path_separator = (char) get_info_int(IMGTOOLINFO_INT_PATH_SEPARATOR); buf = imgtool_temp_str(); if (initial_path_separator) @@ -2427,20 +2335,19 @@ const char *imgtool_partition_get_root_path(imgtool_partition *partition) } +//------------------------------------------------- +// partition::path_concatenate - retrieves +// a pointer associated with a partition's format +//------------------------------------------------- -/*------------------------------------------------- - imgtool_partition_path_concatenate - retrieves - a pointer associated with a partition's format --------------------------------------------------*/ - -const char *imgtool_partition_path_concatenate(imgtool_partition *partition, const char *path1, const char *path2) +const char *imgtool::partition::path_concatenate(const char *path1, const char *path2) { char path_separator; size_t len; char *buffer; size_t buffer_len; - path_separator = (char) imgtool_partition_get_info_int(partition, IMGTOOLINFO_INT_PATH_SEPARATOR); + path_separator = (char) get_info_int(IMGTOOLINFO_INT_PATH_SEPARATOR); len = strlen(path1); /* prepare buffer */ @@ -2476,19 +2383,18 @@ const char *imgtool_partition_path_concatenate(imgtool_partition *partition, con } +//------------------------------------------------- +// partition::get_base_name - retrieves +// a base name for a partition specific path +//------------------------------------------------- -/*------------------------------------------------- - imgtool_partition_get_base_name - retrieves - a base name for a partition specific path --------------------------------------------------*/ - -const char *imgtool_partition_get_base_name(imgtool_partition *partition, const char *path) +const char *imgtool::partition::get_base_name(const char *path) { char path_separator; const char *new_path = path; int i; - path_separator = (char) imgtool_partition_get_info_int(partition, IMGTOOLINFO_INT_PATH_SEPARATOR); + path_separator = (char) get_info_int(IMGTOOLINFO_INT_PATH_SEPARATOR); for (i = 0; path[i]; i++) { @@ -2506,51 +2412,59 @@ const char *imgtool_partition_get_base_name(imgtool_partition *partition, const ***************************************************************************/ -/*------------------------------------------------- - imgtool_directory_open - begins - enumerating files on a partition --------------------------------------------------*/ +//------------------------------------------------- +// directory ctor +//------------------------------------------------- -imgtoolerr_t imgtool_directory_open(imgtool_partition *partition, const char *path, imgtool_directory **outenum) +imgtool::directory::directory(imgtool::partition &partition) + : m_partition(partition) + , m_okay_to_close(false) +{ + if (partition.m_directory_extra_bytes > 0) + { + m_extra_bytes = std::make_unique(partition.m_directory_extra_bytes); + memset(m_extra_bytes.get(), 0, sizeof(m_extra_bytes.get()[0] * partition.m_directory_extra_bytes)); + } +} + + +//------------------------------------------------- +// directory::open - begins +// enumerating files on a partition +//------------------------------------------------- + +imgtoolerr_t imgtool::directory::open(imgtool::partition &partition, const char *path, imgtool::directory::ptr &outenum) { imgtoolerr_t err = (imgtoolerr_t)IMGTOOLERR_SUCCESS; - imgtool_directory *enumeration = nullptr; + imgtool::directory::ptr enumeration; char *alloc_path = nullptr; char *new_path = nullptr; - size_t size; - /* sanity checks */ - assert(partition); - assert(outenum); + outenum.reset(); - *outenum = nullptr; - - if (!partition->next_enum) + if (!partition.m_next_enum) { err = (imgtoolerr_t)(IMGTOOLERR_UNIMPLEMENTED | IMGTOOLERR_SRC_FUNCTIONALITY); goto done; } - new_path = normalize_filename(partition, path); + new_path = partition.normalize_filename(path); path = new_path; - err = cannonicalize_path(partition, PATH_MUSTBEDIR, &path, &alloc_path); + err = partition.cannonicalize_path(PATH_MUSTBEDIR, &path, &alloc_path); if (err) goto done; - size = sizeof(imgtool_directory) + partition->directory_extra_bytes; - enumeration = (imgtool_directory *) malloc(size); - if (!enumeration) + try { enumeration = std::make_unique(partition); } + catch (std::bad_alloc const &) { err = (imgtoolerr_t)IMGTOOLERR_OUTOFMEMORY; goto done; } - memset(enumeration, '\0', size); - enumeration->partition = partition; - if (partition->begin_enum) + if (partition.m_begin_enum) { - err = partition->begin_enum(enumeration, path); + err = partition.m_begin_enum(enumeration.get(), path); if (err) { err = markerrorsource(err); @@ -2558,84 +2472,71 @@ imgtoolerr_t imgtool_directory_open(imgtool_partition *partition, const char *pa } } + enumeration->m_okay_to_close = true; + outenum = std::move(enumeration); + done: if (alloc_path != nullptr) free(alloc_path); if (new_path != nullptr) osd_free(new_path); - if (err && (enumeration != nullptr)) - { - free(enumeration); - enumeration = nullptr; - } - *outenum = enumeration; return err; } +//------------------------------------------------- +// directory dtor +//------------------------------------------------- -/*------------------------------------------------- - imgtool_directory_close - closes a directory --------------------------------------------------*/ - -void imgtool_directory_close(imgtool_directory *directory) +imgtool::directory::~directory() { - imgtool_partition *partition; - partition = imgtool_directory_partition(directory); - if (partition->close_enum) - partition->close_enum(directory); - free(directory); + if (m_okay_to_close && m_partition.m_close_enum) + m_partition.m_close_enum(this); } +//------------------------------------------------- +// directory::get_next - continues +// enumerating files within a partition +//------------------------------------------------- -/*------------------------------------------------- - imgtool_directory_get_next - continues - enumerating files within a partition --------------------------------------------------*/ - -imgtoolerr_t imgtool_directory_get_next(imgtool_directory *directory, imgtool_dirent *ent) +imgtoolerr_t imgtool::directory::get_next(imgtool_dirent &ent) { imgtoolerr_t err; - imgtool_partition *partition; - int charset; - partition = imgtool_directory_partition(directory); + // This makes it so that drivers don't have to take care of clearing + // the attributes if they don't apply + memset(&ent, 0, sizeof(ent)); - /* This makes it so that drivers don't have to take care of clearing - * the attributes if they don't apply - */ - memset(ent, 0, sizeof(*ent)); - - err = partition->next_enum(directory, ent); + err = m_partition.m_next_enum(this, &ent); if (err) return markerrorsource(err); - charset = imgtool_partition_get_info_int(partition, IMGTOOLINFO_INT_CHARSET); + int charset = m_partition.get_info_int(IMGTOOLINFO_INT_CHARSET); if (charset) { - char *new_fname = utf8_from_native((imgtool_charset)charset, ent->filename); + char *new_fname = utf8_from_native((imgtool_charset)charset, ent.filename); if (!new_fname) return IMGTOOLERR_BADFILENAME; - strcpy(ent->filename, new_fname); + snprintf(ent.filename, ARRAY_LENGTH(ent.filename), "%s", new_fname); osd_free(new_fname); } - /* don't trust the module! */ - if (!partition->supports_creation_time && (ent->creation_time != 0)) + // don't trust the module! + if (!m_partition.m_supports_creation_time && (ent.creation_time != 0)) { internal_error(nullptr, "next_enum() specified creation_time, which is marked as unsupported by this module"); return IMGTOOLERR_UNEXPECTED; } - if (!partition->supports_lastmodified_time && (ent->lastmodified_time != 0)) + if (!m_partition.m_supports_lastmodified_time && (ent.lastmodified_time != 0)) { internal_error(nullptr, "next_enum() specified lastmodified_time, which is marked as unsupported by this module"); return IMGTOOLERR_UNEXPECTED; } - if (!partition->path_separator && ent->directory) + if (!m_partition.m_path_separator && ent.directory) { internal_error(nullptr, "next_enum() returned a directory, which is marked as unsupported by this module"); return IMGTOOLERR_UNEXPECTED; @@ -2644,60 +2545,10 @@ imgtoolerr_t imgtool_directory_get_next(imgtool_directory *directory, imgtool_di } - -/*------------------------------------------------- - imgtool_directory_module - returns the module associated - with this directory --------------------------------------------------*/ - -const imgtool_module *imgtool_directory_module(imgtool_directory *directory) -{ - return &directory->partition->image->module(); -} - - - -/*------------------------------------------------- - imgtool_directory_extrabytes - returns extra - bytes on a directory --------------------------------------------------*/ - -void *imgtool_directory_extrabytes(imgtool_directory *directory) -{ - assert(directory->partition->directory_extra_bytes > 0); - return ((UINT8 *) directory) + sizeof(*directory); -} - - - -/*------------------------------------------------- - imgtool_directory_partition - returns the - partition associated with this directory --------------------------------------------------*/ - -imgtool_partition *imgtool_directory_partition(imgtool_directory *directory) -{ - return directory->partition; -} - - - -/*------------------------------------------------- - imgtool_directory_image - returns the image - associated with this directory --------------------------------------------------*/ - -imgtool::image *imgtool_directory_image(imgtool_directory *directory) -{ - return directory->partition->image; -} - - - -/*------------------------------------------------- - unknown_partition_get_info - represents an - unknown partition --------------------------------------------------*/ +//------------------------------------------------- +// unknown_partition_get_info - represents an +// unknown partition +//------------------------------------------------- void unknown_partition_get_info(const imgtool_class *imgclass, UINT32 state, union imgtoolinfo *info) { diff --git a/src/tools/imgtool/imgtool.h b/src/tools/imgtool/imgtool.h index e9da350a050..3d6e9a675eb 100644 --- a/src/tools/imgtool/imgtool.h +++ b/src/tools/imgtool/imgtool.h @@ -133,56 +133,132 @@ namespace imgtool }; } -/* ----- partition management ----- */ -imgtoolerr_t imgtool_partition_open(imgtool::image *image, int partition_index, imgtool_partition **partition); -void imgtool_partition_close(imgtool_partition *partition); -imgtool::image *imgtool_partition_image(imgtool_partition *partition); +namespace imgtool +{ + // ----- partition management ----- + class partition + { + friend class directory; + public: + typedef std::unique_ptr ptr; -/* ----- partition operations ----- */ -imgtoolerr_t imgtool_partition_get_directory_entry(imgtool_partition *partition, const char *path, int index, imgtool_dirent *ent); -imgtoolerr_t imgtool_partition_get_file_size(imgtool_partition *partition, const char *filename, UINT64 *filesize); -imgtoolerr_t imgtool_partition_get_free_space(imgtool_partition *partition, UINT64 *sz); -imgtoolerr_t imgtool_partition_read_file(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *destf, filter_getinfoproc filter); -imgtoolerr_t imgtool_partition_write_file(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *resolution, filter_getinfoproc filter); -imgtoolerr_t imgtool_partition_get_file(imgtool_partition *partition, const char *filename, const char *fork, const char *dest, filter_getinfoproc filter); -imgtoolerr_t imgtool_partition_put_file(imgtool_partition *partition, const char *newfname, const char *fork, const char *source, util::option_resolution *opts, filter_getinfoproc filter); -imgtoolerr_t imgtool_partition_delete_file(imgtool_partition *partition, const char *fname); -imgtoolerr_t imgtool_partition_list_file_forks(imgtool_partition *partition, const char *path, imgtool_forkent *ents, size_t len); -imgtoolerr_t imgtool_partition_create_directory(imgtool_partition *partition, const char *path); -imgtoolerr_t imgtool_partition_delete_directory(imgtool_partition *partition, const char *path); -imgtoolerr_t imgtool_partition_list_file_attributes(imgtool_partition *partition, const char *path, UINT32 *attrs, size_t len); -imgtoolerr_t imgtool_partition_get_file_attributes(imgtool_partition *partition, const char *path, const UINT32 *attrs, imgtool_attribute *values); -imgtoolerr_t imgtool_partition_put_file_attributes(imgtool_partition *partition, const char *path, const UINT32 *attrs, const imgtool_attribute *values); -imgtoolerr_t imgtool_partition_get_file_attribute(imgtool_partition *partition, const char *path, UINT32 attr, imgtool_attribute *value); -imgtoolerr_t imgtool_partition_put_file_attribute(imgtool_partition *partition, const char *path, UINT32 attr, imgtool_attribute value); -void imgtool_partition_get_attribute_name(imgtool_partition *partition, UINT32 attribute, const imgtool_attribute *attr_value, char *buffer, size_t buffer_len); -imgtoolerr_t imgtool_partition_get_icon_info(imgtool_partition *partition, const char *path, imgtool_iconinfo *iconinfo); -imgtoolerr_t imgtool_partition_suggest_file_filters(imgtool_partition *partition, const char *path, imgtool_stream *stream, imgtool_transfer_suggestion *suggestions, size_t suggestions_length); -imgtoolerr_t imgtool_partition_get_block_size(imgtool_partition *partition, UINT32 &length); -imgtoolerr_t imgtool_partition_read_block(imgtool_partition *partition, UINT64 block, void *buffer); -imgtoolerr_t imgtool_partition_write_block(imgtool_partition *partition, UINT64 block, const void *buffer); -imgtoolerr_t imgtool_partition_get_chain(imgtool_partition *partition, const char *path, imgtool_chainent *chain, size_t chain_size); -imgtoolerr_t imgtool_partition_get_chain_string(imgtool_partition *partition, const char *path, char *buffer, size_t buffer_len); -imgtool_partition_features imgtool_partition_get_features(imgtool_partition *partition); -void * imgtool_partition_get_info_ptr(imgtool_partition *partition, UINT32 state); -const char * imgtool_partition_get_info_string(imgtool_partition *partition, UINT32 state); -UINT64 imgtool_partition_get_info_int(imgtool_partition *partition, UINT32 state); -void * imgtool_partition_extra_bytes(imgtool_partition *partition); -UINT64 imgtool_partition_rand(imgtool_partition *partition); + // ctor/dtor + partition(imgtool::image &image, imgtool_class &imgclass, int partition_index, UINT64 base_block, UINT64 block_count); + ~partition(); -/* ----- path management ----- */ -const char * imgtool_partition_get_root_path(imgtool_partition *partition); -const char * imgtool_partition_path_concatenate(imgtool_partition *partition, const char *path1, const char *path2); -const char * imgtool_partition_get_base_name(imgtool_partition *partition, const char *path); + static imgtoolerr_t open(imgtool::image &image, int partition_index, ptr &partition); + image &image() { return m_image; } -/* ----- directory management ----- */ -imgtoolerr_t imgtool_directory_open(imgtool_partition *partition, const char *path, imgtool_directory **outenum); -void imgtool_directory_close(imgtool_directory *enumeration); -imgtoolerr_t imgtool_directory_get_next(imgtool_directory *enumeration, imgtool_dirent *ent); -const imgtool_module *imgtool_directory_module(imgtool_directory *enumeration); -void *imgtool_directory_extrabytes(imgtool_directory *enumeration); -imgtool_partition *imgtool_directory_partition(imgtool_directory *directory); -imgtool::image *imgtool_directory_image(imgtool_directory *enumeration); + // ----- partition operations ----- + imgtoolerr_t get_directory_entry(const char *path, int index, imgtool_dirent &ent); + imgtoolerr_t get_file_size(const char *filename, UINT64 &filesize); + imgtoolerr_t get_free_space(UINT64 &sz); + imgtoolerr_t read_file(const char *filename, const char *fork, imgtool_stream *destf, filter_getinfoproc filter); + imgtoolerr_t write_file(const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *resolution, filter_getinfoproc filter); + imgtoolerr_t get_file(const char *filename, const char *fork, const char *dest, filter_getinfoproc filter); + imgtoolerr_t put_file(const char *newfname, const char *fork, const char *source, util::option_resolution *opts, filter_getinfoproc filter); + imgtoolerr_t delete_file(const char *fname); + imgtoolerr_t list_file_forks(const char *path, imgtool_forkent *ents, size_t len); + imgtoolerr_t create_directory(const char *path); + imgtoolerr_t delete_directory(const char *path); + imgtoolerr_t list_file_attributes(const char *path, UINT32 *attrs, size_t len); + imgtoolerr_t get_file_attributes(const char *path, const UINT32 *attrs, imgtool_attribute *values); + imgtoolerr_t put_file_attributes(const char *path, const UINT32 *attrs, const imgtool_attribute *values); + imgtoolerr_t get_file_attribute(const char *path, UINT32 attr, imgtool_attribute &value); + imgtoolerr_t put_file_attribute(const char *path, UINT32 attr, const imgtool_attribute &value); + void get_attribute_name(UINT32 attribute, const imgtool_attribute *attr_value, char *buffer, size_t buffer_len); + imgtoolerr_t get_icon_info(const char *path, imgtool_iconinfo *iconinfo); + imgtoolerr_t suggest_file_filters(const char *path, imgtool_stream *stream, imgtool_transfer_suggestion *suggestions, size_t suggestions_length); + imgtoolerr_t get_block_size(UINT32 &length); + imgtoolerr_t read_block(UINT64 block, void *buffer); + imgtoolerr_t write_block(UINT64 block, const void *buffer); + imgtoolerr_t get_chain(const char *path, imgtool_chainent *chain, size_t chain_size); + imgtoolerr_t get_chain_string(const char *path, char *buffer, size_t buffer_len); + imgtool_partition_features get_features() const; + void * get_info_ptr(UINT32 state); + const char * get_info_string(UINT32 state); + UINT64 get_info_int(UINT32 state); + void * extra_bytes(); + + // ----- path management ----- + const char * get_root_path(); + const char * path_concatenate(const char *path1, const char *path2); + const char * get_base_name(const char *path); + + private: + imgtool::image &m_image; + int m_partition_index; + UINT64 m_base_block; + UINT64 m_block_count; + + imgtool_class m_imgclass; + size_t m_partition_extra_bytes; + size_t m_directory_extra_bytes; + + char m_path_separator; + char m_alternate_path_separator; + + unsigned int m_prefer_ucase : 1; + unsigned int m_supports_creation_time : 1; + unsigned int m_supports_lastmodified_time : 1; + unsigned int m_supports_bootblock : 1; /* this module supports loading/storing the boot block */ + + imgtoolerr_t(*m_begin_enum) (imgtool::directory *enumeration, const char *path); + imgtoolerr_t(*m_next_enum) (imgtool::directory *enumeration, imgtool_dirent *ent); + void(*m_close_enum) (imgtool::directory *enumeration); + imgtoolerr_t(*m_free_space) (imgtool::partition *partition, UINT64 *size); + imgtoolerr_t(*m_read_file) (imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *destf); + imgtoolerr_t(*m_write_file) (imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts); + imgtoolerr_t(*m_delete_file) (imgtool::partition *partition, const char *filename); + imgtoolerr_t(*m_list_forks) (imgtool::partition *partition, const char *path, imgtool_forkent *ents, size_t len); + imgtoolerr_t(*m_create_dir) (imgtool::partition *partition, const char *path); + imgtoolerr_t(*m_delete_dir) (imgtool::partition *partition, const char *path); + imgtoolerr_t(*m_list_attrs) (imgtool::partition *partition, const char *path, UINT32 *attrs, size_t len); + imgtoolerr_t(*m_get_attrs) (imgtool::partition *partition, const char *path, const UINT32 *attrs, imgtool_attribute *values); + imgtoolerr_t(*m_set_attrs) (imgtool::partition *partition, const char *path, const UINT32 *attrs, const imgtool_attribute *values); + imgtoolerr_t(*m_attr_name) (UINT32 attribute, const imgtool_attribute *attr, char *buffer, size_t buffer_len); + imgtoolerr_t(*m_get_iconinfo) (imgtool::partition *partition, const char *path, imgtool_iconinfo *iconinfo); + imgtoolerr_t(*m_suggest_transfer)(imgtool::partition *partition, const char *path, imgtool_transfer_suggestion *suggestions, size_t suggestions_length); + imgtoolerr_t(*m_get_chain) (imgtool::partition *partition, const char *path, imgtool_chainent *chain, size_t chain_size); + + const util::option_guide *m_writefile_optguide; + std::string m_writefile_optspec; + + std::unique_ptr m_extra_bytes; + + // methods + imgtoolerr_t cannonicalize_path(UINT32 flags, const char **path, char **alloc_path); + imgtoolerr_t cannonicalize_fork(const char **fork); + char *normalize_filename(const char *src); + imgtoolerr_t map_block_to_image_block(UINT64 partition_block, UINT64 &image_block) const; + }; + + // ----- directory management ----- + class directory + { + public: + typedef std::unique_ptr ptr; + + // ctor/dtor + directory(imgtool::partition &partition); + ~directory(); + + // methods + static imgtoolerr_t open(imgtool::partition &partition, const char *path, ptr &outenum); + imgtoolerr_t get_next(imgtool_dirent &ent); + + // accessors + imgtool::partition &partition() { return m_partition; } + imgtool::image &image() { return partition().image(); } + const imgtool_module &module() { return partition().image().module(); } + void *extra_bytes() { assert(m_extra_bytes); return m_extra_bytes.get(); } + + private: + imgtool::partition &m_partition; + std::unique_ptr m_extra_bytes; + bool m_okay_to_close; // similar wart as what is on imgtool::image + }; +}; /* ----- special ----- */ int imgtool_validitychecks(void); diff --git a/src/tools/imgtool/library.h b/src/tools/imgtool/library.h index bc8f0753e57..dc55cb41e67 100644 --- a/src/tools/imgtool/library.h +++ b/src/tools/imgtool/library.h @@ -30,11 +30,10 @@ namespace imgtool { class image; + class partition; + class directory; }; -struct imgtool_partition; -struct imgtool_directory; - enum imgtool_suggestion_viability_t { SUGGESTION_END, @@ -49,8 +48,8 @@ union filterinfo void * f; /* generic function pointers */ const char *s; /* generic strings */ - imgtoolerr_t (*read_file)(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *destf); - imgtoolerr_t (*write_file)(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts); + imgtoolerr_t (*read_file)(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *destf); + imgtoolerr_t (*write_file)(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts); imgtoolerr_t (*check_stream)(imgtool_stream *stream, imgtool_suggestion_viability_t *viability); }; @@ -260,24 +259,24 @@ union imgtoolinfo imgtoolerr_t (*create) (imgtool::image *image, imgtool_stream *stream, util::option_resolution *opts); imgtoolerr_t (*create_partition) (imgtool::image *image, UINT64 first_block, UINT64 block_count); void (*info) (imgtool::image *image, char *string, size_t len); - imgtoolerr_t (*begin_enum) (imgtool_directory *enumeration, const char *path); - imgtoolerr_t (*next_enum) (imgtool_directory *enumeration, imgtool_dirent *ent); - void (*close_enum) (imgtool_directory *enumeration); - imgtoolerr_t (*open_partition) (imgtool_partition *partition, UINT64 first_block, UINT64 block_count); - imgtoolerr_t (*free_space) (imgtool_partition *partition, UINT64 *size); - imgtoolerr_t (*read_file) (imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *destf); - imgtoolerr_t (*write_file) (imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts); - imgtoolerr_t (*delete_file) (imgtool_partition *partition, const char *filename); - imgtoolerr_t (*list_forks) (imgtool_partition *partition, const char *path, imgtool_forkent *ents, size_t len); - imgtoolerr_t (*create_dir) (imgtool_partition *partition, const char *path); - imgtoolerr_t (*delete_dir) (imgtool_partition *partition, const char *path); - imgtoolerr_t (*list_attrs) (imgtool_partition *partition, const char *path, UINT32 *attrs, size_t len); - imgtoolerr_t (*get_attrs) (imgtool_partition *partition, const char *path, const UINT32 *attrs, imgtool_attribute *values); - imgtoolerr_t (*set_attrs) (imgtool_partition *partition, const char *path, const UINT32 *attrs, const imgtool_attribute *values); + imgtoolerr_t (*begin_enum) (imgtool::directory *enumeration, const char *path); + imgtoolerr_t (*next_enum) (imgtool::directory *enumeration, imgtool_dirent *ent); + void (*close_enum) (imgtool::directory *enumeration); + imgtoolerr_t (*open_partition) (imgtool::partition *partition, UINT64 first_block, UINT64 block_count); + imgtoolerr_t (*free_space) (imgtool::partition *partition, UINT64 *size); + imgtoolerr_t (*read_file) (imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *destf); + imgtoolerr_t (*write_file) (imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts); + imgtoolerr_t (*delete_file) (imgtool::partition *partition, const char *filename); + imgtoolerr_t (*list_forks) (imgtool::partition *partition, const char *path, imgtool_forkent *ents, size_t len); + imgtoolerr_t (*create_dir) (imgtool::partition *partition, const char *path); + imgtoolerr_t (*delete_dir) (imgtool::partition *partition, const char *path); + imgtoolerr_t (*list_attrs) (imgtool::partition *partition, const char *path, UINT32 *attrs, size_t len); + imgtoolerr_t (*get_attrs) (imgtool::partition *partition, const char *path, const UINT32 *attrs, imgtool_attribute *values); + imgtoolerr_t (*set_attrs) (imgtool::partition *partition, const char *path, const UINT32 *attrs, const imgtool_attribute *values); imgtoolerr_t (*attr_name) (UINT32 attribute, const imgtool_attribute *attr, char *buffer, size_t buffer_len); - imgtoolerr_t (*get_iconinfo) (imgtool_partition *partition, const char *path, imgtool_iconinfo *iconinfo); - imgtoolerr_t (*suggest_transfer) (imgtool_partition *partition, const char *path, imgtool_transfer_suggestion *suggestions, size_t suggestions_length); - imgtoolerr_t (*get_chain) (imgtool_partition *partition, const char *path, imgtool_chainent *chain, size_t chain_size); + imgtoolerr_t (*get_iconinfo) (imgtool::partition *partition, const char *path, imgtool_iconinfo *iconinfo); + imgtoolerr_t (*suggest_transfer) (imgtool::partition *partition, const char *path, imgtool_transfer_suggestion *suggestions, size_t suggestions_length); + imgtoolerr_t (*get_chain) (imgtool::partition *partition, const char *path, imgtool_chainent *chain, size_t chain_size); imgtoolerr_t (*get_geometry) (imgtool::image *image, UINT32 *tracks, UINT32 *heads, UINT32 *sectors); imgtoolerr_t (*read_sector) (imgtool::image *image, UINT32 track, UINT32 head, UINT32 sector, std::vector &buffer); imgtoolerr_t (*write_sector) (imgtool::image *image, UINT32 track, UINT32 head, UINT32 sector, const void *buffer, size_t len, int ddam); diff --git a/src/tools/imgtool/main.cpp b/src/tools/imgtool/main.cpp index 1307b389001..40ebf0d9f9d 100644 --- a/src/tools/imgtool/main.cpp +++ b/src/tools/imgtool/main.cpp @@ -174,8 +174,8 @@ static int cmd_dir(const struct command *c, int argc, char *argv[]) int total_count, total_size, freespace_err; UINT64 freespace; imgtool::image::ptr image; - imgtool_partition *partition = nullptr; - imgtool_directory *imgenum = nullptr; + imgtool::partition::ptr partition; + imgtool::directory::ptr imgenum; imgtool_dirent ent; char buf[512]; char last_modified[19]; @@ -188,13 +188,13 @@ static int cmd_dir(const struct command *c, int argc, char *argv[]) goto done; /* attempt to open partition */ - err = imgtool_partition_open(image.get(), partition_index, &partition); + err = imgtool::partition::open(*image, partition_index, partition); if (err) goto done; path = argc > 2 ? argv[2] : nullptr; - err = imgtool_directory_open(partition, path, &imgenum); + err = imgtool::directory::open(*partition, path, imgenum); if (err) goto done; @@ -210,7 +210,7 @@ static int cmd_dir(const struct command *c, int argc, char *argv[]) fprintf(stdout, "%s\n", buf); fprintf(stdout, "------------------------------ -------- --------------- ------------------\n"); - while (((err = imgtool_directory_get_next(imgenum, &ent)) == 0) && !ent.eof) + while (((err = imgenum->get_next(ent)) == 0) && !ent.eof) { if (ent.directory) snprintf(buf, sizeof(buf), ""); @@ -238,7 +238,7 @@ static int cmd_dir(const struct command *c, int argc, char *argv[]) memset(&ent, 0, sizeof(ent)); } - freespace_err = imgtool_partition_get_free_space(partition, &freespace); + freespace_err = partition->get_free_space(freespace); if (err) goto done; @@ -249,10 +249,6 @@ static int cmd_dir(const struct command *c, int argc, char *argv[]) fprintf(stdout, " %8u bytes free\n", (unsigned int) freespace); done: - if (imgenum) - imgtool_directory_close(imgenum); - if (partition) - imgtool_partition_close(partition); if (err) reporterror(err, c, argv[0], argv[1], nullptr, nullptr, nullptr); return err ? -1 : 0; @@ -263,8 +259,8 @@ done: static int cmd_get(const struct command *c, int argc, char *argv[]) { imgtoolerr_t err; - std::unique_ptr image; - imgtool_partition *partition = nullptr; + imgtool::image::ptr image; + imgtool::partition::ptr partition; const char *filename; char *new_filename; int unnamedargs = 0; @@ -276,7 +272,7 @@ static int cmd_get(const struct command *c, int argc, char *argv[]) if (err) goto done; - err = imgtool_partition_open(image.get(), partition_index, &partition); + err = imgtool::partition::open(*image, partition_index, partition); if (err) goto done; @@ -288,7 +284,7 @@ static int cmd_get(const struct command *c, int argc, char *argv[]) new_filename = (unnamedargs == 4) ? argv[3] : nullptr; - err = imgtool_partition_get_file(partition, filename, fork, new_filename, filter); + err = partition->get_file(filename, fork, new_filename, filter); if (err) goto done; @@ -297,8 +293,6 @@ static int cmd_get(const struct command *c, int argc, char *argv[]) done: if (err) reporterror(err, c, argv[0], argv[1], argv[2], argv[3], nullptr); - if (partition) - imgtool_partition_close(partition); return (err || (unnamedargs < 0)) ? -1 : 0; } @@ -308,8 +302,8 @@ static int cmd_put(const struct command *c, int argc, char *argv[]) { imgtoolerr_t err = IMGTOOLERR_SUCCESS; int i; - std::unique_ptr image; - imgtool_partition *partition = nullptr; + imgtool::image::ptr image; + imgtool::partition::ptr partition; const char *filename = nullptr; int unnamedargs; filter_getinfoproc filter; @@ -341,12 +335,12 @@ static int cmd_put(const struct command *c, int argc, char *argv[]) goto done; /* open up the partition */ - err = imgtool_partition_open(image.get(), partition_index, &partition); + err = imgtool::partition::open(*image, partition_index, partition); if (err) goto done; - writefile_optguide = (const util::option_guide *) imgtool_partition_get_info_ptr(partition, IMGTOOLINFO_PTR_WRITEFILE_OPTGUIDE); - writefile_optspec = (const char *)imgtool_partition_get_info_ptr(partition, IMGTOOLINFO_STR_WRITEFILE_OPTSPEC); + writefile_optguide = (const util::option_guide *) partition->get_info_ptr(IMGTOOLINFO_PTR_WRITEFILE_OPTGUIDE); + writefile_optspec = (const char *)partition->get_info_ptr(IMGTOOLINFO_STR_WRITEFILE_OPTSPEC); if (writefile_optguide && writefile_optspec) { @@ -374,14 +368,12 @@ static int cmd_put(const struct command *c, int argc, char *argv[]) { filename = filename_list[i]; printf("Putting file '%s'...\n", filename); - err = imgtool_partition_put_file(partition, new_filename, fork, filename, resolution.get(), filter); + err = partition->put_file(new_filename, fork, filename, resolution.get(), filter); if (err) goto done; } done: - if (partition) - imgtool_partition_close(partition); if (err) reporterror(err, c, argv[0], argv[1], filename, nullptr, resolution.get()); return err ? -1 : 0; @@ -392,9 +384,9 @@ done: static int cmd_getall(const struct command *c, int argc, char *argv[]) { imgtoolerr_t err; - std::unique_ptr image; - imgtool_partition *partition = nullptr; - imgtool_directory *imgenum = nullptr; + imgtool::image::ptr image; + imgtool::partition::ptr partition; + imgtool::directory::ptr imgenum; imgtool_dirent ent; filter_getinfoproc filter; int unnamedargs; @@ -406,7 +398,7 @@ static int cmd_getall(const struct command *c, int argc, char *argv[]) if (err) goto done; - err = imgtool_partition_open(image.get(), partition_index, &partition); + err = imgtool::partition::open(*image, partition_index, partition); if (err) goto done; @@ -420,26 +412,22 @@ static int cmd_getall(const struct command *c, int argc, char *argv[]) if (unnamedargs < 0) goto done; - err = imgtool_directory_open(partition, path, &imgenum); + err = imgtool::directory::open(*partition, path, imgenum); if (err) goto done; memset(&ent, 0, sizeof(ent)); - while (((err = imgtool_directory_get_next(imgenum, &ent)) == 0) && !ent.eof) + while (((err = imgenum->get_next(ent)) == 0) && !ent.eof) { fprintf(stdout, "Retrieving %s (%u bytes)\n", ent.filename, (unsigned int) ent.filesize); - err = imgtool_partition_get_file(partition, ent.filename, nullptr, nullptr, filter); + err = partition->get_file(ent.filename, nullptr, nullptr, filter); if (err) goto done; } done: - if (imgenum) - imgtool_directory_close(imgenum); - if (partition) - imgtool_partition_close(partition); if (err) reporterror(err, c, argv[0], argv[1], nullptr, nullptr, nullptr); return err ? -1 : 0; @@ -450,25 +438,23 @@ done: static int cmd_del(const struct command *c, int argc, char *argv[]) { imgtoolerr_t err; - std::unique_ptr image; - imgtool_partition *partition = nullptr; + imgtool::image::ptr image; + imgtool::partition::ptr partition; int partition_index = 0; err = imgtool::image::open(argv[0], argv[1], OSD_FOPEN_RW, image); if (err) goto done; - err = imgtool_partition_open(image.get(), partition_index, &partition); + err = imgtool::partition::open(*image, partition_index, partition); if (err) goto done; - err = imgtool_partition_delete_file(partition, argv[2]); + err = partition->delete_file(argv[2]); if (err) goto done; done: - if (partition) - imgtool_partition_close(partition); if (err) reporterror(err, c, argv[0], argv[1], argv[2], nullptr, nullptr); return err ? -1 : 0; @@ -479,25 +465,23 @@ done: static int cmd_mkdir(const struct command *c, int argc, char *argv[]) { imgtoolerr_t err; - std::unique_ptr image; - imgtool_partition *partition = nullptr; + imgtool::image::ptr image; + imgtool::partition::ptr partition; int partition_index = 0; err = imgtool::image::open(argv[0], argv[1], OSD_FOPEN_RW, image); if (err) goto done; - err = imgtool_partition_open(image.get(), partition_index, &partition); + err = imgtool::partition::open(*image, partition_index, partition); if (err) goto done; - err = imgtool_partition_create_directory(partition, argv[2]); + err = partition->create_directory(argv[2]); if (err) goto done; done: - if (partition) - imgtool_partition_close(partition); if (err) reporterror(err, c, argv[0], argv[1], argv[2], nullptr, nullptr); return err ? -1 : 0; @@ -508,25 +492,23 @@ done: static int cmd_rmdir(const struct command *c, int argc, char *argv[]) { imgtoolerr_t err; - std::unique_ptr image; - imgtool_partition *partition = nullptr; + imgtool::image::ptr image; + imgtool::partition::ptr partition; int partition_index = 0; err = imgtool::image::open(argv[0], argv[1], OSD_FOPEN_RW, image); if (err) goto done; - err = imgtool_partition_open(image.get(), partition_index, &partition); + err = imgtool::partition::open(*image, partition_index, partition); if (err) goto done; - err = imgtool_partition_delete_directory(partition, argv[2]); + err = partition->delete_directory(argv[2]); if (err) goto done; done: - if (partition) - imgtool_partition_close(partition); if (err) reporterror(err, c, argv[0], argv[1], argv[2], nullptr, nullptr); return err ? -1 : 0; diff --git a/src/tools/imgtool/modules/amiga.cpp b/src/tools/imgtool/modules/amiga.cpp index cdccbd36c79..12a168e5256 100644 --- a/src/tools/imgtool/modules/amiga.cpp +++ b/src/tools/imgtool/modules/amiga.cpp @@ -1845,13 +1845,13 @@ static imgtoolerr_t amiga_image_write_sector(imgtool::image* img, UINT32 track, } -static imgtoolerr_t amiga_image_beginenum(imgtool_directory *enumeration, const char *path) +static imgtoolerr_t amiga_image_beginenum(imgtool::directory *enumeration, const char *path) { - int blocks = get_total_blocks(imgtool_directory_image(enumeration)); + int blocks = get_total_blocks(&enumeration->image()); imgtoolerr_t ret; amiga_iterator *iter; - iter = (amiga_iterator *) imgtool_directory_extrabytes(enumeration); + iter = (amiga_iterator *) enumeration->extra_bytes(); if (!iter) return IMGTOOLERR_OUTOFMEMORY; iter->index = 1; @@ -1861,7 +1861,7 @@ static imgtoolerr_t amiga_image_beginenum(imgtool_directory *enumeration, const if (path[0]) { /* search for the directory block, start with the root block */ - ret = find_entry(imgtool_directory_image(enumeration), path, blocks/2, &iter->block); + ret = find_entry(&enumeration->image(), path, blocks/2, &iter->block); if (ret) return ret; } else @@ -1874,9 +1874,9 @@ static imgtoolerr_t amiga_image_beginenum(imgtool_directory *enumeration, const } -static imgtoolerr_t amiga_image_nextenum(imgtool_directory *enumeration, imgtool_dirent *ent) +static imgtoolerr_t amiga_image_nextenum(imgtool::directory *enumeration, imgtool_dirent *ent) { - amiga_iterator *iter = (amiga_iterator *) imgtool_directory_extrabytes(enumeration); + amiga_iterator *iter = (amiga_iterator *) enumeration->extra_bytes(); imgtoolerr_t ret; UINT32 ht[TSIZE]; int block; @@ -1889,7 +1889,7 @@ static imgtoolerr_t amiga_image_nextenum(imgtool_directory *enumeration, imgtool } /* get hash table */ - ret = get_hash_table(imgtool_directory_image(enumeration), iter->block, ht); + ret = get_hash_table(&enumeration->image(), iter->block, ht); if (ret) return ret; /* skip empty hash table entries */ @@ -1907,14 +1907,14 @@ static imgtoolerr_t amiga_image_nextenum(imgtool_directory *enumeration, imgtool /* get block number */ block = (iter->next_block == 0) ? ht[iter->ht_index] : iter->next_block; - switch (get_block_type(imgtool_directory_image(enumeration), block)) + switch (get_block_type(&enumeration->image(), block)) { case ST_FILE: { file_block file; /* get block */ - ret = read_file_block(imgtool_directory_image(enumeration), block, &file); + ret = read_file_block(&enumeration->image(), block, &file); if (ret) return ret; /* fill directory entry */ @@ -1934,7 +1934,7 @@ static imgtoolerr_t amiga_image_nextenum(imgtool_directory *enumeration, imgtool dir_block dir; /* get block */ - ret = read_dir_block(imgtool_directory_image(enumeration), block, &dir); + ret = read_dir_block(&enumeration->image(), block, &dir); if (ret) return ret; /* fill directory entry */ @@ -1954,7 +1954,7 @@ static imgtoolerr_t amiga_image_nextenum(imgtool_directory *enumeration, imgtool softlink_block sl; /* get block */ - ret = read_softlink_block(imgtool_directory_image(enumeration), block, &sl); + ret = read_softlink_block(&enumeration->image(), block, &sl); if (ret) return ret; /* fill directory entry */ @@ -1978,14 +1978,14 @@ static imgtoolerr_t amiga_image_nextenum(imgtool_directory *enumeration, imgtool hardlink_block hl; /* get block */ - ret = read_hardlink_block(imgtool_directory_image(enumeration), block, &hl); + ret = read_hardlink_block(&enumeration->image(), block, &hl); if (ret) return ret; /* get filesize from linked file */ if (!ent->directory) { file_block file; - ret = read_file_block(imgtool_directory_image(enumeration), hl.real_entry, &file); + ret = read_file_block(&enumeration->image(), hl.real_entry, &file); if (ret) return ret; ent->filesize = file.byte_size; } @@ -2019,16 +2019,16 @@ static imgtoolerr_t amiga_image_nextenum(imgtool_directory *enumeration, imgtool } -static void amiga_image_closeenum(imgtool_directory *enumeration) +static void amiga_image_closeenum(imgtool::directory *enumeration) { free(enumeration); } -static imgtoolerr_t amiga_image_freespace(imgtool_partition *partition, UINT64 *size) +static imgtoolerr_t amiga_image_freespace(imgtool::partition *partition, UINT64 *size) { imgtoolerr_t ret; - imgtool::image *image = imgtool_partition_image(partition); + imgtool::image *image = &partition->image(); const int data_size = is_ffs(image) ? BSIZE : BSIZE-24; root_block root; bitmap_block bm; @@ -2079,9 +2079,9 @@ static imgtoolerr_t amiga_image_freespace(imgtool_partition *partition, UINT64 * } -static imgtoolerr_t amiga_image_readfile(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *destf) +static imgtoolerr_t amiga_image_readfile(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *destf) { - imgtool::image *img = imgtool_partition_image(partition); + imgtool::image *img = &partition->image(); imgtoolerr_t ret; file_block file; int filesize, block; @@ -2116,9 +2116,9 @@ static imgtoolerr_t amiga_image_readfile(imgtool_partition *partition, const cha * the Directory block (or from the same-hash-value list) and the bitmap is * updated. File header block, Data blocks and File extension blocks are not * cleared, but the bitmap blocks are updated. */ -static imgtoolerr_t amiga_image_deletefile(imgtool_partition *partition, const char *fname) +static imgtoolerr_t amiga_image_deletefile(imgtool::partition *partition, const char *fname) { - imgtool::image *img = imgtool_partition_image(partition); + imgtool::image *img = &partition->image(); imgtoolerr_t ret; int parent, block; char filename[31]; @@ -2189,7 +2189,7 @@ static imgtoolerr_t amiga_image_deletefile(imgtool_partition *partition, const c } -static imgtoolerr_t amiga_image_writefile(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) +static imgtoolerr_t amiga_image_writefile(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) { return IMGTOOLERR_UNIMPLEMENTED; } @@ -2300,9 +2300,9 @@ static imgtoolerr_t amiga_image_create(imgtool::image *img, imgtool_stream *stre } -static imgtoolerr_t amiga_image_createdir(imgtool_partition *partition, const char *path) +static imgtoolerr_t amiga_image_createdir(imgtool::partition *partition, const char *path) { - imgtool::image *img = imgtool_partition_image(partition); + imgtool::image *img = &partition->image(); imgtoolerr_t ret; /* Create directories */ @@ -2317,25 +2317,25 @@ static imgtoolerr_t amiga_image_createdir(imgtool_partition *partition, const ch } -static imgtoolerr_t amiga_image_getattrs(imgtool_partition *partition, const char *path, const UINT32 *attrs, imgtool_attribute *values) +static imgtoolerr_t amiga_image_getattrs(imgtool::partition *partition, const char *path, const UINT32 *attrs, imgtool_attribute *values) { return IMGTOOLERR_UNIMPLEMENTED; } -static imgtoolerr_t amiga_image_setattrs(imgtool_partition *partition, const char *path, const UINT32 *attrs, const imgtool_attribute *values) +static imgtoolerr_t amiga_image_setattrs(imgtool::partition *partition, const char *path, const UINT32 *attrs, const imgtool_attribute *values) { return IMGTOOLERR_UNIMPLEMENTED; } -static imgtoolerr_t amiga_image_geticoninfo(imgtool_partition *partition, const char *path, imgtool_iconinfo *iconinfo) +static imgtoolerr_t amiga_image_geticoninfo(imgtool::partition *partition, const char *path, imgtool_iconinfo *iconinfo) { return IMGTOOLERR_UNIMPLEMENTED; } -static imgtoolerr_t amiga_image_suggesttransfer(imgtool_partition *partition, const char *fname, imgtool_transfer_suggestion *suggestions, size_t suggestions_length) +static imgtoolerr_t amiga_image_suggesttransfer(imgtool::partition *partition, const char *fname, imgtool_transfer_suggestion *suggestions, size_t suggestions_length) { return IMGTOOLERR_UNIMPLEMENTED; } diff --git a/src/tools/imgtool/modules/bml3.cpp b/src/tools/imgtool/modules/bml3.cpp index 62c090eb6a2..123d2f83bef 100644 --- a/src/tools/imgtool/modules/bml3.cpp +++ b/src/tools/imgtool/modules/bml3.cpp @@ -68,7 +68,7 @@ struct granule_list_t { #define BML3_OPTIONS_FTYPE 'T' #define BML3_OPTIONS_ASCII 'M' -static imgtoolerr_t bml3_diskimage_deletefile(imgtool_partition *partition, const char *fname); +static imgtoolerr_t bml3_diskimage_deletefile(imgtool::partition *partition, const char *fname); @@ -548,7 +548,7 @@ static imgtoolerr_t bml3_diskimage_open(imgtool::image *image, imgtool_stream *s -static imgtoolerr_t bml3_diskimage_nextenum(imgtool_directory *enumeration, imgtool_dirent *ent) +static imgtoolerr_t bml3_diskimage_nextenum(imgtool::directory *enumeration, imgtool_dirent *ent) { floperr_t ferr; imgtoolerr_t err; @@ -558,8 +558,8 @@ static imgtoolerr_t bml3_diskimage_nextenum(imgtool_directory *enumeration, imgt char fname[13]; imgtool::image *image; - image = imgtool_directory_image(enumeration); - rsenum = (struct bml3_direnum *) imgtool_directory_extrabytes(enumeration); + image = &enumeration->image(); + rsenum = (struct bml3_direnum *) enumeration->extra_bytes(); /* Did we hit the end of file before? */ if (rsenum->eof) @@ -613,14 +613,14 @@ eof: -static imgtoolerr_t bml3_diskimage_freespace(imgtool_partition *partition, UINT64 *size) +static imgtoolerr_t bml3_diskimage_freespace(imgtool::partition *partition, UINT64 *size) { floperr_t ferr; UINT8 i; size_t s = 0; UINT8 granule_count; UINT8 granule_map[MAX_GRANULEMAP_SIZE]; - imgtool::image *image = imgtool_partition_image(partition); + imgtool::image *image = &partition->image(); bml3_diskinfo *info = bml3_get_diskinfo(image); ferr = get_granule_map(image, granule_map, &granule_count); @@ -673,12 +673,12 @@ static imgtoolerr_t delete_entry(imgtool::image *img, struct bml3_dirent *ent, i -static imgtoolerr_t bml3_diskimage_readfile(imgtool_partition *partition, const char *fname, const char *fork, imgtool_stream *destf) +static imgtoolerr_t bml3_diskimage_readfile(imgtool::partition *partition, const char *fname, const char *fork, imgtool_stream *destf) { imgtoolerr_t err; struct bml3_dirent ent; size_t size; - imgtool::image *img = imgtool_partition_image(partition); + imgtool::image *img = &partition->image(); err = lookup_bml3_file(img, fname, &ent, NULL); if (err) @@ -696,11 +696,11 @@ static imgtoolerr_t bml3_diskimage_readfile(imgtool_partition *partition, const -static imgtoolerr_t bml3_diskimage_writefile(imgtool_partition *partition, const char *fname, const char *fork, imgtool_stream *sourcef, util::option_resolution *writeoptions) +static imgtoolerr_t bml3_diskimage_writefile(imgtool::partition *partition, const char *fname, const char *fork, imgtool_stream *sourcef, util::option_resolution *writeoptions) { floperr_t ferr; imgtoolerr_t err; - imgtool::image *img = imgtool_partition_image(partition); + imgtool::image *img = &partition->image(); bml3_diskinfo *info = bml3_get_diskinfo(img); struct bml3_dirent ent, ent2; size_t i; @@ -817,10 +817,10 @@ static imgtoolerr_t bml3_diskimage_writefile(imgtool_partition *partition, const -static imgtoolerr_t bml3_diskimage_deletefile(imgtool_partition *partition, const char *fname) +static imgtoolerr_t bml3_diskimage_deletefile(imgtool::partition *partition, const char *fname) { imgtoolerr_t err; - imgtool::image *image = imgtool_partition_image(partition); + imgtool::image *image = &partition->image(); int pos = 0; struct bml3_dirent ent; @@ -833,10 +833,10 @@ static imgtoolerr_t bml3_diskimage_deletefile(imgtool_partition *partition, cons -static imgtoolerr_t bml3_diskimage_suggesttransfer(imgtool_partition *partition, const char *fname, imgtool_transfer_suggestion *suggestions, size_t suggestions_length) +static imgtoolerr_t bml3_diskimage_suggesttransfer(imgtool::partition *partition, const char *fname, imgtool_transfer_suggestion *suggestions, size_t suggestions_length) { imgtoolerr_t err; - imgtool::image *image = imgtool_partition_image(partition); + imgtool::image *image = &partition->image(); struct bml3_dirent ent; int pos; diff --git a/src/tools/imgtool/modules/concept.cpp b/src/tools/imgtool/modules/concept.cpp index 857cbf075ed..69e1ecb987d 100644 --- a/src/tools/imgtool/modules/concept.cpp +++ b/src/tools/imgtool/modules/concept.cpp @@ -129,14 +129,14 @@ struct concept_iterator static imgtoolerr_t concept_image_init(imgtool::image *img, imgtool_stream *f); static void concept_image_exit(imgtool::image *img); static void concept_image_info(imgtool::image *img, char *string, size_t len); -static imgtoolerr_t concept_image_beginenum(imgtool_directory *enumeration, const char *path); -static imgtoolerr_t concept_image_nextenum(imgtool_directory *enumeration, imgtool_dirent *ent); -static void concept_image_closeenum(imgtool_directory *enumeration); -static imgtoolerr_t concept_image_freespace(imgtool_partition *partition, UINT64 *size); -static imgtoolerr_t concept_image_readfile(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *destf); +static imgtoolerr_t concept_image_beginenum(imgtool::directory *enumeration, const char *path); +static imgtoolerr_t concept_image_nextenum(imgtool::directory *enumeration, imgtool_dirent *ent); +static void concept_image_closeenum(imgtool::directory *enumeration); +static imgtoolerr_t concept_image_freespace(imgtool::partition *partition, UINT64 *size); +static imgtoolerr_t concept_image_readfile(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *destf); #if 0 -static imgtoolerr_t concept_image_writefile(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *writeoptions); -static imgtoolerr_t concept_image_deletefile(imgtool_partition *partition, const char *filename); +static imgtoolerr_t concept_image_writefile(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *writeoptions); +static imgtoolerr_t concept_image_deletefile(imgtool::partition *partition, const char *filename); static imgtoolerr_t concept_image_create(const imgtool_module *mod, imgtool_stream *f, util::option_resolution *createoptions); #endif @@ -319,12 +319,12 @@ static void concept_image_info(imgtool::image *img, char *string, size_t len) /* Open the disk catalog for enumeration */ -static imgtoolerr_t concept_image_beginenum(imgtool_directory *enumeration, const char *path) +static imgtoolerr_t concept_image_beginenum(imgtool::directory *enumeration, const char *path) { concept_iterator *iter; - iter = (concept_iterator *) imgtool_directory_extrabytes(enumeration); - iter->image = (concept_image *) imgtool_directory_image(enumeration)->extra_bytes(); + iter = (concept_iterator *) enumeration->extra_bytes(); + iter->image = (concept_image *) enumeration->image().extra_bytes(); iter->index = 0; return IMGTOOLERR_SUCCESS; } @@ -332,9 +332,9 @@ static imgtoolerr_t concept_image_beginenum(imgtool_directory *enumeration, cons /* Enumerate disk catalog next entry */ -static imgtoolerr_t concept_image_nextenum(imgtool_directory *enumeration, imgtool_dirent *ent) +static imgtoolerr_t concept_image_nextenum(imgtool::directory *enumeration, imgtool_dirent *ent) { - concept_iterator *iter = (concept_iterator *) imgtool_directory_extrabytes(enumeration); + concept_iterator *iter = (concept_iterator *) enumeration->extra_bytes(); ent->corrupt = 0; @@ -393,16 +393,16 @@ static imgtoolerr_t concept_image_nextenum(imgtool_directory *enumeration, imgto /* Free enumerator */ -static void concept_image_closeenum(imgtool_directory *enumeration) +static void concept_image_closeenum(imgtool::directory *enumeration) { } /* Compute free space on disk image */ -static imgtoolerr_t concept_image_freespace(imgtool_partition *partition, UINT64 *size) +static imgtoolerr_t concept_image_freespace(imgtool::partition *partition, UINT64 *size) { - imgtool::image *img = imgtool_partition_image(partition); + imgtool::image *img = &partition->image(); concept_image *image = (concept_image*) img; int free_blocks; int i; @@ -426,9 +426,9 @@ static imgtoolerr_t concept_image_freespace(imgtool_partition *partition, UINT64 /* Extract a file from a concept_image. */ -static imgtoolerr_t concept_image_readfile(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *destf) +static imgtoolerr_t concept_image_readfile(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *destf) { - imgtool::image *img = imgtool_partition_image(partition); + imgtool::image *img = &partition->image(); concept_image *image = (concept_image *) img->extra_bytes(); size_t filename_len = strlen(filename); unsigned char concept_fname[16]; @@ -463,7 +463,7 @@ static imgtoolerr_t concept_image_readfile(imgtool_partition *partition, const c /* Add a file to a concept_image. */ -static imgtoolerr_t concept_image_writefile(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *writeoptions) +static imgtoolerr_t concept_image_writefile(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *writeoptions) { /* ... */ @@ -473,7 +473,7 @@ static imgtoolerr_t concept_image_writefile(imgtool_partition *partition, const /* Delete a file from a concept_image. */ -static imgtoolerr_t concept_image_deletefile(imgtool_partition *partition, const char *filename) +static imgtoolerr_t concept_image_deletefile(imgtool::partition *partition, const char *filename) { /* ... */ diff --git a/src/tools/imgtool/modules/cybiko.cpp b/src/tools/imgtool/modules/cybiko.cpp index b71f8f16014..a1f4a8c6129 100644 --- a/src/tools/imgtool/modules/cybiko.cpp +++ b/src/tools/imgtool/modules/cybiko.cpp @@ -377,18 +377,18 @@ static imgtoolerr_t cybiko_image_create( imgtool::image *image, imgtool_stream * return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t cybiko_image_begin_enum( imgtool_directory *enumeration, const char *path) +static imgtoolerr_t cybiko_image_begin_enum( imgtool::directory *enumeration, const char *path) { - cybiko_iter *iter = (cybiko_iter*)imgtool_directory_extrabytes( enumeration); + cybiko_iter *iter = (cybiko_iter*)enumeration->extra_bytes(); iter->block = 0; return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t cybiko_image_next_enum( imgtool_directory *enumeration, imgtool_dirent *ent) +static imgtoolerr_t cybiko_image_next_enum( imgtool::directory *enumeration, imgtool_dirent *ent) { - imgtool::image *image = imgtool_directory_image( enumeration); + imgtool::image *image = &enumeration->image(); cybiko_file_system *cfs = (cybiko_file_system*)image->extra_bytes(); - cybiko_iter *iter = (cybiko_iter*)imgtool_directory_extrabytes( enumeration); + cybiko_iter *iter = (cybiko_iter*)enumeration->extra_bytes(); UINT8 buffer[MAX_PAGE_SIZE]; UINT16 file_id = INVALID_FILE_ID; cfs_file file; @@ -418,22 +418,22 @@ static imgtoolerr_t cybiko_image_next_enum( imgtool_directory *enumeration, imgt return IMGTOOLERR_SUCCESS; } -static void cybiko_image_close_enum( imgtool_directory *enumeration) +static void cybiko_image_close_enum( imgtool::directory *enumeration) { // nothing } -static imgtoolerr_t cybiko_image_free_space( imgtool_partition *partition, UINT64 *size) +static imgtoolerr_t cybiko_image_free_space( imgtool::partition *partition, UINT64 *size) { - imgtool::image *image = imgtool_partition_image( partition); + imgtool::image *image = &partition->image(); cybiko_file_system *cfs = (cybiko_file_system*)image->extra_bytes(); if (size) *size = cfs_calc_free_space( cfs, cfs_calc_free_blocks( cfs)); return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t cybiko_image_read_file( imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *destf) +static imgtoolerr_t cybiko_image_read_file( imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *destf) { - imgtool::image *image = imgtool_partition_image( partition); + imgtool::image *image = &partition->image(); cybiko_file_system *cfs = (cybiko_file_system*)image->extra_bytes(); UINT8 buffer[MAX_PAGE_SIZE]; UINT16 file_id, part_id = 0, old_part_id; @@ -458,9 +458,9 @@ static imgtoolerr_t cybiko_image_read_file( imgtool_partition *partition, const return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t cybiko_image_write_file( imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) +static imgtoolerr_t cybiko_image_write_file( imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) { - imgtool::image *image = imgtool_partition_image( partition); + imgtool::image *image = &partition->image(); cybiko_file_system *cfs = (cybiko_file_system*)image->extra_bytes(); UINT8 buffer[MAX_PAGE_SIZE]; UINT16 file_id, part_id = 0, free_blocks; @@ -518,9 +518,9 @@ static imgtoolerr_t cybiko_image_write_file( imgtool_partition *partition, const return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t cybiko_image_delete_file( imgtool_partition *partition, const char *filename) +static imgtoolerr_t cybiko_image_delete_file( imgtool::partition *partition, const char *filename) { - imgtool::image *image = imgtool_partition_image( partition); + imgtool::image *image = &partition->image(); cybiko_file_system *cfs = (cybiko_file_system*)image->extra_bytes(); UINT16 file_id; // find file diff --git a/src/tools/imgtool/modules/cybikoxt.cpp b/src/tools/imgtool/modules/cybikoxt.cpp index c4d9899c31c..afbeb236bb0 100644 --- a/src/tools/imgtool/modules/cybikoxt.cpp +++ b/src/tools/imgtool/modules/cybikoxt.cpp @@ -347,18 +347,18 @@ static imgtoolerr_t cybiko_image_create( imgtool::image *image, imgtool_stream * return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t cybiko_image_begin_enum( imgtool_directory *enumeration, const char *path) +static imgtoolerr_t cybiko_image_begin_enum( imgtool::directory *enumeration, const char *path) { - cybiko_iter *iter = (cybiko_iter*)imgtool_directory_extrabytes( enumeration); + cybiko_iter *iter = (cybiko_iter*)enumeration->extra_bytes(); iter->block = 0; return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t cybiko_image_next_enum( imgtool_directory *enumeration, imgtool_dirent *ent) +static imgtoolerr_t cybiko_image_next_enum( imgtool::directory *enumeration, imgtool_dirent *ent) { - imgtool::image *image = imgtool_directory_image( enumeration); + imgtool::image *image = &enumeration->image(); cybiko_file_system *cfs = (cybiko_file_system*)image->extra_bytes(); - cybiko_iter *iter = (cybiko_iter*)imgtool_directory_extrabytes( enumeration); + cybiko_iter *iter = (cybiko_iter*)enumeration->extra_bytes(); UINT8 buffer[MAX_PAGE_SIZE]; UINT16 file_id = INVALID_FILE_ID; cfs_file file; @@ -388,22 +388,22 @@ static imgtoolerr_t cybiko_image_next_enum( imgtool_directory *enumeration, imgt return IMGTOOLERR_SUCCESS; } -static void cybiko_image_close_enum( imgtool_directory *enumeration) +static void cybiko_image_close_enum( imgtool::directory *enumeration) { // nothing } -static imgtoolerr_t cybiko_image_free_space( imgtool_partition *partition, UINT64 *size) +static imgtoolerr_t cybiko_image_free_space( imgtool::partition *partition, UINT64 *size) { - imgtool::image *image = imgtool_partition_image( partition); + imgtool::image *image = &partition->image(); cybiko_file_system *cfs = (cybiko_file_system*)image->extra_bytes(); if (size) *size = cfs_calc_free_space( cfs, cfs_calc_free_blocks( cfs)); return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t cybiko_image_read_file( imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *destf) +static imgtoolerr_t cybiko_image_read_file( imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *destf) { - imgtool::image *image = imgtool_partition_image( partition); + imgtool::image *image = &partition->image(); cybiko_file_system *cfs = (cybiko_file_system*)image->extra_bytes(); UINT8 buffer[MAX_PAGE_SIZE]; UINT16 file_id, part_id = 0, old_part_id; @@ -430,9 +430,9 @@ static imgtoolerr_t cybiko_image_read_file( imgtool_partition *partition, const return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t cybiko_image_write_file( imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) +static imgtoolerr_t cybiko_image_write_file( imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) { - imgtool::image *image = imgtool_partition_image( partition); + imgtool::image *image = &partition->image(); cybiko_file_system *cfs = (cybiko_file_system*)image->extra_bytes(); UINT8 buffer[MAX_PAGE_SIZE]; UINT16 file_id, part_id = 0, free_blocks; @@ -493,9 +493,9 @@ static imgtoolerr_t cybiko_image_write_file( imgtool_partition *partition, const return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t cybiko_image_delete_file( imgtool_partition *partition, const char *filename) +static imgtoolerr_t cybiko_image_delete_file( imgtool::partition *partition, const char *filename) { - imgtool::image *image = imgtool_partition_image( partition); + imgtool::image *image = &partition->image(); cybiko_file_system *cfs = (cybiko_file_system*)image->extra_bytes(); UINT16 file_id; // check filename diff --git a/src/tools/imgtool/modules/fat.cpp b/src/tools/imgtool/modules/fat.cpp index 55641a02ba1..37125f0004d 100644 --- a/src/tools/imgtool/modules/fat.cpp +++ b/src/tools/imgtool/modules/fat.cpp @@ -275,14 +275,14 @@ static const char fat32_string[8] = { 'F', 'A', 'T', '3', '2', ' ', ' ', ' ' }; -static fat_partition_info *fat_get_partition_info(imgtool_partition *partition) +static fat_partition_info *fat_get_partition_info(imgtool::partition *partition) { - return (fat_partition_info *) imgtool_partition_extra_bytes(partition); + return (fat_partition_info *)partition->extra_bytes(); } -static imgtoolerr_t fat_read_sector(imgtool_partition *partition, UINT32 sector_index, +static imgtoolerr_t fat_read_sector(imgtool::partition *partition, UINT32 sector_index, int offset, void *buffer, size_t buffer_len) { //const fat_partition_info *disk_info; @@ -294,14 +294,14 @@ static imgtoolerr_t fat_read_sector(imgtool_partition *partition, UINT32 sector_ //disk_info = fat_get_partition_info(partition); /* sanity check */ - err = imgtool_partition_get_block_size(partition, block_size); + err = partition->get_block_size(block_size); if (err) return err; assert(block_size == sizeof(data)); while(buffer_len > 0) { - err = imgtool_partition_read_block(partition, sector_index++, data); + err = partition->read_block(sector_index++, data); if (err) return err; @@ -317,7 +317,7 @@ static imgtoolerr_t fat_read_sector(imgtool_partition *partition, UINT32 sector_ -static imgtoolerr_t fat_write_sector(imgtool_partition *partition, UINT32 sector_index, +static imgtoolerr_t fat_write_sector(imgtool::partition *partition, UINT32 sector_index, int offset, const void *buffer, size_t buffer_len) { //const fat_partition_info *disk_info; @@ -330,7 +330,7 @@ static imgtoolerr_t fat_write_sector(imgtool_partition *partition, UINT32 sector //disk_info = fat_get_partition_info(partition); /* sanity check */ - err = imgtool_partition_get_block_size(partition, block_size); + err = partition->get_block_size(block_size); if (err) return err; assert(block_size == sizeof(data)); @@ -341,7 +341,7 @@ static imgtoolerr_t fat_write_sector(imgtool_partition *partition, UINT32 sector if ((offset != 0) || (buffer_len < sizeof(data))) { - err = imgtool_partition_read_block(partition, sector_index, data); + err = partition->read_block(sector_index, data); if (err) return err; memcpy(data + offset, buffer, len); @@ -352,7 +352,7 @@ static imgtoolerr_t fat_write_sector(imgtool_partition *partition, UINT32 sector write_data = buffer; } - err = imgtool_partition_write_block(partition, sector_index++, write_data); + err = partition->write_block(sector_index++, write_data); if (err) return err; @@ -365,7 +365,7 @@ static imgtoolerr_t fat_write_sector(imgtool_partition *partition, UINT32 sector #ifdef UNUSED_FUNCTION -static imgtoolerr_t fat_clear_sector(imgtool_partition *partition, UINT32 sector_index, UINT8 data) +static imgtoolerr_t fat_clear_sector(imgtool::partition *partition, UINT32 sector_index, UINT8 data) { char buf[FAT_SECLEN]; memset(buf, data, sizeof(buf)); @@ -374,7 +374,7 @@ static imgtoolerr_t fat_clear_sector(imgtool_partition *partition, UINT32 sector #endif -static imgtoolerr_t fat_partition_open(imgtool_partition *partition, UINT64 first_block, UINT64 block_count) +static imgtoolerr_t fat_partition_open(imgtool::partition *partition, UINT64 first_block, UINT64 block_count) { UINT8 header[FAT_SECLEN]; imgtoolerr_t err; @@ -593,7 +593,7 @@ static imgtoolerr_t fat_partition_create(imgtool::image *image, UINT64 first_blo -static imgtoolerr_t fat_load_fat(imgtool_partition *partition, UINT8 **fat_table) +static imgtoolerr_t fat_load_fat(imgtool::partition *partition, UINT8 **fat_table) { imgtoolerr_t err = IMGTOOLERR_SUCCESS; const fat_partition_info *disk_info; @@ -641,7 +641,7 @@ done: -static imgtoolerr_t fat_save_fat(imgtool_partition *partition, const UINT8 *fat_table) +static imgtoolerr_t fat_save_fat(imgtool::partition *partition, const UINT8 *fat_table) { imgtoolerr_t err = IMGTOOLERR_SUCCESS; const fat_partition_info *disk_info; @@ -673,7 +673,7 @@ done: -static UINT32 fat_get_fat_entry(imgtool_partition *partition, const UINT8 *fat_table, UINT32 fat_entry) +static UINT32 fat_get_fat_entry(imgtool::partition *partition, const UINT8 *fat_table, UINT32 fat_entry) { const fat_partition_info *disk_info; UINT64 entry; @@ -720,7 +720,7 @@ static UINT32 fat_get_fat_entry(imgtool_partition *partition, const UINT8 *fat_t -static void fat_set_fat_entry(imgtool_partition *partition, UINT8 *fat_table, UINT32 fat_entry, UINT32 value) +static void fat_set_fat_entry(imgtool::partition *partition, UINT8 *fat_table, UINT32 fat_entry, UINT32 value) { const fat_partition_info *disk_info; UINT64 entry; @@ -747,7 +747,7 @@ static void fat_set_fat_entry(imgtool_partition *partition, UINT8 *fat_table, UI -static void fat_debug_integrity_check(imgtool_partition *partition, const UINT8 *fat_table, const fat_file *file) +static void fat_debug_integrity_check(imgtool::partition *partition, const UINT8 *fat_table, const fat_file *file) { #ifdef MAME_DEBUG /* debug function to test the integrity of a file */ @@ -770,7 +770,7 @@ static void fat_debug_integrity_check(imgtool_partition *partition, const UINT8 -static imgtoolerr_t fat_seek_file(imgtool_partition *partition, fat_file *file, UINT32 pos) +static imgtoolerr_t fat_seek_file(imgtool::partition *partition, fat_file *file, UINT32 pos) { imgtoolerr_t err = IMGTOOLERR_SUCCESS; const fat_partition_info *disk_info; @@ -831,7 +831,7 @@ done: -static UINT32 fat_get_filepos_sector_index(imgtool_partition *partition, fat_file *file) +static UINT32 fat_get_filepos_sector_index(imgtool::partition *partition, fat_file *file) { UINT32 sector_index; const fat_partition_info *disk_info; @@ -873,7 +873,7 @@ static imgtoolerr_t fat_corrupt_file_error(const fat_file *file) -static imgtoolerr_t fat_readwrite_file(imgtool_partition *partition, fat_file *file, +static imgtoolerr_t fat_readwrite_file(imgtool::partition *partition, fat_file *file, void *buffer, size_t buffer_len, size_t *bytes_read, int read_or_write) { imgtoolerr_t err; @@ -921,7 +921,7 @@ static imgtoolerr_t fat_readwrite_file(imgtool_partition *partition, fat_file *f -static imgtoolerr_t fat_read_file(imgtool_partition *partition, fat_file *file, +static imgtoolerr_t fat_read_file(imgtool::partition *partition, fat_file *file, void *buffer, size_t buffer_len, size_t *bytes_read) { return fat_readwrite_file(partition, file, buffer, buffer_len, bytes_read, 0); @@ -929,7 +929,7 @@ static imgtoolerr_t fat_read_file(imgtool_partition *partition, fat_file *file, -static imgtoolerr_t fat_write_file(imgtool_partition *partition, fat_file *file, +static imgtoolerr_t fat_write_file(imgtool::partition *partition, fat_file *file, const void *buffer, size_t buffer_len, size_t *bytes_read) { return fat_readwrite_file(partition, file, (void *) buffer, buffer_len, bytes_read, 1); @@ -937,7 +937,7 @@ static imgtoolerr_t fat_write_file(imgtool_partition *partition, fat_file *file, -static UINT32 fat_allocate_cluster(imgtool_partition *partition, UINT8 *fat_table) +static UINT32 fat_allocate_cluster(imgtool::partition *partition, UINT8 *fat_table) { const fat_partition_info *disk_info; UINT32 i, val; @@ -959,7 +959,7 @@ static UINT32 fat_allocate_cluster(imgtool_partition *partition, UINT8 *fat_tabl /* sets the size of a file; ~0 means 'delete' */ -static imgtoolerr_t fat_set_file_size(imgtool_partition *partition, fat_file *file, +static imgtoolerr_t fat_set_file_size(imgtool::partition *partition, fat_file *file, UINT32 new_size) { imgtoolerr_t err = IMGTOOLERR_SUCCESS; @@ -1277,7 +1277,7 @@ static UINT32 fat_setup_time(time_t ansi_time) -static imgtoolerr_t fat_read_dirent(imgtool_partition *partition, fat_file *file, +static imgtoolerr_t fat_read_dirent(imgtool::partition *partition, fat_file *file, fat_dirent *ent, fat_freeentry_info *freeent) { imgtoolerr_t err; @@ -1600,7 +1600,7 @@ done: -static void fat_bump_dirent(imgtool_partition *partition, UINT8 *entry, size_t entry_len) +static void fat_bump_dirent(imgtool::partition *partition, UINT8 *entry, size_t entry_len) { UINT8 *sfn_entry; int pos, digit_count, i; @@ -1635,7 +1635,7 @@ static void fat_bump_dirent(imgtool_partition *partition, UINT8 *entry, size_t e { /* extreme degenerate case; simply randomize the filename */ for (i = 0; i < 6; i++) - sfn_entry[i] = 'A' + (imgtool_partition_rand(partition) % 26); + sfn_entry[i] = 'A' + (imgtool::image::rand() % 26); sfn_entry[6] = '~'; sfn_entry[7] = '0'; } @@ -1661,7 +1661,7 @@ static void fat_bump_dirent(imgtool_partition *partition, UINT8 *entry, size_t e -static imgtoolerr_t fat_lookup_path(imgtool_partition *partition, const char *path, +static imgtoolerr_t fat_lookup_path(imgtool::partition *partition, const char *path, creation_policy_t create, fat_file *file) { imgtoolerr_t err; @@ -1809,14 +1809,14 @@ done: -static imgtoolerr_t fat_partition_beginenum(imgtool_directory *enumeration, const char *path) +static imgtoolerr_t fat_partition_beginenum(imgtool::directory *enumeration, const char *path) { imgtoolerr_t err; fat_file *file; - file = (fat_file *) imgtool_directory_extrabytes(enumeration); + file = (fat_file *) enumeration->extra_bytes(); - err = fat_lookup_path(imgtool_directory_partition(enumeration), path, CREATE_NONE, file); + err = fat_lookup_path(&enumeration->partition(), path, CREATE_NONE, file); if (err) return err; if (!file->directory) @@ -1826,14 +1826,14 @@ static imgtoolerr_t fat_partition_beginenum(imgtool_directory *enumeration, cons -static imgtoolerr_t fat_partition_nextenum(imgtool_directory *enumeration, imgtool_dirent *ent) +static imgtoolerr_t fat_partition_nextenum(imgtool::directory *enumeration, imgtool_dirent *ent) { imgtoolerr_t err; fat_file *file; fat_dirent fatent; - file = (fat_file *) imgtool_directory_extrabytes(enumeration); - err = fat_read_dirent(imgtool_directory_partition(enumeration), file, &fatent, NULL); + file = (fat_file *) enumeration->extra_bytes(); + err = fat_read_dirent(&enumeration->partition(), file, &fatent, NULL); if (err) return err; @@ -1850,7 +1850,7 @@ static imgtoolerr_t fat_partition_nextenum(imgtool_directory *enumeration, imgto -static imgtoolerr_t fat_read_bootblock(imgtool_partition *partition, imgtool_stream *stream) +static imgtoolerr_t fat_read_bootblock(imgtool::partition *partition, imgtool_stream *stream) { imgtoolerr_t err; UINT8 block[FAT_SECLEN]; @@ -1865,7 +1865,7 @@ static imgtoolerr_t fat_read_bootblock(imgtool_partition *partition, imgtool_str -static imgtoolerr_t fat_write_bootblock(imgtool_partition *partition, imgtool_stream *stream) +static imgtoolerr_t fat_write_bootblock(imgtool::partition *partition, imgtool_stream *stream) { imgtoolerr_t err; UINT8 block[FAT_SECLEN]; @@ -1899,7 +1899,7 @@ static imgtoolerr_t fat_write_bootblock(imgtool_partition *partition, imgtool_st -static imgtoolerr_t fat_partition_readfile(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *destf) +static imgtoolerr_t fat_partition_readfile(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *destf) { imgtoolerr_t err; fat_file file; @@ -1931,7 +1931,7 @@ static imgtoolerr_t fat_partition_readfile(imgtool_partition *partition, const c -static imgtoolerr_t fat_partition_writefile(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) +static imgtoolerr_t fat_partition_writefile(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) { imgtoolerr_t err; fat_file file; @@ -1971,7 +1971,7 @@ static imgtoolerr_t fat_partition_writefile(imgtool_partition *partition, const -static imgtoolerr_t fat_partition_delete(imgtool_partition *partition, const char *filename, unsigned int dir) +static imgtoolerr_t fat_partition_delete(imgtool::partition *partition, const char *filename, unsigned int dir) { imgtoolerr_t err; fat_file file; @@ -2001,14 +2001,14 @@ static imgtoolerr_t fat_partition_delete(imgtool_partition *partition, const cha -static imgtoolerr_t fat_partition_deletefile(imgtool_partition *partition, const char *filename) +static imgtoolerr_t fat_partition_deletefile(imgtool::partition *partition, const char *filename) { return fat_partition_delete(partition, filename, 0); } -static imgtoolerr_t fat_partition_freespace(imgtool_partition *partition, UINT64 *size) +static imgtoolerr_t fat_partition_freespace(imgtool::partition *partition, UINT64 *size) { imgtoolerr_t err; const fat_partition_info *disk_info; @@ -2036,7 +2036,7 @@ done: -static imgtoolerr_t fat_partition_createdir(imgtool_partition *partition, const char *path) +static imgtoolerr_t fat_partition_createdir(imgtool::partition *partition, const char *path) { imgtoolerr_t err; fat_file file; @@ -2070,7 +2070,7 @@ static imgtoolerr_t fat_partition_createdir(imgtool_partition *partition, const -static imgtoolerr_t fat_partition_deletedir(imgtool_partition *partition, const char *path) +static imgtoolerr_t fat_partition_deletedir(imgtool::partition *partition, const char *path) { return fat_partition_delete(partition, path, 1); } diff --git a/src/tools/imgtool/modules/hp48.cpp b/src/tools/imgtool/modules/hp48.cpp index a7790497897..f5cde5760e7 100644 --- a/src/tools/imgtool/modules/hp48.cpp +++ b/src/tools/imgtool/modules/hp48.cpp @@ -436,12 +436,12 @@ static imgtoolerr_t hp48_list_partitions(imgtool::image *img, return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t hp48_open_partition(imgtool_partition *part, +static imgtoolerr_t hp48_open_partition(imgtool::partition *part, UINT64 first_block, UINT64 block_count) { - imgtool::image* img = imgtool_partition_image( part ); + imgtool::image* img = &part->image(); hp48_card* c = (hp48_card*) img->extra_bytes(); - hp48_partition* p = (hp48_partition*) imgtool_partition_extra_bytes( part ); + hp48_partition* p = (hp48_partition*) part->extra_bytes(); if ( first_block + block_count > c->size ) return IMGTOOLERR_INVALIDPARTITION; @@ -455,10 +455,10 @@ static imgtoolerr_t hp48_open_partition(imgtool_partition *part, -static imgtoolerr_t hp48_beginenum(imgtool_directory *enumeration, +static imgtoolerr_t hp48_beginenum(imgtool::directory *enumeration, const char *path) { - hp48_directory* d = (hp48_directory*) imgtool_directory_extrabytes( enumeration ); + hp48_directory* d = (hp48_directory*) enumeration->extra_bytes(); d->pos = 0; @@ -467,14 +467,14 @@ static imgtoolerr_t hp48_beginenum(imgtool_directory *enumeration, -static imgtoolerr_t hp48_nextenum(imgtool_directory *enumeration, +static imgtoolerr_t hp48_nextenum(imgtool::directory *enumeration, imgtool_dirent *ent) { - imgtool_partition *part = imgtool_directory_partition( enumeration ); - //imgtool::image* img = imgtool_partition_image( part ); + imgtool::partition *part = &enumeration->partition(); + //imgtool::image* img = &part->image(); //hp48_card* c = (hp48_card*) img->extra_bytes(); - hp48_partition* p = (hp48_partition*) imgtool_partition_extra_bytes( part ); - hp48_directory* d = (hp48_directory*) imgtool_directory_extrabytes( enumeration ); + hp48_partition* p = (hp48_partition*) part->extra_bytes(); + hp48_directory* d = (hp48_directory*) enumeration->extra_bytes(); UINT8* data = p->data; int pos = d->pos; @@ -526,11 +526,11 @@ static imgtoolerr_t hp48_nextenum(imgtool_directory *enumeration, -static imgtoolerr_t hp48_freespace(imgtool_partition *part, UINT64 *size) +static imgtoolerr_t hp48_freespace(imgtool::partition *part, UINT64 *size) { - //imgtool::image* img = imgtool_partition_image( part ); + //imgtool::image* img = &part->image(); //hp48_card* c = (hp48_card*) img->extra_bytes(); - hp48_partition* p = (hp48_partition*) imgtool_partition_extra_bytes( part ); + hp48_partition* p = (hp48_partition*) part->extra_bytes(); *size = p->size - (find_end(p)+1)/2; @@ -539,14 +539,14 @@ static imgtoolerr_t hp48_freespace(imgtool_partition *part, UINT64 *size) -static imgtoolerr_t hp48_readfile(imgtool_partition *part, +static imgtoolerr_t hp48_readfile(imgtool::partition *part, const char *filename, const char *fork, imgtool_stream *destf) { - //imgtool::image* img = imgtool_partition_image( part ); + //imgtool::image* img = &part->image(); //hp48_card* c = (hp48_card*) img->extra_bytes(); - hp48_partition* p = (hp48_partition*) imgtool_partition_extra_bytes( part ); + hp48_partition* p = (hp48_partition*) part->extra_bytes(); /* find entry */ int totalsize, start, size; @@ -584,12 +584,12 @@ static imgtoolerr_t hp48_readfile(imgtool_partition *part, -static imgtoolerr_t hp48_deletefile(imgtool_partition *part, +static imgtoolerr_t hp48_deletefile(imgtool::partition *part, const char *filename) { - imgtool::image* img = imgtool_partition_image( part ); + imgtool::image* img = &part->image(); hp48_card* c = (hp48_card*) img->extra_bytes(); - hp48_partition* p = (hp48_partition*) imgtool_partition_extra_bytes( part ); + hp48_partition* p = (hp48_partition*) part->extra_bytes(); /* find entry */ int totalsize; @@ -610,15 +610,15 @@ static imgtoolerr_t hp48_deletefile(imgtool_partition *part, -static imgtoolerr_t hp48_writefile(imgtool_partition *part, +static imgtoolerr_t hp48_writefile(imgtool::partition *part, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) { - imgtool::image* img = imgtool_partition_image( part ); + imgtool::image* img = &part->image(); hp48_card* c = (hp48_card*) img->extra_bytes(); - hp48_partition* p = (hp48_partition*) imgtool_partition_extra_bytes( part ); + hp48_partition* p = (hp48_partition*) part->extra_bytes(); /* check header */ char head[8]; diff --git a/src/tools/imgtool/modules/hp9845_tape.cpp b/src/tools/imgtool/modules/hp9845_tape.cpp index 858d8e8ae88..7bf3876cf73 100644 --- a/src/tools/imgtool/modules/hp9845_tape.cpp +++ b/src/tools/imgtool/modules/hp9845_tape.cpp @@ -1081,20 +1081,20 @@ static void hp9845_tape_close(imgtool::image *image) global_free(&tape_image); } -static imgtoolerr_t hp9845_tape_begin_enum (imgtool_directory *enumeration, const char *path) +static imgtoolerr_t hp9845_tape_begin_enum (imgtool::directory *enumeration, const char *path) { - dir_state_t *ds = (dir_state_t*)imgtool_directory_extrabytes(enumeration); + dir_state_t *ds = (dir_state_t*)enumeration->extra_bytes(); ds->dir_idx = 0; return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t hp9845_tape_next_enum (imgtool_directory *enumeration, imgtool_dirent *ent) +static imgtoolerr_t hp9845_tape_next_enum (imgtool::directory *enumeration, imgtool_dirent *ent) { - tape_state_t& state = get_tape_state(imgtool_directory_image(enumeration)); + tape_state_t& state = get_tape_state(&enumeration->image()); tape_image_t& tape_image = get_tape_image(state); - dir_state_t *ds = (dir_state_t*)imgtool_directory_extrabytes(enumeration); + dir_state_t *ds = (dir_state_t*)enumeration->extra_bytes(); const dir_entry_t *entry = nullptr; @@ -1115,9 +1115,9 @@ static imgtoolerr_t hp9845_tape_next_enum (imgtool_directory *enumeration, imgto return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t hp9845_tape_free_space(imgtool_partition *partition, UINT64 *size) +static imgtoolerr_t hp9845_tape_free_space(imgtool::partition *partition, UINT64 *size) { - tape_state_t& state = get_tape_state(imgtool_partition_image(partition)); + tape_state_t& state = get_tape_state(&partition->image()); tape_image_t& tape_image = get_tape_image(state); *size = tape_image.free_sectors() * SECTOR_LEN; @@ -1125,9 +1125,9 @@ static imgtoolerr_t hp9845_tape_free_space(imgtool_partition *partition, UINT64 return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t hp9845_tape_read_file(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *destf) +static imgtoolerr_t hp9845_tape_read_file(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *destf) { - tape_state_t& state = get_tape_state(imgtool_partition_image(partition)); + tape_state_t& state = get_tape_state(&partition->image()); tape_image_t& tape_image = get_tape_image(state); unsigned idx; @@ -1159,9 +1159,9 @@ static imgtoolerr_t hp9845_tape_read_file(imgtool_partition *partition, const ch return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t hp9845_tape_write_file(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) +static imgtoolerr_t hp9845_tape_write_file(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) { - tape_state_t& state = get_tape_state(imgtool_partition_image(partition)); + tape_state_t& state = get_tape_state(&partition->image()); tape_image_t& tape_image = get_tape_image(state); unsigned idx; @@ -1245,9 +1245,9 @@ static imgtoolerr_t hp9845_tape_write_file(imgtool_partition *partition, const c return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t hp9845_tape_delete_file(imgtool_partition *partition, const char *filename) +static imgtoolerr_t hp9845_tape_delete_file(imgtool::partition *partition, const char *filename) { - tape_state_t& state = get_tape_state(imgtool_partition_image(partition)); + tape_state_t& state = get_tape_state(&partition->image()); tape_image_t& tape_image = get_tape_image(state); unsigned idx; @@ -1392,7 +1392,7 @@ static bool dump_string(imgtool_stream *inp, imgtool_stream *out , unsigned len return true; } -static imgtoolerr_t hp9845data_read_file(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *destf) +static imgtoolerr_t hp9845data_read_file(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *destf) { imgtool_stream *inp_data; imgtoolerr_t res; @@ -1533,7 +1533,7 @@ static bool split_string_n_dump(const char *s , imgtool_stream *dest) return true; } -static imgtoolerr_t hp9845data_write_file(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) +static imgtoolerr_t hp9845data_write_file(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) { imgtool_stream *out_data; diff --git a/src/tools/imgtool/modules/mac.cpp b/src/tools/imgtool/modules/mac.cpp index a8a90e133a4..ca1eeea32fd 100644 --- a/src/tools/imgtool/modules/mac.cpp +++ b/src/tools/imgtool/modules/mac.cpp @@ -5274,11 +5274,11 @@ static imgtoolerr_t get_comment(struct mac_l2_imgref *l2_img, UINT16 id, mac_str static void mac_image_exit(imgtool::image *img); #endif static void mac_image_info(imgtool::image *img, char *string, size_t len); -static imgtoolerr_t mac_image_beginenum(imgtool_directory *enumeration, const char *path); -static imgtoolerr_t mac_image_nextenum(imgtool_directory *enumeration, imgtool_dirent *ent); -static imgtoolerr_t mac_image_freespace(imgtool_partition *partition, UINT64 *size); -static imgtoolerr_t mac_image_readfile(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *destf); -static imgtoolerr_t mac_image_writefile(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *writeoptions); +static imgtoolerr_t mac_image_beginenum(imgtool::directory *enumeration, const char *path); +static imgtoolerr_t mac_image_nextenum(imgtool::directory *enumeration, imgtool_dirent *ent); +static imgtoolerr_t mac_image_freespace(imgtool::partition *partition, UINT64 *size); +static imgtoolerr_t mac_image_readfile(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *destf); +static imgtoolerr_t mac_image_writefile(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *writeoptions); #ifdef UNUSED_FUNCTION /* @@ -5336,10 +5336,10 @@ struct mac_iterator /* Open the disk catalog for enumeration */ -static imgtoolerr_t mac_image_beginenum(imgtool_directory *enumeration, const char *path) +static imgtoolerr_t mac_image_beginenum(imgtool::directory *enumeration, const char *path) { - struct mac_l2_imgref *image = get_imgref(imgtool_directory_image(enumeration)); - mac_iterator *iter = (mac_iterator *) imgtool_directory_extrabytes(enumeration); + struct mac_l2_imgref *image = get_imgref(&enumeration->image()); + mac_iterator *iter = (mac_iterator *) enumeration->extra_bytes(); imgtoolerr_t err = IMGTOOLERR_UNEXPECTED; iter->format = image->format; @@ -5545,10 +5545,10 @@ static imgtoolerr_t hfs_image_nextenum(mac_iterator *iter, imgtool_dirent *ent) /* Enumerate disk catalog next entry */ -static imgtoolerr_t mac_image_nextenum(imgtool_directory *enumeration, imgtool_dirent *ent) +static imgtoolerr_t mac_image_nextenum(imgtool::directory *enumeration, imgtool_dirent *ent) { imgtoolerr_t err; - mac_iterator *iter = (mac_iterator *) imgtool_directory_extrabytes(enumeration); + mac_iterator *iter = (mac_iterator *) enumeration->extra_bytes(); switch (iter->format) { @@ -5571,9 +5571,9 @@ static imgtoolerr_t mac_image_nextenum(imgtool_directory *enumeration, imgtool_d /* Compute free space on disk image in bytes */ -static imgtoolerr_t mac_image_freespace(imgtool_partition *partition, UINT64 *size) +static imgtoolerr_t mac_image_freespace(imgtool::partition *partition, UINT64 *size) { - imgtool::image *image = imgtool_partition_image(partition); + imgtool::image *image = &partition->image(); *size = ((UINT64) get_imgref(image)->freeABs) * 512; return IMGTOOLERR_SUCCESS; } @@ -5610,10 +5610,10 @@ static imgtoolerr_t mac_get_comment(struct mac_l2_imgref *image, mac_str255 file /* Extract a file from a disk image. */ -static imgtoolerr_t mac_image_readfile(imgtool_partition *partition, const char *fpath, const char *fork, imgtool_stream *destf) +static imgtoolerr_t mac_image_readfile(imgtool::partition *partition, const char *fpath, const char *fork, imgtool_stream *destf) { imgtoolerr_t err; - imgtool::image *img = imgtool_partition_image(partition); + imgtool::image *img = &partition->image(); struct mac_l2_imgref *image = get_imgref(img); UINT32 parID; mac_str255 filename; @@ -5661,9 +5661,9 @@ static imgtoolerr_t mac_image_readfile(imgtool_partition *partition, const char /* Add a file to a disk image. */ -static imgtoolerr_t mac_image_writefile(imgtool_partition *partition, const char *fpath, const char *fork, imgtool_stream *sourcef, util::option_resolution *writeoptions) +static imgtoolerr_t mac_image_writefile(imgtool::partition *partition, const char *fpath, const char *fork, imgtool_stream *sourcef, util::option_resolution *writeoptions) { - imgtool::image *img = imgtool_partition_image(partition); + imgtool::image *img = &partition->image(); struct mac_l2_imgref *image = get_imgref(img); UINT32 parID; mac_str255 filename; @@ -5738,14 +5738,14 @@ static imgtoolerr_t mac_image_writefile(imgtool_partition *partition, const char -static imgtoolerr_t mac_image_listforks(imgtool_partition *partition, const char *path, imgtool_forkent *ents, size_t len) +static imgtoolerr_t mac_image_listforks(imgtool::partition *partition, const char *path, imgtool_forkent *ents, size_t len) { imgtoolerr_t err; UINT32 parID; mac_str255 filename; mac_dirent cat_info; int fork_num = 0; - imgtool::image *img = imgtool_partition_image(partition); + imgtool::image *img = &partition->image(); struct mac_l2_imgref *image = get_imgref(img); /* resolve path and fetch file info from directory/catalog */ @@ -5776,10 +5776,10 @@ static imgtoolerr_t mac_image_listforks(imgtool_partition *partition, const char -static imgtoolerr_t mac_image_getattrs(imgtool_partition *partition, const char *path, const UINT32 *attrs, imgtool_attribute *values) +static imgtoolerr_t mac_image_getattrs(imgtool::partition *partition, const char *path, const UINT32 *attrs, imgtool_attribute *values) { imgtoolerr_t err; - imgtool::image *img = imgtool_partition_image(partition); + imgtool::image *img = &partition->image(); UINT32 parID; mac_str255 filename; mac_dirent cat_info; @@ -5844,13 +5844,13 @@ static imgtoolerr_t mac_image_getattrs(imgtool_partition *partition, const char -static imgtoolerr_t mac_image_setattrs(imgtool_partition *partition, const char *path, const UINT32 *attrs, const imgtool_attribute *values) +static imgtoolerr_t mac_image_setattrs(imgtool::partition *partition, const char *path, const UINT32 *attrs, const imgtool_attribute *values) { imgtoolerr_t err; UINT32 parID; mac_str255 filename; mac_dirent cat_info; - imgtool::image *img = imgtool_partition_image(partition); + imgtool::image *img = &partition->image(); struct mac_l2_imgref *image = get_imgref(img); int i; @@ -6111,7 +6111,7 @@ static int load_icon(UINT32 *dest, const void *resource_fork, UINT64 resource_fo -static imgtoolerr_t mac_image_geticoninfo(imgtool_partition *partition, const char *path, imgtool_iconinfo *iconinfo) +static imgtoolerr_t mac_image_geticoninfo(imgtool::partition *partition, const char *path, imgtool_iconinfo *iconinfo) { static const UINT32 mac_palette_1bpp[2] = { 0xFFFFFF, 0x000000 }; @@ -6317,13 +6317,13 @@ done: * *************************************/ -static imgtoolerr_t mac_image_suggesttransfer(imgtool_partition *partition, const char *path, imgtool_transfer_suggestion *suggestions, size_t suggestions_length) +static imgtoolerr_t mac_image_suggesttransfer(imgtool::partition *partition, const char *path, imgtool_transfer_suggestion *suggestions, size_t suggestions_length) { imgtoolerr_t err; UINT32 parID; mac_str255 filename; mac_dirent cat_info; - imgtool::image *img = imgtool_partition_image(partition); + imgtool::image *img = &partition->image(); struct mac_l2_imgref *image = get_imgref(img); mac_filecategory_t file_category = MAC_FILECATEGORY_DATA; diff --git a/src/tools/imgtool/modules/macbin.cpp b/src/tools/imgtool/modules/macbin.cpp index 849f9a98aa0..cebf15b6a29 100644 --- a/src/tools/imgtool/modules/macbin.cpp +++ b/src/tools/imgtool/modules/macbin.cpp @@ -63,7 +63,7 @@ static UINT32 pad128(UINT32 length) -static imgtoolerr_t macbinary_readfile(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *destf) +static imgtoolerr_t macbinary_readfile(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *destf) { static const UINT32 attrs[] = { @@ -101,7 +101,7 @@ static imgtoolerr_t macbinary_readfile(imgtool_partition *partition, const char imgtool_attribute attr_values[10]; /* get the forks */ - err = imgtool_partition_list_file_forks(partition, filename, fork_entries, sizeof(fork_entries)); + err = partition->list_file_forks(filename, fork_entries, sizeof(fork_entries)); if (err) return err; for (i = 0; fork_entries[i].type != FORK_END; i++) @@ -113,7 +113,7 @@ static imgtoolerr_t macbinary_readfile(imgtool_partition *partition, const char } /* get the attributes */ - err = imgtool_partition_get_file_attributes(partition, filename, attrs, attr_values); + err = partition->get_file_attributes(filename, attrs, attr_values); if (err && (ERRORCODE(err) != IMGTOOLERR_UNIMPLEMENTED)) return err; if (err == IMGTOOLERR_SUCCESS) @@ -160,7 +160,7 @@ static imgtoolerr_t macbinary_readfile(imgtool_partition *partition, const char if (data_fork) { - err = imgtool_partition_read_file(partition, filename, "", destf, NULL); + err = partition->read_file(filename, "", destf, NULL); if (err) return err; @@ -169,7 +169,7 @@ static imgtoolerr_t macbinary_readfile(imgtool_partition *partition, const char if (resource_fork) { - err = imgtool_partition_read_file(partition, filename, "RESOURCE_FORK", destf, NULL); + err = partition->read_file(filename, "RESOURCE_FORK", destf, NULL); if (err) return err; @@ -181,7 +181,7 @@ static imgtoolerr_t macbinary_readfile(imgtool_partition *partition, const char -static imgtoolerr_t write_fork(imgtool_partition *partition, const char *filename, const char *fork, +static imgtoolerr_t write_fork(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, UINT64 pos, UINT64 fork_len, util::option_resolution *opts) { imgtoolerr_t err = IMGTOOLERR_SUCCESS; @@ -203,7 +203,7 @@ static imgtoolerr_t write_fork(imgtool_partition *partition, const char *filenam stream_fill(mem_stream, 0, fork_len); stream_seek(mem_stream, 0, SEEK_SET); - err = imgtool_partition_write_file(partition, filename, fork, mem_stream, opts, NULL); + err = partition->write_file(filename, fork, mem_stream, opts, NULL); if (err) goto done; } @@ -216,7 +216,7 @@ done: -static imgtoolerr_t macbinary_writefile(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) +static imgtoolerr_t macbinary_writefile(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) { static const UINT32 attrs[] = { @@ -233,7 +233,7 @@ static imgtoolerr_t macbinary_writefile(imgtool_partition *partition, const char 0 }; imgtoolerr_t err; - imgtool::image *image = imgtool_partition_image(partition); + imgtool::image *image = &partition->image(); UINT8 header[128]; UINT32 datafork_size; UINT32 resourcefork_size; @@ -332,7 +332,7 @@ static imgtoolerr_t macbinary_writefile(imgtool_partition *partition, const char attr_values[8].i = script_code; attr_values[9].i = extended_flags; - err = imgtool_partition_put_file_attributes(partition, filename, attrs, attr_values); + err = partition->put_file_attributes(filename, attrs, attr_values); if (err) return err; } diff --git a/src/tools/imgtool/modules/os9.cpp b/src/tools/imgtool/modules/os9.cpp index 393feccf915..7eccad34a61 100644 --- a/src/tools/imgtool/modules/os9.cpp +++ b/src/tools/imgtool/modules/os9.cpp @@ -125,9 +125,9 @@ static os9_diskinfo *os9_get_diskinfo(imgtool::image *image) -static struct os9_direnum *os9_get_dirinfo(imgtool_directory *directory) +static struct os9_direnum *os9_get_dirinfo(imgtool::directory *directory) { - return (struct os9_direnum *) imgtool_directory_extrabytes(directory); + return (struct os9_direnum *) directory->extra_bytes(); } @@ -847,13 +847,13 @@ done: -static imgtoolerr_t os9_diskimage_beginenum(imgtool_directory *enumeration, const char *path) +static imgtoolerr_t os9_diskimage_beginenum(imgtool::directory *enumeration, const char *path) { imgtoolerr_t err = IMGTOOLERR_SUCCESS; struct os9_direnum *os9enum; imgtool::image *image; - image = imgtool_directory_image(enumeration); + image = &enumeration->image(); os9enum = os9_get_dirinfo(enumeration); err = os9_lookup_path(image, path, CREATE_NONE, &os9enum->dir_info, NULL, NULL, NULL); @@ -873,7 +873,7 @@ done: -static imgtoolerr_t os9_diskimage_nextenum(imgtool_directory *enumeration, imgtool_dirent *ent) +static imgtoolerr_t os9_diskimage_nextenum(imgtool::directory *enumeration, imgtool_dirent *ent) { struct os9_direnum *os9enum; UINT32 lsn, index; @@ -883,7 +883,7 @@ static imgtoolerr_t os9_diskimage_nextenum(imgtool_directory *enumeration, imgto struct os9_fileinfo file_info; imgtool::image *image; - image = imgtool_directory_image(enumeration); + image = &enumeration->image(); os9enum = os9_get_dirinfo(enumeration); do @@ -949,7 +949,7 @@ static imgtoolerr_t os9_diskimage_nextenum(imgtool_directory *enumeration, imgto /* read file attributes */ lsn = pick_integer_be(dir_entry, 29, 3); - err = os9_decode_file_header(imgtool_directory_image(enumeration), lsn, &file_info); + err = os9_decode_file_header(&enumeration->image(), lsn, &file_info); if (err) return err; @@ -973,9 +973,9 @@ static imgtoolerr_t os9_diskimage_nextenum(imgtool_directory *enumeration, imgto -static imgtoolerr_t os9_diskimage_freespace(imgtool_partition *partition, UINT64 *size) +static imgtoolerr_t os9_diskimage_freespace(imgtool::partition *partition, UINT64 *size) { - imgtool::image *image = imgtool_partition_image(partition); + imgtool::image *image = &partition->image(); const os9_diskinfo *disk_info; UINT32 free_lsns; @@ -988,10 +988,10 @@ static imgtoolerr_t os9_diskimage_freespace(imgtool_partition *partition, UINT64 -static imgtoolerr_t os9_diskimage_readfile(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *destf) +static imgtoolerr_t os9_diskimage_readfile(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *destf) { imgtoolerr_t err; - imgtool::image *img = imgtool_partition_image(partition); + imgtool::image *img = &partition->image(); const os9_diskinfo *disk_info; struct os9_fileinfo file_info; UINT8 buffer[256]; @@ -1026,10 +1026,10 @@ static imgtoolerr_t os9_diskimage_readfile(imgtool_partition *partition, const c -static imgtoolerr_t os9_diskimage_writefile(imgtool_partition *partition, const char *path, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) +static imgtoolerr_t os9_diskimage_writefile(imgtool::partition *partition, const char *path, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) { imgtoolerr_t err; - imgtool::image *image = imgtool_partition_image(partition); + imgtool::image *image = &partition->image(); struct os9_fileinfo file_info; size_t write_size; dynamic_buffer buf; @@ -1081,11 +1081,11 @@ done: -static imgtoolerr_t os9_diskimage_delete(imgtool_partition *partition, const char *path, +static imgtoolerr_t os9_diskimage_delete(imgtool::partition *partition, const char *path, unsigned int delete_directory) { imgtoolerr_t err; - imgtool::image *image = imgtool_partition_image(partition); + imgtool::image *image = &partition->image(); //const os9_diskinfo *disk_info; struct os9_fileinfo file_info; UINT32 dirent_lsn, dirent_index; @@ -1163,17 +1163,17 @@ static imgtoolerr_t os9_diskimage_delete(imgtool_partition *partition, const cha -static imgtoolerr_t os9_diskimage_deletefile(imgtool_partition *partition, const char *path) +static imgtoolerr_t os9_diskimage_deletefile(imgtool::partition *partition, const char *path) { return os9_diskimage_delete(partition, path, 0); } -static imgtoolerr_t os9_diskimage_createdir(imgtool_partition *partition, const char *path) +static imgtoolerr_t os9_diskimage_createdir(imgtool::partition *partition, const char *path) { imgtoolerr_t err; - imgtool::image *image = imgtool_partition_image(partition); + imgtool::image *image = &partition->image(); struct os9_fileinfo file_info; UINT8 dir_data[64]; UINT32 parent_lsn; @@ -1203,7 +1203,7 @@ done: -static imgtoolerr_t os9_diskimage_deletedir(imgtool_partition *partition, const char *path) +static imgtoolerr_t os9_diskimage_deletedir(imgtool::partition *partition, const char *path) { return os9_diskimage_delete(partition, path, 1); } diff --git a/src/tools/imgtool/modules/prodos.cpp b/src/tools/imgtool/modules/prodos.cpp index 5ce8159f251..b4783aefc3a 100644 --- a/src/tools/imgtool/modules/prodos.cpp +++ b/src/tools/imgtool/modules/prodos.cpp @@ -1486,7 +1486,7 @@ static UINT32 prodos_get_storagetype_maxfilesize(UINT8 storage_type) -static imgtoolerr_t prodos_diskimage_beginenum(imgtool_directory *enumeration, const char *path) +static imgtoolerr_t prodos_diskimage_beginenum(imgtool::directory *enumeration, const char *path) { imgtoolerr_t err; imgtool::image *image; @@ -1494,8 +1494,8 @@ static imgtoolerr_t prodos_diskimage_beginenum(imgtool_directory *enumeration, c prodos_dirent ent; UINT16 block = ROOTDIR_BLOCK; - image = imgtool_directory_image(enumeration); - appleenum = (prodos_direnum *) imgtool_directory_extrabytes(enumeration); + image = &enumeration->image(); + appleenum = (prodos_direnum *) enumeration->extra_bytes(); /* find subdirectory, if appropriate */ if (*path) @@ -1521,7 +1521,7 @@ static imgtoolerr_t prodos_diskimage_beginenum(imgtool_directory *enumeration, c -static imgtoolerr_t prodos_diskimage_nextenum(imgtool_directory *enumeration, imgtool_dirent *ent) +static imgtoolerr_t prodos_diskimage_nextenum(imgtool::directory *enumeration, imgtool_dirent *ent) { imgtoolerr_t err; imgtool::image *image; @@ -1529,8 +1529,8 @@ static imgtoolerr_t prodos_diskimage_nextenum(imgtool_directory *enumeration, im prodos_dirent pd_ent; UINT32 max_filesize; - image = imgtool_directory_image(enumeration); - appleenum = (prodos_direnum *) imgtool_directory_extrabytes(enumeration); + image = &enumeration->image(); + appleenum = (prodos_direnum *) enumeration->extra_bytes(); do { @@ -1675,10 +1675,10 @@ static imgtoolerr_t prodos_write_file_tree(imgtool::image *image, UINT32 *filesi -static imgtoolerr_t prodos_diskimage_freespace(imgtool_partition *partition, UINT64 *size) +static imgtoolerr_t prodos_diskimage_freespace(imgtool::partition *partition, UINT64 *size) { imgtoolerr_t err; - imgtool::image *image = imgtool_partition_image(partition); + imgtool::image *image = &partition->image(); prodos_diskinfo *di; UINT8 *bitmap = NULL; UINT16 i; @@ -1704,10 +1704,10 @@ done: -static imgtoolerr_t prodos_diskimage_readfile(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *destf) +static imgtoolerr_t prodos_diskimage_readfile(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *destf) { imgtoolerr_t err; - imgtool::image *image = imgtool_partition_image(partition); + imgtool::image *image = &partition->image(); prodos_dirent ent; UINT16 key_pointer; int nest_level; @@ -1744,10 +1744,10 @@ static imgtoolerr_t prodos_diskimage_readfile(imgtool_partition *partition, cons -static imgtoolerr_t prodos_diskimage_writefile(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) +static imgtoolerr_t prodos_diskimage_writefile(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) { imgtoolerr_t err; - imgtool::image *image = imgtool_partition_image(partition); + imgtool::image *image = &partition->image(); prodos_dirent ent; prodos_direnum direnum; UINT64 file_size; @@ -1782,10 +1782,10 @@ static imgtoolerr_t prodos_diskimage_writefile(imgtool_partition *partition, con -static imgtoolerr_t prodos_diskimage_deletefile(imgtool_partition *partition, const char *path) +static imgtoolerr_t prodos_diskimage_deletefile(imgtool::partition *partition, const char *path) { imgtoolerr_t err; - imgtool::image *image = imgtool_partition_image(partition); + imgtool::image *image = &partition->image(); prodos_dirent ent; prodos_direnum direnum; @@ -1815,10 +1815,10 @@ static imgtoolerr_t prodos_diskimage_deletefile(imgtool_partition *partition, co -static imgtoolerr_t prodos_diskimage_listforks(imgtool_partition *partition, const char *path, imgtool_forkent *ents, size_t len) +static imgtoolerr_t prodos_diskimage_listforks(imgtool::partition *partition, const char *path, imgtool_forkent *ents, size_t len) { imgtoolerr_t err; - imgtool::image *image = imgtool_partition_image(partition); + imgtool::image *image = &partition->image(); prodos_dirent ent; prodos_direnum direnum; int fork_num = 0; @@ -1851,10 +1851,10 @@ static imgtoolerr_t prodos_diskimage_listforks(imgtool_partition *partition, con -static imgtoolerr_t prodos_diskimage_createdir(imgtool_partition *partition, const char *path) +static imgtoolerr_t prodos_diskimage_createdir(imgtool::partition *partition, const char *path) { imgtoolerr_t err; - imgtool::image *image = imgtool_partition_image(partition); + imgtool::image *image = &partition->image(); prodos_dirent ent; prodos_direnum direnum; @@ -1909,10 +1909,10 @@ static imgtoolerr_t prodos_free_directory(imgtool::image *image, UINT8 *volume_b -static imgtoolerr_t prodos_diskimage_deletedir(imgtool_partition *partition, const char *path) +static imgtoolerr_t prodos_diskimage_deletedir(imgtool::partition *partition, const char *path) { imgtoolerr_t err; - imgtool::image *image = imgtool_partition_image(partition); + imgtool::image *image = &partition->image(); prodos_dirent ent; prodos_direnum direnum; UINT8 *volume_bitmap = NULL; @@ -1999,10 +1999,10 @@ static imgtoolerr_t prodos_get_file_tree(imgtool::image *image, imgtool_chainent -static imgtoolerr_t prodos_diskimage_getattrs(imgtool_partition *partition, const char *path, const UINT32 *attrs, imgtool_attribute *values) +static imgtoolerr_t prodos_diskimage_getattrs(imgtool::partition *partition, const char *path, const UINT32 *attrs, imgtool_attribute *values) { imgtoolerr_t err; - imgtool::image *image = imgtool_partition_image(partition); + imgtool::image *image = &partition->image(); prodos_dirent ent; int i; @@ -2062,10 +2062,10 @@ static imgtoolerr_t prodos_diskimage_getattrs(imgtool_partition *partition, cons -static imgtoolerr_t prodos_diskimage_setattrs(imgtool_partition *partition, const char *path, const UINT32 *attrs, const imgtool_attribute *values) +static imgtoolerr_t prodos_diskimage_setattrs(imgtool::partition *partition, const char *path, const UINT32 *attrs, const imgtool_attribute *values) { imgtoolerr_t err; - imgtool::image *image = imgtool_partition_image(partition); + imgtool::image *image = &partition->image(); prodos_dirent ent; prodos_direnum direnum; int i; @@ -2130,10 +2130,10 @@ static imgtoolerr_t prodos_diskimage_setattrs(imgtool_partition *partition, cons -static imgtoolerr_t prodos_diskimage_suggesttransfer(imgtool_partition *partition, const char *path, imgtool_transfer_suggestion *suggestions, size_t suggestions_length) +static imgtoolerr_t prodos_diskimage_suggesttransfer(imgtool::partition *partition, const char *path, imgtool_transfer_suggestion *suggestions, size_t suggestions_length) { imgtoolerr_t err; - imgtool::image *image = imgtool_partition_image(partition); + imgtool::image *image = &partition->image(); prodos_dirent ent; mac_filecategory_t file_category = MAC_FILECATEGORY_DATA; @@ -2153,10 +2153,10 @@ static imgtoolerr_t prodos_diskimage_suggesttransfer(imgtool_partition *partitio -static imgtoolerr_t prodos_diskimage_getchain(imgtool_partition *partition, const char *path, imgtool_chainent *chain, size_t chain_size) +static imgtoolerr_t prodos_diskimage_getchain(imgtool::partition *partition, const char *path, imgtool_chainent *chain, size_t chain_size) { imgtoolerr_t err; - imgtool::image *image = imgtool_partition_image(partition); + imgtool::image *image = &partition->image(); prodos_dirent ent; size_t chain_pos = 0; int fork_num; diff --git a/src/tools/imgtool/modules/psion.cpp b/src/tools/imgtool/modules/psion.cpp index 05687e4aca5..e0b5e7f5421 100644 --- a/src/tools/imgtool/modules/psion.cpp +++ b/src/tools/imgtool/modules/psion.cpp @@ -447,19 +447,19 @@ static void datapack_close( imgtool::image *image) stream_close( pack->stream ); } -static imgtoolerr_t datapack_begin_enum(imgtool_directory *enumeration, const char *path) +static imgtoolerr_t datapack_begin_enum(imgtool::directory *enumeration, const char *path) { - psion_iter *iter = (psion_iter*)imgtool_directory_extrabytes(enumeration); + psion_iter *iter = (psion_iter*)enumeration->extra_bytes(); iter->index = 0; return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t datapack_next_enum(imgtool_directory *enumeration, imgtool_dirent *ent) +static imgtoolerr_t datapack_next_enum(imgtool::directory *enumeration, imgtool_dirent *ent) { - imgtool::image *image = imgtool_directory_image(enumeration); + imgtool::image *image = &enumeration->image(); psion_pack *pack = (psion_pack*)image->extra_bytes(); - psion_iter *iter = (psion_iter*)imgtool_directory_extrabytes(enumeration); + psion_iter *iter = (psion_iter*)enumeration->extra_bytes(); UINT8 data = 0; if (!pack->pack_index[iter->index].name_rec) @@ -492,13 +492,13 @@ static imgtoolerr_t datapack_next_enum(imgtool_directory *enumeration, imgtool_d return IMGTOOLERR_SUCCESS; } -static void datapack_close_enum( imgtool_directory *enumeration) +static void datapack_close_enum( imgtool::directory *enumeration) { } -static imgtoolerr_t datapack_free_space( imgtool_partition *partition, UINT64 *size) +static imgtoolerr_t datapack_free_space( imgtool::partition *partition, UINT64 *size) { - imgtool::image *image = imgtool_partition_image( partition); + imgtool::image *image = &partition->image(); psion_pack *pack = (psion_pack*)image->extra_bytes(); UINT32 pack_size = 0; @@ -511,9 +511,9 @@ static imgtoolerr_t datapack_free_space( imgtool_partition *partition, UINT64 *s return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t datapack_read_file(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *destf) +static imgtoolerr_t datapack_read_file(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *destf) { - imgtool::image *image = imgtool_partition_image(partition); + imgtool::image *image = &partition->image(); psion_pack *pack = (psion_pack*)image->extra_bytes(); int index = seek_file_name(pack, filename); @@ -543,9 +543,9 @@ static imgtoolerr_t datapack_read_file(imgtool_partition *partition, const char return IMGTOOLERR_FILENOTFOUND; } -static imgtoolerr_t datapack_write_file( imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) +static imgtoolerr_t datapack_write_file( imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) { - imgtool::image *image = imgtool_partition_image(partition); + imgtool::image *image = &partition->image(); psion_pack *pack = (psion_pack*)image->extra_bytes(); static const UINT8 data_head[4] = {0x02, 0x80, 0x00, 0x00}; UINT8 head[3]; @@ -605,9 +605,9 @@ static imgtoolerr_t datapack_write_file( imgtool_partition *partition, const cha return IMGTOOLERR_CORRUPTIMAGE; } -static imgtoolerr_t datapack_delete_file( imgtool_partition *partition, const char *filename) +static imgtoolerr_t datapack_delete_file( imgtool::partition *partition, const char *filename) { - imgtool::image *image = imgtool_partition_image(partition); + imgtool::image *image = &partition->image(); psion_pack *pack = (psion_pack*)image->extra_bytes(); int index = seek_file_name(pack, filename); diff --git a/src/tools/imgtool/modules/rsdos.cpp b/src/tools/imgtool/modules/rsdos.cpp index cc08e1da682..eb34bd45a29 100644 --- a/src/tools/imgtool/modules/rsdos.cpp +++ b/src/tools/imgtool/modules/rsdos.cpp @@ -262,7 +262,7 @@ static imgtoolerr_t prepare_dirent(struct rsdos_dirent *ent, const char *fname) -static imgtoolerr_t rsdos_diskimage_nextenum(imgtool_directory *enumeration, imgtool_dirent *ent) +static imgtoolerr_t rsdos_diskimage_nextenum(imgtool::directory *enumeration, imgtool_dirent *ent) { floperr_t ferr; imgtoolerr_t err; @@ -272,8 +272,8 @@ static imgtoolerr_t rsdos_diskimage_nextenum(imgtool_directory *enumeration, img char fname[13]; imgtool::image *image; - image = imgtool_directory_image(enumeration); - rsenum = (struct rsdos_direnum *) imgtool_directory_extrabytes(enumeration); + image = &enumeration->image(); + rsenum = (struct rsdos_direnum *) enumeration->extra_bytes(); /* Did we hit the end of file before? */ if (rsenum->eof) @@ -327,14 +327,14 @@ eof: -static imgtoolerr_t rsdos_diskimage_freespace(imgtool_partition *partition, UINT64 *size) +static imgtoolerr_t rsdos_diskimage_freespace(imgtool::partition *partition, UINT64 *size) { floperr_t ferr; UINT8 i; size_t s = 0; UINT8 granule_count; UINT8 granule_map[MAX_GRANULEMAP_SIZE]; - imgtool::image *image = imgtool_partition_image(partition); + imgtool::image *image = &partition->image(); ferr = get_granule_map(image, granule_map, &granule_count); if (ferr) @@ -386,12 +386,12 @@ static imgtoolerr_t delete_entry(imgtool::image *img, struct rsdos_dirent *ent, -static imgtoolerr_t rsdos_diskimage_readfile(imgtool_partition *partition, const char *fname, const char *fork, imgtool_stream *destf) +static imgtoolerr_t rsdos_diskimage_readfile(imgtool::partition *partition, const char *fname, const char *fork, imgtool_stream *destf) { imgtoolerr_t err; struct rsdos_dirent ent; size_t size; - imgtool::image *img = imgtool_partition_image(partition); + imgtool::image *img = &partition->image(); err = lookup_rsdos_file(img, fname, &ent, NULL); if (err) @@ -409,11 +409,11 @@ static imgtoolerr_t rsdos_diskimage_readfile(imgtool_partition *partition, const -static imgtoolerr_t rsdos_diskimage_writefile(imgtool_partition *partition, const char *fname, const char *fork, imgtool_stream *sourcef, util::option_resolution *writeoptions) +static imgtoolerr_t rsdos_diskimage_writefile(imgtool::partition *partition, const char *fname, const char *fork, imgtool_stream *sourcef, util::option_resolution *writeoptions) { floperr_t ferr; imgtoolerr_t err; - imgtool::image *img = imgtool_partition_image(partition); + imgtool::image *img = &partition->image(); struct rsdos_dirent ent, ent2; size_t i; UINT64 sz; @@ -514,10 +514,10 @@ static imgtoolerr_t rsdos_diskimage_writefile(imgtool_partition *partition, cons -static imgtoolerr_t rsdos_diskimage_deletefile(imgtool_partition *partition, const char *fname) +static imgtoolerr_t rsdos_diskimage_deletefile(imgtool::partition *partition, const char *fname) { imgtoolerr_t err; - imgtool::image *image = imgtool_partition_image(partition); + imgtool::image *image = &partition->image(); int pos; struct rsdos_dirent ent; @@ -530,10 +530,10 @@ static imgtoolerr_t rsdos_diskimage_deletefile(imgtool_partition *partition, con -static imgtoolerr_t rsdos_diskimage_suggesttransfer(imgtool_partition *partition, const char *fname, imgtool_transfer_suggestion *suggestions, size_t suggestions_length) +static imgtoolerr_t rsdos_diskimage_suggesttransfer(imgtool::partition *partition, const char *fname, imgtool_transfer_suggestion *suggestions, size_t suggestions_length) { imgtoolerr_t err; - imgtool::image *image = imgtool_partition_image(partition); + imgtool::image *image = &partition->image(); struct rsdos_dirent ent; int pos; diff --git a/src/tools/imgtool/modules/thomson.cpp b/src/tools/imgtool/modules/thomson.cpp index 50b56507bca..2d8c72b842f 100644 --- a/src/tools/imgtool/modules/thomson.cpp +++ b/src/tools/imgtool/modules/thomson.cpp @@ -866,34 +866,34 @@ static imgtoolerr_t thom_list_partitions(imgtool::image *img, return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t thom_open_partition(imgtool_partition *part, +static imgtoolerr_t thom_open_partition(imgtool::partition *part, UINT64 first_block, UINT64 block_count) { - imgtool::image* img = imgtool_partition_image( part ); + imgtool::image* img = &part->image(); thom_floppy* f = (thom_floppy*) img->extra_bytes(); if ( first_block >= f->heads ) return IMGTOOLERR_INVALIDPARTITION; - * ( (int*) imgtool_partition_extra_bytes( part ) ) = first_block; + * ( (int*) part->extra_bytes() ) = first_block; return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t thom_begin_enum(imgtool_directory *enumeration, +static imgtoolerr_t thom_begin_enum(imgtool::directory *enumeration, const char *path) { - int* n = (int*) imgtool_directory_extrabytes( enumeration ); + int* n = (int*) enumeration->extra_bytes(); *n = 0; return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t thom_next_enum(imgtool_directory *enumeration, +static imgtoolerr_t thom_next_enum(imgtool::directory *enumeration, imgtool_dirent *ent) { - imgtool_partition *part = imgtool_directory_partition( enumeration); - int head = *( (int*) imgtool_partition_extra_bytes( part ) ); - imgtool::image* img = imgtool_partition_image( part ); + imgtool::partition *part = &enumeration->partition(); + int head = *( (int*) part->extra_bytes() ); + imgtool::image* img = &part->image(); thom_floppy* f = (thom_floppy*) img->extra_bytes(); - int* n = (int*) imgtool_directory_extrabytes( enumeration ); + int* n = (int*) enumeration->extra_bytes(); thom_dirent d; do { @@ -924,23 +924,23 @@ static imgtoolerr_t thom_next_enum(imgtool_directory *enumeration, return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t thom_free_space(imgtool_partition *part, UINT64 *size) +static imgtoolerr_t thom_free_space(imgtool::partition *part, UINT64 *size) { - int head = *( (int*) imgtool_partition_extra_bytes( part ) ); - imgtool::image* img = imgtool_partition_image( part ); + int head = *( (int*) part->extra_bytes() ); + imgtool::image* img = &part->image(); thom_floppy* f = (thom_floppy*) img->extra_bytes(); int nb = thom_get_free_blocks( f, head ); (*size) = nb * f->sectuse_size * 8; return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t thom_read_file(imgtool_partition *part, +static imgtoolerr_t thom_read_file(imgtool::partition *part, const char *filename, const char *fork, imgtool_stream *destf) { - int head = *( (int*) imgtool_partition_extra_bytes( part ) ); - imgtool::image* img = imgtool_partition_image( part ); + int head = *( (int*) part->extra_bytes() ); + imgtool::image* img = &part->image(); thom_floppy* f = (thom_floppy*) img->extra_bytes(); thom_dirent d; char name[9], ext[4], fname[14]; @@ -958,11 +958,11 @@ static imgtoolerr_t thom_read_file(imgtool_partition *part, return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t thom_delete_file(imgtool_partition *part, +static imgtoolerr_t thom_delete_file(imgtool::partition *part, const char *filename) { - int head = *( (int*) imgtool_partition_extra_bytes( part ) ); - imgtool::image* img = imgtool_partition_image( part ); + int head = *( (int*) part->extra_bytes() ); + imgtool::image* img = &part->image(); thom_floppy* f = (thom_floppy*) img->extra_bytes(); thom_dirent d; char name[9], ext[4], fname[14]; @@ -979,14 +979,14 @@ static imgtoolerr_t thom_delete_file(imgtool_partition *part, return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t thom_write_file(imgtool_partition *part, +static imgtoolerr_t thom_write_file(imgtool::partition *part, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) { - int head = *( (int*) imgtool_partition_extra_bytes( part ) ); - imgtool::image* img = imgtool_partition_image( part ); + int head = *( (int*) part->extra_bytes() ); + imgtool::image* img = &part->image(); thom_floppy* f = (thom_floppy*) img->extra_bytes(); thom_dirent d; int size = stream_size( sourcef ); @@ -1063,13 +1063,13 @@ static imgtoolerr_t thom_write_file(imgtool_partition *part, return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t thom_suggest_transfer(imgtool_partition *part, +static imgtoolerr_t thom_suggest_transfer(imgtool::partition *part, const char *fname, imgtool_transfer_suggestion *suggestions, size_t suggestions_length) { - int head = *( (int*) imgtool_partition_extra_bytes( part ) ); - imgtool::image* img = imgtool_partition_image( part ); + int head = *( (int*) part->extra_bytes() ); + imgtool::image* img = &part->image(); thom_floppy* f = (thom_floppy*) img->extra_bytes(); thom_dirent d; int is_basic = 0; @@ -1303,7 +1303,7 @@ static void thom_encrypt(imgtool_stream* out, imgtool_stream* in) } } -static imgtoolerr_t thomcrypt_read_file(imgtool_partition *part, +static imgtoolerr_t thomcrypt_read_file(imgtool::partition *part, const char *name, const char *fork, imgtool_stream *dst) { @@ -1336,7 +1336,7 @@ static imgtoolerr_t thomcrypt_read_file(imgtool_partition *part, return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t thomcrypt_write_file(imgtool_partition *part, +static imgtoolerr_t thomcrypt_write_file(imgtool::partition *part, const char *name, const char *fork, imgtool_stream *src, util::option_resolution *opts) @@ -1382,7 +1382,7 @@ void filter_thomcrypt_getinfo(UINT32 state, union filterinfo *info) } /* untokenization automatically decrypt protected files */ -static imgtoolerr_t thom_basic_read_file(imgtool_partition *part, +static imgtoolerr_t thom_basic_read_file(imgtool::partition *part, const char *name, const char *fork, imgtool_stream *dst, @@ -1452,7 +1452,7 @@ static imgtoolerr_t thom_basic_read_file(imgtool_partition *part, return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t thom_basic_write_file(imgtool_partition *part, +static imgtoolerr_t thom_basic_write_file(imgtool::partition *part, const char *name, const char *fork, imgtool_stream *src, @@ -1464,14 +1464,14 @@ static imgtoolerr_t thom_basic_write_file(imgtool_partition *part, #define FILTER(short,long) \ - static imgtoolerr_t short##_read_file(imgtool_partition *part, \ + static imgtoolerr_t short##_read_file(imgtool::partition *part, \ const char *name, \ const char *fork, \ imgtool_stream *dst) \ { \ return thom_basic_read_file( part, name, fork, dst, short ); \ } \ - static imgtoolerr_t short##_write_file(imgtool_partition *part, \ + static imgtoolerr_t short##_write_file(imgtool::partition *part, \ const char *name, \ const char *fork, \ imgtool_stream *src, \ diff --git a/src/tools/imgtool/modules/ti99.cpp b/src/tools/imgtool/modules/ti99.cpp index d50826e6c7f..7ca8f2ab4dd 100644 --- a/src/tools/imgtool/modules/ti99.cpp +++ b/src/tools/imgtool/modules/ti99.cpp @@ -3855,15 +3855,15 @@ static imgtoolerr_t dsk_image_init_pc99_mfm(imgtool::image *image, imgtool_strea static imgtoolerr_t win_image_init(imgtool::image *image, imgtool_stream *f); static void ti99_image_exit(imgtool::image *img); static void ti99_image_info(imgtool::image *img, char *string, size_t len); -static imgtoolerr_t dsk_image_beginenum(imgtool_directory *enumeration, const char *path); -static imgtoolerr_t dsk_image_nextenum(imgtool_directory *enumeration, imgtool_dirent *ent); -static imgtoolerr_t win_image_beginenum(imgtool_directory *enumeration, const char *path); -static imgtoolerr_t win_image_nextenum(imgtool_directory *enumeration, imgtool_dirent *ent); -static imgtoolerr_t ti99_image_freespace(imgtool_partition *partition, UINT64 *size); -static imgtoolerr_t ti99_image_readfile(imgtool_partition *partition, const char *fpath, const char *fork, imgtool_stream *destf); -static imgtoolerr_t ti99_image_writefile(imgtool_partition *partition, const char *fpath, const char *fork, imgtool_stream *sourcef, util::option_resolution *writeoptions); -static imgtoolerr_t dsk_image_deletefile(imgtool_partition *partition, const char *fpath); -static imgtoolerr_t win_image_deletefile(imgtool_partition *partition, const char *fpath); +static imgtoolerr_t dsk_image_beginenum(imgtool::directory *enumeration, const char *path); +static imgtoolerr_t dsk_image_nextenum(imgtool::directory *enumeration, imgtool_dirent *ent); +static imgtoolerr_t win_image_beginenum(imgtool::directory *enumeration, const char *path); +static imgtoolerr_t win_image_nextenum(imgtool::directory *enumeration, imgtool_dirent *ent); +static imgtoolerr_t ti99_image_freespace(imgtool::partition *partition, UINT64 *size); +static imgtoolerr_t ti99_image_readfile(imgtool::partition *partition, const char *fpath, const char *fork, imgtool_stream *destf); +static imgtoolerr_t ti99_image_writefile(imgtool::partition *partition, const char *fpath, const char *fork, imgtool_stream *sourcef, util::option_resolution *writeoptions); +static imgtoolerr_t dsk_image_deletefile(imgtool::partition *partition, const char *fpath); +static imgtoolerr_t win_image_deletefile(imgtool::partition *partition, const char *fpath); static imgtoolerr_t dsk_image_create_mess(imgtool::image *image, imgtool_stream *f, util::option_resolution *createoptions); static imgtoolerr_t dsk_image_create_v9t9(imgtool::image *image, imgtool_stream *f, util::option_resolution *createoptions); @@ -4209,10 +4209,10 @@ static void ti99_image_info(imgtool::image *img, char *string, size_t len) /* Open the disk catalog for enumeration */ -static imgtoolerr_t dsk_image_beginenum(imgtool_directory *enumeration, const char *path) +static imgtoolerr_t dsk_image_beginenum(imgtool::directory *enumeration, const char *path) { - struct ti99_lvl2_imgref *image = (struct ti99_lvl2_imgref *) imgtool_directory_image(enumeration)->extra_bytes(); - dsk_iterator *iter = (dsk_iterator *) imgtool_directory_extrabytes(enumeration); + struct ti99_lvl2_imgref *image = (struct ti99_lvl2_imgref *) enumeration->image().extra_bytes(); + dsk_iterator *iter = (dsk_iterator *) enumeration->extra_bytes(); iter->image = image; iter->level = 0; @@ -4226,9 +4226,9 @@ static imgtoolerr_t dsk_image_beginenum(imgtool_directory *enumeration, const ch /* Enumerate disk catalog next entry */ -static imgtoolerr_t dsk_image_nextenum(imgtool_directory *enumeration, imgtool_dirent *ent) +static imgtoolerr_t dsk_image_nextenum(imgtool::directory *enumeration, imgtool_dirent *ent) { - dsk_iterator *iter = (dsk_iterator*) imgtool_directory_extrabytes(enumeration); + dsk_iterator *iter = (dsk_iterator*) enumeration->extra_bytes(); dsk_fdr fdr; int reply; unsigned fdr_aphysrec; @@ -4334,10 +4334,10 @@ static imgtoolerr_t dsk_image_nextenum(imgtool_directory *enumeration, imgtool_d /* Open the disk catalog for enumeration */ -static imgtoolerr_t win_image_beginenum(imgtool_directory *enumeration, const char *path) +static imgtoolerr_t win_image_beginenum(imgtool::directory *enumeration, const char *path) { - struct ti99_lvl2_imgref *image = (struct ti99_lvl2_imgref *) imgtool_directory_image(enumeration)->extra_bytes(); - win_iterator *iter = (win_iterator *) imgtool_directory_extrabytes(enumeration); + struct ti99_lvl2_imgref *image = (struct ti99_lvl2_imgref *) enumeration->image().extra_bytes(); + win_iterator *iter = (win_iterator *) enumeration->extra_bytes(); imgtoolerr_t errorcode; iter->image = image; @@ -4354,9 +4354,9 @@ static imgtoolerr_t win_image_beginenum(imgtool_directory *enumeration, const ch /* Enumerate disk catalog next entry */ -static imgtoolerr_t win_image_nextenum(imgtool_directory *enumeration, imgtool_dirent *ent) +static imgtoolerr_t win_image_nextenum(imgtool::directory *enumeration, imgtool_dirent *ent) { - win_iterator *iter = (win_iterator *) imgtool_directory_extrabytes(enumeration); + win_iterator *iter = (win_iterator *) enumeration->extra_bytes(); unsigned fdr_aphysrec; win_fdr fdr; int reply; @@ -4478,9 +4478,9 @@ static imgtoolerr_t win_image_nextenum(imgtool_directory *enumeration, imgtool_d /* Compute free space on disk image (in AUs) */ -static imgtoolerr_t ti99_image_freespace(imgtool_partition *partition, UINT64 *size) +static imgtoolerr_t ti99_image_freespace(imgtool::partition *partition, UINT64 *size) { - imgtool::image *img = imgtool_partition_image(partition); + imgtool::image *img = &partition->image(); struct ti99_lvl2_imgref *image = (struct ti99_lvl2_imgref *) img->extra_bytes(); size_t freeAUs; int i; @@ -4502,9 +4502,9 @@ static imgtoolerr_t ti99_image_freespace(imgtool_partition *partition, UINT64 *s /* Extract a file from a ti99_image. The file is saved in tifile format. */ -static imgtoolerr_t ti99_image_readfile(imgtool_partition *partition, const char *fpath, const char *fork, imgtool_stream *destf) +static imgtoolerr_t ti99_image_readfile(imgtool::partition *partition, const char *fpath, const char *fork, imgtool_stream *destf) { - imgtool::image *img = imgtool_partition_image(partition); + imgtool::image *img = &partition->image(); #if 1 /* extract data as TIFILES */ @@ -4644,9 +4644,9 @@ static imgtoolerr_t ti99_image_readfile(imgtool_partition *partition, const char /* Add a file to a ti99_image. The file must be in tifile format. */ -static imgtoolerr_t ti99_image_writefile(imgtool_partition *partition, const char *fpath, const char *fork, imgtool_stream *sourcef, util::option_resolution *writeoptions) +static imgtoolerr_t ti99_image_writefile(imgtool::partition *partition, const char *fpath, const char *fork, imgtool_stream *sourcef, util::option_resolution *writeoptions) { - imgtool::image *img = imgtool_partition_image(partition); + imgtool::image *img = &partition->image(); struct ti99_lvl2_imgref *image = (struct ti99_lvl2_imgref *) img->extra_bytes(); const char *filename; char ti_fname[10]; @@ -4870,9 +4870,9 @@ static imgtoolerr_t ti99_image_writefile(imgtool_partition *partition, const cha /* Delete a file from a ti99_image. */ -static imgtoolerr_t dsk_image_deletefile(imgtool_partition *partition, const char *fpath) +static imgtoolerr_t dsk_image_deletefile(imgtool::partition *partition, const char *fpath) { - imgtool::image *img = imgtool_partition_image(partition); + imgtool::image *img = &partition->image(); struct ti99_lvl2_imgref *image = (struct ti99_lvl2_imgref *) img->extra_bytes(); dsk_fdr fdr; int i, cluster_index; @@ -5012,9 +5012,9 @@ static imgtoolerr_t dsk_image_deletefile(imgtool_partition *partition, const cha return (imgtoolerr_t)0; } -static imgtoolerr_t win_image_deletefile(imgtool_partition *partition, const char *fpath) +static imgtoolerr_t win_image_deletefile(imgtool::partition *partition, const char *fpath) { - imgtool::image *img = imgtool_partition_image(partition); + imgtool::image *img = &partition->image(); struct ti99_lvl2_imgref *image = (struct ti99_lvl2_imgref *) img->extra_bytes(); int parent_ddr_AU, is_dir, catalog_index; win_fdr fdr; diff --git a/src/tools/imgtool/modules/ti990hd.cpp b/src/tools/imgtool/modules/ti990hd.cpp index bd8bc2063fb..87f4c668ce1 100644 --- a/src/tools/imgtool/modules/ti990hd.cpp +++ b/src/tools/imgtool/modules/ti990hd.cpp @@ -389,14 +389,14 @@ struct ti990_iterator static imgtoolerr_t ti990_image_init(imgtool::image *img, imgtool_stream *f); static void ti990_image_exit(imgtool::image *img); static void ti990_image_info(imgtool::image *img, char *string, size_t len); -static imgtoolerr_t ti990_image_beginenum(imgtool_directory *enumeration, const char *path); -static imgtoolerr_t ti990_image_nextenum(imgtool_directory *enumeration, imgtool_dirent *ent); -static void ti990_image_closeenum(imgtool_directory *enumeration); -static imgtoolerr_t ti990_image_freespace(imgtool_partition *partition, UINT64 *size); +static imgtoolerr_t ti990_image_beginenum(imgtool::directory *enumeration, const char *path); +static imgtoolerr_t ti990_image_nextenum(imgtool::directory *enumeration, imgtool_dirent *ent); +static void ti990_image_closeenum(imgtool::directory *enumeration); +static imgtoolerr_t ti990_image_freespace(imgtool::partition *partition, UINT64 *size); #ifdef UNUSED_FUNCTION -static imgtoolerr_t ti990_image_readfile(imgtool_partition *partition, const char *fpath, imgtool_stream *destf); -static imgtoolerr_t ti990_image_writefile(imgtool_partition *partition, const char *fpath, imgtool_stream *sourcef, util::option_resolution *writeoptions); -static imgtoolerr_t ti990_image_deletefile(imgtool_partition *partition, const char *fpath); +static imgtoolerr_t ti990_image_readfile(imgtool::partition *partition, const char *fpath, imgtool_stream *destf); +static imgtoolerr_t ti990_image_writefile(imgtool::partition *partition, const char *fpath, imgtool_stream *sourcef, util::option_resolution *writeoptions); +static imgtoolerr_t ti990_image_deletefile(imgtool::partition *partition, const char *fpath); #endif static imgtoolerr_t ti990_image_create(imgtool::image *image, imgtool_stream *f, util::option_resolution *createoptions); @@ -1186,10 +1186,10 @@ static void ti990_image_info(imgtool::image *img, char *string, size_t len) /* Open the disk catalog for enumeration */ -static imgtoolerr_t ti990_image_beginenum(imgtool_directory *enumeration, const char *path) +static imgtoolerr_t ti990_image_beginenum(imgtool::directory *enumeration, const char *path) { - ti990_image *image = (ti990_image *) imgtool_directory_image(enumeration)->extra_bytes(); - ti990_iterator *iter = (ti990_iterator *) imgtool_directory_extrabytes(enumeration); + ti990_image *image = (ti990_image *) enumeration->image().extra_bytes(); + ti990_iterator *iter = (ti990_iterator *) enumeration->extra_bytes(); ti990_dor dor; int reply; @@ -1212,9 +1212,9 @@ static imgtoolerr_t ti990_image_beginenum(imgtool_directory *enumeration, const /* Enumerate disk catalog next entry */ -static imgtoolerr_t ti990_image_nextenum(imgtool_directory *enumeration, imgtool_dirent *ent) +static imgtoolerr_t ti990_image_nextenum(imgtool::directory *enumeration, imgtool_dirent *ent) { - ti990_iterator *iter = (ti990_iterator *) imgtool_directory_extrabytes(enumeration); + ti990_iterator *iter = (ti990_iterator *) enumeration->extra_bytes(); int flag; int reply = 0; @@ -1406,16 +1406,16 @@ static imgtoolerr_t ti990_image_nextenum(imgtool_directory *enumeration, imgtool /* Free enumerator */ -static void ti990_image_closeenum(imgtool_directory *enumeration) +static void ti990_image_closeenum(imgtool::directory *enumeration) { } /* Compute free space on disk image (in ADUs) */ -static imgtoolerr_t ti990_image_freespace(imgtool_partition *partition, UINT64 *size) +static imgtoolerr_t ti990_image_freespace(imgtool::partition *partition, UINT64 *size) { - imgtool::image *img = imgtool_partition_image(partition); + imgtool::image *img = &partition->image(); ti990_image *image = (ti990_image *) img->extra_bytes(); int totadus = get_UINT16BE(image->sec0.tna); int adu, record, sub_adu; @@ -1453,9 +1453,9 @@ static imgtoolerr_t ti990_image_freespace(imgtool_partition *partition, UINT64 * /* Extract a file from a ti990_image. */ -static imgtoolerr_t ti990_image_readfile(imgtool_partition *partition, const char *fpath, imgtool_stream *destf) +static imgtoolerr_t ti990_image_readfile(imgtool::partition *partition, const char *fpath, imgtool_stream *destf) { - imgtool::image *img = imgtool_partition_image(partition); + imgtool::image *img = &partition->image(); ti990_image *image = (ti990_image *) img->extra_bytes(); int catalog_index, fdr_secnum, parent_fdr_secnum; imgtoolerr_t reply; @@ -1550,9 +1550,9 @@ static imgtoolerr_t ti990_image_readfile(imgtool_partition *partition, const cha /* Add a file to a ti990_image. */ -static imgtoolerr_t ti990_image_writefile(imgtool_partition *partition, const char *fpath, imgtool_stream *sourcef, util::option_resolution *writeoptions) +static imgtoolerr_t ti990_image_writefile(imgtool::partition *partition, const char *fpath, imgtool_stream *sourcef, util::option_resolution *writeoptions) { - imgtool::image *img = imgtool_partition_image(partition); + imgtool::image *img = &partition->image(); ti990_image *image = (ti990_image *) img->extra_bytes(); int catalog_index, fdr_secnum, parent_fdr_secnum; imgtoolerr_t reply; @@ -1674,9 +1674,9 @@ static imgtoolerr_t ti990_image_writefile(imgtool_partition *partition, const ch /* Delete a file from a ti990_image. */ -static imgtoolerr_t ti990_image_deletefile(imgtool_partition *partition, const char *fpath) +static imgtoolerr_t ti990_image_deletefile(imgtool::partition *partition, const char *fpath) { - imgtool::image *img = imgtool_partition_image(partition); + imgtool::image *img = &partition->image(); ti990_image *image = (ti990_image *) img->extra_bytes(); int catalog_index, fdr_secnum, parent_fdr_secnum; imgtoolerr_t reply; diff --git a/src/tools/imgtool/modules/vzdos.cpp b/src/tools/imgtool/modules/vzdos.cpp index 7f7eae8ab9b..706210b9182 100644 --- a/src/tools/imgtool/modules/vzdos.cpp +++ b/src/tools/imgtool/modules/vzdos.cpp @@ -385,11 +385,11 @@ static imgtoolerr_t vzdos_write_formatted_sector(imgtool::image *img, int track, Imgtool module code *********************************************************************/ -static imgtoolerr_t vzdos_diskimage_beginenum(imgtool_directory *enumeration, const char *path) +static imgtoolerr_t vzdos_diskimage_beginenum(imgtool::directory *enumeration, const char *path) { vz_iterator *iter; - iter = (vz_iterator *) imgtool_directory_extrabytes(enumeration); + iter = (vz_iterator *) enumeration->extra_bytes(); if (!iter) return IMGTOOLERR_OUTOFMEMORY; iter->index = 1; @@ -398,9 +398,9 @@ static imgtoolerr_t vzdos_diskimage_beginenum(imgtool_directory *enumeration, co return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t vzdos_diskimage_nextenum(imgtool_directory *enumeration, imgtool_dirent *ent) +static imgtoolerr_t vzdos_diskimage_nextenum(imgtool::directory *enumeration, imgtool_dirent *ent) { - vz_iterator *iter = (vz_iterator *) imgtool_directory_extrabytes(enumeration); + vz_iterator *iter = (vz_iterator *) enumeration->extra_bytes(); if (iter->eof == 1 || iter->index > MAX_DIRENTS) { ent->eof = 1; @@ -410,7 +410,7 @@ static imgtoolerr_t vzdos_diskimage_nextenum(imgtool_directory *enumeration, img int ret, len; vzdos_dirent dirent; - ret = vzdos_get_dirent(imgtool_directory_image(enumeration), iter->index - 1, &dirent); + ret = vzdos_get_dirent(&enumeration->image(), iter->index - 1, &dirent); if (ret == IMGTOOLERR_FILENOTFOUND) { @@ -455,11 +455,11 @@ static imgtoolerr_t vzdos_diskimage_nextenum(imgtool_directory *enumeration, img /* TRK 0 sector 15 is used to hold the track map of the disk with one bit corresponding to a sector used. */ -static imgtoolerr_t vzdos_diskimage_freespace(imgtool_partition *partition, UINT64 *size) +static imgtoolerr_t vzdos_diskimage_freespace(imgtool::partition *partition, UINT64 *size) { imgtoolerr_t ret; int i; - imgtool::image *image = imgtool_partition_image(partition); + imgtool::image *image = &partition->image(); UINT8 c, v, buffer[DATA_SIZE + 2]; *size = 0; @@ -478,10 +478,10 @@ static imgtoolerr_t vzdos_diskimage_freespace(imgtool_partition *partition, UINT return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t vzdos_diskimage_readfile(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *destf) +static imgtoolerr_t vzdos_diskimage_readfile(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *destf) { imgtoolerr_t ret; - imgtool::image *image = imgtool_partition_image(partition); + imgtool::image *image = &partition->image(); int filesize, track, sector; vzdos_dirent ent; UINT8 buffer[DATA_SIZE + 2]; @@ -524,10 +524,10 @@ static imgtoolerr_t vzdos_diskimage_readfile(imgtool_partition *partition, const } /* deletes directory entry, clears trackmap entries and sectors */ -static imgtoolerr_t vzdos_diskimage_deletefile(imgtool_partition *partition, const char *fname) +static imgtoolerr_t vzdos_diskimage_deletefile(imgtool::partition *partition, const char *fname) { imgtoolerr_t ret; - imgtool::image *img = imgtool_partition_image(partition); + imgtool::image *img = &partition->image(); int index, filesize, track, sector, next_track, next_sector; vzdos_dirent entry, next_entry; UINT8 buffer[DATA_SIZE + 2]; @@ -602,10 +602,10 @@ static imgtoolerr_t vzdos_diskimage_deletefile(imgtool_partition *partition, con return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t vzdos_writefile(imgtool_partition *partition, int offset, imgtool_stream *sourcef, vzdos_dirent *entry) +static imgtoolerr_t vzdos_writefile(imgtool::partition *partition, int offset, imgtool_stream *sourcef, vzdos_dirent *entry) { imgtoolerr_t ret; - imgtool::image *img = imgtool_partition_image(partition); + imgtool::image *img = &partition->image(); int index, track, sector, toread, next_track, next_sector; vzdos_dirent temp_entry; UINT64 filesize = 0, freespace = 0; @@ -700,7 +700,7 @@ static imgtoolerr_t vzdos_writefile(imgtool_partition *partition, int offset, im } /* create a new file or overwrite a file */ -static imgtoolerr_t vzdos_diskimage_writefile(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) +static imgtoolerr_t vzdos_diskimage_writefile(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) { imgtoolerr_t ret; int ftype; @@ -741,10 +741,10 @@ static imgtoolerr_t vzdos_diskimage_writefile(imgtool_partition *partition, cons return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t vzdos_diskimage_suggesttransfer(imgtool_partition *partition, const char *fname, imgtool_transfer_suggestion *suggestions, size_t suggestions_length) +static imgtoolerr_t vzdos_diskimage_suggesttransfer(imgtool::partition *partition, const char *fname, imgtool_transfer_suggestion *suggestions, size_t suggestions_length) { imgtoolerr_t ret; - imgtool::image *image = imgtool_partition_image(partition); + imgtool::image *image = &partition->image(); vzdos_dirent entry; if (fname) { @@ -808,10 +808,10 @@ static imgtoolerr_t vzdos_diskimage_create(imgtool::image *img, imgtool_stream * Imgtool vz filter code *********************************************************************/ -static imgtoolerr_t vzsnapshot_readfile(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *destf) +static imgtoolerr_t vzsnapshot_readfile(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *destf) { imgtoolerr_t ret; - imgtool::image *image = imgtool_partition_image(partition); + imgtool::image *image = &partition->image(); vzdos_dirent entry; UINT8 header[24]; @@ -852,7 +852,7 @@ static imgtoolerr_t vzsnapshot_readfile(imgtool_partition *partition, const char return IMGTOOLERR_SUCCESS; } -static imgtoolerr_t vzsnapshot_writefile(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) +static imgtoolerr_t vzsnapshot_writefile(imgtool::partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, util::option_resolution *opts) { imgtoolerr_t ret; int fnameopt;