Implemented potential fix to obey ECMA

This commit is contained in:
Mario Danic 2007-03-20 09:41:52 +00:00
parent b46f805756
commit ef56dc8f4f
2 changed files with 46 additions and 4 deletions

View File

@ -146,6 +146,7 @@ calc_dir_size(struct ecma119_write_target *t,
struct ecma119_tree_node *dir) struct ecma119_tree_node *dir)
{ {
size_t i; size_t i;
size_t newlen;
assert(dir->type == ECMA119_DIR); assert(dir->type == ECMA119_DIR);
@ -157,7 +158,13 @@ calc_dir_size(struct ecma119_write_target *t,
for (i = 0; i < dir->dir.nchildren; i++) { for (i = 0; i < dir->dir.nchildren; i++) {
struct ecma119_tree_node *ch = dir->dir.children[i]; struct ecma119_tree_node *ch = dir->dir.children[i];
newlen = dir->dir.len + ch->dirent_len + ch->susp.non_CE_len;
if ((newlen % 2048) < (dir->dir.len % 2048)) {
dir->dir.len = newlen + (2048 - (dir->dir.len % 2048));
}
else {
dir->dir.len += ch->dirent_len + ch->susp.non_CE_len; dir->dir.len += ch->dirent_len + ch->susp.non_CE_len;
}
dir->dir.CE_len += ch->susp.CE_len; dir->dir.CE_len += ch->susp.CE_len;
} }
t->total_dir_size += round_up(dir->dir.len + dir->dir.CE_len, t->total_dir_size += round_up(dir->dir.len + dir->dir.CE_len,
@ -567,7 +574,10 @@ write_one_dir(struct ecma119_write_target *t,
uint8_t *buf) uint8_t *buf)
{ {
size_t i; size_t i;
int j;
size_t len;
uint8_t *orig_buf = buf; uint8_t *orig_buf = buf;
uint8_t *prior_buf = buf;
assert(dir->type == ECMA119_DIR); assert(dir->type == ECMA119_DIR);
/* write the "." and ".." entries first */ /* write the "." and ".." entries first */
@ -579,8 +589,19 @@ write_one_dir(struct ecma119_write_target *t,
for (i = 0; i < dir->dir.nchildren; i++) { for (i = 0; i < dir->dir.nchildren; i++) {
write_one_dir_record(t, dir->dir.children[i], -1, buf); write_one_dir_record(t, dir->dir.children[i], -1, buf);
len = ((struct ecma119_dir_record*) buf)->len_dr[0];
if ((buf + len - prior_buf) >= 2048) {
for (j = len - 1; j >= 0; j--) {
prior_buf[2048 + j] = buf[j];
buf[j] = 0;
}
prior_buf += 2048;
buf = prior_buf + len;
}
else {
buf += ((struct ecma119_dir_record*) buf)->len_dr[0]; buf += ((struct ecma119_dir_record*) buf)->len_dr[0];
} }
}
/* write the susp continuation areas */ /* write the susp continuation areas */
if (t->rockridge) { if (t->rockridge) {

View File

@ -101,6 +101,7 @@ joliet_calc_dir_size(struct ecma119_write_target *t,
struct joliet_tree_node *root) struct joliet_tree_node *root)
{ {
size_t i; size_t i;
size_t newlen;
struct joliet_tree_node *ch; struct joliet_tree_node *ch;
assert(root && ISO_ISDIR(root->iso_self)); assert(root && ISO_ISDIR(root->iso_self));
@ -108,7 +109,13 @@ joliet_calc_dir_size(struct ecma119_write_target *t,
root->len = 68; /* for "." and ".." entries */ root->len = 68; /* for "." and ".." entries */
for (i = 0; i < root->nchildren; i++) { for (i = 0; i < root->nchildren; i++) {
ch = root->children[i]; ch = root->children[i];
newlen = root->len + ch->dirent_len;
if ((newlen % 2048) < (root->len % 2048)) {
root->len = newlen + (2048 - (root->len % 2048));
}
else {
root->len += ch->dirent_len; root->len += ch->dirent_len;
}
if (ISO_ISDIR(ch->iso_self)) if (ISO_ISDIR(ch->iso_self))
joliet_calc_dir_size(t, ch); joliet_calc_dir_size(t, ch);
} }
@ -305,7 +312,10 @@ write_one_dir(struct ecma119_write_target *t,
uint8_t *buf) uint8_t *buf)
{ {
size_t i; size_t i;
int j;
size_t len;
uint8_t *orig_buf = buf; uint8_t *orig_buf = buf;
uint8_t *prior_buf = buf;
assert(ISO_ISDIR (dir->iso_self)); assert(ISO_ISDIR (dir->iso_self));
/* write the "." and ".." entries first */ /* write the "." and ".." entries first */
@ -317,8 +327,19 @@ write_one_dir(struct ecma119_write_target *t,
for (i = 0; i < dir->nchildren; i++) { for (i = 0; i < dir->nchildren; i++) {
write_one_dir_record(t, dir->children[i], -1, buf); write_one_dir_record(t, dir->children[i], -1, buf);
len = ((struct ecma119_dir_record*) buf)->len_dr[0];
if ((buf + len - prior_buf) >= 2048) {
for (j = len - 1; j >= 0; j--) {
prior_buf[2048 + j] = buf[j];
buf[j] = 0;
}
prior_buf += 2048;
buf = prior_buf + len;
}
else {
buf += ((struct ecma119_dir_record*) buf)->len_dr[0]; buf += ((struct ecma119_dir_record*) buf)->len_dr[0];
} }
}
assert (buf - orig_buf == dir->len); assert (buf - orig_buf == dir->len);
} }