source: MondoRescue/branches/2.2.10/mondo/src/common/libmondo-devices.c@ 2623

Last change on this file since 2623 was 2623, checked in by Bruno Cornec, 14 years ago

r3783@localhost: bruno | 2010-04-11 11:57:27 +0200

  • Use MINDI_CACHE for temp file communication between archive/restore
  • Remove some now useless globals in mondo
  • Remove function get_cfg_file_from_archive_or_bust and get_cfg_file_from_archive
  • Adds function get_cfg_file_from_initrd (Not finished)
  • Recovery doesn't work in that version atm (checkpoint version)
  • Property svn:keywords set to Id
File size: 91.2 KB
Line 
1/* libmondo-devices.c Subroutines for handling devices
2 $Id: libmondo-devices.c 2623 2010-04-12 13:23:24Z bruno $
3*/
4
5/**
6 * @file
7 * Functions to handle interactions with backup devices.
8 */
9
10#include "my-stuff.h"
11#include "mr_mem.h"
12#include "mr_str.h"
13#include "mondostructures.h"
14#include "libmondo-files-EXT.h"
15#include "libmondo-devices.h"
16#include "lib-common-externs.h"
17#include "libmondo-string-EXT.h"
18#include "libmondo-tools-EXT.h"
19#include "libmondo-gui-EXT.h"
20#include "libmondo-fork-EXT.h"
21#include "libmondo-stream-EXT.h"
22
23extern void mr_strip_spaces(char *);
24
25#include <sys/types.h>
26#ifdef __FreeBSD__
27#define DKTYPENAMES
28#define FSTYPENAMES
29#include <sys/disklabel.h>
30#include <sys/disk.h>
31#elif linux
32#define u64 unsigned long long
33#include <linux/fs.h> /* for BLKGETSIZE64 */
34#include <linux/hdreg.h>
35#endif
36
37/*@unused@*/
38//static char cvsid[] = "$Id: libmondo-devices.c 2623 2010-04-12 13:23:24Z bruno $";
39
40extern int g_current_media_number;
41extern double g_kernel_version;
42
43extern bool g_ISO_restore_mode;
44extern char *g_selfmounted_isodir;
45extern char *MONDO_LOGFILE;
46
47static char g_cdrw_drive_is_here[MAX_STR_LEN / 4] = "";
48static char g_cdrom_drive_is_here[MAX_STR_LEN / 4] = "";
49static char g_dvd_drive_is_here[MAX_STR_LEN / 4] = "";
50
51
52/**
53 * ????? @bug ?????
54 * @ingroup globalGroup
55 */
56extern t_bkptype g_backup_media_type; // set by main()
57
58/* Reference to global bkpinfo */
59extern struct s_bkpinfo *bkpinfo;
60
61/* Stuff that handles the -I and -E option when a whole disk DSF is used */
62typedef struct mounted_fs_struct {
63 char device[MAX_STR_LEN]; /* The name of the device */
64 char mount_point[MAX_STR_LEN]; /* The devices mount point */
65 unsigned char check; /* 1 == included on DSF */
66 struct mounted_fs_struct *next;
67} MOUNTED_FS_STRUCT;
68
69static MOUNTED_FS_STRUCT *DSF_Head = NULL; /* Points to the first entry of mounted_fs_struct list */
70static MOUNTED_FS_STRUCT *DSF_Tail = NULL; /* Points to the last entry of mounted_fs_struct list */
71
72
73void set_g_cdrom_and_g_dvd_to_bkpinfo_value() {
74
75 if (bkpinfo->media_device) {
76 strcpy(g_cdrom_drive_is_here, bkpinfo->media_device); // just in case
77 strcpy(g_dvd_drive_is_here, bkpinfo->media_device); // just in case
78 }
79}
80
81
82
83/**
84 * Retract all CD trays and wait for autorun to complete.
85 * @ingroup deviceGroup
86 */
87void retract_CD_tray_and_defeat_autorun(void)
88{
89// log_it("rctada: Retracting all CD trays", __LINE__);
90 if (strlen(g_cdrom_drive_is_here) > 0) {
91 inject_device(g_cdrom_drive_is_here);
92 }
93 if (strlen(g_dvd_drive_is_here) > 0) {
94 inject_device(g_dvd_drive_is_here);
95 }
96 if (strlen(g_cdrw_drive_is_here) > 0) {
97 inject_device(g_cdrw_drive_is_here);
98 }
99// log_it("rctada: killing autorun");
100// run_program_and_log_output("killall autorun", TRUE);
101 if (!run_program_and_log_output("ps | grep autorun | grep -v grep", 5)) {
102 log_it("autorun detected; sleeping for 2 seconds");
103 sleep(2);
104 }
105 log_it("rctada: Unmounting all CD drives", __LINE__);
106 run_program_and_log_output("umount /dev/cdr* /dev/dvd*", 5);
107}
108
109
110
111/**
112 * Determine whether we're booted off a ramdisk.
113 * @return @c TRUE (we are) or @c FALSE (we aren't).
114 * @ingroup utilityGroup
115 */
116bool am_I_in_disaster_recovery_mode(void)
117{
118 char *tmp = NULL;
119 bool is_this_a_ramdisk = FALSE;
120
121 tmp = where_is_root_mounted();
122 log_msg(0, "root is currently mounted at %s\n", tmp);
123
124#ifdef __FreeBSD__
125 if (strstr(tmp, "/dev/md")) {
126 is_this_a_ramdisk = TRUE;
127 }
128#else
129 if (!strncmp(tmp, "/dev/ram", 8)
130 || (!strncmp(tmp, "/dev/rd", 7) && !strcmp(tmp, "/dev/rd/")
131 && strncmp(tmp, "/dev/rd/cd", 10)) || strstr(tmp, "rootfs")
132 || !strcmp(tmp, "/dev/root")) {
133 is_this_a_ramdisk = TRUE;
134 } else {
135 is_this_a_ramdisk = FALSE;
136 }
137#endif
138 mr_free(tmp);
139
140 log_msg(1, "Is this a ramdisk? result = %s", (is_this_a_ramdisk) ? "TRUE" : "FALSE");
141 return (is_this_a_ramdisk);
142}
143
144
145
146
147
148/**
149 * Turn @c bkpinfo->backup_media_type into a human-readable string.
150 * @return The human readable string (e.g. @c cdr becomes <tt>"cdr"</tt>).
151 * @note The returned string points to static storage that will be overwritten with each call.
152 * @ingroup stringGroup
153 */
154static char *bkptype_to_string(t_bkptype bt)
155{
156 char *output;
157 switch (bt) {
158 case none:
159 mr_asprintf(output, "none");
160 break;
161 case iso:
162 mr_asprintf(output, "iso");
163 break;
164 case cdr:
165 mr_asprintf(output, "cdr");
166 break;
167 case cdrw:
168 mr_asprintf(output, "cdrw");
169 break;
170 case cdstream:
171 mr_asprintf(output, "cdstream");
172 break;
173 case netfs:
174 mr_asprintf(output, "netfs");
175 break;
176 case tape:
177 mr_asprintf(output, "tape");
178 break;
179 case udev:
180 mr_asprintf(output, "udev");
181 break;
182 case usb:
183 mr_asprintf(output, "usb");
184 break;
185 default:
186 mr_asprintf(output, "default");
187 }
188 return (output);
189}
190
191
192
193/**
194 * @addtogroup deviceGroup
195 * @{
196 */
197/**
198 * Eject the tray of the specified CD device.
199 * @param dev The device to eject.
200 * @return the return value of the @c eject command. (0=success, nonzero=failure)
201 */
202int eject_device(char *dev)
203{
204 char *command = NULL;
205 int res1 = 0, res2 = 0;
206
207 if (dev == NULL) {
208 return (1);
209 }
210
211 if (IS_THIS_A_STREAMING_BACKUP(g_backup_media_type)
212 && g_backup_media_type != udev) {
213 mr_asprintf(command, "mt -f %s offline", dev);
214 res1 = run_program_and_log_output(command, 1);
215 mr_free(command);
216 } else {
217 res1 = 0;
218 }
219
220#ifdef __FreeBSD__
221 if (strstr(dev, "acd")) {
222 mr_asprintf(command, "cdcontrol -f %s eject", dev);
223 } else {
224 mr_asprintf(command, "camcontrol eject `echo %s | sed 's|/dev/||'`", dev);
225 }
226#else
227 mr_asprintf(command, "eject %s", dev);
228#endif
229
230 log_msg(3, "Ejecting %s", dev);
231 res2 = run_program_and_log_output(command, 1);
232 mr_free(command);
233 if (res1 && res2) {
234 return (1);
235 } else {
236 return (0);
237 }
238}
239
240/**
241 * Load (inject) the tray of the specified CD device.
242 * @param dev The device to load/inject.
243 * @return 0 for success, nonzero for failure.
244 */
245int inject_device(char *dev)
246{
247 char *command = NULL;
248 int i;
249
250 if (dev == NULL) {
251 return (1);
252 }
253
254#ifdef __FreeBSD__
255 if (strstr(dev, "acd")) {
256 mr_asprintf(command, "cdcontrol -f %s close", dev);
257 } else {
258 mr_asprintf(command, "camcontrol load `echo %s | sed 's|/dev/||'`", dev);
259 }
260#else
261 mr_asprintf(command, "eject -t %s", dev);
262#endif
263 i = run_program_and_log_output(command, FALSE);
264 mr_free(command);
265 return (i);
266}
267
268
269/**
270 * Determine whether the specified @p device (really, you can use any file)
271 * exists.
272 * @return TRUE if it exists, FALSE if it doesn't.
273 */
274bool does_device_exist(char *device)
275{
276
277 /*@ buffers *********************************************************** */
278 char *tmp = NULL;
279 bool ret;
280
281 assert_string_is_neither_NULL_nor_zerolength(device);
282
283 mr_asprintf(tmp, "ls %s > /dev/null 2> /dev/null", device);
284
285 if (system(tmp)) {
286 ret = FALSE;
287 } else {
288 ret = TRUE;
289 }
290 mr_free(tmp);
291 return (ret);
292}
293
294
295/**
296 * Determine whether a non-Microsoft partition exists on any connected hard drive.
297 * @return TRUE (there's a Linux/FreeBSD partition) or FALSE (Microsoft has taken over yet another innocent PC).
298 */
299bool does_nonMS_partition_exist(void)
300{
301#if __FreeBSD__
302 return
303 !system
304 ("for drive in /dev/ad? /dev/da?; do fdisk $drive | grep -q FreeBSD && exit 0; done; false");
305#else
306 return
307 !system
308 ("parted2fdisk -l 2>/dev/null | grep '^/dev/' | grep -Eqv '(MS|DOS|FAT|NTFS)'");
309#endif
310}
311
312/**
313 * Determine whether the specified @p partno exists on the specified @p drive.
314 * @param drive The drive to search for the partition in.
315 * @param partno The partition number to look for.
316 * @return 0 if it exists, nonzero otherwise.
317 */
318int does_partition_exist(const char *drive, int partno)
319{
320 /*@ buffers **************************************************** */
321 char *program = NULL;
322 char *incoming = NULL;
323 char *searchstr = NULL;
324 char *tmp = NULL;
325
326 /*@ ints ******************************************************* */
327 int res = 0;
328
329 /*@ pointers *************************************************** */
330 FILE *fin;
331
332
333 /*@ end vars *************************************************** */
334 assert_string_is_neither_NULL_nor_zerolength(drive);
335 assert(partno >= 0 && partno < 999);
336
337#ifdef __FreeBSD__
338 // We assume here that this is running from mondorestore. (It is.)
339 tmp = build_partition_name(drive, partno);
340 mr_asprintf(program, "ls %s %s >/dev/null 2>&1", drive, tmp);
341 mr_free(tmp);
342
343 res = system(program);
344 mr_free(program);
345 return (res);
346#else
347 /* To avoid compiler warnings */
348 tmp = NULL;
349#endif
350
351 mr_asprintf(program, "parted2fdisk -l %s 2> /dev/null", drive);
352 fin = popen(program, "r");
353 if (!fin) {
354 log_it("program=%s", program);
355 log_OS_error("Cannot popen-in program");
356 mr_free(program);
357 return (0);
358 }
359 mr_free(program);
360
361 searchstr = build_partition_name(drive, partno);
362 mr_strcat(searchstr, " ");
363 for (res = 0, mr_getline(incoming, fin); !res && !feof(fin) ; mr_getline(incoming, fin)) {
364 if (strstr(incoming, searchstr)) {
365 res = 1;
366 }
367 mr_free(incoming);
368 }
369 mr_free(incoming);
370 mr_free(searchstr);
371
372 if (pclose(fin)) {
373 log_OS_error("Cannot pclose fin");
374 }
375 return (res);
376}
377
378
379
380
381
382/**
383 * Determine whether given NULL-terminated @p str exists in the MBR of @p dev.
384 * @param dev The device to look in.
385 * @param str The string to look for.
386 * @return TRUE if it exists, FALSE if it doesn't.
387 */
388bool does_string_exist_in_boot_block(char *dev, char *str)
389{
390 /*@ buffers **************************************************** */
391 char *command = NULL;
392
393 /*@ end vars *************************************************** */
394 int i;
395
396 assert_string_is_neither_NULL_nor_zerolength(dev);
397 assert_string_is_neither_NULL_nor_zerolength(str);
398
399 mr_asprintf(command, "dd if=%s bs=446 count=1 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null", dev, str);
400 i = system(command);
401 mr_free(command);
402 if (i) {
403 return (FALSE);
404 } else {
405 return (TRUE);
406 }
407}
408
409/**
410 * Determine whether specified @p str exists in the first @p n sectors of
411 * @p dev.
412 * @param dev The device to look in.
413 * @param str The string to look for.
414 * @param n The number of 512-byte sectors to search.
415 */
416bool does_string_exist_in_first_N_blocks(char *dev, char *str, int n)
417{
418 /*@ buffers **************************************************** */
419 char *command = NULL;
420 /*@ end vars *************************************************** */
421 int i;
422
423 mr_asprintf(command, "dd if=%s bs=512 count=%i 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null", dev, n, str);
424 i = system(command);
425 mr_free(command);
426 if (i) {
427 return (FALSE);
428 } else {
429 return (TRUE);
430 }
431}
432
433
434
435/**
436 * Try to mount CD-ROM at @p mountpoint. If the CD-ROM is not found or has
437 * not been specified, call find_cdrom_device() to find it.
438 * @param mountpoint Where to mount the CD-ROM.
439 * @return 0 for success, nonzero for failure.
440 * @see mount_CDROM_here
441 */
442int find_and_mount_actual_cd(char *mountpoint) {
443
444 /*@ buffers ***************************************************** */
445
446 /*@ int's ****************************************************** */
447 int res;
448 char *dev = NULL;
449 char *p = NULL;
450
451 /*@ end vars **************************************************** */
452
453 assert(bkpinfo != NULL);
454 assert_string_is_neither_NULL_nor_zerolength(mountpoint);
455
456 if (g_backup_media_type == dvd) {
457 if (g_dvd_drive_is_here[0]) {
458 mr_asprintf(dev, "%s", g_dvd_drive_is_here);
459 }
460 if (dev == NULL) {
461 dev = find_dvd_device();
462 }
463 } else {
464 if (g_cdrom_drive_is_here[0]) {
465 mr_asprintf(dev, "%s", g_cdrom_drive_is_here);
466 }
467 if (dev == NULL) {
468 dev = find_cdrom_device(FALSE);
469 }
470 }
471
472 if (bkpinfo->backup_media_type != iso) {
473 retract_CD_tray_and_defeat_autorun();
474 }
475
476 if ((dev == NULL) || (res = mount_CDROM_here(dev, mountpoint))) {
477 p = popup_and_get_string ("CD-ROM device", "Please enter your CD-ROM's /dev device",dev);
478 if (p == NULL) {
479 res = 1;
480 } else {
481 res = mount_CDROM_here(p, mountpoint);
482 }
483 mr_free(p);
484 }
485 if (res) {
486 log_msg(1, "mount failed");
487 } else {
488 log_msg(1, "mount succeeded with %s", dev);
489 }
490 mr_free(dev);
491 return (res);
492}
493
494
495
496
497
498
499/**
500 * Locate a CD-R/W writer's SCSI node.
501 * @param cdrw_device SCSI node will be placed here.
502 * @return 0 for success, nonzero for failure.
503 */
504char *find_cdrw_device()
505{
506 /*@ buffers ************************ */
507 char *tmp = NULL;
508 char *tmp1 = NULL;
509 char *cdr_exe = NULL;
510 char *command = NULL;
511 char *cdrw_device = NULL;
512
513 if (g_cdrw_drive_is_here[0]) {
514 mr_asprintf(cdrw_device, "%s", g_cdrw_drive_is_here);
515 log_msg(3, "Been there, done that. Returning %s", cdrw_device);
516 return(cdrw_device);
517 }
518 if (g_backup_media_type == dvd) {
519 log_msg(1, "This is dumb. You're calling find_cdrw_device() but you're backing up to DVD. WTF?");
520 return(NULL);
521 }
522 run_program_and_log_output("insmod ide-scsi", -1);
523 tmp = find_home_of_exe("cdrecord");
524 if (tmp) {
525 mr_asprintf(cdr_exe, "cdrecord");
526 } else {
527 mr_asprintf(cdr_exe, "dvdrecord");
528 }
529 mr_free(tmp);
530
531 tmp1 = find_home_of_exe(cdr_exe);
532 if (tmp1) {
533 mr_asprintf(command, "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep CD | cut -d' ' -f2 | head -n1", cdr_exe);
534 tmp = call_program_and_get_last_line_of_output(command);
535 mr_free(command);
536 }
537 mr_free(tmp1);
538
539 if ((tmp == NULL) || (strlen(tmp) < 2)) {
540 mr_free(tmp);
541 mr_free(cdr_exe);
542 return(NULL);
543 } else {
544 cdrw_device = tmp;
545 log_it("Found CDRW device - %s", cdrw_device);
546 strcpy(g_cdrw_drive_is_here, cdrw_device);
547 mr_free(cdr_exe);
548 return (cdrw_device);
549 }
550}
551
552
553/**
554 * Attempt to locate a CD-ROM device's /dev entry.
555 * Several different methods may be used to find the device, including
556 * calling @c cdrecord, searching @c dmesg, and trial-and-error.
557 * @param output Where to put the located /dev entry.
558 * @param try_to_mount Whether to mount the CD as part of the test; if mount
559 * fails then return failure.
560 * @return 0 for success, nonzero for failure.
561 */
562char *find_cdrom_device(bool try_to_mount)
563{
564 /*@ pointers **************************************************** */
565 FILE *fin;
566 char *p;
567 char *q;
568 char *r;
569
570 /*@ bool's ****************************************************** */
571 bool found_it = FALSE;
572
573 /*@ buffers ***************************************************** */
574 char *tmp = NULL;
575 char *output = NULL;
576 char *cdr_exe = NULL;
577 char *phrase_two = NULL;
578 char *command = NULL;
579#ifndef __FreeBSD__
580 char *dvd_last_resort = NULL;
581#endif
582 char *mountpoint = NULL;
583 static char the_last_place_i_found_it[MAX_STR_LEN] = "";
584
585 /*@ intialize *************************************************** */
586
587 output = NULL;
588#ifndef __FreeBSD__
589 mr_asprintf(dvd_last_resort, "%s", "");;
590#endif
591
592 /*@ end vars **************************************************** */
593
594 if (g_cdrom_drive_is_here[0] && !isdigit(g_cdrom_drive_is_here[0])) {
595 mr_asprintf(output, "%s", g_cdrom_drive_is_here);
596 log_msg(3, "Been there, done that. Returning %s", output);
597 return(output);
598 }
599 if (the_last_place_i_found_it[0] != '\0' && !try_to_mount) {
600 mr_asprintf(output, "%s", the_last_place_i_found_it);
601 log_msg(3, "find_cdrom_device() --- returning last found location - '%s'", output);
602 return(output);
603 }
604
605 mr_asprintf(mountpoint, "%s/cd.mnt", bkpinfo->tmpdir);
606 make_hole_for_dir(mountpoint);
607
608 tmp = find_home_of_exe("cdrecord");
609 if (tmp) {
610 mr_asprintf(cdr_exe, "cdrecord");
611 } else {
612 mr_asprintf(cdr_exe, "dvdrecord");
613 }
614 mr_free(tmp);
615
616 tmp = find_home_of_exe(cdr_exe);
617 if (!tmp) {
618 mr_asprintf(output, "/dev/cdrom");
619 log_msg(4, "Can't find cdrecord; assuming %s", output);
620 mr_free(cdr_exe);
621 if (!does_device_exist(output)) {
622 log_msg(4, "That didn't work. Sorry.");
623 mr_free(output);
624 }
625 mr_free(tmp);
626 return(output);
627 }
628 mr_free(tmp);
629
630 mr_asprintf(command, "%s -scanbus 2> /dev/null", cdr_exe);
631 fin = popen(command, "r");
632 log_msg(4, "command=%s", command);
633 mr_free(command);
634
635 if (!fin) {
636 log_OS_error("Cannot popen command");
637 mr_free(cdr_exe);
638 return(NULL);
639 }
640
641 for (mr_getline(tmp, fin); !feof(fin); mr_getline(tmp, fin)) {
642 p = strchr(tmp, '\'');
643 if (p) {
644 q = strchr(++p, '\'');
645 if (q) {
646 for (r = q; *(r - 1) == ' '; r--);
647 *r = '\0';
648 p = strchr(++q, '\'');
649 if (p) {
650 q = strchr(++p, '\'');
651 if (q) {
652 while (*(q - 1) == ' ') {
653 q--;
654 }
655 *q = '\0';
656 mr_asprintf(phrase_two, "%s", p);
657 }
658 }
659 }
660 }
661 mr_free(tmp);
662 }
663 mr_free(tmp);
664 paranoid_pclose(fin);
665
666#ifndef __FreeBSD__
667 if (!phrase_two || strlen(phrase_two) == 0) {
668 log_msg(4, "Not running phase two. String is empty.");
669 } else {
670 mr_asprintf(command, "dmesg | grep \"%s\" 2> /dev/null", phrase_two);
671 fin = popen(command, "r");
672 mr_free(command);
673
674 if (!fin) {
675 log_msg(4, "Cannot run 2nd command - non-fatal, fortunately");
676 } else {
677 for (mr_getline(tmp, fin); !feof(fin); mr_getline(tmp, fin)) {
678 log_msg(5, "--> '%s'", tmp);
679 if (tmp[0] != ' ' && tmp[1] != ' ') {
680 p = strchr(tmp, ':');
681 if (p) {
682 *p = '\0';
683 if (strstr(tmp, "DVD")) {
684 mr_free(dvd_last_resort);
685 mr_asprintf(dvd_last_resort, "/dev/%s", tmp);
686 log_msg(4, "Ignoring '%s' because it's a DVD drive", tmp);
687 } else {
688 mr_asprintf(output, "/dev/%s", tmp);
689 found_it = TRUE;
690 }
691 }
692 }
693 mr_free(tmp);
694 }
695 paranoid_pclose(fin);
696 mr_free(tmp);
697 }
698 }
699 mr_free(phrase_two);
700
701#endif
702#ifdef __FreeBSD__
703 if (!found_it) {
704 log_msg(4, "OK, approach 2");
705 if (!(output = set_dev_to_this_if_rx_OK("/dev/cdrom"))) {
706 if (!(output = set_dev_to_this_if_rx_OK("/dev/cdrom1"))) {
707 if (!(output = set_dev_to_this_if_rx_OK("/dev/dvd"))) {
708 if (!(output = set_dev_to_this_if_rx_OK("/dev/acd0"))) {
709 if (!(output = set_dev_to_this_if_rx_OK("/dev/cd01"))) {
710 if (!(output = set_dev_to_this_if_rx_OK("/dev/acd1"))) {
711 if (!(output = set_dev_to_this_if_rx_OK("/dev/cd1"))) {
712 mr_free(cdr_exe);
713 return(NULL);
714 }
715 }
716 }
717 }
718 }
719 }
720 }
721 }
722#else
723 if (!found_it && strlen(dvd_last_resort) > 0) {
724 log_msg(4, "Well, I'll use the DVD - %s - as a last resort", dvd_last_resort);
725 mr_asprintf(output, "%s", dvd_last_resort);
726 found_it = TRUE;
727 }
728 mr_free(dvd_last_resort);
729
730 if (found_it) {
731 mr_asprintf(tmp, "grep \"%s=ide-scsi\" " CMDLINE " &> /dev/null", strrchr(output, '/') + 1);
732 if (system(tmp) == 0) {
733 log_msg(4, "%s is not right. It's being SCSI-emulated. Continuing.", output);
734 found_it = FALSE;
735 mr_free(output);
736 }
737 mr_free(tmp);
738 }
739
740 if (found_it) {
741 log_msg(4, "(find_cdrom_device) --> '%s'", output);
742 if (!does_device_exist(output)) {
743 found_it = FALSE;
744 log_msg(4, "OK, I was wrong, I haven't found it... yet.");
745 mr_free(output);
746 }
747 }
748
749 if (!found_it) {
750 log_msg(4, "OK, approach 2");
751 if (!(output = set_dev_to_this_if_rx_OK("/dev/scd0"))) {
752 if (!(output = set_dev_to_this_if_rx_OK("/dev/sr0"))) {
753 if (!(output = set_dev_to_this_if_rx_OK("/dev/cdrom"))) {
754 if (!(output = set_dev_to_this_if_rx_OK("/dev/cdrom0"))) {
755 if (!(output = set_dev_to_this_if_rx_OK("/dev/cdrom1"))) {
756 if (!(output = set_dev_to_this_if_rx_OK("/dev/sr1"))) {
757 if (!(output = set_dev_to_this_if_rx_OK("/dev/dvd"))) {
758 if (!(output = set_dev_to_this_if_rx_OK(g_cdrw_drive_is_here))) {
759 mr_free(cdr_exe);
760 return(NULL);
761 }
762 }
763 }
764 }
765 }
766 }
767 }
768 }
769 }
770#endif
771
772 if (found_it && try_to_mount) {
773 if (mount_CDROM_here(output, mountpoint)) {
774 log_msg(4, "[Cardigans] I've changed my mind");
775 found_it = FALSE;
776 mr_free(output);
777 } else {
778 mr_asprintf(tmp, "%s/archives", mountpoint);
779 if (!does_file_exist(tmp)) {
780 log_msg(4, "[Cardigans] I'll take it back");
781 found_it = FALSE;
782 mr_free(output);
783 } else {
784 mr_asprintf(command, "umount %s", output);
785 paranoid_system(command);
786 mr_free(command);
787
788 log_msg(4, "I'm confident the Mondo CD is in %s", output);
789 }
790 mr_free(tmp);
791 }
792 }
793 unlink(mountpoint);
794 mr_free(mountpoint);
795
796 if (found_it) {
797 if (!does_file_exist(output)) {
798 log_msg(3, "I still haven't found it.");
799 mr_free(cdr_exe);
800 mr_free(output);
801 return (NULL);
802 }
803 log_msg(3, "(find_cdrom_device) --> '%s'", output);
804 strcpy(the_last_place_i_found_it, output);
805 strcpy(g_cdrom_drive_is_here, output);
806 mr_free(cdr_exe);
807 return (output);
808 }
809
810 mr_asprintf(command, "%s -scanbus | grep \"[0-9],[0-9],[0-9]\" | grep \"[D|C][V|D]\" | grep -n \"\" | grep \"%s\" | cut -d':' -f2", cdr_exe, g_cdrw_drive_is_here);
811 mr_free(cdr_exe);
812
813 log_msg(1, "command=%s", command);
814 tmp = call_program_and_get_last_line_of_output(command);
815 mr_free(command);
816
817 mr_free(output);
818 if (strlen(tmp) > 0) {
819 mr_asprintf(output, "%s", tmp);
820 log_msg(4, "Finally found it at %s", output);
821 } else {
822 log_msg(4, "Still couldn't find it.");
823 }
824 mr_free(tmp);
825
826 return (output);
827}
828
829
830char *find_dvd_device()
831{
832 char *tmp = NULL;
833 int devno = -1;
834 char *output = NULL;
835
836 if (g_dvd_drive_is_here[0]) {
837 mr_asprintf(output, "%s", g_dvd_drive_is_here);
838 log_msg(3, "Been there, done that. Returning %s", output);
839 return (output);
840 }
841
842 tmp = call_program_and_get_last_line_of_output("dvdrecord -scanbus 2> /dev/null | grep \") '\" | grep -n \"\" | grep DVD | cut -d':' -f1");
843 log_msg(5, "tmp = '%s'", tmp);
844 if (!tmp[0])
845 mr_free(tmp);
846 tmp = call_program_and_get_last_line_of_output("cdrecord -scanbus 2> /dev/null | grep \") '\" | grep -n \"\" | grep DVD | cut -d':' -f1");
847 if (tmp[0]) {
848 devno = atoi(tmp) - 1;
849 }
850 mr_free(tmp);
851
852 if (devno >= 0) {
853 mr_asprintf(output, "/dev/scd%d", devno);
854 strcpy(g_dvd_drive_is_here, output);
855 log_msg(2, "I think DVD is at %s", output);
856 } else {
857 log_msg(2, "I cannot find DVD");
858 }
859
860 return (output);
861}
862
863
864
865
866
867#include <sys/ioctl.h>
868
869/**
870 * Find the size of the specified @p drive, in megabytes. Uses @c ioctl calls
871 * and @c dmesg.
872 * @param drive The device to find the size of.
873 * @return size in megabytes.
874 */
875long get_phys_size_of_drive(char *drive)
876{
877 int fd;
878#if linux
879 unsigned long long s = 0;
880 int fileid, cylinders = 0, cylindersleft = 0;
881 int cylindersize = 0;
882 int gotgeo = 0;
883
884
885 struct hd_geometry hdgeo;
886#elif __FreeBSD__
887 off_t s;
888#endif
889
890 long outvalA = -1;
891 long outvalB = -1;
892 long outvalC = -1;
893
894 if ((fd = open(drive, O_RDONLY)) != -1) {
895 if (ioctl(fd,
896#if linux
897#ifdef BLKGETSIZE64
898 BLKGETSIZE64,
899#else
900 BLKGETSIZE,
901#endif
902#elif __FreeBSD__
903 DIOCGMEDIASIZE,
904#endif
905 &s) != -1) {
906 close(fd);
907 // s>>11 works for older disks but not for newer ones
908 outvalB =
909#if linux
910#ifdef BLKGETSIZE64
911 s >> 20
912#else
913 s >> 11
914#endif
915#else
916 s >> 20
917#endif
918 ;
919 }
920 }
921
922 if (outvalB <= 0) {
923 log_msg(1, "Error getting size of %s: %s", drive, strerror(errno));
924#if linux
925 fileid = open(drive, O_RDONLY);
926 if (fileid != -1) {
927 if (ioctl(fileid, HDIO_GETGEO, &hdgeo) != -1) {
928 if (hdgeo.cylinders && hdgeo.heads && hdgeo.sectors) {
929 cylindersleft = cylinders = hdgeo.cylinders;
930 cylindersize = hdgeo.heads * hdgeo.sectors / 2;
931 outvalA = cylindersize * cylinders / 1024;
932 log_msg(2, "Got Harddisk geometry, C:%d, H:%d, S:%d",
933 hdgeo.cylinders, hdgeo.heads, hdgeo.sectors);
934 gotgeo = 1;
935 } else {
936 log_msg(1, "Harddisk geometry wrong");
937 }
938 } else {
939 log_msg(1,
940 "Error in ioctl() getting new hard disk geometry (%s), resizing in unsafe mode",
941 strerror(errno));
942 }
943 close(fileid);
944 } else {
945 log_msg(1, "Failed to open %s for reading: %s", drive,
946 strerror(errno));
947 }
948 if (!gotgeo) {
949 log_msg(1, "Failed to get harddisk geometry, using old mode");
950 }
951#endif
952 }
953// OLDER DISKS will give ridiculously low value for outvalB (so outvalA is returned) :)
954// NEWER DISKS will give sane value for outvalB (close to outvalA, in other words) :)
955
956 outvalC = (outvalA > outvalB) ? outvalA : outvalB;
957
958// log_msg (5, "drive = %s, error = %s", drive, strerror (errno));
959// fatal_error ("GPSOD: Unable to get size of drive");
960 log_msg(1, "%s --> %ld or %ld --> %ld", drive, outvalA, outvalB,
961 outvalC);
962
963 return (outvalC);
964}
965
966/**
967 * Determine whether @p format is supported by the kernel. Uses /proc/filesystems
968 * under Linux and @c lsvfs under FreeBSD.
969 * @param format The format to test.
970 * @return TRUE if the format is supported, FALSE if not.
971 */
972bool is_this_a_valid_disk_format(char *format)
973{
974 char *good_formats = NULL;
975 char *command = NULL;
976 char *format_sz = NULL;
977
978 FILE *pin;
979 int retval;
980
981 assert_string_is_neither_NULL_nor_zerolength(format);
982
983 mr_asprintf(format_sz, "%s ", format);
984
985#ifdef __FreeBSD__
986 mr_asprintf(command, "lsvfs | tr -s '\t' ' ' | grep -v Filesys | grep -v -- -- | cut -d' ' -f1 | tr -s '\n' ' '");
987#else
988 mr_asprintf(command, "grep -v nodev /proc/filesystems | tr -s '\t' ' ' | cut -d' ' -f2 | tr -s '\n' ' '");
989#endif
990
991 pin = popen(command, "r");
992 mr_free(command);
993
994 if (!pin) {
995 log_OS_error("Unable to read good formats");
996 retval = 0;
997 } else {
998 mr_getline(good_formats, pin);
999 if (pclose(pin)) {
1000 log_OS_error("Cannot pclose good formats");
1001 }
1002 mr_strip_spaces(good_formats);
1003 mr_strcat(good_formats, " swap lvm raid ntfs-3g ntfs 7 "); // " ntfs 7 " -- um, cheating much? :)
1004 if (strstr(good_formats, format_sz)) {
1005 retval = 1;
1006 } else {
1007 retval = 0;
1008 }
1009 mr_free(good_formats);
1010 }
1011 mr_free(format_sz);
1012
1013 return (retval);
1014}
1015
1016
1017/** @def SWAPLIST_COMMAND The command to list the swap files/partitions in use. */
1018
1019/**
1020 * Determine whether @p device_raw is currently mounted.
1021 * @param device_raw The device to check.
1022 * @return TRUE if it's mounted, FALSE if not.
1023 */
1024bool is_this_device_mounted(char *device_raw)
1025{
1026
1027 /*@ pointers **************************************************** */
1028 FILE *fin;
1029
1030 /*@ buffers ***************************************************** */
1031 char *incoming = NULL;
1032 char *device_with_tab = NULL;
1033 char *device_with_space = NULL;
1034 char *tmp = NULL;
1035 bool retval = FALSE;
1036
1037#ifdef __FreeBSD__
1038#define SWAPLIST_COMMAND "swapinfo"
1039#else
1040#define SWAPLIST_COMMAND "cat /proc/swaps"
1041#endif
1042
1043 /*@ end vars **************************************************** */
1044
1045 if (device_raw == NULL) {
1046 return(FALSE);
1047 }
1048
1049 if (device_raw[0] != '/' && !strstr(device_raw, ":/")) {
1050 log_msg(1, "%s needs to have a '/' prefixed - I'll do it",
1051 device_raw);
1052 mr_asprintf(tmp, "/%s", device_raw);
1053 } else {
1054 mr_asprintf(tmp, "%s", device_raw);
1055 }
1056 log_msg(1, "Is %s mounted?", tmp);
1057 if (!strcmp(tmp, "/proc") || !strcmp(tmp, "proc")) {
1058 log_msg(1,
1059 "I don't know how the heck /proc made it into the mountlist. I'll ignore it.");
1060 mr_free(tmp);
1061 return(FALSE);
1062 }
1063 mr_asprintf(device_with_tab, "%s\t", tmp);
1064 mr_asprintf(device_with_space, "%s ", tmp);
1065 mr_free(tmp);
1066
1067 if (!(fin = popen("mount", "r"))) {
1068 log_OS_error("Cannot popen 'mount'");
1069 return(FALSE);
1070 }
1071
1072 for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) {
1073 if (strstr(incoming, device_with_space) || strstr(incoming, device_with_tab)) {
1074 paranoid_pclose(fin);
1075 mr_free(incoming);
1076 return(TRUE);
1077 }
1078 mr_free(incoming);
1079 }
1080 mr_free(incoming);
1081 mr_free(device_with_tab);
1082 paranoid_pclose(fin);
1083 mr_asprintf(tmp, "%s | grep -E \"^%s\" > /dev/null 2> /dev/null", SWAPLIST_COMMAND, device_with_space);
1084 mr_free(device_with_space);
1085 log_msg(4, "tmp (command) = '%s'", tmp);
1086 if (!system(tmp)) {
1087 retval = TRUE;
1088 }
1089 mr_free(tmp);
1090 return(retval);
1091}
1092
1093#ifdef __FreeBSD__
1094// CODE IS FREEBSD-SPECIFIC
1095/**
1096 * Create a loopback device for specified @p fname.
1097 * @param fname The file to associate with a device.
1098 * @return /dev entry for the device, or NULL if it couldn't be allocated.
1099 */
1100char *make_vn(char *fname)
1101{
1102 char *device = (char *) malloc(MAX_STR_LEN);
1103 char *mddevice = (char *) malloc(32);
1104 char command[MAX_STR_LEN];
1105 char *tmp = NULL;
1106 int vndev = 2;
1107 int i = 2;
1108
1109 tmp = call_program_and_get_last_line_of_output("/sbin/sysctl -n kern.osreldate");
1110 i = atoi(tmp);
1111 mr_free(tmp);
1112
1113 if (i < 500000) {
1114 do {
1115 sprintf(mddevice, "vn%ic", vndev++);
1116 sprintf(command, "vnconfig %s %s", mddevice, fname);
1117 if (vndev > 10) {
1118 return NULL;
1119 }
1120 }
1121 while (system(command));
1122 } else {
1123 sprintf(command, "mdconfig -a -t vnode -f %s", fname);
1124 mddevice = call_program_and_get_last_line_of_output(command);
1125 if (!strstr(mddevice, "md")) {
1126 return NULL;
1127 }
1128 }
1129 sprintf(device, "/dev/%s", mddevice);
1130 return device;
1131}
1132
1133
1134
1135// CODE IS FREEBSD-SPECIFIC
1136/**
1137 * Deallocate specified @p dname.
1138 * This should be called when you are done with the device created by make_vn(),
1139 * so the system does not run out of @c vn devices.
1140 * @param dname The device to deallocate.
1141 * @return 0 for success, nonzero for failure.
1142 */
1143int kick_vn(char *dname)
1144{
1145 char *command = NULL;
1146 char *tmp = NULL;
1147 int res = 0;
1148 int i = 0;
1149
1150 if (strncmp(dname, "/dev/", 5) == 0) {
1151 dname += 5;
1152 }
1153
1154 tmp = call_program_and_get_last_line_of_output("/sbin/sysctl -n kern.osreldate"));
1155 i = atoi(tmp);
1156 mr_free(tmp);
1157
1158 if (i < 500000) {
1159 mr_asprintf(command, "vnconfig -d %s", dname);
1160 } else {
1161 mr_asprintf(command, "mdconfig -d -u %s", dname);
1162 }
1163 res = system(command);
1164 mr_free(command);
1165 return(res);
1166}
1167#endif
1168
1169
1170/**
1171 * Mount the CD-ROM at @p mountpoint.
1172 * @param device The device (or file if g_ISO_restore_mode) to mount.
1173 * @param mountpoint The place to mount it.
1174 * @return 0 for success, nonzero for failure.
1175 */
1176int mount_USB_here(char *device, char *mountpoint)
1177{
1178 /*@ buffer ****************************************************** */
1179 char *command = NULL;
1180 int retval;
1181
1182 assert_string_is_neither_NULL_nor_zerolength(device);
1183 assert_string_is_neither_NULL_nor_zerolength(mountpoint);
1184
1185 make_hole_for_dir(mountpoint);
1186 if (isdigit(device[0])) {
1187 return(1);
1188 }
1189 log_msg(4, "(mount_USB_here --- device=%s, mountpoint=%s", device, mountpoint);
1190
1191#ifdef __FreeBSD__
1192 mr_asprintf(command, "mount_vfat %s %s 2>> %s", device, mountpoint, MONDO_LOGFILE);
1193
1194#else
1195 mr_asprintf(command, "mount %s -t vfat %s 2>> %s", device, mountpoint, MONDO_LOGFILE);
1196#endif
1197
1198 log_msg(4, command);
1199 retval = system(command);
1200 log_msg(1, "system(%s) returned %d", command, retval);
1201 mr_free(command);
1202
1203 return (retval);
1204}
1205
1206/**
1207 * Mount the CD-ROM at @p mountpoint.
1208 * @param device The device (or file if g_ISO_restore_mode) to mount.
1209 * @param mountpoint The place to mount it.
1210 * @return 0 for success, nonzero for failure.
1211 */
1212int mount_CDROM_here(char *device, const char *mountpoint)
1213{
1214 /*@ buffer ****************************************************** */
1215 char *command = NULL;
1216 int retval;
1217#ifdef __FreeBSD__
1218 char *dev = NULL;
1219#else
1220 char *options = NULL;
1221#endif
1222
1223 assert_string_is_neither_NULL_nor_zerolength(mountpoint);
1224
1225 make_hole_for_dir(mountpoint);
1226
1227 if ((device == NULL) || (isdigit(device[0]))) {
1228 mr_free(device);
1229 device = find_cdrom_device(FALSE);
1230 }
1231#ifndef __FreeBSD__
1232 mr_asprintf(options, "ro");
1233#endif
1234
1235 if (g_ISO_restore_mode) {
1236
1237#ifdef __FreeBSD__
1238 mr_asprintf(dev, "%s", make_vn(device));
1239 if (!dev) {
1240 mr_asprintf(command, "Unable to mount ISO (make_vn(%s) failed)", device);
1241 fatal_error(command);
1242 }
1243 mr_free(device);
1244 device = dev;
1245#else
1246 mr_strcat(options, ",loop");
1247#endif
1248
1249 }
1250 log_msg(4, "(mount_CDROM_here --- device=%s, mountpoint=%s", device, mountpoint);
1251 /*@ end vars *************************************************** */
1252
1253#ifdef __FreeBSD__
1254 mr_asprintf(command, "mount_cd9660 -r %s %s 2>> %s", device, mountpoint, MONDO_LOGFILE);
1255
1256#else
1257 mr_asprintf(command, "mount %s -o %s -t iso9660 %s 2>> %s", device, options, mountpoint, MONDO_LOGFILE);
1258 paranoid_free(options);
1259#endif
1260
1261 log_msg(4, command);
1262 if (strncmp(device, "/dev/", 5) == 0) {
1263 retract_CD_tray_and_defeat_autorun();
1264 }
1265 retval = system(command);
1266 log_msg(1, "system(%s) returned %d", command, retval);
1267 mr_free(command);
1268
1269 return (retval);
1270}
1271
1272
1273
1274
1275
1276
1277/**
1278 * Ask the user for CD number @p cd_number_i_want.
1279 * Sets g_current_media_number once the correct CD is inserted.
1280 * @param bkpinfo The backup information structure. Fields used:
1281 * - @c bkpinfo->backup_media_type
1282 * - @c bkpinfo->prefix
1283 * - @c bkpinfo->isodir
1284 * - @c bkpinfo->media_device
1285 * - @c bkpinfo->please_dont_eject_when_restoring
1286 * @param cd_number_i_want The CD number to ask for.
1287 */
1288void
1289insist_on_this_cd_number(int cd_number_i_want)
1290{
1291
1292 /*@ int ************************************************************* */
1293 int res = 0;
1294
1295
1296 /*@ buffers ********************************************************* */
1297 char *tmp = NULL;
1298 char *mds = NULL;
1299 char *request = NULL;
1300
1301 assert(bkpinfo != NULL);
1302 assert(cd_number_i_want > 0);
1303
1304// log_msg(3, "Insisting on CD number %d", cd_number_i_want);
1305
1306 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
1307 log_msg(3,
1308 "No need to insist_on_this_cd_number when the backup type isn't CD-R(W) or NFS or ISO");
1309 return;
1310 }
1311 mr_asprintf(tmp, "mkdir -p " MNT_CDROM);
1312 run_program_and_log_output(tmp, 5);
1313 mr_free(tmp);
1314
1315 if (g_ISO_restore_mode || bkpinfo->backup_media_type == iso || bkpinfo->backup_media_type == netfs) {
1316 // BERLIOS --- I'm tempted to do something about this...
1317 // Why unmount and remount again and again?
1318 log_msg(3, "Remounting CD");
1319 g_ISO_restore_mode = TRUE;
1320 if (is_this_device_mounted(MNT_CDROM)) {
1321 run_program_and_log_output("umount " MNT_CDROM, 5);
1322 }
1323 mr_asprintf(tmp, "mkdir -p %s/isodir &> /dev/null", bkpinfo->tmpdir);
1324 (void)system(tmp);
1325 mr_free(tmp);
1326
1327 if (((bkpinfo->isodir == NULL) && (bkpinfo->netfs_remote_dir == NULL)) || (bkpinfo->prefix == NULL)) {
1328 fatal_error("Unable to prepare ISO file name. Please report to dev team");
1329 }
1330 if (bkpinfo->netfs_remote_dir) {
1331 // NETFS
1332 mr_asprintf(tmp, "%s/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->netfs_remote_dir, bkpinfo->prefix, cd_number_i_want);
1333 } else {
1334 // ISO
1335 mr_asprintf(tmp, "%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->prefix, cd_number_i_want);
1336 }
1337 if (!does_file_exist(tmp)) {
1338 mr_free(tmp);
1339 if (bkpinfo->netfs_remote_dir) {
1340 // NETFS
1341 mr_asprintf(tmp, "%s/isodir/%s/%s-%d.iso", bkpinfo->tmpdir, bkpinfo->netfs_remote_dir, bkpinfo->prefix, cd_number_i_want);
1342 } else {
1343 // ISO
1344 mr_asprintf(tmp, "%s/isodir/%s-%d.iso", bkpinfo->tmpdir, bkpinfo->prefix, cd_number_i_want);
1345 }
1346 if (does_file_exist(tmp)) {
1347 log_msg(1, "FIXME - hacking bkpinfo->isodir from '%s' to %s/isodir", bkpinfo->isodir, bkpinfo->tmpdir);
1348 mr_free(bkpinfo->isodir);
1349 mr_asprintf(bkpinfo->isodir, "%s/isodir", bkpinfo->tmpdir);
1350 }
1351 }
1352 log_msg(3, "Mounting %s at %s", tmp, MNT_CDROM);
1353 if (mount_CDROM_here(tmp, MNT_CDROM)) {
1354 mr_free(tmp);
1355 fatal_error("Mommy!");
1356 }
1357 mr_free(tmp);
1358 }
1359 if ((res = what_number_cd_is_this()) != cd_number_i_want) {
1360 log_msg(3, "Currently, we hold %d but we want %d", res, cd_number_i_want);
1361 mds = media_descriptor_string(bkpinfo->backup_media_type);
1362 log_msg(3, "Insisting on %s #%d", mds, cd_number_i_want);
1363 mr_asprintf(request, "Please insert %s #%d and press Enter.", mds, cd_number_i_want);
1364 mr_free(mds);
1365
1366 while (what_number_cd_is_this() != cd_number_i_want) {
1367 sync();
1368 if (is_this_device_mounted(MNT_CDROM)) {
1369 res =
1370 run_program_and_log_output("umount " MNT_CDROM, FALSE);
1371 } else {
1372 res = 0;
1373 }
1374 if (res) {
1375 log_to_screen("WARNING - failed to unmount CD-ROM drive");
1376 }
1377 if (!bkpinfo->please_dont_eject) {
1378 res = eject_device(bkpinfo->media_device);
1379 } else {
1380 res = 0;
1381 }
1382 if (res) {
1383 log_to_screen("WARNING - failed to eject CD-ROM disk");
1384 }
1385 popup_and_OK(request);
1386 if (!bkpinfo->please_dont_eject) {
1387 inject_device(bkpinfo->media_device);
1388 }
1389 sync();
1390 }
1391 mr_free(request);
1392
1393 log_msg(1, "Thankyou. Proceeding...");
1394 g_current_media_number = cd_number_i_want;
1395 }
1396}
1397
1398/* @} - end of deviceGroup */
1399
1400
1401
1402/**
1403 * Creates a singly linked list of all of the non-NETFS mounted file systems.
1404 * @param DSFptr A pointer to the structure MOUNTED_FS_STRUCT used to hold
1405 * the list of mounted file systems.
1406 * @return None.
1407 */
1408static void add_mounted_fs_struct (MOUNTED_FS_STRUCT *DSFptr)
1409{
1410 assert (DSFptr);
1411 if (DSF_Head == NULL) {
1412 DSF_Head = DSFptr;
1413 } else {
1414 DSF_Tail->next = DSFptr;
1415 }
1416 DSFptr->next = NULL;
1417 DSF_Tail = DSFptr;
1418}
1419
1420/**
1421 * Find the structure, in the singly linked list of all of the non-NETFS
1422 * mounted file systems, that contains the specified device.
1423 * @param device The device to find
1424 * @return NULL if it didn't find the device, a pointer to the
1425 * structure if it did.
1426 */
1427static MOUNTED_FS_STRUCT *find_device_in_list (char *device)
1428{
1429 MOUNTED_FS_STRUCT *DSFptr = NULL;
1430
1431 DSFptr = DSF_Head;
1432 while (DSFptr != NULL) {
1433 if (!strcmp(DSFptr->device, device)) {
1434 break;
1435 }
1436 DSFptr = DSFptr->next;
1437 }
1438 return (DSFptr);
1439}
1440
1441/**
1442 * Find the structure, in the singly linked list of all of the non-NETFS
1443 * mounted file systems, that contains the specified mount point.
1444 * @param mount_point The mount point to find
1445 * @return NULL is it didn't find the mount point, a pointer to the
1446 * structure if it did.
1447 */
1448static MOUNTED_FS_STRUCT *find_mount_point_in_list (char *mount_point)
1449{
1450 MOUNTED_FS_STRUCT *DSFptr = NULL;
1451
1452 DSFptr = DSF_Head;
1453 while (DSFptr != NULL) {
1454 if (!strcmp(DSFptr->mount_point, mount_point)) {
1455 break;
1456 }
1457 DSFptr = DSFptr->next;
1458 }
1459 return (DSFptr);
1460}
1461
1462/**
1463 * Frees the memory for all of the structures on the linked list of
1464 * all of the non-NETFS mounted file systems.
1465 */
1466static void free_mounted_fs_list (void) {
1467 MOUNTED_FS_STRUCT *DSFptr = NULL;
1468 MOUNTED_FS_STRUCT *DSFnext = NULL;
1469
1470 DSFptr = DSF_Head;
1471 while (DSFptr != NULL) {
1472 DSFnext = DSFptr->next;
1473 paranoid_free(DSFptr);
1474 DSFptr = DSFnext;
1475 }
1476 DSF_Head = NULL;
1477 DSF_Tail = NULL;
1478}
1479
1480
1481/**
1482 * Creates a linked list of all of the non-NETFS mounted file systems.
1483 * We use a linked list because we don't know how many mounted file
1484 * there are (and there can be a lot).
1485 * @return 0 on success and greated than 0 on failure.
1486 */
1487static int create_list_of_non_NETFS_mounted_file_systems (void)
1488{
1489 int i = 0;
1490 int mount_cnt = 0;
1491 int lastpos = 0;
1492 char *mounted_file_system = NULL;
1493 char *command = NULL;
1494 char *token = NULL;
1495 char token_chars[] =" :\t\r\f\a\0";
1496 MOUNTED_FS_STRUCT *DSFptr = NULL;
1497
1498 free_mounted_fs_list();
1499 /********
1500 * Find the number of mounted file system entries and their respective mount points.
1501 * I can't return all of the entries as one string because it's length can be longer
1502 * than MAX_STR_LEN which is used in call_program_and_get_last_line_of_output().
1503 * So start looping and get the number of mounted file systems and query them one by one.
1504 ********/
1505 /* Get the number of mounted file systems ((those that start with "/dev/" */
1506 mr_asprintf(command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $0}}'|wc -l");
1507 log_msg(5, "Running: %s", command);
1508 mounted_file_system = call_program_and_get_last_line_of_output(command);
1509 mr_free(command);
1510
1511 mount_cnt = atoi(mounted_file_system);
1512 log_msg (5, "mount_cnt: %d", mount_cnt);
1513 mr_free(mounted_file_system);
1514
1515 for (i=mount_cnt; i > 0; i--) {
1516 mr_asprintf(command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $1,$3}}'|head -n %d", i);
1517 log_msg(5, "Running: %s", command);
1518 mounted_file_system = call_program_and_get_last_line_of_output(command);
1519 mr_free(command);
1520
1521 log_msg (5, "mounted_file_system: %s", mounted_file_system);
1522 if ((token = mr_strtok(mounted_file_system, token_chars, &lastpos)) == NULL) {
1523 log_msg (4, "Could not get the list of mounted file systems");
1524 mr_free(mounted_file_system);
1525 mr_free(token);
1526 return (1);
1527 }
1528 if (token) {
1529 log_msg (5, "token: %s", token);
1530 }
1531 while (token != NULL) {
1532 log_msg (5, "token: %s", token);
1533 if ((DSFptr = (MOUNTED_FS_STRUCT *) calloc(1, sizeof(MOUNTED_FS_STRUCT))) == NULL) {
1534 fatal_error ("Cannot allocate memory");
1535 }
1536 add_mounted_fs_struct(DSFptr);
1537 strcpy(DSFptr->device, token);
1538 mr_free(token);
1539 if ((token = mr_strtok(mounted_file_system, token_chars, &lastpos)) == NULL) {
1540 log_msg (5, "Ran out of entries on the mounted file systems list");
1541 mr_free(mounted_file_system);
1542 mr_free(token);
1543 return (1);
1544 }
1545 log_msg (5, "token: %s", token);
1546 strcpy(DSFptr->mount_point, token);
1547 mr_free(token);
1548 token = mr_strtok(mounted_file_system, token_chars, &lastpos);
1549 }
1550 mr_free(mounted_file_system);
1551 }
1552 return (0);
1553}
1554
1555
1556
1557/**
1558 * Given a whole disk device special file, determine which mounted file systems
1559 * are on the dsf's partitions and which mounted file systems are not.
1560 * @param dsf The whole disk device special file.
1561 * @param included_dsf_list A char pointer used to hold the list of mount points
1562 * that are on the dsf. Memory for the array will be allocated within the function.
1563 * @param excluded_dsf_list A char pointer used to hold the list of mount points
1564 * that are not on the dsf. Memory for the array will be allocated within the function.
1565 * @return 0 on success, -1 if no device special file was passed in, -2 if a device
1566 * special file was passed in but it has no partitions on it, or 1 on failure
1567 */
1568static int get_dsf_mount_list (const char *dsf, char **included_dsf_list, char **excluded_dsf_list) {
1569 int i = 0;
1570 int c = 0;
1571 int lastpos = 0;
1572 char *VG = NULL;
1573 char *tmp = NULL;
1574 char *command = NULL;
1575 char *partition_list = NULL;
1576 char *partitions[64];
1577 char *mount_list = NULL;
1578 char *token = NULL;
1579 char *ndsf = NULL;
1580 char token_chars[] =" \t\r\f\a\0";
1581 MOUNTED_FS_STRUCT *DSFptr = NULL;
1582
1583 memset((char *)partitions, 0, sizeof(partitions));
1584
1585 log_msg(5, "dsf: %s", dsf);
1586
1587 /********
1588 * See if a device special file was passed in (i.e. it must start with /dev/
1589 ********/
1590 if (strncmp(dsf, "/dev/", 5)) {
1591 log_msg (4, "%s does not start with /dev/ and (probably) is not a device special file", dsf);
1592 return (-1);
1593 }
1594 log_msg(4, " %s looks like a device special file", dsf);
1595 /* Verify that the dsf exists */
1596 mr_asprintf(command, "ls -al %s 2>/dev/null | wc -l", dsf);
1597 log_msg(5, " Executing: %s", command);
1598 tmp = call_program_and_get_last_line_of_output(command);
1599 mr_free(command);
1600
1601 log_msg(5, " Return value: %s", tmp);
1602 c = atoi(tmp);
1603 mr_free(tmp);
1604
1605 if (!c) {
1606 log_to_screen("Cannot find device special file %s", dsf);
1607 return (1);
1608 }
1609 log_msg(4, " %s device special file exists", dsf);
1610
1611 /* Get a list of the mounted file systems */
1612 if (create_list_of_non_NETFS_mounted_file_systems()) {
1613 log_to_screen ("Could not get the list of mounted file systems");
1614 return (1);
1615 }
1616 log_msg (5, "Processing dsf: %s", dsf);
1617 /********
1618 * Get a list of the dsf's partitions. There could be no partitions on the disk
1619 * or a dsf of a partition was passed in (e.g. /dev/sda1 instead of /dev/sda).
1620 * Either way, it's an error.
1621 ********/
1622 mr_asprintf(command, "parted2fdisk -l %s 2>/dev/null|grep -E \"^/dev/\"|awk '{printf(\"%%s \", $1)}END{print \"\"}'", dsf);
1623 log_msg(5, "Executing: %s", command);
1624 partition_list = call_program_and_get_last_line_of_output(command);
1625 mr_free(command);
1626
1627 log_msg(4, "Partition list for %s: %s", dsf, partition_list);
1628 if (!strlen(partition_list)) {
1629 /* There were no partitions on the disk */
1630 log_msg(4, "No partitions on device special file %s", dsf);
1631 log_msg(4, "I guess it's a partition itself");
1632 mr_asprintf(partitions[0], "%s", dsf);
1633 mr_asprintf(tmp, "%s", dsf);
1634 ndsf = truncate_to_drive_name(tmp);
1635 mr_free(tmp);
1636 } else {
1637 /* Fill the partition list */
1638 i = 0;
1639 lastpos = 0;
1640 while ((token = mr_strtok(partition_list, token_chars, &lastpos)) != NULL) {
1641 log_msg (4, "Found partition: %s", token);
1642 partitions[i++] = token;
1643 }
1644 mr_asprintf(ndsf, "%s", dsf);
1645 }
1646 mr_free(partition_list);
1647
1648 /* In any case we want to exclude the dsf itself from all MondRescue activities
1649 * at restore time (LVM, fdisk, ...) so we want it in our exclude_dev list */
1650 if ((DSFptr = (MOUNTED_FS_STRUCT *) calloc(1, sizeof(MOUNTED_FS_STRUCT))) == NULL) {
1651 fatal_error ("Cannot allocate memory");
1652 }
1653 add_mounted_fs_struct(DSFptr);
1654 strcpy(DSFptr->device, dsf);
1655 DSFptr->check = 1;
1656
1657 /* For the rest ndsf is the new dsf to deal with */
1658 /********
1659 * At this point, we have a list of all of the partitions on the dsf. Now try to
1660 * see which partitions have a file system on them.
1661 *
1662 * Loop through each partition on the disk and:
1663 *
1664 * - If the partition is swap, it ignores it.
1665 *
1666 * - If the partition is mounted (e.g. /dev/sda1 is mounted on /boot), it adds an entry
1667 * to the linked list, copies to it the device name and mount point, and sets check == 1.
1668 *
1669 * - If the partition is part of a Volume Group that has Logical Volumes mounted, it adds
1670 * an entry to the linked list for each mounted Logical Volume in that Volume Group, copying
1671 * to it the device name and mount point, and sets check == 1. Note that if the Volume Group
1672 * contains more than one disk, it will still add the entry even if the Logical Volume's
1673 * extents are not on the dsf that was passed in to the function. For example, Volume Group
1674 * VolGroup00 contains the disks /dev/sda1 and /dev/sdb1, and the Logical Volumes LogVol01,
1675 * which is mounted on /var and has all of its extents on /dev/sda1, and LogVol02, which is
1676 * mounted as /usr and has all of its extents on /dev/sdb1. If you pass /dev/sda into the
1677 * function, both /var and /usr will be archived even though /usr is actually on/dev/sdb.
1678 *
1679 * - If the partition is part of a Volume Group that has Logical Volumes used in a mounted
1680 * software raid device, it adds an entry to the linked list, copies to it the software raid
1681 * device name and mount point, and sets check == 1.
1682 *
1683 * - If the partition is part of a mounted software raid device, it adds an entry to the linked
1684 * list, copies to it the software raid device name and mount point, and sets check == 1.
1685 *
1686 ********/
1687 for (i=0; strlen(partitions[i]); i++) {
1688 log_msg(4, "Processing partition: %s", partitions[i]);
1689 /* See if it's swap. If it is, ignore it. */
1690 mr_asprintf(command, "parted2fdisk -l %s 2>/dev/null | awk '{if(($1==\"%s\")&&(toupper($0) ~ \"SWAP\")){print $1;exit}}'", ndsf, partitions[i]);
1691 log_msg(5, " Running: %s", command);
1692 tmp = call_program_and_get_last_line_of_output(command);
1693 mr_free(command);
1694
1695 log_msg(5, " Return value: %s", tmp);
1696 c = strlen(tmp);
1697 mr_free(tmp);
1698
1699 if (c) {
1700 log_msg(4, "It's swap. Ignoring partition %s", partitions[i]);
1701 continue;
1702 }
1703
1704 /* It's not swap. See if we can find the mount point from the mount command. */
1705 mr_asprintf(command, "mount 2>/dev/null | awk '{if((NF>0)&&($1==\"%s\")){print $3}}'", partitions[i]);
1706 tmp = call_program_and_get_last_line_of_output(command);
1707 mr_free(command);
1708
1709 if (strlen(tmp)) {
1710 log_msg(4, " %s is mounted: %s", partitions[i], tmp);
1711 if ((DSFptr = find_mount_point_in_list(tmp)) == NULL) {
1712 log_msg (4, "Can't find mount point %s in mounted file systems list", tmp);
1713 mr_free(tmp);
1714 return (1);
1715 }
1716 DSFptr->check = 1;
1717 mr_free(tmp);
1718 continue;
1719 }
1720 mr_free(tmp);
1721
1722 /* It's not swap and it's not mounted. See if it's LVM */
1723 log_msg(4, " It's not mounted. Checking to see if it's LVM...");
1724
1725 /* Check for LVM */
1726 mr_asprintf(command, "pvdisplay -c %s | grep '%s:' 2> /dev/null", partitions[i], partitions[i]);
1727 log_msg(5, " Running: %s", command);
1728 tmp = call_program_and_get_last_line_of_output(command);
1729 mr_free(command);
1730
1731 if (strlen(tmp)) {
1732 log_msg(4, "Found an LVM partition at %s. Find the VG it's in...", partitions[i]);
1733 /* It's LVM: Find the VG it's in */
1734 mr_asprintf(command, "pvdisplay -v %s 2>/dev/null|grep \"VG Name\"|awk '{print $NF}'", partitions[i]);
1735 log_msg(5, " Running: %s", command);
1736 strcpy(VG, call_program_and_get_last_line_of_output(command));
1737 mr_free(command);
1738
1739 log_msg(4, " Volume Group: %s", VG);
1740 if (strlen(VG)) {
1741 /* Found the Volume Group. Now find all of the VG's mount points */
1742 log_msg(4, " Found the Volume Group. Now find all of the VG's mount points");
1743 mr_asprintf(command, "mount 2>/dev/null|grep -E \"/dev/mapper/%s-|/dev/%s/\"|awk '{printf(\"%%s \",$3)}END{print \"\"}'", VG, VG);
1744 log_msg(5, " Running: %s", command);
1745 mr_asprintf(mount_list, "%s", call_program_and_get_last_line_of_output(command));
1746 mr_free(command);
1747
1748 log_msg(4, " VG %s mount_list: %s", VG, mount_list);
1749 lastpos = 0;
1750 while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) {
1751 log_msg (5, "mount point token: %s", token);
1752 if ((DSFptr = find_mount_point_in_list(token)) == NULL) {
1753 log_msg (4, "Can't find mount point %s in mounted file systems list", token);
1754 mr_free(tmp);
1755 mr_free(token);
1756 return (1);
1757 }
1758 DSFptr->check = 1;
1759 mr_free(token);
1760 }
1761 /********
1762 * Now we want to see if there are any software raid devices using
1763 * any of the Logical Volumes on the Volume Group.
1764 *******/
1765 mr_free(mount_list);
1766
1767 mr_asprintf(command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
1768 log_msg (5, "Running: %s", command);
1769 mr_asprintf(mount_list, "%s", call_program_and_get_last_line_of_output(command));
1770 mr_free(command);
1771
1772 log_msg(4, " Software raid device list: %s", mount_list);
1773 lastpos = 0;
1774 while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) {
1775 mr_asprintf(command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, VG);
1776 log_msg (5, "Running: %s", command);
1777 mr_free(tmp);
1778 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
1779 mr_free(command);
1780
1781 log_msg(4, "Number of Software raid device: %s", tmp);
1782 if (atoi(tmp)) {
1783 /* This device is on our disk */
1784 if ((DSFptr = find_device_in_list(token)) == NULL) {
1785 log_msg (4, "Can't find device %s in mounted file systems list", token);
1786 mr_free(tmp);
1787 mr_free(VG);
1788 mr_free(token);
1789 return (1);
1790 }
1791 DSFptr->check = 1;
1792 }
1793 }
1794 mr_free(token);
1795 paranoid_free(mount_list);
1796 } else {
1797 log_msg (4, "Error finding Volume Group for partition %s", partitions[i]);
1798 mr_free(tmp);
1799 return (1);
1800 }
1801 mr_free(tmp);
1802 continue;
1803 } else {
1804 log_msg (4, "Error finding partition type for the partition %s", partitions[i]);
1805 }
1806 mr_free(tmp);
1807
1808 /********
1809 * It's not swap, mounted, or LVM. See if it's used in a software raid device.
1810 ********/
1811 log_msg (5, "It's not swap, mounted, or LVM. See if it's used in a software raid device.");
1812 mr_asprintf(command, "mdadm --examine %s 2>/dev/null | awk '{if($1 == \"UUID\"){print $3}}'", partitions[i]);
1813 log_msg(4, " Running: %s", command);
1814 tmp = call_program_and_get_last_line_of_output(command);
1815 mr_free(command);
1816
1817 if (!strlen(tmp)) {
1818 log_msg(4, " Partition %s is not used in a non-LVM software raid device", partitions[i]);
1819 mr_free(tmp);
1820 continue;
1821 }
1822 log_msg (5, " UUID: %s", tmp);
1823
1824 /* Get the Software raid device list */
1825 mr_asprintf(command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
1826 log_msg (5, " Running: %s", command);
1827 mount_list = call_program_and_get_last_line_of_output(command);
1828 mr_free(command);
1829
1830 log_msg(4, " Software raid device list: %s", mount_list);
1831 /* Loop through the software raid device list to see if we can find the partition */
1832 lastpos = 0;
1833 while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) {
1834 mr_asprintf(command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, tmp);
1835 log_msg(4, " Running: %s", command);
1836 mr_free(tmp);
1837
1838 tmp = call_program_and_get_last_line_of_output(command);
1839 mr_free(command);
1840
1841 c = atoi(tmp);
1842 mr_free(tmp);
1843
1844 if (!c) {
1845 log_msg (4," Didn't find partition %s in software raid device %s", partitions[i], token);
1846 } else {
1847 if ((DSFptr = find_device_in_list(token)) == NULL) {
1848 log_msg (4, "Can't find device %s in mounted file systems list", token);
1849 mr_free(token);
1850 return (1);
1851 }
1852 DSFptr->check = 1;
1853 break;
1854 }
1855 mr_free(token);
1856 }
1857 mr_free(tmp);
1858 mr_free(mount_list);
1859 mr_free(partitions[i]);
1860 }
1861
1862 /* Determine how much memory to allocate for included_dsf_list and excluded_dsf_list */
1863 i = 0;
1864 DSFptr= DSF_Head;
1865 while (DSFptr != NULL) {
1866 i += strlen(DSFptr->mount_point) + 1;
1867 DSFptr = DSFptr->next;
1868 }
1869 log_msg (5, "i: %d", i);
1870 if ((*included_dsf_list = (char *) calloc(i+100, sizeof(char))) == NULL) {
1871 fatal_error ("Cannot allocate memory");
1872 }
1873 if ((*excluded_dsf_list = (char *) calloc(i+100, sizeof(char))) == NULL) {
1874 fatal_error ("Cannot allocate memory");
1875 }
1876 DSFptr= DSF_Head;
1877 while (DSFptr != NULL) {
1878 if (DSFptr->check) {
1879 log_msg (4, "%s is mounted on %s and is on disk %s\n", DSFptr->device, DSFptr->mount_point, ndsf);
1880 strcat(*included_dsf_list, DSFptr->mount_point);
1881 strcat(*included_dsf_list, " ");
1882 } else {
1883 log_msg (4, "%s is mounted on %s and is NOT on disk %s\n", DSFptr->device, DSFptr->mount_point, ndsf);
1884 strcat(*excluded_dsf_list, DSFptr->mount_point);
1885 strcat(*excluded_dsf_list, " ");
1886 }
1887 DSFptr = DSFptr->next;
1888 }
1889 mr_free(ndsf);
1890
1891 log_msg (5, "included_dsf_list: %s", *included_dsf_list);
1892 log_msg (5, "excluded_dsf_list: %s", *excluded_dsf_list);
1893 return (0);
1894}
1895
1896
1897/* Update the bkpinfo structure for exclude & include paths
1898 * in order to handle correctly paths corresponding to devices */
1899void mr_make_devlist_from_pathlist(char *pathlist, char mode) {
1900
1901char *token = NULL;
1902int lastpos = 0;
1903char *mounted_on_dsf = NULL;
1904char *not_mounted_on_dsf = NULL;
1905char token_chars[] =" \t\r\f\a\0\n";
1906char *tmp = NULL;
1907char *tmp1 = NULL;
1908
1909while ((token = mr_strtok(pathlist, token_chars, &lastpos)) != NULL) {
1910 switch (get_dsf_mount_list(token, &mounted_on_dsf, &not_mounted_on_dsf)) {
1911 case 1:
1912 if (mode == 'E') {
1913 log_msg(1, "WARNING ! %s doesn't exist in -E option", token);
1914 } else {
1915 log_msg(1, "ERROR ! %s doesn't exist in -I option", token);
1916 fatal_error("Error processing -I option");
1917 }
1918 break;
1919 /* Everything is OK; proceed to archive data */
1920 case 0:
1921 if (mode == 'E') {
1922 if (strlen(mounted_on_dsf)) {
1923 log_to_screen("Excluding the following file systems on %s:\n", token);
1924 log_to_screen(" %s\n", mounted_on_dsf);
1925 log_msg (5, "Adding to bkpinfo->exclude_paths due to -E option: %s", mounted_on_dsf);
1926 mr_strcat(bkpinfo->exclude_paths, " %s ", mounted_on_dsf);
1927 mr_strcat(bkpinfo->exclude_devs, " %s ", token);
1928 }
1929 } else {
1930 log_to_screen("Archiving only the following file systems on %s:\n", token);
1931 log_to_screen(" %s\n", mounted_on_dsf);
1932 strcpy(bkpinfo->include_paths, "/");
1933 if (strlen(not_mounted_on_dsf)) {
1934 log_msg (5, "Adding to bkpinfo->exclude_paths due to -I option: %s", not_mounted_on_dsf);
1935 log_to_screen("Not archiving the following file systems:\n");
1936 log_to_screen(" %s\n", not_mounted_on_dsf);
1937 mr_strcat(bkpinfo->exclude_paths, " %s ", mounted_on_dsf);
1938 }
1939 }
1940 break;
1941 /* It's a dsf but not a whole disk dsf */
1942 case -2:
1943 log_to_screen("Could %s be a partition instead of a whole disk device special file?\nIgnored.", token);
1944 break;
1945 /* A device special file was not passed in. Process it as a path. */
1946 case -1:
1947 /* we need to add a space after token to be sure our strstr test works correctly */
1948 mr_asprintf(tmp1,"%s ",token);
1949 if (mode == 'E') {
1950 /* Add the token if not already in the list */
1951 mr_asprintf(tmp,"%s ",bkpinfo->exclude_paths);
1952 if (strstr(tmp,tmp1) == NULL) {
1953 mr_strcat(bkpinfo->exclude_paths, " %s", tmp1);
1954 }
1955 } else {
1956 /* Add the token if not already in the list */
1957 mr_asprintf(tmp,"%s ",bkpinfo->include_paths);
1958 if (strstr(tmp,tmp1) == NULL) {
1959 mr_strcat(bkpinfo->include_paths, " %s", tmp1);
1960 }
1961 }
1962 mr_free(tmp);
1963 mr_free(tmp1);
1964 break;
1965 }
1966 mr_free(token);
1967
1968 if (bkpinfo->include_paths != NULL) {
1969 mr_strip_spaces(bkpinfo->include_paths);
1970 log_msg(1, "include_paths is now '%s'", bkpinfo->include_paths);
1971 }
1972 if (bkpinfo->exclude_paths != NULL) {
1973 mr_strip_spaces(bkpinfo->exclude_paths);
1974 log_msg(1, "exclude_paths is now '%s'", bkpinfo->exclude_paths);
1975 }
1976 if (bkpinfo->exclude_devs != NULL) {
1977 mr_strip_spaces(bkpinfo->exclude_devs);
1978 log_msg(1, "exclude_devs is now '%s'", bkpinfo->exclude_devs);
1979 }
1980}
1981}
1982
1983
1984/**
1985 * @addtogroup utilityGroup
1986 * @{
1987 */
1988/**
1989 * Get a space-separated list of NETFS devices and mounts.
1990 * @return The list created.
1991 * @note The return value points to static data that will be overwritten with each call.
1992 */
1993char *list_of_NETFS_devices_and_mounts(void)
1994{
1995 char *exclude_these_devices = NULL;
1996 char *exclude_these_directories = NULL;
1997 static char result_sz[1024];
1998
1999 mr_asprintf(exclude_these_directories,"%s",list_of_NETFS_mounts_only());
2000 exclude_these_devices = call_program_and_get_last_line_of_output("tr -s '\t' ' ' < /etc/fstab | grep -E '( (coda|ncpfs|sshfs|nfs|nfs4|smbfs|cifs|afs|gfs|ocfs|ocfs2|mvfs|nsspool|nsvol) )' | cut -d' ' -f1 | tr -s '\n' ' ' | awk '{print $0;}'");
2001 snprintf(result_sz, 1023, "%s %s", exclude_these_directories, exclude_these_devices);
2002 mr_free(exclude_these_devices);
2003 mr_free(exclude_these_directories);
2004 return (result_sz);
2005}
2006
2007
2008
2009
2010/**
2011 * Get a space-separated list of NETFS mounts.
2012 * @return The list created.
2013 * @note The return value points to static data that will be overwritten with each call.
2014 * @bug Even though we only want the mounts, the devices are still checked.
2015 */
2016char *list_of_NETFS_mounts_only(void)
2017{
2018 char *exclude_these_directories = NULL;
2019 static char result_sz[512];
2020
2021 exclude_these_directories = call_program_and_get_last_line_of_output("mount -t coda,ncpfs,fuse.sshfs,nfs,nfs4,smbfs,cifs,afs,gfs,ocfs,ocfs2,mvfs,nsspool,nssvol | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' ' ' | awk '{print $0;}'");
2022 snprintf(result_sz, 511, "%s", exclude_these_directories);
2023 mr_free(exclude_these_directories);
2024 return (result_sz);
2025}
2026
2027/* @} - end of utilityGroup */
2028
2029
2030
2031
2032
2033/**
2034 * Create a randomly-named FIFO. The format is @p stub "." [random] [random] where
2035 * [random] is a random number between 1 and 32767.
2036 * @param store_name_here Where to store the new filename.
2037 * @param stub A random number will be appended to this to make the FIFO's name.
2038 * @ingroup deviceGroup
2039 */
2040void make_fifo(char *store_name_here, char *stub)
2041{
2042 char *tmp = NULL;
2043
2044 assert_string_is_neither_NULL_nor_zerolength(stub);
2045
2046 sprintf(store_name_here, "%s%d%d", stub, (int) (random() % 32768),
2047 (int) (random() % 32768));
2048 make_hole_for_file(store_name_here);
2049 mkfifo(store_name_here, S_IRWXU | S_IRWXG);
2050 mr_asprintf(tmp, "chmod 770 %s", store_name_here);
2051 paranoid_system(tmp);
2052 mr_free(tmp);
2053}
2054
2055
2056
2057
2058
2059
2060/**
2061 * Set the tmpdir and scratchdir to reside on the partition with the most free space.
2062 * Automatically excludes DOS, NTFS, SMB, and NFS filesystems.
2063 * @param bkpinfo The backup information structure. @c bkpinfo->tmpdir and @c bkpinfo->scratchdir will be set.
2064 * @ingroup utilityGroup
2065 */
2066void sensibly_set_scratchdir()
2067{
2068 char *tmp = NULL;
2069 char *command = NULL;
2070 char *sz = NULL;
2071
2072#ifdef __FreeBSD__
2073 tmp = call_program_and_get_last_line_of_output("LANGUAGE=C df -m -P -t nonfs,msdosfs,ntfs,ntfs-3g,smbfs,smb,cifs,afs,gfs,ocfs,ocfs2,mvfs,nsspool,nssvol | grep -vE \"none|Filesystem\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;} | while read x ; do test -w $x && echo $x && break ; done'");
2074#else
2075 tmp = call_program_and_get_last_line_of_output("LANGUAGE=C df -m -P -x nfs -x nfs4 -x fuse.sshfs -x fuse -x vfat -x ntfs -x ntfs-3g -x smbfs -x smb -x cifs -x afs -x gfs -x ocfs -x ocfs2 -x mvfs -x nsspool -x nssvol -x iso9660 | grep -vE \"none|Filesystem|/dev/shm\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}' | while read x ; do test -w $x && echo $x && break ; done");
2076#endif
2077
2078 if (tmp[0] != '/') {
2079 mr_asprintf(sz, "%s", tmp);
2080 mr_free(tmp);
2081 mr_asprintf(tmp, "/%s", sz);
2082 mr_free(sz);
2083 }
2084 if (!tmp[0]) {
2085 fatal_error("I couldn't figure out the scratchdir!");
2086 }
2087
2088 /* Cleaning a potential previous scratchdir */
2089 if (bkpinfo->scratchdir) {
2090 mr_asprintf(command, "rm -Rf %s", bkpinfo->scratchdir);
2091 paranoid_system(command);
2092 mr_free(command);
2093 }
2094 mr_free(bkpinfo->scratchdir);
2095
2096 mr_asprintf(bkpinfo->scratchdir , "%s/mondo.scratch.%d", tmp, (int) (random() % 32768));
2097 log_it("bkpinfo->scratchdir is being set to %s", bkpinfo->scratchdir);
2098
2099 /* Cleaning potential previous scratchdir */
2100 mr_asprintf(command, "rm -Rf %s/mondo.scratch.*", tmp);
2101 mr_free(tmp);
2102
2103 paranoid_system(command);
2104 mr_free(command);
2105}
2106
2107
2108
2109
2110
2111
2112/**
2113 * @addtogroup deviceGroup
2114 * @{
2115 */
2116/**
2117 * If we can read @p dev, set @return output to it.
2118 * If @p dev cannot be read, set @p output to NULL.
2119 * @param dev The device to check for.
2120 * @return output Set to @p dev if @p dev exists, NULL otherwise.
2121 */
2122char *set_dev_to_this_if_rx_OK(char *dev)
2123{
2124 char *command = NULL;
2125 char *output = NULL;
2126
2127 if (!dev || dev[0] == '\0') {
2128 return(NULL);
2129 }
2130 log_msg(10, "Injecting %s", dev);
2131 inject_device(dev);
2132 if (!does_file_exist(dev)) {
2133 log_msg(10, "%s doesn't exist. Returning FALSE.", dev);
2134 return(NULL);
2135 }
2136 mr_asprintf(command, "dd bs=%ld count=1 if=%s of=/dev/null &> /dev/null", 512L, dev);
2137 if (!run_program_and_log_output(command, FALSE)
2138 && !run_program_and_log_output(command, FALSE)) {
2139 mr_asprintf(output, "%s", dev);
2140 log_msg(4, "Found it - %s", dev);
2141 } else {
2142 log_msg(4, "It's not %s", dev);
2143 }
2144 mr_free(command);
2145 return(output);
2146}
2147
2148
2149
2150
2151
2152/**
2153 * Find out what number CD is in the drive.
2154 * @param bkpinfo The backup information structure. The @c bkpinfo->media_device field is the only one used.
2155 * @return The current CD number, or -1 if it could not be found.
2156 * @note If the CD is not mounted, it will be mounted
2157 * (and remain mounted after this function returns).
2158 */
2159int what_number_cd_is_this()
2160{
2161 int cd_number = -1;
2162 char *mountdev = NULL;
2163 char *tmp = NULL;
2164
2165 assert(bkpinfo != NULL);
2166 // log_it("Asking what_number_cd_is_this");
2167 if (g_ISO_restore_mode) {
2168 mr_asprintf(tmp, "mount | grep iso9660 | awk '{print $3;}'");
2169 mountdev = call_program_and_get_last_line_of_output(tmp);
2170 mr_strcat(mountdev, "/archives/THIS-CD-NUMBER");
2171 mr_free(tmp);
2172
2173 tmp = last_line_of_file(mountdev);
2174 cd_number = atoi(tmp);
2175 mr_free(tmp);
2176 mr_free(mountdev);
2177 return (cd_number);
2178 }
2179
2180 if (bkpinfo->media_device) {
2181 mr_asprintf(mountdev, "%s", bkpinfo->media_device);
2182 }
2183 if (!mountdev) {
2184 log_it("(what_number_cd_is_this) Warning - media_device unknown. Finding out...");
2185 mr_free(bkpinfo->media_device);
2186 bkpinfo->media_device = find_cdrom_device(FALSE);
2187 mr_asprintf(mountdev, "%s", bkpinfo->media_device);
2188 }
2189 if (!is_this_device_mounted(MNT_CDROM)) {
2190 if (bkpinfo->backup_media_type == usb) {
2191 mount_USB_here(mountdev, MNT_CDROM);
2192 } else {
2193 mount_CDROM_here(mountdev, MNT_CDROM);
2194 }
2195 }
2196 mr_free(mountdev);
2197
2198 tmp = last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER");
2199 cd_number = atoi(tmp);
2200 mr_free(tmp);
2201 return (cd_number);
2202}
2203
2204
2205
2206
2207
2208
2209
2210/**
2211 * Find out what device is mounted as root (/).
2212 * @return Root device.
2213 * @note The returned string points to static storage and will be overwritten with every call.
2214 * @bug A bit of a misnomer; it's actually finding out the root device.
2215 * The mountpoint (where it's mounted) will obviously be '/'.
2216 */
2217char *where_is_root_mounted() {
2218 /*@ buffers **************** */
2219 char *output = NULL;
2220
2221
2222#ifdef __FreeBSD__
2223 output = call_program_and_get_last_line_of_output("mount | grep ' on / ' | cut -d' ' -f1");
2224#else
2225 output = call_program_and_get_last_line_of_output("mount | grep ' on / ' | cut -d' ' -f1 | sed 's/[0-9]//' | sed 's/[0-9]//'");
2226 if (strstr(output, "/dev/cciss/")) {
2227 mr_free(output);
2228 output = call_program_and_get_last_line_of_output("mount | grep ' on / ' | cut -d' ' -f1 | cut -dp -f1");
2229 }
2230 if (strstr(output, "/dev/md")) {
2231 mr_free(output);
2232 output = call_program_and_get_last_line_of_output("mount | grep ' on / ' | cut -d' ' -f1");
2233 }
2234#endif
2235
2236 return (output);
2237}
2238
2239
2240/**
2241 * Find out which boot loader is in use.
2242 * @param which_device Device to look for the boot loader on.
2243 * @return 'L' for LILO, 'E'for ELILO, 'G' for GRUB, 'B' or 'D' for FreeBSD boot loaders, or 'U' for Unknown.
2244 * @note Under Linux, all drives are examined, not just @p which_device.
2245 */
2246#ifdef __FreeBSD__
2247char which_boot_loader(char *which_device) {
2248 int count_lilos = 0;
2249 int count_grubs = 0;
2250 int count_boot0s = 0;
2251 int count_dangerouslydedicated = 0;
2252
2253 log_it("looking at drive %s's MBR", which_device);
2254 if (does_string_exist_in_boot_block(which_device, "GRUB")) {
2255 count_grubs++;
2256 }
2257 if (does_string_exist_in_boot_block(which_device, "LILO")) {
2258 count_lilos++;
2259 }
2260 if (does_string_exist_in_boot_block(which_device, "Drive")) {
2261 count_boot0s++;
2262 }
2263 if (does_string_exist_in_first_N_blocks(which_device, "FreeBSD/i386", 17)) {
2264 count_dangerouslydedicated++;
2265 }
2266 log_it("%d grubs and %d lilos and %d elilos and %d boot0s and %d DD\n",
2267 count_grubs, count_lilos, count_elilos, count_boot0s,
2268 count_dangerouslydedicated);
2269
2270 if (count_grubs && !count_lilos) {
2271 return ('G');
2272 } else if (count_lilos && !count_grubs) {
2273 return ('L');
2274 } else if (count_grubs == 1 && count_lilos == 1) {
2275 log_it("I'll bet you used to use LILO but switched to GRUB...");
2276 return ('G');
2277 } else if (count_boot0s == 1) {
2278 return ('B');
2279 } else if (count_dangerouslydedicated) {
2280 return ('D');
2281 } else {
2282 log_it("Unknown boot loader");
2283 return ('U');
2284 }
2285}
2286
2287#else
2288
2289char which_boot_loader(char *which_device) {
2290 /*@ buffer ***************************************************** */
2291 char *list_drives_cmd = NULL;
2292 char *tmp = NULL;
2293 char *current_drive = NULL;
2294
2295 /*@ pointers *************************************************** */
2296 FILE *pdrives = NULL;
2297
2298 /*@ int ******************************************************** */
2299 int count_lilos = 0;
2300 int count_grubs = 0;
2301
2302 /*@ end vars *************************************************** */
2303
2304
2305#ifdef __IA64__
2306 /* No choice for it */
2307 return ('E');
2308#endif
2309
2310 tmp = where_is_root_mounted();
2311 mr_asprintf(list_drives_cmd, "parted2fdisk -l 2>/dev/null | grep \"/dev/.*:\" | tr -s ':' ' ' | tr -s ' ' '\n' | grep /dev/; echo %s", tmp);
2312 mr_free(tmp);
2313 log_it("list_drives_cmd = %s", list_drives_cmd);
2314
2315 pdrives = popen(list_drives_cmd, "r");
2316 mr_free(list_drives_cmd);
2317
2318 if (!pdrives) {
2319 log_OS_error("Unable to open list of drives");
2320 return ('\0');
2321 }
2322
2323 for (mr_getline(current_drive, pdrives); !feof(pdrives); mr_getline(current_drive, pdrives)) {
2324 mr_strip_spaces(current_drive);
2325 log_it("looking at drive %s's MBR", current_drive);
2326 if (does_string_exist_in_boot_block(current_drive, "GRUB")) {
2327 count_grubs++;
2328 /* BERLIOS : removed as I don't think it's mandatory here
2329 mr_free(which_device);
2330 mr_asprintf(which_device, "%s", current_drive);
2331 */
2332 mr_free(current_drive);
2333 break;
2334 }
2335 if (does_string_exist_in_boot_block(current_drive, "LILO")) {
2336 count_lilos++;
2337 /* BERLIOS : removed as I don't think it's mandatory here
2338 mr_free(which_device);
2339 mr_asprintf(which_device, "%s", current_drive);
2340 */
2341 mr_free(current_drive);
2342 break;
2343 }
2344 mr_free(current_drive);
2345 }
2346 mr_free(current_drive);
2347
2348 if (pclose(pdrives)) {
2349 log_OS_error("Cannot pclose pdrives");
2350 }
2351 log_it("%d grubs and %d lilos\n", count_grubs, count_lilos);
2352 if (count_grubs && !count_lilos) {
2353 return ('G');
2354 } else if (count_lilos && !count_grubs) {
2355 return ('L');
2356 } else if (count_grubs == 1 && count_lilos == 1) {
2357 log_it("I'll bet you used to use LILO but switched to GRUB...");
2358 return ('G');
2359 } else {
2360 // We need to look on each partition then
2361 mr_asprintf(list_drives_cmd, "parted2fdisk -l 2>/dev/null | grep -E \"^/dev/\" | tr -s ':' ' ' | tr -s ' ' '\n' | grep /dev/");
2362 log_it("list_drives_cmd = %s", list_drives_cmd);
2363
2364 if (!(pdrives = popen(list_drives_cmd, "r"))) {
2365 log_OS_error("Unable to open list of drives");
2366 mr_free(list_drives_cmd);
2367 return ('\0');
2368 }
2369 mr_free(list_drives_cmd);
2370
2371 for (mr_getline(current_drive, pdrives); !feof(pdrives); mr_getline(current_drive, pdrives)) {
2372 mr_strip_spaces(current_drive);
2373 log_it("looking at partition %s's BR", current_drive);
2374 if (does_string_exist_in_boot_block(current_drive, "GRUB")) {
2375 count_grubs++;
2376 /* BERLIOS : removed as I don't think it's mandatory here
2377 mr_free(which_device);
2378 mr_asprintf(which_device, "%s", current_drive);
2379 */
2380 mr_free(current_drive);
2381 break;
2382 }
2383 if (does_string_exist_in_boot_block(current_drive, "LILO")) {
2384 count_lilos++;
2385 /* BERLIOS : removed as I don't think it's mandatory here
2386 mr_free(which_device);
2387 mr_asprintf(which_device, "%s", current_drive);
2388 */
2389 mr_free(current_drive);
2390 break;
2391 }
2392 mr_free(current_drive);
2393 }
2394 mr_free(current_drive);
2395
2396 if (pclose(pdrives)) {
2397 log_OS_error("Cannot pclose pdrives");
2398 }
2399 log_it("%d grubs and %d lilos\n", count_grubs, count_lilos);
2400 if (count_grubs && !count_lilos) {
2401 return ('G');
2402 } else if (count_lilos && !count_grubs) {
2403 return ('L');
2404 } else if (count_grubs == 1 && count_lilos == 1) {
2405 log_it("I'll bet you used to use LILO but switched to GRUB...");
2406 return ('G');
2407 } else {
2408 log_it("Unknown boot loader");
2409 return ('U');
2410 }
2411 }
2412}
2413#endif
2414
2415
2416
2417
2418/**
2419 * Write zeroes over the first 16K of @p device.
2420 * @param device The device to zero.
2421 * @return 0 for success, 1 for failure.
2422 */
2423int zero_out_a_device(char *device)
2424{
2425 FILE *fout;
2426 int i;
2427
2428 assert_string_is_neither_NULL_nor_zerolength(device);
2429
2430 log_it("Zeroing drive %s", device);
2431 if (!(fout = fopen(device, "w"))) {
2432 log_OS_error("Unable to open/write to device");
2433 return (1);
2434 }
2435 for (i = 0; i < 16384; i++) {
2436 fputc('\0', fout);
2437 }
2438 paranoid_fclose(fout);
2439 log_it("Device successfully zeroed.");
2440 return (0);
2441}
2442
2443/**
2444 * Return the device pointed to by @p incoming.
2445 * @param incoming The device to resolve symlinks for.
2446 * @return The path to the real device file.
2447 * @note The returned string points to static storage that will be overwritten with each call.
2448 * @bug Won't work with file v4.0; needs to be written in C.
2449 */
2450char *resolve_softlinks_to_get_to_actual_device_file(char *incoming)
2451{
2452 char *output;
2453 char *command = NULL;
2454 char *curr_fname;
2455 char *scratch = NULL;
2456 char *tmp = NULL;
2457 char *p;
2458
2459 struct stat statbuf;
2460 malloc_string(curr_fname);
2461 if (!does_file_exist(incoming)) {
2462 log_it("resolve_softlinks_to_get_to_actual_device_file --- device not found");
2463 mr_asprintf(output, "%s", incoming);
2464 } else {
2465 strcpy(curr_fname, incoming);
2466 lstat(curr_fname, &statbuf);
2467 while (S_ISLNK(statbuf.st_mode)) {
2468 log_msg(1, "curr_fname = %s", curr_fname);
2469 mr_asprintf(command, "file %s", curr_fname);
2470 tmp = call_program_and_get_last_line_of_output(command);
2471 mr_free(command);
2472 for (p = tmp + strlen(tmp); p != tmp && *p != '`' && *p != ' '; p--);
2473 p++;
2474 mr_asprintf(scratch, "%s", p);
2475 for (p = scratch; *p != '\0' && *p != '\''; p++);
2476 *p = '\0';
2477 log_msg(0, "curr_fname %s --> '%s' --> %s", curr_fname, tmp, scratch);
2478 mr_free(tmp);
2479
2480 if (scratch[0] == '/') {
2481 strcpy(curr_fname, scratch); // copy whole thing because it's an absolute softlink
2482 } else { // copy over the basename cos it's a relative softlink
2483 p = curr_fname + strlen(curr_fname);
2484 while (p != curr_fname && *p != '/') {
2485 p--;
2486 }
2487 if (*p == '/') {
2488 p++;
2489 }
2490 strcpy(p, scratch);
2491 }
2492 mr_free(scratch);
2493 lstat(curr_fname, &statbuf);
2494 }
2495 mr_asprintf(output, "%s", curr_fname);
2496 log_it("resolved %s to %s", incoming, output);
2497 }
2498 paranoid_free(curr_fname);
2499 return (output);
2500}
2501
2502/* @} - end of deviceGroup */
2503
2504/**
2505 * Return the type of partition format (GPT or MBR)
2506 */
2507char *which_partition_format(const char *drive)
2508{
2509 char *output;
2510 char *tmp = NULL;
2511 char *command = NULL;
2512 char *fdisk = NULL;
2513#ifdef __IA64__
2514 struct stat buf;
2515#endif
2516 mr_asprintf(fdisk, "/sbin/parted2fdisk");
2517 mr_asprintf(command, "%s -l %s | grep 'EFI GPT'", fdisk, drive);
2518 mr_free(fdisk);
2519
2520 tmp = call_program_and_get_last_line_of_output(command);
2521 mr_free(command);
2522
2523 if (strstr(tmp, "GPT") == NULL) {
2524 mr_asprintf(output, "MBR");
2525 } else {
2526 mr_asprintf(output, "GPT");
2527 }
2528 mr_free(tmp);
2529
2530 log_msg(0, "Found %s partition table format type", output);
2531 return (output);
2532}
2533/**
2534 * Ask user for details of backup/restore information.
2535 * Called when @c mondoarchive doesn't get any parameters.
2536 * @param bkpinfo The backup information structure to fill out with the user's data.
2537 * @param archiving_to_media TRUE if archiving, FALSE if restoring.
2538 * @return 0, always.
2539 * @bug No point of `int' return value.
2540 * @ingroup archiveGroup
2541 */
2542int interactively_obtain_media_parameters_from_user(bool archiving_to_media)
2543// archiving_to_media is TRUE if I'm being called by mondoarchive
2544// archiving_to_media is FALSE if I'm being called by mondorestore
2545{
2546 char *tmp = NULL;
2547 char *p = NULL;
2548 char *mds = NULL;
2549 char *sz_size = NULL;
2550 char *command = NULL;
2551 char *comment = NULL;
2552 int i;
2553 FILE *fin;
2554
2555 assert(bkpinfo != NULL);
2556 bkpinfo->nonbootable_backup = FALSE;
2557
2558 // Tape, CD, NETFS, ...?
2559 srandom(getpid());
2560 bkpinfo->backup_media_type = which_backup_media_type(bkpinfo->restore_data);
2561 if (bkpinfo->backup_media_type == none) {
2562 log_to_screen("User has chosen not to backup the PC");
2563 finish(1);
2564 }
2565 /* Why asking to remove the media with tape ?
2566 if (bkpinfo->backup_media_type == tape && bkpinfo->restore_data) {
2567 popup_and_OK("Please remove media from drive(s)");
2568 }
2569 */
2570 tmp = bkptype_to_string(bkpinfo->backup_media_type);
2571 log_msg(3, "media type = %s", tmp);
2572 mr_free(tmp);
2573
2574 bkpinfo->cdrw_speed = (bkpinfo->backup_media_type == cdstream) ? 2 : 4;
2575 bkpinfo->compression_level = (bkpinfo->backup_media_type == cdstream) ? 1 : 5;
2576 bkpinfo->use_lzo = (bkpinfo->backup_media_type == cdstream) ? TRUE : FALSE;
2577 mvaddstr_and_log_it(2, 0, " ");
2578
2579 // Find device's /dev (or SCSI) entry
2580 switch (bkpinfo->backup_media_type) {
2581 case cdr:
2582 case cdrw:
2583 case dvd:
2584 case usb:
2585 /* Never try to eject a USB device */
2586 if (bkpinfo->backup_media_type == usb) {
2587 bkpinfo->please_dont_eject = TRUE;
2588 }
2589 if (archiving_to_media) {
2590 if ((bkpinfo->backup_media_type != dvd) && (bkpinfo->backup_media_type != usb)) {
2591 if (ask_me_yes_or_no("Is your computer a laptop, or does the CD writer incorporate BurnProof technology?")) {
2592 bkpinfo->manual_cd_tray = TRUE;
2593 }
2594 }
2595 if ((bkpinfo->compression_level = which_compression_level()) == -1) {
2596 log_to_screen("User has chosen not to backup the PC");
2597 finish(1);
2598 }
2599 mds = media_descriptor_string(bkpinfo->backup_media_type);
2600 mr_asprintf(comment, "What speed is your %s (re)writer?", mds);
2601 mr_free(bkpinfo->media_device);
2602 if (bkpinfo->backup_media_type == dvd) {
2603 bkpinfo->media_device = find_dvd_device();
2604 mr_asprintf(tmp, "1");
2605 mr_asprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4482 MB
2606 log_msg(1, "Setting to DVD defaults");
2607 } else {
2608 mr_asprintf(bkpinfo->media_device, "%s", VANILLA_SCSI_CDROM);
2609 mr_asprintf(tmp, "4");
2610 mr_asprintf(sz_size, "%d", 650);
2611 log_msg(1, "Setting to CD defaults");
2612 }
2613 if ((bkpinfo->backup_media_type != dvd) && (bkpinfo->backup_media_type != usb)) {
2614 p = popup_and_get_string("Speed", comment, tmp);
2615 mr_free(tmp);
2616
2617 if (p == NULL) {
2618 log_to_screen("User has chosen not to backup the PC");
2619 mr_free(comment);
2620 finish(1);
2621 }
2622 /* tmp now has the new value given by the user */
2623 tmp = p;
2624 }
2625 mr_free(comment);
2626
2627 bkpinfo->cdrw_speed = atoi(tmp); // if DVD then this shouldn't ever be used anyway :)
2628 mr_free(tmp);
2629
2630 mr_asprintf(comment, "How much data (in Megabytes) will each %s store?", mds);
2631 mr_free(mds);
2632 p = popup_and_get_string("Size", comment, sz_size);
2633 mr_free(sz_size);
2634 mr_free(comment);
2635
2636 if (p == NULL) {
2637 log_to_screen("User has chosen not to backup the PC");
2638 finish(1);
2639 }
2640 sz_size = p;
2641
2642 for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
2643 bkpinfo->media_size[i] = atoi(sz_size);
2644 }
2645
2646 if (bkpinfo->media_size[0] <= 0) {
2647 log_to_screen("User has chosen not to backup the PC");
2648 finish(1);
2649 }
2650 }
2651 /* No break because we continue even for usb */
2652 case cdstream:
2653 mds = media_descriptor_string(bkpinfo->backup_media_type);
2654
2655 mr_free(bkpinfo->media_device);
2656 if ((bkpinfo->disaster_recovery) && (bkpinfo->backup_media_type != usb)) {
2657 mr_asprintf(bkpinfo->media_device, "/dev/cdrom");
2658 log_msg(2, "CD-ROM device assumed to be at %s", bkpinfo->media_device);
2659 } else if ((bkpinfo->restore_data && (bkpinfo->backup_media_type != usb)) || bkpinfo->backup_media_type == dvd) {
2660 if ((bkpinfo->backup_media_type == dvd) || ((bkpinfo->media_device = find_cdrom_device(FALSE)) != NULL)) {
2661 mr_asprintf(comment, "Please specify your %s drive's /dev entry", mds);
2662 p = popup_and_get_string("Device?", comment, bkpinfo->media_device);
2663 mr_free(comment);
2664
2665 if (p == NULL) {
2666 log_to_screen("User has chosen not to backup the PC");
2667 finish(1);
2668 }
2669 mr_free(bkpinfo->media_device);
2670 bkpinfo->media_device = p;
2671 }
2672 if (bkpinfo->media_device != NULL) {
2673 log_msg(2, "%s device found at %s", mds, bkpinfo->media_device);
2674 } else {
2675 log_msg(2, "%s device not found (bkpinfo->media_device is NULL)", mds);
2676 }
2677 } else {
2678 if (((bkpinfo->media_device = find_cdrw_device()) != NULL) && (bkpinfo->backup_media_type != usb)) {
2679 mr_free(bkpinfo->media_device);
2680 }
2681 if (bkpinfo->media_device != NULL) {
2682 if (bkpinfo->backup_media_type == usb) {
2683 mr_asprintf(tmp, "I think your %s media corresponds to %s. Is this correct?", mds, bkpinfo->media_device);
2684 } else {
2685 mr_asprintf(tmp, "I think I've found your %s burner at SCSI node %s. Is this correct? (Say no if you have an IDE burner and you are running a 2.6 kernel. You will then be prompted for further details.)", mds, bkpinfo->media_device);
2686 }
2687 if (!ask_me_yes_or_no(tmp)) {
2688 mr_free(bkpinfo->media_device);
2689 }
2690 mr_free(tmp);
2691 }
2692 if (!bkpinfo->media_device) {
2693 if (bkpinfo->backup_media_type == usb) {
2694 p = popup_and_get_string("/dev entry?", "What is the /dev entry of your USB Disk/Key, please?", NULL);
2695 } else {
2696 if (g_kernel_version < 2.6) {
2697 p = popup_and_get_string("Device node?", "What is the SCSI node of your CD (re)writer, please?", NULL);
2698 } else {
2699 p = popup_and_get_string("/dev entry?", "What is the /dev entry of your CD (re)writer, please?", NULL);
2700 }
2701 }
2702 if (p == NULL) {
2703 log_to_screen("User has chosen not to backup the PC");
2704 finish(1);
2705 }
2706 bkpinfo->media_device = p;
2707 }
2708 }
2709 mr_free(mds);
2710
2711 if (bkpinfo->backup_media_type == cdstream) {
2712 for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
2713 bkpinfo->media_size[i] = 650;
2714 }
2715 }
2716 break;
2717 case udev:
2718 if (!ask_me_yes_or_no
2719 ("This option is for advanced users only. Are you sure?")) {
2720 log_to_screen("User has chosen not to backup the PC");
2721 finish(1);
2722 }
2723 case tape:
2724
2725 mr_free(bkpinfo->media_device);
2726 if ((!bkpinfo->restore_mode) && ((bkpinfo->media_device = mr_find_tape_device()) == NULL)) {
2727 log_msg(3, "Ok, using vanilla scsi tape.");
2728 mr_asprintf(bkpinfo->media_device, "%s", VANILLA_SCSI_TAPE);
2729 if ((fin = fopen(bkpinfo->media_device, "r"))) {
2730 paranoid_fclose(fin);
2731 } else {
2732 mr_free(bkpinfo->media_device);
2733 mr_asprintf(bkpinfo->media_device, "/dev/osst0");
2734 }
2735 }
2736 if (bkpinfo->media_device != NULL) {
2737 if ((fin = fopen(bkpinfo->media_device, "r"))) {
2738 paranoid_fclose(fin);
2739 } else {
2740 if (does_file_exist(MINDI_CACHE"/mondorestore.cfg")) {
2741 mr_free(bkpinfo->media_device);
2742 bkpinfo->media_device = read_cfg_var(MINDI_CACHE"/mondorestore.cfg", "media-dev");
2743 }
2744 }
2745 }
2746 if (bkpinfo->media_device != NULL) {
2747 mr_asprintf(tmp, "I think I've found your tape streamer at %s; am I right on the money?", bkpinfo->media_device);
2748 if (!ask_me_yes_or_no(tmp)) {
2749 mr_free(bkpinfo->media_device);
2750 }
2751 mr_free(tmp);
2752 }
2753 if (bkpinfo->media_device == NULL) {
2754 p = popup_and_get_string("Device name?", "What is the /dev entry of your tape streamer?", bkpinfo->media_device);
2755 if (p == NULL) {
2756 log_to_screen("User has chosen not to backup the PC");
2757 finish(1);
2758 }
2759 bkpinfo->media_device = p;
2760 }
2761 mr_asprintf(tmp, "ls -l %s", bkpinfo->media_device);
2762 if (run_program_and_log_output(tmp, FALSE)) {
2763 log_to_screen("User has not specified a valid /dev entry");
2764 finish(1);
2765 }
2766 mr_free(tmp);
2767
2768 bkpinfo->use_obdr = ask_me_yes_or_no("Do you want to activate OBDR support for your tapes ?");
2769 bkpinfo->media_size[0] = 0;
2770 log_msg(4, "media_size[0] = %ld", bkpinfo->media_size[0]);
2771 if (bkpinfo->media_size[0] <= 0) {
2772 bkpinfo->media_size[0] = 0;
2773 }
2774 for (i = 1; i <= MAX_NOOF_MEDIA; i++) {
2775 bkpinfo->media_size[i] = bkpinfo->media_size[0];
2776 }
2777 if (archiving_to_media) {
2778 if ((bkpinfo->compression_level =
2779 which_compression_level()) == -1) {
2780 log_to_screen("User has chosen not to backup the PC");
2781 finish(1);
2782 }
2783 }
2784 break;
2785
2786
2787
2788 case netfs:
2789 /* Never try to eject a NETFS device */
2790 bkpinfo->please_dont_eject = TRUE;
2791
2792 /* Initiate bkpinfo netfs_mount path from running environment if not already done */
2793 if (bkpinfo->netfs_mount == NULL) {
2794 bkpinfo->netfs_mount = call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f1 | head -n1");
2795 }
2796#ifdef __FreeBSD__
2797 if (TRUE)
2798#else
2799 if (!bkpinfo->disaster_recovery)
2800#endif
2801 {
2802 p = popup_and_get_string("Network shared dir.", "Please enter path and directory where archives are stored remotely. (Mondo has taken a guess at the correct value. If it is incorrect, delete it and type the correct one.)", bkpinfo->netfs_mount);
2803 if (p == NULL) {
2804 log_to_screen("User has chosen not to backup the PC");
2805 finish(1);
2806 }
2807 mr_free(bkpinfo->netfs_mount);
2808 bkpinfo->netfs_mount = p;
2809 if (!bkpinfo->restore_data) {
2810 if ((bkpinfo->compression_level =
2811 which_compression_level()) == -1) {
2812 log_to_screen("User has chosen not to backup the PC");
2813 finish(1);
2814 }
2815 }
2816 // check whether already mounted - we better remove
2817 // surrounding spaces and trailing '/' for this
2818 mr_strip_spaces(bkpinfo->netfs_mount);
2819 if (bkpinfo->netfs_mount[strlen(bkpinfo->netfs_mount) - 1] == '/')
2820 bkpinfo->netfs_mount[strlen(bkpinfo->netfs_mount) - 1] = '\0';
2821 mr_asprintf(command, "mount | grep \"%s \" | cut -d' ' -f3", bkpinfo->netfs_mount);
2822 mr_free(bkpinfo->isodir);
2823 bkpinfo->isodir = call_program_and_get_last_line_of_output(command);
2824 mr_free(command);
2825
2826 if (!bkpinfo->restore_data) {
2827 mr_asprintf(comment, "How much data (in Megabytes) will each media store?");
2828 mr_asprintf(tmp, "%d", DEFAULT_DVD_DISK_SIZE);
2829 sz_size = popup_and_get_string("Size", comment, tmp);
2830 mr_free(comment);
2831 mr_free(tmp);
2832 if (sz_size == NULL) {
2833 log_to_screen("User has chosen not to backup the PC");
2834 finish(1);
2835 }
2836 } else {
2837 mr_asprintf(sz_size, "0");
2838 }
2839 for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
2840 bkpinfo->media_size[i] = atoi(sz_size);
2841 }
2842 mr_free(sz_size);
2843 if (bkpinfo->media_size[0] < 0) {
2844 log_to_screen("User has chosen not to backup the PC");
2845 finish(1);
2846 }
2847 }
2848 if (bkpinfo->disaster_recovery) {
2849 mr_asprintf(command ,"umount %s/isodir 2> /dev/null", bkpinfo->tmpdir);
2850 (void)system(command);
2851 mr_free(command);
2852
2853 p = popup_and_get_string("Network protocol", "Which Network protocol should I use?", bkpinfo->netfs_proto);
2854 if (p == NULL) {
2855 log_to_screen("User has chosen not to backup the PC");
2856 finish(1);
2857 }
2858 mr_free(bkpinfo->netfs_proto);
2859 bkpinfo->netfs_proto = p;
2860
2861 p = popup_and_get_string("Network share", "Which remote Network share should I mount?", bkpinfo->netfs_mount);
2862 if (p == NULL) {
2863 log_to_screen("User has chosen not to backup the PC");
2864 finish(1);
2865 }
2866 mr_free(bkpinfo->netfs_mount);
2867 bkpinfo->netfs_mount = p;
2868 }
2869 /* Initiate bkpinfo isodir path from running environment if mount already done */
2870 mr_free(bkpinfo->isodir);
2871 if (is_this_device_mounted(bkpinfo->netfs_mount)) {
2872 bkpinfo->isodir = call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f3 | head -n1");
2873
2874 } else {
2875 mr_asprintf(bkpinfo->isodir, "%s/netfsdir", bkpinfo->tmpdir);
2876 mr_asprintf(command, "mkdir -p %s", bkpinfo->isodir);
2877 run_program_and_log_output(command, 5);
2878 mr_free(command);
2879
2880 if (bkpinfo->restore_data) {
2881 if (strstr(bkpinfo->netfs_proto, "sshfs")) {
2882 mr_asprintf(tmp, "sshfs -o ro %s %s", bkpinfo->netfs_mount, bkpinfo->isodir);
2883 } else {
2884 mr_asprintf(tmp, "mount -t %s -o nolock,ro %s %s", bkpinfo->netfs_proto, bkpinfo->netfs_mount, bkpinfo->isodir);
2885 }
2886 } else {
2887 if (strstr(bkpinfo->netfs_proto, "sshfs")) {
2888 mr_asprintf(tmp, "sshfs %s %s", bkpinfo->netfs_mount, bkpinfo->isodir);
2889 } else {
2890 mr_asprintf(tmp, "mount -t %s -o nolock %s %s", bkpinfo->netfs_proto, bkpinfo->netfs_mount, bkpinfo->isodir);
2891 }
2892 }
2893 run_program_and_log_output(tmp, 3);
2894 mr_free(tmp);
2895
2896 malloc_string(g_selfmounted_isodir);
2897 strcpy(g_selfmounted_isodir, bkpinfo->isodir);
2898 }
2899 if (!is_this_device_mounted(bkpinfo->netfs_mount)) {
2900 popup_and_OK("Please mount that partition before you try to backup to or restore from it.");
2901 finish(1);
2902 }
2903 p = popup_and_get_string("Directory", "Which directory within that mountpoint?", bkpinfo->netfs_remote_dir);
2904 if (p == NULL) {
2905 log_to_screen("User has chosen not to backup the PC");
2906 finish(1);
2907 }
2908 mr_free(bkpinfo->netfs_remote_dir);
2909 bkpinfo->netfs_remote_dir = p;
2910
2911 // check whether writable - we better remove surrounding spaces for this
2912 mr_strip_spaces(bkpinfo->netfs_remote_dir);
2913
2914 p = popup_and_get_string("Prefix.", "Please enter the prefix that will be prepended to your ISO filename. Example: machine1 to obtain machine1-[1-9]*.iso files", bkpinfo->prefix);
2915 if (p == NULL) {
2916 log_to_screen("User has chosen not to backup the PC");
2917 finish(1);
2918 }
2919 mr_free(bkpinfo->prefix);
2920 bkpinfo->prefix = p;
2921 log_msg(3, "prefix set to %s", bkpinfo->prefix);
2922
2923 log_msg(3, "Just set netfs_remote_dir to %s", bkpinfo->netfs_remote_dir);
2924 log_msg(3, "isodir is still %s", bkpinfo->isodir);
2925 break;
2926
2927 case iso:
2928 if (!bkpinfo->disaster_recovery) {
2929 p = popup_and_get_string("Storage dir.", "Please enter the full path name to the directory for your ISO images. Example: /mnt/raid0_0", bkpinfo->isodir);
2930 if (p == NULL) {
2931 log_to_screen("User has chosen not to backup the PC");
2932 finish(1);
2933 }
2934 bkpinfo->isodir = p;
2935
2936 if (archiving_to_media) {
2937 if ((bkpinfo->compression_level =
2938 which_compression_level()) == -1) {
2939 log_to_screen("User has chosen not to backup the PC");
2940 finish(1);
2941 }
2942 mr_asprintf(tmp, "%d", DEFAULT_DVD_DISK_SIZE);
2943 p = popup_and_get_string("ISO size.", "Please enter how big you want each ISO image to be (in megabytes). This should be less than or equal to the size of the CD-R[W]'s (700) or DVD's (4480) you plan to backup to.", tmp);
2944 mr_free(tmp);
2945 if (p == NULL) {
2946 log_to_screen("User has chosen not to backup the PC");
2947 finish(1);
2948 }
2949 for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
2950 bkpinfo->media_size[i] = atoi(p);
2951 }
2952 mr_free(p);
2953 } else {
2954 for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
2955 bkpinfo->media_size[i] = 650;
2956 }
2957 }
2958 }
2959 p = popup_and_get_string("Prefix.", "Please enter the prefix that will be prepended to your ISO filename. Example: machine1 to obtain machine1-[1-9]*.iso files", bkpinfo->prefix);
2960 if (p == NULL) {
2961 log_to_screen("User has chosen not to backup the PC");
2962 finish(1);
2963 }
2964 mr_free(bkpinfo->prefix);
2965 bkpinfo->prefix = p;
2966 log_msg(3, "prefix set to %s", bkpinfo->prefix);
2967 break;
2968
2969 default:
2970 fatal_error
2971 ("I, Mojo Jojo, shall defeat those pesky Powerpuff Girls!");
2972 }
2973
2974 if (archiving_to_media) {
2975
2976 mr_free(bkpinfo->boot_device);
2977#ifdef __FreeBSD__
2978#define EXAMPLEBD "/dev/ad0"
2979 bkpinfo->boot_device = call_program_and_get_last_line_of_output("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'");
2980#else
2981#define EXAMPLEBD "/dev/hda"
2982 bkpinfo->boot_device = call_program_and_get_last_line_of_output("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'");
2983#endif
2984 i = which_boot_loader(bkpinfo->boot_device);
2985 if (i == 'U') // unknown
2986 {
2987
2988 p = popup_and_get_string("Boot device", "What is your boot device? (e.g. "EXAMPLEBD")", bkpinfo->boot_device);
2989#undef EXAMPLEBD
2990 if (p == NULL) {
2991 log_to_screen("User has chosen not to backup the PC");
2992 finish(1);
2993 }
2994 mr_free(bkpinfo->boot_device);
2995 bkpinfo->boot_device = p;
2996#ifdef __FreeBSD__
2997 i = which_boot_loader(bkpinfo->boot_device);
2998#else
2999 if (does_string_exist_in_boot_block(bkpinfo->boot_device, "LILO")) {
3000 i = 'L';
3001 } else
3002 if (does_string_exist_in_boot_block(bkpinfo->boot_device, "ELILO")) {
3003 i = 'E';
3004 } else
3005 if (does_string_exist_in_boot_block(bkpinfo->boot_device, "GRUB")) {
3006 i = 'G';
3007 } else {
3008 i = 'U';
3009 }
3010#endif
3011 if (i == 'U') {
3012 if (ask_me_yes_or_no("Unidentified boot loader. Shall I restore it byte-for-byte at restore time and hope for the best?")) {
3013 i = 'R'; // raw
3014 } else {
3015 log_to_screen("I cannot find your boot loader. Please run mondoarchive with parameters.");
3016 finish(1);
3017 }
3018 }
3019 }
3020 bkpinfo->boot_loader = i;
3021 mr_free(bkpinfo->include_paths);
3022 mr_asprintf(p, "/");
3023 bkpinfo->include_paths = p;
3024
3025 p = popup_and_get_string("Backup paths", "Please enter paths which you want me to backup. The default is '/' (i.e. everything).", bkpinfo->include_paths);
3026 if (p == NULL) {
3027 log_to_screen("User has chosen not to backup the PC");
3028 finish(1);
3029 }
3030 mr_free(bkpinfo->include_paths);
3031 bkpinfo->include_paths = p;
3032
3033 mr_asprintf(tmp, "%s", list_of_NETFS_mounts_only());
3034 if (strlen(tmp) > 2) {
3035 mr_strcat(bkpinfo->exclude_paths, " %s",tmp);
3036 }
3037 mr_free(tmp);
3038// NTFS
3039 tmp = call_program_and_get_last_line_of_output("parted2fdisk -l | grep -i ntfs | awk '{ print $1};' | tr -s '\\n' ' ' | awk '{ print $0};'");
3040 if (strlen(tmp) > 2) {
3041 p = popup_and_get_string("NTFS partitions", "Please enter/confirm the NTFS partitions you wish to backup as well.", tmp);
3042
3043 if (p == NULL) {
3044 log_to_screen("User has chosen not to backup the PC");
3045 finish(1);
3046 }
3047 mr_free(bkpinfo->image_devs);
3048 bkpinfo->image_devs = p;
3049 }
3050
3051
3052 p = popup_and_get_string("Exclude paths", "Please enter paths which you do NOT want to backup. Separate them with spaces. NB: /tmp and /proc are always excluded. :-) Just hit 'Enter' if you want to do a full system backup.", bkpinfo->exclude_paths);
3053 if (p == NULL) {
3054 log_to_screen("User has chosen not to backup the PC");
3055 finish(1);
3056 }
3057 mr_free(bkpinfo->exclude_paths);
3058 bkpinfo->exclude_paths = p;
3059 /* Always needs to be finished by a space */
3060 mr_strcat(bkpinfo->exclude_paths, " ");
3061
3062 p = popup_and_get_string("Temporary directory", "Please enter your temporary directory.", bkpinfo->tmpdir);
3063 if (p == NULL) {
3064 log_to_screen("User has chosen not to backup the PC");
3065 finish(1);
3066 }
3067 mr_free(bkpinfo->tmpdir);
3068 bkpinfo->tmpdir = p;
3069
3070 p = popup_and_get_string("Scratch directory", "Please enter your scratch directory.", bkpinfo->scratchdir);
3071 if (p == NULL) {
3072 log_to_screen("User has chosen not to backup the PC");
3073 finish(1);
3074 }
3075 mr_free(bkpinfo->scratchdir);
3076 bkpinfo->scratchdir = p;
3077
3078// Interactive mode:
3079#ifdef __IA64__
3080 bkpinfo->make_cd_use_lilo = TRUE;
3081#else
3082 bkpinfo->make_cd_use_lilo = FALSE;
3083#endif
3084 bkpinfo->backup_data = TRUE;
3085 bkpinfo->verify_data =
3086 ask_me_yes_or_no
3087 ("Will you want to verify your backups after Mondo has created them?");
3088
3089 if (!ask_me_yes_or_no
3090 ("Are you sure you want to proceed? Hit 'no' to abort.")) {
3091 log_to_screen("User has chosen not to backup the PC");
3092 finish(1);
3093 }
3094 } else {
3095 bkpinfo->restore_data = TRUE; // probably...
3096 }
3097
3098 if (bkpinfo->backup_media_type == iso
3099 || bkpinfo->backup_media_type == netfs) {
3100 g_ISO_restore_mode = TRUE;
3101 }
3102#ifdef __FreeSD__
3103// skip
3104#else
3105 if (bkpinfo->backup_media_type == netfs) {
3106 log_msg(3, "I think the Remote mount is mounted at %s", bkpinfo->isodir);
3107 }
3108 log_it("isodir = %s", bkpinfo->isodir);
3109 if (bkpinfo->netfs_mount) {
3110 log_it("netfs_mount = '%s'", bkpinfo->netfs_mount);
3111 }
3112 if (bkpinfo->netfs_user) {
3113 log_it("netfs_user = '%s'", bkpinfo->netfs_user);
3114 }
3115 if (bkpinfo->netfs_proto) {
3116 log_it("netfs_proto = '%s'", bkpinfo->netfs_proto);
3117 }
3118#endif
3119
3120 log_it("media device = %s", bkpinfo->media_device);
3121 log_it("media size = %ld", bkpinfo->media_size[1]);
3122 tmp = bkptype_to_string(bkpinfo->backup_media_type);
3123 log_it("media type = %s", tmp);
3124 mr_free(tmp);
3125
3126 if (bkpinfo->prefix) {
3127 log_it("prefix = %s", bkpinfo->prefix);
3128 }
3129 log_it("compression = %ld", bkpinfo->compression_level);
3130 log_it("exclude_path = %s", bkpinfo->exclude_paths);
3131 log_it("include_path = %s", bkpinfo->include_paths);
3132
3133 /* Handle devices passed in bkpinfo and print result */
3134 /* the mr_make_devlist_from_pathlist function appends
3135 * to the *_paths variables so copy before */
3136 mr_asprintf(tmp, "%s ", bkpinfo->exclude_paths);
3137 mr_make_devlist_from_pathlist(tmp, 'E');
3138 mr_free(tmp);
3139 mr_asprintf(tmp, "%s ", bkpinfo->include_paths);
3140 mr_make_devlist_from_pathlist(tmp, 'I');
3141 mr_free(tmp);
3142
3143 log_it("scratchdir = '%s'", bkpinfo->scratchdir);
3144 log_it("tmpdir = '%s'", bkpinfo->tmpdir);
3145 if (bkpinfo->image_devs) {
3146 log_it("image_devs = '%s'", bkpinfo->image_devs);
3147 }
3148 log_it("boot_device = '%s' (loader=%c)", bkpinfo->boot_device, bkpinfo->boot_loader);
3149 if (bkpinfo->media_size[0] < 0) {
3150 if (archiving_to_media) {
3151 fatal_error("Media size is less than zero.");
3152 } else {
3153 log_msg(2, "Warning - media size is less than zero.");
3154 bkpinfo->media_size[0] = 0;
3155 }
3156 }
3157 paranoid_free(sz_size);
3158 return (0);
3159}
3160
3161
3162
3163
3164/* @} - end of deviceGroup */
Note: See TracBrowser for help on using the repository browser.