Transplanting checksum buffer from Ecma119Image to IsoImage.
This commit is contained in:
parent
72e9c67d05
commit
cadd77776b
@ -49,9 +49,15 @@ void ecma119_image_free(Ecma119Image *t)
|
|||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
|
if (t == NULL)
|
||||||
|
return;
|
||||||
|
if (t->root != NULL)
|
||||||
ecma119_node_free(t->root);
|
ecma119_node_free(t->root);
|
||||||
|
if (t->image != NULL)
|
||||||
iso_image_unref(t->image);
|
iso_image_unref(t->image);
|
||||||
|
if (t->files != NULL)
|
||||||
iso_rbtree_destroy(t->files, iso_file_src_free);
|
iso_rbtree_destroy(t->files, iso_file_src_free);
|
||||||
|
if (t->buffer != NULL)
|
||||||
iso_ring_buffer_free(t->buffer);
|
iso_ring_buffer_free(t->buffer);
|
||||||
|
|
||||||
for (i = 0; i < t->nwriters; ++i) {
|
for (i = 0; i < t->nwriters; ++i) {
|
||||||
@ -59,7 +65,9 @@ void ecma119_image_free(Ecma119Image *t)
|
|||||||
writer->free_data(writer);
|
writer->free_data(writer);
|
||||||
free(writer);
|
free(writer);
|
||||||
}
|
}
|
||||||
|
if (t->input_charset != NULL)
|
||||||
free(t->input_charset);
|
free(t->input_charset);
|
||||||
|
if (t->output_charset != NULL)
|
||||||
free(t->output_charset);
|
free(t->output_charset);
|
||||||
|
|
||||||
#ifdef Libisofs_with_checksumS
|
#ifdef Libisofs_with_checksumS
|
||||||
@ -71,6 +79,7 @@ void ecma119_image_free(Ecma119Image *t)
|
|||||||
free(t->checksum_buffer);
|
free(t->checksum_buffer);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (t->writers != NULL)
|
||||||
free(t->writers);
|
free(t->writers);
|
||||||
free(t);
|
free(t);
|
||||||
}
|
}
|
||||||
@ -891,6 +900,18 @@ void *write_function(void *arg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef Libisofs_with_checksumS
|
||||||
|
|
||||||
|
/* Transplant checksum buffer from Ecma119Image to IsoImage */
|
||||||
|
iso_image_set_checksums(target->image, target->checksum_buffer,
|
||||||
|
target->checksum_range_start,
|
||||||
|
target->checksum_array_pos,
|
||||||
|
target->checksum_idx_counter + 2, 0);
|
||||||
|
target->checksum_buffer = NULL;
|
||||||
|
target->checksum_idx_counter = 0;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
iso_ring_buffer_writer_close(target->buffer, 0);
|
iso_ring_buffer_writer_close(target->buffer, 0);
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
|
|
||||||
@ -904,6 +925,13 @@ void *write_function(void *arg)
|
|||||||
"Image write error");
|
"Image write error");
|
||||||
}
|
}
|
||||||
iso_ring_buffer_writer_close(target->buffer, 1);
|
iso_ring_buffer_writer_close(target->buffer, 1);
|
||||||
|
|
||||||
|
#ifdef Libisofs_with_checksumS
|
||||||
|
|
||||||
|
/* >>> ??? transplant checksum buffer from Ecma119Image to IsoImage */;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1002,7 +1030,7 @@ int checksum_prepare_nodes(Ecma119Image *target, IsoNode *node, int flag)
|
|||||||
static
|
static
|
||||||
int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img)
|
int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img)
|
||||||
{
|
{
|
||||||
int ret, i, voldesc_size, nwriters;
|
int ret, i, voldesc_size, nwriters, image_checksums_mad = 0;
|
||||||
Ecma119Image *target;
|
Ecma119Image *target;
|
||||||
int el_torito_writer_index = -1, file_src_writer_index= -1;
|
int el_torito_writer_index = -1, file_src_writer_index= -1;
|
||||||
|
|
||||||
@ -1015,8 +1043,7 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img)
|
|||||||
/* create the tree for file caching */
|
/* create the tree for file caching */
|
||||||
ret = iso_rbtree_new(iso_file_src_cmp, &(target->files));
|
ret = iso_rbtree_new(iso_file_src_cmp, &(target->files));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
free(target);
|
goto target_cleanup;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
target->image = src;
|
target->image = src;
|
||||||
@ -1074,9 +1101,8 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img)
|
|||||||
|
|
||||||
target->input_charset = strdup(iso_get_local_charset(0));
|
target->input_charset = strdup(iso_get_local_charset(0));
|
||||||
if (target->input_charset == NULL) {
|
if (target->input_charset == NULL) {
|
||||||
iso_image_unref(src);
|
ret = ISO_OUT_OF_MEM;
|
||||||
free(target);
|
goto target_cleanup;
|
||||||
return ISO_OUT_OF_MEM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (opts->output_charset != NULL) {
|
if (opts->output_charset != NULL) {
|
||||||
@ -1085,9 +1111,8 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img)
|
|||||||
target->output_charset = strdup(target->input_charset);
|
target->output_charset = strdup(target->input_charset);
|
||||||
}
|
}
|
||||||
if (target->output_charset == NULL) {
|
if (target->output_charset == NULL) {
|
||||||
iso_image_unref(src);
|
ret = ISO_OUT_OF_MEM;
|
||||||
free(target);
|
goto target_cleanup;
|
||||||
return ISO_OUT_OF_MEM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef Libisofs_with_checksumS
|
#ifdef Libisofs_with_checksumS
|
||||||
@ -1137,13 +1162,16 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img)
|
|||||||
|
|
||||||
if ((target->md5_file_checksums & 1) || target->md5_session_checksum) {
|
if ((target->md5_file_checksums & 1) || target->md5_session_checksum) {
|
||||||
nwriters++;
|
nwriters++;
|
||||||
|
image_checksums_mad = 1; /* from here on the loaded checksums are
|
||||||
|
not consistent with isofs.cx any more.
|
||||||
|
*/
|
||||||
ret = checksum_prepare_image(src, 0);
|
ret = checksum_prepare_image(src, 0);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
goto target_cleanup;
|
||||||
if (target->appendable) {
|
if (target->appendable) {
|
||||||
ret = checksum_prepare_nodes(target, (IsoNode *) src->root, 0);
|
ret = checksum_prepare_nodes(target, (IsoNode *) src->root, 0);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
goto target_cleanup;
|
||||||
}
|
}
|
||||||
target->checksum_idx_counter = 0;
|
target->checksum_idx_counter = 0;
|
||||||
}
|
}
|
||||||
@ -1153,9 +1181,8 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img)
|
|||||||
|
|
||||||
target->writers = malloc(nwriters * sizeof(void*));
|
target->writers = malloc(nwriters * sizeof(void*));
|
||||||
if (target->writers == NULL) {
|
if (target->writers == NULL) {
|
||||||
iso_image_unref(src);
|
ret = ISO_OUT_OF_MEM;
|
||||||
free(target);
|
goto target_cleanup;
|
||||||
return ISO_OUT_OF_MEM;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create writer for ECMA-119 structure */
|
/* create writer for ECMA-119 structure */
|
||||||
@ -1328,7 +1355,7 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img)
|
|||||||
if (target->checksum_rlsb_tag_pos < 32) {
|
if (target->checksum_rlsb_tag_pos < 32) {
|
||||||
ret = iso_md5_start(&(target->checksum_ctx));
|
ret = iso_md5_start(&(target->checksum_ctx));
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
goto target_cleanup;
|
||||||
target->opts_overwrite = (char *) opts->overwrite;
|
target->opts_overwrite = (char *) opts->overwrite;
|
||||||
iso_md5_compute(target->checksum_ctx, target->opts_overwrite,
|
iso_md5_compute(target->checksum_ctx, target->opts_overwrite,
|
||||||
target->checksum_rlsb_tag_pos * 2048);
|
target->checksum_rlsb_tag_pos * 2048);
|
||||||
@ -1360,8 +1387,13 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img)
|
|||||||
iso_md5_end(&(target->checksum_ctx), target->image_md5);
|
iso_md5_end(&(target->checksum_ctx), target->image_md5);
|
||||||
ret = iso_md5_start(&(target->checksum_ctx));
|
ret = iso_md5_start(&(target->checksum_ctx));
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
goto target_cleanup;
|
||||||
}
|
}
|
||||||
|
/* Dispose old image checksum buffer. The one of target is supposed to
|
||||||
|
get attached at the end of write_function(). */
|
||||||
|
iso_image_free_checksums(target->image, 0);
|
||||||
|
image_checksums_mad = 0;
|
||||||
|
|
||||||
#endif /* Libisofs_with_checksumS */
|
#endif /* Libisofs_with_checksumS */
|
||||||
|
|
||||||
/* ensure the thread is created joinable */
|
/* ensure the thread is created joinable */
|
||||||
@ -1388,6 +1420,14 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img)
|
|||||||
return ISO_SUCCESS;
|
return ISO_SUCCESS;
|
||||||
|
|
||||||
target_cleanup: ;
|
target_cleanup: ;
|
||||||
|
|
||||||
|
#ifdef Libisofs_with_checksumS
|
||||||
|
|
||||||
|
if(image_checksums_mad) /* No checksums is better than mad checksums */
|
||||||
|
iso_image_free_checksums(target->image, 0);
|
||||||
|
|
||||||
|
#endif /* Libisofs_with_checksumS */
|
||||||
|
|
||||||
ecma119_image_free(target);
|
ecma119_image_free(target);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -134,10 +134,29 @@ void iso_image_unref(IsoImage *image)
|
|||||||
free(image->biblio_file_id);
|
free(image->biblio_file_id);
|
||||||
if (image->used_inodes != NULL)
|
if (image->used_inodes != NULL)
|
||||||
free(image->used_inodes);
|
free(image->used_inodes);
|
||||||
|
iso_image_free_checksums(image, 0);
|
||||||
free(image);
|
free(image);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int iso_image_free_checksums(IsoImage *image, int flag)
|
||||||
|
{
|
||||||
|
#ifdef Libisofs_with_checksumS
|
||||||
|
|
||||||
|
image->checksum_start_lba = 0;
|
||||||
|
image->checksum_end_lba = 0;
|
||||||
|
image->checksum_idx_count = 0;
|
||||||
|
if (image->checksum_array != NULL)
|
||||||
|
free(image->checksum_array);
|
||||||
|
image->checksum_array = NULL;
|
||||||
|
|
||||||
|
#endif /* Libisofs_with_checksumS */
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attach user defined data to the image. Use this if your application needs
|
* Attach user defined data to the image. Use this if your application needs
|
||||||
* to store addition info together with the IsoImage. If the image already
|
* to store addition info together with the IsoImage. If the image already
|
||||||
@ -559,3 +578,22 @@ int iso_image_get_session_md5(IsoImage *image, uint32_t *start_lba,
|
|||||||
#endif /* ! Libisofs_with_checksumS */
|
#endif /* ! Libisofs_with_checksumS */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int iso_image_set_checksums(IsoImage *image, char *checksum_array,
|
||||||
|
uint32_t start_lba, uint32_t end_lba,
|
||||||
|
uint32_t idx_count, int flag)
|
||||||
|
{
|
||||||
|
|
||||||
|
#ifdef Libisofs_with_checksumS
|
||||||
|
|
||||||
|
iso_image_free_checksums(image, 0);
|
||||||
|
image->checksum_array = checksum_array;
|
||||||
|
image->checksum_start_lba = start_lba;
|
||||||
|
image->checksum_end_lba = end_lba;
|
||||||
|
image->checksum_idx_count = idx_count;
|
||||||
|
|
||||||
|
#endif /* Libisofs_with_checksumS */
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -197,4 +197,18 @@ ino_t img_give_ino_number(IsoImage *image, int flag);
|
|||||||
*/
|
*/
|
||||||
int img_make_inos(IsoImage *image, IsoDir *dir, int flag);
|
int img_make_inos(IsoImage *image, IsoDir *dir, int flag);
|
||||||
|
|
||||||
|
|
||||||
|
/* Free the checksum array of an image and reset its layout parameters
|
||||||
|
*/
|
||||||
|
int iso_image_free_checksums(IsoImage *image, int flag);
|
||||||
|
|
||||||
|
|
||||||
|
/* Equip an ISO image with a new checksum array buffer (after isofs.ca and
|
||||||
|
isofs.cx have already been adjusted).
|
||||||
|
*/
|
||||||
|
int iso_image_set_checksums(IsoImage *image, char *checksum_array,
|
||||||
|
uint32_t start_lba, uint32_t end_lba,
|
||||||
|
uint32_t idx_count, int flag);
|
||||||
|
|
||||||
|
|
||||||
#endif /*LIBISO_IMAGE_H_*/
|
#endif /*LIBISO_IMAGE_H_*/
|
||||||
|
Loading…
Reference in New Issue
Block a user