Merge pull request #1516 from npwoods/imgtool_use_rvalue_refs_for_streams

[Imgtool] Changed the create/open callbacks to take 'imgtool::stream &&'
This commit is contained in:
Vas Crabb 2016-10-16 12:02:27 +11:00 committed by GitHub
commit 72c8586e01
22 changed files with 247 additions and 209 deletions

View File

@ -102,10 +102,11 @@ struct imgtool_floppy_image
static imgtoolerr_t imgtool_floppy_open_internal(imgtool::image *image, imgtool::stream &f, int noclose)
static imgtoolerr_t imgtool_floppy_open_internal(imgtool::image *image, imgtool::stream::ptr &&stream, int noclose)
{
floperr_t ferr;
imgtoolerr_t err;
imgtoolerr_t err = IMGTOOLERR_SUCCESS;
imgtool::stream *f = nullptr;
struct imgtool_floppy_image *fimg;
const imgtool_class *imgclass;
const struct FloppyFormat *format;
@ -116,38 +117,46 @@ static imgtoolerr_t imgtool_floppy_open_internal(imgtool::image *image, imgtool:
format = (const struct FloppyFormat *) imgclass->derived_param;
open = (imgtoolerr_t (*)(imgtool::image *, imgtool::stream *)) imgtool_get_info_ptr(imgclass, IMGTOOLINFO_PTR_FLOPPY_OPEN);
/* open up the floppy */
ferr = floppy_open(&f, noclose ? &imgtool_noclose_ioprocs : &imgtool_ioprocs,
// extract the pointer
f = stream.release();
// open up the floppy
ferr = floppy_open(f, noclose ? &imgtool_noclose_ioprocs : &imgtool_ioprocs,
"", format, FLOPPY_FLAGS_READWRITE, &fimg->floppy);
if (ferr)
{
err = imgtool_floppy_error(ferr);
return err;
goto done;
}
f = nullptr; // the floppy object has the stream now
if (open)
{
err = open(image, nullptr);
if (err)
return err;
goto done;
}
return IMGTOOLERR_SUCCESS;
done:
if (f)
delete f;
return err;
}
static imgtoolerr_t imgtool_floppy_open(imgtool::image *image, imgtool::stream &f)
static imgtoolerr_t imgtool_floppy_open(imgtool::image *image, imgtool::stream::ptr &&stream)
{
return imgtool_floppy_open_internal(image, f, FALSE);
return imgtool_floppy_open_internal(image, std::move(stream), FALSE);
}
static imgtoolerr_t imgtool_floppy_create(imgtool::image *image, imgtool::stream &f, util::option_resolution *opts)
static imgtoolerr_t imgtool_floppy_create(imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *opts)
{
floperr_t ferr;
imgtoolerr_t err = IMGTOOLERR_SUCCESS;
imgtool::stream *f = nullptr;
struct imgtool_floppy_image *fimg;
const imgtool_class *imgclass;
const struct FloppyFormat *format;
@ -160,15 +169,19 @@ static imgtoolerr_t imgtool_floppy_create(imgtool::image *image, imgtool::stream
create = (imgtoolerr_t (*)(imgtool::image *, imgtool::stream *, util::option_resolution *)) imgtool_get_info_ptr(imgclass, IMGTOOLINFO_PTR_FLOPPY_CREATE);
open = (imgtoolerr_t (*)(imgtool::image *, imgtool::stream *)) imgtool_get_info_ptr(imgclass, IMGTOOLINFO_PTR_FLOPPY_OPEN);
/* open up the floppy */
ferr = floppy_create(&f, &imgtool_ioprocs, format, opts, &fimg->floppy);
// extract the pointer
f = stream.release();
// open up the floppy
ferr = floppy_create(f, &imgtool_ioprocs, format, opts, &fimg->floppy);
if (ferr)
{
err = imgtool_floppy_error(ferr);
goto done;
}
f = nullptr; // the floppy object has the stream now
/* do we have to do extra stuff when creating the image? */
// do we have to do extra stuff when creating the image?
if (create)
{
err = create(image, nullptr, opts);
@ -176,7 +189,7 @@ static imgtoolerr_t imgtool_floppy_create(imgtool::image *image, imgtool::stream
goto done;
}
/* do we have to do extra stuff when opening the image? */
// do we have to do extra stuff when opening the image?
if (open)
{
err = open(image, nullptr);
@ -185,6 +198,8 @@ static imgtoolerr_t imgtool_floppy_create(imgtool::image *image, imgtool::stream
}
done:
if (f)
delete f;
return err;
}

View File

@ -218,7 +218,7 @@ const hard_disk_info *imghd_get_header(struct mess_hard_disk_file *disk)
}
static imgtoolerr_t mess_hd_image_create(imgtool::image *image, imgtool::stream &f, util::option_resolution *createoptions);
static imgtoolerr_t mess_hd_image_create(imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *createoptions);
enum
{
@ -257,7 +257,7 @@ void hd_get_info(const imgtool_class *imgclass, UINT32 state, union imgtoolinfo
static imgtoolerr_t mess_hd_image_create(imgtool::image *image, imgtool::stream &f, util::option_resolution *createoptions)
static imgtoolerr_t mess_hd_image_create(imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *createoptions)
{
UINT32 blocksize, cylinders, heads, sectors, seclen;
@ -268,5 +268,5 @@ static imgtoolerr_t mess_hd_image_create(imgtool::image *image, imgtool::stream
sectors = createoptions->lookup_int(mess_hd_createopts_sectors);
seclen = createoptions->lookup_int(mess_hd_createopts_seclen);
return imghd_create(f, blocksize, cylinders, heads, sectors, seclen);
return imghd_create(*stream.get(), blocksize, cylinders, heads, sectors, seclen);
}

View File

@ -896,7 +896,7 @@ imgtoolerr_t imgtool::image::internal_open(const imgtool_module *module, const c
int read_or_write, util::option_resolution *createopts, imgtool::image::ptr &outimg)
{
imgtoolerr_t err;
imgtool::stream *f = nullptr;
imgtool::stream::ptr stream;
imgtool::image::ptr image;
object_pool *pool = nullptr;
void *extra_bytes = nullptr;
@ -919,8 +919,8 @@ imgtoolerr_t imgtool::image::internal_open(const imgtool_module *module, const c
}
// open the stream
f = imgtool::stream::open(fname, read_or_write);
if (!f)
stream = imgtool::stream::ptr(imgtool::stream::open(fname, read_or_write));
if (!stream)
{
err = (imgtoolerr_t)(IMGTOOLERR_FILENOTFOUND | IMGTOOLERR_SRC_IMAGEFILE);
goto done;
@ -951,8 +951,8 @@ imgtoolerr_t imgtool::image::internal_open(const imgtool_module *module, const c
// actually call create or open
err = (read_or_write == OSD_FOPEN_RW_CREATE)
? module->create(image.get(), f, createopts)
: module->open(image.get(), f);
? module->create(image.get(), std::move(stream), createopts)
: module->open(image.get(), std::move(stream));
if (err)
{
err = markerrorsource(err);
@ -965,9 +965,6 @@ imgtoolerr_t imgtool::image::internal_open(const imgtool_module *module, const c
outimg = std::move(image);
done:
if (err && f)
delete f;
if (pool)
pool_free_lib(pool);
return err;

View File

@ -69,8 +69,8 @@ void library::add_class(const imgtool_class *imgclass)
module->tracks_are_called_cylinders = imgtool_get_info_int(imgclass, IMGTOOLINFO_INT_TRACKS_ARE_CALLED_CYLINDERS) ? 1 : 0;
module->writing_untested = imgtool_get_info_int(imgclass, IMGTOOLINFO_INT_WRITING_UNTESTED) ? 1 : 0;
module->creation_untested = imgtool_get_info_int(imgclass, IMGTOOLINFO_INT_CREATION_UNTESTED) ? 1 : 0;
module->open = (imgtoolerr_t (*)(imgtool::image *, imgtool::stream *)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_OPEN);
module->create = (imgtoolerr_t (*)(imgtool::image *, imgtool::stream *, util::option_resolution *)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_CREATE);
module->open = (imgtoolerr_t (*)(imgtool::image *, imgtool::stream::ptr &&)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_OPEN);
module->create = (imgtoolerr_t (*)(imgtool::image *, imgtool::stream::ptr &&, util::option_resolution *)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_CREATE);
module->close = (void (*)(imgtool::image *)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_CLOSE);
module->info = (void (*)(imgtool::image *, char *, size_t)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_INFO);
module->read_sector = (imgtoolerr_t (*)(imgtool::image *, UINT32, UINT32, UINT32, std::vector<UINT8> &)) imgtool_get_info_fct(imgclass, IMGTOOLINFO_PTR_READ_SECTOR);

View File

@ -254,9 +254,9 @@ union imgtoolinfo
void * f; /* generic function pointers */
char * s; /* generic strings */
imgtoolerr_t (*open) (imgtool::image *image, imgtool::stream &stream);
imgtoolerr_t (*open) (imgtool::image *image, imgtool::stream::ptr &&stream);
void (*close) (imgtool::image *image);
imgtoolerr_t (*create) (imgtool::image *image, imgtool::stream &stream, util::option_resolution *opts);
imgtoolerr_t (*create) (imgtool::image *image, imgtool::stream::ptr &&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);
@ -347,10 +347,10 @@ struct imgtool_module
unsigned int writing_untested : 1; /* used when we support writing, but not in main build */
unsigned int creation_untested : 1; /* used when we support creation, but not in main build */
imgtoolerr_t (*open) (imgtool::image *image, imgtool::stream *f);
imgtoolerr_t (*open) (imgtool::image *image, imgtool::stream::ptr &&stream);
void (*close) (imgtool::image *image);
void (*info) (imgtool::image *image, char *string, size_t len);
imgtoolerr_t (*create) (imgtool::image *image, imgtool::stream *f, util::option_resolution *opts);
imgtoolerr_t (*create) (imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *opts);
imgtoolerr_t (*get_geometry) (imgtool::image *image, UINT32 *track, UINT32 *heads, UINT32 *sectors);
imgtoolerr_t (*read_sector) (imgtool::image *image, UINT32 track, UINT32 head, UINT32 sector, std::vector<UINT8> &buffer);
imgtoolerr_t (*write_sector) (imgtool::image *image, UINT32 track, UINT32 head, UINT32 sector, const void *buffer, size_t len);

View File

@ -1742,12 +1742,11 @@ static imgtoolerr_t update_disk_alteration_date(imgtool::image *img)
*****************************************************************************/
static imgtoolerr_t amiga_image_open(imgtool::image *img, imgtool::stream &stream)
static imgtoolerr_t amiga_image_open(imgtool::image *img, imgtool::stream::ptr &&stream)
{
amiga_floppy *f = (amiga_floppy *) img->extra_bytes();
UINT64 size = stream.size();
UINT64 size = stream->size();
f->stream = &stream;
f->sectors = size/BSIZE/80/2;
if (f->sectors != 11 && f->sectors != 22)
@ -1755,12 +1754,16 @@ static imgtoolerr_t amiga_image_open(imgtool::image *img, imgtool::stream &strea
return IMGTOOLERR_CORRUPTIMAGE;
}
f->stream = stream.release();
return IMGTOOLERR_SUCCESS;
}
static void amiga_image_exit(imgtool::image *img)
{
amiga_floppy *f = (amiga_floppy *)img->extra_bytes();
if (f->stream)
delete f->stream;
}
@ -2195,7 +2198,7 @@ static imgtoolerr_t amiga_image_writefile(imgtool::partition *partition, const c
}
static imgtoolerr_t amiga_image_create(imgtool::image *img, imgtool::stream &stream, util::option_resolution *opts)
static imgtoolerr_t amiga_image_create(imgtool::image *img, imgtool::stream::ptr &&stream, util::option_resolution *opts)
{
amiga_floppy *f = (amiga_floppy *) img->extra_bytes();
const std::string &dskname = opts->lookup_string('N');
@ -2206,7 +2209,7 @@ static imgtoolerr_t amiga_image_create(imgtool::image *img, imgtool::stream &str
time_t now;
int blocks;
f->stream = &stream;
f->stream = stream.get();
switch (opts->lookup_int('S'))
{
@ -2296,6 +2299,7 @@ static imgtoolerr_t amiga_image_create(imgtool::image *img, imgtool::stream &str
ret = write_block(img, blocks - 1, buffer);
if (ret) return ret;
f->stream = stream.release();
return IMGTOOLERR_SUCCESS;
}

View File

@ -498,7 +498,7 @@ static imgtoolerr_t prepare_dirent(UINT8 variant, struct bml3_dirent *ent, const
static imgtoolerr_t bml3_diskimage_open(imgtool::image *image, imgtool::stream &stream)
static imgtoolerr_t bml3_diskimage_open(imgtool::image *image, imgtool::stream::ptr &&dummy)
{
// imgtoolerr_t err;
floperr_t ferr;

View File

@ -126,7 +126,7 @@ struct concept_iterator
};
static imgtoolerr_t concept_image_init(imgtool::image *img, imgtool::stream &f);
static imgtoolerr_t concept_image_init(imgtool::image *img, imgtool::stream::ptr &&stream);
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);
@ -260,19 +260,17 @@ static int get_catalog_entry(concept_image *image, const unsigned char *filename
/*
Open a file as a concept_image.
*/
static imgtoolerr_t concept_image_init(imgtool::image *img, imgtool::stream &f)
static imgtoolerr_t concept_image_init(imgtool::image *img, imgtool::stream::ptr &&stream)
{
concept_image *image = (concept_image *) img->extra_bytes();
int reply;
int i;
unsigned totphysrecs;
image->file_handle = &f;
/* read device directory */
for (i=0; i<4; i++)
{
reply = read_physical_record(f, i+2, ((char *) & image->dev_dir)+i*512);
reply = read_physical_record(*stream, i+2, ((char *) & image->dev_dir)+i*512);
if (reply)
return IMGTOOLERR_READERROR;
}
@ -289,6 +287,7 @@ static imgtoolerr_t concept_image_init(imgtool::image *img, imgtool::stream &f)
return IMGTOOLERR_CORRUPTIMAGE;
}
image->file_handle = stream.release();
return IMGTOOLERR_SUCCESS;
}

View File

@ -265,9 +265,9 @@ static int cfs_verify(cybiko_file_system &cfs)
return TRUE;
}
static int cfs_init(cybiko_file_system &cfs, imgtool::stream &stream, int flash_type)
static int cfs_init(cybiko_file_system &cfs, imgtool::stream::ptr &&stream, int flash_type)
{
cfs.stream = &stream;
cfs.stream = stream.release();
switch (flash_type)
{
case FLASH_TYPE_AT45DB041 : cfs.page_count = 2048; cfs.page_size = 264; break;
@ -345,13 +345,13 @@ static int flash_option_to_flash_type( int option)
}
}
static imgtoolerr_t cybiko_image_open(imgtool::image *image, imgtool::stream &stream)
static imgtoolerr_t cybiko_image_open(imgtool::image *image, imgtool::stream::ptr &&stream)
{
cybiko_file_system *cfs = (cybiko_file_system*)image->extra_bytes();
int flash_type;
// init
flash_type = flash_size_to_flash_type(stream.size());
if (!cfs_init(*cfs, stream, flash_type)) return IMGTOOLERR_CORRUPTIMAGE;
flash_type = flash_size_to_flash_type(stream->size());
if (!cfs_init(*cfs, std::move(stream), flash_type)) return IMGTOOLERR_CORRUPTIMAGE;
// verify
if (!cfs_verify(*cfs)) return IMGTOOLERR_CORRUPTIMAGE;
// ok
@ -364,13 +364,13 @@ static void cybiko_image_close( imgtool::image *image)
delete cfs->stream;
}
static imgtoolerr_t cybiko_image_create( imgtool::image *image, imgtool::stream &stream, util::option_resolution *opts)
static imgtoolerr_t cybiko_image_create( imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *opts)
{
cybiko_file_system *cfs = (cybiko_file_system*)image->extra_bytes();
int flash_type;
// init
flash_type = flash_option_to_flash_type(opts->lookup_int('F'));
if (!cfs_init(*cfs, stream, flash_type)) return IMGTOOLERR_CORRUPTIMAGE;
if (!cfs_init(*cfs, std::move(stream), flash_type)) return IMGTOOLERR_CORRUPTIMAGE;
// format
if (!cfs_format(cfs)) return IMGTOOLERR_CORRUPTIMAGE;
// ok

View File

@ -260,9 +260,9 @@ static bool cfs_verify(cybiko_file_system &cfs)
return true;
}
static bool cfs_init(cybiko_file_system &cfs, imgtool::stream &stream)
static bool cfs_init(cybiko_file_system &cfs, imgtool::stream::ptr &&stream)
{
cfs.stream = &stream;
cfs.stream = stream.release();
cfs.page_count = 2005;
cfs.page_size = 258;
cfs.block_count_boot = 5;
@ -319,11 +319,11 @@ static UINT32 cfs_calc_free_space( cybiko_file_system *cfs, UINT16 blocks)
return free_space;
}
static imgtoolerr_t cybiko_image_open(imgtool::image *image, imgtool::stream &stream)
static imgtoolerr_t cybiko_image_open(imgtool::image *image, imgtool::stream::ptr &&stream)
{
cybiko_file_system *cfs = (cybiko_file_system*)image->extra_bytes();
// init
if (!cfs_init(*cfs, stream)) return IMGTOOLERR_CORRUPTIMAGE;
if (!cfs_init(*cfs, std::move(stream))) return IMGTOOLERR_CORRUPTIMAGE;
// verify
if (!cfs_verify(*cfs)) return IMGTOOLERR_CORRUPTIMAGE;
// ok
@ -336,11 +336,11 @@ static void cybiko_image_close(imgtool::image *image)
delete cfs->stream;
}
static imgtoolerr_t cybiko_image_create(imgtool::image *image, imgtool::stream &stream, util::option_resolution *opts)
static imgtoolerr_t cybiko_image_create(imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *opts)
{
cybiko_file_system *cfs = (cybiko_file_system*)image->extra_bytes();
// init
if (!cfs_init(*cfs, stream)) return IMGTOOLERR_CORRUPTIMAGE;
if (!cfs_init(*cfs, std::move(stream))) return IMGTOOLERR_CORRUPTIMAGE;
// format
if (!cfs_format(cfs)) return IMGTOOLERR_CORRUPTIMAGE;
// ok

View File

@ -327,10 +327,10 @@ static UINT16 crc(UINT8* data, int len)
*****************************************************************************/
static imgtoolerr_t hp48_open(imgtool::image *img, imgtool::stream &stream)
static imgtoolerr_t hp48_open(imgtool::image *img, imgtool::stream::ptr &&stream)
{
hp48_card* c = (hp48_card*) img->extra_bytes();
int size = stream.size();
int size = stream->size();
/* check that size is a power of 2 between 32 KB and 4 MG */
if ( (size < 32 * 1024) ||
@ -341,30 +341,31 @@ static imgtoolerr_t hp48_open(imgtool::image *img, imgtool::stream &stream)
}
/* store info */
c->stream = &stream;
c->stream = stream.get();
c->modified = 0;
c->size = size;
c->data = (UINT8*) malloc( 2 * size );
if ( !c->data )
{
return IMGTOOLERR_READERROR;
return IMGTOOLERR_READERROR;
}
/* fully load image */
stream.seek(0, SEEK_SET);
if (stream.read(c->data, size) < size)
c->stream->seek(0, SEEK_SET);
if (c->stream->read(c->data, size) < size)
{
return IMGTOOLERR_READERROR;
return IMGTOOLERR_READERROR;
}
unpack( c->data, c->data, 2 * size );
c->stream = stream.release();
return IMGTOOLERR_SUCCESS;
}
static imgtoolerr_t hp48_create(imgtool::image* img,
imgtool::stream &stream,
imgtool::stream::ptr &&stream,
util::option_resolution *opts)
{
hp48_card* c = (hp48_card*) img->extra_bytes();
@ -372,7 +373,7 @@ static imgtoolerr_t hp48_create(imgtool::image* img,
size = opts->lookup_int('S');
c->stream = &stream;
c->stream = stream.get();
c->modified = 1;
c->size = size * 1024;
c->data = (UINT8*) malloc( 2 * c->size );
@ -384,6 +385,7 @@ static imgtoolerr_t hp48_create(imgtool::image* img,
/* zeroing the image seems fine */
memset( c->data, 0, 2 * c->size );
c->stream = stream.release();
return IMGTOOLERR_SUCCESS;
}

View File

@ -1042,22 +1042,27 @@ static tape_image_t& get_tape_image(tape_state_t& ts)
/********************************************************************************
* Imgtool functions
********************************************************************************/
static imgtoolerr_t hp9845_tape_open(imgtool::image *image, imgtool::stream &stream)
static imgtoolerr_t hp9845_tape_open(imgtool::image *image, imgtool::stream::ptr &&stream)
{
tape_state_t& state = get_tape_state(image);
state.stream = &stream;
state.stream = stream.get();
tape_image_t& tape_image = get_tape_image(state);
return tape_image.load_from_file(&stream);
imgtoolerr_t err = tape_image.load_from_file(state.stream);
if (err)
return err;
state.stream = stream.release();
return IMGTOOLERR_SUCCESS;
}
static imgtoolerr_t hp9845_tape_create(imgtool::image *image, imgtool::stream &stream, util::option_resolution *opts)
static imgtoolerr_t hp9845_tape_create(imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *opts)
{
tape_state_t& state = get_tape_state(image);
state.stream = &stream;
state.stream = stream.release();
tape_image_t& tape_image = get_tape_image(state);

View File

@ -1542,7 +1542,7 @@ struct mfs_dirref
static imgtoolerr_t mfs_image_create(imgtool::image *image, imgtool::stream &stream, util::option_resolution *opts)
static imgtoolerr_t mfs_image_create(imgtool::image *image, imgtool::stream::ptr &&dummy, util::option_resolution *opts)
{
imgtoolerr_t err;
UINT8 buffer[512];
@ -1606,7 +1606,7 @@ static imgtoolerr_t mfs_image_create(imgtool::image *image, imgtool::stream &str
Return imgtool error code
*/
static imgtoolerr_t mfs_image_open(imgtool::image *image, imgtool::stream &stream)
static imgtoolerr_t mfs_image_open(imgtool::image *image, imgtool::stream::ptr &&dummy)
{
imgtoolerr_t err;
struct mac_l2_imgref *l2_img;
@ -3033,7 +3033,7 @@ static int hfs_catKey_compare(const void *p1, const void *p2)
Return imgtool error code
*/
static imgtoolerr_t hfs_image_open(imgtool::image *image, imgtool::stream &stream)
static imgtoolerr_t hfs_image_open(imgtool::image *image, imgtool::stream::ptr &&stream)
{
imgtoolerr_t err;
struct mac_l2_imgref *l2_img;

View File

@ -622,7 +622,7 @@ done:
static imgtoolerr_t os9_diskimage_open(imgtool::image *image, imgtool::stream &stream)
static imgtoolerr_t os9_diskimage_open(imgtool::image *image, imgtool::stream::ptr &&dummy)
{
imgtoolerr_t err;
floperr_t ferr;
@ -710,7 +710,7 @@ static imgtoolerr_t os9_diskimage_open(imgtool::image *image, imgtool::stream &s
static imgtoolerr_t os9_diskimage_create(imgtool::image *img, imgtool::stream &stream, util::option_resolution *opts)
static imgtoolerr_t os9_diskimage_create(imgtool::image *img, imgtool::stream::ptr &&stream, util::option_resolution *opts)
{
imgtoolerr_t err;
dynamic_buffer header;

View File

@ -17,7 +17,7 @@
#define FAT_SECLEN 512
static imgtoolerr_t fat_image_create(imgtool::image *image, imgtool::stream &stream, util::option_resolution *opts)
static imgtoolerr_t fat_image_create(imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *opts)
{
imgtoolerr_t err;
UINT32 tracks, heads, sectors;

View File

@ -232,7 +232,7 @@ static imgtoolerr_t pc_chd_read_partition_header(imgtool::image &image)
static imgtoolerr_t pc_chd_image_create(imgtool::image *image, imgtool::stream &f, util::option_resolution *opts)
static imgtoolerr_t pc_chd_image_create(imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *opts)
{
imgtoolerr_t err;
UINT32 cylinders, heads, sectors;
@ -246,11 +246,11 @@ static imgtoolerr_t pc_chd_image_create(imgtool::image *image, imgtool::stream &
info = pc_chd_get_image_info(*image);
/* create the hard disk image */
err = imghd_create(f, 0, cylinders, heads, sectors, FAT_SECLEN);
err = imghd_create(*stream, 0, cylinders, heads, sectors, FAT_SECLEN);
if (err)
goto done;
err = imghd_open(f, &info->hard_disk);
err = imghd_open(*stream, &info->hard_disk);
if (err)
goto done;
@ -278,7 +278,7 @@ done:
static imgtoolerr_t pc_chd_image_open(imgtool::image *image, imgtool::stream &stream)
static imgtoolerr_t pc_chd_image_open(imgtool::image *image, imgtool::stream::ptr &&stream)
{
imgtoolerr_t err;
pc_chd_image_info *info;
@ -286,7 +286,7 @@ static imgtoolerr_t pc_chd_image_open(imgtool::image *image, imgtool::stream &st
info = pc_chd_get_image_info(*image);
/* open the hard drive */
err = imghd_open(stream, &info->hard_disk);
err = imghd_open(*stream, &info->hard_disk);
if (err)
return err;

View File

@ -502,7 +502,7 @@ static imgtoolerr_t prodos_diskimage_open(imgtool::image *image)
static imgtoolerr_t prodos_diskimage_open_525(imgtool::image *image, imgtool::stream &stream)
static imgtoolerr_t prodos_diskimage_open_525(imgtool::image *image, imgtool::stream::ptr &&dummy)
{
prodos_setprocs_525(image);
return prodos_diskimage_open(image);
@ -510,7 +510,7 @@ static imgtoolerr_t prodos_diskimage_open_525(imgtool::image *image, imgtool::st
static imgtoolerr_t prodos_diskimage_open_35(imgtool::image *image, imgtool::stream &stream)
static imgtoolerr_t prodos_diskimage_open_35(imgtool::image *image, imgtool::stream::ptr &&dummy)
{
prodos_setprocs_35(image);
return prodos_diskimage_open(image);
@ -702,7 +702,7 @@ static imgtoolerr_t prodos_diskimage_create(imgtool::image *image, util::option_
static imgtoolerr_t prodos_diskimage_create_525(imgtool::image *image, imgtool::stream &stream, util::option_resolution *opts)
static imgtoolerr_t prodos_diskimage_create_525(imgtool::image *image, imgtool::stream::ptr &&dummy, util::option_resolution *opts)
{
prodos_setprocs_525(image);
return prodos_diskimage_create(image, opts);
@ -710,7 +710,7 @@ static imgtoolerr_t prodos_diskimage_create_525(imgtool::image *image, imgtool::
static imgtoolerr_t prodos_diskimage_create_35(imgtool::image *image, imgtool::stream &stream, util::option_resolution *opts)
static imgtoolerr_t prodos_diskimage_create_35(imgtool::image *image, imgtool::stream::ptr &&dummy, util::option_resolution *opts)
{
prodos_setprocs_35(image);
return prodos_diskimage_create(image, opts);

View File

@ -385,25 +385,30 @@ UINT16 get_ob3(imgtool::stream &instream, imgtool::stream &outstream, UINT8 type
return size;
}
static imgtoolerr_t datapack_open(imgtool::image *image, imgtool::stream &stream)
static imgtoolerr_t datapack_open(imgtool::image *image, imgtool::stream::ptr &&stream)
{
psion_pack *pack = (psion_pack*)image->extra_bytes();
char opk_magic[4];
stream.read(opk_magic, 4);
stream->read(opk_magic, 4);
if(strcmp(opk_magic, "OPK\0"))
return IMGTOOLERR_UNEXPECTED;
pack->stream = &stream;
pack->stream = stream.get();
if (update_pack_index(pack))
{
pack->stream = stream.release();
return IMGTOOLERR_SUCCESS;
}
else
{
return IMGTOOLERR_CORRUPTIMAGE;
}
}
static imgtoolerr_t datapack_create(imgtool::image *image, imgtool::stream &stream, util::option_resolution *opts)
static imgtoolerr_t datapack_create(imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *opts)
{
psion_pack *pack = (psion_pack*)image->extra_bytes();
static const UINT8 opk_magic[4] = {'O', 'P', 'K', 0x00};
@ -419,25 +424,30 @@ static imgtoolerr_t datapack_create(imgtool::image *image, imgtool::stream &stre
checksum = head_checksum(pack_head);
stream.write(opk_magic, 4);
stream.fill(0x00, 2);
stream.write(pack_head, 8);
stream->write(opk_magic, 4);
stream->fill(0x00, 2);
stream->write(pack_head, 8);
stream.putc((checksum>>8) & 0xff);
stream.putc(checksum & 0xff);
stream->putc((checksum>>8) & 0xff);
stream->putc(checksum & 0xff);
put_name_record(stream, "MAIN", 0x81, 0x90);
put_name_record(*stream, "MAIN", 0x81, 0x90);
stream.fill(0xff, 2);
stream->fill(0xff, 2);
update_opk_head(stream);
update_opk_head(*stream);
pack->stream = &stream;
pack->stream = stream.get();
if (update_pack_index(pack))
{
pack->stream = stream.release();
return IMGTOOLERR_SUCCESS;
}
else
{
return IMGTOOLERR_CORRUPTIMAGE;
}
}
static void datapack_close( imgtool::image *image)

View File

@ -177,71 +177,72 @@ static UINT8* thom_get_sector(thom_floppy* f, unsigned head,
(.fd have 40 or 80 tracks, .qd have 25 tracks) and the file size.
*/
static imgtoolerr_t thom_open_fd_qd(imgtool::image *img, imgtool::stream &stream)
static imgtoolerr_t thom_open_fd_qd(imgtool::image *img, imgtool::stream::ptr &&stream)
{
thom_floppy* f = (thom_floppy*) img->extra_bytes();
int size = stream.size();
int size = stream->size();
f->stream = &stream;
f->stream = stream.get();
f->modified = 0;
/* guess format */
switch ( size ) {
case 81920:
f->tracks = 40;
f->sector_size = 128;
f->sectuse_size = 128;
f->heads = 1;
break;
f->tracks = 40;
f->sector_size = 128;
f->sectuse_size = 128;
f->heads = 1;
break;
case 163840:
f->tracks = 40;
f->sector_size = 256;
f->sectuse_size = 255;
f->heads = 1;
/* could also be: sector_size=128, heads=2 */
/* maight even be: tracks=80, sector_size=128 */
break;
f->tracks = 40;
f->sector_size = 256;
f->sectuse_size = 255;
f->heads = 1;
/* could also be: sector_size=128, heads=2 */
/* maight even be: tracks=80, sector_size=128 */
break;
case 327680:
f->tracks = 80;
f->sector_size = 256;
f->sectuse_size = 255;
f->heads = 1;
/* could also be: tracks=40, heads=2 */
break;
f->tracks = 80;
f->sector_size = 256;
f->sectuse_size = 255;
f->heads = 1;
/* could also be: tracks=40, heads=2 */
break;
case 655360:
f->tracks = 80;
f->sector_size = 256;
f->sectuse_size = 255;
f->heads = 2;
break;
f->tracks = 80;
f->sector_size = 256;
f->sectuse_size = 255;
f->heads = 2;
break;
case 51200:
f->tracks = 25;
f->sector_size = 128;
f->sectuse_size = 128;
f->heads = 1;
break;
f->tracks = 25;
f->sector_size = 128;
f->sectuse_size = 128;
f->heads = 1;
break;
case 62400:
f->tracks = 25;
f->sector_size = 128;
f->sectuse_size = 128;
f->heads = 2;
break;
f->tracks = 25;
f->sector_size = 128;
f->sectuse_size = 128;
f->heads = 2;
break;
default:
return IMGTOOLERR_CORRUPTIMAGE;
return IMGTOOLERR_CORRUPTIMAGE;
}
assert( size == f->heads * f->tracks * 16 * f->sector_size );
stream.seek(0, SEEK_SET);
if ( stream.read(f->data, size ) < size )
return IMGTOOLERR_READERROR;
f->stream->seek(0, SEEK_SET);
if (f->stream->read(f->data, size ) < size)
return IMGTOOLERR_READERROR;
f->stream = stream.release();
return IMGTOOLERR_SUCCESS;
}
@ -308,47 +309,49 @@ static UINT16 thom_sap_crc( UINT8* data, int size )
return crc;
}
static imgtoolerr_t thom_open_sap(imgtool::image *img, imgtool::stream &stream)
static imgtoolerr_t thom_open_sap(imgtool::image *img, imgtool::stream::ptr &&stream)
{
thom_floppy* f = (thom_floppy*) img->extra_bytes();
UINT8 buf[262];
f->stream = &stream;
f->stream = stream.get();
f->modified = 0;
/* check image header */
stream.seek(0, SEEK_SET);
stream.read(buf, 66 );
// check image header
f->stream->seek(0, SEEK_SET);
f->stream->read(buf, 66 );
if ( memcmp( buf+1, sap_header+1, 65 ) ) return IMGTOOLERR_CORRUPTIMAGE;
/* guess format */
stream.read(buf, 1 );
switch ( buf[0] ) {
f->stream->read(buf, 1 );
switch ( buf[0] )
{
case 1:
case 3:
f->heads = 1;
f->tracks = 40;
f->sector_size = 128;
f->sectuse_size = 128;
break;
f->heads = 1;
f->tracks = 40;
f->sector_size = 128;
f->sectuse_size = 128;
break;
case 0:
case 2:
case 4:
f->heads = 1;
f->tracks = 80;
f->sector_size = 256;
f->sectuse_size = 255;
break;
default: return IMGTOOLERR_CORRUPTIMAGE;
f->heads = 1;
f->tracks = 80;
f->sector_size = 256;
f->sectuse_size = 255;
break;
default:
return IMGTOOLERR_CORRUPTIMAGE;
}
stream.seek(66, SEEK_SET);
f->stream->seek(66, SEEK_SET);
while ( 1) {
int i, sector, track;
UINT16 crc;
/* load sector */
if ( stream.read(buf, 6 + f->sector_size ) < 6 + f->sector_size )
if (f->stream->read(buf, 6 + f->sector_size ) < 6 + f->sector_size )
break;
/* parse sector header */
@ -368,6 +371,7 @@ static imgtoolerr_t thom_open_sap(imgtool::image *img, imgtool::stream &stream)
return IMGTOOLERR_CORRUPTIMAGE;
}
f->stream = stream.release();
return IMGTOOLERR_SUCCESS;
}
@ -1113,7 +1117,7 @@ static imgtoolerr_t thom_suggest_transfer(imgtool::partition *part,
}
static imgtoolerr_t thom_create(imgtool::image* img,
imgtool::stream &stream,
imgtool::stream::ptr &&stream,
util::option_resolution *opts)
{
thom_floppy* f = (thom_floppy*) img->extra_bytes();
@ -1121,7 +1125,7 @@ static imgtoolerr_t thom_create(imgtool::image* img,
UINT8* buf;
const char* name;
f->stream = &stream;
f->stream = stream.get();
f->modified = 0;
/* get parameters */
@ -1167,6 +1171,7 @@ static imgtoolerr_t thom_create(imgtool::image* img,
f->modified = 1;
f->stream = stream.release();
return IMGTOOLERR_SUCCESS;
}

View File

@ -966,21 +966,19 @@ static int read_image_vib_no_geometry(imgtool::stream &file_handle, ti99_img_for
Return imgtool error code
*/
static imgtoolerr_t open_image_lvl1(imgtool::stream &file_handle, ti99_img_format img_format, ti99_lvl1_imgref *l1_img, dsk_vib *vib)
static imgtoolerr_t open_image_lvl1(imgtool::stream::ptr &&file_handle, ti99_img_format img_format, ti99_lvl1_imgref *l1_img, dsk_vib *vib)
{
imgtoolerr_t err;
int reply;
UINT16 totphysrecs;
l1_img->img_format = img_format;
l1_img->file_handle = &file_handle;
if (img_format == if_harddisk)
{
const hard_disk_info *info;
err = imghd_open(file_handle, &l1_img->harddisk_handle);
err = imghd_open(*file_handle, &l1_img->harddisk_handle);
if (err)
return err;
@ -1004,7 +1002,7 @@ static imgtoolerr_t open_image_lvl1(imgtool::stream &file_handle, ti99_img_forma
else
{
/* read vib */
reply = read_image_vib_no_geometry(file_handle, img_format, vib);
reply = read_image_vib_no_geometry(*file_handle, img_format, vib);
if (reply)
return (imgtoolerr_t)reply;
@ -1032,7 +1030,7 @@ static imgtoolerr_t open_image_lvl1(imgtool::stream &file_handle, ti99_img_forma
|| (totphysrecs < 2)
|| memcmp(vib->id, "DSK", 3) || (! strchr(" P", vib->protection))
|| (((img_format == if_mess) || (img_format == if_v9t9))
&& (file_handle.size() != totphysrecs*256U)))
&& (file_handle->size() != totphysrecs*256U)))
return (imgtoolerr_t)IMGTOOLERR_CORRUPTIMAGE;
if ((img_format == if_pc99_fm) || (img_format == if_pc99_mfm))
@ -1040,7 +1038,7 @@ static imgtoolerr_t open_image_lvl1(imgtool::stream &file_handle, ti99_img_forma
l1_img->pc99_data_offset_array = (UINT32*)malloc(sizeof(*l1_img->pc99_data_offset_array)*totphysrecs);
if (! l1_img->pc99_data_offset_array)
return IMGTOOLERR_OUTOFMEMORY;
reply = parse_pc99_image(file_handle, img_format == if_pc99_fm, 1, NULL, & l1_img->geometry, l1_img->pc99_data_offset_array, &l1_img->pc99_track_len);
reply = parse_pc99_image(*file_handle, img_format == if_pc99_fm, 1, NULL, & l1_img->geometry, l1_img->pc99_data_offset_array, &l1_img->pc99_track_len);
if (reply)
{
free(l1_img->pc99_data_offset_array);
@ -1049,6 +1047,8 @@ static imgtoolerr_t open_image_lvl1(imgtool::stream &file_handle, ti99_img_forma
}
}
l1_img->file_handle = file_handle.release(); // we can only do this when we're sure we're successful
return (imgtoolerr_t)0;
}
@ -3848,11 +3848,11 @@ struct win_iterator
};
static imgtoolerr_t dsk_image_init_mess(imgtool::image *image, imgtool::stream &f);
static imgtoolerr_t dsk_image_init_v9t9(imgtool::image *image, imgtool::stream &f);
static imgtoolerr_t dsk_image_init_pc99_fm(imgtool::image *image, imgtool::stream &f);
static imgtoolerr_t dsk_image_init_pc99_mfm(imgtool::image *image, imgtool::stream &f);
static imgtoolerr_t win_image_init(imgtool::image *image, imgtool::stream &f);
static imgtoolerr_t dsk_image_init_mess(imgtool::image *image, imgtool::stream::ptr &&stream);
static imgtoolerr_t dsk_image_init_v9t9(imgtool::image *image, imgtool::stream::ptr &&stream);
static imgtoolerr_t dsk_image_init_pc99_fm(imgtool::image *image, imgtool::stream::ptr &&stream);
static imgtoolerr_t dsk_image_init_pc99_mfm(imgtool::image *image, imgtool::stream::ptr &&stream);
static imgtoolerr_t win_image_init(imgtool::image *image, imgtool::stream::ptr &&stream);
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);
@ -3864,8 +3864,8 @@ static imgtoolerr_t ti99_image_readfile(imgtool::partition *partition, const cha
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);
static imgtoolerr_t dsk_image_create_mess(imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *createoptions);
static imgtoolerr_t dsk_image_create_v9t9(imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *createoptions);
enum
{
@ -3995,17 +3995,17 @@ void ti99_ti99hd_get_info(const imgtool_class *imgclass, UINT32 state, union img
/*
Open a file as a ti99_image (common code).
*/
static int dsk_image_init(imgtool::image *img, imgtool::stream &f, ti99_img_format img_format)
static imgtoolerr_t dsk_image_init(imgtool::image *img, imgtool::stream::ptr &&stream, ti99_img_format img_format)
{
struct ti99_lvl2_imgref *image = (struct ti99_lvl2_imgref *) img->extra_bytes();
dsk_vib vib;
int reply;
imgtoolerr_t reply;
int totphysrecs;
unsigned fdir_aphysrec;
int i;
/* open disk image at level 1 */
reply = open_image_lvl1(f, img_format, &image->l1_img, &vib);
reply = open_image_lvl1(std::move(stream), img_format, &image->l1_img, &vib);
if (reply)
return reply;
@ -4029,7 +4029,7 @@ static int dsk_image_init(imgtool::image *img, imgtool::stream &f, ti99_img_form
image->dsk.totphysrecs = get_UINT16BE(vib.totphysrecs);
/* read and check main volume catalog */
reply = dsk_read_catalog(image, 1, &image->dsk.catalogs[0]);
reply = (imgtoolerr_t)dsk_read_catalog(image, 1, &image->dsk.catalogs[0]);
if (reply)
return reply;
@ -4072,7 +4072,7 @@ static int dsk_image_init(imgtool::image *img, imgtool::stream &f, ti99_img_form
image->dsk.fdir_aphysrec[image->dsk.catalogs[0].num_subdirs+1] = fdir_aphysrec;
/*image->dsk.catalogs[0].subdirs[image->dsk.catalogs[0].num_subdirs].dir_ptr = fdir_aphysrec;*/
memcpy(image->dsk.catalogs[0].subdirs[image->dsk.catalogs[0].num_subdirs].name, vib.subdir[i].name, 10);
reply = dsk_read_catalog(image, fdir_aphysrec, &image->dsk.catalogs[image->dsk.catalogs[0].num_subdirs+1]);
reply = (imgtoolerr_t) dsk_read_catalog(image, fdir_aphysrec, &image->dsk.catalogs[image->dsk.catalogs[0].num_subdirs+1]);
if (reply)
{
/* error: invalid fdir */
@ -4090,45 +4090,45 @@ static int dsk_image_init(imgtool::image *img, imgtool::stream &f, ti99_img_form
/* initialize default data_offset */
image->data_offset = 32+2;
return 0;
return (imgtoolerr_t)0;
}
/*
Open a file as a ti99_image (MESS format).
*/
static imgtoolerr_t dsk_image_init_mess(imgtool::image *image, imgtool::stream &f)
static imgtoolerr_t dsk_image_init_mess(imgtool::image *image, imgtool::stream::ptr &&stream)
{
return (imgtoolerr_t)dsk_image_init(image, f, if_mess);
return dsk_image_init(image, std::move(stream), if_mess);
}
/*
Open a file as a ti99_image (V9T9 format).
*/
static imgtoolerr_t dsk_image_init_v9t9(imgtool::image *image, imgtool::stream &f)
static imgtoolerr_t dsk_image_init_v9t9(imgtool::image *image, imgtool::stream::ptr &&stream)
{
return (imgtoolerr_t)dsk_image_init(image, f, if_v9t9);
return dsk_image_init(image, std::move(stream), if_v9t9);
}
/*
Open a file as a ti99_image (PC99 FM format).
*/
static imgtoolerr_t dsk_image_init_pc99_fm(imgtool::image *image, imgtool::stream &f)
static imgtoolerr_t dsk_image_init_pc99_fm(imgtool::image *image, imgtool::stream::ptr &&stream)
{
return (imgtoolerr_t)dsk_image_init(image, f, if_pc99_fm);
return dsk_image_init(image, std::move(stream), if_pc99_fm);
}
/*
Open a file as a ti99_image (PC99 MFM format).
*/
static imgtoolerr_t dsk_image_init_pc99_mfm(imgtool::image *image, imgtool::stream &f)
static imgtoolerr_t dsk_image_init_pc99_mfm(imgtool::image *image, imgtool::stream::ptr &&stream)
{
return (imgtoolerr_t)dsk_image_init(image, f, if_pc99_mfm);
return dsk_image_init(image, std::move(stream), if_pc99_mfm);
}
/*
Open a file as a ti99_image (harddisk format).
*/
static imgtoolerr_t win_image_init(imgtool::image *img, imgtool::stream &f)
static imgtoolerr_t win_image_init(imgtool::image *img, imgtool::stream::ptr &&stream)
{
struct ti99_lvl2_imgref *image = (struct ti99_lvl2_imgref *) img->extra_bytes();
win_vib_ddr vib;
@ -4136,7 +4136,7 @@ static imgtoolerr_t win_image_init(imgtool::image *img, imgtool::stream &f)
int i;
/* open disk image at level 1 */
reply = open_image_lvl1(f, if_harddisk, & image->l1_img, NULL);
reply = open_image_lvl1(std::move(stream), if_harddisk, & image->l1_img, NULL);
if (reply)
return (imgtoolerr_t)reply;
@ -5226,7 +5226,7 @@ static imgtoolerr_t win_image_deletefile(imgtool::partition *partition, const ch
Supports MESS and V9T9 formats only
*/
static imgtoolerr_t dsk_image_create(imgtool::image *image, imgtool::stream &f, util::option_resolution *createoptions, ti99_img_format img_format)
static imgtoolerr_t dsk_image_create(imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *createoptions, ti99_img_format img_format)
{
const char *volname;
int density;
@ -5241,7 +5241,7 @@ static imgtoolerr_t dsk_image_create(imgtool::image *image, imgtool::stream &f,
int i;
l1_img.img_format = img_format;
l1_img.file_handle = &f;
l1_img.file_handle = stream.get(); // can't release here
/* read options */
volname = createoptions->lookup_string(dsk_createopts_volname).c_str();
@ -5328,7 +5328,7 @@ static imgtoolerr_t dsk_image_create(imgtool::image *image, imgtool::stream &f,
vib.abm[0] |= (physrecsperAU == 1) ? 3 : 1;
/* write aphysrec 0 */
if (write_absolute_physrec(& l1_img, 0, &vib))
if (write_absolute_physrec(&l1_img, 0, &vib))
return IMGTOOLERR_WRITEERROR;
@ -5340,21 +5340,21 @@ static imgtoolerr_t dsk_image_create(imgtool::image *image, imgtool::stream &f,
return IMGTOOLERR_WRITEERROR;
return (imgtoolerr_t)dsk_image_init(image, f, img_format);
return dsk_image_init(image, std::move(stream), img_format);
}
/*
Create a blank ti99_image (MESS format).
*/
static imgtoolerr_t dsk_image_create_mess(imgtool::image *image, imgtool::stream &f, util::option_resolution *createoptions)
static imgtoolerr_t dsk_image_create_mess(imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *createoptions)
{
return dsk_image_create(image, f, createoptions, if_mess);
return dsk_image_create(image, std::move(stream), createoptions, if_mess);
}
/*
Create a blank ti99_image (V9T9 format).
*/
static imgtoolerr_t dsk_image_create_v9t9(imgtool::image *image, imgtool::stream &f, util::option_resolution *createoptions)
static imgtoolerr_t dsk_image_create_v9t9(imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *createoptions)
{
return dsk_image_create(image, f, createoptions, if_v9t9);
return dsk_image_create(image, std::move(stream), createoptions, if_v9t9);
}

View File

@ -386,7 +386,7 @@ struct ti990_iterator
};
static imgtoolerr_t ti990_image_init(imgtool::image *img, imgtool::stream &f);
static imgtoolerr_t ti990_image_init(imgtool::image *img, imgtool::stream::ptr &&stream);
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);
@ -398,7 +398,7 @@ static imgtoolerr_t ti990_image_readfile(imgtool::partition *partition, const ch
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);
static imgtoolerr_t ti990_image_create(imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *createoptions);
enum
{
@ -1106,15 +1106,15 @@ static int qsort_catalog_compare(const void *p1, const void *p2)
/*
Open a file as a ti990_image.
*/
static imgtoolerr_t ti990_image_init(imgtool::image *img, imgtool::stream &f)
static imgtoolerr_t ti990_image_init(imgtool::image *img, imgtool::stream::ptr &&stream)
{
ti990_image *image = (ti990_image *) img->extra_bytes();
disk_image_header header;
int reply;
unsigned totsecs;
image->file_handle = &f;
reply = f.read(&header, sizeof(header));
image->file_handle = stream.get();
reply = image->file_handle->read(&header, sizeof(header));
if (reply != sizeof(header))
return IMGTOOLERR_READERROR;
@ -1131,14 +1131,14 @@ static imgtoolerr_t ti990_image_init(imgtool::image *img, imgtool::stream &f)
|| (image->geometry.heads > MAX_HEADS)
|| (image->geometry.cylinders > MAX_CYLINDERS)
|| (totsecs < 1)
|| (f.size() != header_len + totsecs*image->geometry.bytes_per_sector))
|| (image->file_handle->size() != header_len + totsecs*image->geometry.bytes_per_sector))
{
return IMGTOOLERR_CORRUPTIMAGE;
}
{
ti990_phys_sec_address address = { 0, 0, 0 };
reply = read_sector_physical_len(f, &address, &image->geometry, & image->sec0, sizeof(image->sec0));
reply = read_sector_physical_len(*image->file_handle, &address, &image->geometry, & image->sec0, sizeof(image->sec0));
}
if (reply)
{
@ -1156,6 +1156,7 @@ static imgtoolerr_t ti990_image_init(imgtool::image *img, imgtool::stream &f)
return IMGTOOLERR_CORRUPTIMAGE;
}
image->file_handle = stream.release();
return IMGTOOLERR_SUCCESS;
}
@ -1764,7 +1765,7 @@ static imgtoolerr_t ti990_image_deletefile(imgtool::partition *partition, const
/*
Create a blank ti990_image.
*/
static imgtoolerr_t ti990_image_create(imgtool::image *image, imgtool::stream &f, util::option_resolution *createoptions)
static imgtoolerr_t ti990_image_create(imgtool::image *image, imgtool::stream::ptr &&stream, util::option_resolution *createoptions)
{
//const char *volname;
ti990_geometry geometry;
@ -1790,7 +1791,7 @@ static imgtoolerr_t ti990_image_create(imgtool::image *image, imgtool::stream &f
set_UINT32BE(& header.sectors_per_track, geometry.sectors_per_track);
set_UINT32BE(& header.bytes_per_sector, geometry.bytes_per_sector);
reply = f.write(&header, sizeof(header));
reply = stream->write(&header, sizeof(header));
if (reply != sizeof(header))
{
return IMGTOOLERR_WRITEERROR;
@ -1803,7 +1804,7 @@ static imgtoolerr_t ti990_image_create(imgtool::image *image, imgtool::stream &f
/* write sector 0 */
if (write_sector_logical(f, 0, & geometry, &sec0))
if (write_sector_logical(*stream, 0, & geometry, &sec0))
return IMGTOOLERR_WRITEERROR;
@ -1811,7 +1812,7 @@ static imgtoolerr_t ti990_image_create(imgtool::image *image, imgtool::stream &f
memset(empty_sec, 0, geometry.bytes_per_sector);
for (i=1; i<totsecs; i++)
if (write_sector_logical(f, i, & geometry, empty_sec))
if (write_sector_logical(*stream, i, & geometry, empty_sec))
return IMGTOOLERR_WRITEERROR;
return (imgtoolerr_t)0;

View File

@ -789,7 +789,7 @@ static imgtoolerr_t vzdos_diskimage_suggesttransfer(imgtool::partition *partitio
return IMGTOOLERR_SUCCESS;
}
static imgtoolerr_t vzdos_diskimage_create(imgtool::image *img, imgtool::stream &stream, util::option_resolution *opts)
static imgtoolerr_t vzdos_diskimage_create(imgtool::image *img, imgtool::stream::ptr &&dummy, util::option_resolution *opts)
{
imgtoolerr_t ret;
int track, sector;