Made HFS creator, type, blessing persistent in AAIP isofs.hx isofs.hb

This commit is contained in:
2012-06-08 07:09:30 +00:00
parent 396fe7db8a
commit f8f39c322f
9 changed files with 384 additions and 208 deletions

View File

@ -2414,6 +2414,8 @@ int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
struct stat dir_stbuf, stbuf;
void *xinfo;
struct iso_hfsplus_xinfo_data *hfsplus_xinfo;
size_t value_length;
char *value;
action= Findjob_get_action_parms(job, &target, &text_2, &user, &group,
&mode_and, &mode_or, &type, &date, &subjob, 0);
@ -2593,6 +2595,33 @@ int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
Xorriso_result(xorriso, 0);
} else if(ret == 0)
ret= 1;
} else if(action == 49) {
/* internal: update creator, type, and blessings from persistent isofs.* */
ret= Xorriso_get_attr_value(xorriso, node, show_path, "isofs.hx",
&value_length, &value, 0);
if(ret < 0)
return(ret);
if(ret > 0 && value_length >= 10) {
ret= Xorriso_hfsplus_file_creator_type(xorriso, show_path, (void *) node,
value + 2, value + 6, 4);
free(value);
if(ret <= 0)
return(ret);
}
ret= Xorriso_get_attr_value(xorriso, node, show_path, "isofs.hb",
&value_length, &value, 0);
if(ret < 0)
return(ret);
if(ret > 0 && value_length >= 1) {
bless_code[0]= value[0];
bless_code[1]= 0;
ret= Xorriso_hfsplus_bless(xorriso, show_path, (void *) node,
bless_code, 0);
if(ret <= 0)
return(ret);
}
ret= 1;
} else { /* includes : 15 in_iso */
Text_shellsafe(show_path, xorriso->result_line, 0);
strcat(xorriso->result_line, "\n");
@ -3543,8 +3572,92 @@ set_error:;
}
/* flag bit0= in case of error talk of "overwrite" rather than "remove"
*/
static int Xorriso_remove_hfsplus_crtp(struct XorrisO *xorriso, IsoNode *node,
char *path, int flag)
{
int ret;
char *msg, buf[10], *bufpt;
size_t l;
static char *name= "isofs.hx";
ret= iso_node_remove_xinfo(node, iso_hfsplus_xinfo_func);
Xorriso_process_msg_queues(xorriso, 0);
if(ret < 0) {
if(flag & 1)
msg= "Cannot overwrite HFS+ creator and type of ISO node";
else
msg= "Cannot remove HFS+ creator and type of ISO node";
Xorriso_report_iso_error(xorriso, path, ret, msg, 0, "FAILURE", 1);
return(0);
}
/* Delete isofs.hx attribute */
bufpt= buf;
/* >>> ??? check whether there is isofs.hx attached ? */;
ret= Xorriso_setfattr(xorriso, node, path,
(size_t) 1, &name, &l, &bufpt, 4 | 8);
return(ret);
}
static int Xorriso_set_hfsplus_crtp(struct XorrisO *xorriso, IsoNode *node,
char *path, char *creator, char *hfs_type,
int flag)
{
struct iso_hfsplus_xinfo_data *hfs_data= NULL;
char buf[10], *bufpt;
size_t l;
int ret;
static char *name= "isofs.hx";
/* Register as non-persistent xinfo */
hfs_data= iso_hfsplus_xinfo_new(0);
if(hfs_data == NULL) {
Xorriso_no_malloc_memory(xorriso, NULL, 0);
return(-1);
}
memcpy(hfs_data->creator_code, creator, 4);
memcpy(hfs_data->type_code, hfs_type, 4);
ret= iso_node_add_xinfo(node, iso_hfsplus_xinfo_func, (void *) hfs_data);
Xorriso_process_msg_queues(xorriso, 0);
if(ret < 0) {
Xorriso_report_iso_error(xorriso, path, ret,
"Cannot attach HFS+ creator and type to ISO node", 0, "FAILURE", 1);
goto failure;
} else if(ret == 0) {
strcat(xorriso->info_text,
"Programm error: iso_node_add_xinfo refuses to attach HFS+ creator and type");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
goto failure;
}
/* Register as persistent attribute isofs.hx */
bufpt= buf;
l= 10;
buf[0]= 1;
buf[1]= 0;
memcpy(buf + 2, creator, 4);
memcpy(buf + 6, hfs_type, 4);
ret= Xorriso_setfattr(xorriso, node, path,
(size_t) 1, &name, &l, &bufpt, 2 | 8);
if(ret <= 0)
goto failure;
Xorriso_set_change_pending(xorriso, 0);
return(1);
failure:
if(hfs_data != NULL)
iso_hfsplus_xinfo_func(hfs_data, 1);
return(0);
}
/* @param flag bit0= only check creator and hfs_type for compliance.
bit1= with bit0: check for search rather than for setting
bit2= copy 2 times 4 bytes without any check
*/
int Xorriso_hfsplus_file_creator_type(struct XorrisO *xorriso, char *path,
void *in_node,
@ -3552,7 +3665,6 @@ int Xorriso_hfsplus_file_creator_type(struct XorrisO *xorriso, char *path,
{
int ret;
IsoNode *node;
struct iso_hfsplus_xinfo_data *hfs_data= NULL;
if(in_node == NULL && !(flag * 1)) {
ret= Xorriso_node_from_path(xorriso, NULL, path, &node, 0);
@ -3560,11 +3672,13 @@ int Xorriso_hfsplus_file_creator_type(struct XorrisO *xorriso, char *path,
return(ret);
} else
node= (IsoNode *) in_node;
if((creator[0] == 0 && hfs_type[0] == 0) ||
if(flag & 4) {
;
} else if((creator[0] == 0 && hfs_type[0] == 0) ||
strcmp(creator, "--delete") == 0) {
if(flag & 2) {
strcpy(xorriso->info_text,
"HFS+ file creator code for deletion shall be used for searching");
"Attempt to use HFS+ file pseudo-creator '--delete' for searching");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
strcpy(xorriso->info_text,
"Suitable are strings of length 4 or length 1");
@ -3573,14 +3687,9 @@ int Xorriso_hfsplus_file_creator_type(struct XorrisO *xorriso, char *path,
}
if(flag & 1)
return(1);
ret= iso_node_remove_xinfo(node, iso_hfsplus_xinfo_func);
Xorriso_process_msg_queues(xorriso, 0);
if(ret < 0) {
Xorriso_report_iso_error(xorriso, path, ret,
"Cannot remove HFS+ creator and type of ISO node",
0, "FAILURE", 1);
goto failure;
}
ret= Xorriso_remove_hfsplus_crtp(xorriso, node, path, 0);
if(ret < 0)
return(ret);
return(1);
} else if((strlen(creator) != 4 && !(strlen(creator) == 1 &&
(flag & 3) == 3)) ||
@ -3599,43 +3708,16 @@ int Xorriso_hfsplus_file_creator_type(struct XorrisO *xorriso, char *path,
if(flag & 1)
return(1);
hfs_data= iso_hfsplus_xinfo_new(0);
if(hfs_data == NULL) {
Xorriso_no_malloc_memory(xorriso, NULL, 0);
return(-1);
}
memcpy(hfs_data->creator_code, creator, 4);
memcpy(hfs_data->type_code, hfs_type, 4);
ret= iso_node_remove_xinfo(node, iso_hfsplus_xinfo_func);
Xorriso_process_msg_queues(xorriso, 0);
if(ret < 0) {
Xorriso_report_iso_error(xorriso, path, ret,
"Cannot overwrite HFS+ creator and type of ISO node",
0, "FAILURE", 1);
goto failure;
}
ret= iso_node_add_xinfo(node, iso_hfsplus_xinfo_func, (void *) hfs_data);
Xorriso_process_msg_queues(xorriso, 0);
if(ret < 0) {
Xorriso_report_iso_error(xorriso, path, ret,
"Cannot attach HFS+ creator and type to ISO node", 0, "FAILURE", 1);
goto failure;
} else if(ret == 0) {
strcat(xorriso->info_text,
"Programm error: iso_node_add_xinfo refuses to attach HFS+ creator and type");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
goto failure;
}
Xorriso_set_change_pending(xorriso, 0);
ret= Xorriso_remove_hfsplus_crtp(xorriso, node, path, 1);
if(ret <= 0)
return(ret);
ret= Xorriso_set_hfsplus_crtp(xorriso, node, path, creator, hfs_type, 0);
if(ret <= 0)
return(ret);
return(1);
failure:
if(hfs_data != NULL)
iso_hfsplus_xinfo_func(hfs_data, 1);
return(0);
}
/*
@param node
If node is NULL and path is empty, then the blessing will be
@ -3652,31 +3734,39 @@ failure:
int Xorriso_hfsplus_bless(struct XorrisO *xorriso, char *path,
void *in_node, char *blessing, int flag)
{
int ret;
IsoNode *node;
int ret, bless_max;
IsoNode *node, **blessed_nodes;
IsoImage *volume= NULL;
enum IsoHfsplusBlessings bless_code = ISO_HFSPLUS_BLESS_MAX; /* = invalid */
char *hb = "";
size_t l= 0;
static char *name= "isofs.hb";
if(strcmp(blessing, "ppc_bootdir") == 0 ||
strcmp(blessing, "p") == 0 || strcmp(blessing, "P") == 0)
strcmp(blessing, "p") == 0 || strcmp(blessing, "P") == 0) {
bless_code= ISO_HFSPLUS_BLESS_PPC_BOOTDIR;
else if(strcmp(blessing, "intel_bootfile") == 0 ||
strcmp(blessing, "i") == 0 || strcmp(blessing, "I") == 0)
hb= "p";
} else if(strcmp(blessing, "intel_bootfile") == 0 ||
strcmp(blessing, "i") == 0 || strcmp(blessing, "I") == 0) {
bless_code= ISO_HFSPLUS_BLESS_INTEL_BOOTFILE;
else if(strcmp(blessing, "show_folder") == 0 ||
strcmp(blessing, "s") == 0 || strcmp(blessing, "S") == 0)
hb= "i";
} else if(strcmp(blessing, "show_folder") == 0 ||
strcmp(blessing, "s") == 0 || strcmp(blessing, "S") == 0) {
bless_code= ISO_HFSPLUS_BLESS_SHOWFOLDER;
else if(strcmp(blessing, "os9_folder") == 0 ||
strcmp(blessing, "9") == 0)
hb= "s";
} else if(strcmp(blessing, "os9_folder") == 0 ||
strcmp(blessing, "9") == 0) {
bless_code= ISO_HFSPLUS_BLESS_OS9_FOLDER;
else if(strcmp(blessing, "osx_folder") == 0 ||
strcmp(blessing, "x") == 0 || strcmp(blessing, "X") == 0)
hb= "9";
} else if(strcmp(blessing, "osx_folder") == 0 ||
strcmp(blessing, "x") == 0 || strcmp(blessing, "X") == 0) {
bless_code= ISO_HFSPLUS_BLESS_OSX_FOLDER;
else if((flag & 8) && (flag & 4) &&
hb= "x";
} else if((flag & 8) && (flag & 4) &&
(strcmp(blessing, "any") == 0 ||
strcmp(blessing, "a") == 0 || strcmp(blessing, "A") == 0))
strcmp(blessing, "a") == 0 || strcmp(blessing, "A") == 0)) {
bless_code= ISO_HFSPLUS_BLESS_MAX;
else {
} else {
sprintf(xorriso->info_text, "Unknown blessing type ");
Text_shellsafe(blessing, xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
@ -3695,6 +3785,24 @@ int Xorriso_hfsplus_bless(struct XorrisO *xorriso, char *path,
if(ret <= 0)
return(ret);
/* Remove persistent bless mark from current bearer */
ret= iso_image_hfsplus_get_blessed(volume, &blessed_nodes, &bless_max, 0);
Xorriso_process_msg_queues(xorriso, 0);
if(ret < 0) {
Xorriso_report_iso_error(xorriso, "", ret,
"Error when trying to bless a file",
0, "FAILURE", 1);
return(0);
}
if((int) bless_code < bless_max) {
if(blessed_nodes[(int) bless_code] != NULL) {
ret= Xorriso_setfattr(xorriso, node, path,
(size_t) 1, &name, &l, &hb, 4 | 8);
if(ret <= 0)
return(ret);
}
}
ret= iso_image_hfsplus_bless(volume, bless_code, node, flag & 3);
Xorriso_process_msg_queues(xorriso, 0);
if(ret == 0 && path[0]) {
@ -3717,6 +3825,12 @@ int Xorriso_hfsplus_bless(struct XorrisO *xorriso, char *path,
0, "FAILURE", 1);
return(0);
}
/* Attach persistent bless mark to node */
l= 1;
ret= Xorriso_setfattr(xorriso, node, path, (size_t) 1, &name, &l, &hb, 2 | 8);
if(ret <= 0)
return(ret);
Xorriso_set_change_pending(xorriso, 0);
return(1);
}