New -find test -size

This commit is contained in:
Thomas Schmitt 2022-11-10 10:51:21 +01:00
parent a28040df18
commit 008620e19c
10 changed files with 246 additions and 52 deletions

View File

@ -1,7 +1,7 @@
/* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images.
Copyright 2007-2016 Thomas Schmitt, <scdbackup@gmx.net>
Copyright 2007-2022 Thomas Schmitt, <scdbackup@gmx.net>
Provided under GPL version 2 or later.
@ -895,6 +895,28 @@ int Findjob_set_num_filter(struct FindjoB *o, int test_type,
}
int Findjob_set_size_filter(struct FindjoB *o, int test_type,
off_t num1, int num2, int flag)
{
struct ExprtesT *t;
int ret;
ret= Findjob_default_and(o, 0);
if(ret <= 0)
return(ret);
t= o->cursor->test;
t->test_type= test_type;
t->arg1= calloc(sizeof(off_t), 1);
t->arg2= calloc(sizeof(int), 1);
if(t->arg1 == NULL || t->arg2 == NULL)
return(-1);
*((off_t *) t->arg1)= num1;
*((int *) t->arg2)= num2;
return(1);
}
int Findjob_set_lba_range(struct FindjoB *o, int start_lba, int count,
int flag)
{

View File

@ -1,7 +1,7 @@
/* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images.
Copyright 2007-2016 Thomas Schmitt, <scdbackup@gmx.net>
Copyright 2007-2022 Thomas Schmitt, <scdbackup@gmx.net>
Provided under GPL version 2 or later.
@ -55,6 +55,8 @@ struct ExprtesT {
24= -name_limit_blocker int *arg1
25= -maxdepth int *arg1
26= -mindepth int *arg1
27= -size off_t *arg1 int *arg2 (0=test for equal, -1=smaller, 1=larger,
-2=smaller_or_equal , 2=larger_or_equal)
*/
int test_type;
@ -245,6 +247,9 @@ int Findjob_set_commit_filter_2(struct FindjoB *o, int flag);
int Findjob_set_num_filter(struct FindjoB *o, int test_type,
int num1, int num2, int flag);
int Findjob_set_size_filter(struct FindjoB *o, int test_type,
off_t num1, int num2, int flag);
int Findjob_set_lba_range(struct FindjoB *o, int start_lba, int count,
int flag);

View File

