New -find and -findx action list_extattr

This commit is contained in:
Thomas Schmitt 2011-08-25 19:00:46 +00:00
parent dc83e4dcf3
commit 8c98fb039d
10 changed files with 350 additions and 55 deletions

View File

@ -1212,6 +1212,8 @@ int Xorriso_findx_action(struct XorrisO *xorriso, struct FindjoB *job,
if(ret != -1)
ret= Xorriso_estimate_file_size(xorriso, job, basename, stbuf.st_mode,
stbuf.st_size, 0);
} else if(action == 44) { /* list_extattr */
ret= Xorriso_list_extattr(xorriso, NULL, abs_path, show_path, target, 2);
} else {
Text_shellsafe(show_path, xorriso->result_line, 0);
strcat(xorriso->result_line, "\n");

View File

@ -158,6 +158,7 @@ struct FindjoB {
41= update_merge disk_equiv
42= rm_merge
43= clear_merge
44= list_extattr
*/
int action;
int prune;

View File

@ -2543,6 +2543,9 @@ int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
}
} else if(action == 43) { /* clear_merge */
ret= Xorriso_mark_update_merge(xorriso, show_path, node, 2 | 4);
} else if(action == 44) { /* list_extattr */
ret= Xorriso_list_extattr(xorriso, (void *) node, show_path, show_path,
target, 0);
} else { /* includes : 15 in_iso */
Text_shellsafe(show_path, xorriso->result_line, 0);
strcat(xorriso->result_line, "\n");

View File

@ -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

View File

@ -650,9 +650,10 @@ int Xorriso_option_find(struct XorrisO *xorriso, int argc, char **argv,
int *idx, int flag)
{
int ret, i, end_idx, type= 0, action, deleter= 0, start_lba, count;
int list_extattr_head= 0, bsl_mem;
struct FindjoB *job, *first_job= NULL, *new_job;
char *start_path, *path= NULL, *cpt, *other_path_start= NULL;
char *access_acl_text= NULL, *default_acl_text= NULL;
char *start_path, *path= NULL, *cpt, *other_path_start= NULL, *cd_pt;
char *access_acl_text= NULL, *default_acl_text= NULL, *list_extattr_mode;
struct stat dir_stbuf;
uid_t user= 0;
@ -666,6 +667,7 @@ int Xorriso_option_find(struct XorrisO *xorriso, int argc, char **argv,
Xorriso_alloc_meM(other_path_start, char, SfileadrL);
start_path= ".";
list_extattr_mode= "e";
if(end_idx > *idx && start_path[0]!=0)
start_path= argv[*idx];
ret= Findjob_new(&first_job, start_path, 0);
@ -1050,6 +1052,13 @@ not_enough_exec_arguments:;
} else if(strcmp(cpt, "clear_merge")==0) {
Findjob_set_action_target(job, 43, NULL, 0);
xorriso->update_flags&= ~1; /* End update_merge mode for node adding */
} else if(strcmp(cpt, "list_extattr")==0) {
if(i+1>=end_idx)
goto not_enough_exec_arguments;
i++;
Findjob_set_action_target(job, 44, argv[i], 0);
list_extattr_head= 1;
list_extattr_mode= argv[i];
} else {
sprintf(xorriso->info_text, "-find -exec: unknown action ");
Text_shellsafe(argv[i], xorriso->info_text, 1);
@ -1063,6 +1072,33 @@ sorry_ex:;
{ret= 0; goto ex;}
}
}
if(list_extattr_head) {
sprintf(xorriso->result_line,
"# Output of xorriso %s action list_extattr\n",
(flag & 1) ? "-findx" : "-find");
Xorriso_result(xorriso, 0);
strcpy(xorriso->result_line, "cd ");
if(start_path[0] == '/')
strcat(xorriso->result_line, "/");
else {
cd_pt= (flag & 1) ? xorriso->wdx : xorriso->wdi;
if(cd_pt[0] == 0)
cd_pt= "/";
ret= Xorriso_append_extattr_comp(xorriso, cd_pt, strlen(cd_pt),
list_extattr_mode, 0);
if(ret <= 0)
goto ex;
}
strcat(xorriso->result_line, "\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;
sprintf(xorriso->result_line, "c=\"setextattr\"\n\n");
Xorriso_result(xorriso, 0);
}
if(flag&1)
ret= Xorriso_findx(xorriso, first_job, "", start_path, &dir_stbuf, 0, NULL,
0);
@ -1647,8 +1683,8 @@ int Xorriso_option_help(struct XorrisO *xorriso, int flag)
" chmod, chmod_r, alter_date, alter_date_r, lsdl, compare,",
" rm, rm_r, compare, update, report_damage, report_lba,",
" getfacl, setfacl, getfattr, setfattr, get_any_xattr,",
" get_md5, check_md5, make_md5, set_filter, show_stream,",
" mkisofs_r, hide, find.",
" list_extattr, get_md5, check_md5, make_md5,",
" set_filter, show_stream, mkisofs_r, hide, find.",
" params are their arguments except iso_rr_path.",
" -mkdir iso_rr_path [...]",
" Create empty directories if they do not exist yet.",

View File

@ -9,7 +9,7 @@
.\" First parameter, NAME, should be all caps
.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
.\" other parameters are allowed: see man(7), man(1)
.TH XORRISO 1 "Version 1.1.5, Aug 23, 2011"
.TH XORRISO 1 "Version 1.1.5, Aug 25, 2011"
.\" Please adjust this date whenever revising the manpage.
.\"
.\" Some roff macros, for reference:
@ -1757,6 +1757,22 @@ prints xattr name\-value pairs from any namespace
except ACL to the result channel. This is mostly for debugging of
namespace "isofs".
.br
\fBlist_extattr\fR mode
prints a script to the result channel, which would use FreeBSD command
setextattr to set the file's xattr name\-value pairs of user namespace.
Parameter mode controls the form of the output of names and values.
Default mode "e" prints harmless characters in shell quotation marks,
but represents texts with octal 001 to 037 and 0177 to 0377 by an embedded
echo \-e command.
Mode "q" prints any characters in shell quotation marks. This might not be
terminal\-safe but should work in script files.
Mode "r" uses no quotation marks. Not safe.
Mode "b" prints backslash encoding. Not suitable for shell parsing.
.br
E.g. \-exec list_extattr e \-\-
.br
Option \-backslash_codes does not affect the output.
.br
\fBget_md5\fR
prints the MD5 sum, if recorded, together with file path.
.br
@ -3316,6 +3332,13 @@ prints a lower and an upper estimation of the number of blocks which the
found files together will occupy in the emerging ISO image.
This does not account for the superblock,
for the directories in the \-findx path, or for image padding.
.br
\fBlist_extattr\fR mode
prints a script to the result channel, which would use FreeBSD command
setextattr to set the file's xattr name\-value pairs of user namespace.
See \-find for a description of parameter mode.
.br
E.g. \-exec list_extattr e \-\-
.TP
\fB\-compare\fR disk_path iso_rr_path
Compare attributes and eventual data file content of a fileobject in the

View File

@ -1576,6 +1576,20 @@ File: xorriso.info, Node: CmdFind, Next: Filter, Prev: Manip, Up: Options
prints xattr name-value pairs from any namespace except ACL
to the result channel. This is mostly for debugging of
namespace "isofs".
list_extattr mode
prints a script to the result channel, which would use
FreeBSD command setextattr to set the file's xattr name-value
pairs of user namespace. Parameter mode controls the form of
the output of names and values. Default mode "e" prints
harmless characters in shell quotation marks, but represents
texts with octal 001 to 037 and 0177 to 0377 by an embedded
echo -e command. Mode "q" prints any characters in shell
quotation marks. This might not be terminal-safe but should
work in script files. Mode "r" uses no quotation marks. Not
safe. Mode "b" prints backslash encoding. Not suitable for
shell parsing.
E.g. -exec list_extattr e -
Option -backslash_codes does not affect the output.
get_md5
prints the MD5 sum, if recorded, together with file path.
check_md5
@ -2912,6 +2926,12 @@ File: xorriso.info, Node: Navigate, Next: Verify, Prev: Inquiry, Up: Options
blocks which the found files together will occupy in the
emerging ISO image. This does not account for the superblock,
for the directories in the -findx path, or for image padding.
list_extattr mode
prints a script to the result channel, which would use
FreeBSD command setextattr to set the file's xattr name-value
pairs of user namespace. See -find for a description of
parameter mode.
E.g. -exec list_extattr e -
-compare disk_path iso_rr_path
Compare attributes and eventual data file content of a fileobject
@ -4262,9 +4282,9 @@ File: xorriso.info, Node: CommandIdx, Next: ConceptIdx, Prev: Legal, Up: Top
* -close_filter_list bans filter registration: Filter. (line 52)
* -commit writes pending ISO image: Writing. (line 13)
* -commit_eject writes and ejects: Writing. (line 40)
* -compare reports ISO/disk differences: Navigate. (line 140)
* -compare_l reports ISO/disk differences: Navigate. (line 158)
* -compare_r reports ISO/disk differences: Navigate. (line 153)
* -compare reports ISO/disk differences: Navigate. (line 146)
* -compare_l reports ISO/disk differences: Navigate. (line 164)
* -compare_r reports ISO/disk differences: Navigate. (line 159)
* -compliance controls standard compliance: SetWrite. (line 14)
* -copyright_file sets copyright file name: SetWrite. (line 154)
* -cp_clone copies ISO directory tree: Insert. (line 183)
@ -4402,8 +4422,8 @@ File: xorriso.info, Node: CommandIdx, Next: ConceptIdx, Prev: Legal, Up: Top
* -setfattr sets xattr in ISO image: Manip. (line 111)
* -setfattr_list sets xattr in ISO image: Manip. (line 127)
* -setfattr_r sets xattr in ISO image: Manip. (line 124)
* -show_stream shows data source and filters: Navigate. (line 163)
* -show_stream_r shows data source and filters: Navigate. (line 177)
* -show_stream shows data source and filters: Navigate. (line 169)
* -show_stream_r shows data source and filters: Navigate. (line 183)
* -signal_handling controls handling of system signals: Exception.
(line 69)
* -speed set write speed: SetWrite. (line 211)
@ -4509,8 +4529,8 @@ File: xorriso.info, Node: ConceptIdx, Prev: CommandIdx, Up: Top
* Filter, apply to file, -set_filter: Filter. (line 60)
* Filter, ban registration, -close_filter_list: Filter. (line 52)
* Filter, register, -external_filter: Filter. (line 20)
* Filter, show chain, -show_stream: Navigate. (line 163)
* Filter, show chains of tree, -show_stream_r: Navigate. (line 177)
* Filter, show chain, -show_stream: Navigate. (line 169)
* Filter, show chains of tree, -show_stream_r: Navigate. (line 183)
* Filter, unregister, -unregister_filter: Filter. (line 48)
* Filter, zisofs parameters, -zisofs: SetWrite. (line 199)
* Group, global in ISO image, -gid: SetWrite. (line 195)
@ -4660,9 +4680,9 @@ File: xorriso.info, Node: ConceptIdx, Prev: CommandIdx, Up: Top
* Tree, disk, traverse, -findx: Navigate. (line 106)
* Tree, ISO, traverse and alter, -find: CmdFind. (line 7)
* Verify, check blocks, -check_media: Verify. (line 21)
* Verify, compare ISO and disk file, -compare: Navigate. (line 140)
* Verify, compare ISO and disk tree, -compare_r: Navigate. (line 153)
* Verify, compare ISO and disk, -compare_l: Navigate. (line 158)
* Verify, compare ISO and disk file, -compare: Navigate. (line 146)
* Verify, compare ISO and disk tree, -compare_r: Navigate. (line 159)
* Verify, compare ISO and disk, -compare_l: Navigate. (line 164)
* Verify, file checksum, -check_md5: Verify. (line 147)
* Verify, file tree checksums, -check_md5_r: Verify. (line 163)
* Verify, preset -check_media, -check_media_defaults: Verify. (line 40)
@ -4709,43 +4729,43 @@ Node: Insert42438
Node: SetInsert52143
Node: Manip60711
Node: CmdFind69438
Node: Filter80700
Node: Writing85038
Node: SetWrite93031
Node: Bootable107077
Node: Jigdo120295
Node: Charset124541
Node: Exception127300
Node: DialogCtl133413
Node: Inquiry136000
Node: Navigate140844
Node: Verify148812
Node: Restore157477
Node: Emulation164382
Node: Scripting174185
Node: Frontend181195
Node: Examples182494
Node: ExDevices183665
Node: ExCreate184324
Node: ExDialog185598
Node: ExGrowing186860
Node: ExModifying187662
Node: ExBootable188163
Node: ExCharset188712
Node: ExPseudo189532
Node: ExCdrecord190430
Node: ExMkisofs190745
Node: ExGrowisofs192083
Node: ExException193218
Node: ExTime193672
Node: ExIncBackup194131
Node: ExRestore198055
Node: ExRecovery199013
Node: Files199581
Node: Seealso200879
Node: Bugreport201543
Node: Legal202124
Node: CommandIdx203054
Node: ConceptIdx218077
Node: Filter81543
Node: Writing85881
Node: SetWrite93874
Node: Bootable107920
Node: Jigdo121138
Node: Charset125384
Node: Exception128143
Node: DialogCtl134256
Node: Inquiry136843
Node: Navigate141687
Node: Verify149945
Node: Restore158610
Node: Emulation165515
Node: Scripting175318
Node: Frontend182328
Node: Examples183627
Node: ExDevices184798
Node: ExCreate185457
Node: ExDialog186731
Node: ExGrowing187993
Node: ExModifying188795
Node: ExBootable189296
Node: ExCharset189845
Node: ExPseudo190665
Node: ExCdrecord191563
Node: ExMkisofs191878
Node: ExGrowisofs193216
Node: ExException194351
Node: ExTime194805
Node: ExIncBackup195264
Node: ExRestore199188
Node: ExRecovery200146
Node: Files200714
Node: Seealso202012
Node: Bugreport202676
Node: Legal203257
Node: CommandIdx204187
Node: ConceptIdx219210

End Tag Table

View File

@ -50,7 +50,7 @@
@c man .\" First parameter, NAME, should be all caps
@c man .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection
@c man .\" other parameters are allowed: see man(7), man(1)
@c man .TH XORRISO 1 "Version 1.1.5, Aug 23, 2011"
@c man .TH XORRISO 1 "Version 1.1.5, Aug 25, 2011"
@c man .\" Please adjust this date whenever revising the manpage.
@c man .\"
@c man .\" Some roff macros, for reference:
@ -2132,6 +2132,22 @@ prints xattr name-value pairs from any namespace
except ACL to the result channel. This is mostly for debugging of
namespace "isofs".
@*
@item list_extattr mode
prints a script to the result channel, which would use FreeBSD command
setextattr to set the file's xattr name-value pairs of user namespace.
Parameter mode controls the form of the output of names and values.
Default mode "e" prints harmless characters in shell quotation marks,
but represents texts with octal 001 to 037 and 0177 to 0377 by an embedded
echo -e command.
Mode "q" prints any characters in shell quotation marks. This might not be
terminal-safe but should work in script files.
Mode "r" uses no quotation marks. Not safe.
Mode "b" prints backslash encoding. Not suitable for shell parsing.
@*
E.g. -exec list_extattr e --
@*
Option -backslash_codes does not affect the output.
@*
@item get_md5
prints the MD5 sum, if recorded, together with file path.
@*
@ -3927,6 +3943,13 @@ prints a lower and an upper estimation of the number of blocks which the
found files together will occupy in the emerging ISO image.
This does not account for the superblock,
for the directories in the -findx path, or for image padding.
@*
@item list_extattr mode
prints a script to the result channel, which would use FreeBSD command
setextattr to set the file's xattr name-value pairs of user namespace.
See -find for a description of parameter mode.
@*
E.g. -exec list_extattr e --
@end table
@c man .TP
@item -compare disk_path iso_rr_path

View File

@ -1 +1 @@
#define Xorriso_timestamP "2011.08.24.072854"
#define Xorriso_timestamP "2011.08.25.185950"

View File

@ -399,6 +399,14 @@ int Xorriso_getfacl(struct XorrisO *xorriso, void *node,
int Xorriso_getfattr(struct XorrisO *xorriso, void *in_node, char *path,
char **attr_text, int flag);
int Xorriso_list_extattr(struct XorrisO *xorriso, void *in_node, char *path,
char *show_path, char *mode, int flag);
int Xorriso_append_extattr_comp(struct XorrisO *xorriso,
char *comp, size_t comp_len,
char *mode, int flag);
/* Calls iso_image_set_ignore_aclea() according to xorriso->do_aaip */
int Xorriso_set_ignore_aclea(struct XorrisO *xorriso, int flag);