Improve messages shown on some errors (fixes ticket #137).
This commit is contained in:
parent
2de74d04a7
commit
1ccc532808
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2007 Vreixo Formoso
|
||||
*
|
||||
* This file is part of the libisofs project; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2 as
|
||||
*
|
||||
* This file is part of the libisofs project; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation. See COPYING file for details.
|
||||
*/
|
||||
|
||||
@ -61,18 +61,18 @@ int get_iso_name(Ecma119Image *img, IsoNode *iso, char **name)
|
||||
}
|
||||
} else {
|
||||
if (img->max_37_char_filenames) {
|
||||
isoname = iso_r_fileid(ascii_name, 36, relaxed,
|
||||
isoname = iso_r_fileid(ascii_name, 36, relaxed,
|
||||
img->no_force_dots ? 0 : 1);
|
||||
} else if (img->iso_level == 1) {
|
||||
if (relaxed) {
|
||||
isoname = iso_r_fileid(ascii_name, 11, relaxed,
|
||||
isoname = iso_r_fileid(ascii_name, 11, relaxed,
|
||||
img->no_force_dots ? 0 : 1);
|
||||
} else {
|
||||
isoname = iso_1_fileid(ascii_name);
|
||||
}
|
||||
} else {
|
||||
if (relaxed) {
|
||||
isoname = iso_r_fileid(ascii_name, 30, relaxed,
|
||||
isoname = iso_r_fileid(ascii_name, 30, relaxed,
|
||||
img->no_force_dots ? 0 : 1);
|
||||
} else {
|
||||
isoname = iso_2_fileid(ascii_name);
|
||||
@ -84,7 +84,7 @@ int get_iso_name(Ecma119Image *img, IsoNode *iso, char **name)
|
||||
*name = isoname;
|
||||
return ISO_SUCCESS;
|
||||
} else {
|
||||
/*
|
||||
/*
|
||||
* only possible if mem error, as check for empty names is done
|
||||
* in public tree
|
||||
*/
|
||||
@ -129,7 +129,7 @@ int create_dir(Ecma119Image *img, IsoDir *iso, Ecma119Node **node)
|
||||
if (children == NULL) {
|
||||
return ISO_OUT_OF_MEM;
|
||||
}
|
||||
|
||||
|
||||
dir_info = calloc(1, sizeof(struct ecma119_dir_info));
|
||||
if (dir_info == NULL) {
|
||||
free(children);
|
||||
@ -162,9 +162,12 @@ int create_file(Ecma119Image *img, IsoFile *iso, Ecma119Node **node)
|
||||
|
||||
size = iso_stream_get_size(iso->stream);
|
||||
if (size > (off_t)0xffffffff) {
|
||||
return iso_msg_submit(img->image->id, ISO_FILE_TOO_BIG, 0,
|
||||
char *ipath = iso_tree_get_node_path(ISO_NODE(iso));
|
||||
ret = iso_msg_submit(img->image->id, ISO_FILE_TOO_BIG, 0,
|
||||
"File \"%s\" can't be added to image because "
|
||||
"is greater than 4GB", iso->node.name);
|
||||
"is greater than 4GB", ipath);
|
||||
free(ipath);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = iso_file_src_create(img, iso, &src);
|
||||
@ -174,9 +177,9 @@ int create_file(Ecma119Image *img, IsoFile *iso, Ecma119Node **node)
|
||||
|
||||
ret = create_ecma119_node(img, (IsoNode*)iso, node);
|
||||
if (ret < 0) {
|
||||
/*
|
||||
/*
|
||||
* the src doesn't need to be freed, it is free together with
|
||||
* the Ecma119Image
|
||||
* the Ecma119Image
|
||||
*/
|
||||
return ret;
|
||||
}
|
||||
@ -203,9 +206,9 @@ int create_boot_cat(Ecma119Image *img, IsoBoot *iso, Ecma119Node **node)
|
||||
|
||||
ret = create_ecma119_node(img, (IsoNode*)iso, node);
|
||||
if (ret < 0) {
|
||||
/*
|
||||
/*
|
||||
* the src doesn't need to be freed, it is free together with
|
||||
* the Ecma119Image
|
||||
* the Ecma119Image
|
||||
*/
|
||||
return ret;
|
||||
}
|
||||
@ -267,10 +270,10 @@ void ecma119_node_free(Ecma119Node *node)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @return
|
||||
* 1 success, 0 node ignored, < 0 error
|
||||
*
|
||||
*
|
||||
*/
|
||||
static
|
||||
int create_tree(Ecma119Image *image, IsoNode *iso, Ecma119Node **tree,
|
||||
@ -296,15 +299,21 @@ int create_tree(Ecma119Image *image, IsoNode *iso, Ecma119Node **tree,
|
||||
max_path = pathlen + 1 + (iso_name ? strlen(iso_name) : 0);
|
||||
if (!image->rockridge) {
|
||||
if ((iso->type == LIBISO_DIR && depth > 8) && !image->allow_deep_paths) {
|
||||
free(iso_name);
|
||||
char *ipath = iso_tree_get_node_path(iso);
|
||||
return iso_msg_submit(image->image->id, ISO_FILE_IMGPATH_WRONG, 0,
|
||||
"File \"%s\" can't be added, because directory depth "
|
||||
"is greater than 8.", iso->name);
|
||||
} else if (max_path > 255 && !image->allow_longer_paths) {
|
||||
"is greater than 8.", ipath);
|
||||
free(iso_name);
|
||||
return iso_msg_submit(image->image->id, ISO_FILE_IMGPATH_WRONG, 0,
|
||||
free(ipath);
|
||||
return ret;
|
||||
} else if (max_path > 255 && !image->allow_longer_paths) {
|
||||
char *ipath = iso_tree_get_node_path(iso);
|
||||
ret = iso_msg_submit(image->image->id, ISO_FILE_IMGPATH_WRONG, 0,
|
||||
"File \"%s\" can't be added, because path length "
|
||||
"is greater than 255 characters", iso->name);
|
||||
"is greater than 255 characters", ipath);
|
||||
free(iso_name);
|
||||
free(ipath);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@ -317,19 +326,23 @@ int create_tree(Ecma119Image *image, IsoNode *iso, Ecma119Node **tree,
|
||||
ret = create_symlink(image, (IsoSymlink*)iso, &node);
|
||||
} else {
|
||||
/* symlinks are only supported when RR is enabled */
|
||||
char *ipath = iso_tree_get_node_path(iso);
|
||||
ret = iso_msg_submit(image->image->id, ISO_FILE_IGNORED, 0,
|
||||
"File \"%s\" ignored. Symlinks need RockRidge extensions.",
|
||||
iso->name);
|
||||
"File \"%s\" ignored. Symlinks need RockRidge extensions.",
|
||||
ipath);
|
||||
free(ipath);
|
||||
}
|
||||
break;
|
||||
case LIBISO_SPECIAL:
|
||||
if (image->rockridge) {
|
||||
ret = create_special(image, (IsoSpecial*)iso, &node);
|
||||
} else {
|
||||
/* symlinks are only supported when RR is enabled */
|
||||
/* special files are only supported when RR is enabled */
|
||||
char *ipath = iso_tree_get_node_path(iso);
|
||||
ret = iso_msg_submit(image->image->id, ISO_FILE_IGNORED, 0,
|
||||
"File \"%s\" ignored. Special files need RockRidge extensions.",
|
||||
iso->name);
|
||||
"File \"%s\" ignored. Special files need RockRidge extensions.",
|
||||
ipath);
|
||||
free(ipath);
|
||||
}
|
||||
break;
|
||||
case LIBISO_BOOT:
|
||||
@ -338,8 +351,7 @@ int create_tree(Ecma119Image *image, IsoNode *iso, Ecma119Node **tree,
|
||||
} else {
|
||||
/* log and ignore */
|
||||
ret = iso_msg_submit(image->image->id, ISO_FILE_IGNORED, 0,
|
||||
"El-Torito catalog found on a image without El-Torito.",
|
||||
iso->name);
|
||||
"El-Torito catalog found on a image without El-Torito.");
|
||||
}
|
||||
break;
|
||||
case LIBISO_DIR:
|
||||
@ -430,9 +442,9 @@ int mangle_single_dir(Ecma119Image *img, Ecma119Node *dir, int max_file_len,
|
||||
|
||||
nchildren = dir->info.dir->nchildren;
|
||||
children = dir->info.dir->children;
|
||||
|
||||
|
||||
/* a hash table will temporary hold the names, for fast searching */
|
||||
ret = iso_htable_create((nchildren * 100) / 80, iso_str_hash,
|
||||
ret = iso_htable_create((nchildren * 100) / 80, iso_str_hash,
|
||||
(compare_function_t)strcmp, &table);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
@ -463,7 +475,7 @@ int mangle_single_dir(Ecma119Image *img, Ecma119Node *dir, int max_file_len,
|
||||
}
|
||||
|
||||
/*
|
||||
* A max of 7 characters is good enought, it allows handling up to
|
||||
* A max of 7 characters is good enought, it allows handling up to
|
||||
* 9,999,999 files with same name. We can increment this to
|
||||
* max_name_len, but the int_pow() function must then be modified
|
||||
* to return a bigger integer.
|
||||
@ -480,8 +492,8 @@ int mangle_single_dir(Ecma119Image *img, Ecma119Node *dir, int max_file_len,
|
||||
dot = strrchr(full_name, '.');
|
||||
if (dot != NULL && children[i]->type != ECMA119_DIR) {
|
||||
|
||||
/*
|
||||
* File (not dir) with extension
|
||||
/*
|
||||
* File (not dir) with extension
|
||||
* Note that we don't need to check for placeholders, as
|
||||
* tree reparent happens later, so no placeholders can be
|
||||
* here at this time.
|
||||
@ -491,26 +503,26 @@ int mangle_single_dir(Ecma119Image *img, Ecma119Node *dir, int max_file_len,
|
||||
name = full_name;
|
||||
ext = dot + 1;
|
||||
|
||||
/*
|
||||
/*
|
||||
* For iso level 1 we force ext len to be 3, as name
|
||||
* can't grow on the extension space
|
||||
* can't grow on the extension space
|
||||
*/
|
||||
extlen = (max_file_len == 12) ? 3 : strlen(ext);
|
||||
max = max_file_len - extlen - 1 - digits;
|
||||
if (max <= 0) {
|
||||
/* this can happen if extension is too long */
|
||||
if (extlen + max > 3) {
|
||||
/*
|
||||
/*
|
||||
* reduce extension len, to give name an extra char
|
||||
* note that max is negative or 0
|
||||
* note that max is negative or 0
|
||||
*/
|
||||
extlen = extlen + max - 1;
|
||||
ext[extlen] = '\0';
|
||||
max = max_file_len - extlen - 1 - digits;
|
||||
} else {
|
||||
/*
|
||||
/*
|
||||
* error, we don't support extensions < 3
|
||||
* This can't happen with current limit of digits.
|
||||
* This can't happen with current limit of digits.
|
||||
*/
|
||||
ret = ISO_ERROR;
|
||||
goto mangle_cleanup;
|
||||
@ -572,7 +584,7 @@ int mangle_single_dir(Ecma119Image *img, Ecma119Node *dir, int max_file_len,
|
||||
children[k]->iso_name = new;
|
||||
iso_htable_add(table, new, new);
|
||||
|
||||
/*
|
||||
/*
|
||||
* if we change a name we need to sort again children
|
||||
* at the end
|
||||
*/
|
||||
@ -603,7 +615,7 @@ int mangle_single_dir(Ecma119Image *img, Ecma119Node *dir, int max_file_len,
|
||||
}
|
||||
|
||||
ret = ISO_SUCCESS;
|
||||
|
||||
|
||||
mangle_cleanup : ;
|
||||
iso_htable_destroy(table, NULL);
|
||||
return ret;
|
||||
@ -658,7 +670,7 @@ int mangle_tree(Ecma119Image *img, int recurse)
|
||||
/**
|
||||
* Create a new ECMA-119 node representing a placeholder for a relocated
|
||||
* dir.
|
||||
*
|
||||
*
|
||||
* See IEEE P1282, section 4.1.5 for details
|
||||
*/
|
||||
static
|
||||
@ -672,10 +684,10 @@ int create_placeholder(Ecma119Node *parent, Ecma119Node *real,
|
||||
return ISO_OUT_OF_MEM;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* TODO
|
||||
* If real is a dir, while placeholder is a file, ISO name restricctions
|
||||
* are different, what to do?
|
||||
* If real is a dir, while placeholder is a file, ISO name restricctions
|
||||
* are different, what to do?
|
||||
*/
|
||||
ret->iso_name = strdup(real->iso_name);
|
||||
if (ret->iso_name == NULL) {
|
||||
@ -708,10 +720,10 @@ size_t max_child_name_len(Ecma119Node *dir)
|
||||
}
|
||||
|
||||
/**
|
||||
* Relocates a directory, as specified in Rock Ridge Specification
|
||||
* Relocates a directory, as specified in Rock Ridge Specification
|
||||
* (see IEEE P1282, section 4.1.5). This is needed when the number of levels
|
||||
* on a directory hierarchy exceeds 8, or the length of a path is higher
|
||||
* than 255 characters, as specified in ECMA-119, section 6.8.2.1
|
||||
* than 255 characters, as specified in ECMA-119, section 6.8.2.1
|
||||
*/
|
||||
static
|
||||
int reparent(Ecma119Node *child, Ecma119Node *parent)
|
||||
@ -743,7 +755,7 @@ int reparent(Ecma119Node *child, Ecma119Node *parent)
|
||||
/* add the child to its new parent */
|
||||
child->parent = parent;
|
||||
parent->info.dir->nchildren++;
|
||||
parent->info.dir->children = realloc(parent->info.dir->children,
|
||||
parent->info.dir->children = realloc(parent->info.dir->children,
|
||||
sizeof(void*) * parent->info.dir->nchildren);
|
||||
parent->info.dir->children[parent->info.dir->nchildren - 1] = child;
|
||||
return ISO_SUCCESS;
|
||||
@ -754,7 +766,7 @@ int reparent(Ecma119Node *child, Ecma119Node *parent)
|
||||
* - the depth is at most 8
|
||||
* - each path length is at most 255 characters
|
||||
* This restriction is imposed by ECMA-119 specification (ECMA-119, 6.8.2.1).
|
||||
*
|
||||
*
|
||||
* @param dir
|
||||
* Dir we are currently processing
|
||||
* @param level
|
||||
@ -778,9 +790,9 @@ int reorder_tree(Ecma119Image *img, Ecma119Node *dir, int level, int pathlen)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* we are appended to the root's children now, so there is no
|
||||
* need to recurse (the root will hit us again)
|
||||
* need to recurse (the root will hit us again)
|
||||
*/
|
||||
} else {
|
||||
size_t i;
|
||||
@ -831,7 +843,7 @@ int ecma119_tree_create(Ecma119Image *img)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* and we need to remangle the root directory, as the function
|
||||
* above could insert new directories into the root.
|
||||
* Note that recurse = 0, as we don't need to recurse.
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2007 Vreixo Formoso
|
||||
*
|
||||
* This file is part of the libisofs project; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2 as
|
||||
*
|
||||
* This file is part of the libisofs project; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation. See COPYING file for details.
|
||||
*/
|
||||
|
||||
@ -32,7 +32,7 @@ int get_iso1999_name(Ecma119Image *t, const char *str, char **fname)
|
||||
*fname = NULL;
|
||||
return ISO_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
if (!strcmp(t->input_charset, t->output_charset)) {
|
||||
/* no conversion needed */
|
||||
name = strdup(str);
|
||||
@ -50,14 +50,14 @@ int get_iso1999_name(Ecma119Image *t, const char *str, char **fname)
|
||||
name = strdup(str);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ISO 9660:1999 7.5.1 */
|
||||
if (strlen(name) > 207) {
|
||||
name[207] = '\0';
|
||||
}
|
||||
|
||||
|
||||
*fname = name;
|
||||
|
||||
|
||||
return ISO_SUCCESS;
|
||||
}
|
||||
|
||||
@ -118,11 +118,13 @@ int create_node(Ecma119Image *t, IsoNode *iso, Iso1999Node **node)
|
||||
|
||||
size = iso_stream_get_size(file->stream);
|
||||
if (size > (off_t)0xffffffff) {
|
||||
free(n);
|
||||
return iso_msg_submit(t->image->id, ISO_FILE_TOO_BIG, 0,
|
||||
char *ipath = iso_tree_get_node_path(iso);
|
||||
ret = iso_msg_submit(t->image->id, ISO_FILE_TOO_BIG, 0,
|
||||
"File \"%s\" can't be added to image because is "
|
||||
"greater than 4GB", iso->name);
|
||||
return 0;
|
||||
"greater than 4GB", ipath);
|
||||
free(n);
|
||||
free(ipath);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = iso_file_src_create(t, file, &src);
|
||||
@ -159,7 +161,7 @@ int create_node(Ecma119Image *t, IsoNode *iso, Iso1999Node **node)
|
||||
|
||||
/**
|
||||
* Create the low level ISO 9660:1999 tree from the high level ISO tree.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
* 1 success, 0 file ignored, < 0 error
|
||||
*/
|
||||
@ -185,10 +187,13 @@ int create_tree(Ecma119Image *t, IsoNode *iso, Iso1999Node **tree, int pathlen)
|
||||
|
||||
max_path = pathlen + 1 + (iso_name ? strlen(iso_name): 0);
|
||||
if (!t->allow_longer_paths && max_path > 255) {
|
||||
free(iso_name);
|
||||
return iso_msg_submit(t->image->id, ISO_FILE_IMGPATH_WRONG, 0,
|
||||
char *ipath = iso_tree_get_node_path(iso);
|
||||
ret = iso_msg_submit(t->image->id, ISO_FILE_IMGPATH_WRONG, 0,
|
||||
"File \"%s\" can't be added to ISO 9660:1999 tree, "
|
||||
"because its path length is larger than 255", iso->name);
|
||||
"because its path length is larger than 255", ipath);
|
||||
free(iso_name);
|
||||
free(ipath);
|
||||
return ret;
|
||||
}
|
||||
|
||||
switch (iso->type) {
|
||||
@ -230,16 +235,19 @@ int create_tree(Ecma119Image *t, IsoNode *iso, Iso1999Node **tree, int pathlen)
|
||||
} else {
|
||||
/* log and ignore */
|
||||
ret = iso_msg_submit(t->image->id, ISO_FILE_IGNORED, 0,
|
||||
"El-Torito catalog found on a image without El-Torito.",
|
||||
iso->name);
|
||||
"El-Torito catalog found on a image without El-Torito.");
|
||||
}
|
||||
break;
|
||||
case LIBISO_SYMLINK:
|
||||
case LIBISO_SPECIAL:
|
||||
ret = iso_msg_submit(t->image->id, ISO_FILE_IGNORED, 0,
|
||||
{
|
||||
char *ipath = iso_tree_get_node_path(iso);
|
||||
ret = iso_msg_submit(t->image->id, ISO_FILE_IGNORED, 0,
|
||||
"Can't add %s to ISO 9660:1999 tree. This kind of files "
|
||||
"can only be added to a Rock Ridget tree. Skipping.",
|
||||
iso->name);
|
||||
"can only be added to a Rock Ridget tree. Skipping.",
|
||||
ipath);
|
||||
free(ipath);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* should never happen */
|
||||
@ -269,15 +277,15 @@ cmp_node(const void *f1, const void *f2)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort the entries inside an ISO 9660:1999 directory, according to
|
||||
* ISO 9660:1999, 9.3
|
||||
* Sort the entries inside an ISO 9660:1999 directory, according to
|
||||
* ISO 9660:1999, 9.3
|
||||
*/
|
||||
static
|
||||
static
|
||||
void sort_tree(Iso1999Node *root)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
qsort(root->info.dir->children, root->info.dir->nchildren,
|
||||
qsort(root->info.dir->children, root->info.dir->nchildren,
|
||||
sizeof(void*), cmp_node);
|
||||
for (i = 0; i < root->info.dir->nchildren; i++) {
|
||||
Iso1999Node *child = root->info.dir->children[i];
|
||||
@ -297,9 +305,9 @@ int mangle_single_dir(Ecma119Image *img, Iso1999Node *dir)
|
||||
|
||||
nchildren = dir->info.dir->nchildren;
|
||||
children = dir->info.dir->children;
|
||||
|
||||
|
||||
/* a hash table will temporary hold the names, for fast searching */
|
||||
ret = iso_htable_create((nchildren * 100) / 80, iso_str_hash,
|
||||
ret = iso_htable_create((nchildren * 100) / 80, iso_str_hash,
|
||||
(compare_function_t)strcmp, &table);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
@ -320,7 +328,7 @@ int mangle_single_dir(Ecma119Image *img, Iso1999Node *dir)
|
||||
int digits = 1; /* characters to change per name */
|
||||
|
||||
/* first, find all child with same name */
|
||||
while (j + 1 < nchildren &&
|
||||
while (j + 1 < nchildren &&
|
||||
!cmp_node(children + i, children + j + 1)) {
|
||||
++j;
|
||||
}
|
||||
@ -330,7 +338,7 @@ int mangle_single_dir(Ecma119Image *img, Iso1999Node *dir)
|
||||
}
|
||||
|
||||
/*
|
||||
* A max of 7 characters is good enought, it allows handling up to
|
||||
* A max of 7 characters is good enought, it allows handling up to
|
||||
* 9,999,999 files with same name.
|
||||
*/
|
||||
while (digits < 8) {
|
||||
@ -345,7 +353,7 @@ int mangle_single_dir(Ecma119Image *img, Iso1999Node *dir)
|
||||
dot = strrchr(full_name, '.');
|
||||
if (dot != NULL && children[i]->type != ISO1999_DIR) {
|
||||
|
||||
/*
|
||||
/*
|
||||
* File (not dir) with extension.
|
||||
*/
|
||||
int extlen;
|
||||
@ -358,17 +366,17 @@ int mangle_single_dir(Ecma119Image *img, Iso1999Node *dir)
|
||||
if (max <= 0) {
|
||||
/* this can happen if extension is too long */
|
||||
if (extlen + max > 3) {
|
||||
/*
|
||||
/*
|
||||
* reduce extension len, to give name an extra char
|
||||
* note that max is negative or 0
|
||||
* note that max is negative or 0
|
||||
*/
|
||||
extlen = extlen + max - 1;
|
||||
ext[extlen] = '\0';
|
||||
max = 207 - extlen - 1 - digits;
|
||||
} else {
|
||||
/*
|
||||
/*
|
||||
* error, we don't support extensions < 3
|
||||
* This can't happen with current limit of digits.
|
||||
* This can't happen with current limit of digits.
|
||||
*/
|
||||
ret = ISO_ERROR;
|
||||
goto mangle_cleanup;
|
||||
@ -428,7 +436,7 @@ int mangle_single_dir(Ecma119Image *img, Iso1999Node *dir)
|
||||
children[k]->name = new;
|
||||
iso_htable_add(table, new, new);
|
||||
|
||||
/*
|
||||
/*
|
||||
* if we change a name we need to sort again children
|
||||
* at the end
|
||||
*/
|
||||
@ -459,7 +467,7 @@ int mangle_single_dir(Ecma119Image *img, Iso1999Node *dir)
|
||||
}
|
||||
|
||||
ret = ISO_SUCCESS;
|
||||
|
||||
|
||||
mangle_cleanup : ;
|
||||
iso_htable_destroy(table, NULL);
|
||||
return ret;
|
||||
@ -494,7 +502,7 @@ int iso1999_tree_create(Ecma119Image *t)
|
||||
{
|
||||
int ret;
|
||||
Iso1999Node *root;
|
||||
|
||||
|
||||
if (t == NULL) {
|
||||
return ISO_NULL_POINTER;
|
||||
}
|
||||
@ -507,7 +515,7 @@ int iso1999_tree_create(Ecma119Image *t)
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* the ISO 9660:1999 tree is stored in Ecma119Image target */
|
||||
t->iso1999_root = root;
|
||||
|
||||
@ -559,10 +567,10 @@ size_t calc_dir_size(Ecma119Image *t, Iso1999Node *dir)
|
||||
len += dirent_len;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* The size of a dir is always a multiple of block size, as we must add
|
||||
* the size of the unused space after the last directory record
|
||||
* The size of a dir is always a multiple of block size, as we must add
|
||||
* the size of the unused space after the last directory record
|
||||
* (ISO 9660:1999, 6.8.1.3)
|
||||
*/
|
||||
len = ROUND_UP(len, BLOCK_SIZE);
|
||||
@ -626,7 +634,7 @@ int iso1999_writer_compute_data_blocks(IsoImageWriter *writer)
|
||||
t = writer->target;
|
||||
|
||||
/* compute position of directories */
|
||||
iso_msg_debug(t->image->id,
|
||||
iso_msg_debug(t->image->id,
|
||||
"Computing position of ISO 9660:1999 dir structure");
|
||||
t->iso1999_ndirs = 0;
|
||||
calc_dir_pos(t, t->iso1999_root);
|
||||
@ -647,7 +655,7 @@ int iso1999_writer_compute_data_blocks(IsoImageWriter *writer)
|
||||
|
||||
/**
|
||||
* Write a single directory record (ISO 9660:1999, 9.1).
|
||||
*
|
||||
*
|
||||
* @param file_id
|
||||
* if >= 0, we use it instead of the filename (for "." and ".." entries).
|
||||
* @param len_fi
|
||||
@ -677,9 +685,9 @@ void write_one_dir_record(Ecma119Image *t, Iso1999Node *node, int file_id,
|
||||
len = iso_file_src_get_size(node->info.file);
|
||||
block = node->info.file->block;
|
||||
} else {
|
||||
/*
|
||||
* for nodes other than files and dirs, we set both
|
||||
* len and block to 0
|
||||
/*
|
||||
* for nodes other than files and dirs, we set both
|
||||
* len and block to 0
|
||||
*/
|
||||
len = 0;
|
||||
block = 0;
|
||||
@ -701,14 +709,14 @@ void write_one_dir_record(Ecma119Image *t, Iso1999Node *node, int file_id,
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the enhanced volume descriptor (ISO/IEC 9660:1999, 8.5)
|
||||
* Write the enhanced volume descriptor (ISO/IEC 9660:1999, 8.5)
|
||||
*/
|
||||
static
|
||||
int iso1999_writer_write_vol_desc(IsoImageWriter *writer)
|
||||
{
|
||||
IsoImage *image;
|
||||
Ecma119Image *t;
|
||||
|
||||
|
||||
/* The enhanced volume descriptor is like the sup vol desc */
|
||||
struct ecma119_sup_vol_desc vol;
|
||||
|
||||
@ -741,7 +749,7 @@ int iso1999_writer_write_vol_desc(IsoImageWriter *writer)
|
||||
|
||||
vol.vol_desc_type[0] = 2;
|
||||
memcpy(vol.std_identifier, "CD001", 5);
|
||||
|
||||
|
||||
/* descriptor version is 2 (ISO/IEC 9660:1999, 8.5.2) */
|
||||
vol.vol_desc_version[0] = 2;
|
||||
strncpy_pad((char*)vol.volume_id, vol_id, 32);
|
||||
@ -759,7 +767,7 @@ int iso1999_writer_write_vol_desc(IsoImageWriter *writer)
|
||||
strncpy_pad((char*)vol.vol_set_id, volset_id, 128);
|
||||
strncpy_pad((char*)vol.publisher_id, pub_id, 128);
|
||||
strncpy_pad((char*)vol.data_prep_id, data_id, 128);
|
||||
|
||||
|
||||
strncpy_pad((char*)vol.system_id, system_id, 32);
|
||||
|
||||
strncpy_pad((char*)vol.application_id, application_id, 128);
|
||||
@ -1000,7 +1008,7 @@ int iso1999_writer_create(Ecma119Image *target)
|
||||
writer->data = NULL;
|
||||
writer->target = target;
|
||||
|
||||
iso_msg_debug(target->image->id,
|
||||
iso_msg_debug(target->image->id,
|
||||
"Creating low level ISO 9660:1999 tree...");
|
||||
ret = iso1999_tree_create(target);
|
||||
if (ret < 0) {
|
||||
|
@ -1,9 +1,9 @@
|
||||
/*
|
||||
* Copyright (c) 2007 Vreixo Formoso
|
||||
* Copyright (c) 2007 Mario Danic
|
||||
*
|
||||
* This file is part of the libisofs project; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2 as
|
||||
*
|
||||
* This file is part of the libisofs project; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation. See COPYING file for details.
|
||||
*/
|
||||
|
||||
@ -47,7 +47,7 @@ int get_joliet_name(Ecma119Image *t, IsoNode *iso, uint16_t **name)
|
||||
*name = jname;
|
||||
return ISO_SUCCESS;
|
||||
} else {
|
||||
/*
|
||||
/*
|
||||
* only possible if mem error, as check for empty names is done
|
||||
* in public tree
|
||||
*/
|
||||
@ -112,10 +112,13 @@ int create_node(Ecma119Image *t, IsoNode *iso, JolietNode **node)
|
||||
|
||||
size = iso_stream_get_size(file->stream);
|
||||
if (size > (off_t)0xffffffff) {
|
||||
char *ipath = iso_tree_get_node_path(iso);
|
||||
free(joliet);
|
||||
return iso_msg_submit(t->image->id, ISO_FILE_TOO_BIG, 0,
|
||||
ret = iso_msg_submit(t->image->id, ISO_FILE_TOO_BIG, 0,
|
||||
"File \"%s\" can't be added to image because is "
|
||||
"greater than 4GB", iso->name);
|
||||
"greater than 4GB", ipath);
|
||||
free(ipath);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = iso_file_src_create(t, file, &src);
|
||||
@ -152,7 +155,7 @@ int create_node(Ecma119Image *t, IsoNode *iso, JolietNode **node)
|
||||
|
||||
/**
|
||||
* Create the low level Joliet tree from the high level ISO tree.
|
||||
*
|
||||
*
|
||||
* @return
|
||||
* 1 success, 0 file ignored, < 0 error
|
||||
*/
|
||||
@ -177,14 +180,17 @@ int create_tree(Ecma119Image *t, IsoNode *iso, JolietNode **tree, int pathlen)
|
||||
}
|
||||
max_path = pathlen + 1 + (jname ? ucslen(jname) * 2 : 0);
|
||||
if (!t->joliet_longer_paths && max_path > 240) {
|
||||
free(jname);
|
||||
char *ipath = iso_tree_get_node_path(iso);
|
||||
/*
|
||||
* Wow!! Joliet is even more restrictive than plain ISO-9660,
|
||||
* that allows up to 255 bytes!!
|
||||
*/
|
||||
return iso_msg_submit(t->image->id, ISO_FILE_IMGPATH_WRONG, 0,
|
||||
ret = iso_msg_submit(t->image->id, ISO_FILE_IMGPATH_WRONG, 0,
|
||||
"File \"%s\" can't be added to Joliet tree, because "
|
||||
"its path length is larger than 240", iso->name);
|
||||
"its path length is larger than 240", ipath);
|
||||
free(jname);
|
||||
free(ipath);
|
||||
return ret;
|
||||
}
|
||||
|
||||
switch (iso->type) {
|
||||
@ -226,15 +232,19 @@ int create_tree(Ecma119Image *t, IsoNode *iso, JolietNode **tree, int pathlen)
|
||||
} else {
|
||||
/* log and ignore */
|
||||
ret = iso_msg_submit(t->image->id, ISO_FILE_IGNORED, 0,
|
||||
"El-Torito catalog found on a image without El-Torito.",
|
||||
iso->name);
|
||||
"El-Torito catalog found on a image without El-Torito.");
|
||||
}
|
||||
break;
|
||||
case LIBISO_SYMLINK:
|
||||
case LIBISO_SPECIAL:
|
||||
ret = iso_msg_submit(t->image->id, ISO_FILE_IGNORED, 0,
|
||||
"Can't add %s to Joliet tree. This kind of files can only"
|
||||
" be added to a Rock Ridget tree. Skipping.", iso->name);
|
||||
{
|
||||
char *ipath = iso_tree_get_node_path(iso);
|
||||
ret = iso_msg_submit(t->image->id, ISO_FILE_IGNORED, 0,
|
||||
"Can't add %s to Joliet tree. %s can only be added to a "
|
||||
"Rock Ridget tree.", ipath, (iso->type == LIBISO_SYMLINK ?
|
||||
"Symlinks" : "Special files"));
|
||||
free(ipath);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* should never happen */
|
||||
@ -257,12 +267,12 @@ cmp_node(const void *f1, const void *f2)
|
||||
return ucscmp(f->name, g->name);
|
||||
}
|
||||
|
||||
static
|
||||
static
|
||||
void sort_tree(JolietNode *root)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
qsort(root->info.dir->children, root->info.dir->nchildren,
|
||||
qsort(root->info.dir->children, root->info.dir->nchildren,
|
||||
sizeof(void*), cmp_node);
|
||||
for (i = 0; i < root->info.dir->nchildren; i++) {
|
||||
JolietNode *child = root->info.dir->children[i];
|
||||
@ -287,23 +297,23 @@ int joliet_create_mangled_name(uint16_t *dest, uint16_t *src, int digits,
|
||||
uint16_t *ucsnumber;
|
||||
char fmt[16];
|
||||
char *nstr = alloca(digits + 1);
|
||||
|
||||
|
||||
sprintf(fmt, "%%0%dd", digits);
|
||||
sprintf(nstr, fmt, number);
|
||||
|
||||
|
||||
ret = str2ucs("ASCII", nstr, &ucsnumber);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* copy name */
|
||||
pos = ucslen(src);
|
||||
ucsncpy(dest, src, pos);
|
||||
|
||||
|
||||
/* copy number */
|
||||
ucsncpy(dest + pos, ucsnumber, digits);
|
||||
pos += digits;
|
||||
|
||||
|
||||
if (ext[0] != (uint16_t)0) {
|
||||
size_t extlen = ucslen(ext);
|
||||
dest[pos++] = (uint16_t)0x2E00; /* '.' in big endian UCS */
|
||||
@ -326,9 +336,9 @@ int mangle_single_dir(Ecma119Image *t, JolietNode *dir)
|
||||
|
||||
nchildren = dir->info.dir->nchildren;
|
||||
children = dir->info.dir->children;
|
||||
|
||||
|
||||
/* a hash table will temporary hold the names, for fast searching */
|
||||
ret = iso_htable_create((nchildren * 100) / 80, iso_str_hash,
|
||||
ret = iso_htable_create((nchildren * 100) / 80, iso_str_hash,
|
||||
(compare_function_t)ucscmp, &table);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
@ -349,7 +359,7 @@ int mangle_single_dir(Ecma119Image *t, JolietNode *dir)
|
||||
int digits = 1; /* characters to change per name */
|
||||
|
||||
/* first, find all child with same name */
|
||||
while (j + 1 < nchildren &&
|
||||
while (j + 1 < nchildren &&
|
||||
!cmp_node_name(children + i, children + j + 1)) {
|
||||
++j;
|
||||
}
|
||||
@ -359,7 +369,7 @@ int mangle_single_dir(Ecma119Image *t, JolietNode *dir)
|
||||
}
|
||||
|
||||
/*
|
||||
* A max of 7 characters is good enought, it allows handling up to
|
||||
* A max of 7 characters is good enought, it allows handling up to
|
||||
* 9,999,999 files with same name.
|
||||
*/
|
||||
while (digits < 8) {
|
||||
@ -374,7 +384,7 @@ int mangle_single_dir(Ecma119Image *t, JolietNode *dir)
|
||||
dot = ucsrchr(full_name, '.');
|
||||
if (dot != NULL && children[i]->type != JOLIET_DIR) {
|
||||
|
||||
/*
|
||||
/*
|
||||
* File (not dir) with extension
|
||||
*/
|
||||
int extlen;
|
||||
@ -387,17 +397,17 @@ int mangle_single_dir(Ecma119Image *t, JolietNode *dir)
|
||||
if (max <= 0) {
|
||||
/* this can happen if extension is too long */
|
||||
if (extlen + max > 3) {
|
||||
/*
|
||||
/*
|
||||
* reduce extension len, to give name an extra char
|
||||
* note that max is negative or 0
|
||||
* note that max is negative or 0
|
||||
*/
|
||||
extlen = extlen + max - 1;
|
||||
ext[extlen] = 0;
|
||||
max = 66 - extlen - 1 - digits;
|
||||
} else {
|
||||
/*
|
||||
/*
|
||||
* error, we don't support extensions < 3
|
||||
* This can't happen with current limit of digits.
|
||||
* This can't happen with current limit of digits.
|
||||
*/
|
||||
ret = ISO_ERROR;
|
||||
goto mangle_cleanup;
|
||||
@ -455,7 +465,7 @@ int mangle_single_dir(Ecma119Image *t, JolietNode *dir)
|
||||
children[k]->name = new;
|
||||
iso_htable_add(table, new, new);
|
||||
|
||||
/*
|
||||
/*
|
||||
* if we change a name we need to sort again children
|
||||
* at the end
|
||||
*/
|
||||
@ -486,7 +496,7 @@ int mangle_single_dir(Ecma119Image *t, JolietNode *dir)
|
||||
}
|
||||
|
||||
ret = ISO_SUCCESS;
|
||||
|
||||
|
||||
mangle_cleanup : ;
|
||||
iso_htable_destroy(table, NULL);
|
||||
return ret;
|
||||
@ -521,7 +531,7 @@ int joliet_tree_create(Ecma119Image *t)
|
||||
{
|
||||
int ret;
|
||||
JolietNode *root;
|
||||
|
||||
|
||||
if (t == NULL) {
|
||||
return ISO_NULL_POINTER;
|
||||
}
|
||||
@ -534,7 +544,7 @@ int joliet_tree_create(Ecma119Image *t)
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* the Joliet tree is stored in Ecma119Image target */
|
||||
t->joliet_root = root;
|
||||
|
||||
@ -590,10 +600,10 @@ size_t calc_dir_size(Ecma119Image *t, JolietNode *dir)
|
||||
len += dirent_len;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* The size of a dir is always a multiple of block size, as we must add
|
||||
* the size of the unused space after the last directory record
|
||||
* The size of a dir is always a multiple of block size, as we must add
|
||||
* the size of the unused space after the last directory record
|
||||
* (ECMA-119, 6.8.1.3)
|
||||
*/
|
||||
len = ROUND_UP(len, BLOCK_SIZE);
|
||||
@ -677,7 +687,7 @@ int joliet_writer_compute_data_blocks(IsoImageWriter *writer)
|
||||
/**
|
||||
* Write a single directory record for Joliet. It is like (ECMA-119, 9.1),
|
||||
* but file identifier is stored in UCS.
|
||||
*
|
||||
*
|
||||
* @param file_id
|
||||
* if >= 0, we use it instead of the filename (for "." and ".." entries).
|
||||
* @param len_fi
|
||||
@ -716,9 +726,9 @@ void write_one_dir_record(Ecma119Image *t, JolietNode *node, int file_id,
|
||||
len = iso_file_src_get_size(node->info.file);
|
||||
block = node->info.file->block;
|
||||
} else {
|
||||
/*
|
||||
* for nodes other than files and dirs, we set both
|
||||
* len and block to 0
|
||||
/*
|
||||
* for nodes other than files and dirs, we set both
|
||||
* len and block to 0
|
||||
*/
|
||||
len = 0;
|
||||
block = 0;
|
||||
@ -748,19 +758,19 @@ void ucsncpy_pad(uint16_t *dest, const uint16_t *src, size_t max)
|
||||
{
|
||||
char *cdest, *csrc;
|
||||
size_t len, i;
|
||||
|
||||
|
||||
cdest = (char*)dest;
|
||||
csrc = (char*)src;
|
||||
|
||||
|
||||
if (src != NULL) {
|
||||
len = MIN(ucslen(src) * 2, max);
|
||||
} else {
|
||||
len = 0;
|
||||
}
|
||||
|
||||
|
||||
for (i = 0; i < len; ++i)
|
||||
cdest[i] = csrc[i];
|
||||
|
||||
|
||||
for (i = len; i < max; i += 2) {
|
||||
cdest[i] = '\0';
|
||||
cdest[i + 1] = ' ';
|
||||
@ -805,7 +815,7 @@ int joliet_writer_write_vol_desc(IsoImageWriter *writer)
|
||||
memcpy(vol.std_identifier, "CD001", 5);
|
||||
vol.vol_desc_version[0] = 1;
|
||||
ucsncpy_pad((uint16_t*)vol.volume_id, vol_id, 32);
|
||||
|
||||
|
||||
/* make use of UCS-2 Level 3 */
|
||||
memcpy(vol.esc_sequences, "%/E", 3);
|
||||
|
||||
@ -822,7 +832,7 @@ int joliet_writer_write_vol_desc(IsoImageWriter *writer)
|
||||
ucsncpy_pad((uint16_t*)vol.vol_set_id, volset_id, 128);
|
||||
ucsncpy_pad((uint16_t*)vol.publisher_id, pub_id, 128);
|
||||
ucsncpy_pad((uint16_t*)vol.data_prep_id, data_id, 128);
|
||||
|
||||
|
||||
ucsncpy_pad((uint16_t*)vol.system_id, system_id, 32);
|
||||
|
||||
ucsncpy_pad((uint16_t*)vol.application_id, application_id, 128);
|
||||
|
Loading…
Reference in New Issue
Block a user