You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
libisoburn/xorriso/opts_p_z.c

2294 lines
67 KiB

/* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images.
Copyright 2007-2018 Thomas Schmitt, <scdbackup@gmx.net>
Provided under GPL version 2 or later.
This file contains the implementation of options -p* to -z* as mentioned
in man page or info file derived from xorriso.texi.
*/
#ifdef HAVE_CONFIG_H
#include "../config.h"
#endif
#include <ctype.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <time.h>
#include <errno.h>
#include "xorriso.h"
#include "xorriso_private.h"
#include "xorrisoburn.h"
/* Option -pacifier */
int Xorriso_option_pacifier(struct XorrisO *xorriso, char *style, int flag)
{
#define Xorriso_pacifier_min_intvL 0.1
#define Xorriso_pacifier_max_intvL 60.0
if(strcmp(style, "xorriso")==0 || strcmp(style, "default")==0)
xorriso->pacifier_style= 0;
else if(strcmp(style, "mkisofs")==0 || strcmp(style, "genisofs")==0 ||
strcmp(style, "genisoimage")==0 || strcmp(style, "xorrisofs")==0)
xorriso->pacifier_style= 1;
else if(strcmp(style, "cdrecord")==0 || strcmp(style, "cdrskin")==0 ||
strcmp(style, "wodim")==0 || strcmp(style, "xorrecord")==0)
xorriso->pacifier_style= 2;
else if(strncmp(style, "interval=", 9) == 0) {
sscanf(style + 9, "%lf", &(xorriso->pacifier_interval));
if(xorriso->pacifier_interval < Xorriso_pacifier_min_intvL) {
sprintf(xorriso->info_text,
"-pacifier: interval='%s' is too low. Min: %f",
style, Xorriso_pacifier_min_intvL);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0);
xorriso->pacifier_interval= Xorriso_pacifier_min_intvL;
} else if(xorriso->pacifier_interval > Xorriso_pacifier_max_intvL) {
sprintf(xorriso->info_text,
"-pacifier: interval='%s' is too high. Max: %f",
style, Xorriso_pacifier_max_intvL);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0);
xorriso->pacifier_interval= Xorriso_pacifier_max_intvL;
}
} else {
sprintf(xorriso->info_text, "-pacifier: unknown behavior code '%s'", style);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
return(1);
}
/* Option -padding */
int Xorriso_option_padding(struct XorrisO *xorriso, char *size, int flag)
{
double num;
if(strcmp(size, "included") == 0) {
xorriso->do_padding_by_libisofs= 1;
return(1);
} else if(strcmp(size, "excluded") == 0 || strcmp(size, "appended") == 0) {
xorriso->do_padding_by_libisofs= 0;
return(1);
} else if(size[0] < '0' || size[0] > '9') {
sprintf(xorriso->info_text, "-padding: unrecognized non-numerical mode ");
Text_shellsafe(size, xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
num= Scanf_io_size(size, 0);
if(num < 0 || num > 1024.0 * 1024.0 * 1024.0) {
sprintf(xorriso->info_text, "-padding: wrong size %.f (allowed: %.f - %.f)",
num, 0.0, 1024.0 * 1024.0 * 1024.0);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
xorriso->padding= num;
if(xorriso->padding/2048 != num/2048.0)
xorriso->padding++;
return(1);
}
/* Option -page */
int Xorriso_option_page(struct XorrisO *xorriso, int len, int width, int flag)
{
if(len<0 || width<=0) {
sprintf(xorriso->info_text,
"Improper numeric value of arguments of -page: %d %d",
len, width);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
xorriso->result_page_length= len;
xorriso->result_page_width= width;
return(1);
}
/* Option -paste_in */
int Xorriso_option_paste_in(struct XorrisO *xorriso, char *iso_rr_path,
char *disk_path, char *start, char *count, int flag)
{
int ret;
double num;
off_t startbyte, bytecount;
num= Scanf_io_size(start, 0);
if(num<0 || num > 1.0e18) { /* 10^18 = 10^3 ^ 6 < 2^10 ^ 6 = 2^60 */
sprintf(xorriso->info_text,
"-paste_in: startbyte address negative or much too large (%s)", start);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
return(0);
}
startbyte= num;
num= Scanf_io_size(count, 0);
if(num<=0 || num > 1.0e18) {
sprintf(xorriso->info_text,
"-paste_in : bytecount zero, negative or much too large (%s)", count);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
return(0);
}
bytecount= num;
sprintf(xorriso->info_text, "-paste_in from %s to %s, byte %.f to %.f",
disk_path, iso_rr_path,
(double) startbyte, (double) (startbyte+bytecount));
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
ret= Xorriso_paste_in(xorriso, disk_path, startbyte, bytecount,
iso_rr_path, 0);
return(ret);
}
/* Option -path_list , -quoted_path_list */
/* @param flag bit0= -quoted_path_list
bit1= mkisofs mode: Use / as target for pathspecs without =
*/
int Xorriso_option_path_list(struct XorrisO *xorriso, char *adr, int flag)
{
int ret,linecount= 0, insertcount= 0, null= 0, was_failure= 0, fret= 0;
int was_ferror= 0, argc= 0, i, allow_graft_points_mem;
FILE *fp= NULL;
char **argv= NULL, *pathspec= NULL;
allow_graft_points_mem= xorriso->allow_graft_points;
Xorriso_pacifier_reset(xorriso, 0);
if(adr[0]==0) {
sprintf(xorriso->info_text,"Empty file name given with %s",
flag & 1 ? "-quoted_path_list" : "-path_list");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0);
return(0);
}
ret= Xorriso_afile_fopen(xorriso, adr, "rb", &fp, 0);
if(ret <= 0)
return(0);
Xorriso_alloc_meM(pathspec, char, 2 * SfileadrL);
while(1) {
ret= Xorriso_read_lines(xorriso, fp, &linecount, &argc, &argv,
4 | (flag & 1) );
if(ret <= 0)
goto ex;
if(ret == 2)
break;
for(i= 0; i < argc; i++) {
if(argv[i][0] == 0)
continue;
null= 0;
if(flag & 2) {
ret= Xorriso_graftable_pathspec(xorriso, argv[i], pathspec, 0);
if(ret <= 0)
goto problem_handler;
xorriso->allow_graft_points= 3;
ret= Xorriso_option_add(xorriso, 1, &pathspec, &null, 1 | 2);
xorriso->allow_graft_points= allow_graft_points_mem;
} else {
ret= Xorriso_option_add(xorriso, 1, argv + i, &null, 1 | 2);
}
if(ret<=0 || xorriso->request_to_abort)
goto problem_handler;
insertcount++;
continue; /* regular bottom of loop */
problem_handler:;
was_failure= 1;
fret= Xorriso_eval_problem_status(xorriso, ret, 1|2);
if(fret>=0)
continue;
if(ret > 0)
ret= 0;
goto ex;
}
}
ret= 1;
ex:;
xorriso->allow_graft_points= allow_graft_points_mem;
Sfile_make_argv("", "", &argc, &argv, 2);
Xorriso_free_meM(pathspec);
if(flag & 1)
Xorriso_read_lines(xorriso, fp, &linecount, &argc, &argv, 2);
if(fp != NULL && fp != stdin)
fclose(fp);
Xorriso_pacifier_callback(xorriso, "files added", xorriso->pacifier_count,
xorriso->pacifier_total, "", 1);
if(ret<=0) {
sprintf(xorriso->info_text, "Aborted reading of file ");
Text_shellsafe(adr, xorriso->info_text, 1);
sprintf(xorriso->info_text + strlen(xorriso->info_text),
" in line number %d", linecount);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0,
(fret==-2 ? "NOTE" : "FAILURE"), 0);
} else
ret= !was_ferror;
sprintf(xorriso->info_text, "Added %d items from file ", insertcount);
Text_shellsafe(adr, xorriso->info_text, 1);
strcat(xorriso->info_text, "\n");
Xorriso_info(xorriso,0);
if(ret<=0)
return(ret);
return(!was_failure);
}
/* Option -pathspecs */
int Xorriso_option_pathspecs(struct XorrisO *xorriso, char *mode, int flag)
{
if(strcmp(mode, "off")==0)
xorriso->allow_graft_points= 0;
else if(strcmp(mode, "on")==0)
xorriso->allow_graft_points= 1;
else if(strcmp(mode, "as_mkisofs")==0)
xorriso->allow_graft_points= 3;
else {
sprintf(xorriso->info_text, "-pathspecs: unknown mode '%s'", mode);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
return(0);
}
return(1);
}
/* Option -pkt_output */
int Xorriso_option_pkt_output(struct XorrisO *xorriso, char *mode, int flag)
{
if(strcmp(mode,"off")==0)
xorriso->packet_output= 0;
else
xorriso->packet_output= 1;
return(1);
}
/* Option -preparer_id */
int Xorriso_option_preparer_id(struct XorrisO *xorriso, char *name, int flag)
{
if(Xorriso_check_name_len(xorriso, name,
(int) sizeof(xorriso->preparer_id),
"-preparer_id", 0) <= 0)
return(0);
if(strcmp(name, "@xorriso@") == 0)
Xorriso_preparer_string(xorriso, xorriso->preparer_id, 0);
else
strcpy(xorriso->preparer_id, name);
Xorriso_set_change_pending(xorriso, 1);
return(1);
}
/* Options -print , -print_info , -print_mark */
/* @param flag bit0-1= channel: 0=result, 1=info, 2=mark */
int Xorriso_option_print(struct XorrisO *xorriso, char *text, int flag)
{
int maxl, l, mode;
l= strlen(text);
mode= flag & 3;
if(mode == 1)
maxl= sizeof(xorriso->info_text);
else if(mode == 2)
maxl= sizeof(xorriso->mark_text);
else
maxl= sizeof(xorriso->result_line);
if(l >= maxl) {
sprintf(xorriso->info_text, "Output text too long for -print%s(%d > %d)",
mode == 1 ? "_info" : mode == 2 ? "_mark" : "", l, maxl);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0);
return(0);
}
if(mode == 1) {
sprintf(xorriso->info_text,"%s\n", text);
Xorriso_info(xorriso,0);
} else if(mode == 2) {
strcpy(xorriso->info_text, xorriso->mark_text);
strcpy(xorriso->mark_text, text);
Xorriso_mark(xorriso,0);
strcpy(xorriso->mark_text, xorriso->info_text);
} else {
sprintf(xorriso->result_line,"%s\n",text);
Xorriso_result(xorriso,1);
}
return(1);
}
/* Option -print_size
@param flag bit0= report in mkisofs compatible form on real stdout
(resp. on result channel if xorriso->packet_output)
*/
int Xorriso_option_print_size(struct XorrisO *xorriso, int flag)
{
int ret, fd;
if(!Xorriso_change_is_pending(xorriso, 0)) {
sprintf(xorriso->info_text,"-print_size: No image modifications pending");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0);
if(!(flag & 1)) {
sprintf(xorriso->result_line,"Image size : 0s\n");
Xorriso_result(xorriso,0);
}
return(2);
}
ret= Xorriso_write_session(xorriso, 1);
if(ret<=0) {
sprintf(xorriso->info_text,"-print_size: Failed to set up virtual -commit");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
if(flag&1) {
sprintf(xorriso->result_line,"%d\n", ret);
if(xorriso->packet_output) {
Xorriso_result(xorriso,0);
} else {
fd= xorriso->dev_fd_1;
if(fd<0)
fd= 1;
ret= write(fd, xorriso->result_line, strlen(xorriso->result_line));
/* (result of write intentionally ignored) */
fsync(fd);
}
} else {
sprintf(xorriso->result_line,"Image size : %ds\n", ret);
Xorriso_result(xorriso,0);
}
return(1);
}
/* Option -prog */
int Xorriso_option_prog(struct XorrisO *xorriso, char *name, int flag)
{
if(strlen(name)>=sizeof(xorriso->progname)) {
sprintf(xorriso->info_text,
"Name too long with option -prog (%d > %d)",
(int) strlen(name), (int) sizeof(xorriso->progname)-1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
if(Sfile_str(xorriso->progname,name,0)<=0)
return(-1);
return(1);
}
/* Option -prog_help */
int Xorriso_option_prog_help(struct XorrisO *xorriso, char *name, int flag)
{
int ret;
ret= Xorriso_option_prog(xorriso, name, 0);
if(ret<=0)
return(ret);
ret= Xorriso_option_help(xorriso, 0);
return(ret);
}
/* Option -prompt */
int Xorriso_option_prompt(struct XorrisO *xorriso, char *text, int flag)
{
int ret;
char line[80];
strncpy(xorriso->result_line,text,sizeof(xorriso->result_line)-1);
xorriso->result_line[sizeof(xorriso->result_line)-1]= 0;
Xorriso_result(xorriso,0);
ret= Xorriso_dialog_input(xorriso, line, sizeof(line),1);
return(ret);
}
/* Option -publisher */
int Xorriso_option_publisher(struct XorrisO *xorriso, char *name, int flag)
{
if(Xorriso_check_name_len(xorriso, name, (int) sizeof(xorriso->publisher),
"-publisher", 0) <= 0)
return(0);
strcpy(xorriso->publisher,name);
Xorriso_set_change_pending(xorriso, 1);
return(1);
}
/* Option -pvd_info */
int Xorriso_option_pvd_info(struct XorrisO *xorriso, int flag)
{
return(Xorriso_pvd_info(xorriso, 0));
}
/* Option -pwd alias -pwdi */
int Xorriso_option_pwdi(struct XorrisO *xorriso, int flag)
{
sprintf(xorriso->info_text,"current working directory in ISO image:\n");
Xorriso_info(xorriso,0);
Xorriso_esc_filepath(xorriso, xorriso->wdi, xorriso->result_line, 0);
if(xorriso->sh_style_result == 0 || xorriso->wdi[0] == 0)
strcat(xorriso->result_line, "/");
strcat(xorriso->result_line, "\n");
Xorriso_result(xorriso,0);
return(1);
}
/* Option -pwdx */
int Xorriso_option_pwdx(struct XorrisO *xorriso, int flag)
{
sprintf(xorriso->info_text,"current working directory on hard disk:\n");
Xorriso_info(xorriso,0);
Xorriso_esc_filepath(xorriso, xorriso->wdx, xorriso->result_line, 0);
if(xorriso->sh_style_result == 0 || xorriso->wdx[0] == 0)
strcat(xorriso->result_line, "/");
strcat(xorriso->result_line, "\n");
Xorriso_result(xorriso,0);
return(1);
}
/* Command -read_fs */
int Xorriso_option_read_fs(struct XorrisO *xorriso, char *mode, int flag)
{
if(strcmp(mode, "any") == 0) {
xorriso->read_fs= 0;
} else if(strcmp(mode, "norock") == 0) {
xorriso->read_fs= 1;
} else if(strcmp(mode, "nojoliet") == 0) {
xorriso->read_fs= 2;
} else if(strcmp(mode, "ecma119") == 0) {
xorriso->read_fs= 3;
} else {
sprintf(xorriso->info_text, "-read_fs: unknown mode '%s'", mode);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
return(0);
}
return(1);
}
int Xorriso_option_read_mkisofsrc(struct XorrisO *xorriso, int flag)
{
int ret;
ret= Xorriso_read_mkisofsrc(xorriso, 0);
return(ret);
}
/* Option -reassure "on"|"tree"|"off" */
int Xorriso_option_reassure(struct XorrisO *xorriso, char *mode, int flag)
{
if(strcmp(mode, "off")==0)
xorriso->do_reassure= 0;
else if(strcmp(mode, "on")==0)
xorriso->do_reassure= 1;
else if(strcmp(mode, "tree")==0)
xorriso->do_reassure= 2;
else {
sprintf(xorriso->info_text, "-reassure: unknown mode '%s'", mode);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
return(1);
}
/* Option -report_about */
int Xorriso_option_report_about(struct XorrisO *xorriso, char *in_severity,
int flag)
{
int ret, sev;
char severity[20], *official;
Xorriso__to_upper(in_severity, severity, (int) sizeof(severity), 0);
ret= Xorriso__text_to_sev(severity, &sev, 0);
if(ret<=0) {
sprintf(xorriso->info_text, "-report_about: Not a known severity name : ");
Text_shellsafe(in_severity, xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0);
return(ret);
}
ret= Xorriso__sev_to_text(sev, &official, 0);
if(ret <= 0)
official= severity;
if(Sfile_str(xorriso->report_about_text, official, 0) <= 0)
return(-1);
xorriso->report_about_severity= sev;
return(1);
}
/* Command -report_el_torito */
int Xorriso_option_report_el_torito(struct XorrisO *xorriso,
char *form, int flag)
{
int ret;
ret= Xorriso_report_system_area(xorriso, form, 1);
return(ret);
}
/* Command -report_system_area */
int Xorriso_option_report_system_area(struct XorrisO *xorriso,
char *form, int flag)
{
int ret;
ret= Xorriso_report_system_area(xorriso, form, 0);
return(ret);
}
/* Option -return_with */
int Xorriso_option_return_with(struct XorrisO *xorriso, char *in_severity,
int exit_value, int flag)
{
int ret, sev;
char severity[20], *official;
Xorriso__to_upper(in_severity, severity, (int) sizeof(severity), 0);
ret= Xorriso__text_to_sev(severity, &sev, 0);
if(ret<=0) {
sprintf(xorriso->info_text,
"-return_with: Not a known severity name : ");
Text_shellsafe(in_severity, xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
return(ret);
}
ret= Xorriso__sev_to_text(sev, &official, 0);
if(ret <= 0)
official= severity;
if(exit_value && (exit_value < 32 || exit_value > 63)) {
sprintf(xorriso->info_text,
"-return_with: Not an allowed exit_value. Use 0, or 32 to 63.");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
return(0);
}
if(Sfile_str(xorriso->return_with_text, official, 0) <= 0)
return(-1);
xorriso->return_with_severity= sev;
xorriso->return_with_value= exit_value;
return(1);
}
/* Options -rm alias -rmi , -rm_r alias -rm_ri , -rmdir alias -rmdiri */
/* @param flag bit0=recursive , bit1= remove empty directory: rmdir */
int Xorriso_option_rmi(struct XorrisO *xorriso, int argc, char **argv,
int *idx, int flag)
{
int i, ret, end_idx, was_failure= 0, fret;
char *path= NULL, *eff_path= NULL;
int optc= 0;
char **optv= NULL;
ret= Xorriso_opt_args(xorriso, "-rm*i",
argc, argv, *idx, &end_idx, &optc, &optv, 0);
if(ret<=0)
goto ex;
Xorriso_alloc_meM(path, char, SfileadrL);
Xorriso_alloc_meM(eff_path, char, SfileadrL);
for(i= 0; i<optc; i++) {
if(Sfile_str(path,optv[i],0)<=0)
{ret= -1; goto problem_handler;}
if(path[0]!='/') {
ret= Sfile_prepend_path(xorriso->wdi, path, 0);
if(ret<=0)
goto problem_handler;
}
ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, path, eff_path, 1);
if(ret<0)
goto problem_handler;
if(ret==0) {
sprintf(xorriso->info_text, "Cannot find path ");
Text_shellsafe(path, xorriso->info_text, 1);
strcat(xorriso->info_text, " in loaded ISO image for removal");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
goto problem_handler;
}
strcpy(path, eff_path);
ret= Xorriso_rmi(xorriso, NULL, (off_t) 0, path, flag&(1|2));
if(ret<=0 || xorriso->request_to_abort)
goto problem_handler;
if(ret<3) {
sprintf(xorriso->info_text, "Removed from ISO image: %s '%s'\n",
((flag&2) ? "directory" : (ret>1 ? "subtree" : "file")), path);
Xorriso_info(xorriso, 0);
}
continue; /* regular bottom of loop */
problem_handler:;
was_failure= 1;
fret= Xorriso_eval_problem_status(xorriso, ret, 1|2);
if(fret>=0)
continue;
goto ex;
}
ret= 1;
ex:;
(*idx)= end_idx;
Xorriso_free_meM(path);
Xorriso_free_meM(eff_path);
Xorriso_opt_args(xorriso, "-rm*i",
argc, argv, *idx, &end_idx, &optc, &optv, 256);
if(ret<=0)
return(ret);
return(!was_failure);
}
/* Option -rockridge "on"|"off" */
int Xorriso_option_rockridge(struct XorrisO *xorriso, char *mode, int flag)
{
if(strcmp(mode, "off")==0)
xorriso->do_rockridge= 0;
else if(strcmp(mode, "on")==0)
xorriso->do_rockridge= 1;
else {
sprintf(xorriso->info_text, "-rockridge: unknown mode '%s'", mode);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
return(0);
}
return(1);
}
/* Option -rollback */
/* @param flag bit0= do not -reassure
@return <=0 error , 1 success, 2 revoked by -reassure
*/
int Xorriso_option_rollback(struct XorrisO *xorriso, int flag)
{
int ret;
char *indev= NULL, *which_will;
Xorriso_alloc_meM(indev, char, SfileadrL);
if(Xorriso_change_is_pending(xorriso, 0))
which_will= "revoke the pending image changes";
else
which_will= "reload the image";
if(!(flag&1)) {
ret= Xorriso_reassure(xorriso, "-rollback", which_will, 0);
if(ret<=0)
{ret= 2; goto ex;}
}
if(Sfile_str(indev, xorriso->indev, 0)<=0)
{ret= -1; goto ex;}
xorriso->volset_change_pending= 0;
ret= Xorriso_give_up_drive(xorriso, 1|8);
if(ret<=0)
goto ex;
xorriso->image_start_mode&= ~(1<<31); /* reactivate eventual -load address */
ret= Xorriso_option_dev(xorriso, indev, 1|4);
ex:;
Xorriso_free_meM(indev);
return(ret);
}
/* Option -rom_toc_scan */
int Xorriso_option_rom_toc_scan(struct XorrisO *xorriso, char *mode, int flag)
{
int l;
char *cpt, *npt;
npt= cpt= mode;
for(cpt= mode; npt != NULL; cpt= npt + 1) {
npt= strchr(cpt,':');
if(npt==NULL)
l= strlen(cpt);
else
l= npt-cpt;
if(l==0)
continue;
if(strncmp(cpt, "off", l) == 0)
xorriso->toc_emulation_flag&= ~5;
else if(strncmp(cpt, "on", l) == 0)
xorriso->toc_emulation_flag= (xorriso->toc_emulation_flag & ~4) | 1;
else if(strncmp(cpt, "force", l) == 0)
xorriso->toc_emulation_flag|= 5;
else if(strncmp(cpt, "emul_off", l) == 0)
xorriso->toc_emulation_flag|= 2;
else if(strncmp(cpt, "emul_on", l) == 0)
xorriso->toc_emulation_flag&= ~2;
else if(strncmp(cpt, "emul_wide", l) == 0)
xorriso->toc_emulation_flag|= 8;
else if(strncmp(cpt, "emul_narrow", l) == 0)
xorriso->toc_emulation_flag&= ~8;
else {
sprintf(xorriso->info_text, "-rom_toc_scan: unknown mode in '%s'", mode);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
return(0);
}
}
return(1);
}
/* Command -rr_reloc_dir */
int Xorriso_option_rr_reloc_dir(struct XorrisO *xorriso, char *name, int flag)
{
if(strlen(name) > 255) {
sprintf(xorriso->info_text,
"Name too long with -rr_reloc_dir. Max. 255 bytes allowed.");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
return(0);
}
if(strchr(name, '/') != NULL) {
sprintf(xorriso->info_text,
"Name given with -rr_reloc_dir contains '/' character");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
return(0);
}
strcpy(xorriso->rr_reloc_dir, name);
return(1);
}
/* Option -scdbackup_tag list_path record_name */
int Xorriso_option_scdbackup_tag(struct XorrisO *xorriso, char *listname,
char *recname, int flag)
{
if(strlen(recname) > 80) {
sprintf(xorriso->info_text,
"Unsuitable record name given with -scdbackup_tag");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
return(0);
}
strcpy(xorriso->scdbackup_tag_name, recname);
xorriso->scdbackup_tag_time[0]= 0;
if(Sfile_str(xorriso->scdbackup_tag_listname, listname, 0) <= 0)
return(-1);
return(1);
}
/* Command -scsi_dev_family */
int Xorriso_option_scsi_dev_family(struct XorrisO *xorriso, char *mode,
int flag)
{
if(strcmp(mode, "default") == 0)
xorriso->linux_scsi_dev_family= 0;
else if(strcmp(mode, "sr") == 0)
xorriso->linux_scsi_dev_family= 1;
else if(strcmp(mode, "scd") == 0)
xorriso->linux_scsi_dev_family= 2;
else if(strcmp(mode, "sg") == 0)
xorriso->linux_scsi_dev_family= 4;
else {
sprintf(xorriso->info_text, "-scsi_dev_family: unknown family '%s'", mode);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
return(0);
}
Xorriso_scsi_dev_family(xorriso, 0);
return(1);
}
/* Option -scsi_log */
int Xorriso_option_scsi_log(struct XorrisO *xorriso, char *mode, int flag)
{
if(strcmp(mode, "on") == 0)
xorriso->scsi_log= 1;
else if(strcmp(mode, "off") == 0)
xorriso->scsi_log= 0;
else {
sprintf(xorriso->info_text, "-scsi_log: unknown mode '%s'", mode);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
return(0);
}
Xorriso_scsi_log(xorriso, !!xorriso->scsi_log);
return(1);
}
/* Option -session_log */
int Xorriso_option_session_log(struct XorrisO *xorriso, char *path, int flag)
{
if(Sfile_str(xorriso->session_logfile, path, 0)<=0)
return(-1);
return(1);
}
/* Option -setfacl_list alias -setfacl_listi */
int Xorriso_option_setfacl_listi(struct XorrisO *xorriso, char *path, int flag)
{
int ret, eaten, line_size;
size_t buf_size= 0, buf_add, l, linecount= 0, diff_buf_wpt;
char *line= NULL, *buf= NULL, *wpt, *new_buf, limit_text[80];
char *file_path= NULL, *uid= NULL, *gid= NULL;
FILE *fp= NULL;
line_size= SfileadrL * 4;
buf_add= line_size * 4;
Xorriso_alloc_meM(line, char, line_size);
Xorriso_alloc_meM(file_path, char, SfileadrL);
Xorriso_alloc_meM(uid, char, 161);
Xorriso_alloc_meM(gid, char, 161);
Xorriso_pacifier_reset(xorriso, 0);
if(path[0]==0) {
sprintf(xorriso->info_text, "Empty file name given with -setfacl_list");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
{ret= 0; goto ex;}
}
ret= Xorriso_afile_fopen(xorriso, path, "rb", &fp, 0);
if(ret <= 0)
{ret= 0; goto ex;}
buf_size= buf_add;
buf= calloc(buf_size, 1);
if(buf == NULL)
goto out_of_mem;
wpt= buf;
*wpt= 0;
uid[0]= gid[0]= 0;
while(1) {
if(Sfile_fgets_n(line, line_size, fp, 0) == NULL)
break;
linecount++;
if(strncmp(line, "# file: ", 8) ==0) {
if(wpt != buf && file_path[0]) {
/* Commit previous list */
ret= Xorriso_perform_acl_from_list(xorriso, file_path,
uid, gid, buf, 0);
if(ret<=0)
goto ex;
wpt= buf;
*wpt= 0;
file_path[0]= uid[0]= gid[0]= 0;
}
/* Unescape line and register as file path */
Sfile_bsl_interpreter(line + 8, strlen(line + 8), &eaten, 0);
if(strlen(line + 8) >= SfileadrL) {
sprintf(xorriso->info_text, "-setfacl_list: Oversized file path");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
ret= 0; goto ex;
}
strcpy(file_path, line + 8);
continue;
} else if(strncmp(line, "# owner: ", 9) == 0) {
if(strlen(line + 9) > 160) {
sprintf(xorriso->info_text, "-setfacl_list: Oversized owner id");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
ret= 0; goto ex;
}
strcpy(uid, line + 9);
continue;
} else if(strncmp(line, "# group: ", 9) == 0) {
if(strlen(line + 9) > 160) {
sprintf(xorriso->info_text, "-setfacl_list: Oversized group id");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
ret= 0; goto ex;
}
strcpy(gid, line + 9);
continue;
} else if(line[0] == '#' || line[0] == 0) {
continue;
} else if(strcmp(line, "@") == 0) {
Xorriso_msgs_submit(xorriso, 0,
"-setfacl_list input ended by '@'", 0, "NOTE", 0);
break;
} else if(strcmp(line, "@@@") == 0) {
Xorriso_msgs_submit(xorriso, 0,
"-setfacl_list aborted by input line '@@@'", 0, "WARNING", 0);
ret= 0; goto ex;
}
/* Register ACL entry */
l= strlen(line);
if(wpt + l + 2 - buf > (int) buf_size) {
if((int) (buf_size + buf_add) > xorriso->temp_mem_limit) {
Sfile_scale((double) xorriso->temp_mem_limit, limit_text,5,1e4,1);
sprintf(xorriso->info_text,
"-setfacl_list: List entry for a single file exceeds -temp_mem_limit %s",
limit_text);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
ret= 0; goto ex;
}
diff_buf_wpt= wpt - buf;
buf_size+= buf_add;
new_buf= realloc(buf, buf_size);
if(new_buf == NULL)
goto out_of_mem;
buf= new_buf;
wpt= buf + diff_buf_wpt;
}
memcpy(wpt, line, l);
*(wpt + l)= '\n';
wpt+= l + 1;
*wpt= 0;
}
if(wpt != buf && file_path[0]) {
/* Commit last list */
ret= Xorriso_perform_acl_from_list(xorriso, file_path, uid, gid, buf, 0);
if(ret<=0)
goto ex;
} else {
sprintf(xorriso->info_text, "-setfacl_list: Unexpected end of file ");
Text_shellsafe(path, xorriso->info_text, 1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0);
}
ret= 1;
ex:;
if(buf != NULL)
free(buf);
if(fp != NULL && fp != stdin)
fclose(fp);
if(ret <= 0) {
sprintf(xorriso->info_text, "-setfacl_list ");
Text_shellsafe(path, xorriso->info_text, 1);