source: MondoRescue/branches/3.3/mondo/src/common/libmondo-devices.c@ 3648

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