Example #1
0
static imgtoolerr_t write_fork(imgtool_partition *partition, const char *filename, const char *fork,
	imgtool_stream *sourcef, UINT64 pos, UINT64 fork_len, option_resolution *opts)
{
	imgtoolerr_t err = IMGTOOLERR_SUCCESS;
	imgtool_stream *mem_stream = NULL;
	size_t len;

	if (fork_len > 0)
	{
		mem_stream = stream_open_mem(NULL, 0);
		if (!mem_stream)
		{
			err = IMGTOOLERR_OUTOFMEMORY;
			goto done;
		}

		stream_seek(sourcef, pos, SEEK_SET);
		len = stream_transfer(mem_stream, sourcef, fork_len);
		if (len < fork_len)
			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);
		if (err)
			goto done;
	}

done:
	if (mem_stream)
		stream_close(mem_stream);
	return err;
}
Example #2
0
static imgtoolerr_t ascii_writefile(imgtool_partition *partition, const char *filename, const char *fork, imgtool_stream *sourcef, option_resolution *opts)
{
	imgtoolerr_t err;
	imgtool_stream *mem_stream = NULL;
	const char *eoln;

	/* create a stream */
	mem_stream = stream_open_mem(NULL, 0);
	if (!mem_stream)
	{
		err = IMGTOOLERR_OUTOFMEMORY;
		goto done;
	}

	eoln = imgtool_partition_get_info_string(partition, 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, NULL);
	if (err)
		goto done;

done:
	if (mem_stream)
		stream_close(mem_stream);
	return err;
}
Example #3
0
static void node_putfile(struct imgtooltest_state *state, xml_data_node *node)
{
	imgtoolerr_t err;
	const char *filename;
	const char *fork;
	filter_getinfoproc filter;
	imgtool_stream *stream = NULL;
	mess_pile pile;

	if (state->m_partition == NULL)
	{
		state->m_failed = 1;
		report_message(MSG_FAILURE, "Partition not loaded");
		goto done;
	}

	get_file_params(node, &filename, &fork, &filter);
	if (filename == NULL)
		goto done;

	pile_init(&pile);
	messtest_get_data(node, &pile);

	stream = stream_open_mem(NULL, 0);
	if (stream == NULL)
	{
		state->m_failed = 1;
		error_outofmemory();
		goto done;
	}

	stream_write(stream, pile_getptr(&pile), pile_size(&pile));
	stream_seek(stream, 0, SEEK_SET);
	pile_delete(&pile);

	err = imgtool_partition_write_file(state->m_partition, filename, fork, stream, NULL, filter);
	if (err)
	{
		state->m_failed = 1;
		report_imgtoolerr(err);
		goto done;
	}

	if (VERBOSE_FILECHAIN)
	{
		char buf[1024];
		err = imgtool_partition_get_chain_string(state->m_partition, filename, buf, ARRAY_LENGTH(buf));
		if (err == IMGTOOLERR_SUCCESS)
			report_message(MSG_INFO, "Filechain '%s': %s", filename, buf);
	}

done:
	if (stream != NULL)
		stream_close(stream);
}