source: MondoRescue/branches/3.2/mondo/src/common/libmondo-fork.c@ 3191

Last change on this file since 3191 was 3191, checked in by Bruno Cornec, 11 years ago
  • Lots of memory management backports from 3.1 to 3.2 - still not finished, nor working ATM. the common subdir was done during travel, so this is essentially a backup !
  • Property svn:keywords set to Id
File size: 18.8 KB
Line 
1/* libmondo-fork.c
2 $Id: libmondo-fork.c 3191 2013-09-25 06:55:45Z bruno $
3
4- subroutines for handling forking/pthreads/etc.
5*/
6
7
8#include "my-stuff.h"
9#include "mr_mem.h"
10#include "mr_str.h"
11#include "mondostructures.h"
12#include "libmondo-fork.h"
13#include "libmondo-string-EXT.h"
14#include "libmondo-gui-EXT.h"
15#include "libmondo-files-EXT.h"
16#include "libmondo-tools-EXT.h"
17#include "lib-common-externs.h"
18
19/*@unused@*/
20//static char cvsid[] = "$Id: libmondo-fork.c 3191 2013-09-25 06:55:45Z bruno $";
21
22extern t_bkptype g_backup_media_type;
23extern bool g_text_mode;
24extern char *MONDO_LOGFILE;
25
26/* Reference to global bkpinfo */
27extern struct s_bkpinfo *bkpinfo;
28pid_t g_buffer_pid = 0;
29
30
31/**
32 * Call a program and retrieve its last line of output.
33 * @param call The program to run.
34 * @return The last line of its output.
35 * @note The returned value points to static storage that will be overwritten with each call.
36 */
37char *call_program_and_get_last_line_of_output(char *call)
38{
39 /*@ buffers ***************************************************** */
40 static char result[MAX_STR_LEN];
41 char *tmp = NULL;
42
43 /*@ pointers **************************************************** */
44 FILE *fin = NULL;
45 int res = 0;
46
47 /*@ initialize data ********************************************* */
48 result[0] = '\0';
49
50 /*@******************************************************************** */
51
52 assert_string_is_neither_NULL_nor_zerolength(call);
53 if ((fin = popen(call, "r"))) {
54 for (mr_getline(tmp, fin); !feof(fin); mr_getline(tmp, fin)) {
55 if (strlen(tmp) > 1) {
56 strcpy(result, tmp);
57 }
58 mr_free(tmp);
59 }
60 paranoid_pclose(fin);
61 } else {
62 log_OS_error("Unable to open resulting file");
63 }
64 strip_spaces(result);
65 mr_free(tmp);
66 return(result);
67}
68
69
70#define MONDO_POPMSG "Your PC will not retract the CD tray automatically. Please call mondoarchive with the -m (manual CD tray) flag."
71
72/**
73 * Call mkisofs to create an ISO image.
74 * @param bkpinfo The backup information structure. Fields used:
75 * - @c bkpinfo->manual_cd_tray
76 * - @c bkpinfo->backup_media_type
77 * @param basic_call The call to mkisofs. May contain tokens that will be resolved to actual data. The tokens are:
78 * - @c _ISO_ will become the ISO file (@p isofile)
79 * - @c _CD#_ becomes the CD number (@p cd_no)
80 * - @c _ERR_ becomes the logfile (@p g_logfile)
81 * @param isofile Replaces @c _ISO_ in @p basic_call. Should probably be the ISO image to create (-o parameter to mkisofs).
82 * @param cd_no Replaces @c _CD#_ in @p basic_call. Should probably be the CD number.
83 * @param what_i_am_doing The action taking place (e.g. "Making ISO #1"). Used as the title of the progress dialog.
84 * @return Exit code of @c mkisofs (0 is success, anything else indicates failure).
85 */
86int
87eval_call_to_make_ISO(char *basic_call, char *isofile,
88 int cd_no, char *logstub, char *what_i_am_doing)
89{
90
91 /*@ int's *** */
92 int retval = 0;
93
94
95 /*@ buffers *** */
96 char *midway_call = NULL;
97 char *ultimate_call = NULL;
98 char *tmp = NULL;
99
100 char *cd_number_str = NULL;
101 char *command = NULL;
102 char *p= NULL;
103 char *tmp1 = NULL;
104 char *tmp2 = NULL;
105
106/*@*********** End Variables ***************************************/
107
108 log_msg(3, "Starting");
109 assert(bkpinfo != NULL);
110 assert_string_is_neither_NULL_nor_zerolength(isofile);
111
112 if (!(midway_call = malloc(1200))) {
113 fatal_error("Cannot malloc midway_call");
114 }
115 if (!(ultimate_call = malloc(1200))) {
116 fatal_error("Cannot malloc ultimate_call");
117 }
118 if (!(tmp = malloc(1200))) {
119 fatal_error("Cannot malloc tmp");
120 }
121
122 if ((bkpinfo->netfs_user) && (strstr(bkpinfo->netfs_proto,"nfs"))) {
123 mr_asprintf(tmp1, "su - %s -c \"%s\"", bkpinfo->netfs_user, basic_call);
124 } else {
125 mr_asprintf(tmp1, "%s", basic_call);
126 }
127
128 mr_asprintf(cd_number_str, "%d", cd_no);
129 resolve_naff_tokens(midway_call, tmp1, isofile, "_ISO_");
130 log_msg(4, "basic call = '%s'", tmp1);
131 mr_free(tmp1);
132
133 resolve_naff_tokens(tmp, midway_call, cd_number_str, "_CD#_");
134 log_msg(4, "midway_call = '%s'", midway_call);
135 mr_free(cd_number_str);
136
137 resolve_naff_tokens(ultimate_call, tmp, MONDO_LOGFILE, "_ERR_");
138 log_msg(4, "ultimate call = '%s'", ultimate_call);
139 mr_asprintf(command, "%s >> %s", ultimate_call, MONDO_LOGFILE);
140
141 log_to_screen("Please be patient. Do not be alarmed by on-screen inactivity.");
142 log_msg(4, "Calling open_evalcall_form() with what_i_am_doing='%s'", what_i_am_doing);
143 if (bkpinfo->manual_cd_tray) {
144 mr_asprintf(tmp2, "%s", command);
145 p = strstr(tmp2, "2>>");
146 if (p) {
147 sprintf(p, " ");
148 while (*p == ' ') {
149 p++;
150 }
151 for (; (*p != ' ') && (*p != '\0'); p++) {
152 *p = ' ';
153 }
154 }
155 mr_free(command);
156 command = tmp2;
157 if (!g_text_mode) {
158 newtSuspend();
159 }
160 log_msg(1, "command = '%s'", command);
161 retval += system(command);
162 if (!g_text_mode) {
163 newtResume();
164 }
165 if (retval) {
166 popup_and_OK("mkisofs and/or cdrecord returned an error. CD was not created");
167 }
168 }
169 /* if text mode then do the above & RETURN; if not text mode, do this... */
170 else {
171 log_msg(3, "command = '%s'", command);
172 retval = run_external_binary_with_percentage_indicator_NEW(what_i_am_doing, command);
173 }
174 mr_free(command);
175 paranoid_free(midway_call);
176 paranoid_free(ultimate_call);
177 paranoid_free(tmp);
178 return (retval);
179}
180
181
182/**
183 * Call copy of data to create an USB image.
184 * @param bkpinfo The backup information structure. Fields used:
185 * - @c bkpinfo->backup_media_type
186 * @return Exit code of @c copy (0 is success, anything else indicates failure).
187 */
188int
189eval_call_to_make_USB(char *command, char *what_i_am_doing) {
190
191 /*@ int's *** */
192 int retval = 0;
193
194
195/*@*********** End Variables ***************************************/
196
197 log_msg(3, "Starting");
198 assert(bkpinfo != NULL);
199
200 log_to_screen
201 ("Please be patient. Do not be alarmed by on-screen inactivity.");
202 log_msg(4, "Calling open_evalcall_form() with what_i_am_doing='%s'",
203 what_i_am_doing);
204
205 if (!g_text_mode) {
206 newtSuspend();
207 }
208 log_msg(1, "command = '%s'", command);
209 if (!g_text_mode) {
210 retval = run_external_binary_with_percentage_indicator_NEW(what_i_am_doing, command);
211 } else {
212 retval += system(command);
213 }
214 if (!g_text_mode) {
215 newtResume();
216 }
217
218 return (retval);
219}
220
221
222
223
224/**
225 * Run a program and log its output (stdout and stderr) to the logfile.
226 * @param program The program to run. Passed to the shell, so you can use pipes etc.
227 * @param debug_level If @p g_loglevel is higher than this, do not log the output.
228 * @return The exit code of @p program (depends on the command, but 0 almost always indicates success).
229 */
230int run_program_and_log_output(char *program, int debug_level)
231{
232 /*@ buffer ****************************************************** */
233 char *callstr = NULL;
234 char incoming[MAX_STR_LEN * 2];
235 char *tmp1 = NULL;
236
237 /*@ int ********************************************************* */
238 int res;
239 bool log_if_failure = FALSE;
240 bool log_if_success = FALSE;
241
242 /*@ pointers *************************************************** */
243 FILE *fin;
244 char *p;
245 char *q;
246
247 /*@ end vars *************************************************** */
248
249 assert(program != NULL);
250 if (!program[0]) {
251 log_msg(2, "Warning - asked to run zerolength program");
252 return (1);
253 }
254
255 if (debug_level <= g_loglevel) {
256 log_if_success = TRUE;
257 log_if_failure = TRUE;
258 }
259 mr_asprintf(callstr, "%s > %s/mondo-run-prog-thing.tmp 2> %s/mondo-run-prog-thing.err", program, bkpinfo->tmpdir, bkpinfo->tmpdir);
260 while ((p = strchr(callstr, '\r'))) {
261 *p = ' ';
262 }
263 while ((p = strchr(callstr, '\n'))) {
264 *p = ' ';
265 } /* single '=' is intentional */
266
267
268 res = system(callstr);
269 if (((res == 0) && log_if_success) || ((res != 0) && log_if_failure)) {
270 log_msg(0, "running: %s", callstr);
271 log_msg(0, "--------------------------------start of output-----------------------------");
272 }
273 mr_free(callstr);
274
275 mr_asprintf(callstr, "cat %s/mondo-run-prog-thing.err >> %s/mondo-run-prog-thing.tmp 2> /dev/null", bkpinfo->tmpdir, bkpinfo->tmpdir);
276 if (log_if_failure && system(callstr)) {
277 log_OS_error("Command failed");
278 }
279 mr_free(callstr);
280
281 mr_asprintf(tmp1, "%s/mondo-run-prog-thing.err", bkpinfo->tmpdir);
282 unlink(tmp1);
283 mr_free(tmp1);
284
285 mr_asprintf(tmp1, "%s/mondo-run-prog-thing.tmp", bkpinfo->tmpdir);
286 fin = fopen(tmp1, "r");
287 if (fin) {
288 for (q = fgets(incoming, MAX_STR_LEN, fin); !feof(fin) && (q != NULL); q = fgets(incoming, MAX_STR_LEN, fin)) {
289 p = incoming;
290 while (p && *p) {
291 if ((p = strchr(p, '%'))) {
292 memmove(p, p + 1, strlen(p) + 1);
293 p += 2;
294 }
295 }
296 strip_spaces(incoming);
297 if ((res == 0 && log_if_success) || (res != 0 && log_if_failure)) {
298 log_msg(0, incoming);
299 }
300 }
301 paranoid_fclose(fin);
302 }
303 unlink(tmp1);
304 mr_free(tmp1);
305
306 if ((res == 0 && log_if_success) || (res != 0 && log_if_failure)) {
307 log_msg(0,
308 "--------------------------------end of output------------------------------");
309 if (res) {
310 log_msg(0, "...ran with res=%d", res);
311 } else {
312 log_msg(0, "...ran just fine. :-)");
313 }
314 }
315 return (res);
316}
317
318
319
320/**
321 * Run a program and log its output to the screen.
322 * @param basic_call The program to run.
323 * @param what_i_am_doing The title of the evalcall form.
324 * @return The return value of the command (varies, but 0 almost always means success).
325 * @see run_program_and_log_output
326 * @see log_to_screen
327 */
328int run_program_and_log_to_screen(char *basic_call, char *what_i_am_doing)
329{
330 /*@ int ******************************************************** */
331 int retval = 0;
332 int res = 0;
333 int i;
334
335 /*@ pointers **************************************************** */
336 FILE *fin;
337
338 /*@ buffers **************************************************** */
339 char *command = NULL;
340 char *lockfile = NULL;
341
342 /*@ end vars *************************************************** */
343
344 assert_string_is_neither_NULL_nor_zerolength(basic_call);
345
346 mr_asprintf(lockfile, "%s/mojo-jojo.bla.bla", bkpinfo->tmpdir);
347
348 mr_asprintf(command, "echo hi > %s ; %s >> %s 2>> %s; res=$?; sleep 1; rm -f %s; exit $res", lockfile, basic_call, MONDO_LOGFILE, MONDO_LOGFILE, lockfile);
349 open_evalcall_form(what_i_am_doing);
350 log_msg(2, "Executing %s", basic_call);
351
352 if (!(fin = popen(command, "r"))) {
353 log_OS_error("Unable to popen-in command");
354 log_to_screen("Failed utterly to call '%s'", command);
355 mr_free(command);
356 mr_free(lockfile);
357 return (1);
358 }
359
360 if (!does_file_exist(lockfile)) {
361 log_to_screen("Waiting for '%s' to start",command);
362 for (i = 0; i < 60 && !does_file_exist(lockfile); sleep(1), i++) {
363 log_msg(3, "Waiting for lockfile %s to exist", lockfile);
364 }
365 }
366 mr_free(command);
367
368 for (; does_file_exist(lockfile); sleep(1)) {
369 log_file_end_to_screen(MONDO_LOGFILE, "");
370 update_evalcall_form(1);
371 }
372
373 /* Evaluate the status returned by pclose to get the exit code of the called program. */
374 errno = 0;
375 res = pclose(fin);
376 /* Log actual pclose errors. */
377 if (errno) log_msg(5, "pclose err: %d", errno);
378 /* Check if we have a valid status. If we do, extract the called program's exit code. */
379 /* If we don't, highlight this fact by returning -1. */
380 if (WIFEXITED(res)) {
381 retval = WEXITSTATUS(res);
382 } else {
383 retval = -1;
384 }
385 close_evalcall_form();
386 unlink(lockfile);
387 mr_free(lockfile);
388
389 return (retval);
390}
391
392
393
394
395/**
396 * Apparently unused. @bug This has a purpose, but what?
397 */
398#define PIMP_START_SZ "STARTSTARTSTART9ff3kff9a82gv34r7fghbkaBBC2T231hc81h42vws8"
399#define PIMP_END_SZ "ENDENDEND0xBBC10xBBC2T231hc81h42vws89ff3kff9a82gv34r7fghbka"
400
401
402
403
404int copy_from_src_to_dest(FILE * f_orig, FILE * f_archived, char direction)
405{
406// if dir=='w' then copy from orig to archived
407// if dir=='r' then copy from archived to orig
408 char *tmp = NULL;
409 char *tmp1 = NULL;
410 char *buf = NULL;
411 char *filestr = NULL;
412 long int bytes_to_be_read, bytes_read_in, bytes_written_out =
413 0, bufcap, subsliceno = 0;
414 int retval = 0;
415 FILE *fin;
416 FILE *fout;
417 FILE *ftmp;
418 int tmpcap = 512;
419
420 log_msg(5, "Opening.");
421
422 bufcap = 256L * 1024L;
423 if (!(buf = malloc(bufcap))) {
424 fatal_error("Failed to malloc() buf");
425 }
426
427 if (direction == 'w') {
428 fin = f_orig;
429 fout = f_archived;
430 mr_asprintf(tmp, "%-64s", PIMP_START_SZ);
431 if (fwrite(tmp, 1, 64, fout) != 64) {
432 mr_free(tmp);
433 fatal_error("Can't write the introductory block");
434 }
435 mr_free(tmp);
436
437 while (1) {
438 bytes_to_be_read = bytes_read_in = fread(buf, 1, bufcap, fin);
439 if (bytes_read_in == 0) {
440 break;
441 }
442 mr_asprintf(tmp, "%-64ld", bytes_read_in);
443 if (fwrite(tmp, 1, 64, fout) != 64) {
444 mr_free(tmp);
445 fatal_error("Cannot write introductory block");
446 }
447 mr_free(tmp);
448
449 log_msg(7,
450 "subslice #%ld --- I have read %ld of %ld bytes in from f_orig",
451 subsliceno, bytes_read_in, bytes_to_be_read);
452 bytes_written_out += fwrite(buf, 1, bytes_read_in, fout);
453 mr_asprintf(tmp, "%-64ld", subsliceno);
454 if (fwrite(tmp, 1, 64, fout) != 64) {
455 mr_free(tmp);
456 fatal_error("Cannot write post-thingy block");
457 }
458 mr_free(tmp);
459 log_msg(7, "Subslice #%d written OK", subsliceno);
460 subsliceno++;
461 }
462 mr_asprintf(tmp, "%-64ld", 0L);
463 if (fwrite(tmp, 1, 64L, fout) != 64L) {
464 mr_free(tmp);
465 fatal_error("Cannot write final introductory block");
466 }
467 mr_free(tmp);
468
469 mr_asprintf(tmp, "%-64s", PIMP_END_SZ);
470 if (fwrite(tmp, 1, 64, fout) != 64) {
471 mr_free(tmp);
472 fatal_error("Can't write the final block");
473 }
474 mr_free(tmp);
475 } else {
476 fin = f_archived;
477 fout = f_orig;
478 if (!(tmp1 = malloc(tmpcap))) {
479 fatal_error("Failed to malloc() tmp");
480 }
481 if (fread(tmp1, 1, 64L, fin) != 64L) {
482 mr_free(tmp1);
483 fatal_error("Cannot read the introductory block");
484 }
485 log_msg(5, "tmp1 is %s", tmp1);
486 if (!strstr(tmp1, PIMP_START_SZ)) {
487 mr_free(tmp1);
488 fatal_error("Can't find intro blk");
489 }
490 if (fread(tmp1, 1, 64L, fin) != 64L) {
491 mr_free(tmp1);
492 fatal_error("Cannot read introductory blk");
493 }
494 bytes_to_be_read = atol(tmp1);
495 while (bytes_to_be_read > 0) {
496 log_msg(7, "subslice#%ld, bytes=%ld", subsliceno, bytes_to_be_read);
497 bytes_read_in = fread(buf, 1, bytes_to_be_read, fin);
498 if (bytes_read_in != bytes_to_be_read) {
499 mr_free(tmp1);
500 fatal_error("Danger, WIll Robinson. Failed to read whole subvol from archives.");
501 }
502 bytes_written_out += fwrite(buf, 1, bytes_read_in, fout);
503 if (fread(tmp1, 1, 64, fin) != 64) {
504 mr_free(tmp1);
505 fatal_error("Cannot read post-thingy block");
506 }
507 if (atol(tmp1) != subsliceno) {
508 log_msg(1, "Wanted subslice %ld but got %ld ('%s')", subsliceno, atol(tmp1), tmp1);
509 }
510 log_msg(7, "Subslice #%ld read OK", subsliceno);
511 subsliceno++;
512 if (fread(tmp1, 1, 64, fin) != 64) {
513 mr_free(tmp1);
514 fatal_error("Cannot read introductory block");
515 }
516 bytes_to_be_read = atol(tmp1);
517 }
518 }
519
520 if (direction == 'w') {
521 mr_asprintf(tmp, "%-64s", PIMP_END_SZ);
522 if (fwrite(tmp, 1, 64, fout) != 64) {
523 mr_free(tmp);
524 fatal_error("Can't write the final block");
525 }
526 mr_free(tmp);
527 } else {
528 log_msg(1, "tmpA is %s", tmp1);
529 if (!strstr(tmp1, PIMP_END_SZ)) {
530 if (fread(tmp1, 1, 64, fin) != 64) {
531 mr_free(tmp1);
532 fatal_error("Can't read the final block");
533 }
534 log_msg(5, "tmpB is %s", tmp1);
535 if (!strstr(tmp1, PIMP_END_SZ)) {
536 mr_asprintf(filestr, "%s/out.leftover", bkpinfo->tmpdir);
537 ftmp = fopen(filestr, "w");
538 mr_free(filestr);
539
540 bytes_read_in = fread(tmp1, 1, 64, fin);
541 log_msg(1, "bytes_read_in = %ld", bytes_read_in);
542
543 if (fwrite(tmp, 1, bytes_read_in, ftmp)) {
544 fatal_error("Can't fwrite here");
545 }
546
547 mr_asprintf(tmp, "I am here - %lld", (long long)ftello(fin));
548 if (fread(tmp, 1, tmpcap, fin)) {
549 mr_free(tmp);
550 fatal_error("Can't fread here");
551 }
552 log_msg(0, "tmp = '%s'", tmp);
553 if (fwrite(tmp, 1, tmpcap, ftmp)) {
554 mr_free(tmp);
555 fatal_error("Can't fwrite there");
556 }
557 fclose(ftmp);
558 mr_free(tmp);
559 fatal_error("Missing terminating block");
560 }
561 }
562 }
563 mr_free(tmp1);
564
565 paranoid_free(buf);
566 log_msg(3, "Successfully copied %ld bytes", bytes_written_out);
567 return (retval);
568}
569
570
571
572
573/**
574 * Feed @p input_device through ntfsclone to @p output_fname.
575 * @param input_device The device to image.
576 * @param output_fname The file to write.
577 * @return 0 for success, nonzero for failure.
578 */
579int feed_into_ntfsprog(char *input_device, char *output_fname)
580{
581// BACKUP
582 int res = -1;
583 char *command = NULL;
584
585 if (!does_file_exist(input_device)) {
586 fatal_error("input device does not exist");
587 }
588 if ( !find_home_of_exe("ntfsclone")) {
589 fatal_error("ntfsclone not found");
590 }
591 mr_asprintf(command, "ntfsclone --rescue --force --save-image --overwrite %s %s", output_fname, input_device);
592 res = run_program_and_log_output(command, 5);
593 mr_free(command);
594
595 unlink(output_fname);
596 return (res);
597}
598
599
600void *run_prog_in_bkgd_then_exit(void *info)
601{
602 char *sz_command;
603 static int res = 4444;
604
605 res = 999;
606 sz_command = (char *) info;
607 log_msg(4, "sz_command = '%s'", sz_command);
608 res = system(sz_command);
609 if (res > 256 && res != 4444) {
610 res = res / 256;
611 }
612 log_msg(4, "child res = %d", res);
613 sz_command[0] = '\0';
614 pthread_exit((void *) (&res));
615}
616
617
618
619
620int run_external_binary_with_percentage_indicator_NEW(char *tt, char *cmd) {
621
622 /*@ int *************************************************************** */
623 int res = 0;
624 int percentage = 0;
625 int maxpc = 100;
626 int pcno = 0;
627 int last_pcno = 0;
628 int counter = 0;
629
630 /*@ buffers *********************************************************** */
631 char *command = NULL;
632 /*@ pointers ********************************************************** */
633 static int chldres = 0;
634 int *pchild_result;
635 pthread_t childthread;
636
637 pchild_result = &chldres;
638 assert_string_is_neither_NULL_nor_zerolength(cmd);
639 assert_string_is_neither_NULL_nor_zerolength(tt);
640 *pchild_result = 999;
641
642 mr_asprintf(command, "%s 2>> %s", cmd, MONDO_LOGFILE);
643 log_msg(3, "command = '%s'", command);
644 if ((res = pthread_create(&childthread, NULL, run_prog_in_bkgd_then_exit, (void *) command))) {
645 fatal_error("Unable to create an archival thread");
646 }
647
648 log_msg(8, "Parent running");
649 open_evalcall_form(tt);
650
651 for (sleep(1); command[0] != '\0'; sleep(1)) {
652 pcno = grab_percentage_from_last_line_of_file(MONDO_LOGFILE);
653 if (pcno < 0 || pcno > 100) {
654 log_msg(8, "Weird pc# %d", pcno);
655 continue;
656 }
657 percentage = pcno * 100 / maxpc;
658 if (pcno <= 5 && last_pcno >= 40) {
659 close_evalcall_form();
660 open_evalcall_form("Verifying...");
661 }
662 if (counter++ >= 5) {
663 counter = 0;
664 log_file_end_to_screen(MONDO_LOGFILE, "");
665 }
666 last_pcno = pcno;
667 update_evalcall_form(percentage);
668 }
669 mr_free(command);
670
671 log_file_end_to_screen(MONDO_LOGFILE, "");
672 close_evalcall_form();
673 pthread_join(childthread, (void *) (&pchild_result));
674 if (pchild_result) {
675 res = *pchild_result;
676 } else {
677 res = 666;
678 }
679 log_msg(3, "Parent res = %d", res);
680 return (res);
681}
682
683
684/**
685 * Feed @p input_fifo through ntfsclone (restore) to @p output_device.
686 * @param input_fifo The ntfsclone file to read.
687 * @param output_device Where to put the output.
688 * @return The return value of ntfsclone (0 for success).
689 */
690int feed_outfrom_ntfsprog(char *output_device, char *input_fifo)
691{
692// RESTORE
693 int res = -1;
694 char *command = NULL;
695
696 if ( !find_home_of_exe("ntfsclone")) {
697 fatal_error("ntfsclone not found");
698 }
699 mr_asprintf(command, "ntfsclone --rescue --force --restore-image --overwrite %s %s", output_device, input_fifo);
700 res = run_program_and_log_output(command, 5);
701 mr_free(command);
702 return (res);
703}
Note: See TracBrowser for help on using the repository browser.