Enabled osirrox of more file types, curbed with device files
This commit is contained in:
@@ -1474,6 +1474,87 @@ int Xorriso_get_node_by_path(struct XorrisO *xorriso,
|
||||
}
|
||||
|
||||
|
||||
/* <<< this is not safe
|
||||
#define Xorriso_can_get_dev_T 1
|
||||
#define Xorriso_get_dev_by_botcH 1
|
||||
*/
|
||||
|
||||
|
||||
#ifndef Xorriso_can_get_dev_T
|
||||
#ifdef Xorriso_standalonE
|
||||
/* this is safe */
|
||||
#define Xorriso_can_get_dev_T 1
|
||||
#define Xorriso_get_dev_by_botcH 1
|
||||
#endif /* Xorriso_standalonE */
|
||||
#endif /* Xorriso_can_get_dev_T */
|
||||
|
||||
|
||||
/* @param flag bit0= do not complain about being unable to retrieve info
|
||||
*/
|
||||
int Xorriso_node_get_dev(struct XorrisO *xorriso, IsoNode *node,
|
||||
char *path, dev_t *dev, int flag)
|
||||
{
|
||||
|
||||
#ifdef Xorriso_can_get_dev_T
|
||||
|
||||
/* >>> insert future API call here and remove botch below */
|
||||
|
||||
/* <<< */
|
||||
#ifdef Xorriso_get_dev_by_botcH
|
||||
/* Drilling a hole into libisofs-0.6.4 in order to substitute for the lack
|
||||
of an API call which returns the dev_t number of a IsoSpecial (block or
|
||||
character device).
|
||||
*/
|
||||
|
||||
/* These are clones from libisofs/node.h */
|
||||
|
||||
typedef struct iso_extended_info IsoExtendedInfo_0_6_4_xorrisO;
|
||||
|
||||
struct Iso_Node_0_6_4_xorrisO
|
||||
{
|
||||
int refcount;
|
||||
enum IsoNodeType type;
|
||||
char *name;
|
||||
mode_t mode;
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
time_t atime;
|
||||
time_t mtime;
|
||||
time_t ctime;
|
||||
|
||||
int hidden;
|
||||
IsoDir *parent;
|
||||
IsoNode *next;
|
||||
IsoExtendedInfo_0_6_4_xorrisO *xinfo;
|
||||
};
|
||||
|
||||
struct Iso_Special_0_6_4_xorrisO
|
||||
{
|
||||
struct Iso_Node_0_6_4_xorrisO node;
|
||||
dev_t dev;
|
||||
};
|
||||
|
||||
*dev= ((struct Iso_Special_0_6_4_xorrisO *) node)->dev;
|
||||
return(1);
|
||||
|
||||
#endif /* Xorriso_get_dev_by_botcH */
|
||||
|
||||
#else /* Xorriso_can_get_dev_T */
|
||||
|
||||
char sfe[SfileadrL];
|
||||
|
||||
if(flag&1)
|
||||
return(0);
|
||||
sprintf(xorriso->info_text,
|
||||
"Cannot obtain device major,minor from ISO image file %s",
|
||||
Text_shellsafe(path, sfe, 0));
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE", 0);
|
||||
return(0);
|
||||
|
||||
#endif /* ! Xorriso_can_get_dev_T */
|
||||
}
|
||||
|
||||
|
||||
/* @param flag bit0= *node is already valid
|
||||
bit1= add extra block for size estimation
|
||||
*/
|
||||
@@ -1505,11 +1586,13 @@ int Xorriso_fake_stbuf(struct XorrisO *xorriso, char *path, struct stat *stbuf,
|
||||
stbuf->st_mode|= S_IFREG;
|
||||
else if(LIBISO_ISLNK(*node))
|
||||
stbuf->st_mode|= S_IFLNK;
|
||||
else if(LIBISO_ISCHR(*node))
|
||||
else if(LIBISO_ISCHR(*node)) {
|
||||
stbuf->st_mode|= S_IFCHR;
|
||||
else if(LIBISO_ISBLK(*node))
|
||||
Xorriso_node_get_dev(xorriso, *node, path, &(stbuf->st_rdev), 1);
|
||||
} else if(LIBISO_ISBLK(*node)) {
|
||||
stbuf->st_mode|= S_IFBLK;
|
||||
else if(LIBISO_ISFIFO(*node))
|
||||
Xorriso_node_get_dev(xorriso, *node, path, &(stbuf->st_rdev), 1);
|
||||
} else if(LIBISO_ISFIFO(*node))
|
||||
stbuf->st_mode|= S_IFIFO;
|
||||
else if(LIBISO_ISSOCK(*node))
|
||||
stbuf->st_mode|= S_IFSOCK;
|
||||
@@ -1524,8 +1607,6 @@ int Xorriso_fake_stbuf(struct XorrisO *xorriso, char *path, struct stat *stbuf,
|
||||
stbuf->st_uid= iso_node_get_uid(*node);
|
||||
stbuf->st_gid= iso_node_get_gid(*node);
|
||||
|
||||
/* >>> stbuf->st_rdev */
|
||||
|
||||
if(LIBISO_ISREG(*node))
|
||||
stbuf->st_size= iso_file_get_size((IsoFile *) *node)+ (2048 * !!(flag&2));
|
||||
else
|
||||
@@ -2439,16 +2520,22 @@ int Xorriso_restore_implict_properties(struct XorrisO *xorriso, IsoDir *dir,
|
||||
#endif /* Osirrox_not_yeT */
|
||||
|
||||
|
||||
/* @param flag bit0= minimal transfer: access permissions only
|
||||
@return <0 severe error , 0 failure , 1 success
|
||||
/* @param flag bit0= Minimal transfer: access permissions only
|
||||
bit2= This is not a parameter. Do not report if ignored
|
||||
@return <0 severe error , 0 failure , 1 success ,
|
||||
2 regularly not installed (disallowed device, UNIX domain socket)
|
||||
*/
|
||||
int Xorriso_tree_restore_node(struct XorrisO *xorriso, IsoNode *node,
|
||||
char *img_path, char *disk_path, int flag)
|
||||
{
|
||||
int ret= 0, write_fd= -1, wanted, wret;
|
||||
char *what= "[unknown filetype]", sfe[5*SfileadrL], buf[32*1024];
|
||||
char *what= "[unknown filetype]", sfe[5*SfileadrL], sfe2[5*SfileadrL];
|
||||
char buf[32*1024];
|
||||
char *link_target;
|
||||
off_t todo, size;
|
||||
void *stream2= NULL;
|
||||
void *data_stream= NULL;
|
||||
mode_t mode;
|
||||
dev_t dev= 0;
|
||||
|
||||
if(LIBISO_ISDIR(node)) {
|
||||
what= "directory";
|
||||
@@ -2456,8 +2543,10 @@ int Xorriso_tree_restore_node(struct XorrisO *xorriso, IsoNode *node,
|
||||
|
||||
} else if(LIBISO_ISREG(node)) {
|
||||
what= "regular file";
|
||||
|
||||
/* >>> need to exploit node rather than img_path */
|
||||
ret= Xorriso_iso_file_open(xorriso, img_path, &stream2, 0);
|
||||
ret= Xorriso_iso_file_open(xorriso, img_path, &data_stream, 0);
|
||||
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
write_fd= open(disk_path,O_WRONLY|O_EXCL|O_CREAT);
|
||||
@@ -2468,7 +2557,7 @@ int Xorriso_tree_restore_node(struct XorrisO *xorriso, IsoNode *node,
|
||||
wanted= sizeof(buf);
|
||||
if(wanted>todo)
|
||||
wanted= todo;
|
||||
ret= Xorriso_iso_file_read(xorriso, stream2, buf, wanted, 0);
|
||||
ret= Xorriso_iso_file_read(xorriso, data_stream, buf, wanted, 0);
|
||||
if(ret<=0)
|
||||
break;
|
||||
wret= write(write_fd, buf, ret);
|
||||
@@ -2484,40 +2573,77 @@ int Xorriso_tree_restore_node(struct XorrisO *xorriso, IsoNode *node,
|
||||
}
|
||||
close(write_fd);
|
||||
write_fd= -1;
|
||||
Xorriso_iso_file_close(xorriso, &stream2, 0);
|
||||
stream2= NULL;
|
||||
Xorriso_iso_file_close(xorriso, &data_stream, 0);
|
||||
data_stream= NULL;
|
||||
ret= (todo==0);
|
||||
|
||||
} else if(LIBISO_ISLNK(node)) {
|
||||
what= "symbolic link";
|
||||
|
||||
goto not_this_type;
|
||||
/* >>> restore symbolic link */;
|
||||
link_target= (char *) iso_symlink_get_dest((IsoSymlink *) node);
|
||||
ret= symlink(link_target, disk_path);
|
||||
|
||||
} else if(LIBISO_ISCHR(node)) {
|
||||
what= "character device";
|
||||
if(xorriso->allow_restore!=2) {
|
||||
ignored:;
|
||||
if(!(flag&4)) {
|
||||
sprintf(xorriso->info_text, "Ignored file type: %s %s = %s", what,
|
||||
Text_shellsafe(img_path,sfe,0), Text_shellsafe(disk_path,sfe2,0));
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
|
||||
}
|
||||
{ret= 2; goto ex;}
|
||||
}
|
||||
|
||||
#ifdef Xorriso_can_get_dev_T
|
||||
mode= S_IFCHR | 0777;
|
||||
ret= Xorriso_node_get_dev(xorriso, node, img_path, &dev, 0);
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
if(dev == (dev_t) 1) {
|
||||
probably_damaged:;
|
||||
sprintf(xorriso->info_text,
|
||||
"Most probably damaged device file not restored: mknod %s %s 0 1",
|
||||
Text_shellsafe(disk_path, sfe, 0), LIBISO_ISCHR(node) ? "c" : "b");
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE", 0);
|
||||
ret= 0; goto ex;
|
||||
}
|
||||
ret= mknod(disk_path, mode, dev);
|
||||
#else
|
||||
goto not_this_type;
|
||||
/* >>> restore character device */;
|
||||
#endif
|
||||
|
||||
} else if(LIBISO_ISBLK(node)) {
|
||||
what= "block device";
|
||||
if(xorriso->allow_restore!=2)
|
||||
goto ignored;
|
||||
|
||||
#ifdef Xorriso_can_get_dev_T
|
||||
mode= S_IFBLK | 0777;
|
||||
ret= Xorriso_node_get_dev(xorriso, node, img_path, &dev, 0);
|
||||
if(ret<=0)
|
||||
goto ex;
|
||||
if(dev == (dev_t) 1)
|
||||
goto probably_damaged;
|
||||
ret= mknod(disk_path, mode, dev);
|
||||
#else
|
||||
goto not_this_type;
|
||||
/* >>> restore block device */;
|
||||
#endif
|
||||
|
||||
} else if(LIBISO_ISFIFO(node)) {
|
||||
what= "named pipe";
|
||||
|
||||
goto not_this_type;
|
||||
/* >>> restore fifo */;
|
||||
mode= S_IFIFO | 0777;
|
||||
ret= mknod(disk_path, mode, dev);
|
||||
|
||||
} else if(LIBISO_ISSOCK(node)) {
|
||||
what= "";
|
||||
/* restoring a socket file makes no sense */;
|
||||
what= "unix socket";
|
||||
/* Restoring a socket file is not possible. One rather needs to restart
|
||||
the service which temporarily created the socket. */
|
||||
goto ignored;
|
||||
|
||||
} else {
|
||||
#ifndef Xorriso_can_get_dev_T
|
||||
not_this_type:;
|
||||
#endif
|
||||
sprintf(xorriso->info_text, "Cannot restore file type '%s'", what);
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
|
||||
ret= 0; goto ex;
|
||||
@@ -2530,11 +2656,15 @@ cannot_restore:;
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE", 0);
|
||||
ret= 0; goto ex;
|
||||
}
|
||||
ret= Xorriso_restore_properties(xorriso, disk_path, node, flag&1);
|
||||
if(LIBISO_ISLNK(node))
|
||||
ret= 1;
|
||||
else
|
||||
ret= Xorriso_restore_properties(xorriso, disk_path, node, flag&1);
|
||||
ex:;
|
||||
if(write_fd>0)
|
||||
close(write_fd);
|
||||
Xorriso_iso_file_close(xorriso, &stream2, 0);
|
||||
if(data_stream!=NULL)
|
||||
Xorriso_iso_file_close(xorriso, &data_stream, 0);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
@@ -2718,14 +2848,15 @@ attach_source:;
|
||||
img_path_pt= img_path;
|
||||
|
||||
ret= Xorriso_tree_restore_node(xorriso, node, img_path_pt, path,
|
||||
!!(flag&64));
|
||||
(flag&4) | !!(flag&64));
|
||||
if(ret<=0) {
|
||||
sprintf(xorriso->info_text, "Restoring failed: %s = %s",
|
||||
Text_shellsafe(img_path,sfe,0), Text_shellsafe(disk_path,sfe2,0));
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
|
||||
return(0);
|
||||
}
|
||||
|
||||
if(ret==2)
|
||||
return(3);
|
||||
xorriso->pacifier_count++;
|
||||
if(xorriso->pacifier_count%100 && !(flag&2))
|
||||
Xorriso_pacifier_callback(xorriso, "files restored",
|
||||
|
Reference in New Issue
Block a user