source: MondoRescue/branches/3.3/mondo/src/mondorestore/mondo-rstr-tools.c

Last change on this file was 3893, checked in by Bruno Cornec, 6 weeks ago

Remove more warnings - switch and size_t/int comparisons

  • Property svn:keywords set to Id
File size: 74.7 KB
Line 
1/***************************************************************************
2$Id: mondo-rstr-tools.c 3893 2024-03-13 15:49:30Z bruno $
3***************************************************************************/
4
5#include <pthread.h>
6#include <linux/fd.h>
7#include "my-stuff.h"
8#include "mr_mem.h"
9#include "mr_str.h"
10#include "mr_file.h"
11#include "mr_sys.h"
12#include "mondostructures.h"
13#include "libmondo-mountlist-EXT.h"
14#include "libmondo-tools-EXT.h"
15#include "libmondo-filelist-EXT.h"
16#include "libmondo-files-EXT.h"
17#include "libmondo-devices-EXT.h"
18#include "libmondo-string-EXT.h"
19#include "libmondo-raid-EXT.h"
20#include "libmondo-fork-EXT.h"
21#include "newt-specific-EXT.h"
22// no include for now in mondo-rstr-newt.c
23extern int edit_filelist(struct s_node *);
24
25extern struct s_bkpinfo *bkpinfo;
26
27/**
28 * The biggielist stub (appended to the directory where all.tar.gz was unpacked).
29 */
30#define BIGGIELIST_TXT_STUB "tmp/biggielist.txt"
31
32/**
33 * The filelist stub (appended to the directory where all.tar.gz was unpacked).
34 */
35#define FILELIST_FULL_STUB "tmp/filelist.full.gz"
36
37/**
38 * The mountlist stub (appended to the directory where all.tar.gz was unpacked).
39 */
40#define MOUNTLIST_FNAME_STUB "tmp/mountlist.txt"
41
42/**
43 * The mondorestore.cfg stub (appended to the directory where all.tar.gz was unpacked).
44 */
45#define MONDO_CFG_FILE_STUB "tmp/mondorestore.cfg"
46/**
47 * The i-want-my-lvm stub
48 */
49#define IWANTMYLVM_STUB "tmp/i-want-my-lvm"
50
51extern bool g_ISO_restore_mode; /* are we in Iso Mode? */
52extern bool g_I_have_just_nuked;
53/*
54extern char *g_tmpfs_mountpt;
55*/
56
57/**
58 * The device to mount to get at the ISO images. Ignored unless @p g_ISO_restore_mode.
59 */
60char *g_isodir_device;
61
62
63/**
64 * The format of @p g_isodir_device. Ignored unless @p g_ISO_restore_mode.
65 */
66char *g_isodir_format;
67
68extern long g_current_progress, g_maximum_progress;
69extern char *g_biggielist_txt; // where 'biggielist.txt' is stored, on ramdisk / tempdir;
70 // biggielist.txt is the list of big files stored on the
71 // backup media set in question
72extern char *g_filelist_full; // filelist.full.gz is the list of all regular files
73 // (excluding big files) stored on the backup media set
74extern char *g_biggielist_pot; // list of big files which _could_ be restored, if the
75 // user chooses them
76extern char *g_filelist_imagedevs; // list of devices (e.g. /dev/hda1, /dev/sda5) which
77 // were archived as images, not just /dev entries
78 // ... e.g. NTFS, BeOS partitions
79extern char *g_imagedevs_restthese; // of the imagedevs listed in FILELIST_IMAGEDEVS,
80 // restore only these
81extern char *g_mondo_cfg_file; // where mondorestore.cfg (the config file) is stored
82extern char *g_mountlist_fname; // where mountlist.txt (the mountlist file) is stored
83extern char *g_mondo_home; // homedir of Mondo; usually /usr/local/share/mondo
84extern int g_currentY;
85extern bool g_restoring_live_from_cd;
86extern bool g_text_mode;
87extern int g_current_media_number;
88
89extern t_bkptype g_backup_media_type;
90
91extern int g_partition_table_locked_up;
92extern char *MONDO_LOGFILE;
93
94/* Should we use or not extended attributes and acl when restoring */
95extern char *g_getfattr;
96extern char *g_getfacl;
97
98extern void kill_anything_like_this(char *str);
99extern int skip_obdr(void);
100extern int set_tape_block_size_with_mt(long internal_tape_block_size);
101
102/**
103* @addtogroup restoreUtilityGroup
104* @{
105*/
106/**
107* Free the malloc()s for the filename variables.
108*/
109void free_MR_global_filenames(void)
110{
111paranoid_free(g_biggielist_txt);
112paranoid_free(g_filelist_full);
113paranoid_free(g_filelist_imagedevs);
114paranoid_free(g_imagedevs_restthese);
115paranoid_free(g_mondo_cfg_file);
116paranoid_free(g_mountlist_fname);
117paranoid_free(g_mondo_home);
118/*
119paranoid_free(g_tmpfs_mountpt);
120*/
121paranoid_free(g_isodir_device);
122paranoid_free(g_isodir_format);
123
124}
125
126
127
128/**
129* Ask the user which imagedevs from the list contained in @p infname should
130* actually be restored.
131* @param infname The file containing a list of all imagedevs.
132* @param outfname The location of the output file containing the imagedevs the user wanted to restore.
133* @ingroup restoreUtilityGroup
134*/
135void ask_about_these_imagedevs(char *infname, char *outfname) {
136
137FILE *fin;
138FILE *fout;
139char *incoming = NULL;
140char *p = NULL;
141char *question = NULL;
142
143assert_string_is_neither_NULL_nor_zerolength(infname);
144assert_string_is_neither_NULL_nor_zerolength(outfname);
145
146if (!(fin = fopen(infname, "r"))) {
147 fatal_error("Cannot openin infname");
148}
149if (!(fout = fopen(outfname, "w"))) {
150 fatal_error("Cannot openin outfname");
151}
152for (mr_getline(p, fin); !feof(fin) && (p != NULL); mr_getline(p, fin)) {
153 incoming = mr_strip_spaces(p);
154 mr_free(p);
155
156 if (incoming[0] == '\0') {
157 mr_free(incoming);
158 continue;
159 }
160
161 mr_asprintf(question, "Should I restore the image of %s ?", incoming);
162
163 if (ask_me_yes_or_no(question)) {
164 fprintf(fout, "%s\n", incoming);
165 }
166 mr_free(incoming);
167}
168mr_free(incoming);
169mr_free(question);
170paranoid_fclose(fout);
171paranoid_fclose(fin);
172}
173
174/**************************************************************************
175*ASK_ABOUT_THESE_IMAGEDEVS *
176**************************************************************************/
177
178
179
180/**
181 * Extract mondorestore.cfg and the mountlist from the tape inserted
182 * to the ./tmp/ directory.
183 * @param dev The tape device to read from.
184 * @return 0 for success, nonzero for failure.
185 */
186int extract_cfg_file_and_mountlist_from_tape_dev(char *dev)
187{
188 char *command = NULL;
189 int res = 0;
190
191 if (bkpinfo->use_obdr) {
192 skip_obdr();
193 } else {
194 // TODO: below 32KB seems to block at least on RHAS 2.1 and MDK 10.0
195 set_tape_block_size_with_mt(bkpinfo->internal_tape_block_size);
196 }
197
198 mr_asprintf(command, "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx ./%s ./%s ./%s ./%s ./%s", dev, bkpinfo->internal_tape_block_size, 1024L * 1024 * 32 / bkpinfo->internal_tape_block_size, MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB);
199 log_msg(2, "command = '%s'", command);
200 res = run_program_and_log_output(command, -1);
201 mr_free(command);
202
203 if (res != 0) {
204 if (does_file_exist(MONDO_CFG_FILE_STUB)) {
205 res = 0;
206 } else {
207 /* Doing that allow us to remain compatible with pre-2.2.5 versions */
208 log_msg(2, "pre-2.2.4 compatible mode on");
209 mr_asprintf(command, "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx %s %s %s %s %s", dev, bkpinfo->internal_tape_block_size, 1024L * 1024 * 32 / bkpinfo->internal_tape_block_size, MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB);
210 log_msg(2, "command = '%s'", command);
211 res = run_program_and_log_output(command, -1);
212 mr_free(command);
213 if ((res != 0) && (does_file_exist(MONDO_CFG_FILE_STUB))) {
214 res = 0;
215 }
216 }
217 }
218 paranoid_free(command);
219 return (res);
220}
221
222
223
224
225
226/**
227 * Get the configuration file from the tape, or CD.
228 * @param bkpinfo The backup information structure. Fields used:
229 * - @c bkpinfo->backup_media_type
230 * - @c bkpinfo->media_device
231 * - @c bkpinfo->tmpdir
232 * @return 0 for success, nonzero for failure.
233 */
234int get_cfg_file_from_archive()
235{
236 int retval = 0;
237
238 /** malloc *****/
239 char *command = NULL;
240 char *cfg_file = NULL;
241 char *tmp = NULL;
242 char *tmp1 = NULL;
243 char *mountpt = NULL;
244 char *mountlist_file = NULL;
245 bool extract_mountlist_stub = FALSE;
246 bool extract_i_want_my_lvm = FALSE;
247
248 bool try_plan_B;
249
250 assert(bkpinfo != NULL);
251 log_msg(2, "gcffa --- starting");
252 log_to_screen("I'm thinking...");
253 mr_asprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir);
254 if (chdir(bkpinfo->tmpdir)) {
255 // FIXME
256 }
257 mr_asprintf(cfg_file, "%s", MONDO_CFG_FILE_STUB);
258 unlink(cfg_file); // cfg_file[] is missing the '/' at the start, FYI, by intent
259 mr_free(cfg_file);
260
261 unlink(FILELIST_FULL_STUB);
262 unlink(BIGGIELIST_TXT_STUB);
263 mr_asprintf(command, "mkdir -p %s", mountpt);
264 run_program_and_log_output(command, FALSE);
265 mr_free(command);
266
267 mr_asprintf(cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB);
268 mr_asprintf(mountlist_file, "%s/%s", bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);
269 log_msg(2, "mountpt = %s; cfg_file=%s", mountpt, cfg_file);
270 mr_free(mountpt);
271
272 if (!does_file_exist(cfg_file)) {
273 log_msg(2, "gcffa --- we don't have cfg file yet.");
274 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
275 try_plan_B = TRUE;
276 } else {
277 log_msg(2, "gcffa --- calling mount_media now :)");
278 if (!mount_media(MNT_CDROM)) {
279 log_msg(2, "gcffa --- managed to mount CD; so, no need for Plan B");
280 try_plan_B = FALSE;
281 } else {
282 try_plan_B = TRUE;
283 }
284 if (what_number_cd_is_this() > 1) {
285 insist_on_this_cd_number((g_current_media_number = 1));
286 }
287 }
288 if (try_plan_B) {
289 log_msg(2, "gcffa --- OK, switching to Plan B");
290 if (chdir(bkpinfo->tmpdir)) {
291 // FIXME
292 }
293 run_program_and_log_output("mkdir -p tmp", FALSE);
294
295 if (bkpinfo->media_device == NULL) {
296 mr_asprintf(bkpinfo->media_device, "%s", "/dev/st0");
297 log_msg(2, "media_device is blank; assuming %s", bkpinfo->media_device);
298 }
299 mr_asprintf(tmp, "%s", bkpinfo->media_device);
300 if (extract_cfg_file_and_mountlist_from_tape_dev(bkpinfo->media_device)) {
301 mr_free(bkpinfo->media_device);
302 mr_asprintf(bkpinfo->media_device, "%s", "/dev/st0");
303 if (extract_cfg_file_and_mountlist_from_tape_dev(bkpinfo->media_device)) {
304 mr_free(bkpinfo->media_device);
305 mr_asprintf(bkpinfo->media_device, "%s", "/dev/osst0");
306 if (extract_cfg_file_and_mountlist_from_tape_dev(bkpinfo->media_device)) {
307 mr_free(bkpinfo->media_device);
308 mr_asprintf(bkpinfo->media_device, "%s", "/dev/ht0");
309 if (extract_cfg_file_and_mountlist_from_tape_dev(bkpinfo->media_device)) {
310 log_msg(3, "I tried lots of devices but none worked.");
311 mr_free(bkpinfo->media_device);
312 }
313 }
314 }
315 }
316 if (bkpinfo->media_device == NULL) {
317 bkpinfo->media_device = tmp;
318 } else {
319 mr_free(tmp);
320 }
321
322 if (!does_file_exist("tmp/mondorestore.cfg")) {
323 log_to_screen("Cannot find config info on media");
324 return (1);
325 }
326 } else {
327 if (does_file_exist("/"MOUNTLIST_FNAME_STUB)) {
328 extract_mountlist_stub = FALSE;
329 } else {
330 extract_mountlist_stub = TRUE;
331 }
332 if (does_file_exist("/"IWANTMYLVM_STUB)) {
333 extract_i_want_my_lvm = FALSE;
334 } else {
335 extract_i_want_my_lvm = TRUE;
336 }
337
338 log_msg(2, "gcffa --- Plan B, a.k.a. untarring some file from all.tar.gz");
339 mr_asprintf(command, "tar -zxvf " MNT_CDROM "/images/all.tar.gz ./%s ./%s ./%s ./%s ./%s", MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB); // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary
340 run_program_and_log_output(command, TRUE);
341 mr_free(command);
342
343 if (!does_file_exist(MONDO_CFG_FILE_STUB)) {
344 /* Doing that allow us to remain compatible with pre-2.2.5 versions */
345 log_msg(2, "pre-2.2.4 compatible mode on");
346 mr_asprintf(command, "tar -zxvf " MNT_CDROM "/images/all.tar.gz %s %s %s %s %s", MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB); // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary
347 run_program_and_log_output(command, TRUE);
348 mr_free(command);
349 if (!does_file_exist(MONDO_CFG_FILE_STUB)) {
350 fatal_error
351 ("Please reinsert the disk/CD and try again.");
352 }
353 }
354 }
355 }
356 if (does_file_exist(MONDO_CFG_FILE_STUB)) {
357 log_msg(1, "gcffa --- great! We've got the config file");
358 tmp1 = call_program_and_get_last_line_of_output("pwd");
359 mr_asprintf(tmp, "%s/%s", tmp1, MONDO_CFG_FILE_STUB);
360 mr_asprintf(command, "cp -f %s %s", tmp, cfg_file);
361 log_it("%s",command);
362 if (strcmp(tmp, cfg_file) && run_program_and_log_output(command, 1)) {
363 log_msg(1,
364 "... but an error occurred when I tried to move it to %s",
365 cfg_file);
366 } else {
367 log_msg(1, "... and I moved it successfully to %s", cfg_file);
368 }
369 mr_free(command);
370
371 mr_asprintf(command, "cp -f %s/%s %s", tmp1, MOUNTLIST_FNAME_STUB, mountlist_file);
372 mr_free(tmp1);
373 log_it("%s",command);
374 if (extract_mountlist_stub) {
375 if (strcmp(tmp, cfg_file) && run_program_and_log_output(command, 1)) {
376 log_msg(1, "Failed to get mountlist");
377 } else {
378 log_msg(1, "Got mountlist too");
379 mr_free(command);
380 mr_asprintf(command, "cp -f %s %s", mountlist_file, g_mountlist_fname);
381 if (run_program_and_log_output(command, 1)) {
382 log_msg(1, "Failed to copy mountlist to /tmp");
383 } else {
384 log_msg(1, "Copied mountlist to /tmp as well OK");
385 mr_free(command);
386 mr_asprintf(command, "cp -f %s /tmp/",IWANTMYLVM_STUB);
387 run_program_and_log_output(command, 1);
388 }
389 }
390 }
391 mr_free(command);
392 mr_free(tmp);
393 }
394
395 run_program_and_log_output("umount -d " MNT_CDROM, FALSE);
396 if (!does_file_exist(cfg_file)) {
397 log_it("%s",cfg_file);
398 log_msg(1, "%s not found", cfg_file);
399 log_to_screen("Oh dear. Unable to recover configuration file from boot disk");
400 return (1);
401 }
402
403 log_to_screen("Recovered mondorestore.cfg");
404 if (!does_file_exist(MOUNTLIST_FNAME_STUB)) {
405 log_to_screen("...but not mountlist.txt - a pity, really...");
406 } else {
407 /* Is this code really useful ??? */
408 if (extract_mountlist_stub) {
409 mr_asprintf(command, "cp -f %s %s/%s", MOUNTLIST_FNAME_STUB, bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);
410 run_program_and_log_output(command, FALSE);
411 mr_free(command);
412 }
413 }
414
415 mr_asprintf(command, "cp -f %s /%s", cfg_file, MONDO_CFG_FILE_STUB);
416 mr_free(cfg_file);
417
418 run_program_and_log_output(command, FALSE);
419 mr_free(command);
420
421 if (extract_mountlist_stub) {
422 mr_asprintf(command, "cp -f %s /%s", mountlist_file, MOUNTLIST_FNAME_STUB);
423 run_program_and_log_output(command, FALSE);
424 mr_free(command);
425 }
426 mr_free(mountlist_file);
427
428 mr_asprintf(command, "cp -f etc/raidtab /etc/");
429 run_program_and_log_output(command, FALSE);
430 mr_free(command);
431
432 if (extract_i_want_my_lvm) {
433 mr_asprintf(command, "cp -f %s /tmp/",IWANTMYLVM_STUB);
434 run_program_and_log_output(command, FALSE);
435 mr_free(command);
436 }
437 g_backup_media_type = bkpinfo->backup_media_type;
438 return (retval);
439}
440
441/**************************************************************************
442 *END_GET_CFG_FILE_FROM_ARCHIVE *
443 **************************************************************************/
444
445
446
447
448/**
449* Extract @c mondorestore.cfg and @c mountlist.txt from @p ramdisk_fname.
450* @param bkpinfo The backup information structure. @c tmpdir is the only field used.
451* @param ramdisk_fname The filename of the @b compressed ramdisk to look in.
452* @param output_cfg_file Where to put the configuration file extracted.
453* @param output_mountlist_file Where to put the mountlist file extracted.
454* @return 0 for success, nonzero for failure.
455* @ingroup restoreUtilityGroup
456*/
457
458/**
459* Keep trying to get mondorestore.cfg from the archive, until the user gives up.
460*/
461void get_cfg_file_from_archive_or_bust()
462{
463while (get_cfg_file_from_archive()) {
464 if (!ask_me_yes_or_no("Failed to find config file/archives. Choose another source?")) {
465 fatal_error("Could not find config file/archives. Aborting.");
466 }
467 interactively_obtain_media_parameters_from_user(FALSE);
468 }
469}
470
471
472/**
473* Determine whether @p list_fname contains a line containing @p f.
474* @param f The line to search for.
475* @param list_fname The file to search in.
476* @param preamble Ignore this beginning part of @p f ("" to disable).
477* @return TRUE if it's in the list, FALSE if it's not.
478*/
479bool is_file_in_list(char *f, char *list_fname, char *preamble)
480{
481
482char *command = NULL;
483char *file = NULL;
484char *tmp = NULL;
485int res;
486
487assert_string_is_neither_NULL_nor_zerolength(f);
488assert_string_is_neither_NULL_nor_zerolength(list_fname);
489assert(preamble != NULL);
490
491if (strncmp(preamble, f, strlen(preamble)) == 0) {
492 mr_asprintf(file, "%s", f + strlen(preamble));
493} else {
494 mr_asprintf(file, "%s", f);
495}
496if (file[0] == '/' && file[1] == '/') {
497 tmp = file;
498
499 mr_asprintf(file, "%s", tmp + 1);
500 mr_free(tmp);
501}
502log_msg(2, "Checking to see if f=%s, file=%s, is in the list of biggiefiles", f, file);
503mr_asprintf(command, "grep -E '^%s$' %s", file, list_fname);
504mr_free(file);
505
506res = run_program_and_log_output(command, FALSE);
507mr_free(command);
508if (res) {
509 return (FALSE);
510} else {
511 return (TRUE);
512}
513}
514
515/**************************************************************************
516*END_IS_FILE_IN_LIST *
517**************************************************************************/
518
519/**
520 * Get information about the location of ISO images from the user.
521 * @param isodir_device Where to put the device (e.g. /dev/hda4) the user enters.
522 * @param isodir_format Where to put the format (e.g. ext2) the user enters.
523 * @param nuke_me_please Whether we're planning on nuking or not.
524 * @return TRUE if OK was pressed, FALSE otherwise.
525 */
526bool get_isodir_info(char *isodir_device, char *isodir_format, bool nuke_me_please)
527{
528
529 bool HDD = FALSE;
530 char *tmp = NULL;
531 /** initialize ********************************************************/
532
533 assert(isodir_device != NULL);
534 assert(isodir_format != NULL);
535 assert(bkpinfo->isodir != NULL);
536
537 log_it("bkpinfo->isodir = %s", bkpinfo->isodir);
538 isodir_format[0] = '\0';
539 if (isodir_device[0] == '\0') {
540 strcpy(isodir_device, "/dev/");
541 }
542 if (bkpinfo->isodir == NULL) {
543 mr_asprintf(bkpinfo->isodir, "%s", "/");
544 }
545 // TODO: Are we sure it does what it's expected to do here ?
546 if (does_file_exist("/tmp/NETFS-SERVER-MOUNT")) {
547 strcpy(isodir_device, last_line_of_file("/tmp/NETFS-SERVER-MOUNT"));
548 strcpy(isodir_format, "netfs");
549 mr_asprintf(bkpinfo->isodir, "%s", last_line_of_file("/tmp/ISO-DIR"));
550 }
551 if (nuke_me_please) {
552 return (TRUE);
553 }
554
555 if (popup_and_get_string("ISO Mode - device", "On what device do the ISO files live?", isodir_device, MAX_STR_LEN / 4)) {
556 if (popup_and_get_string ("ISO Mode - format", "What is the disk format of the device? (Hit ENTER if you don't know.)", isodir_format, 16)) {
557 if (popup_with_buttons("Are you restoring from an external hard drive ?", "Yes", "No")) {
558 HDD = TRUE;
559 }
560 tmp = mr_popup_and_get_string ("ISO Mode - path", "At what path on this device can the ISO files be found ?", bkpinfo->isodir);
561 if (tmp) {
562 strip_spaces(isodir_device);
563 strip_spaces(isodir_format);
564 bkpinfo->isodir = mr_strip_spaces(tmp);
565 mr_free(tmp);
566 log_it("isodir_device = %s - isodir_format = %s - bkpinfo->isodir = %s", isodir_device, isodir_format, bkpinfo->isodir);
567 if (HDD) {
568 /* We need an additional param */
569 mr_asprintf(bkpinfo->subdir, "%s", bkpinfo->isodir);
570 mr_asprintf(bkpinfo->isodir, "%s", "/tmp/isodir");
571 log_it("Now bkpinfo->isodir = %s and subdir = ", bkpinfo->isodir, bkpinfo->subdir);
572 }
573 return (TRUE);
574 }
575 }
576 }
577 return (FALSE);
578}
579
580
581/**
582* Set up an ISO backup.
583* @param bkpinfo The backup information structure. Fields used:
584* - @c bkpinfo->backup_media_type
585* - @c bkpinfo->disaster_recovery
586* - @c bkpinfo->isodir
587* @param nuke_me_please If TRUE, we're in nuke mode; if FALSE we're in interactive mode.
588* @return 0 for success, nonzero for failure.
589*/
590int iso_fiddly_bits(bool nuke_me_please) {
591
592char *mount_isodir_command = NULL;
593char *command = NULL;
594char *mds = NULL;
595int retval = 0, i;
596
597g_ISO_restore_mode = TRUE;
598read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device);
599if (bkpinfo->disaster_recovery) {
600 /* Don't let this clobber an existing bkpinfo->isodir */
601 if (bkpinfo->isodir == NULL) {
602 mr_asprintf(bkpinfo->isodir, "%s", "/tmp/isodir");
603 }
604 mr_asprintf(command, "mkdir -p %s", bkpinfo->isodir);
605 run_program_and_log_output(command, 5);
606 mr_free(command);
607 log_msg(2, "Setting isodir to %s", bkpinfo->isodir);
608}
609
610if (!get_isodir_info(g_isodir_device, g_isodir_format, nuke_me_please)) {
611 return (1);
612}
613paranoid_system("umount -d " MNT_CDROM " 2> /dev/null"); /* just in case */
614
615if (is_this_device_mounted(g_isodir_device)) {
616 log_to_screen("WARNING - isodir is already mounted");
617} else {
618 mr_asprintf(mount_isodir_command, "mount %s", g_isodir_device);
619 if (strlen(g_isodir_format) > 1) {
620 mr_strcat(mount_isodir_command, " -t %s", g_isodir_format);
621 }
622
623 mr_strcat(mount_isodir_command, " -o ro %s", bkpinfo->isodir);
624 run_program_and_log_output("df -m -P -T", FALSE);
625 log_msg(1, "The 'mount' command is '%s'. PLEASE report this command to be if you have problems, ok?", mount_isodir_command);
626 if (run_program_and_log_output(mount_isodir_command, FALSE)) {
627 popup_and_OK("Cannot mount the device where the ISO files are stored.");
628 return (1);
629 }
630 paranoid_free(mount_isodir_command);
631 log_to_screen("I have mounted the device where the ISO files are stored.");
632}
633if (!IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
634 mount_media(MNT_CDROM);
635}
636i = what_number_cd_is_this(); /* has the side-effect of calling mount_media() */
637mds = media_descriptor_string(bkpinfo->backup_media_type);
638mr_free(mds);
639
640log_msg(1, "%s #%d has been mounted via loopback mount", mds, i);
641if (i < 0) {
642 popup_and_OK("Cannot find ISO images in the directory you specified.");
643 retval = 1;
644}
645log_msg(2, "bkpinfo->isodir is now %s", bkpinfo->isodir);
646return (retval);
647}
648
649
650
651
652/**
653* Kill all Petris processes.
654*/
655void kill_petris(void) {
656 kill_anything_like_this("petris");
657}
658
659/**************************************************************************
660*END_KILL_PETRIS *
661**************************************************************************/
662
663
664/**
665 * Mount @p device at @p mpt as @p format.
666 * @param device The device (/dev entry) to mount.
667 * @param mpt The directory to mount it on.
668 * @param format The filesystem type of @p device.
669 * @param writeable If TRUE, mount read-write; if FALSE, mount read-only.
670 * @return 0 for success, nonzero for failure.
671 */
672int mount_device(char *device, char *mpt, char *format, bool writeable)
673{
674int res = 0;
675
676/** malloc **/
677char *tmp = NULL;
678char *command = NULL;
679char *mountdir = NULL;
680char *mountpoint = NULL;
681char *additional_parameters = NULL;
682
683assert_string_is_neither_NULL_nor_zerolength(device);
684assert_string_is_neither_NULL_nor_zerolength(mpt);
685assert(format != NULL);
686
687 if (!strcmp(mpt, "/1")) {
688 mr_asprintf(mountpoint, "/");
689 log_msg(3, "Mommm! SME is being a dildo!");
690 } else {
691 mr_asprintf(mountpoint, "%s", mpt);
692 }
693
694 if (!strcmp(mountpoint, "lvm")) {
695 return (0);
696 }
697 if (!strcmp(mountpoint, "image")) {
698 return (0);
699 }
700 mr_asprintf(tmp, "Mounting device %s ", device);
701 log_msg(1, tmp);
702 /* Deal with additional params only if not /proc or /sys */
703 mr_asprintf(additional_parameters, "");
704 if (strcmp(format, "proc") && strcmp(format, "sys")) {
705 if (writeable) {
706 mr_strcat(additional_parameters, "-o rw");
707 } else {
708 mr_strcat(additional_parameters, "-o ro");
709 }
710 if ((tmp = find_home_of_exe("setfattr")) != NULL) {
711 mr_strcat(additional_parameters, ",user_xattr");
712 }
713 mr_free(tmp);
714 if ((tmp = find_home_of_exe("setfacl")) != NULL) {
715 mr_strcat(additional_parameters, ",acl");
716 }
717 mr_free(tmp);
718 }
719
720 if (!strcmp(mountpoint, "swap")) {
721 mr_asprintf(command, "swapon %s", device);
722 mr_asprintf(mountdir, "swap");
723 } else {
724 if (!strcmp(mountpoint, "/")) {
725 mr_asprintf(mountdir, "%s", MNT_RESTORING);
726 } else {
727 mr_asprintf(mountdir, "%s%s", MNT_RESTORING, mountpoint);
728 }
729 mr_asprintf(command, "mkdir -p %s", mountdir);
730 run_program_and_log_output(command, FALSE);
731 mr_free(command);
732
733 mr_asprintf(command, "mount -t %s %s %s %s 2>> %s", format, device, additional_parameters, mountdir, MONDO_LOGFILE);
734 log_msg(2, "command='%s'", command);
735 }
736 mr_free(additional_parameters);
737
738 res = run_program_and_log_output(command, TRUE);
739 if (res && (strstr(command, "xattr") || strstr(command, "acl"))) {
740 log_msg(1, "Re-trying without the fancy extra parameters");
741 mr_free(command);
742 mr_asprintf(command, "mount -t %s %s %s 2>> %s", format, device, mountdir, MONDO_LOGFILE);
743 res = run_program_and_log_output(command, TRUE);
744 }
745 if (res) {
746 log_msg(1, "Unable to mount device %s (type %s) at %s", device, format, mountdir);
747 log_msg(1, "command was '%s'", command);
748 if (!strcmp(mountpoint, "swap")) {
749 log_to_screen(tmp);
750 } else {
751 log_msg(2, "Retrying w/o the '-t' switch");
752 mr_free(command);
753 mr_asprintf(command, "mount %s %s 2>> %s", device, mountdir, MONDO_LOGFILE);
754 log_msg(2, "2nd command = '%s'", command);
755 res = run_program_and_log_output(command, TRUE);
756 if (res == 0) {
757 log_msg(1,
758 "That's OK. I called mount w/o a filesystem type and it worked fine in the end.");
759 } else {
760 log_to_screen(tmp);
761 }
762 }
763 }
764
765 if (res && !strcmp(mountpoint, "swap")) {
766 log_msg(2, "That's ok. It's just a swap partition.");
767 log_msg(2, "Non-fatal error. Returning 0.");
768 res = 0;
769 }
770
771mr_free(tmp);
772mr_free(command);
773mr_free(mountdir);
774mr_free(mountpoint);
775
776return (res);
777}
778/**************************************************************************
779 *END_MOUNT_DEVICE *
780**************************************************************************/
781
782
783/**
784 * Mount all devices in @p p_external_copy_of_mountlist on @p MNT_RESTORING.
785 * @param p_external_copy_of_mountlist The mountlist containing devices to be mounted.
786 * @param writeable If TRUE, then mount read-write; if FALSE mount read-only.
787 * @return The number of errors encountered (0 for success).
788 */
789int mount_all_devices(struct mountlist_itself *p_external_copy_of_mountlist, bool writeable)
790{
791int retval = 0, lino, res;
792char *tmp = NULL;
793char *these_failed = NULL;
794struct mountlist_itself *mountlist = NULL;
795
796assert(p_external_copy_of_mountlist != NULL);
797mountlist = malloc(sizeof(struct mountlist_itself));
798memcpy((void *) mountlist, (void *) p_external_copy_of_mountlist,
799 sizeof(struct mountlist_itself));
800 sort_mountlist_by_mountpoint(mountlist, 0);
801
802
803 mvaddstr_and_log_it(g_currentY, 0, "Mounting devices ");
804 open_progress_form("Mounting devices", "I am now mounting all the drives.", "This should not take long.", "", mountlist->entries);
805
806 mr_asprintf(these_failed, "");
807 for (lino = 0; lino < mountlist->entries; lino++) {
808 if (!strcmp(mountlist->el[lino].device, "/proc")) {
809 log_msg(1, "Again with the /proc - why is this in your mountlist?");
810 } else if (is_this_device_mounted(mountlist->el[lino].device)) {
811 log_to_screen("%s is already mounted", mountlist->el[lino].device);
812 } else if (strcmp(mountlist->el[lino].mountpoint, "none")
813 && strcmp(mountlist->el[lino].mountpoint, "lvm")
814 && strcmp(mountlist->el[lino].mountpoint, "raid")
815 && strcmp(mountlist->el[lino].mountpoint, "image")) {
816 mr_asprintf(tmp, "Mounting %s", mountlist->el[lino].device);
817 update_progress_form(tmp);
818 mr_free(tmp);
819 res = mount_device(mountlist->el[lino].device, mountlist->el[lino].mountpoint, mountlist->el[lino].format, writeable);
820 retval += res;
821 if (res) {
822 mr_strcat(these_failed, "%s ",mountlist->el[lino].device);
823 }
824 }
825 g_current_progress++;
826 }
827 close_progress_form();
828 if (retval) {
829 if (g_partition_table_locked_up > 0) {
830 log_to_screen("fdisk's ictol() call to refresh its copy of the partition table causes the kernel to");
831 log_to_screen("lock up the partition table. You might have to reboot and use Interactive Mode to");
832 log_to_screen("format and restore *without* partitioning first. Sorry for the inconvenience.");
833 }
834 mr_asprintf(tmp, "Could not mount device(s) %s- shall I abort?", these_failed);
835
836 if (!ask_me_yes_or_no(tmp)) {
837 retval = 0;
838 log_to_screen("Continuing, although some device(s) failed to be mounted");
839 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
840 } else {
841 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
842 log_to_screen("Unable to mount some or all of your partitions.");
843 }
844 mr_free(tmp);
845 } else {
846 log_to_screen("All partitions were mounted OK.");
847 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
848 }
849 paranoid_free(these_failed);
850
851 /* Also mounting under MNT_RESTORING special FS */
852 (void)mount_device("/proc","/proc","proc",TRUE);
853 (void)mount_device("/sys","/sys","sysfs",TRUE);
854 /* BR#852: we need to create BTRFS subvols now */
855 /* Creating potential btrfs subvolumes */
856 if (does_file_exist("/tmp/create-btrfs-subvol")) {
857 run_program_and_log_output("/tmp/create-btrfs-subvol",3);
858 }
859 /* Mounting potential btrfs subvolumes */
860 if (does_file_exist("/tmp/mount-btrfs-subvol")) {
861 run_program_and_log_output("/tmp/mount-btrfs-subvol",3);
862 }
863 run_program_and_log_output("df -m -P -T", 3);
864 paranoid_free(mountlist);
865 return (retval);
866}
867/**************************************************************************
868*END_MOUNT_ALL_DEVICES *
869**************************************************************************/
870
871
872/**
873* Fix some miscellaneous things in the filesystem so the system will come
874* up correctly on the first boot.
875*/
876void protect_against_braindead_sysadmins() {
877
878run_program_and_log_output("touch " MNT_RESTORING "/var/log/pacct", 0);
879run_program_and_log_output("touch " MNT_RESTORING "/var/account/pacct", 0);
880
881/* Log the status of the boot area */
882run_program_and_log_output("ls -alR " MNT_RESTORING "/boot", 0);
883
884if (run_program_and_log_output("ls -al " MNT_RESTORING " /tmp", 0)) {
885 run_program_and_log_output("chmod 1777 " MNT_RESTORING "/tmp", 0);
886}
887run_program_and_log_output("mkdir -p " MNT_RESTORING "/var/run/console", 0);
888run_program_and_log_output("chmod 666 " MNT_RESTORING "/dev/null", 0);
889/* This doesn't work as the mkdir should be done in home ! Maybe time to remove
890 run_program_and_log_output("cd " MNT_RESTORING "; for i in `ls home/`; do echo \"Moving $i's spurious files to $i/.disabled\"; mkdir \"$i\"/.disabled ; mv -f \"$i\"/.DCOP* \"$i\"/.MCOP* \"$i\"/.*authority \"$i\"/.kde/tmp* \"$i\"/.kde/socket* \"$i\"/.disabled/ ; done", 1);
891 */
892run_program_and_log_output("rm -f " MNT_RESTORING "/var/run/*.pid", 1);
893run_program_and_log_output("rm -f " MNT_RESTORING "/var/lock/subsys/*", 1);
894}
895
896/**************************************************************************
897*END_PROTECT_AGAINST_BRAINDEAD_SYSADMINS *
898**************************************************************************/
899
900
901
902
903/**
904* Fill out @p bkpinfo based on @p cfg_file.
905* @param cfg_file The mondorestore.cfg file to read into @p bkpinfo.
906* @param bkpinfo The backup information structure to fill out with information
907* from @p cfg_file.
908* @return 0 for success, nonzero for failure.
909*/
910int read_cfg_file_into_bkpinfo(char *cfgf)
911{
912/** add mallocs **/
913char value[MAX_STR_LEN];
914char *tmp = NULL;
915char *tmp1 = NULL;
916char *envtmp1 = NULL;
917char *envtmp2 = NULL;
918char *command = NULL;
919char iso_mnt[MAX_STR_LEN];
920char iso_path[MAX_STR_LEN];
921char *old_isodir = NULL;
922char *cfg_file = NULL;
923t_bkptype media_specified_by_user;
924
925// assert_string_is_neither_NULL_nor_zerolength(cfg_file);
926assert(bkpinfo != NULL);
927assert(cfgf != NULL);
928log_it("Entering read_cfg_file_into_bkpinfo");
929
930if (!cfgf) {
931 mr_asprintf(cfg_file, "%s", g_mondo_cfg_file);
932} else {
933 mr_asprintf(cfg_file, "%s", cfgf);
934}
935
936media_specified_by_user = bkpinfo->backup_media_type; // or 'none', if not specified
937
938if (0 == read_cfg_var(cfg_file, "backup-media-type", value)) {
939 if (!strcmp(value, "optical")) {
940 bkpinfo->backup_media_type = optical;
941 } else if (!strcmp(value, "usb")) {
942 bkpinfo->backup_media_type = usb;
943 bkpinfo->please_dont_eject = TRUE;
944 } else if (!strcmp(value, "iso")) {
945 bkpinfo->backup_media_type = iso;
946 if (am_I_in_disaster_recovery_mode()) {
947 /* Check to see if CD is already mounted before mounting it... */
948 if (!is_this_device_mounted("/dev/cdrom")) {
949 log_msg(2, "NB: CDROM device not mounted, mounting...");
950 run_program_and_log_output("mount /dev/cdrom "MNT_CDROM, 1);
951 }
952 if (does_file_exist(ARCHIVES_PATH "/filelist.0")) {
953 bkpinfo->backup_media_type = optical;
954 run_program_and_log_output("umount -d "MNT_CDROM, 1);
955 log_it("Re-jigging configuration AGAIN. Optical, not ISO.");
956 }
957 }
958 if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) {
959 mr_asprintf(bkpinfo->prefix, "%s", value);
960 } else {
961 mr_asprintf(bkpinfo->prefix, "%s", STD_PREFIX);
962 }
963 log_it("Setting Prefix to %s", bkpinfo->prefix);
964 } else if ((!strcmp(value, "netfs")) || (!strcmp(value, "nfs"))) {
965 /* Stay compatible with previous versions by allowing nfs as an entry here */
966 bkpinfo->backup_media_type = netfs;
967 bkpinfo->please_dont_eject = TRUE;
968 if (read_cfg_var(cfg_file, "netfs-proto", value) == 0) {
969 mr_asprintf(bkpinfo->netfs_proto,"%s", value);
970 } else {
971 /* For compatibility, force protocol in old nfs case to be transparent */
972 mr_asprintf(bkpinfo->netfs_proto, "nfs");
973 }
974 if (read_cfg_var(cfg_file, "netfs-server-user", value) == 0) {
975 mr_asprintf(bkpinfo->netfs_user,"%s", value);
976 }
977 if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) {
978 mr_asprintf(bkpinfo->prefix, "%s", value);
979 } else {
980 mr_asprintf(bkpinfo->prefix, "%s", STD_PREFIX);
981 }
982 tmp1 = call_program_and_get_last_line_of_output("cat "CMDLINE);
983 if (strstr(tmp1, "pxe")) {
984 /* We need to override prefix value in PXE mode as it's
985 * already done in start-netfs */
986 envtmp1 = getenv("imgname");
987 if (envtmp1 == NULL) {
988 fatal_error("no imgname variable in environment");
989 }
990 mr_asprintf(bkpinfo->prefix, "%s", envtmp1);
991 }
992 mr_free(tmp1);
993 } else if (!strcmp(value, "tape")) {
994 bkpinfo->backup_media_type = tape;
995 } else if (!strcmp(value, "udev")) {
996 bkpinfo->backup_media_type = udev;
997 } else {
998 fatal_error("UNKNOWN bkp-media-type");
999 }
1000} else {
1001 fatal_error("backup-media-type not specified!");
1002}
1003
1004if (bkpinfo->disaster_recovery) {
1005 if (bkpinfo->backup_media_type == usb) {
1006 envtmp1 = getenv("MRUSBDEV");
1007 if (envtmp1 == NULL) {
1008 if (read_cfg_var(cfg_file, "usb-dev", value)) {
1009 fatal_error("Cannot get USB device name from cfg file");
1010 }
1011 } else {
1012 strcpy(value,envtmp1);
1013 }
1014 mr_asprintf(bkpinfo->media_device, "%s1", value);
1015 log_msg(2, "Backup medium is USB --- dev=%s", bkpinfo->media_device);
1016 } else if (bkpinfo->backup_media_type == tape || bkpinfo->backup_media_type == udev) {
1017 if (read_cfg_var(cfg_file, "media-dev", value)) {
1018 fatal_error("Cannot get tape device name from cfg file");
1019 }
1020 mr_asprintf(bkpinfo->media_device, "%s", value);
1021 read_cfg_var(cfg_file, "media-size", value);
1022 bkpinfo->media_size = atol(value);
1023 log_msg(2, "Backup medium is TAPE --- dev=%s", bkpinfo->media_device);
1024 } else {
1025 mr_asprintf(bkpinfo->media_device, "%s", "/dev/cdrom"); /* we don't really need this var */
1026 bkpinfo->media_size = 1999 * 1024; /* 650, probably, but we don't need this var anyway */
1027 log_msg(2, "Backup medium is similar to CD-R[W]");
1028 }
1029} else {
1030 log_msg(2, "Not in Disaster Recovery Mode. No need to derive device name from config file.");
1031}
1032
1033read_cfg_var(cfg_file, "use-star", value);
1034if (strstr(value, "yes")) {
1035 bkpinfo->use_star = TRUE;
1036 log_msg(1, "Goody! ... bkpinfo->use_star is now true.");
1037}
1038
1039read_cfg_var(cfg_file, "obdr", value);
1040if (strstr(value, "TRUE")) {
1041 bkpinfo->use_obdr = TRUE;
1042 log_msg(1, "OBDR mode activated");
1043}
1044
1045read_cfg_var(cfg_file, "acl", value);
1046if (strstr(value, "TRUE")) {
1047 if ((tmp = find_home_of_exe("setfacl")) == NULL) {
1048 log_msg(1, "Unable to restore ACLs as no setfacl found");
1049 } else {
1050 mr_asprintf(g_getfacl,"%s", tmp);
1051 log_msg(1, "We will restore ACLs");
1052 }
1053 mr_free(tmp);
1054}
1055read_cfg_var(cfg_file, "xattr", value);
1056if (strstr(value, "TRUE")) {
1057 if ((tmp = find_home_of_exe("setfattr")) == NULL) {
1058 log_msg(1, "Unable to restore XATTRs as no setfattr found");
1059 } else {
1060 mr_asprintf(g_getfattr,"%s", tmp);
1061 log_msg(1, "We will restore XATTRs");
1062 }
1063 mr_free(tmp);
1064}
1065
1066if (0 == read_cfg_var(cfg_file, "internal-tape-block-size", value)) {
1067 bkpinfo->internal_tape_block_size = atol(value);
1068} else {
1069 bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
1070}
1071log_msg(1, "Internal tape block size set to %ld", bkpinfo->internal_tape_block_size);
1072
1073read_cfg_var(cfg_file, "use-lzma", value);
1074if (strstr(value, "yes")) {
1075 bkpinfo->use_lzma = TRUE;
1076 bkpinfo->use_lzo = FALSE;
1077 bkpinfo->use_gzip = FALSE;
1078 mr_asprintf(bkpinfo->zip_exe, "%s", "lzma");
1079 mr_asprintf(bkpinfo->zip_suffix, "%s", "lzma");
1080}
1081
1082read_cfg_var(cfg_file, "use-lzo", value);
1083if (strstr(value, "yes")) {
1084 bkpinfo->use_lzma = FALSE;
1085 bkpinfo->use_lzo = TRUE;
1086 bkpinfo->use_gzip = FALSE;
1087 mr_asprintf(bkpinfo->zip_exe, "%s", "lzop");
1088 mr_asprintf(bkpinfo->zip_suffix, "%s", "lzo");
1089}
1090
1091read_cfg_var(cfg_file, "use-gzip", value);
1092if (strstr(value, "yes")) {
1093 bkpinfo->use_lzma = FALSE;
1094 bkpinfo->use_lzo = FALSE;
1095 bkpinfo->use_gzip = TRUE;
1096 mr_asprintf(bkpinfo->zip_exe, "%s", "gzip");
1097 mr_asprintf(bkpinfo->zip_suffix, "%s", "gz");
1098}
1099
1100read_cfg_var(cfg_file, "use-comp", value);
1101if (strstr(value, "yes")) {
1102 bkpinfo->use_lzma = FALSE;
1103 bkpinfo->use_lzo = FALSE;
1104 bkpinfo->use_gzip = FALSE;
1105 mr_asprintf(bkpinfo->zip_exe, "%s", "xz");
1106 mr_asprintf(bkpinfo->zip_suffix, "%s", "xz");
1107}
1108
1109value[0] = '\0';
1110read_cfg_var(cfg_file, "differential", value);
1111if (!strcmp(value, "yes") || !strcmp(value, "1")) {
1112 bkpinfo->differential = TRUE;
1113}
1114log_msg(2, "differential var = '%s'", value);
1115if (bkpinfo->differential) {
1116 log_msg(2, "THIS IS A DIFFERENTIAL BACKUP");
1117} else {
1118 log_msg(2, "This is a regular (full) backup");
1119}
1120
1121read_cfg_var(cfg_file, "please-dont-eject", value);
1122tmp1 = call_program_and_get_last_line_of_output("cat "CMDLINE);
1123if (value[0] || strstr(tmp1, "donteject")) {
1124 bkpinfo->please_dont_eject = TRUE;
1125 log_msg(2, "Ok, I shan't eject when restoring! Groovy.");
1126}
1127mr_free(tmp1);
1128
1129/* TODO: Read here the boot_* variables */
1130read_cfg_var(cfg_file, "boot-type", value);
1131if (!strcmp(value, "BIOS")) {
1132 bkpinfo->boot_type = BIOS;
1133} else if (!strcmp(value, "UEFI")) {
1134 bkpinfo->boot_type = UEFI;
1135} else {
1136 log_msg(1, "No known boot type found");
1137}
1138log_msg(1, "Found %s boot type",value);
1139
1140if (bkpinfo->backup_media_type == netfs) {
1141 if (!cfgf) {
1142 if (bkpinfo->netfs_mount) {
1143 log_msg(2, "netfs_mount remains %s", bkpinfo->netfs_mount);
1144 }
1145 if (bkpinfo->netfs_remote_dir != NULL) {
1146 log_msg(2, "netfs_remote_dir remains %s", bkpinfo->netfs_remote_dir);
1147 }
1148 log_msg(2, "...cos it wouldn't make sense to abandon the values that GOT ME to this config file in the first place");
1149 } else {
1150 read_cfg_var(cfg_file, "netfs-server-mount", value);
1151 mr_free(bkpinfo->netfs_mount);
1152 mr_asprintf(bkpinfo->netfs_mount, "%s", value);
1153 if (bkpinfo->netfs_mount != NULL) {
1154 log_msg(2, "netfs_mount is %s", bkpinfo->netfs_mount);
1155 }
1156
1157 read_cfg_var(cfg_file, "iso-dir", value);
1158 mr_free(bkpinfo->netfs_remote_dir);
1159 mr_asprintf(bkpinfo->netfs_remote_dir, "%s", value);
1160 if (bkpinfo->netfs_remote_dir != NULL) {
1161 log_msg(2, "netfs_remote_dir is %s", bkpinfo->netfs_remote_dir);
1162 }
1163
1164 if (bkpinfo->netfs_proto != NULL) {
1165 log_msg(2, "netfs_proto is %s", bkpinfo->netfs_proto);
1166 }
1167 if (bkpinfo->netfs_user != NULL) {
1168 log_msg(2, "netfs_user is %s", bkpinfo->netfs_user);
1169 }
1170 }
1171 tmp1 = call_program_and_get_last_line_of_output("cat "CMDLINE);
1172 if (strstr(tmp1, "pxe")) {
1173 /* We need to override values in PXE mode as it's
1174 * already done in start-netfs */
1175 envtmp1 = getenv("netfsmount");
1176 if (envtmp1 == NULL) {
1177 fatal_error("no netfsmount variable in environment");
1178 }
1179 envtmp2 = getenv("dirimg");
1180 if (envtmp2 == NULL) {
1181 fatal_error("no dirimg variable in environment");
1182 }
1183 mr_free(bkpinfo->netfs_mount);
1184 mr_asprintf(bkpinfo->netfs_mount, "%s", envtmp1);
1185
1186 mr_free(bkpinfo->netfs_remote_dir);
1187 mr_asprintf(bkpinfo->netfs_remote_dir, "%s", envtmp2);
1188 }
1189 mr_free(tmp1);
1190} else if (bkpinfo->backup_media_type == iso) {
1191 /* Patch by Conor Daly 23-june-2004
1192 * to correctly mount iso-dev and set a sensible
1193 * isodir in disaster recovery mode
1194 */
1195 mr_asprintf(old_isodir, "%s", bkpinfo->isodir);
1196 if (read_cfg_var(cfg_file, "iso-mnt", iso_mnt) != 0) {
1197 iso_mnt[0] = '\0';
1198 }
1199 if (read_cfg_var(cfg_file, "iso-dir", iso_path) != 0) {
1200 iso_path[0] = '\0';
1201 }
1202 mr_asprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
1203 if (!strcmp(bkpinfo->isodir,"")) {
1204 mr_asprintf(bkpinfo->isodir, "%s", old_isodir);
1205 }
1206
1207 if ((!bkpinfo->disaster_recovery) || (g_isodir_device[0] != '\0')) {
1208 if (strcmp(old_isodir, bkpinfo->isodir)) {
1209 log_it("user nominated isodir %s differs from archive, keeping user's choice: %s\n", bkpinfo->isodir, old_isodir );
1210 mr_asprintf(bkpinfo->isodir, "%s", old_isodir);
1211 }
1212 }
1213 mr_free(old_isodir);
1214
1215 if (g_isodir_device[0] == '\0') {
1216 /* We don't want to loose our conf made earlier in iso_fiddly_bits
1217 * so go here only if job not done already */
1218 read_cfg_var(cfg_file, "iso-dev", g_isodir_device);
1219 }
1220
1221 log_msg(2, "isodir=%s; iso-dev=%s", bkpinfo->isodir, g_isodir_device);
1222
1223 if (bkpinfo->disaster_recovery) {
1224 if (is_this_device_mounted(g_isodir_device)) {
1225 log_msg(2, "NB: isodir is already mounted");
1226 /* Find out where it's mounted */
1227 mr_asprintf(command, "mount | grep -E '^%s' | tail -n1 | cut -d' ' -f3", g_isodir_device);
1228 log_it("command = %s", command);
1229 tmp1 = call_program_and_get_last_line_of_output(command);
1230 log_it("res of it = %s", tmp1);
1231 sprintf(iso_mnt, "%s", tmp1);
1232 mr_free(command);
1233 mr_free(tmp1);
1234 } else {
1235 sprintf(iso_mnt, "/tmp/isodir");
1236 mr_asprintf(tmp1, "mkdir -p %s", iso_mnt);
1237 run_program_and_log_output(tmp1, 5);
1238 mr_free(tmp1);
1239
1240 mr_asprintf(tmp1, "mount %s %s", g_isodir_device, iso_mnt);
1241 if (run_program_and_log_output(tmp1, 3)) {
1242 log_msg(1, "Unable to mount isodir. Perhaps this is really an optical based backup?");
1243 bkpinfo->backup_media_type = optical;
1244 mr_asprintf(bkpinfo->media_device, "%s", "/dev/cdrom"); /* superfluous */
1245 mr_free(bkpinfo->isodir);
1246 iso_mnt[0] = iso_path[0] = '\0';
1247 if (mount_media(MNT_CDROM)) {
1248 mr_free(tmp1);
1249 fatal_error("Unable to mount isodir. Failed to mount CD-ROM as well.");
1250 } else {
1251 log_msg(1, "You backed up to disk, then burned some CDs.");
1252 }
1253 }
1254 mr_free(tmp1);
1255 }
1256 /* bkpinfo->isodir should now be the true path to prefix-1.iso etc... */
1257 /* except when already done in iso_fiddly_bits */
1258 if ((bkpinfo->backup_media_type == iso) && (g_isodir_device[0] == '\0')) {
1259 mr_asprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path);
1260 }
1261 }
1262}
1263mr_free(cfg_file);
1264
1265if (media_specified_by_user != none) {
1266 if (g_restoring_live_from_cd) {
1267 if (bkpinfo->backup_media_type != media_specified_by_user) {
1268 log_msg(2, "bkpinfo->backup_media_type != media_specified_by_user, so I'd better ask :)");
1269 interactively_obtain_media_parameters_from_user(FALSE);
1270 media_specified_by_user = bkpinfo->backup_media_type;
1271 get_cfg_file_from_archive();
1272 }
1273 }
1274 bkpinfo->backup_media_type = media_specified_by_user;
1275}
1276g_backup_media_type = bkpinfo->backup_media_type;
1277return (0);
1278
1279}
1280
1281/**************************************************************************
1282*END_READ_CFG_FILE_INTO_BKPINFO *
1283**************************************************************************/
1284
1285
1286
1287
1288/**
1289 * Allow the user to edit the filelist and biggielist.
1290 * The filelist is unlinked after it is read.
1291 * @param bkpinfo The backup information structure. Fields used:
1292 * - @c bkpinfo->backup_media_type
1293 * - @c bkpinfo->isodir
1294 * - @c bkpinfo->media_device
1295 * - @c bkpinfo->tmpdir
1296 * @return The filelist structure containing the information read from disk.
1297 */
1298struct
1299s_node *process_filelist_and_biggielist()
1300{
1301struct s_node *filelist;
1302
1303char *command = NULL;
1304char *old_pwd = NULL;
1305char *q;
1306int res = 0;
1307pid_t pid;
1308bool extract_mountlist_stub = FALSE;
1309
1310assert(bkpinfo != NULL);
1311
1312/* If those files already exist, do not overwrite them later on */
1313if (does_file_exist("/"MOUNTLIST_FNAME_STUB)) {
1314 extract_mountlist_stub = FALSE;
1315} else {
1316 extract_mountlist_stub = TRUE;
1317}
1318
1319if (does_file_exist(g_filelist_full)
1320&& does_file_exist(g_biggielist_txt)) {
1321 log_msg(1, "%s exists", g_filelist_full);
1322 log_msg(1, "%s exists", g_biggielist_txt);
1323 log_msg(2,
1324 "Filelist and biggielist already recovered from media. Yay!");
1325} else {
1326 old_pwd = mr_getcwd();
1327 if (chdir(bkpinfo->tmpdir)) {
1328 // FIXME
1329 }
1330 log_msg(1, "chdir(%s)", bkpinfo->tmpdir);
1331 log_to_screen("Extracting filelist and biggielist from media...");
1332 unlink("/tmp/filelist.full");
1333 unlink(FILELIST_FULL_STUB);
1334 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
1335 mr_asprintf(command, "tar -b %ld -zxf %s ./%s ./%s ./%s ./%s ./%s", bkpinfo->internal_tape_block_size, bkpinfo->media_device, MOUNTLIST_FNAME_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB, MONDO_CFG_FILE_STUB);
1336 log_msg(1, "tarcommand = %s", command);
1337 run_program_and_log_output(command, 1);
1338 mr_free(command);
1339
1340 if (!does_file_exist(FILELIST_FULL_STUB)) {
1341 /* Doing that allow us to remain compatible with pre-2.2.5 versions */
1342 log_msg(2, "pre-2.2.4 compatible mode on");
1343 mr_asprintf(command, "tar -b %ld -zxf %s %s %s %s %s %s", bkpinfo->internal_tape_block_size, bkpinfo->media_device, MOUNTLIST_FNAME_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB, MONDO_CFG_FILE_STUB);
1344 log_msg(1, "tarcommand = %s", command);
1345 run_program_and_log_output(command, 1);
1346 mr_free(command);
1347 }
1348 } else {
1349 log_msg(2, "Calling insist_on_this_cd_number; bkpinfo->isodir=%s", bkpinfo->isodir);
1350 insist_on_this_cd_number(1);
1351 log_msg(2, "Back from iotcn");
1352 run_program_and_log_output("mount", 1);
1353 mr_asprintf(command, "tar -zxf %s/images/all.tar.gz ./%s ./%s ./%s ./%s ./%s", MNT_CDROM, MOUNTLIST_FNAME_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB, MONDO_CFG_FILE_STUB);
1354
1355 log_msg(1, "tarcommand = %s", command);
1356 run_program_and_log_output(command, 1);
1357 mr_free(command);
1358
1359 if (!does_file_exist(FILELIST_FULL_STUB)) {
1360 /* Doing that allow us to remain compatible with pre-2.2.5 versions */
1361 log_msg(2, "pre-2.2.4 compatible mode on");
1362 mr_asprintf(command, "tar -zxf %s/images/all.tar.gz %s %s %s %s %s", MNT_CDROM, MOUNTLIST_FNAME_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB, MONDO_CFG_FILE_STUB);
1363
1364 log_msg(1, "tarcommand = %s", command);
1365 run_program_and_log_output(command, 1);
1366 mr_free(command);
1367 }
1368 if (!does_file_exist(BIGGIELIST_TXT_STUB)) {
1369 fatal_error("all.tar.gz did not include " BIGGIELIST_TXT_STUB);
1370 }
1371 if (!does_file_exist(FILELIST_FULL_STUB)) {
1372 fatal_error("all.tar.gz did not include " FILELIST_FULL_STUB);
1373 }
1374 }
1375 mr_asprintf(command, "cp -f %s %s", MONDO_CFG_FILE_STUB, g_mondo_cfg_file);
1376 run_program_and_log_output(command, FALSE);
1377 mr_free(command);
1378
1379 mr_asprintf(command, "cp -f %s/%s %s", bkpinfo->tmpdir, BIGGIELIST_TXT_STUB, g_biggielist_txt);
1380 log_msg(1, "command = %s", command);
1381 paranoid_system(command);
1382 mr_free(command);
1383
1384 mr_asprintf(command, "ln -sf %s/%s %s", bkpinfo->tmpdir, FILELIST_FULL_STUB, g_filelist_full);
1385 log_msg(1, "command = %s", command);
1386 paranoid_system(command);
1387 mr_free(command);
1388 }
1389
1390 if (am_I_in_disaster_recovery_mode()
1391 &&
1392 /* If it was there, do not overwrite it */
1393 (extract_mountlist_stub)
1394 &&
1395 ask_me_yes_or_no("Do you want to retrieve the mountlist as well?"))
1396 {
1397 mr_asprintf(command, "ln -sf %s/%s /tmp", MOUNTLIST_FNAME_STUB, bkpinfo->tmpdir);
1398 paranoid_system(command);
1399 mr_free(command);
1400 }
1401
1402 if (chdir(old_pwd)) {
1403 // FIXME
1404 }
1405 mr_free(old_pwd);
1406
1407 if (!does_file_exist(g_biggielist_txt)) {
1408 log_msg(1, "Warning - %s not found", g_biggielist_txt);
1409 }
1410 if (!does_file_exist(g_filelist_full)) {
1411 log_msg(1, "Warning - %s does not exist", g_filelist_full);
1412 }
1413
1414 log_msg(2, "Forking");
1415 pid = fork();
1416 switch (pid) {
1417 case -1:
1418 fatal_error("Forking error");
1419 break;
1420
1421 case 0:
1422 log_to_screen("Pre-processing filelist");
1423 if (!does_file_exist(g_biggielist_txt)) {
1424 mr_asprintf(command, "echo -n > %s", g_biggielist_txt);
1425 paranoid_system(command);
1426 mr_free(command);
1427 }
1428 mr_asprintf(command, "grep -E '^/dev/.*' %s > %s", g_biggielist_txt, g_filelist_imagedevs);
1429 paranoid_system(command);
1430 mr_free(command);
1431 exit(0);
1432 break;
1433
1434 default:
1435 open_evalcall_form("Pre-processing filelist");
1436 while (!waitpid(pid, (int *) 0, WNOHANG)) {
1437 usleep(100000);
1438 update_evalcall_form(0);
1439 }
1440 break;
1441 }
1442 close_evalcall_form();
1443
1444 log_msg(3, "loading filelist");
1445 filelist = load_filelist(g_filelist_full);
1446 log_msg(3, "deleting original filelist");
1447 unlink(g_filelist_full);
1448 if (g_text_mode) {
1449 q = NULL;
1450 while (q == NULL) {
1451 printf("Restore which directory? --> ");
1452 mr_getline(q, stdin);
1453 }
1454 toggle_path_selection(filelist, q, TRUE);
1455 if (strlen(q) == 0) {
1456 res = 1;
1457 } else {
1458 res = 0;
1459 }
1460 mr_free(q);
1461 } else {
1462 res = edit_filelist(filelist);
1463 }
1464 if (res) {
1465 log_msg(2, "User hit 'cancel'. Freeing filelist and aborting.");
1466 free_filelist(filelist);
1467 return (NULL);
1468 }
1469 ask_about_these_imagedevs(g_filelist_imagedevs, g_imagedevs_restthese);
1470 close_evalcall_form();
1471
1472 // NB: It's not necessary to add g_biggielist_txt to the filelist.full
1473 // file. The filelist.full file already contains the filename of EVERY
1474 // file backed up - regular and biggie files.
1475
1476 // However, we do want to make sure the imagedevs selected by the user
1477 // are flagged for restoring.
1478 if (length_of_file(g_imagedevs_restthese) > 2) {
1479 add_list_of_files_to_filelist(filelist, g_imagedevs_restthese,
1480 TRUE);
1481 }
1482
1483 return (filelist);
1484}
1485
1486/**************************************************************************
1487 *END_ PROCESS_FILELIST_AND_BIGGIELIST *
1488 **************************************************************************/
1489
1490
1491
1492
1493/**
1494 * Make a backup copy of <tt>path_root</tt>/<tt>filename</tt>.
1495 * The backup filename is the filename of the original with ".pristine" added.
1496 * @param path_root The place where the filesystem is mounted (e.g. MNT_RESTORING).
1497 * @param filename The filename (absolute path) within @p path_root.
1498 * @return 0 for success, nonzero for failure.
1499 */
1500int backup_crucial_file(char *path_root, char *filename)
1501{
1502 char *tmp = NULL;
1503 char *command = NULL;
1504 int res;
1505
1506 assert(path_root != NULL);
1507 assert_string_is_neither_NULL_nor_zerolength(filename);
1508
1509 mr_asprintf(tmp, "%s/%s", path_root, filename);
1510 mr_asprintf(command, "cp -f %s %s.pristine", tmp, tmp);
1511 mr_free(tmp);
1512
1513 res = run_program_and_log_output(command, 5);
1514 mr_free(command);
1515 return (res);
1516}
1517
1518void offer_to_make_initrd() {
1519
1520if (bkpinfo->restore_mode != nuke) {
1521 if (ask_me_yes_or_no
1522 ("You will now be able to re-generate your initrd.\nThis is especially useful if you changed of hardware configuration, cloned, made P2V, used multipath...\nDo you need to do it ?")) {
1523 log_msg(1,"Launching shell for manual initrd recreation");
1524 if (does_file_exist(MNT_RESTORING"/etc/arch-release")) {
1525 popup_and_OK("You'll now be chrooted under your future / partition.\nEdit /etc/mkinitcpio.conf if needed and rebuild your initrd with the kernel preset name e.g.\nmkinitcpio -p kernel26\nThen type exit to finish.\n");
1526 } else {
1527 popup_and_OK("You'll now be chrooted under your future / partition.\nGo under /boot and rebuild your init(rd|ramfs) with\nmkinitrd -f -v initrd-2.x.y.img 2.x.y e.g.\nor initramfs, dracut, ... Then type exit to finish.");
1528 }
1529 mvaddstr_and_log_it(g_currentY, 0, "Modifying initrd...");
1530 if (!g_text_mode) {
1531 newtSuspend();
1532 }
1533 paranoid_system("chroot " MNT_RESTORING);
1534 if (!g_text_mode) {
1535 newtResume();
1536 }
1537 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1538 } else {
1539 return;
1540 }
1541} else {
1542 log_to_screen("Non-interactive mode: no way to give you the keyboard so that you re-generate your initrd. Hope it's OK");
1543 log_msg(1,"Non-interactive mode: no way to give you the keyboard so that you re-generate your initrd. Hope it's OK");
1544}
1545}
1546
1547
1548/**
1549 * Attempt to find the user's editor.
1550 * @return The editor found ("vi" if none could be found).
1551 * @note The returned string points to an allocated storage that needs to be freed by caller
1552 */
1553char *find_my_editor(void) {
1554
1555 char *output = NULL ;
1556
1557 if ((output = find_home_of_exe("pico")) == NULL) {
1558 if ((output = find_home_of_exe("nano")) == NULL) {
1559 if ((output = find_home_of_exe("e3em")) == NULL) {
1560 if ((output = find_home_of_exe("e3vi")) == NULL) {
1561 if ((output = find_home_of_exe("vim")) == NULL) {
1562 output = find_home_of_exe("vi");
1563 }
1564 }
1565 }
1566 }
1567 }
1568 if (output == NULL) {
1569 log_msg(2, " (find_my_editor) --- warning - no editor found, even vi");
1570 }
1571 return (output);
1572}
1573
1574
1575
1576
1577/**
1578 * Install LILO on the user's boot drive (determined by /etc/lilo.conf).
1579 * @param offer_to_run_stablilo If TRUE, then offer to hack the user's fstab for them.
1580 * @return 0 for success, nonzero for failure.
1581 */
1582int run_lilo(bool offer_to_run_stablilo)
1583{
1584 /** malloc **/
1585 char *command = NULL;
1586 char *tmp = NULL;
1587 char *editor = NULL;
1588
1589 int res;
1590 int done;
1591 bool run_lilo_M = FALSE;
1592
1593 if (!run_program_and_log_output
1594 ("grep \"boot.*=.*/dev/md\" " MNT_RESTORING "/etc/lilo.conf", 1)) {
1595 run_lilo_M = TRUE;
1596 }
1597
1598 if (offer_to_run_stablilo
1599 && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?"))
1600
1601 /* interactive mode */
1602 {
1603 mvaddstr_and_log_it(g_currentY,
1604 0,
1605 "Modifying fstab and lilo.conf, and running LILO... ");
1606 mr_asprintf(command, "mr-stablilo-me");
1607 res = run_program_and_log_output(command, 3);
1608 mr_free(command);
1609
1610 if (res) {
1611 popup_and_OK
1612 ("You will now edit fstab and lilo.conf, to make sure they match your new mountlist.");
1613 for (done = FALSE; !done;) {
1614 editor = find_my_editor();
1615 if (editor == NULL) {
1616 popup_and_OK("No editor found. You won't be able to edit conf files");
1617 } else {
1618 if (!g_text_mode) {
1619 newtSuspend();
1620 }
1621 mr_asprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
1622 paranoid_system(tmp);
1623 mr_free(tmp);
1624
1625 mr_asprintf(tmp, "%s " MNT_RESTORING "/etc/lilo.conf", editor);
1626 paranoid_system(tmp);
1627 mr_free(tmp);
1628 mr_free(editor);
1629
1630 if (!g_text_mode) {
1631 newtResume();
1632 }
1633// newtCls();
1634 if (ask_me_yes_or_no("Edit them again?")) {
1635 continue;
1636 }
1637 }
1638 mr_free(editor);
1639
1640 res = run_program_and_log_output("chroot " MNT_RESTORING " lilo -L", 3);
1641 if (res) {
1642 res = run_program_and_log_output("chroot " MNT_RESTORING " lilo", 3);
1643 }
1644 if (res) {
1645 done = ask_me_yes_or_no("LILO failed. Re-edit system files?");
1646 } else {
1647 done = TRUE;
1648 }
1649 }
1650 } else {
1651 log_to_screen("lilo.conf and fstab were modified OK");
1652 }
1653 } else
1654 /* nuke mode */
1655 {
1656 mvaddstr_and_log_it(g_currentY,
1657 0,
1658 "Running LILO... ");
1659 res =
1660 run_program_and_log_output("chroot " MNT_RESTORING " lilo -L",
1661 3);
1662 if (res) {
1663 res =
1664 run_program_and_log_output("chroot " MNT_RESTORING " lilo",
1665 3);
1666 }
1667 if (res) {
1668 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
1669 log_to_screen
1670 ("Failed to re-jig fstab and/or lilo. Edit/run manually, please.");
1671 } else {
1672 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1673 }
1674 }
1675 if (run_lilo_M) {
1676 run_program_and_log_output("chroot " MNT_RESTORING
1677 " lilo -M /dev/hda", 3);
1678 run_program_and_log_output("chroot " MNT_RESTORING
1679 " lilo -M /dev/sda", 3);
1680 }
1681 return (res);
1682}
1683
1684/**************************************************************************
1685 *END_RUN_LILO *
1686 **************************************************************************/
1687
1688
1689/**
1690 * Install a raw MBR onto @p bd.
1691 * @param offer_to_hack_scripts If TRUE, then offer to hack the user's fstab for them.
1692 * @param bd The device to copy the stored MBR to.
1693 * @return 0 for success, nonzero for failure.
1694 */
1695int run_raw_mbr(bool offer_to_hack_scripts, char *bd)
1696{
1697 /** malloc **/
1698 char *command = NULL;
1699 char *boot_device = NULL;
1700 char *tmp = NULL;
1701 char *editor;
1702 int res;
1703 int done;
1704
1705 malloc_string(boot_device);
1706 assert_string_is_neither_NULL_nor_zerolength(bd);
1707
1708 strcpy(boot_device, bd);
1709
1710 if (offer_to_hack_scripts
1711 && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?")) {
1712 /* interactive mode */
1713 mvaddstr_and_log_it(g_currentY, 0, "Modifying fstab and restoring MBR... ");
1714 for (done = FALSE; !done;) {
1715 popup_and_OK("You will now edit fstab");
1716 editor = find_my_editor();
1717 if (editor == NULL) {
1718 popup_and_OK("No editor found. You won't be able to edit conf files");
1719 } else {
1720 if (!g_text_mode) {
1721 newtSuspend();
1722 }
1723 mr_asprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor);
1724
1725 paranoid_system(tmp);
1726 mr_free(tmp);
1727 if (!g_text_mode) {
1728 newtResume();
1729 }
1730 }
1731 mr_free(editor);
1732
1733 popup_and_get_string("Boot device", "Please confirm/enter the boot device. If in doubt, try /dev/hda", boot_device, MAX_STR_LEN / 4);
1734 mr_asprintf(command, "mr-stabraw-me %s", boot_device);
1735 res = run_program_and_log_output(command, 3);
1736 mr_free(command);
1737
1738 if (res) {
1739 done = ask_me_yes_or_no("Modifications failed. Re-try?");
1740 } else {
1741 done = TRUE;
1742 }
1743 }
1744 } else {
1745 /* nuke mode */
1746 mr_asprintf(command, "mr-raw %s /"MOUNTLIST_FNAME_STUB, boot_device);
1747 log_msg(2, "run_raw_mbr() --- command='%s'", command);
1748
1749 mvaddstr_and_log_it(g_currentY, 0, "Restoring MBR... ");
1750 res = run_program_and_log_output(command, 3);
1751 mr_free(command);
1752 }
1753 if (res) {
1754 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
1755 log_to_screen("MBR+fstab processed w/error(s). See %s for more info.", MONDO_LOGFILE);
1756 } else {
1757 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1758 }
1759 paranoid_free(boot_device);
1760 return (res);
1761}
1762
1763/**************************************************************************
1764 *END_RUN_RAW_MBR *
1765 **************************************************************************/
1766
1767
1768/**
1769 * Install GRUB on @p bd.
1770 * @param offer_to_run_stabgrub If TRUE, then offer to hack the user's fstab for them.
1771 * @param bd The boot device where GRUB is installed.
1772 * @return 0 for success, nonzero for failure.
1773 */
1774int run_grub(bool offer_to_run_stabgrub, char *bd)
1775{
1776 /** malloc **/
1777 char *command = NULL;
1778 char *boot_device = NULL;
1779 char *tmp = NULL;
1780 char *editor = NULL;
1781
1782 bool done;
1783 int res = 0; /* FALSE */
1784 bool mntlistchg = FALSE;
1785 FILE *fin = NULL;
1786
1787 malloc_string(boot_device);
1788
1789 assert_string_is_neither_NULL_nor_zerolength(bd);
1790 strcpy(boot_device, bd);
1791
1792 if (offer_to_run_stabgrub && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?")) {
1793 /* interactive mode */
1794 mvaddstr_and_log_it(g_currentY, 0, "Modifying fstab, mtab, device.map and menu.lst/grub.cfg, and running GRUB...");
1795 /* Did we changed the mountlist ? If yes, then force editing conf files */
1796 if ((fin = fopen(MONDO_MNTLISTCHG, "r")) != NULL) {
1797 mntlistchg = TRUE;
1798 }
1799 for (done = FALSE; !done;) {
1800 popup_and_get_string("Boot device", "Please confirm/enter the boot device. If in doubt, try /dev/sda", boot_device, MAX_STR_LEN / 4);
1801 /* Only try to adapt grub here first if the mountlist wasn't changed before */
1802 if (! mntlistchg) {
1803 mr_asprintf(command, "mr-stabgrub-me %s", boot_device);
1804 res = run_program_and_log_output(command, 1);
1805 mr_free(command);
1806 }
1807
1808 if ((res) || (mntlistchg)) {
1809 if (res) {
1810 popup_and_OK("GRUB installation failed. You will now edit fstab, mtab, device.map and menu.lst/grub.cfg in order to fix grub install");
1811 } else {
1812 popup_and_OK("The mountlist was changed. You will now edit fstab, mtab, device.map and menu.lst/grub.cfg in order to fix grub install");
1813 }
1814 editor = find_my_editor();
1815 if (editor == NULL) {
1816 popup_and_OK("No editor found. You won't be able to edit conf files");
1817 } else {
1818 if (!g_text_mode) {
1819 newtSuspend();
1820 }
1821 mr_asprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor);
1822 paranoid_system(tmp);
1823 mr_free(tmp);
1824
1825 mr_asprintf(tmp, "chroot %s %s /etc/mtab", MNT_RESTORING, editor);
1826 paranoid_system(tmp);
1827 mr_free(tmp);
1828
1829 if (does_file_exist(MNT_RESTORING"/boot/grub/menu.lst")) {
1830 mr_asprintf(tmp, "chroot %s %s /boot/grub/menu.lst", MNT_RESTORING, editor);
1831 } else if (does_file_exist(MNT_RESTORING"/boot/grub/grub.cfg")) {
1832 mr_asprintf(tmp, "chroot %s %s /boot/grub/grub.cfg", MNT_RESTORING, editor);
1833 } else if (does_file_exist(MNT_RESTORING"/boot/grub2/grub.cfg")) {
1834 mr_asprintf(tmp, "chroot %s %s /boot/grub2/grub.cfg", MNT_RESTORING, editor);
1835 }
1836 paranoid_system(tmp);
1837 mr_free(tmp);
1838
1839 if (does_file_exist(MNT_RESTORING"/boot/grub/device.map")) {
1840 mr_asprintf(tmp, "chroot %s %s /boot/grub/device.map", MNT_RESTORING, editor);
1841 } else if (does_file_exist(MNT_RESTORING"/boot/grub2/device.map")) {
1842 mr_asprintf(tmp, "chroot %s %s /boot/grub2/device.map", MNT_RESTORING, editor);
1843 }
1844 paranoid_system(tmp);
1845 mr_free(tmp);
1846 if (!g_text_mode) {
1847 newtResume();
1848 }
1849 }
1850 mr_free(editor);
1851
1852 mr_asprintf(command, "mr-stabgrub-me %s", boot_device);
1853 res = run_program_and_log_output(command, 1);
1854 mr_free(command);
1855
1856 if (res) {
1857 popup_and_OK("GRUB installation failed. Please fix the conf files so that a manual install using 'grub-install' or similar command works. You are now chroot()'ed to your restored system. Please type 'exit' when you are done.");
1858 newtSuspend();
1859 paranoid_system("chroot " MNT_RESTORING);
1860 newtResume();
1861 } else {
1862 popup_and_OK("GRUB is now installed correctly");
1863 done = TRUE;
1864 }
1865 } else {
1866 done = TRUE;
1867 }
1868 }
1869 } else {
1870 /* nuke mode */
1871 if (!run_program_and_log_output("which mr-grub", FALSE)) {
1872 log_msg(1, "Yay! mr-grub found...");
1873 mr_asprintf(command, "mr-grub %s /"MOUNTLIST_FNAME_STUB, boot_device);
1874 log_msg(1, "command = %s", command);
1875 } else {
1876 // Or grub2-install
1877 mr_asprintf(command, "chroot " MNT_RESTORING " grub-install %s", boot_device);
1878 log_msg(1, "WARNING - mr-grub not found; using grub-install");
1879 }
1880 mvaddstr_and_log_it(g_currentY, 0, "Running GRUB... ");
1881 log_it("%s",command);
1882 res = run_program_and_log_output(command, 1);
1883 mr_free(command);
1884
1885 if (res) {
1886 popup_and_OK("Because of bugs in GRUB's own installer, GRUB was not installed properly. Please install the boot loader manually now, using this chroot()'ed shell prompt. Type 'exit' when you have finished.");
1887 newtSuspend();
1888 paranoid_system("chroot " MNT_RESTORING);
1889 newtResume();
1890 }
1891 }
1892 if (res) {
1893 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
1894 log_to_screen
1895 ("GRUB ran w/error(s). See %s for more info.", MONDO_LOGFILE);
1896 log_msg(1, "Type:-");
1897 log_msg(1, " mr-mount-me");
1898 log_msg(1, " chroot " MNT_RESTORING);
1899 log_msg(1, " mount /boot if needed");
1900 log_msg(1, " grub-install '(hd0)'");
1901 log_msg(1, " exit");
1902 log_msg(1, " mr-unmount-me");
1903 log_msg(1,
1904 "If you're really stuck, please e-mail the mailing list.");
1905 } else {
1906 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
1907 }
1908 paranoid_free(boot_device);
1909
1910 return (res);
1911}
1912
1913/**************************************************************************
1914 *END_RUN_GRUB *
1915 **************************************************************************/
1916
1917
1918/**
1919 * Install the user's boot loader in the MBR.
1920 * Currently LILO, GRUB, RAW (dd of MBR), and the FreeBSD bootloader are supported.
1921 * @param offer_to_hack_scripts If TRUE, then offer to hack the user's fstab for them.
1922 * @return 0 for success, nonzero for failure.
1923 */
1924int run_boot_loader(bool offer_to_hack_scripts)
1925{
1926 int res;
1927 int retval = 0;
1928
1929 /** malloc *******/
1930 char *device = NULL;
1931 char *disk = NULL;
1932 char *name = NULL;
1933 char *type = NULL;
1934 char *cmd = NULL;
1935
1936 malloc_string(device);
1937 malloc_string(name);
1938 malloc_string(type);
1939
1940 /* In order to have a working bootloader, we need to have all devices
1941 * ready in the chroot. If they are not there (udev) then copy them from
1942 * the current /dev location
1943 */
1944 mr_asprintf(cmd,"tar cf - /dev | ( cd %s ; tar xf - )",MNT_RESTORING);
1945 run_program_and_log_output(cmd, 3);
1946 mr_free(cmd);
1947
1948 backup_crucial_file(MNT_RESTORING, "/etc/fstab");
1949 backup_crucial_file(MNT_RESTORING, "/boot/grub/menu.lst");
1950 backup_crucial_file(MNT_RESTORING, "/boot/grub/grub.cfg");
1951 backup_crucial_file(MNT_RESTORING, "/boot/grub2/grub.cfg");
1952 backup_crucial_file(MNT_RESTORING, "/etc/lilo.conf");
1953 backup_crucial_file(MNT_RESTORING, "/boot/grub/device.map");
1954 backup_crucial_file(MNT_RESTORING, "/boot/grub2/device.map");
1955 backup_crucial_file(MNT_RESTORING, "/etc/mtab");
1956 read_cfg_var(g_mondo_cfg_file, "bootloader.device", device);
1957 read_cfg_var(g_mondo_cfg_file, "bootloader.name", name);
1958 read_cfg_var(g_mondo_cfg_file, "boot-type", type);
1959 log_msg(2, "run_boot_loader: device='%s', name='%s', type='%s'", device, name, type);
1960 sync();
1961
1962 offer_to_make_initrd();
1963
1964 disk = truncate_to_drive_name(device);
1965 if (strcmp(type,"BIOS") == 0) {
1966 // Force installation of a MBR bootloader brought by mindi on the disk
1967 // in case none was available and we then start from a partition
1968 log_msg(2, "Reinstalling mbr.bin on %s", disk);
1969 mr_system("dd bs=440 count=1 conv=notrunc if=/tmp/mbr.bin of=%s &> /dev/null",disk);
1970 } else {
1971 // Same for GPT
1972 log_msg(2, "Reinstalling gptmbr.bin on %s", disk);
1973 mr_system("dd bs=440 count=1 conv=notrunc if=/tmp/gptmbr.bin of=%s &> /dev/null",disk);
1974 }
1975
1976 // Now reinstall bootloader
1977 if (!strcmp(name, "LILO")) {
1978 res = run_lilo(offer_to_hack_scripts);
1979 } else if (!strcmp(name, "GRUB")) {
1980 res = run_grub(offer_to_hack_scripts, device);
1981 } else if (!strcmp(name, "RAW")) {
1982 res = run_raw_mbr(offer_to_hack_scripts, device);
1983 }
1984#ifdef __FreeBSD__
1985 else if (!strcmp(name, "BOOT0")) {
1986 mr_asprintf(tmp, "boot0cfg -B %s", device);
1987 res = run_program_and_log_output(tmp, FALSE);
1988 paranoid_free(tmp);
1989 } else {
1990 mr_asprintf(tmp, "ls /dev | grep -Eq '^%ss[1-4].*'", device);
1991 if (!system(tmp)) {
1992 mr_free(tmp);
1993 mr_asprintf(tmp, MNT_RESTORING "/sbin/fdisk -B %s", device);
1994 res = run_program_and_log_output(tmp, 3);
1995 } else {
1996 log_msg(1, "I'm not running any boot loader. You have a DD boot drive. It's already loaded up.");
1997 }
1998 mr_free(tmp);
1999 }
2000#else
2001 else {
2002 log_to_screen
2003 ("Unable to determine type of boot loader. Defaulting to LILO.");
2004 res = run_lilo(offer_to_hack_scripts);
2005 }
2006#endif
2007 retval += res;
2008 if (res) {
2009 log_to_screen("Your boot loader returned an error");
2010 } else {
2011 log_to_screen("Your boot loader ran OK");
2012 }
2013 paranoid_free(device);
2014 paranoid_free(name);
2015 return (retval);
2016}
2017
2018/**************************************************************************
2019 *END_ RUN_BOOT_LOADER *
2020 **************************************************************************/
2021
2022
2023
2024/**
2025 * malloc() and set sensible defaults for the mondorestore filename variables.
2026 * @param bkpinfo The backup information structure. Fields used:
2027 * - @c bkpinfo->tmpdir
2028 * - @c bkpinfo->disaster_recovery
2029 */
2030void setup_MR_global_filenames()
2031{
2032 assert(bkpinfo != NULL);
2033
2034 malloc_string(g_biggielist_txt);
2035 malloc_string(g_filelist_full);
2036 malloc_string(g_filelist_imagedevs);
2037 malloc_string(g_imagedevs_restthese);
2038 malloc_string(g_mondo_cfg_file);
2039 malloc_string(g_mountlist_fname);
2040 malloc_string(g_mondo_home);
2041 malloc_string(g_isodir_device);
2042 malloc_string(g_isodir_format);
2043
2044 sprintf(g_biggielist_txt, "%s/%s", bkpinfo->tmpdir, BIGGIELIST_TXT_STUB);
2045 sprintf(g_filelist_full, "%s/%s", bkpinfo->tmpdir, FILELIST_FULL_STUB);
2046 sprintf(g_filelist_imagedevs, "%s/tmp/filelist.imagedevs", bkpinfo->tmpdir);
2047// sprintf(g_imagedevs_pot, "%s/tmp/imagedevs.pot", bkpinfo->tmpdir);
2048 sprintf(g_imagedevs_restthese, "%s/tmp/imagedevs.restore-these",
2049 bkpinfo->tmpdir);
2050 if (bkpinfo->disaster_recovery) {
2051 sprintf(g_mondo_cfg_file, "/%s", MONDO_CFG_FILE_STUB);
2052 sprintf(g_mountlist_fname, "/%s", MOUNTLIST_FNAME_STUB);
2053 } else {
2054 sprintf(g_mondo_cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB);
2055 sprintf(g_mountlist_fname, "%s/%s", bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);
2056 }
2057}
2058
2059/**************************************************************************
2060 *END_SET_GLOBAL_FILENAME *
2061 **************************************************************************/
2062
2063
2064/**
2065 * Copy @p input_file (containing the result of a compare) to @p output_file,
2066 * deleting spurious "changes" along the way.
2067 * @param output_file The output file to write with spurious changes removed.
2068 * @param input_file The input file, a list of changed files created by a compare.
2069 */
2070void streamline_changes_file(char *output_file, char *input_file)
2071{
2072 FILE *fin;
2073 FILE *fout;
2074 char *incoming = NULL;
2075
2076 assert_string_is_neither_NULL_nor_zerolength(output_file);
2077 assert_string_is_neither_NULL_nor_zerolength(input_file);
2078
2079 if (!(fin = fopen(input_file, "r"))) {
2080 log_OS_error(input_file);
2081 return;
2082 }
2083 if (!(fout = fopen(output_file, "w"))) {
2084 fatal_error("cannot open output_file");
2085 }
2086 for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) {
2087 if (strncmp(incoming, "etc/adjtime", 11)
2088 && strncmp(incoming, "etc/mtab", 8)
2089 && strncmp(incoming, "tmp/", 4)
2090 && strncmp(incoming, "boot/map", 8)
2091 && !strstr(incoming, "incheckentry")
2092 && strncmp(incoming, "etc/mail/statistics", 19)
2093 && strncmp(incoming, "var/", 4))
2094 fprintf(fout, "%s", incoming); /* don't need \n here, for some reason.. */
2095 mr_free(incoming);
2096 }
2097 mr_free(incoming);
2098 paranoid_fclose(fout);
2099 paranoid_fclose(fin);
2100}
2101
2102/**************************************************************************
2103 *END_STREAMLINE_CHANGES_FILE *
2104 **************************************************************************/
2105
2106
2107/**
2108 * Give the user twenty seconds to press Ctrl-Alt-Del before we nuke their drives.
2109 */
2110void twenty_seconds_til_yikes()
2111{
2112 int i;
2113 /* MALLOC * */
2114 char *tmp = NULL;
2115
2116 if (does_file_exist("/tmp/NOPAUSE")) {
2117 return;
2118 }
2119 open_progress_form("CAUTION",
2120 "Be advised: I am about to ERASE your hard disk(s)!",
2121 "You may press Ctrl+Alt+Del to abort safely.",
2122 "", 20);
2123 for (i = 0; i < 20; i++) {
2124 g_current_progress = i;
2125 mr_asprintf(tmp, "You have %d seconds left to abort.", 20 - i);
2126 update_progress_form(tmp);
2127 mr_free(tmp);
2128 sleep(1);
2129 }
2130 close_progress_form();
2131}
2132
2133/**************************************************************************
2134 *END_TWENTY_SECONDS_TIL_YIKES *
2135 **************************************************************************/
2136
2137
2138/**
2139 * Unmount all devices in @p p_external_copy_of_mountlist.
2140 * @param p_external_copy_of_mountlist The mountlist to guide the devices to unmount.
2141 * @return 0 for success, nonzero for failure.
2142 */
2143int unmount_all_devices(struct mountlist_itself
2144 *p_external_copy_of_mountlist)
2145{
2146 struct mountlist_itself *mountlist;
2147 int retval = 0, lino, res = 0, i;
2148 char *command = NULL;
2149 char *tmp = NULL;
2150
2151 assert(p_external_copy_of_mountlist != NULL);
2152
2153 mountlist = malloc(sizeof(struct mountlist_itself));
2154 memcpy((void *) mountlist, (void *) p_external_copy_of_mountlist, sizeof(struct mountlist_itself));
2155 sort_mountlist_by_mountpoint(mountlist, 0);
2156
2157 run_program_and_log_output("df -m -P -T", 3);
2158 mvaddstr_and_log_it(g_currentY, 0, "Unmounting devices ");
2159 open_progress_form("Unmounting devices", "Unmounting all devices that were mounted,", "in preparation for the post-restoration reboot.", "", mountlist->entries);
2160 if (chdir("/")) {
2161 // FIXME
2162 }
2163 for (i = 0; i < 10 && run_program_and_log_output("ps | grep buffer | grep -v \"grep buffer\"", TRUE) == 0; i++) {
2164 sleep(1);
2165 log_msg(2, "Waiting for buffer() to finish");
2166 }
2167
2168 sync();
2169
2170 /* after that what is logged is not copied on disk, typically the result of labelling */
2171 mr_asprintf(tmp, "cp -f %s " MNT_RESTORING "/var/log", MONDO_LOGFILE);
2172 if (run_program_and_log_output(tmp, FALSE)) {
2173 log_msg(1, "Error. Failed to copy log to the machine's /var/log dir. (Mounted read-only?)");
2174 }
2175 paranoid_free(tmp);
2176 if (does_file_exist("/tmp/DUMBASS-GENTOO")) {
2177 run_program_and_log_output("mkdir -p " MNT_RESTORING "/mnt/.boot.d", 5);
2178 }
2179
2180 /* Unmounting the local /proc and /sys first */
2181 run_program_and_log_output("umount -d " MNT_RESTORING "/proc",3);
2182 run_program_and_log_output("umount -d " MNT_RESTORING "/sys",3);
2183
2184 /* Unmounting potential btrfs subvolumes */
2185 if (does_file_exist("/tmp/umount-btrfs-subvol")) {
2186 run_program_and_log_output("/tmp/umount-btrfs-subvol",3);
2187 }
2188
2189 for (lino = mountlist->entries - 1; lino >= 0; lino--) {
2190 if (!strcmp(mountlist->el[lino].mountpoint, "lvm")) {
2191 continue;
2192 }
2193 mr_asprintf(tmp, "Unmounting device %s ", mountlist->el[lino].device);
2194 update_progress_form(tmp);
2195
2196 //TODO: this should be done in a certain order normally if there are cascading mount
2197 if (is_this_device_mounted(mountlist->el[lino].device)) {
2198 if (!strcmp(mountlist->el[lino].mountpoint, "swap")) {
2199 mr_asprintf(command, "swapoff %s", mountlist->el[lino].device);
2200 } else {
2201 if (!strcmp(mountlist->el[lino].mountpoint, "/1")) {
2202 mr_asprintf(command, "umount -d %s/", MNT_RESTORING);
2203 log_msg(3,
2204 "Well, I know a certain kitty-kitty who'll be sleeping with Mommy tonight...");
2205 } else {
2206 mr_asprintf(command, "umount -d " MNT_RESTORING "%s", mountlist->el[lino].mountpoint);
2207
2208 /* To support latest Ubuntu where /var is a separate FS
2209 * Cf: http://linux.derkeiler.com/Mailing-Lists/Ubuntu/2007-04/msg01319.html
2210 * we need to create some dirs under the real / before unmounting it */
2211 if (!strcmp(mountlist->el[lino].mountpoint, "/")) {
2212 run_program_and_log_output("mkdir -p " MNT_RESTORING "/var/lock", FALSE);
2213 run_program_and_log_output("mkdir -p " MNT_RESTORING "/var/run", FALSE);
2214 }
2215 }
2216 }
2217 log_msg(10, "The 'umount' command is '%s'", command);
2218 res = run_program_and_log_output(command, 3);
2219 mr_free(command);
2220 } else {
2221 mr_strcat(tmp, "...not mounted anyway :-) OK");
2222 res = 0;
2223 }
2224 g_current_progress++;
2225 if (res) {
2226 mr_strcat(tmp, "...Failed");
2227 retval++;
2228 log_to_screen(tmp);
2229 } else {
2230 log_msg(2, tmp);
2231 }
2232 paranoid_free(tmp);
2233 }
2234 close_progress_form();
2235 if (retval) {
2236 mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
2237 } else {
2238 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2239 }
2240 if (retval) {
2241 log_to_screen("Unable to unmount some of your partitions.");
2242 } else {
2243 log_to_screen("All partitions were unmounted OK.");
2244 }
2245 mr_asprintf(command, "mount");
2246 log_msg(4, "mount result after unmounting all FS", command);
2247 (void)run_program_and_log_output(command, 3);
2248 mr_free(command);
2249 free(mountlist);
2250 return (retval);
2251}
2252
2253/**************************************************************************
2254 *END_UNMOUNT_ALL_DEVICES *
2255 **************************************************************************/
2256/* @} - end restoreUtilityGroup */
2257
2258void wait_until_software_raids_are_prepped(int wait_for_percentage)
2259{
2260 struct raidlist_itself *raidlist;
2261 int unfinished_mdstat_devices = 9999;
2262 int i = 0;
2263 char *screen_message = NULL;
2264
2265 raidlist = malloc(sizeof(struct raidlist_itself));
2266
2267 assert(wait_for_percentage <= 100);
2268 log_it("wait_until_software_raids_are_prepped");
2269 while (unfinished_mdstat_devices > 0) {
2270 // FIXME: Prefix '/dev/' should really be dynamic!
2271 if (parse_mdstat(MDSTAT_FILE, raidlist, "/dev/")) {
2272 log_to_screen("Sorry, cannot read %s", MDSTAT_FILE);
2273 log_msg(1,"Sorry, cannot read %s", MDSTAT_FILE);
2274 return;
2275 }
2276 for (unfinished_mdstat_devices = 0; i <= raidlist->entries; i++) {
2277 if (raidlist->el[i].progress < wait_for_percentage) {
2278 unfinished_mdstat_devices++;
2279 if (raidlist->el[i].progress == -1) // delayed while another partition inits
2280 {
2281 continue;
2282 }
2283 log_msg(1,"Sync'ing %s (i=%d)", raidlist->el[i].raid_device, i);
2284 mr_asprintf(screen_message, "Sync'ing %s", raidlist->el[i].raid_device);
2285 open_evalcall_form(screen_message);
2286 mr_free(screen_message);
2287
2288 while (raidlist->el[i].progress < wait_for_percentage) {
2289 log_msg(1,"Percentage sync'ed: %d", raidlist->el[i].progress);
2290 update_evalcall_form(raidlist->el[i].progress);
2291 sleep(2);
2292 // FIXME: Prefix '/dev/' should really be dynamic!
2293 if (parse_mdstat(MDSTAT_FILE, raidlist, "/dev/")) {
2294 break;
2295 }
2296 }
2297 close_evalcall_form();
2298 }
2299 }
2300 }
2301 paranoid_free(raidlist);
2302}
Note: See TracBrowser for help on using the repository browser.