New options -setfattr, -setfattr_r, new find -exec setfattr

This commit is contained in:
2009-02-09 18:59:41 +00:00
parent fdabb16ad4
commit f4e0f103da
3 changed files with 84 additions and 39 deletions

View File

@ -8430,7 +8430,7 @@ int Xorriso_lsx_filev(struct XorrisO *xorriso, char *wd,
link_target[0]= 0;
rpt[0]= 0;
if((flag&5)==1) {
ret= Xorriso_local_getfacl(xorriso, path, &acl_text, 16);
Xorriso_local_getfacl(xorriso, path, &acl_text, 16);
ret= Xorriso_format_ls_l(xorriso, &stbuf, (acl_text != NULL) << 1);
Xorriso_local_getfacl(xorriso, path, &acl_text, 1 << 15);
if(ret<=0)
@ -11025,6 +11025,46 @@ int Xorriso_perform_acl_from_list(struct XorrisO *xorriso, char *file_path,
}
/*
@param flag bit0= do not perform setfattr but only check input
*/
int Xorriso_path_setfattr(struct XorrisO *xorriso, void *in_node, char *path,
char *name, size_t value_length, char *value, int flag)
{
int ret, hflag;
size_t num_attrs= 1;
char *name_pt;
hflag= 2;
name_pt= name;
if(name[0] == 0) {
sprintf(xorriso->info_text,
"-setfattr: Empty attribute name is not allowed");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
} else if(strcmp(name, "--remove-all") == 0) {
if(value[0]) {
sprintf(xorriso->info_text,
"-setfattr: Value is not empty with pseudo name --remove-all");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
num_attrs= 0;
hflag= 0;
} else if(name[0] == '-') {
name_pt++;
hflag|= 4;
} else if(name[0] == '=' || name[0] == '+') {
name_pt++;
}
if(flag & 1)
return(1);
ret= Xorriso_setfattr(xorriso, in_node, path,
num_attrs, &name_pt, &value_length, &value, hflag);
return(ret);
}
/* ---------------------------- Options API ------------------------ */
@ -13231,6 +13271,16 @@ not_enough_arguments:;
0);
} else if(strcmp(cpt, "getfattr")==0) {
Findjob_set_action_target(job, 26, NULL, 0);
} else if(strcmp(cpt, "setfattr")==0) {
if(i + 2 >= end_idx)
goto not_enough_arguments;
i+= 2;
/* check input */
ret= Xorriso_path_setfattr(xorriso, NULL, "", argv[i - 1],
strlen(argv[i]), argv[i], 1);
if(ret <= 0)
goto ex;
Findjob_set_action_text_2(job, 27, argv[i - 1], argv[i], 0);
} else {
sprintf(xorriso->info_text, "-find -exec: unknown action %s",
Text_shellsafe(argv[i], sfe, 0));
@ -13629,6 +13679,12 @@ int Xorriso_option_help(struct XorrisO *xorriso, int flag)
" -setfacl_list disk_path",
" Read output of getfacl from file disk_path. Set owner,",
" group and ACL of the iso_rr_path given by line \"# file:\".",
" -setfattr [-]name value iso_rr_path [***]",
" Set xattr pair with the given name to the given value, or",
" delete pair if name is prefixed with \"-\" and value is",
" an empty text.",
" -setfattr_r [-]name value iso_rr_path [***]",
" Like -setfattr but affecting all files below directories.",
" -alter_date type timestring iso_rr_path [***]",
" Alter the date entries of a file in the ISO image. type is",
" one of \"a\", \"m\", \"b\" for:",
@ -13647,7 +13703,7 @@ int Xorriso_option_help(struct XorrisO *xorriso, int flag)
" Action may be one of: echo, chown, chown_r, chgrp, chgrp_r",
" chmod, chmod_r, alter_date, alter_date_r, lsdl, compare,",
" rm, rm_r, compare, update, report_damage, report_lba,",
" getfacl, setfacl, getfattr, find.",
" getfacl, setfacl, getfattr, setfattr, find.",
" params are their arguments except iso_rr_path.",
" echo, lsdl, rm, rm_r, report_damage have no params at all.",
" -mkdir iso_rr_path [...]",
@ -15662,10 +15718,9 @@ ex:;
int Xorriso_option_setfattri(struct XorrisO *xorriso, char *name, char *value,
int argc, char **argv, int *idx, int flag)
{
int i, ret, was_failure= 0, end_idx, fret, hflag;
int i, ret, was_failure= 0, end_idx, fret;
int optc= 0;
size_t value_length, num_attrs= 1;
char **optv= NULL, *name_pt;
char **optv= NULL;
struct FindjoB *job= NULL;
struct stat dir_stbuf;
@ -15673,6 +15728,11 @@ int Xorriso_option_setfattri(struct XorrisO *xorriso, char *name, char *value,
&optv, 0);
if(ret <= 0)
goto ex;
/* check input */
ret= Xorriso_path_setfattr(xorriso, NULL, "", name, strlen(value), value, 1);
if(ret <= 0)
goto ex;
for(i= 0; i<optc; i++) {
if(flag&1) {
@ -15687,31 +15747,8 @@ int Xorriso_option_setfattri(struct XorrisO *xorriso, char *name, char *value,
Findjob_destroy(&job, 0);
} else {
ret= 1;
value_length= strlen(value);
hflag= 2;
name_pt= name;
if(name[0] == 0) {
sprintf(xorriso->info_text,
"-setfattr: Empty attribute name is not allowed");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
ret= 0; goto ex;
} else if(strcmp(name, "--remove-all") == 0) {
if(value[0]) {
sprintf(xorriso->info_text,
"-setfattr: Value is not empty with pseudo name --remove-all");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
ret= 0; goto ex;
}
num_attrs= 0;
hflag= 0;
} else if(name[0] == '-') {
name_pt++;
hflag|= 4;
} else if(name[0] == '=' || name[0] == '+') {
name_pt++;
}
ret= Xorriso_setfattr(xorriso, NULL, optv[i],
num_attrs, &name_pt, &value_length, &value, hflag);
ret= Xorriso_path_setfattr(xorriso, NULL, optv[i],
name, strlen(value), value, 0);
}
if(ret>0 && !xorriso->request_to_abort)
continue; /* regular bottom of loop */
@ -16917,6 +16954,10 @@ next_command:;
(*idx)+= 2;
ret= Xorriso_option_setfattri(xorriso, arg1, arg2, argc, argv, idx, 0);
} else if(strcmp(cmd,"setfattr_r")==0 || strcmp(cmd,"setfattr_ri")==0) {
(*idx)+= 2;
ret= Xorriso_option_setfattri(xorriso, arg1, arg2, argc, argv, idx, 1);
} else if(strcmp(cmd,"speed")==0) {
(*idx)++;
ret= Xorriso_option_speed(xorriso, arg1, 0);