source: MondoRescue/branches/3.2/mondo/src/common/libmondo-devices.c@ 3610

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