From ecf2ca044e09b991308a259c04489fbe4975cbbc Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Tue, 11 Aug 2009 21:08:15 +0200 Subject: [PATCH] Prevented that non-MD5 nodes from old image get an MD5 in appended session. --- libisofs/ecma119.c | 33 ++++++++++++++++++++++----------- libisofs/filesrc.c | 14 +++++++++++--- libisofs/libisofs.h | 3 ++- libisofs/md5.c | 2 +- libisofs/node.c | 7 +++++-- 5 files changed, 41 insertions(+), 18 deletions(-) diff --git a/libisofs/ecma119.c b/libisofs/ecma119.c index 22a6882..fb44cbb 100644 --- a/libisofs/ecma119.c +++ b/libisofs/ecma119.c @@ -896,20 +896,24 @@ int checksum_prepare_image(IsoImage *src, int flag) @flag bit0= recursion */ static -int checksum_prepare_nodes(IsoImage *img, IsoNode *node, int flag) +int checksum_prepare_nodes(Ecma119Image *target, IsoNode *node, int flag) { IsoNode *pos; IsoFile *file; - int ret, i; + IsoImage *img; + int ret, i, no_md5 = 0; size_t value_length; unsigned int idx = 0; char *value; void *xipt = NULL; + img= target->image; + if (node->type == LIBISO_FILE) { file = (IsoFile *) node; - if (file->from_old_session) { - /* Save eventual MD5 data of files from old image */ + if (file->from_old_session && target->appendable) { + /* Save MD5 data of files from old image which will not + be copied and have an MD5 recorded in the old image. */ value= NULL; ret = iso_node_lookup_attr(node, "isofs.cx", &value_length, &value, 0); @@ -924,18 +928,25 @@ int checksum_prepare_nodes(IsoImage *img, IsoNode *node, int flag) xipt); if (ret < 0) return ret; - } + } else + no_md5 = 1; + } else { + no_md5 = 1; } if (value != NULL) free(value); } - /* Equip all nodes with provisory isofs.cx numbers: 4 byte, all 0. */ - ret = iso_file_set_isofscx(file, (unsigned int) 0, 0); - if (ret < 0) - return ret; + /* Equip nodes with provisory isofs.cx numbers: 4 byte, all 0. + Omit those from old image which will not be copied and have no MD5. + */ + if (!no_md5) { + ret = iso_file_set_isofscx(file, (unsigned int) 0, 0); + if (ret < 0) + return ret; + } } else if (node->type == LIBISO_DIR) { for (pos = ((IsoDir *) node)->children; pos != NULL; pos = pos->next) { - ret = checksum_prepare_nodes(img, pos, 1); + ret = checksum_prepare_nodes(target, pos, 1); if (ret < 0) return ret; } @@ -1081,7 +1092,7 @@ int ecma119_image_new(IsoImage *src, IsoWriteOpts *opts, Ecma119Image **img) if (ret < 0) return ret; if (target->appendable) { - ret = checksum_prepare_nodes(src, (IsoNode *) src->root, 0); + ret = checksum_prepare_nodes(target, (IsoNode *) src->root, 0); if (ret < 0) return ret; } diff --git a/libisofs/filesrc.c b/libisofs/filesrc.c index 6a4c22b..206bec0 100644 --- a/libisofs/filesrc.c +++ b/libisofs/filesrc.c @@ -49,7 +49,8 @@ int iso_file_src_create(Ecma119Image *img, IsoFile *file, IsoFileSrc **src) ino_t ino_id; #ifdef Libisofs_with_checksumS - int cret; + int cret, no_md5= 0; + void *xipt = NULL; #endif if (img == NULL || file == NULL || src == NULL) { @@ -99,7 +100,7 @@ int iso_file_src_create(Ecma119Image *img, IsoFile *file, IsoFileSrc **src) #ifdef Libisofs_with_checksumS - if (ret == 0) { + if (ret == 0 && (*src)->checksum_index > 0) { /* Duplicate file source was mapped to previously registered source */ cret = iso_file_set_isofscx(file, (*src)->checksum_index, 0); @@ -117,7 +118,14 @@ int iso_file_src_create(Ecma119Image *img, IsoFile *file, IsoFileSrc **src) #ifdef Libisofs_with_checksumS - if(img->md5_file_checksums) { + if (img->md5_file_checksums && file->from_old_session && img->appendable) { + /* Omit MD5 indexing with old image nodes which have no MD5 */ + ret = iso_node_get_xinfo((IsoNode *) file, checksum_xinfo_func, &xipt); + if (ret <= 0) + no_md5 = 1; + } + + if (img->md5_file_checksums && !no_md5) { img->checksum_idx_counter++; if (img->checksum_idx_counter < 0x80000000) { fsrc->checksum_index= img->checksum_idx_counter; diff --git a/libisofs/libisofs.h b/libisofs/libisofs.h index 7b644ba..025fd4c 100644 --- a/libisofs/libisofs.h +++ b/libisofs/libisofs.h @@ -5033,7 +5033,8 @@ int iso_image_get_session_md5(IsoImage *image, uint32_t *start_lba, * @param md5 * Eventually returns 16 byte of MD5 checksum * @param flag - * Bitfield for control purposes, unused yet, submit 0 + * Bitfield for control purposes + * bit0= only determine return value, do not touch parameter md5 * @return * 1= md5 found , 0= no md5 available , <0 indicates error * diff --git a/libisofs/md5.c b/libisofs/md5.c index ad405d2..b9b4313 100644 --- a/libisofs/md5.c +++ b/libisofs/md5.c @@ -427,7 +427,7 @@ int checksum_copy_old_nodes(Ecma119Image *target, IsoNode *node, int flag) if (node->type == LIBISO_FILE) { file = (IsoFile *) node; - if (file->from_old_session) { + if (file->from_old_session && target->appendable) { ret = iso_node_get_xinfo(node, checksum_xinfo_func, &xipt); if (ret <= 0) return ret; diff --git a/libisofs/node.c b/libisofs/node.c index 008ab5e..7b55b7d 100644 --- a/libisofs/node.c +++ b/libisofs/node.c @@ -2696,8 +2696,11 @@ int iso_file_get_md5(IsoImage *image, IsoFile *file, char md5[16], int flag) ret = 0; goto ex; } - memcpy(md5, image->checksum_array + ((size_t) 16) * ((size_t) idx), 16); - ret = ISO_SUCCESS; + if (!(flag & 1)) { + memcpy(md5, image->checksum_array + ((size_t) 16) * ((size_t) idx), + 16); + } + ret = 1; ex:; if (value != NULL) free(value);