New commands -projid, -get_projid, -get_projid_r, -set_projid, -set_projid_r, -find test -has_projid, -find actions get_projid, set_projid, get_projid_minmax
This commit is contained in:
@ -401,6 +401,95 @@ int Xorriso_option_prog_help(struct XorrisO *xorriso, char *name, int flag)
|
||||
}
|
||||
|
||||
|
||||
/* Command -projid */
|
||||
int Xorriso_option_projid(struct XorrisO *xorriso, char *mode, int flag)
|
||||
{
|
||||
int ret, l;
|
||||
off_t from_low= 0, from_high= 0, to_low= 0, to_high= 0;
|
||||
char *npt, *cpt, errmsg[80];
|
||||
|
||||
npt= cpt= mode;
|
||||
for(; npt != NULL; cpt= npt + 1) {
|
||||
npt= strchr(cpt, ':');
|
||||
if(npt==NULL)
|
||||
l= strlen(cpt);
|
||||
else
|
||||
l= npt-cpt;
|
||||
if(l == 0)
|
||||
continue;
|
||||
if(l == 2 && strncmp(cpt, "on", l) == 0) {
|
||||
xorriso->do_aaip|= (1 << 17);
|
||||
} else if(l == 3 && strncmp(cpt, "off", l) == 0) {
|
||||
xorriso->do_aaip&= ~(1 << 17);
|
||||
} else if(l == 9 && strncmp(cpt, "restore_0", l) == 0) {
|
||||
xorriso->do_aaip|= (1 << 18);
|
||||
} else if(l == 9 && strncmp(cpt, "no_restore_0", l) == 0) {
|
||||
xorriso->do_aaip&= ~(1 << 18);
|
||||
} else if(l >= 4 && strncmp(cpt, "map+", 4) == 0) {
|
||||
if(xorriso->projid_mapper == NULL) {
|
||||
ret= Numbermapper_new(&(xorriso->projid_mapper),
|
||||
(off_t) 0, (off_t) 0xffffffff, 0);
|
||||
if(ret <= 0) {
|
||||
sprintf(xorriso->info_text, "-projid: Cannot create mapper object");
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
|
||||
{ret= 0; goto ex;}
|
||||
}
|
||||
}
|
||||
ret= Numbermapper_decode(xorriso->projid_mapper, cpt + 4,
|
||||
&from_low, &from_high, &to_low, &to_high,
|
||||
errmsg, 0);
|
||||
if(ret <= 0) {
|
||||
sprintf(xorriso->info_text, "-projid: map+ text unusable: %s", errmsg);
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
||||
{ret= 0; goto ex;}
|
||||
}
|
||||
ret= Numbermapper_add(xorriso->projid_mapper, from_low, from_high,
|
||||
to_low, to_high, 0);
|
||||
if(ret <= 0) {
|
||||
sprintf(xorriso->info_text, "-projid: Cannot create mapper entry");
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
|
||||
{ret= 0; goto ex;}
|
||||
}
|
||||
} else if(l > 9 && strncmp(cpt, "map_test=", 9) == 0) {
|
||||
strncpy(errmsg, cpt + 9, l - 9);
|
||||
errmsg[l - 9]= 0;
|
||||
ret= Sfile_text_to_off_t(errmsg, &from_low, 0);
|
||||
if(ret <= 0) {
|
||||
sprintf(xorriso->info_text,
|
||||
"-projid: map= text cannot be converted to a number: %s",
|
||||
errmsg);
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
||||
{ret= 0; goto ex;}
|
||||
}
|
||||
ret= Numbermapper_map(xorriso->projid_mapper, from_low, &to_low, 0);
|
||||
if(ret < 0) {
|
||||
sprintf(xorriso->info_text,
|
||||
"-projid: map=%s yields unexpected error", errmsg);
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
||||
{ret= 0; goto ex;}
|
||||
}
|
||||
sprintf(xorriso->result_line, "projid mapped: %lu -> %lu\n",
|
||||
from_low, to_low);
|
||||
Xorriso_result(xorriso, 0);
|
||||
} else if(l == 7 && strncmp(cpt, "default", l) == 0) {
|
||||
xorriso->do_aaip&= ~(3 << 17);
|
||||
Numbermapper_destroy(&(xorriso->projid_mapper), 0);
|
||||
} else {
|
||||
sprintf(xorriso->info_text,
|
||||
"-projid: unknown or mistyped mode in '%s'", mode);
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
|
||||
{ret= 0; goto ex;}
|
||||
}
|
||||
}
|
||||
ret= Xorriso_set_ignore_aclea(xorriso, 0);
|
||||
if(ret <= 0)
|
||||
goto ex;
|
||||
ret= 1;
|
||||
ex:
|
||||
return(ret);
|
||||
}
|
||||
|
||||
|
||||
/* Option -prompt */
|
||||
int Xorriso_option_prompt(struct XorrisO *xorriso, char *text, int flag)
|
||||
{
|
||||
@ -831,6 +920,71 @@ int Xorriso_option_session_log(struct XorrisO *xorriso, char *path, int flag)
|
||||
}
|
||||
|
||||
|
||||
/* Commands -set_projid alias -set_projidi
|
||||
-set_projid_r alias -set_projid_ri */
|
||||
/* @param flag bit0=recursive -set_projid_r
|
||||
*/
|
||||
int Xorriso_option_set_projid(struct XorrisO *xorriso, char *projid_text,
|
||||
int argc, char **argv, int *idx, int flag)
|
||||
{
|
||||
int i, ret, was_failure= 0, end_idx, fret;
|
||||
int optc= 0;
|
||||
uint32_t projid= 0;
|
||||
off_t num;
|
||||
char **optv= NULL;
|
||||
struct FindjoB *job= NULL;
|
||||
struct stat dir_stbuf;
|
||||
|
||||
ret= Xorriso_opt_args(xorriso, "-set_projid", argc, argv, *idx,
|
||||
&end_idx, &optc, &optv, 0);
|
||||
if(ret <= 0)
|
||||
goto ex;
|
||||
ret= Sfile_text_to_off_t(projid_text, &num, 0);
|
||||
if(ret <= 0) {
|
||||
bad_set_projid:;
|
||||
sprintf(xorriso->info_text,
|
||||
"-set_projid: project id number too large or too small");
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
|
||||
ret= 0; goto ex;
|
||||
}
|
||||
if(num < 0 || num > (off_t) 0xffffffff)
|
||||
goto bad_set_projid;
|
||||
projid= num;
|
||||
|
||||
for(i= 0; i < optc; i++) {
|
||||
if(flag & 1) {
|
||||
ret= Findjob_new(&job, optv[i], 0);
|
||||
if(ret <= 0) {
|
||||
Xorriso_no_findjob(xorriso, "-set_projid_r", 0);
|
||||
{ret= -1; goto ex;}
|
||||
}
|
||||
Findjob_set_action_chattr(job, 64, (uint64_t) projid, 0, 0);
|
||||
ret= Xorriso_findi(xorriso, job, NULL, (off_t) 0,
|
||||
NULL, optv[i], &dir_stbuf, 0, 0);
|
||||
Findjob_destroy(&job, 0);
|
||||
} else {
|
||||
ret= Xorriso_set_projid(xorriso, NULL, optv[i], projid, 0);
|
||||
}
|
||||
if(ret>0 && !xorriso->request_to_abort)
|
||||
continue; /* regular bottom of loop */
|
||||
was_failure= 1;
|
||||
fret= Xorriso_eval_problem_status(xorriso, ret, 1|2);
|
||||
if(fret>=0)
|
||||
continue;
|
||||
ret= 0; goto ex;
|
||||
}
|
||||
ret= 1;
|
||||
ex:;
|
||||
(*idx)= end_idx;
|
||||
Xorriso_opt_args(xorriso, "-set_projid", argc, argv, *idx, &end_idx,
|
||||
&optc, &optv, 256);
|
||||
Findjob_destroy(&job, 0);
|
||||
if(ret<=0)
|
||||
return(ret);
|
||||
return(!was_failure);
|
||||
}
|
||||
|
||||
|
||||
/* Option -setfacl_list alias -setfacl_listi */
|
||||
int Xorriso_option_setfacl_listi(struct XorrisO *xorriso, char *path, int flag)
|
||||
{
|
||||
|
Reference in New Issue
Block a user