2007-10-14 12:20:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Adapter to libisoburn, libisofs and libburn for xorriso,
|
|
|
|
a command line oriented batch and dialog tool which creates, loads,
|
|
|
|
manipulates and burns ISO 9660 filesystem images.
|
|
|
|
|
2008-01-01 12:32:23 +00:00
|
|
|
Copyright 2007-2008 Thomas Schmitt, <scdbackup@gmx.net>
|
2007-10-14 12:20:56 +00:00
|
|
|
|
|
|
|
Provided under GPL version 2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
2007-10-15 15:27:51 +00:00
|
|
|
#include <sys/stat.h>
|
2007-10-22 21:18:13 +00:00
|
|
|
#include <time.h>
|
2007-10-14 12:20:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
2008-01-26 00:26:57 +00:00
|
|
|
#ifndef Xorriso_standalonE
|
2007-10-14 12:20:56 +00:00
|
|
|
|
|
|
|
/* The library which does the ISO 9660 / RockRidge manipulations */
|
|
|
|
#include <libisofs/libisofs.h>
|
|
|
|
|
|
|
|
/* The library which does MMC optical drive operations */
|
|
|
|
#include <libburn/libburn.h>
|
|
|
|
|
|
|
|
/* The library which enhances overwriteable media with ISO 9660 multi-session
|
|
|
|
capabilities via the method invented by Andy Polyakov for growisofs */
|
|
|
|
#include <libisoburn/libisoburn.h>
|
|
|
|
|
2007-10-16 21:09:36 +00:00
|
|
|
/* The official xorriso options API. "No shortcuts" */
|
|
|
|
#include "xorriso.h"
|
|
|
|
|
2007-10-14 12:20:56 +00:00
|
|
|
/* The inner description of XorrisO */
|
|
|
|
#include "xorriso_private.h"
|
|
|
|
|
|
|
|
/* The inner isofs- and burn-library interface */
|
|
|
|
#include "xorrisoburn.h"
|
|
|
|
|
2008-01-26 00:26:57 +00:00
|
|
|
#else /* ! Xorriso_standalonE */
|
|
|
|
|
|
|
|
#include "../libisofs/libisofs.h"
|
|
|
|
#include "../libburn/libburn.h"
|
|
|
|
#include "../libisoburn/libisoburn.h"
|
|
|
|
#include "xorriso.h"
|
|
|
|
#include "xorriso_private.h"
|
|
|
|
#include "xorrisoburn.h"
|
|
|
|
|
|
|
|
#endif /* Xorriso_standalonE */
|
|
|
|
|
2007-10-14 12:20:56 +00:00
|
|
|
|
2007-11-07 12:37:19 +00:00
|
|
|
int Xorriso_pacifier_loop(struct XorrisO *xorriso, struct burn_drive *drive,
|
|
|
|
int flag);
|
|
|
|
|
2008-01-26 00:26:57 +00:00
|
|
|
#define LIBISO_ISDIR(node) (iso_node_get_type(node) == LIBISO_DIR)
|
|
|
|
#define LIBISO_ISREG(node) (iso_node_get_type(node) == LIBISO_FILE)
|
|
|
|
#define LIBISO_ISLNK(node) (iso_node_get_type(node) == LIBISO_SYMLINK)
|
|
|
|
#define LIBISO_ISCHR(node) (iso_node_get_type(node) == LIBISO_SPECIAL && \
|
|
|
|
S_ISCHR(iso_node_get_mode(node)))
|
|
|
|
#define LIBISO_ISBLK(node) (iso_node_get_type(node) == LIBISO_SPECIAL && \
|
|
|
|
S_ISBLK(iso_node_get_mode(node)))
|
|
|
|
#define LIBISO_ISFIFO(node) (iso_node_get_type(node) == LIBISO_SPECIAL && \
|
|
|
|
S_ISFIFO(iso_node_get_mode(node)))
|
|
|
|
#define LIBISO_ISSOCK(node) (iso_node_get_type(node) == LIBISO_SPECIAL && \
|
|
|
|
S_ISSOCK(iso_node_get_mode(node)))
|
|
|
|
|
2007-11-07 12:37:19 +00:00
|
|
|
|
2008-02-02 18:13:03 +00:00
|
|
|
#define Xorriso_min_track_sizE 300
|
|
|
|
|
|
|
|
|
2007-10-14 12:20:56 +00:00
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
|
|
|
|
|
|
|
int Xorriso_startup_libraries(struct XorrisO *xorriso, int flag)
|
|
|
|
{
|
2008-01-29 18:44:54 +00:00
|
|
|
int ret, major, minor, micro;
|
2007-10-14 12:20:56 +00:00
|
|
|
char *handler_prefix= NULL;
|
2008-01-26 11:36:58 +00:00
|
|
|
char *queue_sev, *print_sev, reason[1024];
|
2007-10-14 12:20:56 +00:00
|
|
|
|
2008-02-02 18:13:03 +00:00
|
|
|
|
|
|
|
/* First an ugly compile time check for header version compatibility.
|
|
|
|
If everthing matches, then no C code is produced. In case of mismatch,
|
|
|
|
intentionally faulty C code will be inserted.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* The minimum requirement of xorriso towards the libisoburn header
|
|
|
|
at compile time is defined in xorriso/xorrisoburn.h
|
|
|
|
xorriso_libisoburn_req_major
|
|
|
|
xorriso_libisoburn_req_minor
|
|
|
|
xorriso_libisoburn_req_micro
|
|
|
|
It gets compared against the version macros in libburn/libburn.h :
|
|
|
|
isoburn_header_version_major
|
|
|
|
isoburn_header_version_minor
|
|
|
|
isoburn_header_version_micro
|
|
|
|
If the header is too old then the following code shall cause failure of
|
|
|
|
cdrskin compilation rather than to allow production of a program with
|
|
|
|
unpredictable bugs or memory corruption.
|
|
|
|
The compiler messages supposed to appear in this case are:
|
|
|
|
error: 'LIBISOBURN_MISCONFIGURATION' undeclared (first use in this function)
|
|
|
|
error: 'INTENTIONAL_ABORT_OF_COMPILATION__HEADERFILE_libisoburn_dot_h_TOO_OLD__SEE_xorrisoburn_dot_c' undeclared (first use in this function)
|
|
|
|
error: 'LIBISOBURN_MISCONFIGURATION_' undeclared (first use in this function)
|
|
|
|
*/
|
|
|
|
/* The indendation is an advise of man gcc to help old compilers ignoring */
|
|
|
|
#if xorriso_libisoburn_req_major > isoburn_header_version_major
|
|
|
|
#define Isoburn_libisoburn_dot_h_too_olD 1
|
|
|
|
#endif
|
|
|
|
#if xorriso_libisoburn_req_major == isoburn_header_version_major && xorriso_libisoburn_req_minor > isoburn_header_version_minor
|
|
|
|
#define Isoburn_libisoburn_dot_h_too_olD 1
|
|
|
|
#endif
|
|
|
|
#if xorriso_libisoburn_req_minor == isoburn_header_version_minor && xorriso_libisoburn_req_micro > isoburn_header_version_micro
|
|
|
|
#define Isoburn_libisoburn_dot_h_too_olD 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef Isoburn_libisoburn_dot_h_too_olD
|
|
|
|
LIBISOBURN_MISCONFIGURATION = 0;
|
|
|
|
INTENTIONAL_ABORT_OF_COMPILATION__HEADERFILE_libisoburn_dot_h_TOO_OLD__SEE_xorrisoburn_dot_c = 0;
|
|
|
|
LIBISOBURN_MISCONFIGURATION_ = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* End of ugly compile time test (scroll up for explanation) */
|
|
|
|
|
|
|
|
|
2007-10-16 21:09:36 +00:00
|
|
|
sprintf(xorriso->info_text, "Starting up libraries ...\n");
|
|
|
|
Xorriso_info(xorriso, 0);
|
2007-10-14 12:20:56 +00:00
|
|
|
|
|
|
|
handler_prefix= calloc(strlen(xorriso->progname)+3+1, 1);
|
|
|
|
if(handler_prefix==NULL) {
|
2007-10-16 21:09:36 +00:00
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Cannot allocate memory for initializing libraries");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
2007-10-14 12:20:56 +00:00
|
|
|
return(-1);
|
|
|
|
}
|
2008-01-26 11:36:58 +00:00
|
|
|
reason[0]= 0;
|
|
|
|
ret= isoburn_initialize(reason, 0);
|
2007-10-14 12:20:56 +00:00
|
|
|
if(ret==0) {
|
2007-10-16 21:09:36 +00:00
|
|
|
sprintf(xorriso->info_text, "Cannot initialize libraries");
|
2008-01-26 11:36:58 +00:00
|
|
|
if(reason[0])
|
|
|
|
sprintf(xorriso->info_text+strlen(xorriso->info_text),
|
|
|
|
". Reason given:\n%s", reason);
|
2007-10-16 21:09:36 +00:00
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
2007-10-14 12:20:56 +00:00
|
|
|
free(handler_prefix);
|
|
|
|
return(0);
|
|
|
|
}
|
2008-01-29 18:44:54 +00:00
|
|
|
ret= isoburn_is_compatible(isoburn_header_version_major,
|
|
|
|
isoburn_header_version_minor,
|
|
|
|
isoburn_header_version_micro, 0);
|
|
|
|
if(ret<=0) {
|
|
|
|
isoburn_version(&major, &minor, µ);
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"libisoburn version too old: %d.%d.%d . Need at least: %d.%d.%d .\n",
|
|
|
|
major, minor, micro,
|
|
|
|
isoburn_header_version_major, isoburn_header_version_minor,
|
|
|
|
isoburn_header_version_micro);
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
|
|
|
return(-1);
|
|
|
|
}
|
2008-01-26 11:36:58 +00:00
|
|
|
|
2007-10-18 18:57:19 +00:00
|
|
|
xorriso->libs_are_started= 1;
|
2007-10-14 12:20:56 +00:00
|
|
|
|
2007-10-17 13:02:32 +00:00
|
|
|
queue_sev= "DEBUG";
|
|
|
|
if(xorriso->library_msg_direct_print) {
|
|
|
|
|
|
|
|
/* >>> need option for controlling this in XorrisO.
|
|
|
|
See also Xorriso_msgs_submit */;
|
|
|
|
|
2007-10-19 16:49:37 +00:00
|
|
|
print_sev= xorriso->report_about_text;
|
2007-10-17 13:02:32 +00:00
|
|
|
} else
|
|
|
|
print_sev= "NEVER";
|
2008-01-26 00:26:57 +00:00
|
|
|
|
|
|
|
iso_set_msgs_severities(queue_sev, print_sev, "libsofs : ");
|
2007-10-17 13:02:32 +00:00
|
|
|
burn_msgs_set_severities(queue_sev, print_sev, "libburn : ");
|
2007-10-16 21:09:36 +00:00
|
|
|
|
|
|
|
/* ??? >>> do we want united queues ? */
|
|
|
|
/* burn_set_messenger(iso_get_messenger()); */
|
|
|
|
|
2007-10-14 12:20:56 +00:00
|
|
|
sprintf(handler_prefix, "%s : ", xorriso->progname);
|
2007-10-15 15:27:51 +00:00
|
|
|
burn_set_signal_handling(handler_prefix, NULL, 0);
|
2007-10-14 12:20:56 +00:00
|
|
|
|
2007-10-17 13:02:32 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2008-02-03 13:16:18 +00:00
|
|
|
if(reason[0]) {
|
|
|
|
sprintf(xorriso->info_text, "%s", reason);
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
|
|
|
|
}
|
|
|
|
|
2007-10-16 21:09:36 +00:00
|
|
|
sprintf(xorriso->info_text, "Library startup done.\n");
|
|
|
|
Xorriso_info(xorriso, 0);
|
2007-10-14 12:20:56 +00:00
|
|
|
free(handler_prefix);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-15 20:41:56 +00:00
|
|
|
/* @param flag bit0= global shutdown of libraries */
|
|
|
|
int Xorriso_detach_libraries(struct XorrisO *xorriso, int flag)
|
2008-01-15 17:45:08 +00:00
|
|
|
{
|
2008-01-15 20:41:56 +00:00
|
|
|
Xorriso_give_up_drive(xorriso, 3);
|
2008-01-26 00:26:57 +00:00
|
|
|
if(xorriso->in_volset_handle!=NULL) { /* standalone image */
|
|
|
|
iso_image_unref((IsoImage *) xorriso->in_volset_handle);
|
|
|
|
xorriso->in_volset_handle= NULL;
|
|
|
|
}
|
2008-01-15 20:41:56 +00:00
|
|
|
if(flag&1) {
|
|
|
|
if(xorriso->libs_are_started==0)
|
|
|
|
return(0);
|
|
|
|
isoburn_finish();
|
|
|
|
}
|
2008-01-15 17:45:08 +00:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-18 18:32:32 +00:00
|
|
|
/* @param flag bit1= obtain outdrive, else indrive */
|
|
|
|
int Xorriso_get_drive_handles(struct XorrisO *xorriso,
|
|
|
|
struct burn_drive_info **dinfo,
|
|
|
|
struct burn_drive **drive,
|
|
|
|
char *attempt, int flag)
|
|
|
|
{
|
|
|
|
if(flag&2)
|
|
|
|
*dinfo= (struct burn_drive_info *) xorriso->out_drive_handle;
|
|
|
|
else
|
|
|
|
*dinfo= (struct burn_drive_info *) xorriso->in_drive_handle;
|
|
|
|
if(*dinfo==NULL) {
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-11-14 14:28:44 +00:00
|
|
|
sprintf(xorriso->info_text, "No %s drive aquired %s",
|
|
|
|
(flag&2 ? "output" : "input"), attempt);
|
2007-10-18 18:32:32 +00:00
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
*drive= (*dinfo)[0].drive;
|
2007-10-19 17:35:20 +00:00
|
|
|
return((*drive)!=NULL);
|
2007-10-18 18:32:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-03 13:16:18 +00:00
|
|
|
/* <<< to be replaced by libburn-0.4.3 API call burn_sev_to_text().
|
|
|
|
This is a copy of libdax_msgs__sev_to_text() which is not exposed
|
|
|
|
by the API of of libburn-0.4.2 . As soon as xorriso gets based on
|
|
|
|
libburn-0.4.4 this redundancy is to be removed.
|
|
|
|
It is safe, nevertheless, because the severity codes are eternal.
|
|
|
|
*/
|
|
|
|
#define LIBDAX_MSGS_SEV_ALL 0x00000000
|
|
|
|
#define LIBDAX_MSGS_SEV_DEBUG 0x10000000
|
|
|
|
#define LIBDAX_MSGS_SEV_UPDATE 0x20000000
|
|
|
|
#define LIBDAX_MSGS_SEV_NOTE 0x30000000
|
|
|
|
#define LIBDAX_MSGS_SEV_HINT 0x40000000
|
|
|
|
#define LIBDAX_MSGS_SEV_WARNING 0x50000000
|
|
|
|
#define LIBDAX_MSGS_SEV_SORRY 0x60000000
|
|
|
|
#define LIBDAX_MSGS_SEV_FAILURE 0x68000000
|
|
|
|
#define LIBDAX_MSGS_SEV_FATAL 0x70000000
|
|
|
|
#define LIBDAX_MSGS_SEV_ABORT 0x71000000
|
|
|
|
#define LIBDAX_MSGS_SEV_NEVER 0x7fffffff
|
|
|
|
|
|
|
|
int Xorriso__sev_to_text(int severity, char **severity_name,
|
|
|
|
int flag)
|
|
|
|
{
|
|
|
|
if(flag&1) {
|
|
|
|
*severity_name= "NEVER\nABORT\nFATAL\nFAILURE\nSORRY\nWARNING\nHINT\nNOTE\nUPDATE\nDEBUG\nALL";
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
*severity_name= "";
|
|
|
|
if(severity>=LIBDAX_MSGS_SEV_NEVER)
|
|
|
|
*severity_name= "NEVER";
|
|
|
|
else if(severity>=LIBDAX_MSGS_SEV_ABORT)
|
|
|
|
*severity_name= "ABORT";
|
|
|
|
else if(severity>=LIBDAX_MSGS_SEV_FATAL)
|
|
|
|
*severity_name= "FATAL";
|
|
|
|
else if(severity>=LIBDAX_MSGS_SEV_FAILURE)
|
|
|
|
*severity_name= "FAILURE";
|
|
|
|
else if(severity>=LIBDAX_MSGS_SEV_SORRY)
|
|
|
|
*severity_name= "SORRY";
|
|
|
|
else if(severity>=LIBDAX_MSGS_SEV_WARNING)
|
|
|
|
*severity_name= "WARNING";
|
|
|
|
else if(severity>=LIBDAX_MSGS_SEV_HINT)
|
|
|
|
*severity_name= "HINT";
|
|
|
|
else if(severity>=LIBDAX_MSGS_SEV_NOTE)
|
|
|
|
*severity_name= "NOTE";
|
|
|
|
else if(severity>=LIBDAX_MSGS_SEV_UPDATE)
|
|
|
|
*severity_name= "UPDATE";
|
|
|
|
else if(severity>=LIBDAX_MSGS_SEV_DEBUG)
|
|
|
|
*severity_name= "DEBUG";
|
|
|
|
else if(severity>=LIBDAX_MSGS_SEV_ALL)
|
|
|
|
*severity_name= "ALL";
|
|
|
|
else {
|
|
|
|
*severity_name= "";
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* @param flag bit0=report libisofs error text */
|
|
|
|
int Xorriso_report_iso_error(struct XorrisO *xorriso,
|
|
|
|
int iso_error_code, char msg_text[], int os_errno,
|
|
|
|
char min_severity[], int flag)
|
|
|
|
{
|
|
|
|
int error_code, iso_sev, min_sev, ret;
|
|
|
|
char *sev_text_pt, *msg_text_pt= NULL;
|
|
|
|
|
|
|
|
error_code= 0x00050000 | ISO_ERR_CODE(iso_error_code);
|
|
|
|
if(flag&1)
|
|
|
|
msg_text_pt= (char *) iso_error_to_msg(iso_error_code);
|
|
|
|
if(msg_text_pt==NULL)
|
|
|
|
msg_text_pt= msg_text;
|
|
|
|
iso_sev= ISO_ERR_SEV(iso_error_code);
|
|
|
|
sev_text_pt= min_severity;
|
|
|
|
burn_text_to_sev(min_severity, &min_sev, 0);
|
|
|
|
if(min_sev < iso_sev)
|
|
|
|
/* >>> with libburn-0.4.4 do: burn_sev_to_text(iso_sev, &sev_text_pt, 0); */
|
|
|
|
Xorriso__sev_to_text(iso_sev, &sev_text_pt, 0);
|
|
|
|
ret= Xorriso_msgs_submit(xorriso, error_code, msg_text_pt,
|
|
|
|
os_errno, sev_text_pt, 0);
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-26 00:26:57 +00:00
|
|
|
/* @param flag bit0= suppress DEBUG messages */
|
|
|
|
int Xorriso_set_image_severities(struct XorrisO *xorriso, int flag)
|
|
|
|
{
|
|
|
|
char *queue_sev, *print_sev;
|
|
|
|
|
|
|
|
if(flag&1)
|
|
|
|
queue_sev= "UPDATE";
|
|
|
|
else
|
|
|
|
queue_sev= "DEBUG";
|
|
|
|
if(xorriso->library_msg_direct_print)
|
|
|
|
print_sev= xorriso->report_about_text;
|
|
|
|
else
|
|
|
|
print_sev= "NEVER";
|
|
|
|
iso_set_msgs_severities(queue_sev, print_sev, "libisofs : ");
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Xorriso_update_volid(struct XorrisO *xorriso, int flag)
|
|
|
|
{
|
|
|
|
int gret, sret= 1;
|
|
|
|
|
|
|
|
gret= Xorriso_get_volid(xorriso, xorriso->loaded_volid, 0);
|
|
|
|
if(gret>0 && strcmp(xorriso->volid, "ISOIMAGE")==0)
|
|
|
|
strcpy(xorriso->volid, xorriso->loaded_volid);
|
|
|
|
else
|
|
|
|
sret= Xorriso_set_volid(xorriso, xorriso->volid, 1);
|
|
|
|
return(gret>0 && sret>0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-14 14:28:44 +00:00
|
|
|
int Xorriso_create_empty_iso(struct XorrisO *xorriso, int flag)
|
|
|
|
{
|
|
|
|
int ret;
|
2008-01-26 00:26:57 +00:00
|
|
|
IsoImage *volset;
|
2008-01-29 13:00:46 +00:00
|
|
|
struct isoburn_read_opts *ropts;
|
2007-11-14 14:28:44 +00:00
|
|
|
struct burn_drive_info *dinfo= NULL;
|
|
|
|
struct burn_drive *drive= NULL;
|
|
|
|
|
|
|
|
if(xorriso->out_drive_handle != NULL) {
|
|
|
|
ret= Xorriso_get_drive_handles(xorriso, &dinfo, &drive,
|
|
|
|
"on attempt to attach volset to drive", 2);
|
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
if(xorriso->in_volset_handle!=NULL) {
|
2008-01-26 00:26:57 +00:00
|
|
|
iso_image_unref((IsoImage *) xorriso->in_volset_handle);
|
2007-11-14 14:28:44 +00:00
|
|
|
xorriso->in_volset_handle= NULL;
|
2008-01-26 00:26:57 +00:00
|
|
|
xorriso->loaded_volid[0]= 0;
|
2007-11-14 14:28:44 +00:00
|
|
|
xorriso->volset_change_pending= 0;
|
|
|
|
}
|
2008-01-29 13:00:46 +00:00
|
|
|
|
|
|
|
ret= isoburn_ropt_new(&ropts, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
|
|
|
/* Note: no return before isoburn_ropt_destroy() */
|
|
|
|
isoburn_ropt_set_extensions(ropts, isoburn_ropt_pretend_blank);
|
|
|
|
isoburn_ropt_set_input_charset(ropts, NULL);
|
|
|
|
ret= isoburn_read_image(drive, ropts, &volset);
|
2007-11-14 14:28:44 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2008-01-29 13:00:46 +00:00
|
|
|
isoburn_ropt_destroy(&ropts, 0);
|
2007-11-14 14:28:44 +00:00
|
|
|
if(ret<=0) {
|
|
|
|
sprintf(xorriso->info_text, "Failed to create new empty ISO image object");
|
2008-02-03 13:16:18 +00:00
|
|
|
Xorriso_report_iso_error(xorriso, ret, xorriso->info_text, 0, "FATAL", 0);
|
2007-11-14 14:28:44 +00:00
|
|
|
return(-1);
|
|
|
|
}
|
2008-01-26 00:26:57 +00:00
|
|
|
xorriso->in_volset_handle= (void *) volset;
|
|
|
|
Xorriso_update_volid(xorriso, 0);
|
2007-11-14 14:28:44 +00:00
|
|
|
xorriso->volset_change_pending= 0;
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-15 15:27:51 +00:00
|
|
|
/* @param flag bit0=aquire as isoburn input drive
|
|
|
|
bit1=aquire as libburn output drive (as isoburn drive if bit0)
|
2007-11-14 14:28:44 +00:00
|
|
|
@return <=0 failure , 1= ok
|
|
|
|
2=success, but not writeable with bit1
|
|
|
|
3=success, but not blank and not ISO with bit0
|
2007-10-15 15:27:51 +00:00
|
|
|
*/
|
|
|
|
int Xorriso_aquire_drive(struct XorrisO *xorriso, char *adr, int flag)
|
|
|
|
{
|
2007-11-14 14:28:44 +00:00
|
|
|
int ret, hret, not_writeable= 0;
|
|
|
|
struct burn_drive_info *dinfo= NULL, *out_dinfo, *in_dinfo;
|
|
|
|
struct burn_drive *drive, *out_drive, *in_drive;
|
2007-10-15 15:27:51 +00:00
|
|
|
enum burn_disc_status state;
|
2008-01-26 00:26:57 +00:00
|
|
|
IsoImage *volset = NULL;
|
2008-01-29 13:00:46 +00:00
|
|
|
struct isoburn_read_opts *ropts= NULL;
|
2008-01-26 00:26:57 +00:00
|
|
|
char adr_data[SfileadrL], *libburn_adr;
|
2007-10-15 15:27:51 +00:00
|
|
|
|
2007-11-14 14:28:44 +00:00
|
|
|
if((flag&3)==0) {
|
2007-10-16 21:09:36 +00:00
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"XORRISOBURN program error : Xorriso_aquire_drive bit0+bit1 not set");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
2007-10-15 15:27:51 +00:00
|
|
|
return(0);
|
|
|
|
}
|
2007-11-14 14:28:44 +00:00
|
|
|
ret= Xorriso_give_up_drive(xorriso, (flag&3)|8);
|
2007-10-15 15:27:51 +00:00
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
|
|
|
|
2008-01-26 00:26:57 +00:00
|
|
|
libburn_adr= adr;
|
|
|
|
if(strcmp(adr,"stdio:/dev/fd/1")==0) {
|
|
|
|
if(xorriso->dev_fd_1<0) {
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"\"stdio:/dev/fd/1\" was not a start argument. stdout possibly already tainted.");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
{ret= 0; goto ex;}
|
|
|
|
} else {
|
|
|
|
sprintf(adr_data, "stdio:/dev/fd/%d", xorriso->dev_fd_1);
|
|
|
|
libburn_adr= adr_data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-14 14:28:44 +00:00
|
|
|
if((flag&3)==1 && xorriso->out_drive_handle!=NULL) {
|
|
|
|
ret= Xorriso_get_drive_handles(xorriso, &out_dinfo, &out_drive,
|
|
|
|
"on attempt to compare new indev with outdev", 2);
|
|
|
|
if(ret<=0)
|
|
|
|
goto ex;
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= burn_drive_equals_adr(out_drive, libburn_adr, 1);
|
2007-11-14 14:28:44 +00:00
|
|
|
if(ret==1)
|
|
|
|
dinfo= out_dinfo;
|
|
|
|
} else if((flag&3)==2 && xorriso->in_drive_handle!=NULL) {
|
|
|
|
ret= Xorriso_get_drive_handles(xorriso, &in_dinfo, &in_drive,
|
|
|
|
"on attempt to compare new indev with outdev", 0);
|
|
|
|
if(ret<=0)
|
|
|
|
goto ex;
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= burn_drive_equals_adr(in_drive, libburn_adr, 1);
|
2007-11-14 14:28:44 +00:00
|
|
|
if(ret==1)
|
|
|
|
dinfo= in_dinfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(dinfo==NULL) {
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= isoburn_drive_scan_and_grab(&dinfo, libburn_adr, 1);
|
2007-11-14 14:28:44 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
if(ret<=0) {
|
|
|
|
sprintf(xorriso->info_text,"Cannot aquire drive '%s'", adr);
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
return(0);
|
|
|
|
}
|
2007-10-15 15:27:51 +00:00
|
|
|
}
|
2007-11-14 14:28:44 +00:00
|
|
|
drive= dinfo[0].drive;
|
|
|
|
state= isoburn_disc_get_status(drive);
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2008-01-26 00:26:57 +00:00
|
|
|
if(flag&1) {
|
|
|
|
volset= isoburn_get_attached_image(drive);
|
|
|
|
if(volset != NULL) { /* The image object is already created */
|
|
|
|
iso_image_unref(volset);
|
|
|
|
}
|
|
|
|
}
|
2007-11-14 14:28:44 +00:00
|
|
|
|
2007-10-19 20:41:34 +00:00
|
|
|
if(flag&2) {
|
2007-10-15 15:27:51 +00:00
|
|
|
xorriso->out_drive_handle= dinfo;
|
2007-11-14 14:28:44 +00:00
|
|
|
if(Sfile_str(xorriso->outdev, adr, 0)<=0)
|
2007-10-19 20:41:34 +00:00
|
|
|
return(-1);
|
2007-11-14 14:28:44 +00:00
|
|
|
if(state != BURN_DISC_BLANK && state != BURN_DISC_APPENDABLE) {
|
|
|
|
sprintf(xorriso->info_text, "Disc status unsuitable for writing");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0);
|
|
|
|
not_writeable= 1;
|
|
|
|
}
|
2007-10-19 20:41:34 +00:00
|
|
|
}
|
|
|
|
if(flag&1) {
|
2007-10-15 15:27:51 +00:00
|
|
|
xorriso->in_drive_handle= dinfo;
|
2007-11-14 14:28:44 +00:00
|
|
|
if(Sfile_str(xorriso->indev, adr, 0)<=0)
|
2007-10-19 20:41:34 +00:00
|
|
|
return(-1);
|
2007-11-14 14:28:44 +00:00
|
|
|
} else if(flag&2) {
|
|
|
|
if(xorriso->in_volset_handle==NULL) {
|
|
|
|
/* No volume loaded: create empty one */
|
|
|
|
ret= Xorriso_create_empty_iso(xorriso, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
|
|
|
} else {
|
2008-01-26 00:26:57 +00:00
|
|
|
iso_image_ref((IsoImage *) xorriso->in_volset_handle);
|
|
|
|
ret= isoburn_attach_image(drive, (IsoImage *) xorriso->in_volset_handle);
|
2007-11-14 14:28:44 +00:00
|
|
|
if(ret<=0) {
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Failed to attach ISO image object to outdev");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Xorriso_toc(xorriso, 1|2);
|
|
|
|
return(1+not_writeable);
|
|
|
|
}
|
2007-10-15 15:27:51 +00:00
|
|
|
|
2007-11-14 14:28:44 +00:00
|
|
|
if(xorriso->in_volset_handle!=NULL)
|
2008-01-26 00:26:57 +00:00
|
|
|
iso_image_unref((IsoImage *) xorriso->in_volset_handle);
|
2007-11-14 14:28:44 +00:00
|
|
|
xorriso->in_volset_handle= NULL;
|
2007-10-15 15:27:51 +00:00
|
|
|
|
|
|
|
/* check for invalid state */
|
2007-11-14 14:28:44 +00:00
|
|
|
if(state != BURN_DISC_BLANK && state != BURN_DISC_APPENDABLE &&
|
|
|
|
state != BURN_DISC_FULL) {
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Disc status not blank and unsuitable for reading");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
return(0);
|
2007-10-15 15:27:51 +00:00
|
|
|
}
|
|
|
|
/* fill read opts */
|
2008-01-29 13:00:46 +00:00
|
|
|
ret= isoburn_ropt_new(&ropts, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
|
|
|
isoburn_ropt_set_extensions(ropts, isoburn_ropt_noiso1999);
|
|
|
|
isoburn_ropt_set_default_perms(ropts, (uid_t) 0, (gid_t) 0, (mode_t) 0555);
|
|
|
|
isoburn_ropt_set_input_charset(ropts, NULL);
|
|
|
|
|
|
|
|
#ifdef NIX
|
2007-11-14 14:28:44 +00:00
|
|
|
memset(&ropts, sizeof(ropts), 0);
|
2007-10-15 15:27:51 +00:00
|
|
|
ropts.norock= 0;
|
|
|
|
ropts.nojoliet= 0;
|
2008-01-26 00:26:57 +00:00
|
|
|
ropts.noiso1999= 1;
|
2007-10-15 15:27:51 +00:00
|
|
|
ropts.preferjoliet= 0;
|
|
|
|
ropts.uid= 0;
|
|
|
|
ropts.gid= 0;
|
|
|
|
ropts.mode= 0555;
|
2008-01-26 00:26:57 +00:00
|
|
|
ropts.input_charset= NULL;
|
2007-11-14 14:28:44 +00:00
|
|
|
ropts.pretend_blank= 0;
|
2008-01-29 13:00:46 +00:00
|
|
|
#endif /* NIX */
|
2007-10-15 15:27:51 +00:00
|
|
|
|
2008-01-26 00:26:57 +00:00
|
|
|
Xorriso_set_image_severities(xorriso, 1); /* No DEBUG messages */
|
2008-01-29 13:00:46 +00:00
|
|
|
if(isoburn_read_image(drive, ropts, &volset) <= 0) {
|
2007-10-17 13:02:32 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2008-01-26 00:26:57 +00:00
|
|
|
Xorriso_set_image_severities(xorriso, 0);
|
2007-10-17 20:02:45 +00:00
|
|
|
sprintf(xorriso->info_text,"Cannot read ISO image volset");
|
2007-10-16 21:09:36 +00:00
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
2007-11-14 14:28:44 +00:00
|
|
|
ret= 3; goto ex;
|
2007-10-15 15:27:51 +00:00
|
|
|
}
|
2008-01-26 00:26:57 +00:00
|
|
|
xorriso->in_volset_handle= (void *) volset;
|
|
|
|
Xorriso_set_image_severities(xorriso, 0);
|
|
|
|
Xorriso_update_volid(xorriso, 0);
|
|
|
|
|
2007-11-14 14:28:44 +00:00
|
|
|
if(xorriso->out_drive_handle != NULL &&
|
|
|
|
xorriso->out_drive_handle != xorriso->in_drive_handle) {
|
|
|
|
ret= Xorriso_get_drive_handles(xorriso, &out_dinfo, &out_drive,
|
|
|
|
"on attempt to attach ISO image volset to outdev", 2);
|
|
|
|
if(ret<=0)
|
|
|
|
goto ex;
|
2008-01-26 00:26:57 +00:00
|
|
|
iso_image_ref((IsoImage *) xorriso->in_volset_handle);
|
|
|
|
isoburn_attach_image(out_drive, xorriso->in_volset_handle);
|
2007-11-14 14:28:44 +00:00
|
|
|
}
|
2007-11-02 14:36:26 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
Xorriso_toc(xorriso, 1);
|
2008-01-26 00:26:57 +00:00
|
|
|
if(xorriso->loaded_volid[0]!=0) {
|
|
|
|
sprintf(xorriso->result_line,"Volume id : '%s'\n",xorriso->loaded_volid);
|
|
|
|
Xorriso_result(xorriso,0);
|
|
|
|
if(strcmp(xorriso->loaded_volid, xorriso->volid)!=0) {
|
|
|
|
sprintf(xorriso->result_line, "New volume id: '%s'\n", xorriso->volid);
|
|
|
|
Xorriso_result(xorriso,0);
|
|
|
|
}
|
|
|
|
}
|
2007-11-14 14:28:44 +00:00
|
|
|
ret= 1+not_writeable;
|
2007-10-15 15:27:51 +00:00
|
|
|
ex:
|
2008-01-29 13:00:46 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-11-14 14:28:44 +00:00
|
|
|
if(ret<=0) {
|
|
|
|
hret= Xorriso_give_up_drive(xorriso, flag&3);
|
|
|
|
if(hret<ret)
|
|
|
|
ret= hret;
|
2007-10-15 15:27:51 +00:00
|
|
|
}
|
2008-01-29 13:00:46 +00:00
|
|
|
isoburn_ropt_destroy(&ropts, 0);
|
2007-10-15 15:27:51 +00:00
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* @param flag bit0=input drive
|
|
|
|
bit1=output drive
|
2007-10-19 17:35:20 +00:00
|
|
|
bit2=eject
|
2007-11-14 14:28:44 +00:00
|
|
|
bit3=no info message or toc
|
2007-10-15 15:27:51 +00:00
|
|
|
*/
|
|
|
|
int Xorriso_give_up_drive(struct XorrisO *xorriso, int flag)
|
|
|
|
{
|
2007-11-14 14:28:44 +00:00
|
|
|
int in_is_out_too, ret;
|
2007-10-15 15:27:51 +00:00
|
|
|
struct burn_drive_info *dinfo;
|
|
|
|
struct burn_drive *drive;
|
2008-01-26 00:26:57 +00:00
|
|
|
char sfe[5*SfileadrL];
|
2007-10-15 15:27:51 +00:00
|
|
|
|
|
|
|
in_is_out_too= (xorriso->in_drive_handle == xorriso->out_drive_handle);
|
2008-01-26 00:26:57 +00:00
|
|
|
if((flag&4) && in_is_out_too && (flag&(1|2))) {
|
|
|
|
if((flag&3)!=3) {
|
|
|
|
sprintf(xorriso->info_text,"Giving up for -eject whole -dev %s",
|
|
|
|
Text_shellsafe(xorriso->indev, sfe, 0));
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
|
|
|
|
}
|
|
|
|
flag|= 3; /* give up in/out drive to eject it */
|
|
|
|
}
|
2007-10-15 15:27:51 +00:00
|
|
|
|
|
|
|
if((flag&1) && xorriso->in_drive_handle != NULL) {
|
2007-10-18 18:32:32 +00:00
|
|
|
Xorriso_get_drive_handles(xorriso, &dinfo, &drive,
|
2007-11-14 14:28:44 +00:00
|
|
|
"on attempt to give up drive", 0);
|
|
|
|
|
|
|
|
if(!in_is_out_too) {
|
|
|
|
if(drive!=NULL && !in_is_out_too)
|
|
|
|
isoburn_drive_release(drive,!!(flag&4));
|
|
|
|
if(dinfo!=NULL && !in_is_out_too)
|
|
|
|
burn_drive_info_free(dinfo);
|
|
|
|
}
|
|
|
|
xorriso->in_drive_handle= NULL;
|
|
|
|
xorriso->indev[0]= 0;
|
2007-10-15 15:27:51 +00:00
|
|
|
|
2007-10-18 22:56:43 +00:00
|
|
|
if(xorriso->in_volset_handle!=NULL)
|
2008-01-26 00:26:57 +00:00
|
|
|
iso_image_unref((IsoImage *) xorriso->in_volset_handle);
|
2007-10-18 14:48:35 +00:00
|
|
|
xorriso->in_volset_handle= NULL;
|
2008-01-26 00:26:57 +00:00
|
|
|
xorriso->loaded_volid[0]= 0;
|
2007-10-15 22:40:39 +00:00
|
|
|
xorriso->volset_change_pending= 0;
|
2007-10-15 15:27:51 +00:00
|
|
|
|
2007-11-14 14:28:44 +00:00
|
|
|
in_is_out_too= 0;
|
2007-10-15 15:27:51 +00:00
|
|
|
}
|
|
|
|
if((flag&2) && xorriso->out_drive_handle!=NULL) {
|
2007-10-18 18:32:32 +00:00
|
|
|
Xorriso_get_drive_handles(xorriso, &dinfo, &drive,
|
2008-01-26 00:26:57 +00:00
|
|
|
"on attempt to give up drive", 2);
|
2007-11-14 14:28:44 +00:00
|
|
|
if(!in_is_out_too) {
|
|
|
|
if(drive!=NULL)
|
|
|
|
isoburn_drive_release(drive,!!(flag&4));
|
|
|
|
if(dinfo!=NULL)
|
|
|
|
burn_drive_info_free(dinfo);
|
|
|
|
}
|
2007-10-15 15:27:51 +00:00
|
|
|
xorriso->out_drive_handle= NULL;
|
2007-10-19 20:41:34 +00:00
|
|
|
xorriso->outdev[0]= 0;
|
2007-11-14 14:28:44 +00:00
|
|
|
} else if((flag&1) && xorriso->out_drive_handle!=NULL) {
|
|
|
|
ret= Xorriso_create_empty_iso(xorriso, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
|
|
|
if(!(flag&8)) {
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Only the output drive remains. Created empty ISO image.\n");
|
|
|
|
Xorriso_info(xorriso, 0);
|
|
|
|
Xorriso_toc(xorriso, 1|2);
|
|
|
|
}
|
2007-10-15 15:27:51 +00:00
|
|
|
}
|
2007-10-17 13:02:32 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-10-15 15:27:51 +00:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
2007-10-15 22:40:39 +00:00
|
|
|
|
2007-10-18 18:32:32 +00:00
|
|
|
int Xorriso_make_write_options(
|
|
|
|
struct XorrisO *xorriso, struct burn_drive *drive,
|
|
|
|
struct burn_write_opts **burn_options, int flag)
|
|
|
|
{
|
2008-01-26 00:26:57 +00:00
|
|
|
int drive_role;
|
|
|
|
|
2007-10-18 18:32:32 +00:00
|
|
|
*burn_options= burn_write_opts_new(drive);
|
|
|
|
if(*burn_options==NULL) {
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
sprintf(xorriso->info_text,"Cannot allocate option set");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
burn_write_opts_set_simulate(*burn_options, !!xorriso->do_dummy);
|
2008-01-26 00:26:57 +00:00
|
|
|
drive_role= burn_drive_get_drive_role(drive);
|
|
|
|
burn_write_opts_set_multi(*burn_options,
|
|
|
|
!(xorriso->do_close || drive_role==0 || drive_role==3));
|
2007-10-18 18:32:32 +00:00
|
|
|
burn_drive_set_speed(drive, xorriso->speed, xorriso->speed);
|
|
|
|
burn_write_opts_set_underrun_proof(*burn_options, 1);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-19 15:13:16 +00:00
|
|
|
/* @param flag bit0= do not write but only prepare and return size in sectors
|
|
|
|
*/
|
2007-11-14 14:28:44 +00:00
|
|
|
int Xorriso_write_session(struct XorrisO *xorriso, int flag)
|
2007-10-15 15:27:51 +00:00
|
|
|
{
|
2008-02-02 18:13:03 +00:00
|
|
|
int ret, media_space, img_sectors;
|
2008-01-28 23:58:12 +00:00
|
|
|
struct isoburn_imgen_opts *sopts= NULL;
|
2007-11-14 14:28:44 +00:00
|
|
|
struct burn_drive_info *dinfo, *source_dinfo;
|
|
|
|
struct burn_drive *drive, *source_drive;
|
2007-10-18 22:17:46 +00:00
|
|
|
struct burn_disc *disc= NULL;
|
2007-10-15 15:27:51 +00:00
|
|
|
struct burn_write_opts *burn_options;
|
2007-11-02 14:36:26 +00:00
|
|
|
off_t readcounter= 0,writecounter= 0;
|
|
|
|
int num_sessions= 0, num_tracks= 0;
|
|
|
|
struct burn_session **sessions;
|
|
|
|
struct burn_track **tracks;
|
2007-11-14 14:28:44 +00:00
|
|
|
enum burn_disc_status s;
|
2007-10-15 15:27:51 +00:00
|
|
|
|
2007-10-18 18:32:32 +00:00
|
|
|
ret= Xorriso_get_drive_handles(xorriso, &dinfo, &drive,
|
|
|
|
"on attempt to write", 2);
|
|
|
|
if(ret<=0)
|
2007-10-15 15:27:51 +00:00
|
|
|
return(0);
|
|
|
|
|
2008-01-28 23:58:12 +00:00
|
|
|
ret= isoburn_igopt_new(&sopts, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
|
|
|
isoburn_igopt_set_level(sopts, 2);
|
|
|
|
isoburn_igopt_set_extensions(sopts, 1|((!!xorriso->do_joliet)<<1));
|
|
|
|
isoburn_igopt_set_relaxed(sopts, isoburn_igopt_allow_deep_paths);
|
|
|
|
isoburn_igopt_set_sort_files(sopts, 1);
|
|
|
|
isoburn_igopt_set_over_mode(sopts, 0, 0, (mode_t) 0, (mode_t) 0);
|
|
|
|
isoburn_igopt_set_over_ugid(sopts, 0, 0, (uid_t) 0, (gid_t) 0);
|
|
|
|
isoburn_igopt_set_out_charset(sopts, NULL);
|
|
|
|
isoburn_igopt_set_fifo_size(sopts, xorriso->fs * 2048);
|
|
|
|
|
|
|
|
#ifdef NIX
|
2008-01-26 00:26:57 +00:00
|
|
|
memset(&sopts, 0, sizeof(sopts));
|
2007-10-15 15:27:51 +00:00
|
|
|
sopts.level= 2;
|
2008-01-26 00:26:57 +00:00
|
|
|
sopts.rockridge= 1;
|
|
|
|
sopts.joliet= !!xorriso->do_joliet;
|
|
|
|
sopts.iso1999= 0;
|
|
|
|
sopts.omit_version_numbers= 0;
|
|
|
|
sopts.allow_deep_paths= 1;
|
|
|
|
sopts.allow_longer_paths= 0;
|
|
|
|
sopts.max_37_char_filenames= 0;
|
|
|
|
sopts.no_force_dots= 0;
|
|
|
|
sopts.allow_lowercase= 0;
|
|
|
|
sopts.allow_full_ascii= 0;
|
|
|
|
sopts.joliet_longer_paths= 0;
|
2007-10-15 15:27:51 +00:00
|
|
|
sopts.sort_files= 1;
|
2008-01-26 00:26:57 +00:00
|
|
|
sopts.replace_dir_mode= 2*!!xorriso->do_global_mode;
|
2007-11-08 14:43:53 +00:00
|
|
|
sopts.dir_mode= xorriso->global_dir_mode;
|
2008-01-26 00:26:57 +00:00
|
|
|
sopts.replace_file_mode= 2*!!xorriso->do_global_mode;
|
2007-11-08 14:43:53 +00:00
|
|
|
sopts.file_mode= xorriso->global_file_mode;
|
2008-01-26 00:26:57 +00:00
|
|
|
sopts.replace_uid= 2*!!xorriso->do_global_uid;
|
2007-10-15 15:27:51 +00:00
|
|
|
sopts.uid= xorriso->global_uid;
|
2008-01-26 00:26:57 +00:00
|
|
|
sopts.replace_gid= 2*!!xorriso->do_global_gid;
|
2007-10-15 15:27:51 +00:00
|
|
|
sopts.gid= xorriso->global_gid;
|
2008-01-26 00:26:57 +00:00
|
|
|
sopts.output_charset= NULL;
|
2007-10-23 12:28:36 +00:00
|
|
|
sopts.fifo_size= xorriso->fs * 2048;
|
2008-01-28 23:58:12 +00:00
|
|
|
#endif /* NIX */
|
2007-10-15 15:27:51 +00:00
|
|
|
|
2007-11-14 14:28:44 +00:00
|
|
|
if(xorriso->out_drive_handle == xorriso->in_drive_handle ||
|
|
|
|
xorriso->in_drive_handle == NULL) {
|
2008-01-28 23:58:12 +00:00
|
|
|
ret= isoburn_prepare_disc(drive, &disc, sopts);
|
2007-11-14 14:28:44 +00:00
|
|
|
} else {
|
|
|
|
s= isoburn_disc_get_status(drive);
|
|
|
|
if(s!=BURN_DISC_BLANK) {
|
|
|
|
s= burn_disc_get_status(drive);
|
|
|
|
if(s!=BURN_DISC_BLANK)
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"-indev differs from -outdev and -outdev media is not blank");
|
|
|
|
else
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"-indev differs from -outdev and -outdev media holds valid ISO image");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
{ret= 0; goto ex;}
|
|
|
|
}
|
|
|
|
ret= Xorriso_get_drive_handles(xorriso, &source_dinfo, &source_drive,
|
|
|
|
"on attempt to get source for write", 0);
|
|
|
|
if(ret<=0)
|
|
|
|
goto ex;
|
2008-01-28 23:58:12 +00:00
|
|
|
ret= isoburn_prepare_new_image(source_drive, &disc, sopts, drive);
|
2007-11-14 14:28:44 +00:00
|
|
|
}
|
|
|
|
if (ret <= 0) {
|
2007-10-17 13:02:32 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-11-14 14:28:44 +00:00
|
|
|
sprintf(xorriso->info_text,"Failed to prepare session write run");
|
2007-10-16 21:09:36 +00:00
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
2007-10-18 22:17:46 +00:00
|
|
|
{ret= 0; goto ex;}
|
2007-10-15 15:27:51 +00:00
|
|
|
}
|
|
|
|
|
2007-10-18 18:32:32 +00:00
|
|
|
ret= Xorriso_make_write_options(xorriso, drive, &burn_options, 0);
|
|
|
|
if(ret<=0)
|
2007-10-18 22:17:46 +00:00
|
|
|
goto ex;
|
2007-10-19 15:13:16 +00:00
|
|
|
|
2008-02-02 18:13:03 +00:00
|
|
|
ret= img_sectors= burn_disc_get_sectors(disc);
|
2007-10-20 19:48:36 +00:00
|
|
|
if(flag&1)
|
|
|
|
goto ex;
|
2007-11-14 14:28:44 +00:00
|
|
|
|
2007-10-20 19:48:36 +00:00
|
|
|
media_space= burn_disc_available_space(drive, burn_options) / (off_t) 2048;
|
2008-02-02 18:13:03 +00:00
|
|
|
if(media_space < img_sectors || media_space < Xorriso_min_track_sizE) {
|
2007-10-20 19:48:36 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
sprintf(xorriso->info_text,"Image size %ds exceeds free space on media %ds",
|
2008-02-02 18:13:03 +00:00
|
|
|
(img_sectors < Xorriso_min_track_sizE ? Xorriso_min_track_sizE
|
|
|
|
: img_sectors ),
|
|
|
|
media_space);
|
2007-10-20 19:48:36 +00:00
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
{ret= 0; goto ex;}
|
|
|
|
}
|
|
|
|
|
2008-02-02 18:13:03 +00:00
|
|
|
if(img_sectors < Xorriso_min_track_sizE) {
|
|
|
|
sessions= burn_disc_get_sessions(disc, &num_sessions);
|
|
|
|
if(sessions==NULL || num_sessions < 1) {
|
|
|
|
no_track:;
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
sprintf(xorriso->info_text,"Program error : no track in prepared disc");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
|
|
|
{ret= -1; goto ex;}
|
|
|
|
}
|
|
|
|
tracks= burn_session_get_tracks(sessions[0], &num_tracks);
|
|
|
|
if(tracks==NULL || num_tracks < 1)
|
|
|
|
goto no_track;
|
|
|
|
burn_track_define_data(tracks[0], 0,
|
|
|
|
(Xorriso_min_track_sizE - img_sectors) * 2048,
|
|
|
|
0, BURN_MODE1);
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
sprintf(xorriso->info_text, "Expanded track to minimum size of %d sectors",
|
|
|
|
Xorriso_min_track_sizE);
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
|
|
|
|
}
|
|
|
|
|
2007-10-15 15:27:51 +00:00
|
|
|
isoburn_disc_write(burn_options, disc);
|
|
|
|
burn_write_opts_free(burn_options);
|
|
|
|
|
|
|
|
ret= Xorriso_pacifier_loop(xorriso, drive, 0);
|
|
|
|
if(ret<=0)
|
2007-10-18 22:17:46 +00:00
|
|
|
goto ex;
|
2007-10-20 17:10:04 +00:00
|
|
|
if(!isoburn_drive_wrote_well(drive)) {
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"libburn indicates failure with writing.");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
ret= 0; goto ex;
|
|
|
|
}
|
2007-10-15 15:27:51 +00:00
|
|
|
|
2007-11-02 14:36:26 +00:00
|
|
|
sessions= burn_disc_get_sessions(disc, &num_sessions);
|
|
|
|
if(num_sessions>0) {
|
|
|
|
tracks= burn_session_get_tracks(sessions[0], &num_tracks);
|
|
|
|
if(tracks!=NULL && num_tracks>0) {
|
|
|
|
burn_track_get_counters(tracks[0],&readcounter,&writecounter);
|
2007-11-02 18:47:38 +00:00
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"ISO image produced: %d sectors. Written to media: %d sectors\n",
|
2008-01-26 00:26:57 +00:00
|
|
|
(int) (readcounter/ (off_t) 2048),
|
|
|
|
(int) (writecounter/ (off_t) 2048));
|
2007-11-02 14:36:26 +00:00
|
|
|
Xorriso_info(xorriso, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-15 15:27:51 +00:00
|
|
|
ret= isoburn_activate_session(drive);
|
2007-10-17 13:02:32 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-10-15 15:27:51 +00:00
|
|
|
if(ret<=0) {
|
2007-10-17 13:02:32 +00:00
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Could not write new set of volume descriptors");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
2007-10-18 22:17:46 +00:00
|
|
|
goto ex;
|
2007-10-15 15:27:51 +00:00
|
|
|
}
|
2007-11-02 14:36:26 +00:00
|
|
|
|
|
|
|
sprintf(xorriso->info_text, "Writing completed sucessfully.\n\n");
|
|
|
|
Xorriso_info(xorriso, 0);
|
2007-10-18 22:17:46 +00:00
|
|
|
ret= 1;
|
|
|
|
ex:;
|
|
|
|
if(disc!=NULL)
|
|
|
|
burn_disc_free(disc);
|
2008-01-28 23:58:12 +00:00
|
|
|
isoburn_igopt_destroy(&sopts, 0);
|
2007-10-17 13:02:32 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-10-18 22:17:46 +00:00
|
|
|
return(ret);
|
2007-10-15 15:27:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Xorriso_pacifier_loop(struct XorrisO *xorriso, struct burn_drive *drive,
|
|
|
|
int flag)
|
|
|
|
{
|
|
|
|
int ret, size, free_bytes, i;
|
|
|
|
struct burn_progress progress;
|
|
|
|
char *status_text;
|
2007-10-20 17:10:04 +00:00
|
|
|
enum burn_drive_status drive_status;
|
|
|
|
double start_time, current_time;
|
2007-10-15 15:27:51 +00:00
|
|
|
|
2007-10-20 17:10:04 +00:00
|
|
|
start_time= Sfile_microtime(0);
|
2007-10-15 15:27:51 +00:00
|
|
|
while(burn_drive_get_status(drive, NULL) == BURN_DRIVE_SPAWNING)
|
|
|
|
usleep(100002);
|
|
|
|
|
2007-10-20 17:10:04 +00:00
|
|
|
while(1) {
|
|
|
|
drive_status= burn_drive_get_status(drive, &progress);
|
|
|
|
if(drive_status == BURN_DRIVE_IDLE)
|
|
|
|
break;
|
|
|
|
current_time= Sfile_microtime(0);
|
2007-11-01 11:14:42 +00:00
|
|
|
if(drive_status == BURN_DRIVE_WRITING && progress.sectors > 0) {
|
2007-10-20 17:10:04 +00:00
|
|
|
sprintf(xorriso->info_text, "Writing: sector %d of %d",
|
|
|
|
progress.sector, progress.sectors);
|
|
|
|
ret= isoburn_get_fifo_status(drive, &size, &free_bytes, &status_text);
|
|
|
|
if(ret>0 )
|
|
|
|
sprintf(xorriso->info_text+strlen(xorriso->info_text),
|
|
|
|
" [fifo %s, %2d%% fill]", status_text,
|
|
|
|
(int) (100.0-100.0*((double) free_bytes)/(double) size));
|
|
|
|
} else if(drive_status == BURN_DRIVE_CLOSING_SESSION ||
|
|
|
|
drive_status == BURN_DRIVE_CLOSING_TRACK)
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Closing track/session. Working since %.f seconds",
|
|
|
|
current_time-start_time);
|
|
|
|
else if(drive_status == BURN_DRIVE_FORMATTING)
|
|
|
|
sprintf(xorriso->info_text, "Formatting. Working since %.f seconds",
|
|
|
|
current_time-start_time);
|
|
|
|
else
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Thank you for being patient since %.f seconds",
|
|
|
|
current_time-start_time);
|
2007-10-16 21:09:36 +00:00
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "UPDATE", 0);
|
2007-10-15 15:27:51 +00:00
|
|
|
|
|
|
|
for(i= 0; i<10; i++) {
|
2007-10-17 13:02:32 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso, 0);
|
2007-10-15 15:27:51 +00:00
|
|
|
usleep(100000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-26 00:26:57 +00:00
|
|
|
int Xorriso_get_volume(struct XorrisO *xorriso, IsoImage **volume,
|
2007-10-21 09:48:17 +00:00
|
|
|
int flag)
|
2007-10-15 15:27:51 +00:00
|
|
|
{
|
2007-10-15 20:37:53 +00:00
|
|
|
if(xorriso->in_volset_handle==NULL) {
|
2007-10-17 13:02:32 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2008-01-26 00:26:57 +00:00
|
|
|
sprintf(xorriso->info_text,"No ISO image present.");
|
|
|
|
if(xorriso->indev[0]==0 && xorriso->outdev[0]==0)
|
2007-10-18 18:32:32 +00:00
|
|
|
sprintf(xorriso->info_text+strlen(xorriso->info_text),
|
2008-01-26 00:26:57 +00:00
|
|
|
" No -dev, -indev, or -outdev selected.");
|
2007-10-15 20:37:53 +00:00
|
|
|
else
|
2007-10-18 18:32:32 +00:00
|
|
|
sprintf(xorriso->info_text+strlen(xorriso->info_text),
|
|
|
|
" Possible program error with drive '%s'.", xorriso->indev);
|
2007-10-15 20:37:53 +00:00
|
|
|
|
2007-10-16 21:09:36 +00:00
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
2007-10-15 20:37:53 +00:00
|
|
|
return(0);
|
|
|
|
}
|
2008-01-26 00:26:57 +00:00
|
|
|
*volume= (IsoImage *) xorriso->in_volset_handle;
|
2007-10-21 09:48:17 +00:00
|
|
|
return(*volume != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-26 00:26:57 +00:00
|
|
|
/* @param flag bit0=do not complain about non existent node */
|
|
|
|
int Xorriso_node_from_path(struct XorrisO *xorriso, IsoImage *volume,
|
|
|
|
char *path, IsoNode **node, int flag)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
char sfe[5*SfileadrL], *path_pt;
|
|
|
|
|
|
|
|
path_pt= path;
|
|
|
|
if(path[0]==0)
|
|
|
|
path_pt= "/";
|
|
|
|
*node= NULL;
|
|
|
|
ret= iso_tree_path_to_node(volume, path_pt, node);
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
if(ret<=0) {
|
|
|
|
if(!(flag&1)) {
|
|
|
|
sprintf(xorriso->info_text, "Cannot find path %s in loaded ISO image",
|
|
|
|
Text_shellsafe(path_pt, sfe, 0));
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
}
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-21 15:10:41 +00:00
|
|
|
/* @param eff_path returns resulting effective path.
|
|
|
|
Must provide at least SfileadrL bytes of storage.
|
2007-10-24 17:53:54 +00:00
|
|
|
@param flag bit0= do not produce problem events (unless faulty path format)
|
2007-10-21 18:52:03 +00:00
|
|
|
bit1= work purely literally, do not use libisofs
|
2007-10-27 23:04:35 +00:00
|
|
|
bit2= (with bit1) this is an address in the disk world
|
2007-10-24 17:53:54 +00:00
|
|
|
@return -1 = faulty path format, 0 = not found ,
|
2007-10-21 15:10:41 +00:00
|
|
|
1 = found simple node , 2 = found directory
|
|
|
|
*/
|
2007-12-15 18:31:39 +00:00
|
|
|
int Xorriso_normalize_img_path(struct XorrisO *xorriso, char *wd,
|
|
|
|
char *img_path, char eff_path[], int flag)
|
2007-10-21 15:10:41 +00:00
|
|
|
{
|
2007-10-24 17:53:54 +00:00
|
|
|
int ret, is_dir= 0, done= 0;
|
2008-01-26 00:26:57 +00:00
|
|
|
IsoImage *volume;
|
|
|
|
IsoDir *dir= NULL;
|
|
|
|
IsoNode *node= NULL;
|
2007-11-08 16:11:26 +00:00
|
|
|
char path[SfileadrL], *apt, *npt, sfe[5*SfileadrL], *cpt;
|
2007-10-21 15:10:41 +00:00
|
|
|
|
2007-10-28 12:54:22 +00:00
|
|
|
eff_path[0]= 0;
|
|
|
|
if(img_path[0]==0)
|
|
|
|
return(2); /* root directory */
|
|
|
|
|
2007-10-21 18:52:03 +00:00
|
|
|
if(!(flag&2)) {
|
|
|
|
ret= Xorriso_get_volume(xorriso, &volume, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
|
|
|
}
|
2007-10-21 15:10:41 +00:00
|
|
|
|
2007-11-11 11:21:46 +00:00
|
|
|
apt= npt= path;
|
2007-10-27 22:41:24 +00:00
|
|
|
if(img_path[0]!='/') {
|
2007-12-15 18:31:39 +00:00
|
|
|
strcpy(path, wd);
|
2007-10-27 22:41:24 +00:00
|
|
|
ret= Sfile_add_to_path(path, img_path, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
goto much_too_long;
|
|
|
|
} else
|
|
|
|
if(Sfile_str(path, img_path, 0)<=0)
|
|
|
|
return(-1);
|
2007-10-21 15:10:41 +00:00
|
|
|
|
|
|
|
if(path[0]!='/') {
|
|
|
|
sprintf(xorriso->info_text,
|
2007-10-27 22:41:24 +00:00
|
|
|
"Internal error: Unresolvable relative addressing in iso_rr_path '%s'",
|
|
|
|
img_path);
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FATAL", 0);
|
2007-10-24 17:53:54 +00:00
|
|
|
return(-1);
|
2007-10-28 12:54:22 +00:00
|
|
|
} else if(path[1]==0)
|
|
|
|
return(2); /* root directory */
|
2007-10-21 15:10:41 +00:00
|
|
|
|
|
|
|
for(npt= apt; !done; apt= npt+1) {
|
|
|
|
npt= strchr(apt, '/');
|
|
|
|
if(npt==NULL) {
|
|
|
|
npt= apt+strlen(apt);
|
|
|
|
done= 1;
|
|
|
|
} else
|
|
|
|
*npt= 0;
|
|
|
|
if(*apt==0) {
|
|
|
|
*apt= '/';
|
|
|
|
apt++;
|
|
|
|
if(done)
|
|
|
|
break;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(strcmp(apt,".")==0)
|
|
|
|
continue;
|
|
|
|
if(strcmp(apt,"..")==0) {
|
2007-10-21 18:52:03 +00:00
|
|
|
if(!(flag&2)) {
|
2008-01-26 00:26:57 +00:00
|
|
|
node= (IsoNode *) dir;
|
2007-10-21 18:52:03 +00:00
|
|
|
if(node==NULL) {
|
|
|
|
bonked_root:;
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Relative addressing in path exceeds root directory: %s",
|
2007-10-24 17:53:54 +00:00
|
|
|
Text_shellsafe(img_path, sfe, 0));
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
return(-1);
|
2007-10-21 18:52:03 +00:00
|
|
|
}
|
2008-01-26 00:26:57 +00:00
|
|
|
dir= iso_node_get_parent(node);
|
2007-10-21 15:10:41 +00:00
|
|
|
}
|
|
|
|
/* truncate eff_path */;
|
|
|
|
cpt= strrchr(eff_path, '/');
|
2007-10-21 18:52:03 +00:00
|
|
|
if(cpt==NULL) /* ??? if not flag&2 then this is a bug */
|
|
|
|
goto bonked_root;
|
2007-10-21 15:10:41 +00:00
|
|
|
*cpt= 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ret= Sfile_add_to_path(eff_path, apt, 0);
|
|
|
|
if(ret<=0) {
|
2007-10-27 22:41:24 +00:00
|
|
|
much_too_long:;
|
2007-10-21 18:52:03 +00:00
|
|
|
sprintf(xorriso->info_text, "Effective path gets much too long (%d)",
|
2007-11-26 19:22:38 +00:00
|
|
|
(int) (strlen(eff_path)+strlen(apt)+1));
|
2007-10-21 15:10:41 +00:00
|
|
|
if(!(flag&1))
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
2007-10-24 17:53:54 +00:00
|
|
|
return(-1);
|
2007-10-21 15:10:41 +00:00
|
|
|
}
|
2007-10-21 18:52:03 +00:00
|
|
|
if(!(flag&2)) {
|
2008-01-26 00:26:57 +00:00
|
|
|
dir= (IsoDir *) node;
|
|
|
|
ret= Xorriso_node_from_path(xorriso, volume, eff_path, &node, flag&1);
|
|
|
|
if(ret<=0)
|
|
|
|
return(0);
|
2007-10-21 18:52:03 +00:00
|
|
|
if(dir==NULL) /* could be false with "/dir/.." */
|
2008-01-26 00:26:57 +00:00
|
|
|
dir= iso_node_get_parent(node);
|
2007-10-21 18:52:03 +00:00
|
|
|
is_dir= LIBISO_ISDIR(node);
|
2007-10-21 15:10:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return(1+!!is_dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-07 19:18:31 +00:00
|
|
|
int Xorriso_get_node_by_path(struct XorrisO *xorriso,
|
|
|
|
char *in_path, char *eff_path,
|
2008-01-26 00:26:57 +00:00
|
|
|
IsoNode **node, int flag)
|
2007-11-07 19:18:31 +00:00
|
|
|
{
|
|
|
|
int ret;
|
2008-01-26 00:26:57 +00:00
|
|
|
char path[SfileadrL];
|
|
|
|
IsoImage *volume;
|
2007-11-07 19:18:31 +00:00
|
|
|
|
2007-12-15 18:31:39 +00:00
|
|
|
ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, in_path, path, 0);
|
2007-11-07 19:18:31 +00:00
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
|
|
|
if(eff_path!=NULL)
|
|
|
|
strcpy(eff_path, path);
|
|
|
|
ret= Xorriso_get_volume(xorriso, &volume, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= Xorriso_node_from_path(xorriso, volume, path, node, 0);
|
|
|
|
if(ret<=0)
|
2007-11-07 19:18:31 +00:00
|
|
|
return(0);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-16 12:27:35 +00:00
|
|
|
int Xorriso_transfer_properties(struct XorrisO *xorriso, struct stat *stbuf,
|
2008-01-26 00:26:57 +00:00
|
|
|
IsoNode *node, int flag)
|
2007-12-16 12:27:35 +00:00
|
|
|
{
|
2008-01-26 00:26:57 +00:00
|
|
|
iso_node_set_permissions(node, stbuf->st_mode & 07777);
|
|
|
|
iso_node_set_uid(node, stbuf->st_uid);
|
|
|
|
iso_node_set_gid(node, stbuf->st_gid);
|
|
|
|
iso_node_set_atime(node, stbuf->st_atime);
|
|
|
|
iso_node_set_mtime(node, stbuf->st_mtime);
|
|
|
|
iso_node_set_ctime(node, stbuf->st_ctime);
|
2007-12-16 12:27:35 +00:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-06 16:32:39 +00:00
|
|
|
/* @param flag bit0= recursion is active */
|
2008-01-26 00:26:57 +00:00
|
|
|
int Xorriso_add_tree(struct XorrisO *xorriso, IsoDir *dir,
|
2007-12-15 18:31:39 +00:00
|
|
|
char *img_dir_path, char *disk_dir_path,
|
|
|
|
struct LinkiteM *link_stack, int flag)
|
2007-11-06 16:32:39 +00:00
|
|
|
{
|
2008-01-26 00:26:57 +00:00
|
|
|
IsoImage *volume;
|
|
|
|
IsoNode *node;
|
|
|
|
IsoSymlink *iso_symlink;
|
2007-12-15 18:31:39 +00:00
|
|
|
int ret, target_is_dir, source_is_dir, source_is_link, fret, was_failure= 0;
|
|
|
|
int do_not_dive;
|
2007-11-06 16:32:39 +00:00
|
|
|
struct DirseQ *dirseq= NULL;
|
2007-12-15 18:31:39 +00:00
|
|
|
char *name, *img_name, *srcpt;
|
|
|
|
struct stat stbuf, hstbuf;
|
|
|
|
dev_t dir_dev;
|
|
|
|
struct LinkiteM *own_link_stack;
|
|
|
|
|
2007-12-28 13:28:48 +00:00
|
|
|
#ifdef Xorriso_fat_local_meM
|
|
|
|
char sfe[5*SfileadrL], sfe2[5*SfileadrL];
|
|
|
|
char disk_path[2*SfileadrL], img_path[2*SfileadrL], link_target[SfileadrL];
|
|
|
|
#else /* Xorriso_fat_local_meM */
|
|
|
|
|
|
|
|
char *sfe= NULL, *sfe2= NULL;
|
|
|
|
char *disk_path= NULL, *img_path= NULL, *link_target= NULL;
|
|
|
|
|
|
|
|
/* Avoiding large local memory objects in order to save stack space */
|
|
|
|
sfe= malloc(5*SfileadrL);
|
|
|
|
sfe2= malloc(5*SfileadrL);
|
|
|
|
disk_path= malloc(2*SfileadrL);
|
|
|
|
img_path= malloc(2*SfileadrL);
|
|
|
|
link_target= malloc(SfileadrL);
|
|
|
|
if(sfe==NULL || sfe2==NULL || disk_path==NULL || img_path==NULL ||
|
|
|
|
link_target==NULL) {
|
|
|
|
Xorriso_no_malloc_memory(xorriso, &sfe, 0);
|
|
|
|
{ret= -1; goto ex;}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* ! Xorriso_fat_local_meM */
|
|
|
|
|
2007-12-15 18:31:39 +00:00
|
|
|
own_link_stack= link_stack;
|
2007-11-06 16:32:39 +00:00
|
|
|
|
|
|
|
ret= Xorriso_get_volume(xorriso, &volume, 0);
|
|
|
|
if(ret<=0)
|
2007-12-28 13:28:48 +00:00
|
|
|
goto ex;
|
2007-11-06 16:32:39 +00:00
|
|
|
|
2007-12-15 18:31:39 +00:00
|
|
|
if(lstat(disk_dir_path, &stbuf)==-1)
|
|
|
|
goto cannot_open_dir;
|
|
|
|
dir_dev= stbuf.st_dev;
|
|
|
|
if(S_ISLNK(stbuf.st_mode)) {
|
|
|
|
if(!(xorriso->do_follow_links || (xorriso->do_follow_param && !(flag&1))))
|
2007-12-28 13:28:48 +00:00
|
|
|
{ret= 2; goto ex;}
|
2007-12-15 18:31:39 +00:00
|
|
|
if(stat(disk_dir_path, &stbuf)==-1)
|
|
|
|
goto cannot_open_dir;
|
|
|
|
if(dir_dev != stbuf.st_dev &&
|
|
|
|
!(xorriso->do_follow_mount || (xorriso->do_follow_param && !(flag&1))))
|
2007-12-28 13:28:48 +00:00
|
|
|
{ret= 2; goto ex;}
|
2007-12-15 18:31:39 +00:00
|
|
|
}
|
2007-11-06 16:32:39 +00:00
|
|
|
ret= Dirseq_new(&dirseq, disk_dir_path, 1);
|
|
|
|
if(ret<0) {
|
|
|
|
sprintf(xorriso->info_text,"Failed to create source filesystem iterator");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
|
|
|
{ret= -1; goto ex;}
|
|
|
|
}
|
|
|
|
if(ret==0) {
|
2007-12-15 18:31:39 +00:00
|
|
|
cannot_open_dir:;
|
2007-11-06 16:32:39 +00:00
|
|
|
sprintf(xorriso->info_text,"Cannot open as source directory: %s",
|
|
|
|
Text_shellsafe(disk_dir_path, sfe, 0));
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
{ret= 0; goto ex;}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(Sfile_str(disk_path, disk_dir_path,0)<=0)
|
|
|
|
{ret= -1; goto ex;}
|
2007-11-07 12:37:19 +00:00
|
|
|
if(disk_path[0]==0 || disk_path[strlen(disk_path)-1]!='/')
|
2007-11-06 16:32:39 +00:00
|
|
|
strcat(disk_path,"/");
|
|
|
|
name= disk_path+strlen(disk_path);
|
|
|
|
if(Sfile_str(img_path, img_dir_path, 0)<=0)
|
|
|
|
{ret= -1; goto ex;}
|
2007-11-07 12:37:19 +00:00
|
|
|
if(img_path[0] || img_path[strlen(img_path)-1]!='/')
|
2007-11-06 16:32:39 +00:00
|
|
|
strcat(img_path,"/");
|
|
|
|
img_name= img_path+strlen(img_path);
|
|
|
|
|
|
|
|
while(1) { /* loop over directory content */
|
2007-12-15 18:31:39 +00:00
|
|
|
Linkitem_reset_stack(&own_link_stack, link_stack, 0);
|
|
|
|
srcpt= disk_path;
|
2007-11-06 16:32:39 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
ret= Dirseq_next_adr(dirseq,name,0);
|
|
|
|
if(ret==0)
|
|
|
|
break;
|
|
|
|
if(ret<0) {
|
|
|
|
sprintf(xorriso->info_text,"Failed to obtain next directory entry");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
|
|
|
{ret= -1; goto ex;}
|
|
|
|
}
|
|
|
|
strcpy(img_name, name);
|
|
|
|
if(Xorriso_much_too_long(xorriso, strlen(img_path), 0)<=0)
|
2007-11-11 11:21:46 +00:00
|
|
|
{ret= 0; goto was_problem;}
|
2007-12-15 18:31:39 +00:00
|
|
|
if(Xorriso_much_too_long(xorriso, strlen(srcpt), 0)<=0)
|
2007-11-11 11:21:46 +00:00
|
|
|
{ret= 0; goto was_problem;}
|
2007-12-15 18:31:39 +00:00
|
|
|
if(lstat(srcpt, &stbuf)==-1) {
|
|
|
|
cannot_lstat:;
|
2007-11-06 16:32:39 +00:00
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Cannot determine attributes of source file %s",
|
2007-12-15 18:31:39 +00:00
|
|
|
Text_shellsafe(srcpt, sfe, 0));
|
2007-11-06 16:32:39 +00:00
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "SORRY", 0);
|
2007-11-11 11:21:46 +00:00
|
|
|
ret= 0; goto was_problem;
|
2007-11-06 16:32:39 +00:00
|
|
|
}
|
|
|
|
source_is_dir= 0;
|
2007-12-15 18:31:39 +00:00
|
|
|
source_is_link= S_ISLNK(stbuf.st_mode);
|
|
|
|
if(xorriso->do_follow_links && source_is_link) {
|
|
|
|
/* Xorriso_hop_link checks for wide link loops */
|
|
|
|
ret= Xorriso_hop_link(xorriso, srcpt, &own_link_stack, &hstbuf, 0);
|
|
|
|
if(ret<0)
|
|
|
|
goto was_problem;
|
|
|
|
if(ret==1) {
|
|
|
|
ret= Xorriso_resolve_link(xorriso, srcpt, link_target, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
goto was_problem;
|
|
|
|
srcpt= link_target;
|
|
|
|
if(lstat(srcpt, &stbuf)==-1)
|
|
|
|
goto cannot_lstat;
|
|
|
|
} else {
|
|
|
|
if(Xorriso_eval_problem_status(xorriso, 0, 1|2)<0)
|
|
|
|
{ret= 0; goto was_problem;}
|
|
|
|
}
|
|
|
|
} else if (S_ISLNK(stbuf.st_mode)) {
|
|
|
|
ret= Xorriso_resolve_link(xorriso, srcpt, link_target, 1);
|
|
|
|
if(ret<=0)
|
|
|
|
goto was_problem;
|
|
|
|
}
|
|
|
|
do_not_dive= 0;
|
2007-11-06 16:32:39 +00:00
|
|
|
if(S_ISDIR(stbuf.st_mode)) {
|
|
|
|
source_is_dir= 1;
|
2007-12-15 18:31:39 +00:00
|
|
|
if(dir_dev != stbuf.st_dev && !xorriso->do_follow_mount)
|
|
|
|
do_not_dive= 1;
|
2008-01-26 00:26:57 +00:00
|
|
|
|
|
|
|
#ifdef NIX
|
2007-11-06 16:32:39 +00:00
|
|
|
} else if(!(S_ISREG(stbuf.st_mode) || S_ISLNK(stbuf.st_mode))) {
|
2007-12-15 18:31:39 +00:00
|
|
|
sprintf(xorriso->info_text,"Source file %s %s non-supported file type",
|
|
|
|
Text_shellsafe(disk_path, sfe, 0),
|
|
|
|
source_is_link ? "leads to" : "is of");
|
2007-11-06 16:32:39 +00:00
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
2007-11-11 11:21:46 +00:00
|
|
|
ret= 0; goto was_problem;
|
2008-01-26 00:26:57 +00:00
|
|
|
#endif /* NIX */
|
|
|
|
|
2007-11-06 16:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* does a node exist with this name ? */
|
2008-01-26 00:26:57 +00:00
|
|
|
node= NULL;
|
|
|
|
ret= Xorriso_node_from_path(xorriso, volume, img_path, &node, 1);
|
|
|
|
if(ret>0) {
|
|
|
|
target_is_dir= LIBISO_ISDIR(node);
|
2007-11-06 16:32:39 +00:00
|
|
|
if(!(target_is_dir && source_is_dir)) {
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
|
|
|
|
/* handle overwrite situation */;
|
|
|
|
if(xorriso->do_overwrite==1 ||
|
|
|
|
(xorriso->do_overwrite==2 && !target_is_dir)) {
|
2007-11-07 12:37:19 +00:00
|
|
|
ret= Xorriso_rmi(xorriso, NULL, img_path, 1|8);
|
2007-11-06 16:32:39 +00:00
|
|
|
if(ret<=0)
|
|
|
|
goto was_problem;
|
2007-11-07 12:37:19 +00:00
|
|
|
if(ret==3) {
|
|
|
|
sprintf(xorriso->info_text, "User revoked adding of: %s",
|
2007-12-15 18:31:39 +00:00
|
|
|
Text_shellsafe(img_path, sfe, 0));
|
2007-11-07 12:37:19 +00:00
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
|
2007-11-11 11:21:46 +00:00
|
|
|
ret= 0; goto was_problem;
|
2007-11-07 12:37:19 +00:00
|
|
|
}
|
2007-11-06 16:32:39 +00:00
|
|
|
node= NULL;
|
|
|
|
} else {
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"While grafting %s : file object exists and may not be overwritten",
|
|
|
|
Text_shellsafe(img_path,sfe,0));
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
2007-11-11 11:21:46 +00:00
|
|
|
ret= 0; goto was_problem;
|
2007-11-06 16:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-15 18:31:39 +00:00
|
|
|
if(node==NULL) {
|
|
|
|
if(S_ISLNK(stbuf.st_mode)) {
|
|
|
|
|
2008-01-26 00:26:57 +00:00
|
|
|
/* ??? NG : A80107 : is this solved now ? */
|
2007-12-15 18:31:39 +00:00
|
|
|
/* <<< One should rather change libisofs so that iso_tree_add_node()
|
|
|
|
adds a disk_link as RR link, if RR is enabled */
|
|
|
|
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= iso_tree_add_new_symlink(dir, img_name, link_target, &iso_symlink);
|
|
|
|
node= (IsoNode *) iso_symlink;
|
|
|
|
if(ret>0) {
|
2007-12-16 12:27:35 +00:00
|
|
|
ret= Xorriso_transfer_properties(xorriso, &stbuf, node, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
goto was_problem;
|
2008-02-03 13:16:18 +00:00
|
|
|
} else {
|
|
|
|
Xorriso_report_iso_error(xorriso, ret, "Cannot create symbolic link",
|
|
|
|
0, "SORRY", 1);
|
2008-01-09 17:55:27 +00:00
|
|
|
{ret= 0; goto was_problem;}
|
2008-02-03 13:16:18 +00:00
|
|
|
}
|
2008-01-26 00:26:57 +00:00
|
|
|
} else {
|
|
|
|
ret= iso_tree_add_node(volume, dir, srcpt, &node);
|
2008-02-03 13:16:18 +00:00
|
|
|
if(ret<0) {
|
|
|
|
Xorriso_report_iso_error(xorriso, ret, "Cannot add node to tree",
|
|
|
|
0, "SORRY", 1);
|
2008-01-26 00:26:57 +00:00
|
|
|
goto was_problem;
|
2008-02-03 13:16:18 +00:00
|
|
|
}
|
2008-01-26 00:26:57 +00:00
|
|
|
}
|
2007-12-15 18:31:39 +00:00
|
|
|
}
|
2008-01-26 00:26:57 +00:00
|
|
|
if(node==NULL) {
|
2007-11-06 16:32:39 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2008-01-26 00:26:57 +00:00
|
|
|
sprintf(xorriso->info_text, "Grafting failed: %s = %s",
|
|
|
|
Text_shellsafe(img_path,sfe,0), Text_shellsafe(disk_path,sfe2,0));
|
2007-11-06 16:32:39 +00:00
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
2007-11-11 11:21:46 +00:00
|
|
|
ret=0; goto was_problem;
|
2007-11-06 16:32:39 +00:00
|
|
|
}
|
2007-12-04 07:44:59 +00:00
|
|
|
xorriso->volset_change_pending= 1;
|
2007-11-06 16:32:39 +00:00
|
|
|
if(source_is_dir) {
|
2007-12-15 18:31:39 +00:00
|
|
|
if(do_not_dive) {
|
|
|
|
sprintf(xorriso->info_text, "Did not follow mount point : %s",
|
|
|
|
Text_shellsafe(disk_path, sfe, 0));
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
|
|
|
|
} else {
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= Xorriso_add_tree(xorriso, (IsoDir *) node,
|
2007-12-15 18:31:39 +00:00
|
|
|
img_path, disk_path, own_link_stack, 1);
|
|
|
|
}
|
2007-11-11 11:21:46 +00:00
|
|
|
if(ret<=0)
|
2007-11-06 16:32:39 +00:00
|
|
|
goto was_problem;
|
|
|
|
}
|
|
|
|
|
2007-11-11 11:21:46 +00:00
|
|
|
continue; /* regular bottom of loop */
|
2007-11-06 16:32:39 +00:00
|
|
|
was_problem:;
|
2007-11-11 11:21:46 +00:00
|
|
|
was_failure= 1;
|
|
|
|
fret= Xorriso_eval_problem_status(xorriso, ret, 1|2);
|
|
|
|
if(fret<0)
|
|
|
|
goto ex;
|
2007-11-06 16:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret= 1;
|
|
|
|
ex:
|
2007-12-28 13:28:48 +00:00
|
|
|
|
|
|
|
#ifndef Xorriso_fat_local_meM
|
|
|
|
if(sfe!=NULL)
|
|
|
|
free(sfe);
|
|
|
|
if(sfe2!=NULL)
|
|
|
|
free(sfe2);
|
|
|
|
if(disk_path!=NULL)
|
|
|
|
free(disk_path);
|
|
|
|
if(img_path!=NULL)
|
|
|
|
free(img_path);
|
|
|
|
if(link_target!=NULL)
|
|
|
|
free(link_target);
|
|
|
|
#endif /* ! Xorriso_fat_local_meM */
|
|
|
|
|
2007-11-06 16:32:39 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-12-15 18:31:39 +00:00
|
|
|
Linkitem_reset_stack(&own_link_stack, link_stack, 0);
|
2007-11-06 16:32:39 +00:00
|
|
|
Dirseq_destroy(&dirseq, 0);
|
2007-11-11 11:21:46 +00:00
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
|
|
|
return(!was_failure);
|
2007-11-06 16:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-27 22:41:24 +00:00
|
|
|
/** @param flag bit0= mkdir: graft in as empty directory, not as copy from disk
|
|
|
|
@return <=0 = error , 1 = added simple node , 2 = added directory */
|
2007-10-21 09:48:17 +00:00
|
|
|
int Xorriso_graft_in(struct XorrisO *xorriso, char *disk_path, char *img_path,
|
|
|
|
int flag)
|
|
|
|
{
|
2008-01-26 00:26:57 +00:00
|
|
|
IsoImage *volume;
|
|
|
|
char path[SfileadrL], *apt, *npt, *cpt, sfe[5*SfileadrL], sfe2[5*SfileadrL];
|
|
|
|
IsoDir *dir, *hdir;
|
|
|
|
IsoNode *node;
|
2007-11-06 16:32:39 +00:00
|
|
|
int done= 0, is_dir= 0, l, ret, target_is_dir, source_is_dir;
|
2007-10-21 09:48:17 +00:00
|
|
|
struct stat stbuf;
|
|
|
|
|
2007-10-21 15:10:41 +00:00
|
|
|
for(cpt= img_path; 1; cpt++) {
|
2007-12-04 07:44:59 +00:00
|
|
|
/*
|
2007-10-21 15:10:41 +00:00
|
|
|
if(cpt[0]!='/')
|
|
|
|
break;
|
2007-12-04 07:44:59 +00:00
|
|
|
*/
|
2007-10-21 15:10:41 +00:00
|
|
|
cpt= strstr(cpt,"/.");
|
|
|
|
if(cpt==NULL)
|
|
|
|
break;
|
|
|
|
if(cpt[2]=='.') {
|
|
|
|
if(cpt[3]=='/' || cpt[3]==0)
|
|
|
|
break;
|
|
|
|
} else if(cpt[2]=='/' || cpt[2]==0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(cpt!=NULL) {
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Unsupported relative addressing in iso_rr_path '%s'", img_path);
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "SORRY", 0);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
2007-10-21 09:48:17 +00:00
|
|
|
ret= Xorriso_get_volume(xorriso, &volume, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
|
|
|
|
2007-10-15 15:27:51 +00:00
|
|
|
strncpy(path, img_path, sizeof(path)-1);
|
|
|
|
path[sizeof(path)-1]= 0;
|
|
|
|
apt= npt= path;
|
|
|
|
|
2007-10-27 22:41:24 +00:00
|
|
|
if(!(flag&1)) {
|
2007-12-15 18:31:39 +00:00
|
|
|
if(xorriso->do_follow_links || xorriso->do_follow_param)
|
|
|
|
ret= stat(disk_path, &stbuf);
|
|
|
|
else
|
|
|
|
ret= lstat(disk_path, &stbuf);
|
|
|
|
if(ret == -1) {
|
2007-10-27 22:41:24 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Cannot determine attributes of source file '%s'",disk_path);
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "SORRY", 0);
|
|
|
|
return(0);
|
|
|
|
}
|
2008-01-26 00:26:57 +00:00
|
|
|
if(S_ISDIR(stbuf.st_mode)) {
|
2007-10-27 22:41:24 +00:00
|
|
|
is_dir= 1;
|
2008-01-26 00:26:57 +00:00
|
|
|
|
|
|
|
#ifdef NIX
|
|
|
|
} else if(!(S_ISREG(stbuf.st_mode) || S_ISLNK(stbuf.st_mode))) {
|
2007-10-27 22:41:24 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-10-16 21:09:36 +00:00
|
|
|
sprintf(xorriso->info_text,
|
2007-10-27 22:41:24 +00:00
|
|
|
"Source file '%s' is of non-supported file type", disk_path);
|
2007-10-16 21:09:36 +00:00
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
2007-10-27 22:41:24 +00:00
|
|
|
return(0);
|
2008-01-26 00:26:57 +00:00
|
|
|
#endif /* NIX */
|
|
|
|
|
2007-10-27 22:41:24 +00:00
|
|
|
} else {
|
|
|
|
l= strlen(img_path);
|
|
|
|
if(l>0)
|
|
|
|
if(img_path[l-1]=='/')
|
|
|
|
l= 0;
|
|
|
|
if(l==0) {
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Source '%s' is not a directory. Target '%s' would be.",
|
|
|
|
disk_path, img_path);
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
2007-12-04 07:44:59 +00:00
|
|
|
return(0);
|
2007-10-27 22:41:24 +00:00
|
|
|
}
|
2007-10-15 20:37:53 +00:00
|
|
|
}
|
2007-10-15 15:27:51 +00:00
|
|
|
}
|
|
|
|
|
2008-01-26 00:26:57 +00:00
|
|
|
dir= iso_image_get_root(volume);
|
2007-10-15 15:27:51 +00:00
|
|
|
if(dir==NULL) {
|
2007-10-17 13:02:32 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-10-16 21:09:36 +00:00
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"While grafting '%s' : no root node available", img_path);
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
2007-10-15 15:27:51 +00:00
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
for(npt= apt; !done; apt= npt+1) {
|
|
|
|
npt= strchr(apt, '/');
|
|
|
|
if(npt==NULL) {
|
|
|
|
npt= apt+strlen(apt);
|
|
|
|
done= 1;
|
|
|
|
} else
|
|
|
|
*npt= 0;
|
|
|
|
if(*apt==0) {
|
|
|
|
*apt= '/';
|
|
|
|
apt++;
|
2007-10-15 20:37:53 +00:00
|
|
|
if(done)
|
|
|
|
goto attach_source;
|
2007-10-15 15:27:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
2007-11-06 16:32:39 +00:00
|
|
|
source_is_dir= (is_dir || (flag&1) || !done);
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= Xorriso_node_from_path(xorriso, volume, path, &node, 1);
|
|
|
|
if(ret>0) {
|
|
|
|
target_is_dir= LIBISO_ISDIR(node);
|
2007-11-06 16:32:39 +00:00
|
|
|
if(!(target_is_dir && source_is_dir)) {
|
2007-10-17 13:02:32 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-10-15 15:27:51 +00:00
|
|
|
|
2007-11-06 16:32:39 +00:00
|
|
|
/* handle overwrite situation */;
|
|
|
|
if(xorriso->do_overwrite==1 ||
|
|
|
|
(xorriso->do_overwrite==2 && !target_is_dir)) {
|
2007-11-07 12:37:19 +00:00
|
|
|
ret= Xorriso_rmi(xorriso, NULL, path, 1|8);
|
2007-11-06 16:32:39 +00:00
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
2007-11-07 12:37:19 +00:00
|
|
|
if(ret==3) {
|
|
|
|
sprintf(xorriso->info_text, "User revoked adding of: %s",
|
|
|
|
Text_shellsafe(disk_path, sfe, 0));
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
|
|
|
|
return(0);
|
|
|
|
}
|
2007-11-06 16:32:39 +00:00
|
|
|
node= NULL;
|
|
|
|
goto handle_path_node;
|
2007-10-15 20:37:53 +00:00
|
|
|
}
|
2007-11-06 16:32:39 +00:00
|
|
|
|
2007-10-16 21:09:36 +00:00
|
|
|
sprintf(xorriso->info_text,
|
2007-11-06 16:32:39 +00:00
|
|
|
"While grafting '%s' : '%s' exists and may not be overwritten",
|
2007-10-15 20:37:53 +00:00
|
|
|
img_path, path);
|
2007-10-16 21:09:36 +00:00
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
2007-10-15 15:27:51 +00:00
|
|
|
return(0);
|
|
|
|
}
|
2008-01-26 00:26:57 +00:00
|
|
|
dir= (IsoDir *) node;
|
2007-11-06 16:32:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handle_path_node:;
|
|
|
|
if(node==NULL && source_is_dir) { /* make a directory */
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= iso_tree_add_new_dir(dir, apt, &hdir);
|
|
|
|
if(ret<0) {
|
2007-10-17 13:02:32 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2008-02-03 13:16:18 +00:00
|
|
|
Xorriso_report_iso_error(xorriso, ret, "Cannot create directory",
|
|
|
|
0, "SORRY", 1);
|
2007-10-16 21:09:36 +00:00
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"While grafting '%s' : could not insert '%s'", img_path, path);
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
2007-10-15 15:27:51 +00:00
|
|
|
return(0);
|
|
|
|
}
|
2008-01-26 00:26:57 +00:00
|
|
|
dir= hdir;
|
2007-12-04 07:44:59 +00:00
|
|
|
xorriso->volset_change_pending= 1;
|
2008-01-26 00:26:57 +00:00
|
|
|
iso_node_set_ctime((IsoNode *) dir, time(NULL));
|
|
|
|
iso_node_set_uid((IsoNode *) dir, geteuid());
|
|
|
|
iso_node_set_gid((IsoNode *) dir, getegid());
|
2007-10-24 10:02:15 +00:00
|
|
|
|
|
|
|
/* >>> copy properties from correspondent directory in disk_path
|
|
|
|
if there is any */;
|
|
|
|
|
2007-10-15 15:27:51 +00:00
|
|
|
}
|
|
|
|
if(done) {
|
2007-10-15 20:37:53 +00:00
|
|
|
attach_source:;
|
2007-10-27 22:41:24 +00:00
|
|
|
if(flag&1) {
|
|
|
|
/* directory node was created above */;
|
|
|
|
|
|
|
|
} else if(is_dir) {
|
2008-01-26 00:26:57 +00:00
|
|
|
Xorriso_transfer_properties(xorriso, &stbuf, (IsoNode *) dir, 0);
|
2007-12-15 18:31:39 +00:00
|
|
|
ret= Xorriso_add_tree(xorriso, dir, img_path, disk_path, NULL, 0);
|
2007-11-06 16:32:39 +00:00
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
2007-10-24 10:02:15 +00:00
|
|
|
|
2007-10-15 15:27:51 +00:00
|
|
|
} else {
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= iso_tree_add_node(volume, dir, disk_path, &node);
|
|
|
|
if(ret<0) {
|
2007-10-17 13:02:32 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2008-02-03 13:16:18 +00:00
|
|
|
Xorriso_report_iso_error(xorriso, ret, "Cannot create node",
|
|
|
|
0, "SORRY", 1);
|
2008-01-26 00:26:57 +00:00
|
|
|
sprintf(xorriso->info_text, "Grafting failed: %s = %s",
|
|
|
|
Text_shellsafe(img_path,sfe,0), Text_shellsafe(disk_path,sfe2,0));
|
2007-10-16 21:09:36 +00:00
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
2007-10-15 15:27:51 +00:00
|
|
|
return(0);
|
|
|
|
}
|
2007-12-04 07:44:59 +00:00
|
|
|
xorriso->volset_change_pending= 1;
|
2008-01-26 00:26:57 +00:00
|
|
|
iso_node_set_name(node, apt);
|
2007-10-15 15:27:51 +00:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
*npt= '/';
|
|
|
|
}
|
2007-10-17 13:02:32 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-10-21 09:48:17 +00:00
|
|
|
return(1+!!is_dir);
|
2007-10-15 15:27:51 +00:00
|
|
|
}
|
|
|
|
|
2007-10-14 12:20:56 +00:00
|
|
|
|
2007-10-16 21:09:36 +00:00
|
|
|
int Xorriso__text_to_sev(char *severity_name, int *severity_number, int flag)
|
|
|
|
{
|
|
|
|
int ret= 1;
|
|
|
|
|
|
|
|
if(severity_name[0]==0)
|
|
|
|
*severity_number= 0;
|
|
|
|
else
|
|
|
|
ret= burn_text_to_sev(severity_name, severity_number, 0);
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-17 13:02:32 +00:00
|
|
|
int Xorriso_process_msg_queues(struct XorrisO *xorriso, int flag)
|
|
|
|
{
|
2008-02-03 13:16:18 +00:00
|
|
|
int ret, error_code= 0, os_errno= 0, count= 0, pass, imgid, tunneled;
|
2007-10-17 13:02:32 +00:00
|
|
|
char severity[80];
|
|
|
|
|
2007-10-18 18:57:19 +00:00
|
|
|
if(!xorriso->libs_are_started)
|
|
|
|
return(1);
|
2007-10-17 13:02:32 +00:00
|
|
|
for(pass= 0; pass< 2; pass++) {
|
|
|
|
while(1) {
|
|
|
|
if(pass==0)
|
2008-01-28 17:20:10 +00:00
|
|
|
ret= iso_obtain_msgs("ALL", &error_code, &imgid,
|
|
|
|
xorriso->info_text, severity);
|
2008-02-03 13:16:18 +00:00
|
|
|
else {
|
2007-10-17 13:02:32 +00:00
|
|
|
ret= burn_msgs_obtain("ALL", &error_code, xorriso->info_text, &os_errno,
|
|
|
|
severity);
|
2008-02-03 13:16:18 +00:00
|
|
|
tunneled= (error_code>=0x00050000 && error_code<0x00060000);
|
|
|
|
}
|
2007-10-17 13:02:32 +00:00
|
|
|
if(ret<=0)
|
|
|
|
break;
|
|
|
|
Xorriso_msgs_submit(xorriso, error_code, xorriso->info_text, os_errno,
|
2008-02-03 13:16:18 +00:00
|
|
|
severity, ((pass&&!tunneled)+1)<<2);
|
2007-10-17 13:02:32 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(xorriso->library_msg_direct_print && count>0) {
|
|
|
|
sprintf(xorriso->info_text," (%d library messages repeated by xorriso)\n",
|
|
|
|
count);
|
|
|
|
Xorriso_info(xorriso, 0);
|
|
|
|
}
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
2007-10-17 18:30:37 +00:00
|
|
|
|
2007-11-02 14:36:26 +00:00
|
|
|
/* @param flag bit0=short report form
|
2007-11-14 14:28:44 +00:00
|
|
|
bit1=report about output drive
|
2007-11-02 14:36:26 +00:00
|
|
|
*/
|
2007-10-17 18:30:37 +00:00
|
|
|
int Xorriso_toc(struct XorrisO *xorriso, int flag)
|
|
|
|
{
|
2007-11-02 14:36:26 +00:00
|
|
|
int num_sessions= 0, num_tracks= 0, lba= 0, nwa= -1, pmin, psec, pframe, ret;
|
2007-10-17 18:30:37 +00:00
|
|
|
int track_count= 0, session_no, track_no, profile_no= -1;
|
2007-11-11 11:21:46 +00:00
|
|
|
int last_track_start= 0, last_track_size= -1, num_data= 0, is_data= 0;
|
2008-01-26 00:26:57 +00:00
|
|
|
int is_inout_drive= 0, drive_role;
|
2007-11-14 14:28:44 +00:00
|
|
|
char profile_name[80],*respt,*devadr;
|
2007-10-17 18:30:37 +00:00
|
|
|
struct burn_disc *disc= NULL;
|
|
|
|
struct burn_session **sessions;
|
|
|
|
struct burn_track **tracks;
|
|
|
|
struct burn_toc_entry toc_entry;
|
|
|
|
struct burn_drive_info *dinfo;
|
|
|
|
struct burn_drive *drive;
|
|
|
|
enum burn_disc_status s;
|
2007-12-04 21:00:35 +00:00
|
|
|
char mem_text[80];
|
2007-10-17 18:30:37 +00:00
|
|
|
|
2007-10-18 18:32:32 +00:00
|
|
|
ret= Xorriso_get_drive_handles(xorriso, &dinfo, &drive,
|
2007-11-14 14:28:44 +00:00
|
|
|
"on attempt to print Table Of Content", flag&2);
|
2007-10-18 18:32:32 +00:00
|
|
|
if(ret<=0)
|
2007-10-17 18:30:37 +00:00
|
|
|
return(0);
|
|
|
|
|
|
|
|
respt= xorriso->result_line;
|
|
|
|
|
2007-11-14 14:28:44 +00:00
|
|
|
if(strcmp(xorriso->indev, xorriso->outdev)==0)
|
|
|
|
is_inout_drive= 1;
|
|
|
|
if(flag&2)
|
|
|
|
devadr= xorriso->outdev;
|
|
|
|
else
|
|
|
|
devadr= xorriso->indev;
|
|
|
|
sprintf(respt, "Drive current: %s '%s'\n",
|
|
|
|
(is_inout_drive ? "-dev" : (flag&2 ? "-outdev" : "-indev")),
|
|
|
|
devadr);
|
2007-10-17 20:02:45 +00:00
|
|
|
Xorriso_result(xorriso,0);
|
|
|
|
sprintf(respt, "Drive type : vendor '%s' product '%s' revision '%s'\n",
|
|
|
|
dinfo[0].vendor, dinfo[0].product, dinfo[0].revision);
|
2007-11-02 14:36:26 +00:00
|
|
|
if(!(flag&1))
|
|
|
|
Xorriso_result(xorriso,0);
|
2007-10-17 20:02:45 +00:00
|
|
|
|
2007-10-17 18:30:37 +00:00
|
|
|
sprintf(respt, "Media current: ");
|
|
|
|
ret= burn_disc_get_profile(drive, &profile_no, profile_name);
|
|
|
|
if (profile_no > 0 && ret > 0) {
|
|
|
|
if (profile_name[0])
|
2008-01-26 00:26:57 +00:00
|
|
|
sprintf(respt+strlen(respt), "%s", profile_name);
|
2007-10-17 18:30:37 +00:00
|
|
|
else
|
2008-01-26 00:26:57 +00:00
|
|
|
sprintf(respt+strlen(respt), "%4.4Xh", profile_no);
|
|
|
|
drive_role= burn_drive_get_drive_role(drive);
|
|
|
|
if(drive_role==2)
|
|
|
|
sprintf(respt+strlen(respt), ", overwriteable");
|
|
|
|
else if(drive_role==0 || drive_role==3)
|
|
|
|
sprintf(respt+strlen(respt), ", sequential");
|
|
|
|
strcat(respt, "\n");
|
2007-10-17 18:30:37 +00:00
|
|
|
} else
|
|
|
|
sprintf(respt+strlen(respt), "is not recognizable\n");
|
|
|
|
Xorriso_result(xorriso,0);
|
|
|
|
|
|
|
|
sprintf(respt, "Media status : ");
|
|
|
|
s= isoburn_disc_get_status(drive);
|
|
|
|
if (s == BURN_DISC_FULL) {
|
|
|
|
sprintf(respt+strlen(respt), "is written , is closed\n");
|
|
|
|
} else if (s == BURN_DISC_APPENDABLE) {
|
|
|
|
sprintf(respt+strlen(respt), "is written , is appendable\n");
|
|
|
|
} else if (s == BURN_DISC_BLANK) {
|
|
|
|
sprintf(respt+strlen(respt), "is blank\n");
|
|
|
|
} else if (s == BURN_DISC_EMPTY)
|
|
|
|
sprintf(respt+strlen(respt), "is not present\n");
|
|
|
|
else
|
|
|
|
sprintf(respt+strlen(respt), "is not recognizable\n");
|
|
|
|
Xorriso_result(xorriso,0);
|
|
|
|
|
2007-10-17 21:42:37 +00:00
|
|
|
if(s != BURN_DISC_FULL && s != BURN_DISC_APPENDABLE)
|
2007-10-17 18:30:37 +00:00
|
|
|
return(1);
|
|
|
|
|
2007-11-06 16:32:39 +00:00
|
|
|
if(xorriso->request_to_abort)
|
|
|
|
return(1);
|
|
|
|
|
2007-10-17 18:30:37 +00:00
|
|
|
disc= burn_drive_get_disc(drive);
|
|
|
|
if (disc==NULL) {
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-10-17 21:42:37 +00:00
|
|
|
|
|
|
|
#define Xorriso_with_isoburn_get_min_start_bytE 1
|
|
|
|
#ifdef Xorriso_with_isoburn_get_min_start_bytE
|
|
|
|
{ off_t start_byte= 0;
|
|
|
|
ret= isoburn_get_min_start_byte(drive, &start_byte, 0);
|
|
|
|
nwa= start_byte / 2048;
|
|
|
|
}
|
|
|
|
#else
|
2007-10-17 18:30:37 +00:00
|
|
|
ret= isoburn_disc_track_lba_nwa(drive, NULL, 0, &lba, &nwa);
|
2007-10-17 21:42:37 +00:00
|
|
|
#endif
|
|
|
|
|
2007-10-17 18:30:37 +00:00
|
|
|
if(ret<=0) {
|
2007-11-02 14:36:26 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
if(flag&1)
|
|
|
|
return(0);
|
2007-10-17 18:30:37 +00:00
|
|
|
sprintf(xorriso->info_text, "Cannot obtain Table Of Content");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
/* fabricate TOC */
|
|
|
|
sprintf(respt, "Media content: session %2d ", 1);
|
|
|
|
sprintf(respt+strlen(respt), "track %2d %s lba: %9d\n", 1, "data ", 0);
|
2007-11-02 14:36:26 +00:00
|
|
|
if(!(flag&1))
|
|
|
|
Xorriso_result(xorriso,0);
|
2007-10-17 18:30:37 +00:00
|
|
|
last_track_start= lba;
|
|
|
|
sprintf(respt, "Media content: session %2d ", 1);
|
|
|
|
sprintf(respt+strlen(respt), "leadout lba: %9d\n", nwa);
|
2007-11-02 14:36:26 +00:00
|
|
|
if(!(flag&1))
|
|
|
|
Xorriso_result(xorriso,0);
|
|
|
|
num_data= last_track_size= nwa;
|
|
|
|
num_sessions= 1;
|
2007-10-17 18:30:37 +00:00
|
|
|
} else {
|
|
|
|
sessions= burn_disc_get_sessions(disc, &num_sessions);
|
2007-11-06 16:32:39 +00:00
|
|
|
for (session_no= 0; session_no<num_sessions && !(xorriso->request_to_abort);
|
|
|
|
session_no++) {
|
2007-10-17 18:30:37 +00:00
|
|
|
tracks = burn_session_get_tracks(sessions[session_no], &num_tracks);
|
|
|
|
if (tracks==NULL)
|
|
|
|
continue;
|
2007-11-06 16:32:39 +00:00
|
|
|
for(track_no= 0; track_no<num_tracks && !(xorriso->request_to_abort);
|
|
|
|
track_no++) {
|
2007-10-17 18:30:37 +00:00
|
|
|
track_count++;
|
2007-11-02 14:36:26 +00:00
|
|
|
is_data= 0;
|
2007-10-17 18:30:37 +00:00
|
|
|
burn_track_get_entry(tracks[track_no], &toc_entry);
|
|
|
|
if (toc_entry.extensions_valid & 1) {
|
|
|
|
/* DVD extension valid */
|
|
|
|
lba= toc_entry.start_lba;
|
|
|
|
} else {
|
|
|
|
lba= burn_msf_to_lba(toc_entry.pmin, toc_entry.psec, toc_entry.pframe);
|
|
|
|
}
|
|
|
|
sprintf(respt, "Media content: session %2d ", session_no+1);
|
|
|
|
sprintf(respt+strlen(respt), "track %2d %s lba: %9d\n",
|
|
|
|
track_count, ((toc_entry.control&7)<4?"audio":"data "), lba);
|
2007-11-02 14:36:26 +00:00
|
|
|
if(!(flag&1))
|
|
|
|
Xorriso_result(xorriso,0);
|
2007-10-17 18:30:37 +00:00
|
|
|
last_track_start= lba;
|
2007-11-02 14:36:26 +00:00
|
|
|
if((toc_entry.control&7)>=4) /* data track */
|
|
|
|
is_data= 1;
|
2007-10-17 18:30:37 +00:00
|
|
|
}
|
|
|
|
burn_session_get_leadout_entry(sessions[session_no], &toc_entry);
|
|
|
|
if (toc_entry.extensions_valid & 1) {
|
|
|
|
lba= toc_entry.start_lba;
|
|
|
|
burn_lba_to_msf(lba, &pmin, &psec, &pframe);
|
|
|
|
} else {
|
|
|
|
lba= burn_msf_to_lba(pmin, psec, pframe);
|
|
|
|
lba= burn_msf_to_lba(toc_entry.pmin, toc_entry.psec, toc_entry.pframe);
|
|
|
|
}
|
|
|
|
sprintf(respt, "Media content: session %2d ", session_no+1);
|
2007-10-17 20:02:45 +00:00
|
|
|
sprintf(respt+strlen(respt), "leadout lba: %9d\n", lba);
|
2007-11-02 14:36:26 +00:00
|
|
|
if(!(flag&1))
|
|
|
|
Xorriso_result(xorriso,0);
|
2007-10-17 18:30:37 +00:00
|
|
|
last_track_size= lba - last_track_start;
|
2007-11-02 14:36:26 +00:00
|
|
|
if(is_data)
|
|
|
|
num_data+= last_track_size;
|
2007-10-17 18:30:37 +00:00
|
|
|
}
|
|
|
|
}
|
2007-11-06 16:32:39 +00:00
|
|
|
if(xorriso->request_to_abort)
|
|
|
|
return(1);
|
2007-12-04 21:00:35 +00:00
|
|
|
Sfile_scale(((double) num_data) * 2048.0, mem_text,5,1e4,1);
|
2007-12-08 17:52:32 +00:00
|
|
|
sprintf(respt, "Media summary: %d session%s, %d data blocks, %s\n",
|
2007-12-04 21:00:35 +00:00
|
|
|
num_sessions, (num_sessions==1 ? "" : "s"), num_data, mem_text);
|
2007-11-02 14:36:26 +00:00
|
|
|
Xorriso_result(xorriso,0);
|
2007-10-17 18:30:37 +00:00
|
|
|
|
2007-11-02 14:36:26 +00:00
|
|
|
if (s == BURN_DISC_APPENDABLE && nwa!=0) {
|
2007-10-17 21:42:37 +00:00
|
|
|
ret= isoburn_disc_track_lba_nwa(drive, NULL, 0, &lba, &nwa);
|
|
|
|
if(ret>0) {
|
|
|
|
sprintf(respt, "Media nwa : %ds\n", nwa);
|
2007-11-02 14:36:26 +00:00
|
|
|
if(!(flag&1))
|
|
|
|
Xorriso_result(xorriso,0);
|
2007-10-17 21:42:37 +00:00
|
|
|
}
|
2007-10-17 18:30:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (disc!=NULL)
|
|
|
|
burn_disc_free(disc);
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
2007-10-18 17:14:09 +00:00
|
|
|
|
|
|
|
int Xorriso_show_devices(struct XorrisO *xorriso, int flag)
|
|
|
|
{
|
|
|
|
char adr[BURN_DRIVE_ADR_LEN];
|
|
|
|
int i;
|
|
|
|
struct burn_drive_info *drive_list= NULL;
|
|
|
|
unsigned int drive_count;
|
|
|
|
char *respt, perms[8];
|
|
|
|
struct stat stbuf;
|
|
|
|
|
|
|
|
sprintf(xorriso->info_text, "Beginning to scan for devices ...\n");
|
|
|
|
Xorriso_info(xorriso,0);
|
|
|
|
|
|
|
|
burn_drive_clear_whitelist();
|
|
|
|
while(!burn_drive_scan(&drive_list, &drive_count)) {
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
usleep(100000);
|
|
|
|
}
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
if(drive_count <= 0) {
|
|
|
|
|
|
|
|
/* >>> was a drive_list created at all ? */
|
|
|
|
/* >>> must it be freed ? */
|
|
|
|
|
|
|
|
sprintf(xorriso->info_text, "No drives found");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
sprintf(xorriso->info_text, "Full drive scan done\n");
|
|
|
|
Xorriso_info(xorriso,0);
|
|
|
|
|
|
|
|
respt= xorriso->result_line;
|
2007-11-06 16:32:39 +00:00
|
|
|
for(i= 0; i < drive_count && !(xorriso->request_to_abort); i++) {
|
2007-10-18 17:14:09 +00:00
|
|
|
if(burn_drive_get_adr(&(drive_list[i]), adr)<=0)
|
|
|
|
strcpy(adr, "-get_adr_failed-");
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
if(stat(adr,&stbuf)==-1) {
|
|
|
|
sprintf(perms,"errno=%d",errno);
|
|
|
|
} else {
|
|
|
|
strcpy(perms,"------");
|
|
|
|
if(stbuf.st_mode&S_IRUSR) perms[0]= 'r';
|
|
|
|
if(stbuf.st_mode&S_IWUSR) perms[1]= 'w';
|
|
|
|
if(stbuf.st_mode&S_IRGRP) perms[2]= 'r';
|
|
|
|
if(stbuf.st_mode&S_IWGRP) perms[3]= 'w';
|
|
|
|
if(stbuf.st_mode&S_IROTH) perms[4]= 'r';
|
|
|
|
if(stbuf.st_mode&S_IWOTH) perms[5]= 'w';
|
|
|
|
}
|
|
|
|
sprintf(respt, "%d -dev '%s' %s : '%-8.8s' '%s' \n",
|
|
|
|
i, adr, perms, drive_list[i].vendor, drive_list[i].product);
|
|
|
|
Xorriso_result(xorriso,0);
|
|
|
|
}
|
|
|
|
burn_drive_info_free(drive_list);
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-20 19:48:36 +00:00
|
|
|
int Xorriso_tell_media_space(struct XorrisO *xorriso,
|
|
|
|
int *media_space, int *free_space, int flag)
|
2007-10-18 18:32:32 +00:00
|
|
|
{
|
2007-10-20 19:48:36 +00:00
|
|
|
int ret;
|
2007-10-18 18:32:32 +00:00
|
|
|
struct burn_drive_info *dinfo;
|
|
|
|
struct burn_drive *drive;
|
|
|
|
struct burn_write_opts *burn_options;
|
|
|
|
|
2007-10-20 19:48:36 +00:00
|
|
|
(*free_space)= (*media_space)= 0;
|
|
|
|
|
2007-10-18 18:32:32 +00:00
|
|
|
ret= Xorriso_get_drive_handles(xorriso, &dinfo, &drive,
|
|
|
|
"on attempt to -tell_media_space", 2);
|
|
|
|
if(ret<=0)
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
ret= Xorriso_make_write_options(xorriso, drive, &burn_options, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
return(-1);
|
2007-10-20 19:48:36 +00:00
|
|
|
(*free_space)= (*media_space)=
|
|
|
|
burn_disc_available_space(drive, burn_options) / (off_t) 2048;
|
2007-10-18 18:32:32 +00:00
|
|
|
burn_write_opts_free(burn_options);
|
|
|
|
|
2007-10-20 19:48:36 +00:00
|
|
|
if(xorriso->volset_change_pending) {
|
2007-11-14 14:28:44 +00:00
|
|
|
ret= Xorriso_write_session(xorriso, 1);
|
2007-10-20 19:48:36 +00:00
|
|
|
if(ret>0)
|
|
|
|
(*free_space)-= ret;
|
|
|
|
}
|
2007-10-19 20:41:34 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-10-20 19:48:36 +00:00
|
|
|
return(1);
|
2007-10-18 18:32:32 +00:00
|
|
|
}
|
|
|
|
|
2007-10-19 20:41:34 +00:00
|
|
|
|
2007-10-20 17:10:04 +00:00
|
|
|
/* @param flag bit0=fast , bit1=deformat
|
|
|
|
@return 0=failure, did not touch media , -1=failure, altered media
|
|
|
|
1=success, altered media , 2=success, did not touch media
|
|
|
|
*/
|
2007-10-19 20:41:34 +00:00
|
|
|
int Xorriso_blank_media(struct XorrisO *xorriso, int flag)
|
|
|
|
{
|
2007-10-20 17:10:04 +00:00
|
|
|
int ret, do_deformat= 0;
|
2007-10-19 20:41:34 +00:00
|
|
|
struct burn_drive_info *dinfo;
|
|
|
|
struct burn_drive *drive;
|
|
|
|
enum burn_disc_status disc_state;
|
|
|
|
struct burn_progress p;
|
|
|
|
double percent = 1.0;
|
|
|
|
int current_profile;
|
|
|
|
char current_profile_name[80];
|
2007-10-20 17:10:04 +00:00
|
|
|
char mode_names[4][80]= {"all", "fast", "deformat", "deformat_quickest"};
|
2007-10-19 20:41:34 +00:00
|
|
|
|
|
|
|
ret= Xorriso_get_drive_handles(xorriso, &dinfo, &drive,
|
|
|
|
"on attempt to -blank", 2);
|
|
|
|
if(ret<=0)
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
burn_disc_get_profile(drive, ¤t_profile, current_profile_name);
|
|
|
|
|
|
|
|
/* >>> */;
|
|
|
|
|
|
|
|
disc_state = isoburn_disc_get_status(drive);
|
2007-10-20 17:10:04 +00:00
|
|
|
if(current_profile == 0x13) { /* overwriteable DVD-RW */
|
|
|
|
/* Depending on flag bit1 formatted DVD-RW will get blanked to sequential
|
|
|
|
state or pseudo blanked by invalidating an eventual ISO image. */
|
|
|
|
if(flag&2)
|
|
|
|
do_deformat= 1;
|
|
|
|
} else if(current_profile == 0x14) { /* sequential DVD-RW */
|
|
|
|
if((flag&1) && !(flag&2)) {
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"-blank: DVD-RW present. Mode 'fast' defaulted to mode 'all'.");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Mode 'deformat_quickest' produces single-session-only media.");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "HINT", 0);
|
|
|
|
flag&= ~1;
|
|
|
|
}
|
2007-10-19 20:41:34 +00:00
|
|
|
} else if(disc_state == BURN_DISC_BLANK) {
|
|
|
|
sprintf(xorriso->info_text,"Blank media detected. Will leave it untouched");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
|
|
|
|
return 2;
|
|
|
|
} else if(disc_state==BURN_DISC_FULL || disc_state==BURN_DISC_APPENDABLE) {
|
|
|
|
;
|
|
|
|
} else if(disc_state == BURN_DISC_EMPTY) {
|
|
|
|
sprintf(xorriso->info_text,"No media detected in drive");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
sprintf(xorriso->info_text, "Unsuitable drive and media state");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if(!isoburn_disc_erasable(drive)) {
|
|
|
|
sprintf(xorriso->info_text, "Media is not of erasable type");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
return 0;
|
|
|
|
}
|
2007-10-20 17:10:04 +00:00
|
|
|
if(xorriso->do_dummy) {
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"-dummy mode prevents blanking of media in mode '%s'.",
|
|
|
|
mode_names[flag&3]);
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
sprintf(xorriso->info_text, "Beginning to blank media in mode '%s'.\n",
|
|
|
|
mode_names[flag&3]);
|
2007-10-19 20:41:34 +00:00
|
|
|
Xorriso_info(xorriso,0);
|
2007-10-20 17:10:04 +00:00
|
|
|
|
|
|
|
if(do_deformat)
|
|
|
|
burn_disc_erase(drive, (flag&1));
|
|
|
|
else
|
|
|
|
isoburn_disc_erase(drive, (flag&1));
|
2007-10-19 20:41:34 +00:00
|
|
|
usleep(1000000);
|
|
|
|
while (burn_drive_get_status(drive, &p) != BURN_DRIVE_IDLE) {
|
|
|
|
if(p.sectors>0 && p.sector>=0) /* display 1 to 99 percent */
|
|
|
|
percent = 1.0 + ((double) p.sector+1.0) / ((double) p.sectors) * 98.0;
|
|
|
|
sprintf(xorriso->info_text, "Blanking ( %.1f%% done )", percent);
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "UPDATE", 0);
|
|
|
|
usleep(1000000);
|
|
|
|
}
|
2007-10-20 17:10:04 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-10-19 20:41:34 +00:00
|
|
|
sprintf(xorriso->info_text, "Blanking done\n");
|
|
|
|
Xorriso_info(xorriso,0);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
2007-10-20 17:10:04 +00:00
|
|
|
/* @return 0=failure, did not touch media , -1=failure, altered media
|
|
|
|
1=success, altered media , 2=success, did not touch media
|
|
|
|
*/
|
2007-10-19 20:41:34 +00:00
|
|
|
int Xorriso_format_media(struct XorrisO *xorriso, int flag)
|
|
|
|
{
|
2007-10-20 17:10:04 +00:00
|
|
|
int ret, mode_flag= 0;
|
|
|
|
struct burn_drive_info *dinfo;
|
|
|
|
struct burn_drive *drive;
|
|
|
|
int current_profile;
|
|
|
|
char current_profile_name[80];
|
|
|
|
|
|
|
|
ret= Xorriso_get_drive_handles(xorriso, &dinfo, &drive,
|
|
|
|
"on attempt to -format", 2);
|
|
|
|
if(ret<=0)
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
burn_disc_get_profile(drive, ¤t_profile, current_profile_name);
|
|
|
|
if(current_profile == 0x14) {
|
|
|
|
; /* ok DVD-RW sequential */
|
|
|
|
} else if(current_profile == 0x1a) {
|
|
|
|
mode_flag= 2;
|
|
|
|
} else {
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Can only -format DVD+RW and sequential DVD-RW");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
sprintf(xorriso->info_text,"Media current: %s (%4.4xh)",
|
|
|
|
current_profile_name, current_profile);
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(xorriso->do_dummy) {
|
|
|
|
sprintf(xorriso->info_text, "-dummy mode prevents formatting of media.");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
sprintf(xorriso->info_text, "Beginning to format media.\n");
|
|
|
|
Xorriso_info(xorriso, 0);
|
|
|
|
burn_disc_format(drive, (off_t) 0, mode_flag);
|
|
|
|
|
|
|
|
ret= Xorriso_pacifier_loop(xorriso, drive, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
|
|
|
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
sprintf(xorriso->info_text, "Formatting done\n");
|
|
|
|
Xorriso_info(xorriso,0);
|
2007-10-19 20:41:34 +00:00
|
|
|
return(1);
|
|
|
|
}
|
2007-10-21 09:48:17 +00:00
|
|
|
|
|
|
|
|
2008-02-03 13:16:18 +00:00
|
|
|
int Xorriso_cannot_create_iter(struct XorrisO *xorriso, int iso_error,int flag)
|
|
|
|
{
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
Xorriso_report_iso_error(xorriso, iso_error, "Cannot create iter", 0,
|
|
|
|
"FATAL", 1);
|
|
|
|
sprintf(xorriso->info_text, "Cannot create IsoDirIter object");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-07 12:37:19 +00:00
|
|
|
/* @param boss_iter If not NULL then this is an iterator suitable for
|
2008-01-26 00:26:57 +00:00
|
|
|
iso_dir_iter_remove() which is then to be used instead
|
|
|
|
of iso_node_remove().
|
2007-11-07 12:37:19 +00:00
|
|
|
@param flag bit0= remove whole sub tree: rm -r
|
2007-11-06 16:32:39 +00:00
|
|
|
bit1= remove empty directory: rmdir
|
2007-11-07 12:37:19 +00:00
|
|
|
bit2= recursion: do not reassure in mode 2 "tree"
|
|
|
|
bit3= this is for overwriting and not for plain removal
|
2007-10-21 12:42:27 +00:00
|
|
|
@return <=0 = error
|
|
|
|
1 = removed simple node
|
|
|
|
2 = removed directory or tree
|
2007-11-07 12:37:19 +00:00
|
|
|
3 = did not remove on user revocation
|
2007-10-21 09:48:17 +00:00
|
|
|
*/
|
2007-11-07 12:37:19 +00:00
|
|
|
int Xorriso_rmi(struct XorrisO *xorriso, void *boss_iter,
|
|
|
|
char *path, int flag)
|
2007-10-21 09:48:17 +00:00
|
|
|
{
|
2007-11-11 11:21:46 +00:00
|
|
|
int ret, is_dir= 0, pl, not_removed= 0, fret;
|
2008-01-26 00:26:57 +00:00
|
|
|
IsoNode *victim_node, *node;
|
|
|
|
IsoDir *boss_node, *root_dir;
|
|
|
|
IsoDirIter *iter= NULL;
|
|
|
|
IsoImage *volume;
|
2007-12-28 13:28:48 +00:00
|
|
|
char *sub_name, *name;
|
|
|
|
|
|
|
|
#ifdef Xorriso_fat_local_meM
|
|
|
|
char sfe[5*SfileadrL], sub_path[2*SfileadrL];
|
|
|
|
#else
|
|
|
|
char *sfe= NULL, *sub_path= NULL;
|
|
|
|
|
|
|
|
/* Avoiding large local memory objects in order to save stack space */
|
|
|
|
sfe= malloc(5*SfileadrL);
|
|
|
|
sub_path= malloc(2*SfileadrL);
|
|
|
|
if(sfe==NULL || sub_path==NULL) {
|
|
|
|
Xorriso_no_malloc_memory(xorriso, &sfe, 0);
|
|
|
|
{ret= -1; goto ex;}
|
|
|
|
}
|
|
|
|
#endif /* ! Xorriso_fat_local_meM */
|
2007-10-21 09:48:17 +00:00
|
|
|
|
|
|
|
ret= Xorriso_get_volume(xorriso, &volume, 0);
|
|
|
|
if(ret<=0)
|
2007-11-07 12:37:19 +00:00
|
|
|
goto ex;
|
2007-10-19 20:41:34 +00:00
|
|
|
|
2007-11-06 16:32:39 +00:00
|
|
|
if(Xorriso_much_too_long(xorriso, strlen(path), 0)<=0)
|
2007-11-07 12:37:19 +00:00
|
|
|
{ret= 0; goto ex;}
|
2007-10-21 12:42:27 +00:00
|
|
|
ret= Xorriso_node_from_path(xorriso, volume, path, &victim_node, 0);
|
|
|
|
if(ret<=0)
|
2007-11-07 12:37:19 +00:00
|
|
|
goto ex;
|
2008-01-26 00:26:57 +00:00
|
|
|
root_dir= iso_image_get_root(volume);
|
2007-11-07 12:37:19 +00:00
|
|
|
if(((void *) root_dir) == ((void *) victim_node)) {
|
|
|
|
sprintf(xorriso->info_text, "May not delete root directory");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
2007-12-28 13:28:48 +00:00
|
|
|
{ret= 0; goto ex;}
|
2007-11-07 12:37:19 +00:00
|
|
|
}
|
2007-10-21 09:48:17 +00:00
|
|
|
|
|
|
|
if(LIBISO_ISDIR(victim_node))
|
|
|
|
is_dir= 1;
|
2007-11-07 15:01:20 +00:00
|
|
|
if(!is_dir) {
|
|
|
|
if(flag&2) { /* rmdir */
|
|
|
|
sprintf(xorriso->info_text, "%s in loaded ISO image is not a directory",
|
|
|
|
Text_shellsafe(path, sfe, 0));
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
ret= 0; goto ex;
|
|
|
|
}
|
|
|
|
} else {
|
2007-11-07 12:37:19 +00:00
|
|
|
if(flag&1) { /* rm -r */
|
|
|
|
if(xorriso->do_reassure==1 && !xorriso->request_not_to_ask) {
|
|
|
|
/* Iterate over subordinates and delete them */
|
|
|
|
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= iso_dir_get_children((IsoDir *) victim_node, &iter);
|
2007-11-07 12:37:19 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2008-01-26 00:26:57 +00:00
|
|
|
if(ret<0) {
|
|
|
|
cannot_create_iter:;
|
2008-02-03 13:16:18 +00:00
|
|
|
Xorriso_cannot_create_iter(xorriso, ret, 0);
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= -1; goto ex;
|
|
|
|
}
|
2007-11-07 12:37:19 +00:00
|
|
|
pl= strlen(path);
|
|
|
|
strcpy(sub_path, path);
|
|
|
|
if(pl==0 || sub_path[pl-1]!='/') {
|
|
|
|
sub_path[pl++]= '/';
|
|
|
|
sub_path[pl]= 0;
|
|
|
|
}
|
|
|
|
sub_name= sub_path+pl;
|
2008-01-26 00:26:57 +00:00
|
|
|
while(iso_dir_iter_next(iter, &node) == 1
|
|
|
|
&& !xorriso->request_to_abort) {
|
|
|
|
name= (char *) iso_node_get_name(node);
|
2007-11-07 12:37:19 +00:00
|
|
|
if(Xorriso_much_too_long(xorriso, pl+1+strlen(name), 0)<=0)
|
2007-11-11 11:21:46 +00:00
|
|
|
{ret= 0; goto rm_r_problem_handler;}
|
2007-11-07 12:37:19 +00:00
|
|
|
strcpy(sub_name, name);
|
|
|
|
ret= Xorriso_rmi(xorriso, iter, sub_path, (flag&(1|2|8))|4);
|
2007-11-11 11:21:46 +00:00
|
|
|
if(ret==3 || ret<=0 || xorriso->request_to_abort) {
|
|
|
|
rm_r_problem_handler:;
|
2007-11-07 12:37:19 +00:00
|
|
|
not_removed= 1;
|
2007-11-11 11:21:46 +00:00
|
|
|
fret= Xorriso_eval_problem_status(xorriso, ret, 1|2);
|
|
|
|
if(fret<0)
|
|
|
|
goto dir_not_removed;
|
|
|
|
}
|
2007-11-07 12:37:19 +00:00
|
|
|
}
|
|
|
|
if(not_removed) {
|
2007-11-11 11:21:46 +00:00
|
|
|
dir_not_removed:;
|
|
|
|
sprintf(xorriso->info_text, "Directory not removed: %s",
|
|
|
|
Text_shellsafe(path, sfe, 0));
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
|
|
|
|
if(ret>0)
|
|
|
|
ret= 3;
|
|
|
|
goto ex;
|
2007-11-07 12:37:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2007-10-21 09:48:17 +00:00
|
|
|
if(!(flag&2)) { /* not rmdir */
|
|
|
|
sprintf(xorriso->info_text, "%s in loaded ISO image is a directory",
|
|
|
|
Text_shellsafe(path, sfe, 0));
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
2007-11-07 12:37:19 +00:00
|
|
|
ret= 0; goto ex;
|
2007-10-21 09:48:17 +00:00
|
|
|
}
|
|
|
|
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= iso_dir_get_children((IsoDir *) victim_node, &iter);
|
2007-11-07 12:37:19 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2008-01-26 00:26:57 +00:00
|
|
|
if(ret<0)
|
|
|
|
goto cannot_create_iter;
|
|
|
|
if(ret>0) {
|
|
|
|
if(iso_dir_iter_next(iter, &node) == 1) {
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Directory not empty on attempt to delete: %s",
|
|
|
|
Text_shellsafe(path, sfe, 0));
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
ret= 0; goto ex;
|
|
|
|
}
|
2007-11-07 12:37:19 +00:00
|
|
|
}
|
2007-10-21 09:48:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-07 12:37:19 +00:00
|
|
|
if(xorriso->request_to_abort)
|
|
|
|
{ret= 3; goto ex;}
|
2008-01-26 00:26:57 +00:00
|
|
|
boss_node= iso_node_get_parent(victim_node);
|
2007-10-21 09:48:17 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
if(boss_node==NULL) {
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Cannot find parent node of %s in loaded ISO image",
|
|
|
|
Text_shellsafe(path, sfe, 0));
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
2007-11-07 12:37:19 +00:00
|
|
|
ret= 0; goto ex;
|
2007-10-21 09:48:17 +00:00
|
|
|
}
|
|
|
|
|
2007-11-07 12:37:19 +00:00
|
|
|
while((xorriso->do_reassure==1 || (xorriso->do_reassure==2 && !(flag&4)))
|
|
|
|
&& !xorriso->request_not_to_ask) {
|
2007-12-18 18:00:37 +00:00
|
|
|
/* ls -ld */
|
|
|
|
Xorriso_ls_filev(xorriso, xorriso->wdi, 1, &path, (off_t) 0, 1|2|8);
|
|
|
|
if(is_dir) /* du -s */
|
|
|
|
Xorriso_ls_filev(xorriso, xorriso->wdi, 1, &path, (off_t) 0, 2|4);
|
2007-11-07 12:37:19 +00:00
|
|
|
if(flag&8)
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"File exists. Remove ? n= keep old, y= remove, x= abort, @= stop asking\n");
|
|
|
|
else
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Remove above file ? n= keep it, y= remove it, x= abort, @= stop asking\n");
|
|
|
|
Xorriso_info(xorriso, 4);
|
2007-11-11 11:21:46 +00:00
|
|
|
ret= Xorriso_request_confirmation(xorriso, 1|2|4|16);
|
2007-11-07 12:37:19 +00:00
|
|
|
if(ret<=0)
|
|
|
|
goto ex;
|
|
|
|
if(xorriso->request_to_abort) {
|
2007-11-11 11:21:46 +00:00
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Removal operation aborted by user before file: %s",
|
|
|
|
Text_shellsafe(path, sfe, 0));
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
|
2007-11-07 12:37:19 +00:00
|
|
|
ret= 3; goto ex;
|
|
|
|
}
|
|
|
|
if(ret==3)
|
|
|
|
continue;
|
|
|
|
if(ret==6) /* yes */
|
|
|
|
break;
|
|
|
|
if(ret==4) { /* yes, do not ask again */
|
|
|
|
xorriso->request_not_to_ask= 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(ret==1) { /* no */
|
|
|
|
sprintf(xorriso->info_text, "Kept in existing state: %s",
|
|
|
|
Text_shellsafe(path, sfe, 0));
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
|
|
|
|
ret= 3; goto ex;
|
|
|
|
}
|
2007-11-06 16:32:39 +00:00
|
|
|
}
|
2007-10-21 09:48:17 +00:00
|
|
|
|
2007-11-07 12:37:19 +00:00
|
|
|
if(boss_iter!=NULL) {
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= iso_dir_iter_remove((IsoDirIter *) boss_iter);
|
2007-11-07 12:37:19 +00:00
|
|
|
if(ret<0)
|
|
|
|
ret= -1;
|
|
|
|
} else
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= iso_node_remove(victim_node);
|
2007-10-21 09:48:17 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2008-02-03 13:16:18 +00:00
|
|
|
if(ret<0) {
|
|
|
|
Xorriso_report_iso_error(xorriso, ret, "Cannot remove node", 0, "FATAL", 1);
|
2007-10-21 09:48:17 +00:00
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Internal failure to remove %s from loaded ISO image",
|
|
|
|
Text_shellsafe(path, sfe, 0));
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
2007-11-07 12:37:19 +00:00
|
|
|
ret= -1; goto ex;
|
2007-10-21 09:48:17 +00:00
|
|
|
}
|
|
|
|
xorriso->volset_change_pending= 1;
|
2007-11-07 12:37:19 +00:00
|
|
|
ret= 1+!!is_dir;
|
|
|
|
ex:;
|
2007-12-28 13:28:48 +00:00
|
|
|
|
|
|
|
#ifndef Xorriso_fat_local_meM
|
|
|
|
if(sfe!=NULL)
|
|
|
|
free(sfe);
|
|
|
|
if(sub_path!=NULL)
|
|
|
|
free(sub_path);
|
|
|
|
#endif /* ! Xorriso_fat_local_meM */
|
|
|
|
|
2007-11-07 12:37:19 +00:00
|
|
|
if(iter!=NULL)
|
2008-01-26 00:26:57 +00:00
|
|
|
iso_dir_iter_free(iter);
|
2007-11-07 12:37:19 +00:00
|
|
|
return(ret);
|
2007-10-21 09:48:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-01 19:11:56 +00:00
|
|
|
int Xorriso__node_name_cmp(const void *node1, const void *node2)
|
|
|
|
{
|
|
|
|
char *name1, *name2;
|
|
|
|
|
2008-01-26 00:26:57 +00:00
|
|
|
name1= (char *) iso_node_get_name(*((IsoNode **) node1));
|
|
|
|
name2= (char *) iso_node_get_name(*((IsoNode **) node2));
|
2007-11-01 19:11:56 +00:00
|
|
|
return(strcmp(name1,name2));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* @param flag bit0= only accept directory nodes
|
|
|
|
bit1= do not report memory usage as DEBUG
|
|
|
|
bit2= do not apply search pattern but accept any node
|
|
|
|
*/
|
|
|
|
int Xorriso_sorted_node_array(struct XorrisO *xorriso,
|
2008-01-26 00:26:57 +00:00
|
|
|
IsoDir *dir_node,
|
|
|
|
int *nodec, IsoNode ***node_array,
|
2007-11-01 19:11:56 +00:00
|
|
|
off_t boss_mem, int flag)
|
|
|
|
{
|
|
|
|
int i, ret, failed_at;
|
2007-12-04 07:44:59 +00:00
|
|
|
char *npt;
|
2008-01-26 00:26:57 +00:00
|
|
|
IsoDirIter *iter= NULL;
|
|
|
|
IsoNode *node;
|
2007-11-01 19:11:56 +00:00
|
|
|
off_t mem;
|
|
|
|
|
2008-01-26 00:26:57 +00:00
|
|
|
mem= ((*nodec)+1)*sizeof(IsoNode *);
|
2007-12-04 07:44:59 +00:00
|
|
|
ret= Xorriso_check_temp_mem_limit(xorriso, mem+boss_mem, flag&2);
|
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
2007-11-01 19:11:56 +00:00
|
|
|
|
2008-01-26 00:26:57 +00:00
|
|
|
*node_array= calloc(sizeof(IsoNode *), (*nodec)+1);
|
2007-11-01 19:11:56 +00:00
|
|
|
if(*node_array==NULL) {
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Cannot allocate memory for %d directory entries", *nodec);
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= iso_dir_get_children(dir_node, &iter);
|
|
|
|
if(ret<0) {
|
2008-02-03 13:16:18 +00:00
|
|
|
Xorriso_cannot_create_iter(xorriso, ret, 0);
|
2008-01-26 00:26:57 +00:00
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i= 0; iso_dir_iter_next(iter, &node) == 1 && i<*nodec; ) {
|
|
|
|
npt= (char *) iso_node_get_name(node);
|
2007-11-01 19:11:56 +00:00
|
|
|
if(!(flag&4)) {
|
|
|
|
ret= Xorriso_regexec(xorriso, npt, &failed_at, 0);
|
|
|
|
if(ret)
|
|
|
|
continue; /* no match */
|
|
|
|
}
|
|
|
|
if(flag&1)
|
|
|
|
if(!LIBISO_ISDIR(node))
|
|
|
|
continue;
|
|
|
|
(*node_array)[i++]= node;
|
|
|
|
}
|
2008-01-26 00:26:57 +00:00
|
|
|
iso_dir_iter_free(iter);
|
2007-11-01 19:11:56 +00:00
|
|
|
*nodec= i;
|
|
|
|
if(*nodec<=0)
|
|
|
|
return(1);
|
2008-01-26 00:26:57 +00:00
|
|
|
qsort(*node_array, *nodec, sizeof(IsoNode *), Xorriso__node_name_cmp);
|
2007-11-01 19:11:56 +00:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* @param flag bit0= do not only sum up sizes but also print subdirs
|
|
|
|
*/
|
2008-01-26 00:26:57 +00:00
|
|
|
int Xorriso_show_du_subs(struct XorrisO *xorriso, IsoDir *dir_node,
|
2007-11-01 19:11:56 +00:00
|
|
|
char *abs_path, char *rel_path, off_t *size,
|
|
|
|
off_t boss_mem, int flag)
|
|
|
|
{
|
|
|
|
int i, ret, no_sort= 0, filec= 0, l;
|
2008-01-26 00:26:57 +00:00
|
|
|
IsoDirIter *iter= NULL;
|
|
|
|
IsoNode *node, **node_array= NULL;
|
2007-12-28 13:28:48 +00:00
|
|
|
char *name;
|
2007-11-01 19:11:56 +00:00
|
|
|
off_t sub_size, report_size, mem= 0;
|
|
|
|
|
2007-12-28 13:28:48 +00:00
|
|
|
#ifdef Xorriso_fat_local_meM
|
|
|
|
char path[SfileadrL], show_path[SfileadrL], sfe[5*SfileadrL];
|
|
|
|
#else /* Xorriso_fat_local_meM */
|
|
|
|
char *path= NULL, *show_path= NULL, *sfe= NULL;
|
|
|
|
|
|
|
|
sfe= malloc(5*SfileadrL);
|
|
|
|
path= malloc(SfileadrL);
|
|
|
|
show_path= malloc(SfileadrL);
|
|
|
|
if(path==NULL || show_path==NULL || sfe==NULL) {
|
|
|
|
Xorriso_no_malloc_memory(xorriso, &sfe, 0);
|
|
|
|
{ret= -1; goto ex;}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* ! Xorriso_fat_local_meM */
|
|
|
|
|
2007-11-01 19:11:56 +00:00
|
|
|
*size= 0;
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= iso_dir_get_children(dir_node, &iter);
|
|
|
|
if(ret<0) {
|
|
|
|
cannot_create_iter:;
|
2008-02-03 13:16:18 +00:00
|
|
|
Xorriso_cannot_create_iter(xorriso, ret, 0);
|
2007-11-01 19:11:56 +00:00
|
|
|
{ret= -1; goto ex;}
|
|
|
|
}
|
2008-01-26 00:26:57 +00:00
|
|
|
for(i= 0; iso_dir_iter_next(iter, &node) == 1; ) {
|
2007-11-01 19:11:56 +00:00
|
|
|
sub_size= 0;
|
2008-01-26 00:26:57 +00:00
|
|
|
name= (char *) iso_node_get_name(node);
|
2007-11-01 19:11:56 +00:00
|
|
|
strcpy(show_path, rel_path);
|
|
|
|
if(Sfile_add_to_path(show_path, name, 0)<=0)
|
|
|
|
goto much_too_long;
|
|
|
|
if(LIBISO_ISDIR(node)) {
|
|
|
|
strcpy(path, abs_path);
|
|
|
|
if(Sfile_add_to_path(path, name, 0)<=0) {
|
|
|
|
much_too_long:;
|
2007-11-06 16:32:39 +00:00
|
|
|
Xorriso_much_too_long(xorriso, strlen(path)+strlen(name)+1, 2);
|
2007-11-01 19:11:56 +00:00
|
|
|
{ret= -1; goto ex;}
|
|
|
|
}
|
|
|
|
filec++;
|
2007-11-11 11:21:46 +00:00
|
|
|
l= strlen(rel_path)+1;
|
|
|
|
mem+= l;
|
2007-11-01 19:11:56 +00:00
|
|
|
if(l % sizeof(char *))
|
|
|
|
mem+= sizeof(char *)-(l % sizeof(char *));
|
2007-12-16 14:47:26 +00:00
|
|
|
if(flag&1) /* diving and counting is done further below */
|
|
|
|
continue;
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= Xorriso_show_du_subs(xorriso, (IsoDir *) node,
|
2007-11-01 19:11:56 +00:00
|
|
|
path, show_path, &sub_size, boss_mem, 0);
|
|
|
|
if(ret<0)
|
|
|
|
goto ex;
|
|
|
|
if(ret==0)
|
|
|
|
continue;
|
|
|
|
}
|
2008-01-26 00:26:57 +00:00
|
|
|
|
|
|
|
if(LIBISO_ISREG(node)) {
|
|
|
|
sub_size+= iso_file_get_size((IsoFile *) node)+2048;
|
2007-12-16 14:47:26 +00:00
|
|
|
/*
|
2008-01-26 00:26:57 +00:00
|
|
|
sub_size+= iso_file_get_size((IsoFile *) node)+strlen(name)+1;
|
2007-12-16 14:47:26 +00:00
|
|
|
*/
|
2008-01-26 00:26:57 +00:00
|
|
|
}
|
|
|
|
|
2007-11-01 19:11:56 +00:00
|
|
|
if(sub_size>0)
|
|
|
|
(*size)+= sub_size;
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(filec<=0 || !(flag&1))
|
|
|
|
{ret= 1; goto ex;}
|
|
|
|
|
|
|
|
/* Reset iteration */
|
2008-01-26 00:26:57 +00:00
|
|
|
iso_dir_iter_free(iter);
|
2007-11-01 19:11:56 +00:00
|
|
|
iter= NULL;
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
|
|
|
|
ret= Xorriso_sorted_node_array(xorriso, dir_node, &filec, &node_array,
|
|
|
|
boss_mem, 1|2|4);
|
|
|
|
if(ret<0)
|
|
|
|
goto ex;
|
|
|
|
if(ret==0) {
|
|
|
|
no_sort= 1;
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= iso_dir_get_children(dir_node, &iter);
|
|
|
|
if(ret<0)
|
|
|
|
goto cannot_create_iter;
|
2007-11-01 19:11:56 +00:00
|
|
|
}
|
|
|
|
|
2007-12-04 07:44:59 +00:00
|
|
|
for(i= 0; (no_sort || i<filec) && !(xorriso->request_to_abort); i++) {
|
2007-11-01 19:11:56 +00:00
|
|
|
if(no_sort) {
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= iso_dir_iter_next(iter, &node);
|
|
|
|
if(ret!=1)
|
2007-11-01 19:11:56 +00:00
|
|
|
break;
|
|
|
|
if(!LIBISO_ISDIR(node))
|
|
|
|
continue;
|
|
|
|
} else
|
|
|
|
node= node_array[i];
|
|
|
|
|
|
|
|
sub_size= 0;
|
2008-01-26 00:26:57 +00:00
|
|
|
name= (char *) iso_node_get_name(node);
|
2007-11-01 19:11:56 +00:00
|
|
|
strcpy(show_path, rel_path);
|
|
|
|
if(Sfile_add_to_path(show_path, name, 0)<=0)
|
|
|
|
goto much_too_long;
|
|
|
|
strcpy(path, abs_path);
|
|
|
|
if(Sfile_add_to_path(path, name, 0)<=0)
|
|
|
|
goto much_too_long;
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= Xorriso_show_du_subs(xorriso, (IsoDir *) node,
|
2007-11-01 19:11:56 +00:00
|
|
|
path, show_path, &sub_size, boss_mem+mem, flag&1);
|
|
|
|
if(ret<0)
|
|
|
|
goto ex;
|
2008-01-26 00:26:57 +00:00
|
|
|
|
|
|
|
if(LIBISO_ISREG(node)) {
|
|
|
|
sub_size+= iso_file_get_size((IsoFile *) node)+2048;
|
2007-12-16 14:47:26 +00:00
|
|
|
/*
|
2008-01-26 00:26:57 +00:00
|
|
|
sub_size+= iso_tree_node_get_size((IsoFile *) node)+strlen(name)+1;
|
2007-12-16 14:47:26 +00:00
|
|
|
*/
|
2008-01-26 00:26:57 +00:00
|
|
|
}
|
2007-12-16 14:47:26 +00:00
|
|
|
if(sub_size>0)
|
|
|
|
(*size)+= sub_size;
|
2007-11-01 19:11:56 +00:00
|
|
|
report_size= sub_size/1024;
|
|
|
|
if(report_size*1024<sub_size)
|
|
|
|
report_size++;
|
|
|
|
sprintf(xorriso->result_line, "%7.f ",(double) (report_size));
|
|
|
|
sprintf(xorriso->result_line+strlen(xorriso->result_line), "%s\n",
|
|
|
|
Text_shellsafe(show_path, sfe, 0));
|
|
|
|
Xorriso_result(xorriso, 0);
|
|
|
|
}
|
|
|
|
ret= 1;
|
|
|
|
ex:;
|
2007-12-28 13:28:48 +00:00
|
|
|
|
|
|
|
#ifndef Xorriso_fat_local_meM
|
|
|
|
if(sfe!=NULL)
|
|
|
|
free(sfe);
|
|
|
|
if(path!=NULL)
|
|
|
|
free(path);
|
|
|
|
if(show_path!=NULL)
|
|
|
|
free(show_path);
|
|
|
|
#endif /* ! Xorriso_fat_local_meM */
|
|
|
|
|
2007-11-01 19:11:56 +00:00
|
|
|
if(iter!=NULL)
|
2008-01-26 00:26:57 +00:00
|
|
|
iso_dir_iter_free(iter);
|
2007-11-01 19:11:56 +00:00
|
|
|
if(node_array!=NULL)
|
|
|
|
free((char *) node_array);
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-08 17:52:32 +00:00
|
|
|
/* @param flag bit0= *node is already valid */
|
|
|
|
int Xorriso_fake_stbuf(struct XorrisO *xorriso, char *path, struct stat *stbuf,
|
2008-01-26 00:26:57 +00:00
|
|
|
IsoNode **node, int flag)
|
2007-12-08 17:52:32 +00:00
|
|
|
{
|
|
|
|
int ret;
|
2008-01-26 00:26:57 +00:00
|
|
|
IsoImage *volume;
|
2007-12-08 17:52:32 +00:00
|
|
|
|
2007-12-21 13:16:49 +00:00
|
|
|
memset((char *) stbuf, 0, sizeof(struct stat));
|
2007-12-08 17:52:32 +00:00
|
|
|
if(!(flag&1)) {
|
|
|
|
ret= Xorriso_get_volume(xorriso, &volume, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
return(-1);
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= Xorriso_node_from_path(xorriso, volume, path, node, 1);
|
|
|
|
if(ret<=0)
|
|
|
|
*node= NULL;
|
2007-12-08 17:52:32 +00:00
|
|
|
}
|
|
|
|
if(*node==NULL)
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
/* >>> stbuf->st_dev */
|
|
|
|
/* >>> stbuf->st_ino */
|
|
|
|
|
2008-01-26 00:26:57 +00:00
|
|
|
stbuf->st_mode= iso_node_get_permissions(*node) & 07777;
|
2007-12-08 17:52:32 +00:00
|
|
|
if(LIBISO_ISDIR(*node))
|
|
|
|
stbuf->st_mode|= S_IFDIR;
|
|
|
|
else if(LIBISO_ISREG(*node))
|
|
|
|
stbuf->st_mode|= S_IFREG;
|
|
|
|
else if(LIBISO_ISLNK(*node))
|
|
|
|
stbuf->st_mode|= S_IFLNK;
|
2008-01-26 00:26:57 +00:00
|
|
|
else if(LIBISO_ISLNK(*node))
|
|
|
|
stbuf->st_mode|= S_IFCHR;
|
|
|
|
else if(LIBISO_ISBLK(*node))
|
|
|
|
stbuf->st_mode|= S_IFBLK;
|
|
|
|
else if(LIBISO_ISFIFO(*node))
|
|
|
|
stbuf->st_mode|= S_IFIFO;
|
|
|
|
else if(LIBISO_ISSOCK(*node))
|
|
|
|
stbuf->st_mode|= S_IFSOCK;
|
|
|
|
|
|
|
|
/* >>> NG How to represent LIBISO_BOOT ? */
|
|
|
|
|
2007-12-08 17:52:32 +00:00
|
|
|
|
|
|
|
/* >>> With directories this should be : number of subdirs + 2 */
|
|
|
|
/* >>> ??? How to obtain RR hardlink number for other types ? */
|
|
|
|
stbuf->st_nlink= 1;
|
|
|
|
|
2008-01-26 00:26:57 +00:00
|
|
|
stbuf->st_uid= iso_node_get_uid(*node);
|
|
|
|
stbuf->st_gid= iso_node_get_gid(*node);
|
2007-12-08 17:52:32 +00:00
|
|
|
|
|
|
|
/* >>> stbuf->st_rdev */
|
|
|
|
|
2008-01-26 00:26:57 +00:00
|
|
|
if(LIBISO_ISREG(*node))
|
|
|
|
stbuf->st_size= iso_file_get_size((IsoFile *) *node)+2048;
|
|
|
|
else
|
|
|
|
stbuf->st_size= 0;
|
2007-12-08 17:52:32 +00:00
|
|
|
|
|
|
|
stbuf->st_blksize= 2048;
|
|
|
|
stbuf->st_blocks= stbuf->st_size / (off_t) 2048;
|
|
|
|
if(stbuf->st_blocks * (off_t) 2048 != stbuf->st_size)
|
|
|
|
stbuf->st_blocks++;
|
|
|
|
|
2008-01-26 00:26:57 +00:00
|
|
|
stbuf->st_atime= iso_node_get_atime(*node);
|
|
|
|
stbuf->st_mtime= iso_node_get_mtime(*node);
|
|
|
|
stbuf->st_ctime= iso_node_get_ctime(*node);
|
2007-12-08 17:52:32 +00:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-26 00:26:57 +00:00
|
|
|
int Xorriso_sorted_dir_i(struct XorrisO *xorriso, IsoDir *dir_node,
|
2007-12-18 18:00:37 +00:00
|
|
|
int *filec, char ***filev, off_t boss_mem, int flag)
|
|
|
|
{
|
|
|
|
int i,j,ret;
|
2008-01-26 00:26:57 +00:00
|
|
|
IsoDirIter *iter= NULL;
|
|
|
|
IsoNode *node;
|
2007-12-18 18:00:37 +00:00
|
|
|
char *name;
|
|
|
|
off_t mem;
|
|
|
|
|
|
|
|
(*filec)= 0;
|
|
|
|
(*filev)= NULL;
|
|
|
|
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= iso_dir_get_children(dir_node, &iter);
|
|
|
|
if(ret<0) {
|
2007-12-18 18:00:37 +00:00
|
|
|
cannot_iter:;
|
2008-02-03 13:16:18 +00:00
|
|
|
Xorriso_cannot_create_iter(xorriso, ret, 0);
|
2007-12-18 18:00:37 +00:00
|
|
|
{ret= -1; goto ex;}
|
|
|
|
}
|
|
|
|
mem= 0;
|
2008-01-26 00:26:57 +00:00
|
|
|
for(i= 0; iso_dir_iter_next(iter, &node) == 1; ) {
|
|
|
|
name= (char *) iso_node_get_name(node);
|
2007-12-18 18:00:37 +00:00
|
|
|
mem+= sizeof(char *)+strlen(name)+8;
|
|
|
|
(*filec)++;
|
|
|
|
}
|
2008-01-26 00:26:57 +00:00
|
|
|
iso_dir_iter_free(iter);
|
|
|
|
iter= NULL;
|
2007-12-18 18:00:37 +00:00
|
|
|
if(*filec==0)
|
|
|
|
{ret= 1; goto ex;}
|
|
|
|
|
|
|
|
ret= Xorriso_check_temp_mem_limit(xorriso, mem+boss_mem, 2);
|
|
|
|
if(ret<=0)
|
|
|
|
goto ex;
|
|
|
|
(*filev)= (char **) calloc(*filec, sizeof(char *));
|
|
|
|
if(*filev==NULL)
|
|
|
|
{ret= -1; goto ex; }
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= iso_dir_get_children(dir_node, &iter);
|
|
|
|
if(ret<0)
|
2007-12-18 18:00:37 +00:00
|
|
|
goto cannot_iter;
|
|
|
|
for(i= 0; i<*filec; i++) {
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= iso_dir_iter_next(iter, &node);
|
|
|
|
if(ret!=1)
|
|
|
|
break;
|
|
|
|
name= (char *) iso_node_get_name(node);
|
2007-12-18 18:00:37 +00:00
|
|
|
(*filev)[i]= strdup(name);
|
|
|
|
if((*filev)[i]==NULL) {
|
|
|
|
for(j= 0; j<i; j++)
|
|
|
|
if((*filev)[j]!=NULL)
|
|
|
|
free((*filev)[j]);
|
|
|
|
free((char *) (*filev));
|
|
|
|
ret= -1; goto ex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Sort_argv(*filec, *filev, 0);
|
|
|
|
ret= 1;
|
|
|
|
ex:;
|
|
|
|
if(iter!=NULL)
|
2008-01-26 00:26:57 +00:00
|
|
|
iso_dir_iter_free(iter);
|
2007-12-18 18:00:37 +00:00
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-01 19:11:56 +00:00
|
|
|
/* @param flag bit0= long format
|
2007-11-07 12:37:19 +00:00
|
|
|
bit1= do not print count of nodes
|
2007-11-01 19:11:56 +00:00
|
|
|
bit2= du format
|
2007-12-18 18:00:37 +00:00
|
|
|
bit3= print directories as themselves (ls -d)
|
2007-11-01 19:11:56 +00:00
|
|
|
*/
|
2007-12-18 18:00:37 +00:00
|
|
|
int Xorriso_ls_filev(struct XorrisO *xorriso, char *wd,
|
|
|
|
int filec, char **filev, off_t boss_mem, int flag)
|
2007-10-29 21:41:17 +00:00
|
|
|
{
|
2007-12-18 18:00:37 +00:00
|
|
|
int i, ret, was_error= 0, dfilec= 0, pass, passes;
|
2008-01-26 00:26:57 +00:00
|
|
|
IsoNode *node;
|
|
|
|
IsoImage *volume;
|
2007-12-15 18:31:39 +00:00
|
|
|
char sfe[5*SfileadrL], sfe2[5*SfileadrL], path[SfileadrL];
|
2007-12-18 18:00:37 +00:00
|
|
|
char link_target[SfileadrL], *rpt, **dfilev= NULL;
|
2007-10-29 21:41:17 +00:00
|
|
|
off_t size;
|
2007-12-08 17:52:32 +00:00
|
|
|
struct stat stbuf;
|
2007-10-29 21:41:17 +00:00
|
|
|
|
|
|
|
rpt= xorriso->result_line;
|
|
|
|
|
|
|
|
ret= Xorriso_get_volume(xorriso, &volume, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
|
|
|
|
|
|
|
Sort_argv(filec, filev, 0);
|
|
|
|
|
2007-10-30 21:44:08 +00:00
|
|
|
/* Count valid nodes, warn of invalid ones */
|
2007-10-29 21:41:17 +00:00
|
|
|
for(i= 0; i<filec; i++) {
|
2008-01-11 13:37:26 +00:00
|
|
|
ret= Xorriso_make_abs_adr(xorriso, wd, filev[i], path, 1|2|4);
|
2007-12-08 17:52:32 +00:00
|
|
|
if(ret<=0) {
|
|
|
|
was_error++;
|
2007-10-29 21:41:17 +00:00
|
|
|
continue;
|
2007-12-08 17:52:32 +00:00
|
|
|
}
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= Xorriso_node_from_path(xorriso, volume, path, &node, 1);
|
|
|
|
if(ret<=0) {
|
2007-10-30 21:44:08 +00:00
|
|
|
sprintf(xorriso->info_text, "Not found in ISO image: %s",
|
2007-10-29 21:41:17 +00:00
|
|
|
Text_shellsafe(path, sfe, 0));
|
2007-10-30 21:44:08 +00:00
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0);
|
|
|
|
was_error++;
|
|
|
|
continue;
|
2007-10-29 21:41:17 +00:00
|
|
|
}
|
2007-10-30 21:44:08 +00:00
|
|
|
}
|
|
|
|
|
2007-12-18 18:00:37 +00:00
|
|
|
if((flag&8) && !(flag&(2|4))) {
|
2007-11-01 19:11:56 +00:00
|
|
|
sprintf(xorriso->info_text, "Valid ISO nodes found: %d\n", filec-was_error);
|
2007-11-11 11:21:46 +00:00
|
|
|
Xorriso_info(xorriso,1);
|
2007-11-01 19:11:56 +00:00
|
|
|
if(filec-was_error<=0)
|
|
|
|
return(!was_error);
|
|
|
|
}
|
2007-10-30 21:44:08 +00:00
|
|
|
|
2007-12-18 18:00:37 +00:00
|
|
|
passes= 1+!(flag&(4|8));
|
|
|
|
for(pass= 0; pass<passes; pass++)
|
2007-11-06 16:32:39 +00:00
|
|
|
for(i= 0; i<filec && !(xorriso->request_to_abort); i++) {
|
2007-12-08 17:52:32 +00:00
|
|
|
rpt[0]= 0;
|
2008-01-11 17:48:30 +00:00
|
|
|
ret= Xorriso_make_abs_adr(xorriso, wd, filev[i], path, 1|2|4);
|
2007-12-08 17:52:32 +00:00
|
|
|
if(ret<=0)
|
2007-10-30 21:44:08 +00:00
|
|
|
continue;
|
2007-12-08 17:52:32 +00:00
|
|
|
ret= Xorriso_fake_stbuf(xorriso, path, &stbuf, &node, 0);
|
|
|
|
if(ret<=0)
|
2007-12-18 18:00:37 +00:00
|
|
|
continue;
|
|
|
|
if(LIBISO_ISDIR(node) && !(flag&(4|8))) {
|
|
|
|
if(pass==0)
|
|
|
|
continue;
|
|
|
|
if(filec>1) {
|
|
|
|
strcpy(xorriso->result_line, "\n");
|
|
|
|
Xorriso_result(xorriso,0);
|
|
|
|
sprintf(xorriso->result_line, "%s:\n", Text_shellsafe(filev[i], sfe,0));
|
|
|
|
Xorriso_result(xorriso,0);
|
|
|
|
}
|
|
|
|
ret= Xorriso_sorted_dir_i(xorriso,
|
2008-01-26 00:26:57 +00:00
|
|
|
(IsoDir *) node, &dfilec, &dfilev, boss_mem, 0);
|
2007-12-18 18:00:37 +00:00
|
|
|
if(ret<=0) {
|
|
|
|
|
|
|
|
/* >>> libisofs iterator loop and single item Xorriso_lsx_filev() */;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if(flag&1) {
|
|
|
|
sprintf(xorriso->result_line, "total %d\n", dfilec);
|
|
|
|
Xorriso_result(xorriso,0);
|
|
|
|
}
|
|
|
|
Xorriso_ls_filev(xorriso, path,
|
|
|
|
dfilec, dfilev, boss_mem, (flag&1)|2|8);
|
|
|
|
}
|
|
|
|
if(dfilec>0)
|
|
|
|
Sfile_destroy_argv(&dfilec, &dfilev, 0);
|
|
|
|
continue;
|
|
|
|
} else
|
|
|
|
if(pass>0)
|
2007-10-30 21:44:08 +00:00
|
|
|
continue;
|
2007-12-15 18:31:39 +00:00
|
|
|
link_target[0]= 0;
|
2007-11-01 19:11:56 +00:00
|
|
|
if((flag&5)==1) { /* -ls_l */
|
2007-12-08 17:52:32 +00:00
|
|
|
ret= Xorriso_format_ls_l(xorriso, &stbuf, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
continue;
|
2007-12-15 18:31:39 +00:00
|
|
|
if(LIBISO_ISLNK(node)) {
|
2008-01-26 00:26:57 +00:00
|
|
|
if(Sfile_str(link_target, (char *) iso_symlink_get_dest(
|
|
|
|
(IsoSymlink *) node), 0)<=0)
|
2007-12-15 18:31:39 +00:00
|
|
|
link_target[0]= 0;
|
|
|
|
}
|
2007-12-20 11:14:49 +00:00
|
|
|
} else if(flag&4) { /* -du or -dus */
|
2007-12-08 17:52:32 +00:00
|
|
|
size= stbuf.st_size;
|
|
|
|
if(S_ISDIR(stbuf.st_mode)) {
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= Xorriso_show_du_subs(xorriso, (IsoDir *) node,
|
2007-11-01 19:11:56 +00:00
|
|
|
path, filev[i], &size, boss_mem, flag&1);
|
|
|
|
if(ret<0)
|
|
|
|
return(-1);
|
|
|
|
if(ret==0)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
sprintf(rpt, "%7.f ",(double) (size/1024));
|
2007-10-29 21:41:17 +00:00
|
|
|
}
|
2007-12-15 18:31:39 +00:00
|
|
|
if(link_target[0] && (flag&5)==1)
|
|
|
|
sprintf(xorriso->result_line+strlen(xorriso->result_line), "%s -> %s\n",
|
|
|
|
Text_shellsafe(filev[i], sfe, 0),
|
|
|
|
Text_shellsafe(link_target, sfe2, 0));
|
|
|
|
else
|
|
|
|
sprintf(xorriso->result_line+strlen(xorriso->result_line), "%s\n",
|
|
|
|
Text_shellsafe(filev[i], sfe, 0));
|
2007-10-29 21:41:17 +00:00
|
|
|
Xorriso_result(xorriso, 0);
|
|
|
|
}
|
2007-10-30 21:44:08 +00:00
|
|
|
return(!was_error);
|
2007-10-29 21:41:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-31 16:55:55 +00:00
|
|
|
/* This function needs less buffer memory than Xorriso_ls_filev() but cannot
|
2007-12-08 17:52:32 +00:00
|
|
|
perform structured pattern matching as done by Xorriso_expand_pattern()
|
|
|
|
for subsequent Xorriso_ls_filev().
|
2007-10-31 16:55:55 +00:00
|
|
|
@param flag bit0= long format
|
|
|
|
bit1= only check for directory existence
|
|
|
|
bit2= do not apply search pattern but accept any file
|
|
|
|
*/
|
2007-10-21 12:42:27 +00:00
|
|
|
int Xorriso_ls(struct XorrisO *xorriso, int flag)
|
|
|
|
{
|
2007-10-31 16:55:55 +00:00
|
|
|
int ret, is_dir= 0, i, filec= 0, failed_at, no_sort= 0;
|
2008-01-26 00:26:57 +00:00
|
|
|
IsoNode *node, **node_array= NULL;
|
|
|
|
IsoDir *dir_node;
|
|
|
|
IsoImage *volume;
|
|
|
|
IsoDirIter *iter= NULL;
|
2007-12-15 18:31:39 +00:00
|
|
|
char sfe[5*SfileadrL], sfe2[5*SfileadrL], link_target[SfileadrL], *npt, *rpt;
|
2007-12-08 17:52:32 +00:00
|
|
|
struct stat stbuf;
|
2007-10-22 21:18:13 +00:00
|
|
|
|
2007-10-21 12:42:27 +00:00
|
|
|
rpt= xorriso->result_line;
|
|
|
|
|
|
|
|
ret= Xorriso_get_volume(xorriso, &volume, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
|
|
|
|
|
|
|
ret= Xorriso_node_from_path(xorriso, volume, xorriso->wdi, &node, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
goto wdi_is_not_a_dir;
|
|
|
|
if(LIBISO_ISDIR(node))
|
|
|
|
is_dir= 1;
|
|
|
|
if(!is_dir) {
|
|
|
|
wdi_is_not_a_dir:;
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Working directory path does not lead to a directory in ISO image");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
2007-10-21 21:32:23 +00:00
|
|
|
ret= 0; goto ex;
|
2007-10-21 12:42:27 +00:00
|
|
|
}
|
|
|
|
if(flag&2)
|
2007-10-21 21:32:23 +00:00
|
|
|
{ret= 1; goto ex;}
|
2007-10-21 12:42:27 +00:00
|
|
|
|
2008-01-26 00:26:57 +00:00
|
|
|
dir_node= (IsoDir *) node;
|
|
|
|
ret= iso_dir_get_children(dir_node, &iter);
|
|
|
|
if(ret<0) {
|
|
|
|
cannot_create_iter:;
|
2008-02-03 13:16:18 +00:00
|
|
|
Xorriso_cannot_create_iter(xorriso, ret, 0);
|
2008-01-26 00:26:57 +00:00
|
|
|
{ret= -1; goto ex;}
|
|
|
|
}
|
2007-10-21 12:42:27 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
|
2008-01-26 00:26:57 +00:00
|
|
|
for(i= 0; iso_dir_iter_next(iter, &node) == 1; ) {
|
|
|
|
npt= (char *) iso_node_get_name(node);
|
2007-10-31 16:55:55 +00:00
|
|
|
if(!(flag&4)) {
|
|
|
|
ret= Xorriso_regexec(xorriso, npt, &failed_at, 0);
|
|
|
|
if(ret)
|
2007-10-21 21:32:23 +00:00
|
|
|
continue; /* no match */
|
2007-10-31 16:55:55 +00:00
|
|
|
}
|
2007-10-21 21:32:23 +00:00
|
|
|
filec++;
|
|
|
|
}
|
2007-10-31 16:55:55 +00:00
|
|
|
/* Reset iteration */
|
2008-01-26 00:26:57 +00:00
|
|
|
iso_dir_iter_free(iter);
|
2007-10-21 21:32:23 +00:00
|
|
|
iter= NULL;
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-10-31 16:55:55 +00:00
|
|
|
|
|
|
|
sprintf(xorriso->info_text, "Valid ISO nodes found: %d\n", filec);
|
2007-11-11 11:21:46 +00:00
|
|
|
Xorriso_info(xorriso,1);
|
2007-10-21 12:42:27 +00:00
|
|
|
|
2007-11-01 19:11:56 +00:00
|
|
|
ret= Xorriso_sorted_node_array(xorriso, dir_node, &filec, &node_array, 0,
|
|
|
|
flag&4);
|
|
|
|
if(ret<0)
|
|
|
|
goto ex;
|
|
|
|
if(ret==0) {
|
|
|
|
no_sort= 1;
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= iso_dir_get_children(dir_node, &iter);
|
|
|
|
if(ret<0)
|
|
|
|
goto cannot_create_iter;
|
2007-10-21 21:32:23 +00:00
|
|
|
}
|
2007-10-21 12:42:27 +00:00
|
|
|
|
2007-11-06 16:32:39 +00:00
|
|
|
for(i= 0; i<filec && !(xorriso->request_to_abort); i++) {
|
2007-10-31 16:55:55 +00:00
|
|
|
if(no_sort) {
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= iso_dir_iter_next(iter, &node);
|
|
|
|
if(ret!=1)
|
2007-10-31 16:55:55 +00:00
|
|
|
break;
|
2008-01-26 00:26:57 +00:00
|
|
|
npt= (char *) iso_node_get_name(node);
|
2007-10-31 16:55:55 +00:00
|
|
|
if(!(flag&4)) {
|
|
|
|
ret= Xorriso_regexec(xorriso, npt, &failed_at, 0);
|
|
|
|
if(ret)
|
|
|
|
continue; /* no match */
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
node= node_array[i];
|
|
|
|
|
2008-01-26 00:26:57 +00:00
|
|
|
npt= (char *) iso_node_get_name(node);
|
2007-12-15 18:31:39 +00:00
|
|
|
link_target[0]= 0;
|
|
|
|
if(LIBISO_ISLNK(node)) {
|
2008-01-26 00:26:57 +00:00
|
|
|
if(Sfile_str(link_target, (char *) iso_symlink_get_dest(
|
|
|
|
(IsoSymlink *) node), 0)<=0)
|
2007-12-15 18:31:39 +00:00
|
|
|
link_target[0]= 0;
|
|
|
|
}
|
2007-10-21 21:32:23 +00:00
|
|
|
rpt[0]= 0;
|
2007-10-22 21:18:13 +00:00
|
|
|
if(flag&1) {
|
2007-12-08 17:52:32 +00:00
|
|
|
ret= Xorriso_fake_stbuf(xorriso, "", &stbuf, &node, 1);
|
|
|
|
if(ret<=0)
|
|
|
|
continue;
|
|
|
|
ret= Xorriso_format_ls_l(xorriso, &stbuf, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
continue;
|
2007-10-21 12:42:27 +00:00
|
|
|
}
|
2007-12-15 18:31:39 +00:00
|
|
|
if(link_target[0] && (flag&1))
|
|
|
|
sprintf(xorriso->result_line+strlen(xorriso->result_line), "%s -> %s\n",
|
|
|
|
Text_shellsafe(npt, sfe, 0),
|
|
|
|
Text_shellsafe(link_target, sfe2, 0));
|
|
|
|
else
|
|
|
|
sprintf(xorriso->result_line+strlen(xorriso->result_line), "%s\n",
|
|
|
|
Text_shellsafe(npt, sfe, 0));
|
2007-10-21 12:42:27 +00:00
|
|
|
Xorriso_result(xorriso, 0);
|
|
|
|
}
|
|
|
|
|
2007-10-21 21:32:23 +00:00
|
|
|
ret= 1;
|
|
|
|
ex:;
|
|
|
|
if(iter!=NULL)
|
2008-01-26 00:26:57 +00:00
|
|
|
iso_dir_iter_free(iter);
|
2007-10-21 12:42:27 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-10-21 21:32:23 +00:00
|
|
|
if(node_array!=NULL)
|
|
|
|
free((char *) node_array);
|
2007-10-21 12:42:27 +00:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
2007-10-21 09:48:17 +00:00
|
|
|
|
2007-10-28 16:54:29 +00:00
|
|
|
int Xorriso_rename(struct XorrisO *xorriso, char *origin, char *dest, int flag)
|
2007-10-27 22:41:24 +00:00
|
|
|
{
|
2007-10-28 12:54:22 +00:00
|
|
|
int ret, ol, dest_ret;
|
2007-11-08 16:11:26 +00:00
|
|
|
char sfe[5*SfileadrL], eff_dest[SfileadrL], dir_adr[SfileadrL], *cpt;
|
2008-01-26 00:26:57 +00:00
|
|
|
char *leafname, eff_origin[SfileadrL], sfe2[5*SfileadrL], *old_leafname;
|
|
|
|
IsoImage *volume;
|
|
|
|
IsoDir *origin_dir, *dest_dir;
|
|
|
|
IsoNode *node, *iso_node;
|
2007-10-27 22:41:24 +00:00
|
|
|
|
2007-12-15 18:31:39 +00:00
|
|
|
ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, origin, eff_origin, 0);
|
2007-10-28 12:54:22 +00:00
|
|
|
if(ret<=0)
|
2007-10-27 22:41:24 +00:00
|
|
|
return(ret);
|
2007-12-15 18:31:39 +00:00
|
|
|
dest_ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, dest, eff_dest,1);
|
2007-10-28 12:54:22 +00:00
|
|
|
if(dest_ret<0)
|
|
|
|
return(dest_ret);
|
|
|
|
if(dest_ret==0) { /* obtain eff_dest address despite it does not exist */
|
2007-12-15 18:31:39 +00:00
|
|
|
ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, dest, eff_dest, 2);
|
2007-10-28 12:54:22 +00:00
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Prevent that destination is a subordinate of origin
|
|
|
|
(that would be a black hole plopping out of the universe) */
|
|
|
|
ol= strlen(eff_origin);
|
|
|
|
if(ol==0) {
|
|
|
|
sprintf(xorriso->info_text, "May not rename root directory");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
return(0);
|
|
|
|
} else if(strcmp(eff_origin, eff_dest)==0) {
|
|
|
|
sprintf(xorriso->info_text, "Ignored attempt to rename %s to itself",
|
|
|
|
Text_shellsafe(eff_origin,sfe,0));
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0);
|
|
|
|
return(0);
|
|
|
|
} else if(strncmp(eff_origin, eff_dest, ol)==0 &&
|
|
|
|
(eff_dest[ol]==0 || eff_dest[ol]=='/')) {
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"May not rename %s to its own sub address %s",
|
|
|
|
Text_shellsafe(eff_origin,sfe,0), Text_shellsafe(eff_dest,sfe2,0));
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check whether destination exists and may be not overwriteable */
|
2007-11-11 11:21:46 +00:00
|
|
|
if(dest_ret==2 && xorriso->do_overwrite!=1) {
|
|
|
|
sprintf(xorriso->info_text, "Renaming may not overwrite directory: %s",
|
2007-10-27 22:41:24 +00:00
|
|
|
Text_shellsafe(eff_dest, sfe, 0));
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
return(0);
|
2007-10-28 12:54:22 +00:00
|
|
|
} else if (dest_ret==1 && !xorriso->do_overwrite) {
|
2007-10-27 22:41:24 +00:00
|
|
|
sprintf(xorriso->info_text, "Renaming may not overwite: %s",
|
|
|
|
Text_shellsafe(eff_dest, sfe, 0));
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
return(0);
|
2007-10-28 12:54:22 +00:00
|
|
|
} else if(dest_ret>0) {
|
2007-11-11 11:21:46 +00:00
|
|
|
ret= Xorriso_rmi(xorriso, NULL, eff_dest, 1|8);
|
2007-10-27 22:41:24 +00:00
|
|
|
if(ret<=0)
|
|
|
|
return(0);
|
2007-11-07 12:37:19 +00:00
|
|
|
if(ret==3) {
|
|
|
|
sprintf(xorriso->info_text, "User revoked renaming of: %s",
|
|
|
|
Text_shellsafe(eff_origin, sfe, 0));
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
|
|
|
|
return(0);
|
|
|
|
}
|
2007-10-27 22:41:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Ensure existence of destination directory */
|
|
|
|
strcpy(dir_adr, eff_dest);
|
|
|
|
cpt= strrchr(dir_adr, '/');
|
|
|
|
if(cpt==NULL)
|
|
|
|
cpt= dir_adr+strlen(dir_adr);
|
|
|
|
*cpt= 0;
|
2007-10-28 12:54:22 +00:00
|
|
|
if(dir_adr[0]!=0) {
|
|
|
|
ret= Xorriso_graft_in(xorriso, NULL, dir_adr, 1);
|
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
|
|
|
}
|
2007-10-27 22:41:24 +00:00
|
|
|
|
|
|
|
/* Move node */
|
|
|
|
ret= Xorriso_get_volume(xorriso, &volume, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
2008-01-26 00:26:57 +00:00
|
|
|
Xorriso_node_from_path(xorriso, volume, dir_adr, &iso_node, 0);
|
|
|
|
dest_dir= (IsoDir *) iso_node;
|
2007-10-28 12:54:22 +00:00
|
|
|
strcpy(dir_adr, eff_origin);
|
2007-10-27 22:41:24 +00:00
|
|
|
cpt= strrchr(dir_adr, '/');
|
|
|
|
if(cpt==NULL)
|
|
|
|
cpt= dir_adr+strlen(dir_adr);
|
|
|
|
*cpt= 0;
|
2008-01-26 00:26:57 +00:00
|
|
|
Xorriso_node_from_path(xorriso, volume, dir_adr, &iso_node, 0);
|
|
|
|
origin_dir= (IsoDir *) iso_node;
|
|
|
|
Xorriso_node_from_path(xorriso, volume, eff_origin, &node, 0);
|
2007-10-27 22:41:24 +00:00
|
|
|
if(dest_dir==NULL || origin_dir==NULL || node==NULL) {
|
2007-10-28 12:54:22 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-10-27 22:41:24 +00:00
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Internal error on rename: confirmed node turns out as NULL");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
|
|
|
return(-1);
|
|
|
|
}
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= iso_node_take(node);
|
|
|
|
if(ret<0) {
|
2007-10-28 12:54:22 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2008-02-03 13:16:18 +00:00
|
|
|
Xorriso_report_iso_error(xorriso, 0, "Cannot take", 0, "FATAL", 1);
|
2007-10-27 22:41:24 +00:00
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Internal error on rename: failed to take node");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
|
|
|
return(-1);
|
|
|
|
}
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= iso_dir_add_node(dest_dir, node, 0);
|
|
|
|
if(ret<0) {
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2008-02-03 13:16:18 +00:00
|
|
|
Xorriso_report_iso_error(xorriso, 0, "Cannot add", 0, "FATAL", 1);
|
2008-01-26 00:26:57 +00:00
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"Internal error on rename: failed to insert node");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
|
|
|
return(-1);
|
|
|
|
}
|
2007-10-27 22:41:24 +00:00
|
|
|
leafname= strrchr(eff_dest, '/');
|
|
|
|
if(leafname==NULL)
|
|
|
|
leafname= eff_dest;
|
|
|
|
else
|
|
|
|
leafname++;
|
2008-01-26 00:26:57 +00:00
|
|
|
|
|
|
|
old_leafname= (char *) iso_node_get_name(node);
|
|
|
|
if(strcmp(leafname, old_leafname)!=0)
|
|
|
|
ret= iso_node_set_name(node, leafname);
|
2008-02-03 13:16:18 +00:00
|
|
|
else
|
|
|
|
ret= 1;
|
2008-01-26 00:26:57 +00:00
|
|
|
if(ret<0) {
|
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2008-02-03 13:16:18 +00:00
|
|
|
Xorriso_report_iso_error(xorriso, 0, "Cannot set name", 0, "FATAL", 1);
|
2008-01-26 00:26:57 +00:00
|
|
|
sprintf(xorriso->info_text, "Internal error on rename: failed to set name");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
|
|
|
return(-1);
|
|
|
|
}
|
2007-10-28 12:54:22 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-10-27 22:41:24 +00:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-28 16:54:29 +00:00
|
|
|
/* @param flag bit0= do not produce info message on success
|
|
|
|
@return 1=success,
|
|
|
|
0=was already directory, -1=was other type, -2=other error
|
|
|
|
*/
|
|
|
|
int Xorriso_mkdir(struct XorrisO *xorriso, char *path, int flag)
|
|
|
|
{
|
|
|
|
int ret;
|
2007-11-08 16:11:26 +00:00
|
|
|
char eff_path[SfileadrL], sfe[5*SfileadrL];
|
2007-10-28 16:54:29 +00:00
|
|
|
|
2007-12-15 18:31:39 +00:00
|
|
|
ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, path, eff_path, 1);
|
2007-10-28 16:54:29 +00:00
|
|
|
if(ret<0)
|
|
|
|
return(-2);
|
|
|
|
if(ret>0) {
|
|
|
|
sprintf(xorriso->info_text,"-mkdir: Address already existing %s",
|
|
|
|
Text_shellsafe(eff_path, sfe, 0));
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0,
|
|
|
|
(ret==2 ? "WARNING" : "SORRY"), 0);
|
|
|
|
return(-1+(ret==2));
|
|
|
|
}
|
2007-12-15 18:31:39 +00:00
|
|
|
ret= Xorriso_normalize_img_path(xorriso, xorriso->wdi, path, eff_path, 2);
|
2007-10-28 16:54:29 +00:00
|
|
|
if(ret<0)
|
|
|
|
return(-2);
|
|
|
|
ret= Xorriso_graft_in(xorriso, NULL, eff_path, 1);
|
|
|
|
if(ret<=0)
|
|
|
|
return(-2);
|
|
|
|
if(!(flag&1)) {
|
|
|
|
sprintf(xorriso->info_text, "Created directory in ISO image: %s\n",
|
|
|
|
Text_shellsafe(eff_path,sfe,0));
|
|
|
|
Xorriso_info(xorriso, 0);
|
|
|
|
}
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-29 21:41:17 +00:00
|
|
|
/* @param flag bit0= count results rather than storing them
|
|
|
|
bit1= this is a recursion
|
2007-12-04 07:44:59 +00:00
|
|
|
bit2= prepend wd (automatically done if wd[0]!=0)
|
2007-10-29 21:41:17 +00:00
|
|
|
*/
|
2007-12-04 21:00:35 +00:00
|
|
|
int Xorriso_obtain_pattern_files_i(
|
2008-01-26 00:26:57 +00:00
|
|
|
struct XorrisO *xorriso, char *wd, IsoDir *dir,
|
2007-12-04 21:00:35 +00:00
|
|
|
int *filec, char **filev, int count_limit, off_t *mem,
|
|
|
|
int *dive_count, int flag)
|
2007-10-29 21:41:17 +00:00
|
|
|
{
|
2007-12-04 21:00:35 +00:00
|
|
|
int ret, failed_at;
|
2008-01-26 00:26:57 +00:00
|
|
|
IsoDirIter *iter= NULL;
|
|
|
|
IsoNode *node;
|
2007-12-28 13:28:48 +00:00
|
|
|
char *name;
|
|
|
|
|
|
|
|
#ifdef Xorriso_fat_local_meM
|
|
|
|
char adr[SfileadrL];
|
|
|
|
#else /* Xorriso_fat_local_meM */
|
|
|
|
char *adr= NULL;
|
|
|
|
|
|
|
|
adr= malloc(SfileadrL);
|
|
|
|
if(adr==NULL) {
|
|
|
|
Xorriso_no_malloc_memory(xorriso, &adr, 0);
|
|
|
|
{ret= -1; goto ex;}
|
|
|
|
}
|
|
|
|
#endif /* ! Xorriso_fat_local_meM */
|
|
|
|
|
2007-10-29 21:41:17 +00:00
|
|
|
|
2007-12-04 21:00:35 +00:00
|
|
|
if(!(flag&2))
|
|
|
|
*dive_count= 0;
|
|
|
|
else
|
|
|
|
(*dive_count)++;
|
|
|
|
ret= Xorriso_check_for_root_pattern(xorriso, filec, filev, count_limit,
|
|
|
|
mem, (flag&1)|2);
|
|
|
|
if(ret!=2)
|
|
|
|
goto ex;
|
|
|
|
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= iso_dir_get_children(dir, &iter);
|
|
|
|
if(ret<0) {
|
2008-02-03 13:16:18 +00:00
|
|
|
Xorriso_cannot_create_iter(xorriso, ret, 0);
|
2007-12-04 21:00:35 +00:00
|
|
|
{ret= -1; goto ex;}
|
2007-10-29 21:41:17 +00:00
|
|
|
}
|
2008-01-26 00:26:57 +00:00
|
|
|
while(iso_dir_iter_next(iter, &node) == 1) {
|
|
|
|
name= (char *) iso_node_get_name(node);
|
2007-12-21 13:16:49 +00:00
|
|
|
ret= Xorriso_make_abs_adr(xorriso, wd, name, adr, flag&4);
|
2007-12-04 21:00:35 +00:00
|
|
|
if(ret<=0)
|
|
|
|
goto ex;
|
|
|
|
ret= Xorriso_regexec(xorriso, adr, &failed_at, 1);
|
2007-10-29 21:41:17 +00:00
|
|
|
if(ret) { /* no match */
|
2007-12-04 21:00:35 +00:00
|
|
|
if(failed_at <= *dive_count) /* no hope for a match */
|
2007-10-29 21:41:17 +00:00
|
|
|
continue;
|
2007-12-04 21:00:35 +00:00
|
|
|
|
|
|
|
if(!LIBISO_ISDIR(node)) {
|
|
|
|
|
|
|
|
/* >>> How to deal with softlinks ? */
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
2007-10-29 21:41:17 +00:00
|
|
|
/* dive deeper */
|
2007-12-04 21:00:35 +00:00
|
|
|
ret= Xorriso_obtain_pattern_files_i(
|
2008-01-26 00:26:57 +00:00
|
|
|
xorriso, adr, (IsoDir *) node,
|
2007-12-04 21:00:35 +00:00
|
|
|
filec, filev, count_limit, mem, dive_count, flag|2);
|
2007-10-29 21:41:17 +00:00
|
|
|
if(ret<=0)
|
2007-12-04 21:00:35 +00:00
|
|
|
goto ex;
|
2007-10-29 21:41:17 +00:00
|
|
|
} else {
|
2007-12-04 21:00:35 +00:00
|
|
|
ret= Xorriso_register_matched_adr(xorriso, adr, count_limit,
|
|
|
|
filec, filev, mem, (flag&1)|2);
|
|
|
|
if(ret<=0)
|
|
|
|
goto ex;
|
2007-10-29 21:41:17 +00:00
|
|
|
}
|
|
|
|
}
|
2007-12-04 21:00:35 +00:00
|
|
|
ret= 1;
|
|
|
|
ex:;
|
2007-12-28 13:28:48 +00:00
|
|
|
|
|
|
|
#ifndef Xorriso_fat_local_meM
|
|
|
|
if(adr!=NULL)
|
|
|
|
free(adr);
|
|
|
|
#endif /* ! Xorriso_fat_local_meM */
|
|
|
|
|
2007-12-04 21:00:35 +00:00
|
|
|
if(flag&2)
|
|
|
|
(*dive_count)--;
|
|
|
|
return(ret);
|
2007-10-29 21:41:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-09 19:30:25 +00:00
|
|
|
/* @param flag bit0= a match count !=1 is a SORRY event
|
|
|
|
bit1= with bit0 tolerate 0 matches if pattern is a constant
|
|
|
|
*/
|
2007-10-30 21:44:08 +00:00
|
|
|
int Xorriso_expand_pattern(struct XorrisO *xorriso,
|
2007-11-09 19:30:25 +00:00
|
|
|
int num_patterns, char **patterns, int extra_filec,
|
2007-11-01 19:11:56 +00:00
|
|
|
int *filec, char ***filev, off_t *mem, int flag)
|
2007-10-29 21:41:17 +00:00
|
|
|
{
|
2007-12-04 21:00:35 +00:00
|
|
|
int ret, count= 0, abs_adr= 0, i, was_count, was_filec;
|
|
|
|
int nonconst_mismatches= 0, dive_count= 0;
|
|
|
|
char sfe[5*SfileadrL];
|
2008-01-26 00:26:57 +00:00
|
|
|
IsoImage *volume;
|
|
|
|
IsoDir *dir= NULL, *root_dir;
|
|
|
|
IsoNode *iso_node;
|
2007-10-29 21:41:17 +00:00
|
|
|
|
|
|
|
*filec= 0;
|
|
|
|
*filev= NULL;
|
|
|
|
|
|
|
|
xorriso->search_mode= 3;
|
|
|
|
xorriso->structured_search= 1;
|
|
|
|
|
|
|
|
ret= Xorriso_get_volume(xorriso, &volume, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
2008-01-26 00:26:57 +00:00
|
|
|
root_dir= iso_image_get_root(volume);
|
2007-10-31 10:34:52 +00:00
|
|
|
if(root_dir==NULL) {
|
2007-10-30 21:44:08 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"While expanding pattern : Cannot obtain root node of ISO image");
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
|
|
|
|
ret= -1; goto ex;
|
|
|
|
}
|
2007-10-29 21:41:17 +00:00
|
|
|
|
2007-10-30 21:44:08 +00:00
|
|
|
for(i= 0; i<num_patterns; i++) {
|
2007-12-04 07:44:59 +00:00
|
|
|
ret= Xorriso_prepare_expansion_pattern(xorriso, patterns[i], 0);
|
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
|
|
|
if(ret==2)
|
2007-10-30 21:44:08 +00:00
|
|
|
abs_adr= 4;
|
|
|
|
if(patterns[i][0]=='/' || abs_adr) {
|
|
|
|
dir= root_dir;
|
|
|
|
abs_adr= 4;
|
|
|
|
} else {
|
2007-11-09 19:30:25 +00:00
|
|
|
/* This is done so late to allow the following:
|
2007-10-30 21:44:08 +00:00
|
|
|
It is not an error if xorriso->wdi does not exist yet, but one may
|
|
|
|
not use it as base for relative address searches.
|
|
|
|
*/
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= Xorriso_node_from_path(xorriso, volume, xorriso->wdi, &iso_node, 1);
|
|
|
|
dir= (IsoDir *) iso_node;
|
|
|
|
if(ret<=0) {
|
2007-10-30 21:44:08 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
"While expanding pattern %s : Working directory does not exist in ISO image",
|
|
|
|
Text_shellsafe(patterns[i], sfe, 0));
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
ret= 0; goto ex;
|
|
|
|
}
|
2008-01-26 00:26:57 +00:00
|
|
|
if(!LIBISO_ISDIR((IsoNode *) dir)) {
|
2007-10-30 21:44:08 +00:00
|
|
|
sprintf(xorriso->info_text,
|
2007-10-29 21:41:17 +00:00
|
|
|
"Working directory path does not lead to a directory in ISO image");
|
2007-10-30 21:44:08 +00:00
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
|
|
|
ret= 0; goto ex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* count the matches */
|
|
|
|
was_count= count;
|
2007-12-04 21:00:35 +00:00
|
|
|
ret= Xorriso_obtain_pattern_files_i(xorriso, "", dir, &count, NULL, 0,
|
|
|
|
mem, &dive_count, 1 | abs_adr);
|
2007-10-30 21:44:08 +00:00
|
|
|
if(ret<=0)
|
|
|
|
goto ex;
|
2007-11-09 19:30:25 +00:00
|
|
|
if(was_count==count && strcmp(patterns[i],"*")!=0 && (flag&3)!=1) {
|
2007-10-30 21:44:08 +00:00
|
|
|
count++;
|
2007-12-04 21:00:35 +00:00
|
|
|
Xorriso_eval_nonmatch(xorriso, patterns[i], &nonconst_mismatches, mem, 0);
|
2007-10-29 21:41:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-04 21:00:35 +00:00
|
|
|
ret= Xorriso_check_matchcount(xorriso, count, nonconst_mismatches,
|
|
|
|
num_patterns, patterns, flag&1);
|
|
|
|
if(ret<=0)
|
|
|
|
goto ex;
|
2007-11-09 19:30:25 +00:00
|
|
|
count+= extra_filec;
|
|
|
|
mem+= extra_filec*sizeof(char *);
|
2007-10-29 21:41:17 +00:00
|
|
|
if(count<=0)
|
|
|
|
{ret= 0; goto ex;}
|
2007-12-04 21:00:35 +00:00
|
|
|
ret= Xorriso_alloc_pattern_mem(xorriso, *mem, count, filev, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
goto ex;
|
2007-11-01 19:11:56 +00:00
|
|
|
/* now store addresses */
|
2007-10-30 21:44:08 +00:00
|
|
|
for(i= 0; i<num_patterns; i++) {
|
2007-12-04 07:44:59 +00:00
|
|
|
ret= Xorriso_prepare_expansion_pattern(xorriso, patterns[i], 0);
|
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
|
|
|
if(ret==2)
|
2007-10-30 21:44:08 +00:00
|
|
|
abs_adr= 4;
|
2007-12-04 07:44:59 +00:00
|
|
|
|
2007-10-30 21:44:08 +00:00
|
|
|
was_filec= *filec;
|
2007-12-04 21:00:35 +00:00
|
|
|
ret= Xorriso_obtain_pattern_files_i(xorriso, "", dir, filec, *filev, count,
|
|
|
|
mem, &dive_count, abs_adr);
|
2007-10-30 21:44:08 +00:00
|
|
|
if(ret<=0)
|
|
|
|
goto ex;
|
|
|
|
if(was_filec == *filec && strcmp(patterns[i],"*")!=0) {
|
|
|
|
(*filev)[*filec]= strdup(patterns[i]);
|
|
|
|
if((*filev)[*filec]==NULL) {
|
2007-11-01 19:11:56 +00:00
|
|
|
(*mem)= strlen(patterns[i])+1;
|
2007-12-04 21:00:35 +00:00
|
|
|
Xorriso_no_pattern_memory(xorriso, *mem, 0);
|
|
|
|
ret= -1; goto ex;
|
2007-10-30 21:44:08 +00:00
|
|
|
}
|
|
|
|
(*filec)++;
|
|
|
|
}
|
|
|
|
}
|
2007-10-29 21:41:17 +00:00
|
|
|
ret= 1;
|
|
|
|
ex:;
|
|
|
|
if(ret<=0) {
|
|
|
|
if(filev!=NULL)
|
|
|
|
Sfile_destroy_argv(&count, filev, 0);
|
|
|
|
*filec= 0;
|
|
|
|
}
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
2007-11-02 14:36:26 +00:00
|
|
|
|
2007-11-07 19:18:31 +00:00
|
|
|
int Xorriso_set_st_mode(struct XorrisO *xorriso, char *in_path,
|
|
|
|
mode_t mode_and, mode_t mode_or, int flag)
|
|
|
|
{
|
|
|
|
mode_t mode= 0;
|
|
|
|
int ret;
|
2008-01-26 00:26:57 +00:00
|
|
|
IsoNode *node;
|
2007-11-08 16:11:26 +00:00
|
|
|
char sfe[5*SfileadrL], path[SfileadrL];
|
2007-11-07 19:18:31 +00:00
|
|
|
|
|
|
|
ret= Xorriso_get_node_by_path(xorriso, in_path, path, &node, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
2008-01-26 00:26:57 +00:00
|
|
|
mode= iso_node_get_permissions(node);
|
2007-11-07 19:18:31 +00:00
|
|
|
mode= (mode & mode_and) | mode_or;
|
2008-01-26 00:26:57 +00:00
|
|
|
iso_node_set_permissions(node, mode);
|
|
|
|
iso_node_set_ctime(node, time(NULL));
|
2007-11-07 19:18:31 +00:00
|
|
|
sprintf(xorriso->info_text,"Permissions now: %-5.5o %s",
|
|
|
|
mode, Text_shellsafe(path, sfe, 0));
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
|
|
|
|
xorriso->volset_change_pending= 1;
|
2007-12-26 16:01:59 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-11-07 19:18:31 +00:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
2007-11-07 22:55:37 +00:00
|
|
|
|
|
|
|
int Xorriso_set_uid(struct XorrisO *xorriso, char *in_path, uid_t uid,
|
|
|
|
int flag)
|
|
|
|
{
|
|
|
|
int ret;
|
2008-01-26 00:26:57 +00:00
|
|
|
IsoNode *node;
|
2007-11-07 22:55:37 +00:00
|
|
|
|
|
|
|
ret= Xorriso_get_node_by_path(xorriso, in_path, NULL, &node, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
2008-01-26 00:26:57 +00:00
|
|
|
iso_node_set_uid(node, uid);
|
|
|
|
iso_node_set_ctime(node, time(NULL));
|
2007-11-07 22:55:37 +00:00
|
|
|
xorriso->volset_change_pending= 1;
|
2007-12-26 16:01:59 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-11-07 22:55:37 +00:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int Xorriso_set_gid(struct XorrisO *xorriso, char *in_path, gid_t gid,
|
|
|
|
int flag)
|
|
|
|
{
|
|
|
|
int ret;
|
2008-01-26 00:26:57 +00:00
|
|
|
IsoNode *node;
|
2007-11-07 22:55:37 +00:00
|
|
|
|
|
|
|
ret= Xorriso_get_node_by_path(xorriso, in_path, NULL, &node, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
2008-01-26 00:26:57 +00:00
|
|
|
iso_node_set_gid(node, gid);
|
|
|
|
iso_node_set_ctime(node, time(NULL));
|
2007-11-08 14:43:53 +00:00
|
|
|
xorriso->volset_change_pending= 1;
|
2007-12-26 16:01:59 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-11-08 14:43:53 +00:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* @parm flag bit0= atime, bit1= ctime, bit2= mtime, bit8=no auto ctime */
|
|
|
|
int Xorriso_set_time(struct XorrisO *xorriso, char *in_path, time_t t,
|
|
|
|
int flag)
|
|
|
|
{
|
|
|
|
int ret;
|
2008-01-26 00:26:57 +00:00
|
|
|
IsoNode *node;
|
2007-11-08 14:43:53 +00:00
|
|
|
|
|
|
|
ret= Xorriso_get_node_by_path(xorriso, in_path, NULL, &node, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
|
|
|
if(flag&1)
|
2008-01-26 00:26:57 +00:00
|
|
|
iso_node_set_atime(node, t);
|
2007-11-08 14:43:53 +00:00
|
|
|
if(flag&2)
|
2008-01-26 00:26:57 +00:00
|
|
|
iso_node_set_ctime(node, t);
|
2007-11-08 14:43:53 +00:00
|
|
|
if(flag&4)
|
2008-01-26 00:26:57 +00:00
|
|
|
iso_node_set_mtime(node, t);
|
2007-11-08 14:43:53 +00:00
|
|
|
if(!(flag&(2|256)))
|
2008-01-26 00:26:57 +00:00
|
|
|
iso_node_set_ctime(node, time(NULL));
|
2007-11-07 22:55:37 +00:00
|
|
|
xorriso->volset_change_pending= 1;
|
2007-12-26 16:01:59 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-11-07 22:55:37 +00:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-30 19:02:44 +00:00
|
|
|
int Xorriso_findi_action(struct XorrisO *xorriso, struct FindjoB *job,
|
|
|
|
char *abs_path, char *show_path,
|
2008-01-26 00:26:57 +00:00
|
|
|
IsoNode *node, int depth, int flag)
|
2007-12-30 19:02:44 +00:00
|
|
|
{
|
2008-01-26 00:26:57 +00:00
|
|
|
int ret= 0, type, action= 0;
|
2007-12-30 19:02:44 +00:00
|
|
|
uid_t user= 0;
|
|
|
|
gid_t group= 0;
|
|
|
|
time_t date= 0;
|
|
|
|
mode_t mode_or= 0, mode_and= ~1;
|
|
|
|
char *target, sfe[5*SfileadrL];
|
2008-01-01 12:32:23 +00:00
|
|
|
struct FindjoB *subjob;
|
|
|
|
struct stat dir_stbuf;
|
2007-12-30 19:02:44 +00:00
|
|
|
|
|
|
|
action= Findjob_get_action_parms(job, &target, &user, &group,
|
2008-01-01 12:32:23 +00:00
|
|
|
&mode_and, &mode_or, &type, &date, &subjob, 0);
|
2007-12-30 19:02:44 +00:00
|
|
|
if(action<0)
|
|
|
|
action= 0;
|
|
|
|
|
|
|
|
if(action==1) {
|
|
|
|
/* >>> rm */;
|
|
|
|
} else if(action==2) {
|
|
|
|
|
|
|
|
/* >>> rm_r */;
|
|
|
|
|
|
|
|
} else if(action==3) {
|
|
|
|
|
|
|
|
/* >>> mv target */;
|
|
|
|
|
|
|
|
} else if(action==4) { /* chown */
|
|
|
|
ret= Xorriso_set_uid(xorriso, abs_path, user, 0);
|
|
|
|
} else if(action==5) { /* chgrp */
|
|
|
|
ret= Xorriso_set_gid(xorriso, abs_path, group, 0);
|
|
|
|
} else if(action==6) { /* chmod */
|
|
|
|
ret= Xorriso_set_st_mode(xorriso, abs_path, mode_and, mode_or, 0);
|
|
|
|
} else if(action==7) { /* alter_date */
|
|
|
|
ret= Xorriso_set_time(xorriso, abs_path, date, type&7);
|
|
|
|
} else if(action==8) { /* lsdl */
|
|
|
|
ret= Xorriso_ls_filev(xorriso, "", 1, &abs_path, (off_t) 0, 1|2|8);
|
2008-01-01 12:32:23 +00:00
|
|
|
} else if(action>=9 && action<=13) { /* actions which have own findjobs */
|
|
|
|
Findjob_set_start_path(subjob, abs_path, 0);
|
|
|
|
ret= Xorriso_findi(xorriso, subjob, NULL, abs_path, &dir_stbuf, depth, 0);
|
2007-12-30 19:02:44 +00:00
|
|
|
} else {
|
|
|
|
sprintf(xorriso->result_line, "%s\n", Text_shellsafe(show_path, sfe, 0));
|
|
|
|
Xorriso_result(xorriso, 0);
|
2007-12-31 09:53:30 +00:00
|
|
|
ret= 1;
|
2007-12-30 19:02:44 +00:00
|
|
|
}
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-21 13:16:49 +00:00
|
|
|
int Xorriso_findi(struct XorrisO *xorriso, struct FindjoB *job,
|
|
|
|
void *dir_node_generic, char *dir_path,
|
|
|
|
struct stat *dir_stbuf, int depth, int flag)
|
|
|
|
{
|
2007-12-30 19:02:44 +00:00
|
|
|
int ret, action= 0;
|
2008-01-26 00:26:57 +00:00
|
|
|
IsoDirIter *iter= NULL;
|
|
|
|
IsoDir *dir_node;
|
|
|
|
IsoNode *node, *iso_node;
|
|
|
|
IsoImage *volume;
|
2007-12-21 13:16:49 +00:00
|
|
|
struct stat stbuf;
|
2007-12-28 13:28:48 +00:00
|
|
|
char *name;
|
|
|
|
#ifdef Xorriso_fat_local_meM
|
2008-01-26 00:26:57 +00:00
|
|
|
char path[SfileadrL], abs_path[SfileadrL];
|
2007-12-28 13:28:48 +00:00
|
|
|
#else /* Xorriso_fat_local_meM */
|
2008-01-26 00:26:57 +00:00
|
|
|
char *path= NULL, *abs_path= NULL;
|
2007-12-28 13:28:48 +00:00
|
|
|
|
|
|
|
path= malloc(SfileadrL);
|
2007-12-30 19:02:44 +00:00
|
|
|
abs_path= malloc(SfileadrL);
|
2008-01-26 00:26:57 +00:00
|
|
|
if(path==NULL || abs_path==NULL) {
|
|
|
|
Xorriso_no_malloc_memory(xorriso, &path, 0);
|
2007-12-28 13:28:48 +00:00
|
|
|
{ret= -1; goto ex;}
|
|
|
|
}
|
|
|
|
#endif /* ! Xorriso_fat_local_meM */
|
2007-12-21 13:16:49 +00:00
|
|
|
|
2007-12-30 19:02:44 +00:00
|
|
|
action= Findjob_get_action(job, 0);
|
|
|
|
if(action<0)
|
|
|
|
action= 0;
|
|
|
|
|
2008-01-26 00:26:57 +00:00
|
|
|
dir_node= (IsoDir *) dir_node_generic;
|
2007-12-21 13:16:49 +00:00
|
|
|
if(dir_node==NULL) {
|
|
|
|
ret= Xorriso_get_volume(xorriso, &volume, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
{ret= -1; goto ex;}
|
2007-12-22 14:39:12 +00:00
|
|
|
ret= Xorriso_make_abs_adr(xorriso, xorriso->wdi, dir_path, path, 1|2|4);
|
2007-12-21 13:16:49 +00:00
|
|
|
if(ret<=0)
|
|
|
|
goto ex;
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= Xorriso_node_from_path(xorriso, volume, path, &iso_node, 0);
|
|
|
|
dir_node= (IsoDir *) iso_node;
|
|
|
|
if(ret<=0)
|
2007-12-21 13:16:49 +00:00
|
|
|
{ret= 0; goto ex;}
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= Xorriso_fake_stbuf(xorriso, "", dir_stbuf, &iso_node, 1);
|
|
|
|
dir_node= (IsoDir *) iso_node;
|
2007-12-22 14:39:12 +00:00
|
|
|
if(ret<=0)
|
2007-12-21 13:16:49 +00:00
|
|
|
goto ex;
|
|
|
|
|
|
|
|
name= strrchr(dir_path, '/');
|
|
|
|
if(name==NULL)
|
|
|
|
name= dir_path;
|
|
|
|
else
|
|
|
|
name++;
|
|
|
|
ret= Findjob_test(job, name, NULL, dir_stbuf, depth, 0);
|
|
|
|
if(ret<0)
|
|
|
|
goto ex;
|
2007-12-31 13:54:37 +00:00
|
|
|
if(ret>0) {
|
2007-12-30 19:02:44 +00:00
|
|
|
ret= Xorriso_findi_action(xorriso, job, path, dir_path,
|
2008-01-26 00:26:57 +00:00
|
|
|
(IsoNode *) dir_node, depth, 0);
|
2007-12-30 19:02:44 +00:00
|
|
|
if(ret<=0)
|
|
|
|
goto ex;
|
2007-12-21 13:16:49 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-26 00:26:57 +00:00
|
|
|
if(!LIBISO_ISDIR((IsoNode *) dir_node))
|
2007-12-21 13:16:49 +00:00
|
|
|
{ret= 2; goto ex;}
|
|
|
|
|
2008-01-26 00:26:57 +00:00
|
|
|
ret= iso_dir_get_children(dir_node, &iter);
|
|
|
|
if(ret<0) {
|
2008-02-03 13:16:18 +00:00
|
|
|
Xorriso_cannot_create_iter(xorriso, ret, 0);
|
2007-12-21 13:16:49 +00:00
|
|
|
{ret= -1; goto ex;}
|
|
|
|
}
|
2008-01-26 00:26:57 +00:00
|
|
|
while(iso_dir_iter_next(iter, &node) == 1 && !xorriso->request_to_abort) {
|
|
|
|
name= (char *) iso_node_get_name(node);
|
2007-12-21 13:16:49 +00:00
|
|
|
ret= Xorriso_make_abs_adr(xorriso, dir_path, name, path, 4);
|
|
|
|
if(ret<=0)
|
|
|
|
goto ex;
|
|
|
|
ret= Xorriso_fake_stbuf(xorriso, "", &stbuf, &node, 1);
|
|
|
|
if(ret<0)
|
|
|
|
goto ex;
|
|
|
|
if(ret==0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ret= Findjob_test(job, name, dir_stbuf, &stbuf, depth, 0);
|
|
|
|
if(ret<0)
|
|
|
|
goto ex;
|
|
|
|
if(ret>0) {
|
2007-12-30 19:02:44 +00:00
|
|
|
ret= Xorriso_make_abs_adr(xorriso, xorriso->wdi, path, abs_path, 1|4);
|
|
|
|
if(ret<=0)
|
|
|
|
goto ex;
|
2008-01-01 12:32:23 +00:00
|
|
|
ret= Xorriso_findi_action(xorriso, job, abs_path, path, node, depth, 0);
|
2007-12-30 19:02:44 +00:00
|
|
|
if(ret<=0) {
|
|
|
|
if(Xorriso_eval_problem_status(xorriso, ret, 1|2)<0)
|
|
|
|
goto ex;
|
|
|
|
}
|
2007-12-21 13:16:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(S_ISDIR(stbuf.st_mode)) {
|
|
|
|
ret= Xorriso_findi(xorriso, job, (void *) node, path,
|
|
|
|
&stbuf, depth+1, flag);
|
|
|
|
if(ret<0)
|
|
|
|
goto ex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret= 1;
|
|
|
|
ex:;
|
2007-12-28 13:28:48 +00:00
|
|
|
|
|
|
|
#ifndef Xorriso_fat_local_meM
|
|
|
|
if(path!=NULL)
|
|
|
|
free(path);
|
2007-12-30 19:02:44 +00:00
|
|
|
if(abs_path!=NULL)
|
|
|
|
free(abs_path);
|
2007-12-28 13:28:48 +00:00
|
|
|
#endif /* ! Xorriso_fat_local_meM */
|
|
|
|
|
2007-12-26 16:01:59 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2007-12-21 13:16:49 +00:00
|
|
|
if(iter!=NULL)
|
2008-01-26 00:26:57 +00:00
|
|
|
iso_dir_iter_free(iter);
|
2007-12-21 13:16:49 +00:00
|
|
|
return(ret);
|
|
|
|
}
|
2007-12-26 16:01:59 +00:00
|
|
|
|
|
|
|
|
2008-01-26 00:26:57 +00:00
|
|
|
/* @param flag bit0= do not mark image as changed */
|
2007-12-26 16:01:59 +00:00
|
|
|
int Xorriso_set_volid(struct XorrisO *xorriso, char *volid, int flag)
|
|
|
|
{
|
|
|
|
int ret;
|
2008-01-26 00:26:57 +00:00
|
|
|
IsoImage *volume;
|
2007-12-26 16:01:59 +00:00
|
|
|
|
|
|
|
ret= Xorriso_get_volume(xorriso, &volume, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
2008-01-26 00:26:57 +00:00
|
|
|
iso_image_set_volume_id(volume, volid);
|
|
|
|
if(!(flag&1))
|
|
|
|
xorriso->volset_change_pending= 1;
|
2007-12-26 16:01:59 +00:00
|
|
|
Xorriso_process_msg_queues(xorriso,0);
|
2008-01-26 00:26:57 +00:00
|
|
|
sprintf(xorriso->info_text,"Volume ID: '%s'",iso_image_get_volume_id(volume));
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
|
2007-12-26 16:01:59 +00:00
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-15 17:45:08 +00:00
|
|
|
int Xorriso_get_volid(struct XorrisO *xorriso, char volid[33], int flag)
|
|
|
|
{
|
2008-01-26 00:26:57 +00:00
|
|
|
int ret;
|
|
|
|
IsoImage *volume;
|
|
|
|
|
|
|
|
ret= Xorriso_get_volume(xorriso, &volume, 0);
|
|
|
|
if(ret<=0)
|
|
|
|
return(ret);
|
|
|
|
strncpy(volid, iso_image_get_volume_id(volume), 32);
|
|
|
|
volid[32]= 0;
|
2008-01-15 17:45:08 +00:00
|
|
|
return(1);
|
|
|
|
}
|
2008-01-28 10:54:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
int Xorriso_set_abort_severity(struct XorrisO *xorriso, int flag)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret= iso_set_abort_severity(xorriso->abort_on_text);
|
|
|
|
return(ret>=0);
|
|
|
|
}
|
|
|
|
|