From ce0949a585e68ac28ded527baab7511a532ad102 Mon Sep 17 00:00:00 2001 From: Vreixo Formoso Date: Tue, 19 Aug 2008 03:31:50 +0200 Subject: [PATCH] Compute correctly directory size. --- libisofs/ecma119.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/libisofs/ecma119.c b/libisofs/ecma119.c index 45f524a..0fd4dd7 100644 --- a/libisofs/ecma119.c +++ b/libisofs/ecma119.c @@ -117,18 +117,23 @@ size_t calc_dir_size(Ecma119Image *t, Ecma119Node *dir, size_t *ce) for (i = 0; i < dir->info.dir->nchildren; ++i) { size_t remaining; + int section, nsections; Ecma119Node *child = dir->info.dir->children[i]; size_t dirent_len = calc_dirent_len(t, child); - if (t->rockridge) { - dirent_len += rrip_calc_len(t, child, 0, 255 - dirent_len, &ce_len); - *ce += ce_len; - } - remaining = BLOCK_SIZE - (len % BLOCK_SIZE); - if (dirent_len > remaining) { - /* child directory entry doesn't fit on block */ - len += remaining + dirent_len; - } else { - len += dirent_len; + + nsections = (child->type == ECMA119_FILE) ? child->info.file->nsections : 1; + for (section = 0; section < nsections; ++section) { + if (t->rockridge && section == nsections - 1) { + dirent_len += rrip_calc_len(t, child, 0, 255 - dirent_len, &ce_len); + *ce += ce_len; + } + remaining = BLOCK_SIZE - (len % BLOCK_SIZE); + if (dirent_len > remaining) { + /* child directory entry doesn't fit on block */ + len += remaining + dirent_len; + } else { + len += dirent_len; + } } } @@ -459,18 +464,18 @@ int write_one_dir(Ecma119Image *t, Ecma119Node *dir) len += 2; } - /* get the SUSP fields if rockridge is enabled */ - if (t->rockridge) { - ret = rrip_get_susp_fields(t, child, 0, 255 - len, &info); - if (ret < 0) { - return ret; - } - len += info.suf_len; - } - nsections = (child->type == ECMA119_FILE) ? child->info.file->nsections : 1; for (section = 0; section < nsections; ++section) { + /* get the SUSP fields if rockridge is enabled */ + if (t->rockridge && section == nsections - 1) { + ret = rrip_get_susp_fields(t, child, 0, 255 - len, &info); + if (ret < 0) { + return ret; + } + len += info.suf_len; + } + if ( (buf + len - buffer) > BLOCK_SIZE) { /* dir doesn't fit in current block */ ret = iso_write(t, buffer, BLOCK_SIZE);