@ -3054,12 +3054,12 @@ return:
3 = immediate decision : does match
*/
{
int value=0, ret, start_lba, end_lba, bless_idx;
int value=0, ret, start_lba, end_lba, bless_idx, size_mode;
int lba_count, *file_end_lbas= NULL, *file_start_lbas= NULL, i, mask;
void *arg1, *arg2;
char ft, *decision, md5[16], bless_code[17];
regmatch_t name_match;
off_t damage_start, damage_end, size, *section_sizes= NULL;
off_t damage_start, damage_end, size, *section_sizes= NULL, size_arg;
void *xinfo_dummy;
IsoNode *node;
IsoStream *stream;
@ -3314,6 +3314,30 @@ return:
break; case 26: /* -mindepth */
value= (ftest->boss->depth >= *((int *) arg1));
break; case 27: /* -size */
size_arg= *((off_t *) arg1);
size_mode= *((int *) arg2);
ret= Xorriso__get_file_size(node, &size, 0);
if(ret <= 0) {
if(ret < 0)
Xorriso_process_msg_queues(xorriso, 0);
value= 0;
goto ex;
}
if(size_mode == 0) {
value= (size == size_arg);
} else if(size_mode == 1) {
value= (size > size_arg);
} else if(size_mode == 2) {
value= (size >= size_arg);
} else if(size_mode == -1) {
value= (size < size_arg);
} else if(size_mode == -2) {
value= (size <= size_arg);
} else {
value= 0;
}
break; default:
/* >>> complain about unknown test type */;

View File

@ -1,7 +1,7 @@
/* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images.
Copyright 2007-2019 Thomas Schmitt, <scdbackup@gmx.net>
Copyright 2007-2022 Thomas Schmitt, <scdbackup@gmx.net>
Provided under GPL version 2 or later.
@ -2207,6 +2207,18 @@ ex:;
}
/* @return 1= size is valid , 0= not a regular file , -1 = error
*/
int Xorriso__get_file_size(IsoNode *node, off_t *size, int flag)
{
*size= 0;
if(!LIBISO_ISREG(node))
return(0);
*size= iso_file_get_size((IsoFile *) node);
return(1);
}
int Xorriso__start_end_lbas(IsoNode *node,
int *lba_count, int **start_lbas, int **end_lbas,
off_t **section_sizes, off_t *size, int flag)

View File

@ -1,7 +1,7 @@
/* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images.
Copyright 2007-2016 Thomas Schmitt, <scdbackup@gmx.net>
Copyright 2007-2022 Thomas Schmitt, <scdbackup@gmx.net>
Provided under GPL version 2 or later.
@ -71,6 +71,8 @@ int Xorriso_obtain_pattern_files_i(
int *filec, char **filev, int count_limit, off_t *mem,
int *dive_count, int flag);
int Xorriso__get_file_size(IsoNode *node, off_t *size, int flag);
int Xorriso__start_end_lbas(IsoNode *node,
int *lba_count, int **start_lbas, int **end_lbas,
off_t **section_sizes, off_t *size, int flag);

View File

@ -1,7 +1,7 @@
/* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images.
Copyright 2007-2021 Thomas Schmitt, <scdbackup@gmx.net>
Copyright 2007-2022 Thomas Schmitt, <scdbackup@gmx.net>
Provided under GPL version 2 or later.
@ -836,11 +836,12 @@ 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, disk_path, name_space;
int list_extattr_head= 0, bsl_mem, disk_path, name_space, prefix_code;
struct FindjoB *job, *first_job= NULL, *new_job;
char *start_path, *path= NULL, *cpt, *other_path_start= NULL, *cd_pt;
char *access_acl_text= NULL, *default_acl_text= NULL, *list_extattr_mode;
char *arg1_pt, *namept;
char *arg1_pt, *namept, *suffix_pt, *value_pt, size_text[40];
off_t size_value, suffix_factor= 1;
struct stat dir_stbuf;
uid_t user= 0;
@ -1121,6 +1122,59 @@ not_enough_arguments:;
count, 0, 0);
if(ret <= 0)
goto ex;
} else if(strcmp(argv[i], "-size") == 0) {
if(i + 1 >= end_idx)
goto not_enough_arguments;
i++;
if(strlen(argv[i]) >= sizeof(size_text) - 1) {
sprintf(xorriso->info_text,
"-findi: Number text after -size is much too long");
goto sorry_ex;
}
strcpy(size_text, argv[i]);
value_pt= size_text;
prefix_code= 0;
if(*value_pt == 0)
goto size_value_bad;
if(*value_pt == '-') {
prefix_code= -1;
value_pt++;
} else if(*value_pt == '+') {
prefix_code= 1;
value_pt++;
}
if(*value_pt == 0)
goto size_value_bad;
if(*value_pt == '=') {
prefix_code*= 2;
value_pt++;
}
if(*value_pt == 0) {
size_value_bad:;
sprintf(xorriso->info_text,
"-findi: Number text after -size is not suitable");
}
/* Convert "find -size" suffix to Scanf_io_size suffix */
suffix_pt= value_pt + strlen(value_pt) - 1;
if(*suffix_pt == 'b' || *suffix_pt == 'B') {
*suffix_pt= 'd'; /* 512 bytes */
} else if(*suffix_pt == 'c' || *suffix_pt == 'C') {
*suffix_pt= 0; /* 1 byte */
} else if(*suffix_pt == 'w'|| *suffix_pt == 'W') {
*suffix_pt= 0; /* 2 byte */
suffix_factor= 2;
} else if(*suffix_pt >= '0' && *suffix_pt <= '9') {
suffix_pt++;
*suffix_pt= 'd'; /* 512 bytes */
*(suffix_pt + 1)= 0;
}
size_value= (off_t) Scanf_io_size(value_pt, 1) * (off_t) suffix_factor;
if(size_value < 0)
goto size_value_bad;
ret= Findjob_set_size_filter(job, 27, size_value, prefix_code, 0);
if(ret <= 0)
goto ex;
} else if(strcmp(argv[i], "-exec")==0) {
if(i+1>=end_idx) {
not_enough_exec_arguments:;
@ -2140,7 +2194,7 @@ int Xorriso_option_help(struct XorrisO *xorriso, int flag)
" -lba_range start count, -damaged, -has_acl, -has_xattr,",
" -has_aaip, -has_filter, -has_md5, -has_any_xattr,",
" -has_hfs_crtp, -has_hfs_bless, -bad_outname,",
" -name_limit_blocker, -maxdepth, -mindepth,",
" -name_limit_blocker, -maxdepth, -mindepth, -size,",
" -prune, -decision yes|no, -true, -false",
" Operators: -not, -or, -and, -sub, (, -subend, ),",
" -if, -then, -elseif, -else, -endif",

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.5.5, Oct 06, 2022"
.TH XORRISO 1 "Version 1.5.5, Nov 09, 2022"
.\" Please adjust this date whenever revising the manpage.
.\"
.\" Some roff macros, for reference:
@ -2027,6 +2027,33 @@ and "Xotic" which matches what is not matched by the other types.
.br
Only the first letter is interpreted. E.g.: \-find / \-type d
.br
\fB\-size\fR [+-][=]number[cwbdksmg] :
Matches files with matching relation to the given size number.
.br
The prefix defines the desired relation:
.br
No prefix or prefix "=" means: File must have exactly the given size.
.br
Prefix "+" means: File must be larger than given size.
.br
Prefix "+=" means: File must be larger than or equal to given size limit.
.br
Prefix "\-" means: File must be smaller than given size limit.
.br
Prefix "\-=" means: File must be smaller than or equal to given size limit.
.br
Suffixes are peculiar to stay compatible with program "find":
.br
No suffix means blocks of 512 bytes, "c" means single bytes, "w" means 2 bytes,
"b" means 512 bytes.
The suffixes "k", "M", and "G" mean 1024, 1024k, and 1024M respectively.
As usual with xorriso, the suffixes "d" and "s" mean 512 and 2048 and all
suffixes are recognized as both, uppercase and lowercase letters.
.br
E.g. match files larger or equal 4 GiB:
.br
\-size +=4g
.br
\fB\-maxdepth\fR number :
Matches only files which are at most at the given depth level relative to
the iso_rr_path where \-find starts. That path itself is at depth 0, its

View File

@ -1745,6 +1745,27 @@ File: xorriso.info, Node: CmdFind, Next: Filter, Prev: Manip, Up: Commands
"pipe", "file", "link", "socket", "eltorito", and "Xotic"
which matches what is not matched by the other types.
Only the first letter is interpreted. E.g.: -find / -type d
-size [+-][=]number[cwbdksmg] :
Matches files with matching relation to the given size number.
The prefix defines the desired relation:
No prefix or prefix "=" means: File must have exactly the
given size.
Prefix "+" means: File must be larger than given size.
Prefix "+=" means: File must be larger than or equal to given
size limit.
Prefix "-" means: File must be smaller than given size limit.
Prefix "-=" means: File must be smaller than or equal to given
size limit.
Suffixes are peculiar to stay compatible with program "find":
No suffix means blocks of 512 bytes, "c" means single bytes,
"w" means 2 bytes, "b" means 512 bytes. The suffixes "k",
"M", and "G" mean 1024, 1024k, and 1024M respectively. As
usual with xorriso, the suffixes "d" and "s" mean 512 and 2048
and all suffixes are recognized as both, uppercase and
lowercase letters.
E.g. match files larger or equal 4 GiB:
-size +=4g
-maxdepth number :
Matches only files which are at most at the given depth level
relative to the iso_rr_path where -find starts. That path
@ -6222,44 +6243,44 @@ Node: Insert58208
Node: SetInsert70325
Node: Manip80442
Node: CmdFind90542
Node: Filter109471
Node: Writing114093
Node: SetWrite126348
Node: Bootable156200
Node: Jigdo184081
Node: Charset189084
Node: Exception192413
Node: DialogCtl198542
Node: Inquiry201144
Node: Navigate212402
Node: Verify221109
Node: Restore232258
Node: Emulation244466
Node: Scripting254922
Node: Frontend262705
Node: Examples272331
Node: ExDevices273509
Node: ExCreate274170
Node: ExDialog275470
Node: ExGrowing276741
Node: ExModifying277550
Node: ExBootable278060
Node: ExCharset278615
Node: ExPseudo279511
Node: ExCdrecord280438
Node: ExMkisofs280758
Node: ExGrowisofs282655
Node: ExException283808
Node: ExTime284266
Node: ExIncBackup284724
Node: ExRestore288750
Node: ExRecovery289696
Node: Files290268
Node: Environ291602
Node: Seealso292350
Node: Bugreport293067
Node: Legal293658
Node: CommandIdx294670
Node: ConceptIdx312568
Node: Filter110569
Node: Writing115191
Node: SetWrite127446
Node: Bootable157298
Node: Jigdo185179
Node: Charset190182
Node: Exception193511
Node: DialogCtl199640
Node: Inquiry202242
Node: Navigate213500
Node: Verify222207
Node: Restore233356
Node: Emulation245564
Node: Scripting256020
Node: Frontend263803
Node: Examples273429
Node: ExDevices274607
Node: ExCreate275268
Node: ExDialog276568
Node: ExGrowing277839
Node: ExModifying278648
Node: ExBootable279158
Node: ExCharset279713
Node: ExPseudo280609
Node: ExCdrecord281536
Node: ExMkisofs281856
Node: ExGrowisofs283753
Node: ExException284906
Node: ExTime285364
Node: ExIncBackup285822
Node: ExRestore289848
Node: ExRecovery290794
Node: Files291366
Node: Environ292700
Node: Seealso293448
Node: Bugreport294165
Node: Legal294756
Node: CommandIdx295768
Node: ConceptIdx313666

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.5.5, Oct 06, 2022"
@c man .TH XORRISO 1 "Version 1.5.5, Nov 09, 2022"
@c man .\" Please adjust this date whenever revising the manpage.
@c man .\"
@c man .\" Some roff macros, for reference:
@ -2429,6 +2429,33 @@ and "Xotic" which matches what is not matched by the other types.
@*
Only the first letter is interpreted. E.g.: -find / -type d
@*
@item -size [+-][=]number[cwbdksmg] :
Matches files with matching relation to the given size number.
@*
The prefix defines the desired relation:
@*
No prefix or prefix "=" means: File must have exactly the given size.
@*
Prefix "+" means: File must be larger than given size.
@*
Prefix "+=" means: File must be larger than or equal to given size limit.
@*
Prefix "-" means: File must be smaller than given size limit.
@*
Prefix "-=" means: File must be smaller than or equal to given size limit.
@*
Suffixes are peculiar to stay compatible with program "find":
@*
No suffix means blocks of 512 bytes, "c" means single bytes, "w" means 2 bytes,
"b" means 512 bytes.
The suffixes "k", "M", and "G" mean 1024, 1024k, and 1024M respectively.
As usual with xorriso, the suffixes "d" and "s" mean 512 and 2048 and all
suffixes are recognized as both, uppercase and lowercase letters.
@*
E.g. match files of 4 GiB or larger:
@*
-size +=4g
@*
@item -maxdepth number :
Matches only files which are at most at the given depth level relative to
the iso_rr_path where -find starts. That path itself is at depth 0, its

View File

@ -1 +1 @@
#define Xorriso_timestamP "2022.11.05.133746"
#define Xorriso_timestamP "2022.11.10.095102"