bug-xorriso
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug-xorriso] Fwd: Fixes and improvements for libisoburn


From: Eliska Svobodova
Subject: [Bug-xorriso] Fwd: Fixes and improvements for libisoburn
Date: Fri, 16 Aug 2019 09:49:04 +0200

Hi,
glad about the applied patches. To the rest:

On Wed, Aug 14, 2019 at 7:31 PM Thomas Schmitt <address@hidden> wrote:
Hi,

please brace for lengthy text. :)

--------------------------------------------------------------------------

Eliska Svobodova wrote:
> 1) Bitwise operations - shift 1 << 31 is used on multiple places through
> xorriso, which is an undefined operation; fix: make 1 unsigned:  1u << 31

Looks good to me. Applied as
  https://dev.lovelyhq.com/libburnia/libisoburn/commit/fb61be034f3ab95c48e3de5855599c8acf17fa13

--------------------------------------------------------------------------

> 2) Absolute value - you are using abs() to calculate the absolute value of
> r1count and r2count, which are of type long int, so it could be truncated;
> fix: use labs()

They are off_t rather than long int. The whole ado with (double) is
because there is no printf formatter for off_t and the number of "long"s
is pure guesswork on source code level.

So i decided for a (double) based solution, avoiding fabs(3) because
there is no dependency on libm yet.
  https://dev.lovelyhq.com/libburnia/libisoburn/commit/fb61be034f3ab95c48e3de5855599c8acf17fa13
I didn't realize it. Pavel Cahyna suggested you use intmax_t in place of double because printf has a conversion for it and it would be better to stay in integer types.
--------------------------------------------------------------------------

> 3) Dereference of NULL pointers - in xorriso/opts_d_h.c, first_job pointer
> can be in case of failure of Findjob_new a NULL pointer, which is
> dereferenced in ex:

Indeed.


> in xorriso/opts_i_o.c,
> also descr can be NULL, if end_idx <= 0 and execution goes straight to ex:

Yes. But then Xorriso_opt_args() is called with flag bit 8 for disposal
of optv. descr (function parameter "argv") is not dereferenced in this case.

But argv is used for a computation which makes sense only if it is a
valid memory address. To perform it with argv == NULL invites for
misinterpretation, although i deem it unlikely that a malloc() heap
pointer is near enough to 0 to step into that puddle.

So i dediced to add a test for (argv == NUL) in Xorriso_opt_args() in
order to avoid the unlikely mistake which would cause a memory leak.
opts_i_o.c stays as is.

I missed the flag, sorry. 

> in xorriso/read_run.c,
> when catcontent is NULL, NULL is put in buf_pt and is passed to write()
> function

This is a tricky situation. A file shall be copied from ISO to hard disk.
Its type is El Torito Boot Catalog which will be mapped to regular file.
What to do if libisofs does not deliver catalog content ?
Create no file ? Create an empty file ?

Currently, the NULL pointer is supposed to be not used in the further
course of the function, because if iso_image_get_bootcat() returns no
catcontent, then catsize is supposed to be 0.
--------------------------
<libisofs/libisofs.h> has:
  * @param content
  *      Will return either NULL or an allocated memory buffer with the
  *      content bytes of the boot catalog.
  *      Dispose it by free() when no longer needed.
  * @param size
  *      Will return the number of bytes in content.
  * @return
  *      1 if reply is valid, 0 if not boot catalog was loaded, < 0 on error.
  *
  * @since 1.1.2
  */
 int iso_image_get_bootcat(IsoImage *image, IsoBoot **catnode, uint32_t *lba,
                           char **content, off_t *size);
---------------------
The implementation in libisofs is a bit complicated. It looks like no
size > 0 can be recorded if content is NULL.
Nevertheless i made sure in iso_image_get_bootcat() that if content is
NULL then size is forced to 0.
  https://dev.lovelyhq.com/libburnia/libisofs/commit/fe98b35afb2f16b4605d15c523c70541997a72de

That seems clearer to me.
So the loop while(todo>0) in libisoburn gets skipped and an empty file
emerges. For now i leave this as is.

Changes applied as
  https://dev.lovelyhq.com/libburnia/libisoburn/commit/e17db6aa3e80feaed546ad8ebee7a46b01b5d2e1

--------------------------------------------------------------------------

> 4) Missing initialization - in xorriso/iso_manip.c, own_link_stack isn't
> initialized,

Applied as
  https://dev.lovelyhq.com/libburnia/libisoburn/commit/b35629170077e591af9d32b1e2e95ce5c08160e0

--------------------------------------------------------------------------

> And we have some improvements to make the code safer and cleaner:
>
> 1) Resource leaks - in xorriso/drive_mgt.c, dynamically allocated disc isn't
> freed in case that goto ex; is used; fix: move freeing after ex:

Indeed. Just for completeness i also move the processing of possible
library messages after ex, too.


>                            - in xorriso/emulators.c and
> xorriso/opts_i_o.c,arguments should be freed by Sfile_destroy_argv function

I wonder which tool reported this with what messages.
There is a fourth occasion of the Xorriso_read_lines() loop which is not
in your patch: opts_p_z.c, Xorriso_option_path_list().

Two of the found occasions are false positives. Only those where
Xorriso_read_lines(...,2) is called conditionally are prone to memory
leaks in case of goto ex. I.e. the two in opts_i_o.c are ok by
always calling Xorriso_read_lines(...,2) after the loop.

While analysing the possibilities for a memory leak in
Xorriso_option_path_list() i found a potential leak which happens when
the argv pointer array can be allocated but then its content string cannot.
See the text_io.c part of the changeset.
  https://dev.lovelyhq.com/libburnia/libisoburn/commit/3eba8cc9210639caa830ed0f1793592bf60b66bf

So how come that the analizer reported two false positives and missed
one true positive ?
I mainly ask because it might be that the reported positives are not
actually about the aspects which we inspected, but about something else.
All reports about resource leaks are from Coverity. Here they are:

Error: RESOURCE_LEAK (CWE-772): [#def73]
libisoburn-1.4.8/xorriso/drive_mgt.c:1208: alloc_fn: Storage is returned from allocation function "isoburn_toc_drive_get_disc".
libisoburn-1.4.8/xorriso/drive_mgt.c:1208: var_assign: Assigning: "disc" = storage returned from "isoburn_toc_drive_get_disc(drive)".
libisoburn-1.4.8/xorriso/drive_mgt.c:1274: noescape: Resource "disc" is not freed or pointed-to in "isoburn_toc_disc_get_sessions".
libisoburn-1.4.8/xorriso/drive_mgt.c:1275: noescape: Resource "disc" is not freed or pointed-to in "isoburn_toc_disc_get_incmpl_sess".
libisoburn-1.4.8/xorriso/drive_mgt.c:1418: leaked_storage: Variable "disc" going out of scope leaks the storage it points to.
# 1416|    ret= 1;
# 1417|   ex:;
# 1418|->  return(ret);
# 1419|   }
# 1420|  

Error: RESOURCE_LEAK (CWE-772): [#def79]
libisoburn-1.4.8/xorriso/emulators.c:1033: alloc_arg: "Xorriso_read_lines" allocates memory that is stored into "argv".
libisoburn-1.4.8/xorriso/emulators.c:1038: leaked_storage: Variable "argv" going out of scope leaks the storage it points to.
# 1036|    if(ret<=0)
# 1037|      return(ret);
# 1038|->  return(!was_failure);
# 1039|   }
# 1040|  

Error: RESOURCE_LEAK (CWE-772): [#def187]
libisoburn-1.4.8/xorriso/opts_i_o.c:1431: alloc_arg: "Xorriso_read_lines" allocates memory that is stored into "argv".
libisoburn-1.4.8/xorriso/opts_i_o.c:1446: leaked_storage: Variable "argv" going out of scope leaks the storage it points to.
# 1444|    strcat(xorriso->info_text, "\n");
# 1445|    Xorriso_info(xorriso,0);
# 1446|->  return(ret);
# 1447|   }
# 1448|  

Error: RESOURCE_LEAK (CWE-772): [#def189]
libisoburn-1.4.8/xorriso/opts_i_o.c:1695: alloc_arg: "Xorriso_read_lines" allocates memory that is stored into "linev".
libisoburn-1.4.8/xorriso/opts_i_o.c:1711: leaked_storage: Variable "linev" going out of scope leaks the storage it points to.
# 1709|    if(ret!=1)
# 1710|      return(ret);
# 1711|->  return(!was_failure);
# 1712|   }
# 1713| 

I couldn't find the reason, why it missed the true-positive. I would guess that it has something to do with flags, analyzers I used, had real problems with them because they weren't able to determine when and what flags will be raised.

--------------------------------------------------------------------------

> 2) Overflow in strcpy - in multiple files, there are strcpys which copy
> dynamically allocated strings into static strings, it would be better to use
> strncpy to avoid overflow

This would put a cap on potential memory errors. But an overflow of
a string is also a problem with program logics. So a blanket solution is
not to expect.
I realize that but I don't know the program sufficiently to handle logics after error occurs...

In particular:

> --- a/xorriso/drive_mgt.c
> @@ -910,7 +910,8 @@ int Xorriso_toc_line(struct XorrisO *xorriso, int flag)
> - strcpy(xorriso->info_text, xorriso->result_line);

xorriso->result_line is of the same size as xorriso->info_text.
If any oversized text made it into result_line, then the program is
doomed already.

No need for action.


> --- a/xorriso/iso_tree.c
> @@ -865,7 +865,8 @@ int Xorriso_getfattr(struct XorrisO *xorriso,
> -       strcpy(xorriso->result_line, bsl);

(The patch does not address the subsequent sprintf() which would overflow
 if all available space was filled by the strncpy().)

The result size is pre-checked by

     if(strlen(names[i]) + value_lengths[i] >= SfileadrL) {
       sprintf(xorriso->result_line, "# oversized: name %d , value %d bytes\n",
               (int) strlen(names[i]), (int) value_lengths[i]);

Function Sfile_bsl_encoder() cannot inflate the text size by a factor
of 10 to surpass the size of xorriso->result_line.

No need for action.


> --- a/xorriso/misc_funct.c
> @@ -521,7 +521,8 @@ int Decode_xorriso_timestamp(struct tm *erg, char *code,
> - strcpy(buf, code);

The size is pre-checked by

  l= strlen(code);
  if(l>17 || l<10)
    return(0);

No need for action.


> --- a/xorriso/opts_a_c.c
> @@ -368,8 +368,10 @@ int Xorriso_option_application_id(struct XorrisO
> - else
> -   strcpy(xorriso->application_id,name);

The size is pre-checked by

 if(Xorriso_check_name_len(xorriso, name,
                           (int) sizeof(xorriso->application_id),
                           "-application_id", 0) <= 0)
   return(0);

which will complain and refuse if oversize is detected.

No need for action.


> @@ -568,7 +570,8 @@ int Xorriso_option_biblio_file(struct XorrisO *xorriso, char *name, int flag)
>  if(Xorriso_check_name_len(xorriso, name, (int) sizeof(xorriso->biblio_file),
>                            "-biblio_file", 0) <= 0)
> - strcpy(xorriso->biblio_file, name);

The same.

No need for action.


> @@ -847,7 +850,8 @@ treatment_patch:;
> -     strcpy(xorriso->boot_image_bin_path, treatpt + 9);
> @@ -871,7 +876,8 @@ treatment_patch:;
> -     strcpy(xorriso->boot_image_bin_path, treatpt + 9);

Here xorriso should refuse to perform the -boot_image command.

I added length tests with error exit.
I am glad that at least one message was right. I am sorry I bothered you with so many false-positives, I should have checked them more closely. I just thought that additional control wouldn't mind.


> @@ -861,7 +865,8 @@ treatment_patch:;
> -     strcpy(xorriso->boot_image_bin_form, formpt);

This line is only executed with known short texts:

 if(strcmp(formpt, "isolinux")==0 || strcmp(formpt, "grub") == 0)
   isolinux_grub= 1;
 ...
   if(isolinux_grub) {
     ...
     strcpy(xorriso->boot_image_bin_form, formpt);

No need for action.


> @@ -1438,7 +1444,8 @@ int Xorriso_option_cdi(struct XorrisO *xorriso,
> - strcpy(xorriso->wdi, namept);

The length of eff_path was tested in Xorriso_normalize_img_path().
Xorriso_truncate_path_comps() either sets namept to eff_path or it
writes a truncated version of eff_path into path and sets namept to
path.

No need for action.


> @@ -2378,10 +2385,12 @@ int Xorriso_option_concat(struct XorrisO *xorriso,
> -   strcpy(xorriso->list_delimiter, delimiter);

The size is pre-checked by

   ret= Xorriso_check_thing_len(xorriso, argv[*idx + 1],
                                sizeof(xorriso->list_delimiter), "-concat",
                                "Delimiter", 0);
   if(ret <= 0)
     goto ex;

No need for action.


> -   strcpy(xorriso->list_delimiter, delimiter_mem);

delimiter_mem is the memorized content of xorriso->list_delimiter before
the operation began. So it cannot be too large.

No need for action.


> @@ -2427,7 +2436,8 @@ int Xorriso_option_copyright_file(struct XorrisO
> - strcpy(xorriso->copyright_file, name);

The size is pre-checked by

 if(Xorriso_check_name_len(xorriso, name,
                           (int) sizeof(xorriso->copyright_file),
                           "-copyright_file", 0) <= 0)
   return(0);

No need for action.


> --- a/xorriso/opts_p_z.c
> -   strcpy(xorriso->mark_text, xorriso->info_text);

mark_text is indeed smaller than info_text. But info_text only serves
as temporary storage for a string which formerly was in mark_text:

   strcpy(xorriso->info_text, xorriso->mark_text);

No need for action.


> @@ -417,7 +418,8 @@ int Xorriso_option_publisher(struct XorrisO *xorriso,
> strcpy(xorriso->publisher,name);

The size is pre-checked by Xorriso_check_name_len().

No need for action.


> --- a/xorriso/text_io.c
> @@ -612,7 +612,8 @@ klammer_affe:;
> -   strcpy(xorriso->pending_option,cpt);

cpt cannot be longer than SfileadrL-1, because it is a pointer into
a string which was checked for this length:

 ret= Xorriso_dialog_input(xorriso,line, SfileadrL, 1);
 ...
 cpt= line;
 ...

No need for action.

So only one occasion survived:
  https://dev.lovelyhq.com/libburnia/libisoburn/commit/06346c1e982ee4e813372914b16201cba17ced3f

--------------------------------------------------------------------------

> 3) Memcpy - in libisoburn/isofs_wrap.c, strncpy is used to copy fixed-size
> memory without ending null (Coverity reported it as a mistake), memcpy would
> be probably better in order to express the intent more clearly and to avoid
> false-positive warning in the future.

Maybe it gets smarter and avoids this warning together with all the false
positives above.

The man pages of strncpy(3) and memcpy(3) describe quite similar semantics
with the difference that strncpy() would be safe against reading
inappropriate bytes if src is shorter than n.
But on the other hand, a manipulation of an ISO 9660 Primary Volume
Descriptor is sypposed to be a binary data operation. So memset() is
indeed more appropriate than strncpy().

Applied by
  https://dev.lovelyhq.com/libburnia/libisoburn/commit/fe5fd8eefa42273c6d84d240582eee5c90412b43
As I said, this is more a cosmetic change to improve code readability and performance (even only little bit).


--------------------------------------------------------------------------

I hope i got everything properly processed now. Review is welcome.


Have a nice day :)

Thomas


 These are all remaining errors I found. Thank you for checking them, I really appreciate that (this is my first attempt in contributing).

Have a nice day too!
Eliska


Additional info:
I just realized I didn't send you the right error messages from Coverity (those I sent were processed by another tool). So, here they are.
With Pavel Cahyna, we might also have discovered the reason why Coverity reported those false-positive resource leaks. It cannot understand flags, so when it sees call:
Xorriso_read_lines(xorriso, fp, &linecount, &argc, &argv, 2);
it thinks it is a memory-allocating function. It cannot know that with flag==2 it only deallocates memory and leaves.
In fact, all three reports were false-positives but one of them was close to another mistake (deallocating inside if condition).
Why it didn't find the fourth call of the function Xorriso_read_lines remains a mystery. It would be a false-positive anyway.
1    	
2    	/* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images.
3    	
4    	   Copyright 2007-2015 Thomas Schmitt, <address@hidden>
5    	
6    	   Provided under GPL version 2 or later.
7    	
8    	   This file contains the implementation of options as mentioned in man page
9    	   or info file derived from xorriso.texi.
10   	*/
11   	
12   	#ifdef HAVE_CONFIG_H
13   	#include "../config.h"
14   	#endif
15   	
16   	#include <ctype.h>
17   	#include <sys/types.h>
18   	#include <unistd.h>
19   	#include <stdlib.h>
20   	#include <stdio.h>
21   	#include <string.h>
22   	#include <sys/stat.h>
23   	#include <sys/time.h>
24   	#include <time.h>
25   	#include <errno.h>
26   	
27   	#include "xorriso.h"
28   	#include "xorriso_private.h"
29   	#include "xorrisoburn.h"
30   	
31   	
32   	/* Option -iso_rr_pattern "on"|"ls"|"off" */
33   	int Xorriso_option_iso_rr_pattern(struct XorrisO *xorriso, char *mode,int flag)
34   	{
35   	 if(strcmp(mode, "off")==0)
36   	   xorriso->do_iso_rr_pattern= 0;
37   	 else if(strcmp(mode, "on")==0)
38   	   xorriso->do_iso_rr_pattern= 1;
39   	 else if(strcmp(mode, "ls")==0)
40   	   xorriso->do_iso_rr_pattern= 2;
41   	 else {
42   	   sprintf(xorriso->info_text, "-iso_rr_pattern: unknown mode '%s'", mode);
43   	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
44   	   return(0);
45   	 }
46   	 return(1);
47   	}
48   	
49   	
50   	/* Option -jigdo aspect argument */
51   	int Xorriso_option_jigdo(struct XorrisO *xorriso, char *aspect, char *arg,
52   	                         int flag)
53   	{
54   	 int ret;
55   	
56   	 ret= Xorriso_jigdo_interpreter(xorriso, aspect, arg, 0);
57   	 return(ret);
58   	}
59   	
60   	
61   	/* Option -joliet "on"|"off" */
62   	int Xorriso_option_joliet(struct XorrisO *xorriso, char *mode, int flag)
63   	{
64   	 if(strcmp(mode, "off")==0)
65   	   xorriso->do_joliet= 0;
66   	 else if(strcmp(mode, "on")==0)
67   	   xorriso->do_joliet= 1;
68   	 else {
69   	   sprintf(xorriso->info_text, "-joliet: unknown mode '%s'", mode);
70   	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
71   	   return(0);
72   	 }
73   	 return(1);
74   	}
75   	
76   	
77   	/* Command -launch_frontend */
78   	int Xorriso_option_launch_frontend(struct XorrisO *xorriso,
79   	                                   int argc, char **argv, int *idx, int flag)
80   	{
81   	 int ret, end_idx;
82   	
83   	 end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 1);
84   	
85   	 if(xorriso->launch_frontend_banned) {
86   	   sprintf(xorriso->info_text,
87   	           "-launch_frontend was already executed in this xorriso run");
88   	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
89   	   ret= 0; goto ex;
90   	 }
91   	 xorriso->launch_frontend_banned= 1;
92   	 if(end_idx <= *idx)
93   	   {ret= 1; goto ex;}
94   	 if(argv[*idx][0] == 0)
95   	   {ret= 1; goto ex;}
96   	 xorriso->dialog= 2;
97   	 ret= Xorriso_launch_frontend(xorriso, end_idx - *idx, argv + *idx,
98   	                              "", "", 0);
99   	ex:;
100  	 (*idx)= end_idx;
101  	 return(ret);
102  	}
103  	
104  	
105  	/* Option -list_arg_sorting */
106  	int Xorriso_option_list_arg_sorting(struct XorrisO *xorriso, int flag)
107  	{
108  	 int ret;
109  	
110  	 ret= Xorriso_cmd_sorting_rank(xorriso, 0, NULL, 0, 1);
111  	 return(ret);
112  	}
113  	
114  	
115  	/* Option -list_delimiter */
116  	int Xorriso_option_list_delimiter(struct XorrisO *xorriso, char *text,
117  	                                  int flag)
118  	{
119  	 int ret, argc;
120  	 char **argv= NULL;
121  	
122  	 if(text[0] == 0) {
123  	   sprintf(xorriso->info_text,
124  	           "-list_delimiter: New delimiter text is empty");
125  	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
126  	   return(0);
127  	 }
128  	 if(strlen(text) > 80) {
129  	   sprintf(xorriso->info_text,
130  	           "-list_delimiter: New delimiter text is too long");
131  	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
132  	   return(0);
133  	 }
134  	 ret= Sfile_make_argv(xorriso->progname, text, &argc, &argv, 4);
135  	 if(ret > 0) {
136  	   if(argc > 2) {
137  	     sprintf(xorriso->info_text,
138  	            "-list_delimiter: New delimiter text contains more than one word");
139  	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
140  	   }
141  	   Sfile_make_argv(xorriso->progname, text, &argc, &argv, 2);
142  	   if(argc > 2)
143  	     return(0);
144  	 }
145  	 if(strchr(text, '"') != NULL || strchr(text, '\'') != NULL) {
146  	   sprintf(xorriso->info_text,
147  	           "-list_delimiter: New delimiter text contains quotation marks");
148  	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
149  	   return(0);
150  	 }
151  	 strcpy(xorriso->list_delimiter, text);
152  	 return(1);
153  	}
154  	
155  	
156  	/* Option -list_extras */
157  	int Xorriso_option_list_extras(struct XorrisO *xorriso, char *mode, int flag)
158  	{
159  	 int ret;
160  	
161  	 ret= Xorriso_list_extras(xorriso, mode, 0);
162  	 return(ret);
163  	}
164  	
165  	
166  	/* Option -list_formats */
167  	int Xorriso_option_list_formats(struct XorrisO *xorriso, int flag)
168  	{
169  	 int ret;
170  	
171  	 ret= Xorriso_list_formats(xorriso, 0);
172  	 return(ret);
173  	}
174  	
175  	
176  	/* Option -list_speeds */
177  	int Xorriso_option_list_speeds(struct XorrisO *xorriso, int flag)
178  	{
179  	 int ret;
180  	
181  	 ret= Xorriso_list_speeds(xorriso, 0);
182  	 return(ret);
183  	}
184  	
185  	
186  	/* Option -list_profiles */
187  	int Xorriso_option_list_profiles(struct XorrisO *xorriso, char *which,
188  	                                 int flag)
189  	{
190  	 int ret;
191  	 int mode= 0;
192  	
193  	 if(strncmp(which,"in",2)==0)
194  	   mode|= 1;
195  	 else if(strncmp(which,"out",3)==0)
196  	   mode|= 2;
197  	 else
198  	   mode|= 3;
199  	 if(mode & 1) {
200  	   ret= Xorriso_toc(xorriso, 1 | 16 | 32);
201  	   if(ret > 0)
202  	     Xorriso_list_profiles(xorriso, 0);
203  	 }
204  	 if((mode & 2) && xorriso->in_drive_handle != xorriso->out_drive_handle) {
205  	   ret= Xorriso_toc(xorriso, 1 | 2 | 16 | 32);
206  	   if(ret > 0)
207  	     Xorriso_list_profiles(xorriso, 2);
208  	 }
209  	 return(1);
210  	}
211  	
212  	
213  	/* Command -lns alias -lnsi */
214  	int Xorriso_option_lnsi(struct XorrisO *xorriso, char *target, char *path,
215  	                        int flag)
216  	{
217  	 int ret;
218  	 char *eff_path= NULL, *buffer= NULL, *namept;
219  	
220  	 Xorriso_alloc_meM(eff_path, char, SfileadrL);
221  	 Xorriso_alloc_meM(buffer, char, SfileadrL);
222  	
223  	 ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, path, eff_path, 1);
224  	 if(ret < 0)
225  	   {ret= 0; goto ex;}
226  	 if(ret > 0) { 
227  	   sprintf(xorriso->info_text, "-lns: Address already existing: ");
228  	   Text_shellsafe(eff_path, xorriso->info_text, 1);
229  	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
230  	   {ret= 0; goto ex;}
231  	 } 
232  	 ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, path, eff_path, 2);
233  	 if(ret < 0)
234  	   {ret= 0; goto ex;}
235  	 ret= Xorriso_truncate_path_comps(xorriso, target, buffer, &namept, 0);
236  	 if(ret < 0)
237  	   {ret= 0; goto ex;}
238  	 ret= Xorriso_graft_in(xorriso, NULL, namept, eff_path, (off_t) 0, (off_t) 0,
239  	                       1024);
240  	 if(ret <= 0)
241  	   {ret= 0; goto ex;}
242  	 ret= 1;
243  	ex:;
244  	 Xorriso_free_meM(buffer);
245  	 Xorriso_free_meM(eff_path);
246  	 return(ret);
247  	}
248  	
249  	
250  	/* Option -load session|track|sbsector value */
251  	/* @param flag bit0= with adr_mode sbsector: adr_value is possibly 16 too high
252  	   @return <=0 error , 1 success, 2 revoked by -reassure
253  	*/
254  	int Xorriso_option_load(struct XorrisO *xorriso, char *adr_mode,
255  	                          char *adr_value, int flag)
256  	{
257  	 int ret;
258  	
259  	 if(Xorriso_change_is_pending(xorriso, 0)) {
260  	   sprintf(xorriso->info_text,
261  	           "-load: Image changes pending. -commit or -rollback first");
262  	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
263  	   return(0);
264  	 }
265  	 ret= Xorriso_reassure(xorriso, "-load", "loads an alternative image", 0);
266  	 if(ret<=0)
267  	   return(2);
268  	 ret= Xorriso_decode_load_adr(xorriso, "-load", adr_mode, adr_value,
269  	                              &(xorriso->image_start_mode),
270  	                              xorriso->image_start_value, flag & 1);
271  	 if(ret <= 0)
272  	   return(ret);
273  	 xorriso->image_start_mode|= (1<<30); /* enable non-default msc1 processing */
274  	 if(strlen(xorriso->indev)>0) {
275  	   ret= Xorriso_option_rollback(xorriso, 1); /* Load image, no -reassure */
276  	   if(ret<=0)
277  	     return(ret);
278  	 }
279  	 return(1);
280  	}
281  	
282  	
283  	/* Option -logfile */
284  	int Xorriso_option_logfile(struct XorrisO *xorriso, char *channel,
285  	                                                      char *fileadr, int flag)
286  	{
287  	 int hflag,channel_no= 0, ret;
288  	   
289  	 if(channel[0]==0) {
290  	logfile_wrong_form:;
291  	   sprintf(xorriso->info_text,"Wrong form. Correct would be: -logfile \".\"|\"R\"|\"I\"|\"M\" file_address");
292  	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
293  	   return(0);
294  	 }
295  	 hflag= 2;
296  	 if(channel[0]=='R')
297  	   channel_no= 1;
298  	 else if(channel[0]=='I')
299  	   channel_no= 2;
300  	 else if(channel[0]=='M')
301  	   channel_no= 3;
302  	 else if(channel[0]=='.')
303  	   hflag= 4;
304  	 else
305  	   goto logfile_wrong_form;
306  	 if(strcmp(fileadr,"-")==0 || fileadr[0]==0)
307  	     hflag|= (1<<15);
308  	 xorriso->logfile[channel_no][0]= 0;
309  	 ret= Xorriso_write_to_channel(xorriso, fileadr, channel_no, hflag);
310  	 if(ret<=0) {
311  	   sprintf(xorriso->info_text, "Cannot open logfile:  %s", fileadr);
312  	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
313  	 } else if(!(hflag&(1<<15)))
314  	   if(Sfile_str(xorriso->logfile[channel_no], fileadr, 0)<=0)
315  	     return(-1);
316  	 return(ret>0);
317  	}
318  	
319  	
320  	/* Options -ls  alias -lsi   and -lsl  alias -lsli
321  	       and -lsd alias -lsdi  and -lsdl alias -lsdli
322  	       and -du  alias -dui   and -dus  alias -dusi
323  	   @param flag bit0= long format (-lsl , -du, not -dus, not -ls)
324  	               bit1= do not expand patterns but use literally
325  	               bit2= -du rather than -ls
326  	               bit3= list directories as themselves (-lsd) 
327  	*/
328  	int Xorriso_option_lsi(struct XorrisO *xorriso, int argc, char **argv,
329  	                      int *idx, int flag)
330  	{
331  	 int ret, end_idx, filec= 0, nump, i, star= 1;
332  	 char **filev= NULL, **patterns= NULL;
333  	 off_t mem= 0;
334  	 struct stat stbuf;
335  	
336  	 if(flag & 4) {
337  	   if(!(flag & 1))
338  	     star= 0;
339  	 } else {
340  	   if(flag & 8)
341  	     star= 0;
342  	 }
343  	
344  	 end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 1);
345  	 if(xorriso->do_iso_rr_pattern==0)
346  	   flag|= 2;
347  	
348  	 nump= end_idx - *idx;
349  	 if((flag&2) && nump>0 ) {
350  	   ;
351  	 } else if(nump <= 0) {
352  	   if(Xorriso_iso_lstat(xorriso, xorriso->wdi, &stbuf, 0)<0) {
353  	     sprintf(xorriso->info_text,
354  	             "Current -cd path does not yet exist in the ISO image");
355  	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
356  	     {ret= 0; goto ex;}
357  	   }
358  	   if(!S_ISDIR(stbuf.st_mode)) {
359  	     sprintf(xorriso->info_text,
360  	             "Current -cd meanwhile points to a non-directory in ISO image");
361  	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
362  	     {ret= 0; goto ex;}
363  	   }
364  	   patterns= calloc(1, sizeof(char *));
365  	   if(patterns == NULL) {
366  	no_memory:;
367  	     sprintf(xorriso->info_text,
368  	             "Cannot allocate enough memory for pattern expansion");
369  	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
370  	     {ret= -1; goto ex;}
371  	   }
372  	   nump= 1;
373  	   if(star)
374  	     patterns[0]= "*";
375  	   else 
376  	     patterns[0]= ".";
377  	   flag&= ~2;
378  	 } else {
379  	   patterns= calloc(nump, sizeof(char *));
380  	   if(patterns==NULL)
381  	     goto no_memory;
382  	   for(i= 0; i<nump; i++) {
383  	     if(argv[i + *idx][0]==0) {
384  	       if(star)
385  	         patterns[i]= "*";
386  	       else
387  	         patterns[i]= ".";
388  	     } else
389  	       patterns[i]= argv[i + *idx];
390  	   }
391  	 }
392  	
393  	 if((flag & 1) && !(xorriso->ino_behavior & 32)) {
394  	   ret= Xorriso_make_hln_array(xorriso, 0); /* for stbuf.st_nlink */
395  	   if(ret < 0)
396  	     goto ex;
397  	 }
398  	 if(flag&2) {
399  	   ret= Xorriso_ls_filev(xorriso, xorriso->wdi, nump, argv + (*idx), mem,
400  	                         flag&(1|4|8)); 
401  	 } else if(nump==1 && strcmp(patterns[0],"*")==0 && !(flag&4)){
402  	   /* save temporary memory by calling simpler function */
403  	   ret= Xorriso_ls(xorriso, (flag&1)|4);
404  	 } else {
405  	   ret= Xorriso_expand_pattern(xorriso, nump, patterns, 0, &filec, &filev,
406  	                               &mem, 0);
407  	   if(ret<=0)
408  	     {ret= 0; goto ex;}
409  	   ret= Xorriso_ls_filev(xorriso, xorriso->wdi, filec, filev, mem,
410  	                         flag&(1|4|8)); 
411  	 }
412  	 if(ret<=0)
413  	   {ret= 0; goto ex;}
414  	
415  	 ret= 1;
416  	ex:;
417  	 if(patterns!=NULL)
418  	   free((char *) patterns);
419  	 Sfile_destroy_argv(&filec, &filev, 0);
420  	 (*idx)= end_idx;
421  	 return(ret);
422  	}
423  	
424  	
425  	/* Options -lsx, -lslx, -lsdx , -lsdlx , -dux , -dusx
426  	   @param flag bit0= long format (-lslx , -dux)
427  	               bit1= do not expand patterns but use literally
428  	               bit2= du rather than ls
429  	               bit3= list directories as themselves (ls -d) 
430  	*/
431  	int Xorriso_option_lsx(struct XorrisO *xorriso, int argc, char **argv,
432  	                      int *idx, int flag)
433  	{
434  	 int ret, end_idx, filec= 0, nump, i;
435  	 char **filev= NULL, **patterns= NULL;
436  	 off_t mem= 0;
437  	
438  	 end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 1|2);
439  	 if(xorriso->do_disk_pattern==0)
440  	   flag|= 2;
441  	
442  	 nump= end_idx - *idx;
443  	 if((flag&2) && nump>0) {
444  	   ;
445  	 } else if(nump <= 0) {
446  	   patterns= calloc(1, sizeof(char *));
447  	   if(patterns == NULL) {
448  	no_memory:;
449  	     sprintf(xorriso->info_text,
450  	             "Cannot allocate enough memory for pattern expansion");
451  	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
452  	     {ret= -1; goto ex;}
453  	   }
454  	   nump= 1;
455  	   if(flag&8)
456  	     patterns[0]= ".";
457  	   else
458  	     patterns[0]= "*";
459  	   flag&= ~2;
460  	 } else {
461  	   patterns= calloc(nump, sizeof(char *));
462  	   if(patterns==NULL)
463  	     goto no_memory;
464  	   for(i= 0; i<nump; i++) {
465  	     if(argv[i + *idx][0]==0)
466  	       patterns[i]= "*";
467  	     else
468  	       patterns[i]= argv[i + *idx];
469  	   }
470  	 }
471  	 if(flag&2) {
472  	   ret= Xorriso_lsx_filev(xorriso, xorriso->wdx,
473  	                          nump, argv + (*idx), mem, flag&(1|4|8)); 
474  	
475  	#ifdef Not_yeT
476  	 } else if(nump==1 && strcmp(patterns[0],"*")==0 && !(flag&4)){
477  	   /* save temporary memory by calling simpler function */
478  	   ret= Xorriso_ls(xorriso, (flag&1)|4);
479  	#endif
480  	
481  	 } else {
482  	   ret= Xorriso_expand_disk_pattern(xorriso, nump, patterns, 0, &filec, &filev,
483  	                                    &mem, 0);
484  	   if(ret<=0)
485  	     {ret= 0; goto ex;}
486  	   ret= Xorriso_lsx_filev(xorriso, xorriso->wdx, filec, filev, mem,
487  	                          flag&(1|4|8)); 
488  	 }
489  	 if(ret<=0)
490  	   {ret= 0; goto ex;}
491  	
492  	 ret= 1;
493  	ex:;
494  	 if(patterns!=NULL)
495  	   free((char *) patterns);
496  	 Sfile_destroy_argv(&filec, &filev, 0);
497  	 (*idx)= end_idx;
498  	 return(ret);
499  	}
500  	
501  	
502  	/* Option -map , -map_single */
503  	/* @param flag bit0=do not report the added item
504  	               bit1=do not reset pacifier, no final pacifier message
505  	               bit5= -map_single: do not insert directory tree
506  	*/
507  	int Xorriso_option_map(struct XorrisO *xorriso, char *disk_path,
508  	                       char *iso_path, int flag)
509  	{
510  	 int ret;
511  	 char *eff_origin= NULL, *eff_dest= NULL, *ipth;
512  	
513  	 Xorriso_alloc_meM(eff_origin, char, SfileadrL);
514  	 Xorriso_alloc_meM(eff_dest, char, SfileadrL);
515  	
516  	 if(!(flag&2))
517  	   Xorriso_pacifier_reset(xorriso, 0);
518  	
519  	 ipth= iso_path;
520  	 if(ipth[0]==0)
521  	   ipth= disk_path;
522  	 if(disk_path[0]==0) {
523  	   sprintf(xorriso->info_text, "-map: Empty disk_path given");
524  	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 1);
525  	   {ret= 0; goto ex;}
526  	 }
527  	 ret= Xorriso_normalize_img_path(xorriso, xorriso->wdx, disk_path, eff_origin,
528  	                                 2|4);
529  	 if(ret<=0)
530  	   goto ex;
531  	 ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, ipth, eff_dest, 2);
532  	 if(ret<=0)
533  	   goto ex;
534  	 ret= Xorriso_graft_in(xorriso, NULL, eff_origin, eff_dest,
535  	                       (off_t) 0, (off_t) 0, 2|(flag&32));
536  	 if(!(flag&2))
537  	   Xorriso_pacifier_callback(xorriso, "files added", xorriso->pacifier_count,
538  	                             xorriso->pacifier_total, "", 1);
539  	 if(ret<=0)
540  	   goto ex;
541  	
542  	 if(!(flag&1)) {
543  	   sprintf(xorriso->info_text, "Added to ISO image: %s '%s'='%s'\n",
544  	           (ret>1 ? "directory" : "file"), (eff_dest[0] ? eff_dest : "/"),
545  	           eff_origin);
546  	   Xorriso_info(xorriso,0);
547  	 }
548  	 ret= 1;
549  	ex:;
550  	 Xorriso_free_meM(eff_origin);
551  	 Xorriso_free_meM(eff_dest);
552  	 return(ret);
553  	}
554  	
555  	
556  	/* Command -map_l , -compare_l , -update_l , -extract_l , -update_lxi ,
557  	           -update_li
558  	*/
559  	/* @param flag bit4= do not establish and dispose xorriso->di_array
560  	                     for update_l
561  	               bit8-11= mode 0= -map_l
562  	                             1= -compare_l
563  	                             2= -update_l
564  	                             3= -extract_l
565  	                             4= -update_lxi
566  	                             5= -update_li
567  	*/
568  	int Xorriso_option_map_l(struct XorrisO *xorriso, int argc, char **argv,
569  	                         int *idx, int flag)
570  	{
571  	 int ret, end_idx, optc= 0, was_failure= 1, i, j, fret, mode, problem_count;
572  	 int ns_flag= 2|4, nt_flag= 2, opt_args_flag= 2, arg2c= 0, opt2c= 0;
573  	 int new_opt2c;
574  	 char *source_prefix= NULL, *target_prefix= NULL, *cmd, **optv= NULL;
575  	 char *eff_source= NULL, *eff_target= NULL, *s_wd, *t_wd;
576  	 char **eff_src_array= NULL, **eff_tgt_array= NULL, **opt2v= NULL;
577  	 char **arg2v= NULL;
578  	
579  	 cmd= "-map_l";
580  	 s_wd= xorriso->wdx;
581  	 t_wd= xorriso->wdi;
582  	 Xorriso_pacifier_reset(xorriso, 0);
583  	 mode= (flag>>8) & 15;
584  	
585  	 if(mode==1)
586  	   cmd= "-compare_l";
587  	 else if(mode==2)
588  	   cmd= "-update_l";
589  	 else if(mode == 3 || mode == 5) {
590  	   if(mode == 5)
591  	     cmd= "-update_li";
592  	   else
593  	     cmd= "-extract_l";
594  	   ns_flag= 2;
595  	   s_wd= xorriso->wdi;
596  	   nt_flag= 2|4;
597  	   t_wd= xorriso->wdx;
598  	   opt_args_flag= 0;
599  	 } else if(mode == 4) {
600  	   cmd= "-update_lxi";
601  	 }
602  	
603  	 end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 1|2);
604  	 if(end_idx - (*idx) < 3) {
605  	   sprintf(xorriso->info_text, "%s: Not enough arguments given (%d < 3)", cmd,
606  	           end_idx - (*idx));
607  	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 1);
608  	   ret= 0; goto ex;
609  	 }
610  	
611  	 Xorriso_alloc_meM(source_prefix, char, SfileadrL);
612  	 Xorriso_alloc_meM(target_prefix, char, SfileadrL);
613  	 Xorriso_alloc_meM(eff_source, char, SfileadrL);
614  	 Xorriso_alloc_meM(eff_target, char, SfileadrL);
615  	
616  	 ret= Xorriso_normalize_img_path(xorriso, s_wd, argv[*idx],
617  	                                 source_prefix, ns_flag | 64);
618  	 if(ret<=0)
619  	   goto ex;
620  	 ret= Xorriso_normalize_img_path(xorriso, t_wd, argv[(*idx)+1],
621  	                                 target_prefix, nt_flag);
622  	 if(ret<=0)
623  	   goto ex;
624  	 ret= Xorriso_opt_args(xorriso, cmd, argc, argv, (*idx)+2, &end_idx,
625  	                       &optc, &optv, opt_args_flag);
626  	 if(ret<=0)
627  	   goto ex;
628  	 if(mode == 4) {
629  	   /* Convert pattern from disk to iso_rr */
630  	   arg2c= end_idx - *idx - 2;
631  	   Xorriso_alloc_meM(arg2v, char *, arg2c);
632  	   for(i = 0; i < arg2c; i++)
633  	     arg2v[i]= NULL;
634  	   arg2c= 0;
635  	   for(i = (*idx) + 2; i < end_idx; i++) {
636  	     ret= Xorriso_normalize_img_path(xorriso, s_wd, argv[i],
637  	                                     eff_source, ns_flag);
638  	     if(ret<=0)
639  	       goto ex;
640  	     ret= Xorriso__exchange_prefix(source_prefix, target_prefix,
641  	                                   eff_source, eff_target, 0);
642  	     if(ret <= 0)
643  	   continue;
644  	     Xorriso_alloc_meM(arg2v[arg2c], char, strlen(eff_target) + 1);
645  	     strcpy(arg2v[arg2c], eff_target);
646  	     arg2c++;
647  	   }
648  	   /* Expand wildcards in iso_rr, do not include unmatched patterns */
649  	   ret= Xorriso_opt_args(xorriso, cmd, arg2c, arg2v, 0, &i,
650  	                          &opt2c, &opt2v, (1 << 10) | (1 << 7));
651  	   if(ret<=0)
652  	     goto ex;
653  	   /* Convert from iso_rr path to disk path */
654  	   new_opt2c= 0;
655  	   for(i = 0; i < opt2c; i++) {
656  	     ret= Xorriso__exchange_prefix(target_prefix, source_prefix,
657  	                                   opt2v[i], eff_source, 0);
658  	     free(opt2v[i]);
659  	     opt2v[i]= NULL;
660  	     if(ret <= 0)
661  	   continue;
662  	     Xorriso_alloc_meM(opt2v[new_opt2c], char, strlen(eff_source) + 1);
663  	     strcpy(opt2v[new_opt2c], eff_source);
664  	     new_opt2c++;
665  	   }
666  	   opt2c= new_opt2c;
667  	   /* Merge both results */
668  	   if(opt2c > 0) {
669  	     Sfile_destroy_argv(&arg2c, &arg2v, 0);
670  	     Xorriso_alloc_meM(arg2v, char *, optc + opt2c);
671  	     for(i = 0; i < optc + opt2c; i++)
672  	       arg2v[i]= NULL;
673  	     arg2c= 0;
674  	     for(i= 0; i < optc; i++) {
675  	       ret= Xorriso_normalize_img_path(xorriso, s_wd, optv[i],
676  	                                       eff_source, ns_flag);
677  	       if(ret<=0)
678  	         goto ex;
679  	       Xorriso_alloc_meM(arg2v[arg2c], char, strlen(eff_source) + 1);
680  	       strcpy(arg2v[arg2c], eff_source);
681  	       arg2c++;
682  	     }
683  	     for(i= 0; i < opt2c; i++) {
684  	       for(j= 0; j < optc; j++)
685  	         if(strcmp(opt2v[i], arg2v[j]) == 0)
686  	       break;
687  	       if(j < optc)
688  	     continue;
689  	       arg2v[arg2c++]= opt2v[i];
690  	       opt2v[i]= NULL;
691  	     }
692  	     Sfile_destroy_argv(&optc, &optv, 0);
693  	     optv= arg2v;
694  	     arg2v= NULL;
695  	     optc= arg2c;
696  	     arg2c= 0;
697  	   }
698  	 }
699  	
700  	 if(mode == 3 &&
701  	    (xorriso->do_restore_sort_lba || !(xorriso->ino_behavior & 4))) {
702  	   eff_src_array= calloc(optc, sizeof(char *));
703  	   eff_tgt_array= calloc(optc, sizeof(char *));
704  	   if(eff_src_array == NULL || eff_tgt_array == NULL) {
705  	     Xorriso_no_malloc_memory(xorriso, NULL, 0);
706  	     ret= -1; goto ex;
707  	   }
708  	   for(i= 0; i < optc; i++)
709  	     eff_src_array[i]= eff_tgt_array[i]= NULL;
710  	 }
711  	 if((mode == 2 || mode == 4) &&
712  	     !((xorriso->ino_behavior & 2) || (flag & 16) ||
713  	       xorriso->di_array != NULL)) {
714  	   /* Create all-image node array sorted by isofs.di */
715  	   ret= Xorriso_make_di_array(xorriso, 0);
716  	   if(ret <= 0)
717  	     goto ex;
718  	 }
719  	
720  	 for(i= 0; i<optc; i++) {
721  	   ret= Xorriso_normalize_img_path(xorriso, s_wd, optv[i],
722  	                                   eff_source, ns_flag);
723  	   if(ret<=0)
724  	     goto ex;
725  	   ret= Xorriso__exchange_prefix(source_prefix, target_prefix,
726  	                                 eff_source, eff_target, 0);
727  	   if(ret == 0) {
728  	     sprintf(xorriso->info_text, "%s: disk_path ", cmd);
729  	     Text_shellsafe(eff_source, xorriso->info_text, 1);
730  	     strcat(xorriso->info_text, " does not begin with disk_prefix ");
731  	     Text_shellsafe(source_prefix, xorriso->info_text, 1);
732  	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 1);
733  	   }
734  	   if(ret <= 0)
735  	     goto ex;
736  	
737  	   if(mode==0)
738  	     ret= Xorriso_option_map(xorriso, eff_source, eff_target, 2);
739  	   else if(mode==1)
740  	     ret= Xorriso_option_compare(xorriso, eff_source, eff_target, 2|8);
741  	   else if(mode == 2 || mode == 4)
742  	     ret= Xorriso_option_update(xorriso, eff_source, eff_target, 2 | 8 | 16);
743  	   else if(mode==3) {
744  	     if(eff_src_array != NULL) {
745  	       eff_src_array[i]= strdup(eff_source);
746  	       eff_tgt_array[i]= strdup(eff_target);
747  	       if(eff_src_array[i] == NULL || eff_tgt_array[i] == NULL) {
748  	         Xorriso_no_malloc_memory(xorriso, &(eff_src_array[i]), 0);
749  	         ret= -1; goto ex;
750  	       }
751  	     } else {
752  	       ret= Xorriso_option_extract(xorriso, eff_source, eff_target, 2 | 4);
753  	     }
754  	   } else if(mode == 5) {
755  	     ret= Xorriso_option_update(xorriso, eff_target, eff_source, 2 | 8 | 16);
756  	   }
757  	
758  	   if(ret>0 && !xorriso->request_to_abort)
759  	 continue; /* regular bottom of loop */
760  	   was_failure= 1;
761  	   fret= Xorriso_eval_problem_status(xorriso, ret, 1 | 2);
762  	   if(fret>=0)
763  	 continue;
764  	   goto ex;
765  	 }
766  	
767  	 ret= 1;
768  	 if(mode == 3 && eff_src_array != NULL) {
769  	   ret= Xorriso_lst_append_binary(&(xorriso->node_disk_prefixes),
770  	                                  target_prefix, strlen(target_prefix) + 1, 0);
771  	   if(ret <= 0)
772  	     goto ex;
773  	   ret= Xorriso_lst_append_binary(&(xorriso->node_img_prefixes),
774  	                                  source_prefix, strlen(source_prefix) + 1, 0);
775  	   if(ret <= 0)
776  	     goto ex;
777  	   ret= Xorriso_restore_sorted(xorriso, optc, eff_src_array, eff_tgt_array,
778  	                               &problem_count, 0);
779  	   if(ret <= 0 || problem_count > 0)
780  	     was_failure= 1;
781  	 }
782  	 if(mode==0)
783  	   Xorriso_pacifier_callback(xorriso, "files added", xorriso->pacifier_count,
784  	                             xorriso->pacifier_total, "", 1);
785  	 else if(mode==1 || mode==2 || mode == 4 || mode == 5)
786  	   Xorriso_pacifier_callback(xorriso, "content bytes read",
787  	                             xorriso->pacifier_count, 0, "", 1 | 8 | 32);
788  	 else if(mode==3)
789  	   Xorriso_pacifier_callback(xorriso, "files restored",xorriso->pacifier_count,
790  	                             xorriso->pacifier_total, "", 1|4);
791  	ex:;
792  	 Xorriso_destroy_node_array(xorriso, 0);
793  	 i= optc;
794  	 Sfile_destroy_argv(&i, &eff_src_array, 0);
795  	 i= optc;
796  	 Sfile_destroy_argv(&i, &eff_tgt_array, 0);
797  	 Xorriso_free_meM(source_prefix);
798  	 Xorriso_free_meM(target_prefix);
799  	 Xorriso_free_meM(eff_source);
800  	 Xorriso_free_meM(eff_target);
801  	 (*idx)= end_idx;
802  	 Xorriso_opt_args(xorriso, cmd, argc, argv, *idx, &end_idx, &optc, &optv, 256);
803  	 Xorriso_opt_args(xorriso, cmd, argc, argv, *idx, &end_idx, &opt2c, &opt2v,
804  	                  256);
805  	 if(arg2c > 0)
806  	   Sfile_destroy_argv(&arg2c, &arg2v, 0);
807  	 else if(arg2v != NULL)
808  	   Xorriso_free_meM(arg2v);
809  	
810  	 if(ret<=0)
811  	   return(ret);
812  	 return(!was_failure);
813  	}
814  	
815  	
816  	/* Option -mark */
817  	int Xorriso_option_mark(struct XorrisO *xorriso, char *mark, int flag)
818  	{
819  	 if(mark[0]==0)
820  	   xorriso->mark_text[0]= 0;
821  	 else
822  	   strncpy(xorriso->mark_text,mark,sizeof(xorriso->mark_text)-1);
823  	 xorriso->mark_text[sizeof(xorriso->mark_text)-1]= 0;
824  	 return(1);
825  	}
826  	
827  	
828  	/* Option -md5 "on"|"all"|"off" */
829  	int Xorriso_option_md5(struct XorrisO *xorriso, char *mode, int flag)
830  	{
831  	 char *npt, *cpt;
832  	 int l;
833  	
834  	 npt= cpt= mode;
835  	 for(; npt!=NULL; cpt= npt+1) {
836  	   npt= strchr(cpt,':');
837  	   if(npt==NULL)
838  	     l= strlen(cpt);
839  	   else
840  	     l= npt-cpt;
841  	   if(l == 0)
842  	 continue;
843  	   if(l == 3 && strncmp(cpt, "off", l) == 0)
844  	     xorriso->do_md5&= ~31;
845  	   else if(l == 2 && strncmp(cpt, "on", l) == 0)
846  	     xorriso->do_md5= (xorriso->do_md5 & ~31) | 7 | 16;
847  	   else if(l == 3 && strncmp(cpt, "all", l) == 0)
848  	     xorriso->do_md5|= 31;
849  	   else if(l == 18 && strncmp(cpt, "stability_check_on", l) == 0)
850  	     xorriso->do_md5|= 8;
851  	   else if(l == 19 && strncmp(cpt, "stability_check_off", l) == 0)
852  	     xorriso->do_md5&= ~8;
853  	   else if(l == 13 && strncmp(cpt, "load_check_on", l) == 0)
854  	     xorriso->do_md5&= ~32;
855  	   else if(l == 14 && strncmp(cpt, "load_check_off", l) == 0)
856  	     xorriso->do_md5|= 32;
857  	   else {
858  	     sprintf(xorriso->info_text, "-md5: unknown mode ");
859  	     Text_shellsafe(cpt, xorriso->info_text, 1);
860  	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
861  	     return(0);
862  	   }
863  	 }
864  	 return(1);
865  	}
866  	
867  	
868  	/* Option -mkdir alias -mkdiri */
869  	int Xorriso_option_mkdiri(struct XorrisO *xorriso, int argc, char **argv,
870  	                          int *idx, int flag)
871  	{
872  	 int i, end_idx, ret, was_failure= 0, fret;
873  	
874  	 end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 0);
875  	
876  	 for(i= *idx; i<end_idx; i++) {
877  	   ret= Xorriso_mkdir(xorriso, argv[i], 0);
878  	   if(ret>0 && !xorriso->request_to_abort)
879  	 continue; /* regular bottom of loop */
880  	   was_failure= 1;
881  	   fret= Xorriso_eval_problem_status(xorriso, ret, 1|2);
882  	   if(fret>=0)
883  	 continue;
884  	   goto ex;
885  	 }
886  	 ret= 1; 
887  	ex:;
888  	 (*idx)= end_idx;
889  	 if(ret<=0)
890  	   return(ret);
891  	 return(!was_failure);
892  	}
893  	
894  	
895  	int Xorriso_option_modesty_on_drive(struct XorrisO *xorriso, char *mode,
896  	                                    int flag)
897  	{
898  	 char *npt, *cpt, *ppt;
899  	 int l, num, set_min;
900  	
901  	 npt= cpt= mode;
902  	 for(; npt!=NULL; cpt= npt+1) {
903  	   npt= strchr(cpt,':');
904  	   if(npt==NULL)
905  	     l= strlen(cpt);
906  	   else
907  	     l= npt-cpt;
908  	   if(l == 0)
909  	 continue;
910  	   if(l == 3 && strncmp(cpt, "off", l) == 0) {
911  	     xorriso->modesty_on_drive= 0;
912  	   } else if(l == 1 && strncmp(cpt, "0", l) == 0) {
913  	     xorriso->modesty_on_drive= 0;
914  	   } else if(l == 2 && strncmp(cpt, "on", l) == 0) {
915  	     xorriso->modesty_on_drive= 1;
916  	   } else if(l == 1 && strncmp(cpt, "1", l) == 0) {
917  	     xorriso->modesty_on_drive= 1;
918  	   } else if(l == 2 && strncmp(cpt, "-1", l) == 0) {
919  	     ;
920  	   } else if(*cpt >= '1' && *cpt <= '9') {
921  	     ppt= cpt;
922  	     set_min= 2;
923  	set_size_percent:;
924  	     sscanf(ppt, "%d", &num);
925  	     if(num == -1) {
926  	       ;
927  	     } else if(num < 25) {
928  	bad_percent:;
929  	       sprintf(xorriso->info_text, "-modesty_on_drive: percentage out of range [25 to 100]");
930  	       Text_shellsafe(cpt, xorriso->info_text, 1);
931  	       Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
932  	       return(0);
933  	     } else if(num > 100) {
934  	       goto bad_percent;
935  	     }
936  	     if(set_min == 2) {
937  	       xorriso->modesty_on_drive= 1;
938  	     }
939  	     if(set_min)
940  	       xorriso->min_buffer_percent= num;
941  	     else
942  	       xorriso->max_buffer_percent= num;
943  	   } else if(l >= 12 && strncmp(cpt, "min_percent=", 12) == 0) {
944  	     ppt= cpt + 12;
945  	     set_min= 1;
946  	     goto set_size_percent;
947  	   } else if(l >= 12 && strncmp(cpt, "max_percent=", 12) == 0) {
948  	     ppt= cpt + 12;
949  	     set_min= 0;
950  	     goto set_size_percent;
951  	   } else if(l >= 9 && strncmp(cpt, "min_usec=", 9) == 0) {
952  	     ppt= cpt + 9;
953  	     set_min= 1;
954  	set_sec:;
955  	     num= -1;
956  	     sscanf(ppt, "%d", &num);
957  	     if(num < 0)
958  	       num= 0;
959  	     if(set_min == 2)
960  	       xorriso->max_buffer_usec= num;
961  	     else if(set_min == 1)
962  	       xorriso->min_buffer_usec= num;
963  	     else if(set_min == 0)
964  	       xorriso->max_buffer_percent= num;
965  	     else
966  	       xorriso->buffer_timeout_sec= num;
967  	   } else if(l >= 9 && strncmp(cpt, "max_usec=", 9) == 0) {
968  	     ppt= cpt + 9;
969  	     set_min= 2;
970  	     goto set_sec;
971  	   } else if(l >= 12 && strncmp(cpt, "timeout_sec=", 12) == 0) {
972  	     ppt= cpt + 12;
973  	     set_min= -1;
974  	     goto set_sec;
975  	   } else {
976  	     sprintf(xorriso->info_text, "-modesty_on_drive: unknown mode ");
977  	     Text_shellsafe(cpt, xorriso->info_text, 1);
978  	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
979  	     return(0);
980  	   }
981  	 }
982  	 return(1);
983  	}
984  	
985  	
986  	/* Options -mount , -mount_cmd , -session_string */
987  	/* @param bit0= -mount_cmd: print mount command to result channel rather
988  	                            than performing it
989  	          bit1= perform -session_string rather than -mount_cmd
990  	*/
991  	int Xorriso_option_mount(struct XorrisO *xorriso, char *dev, char *adr_mode,
992  	                         char *adr, char *cmd, int flag)
993  	{
994  	 int ret, entity_code= 0, m_flag;
995  	 char entity_id[81], *mnt;
996  	
997  	 if(flag & 1)
998  	   mnt= "-mount_cmd";
999  	 else if(flag & 2)
1000 	   mnt= "-session_string";
1001 	 else {
1002 	   mnt= "-mount";
1003 	   if(xorriso->allow_restore <= 0) {
1004 	     sprintf(xorriso->info_text,
1005 	          "-mount: image-to-disk features are not enabled by option -osirrox");
1006 	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1007 	     return(0);
1008 	   }
1009 	   if(Xorriso_change_is_pending(xorriso, 0)) {
1010 	     sprintf(xorriso->info_text,
1011 	             "%s: Image changes pending. -commit or -rollback first", mnt);
1012 	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1013 	     return(0);
1014 	   }
1015 	 }
1016 	 ret= Xorriso_decode_load_adr(xorriso, mnt, adr_mode, adr,
1017 	                              &entity_code, entity_id, 0);
1018 	 if(ret <= 0)
1019 	   return(ret);
1020 	 if(flag & 2)
1021 	   m_flag= 1 | 4;
1022 	 else
1023 	   m_flag= (flag & 1) | 2;
1024 	 ret= Xorriso_mount(xorriso, dev, entity_code, entity_id, cmd, m_flag);
1025 	 return(ret);
1026 	}
1027 	
1028 	
1029 	/* Option -mount_opts option[:...] */
1030 	int Xorriso_option_mount_opts(struct XorrisO *xorriso, char *mode, int flag)
1031 	{
1032 	 int was, l;
1033 	 char *cpt, *npt;
1034 	
1035 	 was= xorriso->mount_opts_flag;
1036 	 npt= cpt= mode;
1037 	 for(cpt= mode; npt!=NULL; cpt= npt+1) {
1038 	   npt= strchr(cpt,':');
1039 	   if(npt==NULL)
1040 	     l= strlen(cpt);
1041 	   else
1042 	     l= npt-cpt;
1043 	   if(l==0)
1044 	     goto unknown_mode;
1045 	   if(strncmp(cpt, "shared", l)==0) {
1046 	     xorriso->mount_opts_flag|= 1;
1047 	   } else if(strncmp(cpt, "exclusive", l)==0) {
1048 	     xorriso->mount_opts_flag&= ~1;
1049 	   } else {
1050 	unknown_mode:;
1051 	     if(l<SfileadrL)
1052 	       sprintf(xorriso->info_text, "-mount_opts: unknown option '%s'", cpt);
1053 	     else
1054 	       sprintf(xorriso->info_text, "-mount_opts: oversized parameter (%d)",l);
1055 	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1056 	     xorriso->mount_opts_flag= was;
1057 	     return(0);
1058 	   }
1059 	 }
1060 	 return(1);
1061 	}
1062 	
1063 	
1064 	/* Command -move */
1065 	int Xorriso_option_move(struct XorrisO *xorriso, char *origin, char *dest,
1066 	                        int flag)
1067 	{
1068 	 int ret;
1069 	 char *eff_origin= NULL, *eff_dest= NULL;
1070 	
1071 	 Xorriso_alloc_meM(eff_origin, char, SfileadrL);
1072 	 Xorriso_alloc_meM(eff_dest, char, SfileadrL);
1073 	
1074 	 ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, origin, eff_origin, 0);
1075 	 if(ret <= 0)
1076 	   {ret= 0; goto ex;}
1077 	 ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, dest, eff_dest, 2);
1078 	 if(ret < 0)
1079 	   {ret= 0; goto ex;}
1080 	 ret= Xorriso_rename(xorriso, NULL, eff_origin, eff_dest, 0);
1081 	 if(ret <= 0)
1082 	   goto ex;
1083 	 ret= 1;
1084 	ex:;
1085 	 Xorriso_free_meM(eff_origin);
1086 	 Xorriso_free_meM(eff_dest);
1087 	 return(ret);
1088 	}
1089 	
1090 	 
1091 	/* Command -msg_op */
1092 	int Xorriso_option_msg_op(struct XorrisO *xorriso, char *what, char *arg,
1093 	                          int flag)
1094 	{
1095 	 int ret, available, argc, pargc, i, pflag, max_words, input_lines, msd_mem;
1096 	 char **argv= NULL, **pargv= NULL, *msg= "";
1097 	 char *prefix, *separators;
1098 	
1099 	 msd_mem= xorriso->msg_sieve_disabled;
1100 	
1101 	 ret= 1;
1102 	 if(strcmp(what, "parse") == 0 || strcmp(what, "parse_silently") == 0 ||
1103 	    strcmp(what, "parse_bulk") == 0 ||
1104 	    strcmp(what, "parse_bulk_silently") == 0) {
1105 	   ret= Xorriso_parse_line(xorriso, arg, "", "", 5, &argc, &argv, 0);
1106 	   prefix= "";
1107 	   if(argc > 0) 
1108 	     prefix= argv[0];
1109 	   separators= "";
1110 	   if(argc > 1)
1111 	     separators= argv[1];
1112 	   max_words= 0;
1113 	   if(argc > 2)
1114 	     sscanf(argv[2], "%d", &max_words);
1115 	   pflag= 0;
1116 	   if(argc > 3)
1117 	     sscanf(argv[3], "%d", &pflag);
1118 	   input_lines= 1;
1119 	   if(argc > 4)
1120 	     sscanf(argv[4], "%d", &input_lines);
1121 	   if(strcmp(what, "parse") == 0 || strcmp(what, "parse_silently") == 0) {
1122 	     ret= Xorriso_msg_op_parse(xorriso, "", prefix, separators,
1123 	                               max_words, pflag, input_lines,
1124 	                               (strcmp(what, "parse_silently") == 0));
1125 	   } else {
1126 	     ret= Xorriso_msg_op_parse_bulk(xorriso, prefix, separators,
1127 	                               max_words, pflag, input_lines,
1128 	                               (strcmp(what, "parse_bulk_silently") == 0));
1129 	   }
1130 	   if(ret <= 0)
1131 	     goto ex;
1132 	   xorriso->msg_sieve_disabled= msd_mem;
1133 	   Xorriso__dispose_words(&argc, &argv);
1134 	 } else if(strcmp(what, "start_sieve") == 0) {
1135 	   Xorriso_sieve_dispose(xorriso, 0);
1136 	   ret= Xorriso_sieve_big(xorriso, 0);
1137 	   msg= "Message sieve enabled";
1138 	
1139 	/* >>> } else if(strcmp(what, "add_filter_rule") == 0) { */;
1140 	
1141 	 } else if(strcmp(what, "clear_sieve") == 0) {
1142 	   ret= Xorriso_sieve_clear_results(xorriso, 0);
1143 	   msg= "Recorded message sieve results disposed";
1144 	 } else if(strcmp(what, "end_sieve") == 0) {
1145 	   ret= Xorriso_sieve_dispose(xorriso, 0);
1146 	   msg= "Message sieve disabled";
1147 	 } else if(strcmp(what, "read_sieve") == 0) {
1148 	   ret= Xorriso_sieve_get_result(xorriso, arg, &pargc, &pargv, &available, 0);
1149 	   xorriso->msg_sieve_disabled= 1;
1150 	   sprintf(xorriso->result_line, "%d\n", ret);
1151 	   Xorriso_result(xorriso, 1);
1152 	   if(ret > 0) {
1153 	     sprintf(xorriso->result_line, "%d\n", pargc);
1154 	     Xorriso_result(xorriso, 1);
1155 	     for(i= 0; i < pargc; i++) {
1156 	       ret= Sfile_count_char(pargv[i], '\n') + 1;
1157 	       sprintf(xorriso->result_line, "%d\n", ret);
1158 	       Xorriso_result(xorriso, 1);
1159 	       Sfile_str(xorriso->result_line, pargv[i], 0);
1160 	       strcat(xorriso->result_line, "\n");
1161 	       Xorriso_result(xorriso, 1);
1162 	     }
1163 	   } else {
1164 	     strcpy(xorriso->result_line, "0\n");
1165 	     Xorriso_result(xorriso, 1);
1166 	     available= 0;
1167 	   }
1168 	   sprintf(xorriso->result_line, "%d\n", available);
1169 	   Xorriso_result(xorriso, 1);
1170 	   xorriso->msg_sieve_disabled= msd_mem;
1171 	   Xorriso__dispose_words(&pargc, &pargv);
1172 	   ret= 1;
1173 	 } else if(strcmp(what, "show_sieve") == 0) {
1174 	   ret= Xorriso_sieve_get_result(xorriso, "", &pargc, &pargv, &available, 8);
1175 	   xorriso->msg_sieve_disabled= 1;
1176 	   sprintf(xorriso->result_line, "%d\n", ret);
1177 	   Xorriso_result(xorriso, 1);
1178 	   if(ret > 0) {
1179 	     sprintf(xorriso->result_line, "%d\n", pargc);
1180 	     Xorriso_result(xorriso, 1);
1181 	     for(i= 0; i < pargc; i++) {
1182 	       sprintf(xorriso->result_line, "%s\n", pargv[i]);
1183 	       Xorriso_result(xorriso, 1);
1184 	     }
1185 	   }
1186 	   xorriso->msg_sieve_disabled= msd_mem;
1187 	   Xorriso__dispose_words(&pargc, &pargv);
1188 	 } else if(strcmp(what, "compare_sev") == 0) {
1189 	   ret= Xorriso_parse_line(xorriso, arg, "", ",", 2, &argc, &argv, 0);
1190 	   if(argc < 2) {
1191 	     sprintf(xorriso->info_text,
1192 	             "-msg_op cmp_sev: malformed severity pair '%s'", arg);
1193 	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
1194 	   } else {
1195 	     ret= Xorriso__severity_cmp(argv[0], argv[1]);
1196 	     sprintf(xorriso->result_line, "%d\n", ret);
1197 	     Xorriso_result(xorriso, 1);
1198 	   }
1199 	   Xorriso__dispose_words(&argc, &argv);
1200 	 } else if(strcmp(what, "list_sev") == 0) {
1201 	   sprintf(xorriso->result_line, "%s\n", Xorriso__severity_list(0));
1202 	   Xorriso_result(xorriso, 1);
1203 	 } else {
1204 	   sprintf(xorriso->info_text, "-msg_op: unknown operation '%s'", what);
1205 	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
1206 	   ret= 0;
1207 	 }
1208 	 if(ret > 0 && msg[0])
1209 	   Xorriso_msgs_submit(xorriso, 0, msg, 0, "NOTE", 0);
1210 	
1211 	ex:;
1212 	 xorriso->msg_sieve_disabled= msd_mem;
1213 	 return(ret);
1214 	}
1215 	
1216 	
1217 	/* Option -mv alias -mvi */
1218 	int Xorriso_option_mvi(struct XorrisO *xorriso, int argc, char **argv,
1219 	                      int *idx, int flag)
1220 	{
1221 	 int i, end_idx_dummy, ret, is_dir= 0, was_failure= 0, fret;
1222 	 char *eff_origin= NULL, *eff_dest= NULL, *dest_dir= NULL;
1223 	 char *leafname= NULL;
1224 	 int optc= 0;
1225 	 char **optv= NULL;
1226 	
1227 	 Xorriso_alloc_meM(eff_origin, char, SfileadrL);
1228 	 Xorriso_alloc_meM(eff_dest, char, SfileadrL);
1229 	 Xorriso_alloc_meM(dest_dir, char, SfileadrL);
1230 	 Xorriso_alloc_meM(leafname, char, SfileadrL);
1231 	
1232 	 ret= Xorriso_cpmv_args(xorriso, "-mvi", argc, argv, idx,
1233 	                        &optc, &optv, eff_dest, 0);
1234 	 if(ret<=0)
1235 	   goto ex;
1236 	 if(ret==2) {
1237 	   is_dir= 1;
1238 	   strcpy(dest_dir, eff_dest);
1239 	 }
1240 	 /* Perform movements */
1241 	 for(i= 0; i<optc; i++) {
1242 	   ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi,optv[i],eff_origin,0);
1243 	   if(ret<=0 || xorriso->request_to_abort)
1244 	     goto problem_handler;
1245 	   if(is_dir) {
1246 	     ret= Sfile_leafname(eff_origin, leafname, 0);
1247 	     if(ret<=0)
1248 	       goto problem_handler;
1249 	     strcpy(eff_dest, dest_dir);
1250 	     ret= Sfile_add_to_path(eff_dest, leafname, 0);
1251 	     if(ret<=0) {
1252 	       sprintf(xorriso->info_text, "Effective path gets much too long (%d)",
1253 	             (int) (strlen(eff_dest)+strlen(leafname)+1));
1254 	       Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1255 	       goto problem_handler;
1256 	     }
1257 	   }
1258 	   ret= Xorriso_rename(xorriso, NULL, eff_origin, eff_dest, 0);
1259 	   if(ret<=0 || xorriso->request_to_abort)
1260 	     goto problem_handler;
1261 	   sprintf(xorriso->info_text, "Renamed in ISO image: ");
1262 	   Text_shellsafe(eff_origin, xorriso->info_text, 1);
1263 	   strcat(xorriso->info_text, " to ");
1264 	   Text_shellsafe(eff_dest, xorriso->info_text, 1 | 2);
1265 	   strcat(xorriso->info_text, "\n");
1266 	   Xorriso_info(xorriso, 0);
1267 	
1268 	 continue; /* regular bottom of loop */
1269 	problem_handler:;
1270 	   was_failure= 1;
1271 	   fret= Xorriso_eval_problem_status(xorriso, ret, 1|2);
1272 	   if(fret>=0)
1273 	 continue;
1274 	   goto ex;
1275 	 }
1276 	 ret= !was_failure;
1277 	ex:;
1278 	 Xorriso_free_meM(eff_origin);
1279 	 Xorriso_free_meM(eff_dest);
1280 	 Xorriso_free_meM(dest_dir);
1281 	 Xorriso_free_meM(leafname);
1282 	 Xorriso_opt_args(xorriso, "-mvi",
1283 	                  argc, argv, *idx, &end_idx_dummy, &optc, &optv, 256);
1284 	 return(ret);
1285 	}
1286 	
1287 	
1288 	/* Option -named_pipe_loop */
1289 	int Xorriso_option_named_pipe_loop(struct XorrisO *xorriso, char *mode,
1290 	                                   char *stdin_pipe, char *stdout_pipe,
1291 	                                   char *stderr_pipe, int flag)
1292 	{
1293 	 char *pipe_paths[3], *cpt, *npt;
1294 	 int ret, hflag= 0, l;
1295 	
1296 	 npt= mode;
1297 	 for(cpt= mode; npt != NULL; cpt= npt + 1) {
1298 	   npt= strchr(cpt, ':');
1299 	   if(npt==NULL)
1300 	     l= strlen(cpt);
1301 	   else
1302 	     l= npt-cpt;
1303 	   if(l==0) {
1304 	     ;
1305 	   } else if(strncmp(cpt, "-", l) == 0) {
1306 	     ;
1307 	   } else if(strncmp(cpt, "cleanup", l) == 0) {
1308 	     hflag|= 1;
1309 	   } else if(strncmp(cpt, "keep", l) == 0) {
1310 	     hflag&= ~1;
1311 	   } else if(strncmp(cpt, "buffered", l) == 0) {
1312 	     hflag|= 2;
1313 	   } else if(strncmp(cpt, "direct", l) == 0) {
1314 	     hflag&= ~2;
1315 	   } else { 
1316 	     sprintf(xorriso->info_text, "-named_pipe_loop: unknown mode in '%s'",
1317 	             mode);
1318 	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1319 	     return(0);
1320 	   }
1321 	 }
1322 	 pipe_paths[0]= stdin_pipe;
1323 	 pipe_paths[1]= stdout_pipe;
1324 	 pipe_paths[2]= stderr_pipe;
1325 	 ret= Xorriso_named_pipe_loop(xorriso, pipe_paths, hflag);
1326 	 return(ret);
1327 	}
1328 	
1329 	
1330 	/* Option -no_rc */
1331 	int Xorriso_option_no_rc(struct XorrisO *xorriso, int flag)
1332 	{
1333 	 xorriso->no_rc= 1;
1334 	 return(1);
1335 	}
1336 	
1337 	
1338 	/* Option -not_leaf , (-hide_disk_leaf , -as mkisofs -hide) */
1339 	/* @param flag  bit0-bit5= hide rather than adding to disk_exclusions
1340 	                  bit0= add to iso_rr_hidings
1341 	                  bit1= add to joliet_hidings
1342 	                  bit2= add to hfsplus_hidings
1343 	*/
1344 	int Xorriso_option_not_leaf(struct XorrisO *xorriso, char *pattern, int flag)
1345 	{
1346 	 regex_t re;
1347 	 char *regexpr= NULL;
1348 	 int ret= 0;
1349 	
1350 	 Xorriso_alloc_meM(regexpr, char, 2 * SfileadrL + 2);
1351 	
1352 	 if(pattern[0]==0)
1353 	   {ret= 0; goto cannot_add;}
1354 	 Xorriso__bourne_to_reg(pattern, regexpr, 0);
1355 	 if(regcomp(&re, regexpr, 0)!=0)
1356 	   {ret= 0; goto cannot_add;}
1357 	 if(flag & 63) {
1358 	   if(flag & 1) {
1359 	     ret= Exclusions_add_not_leafs(xorriso->iso_rr_hidings, pattern, &re, 0);
1360 	     if(ret<=0)
1361 	       goto cannot_add;
1362 	   }
1363 	   if(flag & 2) {
1364 	     ret= Exclusions_add_not_leafs(xorriso->joliet_hidings, pattern, &re, 0);
1365 	     if(ret<=0)
1366 	       goto cannot_add;
1367 	   }
1368 	   if(flag & 4) {
1369 	     ret= Exclusions_add_not_leafs(xorriso->hfsplus_hidings, pattern, &re, 0);
1370 	     if(ret<=0)
1371 	       goto cannot_add;
1372 	   }
1373 	 } else {
1374 	   ret= Exclusions_add_not_leafs(xorriso->disk_exclusions, pattern, &re, 0);
1375 	 }
1376 	 if(ret<=0) {
1377 	cannot_add:;
1378 	   sprintf(xorriso->info_text,"Cannot add pattern: %s ",
1379 	           (flag & 3) ? "-hide_disk_leaf" : "-not_leaf");
1380 	   Text_shellsafe(pattern, xorriso->info_text, 1);
1381 	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1382 	   goto ex;
1383 	 }
1384 	 ret= 1;
1385 	ex:;
1386 	 Xorriso_free_meM(regexpr);
1387 	 return(ret);
1388 	}
1389 	
1390 	
1391 	/* Option -not_list , -quoted_not_list */
1392 	/* @param flag bit0= -quoted_not_list */
1393 	int Xorriso_option_not_list(struct XorrisO *xorriso, char *adr, int flag)
1394 	{
1395 	 int ret, linecount= 0, insertcount= 0, null= 0, argc= 0, i;
1396 	 FILE *fp= NULL;
1397 	 char **argv= NULL;
1398 	 
1399 	 Xorriso_pacifier_reset(xorriso, 0);
1400 	 if(adr[0]==0) {
1401 	   sprintf(xorriso->info_text, "Empty file name given with %s",
1402 	           (flag & 1) ? "-quoted_not_list" : "-not_list");
1403 	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1404 	   return(0);
1405 	 }
1406 	 ret= Xorriso_afile_fopen(xorriso, adr, "rb", &fp, 0);
1407 	 if(ret <= 0)
1408 	   return(0);
1409 	 while(1) {
1410 	   ret= Xorriso_read_lines(xorriso, fp, &linecount, &argc, &argv,
1411 	                           4 | (flag & 1) );
1412 	   if(ret <= 0)
1413 	     goto ex;
1414 	   if(ret == 2)
1415 	 break;
1416 	   for(i= 0; i < argc; i++) {
1417 	     if(argv[i][0] == 0)
1418 	   continue;
1419 	     if(strchr(argv[i], '/')!=NULL) {
1420 	       null= 0;
1421 	       ret= Xorriso_option_not_paths(xorriso, 1, argv + i, &null, 0);
1422 	     } else
1423 	       ret= Xorriso_option_not_leaf(xorriso, argv[i], 0);
1424 	     if(ret<=0)
1425 	       goto ex;
1426 	     insertcount++;
1427 	   }
1428 	 }
1429 	 ret= 1;
1430 	ex:;
1431 	 Xorriso_read_lines(xorriso, fp, &linecount, &argc, &argv, 2);
1432 	 if(fp != NULL && fp != stdin)
1433 	   fclose(fp);
1434 	 if(ret<=0) {
1435 	   sprintf(xorriso->info_text, "Aborted reading of file ");
1436 	   Text_shellsafe(adr, xorriso->info_text, 1);
1437 	   sprintf(xorriso->info_text + strlen(xorriso->info_text),
1438 	           " in line number %d", linecount);
1439 	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1440 	 }
1441 	 sprintf(xorriso->info_text, "Added %d exclusion list items from file ",
1442 	         insertcount);
1443 	 Text_shellsafe(adr, xorriso->info_text, 1);
1444 	 strcat(xorriso->info_text, "\n");
1445 	 Xorriso_info(xorriso,0);
1446 	 return(ret);
1447 	}
1448 	
1449 	
1450 	/* Option -not_mgt */
1451 	int Xorriso_option_not_mgt(struct XorrisO *xorriso, char *setting, int flag)
1452 	{
1453 	 int ret;
1454 	 char *what_data= NULL, *what, *what_next;
1455 	
1456 	 Xorriso_alloc_meM(what_data, char, SfileadrL);
1457 	
1458 	 if(Sfile_str(what_data, setting, 0)<=0) {
1459 	   sprintf(xorriso->info_text,
1460 	           "-not_mgt: setting string is much too long (%d)",
1461 	           (int) strlen(setting));
1462 	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1463 	   {ret= 0; goto ex;}
1464 	 } 
1465 	 for(what= what_data; what!=NULL; what= what_next) {
1466 	   what_next= strchr(what, ':');
1467 	   if(what_next!=NULL) {
1468 	     *what_next= 0;
1469 	     what_next++;
1470 	   }
1471 	
1472 	   if(strcmp(what, "reset")==0 || strcmp(what, "erase")==0) {
1473 	     if(strcmp(what, "reset")==0)
1474 	       xorriso->disk_excl_mode= 1;
1475 	     Exclusions_destroy(&(xorriso->disk_exclusions), 0);
1476 	     ret= Exclusions_new(&(xorriso->disk_exclusions), 0);
1477 	     if(ret<=0) {
1478 	       Xorriso_no_malloc_memory(xorriso, NULL, 0);
1479 	       goto ex;
1480 	     }
1481 	   } else if(strcmp(what, "on")==0) {
1482 	     xorriso->disk_excl_mode|= 1;
1483 	   } else if(strcmp(what, "off")==0) {
1484 	     xorriso->disk_excl_mode&= ~1;
1485 	   } else if(strcmp(what, "param_on")==0) {
1486 	     xorriso->disk_excl_mode|= 2;
1487 	   } else if(strcmp(what, "param_off")==0) {
1488 	     xorriso->disk_excl_mode&= ~2;
1489 	   } else if(strcmp(what, "subtree_on")==0) {
1490 	     xorriso->disk_excl_mode|= 4;
1491 	   } else if(strcmp(what, "subtree_off")==0) {
1492 	     xorriso->disk_excl_mode&= ~4;
1493 	   } else if(strcmp(what, "ignore_on")==0) {
1494 	     xorriso->disk_excl_mode|= 8;
1495 	   } else if(strcmp(what, "ignore_off")==0) {
1496 	     xorriso->disk_excl_mode&= ~8;
1497 	   } else {
1498 	     sprintf(xorriso->info_text, "-not_mgt: unknown setting '%s'", what);
1499 	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1500 	     {ret= 0; goto ex;}
1501 	   }
1502 	 }
1503 	 ret= 1;
1504 	ex:;
1505 	 Xorriso_free_meM(what_data);
1506 	 return(ret);
1507 	}
1508 	
1509 	
1510 	/* Option -not_paths , (-hide_disk_paths , -as mkisofs -hide) */
1511 	/* @param flag  bit0= add to iso_rr_hidings rather than disk_exclusions
1512 	                bit1= add to joliet_hidings rather than disk_exclusions
1513 	                bit2= enable disk pattern expansion regardless of -disk_pattern
1514 	                bit8-13= consolidated hide state bits, duplicating bit0-1
1515 	                   bit8= add to iso_rr_hidings
1516 	                   bit9= add to joliet_hidings
1517 	                  bit10= add to hfsplus_hidings
1518 	*/
1519 	int Xorriso_option_not_paths(struct XorrisO *xorriso, int argc, char **argv,
1520 	                             int *idx, int flag)
1521 	{
1522 	 int ret, end_idx, num_descr= 0, dummy, optc= 0, i;
1523 	 char **descr= NULL, **optv= NULL, *eff_path= NULL, *hpt= NULL;
1524 	
1525 	 end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx,
1526 	                          (xorriso->do_disk_pattern == 1 || (flag & 4)) | 2);
1527 	 if(end_idx<=0)
1528 	   {ret= end_idx; goto ex;}
1529 	
1530 	 num_descr= end_idx - *idx;
1531 	 if(num_descr<=0)
1532 	   {ret= 1; goto ex;}
1533 	 
1534 	 /* produce absolute patterns */
1535 	 Xorriso_alloc_meM(eff_path, char, SfileadrL);
1536 	 descr= TSOB_FELD(char *, num_descr);
1537 	 if(descr==NULL) {
1538 	no_memory:;
1539 	   Xorriso_no_pattern_memory(xorriso, sizeof(char *) * (off_t) num_descr, 0);
1540 	   ret= -1; goto ex;
1541 	 }
1542 	 for(i= 0; i<num_descr; i++)
1543 	   descr[i]= NULL;
1544 	 for(i= 0; i<num_descr; i++) {
1545 	   ret= Xorriso_normalize_img_path(xorriso, xorriso->wdx, argv[i+*idx],
1546 	                                   eff_path, 2|4);
1547 	   if(ret<=0)
1548 	     goto ex;
1549 	   descr[i]= strdup(eff_path); 
1550 	   if(descr[i]==NULL)
1551 	     goto no_memory;
1552 	 }
1553 	
1554 	 ret= Xorriso_opt_args(xorriso,
1555 	                       (flag & 0x3f03) ? "-hide_disk_paths" : "-not_paths",
1556 	                       num_descr, descr, 0, &dummy, &optc, &optv,
1557 	                       2 | ((flag & 4) << 7));
1558 	 if(ret<=0)
1559 	   goto ex; 
1560 	 if(flag & 0x3f03) {
1561 	   if(flag & 0x0101) {
1562 	     ret= Exclusions_add_not_paths(xorriso->iso_rr_hidings,
1563 	                                   num_descr, descr, optc, optv, 0);
1564 	     if(ret<=0) {
1565 	no_hide:;
1566 	       sprintf(xorriso->info_text, "Cannot add path list: -hide_disk_paths ");
1567 	       hpt= Xorriso__hide_mode_text(flag & 0x3f03, 0);
1568 	       if(hpt != NULL)
1569 	         sprintf(xorriso->info_text + strlen(xorriso->info_text), "%s ", hpt);
1570 	       Xorriso_free_meM(hpt);
1571 	       Text_shellsafe(argv[*idx], xorriso->info_text, 1);
1572 	       strcat(xorriso->info_text, num_descr > 1 ? " ... " : " ");
1573 	       strcat(xorriso->info_text, xorriso->list_delimiter);
1574 	       Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1575 	       goto ex;
1576 	     }
1577 	   }
1578 	   if(flag & 0x0202) {
1579 	     ret= Exclusions_add_not_paths(xorriso->joliet_hidings,
1580 	                                   num_descr, descr, optc, optv, 0);
1581 	     if(ret<=0)
1582 	       goto no_hide;
1583 	   }
1584 	   if(flag & 0x0400) {
1585 	     ret= Exclusions_add_not_paths(xorriso->hfsplus_hidings,
1586 	                                   num_descr, descr, optc, optv, 0);
1587 	     if(ret<=0)
1588 	       goto no_hide;
1589 	   }
1590 	 } else {
1591 	   ret= Exclusions_add_not_paths(xorriso->disk_exclusions,
1592 	                                 num_descr, descr, optc, optv, 0);
1593 	   if(ret<=0) {
1594 	     sprintf(xorriso->info_text,"Cannot add path list: -not_paths ");
1595 	     Text_shellsafe(argv[*idx], xorriso->info_text, 1);
1596 	     strcat(xorriso->info_text, num_descr > 1 ? " ... " : " ");
1597 	     strcat(xorriso->info_text, xorriso->list_delimiter);
1598 	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1599 	   }
1600 	 }
1601 	ex:;
1602 	 (*idx)= end_idx;
1603 	 Xorriso_opt_args(xorriso, "-not_paths",
1604 	                  num_descr, descr, 0, &dummy, &optc, &optv, 256);
1605 	 if(descr!=NULL) {
1606 	   for(i= 0; i<num_descr; i++)
1607 	     if(descr[i]!=NULL)
1608 	       free(descr[i]);
1609 	   free((char *) descr);
1610 	   descr= NULL;
1611 	 }
1612 	 Xorriso_free_meM(eff_path);
1613 	 return(ret);
1614 	}
1615 	
1616 	
1617 	/* Option -options_from_file */
1618 	int Xorriso_option_options_from_file(struct XorrisO *xorriso, char *adr,
1619 	                                     int flag)
1620 	/*
1621 	 bit0= called from Xorriso_prescan_args,
1622 	       therefore execute via that same function
1623 	*/
1624 	/*
1625 	return:
1626 	 <=0 error , 1 = success , 3 = end program run
1627 	*/
1628 	{
1629 	 int ret,linecount= 0, argc= 0, was_failure= 0, fret;
1630 	 FILE *fp= NULL;
1631 	 char **argv= NULL;
1632 	 int linec= 0;
1633 	 char *line= NULL, **linev= NULL;
1634 	
1635 	 if(adr[0]==0) {
1636 	   sprintf(xorriso->info_text,"Empty file name given with -options_from_file");
1637 	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
1638 	   return(0);
1639 	 }
1640 	 if(xorriso->is_dialog) {
1641 	   sprintf(xorriso->info_text,"+ performing command lines from file ");
1642 	   Text_shellsafe(adr, xorriso->info_text, 1);
1643 	   strcat(xorriso->info_text, " :\n");
1644 	   Xorriso_info(xorriso,1);
1645 	 }
1646 	 ret= Xorriso_afile_fopen(xorriso, adr, "rb", &fp, 0);
1647 	 if(ret <= 0)
1648 	   return(0);
1649 	 sprintf(xorriso->info_text, "Command file:  ");
1650 	 Text_shellsafe(adr, xorriso->info_text, 1);
1651 	 Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
1652 	 while(1) {
1653 	   ret= Xorriso_read_lines(xorriso, fp, &linecount, &linec, &linev, 1 | 8);
1654 	   if(ret <= 0)
1655 	     goto ex; /* no problem_handler because there is no sense in going on */
1656 	   if(ret == 2)
1657 	 break;
1658 	   line= linev[0];
1659 	   if(line[0]==0 || line[0]=='#')
1660 	 continue;
1661 	
1662 	   if(flag&1) {
1663 	     ret= Sfile_make_argv(xorriso->progname, line, &argc, &argv,
1664 	                          4 | 8 | ((xorriso->bsl_interpretation & 3) << 5));
1665 	     if(ret<=0)
1666 	       goto problem_handler;
1667 	     ret= Xorriso_prescan_args(xorriso,argc,argv,1);
1668 	     if(ret==0)
1669 	       {ret= 3; goto ex;}
1670 	     if(ret<0)
1671 	       goto problem_handler;
1672 	   } else {
1673 	     if(xorriso->is_dialog) {
1674 	       sprintf(xorriso->info_text,"+ %d:  %s\n",linecount,line);
1675 	       Xorriso_info(xorriso,1);
1676 	     }
1677 	     ret= Xorriso_execute_option(xorriso,line,1|(1<<16));
1678 	     if(ret==3)
1679 	       goto ex;
1680 	     if(ret<=0)
1681 	       goto problem_handler;
1682 	   }
1683 	
1684 	 continue; /* regular bottom of loop */
1685 	problem_handler:;
1686 	   was_failure= 1;
1687 	   fret= Xorriso_eval_problem_status(xorriso, ret, 1);
1688 	   if(fret>=0)
1689 	 continue;
1690 	   goto ex;
1691 	 }
(1) Event start: Starting defect path here.
1692 	 ret= 1;
1693 	ex:;
1694 	 Sfile_make_argv("", "", &argc, &argv, 2); /* release memory */
(2) Event alloc_arg: "Xorriso_read_lines" allocates memory that is stored into "linev". [details]
Also see events: [leaked_storage]
1695 	 Xorriso_read_lines(xorriso, fp, &linecount, &linec, &linev, 2);
1696 	 Xorriso_reset_counters(xorriso,0);
(3) Event cond_true: Condition "fp != NULL", taking true branch.
(4) Event cond_true: Condition "fp != stdin", taking true branch.
1697 	 if(fp != NULL && fp != stdin)
1698 	   fclose(fp);
(5) Event cond_false: Condition "ret <= 0", taking false branch.
1699 	 if(ret<=0) {
1700 	   sprintf(xorriso->info_text,
1701 	           "error triggered by line %d of file:\n    ", linecount);
1702 	   Text_shellsafe(adr, xorriso->info_text, 1);
1703 	   strcat(xorriso->info_text, "\n");
1704 	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 1);
(6) Event if_end: End of if statement.
1705 	 }
1706 	 sprintf(xorriso->info_text, "Command file end:  ");
1707 	 Text_shellsafe(adr, xorriso->info_text, 1);
1708 	 Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
(7) Event cond_false: Condition "ret != 1", taking false branch.
1709 	 if(ret!=1)
(8) Event if_end: End of if statement.
1710 	   return(ret);
(9) Event cond_true: Condition "!was_failure", taking true branch.
(10) Event leaked_storage: Variable "linev" going out of scope leaks the storage it points to.
Also see events: [alloc_arg]
1711 	 return(!was_failure);
1712 	}
1713 	
1714 	
1715 	/* Option -osirrox "on"|"off" */
1716 	int Xorriso_option_osirrox(struct XorrisO *xorriso, char *mode, int flag)
1717 	{
1718 	 int l, allow_restore;
1719 	 char *npt, *cpt;
1720 	
1721 	 allow_restore= xorriso->allow_restore;
1722 	
1723 	 npt= cpt= mode;
1724 	 for(cpt= mode; npt!=NULL; cpt= npt+1) {
1725 	   npt= strchr(cpt,':');
1726 	   if(npt==NULL)
1727 	     l= strlen(cpt);
1728 	   else
1729 	     l= npt-cpt;
1730 	   if(l==0 && mode[0]!=0)
1731 	     goto unknown_mode;
1732 	   if(strncmp(cpt, "off", l)==0 && l >= 3)
1733 	     allow_restore= 0;
1734 	   else if(strncmp(cpt, "banned", l)==0 && l >= 5)
1735 	     allow_restore= -1;
1736 	   else if(strncmp(cpt, "blocked", l)==0 && l >= 7)
1737 	     allow_restore= -2;
1738 	   else if(strncmp(cpt, "unblock", l)==0 && l >= 7) {
1739 	     if(xorriso->allow_restore == -2)
1740 	       xorriso->allow_restore= 0;
1741 	     allow_restore= 1;
1742 	   } else if(strncmp(cpt, "device_files", l)==0 && l >= 12)
1743 	     allow_restore= 2;
1744 	   else if((strncmp(cpt, "on", l)==0 && l >= 2) || mode[0]==0)
1745 	     allow_restore= 1;
1746 	   else if(strncmp(cpt, "concat_split_on", l)==0 && l >= 15)
1747 	     xorriso->do_concat_split= 1;
1748 	   else if(strncmp(cpt, "concat_split_off", l)==0 && l >= 16)
1749 	     xorriso->do_concat_split= 0;
1750 	   else if(strncmp(cpt, "auto_chmod_on", l)==0 && l >= 13)
1751 	     xorriso->do_auto_chmod= 1;
1752 	   else if(strncmp(cpt, "auto_chmod_off", l)==0 && l >= 14)
1753 	     xorriso->do_auto_chmod= 0;
1754 	   else if(strncmp(cpt, "sort_lba_on", l)==0 && l >= 11)
1755 	     xorriso->do_restore_sort_lba= 1;
1756 	   else if(strncmp(cpt, "sort_lba_off", l)==0 && l >= 12)
1757 	     xorriso->do_restore_sort_lba= 0;
1758 	   else if(strncmp(cpt, "o_excl_on", l)==0 && l >= 9)
1759 	     xorriso->drives_exclusive= 1;
1760 	   else if(strncmp(cpt, "o_excl_off", l)==0 && l >= 10)
1761 	     xorriso->drives_exclusive= 0;
1762 	   else if(strncmp(cpt, "strict_acl_on", l)==0 && l >= 13)
1763 	     xorriso->do_strict_acl|= 1;
1764 	   else if(strncmp(cpt, "strict_acl_off", l)==0 && l >= 14)
1765 	     xorriso->do_strict_acl&= ~1;
1766 	   else {
1767 	unknown_mode:;
1768 	     sprintf(xorriso->info_text, "-osirrox: unknown mode '%s'", cpt);
1769 	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1770 	     return(0);
1771 	   }
1772 	 }
1773 	 if(allow_restore > 0 && xorriso->allow_restore == -1) {
1774 	   sprintf(xorriso->info_text,
1775 	     "-osirrox: was already permanently disabled by setting 'banned'");
1776 	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1777 	   return(0);
1778 	 }
1779 	 if(allow_restore > 0 && xorriso->allow_restore == -2) {
1780 	   sprintf(xorriso->info_text,
1781 	           "-osirrox: is currently disabled by setting 'blocked'");
1782 	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1783 	   return(0);
1784 	 }
1785 	 if(xorriso->allow_restore != -1)
1786 	   xorriso->allow_restore= allow_restore;
1787 	 sprintf(xorriso->info_text,
1788 	         "Copying of file objects from ISO image to disk filesystem is: %s\n",
1789 	         xorriso->allow_restore > 0 ? "Enabled" : "Disabled");
1790 	 Xorriso_info(xorriso, 0);
1791 	 return(1);
1792 	}
1793 	
1794 	
1795 	/* Option -overwrite "on"|"nondir"|"off" */
1796 	int Xorriso_option_overwrite(struct XorrisO *xorriso, char *mode, int flag)
1797 	{
1798 	 if(strcmp(mode, "off")==0)
1799 	   xorriso->do_overwrite= 0;
1800 	 else if(strcmp(mode, "on")==0)
1801 	   xorriso->do_overwrite= 1;
1802 	 else if(strcmp(mode, "nondir")==0)
1803 	   xorriso->do_overwrite= 2;
1804 	 else {
1805 	   sprintf(xorriso->info_text, "-overwrite: unknown mode '%s'", mode);
1806 	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1807 	   return(0);
1808 	 }
1809 	 return(1);
1810 	}
1811 	
1812 	
1813 	


















































1    	
2    	/* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images.
3    	
4    	   Copyright 2007-2015 Thomas Schmitt, <address@hidden>
5    	
6    	   Provided under GPL version 2 or later.
7    	
8    	   This file contains the implementation of options as mentioned in man page
9    	   or info file derived from xorriso.texi.
10   	*/
11   	
12   	#ifdef HAVE_CONFIG_H
13   	#include "../config.h"
14   	#endif
15   	
16   	#include <ctype.h>
17   	#include <sys/types.h>
18   	#include <unistd.h>
19   	#include <stdlib.h>
20   	#include <stdio.h>
21   	#include <string.h>
22   	#include <sys/stat.h>
23   	#include <sys/time.h>
24   	#include <time.h>
25   	#include <errno.h>
26   	
27   	#include "xorriso.h"
28   	#include "xorriso_private.h"
29   	#include "xorrisoburn.h"
30   	
31   	
32   	/* Option -iso_rr_pattern "on"|"ls"|"off" */
33   	int Xorriso_option_iso_rr_pattern(struct XorrisO *xorriso, char *mode,int flag)
34   	{
35   	 if(strcmp(mode, "off")==0)
36   	   xorriso->do_iso_rr_pattern= 0;
37   	 else if(strcmp(mode, "on")==0)
38   	   xorriso->do_iso_rr_pattern= 1;
39   	 else if(strcmp(mode, "ls")==0)
40   	   xorriso->do_iso_rr_pattern= 2;
41   	 else {
42   	   sprintf(xorriso->info_text, "-iso_rr_pattern: unknown mode '%s'", mode);
43   	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
44   	   return(0);
45   	 }
46   	 return(1);
47   	}
48   	
49   	
50   	/* Option -jigdo aspect argument */
51   	int Xorriso_option_jigdo(struct XorrisO *xorriso, char *aspect, char *arg,
52   	                         int flag)
53   	{
54   	 int ret;
55   	
56   	 ret= Xorriso_jigdo_interpreter(xorriso, aspect, arg, 0);
57   	 return(ret);
58   	}
59   	
60   	
61   	/* Option -joliet "on"|"off" */
62   	int Xorriso_option_joliet(struct XorrisO *xorriso, char *mode, int flag)
63   	{
64   	 if(strcmp(mode, "off")==0)
65   	   xorriso->do_joliet= 0;
66   	 else if(strcmp(mode, "on")==0)
67   	   xorriso->do_joliet= 1;
68   	 else {
69   	   sprintf(xorriso->info_text, "-joliet: unknown mode '%s'", mode);
70   	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
71   	   return(0);
72   	 }
73   	 return(1);
74   	}
75   	
76   	
77   	/* Command -launch_frontend */
78   	int Xorriso_option_launch_frontend(struct XorrisO *xorriso,
79   	                                   int argc, char **argv, int *idx, int flag)
80   	{
81   	 int ret, end_idx;
82   	
83   	 end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 1);
84   	
85   	 if(xorriso->launch_frontend_banned) {
86   	   sprintf(xorriso->info_text,
87   	           "-launch_frontend was already executed in this xorriso run");
88   	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
89   	   ret= 0; goto ex;
90   	 }
91   	 xorriso->launch_frontend_banned= 1;
92   	 if(end_idx <= *idx)
93   	   {ret= 1; goto ex;}
94   	 if(argv[*idx][0] == 0)
95   	   {ret= 1; goto ex;}
96   	 xorriso->dialog= 2;
97   	 ret= Xorriso_launch_frontend(xorriso, end_idx - *idx, argv + *idx,
98   	                              "", "", 0);
99   	ex:;
100  	 (*idx)= end_idx;
101  	 return(ret);
102  	}
103  	
104  	
105  	/* Option -list_arg_sorting */
106  	int Xorriso_option_list_arg_sorting(struct XorrisO *xorriso, int flag)
107  	{
108  	 int ret;
109  	
110  	 ret= Xorriso_cmd_sorting_rank(xorriso, 0, NULL, 0, 1);
111  	 return(ret);
112  	}
113  	
114  	
115  	/* Option -list_delimiter */
116  	int Xorriso_option_list_delimiter(struct XorrisO *xorriso, char *text,
117  	                                  int flag)
118  	{
119  	 int ret, argc;
120  	 char **argv= NULL;
121  	
122  	 if(text[0] == 0) {
123  	   sprintf(xorriso->info_text,
124  	           "-list_delimiter: New delimiter text is empty");
125  	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
126  	   return(0);
127  	 }
128  	 if(strlen(text) > 80) {
129  	   sprintf(xorriso->info_text,
130  	           "-list_delimiter: New delimiter text is too long");
131  	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
132  	   return(0);
133  	 }
134  	 ret= Sfile_make_argv(xorriso->progname, text, &argc, &argv, 4);
135  	 if(ret > 0) {
136  	   if(argc > 2) {
137  	     sprintf(xorriso->info_text,
138  	            "-list_delimiter: New delimiter text contains more than one word");
139  	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
140  	   }
141  	   Sfile_make_argv(xorriso->progname, text, &argc, &argv, 2);
142  	   if(argc > 2)
143  	     return(0);
144  	 }
145  	 if(strchr(text, '"') != NULL || strchr(text, '\'') != NULL) {
146  	   sprintf(xorriso->info_text,
147  	           "-list_delimiter: New delimiter text contains quotation marks");
148  	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
149  	   return(0);
150  	 }
151  	 strcpy(xorriso->list_delimiter, text);
152  	 return(1);
153  	}
154  	
155  	
156  	/* Option -list_extras */
157  	int Xorriso_option_list_extras(struct XorrisO *xorriso, char *mode, int flag)
158  	{
159  	 int ret;
160  	
161  	 ret= Xorriso_list_extras(xorriso, mode, 0);
162  	 return(ret);
163  	}
164  	
165  	
166  	/* Option -list_formats */
167  	int Xorriso_option_list_formats(struct XorrisO *xorriso, int flag)
168  	{
169  	 int ret;
170  	
171  	 ret= Xorriso_list_formats(xorriso, 0);
172  	 return(ret);
173  	}
174  	
175  	
176  	/* Option -list_speeds */
177  	int Xorriso_option_list_speeds(struct XorrisO *xorriso, int flag)
178  	{
179  	 int ret;
180  	
181  	 ret= Xorriso_list_speeds(xorriso, 0);
182  	 return(ret);
183  	}
184  	
185  	
186  	/* Option -list_profiles */
187  	int Xorriso_option_list_profiles(struct XorrisO *xorriso, char *which,
188  	                                 int flag)
189  	{
190  	 int ret;
191  	 int mode= 0;
192  	
193  	 if(strncmp(which,"in",2)==0)
194  	   mode|= 1;
195  	 else if(strncmp(which,"out",3)==0)
196  	   mode|= 2;
197  	 else
198  	   mode|= 3;
199  	 if(mode & 1) {
200  	   ret= Xorriso_toc(xorriso, 1 | 16 | 32);
201  	   if(ret > 0)
202  	     Xorriso_list_profiles(xorriso, 0);
203  	 }
204  	 if((mode & 2) && xorriso->in_drive_handle != xorriso->out_drive_handle) {
205  	   ret= Xorriso_toc(xorriso, 1 | 2 | 16 | 32);
206  	   if(ret > 0)
207  	     Xorriso_list_profiles(xorriso, 2);
208  	 }
209  	 return(1);
210  	}
211  	
212  	
213  	/* Command -lns alias -lnsi */
214  	int Xorriso_option_lnsi(struct XorrisO *xorriso, char *target, char *path,
215  	                        int flag)
216  	{
217  	 int ret;
218  	 char *eff_path= NULL, *buffer= NULL, *namept;
219  	
220  	 Xorriso_alloc_meM(eff_path, char, SfileadrL);
221  	 Xorriso_alloc_meM(buffer, char, SfileadrL);
222  	
223  	 ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, path, eff_path, 1);
224  	 if(ret < 0)
225  	   {ret= 0; goto ex;}
226  	 if(ret > 0) { 
227  	   sprintf(xorriso->info_text, "-lns: Address already existing: ");
228  	   Text_shellsafe(eff_path, xorriso->info_text, 1);
229  	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
230  	   {ret= 0; goto ex;}
231  	 } 
232  	 ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, path, eff_path, 2);
233  	 if(ret < 0)
234  	   {ret= 0; goto ex;}
235  	 ret= Xorriso_truncate_path_comps(xorriso, target, buffer, &namept, 0);
236  	 if(ret < 0)
237  	   {ret= 0; goto ex;}
238  	 ret= Xorriso_graft_in(xorriso, NULL, namept, eff_path, (off_t) 0, (off_t) 0,
239  	                       1024);
240  	 if(ret <= 0)
241  	   {ret= 0; goto ex;}
242  	 ret= 1;
243  	ex:;
244  	 Xorriso_free_meM(buffer);
245  	 Xorriso_free_meM(eff_path);
246  	 return(ret);
247  	}
248  	
249  	
250  	/* Option -load session|track|sbsector value */
251  	/* @param flag bit0= with adr_mode sbsector: adr_value is possibly 16 too high
252  	   @return <=0 error , 1 success, 2 revoked by -reassure
253  	*/
254  	int Xorriso_option_load(struct XorrisO *xorriso, char *adr_mode,
255  	                          char *adr_value, int flag)
256  	{
257  	 int ret;
258  	
259  	 if(Xorriso_change_is_pending(xorriso, 0)) {
260  	   sprintf(xorriso->info_text,
261  	           "-load: Image changes pending. -commit or -rollback first");
262  	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
263  	   return(0);
264  	 }
265  	 ret= Xorriso_reassure(xorriso, "-load", "loads an alternative image", 0);
266  	 if(ret<=0)
267  	   return(2);
268  	 ret= Xorriso_decode_load_adr(xorriso, "-load", adr_mode, adr_value,
269  	                              &(xorriso->image_start_mode),
270  	                              xorriso->image_start_value, flag & 1);
271  	 if(ret <= 0)
272  	   return(ret);
273  	 xorriso->image_start_mode|= (1<<30); /* enable non-default msc1 processing */
274  	 if(strlen(xorriso->indev)>0) {
275  	   ret= Xorriso_option_rollback(xorriso, 1); /* Load image, no -reassure */
276  	   if(ret<=0)
277  	     return(ret);
278  	 }
279  	 return(1);
280  	}
281  	
282  	
283  	/* Option -logfile */
284  	int Xorriso_option_logfile(struct XorrisO *xorriso, char *channel,
285  	                                                      char *fileadr, int flag)
286  	{
287  	 int hflag,channel_no= 0, ret;
288  	   
289  	 if(channel[0]==0) {
290  	logfile_wrong_form:;
291  	   sprintf(xorriso->info_text,"Wrong form. Correct would be: -logfile \".\"|\"R\"|\"I\"|\"M\" file_address");
292  	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
293  	   return(0);
294  	 }
295  	 hflag= 2;
296  	 if(channel[0]=='R')
297  	   channel_no= 1;
298  	 else if(channel[0]=='I')
299  	   channel_no= 2;
300  	 else if(channel[0]=='M')
301  	   channel_no= 3;
302  	 else if(channel[0]=='.')
303  	   hflag= 4;
304  	 else
305  	   goto logfile_wrong_form;
306  	 if(strcmp(fileadr,"-")==0 || fileadr[0]==0)
307  	     hflag|= (1<<15);
308  	 xorriso->logfile[channel_no][0]= 0;
309  	 ret= Xorriso_write_to_channel(xorriso, fileadr, channel_no, hflag);
310  	 if(ret<=0) {
311  	   sprintf(xorriso->info_text, "Cannot open logfile:  %s", fileadr);
312  	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
313  	 } else if(!(hflag&(1<<15)))
314  	   if(Sfile_str(xorriso->logfile[channel_no], fileadr, 0)<=0)
315  	     return(-1);
316  	 return(ret>0);
317  	}
318  	
319  	
320  	/* Options -ls  alias -lsi   and -lsl  alias -lsli
321  	       and -lsd alias -lsdi  and -lsdl alias -lsdli
322  	       and -du  alias -dui   and -dus  alias -dusi
323  	   @param flag bit0= long format (-lsl , -du, not -dus, not -ls)
324  	               bit1= do not expand patterns but use literally
325  	               bit2= -du rather than -ls
326  	               bit3= list directories as themselves (-lsd) 
327  	*/
328  	int Xorriso_option_lsi(struct XorrisO *xorriso, int argc, char **argv,
329  	                      int *idx, int flag)
330  	{
331  	 int ret, end_idx, filec= 0, nump, i, star= 1;
332  	 char **filev= NULL, **patterns= NULL;
333  	 off_t mem= 0;
334  	 struct stat stbuf;
335  	
336  	 if(flag & 4) {
337  	   if(!(flag & 1))
338  	     star= 0;
339  	 } else {
340  	   if(flag & 8)
341  	     star= 0;
342  	 }
343  	
344  	 end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 1);
345  	 if(xorriso->do_iso_rr_pattern==0)
346  	   flag|= 2;
347  	
348  	 nump= end_idx - *idx;
349  	 if((flag&2) && nump>0 ) {
350  	   ;
351  	 } else if(nump <= 0) {
352  	   if(Xorriso_iso_lstat(xorriso, xorriso->wdi, &stbuf, 0)<0) {
353  	     sprintf(xorriso->info_text,
354  	             "Current -cd path does not yet exist in the ISO image");
355  	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
356  	     {ret= 0; goto ex;}
357  	   }
358  	   if(!S_ISDIR(stbuf.st_mode)) {
359  	     sprintf(xorriso->info_text,
360  	             "Current -cd meanwhile points to a non-directory in ISO image");
361  	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
362  	     {ret= 0; goto ex;}
363  	   }
364  	   patterns= calloc(1, sizeof(char *));
365  	   if(patterns == NULL) {
366  	no_memory:;
367  	     sprintf(xorriso->info_text,
368  	             "Cannot allocate enough memory for pattern expansion");
369  	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
370  	     {ret= -1; goto ex;}
371  	   }
372  	   nump= 1;
373  	   if(star)
374  	     patterns[0]= "*";
375  	   else 
376  	     patterns[0]= ".";
377  	   flag&= ~2;
378  	 } else {
379  	   patterns= calloc(nump, sizeof(char *));
380  	   if(patterns==NULL)
381  	     goto no_memory;
382  	   for(i= 0; i<nump; i++) {
383  	     if(argv[i + *idx][0]==0) {
384  	       if(star)
385  	         patterns[i]= "*";
386  	       else
387  	         patterns[i]= ".";
388  	     } else
389  	       patterns[i]= argv[i + *idx];
390  	   }
391  	 }
392  	
393  	 if((flag & 1) && !(xorriso->ino_behavior & 32)) {
394  	   ret= Xorriso_make_hln_array(xorriso, 0); /* for stbuf.st_nlink */
395  	   if(ret < 0)
396  	     goto ex;
397  	 }
398  	 if(flag&2) {
399  	   ret= Xorriso_ls_filev(xorriso, xorriso->wdi, nump, argv + (*idx), mem,
400  	                         flag&(1|4|8)); 
401  	 } else if(nump==1 && strcmp(patterns[0],"*")==0 && !(flag&4)){
402  	   /* save temporary memory by calling simpler function */
403  	   ret= Xorriso_ls(xorriso, (flag&1)|4);
404  	 } else {
405  	   ret= Xorriso_expand_pattern(xorriso, nump, patterns, 0, &filec, &filev,
406  	                               &mem, 0);
407  	   if(ret<=0)
408  	     {ret= 0; goto ex;}
409  	   ret= Xorriso_ls_filev(xorriso, xorriso->wdi, filec, filev, mem,
410  	                         flag&(1|4|8)); 
411  	 }
412  	 if(ret<=0)
413  	   {ret= 0; goto ex;}
414  	
415  	 ret= 1;
416  	ex:;
417  	 if(patterns!=NULL)
418  	   free((char *) patterns);
419  	 Sfile_destroy_argv(&filec, &filev, 0);
420  	 (*idx)= end_idx;
421  	 return(ret);
422  	}
423  	
424  	
425  	/* Options -lsx, -lslx, -lsdx , -lsdlx , -dux , -dusx
426  	   @param flag bit0= long format (-lslx , -dux)
427  	               bit1= do not expand patterns but use literally
428  	               bit2= du rather than ls
429  	               bit3= list directories as themselves (ls -d) 
430  	*/
431  	int Xorriso_option_lsx(struct XorrisO *xorriso, int argc, char **argv,
432  	                      int *idx, int flag)
433  	{
434  	 int ret, end_idx, filec= 0, nump, i;
435  	 char **filev= NULL, **patterns= NULL;
436  	 off_t mem= 0;
437  	
438  	 end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 1|2);
439  	 if(xorriso->do_disk_pattern==0)
440  	   flag|= 2;
441  	
442  	 nump= end_idx - *idx;
443  	 if((flag&2) && nump>0) {
444  	   ;
445  	 } else if(nump <= 0) {
446  	   patterns= calloc(1, sizeof(char *));
447  	   if(patterns == NULL) {
448  	no_memory:;
449  	     sprintf(xorriso->info_text,
450  	             "Cannot allocate enough memory for pattern expansion");
451  	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
452  	     {ret= -1; goto ex;}
453  	   }
454  	   nump= 1;
455  	   if(flag&8)
456  	     patterns[0]= ".";
457  	   else
458  	     patterns[0]= "*";
459  	   flag&= ~2;
460  	 } else {
461  	   patterns= calloc(nump, sizeof(char *));
462  	   if(patterns==NULL)
463  	     goto no_memory;
464  	   for(i= 0; i<nump; i++) {
465  	     if(argv[i + *idx][0]==0)
466  	       patterns[i]= "*";
467  	     else
468  	       patterns[i]= argv[i + *idx];
469  	   }
470  	 }
471  	 if(flag&2) {
472  	   ret= Xorriso_lsx_filev(xorriso, xorriso->wdx,
473  	                          nump, argv + (*idx), mem, flag&(1|4|8)); 
474  	
475  	#ifdef Not_yeT
476  	 } else if(nump==1 && strcmp(patterns[0],"*")==0 && !(flag&4)){
477  	   /* save temporary memory by calling simpler function */
478  	   ret= Xorriso_ls(xorriso, (flag&1)|4);
479  	#endif
480  	
481  	 } else {
482  	   ret= Xorriso_expand_disk_pattern(xorriso, nump, patterns, 0, &filec, &filev,
483  	                                    &mem, 0);
484  	   if(ret<=0)
485  	     {ret= 0; goto ex;}
486  	   ret= Xorriso_lsx_filev(xorriso, xorriso->wdx, filec, filev, mem,
487  	                          flag&(1|4|8)); 
488  	 }
489  	 if(ret<=0)
490  	   {ret= 0; goto ex;}
491  	
492  	 ret= 1;
493  	ex:;
494  	 if(patterns!=NULL)
495  	   free((char *) patterns);
496  	 Sfile_destroy_argv(&filec, &filev, 0);
497  	 (*idx)= end_idx;
498  	 return(ret);
499  	}
500  	
501  	
502  	/* Option -map , -map_single */
503  	/* @param flag bit0=do not report the added item
504  	               bit1=do not reset pacifier, no final pacifier message
505  	               bit5= -map_single: do not insert directory tree
506  	*/
507  	int Xorriso_option_map(struct XorrisO *xorriso, char *disk_path,
508  	                       char *iso_path, int flag)
509  	{
510  	 int ret;
511  	 char *eff_origin= NULL, *eff_dest= NULL, *ipth;
512  	
513  	 Xorriso_alloc_meM(eff_origin, char, SfileadrL);
514  	 Xorriso_alloc_meM(eff_dest, char, SfileadrL);
515  	
516  	 if(!(flag&2))
517  	   Xorriso_pacifier_reset(xorriso, 0);
518  	
519  	 ipth= iso_path;
520  	 if(ipth[0]==0)
521  	   ipth= disk_path;
522  	 if(disk_path[0]==0) {
523  	   sprintf(xorriso->info_text, "-map: Empty disk_path given");
524  	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 1);
525  	   {ret= 0; goto ex;}
526  	 }
527  	 ret= Xorriso_normalize_img_path(xorriso, xorriso->wdx, disk_path, eff_origin,
528  	                                 2|4);
529  	 if(ret<=0)
530  	   goto ex;
531  	 ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, ipth, eff_dest, 2);
532  	 if(ret<=0)
533  	   goto ex;
534  	 ret= Xorriso_graft_in(xorriso, NULL, eff_origin, eff_dest,
535  	                       (off_t) 0, (off_t) 0, 2|(flag&32));
536  	 if(!(flag&2))
537  	   Xorriso_pacifier_callback(xorriso, "files added", xorriso->pacifier_count,
538  	                             xorriso->pacifier_total, "", 1);
539  	 if(ret<=0)
540  	   goto ex;
541  	
542  	 if(!(flag&1)) {
543  	   sprintf(xorriso->info_text, "Added to ISO image: %s '%s'='%s'\n",
544  	           (ret>1 ? "directory" : "file"), (eff_dest[0] ? eff_dest : "/"),
545  	           eff_origin);
546  	   Xorriso_info(xorriso,0);
547  	 }
548  	 ret= 1;
549  	ex:;
550  	 Xorriso_free_meM(eff_origin);
551  	 Xorriso_free_meM(eff_dest);
552  	 return(ret);
553  	}
554  	
555  	
556  	/* Command -map_l , -compare_l , -update_l , -extract_l , -update_lxi ,
557  	           -update_li
558  	*/
559  	/* @param flag bit4= do not establish and dispose xorriso->di_array
560  	                     for update_l
561  	               bit8-11= mode 0= -map_l
562  	                             1= -compare_l
563  	                             2= -update_l
564  	                             3= -extract_l
565  	                             4= -update_lxi
566  	                             5= -update_li
567  	*/
568  	int Xorriso_option_map_l(struct XorrisO *xorriso, int argc, char **argv,
569  	                         int *idx, int flag)
570  	{
571  	 int ret, end_idx, optc= 0, was_failure= 1, i, j, fret, mode, problem_count;
572  	 int ns_flag= 2|4, nt_flag= 2, opt_args_flag= 2, arg2c= 0, opt2c= 0;
573  	 int new_opt2c;
574  	 char *source_prefix= NULL, *target_prefix= NULL, *cmd, **optv= NULL;
575  	 char *eff_source= NULL, *eff_target= NULL, *s_wd, *t_wd;
576  	 char **eff_src_array= NULL, **eff_tgt_array= NULL, **opt2v= NULL;
577  	 char **arg2v= NULL;
578  	
579  	 cmd= "-map_l";
580  	 s_wd= xorriso->wdx;
581  	 t_wd= xorriso->wdi;
582  	 Xorriso_pacifier_reset(xorriso, 0);
583  	 mode= (flag>>8) & 15;
584  	
585  	 if(mode==1)
586  	   cmd= "-compare_l";
587  	 else if(mode==2)
588  	   cmd= "-update_l";
589  	 else if(mode == 3 || mode == 5) {
590  	   if(mode == 5)
591  	     cmd= "-update_li";
592  	   else
593  	     cmd= "-extract_l";
594  	   ns_flag= 2;
595  	   s_wd= xorriso->wdi;
596  	   nt_flag= 2|4;
597  	   t_wd= xorriso->wdx;
598  	   opt_args_flag= 0;
599  	 } else if(mode == 4) {
600  	   cmd= "-update_lxi";
601  	 }
602  	
603  	 end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 1|2);
604  	 if(end_idx - (*idx) < 3) {
605  	   sprintf(xorriso->info_text, "%s: Not enough arguments given (%d < 3)", cmd,
606  	           end_idx - (*idx));
607  	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 1);
608  	   ret= 0; goto ex;
609  	 }
610  	
611  	 Xorriso_alloc_meM(source_prefix, char, SfileadrL);
612  	 Xorriso_alloc_meM(target_prefix, char, SfileadrL);
613  	 Xorriso_alloc_meM(eff_source, char, SfileadrL);
614  	 Xorriso_alloc_meM(eff_target, char, SfileadrL);
615  	
616  	 ret= Xorriso_normalize_img_path(xorriso, s_wd, argv[*idx],
617  	                                 source_prefix, ns_flag | 64);
618  	 if(ret<=0)
619  	   goto ex;
620  	 ret= Xorriso_normalize_img_path(xorriso, t_wd, argv[(*idx)+1],
621  	                                 target_prefix, nt_flag);
622  	 if(ret<=0)
623  	   goto ex;
624  	 ret= Xorriso_opt_args(xorriso, cmd, argc, argv, (*idx)+2, &end_idx,
625  	                       &optc, &optv, opt_args_flag);
626  	 if(ret<=0)
627  	   goto ex;
628  	 if(mode == 4) {
629  	   /* Convert pattern from disk to iso_rr */
630  	   arg2c= end_idx - *idx - 2;
631  	   Xorriso_alloc_meM(arg2v, char *, arg2c);
632  	   for(i = 0; i < arg2c; i++)
633  	     arg2v[i]= NULL;
634  	   arg2c= 0;
635  	   for(i = (*idx) + 2; i < end_idx; i++) {
636  	     ret= Xorriso_normalize_img_path(xorriso, s_wd, argv[i],
637  	                                     eff_source, ns_flag);
638  	     if(ret<=0)
639  	       goto ex;
640  	     ret= Xorriso__exchange_prefix(source_prefix, target_prefix,
641  	                                   eff_source, eff_target, 0);
642  	     if(ret <= 0)
643  	   continue;
644  	     Xorriso_alloc_meM(arg2v[arg2c], char, strlen(eff_target) + 1);
645  	     strcpy(arg2v[arg2c], eff_target);
646  	     arg2c++;
647  	   }
648  	   /* Expand wildcards in iso_rr, do not include unmatched patterns */
649  	   ret= Xorriso_opt_args(xorriso, cmd, arg2c, arg2v, 0, &i,
650  	                          &opt2c, &opt2v, (1 << 10) | (1 << 7));
651  	   if(ret<=0)
652  	     goto ex;
653  	   /* Convert from iso_rr path to disk path */
654  	   new_opt2c= 0;
655  	   for(i = 0; i < opt2c; i++) {
656  	     ret= Xorriso__exchange_prefix(target_prefix, source_prefix,
657  	                                   opt2v[i], eff_source, 0);
658  	     free(opt2v[i]);
659  	     opt2v[i]= NULL;
660  	     if(ret <= 0)
661  	   continue;
662  	     Xorriso_alloc_meM(opt2v[new_opt2c], char, strlen(eff_source) + 1);
663  	     strcpy(opt2v[new_opt2c], eff_source);
664  	     new_opt2c++;
665  	   }
666  	   opt2c= new_opt2c;
667  	   /* Merge both results */
668  	   if(opt2c > 0) {
669  	     Sfile_destroy_argv(&arg2c, &arg2v, 0);
670  	     Xorriso_alloc_meM(arg2v, char *, optc + opt2c);
671  	     for(i = 0; i < optc + opt2c; i++)
672  	       arg2v[i]= NULL;
673  	     arg2c= 0;
674  	     for(i= 0; i < optc; i++) {
675  	       ret= Xorriso_normalize_img_path(xorriso, s_wd, optv[i],
676  	                                       eff_source, ns_flag);
677  	       if(ret<=0)
678  	         goto ex;
679  	       Xorriso_alloc_meM(arg2v[arg2c], char, strlen(eff_source) + 1);
680  	       strcpy(arg2v[arg2c], eff_source);
681  	       arg2c++;
682  	     }
683  	     for(i= 0; i < opt2c; i++) {
684  	       for(j= 0; j < optc; j++)
685  	         if(strcmp(opt2v[i], arg2v[j]) == 0)
686  	       break;
687  	       if(j < optc)
688  	     continue;
689  	       arg2v[arg2c++]= opt2v[i];
690  	       opt2v[i]= NULL;
691  	     }
692  	     Sfile_destroy_argv(&optc, &optv, 0);
693  	     optv= arg2v;
694  	     arg2v= NULL;
695  	     optc= arg2c;
696  	     arg2c= 0;
697  	   }
698  	 }
699  	
700  	 if(mode == 3 &&
701  	    (xorriso->do_restore_sort_lba || !(xorriso->ino_behavior & 4))) {
702  	   eff_src_array= calloc(optc, sizeof(char *));
703  	   eff_tgt_array= calloc(optc, sizeof(char *));
704  	   if(eff_src_array == NULL || eff_tgt_array == NULL) {
705  	     Xorriso_no_malloc_memory(xorriso, NULL, 0);
706  	     ret= -1; goto ex;
707  	   }
708  	   for(i= 0; i < optc; i++)
709  	     eff_src_array[i]= eff_tgt_array[i]= NULL;
710  	 }
711  	 if((mode == 2 || mode == 4) &&
712  	     !((xorriso->ino_behavior & 2) || (flag & 16) ||
713  	       xorriso->di_array != NULL)) {
714  	   /* Create all-image node array sorted by isofs.di */
715  	   ret= Xorriso_make_di_array(xorriso, 0);
716  	   if(ret <= 0)
717  	     goto ex;
718  	 }
719  	
720  	 for(i= 0; i<optc; i++) {
721  	   ret= Xorriso_normalize_img_path(xorriso, s_wd, optv[i],
722  	                                   eff_source, ns_flag);
723  	   if(ret<=0)
724  	     goto ex;
725  	   ret= Xorriso__exchange_prefix(source_prefix, target_prefix,
726  	                                 eff_source, eff_target, 0);
727  	   if(ret == 0) {
728  	     sprintf(xorriso->info_text, "%s: disk_path ", cmd);
729  	     Text_shellsafe(eff_source, xorriso->info_text, 1);
730  	     strcat(xorriso->info_text, " does not begin with disk_prefix ");
731  	     Text_shellsafe(source_prefix, xorriso->info_text, 1);
732  	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 1);
733  	   }
734  	   if(ret <= 0)
735  	     goto ex;
736  	
737  	   if(mode==0)
738  	     ret= Xorriso_option_map(xorriso, eff_source, eff_target, 2);
739  	   else if(mode==1)
740  	     ret= Xorriso_option_compare(xorriso, eff_source, eff_target, 2|8);
741  	   else if(mode == 2 || mode == 4)
742  	     ret= Xorriso_option_update(xorriso, eff_source, eff_target, 2 | 8 | 16);
743  	   else if(mode==3) {
744  	     if(eff_src_array != NULL) {
745  	       eff_src_array[i]= strdup(eff_source);
746  	       eff_tgt_array[i]= strdup(eff_target);
747  	       if(eff_src_array[i] == NULL || eff_tgt_array[i] == NULL) {
748  	         Xorriso_no_malloc_memory(xorriso, &(eff_src_array[i]), 0);
749  	         ret= -1; goto ex;
750  	       }
751  	     } else {
752  	       ret= Xorriso_option_extract(xorriso, eff_source, eff_target, 2 | 4);
753  	     }
754  	   } else if(mode == 5) {
755  	     ret= Xorriso_option_update(xorriso, eff_target, eff_source, 2 | 8 | 16);
756  	   }
757  	
758  	   if(ret>0 && !xorriso->request_to_abort)
759  	 continue; /* regular bottom of loop */
760  	   was_failure= 1;
761  	   fret= Xorriso_eval_problem_status(xorriso, ret, 1 | 2);
762  	   if(fret>=0)
763  	 continue;
764  	   goto ex;
765  	 }
766  	
767  	 ret= 1;
768  	 if(mode == 3 && eff_src_array != NULL) {
769  	   ret= Xorriso_lst_append_binary(&(xorriso->node_disk_prefixes),
770  	                                  target_prefix, strlen(target_prefix) + 1, 0);
771  	   if(ret <= 0)
772  	     goto ex;
773  	   ret= Xorriso_lst_append_binary(&(xorriso->node_img_prefixes),
774  	                                  source_prefix, strlen(source_prefix) + 1, 0);
775  	   if(ret <= 0)
776  	     goto ex;
777  	   ret= Xorriso_restore_sorted(xorriso, optc, eff_src_array, eff_tgt_array,
778  	                               &problem_count, 0);
779  	   if(ret <= 0 || problem_count > 0)
780  	     was_failure= 1;
781  	 }
782  	 if(mode==0)
783  	   Xorriso_pacifier_callback(xorriso, "files added", xorriso->pacifier_count,
784  	                             xorriso->pacifier_total, "", 1);
785  	 else if(mode==1 || mode==2 || mode == 4 || mode == 5)
786  	   Xorriso_pacifier_callback(xorriso, "content bytes read",
787  	                             xorriso->pacifier_count, 0, "", 1 | 8 | 32);
788  	 else if(mode==3)
789  	   Xorriso_pacifier_callback(xorriso, "files restored",xorriso->pacifier_count,
790  	                             xorriso->pacifier_total, "", 1|4);
791  	ex:;
792  	 Xorriso_destroy_node_array(xorriso, 0);
793  	 i= optc;
794  	 Sfile_destroy_argv(&i, &eff_src_array, 0);
795  	 i= optc;
796  	 Sfile_destroy_argv(&i, &eff_tgt_array, 0);
797  	 Xorriso_free_meM(source_prefix);
798  	 Xorriso_free_meM(target_prefix);
799  	 Xorriso_free_meM(eff_source);
800  	 Xorriso_free_meM(eff_target);
801  	 (*idx)= end_idx;
802  	 Xorriso_opt_args(xorriso, cmd, argc, argv, *idx, &end_idx, &optc, &optv, 256);
803  	 Xorriso_opt_args(xorriso, cmd, argc, argv, *idx, &end_idx, &opt2c, &opt2v,
804  	                  256);
805  	 if(arg2c > 0)
806  	   Sfile_destroy_argv(&arg2c, &arg2v, 0);
807  	 else if(arg2v != NULL)
808  	   Xorriso_free_meM(arg2v);
809  	
810  	 if(ret<=0)
811  	   return(ret);
812  	 return(!was_failure);
813  	}
814  	
815  	
816  	/* Option -mark */
817  	int Xorriso_option_mark(struct XorrisO *xorriso, char *mark, int flag)
818  	{
819  	 if(mark[0]==0)
820  	   xorriso->mark_text[0]= 0;
821  	 else
822  	   strncpy(xorriso->mark_text,mark,sizeof(xorriso->mark_text)-1);
823  	 xorriso->mark_text[sizeof(xorriso->mark_text)-1]= 0;
824  	 return(1);
825  	}
826  	
827  	
828  	/* Option -md5 "on"|"all"|"off" */
829  	int Xorriso_option_md5(struct XorrisO *xorriso, char *mode, int flag)
830  	{
831  	 char *npt, *cpt;
832  	 int l;
833  	
834  	 npt= cpt= mode;
835  	 for(; npt!=NULL; cpt= npt+1) {
836  	   npt= strchr(cpt,':');
837  	   if(npt==NULL)
838  	     l= strlen(cpt);
839  	   else
840  	     l= npt-cpt;
841  	   if(l == 0)
842  	 continue;
843  	   if(l == 3 && strncmp(cpt, "off", l) == 0)
844  	     xorriso->do_md5&= ~31;
845  	   else if(l == 2 && strncmp(cpt, "on", l) == 0)
846  	     xorriso->do_md5= (xorriso->do_md5 & ~31) | 7 | 16;
847  	   else if(l == 3 && strncmp(cpt, "all", l) == 0)
848  	     xorriso->do_md5|= 31;
849  	   else if(l == 18 && strncmp(cpt, "stability_check_on", l) == 0)
850  	     xorriso->do_md5|= 8;
851  	   else if(l == 19 && strncmp(cpt, "stability_check_off", l) == 0)
852  	     xorriso->do_md5&= ~8;
853  	   else if(l == 13 && strncmp(cpt, "load_check_on", l) == 0)
854  	     xorriso->do_md5&= ~32;
855  	   else if(l == 14 && strncmp(cpt, "load_check_off", l) == 0)
856  	     xorriso->do_md5|= 32;
857  	   else {
858  	     sprintf(xorriso->info_text, "-md5: unknown mode ");
859  	     Text_shellsafe(cpt, xorriso->info_text, 1);
860  	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
861  	     return(0);
862  	   }
863  	 }
864  	 return(1);
865  	}
866  	
867  	
868  	/* Option -mkdir alias -mkdiri */
869  	int Xorriso_option_mkdiri(struct XorrisO *xorriso, int argc, char **argv,
870  	                          int *idx, int flag)
871  	{
872  	 int i, end_idx, ret, was_failure= 0, fret;
873  	
874  	 end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 0);
875  	
876  	 for(i= *idx; i<end_idx; i++) {
877  	   ret= Xorriso_mkdir(xorriso, argv[i], 0);
878  	   if(ret>0 && !xorriso->request_to_abort)
879  	 continue; /* regular bottom of loop */
880  	   was_failure= 1;
881  	   fret= Xorriso_eval_problem_status(xorriso, ret, 1|2);
882  	   if(fret>=0)
883  	 continue;
884  	   goto ex;
885  	 }
886  	 ret= 1; 
887  	ex:;
888  	 (*idx)= end_idx;
889  	 if(ret<=0)
890  	   return(ret);
891  	 return(!was_failure);
892  	}
893  	
894  	
895  	int Xorriso_option_modesty_on_drive(struct XorrisO *xorriso, char *mode,
896  	                                    int flag)
897  	{
898  	 char *npt, *cpt, *ppt;
899  	 int l, num, set_min;
900  	
901  	 npt= cpt= mode;
902  	 for(; npt!=NULL; cpt= npt+1) {
903  	   npt= strchr(cpt,':');
904  	   if(npt==NULL)
905  	     l= strlen(cpt);
906  	   else
907  	     l= npt-cpt;
908  	   if(l == 0)
909  	 continue;
910  	   if(l == 3 && strncmp(cpt, "off", l) == 0) {
911  	     xorriso->modesty_on_drive= 0;
912  	   } else if(l == 1 && strncmp(cpt, "0", l) == 0) {
913  	     xorriso->modesty_on_drive= 0;
914  	   } else if(l == 2 && strncmp(cpt, "on", l) == 0) {
915  	     xorriso->modesty_on_drive= 1;
916  	   } else if(l == 1 && strncmp(cpt, "1", l) == 0) {
917  	     xorriso->modesty_on_drive= 1;
918  	   } else if(l == 2 && strncmp(cpt, "-1", l) == 0) {
919  	     ;
920  	   } else if(*cpt >= '1' && *cpt <= '9') {
921  	     ppt= cpt;
922  	     set_min= 2;
923  	set_size_percent:;
924  	     sscanf(ppt, "%d", &num);
925  	     if(num == -1) {
926  	       ;
927  	     } else if(num < 25) {
928  	bad_percent:;
929  	       sprintf(xorriso->info_text, "-modesty_on_drive: percentage out of range [25 to 100]");
930  	       Text_shellsafe(cpt, xorriso->info_text, 1);
931  	       Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
932  	       return(0);
933  	     } else if(num > 100) {
934  	       goto bad_percent;
935  	     }
936  	     if(set_min == 2) {
937  	       xorriso->modesty_on_drive= 1;
938  	     }
939  	     if(set_min)
940  	       xorriso->min_buffer_percent= num;
941  	     else
942  	       xorriso->max_buffer_percent= num;
943  	   } else if(l >= 12 && strncmp(cpt, "min_percent=", 12) == 0) {
944  	     ppt= cpt + 12;
945  	     set_min= 1;
946  	     goto set_size_percent;
947  	   } else if(l >= 12 && strncmp(cpt, "max_percent=", 12) == 0) {
948  	     ppt= cpt + 12;
949  	     set_min= 0;
950  	     goto set_size_percent;
951  	   } else if(l >= 9 && strncmp(cpt, "min_usec=", 9) == 0) {
952  	     ppt= cpt + 9;
953  	     set_min= 1;
954  	set_sec:;
955  	     num= -1;
956  	     sscanf(ppt, "%d", &num);
957  	     if(num < 0)
958  	       num= 0;
959  	     if(set_min == 2)
960  	       xorriso->max_buffer_usec= num;
961  	     else if(set_min == 1)
962  	       xorriso->min_buffer_usec= num;
963  	     else if(set_min == 0)
964  	       xorriso->max_buffer_percent= num;
965  	     else
966  	       xorriso->buffer_timeout_sec= num;
967  	   } else if(l >= 9 && strncmp(cpt, "max_usec=", 9) == 0) {
968  	     ppt= cpt + 9;
969  	     set_min= 2;
970  	     goto set_sec;
971  	   } else if(l >= 12 && strncmp(cpt, "timeout_sec=", 12) == 0) {
972  	     ppt= cpt + 12;
973  	     set_min= -1;
974  	     goto set_sec;
975  	   } else {
976  	     sprintf(xorriso->info_text, "-modesty_on_drive: unknown mode ");
977  	     Text_shellsafe(cpt, xorriso->info_text, 1);
978  	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
979  	     return(0);
980  	   }
981  	 }
982  	 return(1);
983  	}
984  	
985  	
986  	/* Options -mount , -mount_cmd , -session_string */
987  	/* @param bit0= -mount_cmd: print mount command to result channel rather
988  	                            than performing it
989  	          bit1= perform -session_string rather than -mount_cmd
990  	*/
991  	int Xorriso_option_mount(struct XorrisO *xorriso, char *dev, char *adr_mode,
992  	                         char *adr, char *cmd, int flag)
993  	{
994  	 int ret, entity_code= 0, m_flag;
995  	 char entity_id[81], *mnt;
996  	
997  	 if(flag & 1)
998  	   mnt= "-mount_cmd";
999  	 else if(flag & 2)
1000 	   mnt= "-session_string";
1001 	 else {
1002 	   mnt= "-mount";
1003 	   if(xorriso->allow_restore <= 0) {
1004 	     sprintf(xorriso->info_text,
1005 	          "-mount: image-to-disk features are not enabled by option -osirrox");
1006 	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1007 	     return(0);
1008 	   }
1009 	   if(Xorriso_change_is_pending(xorriso, 0)) {
1010 	     sprintf(xorriso->info_text,
1011 	             "%s: Image changes pending. -commit or -rollback first", mnt);
1012 	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1013 	     return(0);
1014 	   }
1015 	 }
1016 	 ret= Xorriso_decode_load_adr(xorriso, mnt, adr_mode, adr,
1017 	                              &entity_code, entity_id, 0);
1018 	 if(ret <= 0)
1019 	   return(ret);
1020 	 if(flag & 2)
1021 	   m_flag= 1 | 4;
1022 	 else
1023 	   m_flag= (flag & 1) | 2;
1024 	 ret= Xorriso_mount(xorriso, dev, entity_code, entity_id, cmd, m_flag);
1025 	 return(ret);
1026 	}
1027 	
1028 	
1029 	/* Option -mount_opts option[:...] */
1030 	int Xorriso_option_mount_opts(struct XorrisO *xorriso, char *mode, int flag)
1031 	{
1032 	 int was, l;
1033 	 char *cpt, *npt;
1034 	
1035 	 was= xorriso->mount_opts_flag;
1036 	 npt= cpt= mode;
1037 	 for(cpt= mode; npt!=NULL; cpt= npt+1) {
1038 	   npt= strchr(cpt,':');
1039 	   if(npt==NULL)
1040 	     l= strlen(cpt);
1041 	   else
1042 	     l= npt-cpt;
1043 	   if(l==0)
1044 	     goto unknown_mode;
1045 	   if(strncmp(cpt, "shared", l)==0) {
1046 	     xorriso->mount_opts_flag|= 1;
1047 	   } else if(strncmp(cpt, "exclusive", l)==0) {
1048 	     xorriso->mount_opts_flag&= ~1;
1049 	   } else {
1050 	unknown_mode:;
1051 	     if(l<SfileadrL)
1052 	       sprintf(xorriso->info_text, "-mount_opts: unknown option '%s'", cpt);
1053 	     else
1054 	       sprintf(xorriso->info_text, "-mount_opts: oversized parameter (%d)",l);
1055 	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1056 	     xorriso->mount_opts_flag= was;
1057 	     return(0);
1058 	   }
1059 	 }
1060 	 return(1);
1061 	}
1062 	
1063 	
1064 	/* Command -move */
1065 	int Xorriso_option_move(struct XorrisO *xorriso, char *origin, char *dest,
1066 	                        int flag)
1067 	{
1068 	 int ret;
1069 	 char *eff_origin= NULL, *eff_dest= NULL;
1070 	
1071 	 Xorriso_alloc_meM(eff_origin, char, SfileadrL);
1072 	 Xorriso_alloc_meM(eff_dest, char, SfileadrL);
1073 	
1074 	 ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, origin, eff_origin, 0);
1075 	 if(ret <= 0)
1076 	   {ret= 0; goto ex;}
1077 	 ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, dest, eff_dest, 2);
1078 	 if(ret < 0)
1079 	   {ret= 0; goto ex;}
1080 	 ret= Xorriso_rename(xorriso, NULL, eff_origin, eff_dest, 0);
1081 	 if(ret <= 0)
1082 	   goto ex;
1083 	 ret= 1;
1084 	ex:;
1085 	 Xorriso_free_meM(eff_origin);
1086 	 Xorriso_free_meM(eff_dest);
1087 	 return(ret);
1088 	}
1089 	
1090 	 
1091 	/* Command -msg_op */
1092 	int Xorriso_option_msg_op(struct XorrisO *xorriso, char *what, char *arg,
1093 	                          int flag)
1094 	{
1095 	 int ret, available, argc, pargc, i, pflag, max_words, input_lines, msd_mem;
1096 	 char **argv= NULL, **pargv= NULL, *msg= "";
1097 	 char *prefix, *separators;
1098 	
1099 	 msd_mem= xorriso->msg_sieve_disabled;
1100 	
1101 	 ret= 1;
1102 	 if(strcmp(what, "parse") == 0 || strcmp(what, "parse_silently") == 0 ||
1103 	    strcmp(what, "parse_bulk") == 0 ||
1104 	    strcmp(what, "parse_bulk_silently") == 0) {
1105 	   ret= Xorriso_parse_line(xorriso, arg, "", "", 5, &argc, &argv, 0);
1106 	   prefix= "";
1107 	   if(argc > 0) 
1108 	     prefix= argv[0];
1109 	   separators= "";
1110 	   if(argc > 1)
1111 	     separators= argv[1];
1112 	   max_words= 0;
1113 	   if(argc > 2)
1114 	     sscanf(argv[2], "%d", &max_words);
1115 	   pflag= 0;
1116 	   if(argc > 3)
1117 	     sscanf(argv[3], "%d", &pflag);
1118 	   input_lines= 1;
1119 	   if(argc > 4)
1120 	     sscanf(argv[4], "%d", &input_lines);
1121 	   if(strcmp(what, "parse") == 0 || strcmp(what, "parse_silently") == 0) {
1122 	     ret= Xorriso_msg_op_parse(xorriso, "", prefix, separators,
1123 	                               max_words, pflag, input_lines,
1124 	                               (strcmp(what, "parse_silently") == 0));
1125 	   } else {
1126 	     ret= Xorriso_msg_op_parse_bulk(xorriso, prefix, separators,
1127 	                               max_words, pflag, input_lines,
1128 	                               (strcmp(what, "parse_bulk_silently") == 0));
1129 	   }
1130 	   if(ret <= 0)
1131 	     goto ex;
1132 	   xorriso->msg_sieve_disabled= msd_mem;
1133 	   Xorriso__dispose_words(&argc, &argv);
1134 	 } else if(strcmp(what, "start_sieve") == 0) {
1135 	   Xorriso_sieve_dispose(xorriso, 0);
1136 	   ret= Xorriso_sieve_big(xorriso, 0);
1137 	   msg= "Message sieve enabled";
1138 	
1139 	/* >>> } else if(strcmp(what, "add_filter_rule") == 0) { */;
1140 	
1141 	 } else if(strcmp(what, "clear_sieve") == 0) {
1142 	   ret= Xorriso_sieve_clear_results(xorriso, 0);
1143 	   msg= "Recorded message sieve results disposed";
1144 	 } else if(strcmp(what, "end_sieve") == 0) {
1145 	   ret= Xorriso_sieve_dispose(xorriso, 0);
1146 	   msg= "Message sieve disabled";
1147 	 } else if(strcmp(what, "read_sieve") == 0) {
1148 	   ret= Xorriso_sieve_get_result(xorriso, arg, &pargc, &pargv, &available, 0);
1149 	   xorriso->msg_sieve_disabled= 1;
1150 	   sprintf(xorriso->result_line, "%d\n", ret);
1151 	   Xorriso_result(xorriso, 1);
1152 	   if(ret > 0) {
1153 	     sprintf(xorriso->result_line, "%d\n", pargc);
1154 	     Xorriso_result(xorriso, 1);
1155 	     for(i= 0; i < pargc; i++) {
1156 	       ret= Sfile_count_char(pargv[i], '\n') + 1;
1157 	       sprintf(xorriso->result_line, "%d\n", ret);
1158 	       Xorriso_result(xorriso, 1);
1159 	       Sfile_str(xorriso->result_line, pargv[i], 0);
1160 	       strcat(xorriso->result_line, "\n");
1161 	       Xorriso_result(xorriso, 1);
1162 	     }
1163 	   } else {
1164 	     strcpy(xorriso->result_line, "0\n");
1165 	     Xorriso_result(xorriso, 1);
1166 	     available= 0;
1167 	   }
1168 	   sprintf(xorriso->result_line, "%d\n", available);
1169 	   Xorriso_result(xorriso, 1);
1170 	   xorriso->msg_sieve_disabled= msd_mem;
1171 	   Xorriso__dispose_words(&pargc, &pargv);
1172 	   ret= 1;
1173 	 } else if(strcmp(what, "show_sieve") == 0) {
1174 	   ret= Xorriso_sieve_get_result(xorriso, "", &pargc, &pargv, &available, 8);
1175 	   xorriso->msg_sieve_disabled= 1;
1176 	   sprintf(xorriso->result_line, "%d\n", ret);
1177 	   Xorriso_result(xorriso, 1);
1178 	   if(ret > 0) {
1179 	     sprintf(xorriso->result_line, "%d\n", pargc);
1180 	     Xorriso_result(xorriso, 1);
1181 	     for(i= 0; i < pargc; i++) {
1182 	       sprintf(xorriso->result_line, "%s\n", pargv[i]);
1183 	       Xorriso_result(xorriso, 1);
1184 	     }
1185 	   }
1186 	   xorriso->msg_sieve_disabled= msd_mem;
1187 	   Xorriso__dispose_words(&pargc, &pargv);
1188 	 } else if(strcmp(what, "compare_sev") == 0) {
1189 	   ret= Xorriso_parse_line(xorriso, arg, "", ",", 2, &argc, &argv, 0);
1190 	   if(argc < 2) {
1191 	     sprintf(xorriso->info_text,
1192 	             "-msg_op cmp_sev: malformed severity pair '%s'", arg);
1193 	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
1194 	   } else {
1195 	     ret= Xorriso__severity_cmp(argv[0], argv[1]);
1196 	     sprintf(xorriso->result_line, "%d\n", ret);
1197 	     Xorriso_result(xorriso, 1);
1198 	   }
1199 	   Xorriso__dispose_words(&argc, &argv);
1200 	 } else if(strcmp(what, "list_sev") == 0) {
1201 	   sprintf(xorriso->result_line, "%s\n", Xorriso__severity_list(0));
1202 	   Xorriso_result(xorriso, 1);
1203 	 } else {
1204 	   sprintf(xorriso->info_text, "-msg_op: unknown operation '%s'", what);
1205 	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
1206 	   ret= 0;
1207 	 }
1208 	 if(ret > 0 && msg[0])
1209 	   Xorriso_msgs_submit(xorriso, 0, msg, 0, "NOTE", 0);
1210 	
1211 	ex:;
1212 	 xorriso->msg_sieve_disabled= msd_mem;
1213 	 return(ret);
1214 	}
1215 	
1216 	
1217 	/* Option -mv alias -mvi */
1218 	int Xorriso_option_mvi(struct XorrisO *xorriso, int argc, char **argv,
1219 	                      int *idx, int flag)
1220 	{
1221 	 int i, end_idx_dummy, ret, is_dir= 0, was_failure= 0, fret;
1222 	 char *eff_origin= NULL, *eff_dest= NULL, *dest_dir= NULL;
1223 	 char *leafname= NULL;
1224 	 int optc= 0;
1225 	 char **optv= NULL;
1226 	
1227 	 Xorriso_alloc_meM(eff_origin, char, SfileadrL);
1228 	 Xorriso_alloc_meM(eff_dest, char, SfileadrL);
1229 	 Xorriso_alloc_meM(dest_dir, char, SfileadrL);
1230 	 Xorriso_alloc_meM(leafname, char, SfileadrL);
1231 	
1232 	 ret= Xorriso_cpmv_args(xorriso, "-mvi", argc, argv, idx,
1233 	                        &optc, &optv, eff_dest, 0);
1234 	 if(ret<=0)
1235 	   goto ex;
1236 	 if(ret==2) {
1237 	   is_dir= 1;
1238 	   strcpy(dest_dir, eff_dest);
1239 	 }
1240 	 /* Perform movements */
1241 	 for(i= 0; i<optc; i++) {
1242 	   ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi,optv[i],eff_origin,0);
1243 	   if(ret<=0 || xorriso->request_to_abort)
1244 	     goto problem_handler;
1245 	   if(is_dir) {
1246 	     ret= Sfile_leafname(eff_origin, leafname, 0);
1247 	     if(ret<=0)
1248 	       goto problem_handler;
1249 	     strcpy(eff_dest, dest_dir);
1250 	     ret= Sfile_add_to_path(eff_dest, leafname, 0);
1251 	     if(ret<=0) {
1252 	       sprintf(xorriso->info_text, "Effective path gets much too long (%d)",
1253 	             (int) (strlen(eff_dest)+strlen(leafname)+1));
1254 	       Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1255 	       goto problem_handler;
1256 	     }
1257 	   }
1258 	   ret= Xorriso_rename(xorriso, NULL, eff_origin, eff_dest, 0);
1259 	   if(ret<=0 || xorriso->request_to_abort)
1260 	     goto problem_handler;
1261 	   sprintf(xorriso->info_text, "Renamed in ISO image: ");
1262 	   Text_shellsafe(eff_origin, xorriso->info_text, 1);
1263 	   strcat(xorriso->info_text, " to ");
1264 	   Text_shellsafe(eff_dest, xorriso->info_text, 1 | 2);
1265 	   strcat(xorriso->info_text, "\n");
1266 	   Xorriso_info(xorriso, 0);
1267 	
1268 	 continue; /* regular bottom of loop */
1269 	problem_handler:;
1270 	   was_failure= 1;
1271 	   fret= Xorriso_eval_problem_status(xorriso, ret, 1|2);
1272 	   if(fret>=0)
1273 	 continue;
1274 	   goto ex;
1275 	 }
1276 	 ret= !was_failure;
1277 	ex:;
1278 	 Xorriso_free_meM(eff_origin);
1279 	 Xorriso_free_meM(eff_dest);
1280 	 Xorriso_free_meM(dest_dir);
1281 	 Xorriso_free_meM(leafname);
1282 	 Xorriso_opt_args(xorriso, "-mvi",
1283 	                  argc, argv, *idx, &end_idx_dummy, &optc, &optv, 256);
1284 	 return(ret);
1285 	}
1286 	
1287 	
1288 	/* Option -named_pipe_loop */
1289 	int Xorriso_option_named_pipe_loop(struct XorrisO *xorriso, char *mode,
1290 	                                   char *stdin_pipe, char *stdout_pipe,
1291 	                                   char *stderr_pipe, int flag)
1292 	{
1293 	 char *pipe_paths[3], *cpt, *npt;
1294 	 int ret, hflag= 0, l;
1295 	
1296 	 npt= mode;
1297 	 for(cpt= mode; npt != NULL; cpt= npt + 1) {
1298 	   npt= strchr(cpt, ':');
1299 	   if(npt==NULL)
1300 	     l= strlen(cpt);
1301 	   else
1302 	     l= npt-cpt;
1303 	   if(l==0) {
1304 	     ;
1305 	   } else if(strncmp(cpt, "-", l) == 0) {
1306 	     ;
1307 	   } else if(strncmp(cpt, "cleanup", l) == 0) {
1308 	     hflag|= 1;
1309 	   } else if(strncmp(cpt, "keep", l) == 0) {
1310 	     hflag&= ~1;
1311 	   } else if(strncmp(cpt, "buffered", l) == 0) {
1312 	     hflag|= 2;
1313 	   } else if(strncmp(cpt, "direct", l) == 0) {
1314 	     hflag&= ~2;
1315 	   } else { 
1316 	     sprintf(xorriso->info_text, "-named_pipe_loop: unknown mode in '%s'",
1317 	             mode);
1318 	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1319 	     return(0);
1320 	   }
1321 	 }
1322 	 pipe_paths[0]= stdin_pipe;
1323 	 pipe_paths[1]= stdout_pipe;
1324 	 pipe_paths[2]= stderr_pipe;
1325 	 ret= Xorriso_named_pipe_loop(xorriso, pipe_paths, hflag);
1326 	 return(ret);
1327 	}
1328 	
1329 	
1330 	/* Option -no_rc */
1331 	int Xorriso_option_no_rc(struct XorrisO *xorriso, int flag)
1332 	{
1333 	 xorriso->no_rc= 1;
1334 	 return(1);
1335 	}
1336 	
1337 	
1338 	/* Option -not_leaf , (-hide_disk_leaf , -as mkisofs -hide) */
1339 	/* @param flag  bit0-bit5= hide rather than adding to disk_exclusions
1340 	                  bit0= add to iso_rr_hidings
1341 	                  bit1= add to joliet_hidings
1342 	                  bit2= add to hfsplus_hidings
1343 	*/
1344 	int Xorriso_option_not_leaf(struct XorrisO *xorriso, char *pattern, int flag)
1345 	{
1346 	 regex_t re;
1347 	 char *regexpr= NULL;
1348 	 int ret= 0;
1349 	
1350 	 Xorriso_alloc_meM(regexpr, char, 2 * SfileadrL + 2);
1351 	
1352 	 if(pattern[0]==0)
1353 	   {ret= 0; goto cannot_add;}
1354 	 Xorriso__bourne_to_reg(pattern, regexpr, 0);
1355 	 if(regcomp(&re, regexpr, 0)!=0)
1356 	   {ret= 0; goto cannot_add;}
1357 	 if(flag & 63) {
1358 	   if(flag & 1) {
1359 	     ret= Exclusions_add_not_leafs(xorriso->iso_rr_hidings, pattern, &re, 0);
1360 	     if(ret<=0)
1361 	       goto cannot_add;
1362 	   }
1363 	   if(flag & 2) {
1364 	     ret= Exclusions_add_not_leafs(xorriso->joliet_hidings, pattern, &re, 0);
1365 	     if(ret<=0)
1366 	       goto cannot_add;
1367 	   }
1368 	   if(flag & 4) {
1369 	     ret= Exclusions_add_not_leafs(xorriso->hfsplus_hidings, pattern, &re, 0);
1370 	     if(ret<=0)
1371 	       goto cannot_add;
1372 	   }
1373 	 } else {
1374 	   ret= Exclusions_add_not_leafs(xorriso->disk_exclusions, pattern, &re, 0);
1375 	 }
1376 	 if(ret<=0) {
1377 	cannot_add:;
1378 	   sprintf(xorriso->info_text,"Cannot add pattern: %s ",
1379 	           (flag & 3) ? "-hide_disk_leaf" : "-not_leaf");
1380 	   Text_shellsafe(pattern, xorriso->info_text, 1);
1381 	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1382 	   goto ex;
1383 	 }
1384 	 ret= 1;
1385 	ex:;
1386 	 Xorriso_free_meM(regexpr);
1387 	 return(ret);
1388 	}
1389 	
1390 	
1391 	/* Option -not_list , -quoted_not_list */
1392 	/* @param flag bit0= -quoted_not_list */
1393 	int Xorriso_option_not_list(struct XorrisO *xorriso, char *adr, int flag)
1394 	{
1395 	 int ret, linecount= 0, insertcount= 0, null= 0, argc= 0, i;
1396 	 FILE *fp= NULL;
1397 	 char **argv= NULL;
1398 	 
1399 	 Xorriso_pacifier_reset(xorriso, 0);
1400 	 if(adr[0]==0) {
1401 	   sprintf(xorriso->info_text, "Empty file name given with %s",
1402 	           (flag & 1) ? "-quoted_not_list" : "-not_list");
1403 	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1404 	   return(0);
1405 	 }
1406 	 ret= Xorriso_afile_fopen(xorriso, adr, "rb", &fp, 0);
1407 	 if(ret <= 0)
1408 	   return(0);
1409 	 while(1) {
1410 	   ret= Xorriso_read_lines(xorriso, fp, &linecount, &argc, &argv,
1411 	                           4 | (flag & 1) );
1412 	   if(ret <= 0)
1413 	     goto ex;
1414 	   if(ret == 2)
1415 	 break;
1416 	   for(i= 0; i < argc; i++) {
1417 	     if(argv[i][0] == 0)
1418 	   continue;
1419 	     if(strchr(argv[i], '/')!=NULL) {
1420 	       null= 0;
1421 	       ret= Xorriso_option_not_paths(xorriso, 1, argv + i, &null, 0);
1422 	     } else
1423 	       ret= Xorriso_option_not_leaf(xorriso, argv[i], 0);
1424 	     if(ret<=0)
1425 	       goto ex;
1426 	     insertcount++;
1427 	   }
1428 	 }
(1) Event start: Starting defect path here.
1429 	 ret= 1;
1430 	ex:;
(2) Event alloc_arg: "Xorriso_read_lines" allocates memory that is stored into "argv". [details]
Also see events: [leaked_storage]
1431 	 Xorriso_read_lines(xorriso, fp, &linecount, &argc, &argv, 2);
(3) Event cond_true: Condition "fp != NULL", taking true branch.
(4) Event cond_true: Condition "fp != stdin", taking true branch.
1432 	 if(fp != NULL && fp != stdin)
1433 	   fclose(fp);
(5) Event cond_false: Condition "ret <= 0", taking false branch.
1434 	 if(ret<=0) {
1435 	   sprintf(xorriso->info_text, "Aborted reading of file ");
1436 	   Text_shellsafe(adr, xorriso->info_text, 1);
1437 	   sprintf(xorriso->info_text + strlen(xorriso->info_text),
1438 	           " in line number %d", linecount);
1439 	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
(6) Event if_end: End of if statement.
1440 	 }
1441 	 sprintf(xorriso->info_text, "Added %d exclusion list items from file ",
1442 	         insertcount);
1443 	 Text_shellsafe(adr, xorriso->info_text, 1);
1444 	 strcat(xorriso->info_text, "\n");
1445 	 Xorriso_info(xorriso,0);
(7) Event leaked_storage: Variable "argv" going out of scope leaks the storage it points to.
Also see events: [alloc_arg]
1446 	 return(ret);
1447 	}
1448 	
1449 	
1450 	/* Option -not_mgt */
1451 	int Xorriso_option_not_mgt(struct XorrisO *xorriso, char *setting, int flag)
1452 	{
1453 	 int ret;
1454 	 char *what_data= NULL, *what, *what_next;
1455 	
1456 	 Xorriso_alloc_meM(what_data, char, SfileadrL);
1457 	
1458 	 if(Sfile_str(what_data, setting, 0)<=0) {
1459 	   sprintf(xorriso->info_text,
1460 	           "-not_mgt: setting string is much too long (%d)",
1461 	           (int) strlen(setting));
1462 	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1463 	   {ret= 0; goto ex;}
1464 	 } 
1465 	 for(what= what_data; what!=NULL; what= what_next) {
1466 	   what_next= strchr(what, ':');
1467 	   if(what_next!=NULL) {
1468 	     *what_next= 0;
1469 	     what_next++;
1470 	   }
1471 	
1472 	   if(strcmp(what, "reset")==0 || strcmp(what, "erase")==0) {
1473 	     if(strcmp(what, "reset")==0)
1474 	       xorriso->disk_excl_mode= 1;
1475 	     Exclusions_destroy(&(xorriso->disk_exclusions), 0);
1476 	     ret= Exclusions_new(&(xorriso->disk_exclusions), 0);
1477 	     if(ret<=0) {
1478 	       Xorriso_no_malloc_memory(xorriso, NULL, 0);
1479 	       goto ex;
1480 	     }
1481 	   } else if(strcmp(what, "on")==0) {
1482 	     xorriso->disk_excl_mode|= 1;
1483 	   } else if(strcmp(what, "off")==0) {
1484 	     xorriso->disk_excl_mode&= ~1;
1485 	   } else if(strcmp(what, "param_on")==0) {
1486 	     xorriso->disk_excl_mode|= 2;
1487 	   } else if(strcmp(what, "param_off")==0) {
1488 	     xorriso->disk_excl_mode&= ~2;
1489 	   } else if(strcmp(what, "subtree_on")==0) {
1490 	     xorriso->disk_excl_mode|= 4;
1491 	   } else if(strcmp(what, "subtree_off")==0) {
1492 	     xorriso->disk_excl_mode&= ~4;
1493 	   } else if(strcmp(what, "ignore_on")==0) {
1494 	     xorriso->disk_excl_mode|= 8;
1495 	   } else if(strcmp(what, "ignore_off")==0) {
1496 	     xorriso->disk_excl_mode&= ~8;
1497 	   } else {
1498 	     sprintf(xorriso->info_text, "-not_mgt: unknown setting '%s'", what);
1499 	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1500 	     {ret= 0; goto ex;}
1501 	   }
1502 	 }
1503 	 ret= 1;
1504 	ex:;
1505 	 Xorriso_free_meM(what_data);
1506 	 return(ret);
1507 	}
1508 	
1509 	
1510 	/* Option -not_paths , (-hide_disk_paths , -as mkisofs -hide) */
1511 	/* @param flag  bit0= add to iso_rr_hidings rather than disk_exclusions
1512 	                bit1= add to joliet_hidings rather than disk_exclusions
1513 	                bit2= enable disk pattern expansion regardless of -disk_pattern
1514 	                bit8-13= consolidated hide state bits, duplicating bit0-1
1515 	                   bit8= add to iso_rr_hidings
1516 	                   bit9= add to joliet_hidings
1517 	                  bit10= add to hfsplus_hidings
1518 	*/
1519 	int Xorriso_option_not_paths(struct XorrisO *xorriso, int argc, char **argv,
1520 	                             int *idx, int flag)
1521 	{
1522 	 int ret, end_idx, num_descr= 0, dummy, optc= 0, i;
1523 	 char **descr= NULL, **optv= NULL, *eff_path= NULL, *hpt= NULL;
1524 	
1525 	 end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx,
1526 	                          (xorriso->do_disk_pattern == 1 || (flag & 4)) | 2);
1527 	 if(end_idx<=0)
1528 	   {ret= end_idx; goto ex;}
1529 	
1530 	 num_descr= end_idx - *idx;
1531 	 if(num_descr<=0)
1532 	   {ret= 1; goto ex;}
1533 	 
1534 	 /* produce absolute patterns */
1535 	 Xorriso_alloc_meM(eff_path, char, SfileadrL);
1536 	 descr= TSOB_FELD(char *, num_descr);
1537 	 if(descr==NULL) {
1538 	no_memory:;
1539 	   Xorriso_no_pattern_memory(xorriso, sizeof(char *) * (off_t) num_descr, 0);
1540 	   ret= -1; goto ex;
1541 	 }
1542 	 for(i= 0; i<num_descr; i++)
1543 	   descr[i]= NULL;
1544 	 for(i= 0; i<num_descr; i++) {
1545 	   ret= Xorriso_normalize_img_path(xorriso, xorriso->wdx, argv[i+*idx],
1546 	                                   eff_path, 2|4);
1547 	   if(ret<=0)
1548 	     goto ex;
1549 	   descr[i]= strdup(eff_path); 
1550 	   if(descr[i]==NULL)
1551 	     goto no_memory;
1552 	 }
1553 	
1554 	 ret= Xorriso_opt_args(xorriso,
1555 	                       (flag & 0x3f03) ? "-hide_disk_paths" : "-not_paths",
1556 	                       num_descr, descr, 0, &dummy, &optc, &optv,
1557 	                       2 | ((flag & 4) << 7));
1558 	 if(ret<=0)
1559 	   goto ex; 
1560 	 if(flag & 0x3f03) {
1561 	   if(flag & 0x0101) {
1562 	     ret= Exclusions_add_not_paths(xorriso->iso_rr_hidings,
1563 	                                   num_descr, descr, optc, optv, 0);
1564 	     if(ret<=0) {
1565 	no_hide:;
1566 	       sprintf(xorriso->info_text, "Cannot add path list: -hide_disk_paths ");
1567 	       hpt= Xorriso__hide_mode_text(flag & 0x3f03, 0);
1568 	       if(hpt != NULL)
1569 	         sprintf(xorriso->info_text + strlen(xorriso->info_text), "%s ", hpt);
1570 	       Xorriso_free_meM(hpt);
1571 	       Text_shellsafe(argv[*idx], xorriso->info_text, 1);
1572 	       strcat(xorriso->info_text, num_descr > 1 ? " ... " : " ");
1573 	       strcat(xorriso->info_text, xorriso->list_delimiter);
1574 	       Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1575 	       goto ex;
1576 	     }
1577 	   }
1578 	   if(flag & 0x0202) {
1579 	     ret= Exclusions_add_not_paths(xorriso->joliet_hidings,
1580 	                                   num_descr, descr, optc, optv, 0);
1581 	     if(ret<=0)
1582 	       goto no_hide;
1583 	   }
1584 	   if(flag & 0x0400) {
1585 	     ret= Exclusions_add_not_paths(xorriso->hfsplus_hidings,
1586 	                                   num_descr, descr, optc, optv, 0);
1587 	     if(ret<=0)
1588 	       goto no_hide;
1589 	   }
1590 	 } else {
1591 	   ret= Exclusions_add_not_paths(xorriso->disk_exclusions,
1592 	                                 num_descr, descr, optc, optv, 0);
1593 	   if(ret<=0) {
1594 	     sprintf(xorriso->info_text,"Cannot add path list: -not_paths ");
1595 	     Text_shellsafe(argv[*idx], xorriso->info_text, 1);
1596 	     strcat(xorriso->info_text, num_descr > 1 ? " ... " : " ");
1597 	     strcat(xorriso->info_text, xorriso->list_delimiter);
1598 	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1599 	   }
1600 	 }
1601 	ex:;
1602 	 (*idx)= end_idx;
1603 	 Xorriso_opt_args(xorriso, "-not_paths",
1604 	                  num_descr, descr, 0, &dummy, &optc, &optv, 256);
1605 	 if(descr!=NULL) {
1606 	   for(i= 0; i<num_descr; i++)
1607 	     if(descr[i]!=NULL)
1608 	       free(descr[i]);
1609 	   free((char *) descr);
1610 	   descr= NULL;
1611 	 }
1612 	 Xorriso_free_meM(eff_path);
1613 	 return(ret);
1614 	}
1615 	
1616 	
1617 	/* Option -options_from_file */
1618 	int Xorriso_option_options_from_file(struct XorrisO *xorriso, char *adr,
1619 	                                     int flag)
1620 	/*
1621 	 bit0= called from Xorriso_prescan_args,
1622 	       therefore execute via that same function
1623 	*/
1624 	/*
1625 	return:
1626 	 <=0 error , 1 = success , 3 = end program run
1627 	*/
1628 	{
1629 	 int ret,linecount= 0, argc= 0, was_failure= 0, fret;
1630 	 FILE *fp= NULL;
1631 	 char **argv= NULL;
1632 	 int linec= 0;
1633 	 char *line= NULL, **linev= NULL;
1634 	
1635 	 if(adr[0]==0) {
1636 	   sprintf(xorriso->info_text,"Empty file name given with -options_from_file");
1637 	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
1638 	   return(0);
1639 	 }
1640 	 if(xorriso->is_dialog) {
1641 	   sprintf(xorriso->info_text,"+ performing command lines from file ");
1642 	   Text_shellsafe(adr, xorriso->info_text, 1);
1643 	   strcat(xorriso->info_text, " :\n");
1644 	   Xorriso_info(xorriso,1);
1645 	 }
1646 	 ret= Xorriso_afile_fopen(xorriso, adr, "rb", &fp, 0);
1647 	 if(ret <= 0)
1648 	   return(0);
1649 	 sprintf(xorriso->info_text, "Command file:  ");
1650 	 Text_shellsafe(adr, xorriso->info_text, 1);
1651 	 Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
1652 	 while(1) {
1653 	   ret= Xorriso_read_lines(xorriso, fp, &linecount, &linec, &linev, 1 | 8);
1654 	   if(ret <= 0)
1655 	     goto ex; /* no problem_handler because there is no sense in going on */
1656 	   if(ret == 2)
1657 	 break;
1658 	   line= linev[0];
1659 	   if(line[0]==0 || line[0]=='#')
1660 	 continue;
1661 	
1662 	   if(flag&1) {
1663 	     ret= Sfile_make_argv(xorriso->progname, line, &argc, &argv,
1664 	                          4 | 8 | ((xorriso->bsl_interpretation & 3) << 5));
1665 	     if(ret<=0)
1666 	       goto problem_handler;
1667 	     ret= Xorriso_prescan_args(xorriso,argc,argv,1);
1668 	     if(ret==0)
1669 	       {ret= 3; goto ex;}
1670 	     if(ret<0)
1671 	       goto problem_handler;
1672 	   } else {
1673 	     if(xorriso->is_dialog) {
1674 	       sprintf(xorriso->info_text,"+ %d:  %s\n",linecount,line);
1675 	       Xorriso_info(xorriso,1);
1676 	     }
1677 	     ret= Xorriso_execute_option(xorriso,line,1|(1<<16));
1678 	     if(ret==3)
1679 	       goto ex;
1680 	     if(ret<=0)
1681 	       goto problem_handler;
1682 	   }
1683 	
1684 	 continue; /* regular bottom of loop */
1685 	problem_handler:;
1686 	   was_failure= 1;
1687 	   fret= Xorriso_eval_problem_status(xorriso, ret, 1);
1688 	   if(fret>=0)
1689 	 continue;
1690 	   goto ex;
1691 	 }
1692 	 ret= 1;
1693 	ex:;
1694 	 Sfile_make_argv("", "", &argc, &argv, 2); /* release memory */
1695 	 Xorriso_read_lines(xorriso, fp, &linecount, &linec, &linev, 2);
1696 	 Xorriso_reset_counters(xorriso,0);
1697 	 if(fp != NULL && fp != stdin)
1698 	   fclose(fp);
1699 	 if(ret<=0) {
1700 	   sprintf(xorriso->info_text,
1701 	           "error triggered by line %d of file:\n    ", linecount);
1702 	   Text_shellsafe(adr, xorriso->info_text, 1);
1703 	   strcat(xorriso->info_text, "\n");
1704 	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 1);
1705 	 }
1706 	 sprintf(xorriso->info_text, "Command file end:  ");
1707 	 Text_shellsafe(adr, xorriso->info_text, 1);
1708 	 Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
1709 	 if(ret!=1)
1710 	   return(ret);
1711 	 return(!was_failure);
1712 	}
1713 	
1714 	
1715 	/* Option -osirrox "on"|"off" */
1716 	int Xorriso_option_osirrox(struct XorrisO *xorriso, char *mode, int flag)
1717 	{
1718 	 int l, allow_restore;
1719 	 char *npt, *cpt;
1720 	
1721 	 allow_restore= xorriso->allow_restore;
1722 	
1723 	 npt= cpt= mode;
1724 	 for(cpt= mode; npt!=NULL; cpt= npt+1) {
1725 	   npt= strchr(cpt,':');
1726 	   if(npt==NULL)
1727 	     l= strlen(cpt);
1728 	   else
1729 	     l= npt-cpt;
1730 	   if(l==0 && mode[0]!=0)
1731 	     goto unknown_mode;
1732 	   if(strncmp(cpt, "off", l)==0 && l >= 3)
1733 	     allow_restore= 0;
1734 	   else if(strncmp(cpt, "banned", l)==0 && l >= 5)
1735 	     allow_restore= -1;
1736 	   else if(strncmp(cpt, "blocked", l)==0 && l >= 7)
1737 	     allow_restore= -2;
1738 	   else if(strncmp(cpt, "unblock", l)==0 && l >= 7) {
1739 	     if(xorriso->allow_restore == -2)
1740 	       xorriso->allow_restore= 0;
1741 	     allow_restore= 1;
1742 	   } else if(strncmp(cpt, "device_files", l)==0 && l >= 12)
1743 	     allow_restore= 2;
1744 	   else if((strncmp(cpt, "on", l)==0 && l >= 2) || mode[0]==0)
1745 	     allow_restore= 1;
1746 	   else if(strncmp(cpt, "concat_split_on", l)==0 && l >= 15)
1747 	     xorriso->do_concat_split= 1;
1748 	   else if(strncmp(cpt, "concat_split_off", l)==0 && l >= 16)
1749 	     xorriso->do_concat_split= 0;
1750 	   else if(strncmp(cpt, "auto_chmod_on", l)==0 && l >= 13)
1751 	     xorriso->do_auto_chmod= 1;
1752 	   else if(strncmp(cpt, "auto_chmod_off", l)==0 && l >= 14)
1753 	     xorriso->do_auto_chmod= 0;
1754 	   else if(strncmp(cpt, "sort_lba_on", l)==0 && l >= 11)
1755 	     xorriso->do_restore_sort_lba= 1;
1756 	   else if(strncmp(cpt, "sort_lba_off", l)==0 && l >= 12)
1757 	     xorriso->do_restore_sort_lba= 0;
1758 	   else if(strncmp(cpt, "o_excl_on", l)==0 && l >= 9)
1759 	     xorriso->drives_exclusive= 1;
1760 	   else if(strncmp(cpt, "o_excl_off", l)==0 && l >= 10)
1761 	     xorriso->drives_exclusive= 0;
1762 	   else if(strncmp(cpt, "strict_acl_on", l)==0 && l >= 13)
1763 	     xorriso->do_strict_acl|= 1;
1764 	   else if(strncmp(cpt, "strict_acl_off", l)==0 && l >= 14)
1765 	     xorriso->do_strict_acl&= ~1;
1766 	   else {
1767 	unknown_mode:;
1768 	     sprintf(xorriso->info_text, "-osirrox: unknown mode '%s'", cpt);
1769 	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1770 	     return(0);
1771 	   }
1772 	 }
1773 	 if(allow_restore > 0 && xorriso->allow_restore == -1) {
1774 	   sprintf(xorriso->info_text,
1775 	     "-osirrox: was already permanently disabled by setting 'banned'");
1776 	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1777 	   return(0);
1778 	 }
1779 	 if(allow_restore > 0 && xorriso->allow_restore == -2) {
1780 	   sprintf(xorriso->info_text,
1781 	           "-osirrox: is currently disabled by setting 'blocked'");
1782 	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1783 	   return(0);
1784 	 }
1785 	 if(xorriso->allow_restore != -1)
1786 	   xorriso->allow_restore= allow_restore;
1787 	 sprintf(xorriso->info_text,
1788 	         "Copying of file objects from ISO image to disk filesystem is: %s\n",
1789 	         xorriso->allow_restore > 0 ? "Enabled" : "Disabled");
1790 	 Xorriso_info(xorriso, 0);
1791 	 return(1);
1792 	}
1793 	
1794 	
1795 	/* Option -overwrite "on"|"nondir"|"off" */
1796 	int Xorriso_option_overwrite(struct XorrisO *xorriso, char *mode, int flag)
1797 	{
1798 	 if(strcmp(mode, "off")==0)
1799 	   xorriso->do_overwrite= 0;
1800 	 else if(strcmp(mode, "on")==0)
1801 	   xorriso->do_overwrite= 1;
1802 	 else if(strcmp(mode, "nondir")==0)
1803 	   xorriso->do_overwrite= 2;
1804 	 else {
1805 	   sprintf(xorriso->info_text, "-overwrite: unknown mode '%s'", mode);
1806 	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1807 	   return(0);
1808 	 }
1809 	 return(1);
1810 	}
1811 	
1812 	
1813 	


















































1    	
2    	/* xorriso - creates, loads, manipulates and burns ISO 9660 filesystem images.
3    	
4    	   Copyright 2007-2017 Thomas Schmitt, <address@hidden>
5    	
6    	   Provided under GPL version 2 or later.
7    	
8    	   This file contains the implementation of emulators for mkisofs and cdrecord.
9    	*/
10   	
11   	#ifdef HAVE_CONFIG_H
12   	#include "../config.h"
13   	#endif
14   	
15   	#include <ctype.h>
16   	#include <sys/types.h>
17   	#include <unistd.h>
18   	#include <stdlib.h>
19   	#include <stdio.h>
20   	#include <string.h>
21   	#include <sys/stat.h>
22   	#include <sys/time.h>
23   	#include <time.h>
24   	#include <fcntl.h>
25   	#include <errno.h>
26   	
27   	#include "xorriso.h"
28   	#include "xorriso_private.h"
29   	#include "xorrisoburn.h"
30   	
31   	
32   	int Xorriso_cdrskin_uses_stdout(struct XorrisO *xorriso, int argc, char **argv,
33   	                                int flag)
34   	{
35   	 int i;
36   	
37   	 for(i= 0; i < argc; i++) {
38   	   if(strcmp(argv[i], "dev=-") == 0 ||
39   	      strcmp(argv[i], "dev=stdio:/dev/fd/1") == 0 ||
40   	      strcmp(argv[i], "-dev=-") == 0 ||
41   	      strcmp(argv[i], "-dev=stdio:/dev/fd/1") == 0)
42   	     return(1);
43   	 }
44   	 return(0);
45   	}
46   	
47   	
48   	int Xorriso_cdrskin_help(struct XorrisO *xorriso, int flag)
49   	{
50   	 static char helptext[][80]= {
51   	"Usage: xorriso -as cdrecord [options|source_addresses]",
52   	"Note: This is not cdrecord. See xorriso -help, xorriso -version, man xorrecord",
53   	"Options:",
54   	"\t-version\tprint version information and exit emulation",
55   	"\t--devices\tprint list of available MMC drives and exit emulation",
56   	"\tdev=target\tpseudo-SCSI target to use as CD-Recorder",
57   	"\tdrive_scsi_dev_family=sr|scd|sg\t\tselect Linux device type",
58   	"\t-v\t\tincrement verbose level by one",
59   	"\t-V\t\tincrement SCSI command transport verbose level by one",
60   	"\t-checkdrive\tcheck if a driver for the drive is present",
61   	"\t-inq\t\tdo an inquiry for the drive",
62   	"\tspeed=#\t\tset speed of drive",
63   	"\tblank=type\tblank a CD-RW disc (see blank=help)",
64   	"\tfs=#\t\tSet fifo size to # (0 to disable, default is 4 MB)",
65   	"\t-eject\t\teject the disk after doing the work",
66   	"\t-dummy\t\tdo everything with laser turned off",
67   	"\t-msinfo\t\tretrieve multi-session info for mkisofs >= 1.10",
68   	"\t-toc\t\tretrieve and print TOC/PMA data",
69   	"\t-atip\t\tretrieve media state, print \"Is *erasable\"",
70   	"\t-multi\t\tgenerate a TOC that allows multi session",
71   	"\t--multi_if_possible\tapply -multi if the medium supports it",
72   	"\t-waiti\t\twait until input is available before opening SCSI",
73   	"\t-tao\t\tWrite disk in TAO mode.",
74   	"\t-dao\t\tWrite disk in SAO mode.",
75   	"\t-sao\t\tWrite disk in SAO mode.",
76   	"\ttsize=#\t\tannounces exact size of source data",
77   	"\tpadsize=#\tAmount of padding",
78   	"\t-data\t\tSubsequent tracks are CD-ROM data mode 1 (default)",
79   	"\t-isosize\tUse iso9660 file system size for next data track",
80   	"\t-pad\t\tpadsize=30k",
81   	"\t-nopad\t\tDo not pad",
82   	"\tminbuf=\t\tKeep drive buffer hungry",
83   	"\tmodesty_on_drive=\tLike minbuf=, but with more parameters",
84   	"\t-immed\t\tEquivalent to minbuf=75",
85   	"\t--grow_overwriteable_iso\temulate multi-session on DVD+RW, BD-RE",
86   	"\twrite_start_address=#\t\twrite to byte address on DVD+RW, BD-RE",
87   	"\tstream_recording=on|number\ttry to get full speed on DVD-RAM, BD",
88   	"\tuse_immed_bit=on|off|default\tcontrol use of Immed bit",
89   	"\tdvd_obs=default|32k|64k\t\tbytes per DVD/BD write operation",
90   	"\tstdio_sync=on|off|end|number\twhether to fsync output to \"stdio:\"",
91   	"\t--no_rc\t\tDo not execute xorriso startup files",
92   	"\t-help\t\tprint this text to stderr and exit emulation",
93   	"Actually this is the integrated ISO RockRidge filesystem manipulator xorriso",
94   	"lending its libburn capabilities to a very limited cdrecord emulation. Only",
95   	"a single data track can be burnt to blank, appendable or overwriteable media.",
96   	"A much more elaborate cdrecord emulator is cdrskin from the same project.",
97   	"@End_of_helptexT@"
98   	};
99   	 int i;
100  	
101  	 for(i= 0; strcmp(helptext[i], "@End_of_helptexT@")!=0; i++) {
102  	   sprintf(xorriso->info_text, "%s\n", helptext[i]);
103  	   Xorriso_info(xorriso,0);
104  	 }
105  	 return(1);
106  	}
107  	
108  	
109  	/* micro version of cdrskin */
110  	int Xorriso_cdrskin(struct XorrisO *xorriso, char *whom, int argc, char **argv,
111  	                    int flag)
112  	{
113  	 int ret, i, k, mem_do_close, aq_ret, eject_ret, msc1, msc2, hflag;
114  	 int do_atip= 0, do_checkdrive= 0, do_eject= 0, do_scanbus= 0;
115  	 int do_toc= 0, do_verbous= 0, do_version= 0, do_help= 0, do_waiti= 0;
116  	 int do_multi= 0, do_msinfo= 0, do_grow= 0, do_isosize= 0, do_xa1= 0;
117  	 int do_auto_close= 0;
118  	 double write_start_address= -1.0, tsize= -1.0, mem_auto_close;
119  	 char *track_source= NULL, *dev_adr= NULL, *cpt;
120  	 char mem_report_about_text[80], *report_about= "SORRY", blank_mode[80];
121  	 char speed[80], *argpt;
122  	
123  	 /* cdrecord 2.01 options which are not scheduled for implementation, yet */
124  	 static char ignored_partial_options[][41]= {
125  	   "timeout=", "debug=", "kdebug=", "kd=", "driver=", "ts=",
126  	   "pregap=", "defpregap=", "mcn=", "isrc=", "index=", "textfile=",
127  	   "pktsize=", "cuefile=",
128  	   "gracetime=",
129  	
130  	   "assert_write_lba=", "fifo_start_at=", "dev_translation=",
131  	   "fallback_program=",
132  	   "tao_to_sao_tsize=", 
133  	   
134  	   "direct_write_amount=", "msifile=",
135  	
136  	   ""
137  	 };
138  	 static char ignored_full_options[][41]= {
139  	   "-d", "-silent", "-s", "-setdropts", "-prcap",
140  	   "-reset", "-abort", "-overburn", "-ignsize", "-useinfo",
141  	   "-fix", "-nofix",
142  	   "-raw", "-raw96p", "-raw16",
143  	   "-clone", "-text",
144  	   "-cdi", "-preemp", "-nopreemp", "-copy", "-nocopy",
145  	   "-scms", "-shorttrack", "-noshorttrack", "-packet", "-noclose",
146  	   "-media-info", "-minfo",
147  	   "-load", "-lock", "-raw96r", "-swab",
148  	   "-force", "-format",
149  	
150  	   "--adjust_speed_to_drive", "--allow_emulated_drives", "--allow_setuid",
151  	   "--allow_untested_media", "--any_track", "--demand_a_drive", 
152  	   "--fifo_disable", "--fifo_start_empty", "--fill_up_media",
153  	   "--list_ignored_options", "--no_rc", "--no_convert_fs_adr",
154  	   "--prodvd_cli_compatible", "--single_track", 
155  	   "--tell_media_space",
156  	
157  	   ""
158  	 };
159  	
160  	static char blank_help[][80]= {
161  	"Blanking options:",
162  	"\tall\t\tblank the entire disk",
163  	"\tdisc\t\tblank the entire disk",
164  	"\tdisk\t\tblank the entire disk",
165  	"\tfast\t\tminimally blank the entire disk",
166  	"\tminimal\t\tminimally blank the entire disk",
167  	"\tas_needed\tblank or format medium to make it ready for (re-)use",
168  	"\tdeformat\t\tblank a formatted DVD-RW",
169  	"\tdeformat_quickest\tminimally blank a formatted DVD-RW to DAO only",
170  	"\tformat_overwrite\tformat a DVD-RW to \"Restricted Overwrite\"",
171  	"@End_of_helptexT@"
172  	};
173  	
174  	 mem_do_close= xorriso->do_close;
175  	 mem_auto_close= xorriso->auto_close;
176  	 Xorriso_alloc_meM(track_source, char, SfileadrL);
177  	 Xorriso_alloc_meM(dev_adr, char, SfileadrL);
178  	
179  	 strcpy(mem_report_about_text, xorriso->report_about_text);
180  	
181  	 track_source[0]= 0;
182  	 dev_adr[0]= 0;
183  	 blank_mode[0]= 0;
184  	 speed[0]= 0;
185  	
186  	 if(xorriso->in_drive_handle != NULL) {
187  	   ret= Xorriso_option_dev(xorriso, "", 1|32); /* give up indev */
188  	   if(ret!=1)
189  	     goto ex;
190  	 }
191  	
192  	
193  	 /* Assess plan, make settings */
194  	 for(i= 0; i<argc; i++) {
195  	   sprintf(xorriso->info_text, "-as %s: ", whom);
196  	   Text_shellsafe(argv[i], xorriso->info_text, 1);
197  	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
198  	
199  	   argpt= argv[i];
200  	   if (strncmp(argpt, "--", 2) == 0 && strlen(argpt) > 3)
201  	     argpt++;
202  	
203  	   for(k=0;ignored_partial_options[k][0]!=0;k++) {
204  	     if(argpt[0]=='-')
205  	       if(strncmp(argpt+1,ignored_partial_options[k],
206  	                            strlen(ignored_partial_options[k]))==0) {
207  	         argpt++;
208  	         goto no_volunteer;
209  	       }
210  	     if(strncmp(argpt,ignored_partial_options[k],
211  	                        strlen(ignored_partial_options[k]))==0)
212  	       goto no_volunteer;
213  	   }
214  	   for(k=0;ignored_full_options[k][0]!=0;k++)
215  	     if(strcmp(argpt,ignored_full_options[k])==0)
216  	       goto no_volunteer;
217  	   if(0) {
218  	no_volunteer:;
219  	     sprintf(xorriso->info_text, "-as %s: Ignored option ", whom);
220  	     Text_shellsafe(argpt, xorriso->info_text, 1);
221  	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
222  	 continue;
223  	   }
224  	
225  	   if(strcmp(argpt, "-atip")==0) {
226  	     do_atip= 1;
227  	   } else if(strcmp(argpt, "-audio")==0) {
228  	     sprintf(xorriso->info_text, "-as %s: Option -audio not supported.", whom);
229  	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
230  	     ret= 0; goto ex;
231  	   } else if(strncmp(argpt, "-blank=", 7)==0 ||
232  	             strncmp(argpt, "blank=", 6)==0) {
233  	     cpt= strchr(argpt, '=')+1;
234  	     if(strcmp(cpt,"all")==0 || strcmp(cpt,"disc")==0
235  	        || strcmp(cpt,"disk")==0) {
236  	       strcpy(blank_mode, "all");
237  	     } else if(strcmp(cpt,"fast")==0 || strcmp(cpt,"minimal")==0) {
238  	       strcpy(blank_mode, "fast");
239  	     } else if(strcmp(cpt,"help")==0) {
240  	       strcpy(blank_mode, "help");
241  	     } else if(strcmp(cpt,"deformat")==0 ||
242  	               strcmp(cpt,"deformat_sequential")==0 ||
243  	               strcmp(cpt,"deformat_quickest")==0 ||
244  	               strcmp(cpt,"deformat_sequential_quickest")==0) {
245  	       strcpy(blank_mode, cpt);
246  	     } else if(strcmp(cpt,"format_overwrite")==0) {
247  	       strcpy(blank_mode, "format_overwrite");
248  	     } else if(strcmp(cpt,"as_needed")==0) {
249  	       strcpy(blank_mode, "as_needed");
250  	     } else {
251  	       sprintf(xorriso->info_text, "-as %s: blank=", whom);
252  	       Text_shellsafe(cpt, xorriso->info_text, 1);
253  	       strcat(xorriso->info_text, " not supported. See blank=help .");
254  	       Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
255  	       ret= 0; goto ex;
256  	     }
257  	   } else if(strcmp(argpt, "-checkdrive")==0) {
258  	     do_checkdrive= 1;
259  	   } else if(strcmp(argpt, "-dao")==0) {
260  	     xorriso->do_tao= -1;
261  	   } else if(strcmp(argpt, "-data")==0) {
262  	     /* ok */;
263  	   } else if(strncmp(argpt, "-dev=", 5)==0 ||
264  	             strncmp(argpt, "dev=", 4)==0) {
265  	     cpt= strchr(argpt, '=')+1;
266  	     strcpy(dev_adr, cpt);
267  	   } else if(strcmp(argv[i], "--devices")==0) {      /* intentional: argv[i] */
268  	     do_scanbus= 2;
269  	   } else if(strncmp(argpt,"driveropts=", 11)==0 ||
270  	             strncmp(argpt,"-driveropts=", 12)==0) {
271  	     if(strcmp(argpt+11, "help")==0) {
272  	       fprintf(stderr,"Driver options:\n");
273  	       fprintf(stderr,
274  	               "burnfree\tPrepare writer to use BURN-Free technology\n");
275  	     } 
276  	   } else if(strcmp(argpt, "-dummy")==0) {
277  	     xorriso->do_dummy= 1;
278  	   } else if(strncmp(argpt, "-dvd_obs=", 9)==0 ||
279  	             strncmp(argpt, "dvd_obs=", 8)==0) {
280  	     cpt= strchr(argpt, '=') + 1;
281  	     Xorriso_option_dvd_obs(xorriso, cpt, 0);
282  	   } else if(strcmp(argpt, "-eject")==0) {
283  	     do_eject= 1;
284  	   } else if(strncmp(argpt, "-fs=", 4)==0 || strncmp(argpt, "fs=", 3)==0) {
285  	     cpt= strchr(argpt, '=')+1;
286  	     ret= Xorriso_option_fs(xorriso, cpt, 0);
287  	     if(ret<=0)
288  	       goto ex;
289  	   } else if(strcmp(argv[i], "--grow_overwriteable_iso")==0 ||
290  	             strcmp(argv[i], "--grow_overwritable_iso")==0 ||
291  	             strcmp(argv[i], "--grow_overriteable_iso")==0
292  	             ) { /* (A history of typos) */
293  	                                                     /* intentional: argv[i] */
294  	     do_grow= 1;
295  	   } else if(strcmp(argpt, "-help")==0) {
296  	     do_help= 1;
297  	   } else if(strcmp(argpt, "-isosize")==0) {
298  	     do_isosize= 1;
299  	   } else if(strcmp(argpt, "-inq")==0) {
300  	     do_checkdrive= 2;
301  	   } else if(strcmp(argpt, "-mode2")==0) {
302  	     Xorriso_msgs_submit(xorriso, 0,
303  	                     "Defaulting option -mode2 to option -data", 0, "NOTE", 0);
304  	   } else if(strcmp(argpt, "-msinfo")==0) {
305  	     do_msinfo= 1;
306  	   } else if(strcmp(argpt, "-multi")==0) {
307  	     do_multi= 1;
308  	     do_auto_close= 0;
309  	   } else if(strcmp(argv[i], "--multi_if_possible") == 0) {
310  	     do_multi= 1;
311  	     do_auto_close= 1;
312  	   } else if(strcmp(argpt, "-nopad")==0) {
313  	     xorriso->padding= 0;
314  	   } else if(strcmp(argv[i], "--no_rc")==0) { /* intentional: argv[i] */
315  	     /* already performed in Xorriso_prescan_args */;
316  	   } else if(strcmp(argpt, "-pad")==0) {
317  	     xorriso->padding= 15*2048;
318  	   } else if(strncmp(argpt, "-padsize=", 9)==0 ||
319  	             strncmp(argpt, "padsize=", 8)==0) {
320  	     cpt= strchr(argpt, '=')+1;
321  	     ret= Xorriso_option_padding(xorriso, cpt, 0);
322  	     if(ret<=0)
323  	       goto ex;
324  	   } else if(strcmp(argpt, "-sao")==0) {
325  	     xorriso->do_tao= -1;
326  	   } else if(strcmp(argpt, "-scanbus")==0) {
327  	     sprintf(xorriso->info_text, "-as %s: Option -scanbus not supported.",
328  	             whom);
329  	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
330  	     ret= 0; goto ex;
331  	   } else if(strncmp(argpt, "-speed=", 7)==0 ||
332  	             strncmp(argpt, "speed=", 6)==0) {
333  	     cpt= strchr(argpt, '=')+1;
334  	     strncpy(speed, cpt, 79);
335  	     speed[79]= 0;
336  	   } else if(strncmp(argpt, "-stream_recording=", 18)==0 ||
337  	             strncmp(argpt, "stream_recording=", 17)==0) {
338  	     cpt= strchr(argpt, '=')+1;
339  	     Xorriso_option_stream_recording(xorriso, cpt, 0);
340  	
341  	   } else if(strncmp(argpt, "-use_immed_bit=", 15) == 0 ||
342  	             strncmp(argpt, "use_immed_bit=", 14) == 0) {
343  	     cpt= strchr(argpt, '=') + 1;
344  	     Xorriso_option_use_immed_bit(xorriso, cpt, 0);
345  	
346  	   } else if(strcmp(argpt, "-immed") == 0) {
347  	     Xorriso_option_modesty_on_drive(xorriso, "75", 0);
348  	
349  	   } else if(strncmp(argpt, "-minbuf=", 8) == 0 ||
350  	             strncmp(argpt, "minbuf=", 7) == 0 ||
351  	             strncmp(argpt, "-modesty_on_drive=", 18) == 0 ||
352  	             strncmp(argpt, "modesty_on_drive=", 17) == 0) {
353  	     cpt= strchr(argpt, '=') + 1;
354  	     Xorriso_option_modesty_on_drive(xorriso, cpt, 0);
355  	
356  	   } else if(strncmp(argpt, "-drive_scsi_dev_family=", 23) == 0 ||
357  	             strncmp(argpt, "drive_scsi_dev_family=", 22) == 0) {
358  	     cpt= strchr(argpt, '=') + 1;
359  	     Xorriso_option_scsi_dev_family(xorriso, cpt, 0);
360  	
361  	   } else if(strncmp(argpt, "-stdio_sync=", 12)==0 ||
362  	             strncmp(argpt, "stdio_sync=", 11)==0) {
363  	     cpt= strchr(argpt, '=') + 1;
364  	     Xorriso_option_stdio_sync(xorriso, cpt, 0);
365  	   } else if(strcmp(argpt, "-tao")==0) {
366  	     xorriso->do_tao= 1;
367  	   } else if(strcmp(argpt, "-toc")==0 || strcmp(argv[i], "--long_toc")==0) {
368  	                                             /* intentional: argpt , argv[i] */
369  	     do_toc= 1;
370  	   } else if(strncmp(argpt, "-tsize=", 7)==0 ||
371  	             strncmp(argpt, "tsize=", 6)==0) {
372  	     cpt= strchr(argpt, '=')+1;
373  	     tsize= Scanf_io_size(cpt, 1);
374  	     if(tsize > 1024.0*1024.0*1024.0*1024.0*1024.0) {
375  	       sprintf(xorriso->info_text, "-as %s: much too large: %s",whom, argpt);
376  	       Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
377  	       ret= 0; goto ex;
378  	     }
379  	   } else if(strcmp(argv[i], "-V")==0 || strcmp(argpt,"-Verbose")==0) {
380  	     Xorriso_option_scsi_log(xorriso, "on", 0);
381  	   } else if(strcmp(argv[i], "-v")==0 || strcmp(argpt,"-verbose")==0) {
382  	     do_verbous++;
383  	   } else if(strcmp(argv[i], "-vv")==0) { /* intentional: argv[i] */
384  	     do_verbous+= 2;
385  	   } else if(strcmp(argv[i], "-vvv")==0) { /* intentional: argv[i] */
386  	     do_verbous+= 3;
387  	   } else if(strcmp(argpt, "-version")==0) {
388  	     do_version= 1;
389  	   } else if(strcmp(argpt, "-waiti")==0) {
390  	     do_waiti= 1;
391  	   } else if(strncmp(argv[i], "write_start_address=", 20)==0) {
392  	                                                     /* intentional: argv[i] */
393  	     write_start_address= Scanf_io_size(argv[i]+20,0);
394  	   } else if(strcmp(argpt, "-xa")==0) {
395  	     Xorriso_msgs_submit(xorriso, 0,
396  	                        "Defaulting option -xa to option -data", 0, "NOTE", 0);
397  	   } else if(strcmp(argpt, "-xa1")==0) {
398  	     if(do_xa1 == 0)
399  	       do_xa1= 1;
400  	   } else if(strcmp(argv[i], "--xa1-ignore")==0) { /* intentional: argv[i] */
401  	     do_xa1= -1;
402  	   } else if(strcmp(argpt, "-xa2")==0) {
403  	     Xorriso_msgs_submit(xorriso, 0,
404  	                       "Defaulting option -xa2 to option -data", 0, "NOTE", 0);
405  	   } else if(strcmp(argpt, "-xamix")==0) {
406  	     Xorriso_msgs_submit(xorriso, 0,
407  	   "Option -xamix not implemented and data not yet convertible to other modes",
408  	                         0, "FATAL", 0);
409  	     ret= 0; goto ex;
410  	   } else if(argpt[0]=='-' && argpt[1]!=0) {
411  	     sprintf(xorriso->info_text, "-as %s: Unknown option ", whom);
412  	     Text_shellsafe(argv[i], xorriso->info_text, 1);
413  	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
414  	     ret= 0; goto ex;
415  	   } else {
416  	     if(track_source[0]) {
417  	       sprintf(xorriso->info_text, "-as %s: Surplus track source ", whom);
418  	       Text_shellsafe(argv[i], xorriso->info_text, 1);
419  	       Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
420  	       sprintf(xorriso->info_text, "First and only track source is ");
421  	       Text_shellsafe(track_source, xorriso->info_text, 1);
422  	       Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
423  	       ret= 0; goto ex;
424  	     }
425  	     if(Sfile_str(track_source, argv[i], 0)<=0)
426  	       {ret= -1; goto ex;}
427  	   }
428  	 }
429  	
430  	 /* Perform actions */
431  	 Xorriso_option_report_about(xorriso, "NOTE", 0);
432  	 if(do_version) {
433  	   sprintf(xorriso->result_line, "Cdrecord 2.01-Emulation Copyright (C) 2017 see libburnia-project.org xorriso\n");
434  	   Xorriso_result(xorriso, 1);
435  	   Xorriso_option_version(xorriso, 0);
436  	 }
437  	
438  	 if(do_help) {
439  	   Xorriso_cdrskin_help(xorriso, 0);
440  	 }
441  	 if(strcmp(blank_mode, "help")==0) {
442  	   for(i= 0; strcmp(blank_help[i], "@End_of_helptexT@")!=0; i++) {
443  	     sprintf(xorriso->info_text, "%s\n", blank_help[i]);
444  	     Xorriso_info(xorriso,0);
445  	   }
446  	 }
447  	 if(do_help || strcmp(blank_mode, "help") == 0 || do_version) {
448  	   ret= 1; goto ex;
449  	 }
450  	
451  	 if(do_verbous<=0)
452  	   report_about= "NOTE";
453  	 else if(do_verbous<=2)
454  	   report_about= "UPDATE";
455  	 else if(do_verbous==3)
456  	   report_about= "DEBUG";
457  	 else
458  	   report_about= "ALL";
459  	 Xorriso_option_report_about(xorriso, report_about, 0);
460  	
461  	 if(do_scanbus) {
462  	   if(do_scanbus==1)
463  	     /* >>> would need -scanbus compatible output and input format */;
464  	   else
465  	     Xorriso_option_devices(xorriso, 0);
466  	   ret= 1; goto ex;
467  	 }
468  	
469  	 if(!(do_checkdrive || do_atip || do_toc || blank_mode[0] || track_source[0] ||
470  	      do_eject || do_msinfo)) {
471  	   sprintf(xorriso->info_text,
472  	           "-as cdrskin: No option specified, which would cause an action.");
473  	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
474  	   ret= 1; goto ex;
475  	 }
476  	
477  	 if(do_waiti) {
478  	   sprintf(xorriso->info_text,
479  	       "xorriso: Option -waiti pauses program until input appears at stdin\n");
480  	   Xorriso_info(xorriso,0);
481  	   sprintf(xorriso->result_line, "Waiting for data on stdin...\n");
482  	   Xorriso_result(xorriso, 1);
483  	   for(ret= 0; ret==0; )
484  	     ret= Wait_for_input(0,1000000,0);
485  	   if(ret<0 || feof(stdin)) {
486  	     Xorriso_msgs_submit(xorriso, 0,
487  	                    "stdin produces exception rather than data", 0, "NOTE", 0);
488  	   }
489  	   sprintf(xorriso->info_text, "xorriso: Option -waiti pausing is done.\n");
490  	 }
491  	 if(dev_adr[0]) {
492  	   hflag= 2 | 64;       /* ts B11201 no more:  | 32 */
493  	   if(!do_grow)
494  	     hflag|= 8; /* consider overwriteables as blank */
495  	   ret= Xorriso_option_dev(xorriso, dev_adr, hflag);
496  	   if(ret<=0)
497  	     goto ex;
498  	 }
499  	
500  	 if(xorriso->out_drive_handle==NULL) {
501  	   sprintf(xorriso->info_text, "-as %s: No output drive selected", whom);
502  	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
503  	   ret= 0; goto ex;
504  	 }
505  	
506  	 if(do_msinfo) {
507  	   ret= Xorriso_msinfo(xorriso, &msc1, &msc2, 2 | !!do_grow);
508  	   if(ret<=0)
509  	     goto ex;
510  	   sprintf(xorriso->result_line, "%d,%d\n", msc1, msc2);
511  	   Xorriso_result(xorriso, 1);
512  	 }
513  	
514  	 if(speed[0]) {
515  	   ret= Xorriso_option_speed(xorriso, speed, 0);
516  	   if(ret<=0)
517  	     goto ex;
518  	 }
519  	
520  	 if(do_checkdrive) {
521  	   ret= Xorriso_atip(xorriso, 2-(do_checkdrive==2));
522  	   if(ret<=0)
523  	     goto ex;
524  	 }
525  	 if(do_atip) {
526  	   ret= Xorriso_atip(xorriso, 0);
527  	   if(ret<=0)
528  	     goto ex;
529  	 }
530  	 if(do_toc) {
531  	   ret= Xorriso_option_toc(xorriso, 0);
532  	   if(ret<=0)
533  	     goto ex;
534  	 }
535  	 if(strcmp(blank_mode, "format_overwrite")==0) {
536  	   ret= Xorriso_option_blank(xorriso, "fast", 1);
537  	   if(ret<=0)
538  	     goto ex;
539  	 } else if(blank_mode[0]) {
540  	   ret= Xorriso_option_blank(xorriso, blank_mode, 0);
541  	   if(ret<=0)
542  	     goto ex;
543  	 }
544  	 if(track_source[0]) {
545  	   xorriso->do_close= !do_multi;
546  	   xorriso->auto_close= do_auto_close;
547  	   ret= Xorriso_burn_track(xorriso, (off_t) write_start_address,
548  	                           track_source, (off_t) tsize,
549  	                   (!!do_grow) | ((!!do_isosize) << 1) | ((do_xa1 == 1) << 2));
550  	   if(ret == 2) {
551  	     ret= Xorriso_retry_burn_track(xorriso, (off_t) write_start_address,
552  	                           track_source, (off_t) tsize,
553  	                   (!!do_grow) | ((!!do_isosize) << 1) | ((do_xa1 == 1) << 2));
554  	   }
555  	   aq_ret= Xorriso_reaquire_outdev(xorriso, 2*(ret>0));
556  	   if(ret<=0 && ret<aq_ret)
557  	     goto ex;
558  	   if(aq_ret<=0)
559  	     {ret= aq_ret; goto ex;}
560  	 }
561  	
562  	 ret= 1;
563  	ex:;
564  	 if(do_eject && ret>=0) {
565  	   eject_ret= Xorriso_option_eject(xorriso, "out", 0);
566  	   if(eject_ret<ret)
567  	     ret= eject_ret;
568  	 }
569  	 if(ret<=0) {
570  	   sprintf(xorriso->info_text, "-as %s: Job could not be performed properly.",
571  	           whom);
572  	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
573  	 }
574  	 Xorriso_option_report_about(xorriso, mem_report_about_text, 0);
575  	 xorriso->do_close= mem_do_close;
576  	 xorriso->auto_close= mem_auto_close;
577  	 Xorriso_free_meM(dev_adr);
578  	 Xorriso_free_meM(track_source);
579  	 return(ret);
580  	}
581  	
582  	
583  	/* This function shall know all options of mkisofs, genisoimage, xorrisofs, ...
584  	   and the number of arguments which they expect and consume.
585  	*/
586  	int Xorriso_genisofs_count_args(struct XorrisO *xorriso, int argc, char **argv,
587  	                                int *count, int flag)
588  	{
589  	 int i;
590  	 char *cmd;
591  	
592  	 static char partial_options[][41]= {
593  	    "errctl=",
594  	    "isolinux_mbr=", "--modification-date=",
595  	    ""
596  	 };
597  	 static char arg0_options[][41]= {
598  	    "-allow-leading-dots", "-ldots", "-allow-lowercase", "-allow-multidot",
599  	    "-cache-inodes", "-no-cache-inodes", "-eltorito-alt-boot",
600  	    "-hard-disk-boot", "-no-emul-boot", "-no-boot", "-boot-info-table",
601  	    "-check-oldnames", "-d", "-D", "-dvd-video", "-f", "-gui", "-graft-points",
602  	    "-hide-joliet-trans-tbl", "-hide-rr-moved", "-J", "-joliet-long", "-l",
603  	    "-L", "-max-iso9660-filenames", "-N", "-nobak", "-no-bak",
604  	    "-no-limit-pathtables", "-force-rr", "-no-rr",
605  	    "-no-split-symlink-components", "-no-split-symlink-fields", "-pad",
606  	    "-no-pad", "-posix-H", "-posix-L", "-posix-P", "-print-size",
607  	    "-quiet", "-R", "-r", "-relaxed-filenames", "-rrip110", "-rrip112",
608  	    "-split-output", "-T", "-UDF", "-udf", "-udf-symlinks", "-no-udf-symlinks",
609  	    "-U", "-no-iso-translate", "-v", "-XA", "-xa", "-z",
610  	    "-hfs", "-no-hfs", "-apple", "-probe", "-no-desktop", "-mac-name",
611  	    "-part", "-icon-position", "-chrp-t", "-hfs-unlock", "--cap", "--netatalk",
612  	    "--double", "--ethershare", "--ushare", "--exchange", "--sgi", "--xinet",
613  	    "--macbin", "--single", "--dave", "--sfm", "--osx-double", "--osx-hfs",
614  	    "-debug", "-omit-period", "-disable-deep-relocation", "-joliet",
615  	    "-full-iso9660-filenames", "-follow-links", "-help",
616  	    "-transparent-compression",
617  	    "-omit-version-number", "-rational-rock", "-rock", "-translation-table",
618  	    "-untranslated-filenames", "-verbose", "-version", "-g", "-h",
619  	    "-no-mac-files", "-chrp-boot",
620  	    "--hardlinks", "--acl", "--xattr", "--md5", "--for_backup",
621  	    "--protective-msdos-label", "--boot-catalog-hide", "--no-emul-toc",
622  	    "--emul-toc", "-disallow_dir_id_ext", "--old-empty",
623  	    "--old-root-no-md5", "--old-root-devno", "--old-root-no-ino",
624  	    "--no_rc", "--norock", "-hfsplus", "-fat", "-chrp-boot-part",
625  	    "-isohybrid-gpt-basdat", "-isohybrid-gpt-hfsplus",
626  	    "-isohybrid-apm-hfsplus", "--grub2-boot-info", "-joliet-utf16",
627  	    "-appended_part_as_gpt", "-appended_part_as_apm", "--mbr-force-bootable",
628  	    "-part_like_isohybrid",
629  	    ""
630  	 };
631  	 static char arg1_options[][41]= {
632  	    "-abstract", "-A", "-appid", "--application_use",
633  	    "-biblio", "-b", "-B", "-boot-load-seg",
634  	    "-boot-load-size", "-C", "-c", "-check-session", "-copyright",
635  	    "-dir-mode", "-eltorito-id", "-eltorito-selcrit",
636  	    "-file-mode", "-G", "-gid", "-hide", "-hide-list",
637  	    "-hidden", "-hidden-list", "-hide-joliet", "-hide-joliet-list",
638  	    "-hide-hfsplus", "-hide-hfsplus-list",
639  	    "-hide-udf", "-hide-udf-list", "-input-charset", "-output-charset",
640  	    "-iso-level", "-jcharset", "-log-file", "-m", "-exclude-list", "-M",
641  	    "-dev", "-new-dir-mode", "-o", "-p", "-preparer",
642  	    "-path-list", "-publisher", "-root",
643  	    "-old-root", "-s", "-sectype", "-sort", "-sparc-boot", "-sparc-label",
644  	    "-stream-media-size", "-stream-file-name", "-sunx86-boot", "-sunx86-label",
645  	    "-sysid", "-table-name", "-ucs-level", "-uid", "-V", "-volset",
646  	    "-volset-size", "-volset-seqno", "-x", "-P",
647  	    "-map", "-magic", "-hfs-creator", "-hfs-type", "-boot-hfs-file", "-auto",
648  	    "-cluster-size", "-hide-hfs", "-hide-hfs-list", "-hfs-volid",
649  	    "-root-info", "-prep-boot", "-input-hfs-charset", "-output-hfs-charset",
650  	    "-hfs-bless", "-hfs-parms", 
651  	    "-eltorito-boot", "-generic-boot", "-eltorito-catalog", "-cdrecord-params",
652  	    "-errctl", "-exclude", "-prev-session", "-output", "-use-fileversion",
653  	    "-volid", "-old-exclude",
654  	    "-alpha-boot", "-hppa-cmdline", "-hppa-kernel-32", "-hppa-kernel-64",
655  	    "-hppa-bootloader", "-hppa-ramdisk", "-mips-boot", "-mipsel-boot",
656  	    "-jigdo-jigdo", "-jigdo-template", "-jigdo-min-file-size",
657  	    "-jigdo-force-md5", "-jigdo-exclude", "-jigdo-map", "-md5-list",
658  	    "-jigdo-template-compress",
659  	    "-checksum_algorithm_iso", "-checksum_algorithm_template",
660  	    "--stdio_sync", "--quoted_path_list", "--efi-boot", "--embedded-boot",
661  	    "-isohybrid-mbr", "-e", "-partition_offset", "-partition_hd_cyl",
662  	    "-partition_sec_hd", "-partition_cyl_align", "-untranslated_name_len",
663  	    "-rr_reloc_dir", "-hfsplus-serial-no", "-prep-boot-part", "-efi-boot-part",
664  	    "-hfsplus-block-size", "-apm-block-size", "--grub2-mbr",
665  	    "--grub2-sparc-core", "--sort-weight-list", "--sort-weight-patterns",
666  	    "-hppa-hdrversion", "-file_name_limit", "--set_all_file_dates",
667  	    "--gpt_disk_guid", "-iso_mbr_part_type", "-eltorito-platform",
668  	    ""
669  	 };
670  	 static char arg2_options[][41]= {
671  	    "-hfs-bless-by", "--scdbackup_tag", "--sort-weight",
672  	    ""
673  	 };
674  	 static char arg3_options[][41]= {
675  	    "-append_partition", "-hfsplus-file-creator-type",
676  	    ""
677  	 };
678  	 static char final_options[][41]= {
679  	    "-find",
680  	    ""
681  	 };
682  	
683  	 cmd= argv[0];
684  	 *count= 0;
685  	 for(i=0; partial_options[i][0]!=0; i++)
686  	   if(strncmp(partial_options[i], cmd, strlen(partial_options[i]))==0)
687  	     return(1);
688  	 for(i=0; arg0_options[i][0]!=0; i++)
689  	   if(strcmp(arg0_options[i], cmd)==0)
690  	     return(1);
691  	 *count= 1;
692  	 for(i=0; arg1_options[i][0]!=0; i++)
693  	   if(strcmp(arg1_options[i], cmd)==0)
694  	     return(1);
695  	 *count= 2;
696  	 for(i=0; arg2_options[i][0]!=0; i++)
697  	   if(strcmp(arg2_options[i], cmd)==0)
698  	     return(1);
699  	 *count= 3;
700  	 for(i=0; arg3_options[i][0]!=0; i++)
701  	   if(strcmp(arg3_options[i], cmd)==0)
702  	     return(1);
703  	 *count= argc - 1;
704  	 for(i=0; final_options[i][0]!=0; i++)
705  	   if(strcmp(final_options[i], cmd)==0)
706  	     return(1);
707  	 *count= 0;
708  	 return(0); 
709  	}
710  	
711  	
712  	/* @param flag bit0= do not report eventual ignore decision
713  	*/
714  	int Xorriso_genisofs_ignore(struct XorrisO *xorriso, char *whom,
715  	                            char *argpt, int *i, int flag)
716  	{
717  	 /* mkisofs 2.01 options which are not scheduled for implementation, yet */
718  	 static char ignored_arg0_options[][41]= {
719  	   "-allow-leading-dots", "-ldots", "-allow-multidot",
720  	   "-cache-inodes", "-check-oldnames",
721  	   "-L", "-no-bak", "-no-cache-inodes",
722  	   "-no-split-symlink-components", "-no-split-symlink-fields", "-nobak",
723  	   "-force-rr", "-T",
724  	   "-no-iso-translate",
725  	   ""
726  	 };
727  	 static char ignored_arg1_options[][41]= {
728  	   "-check-session", "-hide-hfs", "-hide-hfs-list",
729  	   "-table-name", "-volset-seqno", "-volset-size", "-sort",
730  	   ""
731  	 };
732  	 int k;
733  	
734  	 for(k=0;ignored_arg0_options[k][0]!=0;k++)
735  	   if(strcmp(argpt,ignored_arg0_options[k])==0)
736  	     goto no_volunteer;
737  	 for(k=0;ignored_arg1_options[k][0]!=0;k++)
738  	   if(strcmp(argpt,ignored_arg1_options[k])==0) {
739  	     (*i)++;
740  	     goto no_volunteer;
741  	   }
742  	 return(0);
743  	no_volunteer:;
744  	 sprintf(xorriso->info_text, "-as %s: Ignored option ", whom);
745  	 Text_shellsafe(argpt, xorriso->info_text, 1);
746  	 if(!(flag & 1))
747  	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
748  	 return(1);
749  	}
750  	
751  	
752  	int Xorriso_genisofs_add_boot(struct XorrisO *xorriso, int flag)
753  	{
754  	 int ret;
755  	
756  	 if(xorriso->boot_img_size_default && xorriso->boot_image_emul == 0)
757  	   xorriso->boot_img_full_size= 1;
758  	 ret= Xorriso_attach_boot_image(xorriso, 0);
759  	 if(ret <= 0)
760  	   xorriso->boot_image_bin_path[0]= 0;
761  	 return(ret);
762  	}
763  	
764  	
765  	int Xorriso_genisofs_help(struct XorrisO *xorriso, int flag)
766  	{
767  	 static char helptext[][160]= {
768  	"Usage: xorriso -as mkisofs [options] file...",
769  	"Note: This is not mkisofs. See xorriso -help, xorriso -version, man xorrisofs",
770  	"Options:",
771  	"  -f, -follow-links           Follow symbolic links",
772  	"  -graft-points               Allow to use graft points for filenames",
773  	"  -help                       Print option help",
774  	"  -hfsplus                    Generate HFS+ filesystem",
775  	"  -hfsplus-file-creator-type CREATOR TYPE iso_rr_path",
776  	"                              Attach creator and type to a File",
777  	"  -hfs-bless FOLDER_NAME      Name of Folder to be blessed",
778  	"  -hfs-bless-by BLESS_TYPE ISO_RR_PATH",
779  	"                              Bless ISO_RR_PATH by BLESS_TYPE {p,i,s,9,x}",
780  	"  -hfsplus-serial-no HEXSTRING",
781  	"                              HFS serial number: 16 characters [0-9a-fA-F]",
782  	"  -hfsplus-block-size NUMBER  Set HFS+ block size",
783  	"  -apm-block-size NUMBER      Set Apple Partition Map block size",
784  	"  -hide GLOBFILE              Hide ISO9660/RR file",
785  	"  -hide-list FILE             File with list of ISO9660/RR files to hide",
786  	"  -hide-joliet GLOBFILE       Hide Joliet file",
787  	"  -hide-joliet-list FILE      File with list of Joliet files to hide",
788  	"  -hide-hfsplus GLOBFILE      Hide HFS+ file",
789  	"  -hide-hfsplus-list FILE     File with list of HFS+ files to hide",
790  	"  -input-charset CHARSET      Local input charset for file name conversion",
791  	"  -output-charset CHARSET     Output charset for file name conversion",
792  	"  -iso-level LEVEL            Set ISO9660 conformance level (1..3) or 4 for ISO9660 version 2",
793  	"  -disallow_dir_id_ext        Do not allow dot in ISO directory names",
794  	"  -J, -joliet                 Generate Joliet directory information",
795  	"  -joliet-long                Allow Joliet file names to be 103 Unicode characters",
796  	"  -joliet-utf16               Encode Joliet names in UTF-16BE rather than UCS-2",
797  	"  -U, -untranslated-filenames Allow Untranslated filenames (for HPUX & AIX - violates ISO9660).",
798  	"  -untranslated_name_len LEN  Allow up to LEN (1..96) name characters (heavily violates ISO9660).",
799  	"  -allow-lowercase            Allow lower case characters in addition to the current character set (violates ISO9660)",
800  	"  -relaxed-filenames          Allow 7 bit ASCII except lower case characters (violates ISO9660)",
801  	"  -d, -omit-period            Omit trailing periods from filenames (violates ISO9660)",
802  	"  -l, -full-iso9660-filenames Allow full 31 character filenames for ISO9660 names",
803  	"  -max-iso9660-filenames      Allow 37 character filenames for ISO9660 names (violates ISO9660)",
804  	"  -N, -omit-version-number    Omit version number from ISO9660 filename (violates ISO9660)",
805  	"  -D, -disable-deep-relocation",
806  	"                              Disable deep directory relocation (violates ISO9660)",
807  	"  -hide-rr-moved              Relocate deep directories to /.rr_moved",
808  	"  -rr_reloc_dir NAME          Set deep directory relocation target in root",
809  	"  -o FILE, -output FILE       Set output file name",
810  	"  -m GLOBFILE, -exclude GLOBFILE",
811  	"                              Exclude file name",
812  	"  -x FILE, -old-exclude FILE  Exclude file name",
813  	"  -exclude-list FILE          File with list of file names to exclude",
814  	"  -pad                        Pad output by 300k (default)",
815  	"  -no-pad                     Do not pad output",
816  	"  -M FILE, -prev-session FILE Set path to previous session to merge",
817  	"  -C PARAMS, -cdrecord-params PARAMS",
818  	"                              Magic paramters from cdrecord",
819  	"  -dir-mode mode              Make the mode of all directories this mode.",
820  	"  -file-mode mode             Make the mode of all plain files this mode.",
821  	"  -path-list FILE             File with list of pathnames to process",
822  	"  --quoted_path_list FILE     File with list of quoted pathnames to process",
823  	"  -print-size                 Print estimated filesystem size and exit",
824  	"  -quiet                      Run quietly",
825  	"  -gui                        Switch behaviour for GUI",
826  	"  -R, -rock                   Generate Rock Ridge directory information",
827  	"  -r, -rational-rock          Generate rationalized Rock Ridge directory information",
828  	"  --norock                    Disable Rock Ridge. (Strongly discouraged !)",
829  	"  -file_name_limit LEN        Set truncation limit for Rock Ridge names",
830  	"  --hardlinks                 Record eventual hard link relations of files",
831  	"  --acl                       Record eventual ACLs of files",
832  	"  --xattr                     Record eventual user space xattr of files",
833  	"  --md5                       Compute and record MD5 checksums of data files",
834  	"  --scdbackup_tag PATH NAME   With --md5 record a scdbackup checksum tag",
835  	"  --for_backup                Use all options which improve backup fidelity",
836  	"  -V ID, -volid ID            Set Volume ID",
837  	"  -volset ID                  Set Volume set ID",
838  	"  -publisher PUB              Set Volume publisher",
839  	"  -A ID, -appid ID            Set Application ID",
840  	"  -sysid ID                   Set System ID",
841  	"  -p PREP, -preparer PREP     Set Volume preparer",
842  	"  -abstract FILE              Set Abstract filename",
843  	"  -biblio FILE                Set Bibliographic filename",
844  	"  -copyright FILE             Set Copyright filename",
845  	"  --application_use CHAR|PATH  Set content of Application Use field",
846  	"  -jigdo-jigdo FILE           Produce a jigdo .jigdo file as well as the .iso",
847  	"  -jigdo-template FILE        Produce a jigdo .template file as well as the .iso",
848  	"  -jigdo-min-file-size SIZE   Minimum size for a file to be listed in the jigdo file", 
849  	"  -jigdo-force-md5 PATTERN    Pattern(s) where files MUST match an externally-supplied MD5sum",
850  	"  -jigdo-exclude PATTERN      Pattern(s) to exclude from the jigdo file",
851  	"  -jigdo-map PATTERN1=PATTERN2",
852  	"                              Pattern(s) to map paths (e.g. Debian=/mirror/debian)",
853  	"  -md5-list FILE              File containing MD5 sums of the files that should be checked",
854  	"  -jigdo-template-compress ALGORITHM",
855  	"                              Choose to use gzip or bzip2 compression for template data; default is gzip",
856  	"  -checksum_algorithm_iso alg1,alg2,...",
857  	"                              Specify the checksum types desired for the output image (in .jigdo)",
858  	"  -checksum_algorithm_template alg1,alg2,...",
859  	"                              Specify the checksum types desired for the output jigdo template",
860  	"  -eltorito-platform          Set El Torito platform id for the next boot entry",
861  	"  -b FILE, -eltorito-boot FILE",
862  	"                              Set El Torito boot image name",
863  	"  -eltorito-alt-boot          Start specifying alternative El Torito boot parameters",
864  	"  --efi-boot FILE             Set El Torito EFI boot image name and type",
865  	"  -e FILE                     Set EFI boot image name (more rawly)",
866  	"  -c FILE, -eltorito-catalog FILE",
867  	"                              Set El Torito boot catalog name",
868  	"  --boot-catalog-hide         Hide boot catalog from ISO9660/RR and Joliet",
869  	"  -boot-load-size #           Set numbers of load sectors",
870  	"  -hard-disk-boot             Boot image is a hard disk image",
871  	"  -no-emul-boot               Boot image is 'no emulation' image",
872  	"  -boot-info-table            Patch boot image with info table",
873  	"  --grub2-boot-info           Patch boot image at byte 2548",
874  	"  -eltorito-id ID             Set El Torito Id String",
875  	"  -eltorito-selcrit HEXBYTES  Set El Torito Selection Criteria",
876  	"  -isohybrid-gpt-basdat       Mark El Torito boot image as Basic Data in GPT",
877  	"  -isohybrid-gpt-hfsplus      Mark El Torito boot image as HFS+ in GPT",
878  	"  -isohybrid-apm-hfsplus      Mark El Torito boot image as HFS+ in APM",
879  	"  -part_like_isohybrid        Mark in MBR, GPT, APM without -isohybrid-mbr",
880  	"  -iso_mbr_part_type          Set type byte of ISO partition in MBR",
881  	"  --gpt_disk_guid GUID        Set GPT disk GUID or choose automatic GUID",
882  	"  -G FILE, -generic-boot FILE Set generic boot image name",
883  	"  --embedded-boot FILE        Alias of -G",
884  	"  --protective-msdos-label    Patch System Area by partition table",
885  	"  --mbr-force-bootable        Enforce existence of bootable flag in MBR",
886  	"  -partition_offset LBA       Make image mountable by first partition, too",
887  	"  -partition_sec_hd NUMBER    Define number of sectors per head",
888  	"  -partition_hd_cyl NUMBER    Define number of heads per cylinder",
889  	"  -partition_cyl_align MODE   Control cylinder alignment: off, on, auto, all",
890  	"  -mips-boot FILE             Set mips boot image name (relative to image root)",
891  	"  -mipsel-boot FILE           Set mipsel boot image name (relative to image root)",
892  	"  -B FILES, -sparc-boot FILES Set sparc boot image names",
893  	"  -sparc-label label text     Set sparc boot disk label",
894  	"  -hppa-cmdline CMDLINE       Set hppa boot command line",
895  	"  -hppa-kernel-32 FILE        Set hppa 32-bit image name (relative to image root)",
896  	"  -hppa-kernel-64 FILE        Set hppa 64-bit image name (relative to image root)",
897  	"  -hppa-bootloader FILE       Set hppa boot loader file name (relative to image root)",
898  	"  -hppa-ramdisk FILE          Set hppa ramdisk file name (relative to image root)",
899  	"  -hppa-hdrversion NUMBER     Set hppa PALO header version to 4 or 5",
900  	"  -alpha-boot FILE            Set alpha boot image name (relative to image root)",
901  	"  --grub2-sparc-core FILE     Set path of core file for disk label patching",
902  	"  -efi-boot-part DISKFILE|--efi-boot-image",
903  	"                              Set data source for EFI System Partition",
904  	"  -chrp-boot-part             Mark ISO image size by MBR partition type 0x96",
905  	"  -chrp-boot                  Alias of -chrp-boot-part",
906  	"  -prep-boot-part DISKFILE    Set data source for MBR partition type 0x41",
907  	"  -append_partition NUMBER TYPE FILE",
908  	"                              Append FILE after image. TYPE is hex: 0x..",
909  	"  -appended_part_as_gpt       mark appended partitions in GPT instead of MBR.",
910  	"  -appended_part_as_apm       mark appended partitions in APM.",
911  	"  --modification-date=YYYYMMDDhhmmsscc",
912  	"                              Override date of creation and modification",
913  	"  --set_all_file_dates TIME   Override mtime, atime, ctime in all files",
914  	"  -isohybrid-mbr FILE         Set SYSLINUX mbr/isohdp[fp]x*.bin for isohybrid",
915  	"  --grub2-mbr FILE            Set GRUB2 MBR for boot image address patching",
916  	#ifdef Xorriso_with_isohybriD
917  	"  isolinux_mbr=on|auto|off    Control eventual isohybrid MBR generation",
918  	#endif
919  	"  --sort-weight NUMBER FILE   Set LBA weight number to file or file tree",
920  	"  --sort-weight-list DISKFILE Read list of NUMBER FILE pairs for --sort-weight",
921  	"  --sort-weight-patterns DISKFILE  --sort-weight-list with pattern expansion",
922  	"  --stdio_sync on|off|number  Control forced output to disk files",
923  	"  --no-emul-toc               Save 64 kB size on random access output files",
924  	"  --emul-toc                  Multi-session history on such output files",
925  	"  --old-empty                 Use old style block addresses for empty files",
926  	"  -z, -transparent-compression",
927  	"                              Enable transparent compression of files",
928  	"  -root DIR                   Set root directory for all new files and directories",
929  	"  -old-root DIR               Set root directory in previous session that is searched for files",
930  	"  --old-root-no-md5           Do not record and use MD5 with -old-root",
931  	"  --old-root-no-ino           Do not use disk inode numbers with -old-root",
932  	"  --old-root-devno            Use disk device numbers with -old-root",
933  	"  -log-file LOG_FILE          Re-direct messages to LOG_FILE",
934  	"  --no_rc                     Do not execute startup files",
935  	"  -v, -verbose                Verbose",
936  	"  -version                    Print the current version",
937  	"@End_of_helptexT@"
938  	};
939  	
940  	 char ra_text[80];
941  	 int i;
942  	
943  	 strcpy(ra_text, xorriso->report_about_text);
944  	
945  	 Xorriso_option_report_about(xorriso, "NOTE", 0);
946  	 for(i= 0; strcmp(helptext[i], "@End_of_helptexT@")!=0; i++) {
947  	   sprintf(xorriso->info_text, "%s\n", helptext[i]);
948  	   Xorriso_info(xorriso, 1 | 2);
949  	 }
950  	 Xorriso_option_report_about(xorriso, ra_text, 0);
951  	 return(1);
952  	}
953  	
954  	
955  	/* Perform hiding.
956  	   Cumbersome: The paths and patterns apply to the disk address and not
957  	   to the Rock Ridge address. Actually even the literal form of the
958  	   mkisofs pathspec would matter (e.g. "./" versus "").
959  	   But xorriso normalizes disk_paths before further processing. Thus
960  	   the literal form does not matter.
961  	   @param hide_attrs
962  	          bit0= hide in ISO/RR
963  	          bit1= hide in Joliet
964  	          bit2= hide in HFS+
965  	          bit3 to bit5 are reserved for future hidings
966  	*/
967  	int Xorriso_genisofs_hide(struct XorrisO *xorriso, char *whom,
968  	                          char *pattern, int hide_attrs, int flag)
969  	{
970  	 int zero= 0, ret;
971  	 char *argv[1];
972  	
973  	 if((hide_attrs & 63) == 0)
974  	   return(2);
975  	
976  	 if(strchr(pattern, '/') != NULL) {
977  	   argv[0]= pattern;
978  	   ret= Xorriso_option_not_paths(xorriso, 1, argv, &zero,
979  	                                 4 | ((hide_attrs & 63) << 8));
980  	 } else {
981  	   ret= Xorriso_option_not_leaf(xorriso, pattern, hide_attrs & 63);
982  	 }
983  	 return(ret);
984  	}
985  	
986  	
987  	/* @param flag bit0= quoted list */
988  	int Xorriso_genisofs_hide_list(struct XorrisO *xorriso, char *whom,
989  	                               char *adr, int hide_attrs, int flag)
990  	{
991  	 int ret, linecount= 0, argc= 0, was_failure= 0, i, fret;
992  	 char **argv= NULL, *id= "";
993  	 FILE *fp= NULL;
994  	
995  	 if(adr[0]==0) {
996  	   if (hide_attrs & 2)
997  	     id = "joliet-";
998  	   else if (hide_attrs & 4)
999  	     id = "hfsplus-";
1000 	   sprintf(xorriso->info_text,
1001 	          "Empty file name given with -as %s -hide-%slist", whom, id);
1002 	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0);
1003 	   return(0);
1004 	 }
1005 	 ret= Xorriso_afile_fopen(xorriso, adr, "rb", &fp, 0);
1006 	 if(ret <= 0)
1007 	   return(0);
1008 	 while(1) {
1009 	   ret= Xorriso_read_lines(xorriso, fp, &linecount, &argc, &argv,
1010 	                           4 | (flag & 1) );
1011 	   if(ret <= 0)
1012 	     goto ex;
1013 	   if(ret == 2)
1014 	 break;
1015 	   for(i= 0; i < argc; i++) {
1016 	     if(argv[i][0] == 0)
1017 	   continue;
1018 	     ret= Xorriso_genisofs_hide(xorriso, whom, argv[i], hide_attrs, 0);
1019 	     if(ret <= 0 || xorriso->request_to_abort) {
1020 	       was_failure= 1;
1021 	       fret= Xorriso_eval_problem_status(xorriso, ret, 1|2);
1022 	       if(fret>=0)
1023 	   continue;
1024 	       if(ret > 0)
1025 	         ret= 0;
1026 	       goto ex;
1027 	     }
1028 	   }
1029 	 }
(1) Event start: Starting defect path here.
1030 	 ret= 1;
1031 	ex:;
(2) Event cond_true: Condition "flag & 1", taking true branch.
1032 	 if(flag & 1)
(3) Event alloc_arg: "Xorriso_read_lines" allocates memory that is stored into "argv". [details]
Also see events: [leaked_storage]
1033 	   Xorriso_read_lines(xorriso, fp, &linecount, &argc, &argv, 2);
(4) Event cond_true: Condition "fp != NULL", taking true branch.
(5) Event cond_true: Condition "fp != stdin", taking true branch.
1034 	 if(fp != NULL && fp != stdin)
1035 	   fclose(fp);
(6) Event cond_false: Condition "ret <= 0", taking false branch.
1036 	 if(ret<=0)
(7) Event if_end: End of if statement.
1037 	   return(ret);
(8) Event cond_true: Condition "!was_failure", taking true branch.
(9) Event leaked_storage: Variable "argv" going out of scope leaks the storage it points to.
Also see events: [alloc_arg]
1038 	 return(!was_failure);
1039 	}
1040 	
1041 	
1042 	/* Strip surplus dash from known single-dash long options */
1043 	int Xorriso_genisofs_strip_dash(struct XorrisO *xorriso, char *arg_in,
1044 	                                 char **arg_out, int flag)
1045 	{
1046 	 int ret, count;
1047 	 char *argv[1];
1048 	
1049 	 *arg_out= arg_in;
1050 	 if(strlen(arg_in) < 4)
1051 	   return(1);
1052 	 if(arg_in[0] != '-' || arg_in[1] != '-' || arg_in[2] == '-')
1053 	   return(1);
1054 	
1055 	 argv[0]= arg_in + 1; 
1056 	 ret= Xorriso_genisofs_count_args(xorriso, 1, argv, &count, 0);
1057 	 if(ret > 0)
1058 	   *arg_out= arg_in + 1;
1059 	 return(1);
1060 	}
1061 	
1062 	
1063 	/* Interprets a string of single-char options which have no parameters
1064 	   @param flag bit0=check whether string is ok
1065 	               bit1=this is pass 1
1066 	   @return with flag bit0: 0=no , 1=yes, 2= with bit1: non-pass-1 options seen
1067 	           else          : 1 = ok , <= 0 indicates error
1068 	*/
1069 	int Xorriso_genisofs_fused_options(struct XorrisO *xorriso, char *whom,
1070 	                                   char *opts,
1071 	                                   int *option_d, int *iso_level, int *lower_r,
1072 	                                   char ra_text[80], int flag)
1073 	{
1074 	 int ret, non_pass1= 0;
1075 	 char *cpt;
1076 	 static char pass1_covered[]= {"fvz"};
1077 	 static char covered[]= {"dDfJlNRrTUvz"};
1078 	
1079 	 if(flag & 1) {
1080 	   for(cpt= opts; *cpt != 0; cpt++) {
1081 	     if(strchr(covered, *cpt) == NULL)
1082 	       {ret= 0; goto ex;}
1083 	     if(flag & 2)
1084 	       if(strchr(pass1_covered, *cpt) == NULL)
1085 	         non_pass1= 1;
1086 	   }
1087 	   ret= 1 + non_pass1; goto ex;
1088 	 }
1089 	 
1090 	 for(cpt= opts; *cpt != 0; cpt++) {
1091 	   if(*cpt == 'd') {
1092 	     if(flag & 2)
1093 	 continue;
1094 	     Xorriso_relax_compliance(xorriso, "no_force_dots", 0);
1095 	   } else if(*cpt == 'D') {
1096 	     if(flag & 2)
1097 	 continue;
1098 	     *option_d= 1;
1099 	   } else if(*cpt == 'f') {
1100 	     if(!(flag & 2))
1101 	 continue;
1102 	     ret= Xorriso_option_follow(xorriso, "on", 0);
1103 	     if(ret <= 0)
1104 	       goto ex;
1105 	   } else if(*cpt == 'J') {
1106 	     if(flag & 2)
1107 	 continue;
1108 	     xorriso->do_joliet= 1;
1109 	   } else if(*cpt == 'l') {
1110 	     if(flag & 2)
1111 	 continue;
1112 	     if(xorriso->iso_level <= 2)
1113 	       Xorriso_relax_compliance(xorriso, "iso_9660_level=2", 0);
1114 	     if(*iso_level <= 2)
1115 	       *iso_level= 2;
1116 	   } else if(*cpt == 'N') {
1117 	     if(flag & 2)
1118 	 continue;
1119 	     Xorriso_relax_compliance(xorriso, "omit_version", 0);
1120 	   } else if(*cpt == 'R') {
1121 	     if(flag & 2)
1122 	 continue;
1123 	     xorriso->do_rockridge= 1;
1124 	   } else if(*cpt == 'r') {
1125 	     if(flag & 2)
1126 	 continue;
1127 	     xorriso->do_rockridge= 1;
1128 	     *lower_r= 1;
1129 	   } else if(*cpt == 'T') {
1130 	     /* ignored */;
1131 	   } else if(*cpt == 'U') {
1132 	     if(flag & 2)
1133 	 continue;
1134 	     Xorriso_relax_compliance(xorriso,
1135 	       "no_force_dots:long_paths:long_names:omit_version:full_ascii:lowercase",
1136 	                              0);
1137 	   } else if(*cpt == 'v') {
1138 	     if(!(flag & 2))
1139 	 continue;
1140 	     strcpy(ra_text, "UPDATE");
1141 	   } else if(*cpt == 'z') {
1142 	     if(!(flag & 2))
1143 	 continue;
1144 	     Xorriso_option_zisofs(xorriso, "by_magic=on", 0);
1145 	   } else {
1146 	     sprintf(xorriso->info_text, "-as %s: Unsupported option -%c", whom, *cpt);
1147 	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1148 	     ret= 0; goto ex;
1149 	   }
1150 	 }
1151 	 ret= 1; 
1152 	ex:;
1153 	 return(ret);
1154 	}
1155 	
1156 	
1157 	/* Implementing mkisofs tendency to map single-path pathspecs to / */
1158 	int Xorriso_graftable_pathspec(struct XorrisO *xorriso, char *in_pathspec,
1159 	                               char *pathspec, int flag)
1160 	{
1161 	 int ret, l;
1162 	 char *esc_wdx= NULL, *eff_path= NULL, *ept;
1163 	
1164 	 if((!xorriso->allow_graft_points) || 
1165 	   Fileliste__target_source_limit(in_pathspec, '=', &ept, 0) <= 0) {
1166 	
1167 	   Xorriso_alloc_meM(esc_wdx, char, SfileadrL);
1168 	   Xorriso_alloc_meM(eff_path, char, SfileadrL);
1169 	
1170 	   strcpy(esc_wdx, xorriso->wdx);
1171 	   if(!xorriso->allow_graft_points) {
1172 	     ret= Fileliste__escape_source_path(esc_wdx, SfileadrL, 0);
1173 	     if(ret <= 0) {
1174 	       Xorriso_msgs_submit(xorriso, 0,
1175 	                 "Escaped -cdx directory gets much too long", 0, "FAILURE", 0);
1176 	       ret= 0; goto ex;
1177 	     }
1178 	   }
1179 	   ret= Xorriso_normalize_img_path(xorriso, esc_wdx, in_pathspec,
1180 	                                   eff_path, 2|4);
1181 	   if(ret <= 0)
1182 	     {ret= 0; goto ex;}
1183 	   ret= Sfile_type(eff_path,
1184 	            1 | ((xorriso->do_follow_param || xorriso->do_follow_links) << 2));
1185 	   if(ret == 2) {
1186 	     strcpy(pathspec, "/=");
1187 	   } else {
1188 	     pathspec[0]= '/';
1189 	     pathspec[1]= 0;
1190 	     ret= Sfile_leafname(eff_path, pathspec + 1, 0);
1191 	     if(ret>0) {
1192 	       if(!xorriso->allow_graft_points) {
1193 	         ret= Fileliste__escape_source_path(pathspec, SfileadrL, 0);
1194 	         if(ret <= 0) {
1195 	           Xorriso_msgs_submit(xorriso, 0,
1196 	                      "Escaped leaf name gets much too long", 0, "FAILURE", 0);
1197 	           ret= 0; goto ex;
1198 	         }
1199 	       }
1200 	       strcat(pathspec, "=");
1201 	     } else
1202 	       pathspec[0]= 0;
1203 	   }
1204 	   l= strlen(pathspec);
1205 	   strcat(pathspec, eff_path);
1206 	   if(!xorriso->allow_graft_points) {
1207 	     ret= Fileliste__escape_source_path(pathspec + l, 2 * SfileadrL - l, 0);
1208 	     if(ret <= 0) {
1209 	       Xorriso_msgs_submit(xorriso, 0,
1210 	                           "Escaped path gets much too long", 0, "FAILURE", 0);
1211 	       ret= 0; goto ex;
1212 	     }
1213 	   }
1214 	 } else {
1215 	   Sfile_str(pathspec, in_pathspec, 0);
1216 	 }
1217 	 ret= 1;
1218 	ex:;
1219 	 Xorriso_free_meM(esc_wdx);
1220 	 Xorriso_free_meM(eff_path);
1221 	 return(ret);
1222 	}
1223 	
1224 	
1225 	int Xorriso_genisofs_path_pecul(struct XorrisO *xorriso, int *was_path,
1226 	                                int with_emul_toc, int *allow_dir_id_ext,
1227 	                                int *iso_level, int flag)
1228 	{
1229 	 char *sfe= NULL;
1230 	 int ret;
1231 	
1232 	 if(*was_path) {
1233 	   ret= 1; goto ex;
1234 	 }
1235 	 *was_path= 1;
1236 	
1237 	 Xorriso_alloc_meM(sfe, char, 5*SfileadrL);
1238 	
1239 	 /* Enforce odd mkisofs defaults on first pathspec */
1240 	 xorriso->pacifier_style= 1;
1241 	 if(xorriso->allow_dir_id_ext_dflt && *allow_dir_id_ext < 0)
1242 	   *allow_dir_id_ext= 1;
1243 	 if(*allow_dir_id_ext == 1) {
1244 	   Xorriso_relax_compliance(xorriso, "allow_dir_id_ext", 0);
1245 	   *allow_dir_id_ext= 2;
1246 	 }
1247 	 if(xorriso->iso_level_is_default && *iso_level < 0)
1248 	   *iso_level= 1;
1249 	 if(*iso_level >= 1 && *iso_level <= 3) {
1250 	   sprintf(sfe, "iso_9660_level=%d", *iso_level);
1251 	   Xorriso_relax_compliance(xorriso, sfe, 0);
1252 	   iso_level= 0;
1253 	 }
1254 	 /* For the sake of compatibility give up emulated multi-session by default
1255 	 */
1256 	 if(with_emul_toc == 0)
1257 	   xorriso->no_emul_toc|= 1;
1258 	 /* mkisofs records mtime in ECMA-119 and Joliet
1259 	 */
1260 	 Xorriso_relax_compliance(xorriso, "rec_mtime", 0);
1261 	 /* mkisofs is substantially faster than xorriso by not fsyncing
1262 	 */
1263 	 if(xorriso->stdio_sync_is_default)
1264 	   Xorriso_option_stdio_sync(xorriso, "off", 0);
1265 	
1266 	 Xorriso_free_meM(sfe);
1267 	 ret= 1;
1268 	ex:;
1269 	 return(ret);
1270 	}
1271 	
1272 	
1273 	int Xorriso_genisofs_platform(struct XorrisO *xorriso, char *id, int flag)
1274 	{
1275 	 unsigned int u;
1276 	 char re_id[64];
1277 	
1278 	 if(strcmp(id, "x86") == 0)
1279 	   return(0);
1280 	 else if(strcmp(id, "PPC") == 0)
1281 	   return(1);
1282 	 else if(strcmp(id, "Mac") == 0)
1283 	   return(2);
1284 	 else if(strcmp(id, "efi") == 0)
1285 	   return(0xef);
1286 	
1287 	 u= 0x100;
1288 	 if(strncmp(id, "0x", 2) == 0) {
1289 	   sscanf(id + 2, "%x", &u);
1290 	 } else {
1291 	   sscanf(id, "%u", &u);
1292 	   sprintf(re_id, "%u", u);
1293 	   if(strcmp(id, re_id) != 0)
1294 	     goto wrong_id;
1295 	 }
1296 	 if(u <= 0xff)
1297 	   return((int) u);
1298 	
1299 	wrong_id:;
1300 	 sprintf(xorriso->info_text,
1301 	         "Unrecognized El Torito Platform Id : '%.16s%s'",
1302 	         id, strlen(id) > 16 ? "..." : "");
1303 	 Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1304 	 sprintf(xorriso->info_text,
1305 	         "Recognizable are: x86, PPC, Mac, efi, [0...255], [0x00...0xff]");
1306 	 Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "HINT", 0);
1307 	 return(-1);
1308 	}
1309 	
1310 	
1311 	/* micro emulation of mkisofs */
1312 	int Xorriso_genisofs(struct XorrisO *xorriso, char *whom,
1313 	                     int argc, char **argv, int flag)
1314 	{
1315 	 int ret, i, j, was_path= 0, was_other_option= 0, mem_graft_points, mem;
1316 	 int do_print_size= 0, fd, idx, iso_level= -1, palohdrversion;
1317 	 int was_failure= 0, fret, lower_r= 0, zero= 0;
1318 	 int dir_mode= -1, file_mode= -1, count, partition_number;
1319 	 int allow_dir_id_ext= -1;
1320 	 int root_seen= 0, do_md5_mem, option_d= 0, arg_count;
1321 	 mode_t mode_and, mode_or;
1322 	 int with_boot_image= 0, with_cat_path= 0, with_emul_toc= 0;
1323 	 int old_root_md5= 1, old_root_dev= 0, old_root_ino= 1, sort_file_pattern= 0;
1324 	 int *weight_list= NULL, weight_count= 0;
1325 	 int *delay_opt_list= NULL, delay_opt_count= 0;
1326 	 int mkisofs_b_platform_id= 0x00;
1327 	 char *sfe= NULL, *adr= NULL, ra_text[80], *pathspec= NULL, *sort_file= NULL;
1328 	 char *ept, *add_pt, *eff_path= NULL, *indev= NULL, msc[80], *cpt;
1329 	 char *old_root= NULL, *argpt, *hargv[1];
1330 	 char *boot_path, partno_text[8], *iso_rr_pt, *disk_pt, *rpt, *wpt;
1331 	 char *rm_merge_args[3], *rr_reloc_dir_pt= NULL;
1332 	 char *sort_weight_args[4], *bless_args[6], *sa_path;
1333 	
1334 	 struct stat stbuf;
1335 	
1336 	 Xorriso_alloc_meM(sfe, char, 5*SfileadrL);
1337 	 Xorriso_alloc_meM(adr, char, SfileadrL+8);
1338 	 Xorriso_alloc_meM(pathspec, char, 2*SfileadrL);
1339 	 Xorriso_alloc_meM(eff_path, char, SfileadrL);
1340 	 Xorriso_alloc_meM(indev, char, SfileadrL+8);
1341 	 Xorriso_alloc_meM(old_root, char, SfileadrL);
1342 	 Xorriso_alloc_meM(sort_file, char, SfileadrL);
1343 	
1344 	 for(i= 0; i<argc; i++) {
1345 	   if(strcmp(argv[i], "-log-file") == 0 ||
1346 	      strcmp(argv[i], "--log-file") == 0 ) {
1347 	     if(i + 1 >= argc)
1348 	       goto not_enough_args;
1349 	     i+= 1;
1350 	     if(argv[i][0]) {
1351 	       sprintf(xorriso->info_text, "re-directing all messages to %s\n",
1352 	               argv[i]);
1353 	       Xorriso_info(xorriso, 0);
1354 	     }
1355 	     ret= Xorriso_write_to_channel(xorriso, argv[i], 2,
1356 	                                   8 | ((argv[i][0] == 0) << 15));
1357 	     if(ret <= 0) {
1358 	       sprintf(xorriso->info_text, "Cannot open logfile:  %s", argv[i]);
1359 	       Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno * (ret == 0),
1360 	                           "SORRY", 0);
1361 	       was_failure= 1;
1362 	       fret= Xorriso_eval_problem_status(xorriso, ret, 1|2);
1363 	       if(fret < 0)
1364 	         {ret= 0; goto ex;}
1365 	     }
1366 	     if(argv[i][0] == 0) {
1367 	       sprintf(xorriso->info_text, "Revoked stderr message redirection");
1368 	       Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
1369 	     }
1370 	   }
1371 	 }
1372 	
1373 	 strcpy(ra_text, xorriso->report_about_text);
1374 	
1375 	 weight_list= TSOB_FELD(int, (argc / 3) + 1);
1376 	 if(weight_list == NULL) {
1377 	   Xorriso_no_malloc_memory(xorriso, NULL, 0);
1378 	   {ret= -1; goto ex;}
1379 	 }
1380 	 delay_opt_list= TSOB_FELD(int, argc + 1);
1381 	 if(delay_opt_list == NULL) {
1382 	   cpt= (char *) weight_list;
1383 	   Xorriso_no_malloc_memory(xorriso, &cpt, 0);
1384 	   {ret= -1; goto ex;}
1385 	 } 
1386 	
1387 	 if(xorriso->boot_image_cat_path[0])
1388 	   with_cat_path= -1;
1389 	 adr[0]= indev[0]= msc[0]= old_root[0]= sort_file[0]= 0;
1390 	 for(i= 0; i<argc; i++) {
1391 	   ret= Xorriso_genisofs_strip_dash(xorriso, argv[i], &argpt, 0);
1392 	   if(ret <= 0)
1393 	     goto ex;
1394 	   ret= Xorriso_genisofs_ignore(xorriso, whom, argpt, &i, 1);
1395 	   if(ret == 1)
1396 	 continue;
1397 	   if(strcmp(argpt, "-version")==0) {
1398 	     sprintf(xorriso->result_line,
1399 	"mkisofs 2.01-Emulation Copyright (C) 2017 see libburnia-project.org xorriso\n"
1400 	            );
1401 	     fd= xorriso->dev_fd_1;
1402 	     if(fd<0)
1403 	       fd= 1;
1404 	     ret= write(fd, xorriso->result_line, strlen(xorriso->result_line));
1405 	     /* (result of write intentionally ignored) */
1406 	     fsync(fd);
1407 	     Xorriso_option_version(xorriso, 0);
1408 	
1409 	   } else if(strcmp(argpt, "-o")==0 || strcmp(argpt, "-output")==0) {
1410 	     if(i+1>=argc)
1411 	       goto not_enough_args;
1412 	     i++;
1413 	     adr[0]= 0;
1414 	     if(strcmp(argv[i],"-")!=0 && strncmp(argv[i], "stdio:", 6)!=0)
1415 	       strcpy(adr, "stdio:");
1416 	     if(Sfile_str(adr+strlen(adr), argv[i], 0)<=0)
1417 	       {ret= -1; goto ex;}
1418 	   } else if(strcmp(argpt, "-M")==0  || strcmp(argpt, "-dev")==0 ||
1419 	             strcmp(argpt, "-prev-session")==0) {
1420 	     if(i+1>=argc)
1421 	       goto not_enough_args;
1422 	     i++;
1423 	     if(strncmp(argv[i], "stdio:", 6)!=0)
1424 	       strcpy(indev, "stdio:");
1425 	     if(Sfile_str(indev+strlen(indev), argv[i], 0)<=0)
1426 	       {ret= -1; goto ex;}
1427 	   } else if(strcmp(argpt, "-C")==0 ||
1428 	             strcmp(argpt, "-cdrecord-params")==0) {
1429 	     if(i+1>=argc)
1430 	       goto not_enough_args;
1431 	     i++;
1432 	     strncpy(msc, argv[i], sizeof(msc)-1);
1433 	     msc[sizeof(msc)-1]= 0;
1434 	   } else if(strcmp(argpt, "-help")==0) {
1435 	     Xorriso_genisofs_help(xorriso, 0);
1436 	   } else if(strcmp(argpt, "-v")==0 || strcmp(argpt, "-verbose")==0) {
1437 	     ret= Xorriso_genisofs_fused_options(xorriso, whom, "v",
1438 	                                  &option_d, &iso_level, &lower_r, ra_text, 2);
1439 	     if(ret <= 0)
1440 	       goto problem_handler_1;
1441 	   } else if(strcmp(argpt, "-quiet")==0) {
1442 	     strcpy(ra_text, "SORRY");
1443 	   } else if(strcmp(argpt, "-f")==0 || strcmp(argpt, "-follow-links")==0) {
1444 	     ret= Xorriso_genisofs_fused_options(xorriso, whom, "f",
1445 	                                  &option_d, &iso_level, &lower_r, ra_text, 2);
1446 	     if(ret <= 0)
1447 	       goto problem_handler_1;
1448 	   } else if(strcmp(argpt, "-iso-level")==0) {
1449 	     if(i+1>=argc)
1450 	       goto not_enough_args;
1451 	     i++;
1452 	     sscanf(argv[i], "%d", &iso_level);
1453 	     if(iso_level < 1 || iso_level > 4) {
1454 	       sprintf(xorriso->info_text,
1455 	               "-as %s: unsupported -iso-level '%s' (use one of: 1,2,3,4)",
1456 	               whom, argv[i]);
1457 	       Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1458 	       ret= 0; goto problem_handler_1;
1459 	     }
1460 	     if(iso_level == 4)
1461 	       xorriso->do_iso1999= 1;
1462 	     else {
1463 	       sprintf(sfe, "iso_9660_level=%s", argv[i]);
1464 	       ret= Xorriso_relax_compliance(xorriso, sfe, 0);
1465 	       if(ret <= 0)
1466 	         goto problem_handler_1;
1467 	     }
1468 	
1469 	   } else if(strcmp(argpt, "-input-charset")==0) {
1470 	     if(i+1>=argc)
1471 	       goto not_enough_args;
1472 	     i++;
1473 	     /* -local_charset */
1474 	     if(strcmp(argv[i], "default") == 0)
1475 	       ret= Xorriso_option_charset(xorriso, "ISO-8859-1", 4);
1476 	     else
1477 	       ret= Xorriso_option_charset(xorriso, argv[i], 4);
1478 	     if(ret <= 0)
1479 	       goto problem_handler_1;
1480 	   } else if(strcmp(argpt, "-output-charset")==0) {
1481 	     if(i+1>=argc)
1482 	       goto not_enough_args;
1483 	     i++;
1484 	     /* -charset */
1485 	     if(strcmp(argv[i], "default") == 0)
1486 	       ret= Xorriso_option_charset(xorriso, "ISO-8859-1", 3);
1487 	     else
1488 	       ret= Xorriso_option_charset(xorriso, argv[i], 3);
1489 	     if(ret <= 0)
1490 	       goto problem_handler_1;
1491 	
1492 	   } else if(strcmp(argpt, "-hide") == 0 ||
1493 	             strcmp(argpt, "-hide-list") == 0 ||
1494 	             strcmp(argpt, "-hide-joliet") == 0 ||
1495 	             strcmp(argpt, "-hide-joliet-list") == 0 ||
1496 	             strcmp(argpt, "-hide-hfsplus") == 0 ||
1497 	             strcmp(argpt, "-hide-hfsplus-list") == 0) {
1498 	     if(i+1>=argc)
1499 	       goto not_enough_args;
1500 	     i++;
1501 	     if(strcmp(argpt, "-hide") == 0)
1502 	       ret= Xorriso_genisofs_hide(xorriso, whom, argv[i], 1, 0);
1503 	     else if(strcmp(argpt, "-hide-list") == 0)
1504 	       ret= Xorriso_genisofs_hide_list(xorriso, whom, argv[i], 1, 0);
1505 	     else if(strcmp(argpt, "-hide-joliet") == 0) 
1506 	       ret= Xorriso_genisofs_hide(xorriso, whom, argv[i], 2, 0);
1507 	     else if(strcmp(argpt, "-hide-joliet-list") == 0) 
1508 	       ret= Xorriso_genisofs_hide_list(xorriso, whom, argv[i], 2, 0);
1509 	     else if(strcmp(argpt, "-hide-hfsplus") == 0)
1510 	       ret= Xorriso_genisofs_hide(xorriso, whom, argv[i], 4, 0);
1511 	     else if(strcmp(argpt, "-hide-hfsplus-list") == 0)
1512 	       ret= Xorriso_genisofs_hide_list(xorriso, whom, argv[i], 4, 0);
1513 	     if(ret <= 0)
1514 	       goto problem_handler_1;
1515 	
1516 	   } else if(strcmp(argpt, "-root") == 0) {
1517 	     if(i+1>=argc)
1518 	       goto not_enough_args;
1519 	     i++;
1520 	     /* Always absolute */
1521 	     strcpy(eff_path, "/");
1522 	     if(Sfile_str(eff_path, argv[i], argv[i][0] != '/') <= 0)
1523 	       {ret= -1; goto ex;}
1524 	     strcpy(xorriso->wdi, eff_path);
1525 	     root_seen= 1;
1526 	
1527 	   } else if(strcmp(argpt, "-old-root") == 0) {
1528 	     if(i+1>=argc)
1529 	       goto not_enough_args;
1530 	     i++;
1531 	     /* Always absolute */
1532 	     strcpy(old_root, "/");
1533 	     if(Sfile_str(old_root, argv[i], argv[i][0] != '/') <= 0)
1534 	       {ret= -1; goto ex;}
1535 	
1536 	   } else if(strcmp(argpt, "--old-root-no-md5")==0) {
1537 	     old_root_md5= 0;
1538 	   } else if(strcmp(argpt, "--old-root-devno")==0) {
1539 	     old_root_dev= 1;
1540 	   } else if(strcmp(argpt, "--old-root-no-ino")==0) {
1541 	     old_root_ino= 0;
1542 	
1543 	   } else if(strcmp(argpt, "-fat") == 0) {
1544 	     xorriso->do_fat= 1;
1545 	   } else if(strcmp(argpt, "-hfsplus") == 0) {
1546 	     /* Already with -indev */
1547 	     xorriso->do_hfsplus= 1;
1548 	
1549 	   } else if(strcmp(argpt, "--hardlinks")==0) {
1550 	     Xorriso_option_hardlinks(xorriso, "on", 0);
1551 	   } else if(strcmp(argpt, "--acl")==0) {
1552 	     Xorriso_option_acl(xorriso, "on", 0);
1553 	   } else if(strcmp(argpt, "--xattr")==0) {
1554 	     Xorriso_option_xattr(xorriso, "on", 0);
1555 	   } else if(strcmp(argpt, "--md5")==0) {
1556 	     Xorriso_option_md5(xorriso, "on", 0);
1557 	   } else if(strcmp(argpt, "--scdbackup_tag")==0) {
1558 	     if(i + 2 >= argc)
1559 	       goto not_enough_args;
1560 	     i+= 2;
1561 	     ret= Xorriso_option_scdbackup_tag(xorriso, argv[i-1], argv[i], 0);
1562 	     if(ret <= 0)
1563 	       goto problem_handler_1;
1564 	   } else if(strcmp(argpt, "--for_backup")==0) {
1565 	     Xorriso_option_hardlinks(xorriso, "on", 0);
1566 	     Xorriso_option_acl(xorriso, "on", 0);
1567 	     Xorriso_option_xattr(xorriso, "on", 0);
1568 	     Xorriso_option_md5(xorriso, "on", 0);
1569 	   } else if(strcmp(argpt, "-z")==0 ||
1570 	             strcmp(argpt, "-transparent-compression")==0) {
1571 	     ret= Xorriso_genisofs_fused_options(xorriso, whom, "z",
1572 	                                  &option_d, &iso_level, &lower_r, ra_text, 2);
1573 	     if(ret <= 0)
1574 	       goto problem_handler_1;
1575 	     Xorriso_option_zisofs(xorriso, "by_magic=on", 0);
1576 	   } else if(strcmp(argpt, "--stdio_sync")==0) {
1577 	     if(i+1>=argc)
1578 	       goto not_enough_args;
1579 	     i++;
1580 	     Xorriso_option_stdio_sync(xorriso, argv[i], 0);
1581 	   } else if(strcmp(argpt, "-disallow_dir_id_ext")==0) {
1582 	     allow_dir_id_ext= 0;
1583 	   } else if(strcmp(argpt, "--emul-toc")==0) {
1584 	     with_emul_toc= 1;
1585 	     xorriso->no_emul_toc&= ~1;
1586 	   } else if(strcmp(argpt, "--no-emul-toc")==0) {
1587 	     with_emul_toc= 0;
1588 	     xorriso->no_emul_toc|= 1;
1589 	   } else if(strcmp(argpt, "-log-file") == 0) {
1590 	     /* already handled before this loop */;
1591 	     i++;
1592 	   } else if(strcmp(argpt, "-gui") == 0) {
1593 	     xorriso->pacifier_interval= 0.25;
1594 	   } else if(strcmp(argpt, "-file_name_limit") == 0) {
1595 	     if(i+1>=argc)
1596 	       goto not_enough_args;
1597 	     i++;
1598 	     Xorriso_option_file_name_limit(xorriso, argv[i], 0);
1599 	   } else {
1600 	     if(argv[i][0] == '-') {
1601 	       ret= Xorriso_genisofs_fused_options(xorriso, whom, argv[i] + 1,
1602 	                              &option_d, &iso_level, &lower_r, ra_text, 1 | 2);
1603 	       if(ret != 1)
1604 	         was_other_option= 1;
1605 	     } else {
1606 	       ret= 0;
1607 	       was_other_option= 1;
1608 	     }
1609 	     if(ret > 0) {
1610 	       Xorriso_genisofs_fused_options(xorriso, whom, argv[i] + 1,
1611 	                                  &option_d, &iso_level, &lower_r, ra_text, 2);
1612 	       if(ret <= 0) 
1613 	         goto problem_handler_1;
1614 	     } else {
1615 	       hargv[0]= argpt;
1616 	       ret= Xorriso_genisofs_count_args(xorriso, argc - i, hargv, &count, 0);
1617 	       if(ret > 0)
1618 	         i+= count; /* skip eventual arguments of known option */
1619 	     }
1620 	   }
1621 	 continue; /* regular bottom of loop */
1622 	problem_handler_1:;
1623 	   was_failure= 1;
1624 	   fret= Xorriso_eval_problem_status(xorriso, ret, 1|2);
1625 	   if(fret>=0)
1626 	 continue;
1627 	   goto ex;
1628 	 }
1629 	 Xorriso_option_report_about(xorriso, ra_text, 0);
1630 	 if(adr[0]) {
1631 	   if(strncmp(adr, "stdio:", 6)==0 && strncmp(adr, "stdio:/dev/fd/", 14)!=0) {
1632 	     ret= Sfile_type(adr+6, 1);
1633 	     if(ret==-1) {
1634 	       /* ok */;
1635 	     } else if(ret==2 || ret==3) {
1636 	       sprintf(xorriso->info_text,
1637 	               "-as %s: Cannot accept %s as target: -o %s",
1638 	               whom, (ret==3 ? "symbolic link" : "directory"),
1639 	               Text_shellsafe(adr+6, sfe, 0));
1640 	       Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1641 	       ret= 0; goto ex;
1642 	     }
1643 	   }
1644 	   /* Regard overwriteable as blank, truncate regular files on write start */
1645 	   ret= Xorriso_option_dev(xorriso, adr, 2|8|16);
1646 	   if(ret<=0)
1647 	     goto ex;
1648 	 }
1649 	
1650 	 if(was_other_option && xorriso->out_drive_handle==NULL) {
1651 	   ret= Xorriso_option_dev(xorriso, "-", 2|4); /* set outdev to stdout */
1652 	   if(ret<=0)
1653 	     goto ex;
1654 	 }
1655 	
1656 	 if(msc[0]) {
1657 	   cpt= strchr(msc, ',');
1658 	   if(cpt==NULL) {
1659 	illegal_c:;
1660 	     sprintf(xorriso->info_text,
1661 	             "-as %s: unusable parameter with option -C: %s",
1662 	             whom, Text_shellsafe(msc, sfe, 0));
1663 	     Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1664 	     {ret= 0; goto ex;}
1665 	   } else if(cpt==msc || msc[1]==0)
1666 	     goto illegal_c;
1667 	   strncpy(sfe, msc, cpt-msc);
1668 	   sfe[cpt-msc]= 0;
1669 	   if(xorriso->in_drive_handle!=NULL && indev[0]) {
1670 	     /* give up indev before setting the load address */
1671 	     ret= Xorriso_option_dev(xorriso, "", 1);
1672 	     if(ret<=0)
1673 	       goto ex;
1674 	   }
1675 	   /* growisofs submits msc1+16 to avoid a theoretical bug in mkisofs.
1676 	      Therefore this bug has to be emulated here. Sigh.
1677 	   */
1678 	   ret= Xorriso_option_load(xorriso, "sbsector", sfe, 1);
1679 	   if(ret<=0)
1680 	     goto ex;
1681 	   ret= Xorriso_option_grow_blindly(xorriso, cpt+1, 0);
1682 	   if(ret<=0)
1683 	     goto ex;
1684 	 }
1685 	
1686 	 if(old_root[0] || root_seen) {
1687 	   Xorriso_option_md5(xorriso, old_root_md5 ? "on" : "off", 0);
1688 	   Xorriso_option_disk_dev_ino(xorriso,
1689 	                               old_root_dev && old_root_ino ? "on" :
1690 	                               old_root_ino ? "ino_only" : "off", 0);
1691 	   if(!old_root_ino)
1692 	     Xorriso_option_hardlinks(xorriso, "without_update", 0);
1693 	 }
1694 	 if(indev[0]) {
1695 	   do_md5_mem= xorriso->do_md5;
1696 	   if(xorriso->do_md5 & 1) /* MD5 loading is enabled */
1697 	     xorriso->do_md5|= 32; /* Do not check tags of superblock,tree,session
1698 	                              because growisofs preserves the first sb tag.*/
1699 	   ret= Xorriso_option_dev(xorriso, indev, 1);
1700 	   xorriso->do_md5= do_md5_mem;
1701 	   if(ret<=0)
1702 	     goto ex;
1703 	 }
1704 	
1705 	 if(!was_other_option)
1706 	   {ret= 1; goto ex;}
1707 	
1708 	 if(old_root[0]) {
1709 	   ret= Xorriso_iso_lstat(xorriso, old_root, &stbuf, 0);
1710 	   if(ret >= 0) {
1711 	     if(root_seen) {
1712 	       ret= Xorriso_mkdir(xorriso, xorriso->wdi, 1 | 2);
1713 	       if(ret < 0)
1714 	         {ret= -(ret != -1); goto ex;}
1715 	     } else {
1716 	       strcpy(xorriso->wdi, "/");
1717 	     }
1718 	     if(strcmp(old_root, xorriso->wdi) != 0) {
1719 	       ret= Xorriso_clone_under(xorriso, old_root, xorriso->wdi, 0);
1720 	       if(ret <= 0)
1721 	         goto ex;
1722 	     }
1723 	   }
1724 	 }
1725 	
1726 	 xorriso->padding= 300*1024;
1727 	
1728 	 for(i= 0; i<argc; i++) {
1729 	   sprintf(xorriso->info_text, "-as %s: %s",
1730 	           whom, Text_shellsafe(argv[i], sfe, 0));
1731 	   Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
1732 	   ret= Xorriso_genisofs_strip_dash(xorriso, argv[i], &argpt, 0);
1733 	   if(ret <= 0)
1734 	     goto ex;
1735 	   ret= Xorriso_genisofs_ignore(xorriso, whom, argpt, &i, 0);
1736 	   if(ret == 1)
1737 	 continue;
1738 	   if(strcmp(argpt, "-version")==0) {
1739 	     /* was already handled in first argument scan */;
1740 	   } else if(strcmp(argpt, "--norock")==0) {
1741 	     xorriso->do_rockridge= 0;
1742 	     lower_r= 0;
1743 	   } else if(strcmp(argpt, "-R")==0 || strcmp(argpt, "-rock")==0) {
1744 	     ret= Xorriso_genisofs_fused_options(xorriso, whom, "R",
1745 	                                  &option_d, &iso_level, &lower_r, ra_text, 0);
1746 	     if(ret <= 0)
1747 	       goto problem_handler_2;
1748 	   } else if(strcmp(argpt, "-r")==0 || strcmp(argpt, "-rational-rock")==0){
1749 	     ret= Xorriso_genisofs_fused_options(xorriso, whom, "r",
1750 	                                  &option_d, &iso_level, &lower_r, ra_text, 0);
1751 	     if(ret <= 0)
1752 	       goto problem_handler_2;
1753 	   } else if(strcmp(argpt, "-J")==0 || strcmp(argpt, "-joliet")==0) {
1754 	     ret= Xorriso_genisofs_fused_options(xorriso, whom, "J",
1755 	                                  &option_d, &iso_level, &lower_r, ra_text, 0);
1756 	     if(ret <= 0)
1757 	       goto problem_handler_2;
1758 	   } else if(strcmp(argpt, "-joliet-long")==0) {
1759 	     Xorriso_relax_compliance(xorriso,
1760 	                              "joliet_long_paths:joliet_long_names", 0);
1761 	   } else if(strcmp(argpt, "-joliet-utf16")==0) {
1762 	     Xorriso_relax_compliance(xorriso, "joliet_utf16", 0);
1763 	   } else if(strcmp(argpt, "-fat") == 0) {
1764 	     /* was already handled in first argument scan */;
1765 	   } else if(strcmp(argpt, "-hfs-bless") == 0 ||
1766 	             strcmp(argpt, "-hfs-bless-by") == 0 ||
1767 	             strcmp(argpt, "-hfsplus-file-creator-type") == 0) {
1768 	     arg_count= 1;
1769 	     if(strcmp(argpt, "-hfs-bless-by") == 0)
1770 	       arg_count= 2;
1771 	     else if(strcmp(argpt, "-hfsplus-file-creator-type") == 0)
1772 	       arg_count= 3;
1773 	     if(i + arg_count >= argc)
1774 	       goto not_enough_args;
1775 	     /* Memorize command until all pathspecs are processed */
1776 	     delay_opt_list[delay_opt_count++]= i;
1777 	     if(argv[i] != argpt)
1778 	       delay_opt_list[delay_opt_count - 1]|= 1<<31;
1779 	     i+= arg_count;
1780 	   } else if(strcmp(argpt, "-hfsplus") == 0) {
1781 	     /* was already handled in first argument scan */;
1782 	   } else if(strcmp(argpt, "-hfsplus-serial-no") == 0) {
1783 	     if(i+1>=argc)
1784 	       goto not_enough_args;
1785 	     i++;
1786 	     sprintf(pathspec, "hfsplus_serial=%.80s", argv[i]);
1787 	     ret= Xorriso_option_boot_image(xorriso, "any", pathspec, 0);
1788 	     if(ret <= 0)
1789 	       goto problem_handler_2;
1790 	   } else if(strcmp(argpt, "-hfsplus-block-size") == 0 ||
1791 	             strcmp(argpt, "-apm-block-size") == 0) {
1792 	     if(i+1>=argc)
1793 	       goto not_enough_args;
1794 	     i++;
1795 	     ret= -1;
1796 	     sscanf(argv[i], "%d", &ret);
1797 	     if(argpt[1] == 'h')
1798 	       sprintf(sfe, "hfsplus_block_size=%d", ret);
1799 	     else
1800 	       sprintf(sfe, "apm_block_size=%d", ret);
1801 	     ret= Xorriso_option_boot_image(xorriso, "any", sfe, 0);
1802 	     if(ret <= 0)
1803 	       goto problem_handler_2;
1804 	
1805 	   } else if(strcmp(argpt, "-graft-points")==0) {
1806 	     xorriso->allow_graft_points= 3;
1807 	   } else if(strcmp(argpt, "-path-list")==0 ||
1808 	             strcmp(argpt, "--quoted_path_list")==0) {
1809 	     if(i+1>=argc) {
1810 	not_enough_args:;
1811 	       sprintf(xorriso->info_text, "-as %s: Not enough arguments to option %s",
1812 	               whom, argv[i]);
1813 	       Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
1814 	       ret= 0; goto ex;
1815 	     }
1816 	     i++;
1817 	     xorriso->pacifier_style= 1;
1818 	     ret= Xorriso_option_path_list(xorriso, argv[i],
1819 	                               (strcmp(argpt, "--quoted_path_list") == 0) | 2);
1820 	     if(ret<=0)
1821 	       goto problem_handler_2;
1822 	     ret = Xorriso_genisofs_path_pecul(xorriso, &was_path, with_emul_toc,
1823 	                                       &allow_dir_id_ext, &iso_level, 0);
1824 	     if(ret <= 0)
1825 	       goto ex;
1826 	   } else if(strcmp(argpt, "-f")==0 || strcmp(argpt, "-follow-links")==0) {
1827 	     /* was already handled in first argument scan */;
1828 	   } else if(strcmp(argpt, "-pad")==0) {
1829 	     xorriso->padding= 300*1024;
1830 	   } else if(strcmp(argpt, "-no-pad")==0) {
1831 	     xorriso->padding= 0;
1832 	   } else if(strcmp(argpt, "-print-size")==0) {
1833 	     do_print_size= 1;
1834 	   } else if(strcmp(argpt, "-o")==0 || strcmp(argpt, "-output") == 0) {
1835 	     i++;
1836 	     /* was already handled in first argument scan */;
1837 	   } else if(strcmp(argpt, "-M")==0  || strcmp(argpt, "-dev")==0 ||
1838 	             strcmp(argpt, "-prev-session")==0) {
1839 	     i++;
1840 	     /* was already handled in first argument scan */;
1841 	   } else if(strcmp(argpt, "-C")==0 ||
1842 	             strcmp(argpt, "-cdrecord-params")==0) {
1843 	     i++;
1844 	     /* was already handled in first argument scan */;
1845 	   } else if(strcmp(argpt, "-help")==0) {
1846 	     /* was already handled in first argument scan */;
1847 	   } else if(strcmp(argpt, "-V")==0 || strcmp(argpt, "-volid")==0 ||
1848 	             strcmp(argpt, "-volset")==0 ||
1849 	             strcmp(argpt, "-p")==0 || strcmp(argpt, "-preparer")==0 ||
1850 	             strcmp(argpt, "-P")==0 || strcmp(argpt, "-publisher")==0 ||
1851 	             strcmp(argpt, "-A")==0 || strcmp(argpt, "-appid")==0 ||
1852 	             strcmp(argpt, "--application_use")==0 ||
1853 	             strcmp(argpt, "-sysid")==0 ||
1854 	             strcmp(argpt, "-biblio")==0 ||
1855 	             strcmp(argpt, "-copyright")==0 ||
1856 	             strcmp(argpt, "-abstract")==0 ) {
1857 	     if(i+1>=argc)
1858 	       goto not_enough_args;
1859 	     i++;
1860 	     ret= 1;
1861 	     if(strcmp(argpt, "-V")==0 || strcmp(argpt, "-volid")==0)
1862 	       ret= Xorriso_option_volid(xorriso, argv[i], 0);
1863 	     else if(strcmp(argpt, "-volset")==0)
1864 	       ret= Xorriso_option_volset_id(xorriso, argv[i], 0);
1865 	     else if(strcmp(argpt, "-p")==0 ||
1866 	             strcmp(argpt, "-preparer")==0)
1867 	       ret= Xorriso_option_preparer_id(xorriso, argv[i], 0);
1868 	     else if(strcmp(argpt, "-P")==0 ||
1869 	             strcmp(argpt, "-publisher")==0)
1870 	       ret= Xorriso_option_publisher(xorriso, argv[i], 0);
1871 	     else if(strcmp(argpt, "-A")==0 || strcmp(argpt, "-appid")==0)
1872 	       ret= Xorriso_option_application_id(xorriso, argv[i], 0);
1873 	     else if(strcmp(argpt, "-sysid")==0)
1874 	       ret= Xorriso_option_system_id(xorriso, argv[i], 0);
1875 	     else if(strcmp(argpt, "-biblio")==0)
1876 	       ret= Xorriso_option_biblio_file(xorriso, argv[i], 0);
1877 	     else if(strcmp(argpt, "-copyright")==0)
1878 	       ret= Xorriso_option_copyright_file(xorriso, argv[i], 0);
1879 	     else if(strcmp(argpt, "-abstract")==0)
1880 	       ret= Xorriso_option_abstract_file(xorriso, argv[i], 0);
1881 	     else if(strcmp(argpt, "--application_use")==0)
1882 	       ret= Xorriso_option_application_use(xorriso, argv[i], 0);
1883 	     if(ret<=0)
1884 	       goto problem_handler_2;
1885 	   } else if(strcmp(argpt, "-m")==0 || strcmp(argpt, "-exclude")==0 ||
1886 	             strcmp(argpt, "-x")==0 || strcmp(argpt, "-old-exclude")==0) {
1887 	     if(i+1>=argc)
1888 	       goto not_enough_args;
1889 	     i++;
1890 	     mem= xorriso->do_disk_pattern;
1891 	     xorriso->do_disk_pattern= 1;
1892 	     if(strchr(argv[i], '/')!=NULL) {
1893 	       idx= i;
1894 	       ret= Xorriso_option_not_paths(xorriso, i+1, argv, &idx, 0);
1895 	     } else
1896 	       ret= Xorriso_option_not_leaf(xorriso, argv[i], 0);
1897 	     xorriso->do_disk_pattern= mem;
1898 	     if(ret<=0)
1899 	       goto problem_handler_2;
1900 	   } else if(strcmp(argpt, "-exclude-list")==0) {
1901 	     if(i+1>=argc)
1902 	       goto not_enough_args;
1903 	     i++;
1904 	     mem= xorriso->do_disk_pattern;
1905 	     xorriso->do_disk_pattern= 1;
1906 	     ret= Xorriso_option_not_list(xorriso, argv[i], 0);
1907 	     xorriso->do_disk_pattern= mem;
1908 	     if(ret<=0)
1909 	       goto problem_handler_2;
1910 	   } else if(strcmp(argpt, "-v")==0 || strcmp(argpt, "-verbose")==0 ||
1911 	             strcmp(argpt, "-quiet")==0) {
1912 	     /* was already handled in first argument scan */;
1913 	
1914 	   } else if(strcmp(argpt, "-iso-level")==0) {
1915 	     i++;
1916 	     /* was already handled in first argument scan */;
1917 	   } else if(strcmp(argpt, "-no-emul-boot")==0 ||
1918 	             strcmp(argpt, "-hard-disk-boot")==0 ||
1919 	             strcmp(argpt, "-boot-info-table")==0 ||
1920 	             strcmp(argpt, "--grub2-boot-info") == 0 ||
1921 	             strncmp(argpt, "isolinux_mbr=", 13)==0 ||
1922 	             strcmp(argpt, "-eltorito-alt-boot")==0 ||
1923 	             strcmp(argpt, "--protective-msdos-label")==0 ||
1924 	             strcmp(argpt, "--mbr-force-bootable")==0 ||
1925 	             strcmp(argpt, "--boot-catalog-hide")==0 ||
1926 	             strcmp(argpt, "-isohybrid-gpt-basdat")==0 ||
1927 	             strcmp(argpt, "-isohybrid-gpt-hfsplus")==0 ||
1928 	             strcmp(argpt, "-isohybrid-apm-hfsplus")==0 ||
1929 	             strcmp(argpt, "-part_like_isohybrid")==0) {
1930 	     delay_opt_list[delay_opt_count++]= i;
1931 	     if(argv[i] != argpt)
1932 	       delay_opt_list[delay_opt_count - 1]|= 1<<31;
1933 	   } else if(strcmp(argpt, "-b") == 0 ||
1934 	             strcmp(argpt, "-eltorito-boot") == 0 ||
1935 	             strcmp(argpt, "-eltorito-platform") == 0 ||
1936 	             strcmp(argpt, "--efi-boot") == 0 ||
1937 	             strcmp(argpt, "-e") == 0 ||
1938 	             strcmp(argpt, "-mips-boot") == 0 ||
1939 	             strcmp(argpt, "-mipsel-boot") == 0 ||
1940 	             strcmp(argpt, "-c") == 0 ||
1941 	             strcmp(argpt, "-eltorito-catalog") == 0 ||
1942 	             strcmp(argpt, "-boot-load-size") == 0 ||
1943 	             strcmp(argpt, "-eltorito-id") == 0 ||
1944 	             strcmp(argpt, "-eltorito-selcrit") == 0 ||
1945 	             strcmp(argpt, "--embedded-boot")==0 ||
1946 	             strcmp(argpt, "-generic-boot")==0 ||
1947 	             strcmp(argpt, "-G") == 0 ||
1948 	             strcmp(argpt, "-partition_offset") == 0 ||
1949 	             strcmp(argpt, "-partition_hd_cyl") == 0 ||
1950 	             strcmp(argpt, "-partition_sec_hd") == 0 ||
1951 	             strcmp(argpt, "-partition_cyl_align") == 0 ||
1952 	             strcmp(argpt, "-isohybrid-mbr") == 0 ||
1953 	             strcmp(argpt, "--grub2-mbr") == 0 ||
1954 	             strncmp(argpt, "-hppa-", 6) == 0 ||
1955 	             strcmp(argpt, "-alpha-boot") == 0 ||
1956 	             strcmp(argpt, "--gpt_disk_guid") == 0 ||
1957 	             strcmp(argpt, "-iso_mbr_part_type") == 0) { 
1958 	     if(i+1>=argc)
1959 	       goto not_enough_args;
1960 	     delay_opt_list[delay_opt_count++]= i;
1961 	     if(argv[i] != argpt)
1962 	       delay_opt_list[delay_opt_count - 1]|= 1<<31;
1963 	     i++;
1964 	   } else if(strncmp(argpt, "--modification-date=", 20)==0) {
1965 	     ret= Xorriso_option_volume_date(xorriso, "uuid", argpt + 20, 0);
1966 	     if(ret <= 0)
1967 	       goto problem_handler_2;
1968 	
1969 	   } else if(strcmp(argpt, "--set_all_file_dates") == 0) {
1970 	     if(i+1>=argc)
1971 	       goto not_enough_args;
1972 	     i++;
1973 	     ret= Xorriso_option_volume_date(xorriso, "all_file_dates", argv[i], 0);
1974 	     if(ret <= 0)
1975 	       goto problem_handler_2;
1976 	   } else if(strcmp(argpt, "-input-charset")==0) {
1977 	     i++;
1978 	     /* was already handled in first argument scan */;
1979 	   } else if(strcmp(argpt, "-output-charset")==0) {
1980 	     i++;
1981 	     /* was already handled in first argument scan */;
1982 	   } else if(strcmp(argpt, "--hardlinks")==0 ||
1983 	             strcmp(argpt, "--acl")==0 ||
1984 	             strcmp(argpt, "--xattr")==0 ||
1985 	             strcmp(argpt, "--md5")==0 ||
1986 	             strcmp(argpt, "--for_backup")==0) {
1987 	     /* was already handled in first argument scan */;
1988 	   } else if(strcmp(argpt, "--scdbackup_tag")==0) {
1989 	     /* was already handled in first argument scan */;
1990 	     i+= 2;
1991 	   } else if(strcmp(argpt, "--sort-weight")==0) {
1992 	     if(i + 2 >= argc)
1993 	       goto not_enough_args;
1994 	     i+= 2;
1995 	     /* memorize for find runs after pathspecs have been added */
1996 	     weight_list[weight_count++]= i - 2;
1997 	   } else if(strcmp(argpt, "--sort-weight-list") == 0 ||
1998 	             strcmp(argpt, "--sort-weight-patterns") == 0) {
1999 	     if(i + 1 >= argc)
2000 	       goto not_enough_args;
2001 	     i++;
2002 	     if(Sfile_str(sort_file, argv[i], 0) <= 0)
2003 	       {ret= -1; goto ex;}
2004 	     sort_file_pattern= (strcmp(argpt, "--sort-weight-patterns") == 0);
2005 	
2006 	   } else if(strcmp(argpt, "-z")==0 ||
2007 	             strcmp(argpt, "-transparent-compression")==0) {
2008 	     /* was already handled in first argument scan */;
2009 	   } else if(strcmp(argpt, "-U") == 0 ||
2010 	             strcmp(argpt, "-untranslated-filenames") == 0) {
2011 	     ret= Xorriso_genisofs_fused_options(xorriso, whom, "U",
2012 	                                  &option_d, &iso_level, &lower_r, ra_text, 0);
2013 	     if(ret <= 0)
2014 	       goto problem_handler_2;
2015 	   } else if(strcmp(argpt, "-untranslated_name_len") == 0) {
2016 	     if(i+1>=argc)
2017 	       goto not_enough_args;
2018 	     i++;
2019 	     sprintf(sfe, "untranslated_name_len=%s", argv[i]);
2020 	     ret= Xorriso_relax_compliance(xorriso, sfe, 0);
2021 	     if(ret <= 0)
2022 	       goto problem_handler_2;
2023 	   } else if(strcmp(argpt, "-N") == 0 ||
2024 	             strcmp(argpt, "-omit-version-number") == 0) {
2025 	     ret= Xorriso_genisofs_fused_options(xorriso, whom, "N",
2026 	                                  &option_d, &iso_level, &lower_r, ra_text, 0);
2027 	     if(ret <= 0)
2028 	       goto problem_handler_2;
2029 	   } else if(strcmp(argpt, "-l") == 0 ||
2030 	             strcmp(argpt, "-full-iso9660-filenames") == 0) {
2031 	     ret= Xorriso_genisofs_fused_options(xorriso, whom, "l",
2032 	                                  &option_d, &iso_level, &lower_r, ra_text, 0);
2033 	     if(ret <= 0)
2034 	       goto problem_handler_2;
2035 	   } else if(strcmp(argpt, "-max-iso9660-filenames") == 0) {
2036 	     Xorriso_relax_compliance(xorriso, "long_names", 0);
2037 	   } else if(strcmp(argpt, "-d") == 0 ||
2038 	             strcmp(argpt, "-omit-period") == 0) {
2039 	     ret= Xorriso_genisofs_fused_options(xorriso, whom, "d",
2040 	                                  &option_d, &iso_level, &lower_r, ra_text, 0);
2041 	     if(ret <= 0)
2042 	       goto problem_handler_2;
2043 	   } else if(strcmp(argpt, "-allow-lowercase") == 0) {
2044 	     Xorriso_relax_compliance(xorriso, "lowercase", 0);
2045 	   } else if(strcmp(argpt, "-relaxed-filenames") == 0) {
2046 	     Xorriso_relax_compliance(xorriso, "7bit_ascii", 0);
2047 	   } else if(strcmp(argpt, "-hide") == 0 ||
2048 	             strcmp(argpt, "-hide-list") == 0 ||
2049 	             strcmp(argpt, "-hide-joliet") == 0 ||
2050 	             strcmp(argpt, "-hide-joliet-list") == 0 ||
2051 	             strcmp(argpt, "-hide-hfsplus") == 0 ||
2052 	             strcmp(argpt, "-hide-hfsplus-list") == 0) {
2053 	     if(i+1>=argc)
2054 	       goto not_enough_args;
2055 	     i++;
2056 	     /* was already handled in first argument scan */;
2057 	   } else if(strcmp(argpt, "-root") == 0 ||
2058 	             strcmp(argpt, "-old-root") == 0) {
2059 	     if(i+1>=argc)
2060 	       goto not_enough_args;
2061 	     i++;
2062 	     /* was already handled in first argument scan */;
2063 	   } else if(strcmp(argpt, "--old-root-no-md5")==0 ||
2064 	             strcmp(argpt, "--old-root-devno")==0 ||
2065 	             strcmp(argpt, "--old-root-no-ino")==0) {
2066 	     /* was already handled in first argument scan */;
2067 	   } else if(strcmp(argpt, "-dir-mode") == 0) {
2068 	     if(i+1>=argc)
2069 	       goto not_enough_args;
2070 	     i++;
2071 	     ret= Xorriso_convert_modstring(xorriso, "-as mkisofs -dir-mode",
2072 	                                    argv[i], &mode_and, &mode_or, 0);
2073 	     if(ret<=0)
2074 	       goto problem_handler_2;
2075 	     dir_mode= mode_or;
2076 	   } else if(strcmp(argpt, "-file-mode") == 0) {
2077 	     if(i+1>=argc)
2078 	       goto not_enough_args;
2079 	     i++;
2080 	     ret= Xorriso_convert_modstring(xorriso, "-as mkisofs -file-mode",
2081 	                                    argv[i], &mode_and, &mode_or, 0);
2082 	     if(ret<=0)
2083 	       goto problem_handler_2;
2084 	     file_mode= mode_or;
2085 	   } else if(strcmp(argpt, "-jigdo-jigdo") == 0 ||
2086 	             strcmp(argpt, "-jigdo-template") == 0 ||     
2087 	             strcmp(argpt, "-jigdo-min-file-size") == 0 ||     
2088 	             strcmp(argpt, "-jigdo-exclude") == 0 ||     
2089 	             strcmp(argpt, "-jigdo-force-md5") == 0 ||     
2090 	             strcmp(argpt, "-jigdo-map") == 0 ||     
2091 	             strcmp(argpt, "-jigdo-template-compress") == 0 ||     
2092 	             strcmp(argpt, "-checksum_algorithm_iso") == 0 ||     
2093 	             strcmp(argpt, "-checksum_algorithm_template") == 0 ||     
2094 	             strcmp(argpt, "-md5-list") == 0) {
2095 	     i++;
2096 	     ret= Xorriso_option_jigdo(xorriso, argpt, argv[i], 0);
2097 	     if(ret <= 0)
2098 	       goto problem_handler_2;
2099 	
2100 	   } else if(strcmp(argpt, "-chrp-boot-part") == 0 ||
2101 	             strcmp(argpt, "-chrp-boot") == 0) {
2102 	     ret= Xorriso_option_boot_image(xorriso, "any", "chrp_boot_part=on", 0);
2103 	     if(ret <= 0)
2104 	       goto problem_handler_2;
2105 	
2106 	   } else if(strcmp(argpt, "-prep-boot-part") == 0) {
2107 	     if(i + 1 >= argc)
2108 	       goto not_enough_args;
2109 	     i++;
2110 	     ret= Sfile_str(xorriso->prep_partition, argv[i], 0);
2111 	     if(ret <= 0)
2112 	       goto ex;
2113 	
2114 	   } else if(strcmp(argpt, "-efi-boot-part") == 0) {
2115 	     if(i + 1 >= argc)
2116 	       goto not_enough_args;
2117 	     i++;
2118 	     ret= Sfile_str(xorriso->efi_boot_partition, argv[i], 0);
2119 	     if(ret <= 0)
2120 	       goto ex;
2121 	
2122 	   } else if(strcmp(argpt, "-append_partition") == 0) {
2123 	     if(i + 3 >= argc)
2124 	       goto not_enough_args;
2125 	     i+= 3;
2126 	     ret= Xorriso_option_append_partition(xorriso, argv[i - 2], argv[i - 1],
2127 	                                          argv[i], 0);
2128 	     if(ret <= 0)
2129 	       goto problem_handler_2;
2130 	
2131 	   } else if(strcmp(argpt, "-appended_part_as_gpt") == 0) {
2132 	     xorriso->appended_as_gpt= 1;
2133 	
2134 	   } else if(strcmp(argpt, "-appended_part_as_apm") == 0) {
2135 	     xorriso->appended_as_apm= 1;
2136 	
2137 	   } else if(strcmp(argpt, "-B") == 0 ||
2138 	             strcmp(argpt, "-sparc-boot") == 0) {
2139 	     i++;
2140 	     if(strlen(argv[i]) >= SfileadrL)
2141 	 continue;
2142 	
2143 	     /* Switch system area type to: SUN Disk Label */
2144 	     strcpy(pathspec, "sparc_label=");
2145 	     strcat(pathspec, xorriso->ascii_disc_label);
2146 	     ret= Xorriso_option_boot_image(xorriso, "any", pathspec, 0);
2147 	     if(ret <= 0)
2148 	       goto problem_handler_2;
2149 	
2150 	     /* Interpret list of boot partition images or "..." */;
2151 	     cpt= ept= argv[i];
2152 	     partition_number= 2;
2153 	     while(ept != NULL) {
2154 	       ept= strchr(cpt, ',');
2155 	       if(ept != NULL) {
2156 	         strncpy(pathspec, cpt, ept - cpt);
2157 	         pathspec[ept - cpt]= 0;
2158 	         cpt= ept + 1;
2159 	       } else
2160 	         strcpy(pathspec, cpt);
2161 	       if(strcmp(pathspec, "...") == 0) {
2162 	         for(; partition_number <= 8; partition_number++) {
2163 	           sprintf(partno_text, "%d", partition_number);
2164 	           ret= Xorriso_option_append_partition(xorriso, partno_text, "0x0",
2165 	                                                ".", 0);
2166 	           if(ret <= 0)
2167 	             goto problem_handler_2;
2168 	         }
2169 	       } else {
2170 	         if(partition_number > 8) {
2171 	           sprintf(xorriso->info_text,
2172 	                "-as %s -sparc-boot %s : Too many boot images", whom, argv[i]);
2173 	           Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE",0);
2174 	           goto problem_handler_2;
2175 	         }
2176 	         sprintf(partno_text, "%d", partition_number);
2177 	         ret= Xorriso_option_append_partition(xorriso, partno_text, "0x0",
2178 	                                              pathspec, 0);
2179 	         if(ret <= 0)
2180 	           goto problem_handler_2;
2181 	         partition_number++;
2182 	       }
2183 	     }
2184 	
2185 	   } else if(strcmp(argpt, "-sparc-label") == 0) {
2186 	     if(i+1>=argc)
2187 	       goto not_enough_args;
2188 	     i++;
2189 	     sprintf(sfe, "sparc_label=%s", argv[i]);
2190 	     ret= Xorriso_option_boot_image(xorriso, "any", sfe, 0);
2191 	     if(ret <= 0)
2192 	       goto problem_handler_2;
2193 	
2194 	   } else if(strcmp(argpt, "--grub2-sparc-core") == 0) {
2195 	     if(i+1>=argc)
2196 	       goto not_enough_args;
2197 	     i++;
2198 	     sprintf(sfe, "grub2_sparc_core=%s", argv[i]);
2199 	     ret= Xorriso_option_boot_image(xorriso, "any", sfe, 0);
2200 	     if(ret <= 0)
2201 	       goto problem_handler_2;
2202 	
2203 	   } else if(strcmp(argpt, "--stdio_sync")==0) {
2204 	     if(i+1>=argc)
2205 	       goto not_enough_args;
2206 	     i++;
2207 	     /* was already handled in first argument scan */;
2208 	
2209 	   } else if(strcmp(argpt, "--emul-toc")==0 ||
2210 	             strcmp(argpt, "--no-emul-toc")==0) {
2211 	     /* was already handled in first argument scan */;
2212 	
2213 	   } else if(strcmp(argpt, "--old-empty")==0) {
2214 	     xorriso->do_old_empty= 1;
2215 	
2216 	   } else if(strcmp(argpt, "-disallow_dir_id_ext")==0) {
2217 	     /* was already handled in first argument scan */;
2218 	
2219 	   } else if(strcmp(argpt, "--no_rc")==0) {
2220 	     /* was already handled in Xorriso_prescan_args */;
2221 	
2222 	   } else if(strcmp(argpt, "-D") == 0 ||
2223 	             strcmp(argpt, "-disable-deep-relocation") == 0) {
2224 	     ret= Xorriso_genisofs_fused_options(xorriso, whom, "D",
2225 	                                  &option_d, &iso_level, &lower_r, ra_text, 0);
2226 	     if(ret <= 0)
2227 	       goto problem_handler_2;
2228 	
2229 	   } else if(strcmp(argpt, "-hide-rr-moved") == 0) {
2230 	     rr_reloc_dir_pt= ".rr_moved";
2231 	     goto rr_reloc_dir;
2232 	
2233 	   } else if(strcmp(argpt, "-rr_reloc_dir") == 0) {
2234 	     i++;
2235 	     rr_reloc_dir_pt= argv[i];
2236 	rr_reloc_dir:;
2237 	     if(rr_reloc_dir_pt[0] == '/')
2238 	        rr_reloc_dir_pt++;
2239 	     if(strchr(rr_reloc_dir_pt, '/') != NULL) {
2240 	       sprintf(xorriso->info_text,
2241 	        "-as %s -rr_reloc_dir %s : May only use directories in root directory",
2242 	               whom, Text_shellsafe(argv[i], sfe, 0));
2243 	       Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE",0);
2244 	     }
2245 	     ret= Xorriso_option_rr_reloc_dir(xorriso, rr_reloc_dir_pt, 0);
2246 	     if(ret <= 0)
2247 	       goto problem_handler_2;
2248 	     Xorriso_relax_compliance(xorriso, "deep_paths_off:long_paths_off", 0);
2249 	
2250 	   } else if(strcmp(argpt, "-log-file") == 0 ||
2251 	             strcmp(argpt, "-file_name_limit") == 0) {
2252 	     i+= 1;
2253 	     /* was already handled before this loop */;
2254 	
2255 	   } else if(strcmp(argpt, "-gui") == 0) {
2256 	     /* was already handled in first argument scan */;
2257 	
2258 	   } else if(argpt[0]=='-' && argpt[1]!=0) {
2259 	     ret= Xorriso_genisofs_fused_options(xorriso, whom, argv[i] + 1,
2260 	                                  &option_d, &iso_level, &lower_r, ra_text, 1);
2261 	     if(ret == 1) {
2262 	       ret= Xorriso_genisofs_fused_options(xorriso, whom, argv[i] + 1,
2263 	                                  &option_d, &iso_level, &lower_r, ra_text, 0);
2264 	       if(ret <= 0)
2265 	         goto problem_handler_2;
2266 	     } else {
2267 	       hargv[0]= argpt;
2268 	       ret= Xorriso_genisofs_count_args(xorriso, argc - i, hargv, &count, 1);
2269 	       if(ret > 0) {
2270 	         sprintf(xorriso->info_text, "-as %s: Unsupported option %s",
2271 	                 whom, Text_shellsafe(argv[i], sfe, 0));
2272 	         Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
2273 	         i+= count;
2274 	         goto problem_handler_2;
2275 	       } else {
2276 	         sprintf(xorriso->info_text, "-as %s: Unrecognized option %s",
2277 	                 whom, Text_shellsafe(argv[i], sfe, 0));
2278 	         Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
2279 	         goto problem_handler_2;
2280 	       }
2281 	     }
2282 	   } else {
2283 	     ret= Xorriso_graftable_pathspec(xorriso, argv[i], pathspec, 0);
2284 	     if(ret <= 0)
2285 	       goto problem_handler_2;
2286 	     add_pt= pathspec;
2287 	
2288 	     if(old_root[0]) {
2289 	       /* Split pathspec */
2290 	       ret= Fileliste__target_source_limit(add_pt, '=', &ept, 0);
2291 	       if(ret > 0) {
2292 	         *ept= 0;
2293 	         iso_rr_pt= add_pt;
2294 	         disk_pt= ept + 1;
2295 	       } else {
2296 	         iso_rr_pt= "/";
2297 	         disk_pt= add_pt;
2298 	       }
2299 	
2300 	       /* Unescape iso_rr_pt */
2301 	       strcpy(eff_path, iso_rr_pt);
2302 	       iso_rr_pt= eff_path;
2303 	       for(wpt= rpt= iso_rr_pt; *rpt != 0; rpt++) {
2304 	         if(*rpt == '\\') {
2305 	           if(*(rpt + 1) == '\\')
2306 	             rpt++;
2307 	           else if(*(rpt + 1) == '=')
2308 	       continue;
2309 	         }
2310 	         *(wpt++) = *rpt;
2311 	       }
2312 	       *wpt= 0;
2313 	
2314 	       if(root_seen) {
2315 	         ret= Sfile_prepend_path(xorriso->wdi, iso_rr_pt, 0);
2316 	         if(ret<=0) {
2317 	           Xorriso_msgs_submit(xorriso, 0, "Effective path gets much too long",
2318 	                               0, "FAILURE", 0);
2319 	           goto problem_handler_2;
2320 	         }
2321 	       }
2322 	       /* update_merge */
2323 	       ret= Xorriso_option_update(xorriso, disk_pt, iso_rr_pt, 1 | 8 | 32);
2324 	     } else {
2325 	       mem_graft_points= xorriso->allow_graft_points;
2326 	       xorriso->allow_graft_points= 3;
2327 	       zero= 0;
2328 	       ret= Xorriso_option_add(xorriso, 1, &add_pt, &zero,
2329 	                               (was_path << 1) | (root_seen << 2));
2330 	       xorriso->allow_graft_points= mem_graft_points;
2331 	     }
2332 	     if(ret<=0)
2333 	       goto problem_handler_2;
2334 	
2335 	     /* Enforce odd mkisofs defaults on first pathspec */
2336 	     ret = Xorriso_genisofs_path_pecul(xorriso, &was_path, with_emul_toc,
2337 	                                       &allow_dir_id_ext, &iso_level, 0);
2338 	     if(ret <= 0)
2339 	       goto ex;
2340 	   }
2341 	 continue; /* regular bottom of loop */
2342 	problem_handler_2:;
2343 	   was_failure= 1;
2344 	   fret= Xorriso_eval_problem_status(xorriso, ret, 1|2);
2345 	   if(fret>=0)
2346 	 continue;
2347 	   goto ex;
2348 	 }
2349 	
2350 	 if(old_root[0]) {
2351 	   /* Delete all visited nodes which were not found on disk */
2352 	   if(root_seen)
2353 	     rm_merge_args[0]= xorriso->wdi;
2354 	   else
2355 	     rm_merge_args[0]= "/";
2356 	   rm_merge_args[1]= "-exec";
2357 	   rm_merge_args[2]= "rm_merge";
2358 	   zero= 0;
2359 	   ret= Xorriso_option_find(xorriso, 3, rm_merge_args, &zero, 2);
2360 	   if(ret<=0)
2361 	     goto ex;
2362 	 }
2363 	
2364 	 if(lower_r) {
2365 	   static char *lower_r_args[3]= {"/", "-exec", "mkisofs_r"};
2366 	   zero= 0;
2367 	   ret= Xorriso_option_find(xorriso, 3, lower_r_args, &zero, 2);
2368 	   if(ret<=0)
2369 	     goto ex;
2370 	 }
2371 	 if(dir_mode >= 0) {
2372 	   static char *dir_mode_args[6]= {"/", "-type", "d", "-exec", "chmod", ""};
2373 	   zero= 0;
2374 	   sprintf(sfe, "0%o", (unsigned int) dir_mode);
2375 	   dir_mode_args[5]= sfe;
2376 	   ret= Xorriso_option_find(xorriso, 6, dir_mode_args, &zero, 2);
2377 	   if(ret<=0)
2378 	     goto ex;
2379 	 }
2380 	 if(file_mode >= 0) {
2381 	   static char *file_mode_args[6]= {"/", "-type", "f", "-exec", "chmod", ""};
2382 	   zero= 0;
2383 	   sprintf(sfe, "0%o", (unsigned int) file_mode);
2384 	   file_mode_args[5]= sfe;
2385 	   ret= Xorriso_option_find(xorriso, 6, file_mode_args, &zero, 2);
2386 	   if(ret<=0)
2387 	     goto ex;
2388 	 }
2389 	
2390 	 if(sort_file[0]) {
2391 	   ret= Xorriso_apply_sort_file(xorriso, sort_file, sort_file_pattern);
2392 	   if(ret<=0)
2393 	     goto ex;
2394 	 }
2395 	
2396 	 for(j= 0; j < weight_count; j++) {
2397 	   i= weight_list[j];
2398 	   /* find argv[i+2] -exec sort_weight argv[i+1] */
2399 	   zero= 0;
2400 	   sort_weight_args[0]= argv[i + 2];
2401 	   sort_weight_args[1]= "-exec";
2402 	   sort_weight_args[2]= "sort_weight";
2403 	   sort_weight_args[3]= argv[i + 1];
2404 	   ret= Xorriso_option_find(xorriso, 4, sort_weight_args, &zero, 2);
2405 	   if(ret > 0)
2406 	 continue;
2407 	   /* Problem handler */
2408 	   was_failure= 1;
2409 	   fret= Xorriso_eval_problem_status(xorriso, ret, 1|2);
2410 	   if(fret>=0)
2411 	 continue;
2412 	   goto ex;
2413 	 }
2414 	
2415 	 if(option_d)
2416 	   Xorriso_relax_compliance(xorriso, "deep_paths:long_paths", 0);
2417 	
2418 	 /* After all pathspecs are added: perform delayed options, mostly boot related
2419 	 */
2420 	 for(j= 0; j < delay_opt_count; j++) {
2421 	   i= delay_opt_list[j] & ~(1 << 31);
2422 	   if(delay_opt_list[j] & (1 << 31))
2423 	     argpt= argv[i] + 1;
2424 	   else
2425 	     argpt= argv[i];
2426 	   if(strcmp(argpt, "-no-emul-boot")==0) {
2427 	     xorriso->boot_image_emul= 0;
2428 	     xorriso->boot_emul_default= 0;
2429 	   } else if(strcmp(argpt, "-hard-disk-boot")==0) {
2430 	     xorriso->boot_image_emul= 1;
2431 	     xorriso->boot_emul_default= 0;
2432 	   } else if(strcmp(argpt, "-boot-info-table")==0) {
2433 	     xorriso->patch_isolinux_image= (xorriso->patch_isolinux_image & ~2) | 1;
2434 	   } else if(strcmp(argpt, "--grub2-boot-info") == 0) {
2435 	     xorriso->patch_isolinux_image=
2436 	                                  (xorriso->patch_isolinux_image & ~2) | 512;
2437 	   } else if(strcmp(argpt, "-b") == 0 ||
2438 	             strcmp(argpt, "-eltorito-boot") == 0 ||
2439 	             strcmp(argpt, "--efi-boot") == 0 ||
2440 	             strcmp(argpt, "-e") == 0) {
2441 	     i++;
2442 	     if(strcmp(argpt, "--efi-boot") == 0) {
2443 	       if(xorriso->boot_image_bin_path[0]) {
2444 	         ret= Xorriso_genisofs_add_boot(xorriso, 0);
2445 	         if(ret <= 0)
2446 	           goto problem_handler_boot;
2447 	       }
2448 	       boot_path= xorriso->boot_image_bin_path;
2449 	       xorriso->boot_efi_default= 1;
2450 	       xorriso->boot_image_emul= 0;
2451 	       xorriso->boot_emul_default= 0;
2452 	
2453 	     } else {
2454 	       boot_path= xorriso->boot_image_bin_path; 
2455 	       if(strcmp(argpt, "-e") == 0)
2456 	         xorriso->boot_platform_id= 0xef;
2457 	       else
2458 	         xorriso->boot_platform_id= mkisofs_b_platform_id;
2459 	       xorriso->boot_efi_default= 0;
2460 	       if(xorriso->boot_emul_default)
2461 	         xorriso->boot_image_emul= 2;
2462 	     }
2463 	     boot_path[0]= 0;
2464 	     if(argv[i][0] != '/' && strncmp(argv[i], "--interval:", 11) != 0)
2465 	       strcat(boot_path, "/");
2466 	     ret= Sfile_str(boot_path + strlen(boot_path), argv[i], 0);
2467 	     if(ret <= 0)
2468 	       goto ex;
2469 	     if(xorriso->boot_efi_default && xorriso->boot_image_bin_path[0]) {
2470 	       ret= Xorriso_genisofs_add_boot(xorriso, 0);
2471 	       if(ret <= 0)
2472 	         goto problem_handler_boot;
2473 	     }
2474 	     xorriso->keep_boot_image= 0;
2475 	     with_boot_image= 1;
2476 	   } else if(strcmp(argpt, "-eltorito-platform") == 0) {
2477 	     if(i + 1>=argc)
2478 	       goto not_enough_args;
2479 	     i++;
2480 	     mem= mkisofs_b_platform_id;
2481 	     mkisofs_b_platform_id= Xorriso_genisofs_platform(xorriso, argv[i], 0);
2482 	     if(mkisofs_b_platform_id < 0) {
2483 	       mkisofs_b_platform_id= 0;
2484 	       goto problem_handler_boot;
2485 	     }
2486 	     if(mkisofs_b_platform_id != mem &&
2487 	        xorriso->boot_image_bin_path[0] != 0) {
2488 	       ret= Xorriso_genisofs_add_boot(xorriso, 0);
2489 	       if(ret <= 0)
2490 	         goto problem_handler_boot;
2491 	     }
2492 	
2493 	   } else if(strcmp(argpt, "-c") == 0 ||
2494 	             strcmp(argpt, "-eltorito-catalog") == 0) {
2495 	     if(i+1>=argc)
2496 	       goto not_enough_args;
2497 	     i++;
2498 	     xorriso->boot_image_cat_path[0]= 0;
2499 	     if(argv[i][0] != '/')
2500 	       strcat(xorriso->boot_image_cat_path, "/");
2501 	     ret= Sfile_str(xorriso->boot_image_cat_path
2502 	                    + strlen(xorriso->boot_image_cat_path), argv[i], 0);
2503 	     if(ret <= 0)
2504 	       goto ex;
2505 	     if(with_cat_path == 0)
2506 	       with_cat_path= 1;
2507 	   } else if(strcmp(argpt, "-boot-load-size") == 0) {
2508 	     if(i+1>=argc)
2509 	       goto not_enough_args;
2510 	     i++;
2511 	     if(strcmp(argv[i], "full") == 0) {
2512 	       xorriso->boot_img_full_size= 1;
2513 	     } else {
2514 	       sscanf(argv[i], "%d", &ret);
2515 	       xorriso->boot_image_load_size= ret * 512;
2516 	     }
2517 	     xorriso->boot_img_size_default= 0;
2518 	   } else if(strcmp(argpt, "-eltorito-id") == 0 ||
2519 	             strcmp(argpt, "-eltorito-selcrit") == 0) {
2520 	     if(i+1>=argc)
2521 	       goto not_enough_args;
2522 	     i++;
2523 	     if(strcmp(argpt, "-eltorito-id") == 0)
2524 	       sprintf(sfe, "id_string=%s", argv[i]);
2525 	     else
2526 	       sprintf(sfe, "sel_crit=%s", argv[i]);
2527 	     ret= Xorriso_option_boot_image(xorriso, "any", sfe, 0);
2528 	     if(ret <= 0)
2529 	       goto problem_handler_boot;
2530 	   } else if(strncmp(argpt, "isolinux_mbr=", 13)==0) {
2531 	     sprintf(sfe, "isohybrid=%s", argpt + 13);
2532 	     ret= Xorriso_option_boot_image(xorriso, "isolinux", sfe, 0);
2533 	     if(ret <= 0)
2534 	       goto problem_handler_boot;
2535 	   } else if(strcmp(argpt, "-isohybrid-gpt-basdat") == 0) {
2536 	     xorriso->patch_isolinux_image = (xorriso->patch_isolinux_image & ~0x0fc) |
2537 	                                     (1 << 2);
2538 	   } else if(strcmp(argpt, "-isohybrid-gpt-hfsplus") == 0) {
2539 	     xorriso->patch_isolinux_image = (xorriso->patch_isolinux_image & ~0x0fc) |
2540 	                                     (2 << 2);
2541 	   } else if(strcmp(argpt, "-isohybrid-apm-hfsplus") == 0) {
2542 	     xorriso->patch_isolinux_image = xorriso->patch_isolinux_image | (1 << 8);
2543 	
2544 	   } else if(strcmp(argpt, "-part_like_isohybrid") == 0) {
2545 	     xorriso->part_like_isohybrid= 1;
2546 	
2547 	   } else if(strcmp(argpt, "-iso_mbr_part_type") == 0) {
2548 	     if(i + 1 >= argc)
2549 	       goto not_enough_args;
2550 	     i++;
2551 	     sprintf(sfe, "iso_mbr_part_type=%s", argv[i]);
2552 	     ret= Xorriso_option_boot_image(xorriso, "any", sfe, 0);
2553 	     if(ret <= 0)
2554 	       goto problem_handler_boot;
2555 	
2556 	   } else if(strcmp(argpt, "--gpt_disk_guid") == 0) {
2557 	     if(i + 1 >= argc)
2558 	       goto not_enough_args;
2559 	     i++;
2560 	     ret= Xorriso_parse_gpt_guid(xorriso, argv[i], 0);
2561 	     if(ret <= 0)
2562 	       goto problem_handler_boot;
2563 	
2564 	   } else if(strcmp(argpt, "-eltorito-alt-boot")==0) {
2565 	     ret= Xorriso_genisofs_add_boot(xorriso, 0);
2566 	     if(ret <= 0)
2567 	       goto problem_handler_boot;
2568 	   } else if(strcmp(argpt, "--embedded-boot")==0 ||
2569 	             strcmp(argpt, "-generic-boot")==0 ||
2570 	             strcmp(argpt, "-G") == 0 ||
2571 	             strcmp(argpt, "-isohybrid-mbr") == 0 ||
2572 	             strcmp(argpt, "--grub2-mbr") == 0) {
2573 	     if(i+1>=argc)
2574 	       goto not_enough_args;
2575 	     i++; 
2576 	     if(strcmp(argv[i], ".") == 0)
2577 	       sa_path= "";
2578 	     else
2579 	       sa_path= argv[i];
2580 	     ret= Xorriso_set_system_area_path(xorriso, sa_path, 0);
2581 	     if(ret <= 0)
2582 	       goto problem_handler_boot;
2583 	     if(strcmp(argpt, "-isohybrid-mbr")==0)
2584 	       xorriso->system_area_options=
2585 	                                    (xorriso->system_area_options & ~4001) | 2;
2586 	     else if(strcmp(argpt, "--grub2-mbr") == 0)
2587 	       xorriso->system_area_options= 
2588 	                                  (xorriso->system_area_options & ~2) | 0x4000;
2589 	   } else if(strcmp(argpt, "--protective-msdos-label")==0) {
2590 	     xorriso->system_area_options= (xorriso->system_area_options & ~2) | 1;
2591 	
2592 	   } else if(strcmp(argpt, "--mbr-force-bootable") == 0) {
2593 	     xorriso->system_area_options= xorriso->system_area_options | (1 << 15);
2594 	
2595 	   } else if(strcmp(argpt, "--boot-catalog-hide")==0) {
2596 	     xorriso->boot_image_cat_hidden|= 3;
2597 	   } else if(strcmp(argpt, "-partition_offset") == 0 ||
2598 	             strcmp(argpt, "-partition_sec_hd") == 0 ||
2599 	             strcmp(argpt, "-partition_hd_cyl") == 0 ||
2600 	             strcmp(argpt, "-partition_cyl_align") == 0) {
2601 	     if(i+1>=argc)
2602 	       goto not_enough_args;
2603 	     i++;
2604 	     sprintf(sfe, "%s=%.16s", argpt + 1, argv[i]);
2605 	     ret= Xorriso_option_boot_image(xorriso, "any", sfe, 0);
2606 	     if(ret <= 0)
2607 	       goto problem_handler_boot;
2608 	
2609 	   } else if(strcmp(argpt, "-mips-boot") == 0 ||
2610 	             strcmp(argpt, "-mipsel-boot") == 0) {
2611 	     if(i + 1 >= argc)
2612 	       goto not_enough_args;
2613 	     i++;
2614 	     if(strcmp(argpt, "-mipsel-boot") == 0)
2615 	       strcpy(sfe, "mipsel_path=");
2616 	     else
2617 	       strcpy(sfe, "mips_path=");
2618 	     ret= Sfile_str(sfe, argv[i], 1);
2619 	     if(ret <= 0)
2620 	       goto ex;
2621 	
2622 	     ret= Xorriso_option_boot_image(xorriso, "any", sfe, 0);
2623 	     if(ret <= 0)
2624 	       goto problem_handler_boot;
2625 	
2626 	   } else if(strncmp(argpt, "-hppa-", 6) == 0) {
2627 	     if(i + 1 >= argc)
2628 	       goto not_enough_args;
2629 	     i++;
2630 	     sprintf(sfe, "-as mkisofs %s %s", argpt, argv[i]);
2631 	     palohdrversion= (xorriso->system_area_options >> 2) & 0x3f;
2632 	     if(palohdrversion != 4)
2633 	       palohdrversion= 5;
2634 	     ret= Xorriso_coordinate_system_area(xorriso, palohdrversion, 0, sfe, 0);
2635 	     if(ret <= 0)
2636 	       goto ex;
2637 	     ret= Xorriso_set_hppa_boot_parm(xorriso, argv[i], argpt + 6, 0);
2638 	     if(ret <= 0)
2639 	       goto problem_handler_boot;
2640 	
2641 	   } else if(strcmp(argpt, "-alpha-boot") == 0) {
2642 	     if(i + 1 >= argc)
2643 	       goto not_enough_args;
2644 	     i++;
2645 	     sprintf(sfe, "-as mkisofs %s %s", argpt, argv[i]);
2646 	     ret= Xorriso_coordinate_system_area(xorriso, 6, 0, sfe, 0);
2647 	     if(ret <= 0)
2648 	       goto ex;
2649 	     ret= Xorriso_set_alpha_boot(xorriso, argv[i], 0);
2650 	
2651 	   } else if(strcmp(argpt, "-hfs-bless") == 0) {
2652 	     static char *bless_arg_data[6]= {
2653 	        "/", "-disk_path", "", "-exec", "set_hfs_bless", "p"};
2654 	
2655 	     for(j= 0; j < 6; j++)
2656 	       bless_args[j]= bless_arg_data[j];
2657 	     bless_args[2]= argv[i + 1];
2658 	     zero= 0;
2659 	     ret= Xorriso_option_find(xorriso, 6, bless_args, &zero, 2 | 16);
2660 	     if(ret<=0)
2661 	        goto ex;
2662 	     if(ret < 2) {
2663 	       sprintf(xorriso->info_text,
2664 	               "-hfs-bless: Could not find a data file which stems from underneath disk directory ");
2665 	       Text_shellsafe(argv[i + 1], xorriso->info_text, 1);
2666 	       Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
2667 	       Xorriso_msgs_submit(xorriso, 0,
2668 	                 "Consider to use: -hfs-bless-by p ISO_RR_PATH", 0, "HINT", 0);
2669 	       goto problem_handler_boot;
2670 	     }
2671 	
2672 	   } else if(strcmp(argpt, "-hfs-bless-by") == 0) {
2673 	     ret= Xorriso_hfsplus_bless(xorriso, argv[i + 2], NULL, argv[i + 1], 0);
2674 	     if(ret <= 0)
2675 	       goto problem_handler_boot;
2676 	
2677 	   } else if(strcmp(argpt, "-hfsplus-file-creator-type") == 0) {
2678 	     ret= Xorriso_hfsplus_file_creator_type(xorriso, argv[i + 3], NULL,
2679 	                                            argv[i + 1],  argv[i + 2], 0);
2680 	     if(ret <= 0)
2681 	       goto problem_handler_boot;
2682 	
2683 	   }
2684 	 continue; /* regular bottom of loop */
2685 	problem_handler_boot:;
2686 	   /* Problem handler */
2687 	   was_failure= 1;
2688 	   fret= Xorriso_eval_problem_status(xorriso, ret, 1|2);
2689 	   if(fret>=0)
2690 	 continue;
2691 	   goto ex;
2692 	 }
2693 	 if(with_boot_image && with_cat_path == 0)
2694 	   strcpy(xorriso->boot_image_cat_path, "/boot.catalog");
2695 	 /* The boot catalog has to be hidden separately */
2696 	 if(xorriso->boot_image_cat_path[0]) {
2697 	   ret= Xorriso_path_is_hidden(xorriso, xorriso->boot_image_cat_path, 0);
2698 	   if(ret > 0)
2699 	     xorriso->boot_image_cat_hidden|= ret;
2700 	   else if(ret < 0)
2701 	     was_failure= 1;
2702 	 }
2703 	
2704 	 /* Enforce the -boot-load-size default of mkisofs */
2705 	 if(with_boot_image && xorriso->boot_img_size_default &&
2706 	    xorriso->boot_image_emul == 0)
2707 	   xorriso->boot_img_full_size= 1;
2708 	
2709 	 if(xorriso->no_emul_toc & 1)
2710 	   xorriso->do_padding_by_libisofs= 1;
2711 	
2712 	 if(do_print_size) {
2713 	   ret= Xorriso_option_print_size(xorriso, 1);
2714 	   goto ex;
2715 	 }
2716 	
2717 	 ret= !was_failure;
2718 	ex:;
2719 	 if(was_path && (!do_print_size) && !old_root[0])
2720 	   Xorriso_pacifier_callback(xorriso, "files added", xorriso->pacifier_count,
2721 	                             xorriso->pacifier_total, "", 1);
2722 	 if(do_print_size && Xorriso_change_is_pending(xorriso, 1))
2723 	   xorriso->volset_change_pending= 2;
2724 	 if(weight_list != NULL)
2725 	   free(weight_list);
2726 	 if(delay_opt_list != NULL)
2727 	   free(delay_opt_list);
2728 	 Xorriso_free_meM(sort_file);
2729 	 Xorriso_free_meM(sfe);
2730 	 Xorriso_free_meM(adr);
2731 	 Xorriso_free_meM(pathspec);
2732 	 Xorriso_free_meM(eff_path);
2733 	 Xorriso_free_meM(indev);
2734 	 Xorriso_free_meM(old_root);
2735 	 return(ret);
2736 	}
2737 	
2738 	
2739 	int Xorriso_as_genisofs(struct XorrisO *xorriso, int argc, char **argv,
2740 	                      int *idx, int flag)
2741 	{
2742 	 int end_idx, ret, old_idx;
2743 	
2744 	 old_idx= *idx;
2745 	 end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 1);
2746 	 (*idx)= end_idx;
2747 	 if(end_idx<=0 || old_idx>=argc)
2748 	   return(1);
2749 	 ret= Xorriso_genisofs(xorriso, "genisofs", end_idx-old_idx, argv+old_idx, 0);
2750 	 return(ret);
2751 	}
2752 	
2753 	
2754 	int Xorriso_as_cdrskin(struct XorrisO *xorriso, int argc, char **argv,
2755 	                      int *idx, int flag)
2756 	{
2757 	 int end_idx, ret, old_idx;
2758 	
2759 	 old_idx= *idx;
2760 	 end_idx= Xorriso_end_idx(xorriso, argc, argv, *idx, 1);
2761 	 (*idx)= end_idx;
2762 	 if(end_idx<=0 || old_idx>=argc)
2763 	   return(1);
2764 	 ret= Xorriso_cdrskin(xorriso, "cdrskin", end_idx-old_idx, argv+old_idx, 0);
2765 	 return(ret);
2766 	}
2767 	
2768 	



















































reply via email to

[Prev in Thread] Current Thread [Next in Thread]