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

Last change on this file since 3743 was 3743, checked in by Bruno Cornec, 4 years ago

Really place the btrfs subvol handler at the right place i.e. shared

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