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

Last change on this file since 3432 was 3432, checked in by Bruno Cornec, 9 years ago
  • Change analyze-my-lvm in order to generate percentage of Extents of a VG to use to create the LV instead of a fixed size. Should improve bugs when creating LVM on a disk of different size greatly.
  • Property svn:keywords set to Id
File size: 98.3 KB
RevLine 
[1]1/* libmondo-devices.c Subroutines for handling devices
[85]2 $Id: libmondo-devices.c 3432 2015-08-28 00:34:47Z 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 3432 2015-08-28 00:34:47Z 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
[3185]137 mr_asprintf(tmp, "%s", 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);
[3185]546 mr_asprintf(tmp, "%s", 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);
[128]552 return 1;
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) {
[3191]756 sprintf(tmp, "grep \"%s=ide-scsi\" /proc/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);
[3185]849 mr_asprintf(tmp1, "%s", 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
[3191]885 mr_asprintf(tmp, "%s", 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);
[3194]889 mr_asprintf(tmp, "%s", 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
[128]1070 /*@ pointers **************************************************** */
1071 FILE *fin;
[1]1072
[128]1073 /*@ buffers ***************************************************** */
[3191]1074 char *incoming = NULL;
[2214]1075 char *device_with_tab = NULL;
1076 char *device_with_space = NULL;
1077 char *tmp = NULL;
1078 bool retval = FALSE;
[128]1079
[1]1080#ifdef __FreeBSD__
[128]1081#define SWAPLIST_COMMAND "swapinfo"
[1]1082#else
[128]1083#define SWAPLIST_COMMAND "cat /proc/swaps"
[1]1084#endif
1085
[128]1086 /*@ end vars **************************************************** */
[1]1087
[3191]1088 if (device_raw == NULL) {
1089 return(FALSE);
1090 }
1091
[128]1092 if (device_raw[0] != '/' && !strstr(device_raw, ":/")) {
[3432]1093 log_msg(1, "%s needs to have a '/' prefixed - I'll do it", device_raw);
[3185]1094 mr_asprintf(tmp, "/%s", device_raw);
[128]1095 } else {
[3185]1096 mr_asprintf(tmp, "%s", device_raw);
[128]1097 }
1098 log_msg(1, "Is %s mounted?", tmp);
1099 if (!strcmp(tmp, "/proc") || !strcmp(tmp, "proc")) {
[3432]1100 log_msg(1, "I don't know how the heck /proc made it into the mountlist. I'll ignore it.");
[2214]1101 mr_free(tmp);
1102 return(FALSE);
[128]1103 }
[3185]1104 mr_asprintf(device_with_tab, "%s\t", tmp);
1105 mr_asprintf(device_with_space, "%s ", tmp);
[2214]1106 mr_free(tmp);
[1]1107
[128]1108 if (!(fin = popen("mount", "r"))) {
1109 log_OS_error("Cannot popen 'mount'");
[2214]1110 return(FALSE);
[1]1111 }
[3191]1112
1113 for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) {
1114 if (strstr(incoming, device_with_space) || strstr(incoming, device_with_tab)) {
[128]1115 paranoid_pclose(fin);
[3191]1116 mr_free(incoming);
[2214]1117 return(TRUE);
[128]1118 }
[3191]1119 mr_free(incoming);
[128]1120 }
[3191]1121 mr_free(incoming);
[2214]1122 mr_free(device_with_tab);
[128]1123 paranoid_pclose(fin);
[3432]1124
[3185]1125 mr_asprintf(tmp, "%s | grep -E \"^%s\" > /dev/null 2> /dev/null", SWAPLIST_COMMAND, device_with_space);
[2423]1126 mr_free(device_with_space);
[128]1127 log_msg(4, "tmp (command) = '%s'", tmp);
1128 if (!system(tmp)) {
[2214]1129 retval = TRUE;
[128]1130 }
[2214]1131 mr_free(tmp);
1132 return(retval);
[1]1133}
1134
1135#ifdef __FreeBSD__
1136// CODE IS FREEBSD-SPECIFIC
1137/**
1138 * Create a loopback device for specified @p fname.
1139 * @param fname The file to associate with a device.
1140 * @return /dev entry for the device, or NULL if it couldn't be allocated.
1141 */
[128]1142char *make_vn(char *fname)
[1]1143{
[128]1144 char *device = (char *) malloc(MAX_STR_LEN);
1145 char *mddevice = (char *) malloc(32);
1146 char command[MAX_STR_LEN];
1147 int vndev = 2;
[3191]1148 if (atoi(call_program_and_get_last_line_of_output("/sbin/sysctl -n kern.osreldate")) < 500000) {
[128]1149 do {
1150 sprintf(mddevice, "vn%ic", vndev++);
1151 sprintf(command, "vnconfig %s %s", mddevice, fname);
1152 if (vndev > 10) {
1153 return NULL;
1154 }
1155 }
1156 while (system(command));
1157 } else {
1158 sprintf(command, "mdconfig -a -t vnode -f %s", fname);
1159 mddevice = call_program_and_get_last_line_of_output(command);
1160 if (!strstr(mddevice, "md")) {
1161 return NULL;
1162 }
1163 }
1164 sprintf(device, "/dev/%s", mddevice);
1165 return device;
[1]1166}
1167
1168
1169
1170// CODE IS FREEBSD-SPECIFIC
1171/**
1172 * Deallocate specified @p dname.
1173 * This should be called when you are done with the device created by make_vn(),
1174 * so the system does not run out of @c vn devices.
1175 * @param dname The device to deallocate.
1176 * @return 0 for success, nonzero for failure.
1177 */
[128]1178int kick_vn(char *dname)
[1]1179{
[3191]1180 char *command = NULL;
1181 int res = 0;
[1]1182
[128]1183 if (strncmp(dname, "/dev/", 5) == 0) {
1184 dname += 5;
1185 }
[1]1186
[3191]1187 if (atoi(call_program_and_get_last_line_of_output("/sbin/sysctl -n kern.osreldate")) < 500000) {
1188 mr_asprintf(command, "vnconfig -d %s", dname);
[128]1189 } else {
[3191]1190 mr_asprintf(command, "mdconfig -d -u %s", dname);
[128]1191 }
[3191]1192 res = system(command);
1193 mr_free(command);
1194 return(res);
[1]1195}
1196#endif
1197
1198
1199/**
1200 * Mount the CD-ROM at @p mountpoint.
1201 * @param device The device (or file if g_ISO_restore_mode) to mount.
1202 * @param mountpoint The place to mount it.
1203 * @return 0 for success, nonzero for failure.
1204 */
[1741]1205int mount_USB_here(char *device, char *mountpoint)
1206{
1207 /*@ buffer ****************************************************** */
[3191]1208 char *command = NULL;
[1741]1209 int retval;
1210
1211 assert_string_is_neither_NULL_nor_zerolength(device);
1212 assert_string_is_neither_NULL_nor_zerolength(mountpoint);
1213
1214 make_hole_for_dir(mountpoint);
1215 if (isdigit(device[0])) {
1216 return(1);
1217 }
[3191]1218 log_msg(4, "(mount_USB_here --- device=%s, mountpoint=%s", device, mountpoint);
[1741]1219
1220#ifdef __FreeBSD__
[3191]1221 mr_asprintf(command, "mount_vfat %s %s 2>> %s", device, mountpoint, MONDO_LOGFILE);
[1741]1222
1223#else
[3191]1224 mr_asprintf(command, "mount %s -t vfat %s 2>> %s", device, mountpoint, MONDO_LOGFILE);
[1741]1225#endif
1226
1227 log_msg(4, command);
1228 retval = system(command);
1229 log_msg(1, "system(%s) returned %d", command, retval);
[3191]1230 mr_free(command);
[1741]1231
1232 return (retval);
1233}
1234
1235/**
1236 * Mount the CD-ROM at @p mountpoint.
1237 * @param device The device (or file if g_ISO_restore_mode) to mount.
1238 * @param mountpoint The place to mount it.
1239 * @return 0 for success, nonzero for failure.
1240 */
[3191]1241int mount_CDROM_here(char *device, const char *mountpoint)
[1]1242{
[128]1243 /*@ buffer ****************************************************** */
[2211]1244 char *command = NULL;
[128]1245 int retval;
[2257]1246#ifdef __FreeBSD__
1247 char *dev = NULL;
1248#else
1249 char *options = NULL;
1250#endif
[1]1251
[128]1252 assert_string_is_neither_NULL_nor_zerolength(device);
1253 assert_string_is_neither_NULL_nor_zerolength(mountpoint);
[1]1254
[128]1255 make_hole_for_dir(mountpoint);
[2211]1256
[2257]1257 if (isdigit(device[0])) {
1258 find_cdrom_device(device, FALSE);
1259 }
1260#ifndef __FreeBSD__
[3185]1261 mr_asprintf(options, "ro");
[2211]1262#endif
1263
[128]1264 if (g_ISO_restore_mode) {
[1]1265
1266#ifdef __FreeBSD__
[3185]1267 mr_asprintf(dev, "%s", make_vn(device));
[128]1268 if (!dev) {
[3185]1269 mr_asprintf(command, "Unable to mount ISO (make_vn(%s) failed)", device);
[128]1270 fatal_error(command);
1271 }
1272 strcpy(device, dev);
[2211]1273 paranoid_free(dev);
[1]1274#else
[2211]1275 mr_strcat(options, ",loop");
[1]1276#endif
1277
[128]1278 }
[3191]1279 log_msg(4, "(mount_CDROM_here --- device=%s, mountpoint=%s", device, mountpoint);
[128]1280 /*@ end vars *************************************************** */
[1]1281
1282#ifdef __FreeBSD__
[3185]1283 mr_asprintf(command, "mount_cd9660 -r %s %s 2>> %s", device, mountpoint, MONDO_LOGFILE);
[1]1284
1285#else
[3185]1286 mr_asprintf(command, "mount %s -o %s -t iso9660 %s 2>> %s", device, options, mountpoint, MONDO_LOGFILE);
[2211]1287 paranoid_free(options);
[1]1288#endif
1289
[128]1290 log_msg(4, command);
1291 if (strncmp(device, "/dev/", 5) == 0) {
1292 retract_CD_tray_and_defeat_autorun();
1293 }
1294 retval = system(command);
1295 log_msg(1, "system(%s) returned %d", command, retval);
[3191]1296 mr_free(command);
[1]1297
[128]1298 return (retval);
[1]1299}
1300
1301
[2682]1302/**
1303* Mount the CD-ROM or USB device at /mnt/cdrom.
1304* @param bkpinfo The backup information structure. Fields used:
1305* - @c bkpinfo->backup_media_type
1306* - @c bkpinfo->disaster_recovery
1307* - @c bkpinfo->isodir
1308* - @c bkpinfo->media_device
1309* @return 0 for success, nonzero for failure.
1310*/
1311int mount_media()
1312{
[3191]1313char *mount_cmd = NULL;
[2769]1314char *mountdir = NULL;
[2682]1315int i, res;
1316#ifdef __FreeBSD__
[3191]1317 char mdd[32];
1318 char *mddev = mdd;
[2682]1319#endif
[1]1320
[3191]1321 if (bkpinfo->backup_media_type == tape || bkpinfo->backup_media_type == udev) {
[2682]1322 log_msg(8, "Tape/udev. Therefore, no need to mount a media.");
1323 return 0;
1324 }
[1]1325
[2682]1326 if (!run_program_and_log_output("mount | grep -F " MNT_CDROM, FALSE)) {
1327 log_msg(2, "mount_media() - media already mounted. Fair enough.");
1328 return (0);
1329 }
[1]1330
[2682]1331 if (bkpinfo->backup_media_type == netfs) {
1332 log_msg(2, "Mounting for Network thingy");
1333 log_msg(2, "isodir = %s", bkpinfo->isodir);
[3191]1334 if ((!bkpinfo->isodir[0] || !strcmp(bkpinfo->isodir, "/")) && am_I_in_disaster_recovery_mode()) {
[2682]1335 strcpy(bkpinfo->isodir, "/tmp/isodir");
1336 log_msg(1, "isodir is being set to %s", bkpinfo->isodir);
1337 }
1338#ifdef __FreeBSD__
[3207]1339 if (bkpinfo->netfs_remote_dir != NULL) {
[3196]1340 // NETFS
1341 mr_asprintf(mount_cmd, "/mnt/isodir/%s/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->netfs_remote_dir, bkpinfo->prefix, g_current_media_number);
1342 } else {
1343 // ISO
1344 mr_asprintf(mount_cmd, "/mnt/isodir/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->prefix, g_current_media_number);
1345 }
[2682]1346 mddev = make_vn(mount_cmd);
[3191]1347 mr_free(mount_cmd);
1348
1349 mr_asprintf(mount_cmd, "mount_cd9660 -r %s " MNT_CDROM, mddev);
[2682]1350#else
[3207]1351 if (bkpinfo->netfs_remote_dir != NULL) {
[3196]1352 // NETFS
1353 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);
1354 } else {
1355 // ISO
1356 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);
1357 }
[2682]1358#endif
1359
1360 } else if (bkpinfo->backup_media_type == iso) {
[2769]1361 if (bkpinfo->subdir) {
[3185]1362 mr_asprintf(mountdir, "%s/%s", bkpinfo->isodir, bkpinfo->subdir);
[2769]1363 } else {
[3185]1364 mr_asprintf(mountdir, "%s", bkpinfo->isodir);
[2769]1365 }
[2682]1366#ifdef __FreeBSD__
[3191]1367 mr_asprintf(mount_cmd, "%s/%s-%d.iso", mountdir, bkpinfo->prefix, g_current_media_number);
[2682]1368 mddev = make_vn(mount_cmd);
[3191]1369 mr_free(mount_cmd);
1370
1371 mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM);
[2682]1372#else
[3191]1373 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]1374#endif
[2774]1375 mr_free(mountdir);
[2682]1376 } else if (bkpinfo->backup_media_type == usb) {
[3191]1377 mr_asprintf(mount_cmd, "mount -t vfat %s %s", bkpinfo->media_device, MNT_CDROM);
[2682]1378 } else if (strstr(bkpinfo->media_device, "/dev/")) {
1379#ifdef __FreeBSD__
[3191]1380 mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, MNT_CDROM);
[2682]1381#else
[3191]1382 mr_asprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", bkpinfo->media_device, MNT_CDROM);
[2682]1383#endif
1384 } else {
1385 if (bkpinfo->disaster_recovery
1386 && does_file_exist("/tmp/CDROM-LIVES-HERE")) {
1387 strcpy(bkpinfo->media_device,
1388 last_line_of_file("/tmp/CDROM-LIVES-HERE"));
1389 } else {
1390 find_cdrom_device(bkpinfo->media_device, TRUE);
1391 }
1392
1393#ifdef __FreeBSD__
[3191]1394 mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, MNT_CDROM);
[2682]1395#else
[3191]1396 mr_asprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", bkpinfo->media_device, MNT_CDROM);
[2682]1397#endif
1398 }
1399
1400 log_msg(2, "(mount_media) --- command = %s", mount_cmd);
1401 for (i = 0; i < 2; i++) {
1402 res = run_program_and_log_output(mount_cmd, FALSE);
1403 if (!res) {
1404 break;
1405 } else {
1406 log_msg(2, "Failed to mount device.");
1407 sleep(5);
[3191]1408 sync();
[2682]1409 }
1410 }
[3191]1411 mr_free(mount_cmd);
[2682]1412
1413 if (res) {
1414 log_msg(2, "Failed, despite %d attempts", i);
1415 } else {
1416 log_msg(2, "Mounted media drive OK");
1417 }
1418 return (res);
1419}
1420/**************************************************************************
1421*END_MOUNT_CDROM *
1422**************************************************************************/
1423
1424
1425
1426
[1]1427/**
1428 * Ask the user for CD number @p cd_number_i_want.
1429 * Sets g_current_media_number once the correct CD is inserted.
1430 * @param bkpinfo The backup information structure. Fields used:
1431 * - @c bkpinfo->backup_media_type
[20]1432 * - @c bkpinfo->prefix
[1]1433 * - @c bkpinfo->isodir
1434 * - @c bkpinfo->media_device
1435 * - @c bkpinfo->please_dont_eject_when_restoring
1436 * @param cd_number_i_want The CD number to ask for.
1437 */
1438void
[1645]1439insist_on_this_cd_number(int cd_number_i_want)
[1]1440{
1441
[128]1442 /*@ int ************************************************************* */
1443 int res = 0;
[1]1444
1445
[128]1446 /*@ buffers ********************************************************* */
[3191]1447 char *tmp = NULL;
[2242]1448 char *mds = NULL;
[3191]1449 char *request = NULL;
[1]1450
[128]1451 assert(bkpinfo != NULL);
1452 assert(cd_number_i_want > 0);
[1]1453
1454// log_msg(3, "Insisting on CD number %d", cd_number_i_want);
1455
[128]1456 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
1457 log_msg(3,
1458 "No need to insist_on_this_cd_number when the backup type isn't CD-R(W) or NFS or ISO");
1459 return;
1460 }
[3191]1461 mr_asprintf(tmp, "mkdir -p " MNT_CDROM);
1462 run_program_and_log_output(tmp, 5);
1463 mr_free(tmp);
1464
1465 if (g_ISO_restore_mode || bkpinfo->backup_media_type == iso || bkpinfo->backup_media_type == netfs) {
[2866]1466 g_ISO_restore_mode = TRUE;
1467 }
[1645]1468 if ((res = what_number_cd_is_this()) != cd_number_i_want) {
[3191]1469 log_msg(3, "Currently, we hold %d but we want %d", res, cd_number_i_want);
[2866]1470
1471 /* Now we need to umount the current media to have the next mounted after */
[2878]1472 run_program_and_log_output("umount -d " MNT_CDROM, FALSE);
[2866]1473 log_msg(3, "Mounting next media %d",cd_number_i_want);
1474 g_current_media_number = cd_number_i_want;
1475 mount_media();
1476
[2242]1477 mds = media_descriptor_string(bkpinfo->backup_media_type);
[3191]1478 log_msg(3, "Insisting on %s #%d", mds, cd_number_i_want);
1479 mr_asprintf(request, "Please insert %s #%d and press Enter.", mds, cd_number_i_want);
[2242]1480 mr_free(mds);
[3191]1481
[1645]1482 while (what_number_cd_is_this() != cd_number_i_want) {
[3191]1483 sync();
[128]1484 if (is_this_device_mounted(MNT_CDROM)) {
1485 res =
[2878]1486 run_program_and_log_output("umount -d " MNT_CDROM, FALSE);
[128]1487 } else {
1488 res = 0;
1489 }
1490 if (res) {
[541]1491 log_to_screen("WARNING - failed to unmount CD-ROM drive");
[128]1492 }
1493 if (!bkpinfo->please_dont_eject) {
1494 res = eject_device(bkpinfo->media_device);
1495 } else {
1496 res = 0;
1497 }
1498 if (res) {
[541]1499 log_to_screen("WARNING - failed to eject CD-ROM disk");
[128]1500 }
1501 popup_and_OK(request);
1502 if (!bkpinfo->please_dont_eject) {
1503 inject_device(bkpinfo->media_device);
1504 }
[3191]1505 sync();
[128]1506 }
[3191]1507 mr_free(request);
1508
[128]1509 log_msg(1, "Thankyou. Proceeding...");
1510 g_current_media_number = cd_number_i_want;
1511 }
[1]1512}
1513
1514/* @} - end of deviceGroup */
1515
1516
1517
[2434]1518/**
1519 * Creates a singly linked list of all of the non-NETFS mounted file systems.
1520 * @param DSFptr A pointer to the structure MOUNTED_FS_STRUCT used to hold
1521 * the list of mounted file systems.
1522 * @return None.
1523 */
1524static void add_mounted_fs_struct (MOUNTED_FS_STRUCT *DSFptr)
1525{
1526 assert (DSFptr);
1527 if (DSF_Head == NULL) {
1528 DSF_Head = DSFptr;
1529 } else {
1530 DSF_Tail->next = DSFptr;
1531 }
1532 DSFptr->next = NULL;
1533 DSF_Tail = DSFptr;
1534}
[1]1535
[2434]1536/**
1537 * Find the structure, in the singly linked list of all of the non-NETFS
1538 * mounted file systems, that contains the specified device.
1539 * @param device The device to find
1540 * @return NULL if it didn't find the device, a pointer to the
1541 * structure if it did.
1542 */
1543static MOUNTED_FS_STRUCT *find_device_in_list (char *device)
1544{
1545 MOUNTED_FS_STRUCT *DSFptr = NULL;
[1]1546
[2434]1547 DSFptr = DSF_Head;
1548 while (DSFptr != NULL) {
1549 if (!strcmp(DSFptr->device, device)) {
1550 break;
1551 }
1552 DSFptr = DSFptr->next;
1553 }
1554 return (DSFptr);
1555}
[1]1556
1557/**
[2434]1558 * Find the structure, in the singly linked list of all of the non-NETFS
1559 * mounted file systems, that contains the specified mount point.
1560 * @param mount_point The mount point to find
1561 * @return NULL is it didn't find the mount point, a pointer to the
1562 * structure if it did.
1563 */
1564static MOUNTED_FS_STRUCT *find_mount_point_in_list (char *mount_point)
1565{
1566 MOUNTED_FS_STRUCT *DSFptr = NULL;
1567
1568 DSFptr = DSF_Head;
1569 while (DSFptr != NULL) {
1570 if (!strcmp(DSFptr->mount_point, mount_point)) {
1571 break;
1572 }
1573 DSFptr = DSFptr->next;
1574 }
1575 return (DSFptr);
1576}
1577
1578/**
1579 * Frees the memory for all of the structures on the linked list of
1580 * all of the non-NETFS mounted file systems.
1581 */
1582static void free_mounted_fs_list (void) {
1583 MOUNTED_FS_STRUCT *DSFptr = NULL;
1584 MOUNTED_FS_STRUCT *DSFnext = NULL;
1585
1586 DSFptr = DSF_Head;
1587 while (DSFptr != NULL) {
1588 DSFnext = DSFptr->next;
1589 paranoid_free(DSFptr);
1590 DSFptr = DSFnext;
1591 }
1592 DSF_Head = NULL;
1593 DSF_Tail = NULL;
1594}
1595
1596
1597/**
1598 * Creates a linked list of all of the non-NETFS mounted file systems.
1599 * We use a linked list because we don't know how many mounted file
1600 * there are (and there can be a lot).
1601 * @return 0 on success and greated than 0 on failure.
1602 */
1603static int create_list_of_non_NETFS_mounted_file_systems (void)
1604{
1605 int i = 0;
1606 int mount_cnt = 0;
[2436]1607 int lastpos = 0;
[2434]1608 char *mounted_file_system = NULL;
1609 char *command = NULL;
1610 char *token = NULL;
1611 char token_chars[] =" :\t\r\f\a\0";
1612 MOUNTED_FS_STRUCT *DSFptr = NULL;
1613
1614 free_mounted_fs_list();
1615 /********
1616 * Find the number of mounted file system entries and their respective mount points.
1617 * I can't return all of the entries as one string because it's length can be longer
1618 * than MAX_STR_LEN which is used in call_program_and_get_last_line_of_output().
1619 * So start looping and get the number of mounted file systems and query them one by one.
1620 ********/
1621 /* Get the number of mounted file systems ((those that start with "/dev/" */
[3185]1622 mr_asprintf(command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $0}}'|wc -l");
[2434]1623 log_msg(5, "Running: %s", command);
[3185]1624 mr_asprintf(mounted_file_system, "%s", call_program_and_get_last_line_of_output(command));
[3191]1625 mr_free(command);
[2434]1626
1627 mount_cnt = atoi(mounted_file_system);
1628 log_msg (5, "mount_cnt: %d", mount_cnt);
[3191]1629 mr_free(mounted_file_system);
[2434]1630
1631 for (i=mount_cnt; i > 0; i--) {
[3185]1632 mr_asprintf(command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $1,$3}}'|head -n %d", i);
[2434]1633 log_msg(5, "Running: %s", command);
[3185]1634 mr_asprintf(mounted_file_system, "%s", call_program_and_get_last_line_of_output(command));
[3191]1635 mr_free(command);
[2434]1636
1637 log_msg (5, "mounted_file_system: %s", mounted_file_system);
[2436]1638 if ((token = mr_strtok(mounted_file_system, token_chars, &lastpos)) == NULL) {
[2434]1639 log_msg (4, "Could not get the list of mounted file systems");
[3191]1640 mr_free(mounted_file_system);
[2434]1641 mr_free(token);
1642 return (1);
1643 }
1644 if (token) {
1645 log_msg (5, "token: %s", token);
1646 }
1647 while (token != NULL) {
1648 log_msg (5, "token: %s", token);
1649 if ((DSFptr = (MOUNTED_FS_STRUCT *) calloc(1, sizeof(MOUNTED_FS_STRUCT))) == NULL) {
1650 fatal_error ("Cannot allocate memory");
1651 }
1652 add_mounted_fs_struct(DSFptr);
1653 strcpy(DSFptr->device, token);
1654 mr_free(token);
[2436]1655 if ((token = mr_strtok(mounted_file_system, token_chars, &lastpos)) == NULL) {
[2434]1656 log_msg (5, "Ran out of entries on the mounted file systems list");
[2436]1657 mr_free(mounted_file_system);
[2434]1658 mr_free(token);
1659 return (1);
1660 }
1661 log_msg (5, "token: %s", token);
1662 strcpy(DSFptr->mount_point, token);
1663 mr_free(token);
[2436]1664 token = mr_strtok(mounted_file_system, token_chars, &lastpos);
[2434]1665 }
[2436]1666 mr_free(mounted_file_system);
[2434]1667 }
1668 return (0);
1669}
1670
1671
1672
1673/**
1674 * Given a whole disk device special file, determine which mounted file systems
1675 * are on the dsf's partitions and which mounted file systems are not.
1676 * @param dsf The whole disk device special file.
1677 * @param included_dsf_list A char pointer used to hold the list of mount points
1678 * that are on the dsf. Memory for the array will be allocated within the function.
1679 * @param excluded_dsf_list A char pointer used to hold the list of mount points
1680 * that are not on the dsf. Memory for the array will be allocated within the function.
1681 * @return 0 on success, -1 if no device special file was passed in, -2 if a device
1682 * special file was passed in but it has no partitions on it, or 1 on failure
1683 */
1684static int get_dsf_mount_list (const char *dsf, char **included_dsf_list, char **excluded_dsf_list) {
1685 int i = 0;
1686 int c = 0;
1687 int lastpos = 0;
[3288]1688 char *VG = NULL;
[2434]1689 char *tmp = NULL;
1690 char *command = NULL;
1691 char *partition_list = NULL;
1692 char partitions[64][MAX_STR_LEN];
1693 char *mount_list = NULL;
1694 char *token = NULL;
[2436]1695 char *ndsf = NULL;
[2434]1696 char token_chars[] =" \t\r\f\a\0";
1697 MOUNTED_FS_STRUCT *DSFptr = NULL;
1698
1699 memset((char *)partitions, 0, sizeof(partitions));
1700
1701 log_msg(5, "dsf: %s", dsf);
1702
1703 /********
1704 * See if a device special file was passed in (i.e. it must start with /dev/
1705 ********/
1706 if (strncmp(dsf, "/dev/", 5)) {
[2527]1707 log_msg (4, "%s does not start with /dev/ and (probably) is not a device special file", dsf);
[2434]1708 return (-1);
1709 }
[2527]1710 log_msg(4, " %s looks like a device special file", dsf);
[2434]1711 /* Verify that the dsf exists */
[3185]1712 mr_asprintf(command, "ls -al %s 2>/dev/null | wc -l", dsf);
[2434]1713 log_msg(5, " Executing: %s", command);
[3185]1714 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
[3191]1715 mr_free(command);
[2434]1716
1717 log_msg(5, " Return value: %s", tmp);
1718 c = atoi(tmp);
[3191]1719 mr_free(tmp);
[2434]1720
1721 if (!c) {
1722 log_to_screen("Cannot find device special file %s", dsf);
1723 return (1);
1724 }
[2527]1725 log_msg(4, " %s device special file exists", dsf);
[2434]1726
1727 /* Get a list of the mounted file systems */
1728 if (create_list_of_non_NETFS_mounted_file_systems()) {
1729 log_to_screen ("Could not get the list of mounted file systems");
1730 return (1);
1731 }
1732 log_msg (5, "Processing dsf: %s", dsf);
1733 /********
1734 * Get a list of the dsf's partitions. There could be no partitions on the disk
1735 * or a dsf of a partition was passed in (e.g. /dev/sda1 instead of /dev/sda).
1736 * Either way, it's an error.
1737 ********/
[3377]1738 mr_asprintf(command, "mr-parted2fdisk -l %s 2>/dev/null|grep -E \"^/dev/\"|awk '{printf(\"%%s \", $1)}END{print \"\"}'", dsf);
[2527]1739 log_msg(5, "Executing: %s", command);
[3185]1740 mr_asprintf(partition_list, "%s", call_program_and_get_last_line_of_output(command));
[3191]1741 mr_free(command);
[2434]1742 log_msg(4, "Partition list for %s: %s", dsf, partition_list);
1743 if (!strlen(partition_list)) {
1744 /* There were no partitions on the disk */
[2436]1745 log_msg(4, "No partitions on device special file %s", dsf);
[2453]1746 log_msg(4, "I guess it's a partition itself");
[2436]1747 strcpy(partitions[0], dsf);
1748 ndsf = truncate_to_drive_name(dsf);
1749 } else {
1750 /* Fill the partition list */
1751 i = 0;
1752 lastpos = 0;
1753 while ((token = mr_strtok(partition_list, token_chars, &lastpos)) != NULL) {
[2527]1754 log_msg (4, "Found partition: %s", token);
[2436]1755 strcpy(partitions[i++], token);
1756 mr_free(token);
1757 }
[3185]1758 mr_asprintf(ndsf, "%s", dsf);
[2434]1759 }
[2436]1760 mr_free(partition_list);
[2527]1761
1762 /* In any case we want to exclude the dsf itself from all MondRescue activities
1763 * at restore time (LVM, fdisk, ...) so we want it in our exclude_dev list */
[2528]1764 if ((DSFptr = (MOUNTED_FS_STRUCT *) calloc(1, sizeof(MOUNTED_FS_STRUCT))) == NULL) {
1765 fatal_error ("Cannot allocate memory");
[2527]1766 }
[2528]1767 add_mounted_fs_struct(DSFptr);
1768 strcpy(DSFptr->device, dsf);
[2527]1769 DSFptr->check = 1;
1770
[2436]1771 /* For the rest ndsf is the new dsf to deal with */
[2434]1772 /********
1773 * At this point, we have a list of all of the partitions on the dsf. Now try to
1774 * see which partitions have a file system on them.
1775 *
1776 * Loop through each partition on the disk and:
1777 *
1778 * - If the partition is swap, it ignores it.
1779 *
1780 * - If the partition is mounted (e.g. /dev/sda1 is mounted on /boot), it adds an entry
1781 * to the linked list, copies to it the device name and mount point, and sets check == 1.
1782 *
1783 * - If the partition is part of a Volume Group that has Logical Volumes mounted, it adds
1784 * an entry to the linked list for each mounted Logical Volume in that Volume Group, copying
1785 * to it the device name and mount point, and sets check == 1. Note that if the Volume Group
1786 * contains more than one disk, it will still add the entry even if the Logical Volume's
1787 * extents are not on the dsf that was passed in to the function. For example, Volume Group
1788 * VolGroup00 contains the disks /dev/sda1 and /dev/sdb1, and the Logical Volumes LogVol01,
1789 * which is mounted on /var and has all of its extents on /dev/sda1, and LogVol02, which is
1790 * mounted as /usr and has all of its extents on /dev/sdb1. If you pass /dev/sda into the
1791 * function, both /var and /usr will be archived even though /usr is actually on/dev/sdb.
1792 *
1793 * - If the partition is part of a Volume Group that has Logical Volumes used in a mounted
1794 * software raid device, it adds an entry to the linked list, copies to it the software raid
1795 * device name and mount point, and sets check == 1.
1796 *
1797 * - If the partition is part of a mounted software raid device, it adds an entry to the linked
1798 * list, copies to it the software raid device name and mount point, and sets check == 1.
1799 *
1800 ********/
1801 for (i=0; strlen(partitions[i]); i++) {
1802 log_msg(4, "Processing partition: %s", partitions[i]);
1803 /* See if it's swap. If it is, ignore it. */
[3377]1804 mr_asprintf(command, "mr-parted2fdisk -l %s 2>/dev/null | awk '{if(($1==\"%s\")&&(toupper($0) ~ \"SWAP\")){print $1;exit}}'", ndsf, partitions[i]);
[2527]1805 log_msg(5, " Running: %s", command);
[3185]1806 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
[3191]1807 mr_free(command);
1808
[2527]1809 log_msg(5, " Return value: %s", tmp);
[2434]1810 c = strlen(tmp);
[3191]1811 mr_free(tmp);
1812
[2434]1813 if (c) {
1814 log_msg(4, "It's swap. Ignoring partition %s", partitions[i]);
1815 continue;
1816 }
[3191]1817
[2434]1818 /* It's not swap. See if we can find the mount point from the mount command. */
[3185]1819 mr_asprintf(command, "mount 2>/dev/null | awk '{if((NF>0)&&($1==\"%s\")){print $3}}'", partitions[i]);
1820 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
[3191]1821 mr_free(command);
1822
[2434]1823 if (strlen(tmp)) {
1824 log_msg(4, " %s is mounted: %s", partitions[i], tmp);
1825 if ((DSFptr = find_mount_point_in_list(tmp)) == NULL) {
1826 log_msg (4, "Can't find mount point %s in mounted file systems list", tmp);
[3191]1827 mr_free(tmp);
[2434]1828 return (1);
1829 }
1830 DSFptr->check = 1;
[3191]1831 mr_free(tmp);
[2434]1832 continue;
1833 }
[3191]1834 mr_free(tmp);
1835
[2434]1836 /* It's not swap and it's not mounted. See if it's LVM */
1837 log_msg(4, " It's not mounted. Checking to see if it's LVM...");
[3191]1838
[2527]1839 /* Check for LVM */
[3185]1840 mr_asprintf(command, "pvdisplay -c %s 2> /dev/null", partitions[i]);
[2527]1841 log_msg(5, " Running: %s", command);
[3185]1842 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
[3191]1843 mr_free(command);
1844
[2434]1845 if (strlen(tmp)) {
[2527]1846 log_msg(4, "Found an LVM partition at %s. Find the VG it's in...", partitions[i]);
1847 /* It's LVM: Find the VG it's in */
[3185]1848 mr_asprintf(command, "pvdisplay -v %s 2>/dev/null|grep \"VG Name\"|awk '{print $NF}'", partitions[i]);
[2527]1849 log_msg(5, " Running: %s", command);
[3288]1850 mr_asprintf(VG, "%s", call_program_and_get_last_line_of_output(command));
[3191]1851 mr_free(command);
1852
[2527]1853 log_msg(4, " Volume Group: %s", VG);
1854 if (strlen(VG)) {
1855 /* Found the Volume Group. Now find all of the VG's mount points */
1856 log_msg(4, " Found the Volume Group. Now find all of the VG's mount points");
[3185]1857 mr_asprintf(command, "mount 2>/dev/null|grep -E \"/dev/mapper/%s|/dev/%s/\"|awk '{printf(\"%%s \",$3)}END{print \"\"}'", VG, VG);
[2527]1858 log_msg(5, " Running: %s", command);
[3185]1859 mr_asprintf(mount_list, "%s", call_program_and_get_last_line_of_output(command));
[3191]1860 mr_free(command);
1861
[2527]1862 log_msg(4, " VG %s mount_list: %s", VG, mount_list);
1863 lastpos = 0;
1864 while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) {
1865 log_msg (5, "mount point token: %s", token);
1866 if ((DSFptr = find_mount_point_in_list(token)) == NULL) {
1867 log_msg (4, "Can't find mount point %s in mounted file systems list", token);
[3191]1868 mr_free(tmp);
[2527]1869 mr_free(token);
1870 return (1);
1871 }
1872 DSFptr->check = 1;
1873 mr_free(token);
1874 }
1875 /********
1876 * Now we want to see if there are any software raid devices using
1877 * any of the Logical Volumes on the Volume Group.
1878 *******/
[3191]1879 mr_free(mount_list);
[2527]1880
[3185]1881 mr_asprintf(command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
[2527]1882 log_msg (5, "Running: %s", command);
[3185]1883 mr_asprintf(mount_list, "%s", call_program_and_get_last_line_of_output(command));
[3191]1884 mr_free(command);
[2527]1885 log_msg(4, " Software raid device list: %s", mount_list);
1886 lastpos = 0;
1887 while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) {
[3185]1888 mr_asprintf(command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, VG);
[2527]1889 log_msg (5, "Running: %s", command);
[3191]1890 mr_free(tmp);
[3185]1891 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
[3191]1892 mr_free(command);
[2527]1893 log_msg(4, "Number of Software raid device: %s", tmp);
1894 if (atoi(tmp)) {
1895 /* This device is on our disk */
1896 if ((DSFptr = find_device_in_list(token)) == NULL) {
1897 log_msg (4, "Can't find device %s in mounted file systems list", token);
[3191]1898 mr_free(tmp);
[2434]1899 mr_free(token);
1900 return (1);
1901 }
1902 DSFptr->check = 1;
1903 }
1904 }
[2527]1905 mr_free(token);
1906 paranoid_free(mount_list);
1907 } else {
1908 log_msg (4, "Error finding Volume Group for partition %s", partitions[i]);
[3191]1909 mr_free(tmp);
[2527]1910 return (1);
[2434]1911 }
[3191]1912 mr_free(tmp);
[3288]1913 mr_free(VG);
[2527]1914 continue;
[2434]1915 } else {
1916 log_msg (4, "Error finding partition type for the partition %s", partitions[i]);
1917 }
[3191]1918 mr_free(tmp);
1919
[2434]1920 /********
1921 * It's not swap, mounted, or LVM. See if it's used in a software raid device.
1922 ********/
1923 log_msg (5, "It's not swap, mounted, or LVM. See if it's used in a software raid device.");
[3185]1924 mr_asprintf(command, "mdadm --examine %s 2>/dev/null | awk '{if($1 == \"UUID\"){print $3}}'", partitions[i]);
[2434]1925 log_msg(4, " Running: %s", command);
[3185]1926 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
[3191]1927 mr_free(command);
1928
[2434]1929 if (!strlen(tmp)) {
1930 log_msg(4, " Partition %s is not used in a non-LVM software raid device", partitions[i]);
[3191]1931 mr_free(tmp);
[2434]1932 continue;
1933 }
1934 log_msg (5, " UUID: %s", tmp);
[3191]1935
[2434]1936 /* Get the Software raid device list */
[3185]1937 mr_asprintf(command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
[2434]1938 log_msg (5, " Running: %s", command);
[3185]1939 mr_asprintf(mount_list, "%s", call_program_and_get_last_line_of_output(command));
[3191]1940 mr_free(command);
1941
[2434]1942 log_msg(4, " Software raid device list: %s", mount_list);
1943 /* Loop through the software raid device list to see if we can find the partition */
1944 lastpos = 0;
1945 while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) {
[3185]1946 mr_asprintf(command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, tmp);
[2434]1947 log_msg(4, " Running: %s", command);
[3191]1948 mr_free(tmp);
[3185]1949 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
[3191]1950 mr_free(command);
1951
[2434]1952 if (!atoi(tmp)) {
1953 log_msg (4," Didn't find partition %s in software raid device %s", partitions[i], token);
1954 } else {
1955 if ((DSFptr = find_device_in_list(token)) == NULL) {
1956 log_msg (4, "Can't find device %s in mounted file systems list", token);
[3191]1957 mr_free(tmp);
[2434]1958 mr_free(token);
1959 return (1);
1960 }
1961 DSFptr->check = 1;
1962 break;
1963 }
1964 mr_free(token);
1965 }
[3191]1966 mr_free(tmp);
1967 mr_free(mount_list);
[2434]1968 }
1969
1970 /* Determine how much memory to allocate for included_dsf_list and excluded_dsf_list */
1971 i = 0;
1972 DSFptr= DSF_Head;
1973 while (DSFptr != NULL) {
1974 i += strlen(DSFptr->mount_point) + 1;
1975 DSFptr = DSFptr->next;
1976 }
1977 log_msg (5, "i: %d", i);
1978 if ((*included_dsf_list = (char *) calloc(i+100, sizeof(char))) == NULL) {
1979 fatal_error ("Cannot allocate memory");
1980 }
1981 if ((*excluded_dsf_list = (char *) calloc(i+100, sizeof(char))) == NULL) {
1982 fatal_error ("Cannot allocate memory");
1983 }
1984 DSFptr= DSF_Head;
1985 while (DSFptr != NULL) {
1986 if (DSFptr->check) {
[2632]1987 log_msg (4, "%s is mounted on %s and is on disk %s", DSFptr->device, DSFptr->mount_point, ndsf);
[2434]1988 strcat(*included_dsf_list, DSFptr->mount_point);
[2713]1989 strcat(*included_dsf_list, "|");
[2434]1990 } else {
[2632]1991 log_msg (4, "%s is mounted on %s and is NOT on disk %s", DSFptr->device, DSFptr->mount_point, ndsf);
[2434]1992 strcat(*excluded_dsf_list, DSFptr->mount_point);
[2713]1993 strcat(*excluded_dsf_list, "|");
[2434]1994 }
1995 DSFptr = DSFptr->next;
1996 }
[2436]1997 mr_free(ndsf);
1998
[2434]1999 log_msg (5, "included_dsf_list: %s", *included_dsf_list);
2000 log_msg (5, "excluded_dsf_list: %s", *excluded_dsf_list);
2001 return (0);
2002}
2003
2004
2005/* Update the bkpinfo structure for exclude & include paths
2006 * in order to handle correctly paths corresponding to devices */
2007void mr_make_devlist_from_pathlist(char *pathlist, char mode) {
2008
2009char *token = NULL;
2010int lastpos = 0;
2011char *mounted_on_dsf = NULL;
2012char *not_mounted_on_dsf = NULL;
[2713]2013char token_chars[] ="|\t\r\f\a\0\n";
[2525]2014char *tmp = NULL;
2015char *tmp1 = NULL;
[2934]2016char *tmp2 = NULL;
[2434]2017
[2745]2018if (pathlist == NULL) {
2019 return;
2020}
[2434]2021while ((token = mr_strtok(pathlist, token_chars, &lastpos)) != NULL) {
2022 switch (get_dsf_mount_list(token, &mounted_on_dsf, &not_mounted_on_dsf)) {
2023 case 1:
2024 if (mode == 'E') {
2025 log_msg(1, "WARNING ! %s doesn't exist in -E option", token);
2026 } else {
[2453]2027 log_msg(1, "ERROR ! %s doesn't exist in -I option", token);
[2434]2028 fatal_error("Error processing -I option");
2029 }
2030 break;
2031 /* Everything is OK; proceed to archive data */
2032 case 0:
2033 if (mode == 'E') {
2034 if (strlen(mounted_on_dsf)) {
[2632]2035 log_to_screen("Excluding the following file systems on %s:", token);
2036 log_to_screen("==> %s", mounted_on_dsf);
[2434]2037 log_msg (5, "Adding to bkpinfo->exclude_paths due to -E option: %s", mounted_on_dsf);
[2713]2038 if (bkpinfo->exclude_paths) {
2039 mr_strcat(bkpinfo->exclude_paths,"|%s",mounted_on_dsf);
2040 } else {
[3185]2041 mr_asprintf(bkpinfo->exclude_paths,"%s",mounted_on_dsf);
[2713]2042 }
2043 if (bkpinfo->exclude_devs) {
2044 mr_strcat(bkpinfo->exclude_devs,"|%s",token);
2045 } else {
[3185]2046 mr_asprintf(bkpinfo->exclude_devs,"%s",token);
[2713]2047 }
[2434]2048 }
[2453]2049 } else {
[2632]2050 log_to_screen("Archiving only the following file systems on %s:", token);
[2636]2051 log_to_screen("==> %s", mounted_on_dsf);
[3191]2052 mr_free(bkpinfo->include_paths);
2053 mr_asprintf(bkpinfo->include_paths, "%s", "/");
[2453]2054 if (strlen(not_mounted_on_dsf)) {
2055 log_msg (5, "Adding to bkpinfo->exclude_paths due to -I option: %s", not_mounted_on_dsf);
[2632]2056 log_to_screen("Not archiving the following file systems:");
2057 log_to_screen("==> %s", not_mounted_on_dsf);
[2713]2058 if (bkpinfo->exclude_paths) {
2059 mr_strcat(bkpinfo->exclude_paths, "|%s",not_mounted_on_dsf);
2060 } else {
[3185]2061 mr_asprintf(bkpinfo->exclude_paths,"%s",not_mounted_on_dsf);
[2713]2062 }
[2453]2063 }
[2434]2064 }
2065 break;
2066 /* It's a dsf but not a whole disk dsf */
2067 case -2:
2068 log_to_screen("Could %s be a partition instead of a whole disk device special file?\nIgnored.", token);
2069 break;
2070 /* A device special file was not passed in. Process it as a path. */
2071 case -1:
[2713]2072 /* Adds a | to ensure correct detection even at both ends */
[3185]2073 mr_asprintf(tmp1,"|%s",token);
2074 mr_asprintf(tmp2,"|%s|",token);
[2434]2075 if (mode == 'E') {
[2473]2076 /* Add the token if not already in the list */
[3185]2077 mr_asprintf(tmp,"|%s|",bkpinfo->exclude_paths);
[2934]2078 if (strstr(tmp,tmp2) == NULL) {
[2713]2079 if (bkpinfo->exclude_paths) {
2080 mr_strcat(bkpinfo->exclude_paths,tmp1);
2081 mr_free(tmp1);
2082 } else {
2083 bkpinfo->exclude_paths = tmp1;
2084 }
[2473]2085 }
[2434]2086 } else {
[2473]2087 /* Add the token if not already in the list */
[3185]2088 mr_asprintf(tmp,"|%s|",bkpinfo->include_paths);
[2934]2089 if (strstr(tmp,tmp2) == NULL) {
[3191]2090 mr_strcat(bkpinfo->include_paths, "%s", tmp1);
[2473]2091 }
[2713]2092 mr_free(tmp1);
[2434]2093 }
[2525]2094 mr_free(tmp);
[2934]2095 mr_free(tmp2);
[2434]2096 break;
2097 }
2098 mr_free(token);
2099
2100 if (bkpinfo->include_paths != NULL) {
2101 log_msg(1, "include_paths is now '%s'", bkpinfo->include_paths);
2102 }
2103 if (bkpinfo->exclude_paths != NULL) {
2104 log_msg(1, "exclude_paths is now '%s'", bkpinfo->exclude_paths);
2105 }
2106 if (bkpinfo->exclude_devs != NULL) {
2107 log_msg(1, "exclude_devs is now '%s'", bkpinfo->exclude_devs);
2108 }
2109}
2110}
2111
2112
[3375]2113/**
2114 * Return the type of boot of the system (UEFI, EFI or BIOS)
2115 */
[3413]2116t_boot mr_boot_type(void) {
[2434]2117
[3375]2118 t_boot ret = BIOS;
[3377]2119 DIR *fd = NULL;
[2434]2120
[3375]2121#ifdef __IA64__
[3395]2122 return(EFI);
[3375]2123#endif
2124 /* Try to detect whether we are in fact in UEFI mode */
[3378]2125 fd = opendir("/sys/firmware/efi");
[3375]2126 if (fd != NULL) {
2127 ret = UEFI;
[3398]2128 log_msg(2, "UEFI boot mode detected");
[3377]2129 closedir(fd);
[3375]2130 }
2131 return(ret);
2132}
2133
2134
[2434]2135/**
[1]2136 * Ask user for details of backup/restore information.
2137 * Called when @c mondoarchive doesn't get any parameters.
2138 * @param bkpinfo The backup information structure to fill out with the user's data.
2139 * @param archiving_to_media TRUE if archiving, FALSE if restoring.
2140 * @return 0, always.
2141 * @bug No point of `int' return value.
2142 * @ingroup archiveGroup
2143 */
[1645]2144int interactively_obtain_media_parameters_from_user(bool archiving_to_media)
[1]2145// archiving_to_media is TRUE if I'm being called by mondoarchive
2146// archiving_to_media is FALSE if I'm being called by mondorestore
2147{
[2214]2148 char *tmp = NULL;
[3154]2149 char *sz = NULL;
[3111]2150 char *tmpro = NULL;
[2304]2151 char *tmp1 = NULL;
[2242]2152 char *mds = NULL;
[3212]2153 char *oldtmp = NULL;
[2847]2154 char *q = NULL;
[3062]2155 char p[16*MAX_STR_LEN];
[3191]2156 char *sz_size = NULL;
2157 char *command = NULL;
[2771]2158 char *compression_type = NULL;
[3191]2159 char *comment = NULL;
[128]2160 int i;
2161 FILE *fin;
[1]2162
[2304]2163 malloc_string(tmp1);
[128]2164 assert(bkpinfo != NULL);
2165 bkpinfo->nonbootable_backup = FALSE;
[1]2166
[2380]2167 // Tape, CD, NETFS, ...?
[128]2168 srandom(getpid());
2169 bkpinfo->backup_media_type =
2170 (g_restoring_live_from_cd) ? cdr :
2171 which_backup_media_type(bkpinfo->restore_data);
2172 if (bkpinfo->backup_media_type == none) {
[541]2173 log_to_screen("User has chosen not to backup the PC");
[128]2174 finish(1);
2175 }
[1934]2176 /* Why asking to remove the media with tape ?
[128]2177 if (bkpinfo->backup_media_type == tape && bkpinfo->restore_data) {
[1885]2178 popup_and_OK("Please remove media from drive(s)");
[128]2179 }
[1934]2180 */
[3154]2181 if (archiving_to_media) {
2182 setup_tmpdir(NULL);
2183 /*
2184 * Set the scratchdir to reside on the partition with the most free space.
2185 * Automatically excludes DOS, NTFS, SMB, and NFS filesystems.
2186 */
2187#ifdef __FreeBSD__
[3185]2188 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("LANGUAGE=C 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]2189#else
[3185]2190 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("LANGUAGE=C df -m -P -x nfs -x nfs4 -x fuse.sshfs -x fuse -x vfat -x ntfs -x ntfs-3g -x 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]2191#endif
2192
2193 if (tmp[0] != '/') {
[3185]2194 mr_asprintf(sz, "%s", tmp);
[3154]2195 mr_free(tmp);
[3185]2196 mr_asprintf(tmp, "/%s", sz);
[3154]2197 mr_free(sz);
2198 }
2199 setup_scratchdir(tmp);
[3292]2200 mr_free(tmp);
[3154]2201 }
[3191]2202 log_msg(3, "media type = %s", bkptype_to_string(bkpinfo->backup_media_type));
[128]2203 bkpinfo->cdrw_speed = (bkpinfo->backup_media_type == cdstream) ? 2 : 4;
[3191]2204 bkpinfo->compression_level = (bkpinfo->backup_media_type == cdstream) ? 1 : 5;
2205 bkpinfo->use_lzo = (bkpinfo->backup_media_type == cdstream) ? TRUE : FALSE;
[128]2206 mvaddstr_and_log_it(2, 0, " ");
[1]2207
[1934]2208 // Find device's /dev (or SCSI) entry
[128]2209 switch (bkpinfo->backup_media_type) {
2210 case cdr:
2211 case cdrw:
2212 case dvd:
[1687]2213 case usb:
[1745]2214 /* Never try to eject a USB device */
2215 if (bkpinfo->backup_media_type == usb) {
[1746]2216 bkpinfo->please_dont_eject = TRUE;
[1745]2217 }
[128]2218 if (archiving_to_media) {
[1687]2219 if ((bkpinfo->backup_media_type != dvd) && (bkpinfo->backup_media_type != usb)) {
[3191]2220 if (ask_me_yes_or_no("Is your computer a laptop, or does the CD writer incorporate BurnProof technology?")) {
[685]2221 bkpinfo->manual_cd_tray = TRUE;
2222 }
[128]2223 }
[2771]2224 if ((compression_type = which_compression_type()) == NULL) {
2225 log_to_screen("User has chosen not to backup the PC");
2226 finish(1);
2227 }
[3191]2228
2229 if ((bkpinfo->compression_level = which_compression_level()) == -1) {
[541]2230 log_to_screen("User has chosen not to backup the PC");
[128]2231 finish(1);
2232 }
[2242]2233 mds = media_descriptor_string(bkpinfo->backup_media_type);
[3191]2234 mr_asprintf(comment, "What speed is your %s (re)writer?", mds);
[128]2235 if (bkpinfo->backup_media_type == dvd) {
2236 find_dvd_device(bkpinfo->media_device, FALSE);
[2304]2237 strcpy(tmp1, "1");
[3191]2238 mr_asprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4482 MB
[128]2239 log_msg(1, "Setting to DVD defaults");
2240 } else {
2241 strcpy(bkpinfo->media_device, VANILLA_SCSI_CDROM);
[2304]2242 strcpy(tmp1, "4");
[3191]2243 mr_asprintf(sz_size, "%d", 650);
[128]2244 log_msg(1, "Setting to CD defaults");
2245 }
[1687]2246 if ((bkpinfo->backup_media_type != dvd) && (bkpinfo->backup_media_type != usb)) {
[2304]2247 if (!popup_and_get_string("Speed", comment, tmp1, 4)) {
[541]2248 log_to_screen("User has chosen not to backup the PC");
[3191]2249 mr_free(comment);
[128]2250 finish(1);
2251 }
2252 }
[3191]2253 mr_free(comment);
[2304]2254 bkpinfo->cdrw_speed = atoi(tmp1); // if DVD then this shouldn't ever be used anyway :)
[2214]2255
[3191]2256 strcpy(tmp1, sz_size);
2257 mr_asprintf(comment, "How much data (in Megabytes) will each %s store?", mds);
[2242]2258 mr_free(mds);
[3191]2259 if (!popup_and_get_string("Size", comment, tmp1, 5)) {
[541]2260 log_to_screen("User has chosen not to backup the PC");
[128]2261 finish(1);
2262 }
[3191]2263 mr_asprintf(sz_size, "%s", tmp1);
[3150]2264 bkpinfo->media_size = atoi(sz_size);
[3191]2265
[3150]2266 if (bkpinfo->media_size <= 0) {
[541]2267 log_to_screen("User has chosen not to backup the PC");
[128]2268 finish(1);
2269 }
2270 }
[1737]2271 /* No break because we continue even for usb */
[128]2272 case cdstream:
[2242]2273 mds = media_descriptor_string(bkpinfo->backup_media_type);
2274
[1737]2275 if ((bkpinfo->disaster_recovery) && (bkpinfo->backup_media_type != usb)) {
[128]2276 strcpy(bkpinfo->media_device, "/dev/cdrom");
[3191]2277 log_msg(2, "CD-ROM device assumed to be at %s", bkpinfo->media_device);
2278 } else if ((bkpinfo->restore_data && (bkpinfo->backup_media_type != usb)) || bkpinfo->backup_media_type == dvd) {
[128]2279 if (!bkpinfo->media_device[0]) {
2280 strcpy(bkpinfo->media_device, "/dev/cdrom");
2281 } // just for the heck of it :)
[3191]2282 log_msg(1, "bkpinfo->media_device = %s", bkpinfo->media_device);
2283 if (bkpinfo->backup_media_type == dvd || find_cdrom_device(bkpinfo->media_device, FALSE)) {
2284 log_msg(1, "bkpinfo->media_device = %s", bkpinfo->media_device);
2285 mr_asprintf(comment, "Please specify your %s drive's /dev entry", mds);
2286 if (!popup_and_get_string("Device?", comment, bkpinfo->media_device, MAX_STR_LEN / 4)) {
[541]2287 log_to_screen("User has chosen not to backup the PC");
[128]2288 finish(1);
2289 }
2290 }
[2242]2291 log_msg(2, "%s device found at %s", mds, bkpinfo->media_device);
[128]2292 } else {
[1737]2293 if ((find_cdrw_device(bkpinfo->media_device)) && (bkpinfo->backup_media_type != usb)) {
[128]2294 bkpinfo->media_device[0] = '\0';
2295 }
2296 if (bkpinfo->media_device[0]) {
[1738]2297 if (bkpinfo->backup_media_type == usb) {
[3185]2298 mr_asprintf(tmp, "I think your %s media corresponds to %s. Is this correct?", mds, bkpinfo->media_device);
[1738]2299 } else {
[3185]2300 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]2301 }
[128]2302 if (!ask_me_yes_or_no(tmp)) {
2303 bkpinfo->media_device[0] = '\0';
2304 }
[2214]2305 mr_free(tmp);
[128]2306 }
2307 if (!bkpinfo->media_device[0]) {
[1737]2308 if (bkpinfo->backup_media_type == usb) {
[3212]2309 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]2310 } else {
2311 if (g_kernel_version < 2.6) {
[3212]2312 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]2313 } else {
[3212]2314 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]2315 }
[128]2316 }
2317 if (!i) {
[541]2318 log_to_screen("User has chosen not to backup the PC");
[128]2319 finish(1);
2320 }
2321 }
2322 }
[2242]2323 mr_free(mds);
2324
[128]2325 if (bkpinfo->backup_media_type == cdstream) {
[3150]2326 bkpinfo->media_size = 650;
[128]2327 }
2328 break;
2329 case udev:
2330 if (!ask_me_yes_or_no
[541]2331 ("This option is for advanced users only. Are you sure?")) {
2332 log_to_screen("User has chosen not to backup the PC");
[128]2333 finish(1);
2334 }
2335 case tape:
[1]2336
[1969]2337 if ((!bkpinfo->restore_mode) && (find_tape_device_and_size(bkpinfo->media_device, sz_size))) {
[541]2338 log_msg(3, "Ok, using vanilla scsi tape.");
[128]2339 strcpy(bkpinfo->media_device, VANILLA_SCSI_TAPE);
2340 if ((fin = fopen(bkpinfo->media_device, "r"))) {
2341 paranoid_fclose(fin);
2342 } else {
2343 strcpy(bkpinfo->media_device, "/dev/osst0");
2344 }
2345 }
2346 if (bkpinfo->media_device[0]) {
2347 if ((fin = fopen(bkpinfo->media_device, "r"))) {
2348 paranoid_fclose(fin);
2349 } else {
[3271]2350 if (does_file_exist("/tmp/mondorestore.cfg")) {
2351 read_cfg_var("/tmp/mondorestore.cfg", "media-dev", bkpinfo->media_device);
[128]2352 }
2353 }
2354 }
2355 if (bkpinfo->media_device[0]) {
[3185]2356 mr_asprintf(tmp, "I think I've found your tape streamer at %s; am I right on the money?", bkpinfo->media_device);
[128]2357 if (!ask_me_yes_or_no(tmp)) {
2358 bkpinfo->media_device[0] = '\0';
2359 }
[2214]2360 mr_free(tmp);
[128]2361 }
2362 if (!bkpinfo->media_device[0]) {
[3212]2363 if (!popup_and_get_string("Device name?", "What is the /dev entry of your tape streamer?", bkpinfo->media_device, MAX_STR_LEN / 4)) {
[541]2364 log_to_screen("User has chosen not to backup the PC");
[128]2365 finish(1);
2366 }
2367 }
[3185]2368 mr_asprintf(tmp, "ls -l %s", bkpinfo->media_device);
[128]2369 if (run_program_and_log_output(tmp, FALSE)) {
[541]2370 log_to_screen("User has not specified a valid /dev entry");
[128]2371 finish(1);
2372 }
[2214]2373 mr_free(tmp);
2374
[3377]2375 mr_asprintf(sz_size,"%s",bkpinfo->internal_tape_block_size);
2376 tmp = mr_popup_and_get_string("Tape block size?", "What is the block size of your tape streamer?", sz_size);
2377 if (tmp == NULL) {
[3169]2378 log_to_screen("User has chosen not to backup the PC");
2379 finish(1);
[128]2380 }
[3377]2381 bkpinfo->internal_tape_block_size = atol(tmp);
2382 mr_free(sz_size);
2383 mr_free(tmp);
2384
[3169]2385 if (bkpinfo->internal_tape_block_size <= 0) {
2386 log_to_screen("User has chosen not to backup the PC");
2387 finish(1);
2388 }
2389
2390 bkpinfo->media_size = 0;
[3150]2391 log_msg(4, "media_size = %ld", bkpinfo->media_size);
[3169]2392
[2993]2393 bkpinfo->use_obdr = ask_me_yes_or_no
2394 ("Do you want to activate OBDR support for your tapes ?");
2395 if (bkpinfo->use_obdr) {
2396 log_msg(4, "obdr mode = TRUE");
2397 } else {
2398 log_msg(4, "obdr mode = FALSE");
2399 }
[128]2400 if (archiving_to_media) {
[2771]2401 if ((compression_type = which_compression_type()) == NULL) {
2402 log_to_screen("User has chosen not to backup the PC");
2403 finish(1);
2404 }
[3191]2405 if ((bkpinfo->compression_level = which_compression_level()) == -1) {
[541]2406 log_to_screen("User has chosen not to backup the PC");
[128]2407 finish(1);
2408 }
2409 }
2410 break;
[1]2411
2412
2413
[2380]2414 case netfs:
2415 /* Never try to eject a NETFS device */
[1848]2416 bkpinfo->please_dont_eject = TRUE;
[3191]2417 /* Force NFS to be the protocol by default */
2418 if (bkpinfo->netfs_proto == NULL) {
2419 mr_asprintf(bkpinfo->netfs_proto, "nfs");
2420 }
[1848]2421
[2380]2422 /* Initiate bkpinfo netfs_mount path from running environment if not already done */
[3194]2423 if (bkpinfo->netfs_mount == NULL) {
2424 mr_asprintf(bkpinfo->netfs_mount, "%s", call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f1 | head -n1"));
[128]2425 }
[1]2426#ifdef __FreeBSD__
[128]2427 if (TRUE)
[1]2428#else
[128]2429 if (!bkpinfo->disaster_recovery)
[1]2430#endif
[128]2431 {
[3212]2432 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]2433 log_to_screen("User has chosen not to backup the PC");
[128]2434 finish(1);
2435 }
[3191]2436 mr_free(bkpinfo->netfs_mount);
[3194]2437 mr_asprintf(bkpinfo->netfs_mount, "%s", p);
[128]2438 if (!bkpinfo->restore_data) {
[2771]2439 if ((compression_type = which_compression_type()) == NULL) {
2440 log_to_screen("User has chosen not to backup the PC");
2441 finish(1);
2442 }
[3191]2443
2444 if ((bkpinfo->compression_level = which_compression_level()) == -1) {
[541]2445 log_to_screen("User has chosen not to backup the PC");
[128]2446 finish(1);
2447 }
2448 }
2449 // check whether already mounted - we better remove
2450 // surrounding spaces and trailing '/' for this
[3191]2451 mr_strip_spaces(bkpinfo->netfs_mount);
[2380]2452 if (bkpinfo->netfs_mount[strlen(bkpinfo->netfs_mount) - 1] == '/')
2453 bkpinfo->netfs_mount[strlen(bkpinfo->netfs_mount) - 1] = '\0';
[2847]2454 q = strchr(bkpinfo->netfs_mount, '@');
2455 if (q != NULL) {
2456 /* User found. Store the 2 values */
2457 q++;
2458 /* new netfs mount */
[3013]2459 strcpy(tmp1,q);
[2847]2460 } else {
[3013]2461 strcpy(tmp1,bkpinfo->netfs_mount);
[2847]2462 }
[3191]2463 mr_asprintf(command, "mount | grep \"%s \" | cut -d' ' -f3", tmp1);
[3013]2464 strcpy(bkpinfo->isodir, call_program_and_get_last_line_of_output(command));
[3191]2465 mr_free(command);
[256]2466
[1847]2467 if (!bkpinfo->restore_data) {
[3194]2468 mr_asprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4482 MB
[3191]2469 mr_asprintf(comment, "How much data (in Megabytes) will each media store?");
2470 strcpy(tmp1, sz_size);
2471 mr_free(sz_size);
2472 if (!popup_and_get_string("Size", comment, tmp1, 5)) {
[1847]2473 log_to_screen("User has chosen not to backup the PC");
2474 finish(1);
2475 }
[3191]2476 mr_free(comment);
2477 mr_asprintf(sz_size, "%s", tmp1);
[1847]2478 } else {
[3191]2479 mr_asprintf(sz_size, "0");
[256]2480 }
[3150]2481 bkpinfo->media_size = atoi(sz_size);
[3191]2482 mr_free(sz_size);
2483
[3150]2484 if (bkpinfo->media_size < 0) {
[541]2485 log_to_screen("User has chosen not to backup the PC");
[256]2486 finish(1);
2487 }
[128]2488 }
2489 if (bkpinfo->disaster_recovery) {
[3191]2490 mr_asprintf(command ,"umount %s/isodir 2> /dev/null", bkpinfo->tmpdir);
[3060]2491 paranoid_system(command);
[3191]2492 mr_free(command);
2493
[128]2494 }
[2628]2495 strcpy(tmp1, bkpinfo->netfs_proto);
[3191]2496 if (!popup_and_get_string("Network protocol", "Which protocol should I use (nfs/sshfs/smbfs) ?",tmp1, MAX_STR_LEN)) {
[2628]2497 log_to_screen("User has chosen not to backup the PC");
2498 finish(1);
2499 }
2500 mr_free(bkpinfo->netfs_proto);
[3185]2501 mr_asprintf(bkpinfo->netfs_proto, "%s", tmp1);
[3191]2502
2503 strcpy(tmp1, bkpinfo->netfs_mount);
2504 if (!popup_and_get_string("Network share", "Which remote share should I mount?", tmp1, MAX_STR_LEN)) {
[2628]2505 log_to_screen("User has chosen not to backup the PC");
2506 finish(1);
2507 }
[3191]2508 mr_free(bkpinfo->netfs_mount);
2509 mr_asprintf(bkpinfo->netfs_mount, "%s", tmp1);
[2628]2510
[2847]2511 if (bkpinfo->netfs_user) {
2512 strcpy(tmp1, bkpinfo->netfs_user);
2513 } else {
2514 strcpy(tmp1, "");
2515 }
[3194]2516 if (!popup_and_get_string("Network user", "Which user should I use if any ?",tmp1, MAX_STR_LEN)) {
[2847]2517 log_to_screen("User has chosen not to backup the PC");
2518 finish(1);
2519 }
2520 mr_free(bkpinfo->netfs_user);
2521 if (strcmp(tmp1, "") != 0) {
[3185]2522 mr_asprintf(bkpinfo->netfs_user, "%s", tmp1);
[2847]2523 }
2524
[1858]2525 /* Initiate bkpinfo isodir path from running environment if mount already done */
[2380]2526 if (is_this_device_mounted(bkpinfo->netfs_mount)) {
[3191]2527 strcpy(bkpinfo->isodir, call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f3 | head -n1"));
[1858]2528 } else {
[3278]2529 // Why netfsdir ?
[2380]2530 sprintf(bkpinfo->isodir, "%s/netfsdir", bkpinfo->tmpdir);
[3191]2531 mr_asprintf(command, "mkdir -p %s", bkpinfo->isodir);
[128]2532 run_program_and_log_output(command, 5);
[3191]2533 mr_free(command);
[3111]2534
[2361]2535 if (bkpinfo->restore_data) {
[3111]2536 /* mount th FS read-only in restore mode to avoid any erase of whatever */
[3185]2537 mr_asprintf(tmpro, "-o ro");
[3111]2538 } else {
[3185]2539 mr_asprintf(tmpro, "");
[3111]2540 }
2541
2542 /* Build the mount string */
2543 if (strstr(bkpinfo->netfs_proto, "smbfs")) {
[3185]2544 mr_asprintf(tmp, "mount -t cifs %s %s %s",bkpinfo->netfs_mount, bkpinfo->isodir,tmpro);
[3111]2545 if (bkpinfo->netfs_user) {
2546 mr_strcat(tmp, " -o user=%s", bkpinfo->netfs_user);
[3107]2547 }
[3111]2548 else {
[2380]2549 if (strstr(bkpinfo->netfs_proto, "sshfs")) {
[3185]2550 mr_asprintf(tmp, "sshfs %s ",tmpro);
[2380]2551 } else {
[3185]2552 mr_asprintf(tmp, "mount -t %s -o nolock %s ", bkpinfo->netfs_proto,tmpro);
[2380]2553 }
[3111]2554 if (bkpinfo->netfs_user) {
2555 mr_strcat(tmp, "%s@", bkpinfo->netfs_user);
2556 }
2557 mr_strcat(tmp, "%s %s", bkpinfo->netfs_mount, bkpinfo->isodir);
[2361]2558 }
[1819]2559 run_program_and_log_output(tmp, 3);
[2214]2560 mr_free(tmp);
2561
[128]2562 malloc_string(g_selfmounted_isodir);
2563 strcpy(g_selfmounted_isodir, bkpinfo->isodir);
[3111]2564 }
[128]2565 }
[2380]2566 if (!is_this_device_mounted(bkpinfo->netfs_mount)) {
[3191]2567 popup_and_OK("Please mount that partition before you try to backup to or restore from it.");
[128]2568 finish(1);
2569 }
[3196]2570 if (bkpinfo->netfs_remote_dir == NULL) {
[3205]2571 fatal_error("bkpinfo->netfs_remote_dir should not be NULL");
[3196]2572 }
[2380]2573 strcpy(tmp1, bkpinfo->netfs_remote_dir);
[3212]2574 if (!popup_and_get_string ("Directory", "Which directory within that mountpoint?", tmp1, MAX_STR_LEN)) {
[541]2575 log_to_screen("User has chosen not to backup the PC");
[128]2576 finish(1);
2577 }
[3196]2578 mr_free(bkpinfo->netfs_remote_dir);
[3194]2579 mr_asprintf(bkpinfo->netfs_remote_dir, "%s", tmp1);
[2214]2580
[128]2581 // check whether writable - we better remove surrounding spaces for this
[3194]2582 mr_strip_spaces(bkpinfo->netfs_remote_dir);
[1767]2583
[3212]2584 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]2585 log_to_screen("User has chosen not to backup the PC");
[251]2586 finish(1);
2587 }
2588 log_msg(3, "prefix set to %s", bkpinfo->prefix);
[3191]2589 log_msg(3, "Just set netfs_remote_dir to %s", bkpinfo->netfs_remote_dir);
[128]2590 log_msg(3, "isodir is still %s", bkpinfo->isodir);
2591 break;
[1]2592
[128]2593 case iso:
2594 if (!bkpinfo->disaster_recovery) {
[3212]2595 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]2596 log_to_screen("User has chosen not to backup the PC");
[128]2597 finish(1);
2598 }
2599 if (archiving_to_media) {
[2771]2600 if ((compression_type = which_compression_type()) == NULL) {
2601 log_to_screen("User has chosen not to backup the PC");
2602 finish(1);
2603 }
[3191]2604 if ((bkpinfo->compression_level = which_compression_level()) == -1) {
[541]2605 log_to_screen("User has chosen not to backup the PC");
[128]2606 finish(1);
2607 }
[3191]2608 sprintf(tmp1, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4482 MB
[3212]2609 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]2610 log_to_screen("User has chosen not to backup the PC");
[128]2611 finish(1);
2612 }
[3191]2613 bkpinfo->media_size = atoi(tmp1);
[128]2614 } else {
[3150]2615 bkpinfo->media_size = 650;
[128]2616 }
2617 }
[3212]2618 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]2619 log_to_screen("User has chosen not to backup the PC");
2620 finish(1);
2621 }
2622 log_msg(3, "prefix set to %s", bkpinfo->prefix);
[128]2623 break;
2624 default:
[3196]2625 fatal_error("I, Mojo Jojo, shall defeat those pesky Powerpuff Girls!");
[128]2626 }
[1]2627
[128]2628 if (archiving_to_media) {
[3373]2629 mr_free(bkpinfo->boot_device);
[1]2630#ifdef __FreeBSD__
[3373]2631 mr_asprintf(bkpinfo->boot_device, "%s", call_program_and_get_last_line_of_output("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
[1]2632#else
[3373]2633 mr_asprintf(bkpinfo->boot_device, "%s", call_program_and_get_last_line_of_output("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
[1]2634#endif
[128]2635 i = which_boot_loader(bkpinfo->boot_device);
2636 if (i == 'U') // unknown
2637 {
[1]2638
2639#ifdef __FreeBSD__
[3212]2640 if (!popup_and_get_string("Boot device", "What is your boot device? (e.g. /dev/ad0)", bkpinfo->boot_device, MAX_STR_LEN / 4)) {
[541]2641 log_to_screen("User has chosen not to backup the PC");
[128]2642 finish(1);
2643 }
2644 i = which_boot_loader(bkpinfo->boot_device);
[1]2645#else
[3373]2646 strcpy(tmp1, bkpinfo->boot_device);
2647 if (!popup_and_get_string("Boot device", "What is your boot device? (e.g. /dev/hda)", tmp1, MAX_STR_LEN / 4)) {
[541]2648 log_to_screen("User has chosen not to backup the PC");
[128]2649 finish(1);
2650 }
[3373]2651 mr_free(bkpinfo->boot_device);
2652 mr_asprintf(bkpinfo->boot_device, "%s", tmp1);
2653
2654 if (does_string_exist_in_boot_block(bkpinfo->boot_device, "ELILO")) {
2655 i = 'E';
2656 } else
2657 if (does_string_exist_in_boot_block(bkpinfo->boot_device, "LILO")) {
[128]2658 i = 'L';
2659 } else
[3191]2660 if (does_string_exist_in_boot_block(bkpinfo->boot_device, "GRUB")) {
[128]2661 i = 'G';
2662 } else {
2663 i = 'U';
2664 }
[1]2665#endif
[128]2666 if (i == 'U') {
[3191]2667 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]2668 i = 'R'; // raw
2669 } else {
[3191]2670 log_to_screen("I cannot find your boot loader. Please run mondoarchive with parameters.");
[128]2671 finish(1);
2672 }
2673 }
[1]2674 }
[128]2675 bkpinfo->boot_loader = i;
[3375]2676 bkpinfo->boot_type = mr_boot_type();
2677 /* TODO: Chcek consisytency of boot type and boot loader */
[3191]2678
[3205]2679 if (bkpinfo->include_paths) {
2680 strcpy(tmp1, bkpinfo->include_paths);
2681 mr_free(bkpinfo->include_paths);
2682 } else {
2683 strcpy(tmp1, "/");
2684 }
[3212]2685 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]2686 log_to_screen("User has chosen not to backup the PC");
[128]2687 finish(1);
[1]2688 }
[3191]2689 mr_asprintf(bkpinfo->include_paths, "%s", tmp1);
2690
[2713]2691 tmp = list_of_NETFS_mounts_only();
[128]2692 if (strlen(tmp) > 2) {
[2713]2693 mr_strcat(bkpinfo->exclude_paths, "|%s",tmp);
[128]2694 }
[2214]2695 mr_free(tmp);
[1]2696// NTFS
[3377]2697 strcpy(tmp1, 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};'"));
[2304]2698 if (strlen(tmp1) > 2) {
[3212]2699 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]2700 log_to_screen("User has chosen not to backup the PC");
[128]2701 finish(1);
2702 }
[2304]2703 strncpy(bkpinfo->image_devs, tmp1, MAX_STR_LEN / 4);
[128]2704 }
[1]2705
[2743]2706 if (bkpinfo->exclude_paths != NULL ) {
[3062]2707 strncpy(p,bkpinfo->exclude_paths,(16*MAX_STR_LEN)-1);
[2743]2708 } else {
2709 p[0] = '\0';
2710 }
[3062]2711 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]2712 if (p == NULL) {
[541]2713 log_to_screen("User has chosen not to backup the PC");
[128]2714 finish(1);
2715 }
[2697]2716 mr_free(bkpinfo->exclude_paths);
[3185]2717 mr_asprintf(tmp, "%s", p);
[2697]2718 bkpinfo->exclude_paths = tmp;
2719
[3212]2720 mr_asprintf(oldtmp, "%s", bkpinfo->tmpdir);
2721 if (bkpinfo->tmpdir != NULL ) {
2722 strncpy(p,bkpinfo->tmpdir,(16*MAX_STR_LEN)-1);
2723 } else {
2724 p[0] = '\0';
2725 }
2726 if (!popup_and_get_string("Temporary directory", "Please enter your temporary directory.", p, (4*MAX_STR_LEN)-1)) {
[2220]2727 log_to_screen("User has chosen not to backup the PC");
2728 finish(1);
2729 }
[3154]2730 /* if modified to another path */
[3212]2731 if (strcmp(p,oldtmp) != 0) {
2732 setup_tmpdir(p);
[3154]2733 }
[3212]2734 mr_free(oldtmp);
2735
2736 mr_asprintf(oldtmp, "%s", bkpinfo->scratchdir);
2737 if (bkpinfo->scratchdir != NULL ) {
2738 strncpy(p,bkpinfo->scratchdir,(16*MAX_STR_LEN)-1);
2739 } else {
2740 p[0] = '\0';
2741 }
2742 if (!popup_and_get_string("Scratch directory", "Please enter your scratch directory.", p, (4*MAX_STR_LEN)-1)) {
[2220]2743 log_to_screen("User has chosen not to backup the PC");
2744 finish(1);
2745 }
[3154]2746 /* if modified to another path */
[3212]2747 if (strcmp(p,oldtmp) != 0) {
2748 setup_scratchdir(p);
[3154]2749 }
[3212]2750 mr_free(oldtmp);
2751
[2772]2752 if (ask_me_yes_or_no("Do you want to backup extended attributes?")) {
2753 if (find_home_of_exe("getfattr")) {
[3191]2754 mr_free(g_getfattr);
[3185]2755 mr_asprintf(g_getfattr,"getfattr");
[2772]2756 }
2757 if (find_home_of_exe("getfacl")) {
[3191]2758 mr_free(g_getfacl);
[3185]2759 mr_asprintf(g_getfacl,"getfacl");
[2772]2760 }
[3171]2761 log_it("Backup of extended attributes");
[2772]2762 }
[1575]2763// Interactive mode:
2764#ifdef __IA64__
2765 bkpinfo->make_cd_use_lilo = TRUE;
2766#else
[128]2767 bkpinfo->make_cd_use_lilo = FALSE;
[1575]2768#endif
[128]2769 bkpinfo->backup_data = TRUE;
[2771]2770 if (strcmp(compression_type,"lzo") == 0) {
2771 strcpy(bkpinfo->zip_exe, "lzop");
2772 strcpy(bkpinfo->zip_suffix, "lzo");
2773 } else if (strcmp(compression_type,"gzip") == 0) {
2774 strcpy(bkpinfo->zip_exe, "gzip");
2775 strcpy(bkpinfo->zip_suffix, "gz");
[3191]2776 } else if (strcmp(compression_type,"lzma") == 0) {
[2771]2777 //strcpy(bkpinfo->zip_exe, "xy");
2778 //strcpy(bkpinfo->zip_suffix, "xy");
2779 } else if (strcmp(compression_type,"bzip2") == 0) {
2780 strcpy(bkpinfo->zip_exe, "bzip2");
2781 strcpy(bkpinfo->zip_suffix, "bz2");
2782 } else {
2783 bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0';
2784 }
[3350]2785#if __FreeBSD__ == 5
2786 strcpy(bkpinfo->kernel_path, "/boot/kernel/kernel");
2787#elif __FreeBSD__ == 4
2788 strcpy(bkpinfo->kernel_path, "/kernel");
2789#elif linux
2790 if (figure_out_kernel_path_interactively_if_necessary(bkpinfo->kernel_path)) {
2791 fatal_error("Kernel not found. Please specify manually with the '-k' switch.");
2792 }
2793#else
2794#error "I don't know about this system!"
2795#endif
[2774]2796
[3350]2797
[128]2798 bkpinfo->verify_data =
2799 ask_me_yes_or_no
[541]2800 ("Will you want to verify your backups after Mondo has created them?");
[1]2801
[128]2802 if (!ask_me_yes_or_no
[541]2803 ("Are you sure you want to proceed? Hit 'no' to abort.")) {
2804 log_to_screen("User has chosen not to backup the PC");
[128]2805 finish(1);
2806 }
2807 } else {
2808 bkpinfo->restore_data = TRUE; // probably...
2809 }
[2774]2810 mr_free(compression_type);
[1]2811
[128]2812 if (bkpinfo->backup_media_type == iso
[2380]2813 || bkpinfo->backup_media_type == netfs) {
[128]2814 g_ISO_restore_mode = TRUE;
2815 }
[1]2816#ifdef __FreeSD__
2817// skip
2818#else
[2380]2819 if (bkpinfo->backup_media_type == netfs) {
[3191]2820 log_msg(3, "I think the Remote mount is mounted at %s", bkpinfo->isodir);
[128]2821 }
2822 log_it("isodir = %s", bkpinfo->isodir);
[3191]2823 if (bkpinfo->netfs_mount) {
2824 log_it("netfs_mount = '%s'", bkpinfo->netfs_mount);
[2682]2825 }
[2380]2826 if (bkpinfo->netfs_user) {
2827 log_it("netfs_user = '%s'", bkpinfo->netfs_user);
[2224]2828 }
[3191]2829 if (bkpinfo->netfs_proto) {
2830 log_it("netfs_proto = '%s'", bkpinfo->netfs_proto);
2831 }
[1]2832#endif
2833
[128]2834 log_it("media device = %s", bkpinfo->media_device);
[3150]2835 log_it("media size = %ld", bkpinfo->media_size);
[3015]2836 log_it("media type = %s", bkptype_to_string(bkpinfo->backup_media_type));
[3191]2837 if (bkpinfo->prefix) {
2838 log_it("prefix = %s", bkpinfo->prefix);
2839 }
[128]2840 log_it("compression = %ld", bkpinfo->compression_level);
[2473]2841 log_it("exclude_path = %s", bkpinfo->exclude_paths);
[3205]2842 if (bkpinfo->include_paths) {
2843 log_it("include_path = %s", bkpinfo->include_paths);
2844 }
[2424]2845
2846 /* Handle devices passed in bkpinfo and print result */
[3194]2847 /* the mr_make_devlist_from_pathlist function appends */
[3191]2848 /* to the *_paths variables so copy before */
[2713]2849 mr_make_devlist_from_pathlist(bkpinfo->exclude_paths, 'E');
2850 mr_make_devlist_from_pathlist(bkpinfo->include_paths, 'I');
[2424]2851
[128]2852 log_it("scratchdir = '%s'", bkpinfo->scratchdir);
2853 log_it("tmpdir = '%s'", bkpinfo->tmpdir);
[3191]2854 if (bkpinfo->image_devs) {
2855 log_it("image_devs = '%s'", bkpinfo->image_devs);
2856 }
2857 log_it("boot_device = '%s' (loader=%c)", bkpinfo->boot_device, bkpinfo->boot_loader);
[3150]2858 if (bkpinfo->media_size < 0) {
[128]2859 if (archiving_to_media) {
2860 fatal_error("Media size is less than zero.");
2861 } else {
2862 log_msg(2, "Warning - media size is less than zero.");
[3150]2863 bkpinfo->media_size = 0;
[128]2864 }
[1]2865 }
[128]2866 paranoid_free(sz_size);
[2305]2867 paranoid_free(tmp1);
[128]2868 return (0);
[1]2869}
2870
2871
2872/**
[2713]2873 * Get a |-separated list of NETFS mounts.
[1]2874 * @return The list created.
[2713]2875 * @note The return value points to allocated string that needs to be freed
[1]2876 * @bug Even though we only want the mounts, the devices are still checked.
2877 */
[2380]2878char *list_of_NETFS_mounts_only(void)
[1]2879{
[2214]2880 char *exclude_these_directories = NULL;
[1]2881
[3185]2882 mr_asprintf(exclude_these_directories,"%s", 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]2883 log_msg(9,"list_of_NETFS_mounts_only returns %s",exclude_these_directories);
[2713]2884 return(exclude_these_directories);
[1]2885}
2886
2887/* @} - end of utilityGroup */
2888
2889
2890
2891
2892
2893/**
2894 * Create a randomly-named FIFO. The format is @p stub "." [random] [random] where
2895 * [random] is a random number between 1 and 32767.
2896 * @param store_name_here Where to store the new filename.
2897 * @param stub A random number will be appended to this to make the FIFO's name.
2898 * @ingroup deviceGroup
2899 */
[128]2900void make_fifo(char *store_name_here, char *stub)
[1]2901{
[3352]2902 char *tmp = NULL;
[1]2903
[128]2904 assert_string_is_neither_NULL_nor_zerolength(stub);
[1]2905
[128]2906 sprintf(store_name_here, "%s%d%d", stub, (int) (random() % 32768),
2907 (int) (random() % 32768));
2908 make_hole_for_file(store_name_here);
2909 mkfifo(store_name_here, S_IRWXU | S_IRWXG);
[3352]2910 mr_asprintf(tmp, "chmod 770 %s", store_name_here);
[128]2911 paranoid_system(tmp);
[3352]2912 mr_free(tmp);
[1]2913}
2914
2915
2916
2917/**
2918 * @addtogroup deviceGroup
2919 * @{
2920 */
2921/**
2922 * If we can read @p dev, set @p output to it.
2923 * If @p dev cannot be read, set @p output to "".
2924 * @param dev The device to check for.
2925 * @param output Set to @p dev if @p dev exists, "" otherwise.
2926 * @return TRUE if @p dev exists, FALSE if it doesn't.
2927 */
[128]2928bool set_dev_to_this_if_rx_OK(char *output, char *dev)
[1]2929{
[3352]2930 char *command = NULL;
2931 bool ret=FALSE;
[1]2932
[128]2933 if (!dev || dev[0] == '\0') {
2934 output[0] = '\0';
[3352]2935 return(ret);
[128]2936 }
[1]2937// assert_string_is_neither_NULL_nor_zerolength(dev);
[2931]2938 if (!bkpinfo->please_dont_eject) {
2939 log_msg(10, "Injecting %s", dev);
2940 inject_device(dev);
2941 }
[128]2942 if (!does_file_exist(dev)) {
2943 log_msg(10, "%s doesn't exist. Returning FALSE.", dev);
[3352]2944 return(ret);
[128]2945 }
[3352]2946 mr_asprintf(command, "dd bs=%ld count=1 if=%s of=/dev/null &> /dev/null", 512L, dev);
2947 if (!run_program_and_log_output(command, FALSE) && !run_program_and_log_output(command, FALSE)) {
[128]2948 strcpy(output, dev);
2949 log_msg(4, "Found it - %s", dev);
[3352]2950 ret = TRUE;
[128]2951 } else {
2952 output[0] = '\0';
2953 log_msg(4, "It's not %s", dev);
2954 }
[3352]2955 mr_free(command);
2956 return(ret);
[1]2957}
2958
2959
2960
2961
2962
2963/**
2964 * Find out what number CD is in the drive.
2965 * @param bkpinfo The backup information structure. The @c bkpinfo->media_device field is the only one used.
2966 * @return The current CD number, or -1 if it could not be found.
2967 * @note If the CD is not mounted, it will be mounted
2968 * (and remain mounted after this function returns).
2969 */
[1645]2970int what_number_cd_is_this()
[1]2971{
[128]2972 int cd_number = -1;
[2211]2973 char *mountdev = NULL;
2974 char *tmp = NULL;
[1]2975
[128]2976 assert(bkpinfo != NULL);
[1]2977// log_it("Asking what_number_cd_is_this");
[128]2978 if (g_ISO_restore_mode) {
[3185]2979 mr_asprintf(tmp, "mount | grep iso9660 | awk '{print $3;}'");
[1]2980
[3185]2981 mr_asprintf(mountdev, "%s%s", call_program_and_get_last_line_of_output(tmp), "/archives/THIS-CD-NUMBER");
[128]2982 cd_number = atoi(last_line_of_file(mountdev));
2983 paranoid_free(mountdev);
2984 paranoid_free(tmp);
[2211]2985
[128]2986 return (cd_number);
2987 }
[1]2988
[3185]2989 mr_asprintf(mountdev, "%s", bkpinfo->media_device);
[128]2990 if (!mountdev[0]) {
2991 log_it
2992 ("(what_number_cd_is_this) Warning - media_device unknown. Finding out...");
2993 find_cdrom_device(bkpinfo->media_device, FALSE);
2994 }
2995 if (!is_this_device_mounted(MNT_CDROM)) {
[1741]2996 if (bkpinfo->backup_media_type == usb) {
2997 mount_USB_here(mountdev, MNT_CDROM);
2998 } else {
2999 mount_CDROM_here(mountdev, MNT_CDROM);
3000 }
[128]3001 }
3002 paranoid_free(mountdev);
[2211]3003
3004 cd_number = atoi(last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER"));
[128]3005 return (cd_number);
[1]3006}
3007
3008
3009/**
3010 * Find out what device is mounted as root (/).
3011 * @return Root device.
3012 * @note The returned string points to static storage and will be overwritten with every call.
3013 * @bug A bit of a misnomer; it's actually finding out the root device.
3014 * The mountpoint (where it's mounted) will obviously be '/'.
3015 */
[3205]3016char *where_is_root_mounted() {
[1]3017
[3205]3018/*@ buffers **************** */
3019static char tmp[MAX_STR_LEN];
[1]3020
[3205]3021
[1]3022#ifdef __FreeBSD__
[3205]3023 strcpy(tmp, call_program_and_get_last_line_of_output("mount | grep \" on / \" | cut -d' ' -f1"));
[1]3024#else
[3205]3025 strcpy(tmp, call_program_and_get_last_line_of_output("mount | grep \" on / \" | cut -d' ' -f1 | sed s/[0-9]// | sed s/[0-9]//"));
[128]3026 if (strstr(tmp, "/dev/cciss/")) {
[3205]3027 strcpy(tmp, call_program_and_get_last_line_of_output("mount | grep \" on / \" | cut -d' ' -f1 | cut -dp -f1"));
[128]3028 }
3029 if (strstr(tmp, "/dev/md")) {
[3205]3030 strcpy(tmp, call_program_and_get_last_line_of_output("mount | grep \" on / \" | cut -d' ' -f1"));
[128]3031 }
[1]3032#endif
3033
[3205]3034return (tmp);
[1]3035}
3036
3037
3038/**
3039 * Find out which boot loader is in use.
3040 * @param which_device Device to look for the boot loader on.
3041 * @return 'L' for LILO, 'E'for ELILO, 'G' for GRUB, 'B' or 'D' for FreeBSD boot loaders, or 'U' for Unknown.
3042 * @note Under Linux, all drives are examined, not just @p which_device.
3043 */
3044#ifdef __FreeBSD__
[128]3045char which_boot_loader(char *which_device)
[1]3046{
[128]3047 int count_lilos = 0;
3048 int count_grubs = 0;
3049 int count_boot0s = 0;
3050 int count_dangerouslydedicated = 0;
[1]3051
[128]3052 log_it("looking at drive %s's MBR", which_device);
3053 if (does_string_exist_in_boot_block(which_device, "GRUB")) {
3054 count_grubs++;
3055 }
3056 if (does_string_exist_in_boot_block(which_device, "LILO")) {
3057 count_lilos++;
3058 }
3059 if (does_string_exist_in_boot_block(which_device, "Drive")) {
3060 count_boot0s++;
3061 }
3062 if (does_string_exist_in_first_N_blocks
3063 (which_device, "FreeBSD/i386", 17)) {
3064 count_dangerouslydedicated++;
3065 }
3066 log_it("%d grubs and %d lilos and %d elilos and %d boot0s and %d DD\n",
3067 count_grubs, count_lilos, count_elilos, count_boot0s,
3068 count_dangerouslydedicated);
[1]3069
[128]3070 if (count_grubs && !count_lilos) {
3071 return ('G');
3072 } else if (count_lilos && !count_grubs) {
3073 return ('L');
3074 } else if (count_grubs == 1 && count_lilos == 1) {
3075 log_it("I'll bet you used to use LILO but switched to GRUB...");
3076 return ('G');
3077 } else if (count_boot0s == 1) {
3078 return ('B');
3079 } else if (count_dangerouslydedicated) {
3080 return ('D');
3081 } else {
3082 log_it("Unknown boot loader");
3083 return ('U');
3084 }
[1]3085}
3086
3087#else
3088
[128]3089char which_boot_loader(char *which_device)
[1]3090{
[128]3091 /*@ buffer ***************************************************** */
[2241]3092 char *list_drives_cmd = NULL;
[128]3093 char *current_drive;
[3060]3094 char *tmp;
[1]3095
[128]3096 /*@ pointers *************************************************** */
3097 FILE *pdrives;
[1]3098
[128]3099 /*@ int ******************************************************** */
3100 int count_lilos = 0;
3101 int count_grubs = 0;
[1]3102
[128]3103 /*@ end vars *************************************************** */
[1]3104
3105#ifdef __IA64__
[128]3106 /* No choice for it */
3107 return ('E');
[1]3108#endif
[3422]3109 if (bkpinfo->boot_type == EFI) {
3110 /* No choice for it */
3111 return ('E');
3112 }
3113
3114 if (bkpinfo->boot_type == UEFI) {
3115 /* hardcoded for now. We can for sure do abetter job here ! */
3116 /* RHEL, SLES, Mageia, Debian, Ubuntu use grub as boot loader as it seems for UEFI */
3117 return ('G');
3118 }
3119
[128]3120 assert(which_device != NULL);
[1]3121
[3377]3122 mr_asprintf(list_drives_cmd, "mr-parted2fdisk -l 2>/dev/null | grep \"/dev/.*:\" | tr -s ':' ' ' | tr -s ' ' '\n' | grep /dev/; echo %s", where_is_root_mounted());
[128]3123 log_it("list_drives_cmd = %s", list_drives_cmd);
[1]3124
[128]3125 if (!(pdrives = popen(list_drives_cmd, "r"))) {
3126 log_OS_error("Unable to open list of drives");
[2241]3127 mr_free(list_drives_cmd);
[128]3128 return ('\0');
[1]3129 }
[2241]3130 mr_free(list_drives_cmd);
3131
[3422]3132 malloc_string(current_drive);
3133 if (bkpinfo->boot_type == BIOS) {
3134 for (tmp = fgets(current_drive, MAX_STR_LEN, pdrives); !feof(pdrives) && (tmp != NULL); tmp = fgets(current_drive, MAX_STR_LEN, pdrives)) {
[1451]3135 strip_spaces(current_drive);
[3422]3136 log_it("looking at drive %s's MBR", current_drive);
[1451]3137 if (does_string_exist_in_boot_block(current_drive, "GRUB")) {
3138 count_grubs++;
3139 strcpy(which_device, current_drive);
3140 break;
3141 }
3142 if (does_string_exist_in_boot_block(current_drive, "LILO")) {
3143 count_lilos++;
3144 strcpy(which_device, current_drive);
3145 break;
3146 }
3147 }
3148 if (pclose(pdrives)) {
3149 log_OS_error("Cannot pclose pdrives");
3150 }
3151 log_it("%d grubs and %d lilos\n", count_grubs, count_lilos);
3152 if (count_grubs && !count_lilos) {
[3422]3153 paranoid_free(current_drive);
[1451]3154 return ('G');
3155 } else if (count_lilos && !count_grubs) {
[3422]3156 paranoid_free(current_drive);
[1451]3157 return ('L');
3158 } else if (count_grubs == 1 && count_lilos == 1) {
3159 log_it("I'll bet you used to use LILO but switched to GRUB...");
[3422]3160 paranoid_free(current_drive);
[1451]3161 return ('G');
3162 } else {
[3422]3163 // We need to look on each partition then
3164 mr_asprintf(list_drives_cmd, "mr-parted2fdisk -l 2>/dev/null | grep -E \"^/dev/\" | tr -s ':' ' ' | tr -s ' ' '\n' | grep /dev/");
3165 log_it("list_drives_cmd = %s", list_drives_cmd);
3166
3167 if (!(pdrives = popen(list_drives_cmd, "r"))) {
3168 log_OS_error("Unable to open list of drives");
3169 mr_free(list_drives_cmd);
3170 paranoid_free(current_drive);
3171 return ('\0');
3172 }
3173 mr_free(list_drives_cmd);
3174
3175 for (tmp = fgets(current_drive, MAX_STR_LEN, pdrives); !feof(pdrives) && (tmp != NULL);
3176 tmp = fgets(current_drive, MAX_STR_LEN, pdrives)) {
3177 strip_spaces(current_drive);
3178 log_it("looking at partition %s's BR", current_drive);
3179 if (does_string_exist_in_boot_block(current_drive, "GRUB")) {
3180 count_grubs++;
3181 strcpy(which_device, current_drive);
3182 break;
3183 }
3184 if (does_string_exist_in_boot_block(current_drive, "LILO")) {
3185 count_lilos++;
3186 strcpy(which_device, current_drive);
3187 break;
3188 }
3189 }
3190 if (pclose(pdrives)) {
3191 log_OS_error("Cannot pclose pdrives");
3192 }
3193 log_it("%d grubs and %d lilos\n", count_grubs, count_lilos);
3194 paranoid_free(current_drive);
3195 if (count_grubs && !count_lilos) {
3196 return ('G');
3197 } else if (count_lilos && !count_grubs) {
3198 return ('L');
3199 } else if (count_grubs == 1 && count_lilos == 1) {
3200 log_it("I'll bet you used to use LILO but switched to GRUB...");
3201 return ('G');
3202 } else {
3203 log_it("Unknown boot loader");
3204 return ('U');
3205 }
[1451]3206 }
[128]3207 }
[1]3208}
3209#endif
3210
3211
3212
3213
3214/**
3215 * Write zeroes over the first 16K of @p device.
3216 * @param device The device to zero.
3217 * @return 0 for success, 1 for failure.
3218 */
[128]3219int zero_out_a_device(char *device)
[1]3220{
[128]3221 FILE *fout;
3222 int i;
[1]3223
[128]3224 assert_string_is_neither_NULL_nor_zerolength(device);
[1]3225
[128]3226 log_it("Zeroing drive %s", device);
3227 if (!(fout = fopen(device, "w"))) {
3228 log_OS_error("Unable to open/write to device");
3229 return (1);
3230 }
3231 for (i = 0; i < 16384; i++) {
3232 fputc('\0', fout);
3233 }
3234 paranoid_fclose(fout);
3235 log_it("Device successfully zeroed.");
3236 return (0);
[1]3237}
3238
3239/**
3240 * Return the device pointed to by @p incoming.
3241 * @param incoming The device to resolve symlinks for.
3242 * @return The path to the real device file.
3243 * @note The returned string points to static storage that will be overwritten with each call.
3244 * @bug Won't work with file v4.0; needs to be written in C.
3245 */
[128]3246char *resolve_softlinks_to_get_to_actual_device_file(char *incoming)
[1]3247{
[128]3248 static char output[MAX_STR_LEN];
[3352]3249 char *command = NULL;
3250 char *curr_fname = NULL;
[2214]3251 char *scratch = NULL;
3252 char *tmp = NULL;
[128]3253 char *p;
3254
3255 struct stat statbuf;
3256 malloc_string(curr_fname);
3257 if (!does_file_exist(incoming)) {
3258 log_it
3259 ("resolve_softlinks_to_get_to_actual_device_file --- device not found");
3260 strcpy(output, incoming);
3261 } else {
3262 strcpy(curr_fname, incoming);
3263 lstat(curr_fname, &statbuf);
3264 while (S_ISLNK(statbuf.st_mode)) {
3265 log_msg(1, "curr_fname = %s", curr_fname);
[3352]3266 mr_asprintf(command, "file %s", curr_fname);
[3185]3267 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
[3352]3268 mr_free(command);
[128]3269 for (p = tmp + strlen(tmp); p != tmp && *p != '`' && *p != ' ';
3270 p--);
3271 p++;
[3185]3272 mr_asprintf(scratch, "%s", p);
[128]3273 for (p = scratch; *p != '\0' && *p != '\''; p++);
3274 *p = '\0';
[2214]3275 log_msg(0, "curr_fname %s --> '%s' --> %s", curr_fname, tmp, scratch);
3276 mr_free(tmp);
3277
[128]3278 if (scratch[0] == '/') {
3279 strcpy(curr_fname, scratch); // copy whole thing because it's an absolute softlink
3280 } else { // copy over the basename cos it's a relative softlink
3281 p = curr_fname + strlen(curr_fname);
3282 while (p != curr_fname && *p != '/') {
3283 p--;
3284 }
3285 if (*p == '/') {
3286 p++;
3287 }
3288 strcpy(p, scratch);
3289 }
[2214]3290 mr_free(scratch);
[128]3291 lstat(curr_fname, &statbuf);
3292 }
3293 strcpy(output, curr_fname);
3294 log_it("resolved %s to %s", incoming, output);
[1]3295 }
[128]3296 paranoid_free(curr_fname);
3297 return (output);
[1]3298}
3299
3300/* @} - end of deviceGroup */
3301
3302/**
3303 * Return the type of partition format (GPT or MBR)
3304 */
3305char *which_partition_format(const char *drive)
3306{
[3237]3307 char *output = NULL;
[2214]3308 char *tmp = NULL;
[3352]3309 char *command = NULL;
[3377]3310 mr_asprintf(command, "mr-parted2fdisk -l %s 2>/dev/null | grep 'EFI GPT'", drive);
[3185]3311 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
[3352]3312 mr_free(command);
3313
[128]3314 if (strstr(tmp, "GPT") == NULL) {
[3237]3315 mr_asprintf(output, "%s", "MBR");
[128]3316 } else {
[3237]3317 mr_asprintf(output, "%s", "GPT");
[128]3318 }
[2214]3319 mr_free(tmp);
3320
[3263]3321 log_msg(0, "Found %s partition table format type on %s", output, drive);
[128]3322 return (output);
[1]3323}
3324/* @} - end of deviceGroup */
[3374]3325
3326
Note: See TracBrowser for help on using the repository browser.