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:
2024-11-03 20:04:54 +01:00
parent 923bfa0be9
commit 32bfa95973
25 changed files with 1168 additions and 214 deletions

View File

@ -40,7 +40,7 @@
/* @param flag bit0= give directory x-permission where is r-permission
bit1= do not transfer ACL, xattr, file attribute flags
bit1= do not transfer ACL, xattr, lfa_flags, projid
bit2= record dev,inode (only if enabled by xorriso)
bit3= with bit0: pretend to have indeed a directory
bit5= transfer ACL or xattr from eventual link target
@ -50,7 +50,8 @@ int Xorriso_transfer_properties(struct XorrisO *xorriso, struct stat *stbuf,
{
mode_t mode;
int ret= 1, max_bit, os_errno;
uint64_t lfa_flags;
uint64_t lfa_flags= 0;
uint32_t projid= 0;
size_t num_attrs= 0, *value_lengths= NULL;
char **names= NULL, **values= NULL;
@ -75,7 +76,7 @@ int Xorriso_transfer_properties(struct XorrisO *xorriso, struct stat *stbuf,
iso_node_set_mtime(node, stbuf->st_mtime);
iso_node_set_ctime(node, stbuf->st_ctime);
if((xorriso->do_aaip & (1 | 4 | 2048)) && !(flag & 2)) {
if((xorriso->do_aaip & (1 | 4 | 2048 | (1 << 17))) && !(flag & 2)) {
ret= iso_local_get_attrs(disk_path, &num_attrs, &names, &value_lengths,
&values, ((xorriso->do_aaip & 1) && !(flag & 2))
| ((!(xorriso->do_aaip & 4)) << 2)
@ -104,11 +105,13 @@ int Xorriso_transfer_properties(struct XorrisO *xorriso, struct stat *stbuf,
if((xorriso->do_aaip & (1 << 15)) && ret >= 0 && lfa_flags == 0)
ret= 4;
if(ret < 0) {
Xorriso_process_msg_queues(xorriso, 0);
Xorriso_report_iso_error(xorriso, disk_path, ret,
"Error when obtaining file attribute flags",
os_errno, "FAILURE", 1 | 2);
ret= 0; goto ex;
if(ret != (int) ISO_LFA_NOT_ENABLED) {
Xorriso_process_msg_queues(xorriso, 0);
Xorriso_report_iso_error(xorriso, disk_path, ret,
"Error when obtaining file attribute flags",
os_errno, "FAILURE", 1 | 2);
ret= 0; goto ex;
}
} else if(ret == 1 || ret == 2) {
ret= iso_node_set_lfa_flags(node, lfa_flags, 0);
if(ret < 0) {
@ -120,6 +123,15 @@ int Xorriso_transfer_properties(struct XorrisO *xorriso, struct stat *stbuf,
}
}
}
if(xorriso->do_aaip & (1 << 17)) {
ret= Xorriso_get_projid(xorriso, NULL, disk_path, &projid,
(flag & 32) | 2);
if(ret <= 0)
goto ex;
ret= Xorriso_set_projid(xorriso, node, NULL, projid, 0);
if(ret <= 0)
goto ex;
}
}
if((flag & 4) && ((xorriso->do_aaip & 16) || !(xorriso->ino_behavior & 2))) {
@ -2712,6 +2724,7 @@ int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
uint64_t lfa_flags, chattr_flags;
int max_bit;
char *lfa_text= NULL;
uint32_t projid;
action= Findjob_get_action_parms(job, &target, &text_2, &user, &group,
&mode_and, &mode_or, &type, &date, &subjob,
@ -3044,6 +3057,23 @@ int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
ret= Xorriso_set_lfa_flags(xorriso, node, show_path, "",
chattr_flags, type, 1 | 4);
} else if(action == 63) { /* get_projid */
ret= Xorriso_get_projid(xorriso, node, NULL, &projid, 0);
if(ret > 0)
Xorriso_show_projid(xorriso, show_path, projid, 0);
} else if(action == 64) { /* set_projid */
ret= Xorriso_set_projid(xorriso, node, NULL, (uint32_t) chattr_flags, 0);
} else if(action == 65) { /* get_projid_minmax */
ret= Xorriso_get_projid(xorriso, node, NULL, &projid, 0);
if(ret > 0) {
if((off_t) projid < job->projid_low || job->projid_low == -1)
job->projid_low= projid;
if((off_t) projid > job->projid_high || job->projid_high == -1)
job->projid_high= projid;
}
} else { /* includes : 15 in_iso */
Xorriso_esc_filepath(xorriso, show_path, xorriso->result_line, 0);
strcat(xorriso->result_line, "\n");
@ -3117,6 +3147,7 @@ return:
off_t range_lba, end_lba, *file_end_lbas= NULL, *file_start_lbas= NULL;
off_t start_lba;
uint64_t lfa_flags, node_flags;
uint32_t projid;
void *arg1, *arg2;
char ft, *decision, md5[16], bless_code[17], *acl_text= NULL;
regmatch_t name_match;
@ -3456,6 +3487,21 @@ test_name:;
value= !!(node_flags & lfa_flags);
}
break; case 30: /* -has_projid uint64_t projid (in ->lfa_flags) */
lfa_flags= *((uint64_t *) ftest->arg1);
if(node == NULL) {
hflag= 2;
ret= Xorriso_get_projid(xorriso, NULL, path, &projid, hflag);
} else {
ret= Xorriso_get_projid(xorriso, node, path, &projid, 0);
}
if(ret <= 0) {
Xorriso_process_msg_queues(xorriso, 0);
value= 0;
goto ex;
}
value= (lfa_flags == (uint64_t) projid);
break; default:
/* >>> complain about unknown test type */;
@ -4846,18 +4892,29 @@ int Xorriso_set_lfa_flags(struct XorrisO *xorriso, void *in_node, char *path,
}
int Xorriso_remove_all_lfa_flags(struct XorrisO *xorriso, int flag)
int Xorriso_tree_remove_isofs_var(struct XorrisO *xorriso, char *isofs_name,
int flag)
{
int ret;
struct FindjoB *job= NULL;
struct stat dir_stbuf;
char name[40];
if(strlen(isofs_name) > 38 || strncmp(isofs_name, "isofs.", 6) != 0) {
Xorriso_msgs_submit(xorriso, 0,
"Program error: Bad name for Xorriso_tree_remove_isofs_var",
0, "FATAL", 0);
Xorriso_msgs_submit(xorriso, 0, isofs_name, 0, "FATAL", 0);
return(-1);
}
sprintf(name, "-%s", isofs_name);
ret= Findjob_new(&job, "/", 0);
if(ret<=0) {
Xorriso_no_findjob(xorriso, "xorriso", 0);
return(-1);
}
Findjob_set_action_text_2(job, 62, "-isofs.fa", "", 0);
Findjob_set_action_text_2(job, 62, name, "", 0);
ret= Xorriso_findi(xorriso, job, NULL, (off_t) 0, NULL, "/",
&dir_stbuf, 0, 0);
@ -4867,3 +4924,34 @@ int Xorriso_remove_all_lfa_flags(struct XorrisO *xorriso, int flag)
return(1);
}
/* @param in_node if not NULL: the node to manipulate
@path if in_node is NULL: path to node
in any case: path to report with errors
*/
int Xorriso_set_projid(struct XorrisO *xorriso, void *in_node, char *path,
uint32_t projid, int flag)
{
int ret;
IsoNode *node;
if(in_node != NULL) {
node= (IsoNode *) in_node;
} else {
ret= Xorriso_get_node_by_path(xorriso, path, NULL, &node, 0);
if(ret <= 0)
return(ret);
}
ret= iso_node_set_projid(node, projid, 0);
if(ret < 0) {
Xorriso_process_msg_queues(xorriso, 0);
Xorriso_report_iso_error(xorriso, path, ret,
"Error when setting XFS-style project id of ISO node",
0, "SORRY", 1);
return(-1);
}
Xorriso_set_change_pending(xorriso, 0);
return(1);
}