New -find and -findx action list_extattr
This commit is contained in:
@ -840,6 +840,185 @@ ex:;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@param flag bit0= with mode "e" : Use echo -e encoding but
|
||||
do not put out commands and quotation marks.
|
||||
Rather apply double backslash.
|
||||
*/
|
||||
int Xorriso_append_extattr_comp(struct XorrisO *xorriso,
|
||||
char *comp, size_t comp_len,
|
||||
char *mode, int flag)
|
||||
{
|
||||
int ret;
|
||||
char *line, *wpt, *bsl = NULL;
|
||||
unsigned char *upt, *uval;
|
||||
|
||||
line= xorriso->result_line;
|
||||
uval= (unsigned char *) comp;
|
||||
|
||||
if(*mode == 'q') {
|
||||
Text_shellsafe(comp, line, 1);
|
||||
} else if(*mode == 'e' || mode[0] == 0) {
|
||||
for(upt= uval; (size_t) (upt - uval) < comp_len; upt++)
|
||||
if(*upt <= 037 || *upt >= 0177)
|
||||
break;
|
||||
if((size_t) (upt - uval) < comp_len || (flag & 1)) {
|
||||
/* Use "$(echo -e '\0xyz')" */;
|
||||
if(!(flag & 1))
|
||||
strcat(line, "\"$(echo -e '");
|
||||
wpt= line + strlen(line);
|
||||
for(upt= uval; (size_t) (upt - uval) < comp_len; upt++) {
|
||||
if(*upt <= 037 || *upt >= 0177 || *upt == '\\' || *upt == '\'') {
|
||||
if(flag & 1)
|
||||
*(wpt++)= '\\';
|
||||
sprintf((char *) wpt, "\\0%-3.3o", *upt);
|
||||
wpt+= strlen(wpt);
|
||||
} else {
|
||||
*(wpt++)= *upt;
|
||||
}
|
||||
}
|
||||
*wpt= 0;
|
||||
if(!(flag & 1))
|
||||
strcpy(wpt, "')\"");
|
||||
} else {
|
||||
Text_shellsafe(comp, line, 1);
|
||||
}
|
||||
} else if(*mode == 'b') {
|
||||
ret= Sfile_bsl_encoder(&bsl, comp, comp_len, 8);
|
||||
if(ret <= 0)
|
||||
{ret= -1; goto ex;}
|
||||
strcat(line, bsl);
|
||||
free(bsl);
|
||||
bsl= NULL;
|
||||
} else if(*mode == 'r') {
|
||||
strcat(line, comp);
|
||||
}
|
||||
ret= 1;
|
||||
ex:;
|
||||
if(bsl != NULL)
|
||||
free(bsl);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@param flag bit1= path is disk_path
|
||||
bit3= do not ignore eventual non-user attributes.
|
||||
bit5= in case of symbolic link on disk: inquire link target
|
||||
*/
|
||||
int Xorriso_list_extattr(struct XorrisO *xorriso, void *in_node, char *path,
|
||||
char *show_path, char *mode, int flag)
|
||||
{
|
||||
int ret= 1, i, bsl_mem;
|
||||
size_t num_attrs= 0, *value_lengths= NULL;
|
||||
char **names= NULL, **values= NULL, *cpt, *space_pt, *name_pt, *path_pt;
|
||||
char *line;
|
||||
unsigned char *upt, *uval;
|
||||
|
||||
line= xorriso->result_line;
|
||||
ret= Xorriso_get_attrs(xorriso, in_node, path, &num_attrs, &names,
|
||||
&value_lengths, &values, flag & (2 | 8 | 32));
|
||||
if(ret <= 0)
|
||||
goto ex;
|
||||
if(flag & 64) {
|
||||
ret= (num_attrs > 0);
|
||||
goto ex;
|
||||
}
|
||||
if(num_attrs == 0)
|
||||
{ret= 2; goto ex;}
|
||||
|
||||
strcpy(line, "n=");
|
||||
path_pt= show_path + (show_path[0] == '/');
|
||||
if(path_pt[0] == 0)
|
||||
path_pt= ".";
|
||||
ret= Xorriso_append_extattr_comp(xorriso, path_pt, strlen(path_pt), mode, 0);
|
||||
if(ret <= 0)
|
||||
goto ex;
|
||||
strcat(line, "\n");
|
||||
Xorriso_result(xorriso, 0);
|
||||
for(i= 0; i < (int) num_attrs; i++) {
|
||||
line[0]= 0;
|
||||
uval= (unsigned char *) values[i];
|
||||
|
||||
if(strlen(names[i]) + value_lengths[i] >= SfileadrL) {
|
||||
sprintf(line,
|
||||
"echo 'OMITTED: Oversized: name %d bytes, value %d bytes in file '\"$n\" >&2\n",
|
||||
(int) strlen(names[i]), (int) value_lengths[i]);
|
||||
Xorriso_result(xorriso, 0);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Form: $c space name value $n */
|
||||
|
||||
/* Split namespace from name */
|
||||
cpt= strchr(names[i], '.');
|
||||
if(cpt == NULL) {
|
||||
space_pt= "user";
|
||||
name_pt= names[i];
|
||||
} else {
|
||||
*cpt= 0;
|
||||
space_pt= names[i];
|
||||
name_pt= cpt + 1;
|
||||
}
|
||||
|
||||
/* FreeBSD setextattr cannot set 0-bytes */
|
||||
for(upt= uval; (size_t) (upt - uval) < value_lengths[i]; upt++)
|
||||
if(*upt == 0
|
||||
)
|
||||
break;
|
||||
if((size_t) (upt - uval) < value_lengths[i]) {
|
||||
strcpy(line, "echo 'OMITTED: Value contains 0-bytes : space \"'\"");
|
||||
Xorriso_append_extattr_comp(xorriso, space_pt, strlen(space_pt), "e", 1);
|
||||
if(ret <= 0)
|
||||
goto ex;
|
||||
strcat(line, "\"'\" , name \"'\"");
|
||||
Xorriso_append_extattr_comp(xorriso, name_pt, strlen(name_pt), "e", 1);
|
||||
if(ret <= 0)
|
||||
goto ex;
|
||||
strcat(line, "\"'\" in file '\"");
|
||||
Xorriso_append_extattr_comp(xorriso, path_pt, strlen(path_pt), "e", 1);
|
||||
strcat(line, "\" >&2\n");
|
||||
|
||||
/* temporarily disable -backslash_codes with result output */
|
||||
bsl_mem= xorriso->bsl_interpretation;
|
||||
xorriso->bsl_interpretation= 0;
|
||||
Xorriso_result(xorriso, 0);
|
||||
xorriso->bsl_interpretation= bsl_mem;
|
||||
strcpy(line, "# ");
|
||||
}
|
||||
|
||||
strcat(line, "$c ");
|
||||
ret= Xorriso_append_extattr_comp(xorriso, space_pt, strlen(space_pt),
|
||||
mode, 0);
|
||||
if(ret <= 0)
|
||||
goto ex;
|
||||
strcat(line, " ");
|
||||
ret= Xorriso_append_extattr_comp(xorriso,name_pt, strlen(name_pt), mode, 0);
|
||||
if(ret <= 0)
|
||||
goto ex;
|
||||
strcat(line, " ");
|
||||
ret= Xorriso_append_extattr_comp(xorriso, values[i], value_lengths[i],
|
||||
mode, 0);
|
||||
if(ret <= 0)
|
||||
goto ex;
|
||||
strcat(line, " \"$n\"\n");
|
||||
|
||||
/* temporarily disable -backslash_codes with result output */
|
||||
bsl_mem= xorriso->bsl_interpretation;
|
||||
xorriso->bsl_interpretation= 0;
|
||||
Xorriso_result(xorriso, 0);
|
||||
xorriso->bsl_interpretation= bsl_mem;
|
||||
}
|
||||
strcpy(line, "\n");
|
||||
Xorriso_result(xorriso, 0);
|
||||
ret= 1;
|
||||
ex:;
|
||||
Xorriso_get_attrs(xorriso, in_node, path, &num_attrs, &names,
|
||||
&value_lengths, &values, 1 << 15);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@param flag
|
||||
Bitfield for control purposes
|
||||
|
Reference in New Issue
Block a user