New -lfa_flags mode restore_error=

This commit is contained in:
Thomas Schmitt 2024-08-25 16:37:57 +02:00
parent 1a5e356d85
commit a40a8a16e0
9 changed files with 102 additions and 24 deletions

View File

@ -1,7 +1,7 @@
/* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images.
Copyright 2007-2010 Thomas Schmitt, <scdbackup@gmx.net>
Copyright 2007-2024 Thomas Schmitt, <scdbackup@gmx.net>
Provided under GPL version 2 or later.
@ -1032,8 +1032,10 @@ int Permstack_pop(struct PermiteM **o, struct PermiteM *stopper,
}
}
if((m->immutable & 1) && !(flag & 4))
if((m->immutable & 1) && !(flag & 4)) {
/* It seems tradition here to just complain but to go on to return 1 */
Xorriso_set_local_chattr_i(xorriso, m->disk_path, 0);
}
m_next= m->next;
free(m->disk_path);

View File

@ -154,6 +154,7 @@ int Xorriso_new(struct XorrisO ** xorriso,char *progname, int flag)
}
m->lfa_flags_setting= m->lfa_flags_default;
m->lfa_restore_mask= ~((uint64_t) 0);
strcpy(m->lfa_restore_err_sev, "sorry");
m->do_aaip= 0;
if(m->lfa_flags_setting & 1)
m->do_aaip|= m->lfa_flags_setting & (15 << 11);

View File

@ -1395,6 +1395,22 @@ int Xorriso__to_upper(char *in, char *out, int out_size, int flag)
}
/* @return 0=truncated, 1=ok
*/
int Xorriso__to_lower(char *in, char *out, int out_size, int flag)
{
int i;
for(i= 0; i < out_size - 1 && in[i] != 0; i++)
if(isalpha(in[i]))
out[i]= tolower(in[i]);
else
out[i]= in[i];
out[i]= 0;
return(in[i] == 0);
}
/* @param flag bit0= prepend target_prefix even if source_prefix does not get
removed
*/

View File

@ -110,6 +110,7 @@ char *Xorriso__hide_mode_text(int hide_mode, int flag);
/* @return 0=truncated, 1=ok
*/
int Xorriso__to_upper(char *in, char *out, int out_size, int flag);
int Xorriso__to_lower(char *in, char *out, int out_size, int flag);
/* @param flag bit0= prepend target_prefix even if source_prefix does not get
removed

View File

@ -150,8 +150,8 @@ ex:;
/* Command -lfa_flags */
int Xorriso_option_lfa_flags(struct XorrisO *xorriso, char *mode, int flag)
{
int ret, lfa_flags_mem, l;
char *npt, *cpt, *mask= NULL;
int ret, lfa_flags_mem, l, sev, max_sev;
char *npt, *cpt, *mask= NULL, severity[20];
uint64_t mask_flags;
lfa_flags_mem= xorriso->lfa_flags_setting;
@ -208,15 +208,39 @@ int Xorriso_option_lfa_flags(struct XorrisO *xorriso, char *mode, int flag)
xorriso->lfa_restore_mask= mask_flags;
} else {
sprintf(xorriso->info_text,
"Cannot apply -lfa_flags restore_mask='%s'", mask);
"Cannot decode mask string of -lfa_flags restore_mask='%s'", mask);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
}
}
} else if(l >= 14 && strncmp(cpt, "restore_error=", 14) == 0) {
Xorriso__to_upper(cpt + 14, severity, (int) (int) sizeof(severity), 0);
if(strcmp(severity, "SILENT") != 0) {
ret= Xorriso__text_to_sev(severity, &sev, 0);
if(ret<=0) {
sprintf(xorriso->info_text,
"-lfa_flags restore_error=: Not a known severity name : ");
Text_shellsafe(cpt + 14, xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
return(ret);
}
Xorriso__text_to_sev("FATAL", &max_sev, 0);
if(sev > max_sev) {
sprintf(xorriso->info_text,
"-lfa_flags restore_error=: Severity curbed to maximum value 'FATAL': ");
Text_shellsafe(cpt + 14, xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0);
strcpy(severity, "FATAL");
}
}
Xorriso__to_lower(severity, xorriso->lfa_restore_err_sev,
sizeof(xorriso->lfa_restore_err_sev), 0);
} else if(l == 7 && strncmp(cpt, "default", l) == 0) {
xorriso->lfa_flags_setting= xorriso->lfa_flags_default;
xorriso->lfa_restore_mask= ~((uint64_t) 0);
} else {
sprintf(xorriso->info_text, "-lfa_flags: unknown mode in '%s'", mode);
sprintf(xorriso->info_text,
"-lfa_flags: unknown or mistyped mode in '%s'", mode);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
xorriso->lfa_flags_setting= lfa_flags_mem;
{ret= 0; goto ex;}

View File

@ -307,12 +307,18 @@ int Xorriso_report_chattr_outcome(struct XorrisO *xorriso, char *disk_path,
uint64_t lfa_flags, uint64_t lfa_mask,
int iso_ret, int os_errno, int flag)
{
int ret;
char msg[101], *lfa_text= NULL;
int ret, eps_ret, sev;
char msg[101], *lfa_text= NULL, severity[20];
if(iso_ret == 1)
{ret= 1; goto ex;}
if(strcmp(xorriso->lfa_restore_err_sev, "silent") == 0 ||
strcmp(xorriso->lfa_restore_err_sev, "all") == 0)
{ret= 2; goto ex;}
Xorriso__to_upper(xorriso->lfa_restore_err_sev, severity, sizeof(severity),
0);
ret= iso_util_encode_lfa_flags(lfa_flags & lfa_mask, &lfa_text, 0);
if(lfa_text == NULL)
lfa_text= strdup("-unknown-attributes-");
@ -321,8 +327,14 @@ int Xorriso_report_chattr_outcome(struct XorrisO *xorriso, char *disk_path,
if(lfa_text != NULL)
strcat(msg, lfa_text);
strcat(msg, "'");
/* Adjust severity to event_pt.
Number 0x7f000000 comes from libisofs.h, iso_error_get_severity */
Xorriso__text_to_sev(severity, &sev, 0);
iso_ret&= ~0x7f000000;
iso_ret|= sev;
Xorriso_report_iso_error(xorriso, disk_path, iso_ret, msg, os_errno,
"FAILURE", 2);
severity, 2);
ret= 0; goto ex;
} else if(iso_ret == 2) {
sprintf(xorriso->info_text,
@ -337,9 +349,14 @@ int Xorriso_report_chattr_outcome(struct XorrisO *xorriso, char *disk_path,
iso_ret, lfa_text);
}
Text_shellsafe(disk_path, xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE", 0);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, severity, 0);
ret= 0;
ex:;
if(ret == 0) {
eps_ret= Xorriso_eval_problem_status(xorriso, 0, 1);
if(eps_ret >= 0)
ret= 2;
}
if(lfa_text != NULL)
free(lfa_text);
return(ret);
@ -367,7 +384,7 @@ int Xorriso_set_local_chattr_i(struct XorrisO *xorriso, char *disk_path,
if(lfa_i == 0xffffffff)
lfa_i= Xorriso__lfa_bits("i");
ret= iso_local_set_lfa_flags(disk_path, lfa_i, max_bit, lfa_i, &os_errno, 0);
ret= iso_local_set_lfa_flags(disk_path, lfa_i, max_bit, lfa_i, &os_errno, 4);
ret= Xorriso_report_chattr_outcome(xorriso, disk_path, lfa_i, lfa_i,
ret, os_errno, 0);
if(ret <= 0)
@ -443,7 +460,7 @@ int Xorriso_early_chattr_CF(struct XorrisO *xorriso, IsoNode *node,
if(set_mask == 0)
return(4);
ret= iso_local_set_lfa_flags(disk_path, lfa_flags, max_bit, set_mask,
os_errno, 0);
os_errno, 4);
ret= Xorriso_report_chattr_outcome(xorriso, disk_path, lfa_flags, set_mask,
ret, *os_errno, 0);
if(ret <= 0)
@ -652,10 +669,7 @@ cannot_set_perm:;
if(xorriso->do_aaip & (1 << 12)) {
if(mask != 0) {
ret= iso_local_set_lfa_flags(disk_path, lfa_flags, max_bit, mask,
&os_errno, 0);
/* >>> Need adjustable graceful error handling */;
&os_errno, 4);
ret= Xorriso_report_chattr_outcome(xorriso, disk_path, lfa_flags,
mask, ret, os_errno, 0);
if(ret <= 0)
@ -1672,9 +1686,12 @@ int Xorriso_restore_disk_object(struct XorrisO *xorriso,
if(ret == 2)
{ret= 3; goto ex;}
}
if(first_part_node != NULL && !no_props)
Xorriso_restore_properties(xorriso, disk_path, first_part_node,
if(first_part_node != NULL && !no_props) {
ret= Xorriso_restore_properties(xorriso, disk_path, first_part_node,
!!(flag&64));
if(ret <= 0)
goto restoring_failed;
}
goto went_well;
}
@ -2304,8 +2321,10 @@ int Xorriso_restore(struct XorrisO *xorriso,
}
} else {
/* keep rwx for the owner, delay lfa_flags 'i' if present */
Xorriso_restore_implicit_properties(xorriso, disk_path, path,
ret= Xorriso_restore_implicit_properties(xorriso, disk_path, path,
img_path, 4);
if(ret <= 0)
goto ex;
}
new_dir_made= 1;
} else if((source_is_dir && !source_is_split)) {
@ -2342,7 +2361,12 @@ attach_source:;
}
if(new_dir_made && !(flag&64)) {
/* set timestamps which Permstack_pop() will not set */
Xorriso_restore_properties(xorriso, disk_path, node, 2);
ret= Xorriso_restore_properties(xorriso, disk_path, node, 2);
if(ret <= 0) {
hret= Xorriso_eval_problem_status(xorriso, ret, 1 | 2);
if(hret < 0)
goto ex;
}
}
} else {
if(dir_create || node_count) {

View File

@ -3783,7 +3783,9 @@ int Xorriso_status(struct XorrisO *xorriso, char *filter, FILE *fp, int flag)
if(!(is_default && no_defaults))
Xorriso_status_result(xorriso,filter,fp,flag&2);
is_default= (xorriso->lfa_flags_setting == xorriso->lfa_flags_default);
is_default= (xorriso->lfa_flags_setting == xorriso->lfa_flags_default) &&
(xorriso->lfa_restore_mask == ~((uint64_t) 0)) &&
strcmp(xorriso->lfa_restore_err_sev, "sorry") == 0;
strcpy(line, "-lfa_flags ");
if(xorriso->lfa_flags_setting & 1)
strcat(line, "on");
@ -3818,6 +3820,10 @@ int Xorriso_status(struct XorrisO *xorriso, char *filter, FILE *fp, int flag)
if(!(is_default && no_defaults))
Xorriso_status_result(xorriso, filter, fp, flag & 2);
sprintf(line, "-lfa_flags restore_error=%s\n", xorriso->lfa_restore_err_sev);
if(!(is_default && no_defaults))
Xorriso_status_result(xorriso, filter, fp, flag & 2);
strcpy(line, "-lfa_flags ");
if(xorriso->lfa_restore_mask == ~((uint64_t) 0)) {
strcat(line, "restore_mask=");

View File

@ -201,6 +201,10 @@ struct XorrisO { /* the global context of xorriso */
uint64_t lfa_restore_mask; /* At most the flag bits which are set here will
be restored when a file gets restored to disk
*/
char lfa_restore_err_sev[20]; /* Severity to use with error message due to
lfa restore problems. "silent" and "all"
suppress error messages.
*/
int do_md5; /* bit0= read MD5 array
bit1= write session MD5

View File

@ -1 +1 @@
#define Xorriso_timestamP "2024.08.18.153958"
#define Xorriso_timestamP "2024.08.25.143621"