Commit 025d6f2e authored by Thomas Schmitt's avatar Thomas Schmitt

New action estimate_size for -find and -findx

parent 65fdba88
......@@ -1087,6 +1087,7 @@ int Xorriso_findx_action(struct XorrisO *xorriso, struct FindjoB *job,
time_t date= 0;
mode_t mode_or= 0, mode_and= ~1;
char *target, *text_2, sfe[5*SfileadrL], *disk_prefix, iso_path[SfileadrL];
char *basename;
struct FindjoB *subjob;
struct stat stbuf;
......@@ -1167,6 +1168,16 @@ int Xorriso_findx_action(struct XorrisO *xorriso, struct FindjoB *job,
Xorriso_result(xorriso,0);
}
{ret= 1; goto ex;}
} else if(action == 40) { /* estimate_size */
basename= strrchr(abs_path, '/');
if(basename != NULL)
basename++;
else
basename= abs_path;
ret= lstat(abs_path, &stbuf);
if(ret != -1)
ret= Xorriso_estimate_file_size(xorriso, job, basename, stbuf.st_mode,
stbuf.st_size, 0);
} else {
sprintf(xorriso->result_line, "%s\n", Text_shellsafe(show_path, sfe, 0));
Xorriso_result(xorriso, 0);
......
......@@ -377,6 +377,8 @@ int Findjob_new(struct FindjoB **o, char *start_path, int flag)
if(m->start_path==NULL)
goto failed;
m->found_path= NULL;
m->estim_upper_size= 0;
m->estim_lower_size= 0;
m->subjob= NULL;
m->errmsg[0]= 0;
m->errn= 0;
......
......@@ -154,6 +154,7 @@ struct FindjoB {
37= mkisofs_r
38= sort_weight number
39= hide on|iso_rr|joliet|off
40= estimate_size
*/
int action;
int prune;
......@@ -167,6 +168,8 @@ struct FindjoB {
int type; /* see Xorriso_set_time flag, also used as weight */
time_t date;
char *found_path;
off_t estim_upper_size;
off_t estim_lower_size;
struct FindjoB *subjob;
/* Errors */
......
......@@ -1688,6 +1688,29 @@ int Xorriso_set_hidden(struct XorrisO *xorriso, void *in_node, char *path,
}
/* @param flag bit0= increase only upper estimation
*/
int Xorriso_estimate_file_size(struct XorrisO *xorriso, struct FindjoB *job,
char *basename, mode_t st_mode, off_t st_size, int flag)
{
off_t upper, lower, size;
lower = 3 * strlen(basename) + 34; /* >>> + minimum RR ? */
upper = 3 * strlen(basename) + 2048;
if(S_ISREG(st_mode)) {
size= ((st_size + (off_t) 2047) / (off_t) 2048) * (off_t) 2048;
lower+= size;
upper+= size;
} else if(S_ISDIR(st_mode)) {
upper+= 4096;
}
job->estim_upper_size+= upper;
if(!(flag & 1))
job->estim_lower_size+= lower;
return(1);
}
int Xorriso_cannot_create_iter(struct XorrisO *xorriso, int iso_error,int flag)
{
Xorriso_process_msg_queues(xorriso,0);
......@@ -1823,9 +1846,9 @@ int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
gid_t group= 0;
time_t date= 0;
mode_t mode_or= 0, mode_and= ~1;
char *target, *text_2, sfe[5*SfileadrL], *iso_prefix, md5[16];
char *target, *text_2, sfe[5*SfileadrL], *iso_prefix, md5[16], *basename;
struct FindjoB *subjob;
struct stat dir_stbuf;
struct stat dir_stbuf, stbuf;
action= Findjob_get_action_parms(job, &target, &text_2, &user, &group,
&mode_and, &mode_or, &type, &date, &subjob, 0);
......@@ -1937,6 +1960,16 @@ int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
iso_node_set_sort_weight(node, type);
} else if(action == 39) { /* hide */
Xorriso_set_hidden(xorriso, node, NULL, type, 0);
} else if(action == 40) { /* estimate_size */
basename= strrchr(abs_path, '/');
if(basename != NULL)
basename++;
else
basename= abs_path;
ret= Xorriso_fake_stbuf(xorriso, "", &stbuf, &node, 1);
if(ret > 0)
ret= Xorriso_estimate_file_size(xorriso, job, basename, stbuf.st_mode,
stbuf.st_size, 0);
} else { /* includes : 15 in_iso */
sprintf(xorriso->result_line, "%s\n", Text_shellsafe(show_path, sfe, 0));
Xorriso_result(xorriso, 0);
......
......@@ -1007,6 +1007,8 @@ not_enough_exec_arguments:;
goto sorry_ex;
}
Findjob_set_action_type(job, 39, type, 0);
} else if(strcmp(cpt, "estimate_size")==0) {
Findjob_set_action_target(job, 40, NULL, 0);
} else {
sprintf(xorriso->info_text, "-find -exec: unknown action %s",
Text_shellsafe(argv[i], sfe, 0));
......@@ -1041,6 +1043,15 @@ ex:;
xorriso->pacifier_count, 0, "", 1);
if(first_job->action == 35 && !(flag & 1))
Xorriso_report_md5_outcome(xorriso, first_job->target, 0);
if(first_job->action == 40) {
sprintf(xorriso->result_line,"Size lower : %lus\n",
(unsigned long) (job->estim_lower_size / (off_t) 2048));
Xorriso_result(xorriso,0);
sprintf(xorriso->result_line,"Size upper : %lus\n",
(unsigned long) ((job->estim_upper_size / (off_t) 2048) +
!!(job->estim_upper_size % 2048)));
Xorriso_result(xorriso,0);
}
if(access_acl_text != NULL)
free(access_acl_text);
if(default_acl_text != NULL)
......
......@@ -1712,6 +1712,12 @@ E.g.:
.br
-find / -disk_name *_secret -exec hide on
.br
\fBestimate_size\fR
prints a lower and an upper estimation of the number of blocks which the
found files together will occupy in the emering ISO image.
This does not account for the superblock,
for the directories in the -find path, or for image padding.
.br
\fBfind\fR
performs another run of -find on the matching file address.
It accepts the same params as -find, except iso_rr_path.
......
No preview for this file type
......@@ -2077,6 +2077,12 @@ E.g.:
@*
-find / -disk_name *_secret -exec hide on
@*
@item estimate_size
prints a lower and an upper estimation of the number of blocks which the
found files together will occupy in the emering ISO image.
This does not account for the superblock,
for the directories in the -find path, or for image padding.
@*
@item find
performs another run of -find on the matching file address.
It accepts the same params as -find, except iso_rr_path.
......
#define Xorriso_timestamP "2010.12.02.063209"
#define Xorriso_timestamP "2010.12.02.111029"
......@@ -552,5 +552,9 @@ int Xorriso_preparer_string(struct XorrisO *xorriso, char xorriso_id[129],
int Xorriso_jigdo_interpreter(struct XorrisO *xorriso, char *aspect, char *arg,
int flag);
int Xorriso_estimate_file_size(struct XorrisO *xorriso, struct FindjoB *job,
char *basename, mode_t st_mode, off_t st_size, int flag);
#endif /* Xorrisoburn_includeD */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment