source: MondoRescue/trunk/mondo/mondo/common/libmondo-devices.c@ 688

Last change on this file since 688 was 688, checked in by bcornec, 18 years ago

Huge memory management patch.
Still not finished but a lot as been done.
What remains is around some functions returning strings, and some structure members.
(Could not finish due to laptop failure !)

  • Property svn:keywords set to Id
File size: 65.7 KB
RevLine 
[688]1/*
2 * $Id: libmondo-devices.c 688 2006-07-17 13:44:46Z bcornec $
[171]3 * Subroutines for handling devices
4 */
[1]5/**
6 * @file
7 * Functions to handle interactions with backup devices.
8 */
9
10#include "my-stuff.h"
11#include "mondostructures.h"
12#include "libmondo-files-EXT.h"
13#include "libmondo-devices.h"
14#include "libmondo-string-EXT.h"
15#include "libmondo-tools-EXT.h"
[507]16#include "newt-specific-EXT.h"
[1]17#include "libmondo-fork-EXT.h"
18#include "libmondo-stream-EXT.h"
19
[146]20#include <sys/ioctl.h>
[1]21#include <sys/types.h>
[688]22#include <unistd.h>
[1]23#ifdef __FreeBSD__
24#define DKTYPENAMES
25#define FSTYPENAMES
26#include <sys/disklabel.h>
27#include <sys/disk.h>
28#elif linux
29#define u64 unsigned long long
[59]30#include <linux/fs.h> /* for BLKGETSIZE64 */
[1]31#include <linux/hdreg.h>
32#endif
33
34/*@unused@*/
[59]35//static char cvsid[] = "$Id: libmondo-devices.c 688 2006-07-17 13:44:46Z bcornec $";
[1]36
37extern int g_current_media_number;
38extern double g_kernel_version;
39
40extern bool g_ISO_restore_mode;
41extern struct s_bkpinfo *g_bkpinfo_DONTUSETHIS;
42extern char *g_erase_tmpdir_and_scratchdir;
[75]43extern char *g_selfmounted_isodir;
[1]44
[171]45static char *g_cdrw_drive_is_here = NULL;
46static char *g_cdrom_drive_is_here = NULL;
47static char *g_dvd_drive_is_here = NULL;
[1]48
49
50/**
51 * ????? @bug ?????
52 * @ingroup globalGroup
53 */
[59]54bool g_restoring_live_from_cd = FALSE;
[1]55
[59]56extern t_bkptype g_backup_media_type; // set by main()
[1]57
58
59
60
61void set_g_cdrom_and_g_dvd_to_bkpinfo_value(struct s_bkpinfo *bkpinfo)
62{
[171]63 if (bkpinfo->media_device != NULL) {
[688]64 paranoid_alloc(g_cdrom_drive_is_here, bkpinfo->media_device); // just in case
[171]65 }
66 if (bkpinfo->media_device != NULL) {
[688]67 paranoid_alloc(g_dvd_drive_is_here, bkpinfo->media_device); // just in case
[171]68 }
[1]69}
70
71
72
73/**
74 * Retract all CD trays and wait for autorun to complete.
75 * @ingroup deviceGroup
76 */
77void retract_CD_tray_and_defeat_autorun(void)
78{
79// log_it("rctada: Retracting all CD trays", __LINE__);
[59]80 if (strlen(g_cdrom_drive_is_here) > 0) {
81 inject_device(g_cdrom_drive_is_here);
82 }
83 if (strlen(g_dvd_drive_is_here) > 0) {
84 inject_device(g_dvd_drive_is_here);
85 }
86 if (strlen(g_cdrw_drive_is_here) > 0) {
87 inject_device(g_cdrw_drive_is_here);
88 }
[1]89// log_it("rctada: killing autorun");
90// run_program_and_log_output("killall autorun", TRUE);
[59]91 if (!run_program_and_log_output("ps | grep autorun | grep -v grep", 5)) {
92 log_it("autorun detected; sleeping for 2 seconds");
93 sleep(2);
94 }
95 log_it("rctada: Unmounting all CD drives", __LINE__);
96 run_program_and_log_output("umount /dev/cdr* /dev/dvd*", 5);
[1]97}
98
99
100
101/**
102 * Determine whether we're booted off a ramdisk.
103 * @return @c TRUE (we are) or @c FALSE (we aren't).
104 * @ingroup utilityGroup
105 */
[59]106bool am_I_in_disaster_recovery_mode(void)
[1]107{
[59]108 char *tmp, *comment;
109 bool is_this_a_ramdisk = FALSE;
[1]110
[146]111 asprintf(&tmp, where_is_root_mounted());
112 asprintf(&comment, "root is mounted at %s\n", tmp);
[59]113 log_msg(0, comment);
[146]114 paranoid_free(comment);
115
[59]116 log_msg(0,
117 "No, Schlomo, 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().",
118 tmp);
[1]119
120#ifdef __FreeBSD__
[59]121 if (strstr(tmp, "/dev/md")) {
122 is_this_a_ramdisk = TRUE;
123 }
[1]124#else
[59]125 if (!strncmp(tmp, "/dev/ram", 8)
126 || (!strncmp(tmp, "/dev/rd", 7) && !strcmp(tmp, "/dev/rd/")
127 && strncmp(tmp, "/dev/rd/cd", 10)) || strstr(tmp, "rootfs")
128 || !strcmp(tmp, "/dev/root")) {
129 is_this_a_ramdisk = TRUE;
130 } else {
131 is_this_a_ramdisk = FALSE;
132 }
[1]133#endif
[146]134 paranoid_free(tmp);
[1]135
[59]136 if (is_this_a_ramdisk) {
137 if (!does_file_exist("/THIS-IS-A-RAMDISK")
138 && !does_file_exist("/tmp/mountlist.txt.sample")) {
139 log_to_screen
[507]140 (_("Using /dev/root is stupid of you but I'll forgive you."));
[59]141 is_this_a_ramdisk = FALSE;
142 }
143 }
144 if (does_file_exist("/THIS-IS-A-RAMDISK")) {
145 is_this_a_ramdisk = TRUE;
146 }
147 log_msg(1, "Is this a ramdisk? result = %d", is_this_a_ramdisk);
148 return (is_this_a_ramdisk);
[1]149}
150
151
152/**
153 * Turn @c bkpinfo->backup_media_type into a human-readable string.
154 * @return The human readable string (e.g. @c cdr becomes <tt>"cdr"</tt>).
155 * @note The returned string points to static storage that will be overwritten with each call.
156 * @ingroup stringGroup
157 */
[171]158char *bkptype_to_string(t_bkptype bt)
[1]159{
[171]160 char *output = NULL;
[146]161
162 paranoid_free(output);
163
[59]164 switch (bt) {
165 case none:
[507]166 asprintf(&output, _("none"));
[1]167 break;
[59]168 case iso:
[507]169 asprintf(&output, _("iso"));
[1]170 break;
[59]171 case cdr:
[507]172 asprintf(&output, _("cdr"));
[1]173 break;
[59]174 case cdrw:
[507]175 asprintf(&output, _("cdrw"));
[1]176 break;
[59]177 case cdstream:
[507]178 asprintf(&output, _("cdstream"));
[1]179 break;
[59]180 case nfs:
[507]181 asprintf(&output, _("nfs"));
[1]182 break;
[59]183 case tape:
[507]184 asprintf(&output, _("tape"));
[1]185 break;
[59]186 case udev:
[507]187 asprintf(&output, _("udev"));
[1]188 break;
[59]189 default:
[507]190 asprintf(&output, _("default"));
[59]191 }
[147]192 return (output);
[1]193}
194
195
196/**
197 * @addtogroup deviceGroup
198 * @{
199 */
200/**
201 * Eject the tray of the specified CD device.
202 * @param dev The device to eject.
203 * @return the return value of the @c eject command. (0=success, nonzero=failure)
204 */
[59]205int eject_device(char *dev)
[1]206{
[59]207 char *command;
208 int res1 = 0, res2 = 0;
[1]209
[59]210 if (IS_THIS_A_STREAMING_BACKUP(g_backup_media_type)
211 && g_backup_media_type != udev) {
[146]212 asprintf(&command, "mt -f %s offline", dev);
[59]213 res1 = run_program_and_log_output(command, 1);
[146]214 paranoid_free(command);
[59]215 } else {
216 res1 = 0;
217 }
[1]218
219#ifdef __FreeBSD__
[59]220 if (strstr(dev, "acd")) {
[146]221 asprintf(&command, "cdcontrol -f %s eject", dev);
[59]222 } else {
[146]223 asprintf(&command, "camcontrol eject `echo %s | sed 's|/dev/||'`",
[59]224 dev);
225 }
[1]226#else
[146]227 asprintf(&command, "eject %s", dev);
[1]228#endif
229
[59]230 log_msg(3, "Ejecting %s", dev);
231 res2 = run_program_and_log_output(command, 1);
232 paranoid_free(command);
233 if (res1 && res2) {
234 return (1);
235 } else {
236 return (0);
237 }
[1]238}
239
[146]240
[1]241/**
242 * Load (inject) the tray of the specified CD device.
243 * @param dev The device to load/inject.
244 * @return 0 for success, nonzero for failure.
245 */
[59]246int inject_device(char *dev)
[1]247{
[59]248 char *command;
249 int i;
[1]250
251#ifdef __FreeBSD__
[59]252 if (strstr(dev, "acd")) {
[146]253 asprintf(&command, "cdcontrol -f %s close", dev);
[59]254 } else {
[146]255 asprintf(&command, "camcontrol load `echo %s | sed 's|/dev/||'`",
[59]256 dev);
257 }
[1]258#else
[146]259 asprintf(&command, "eject -t %s", dev);
[1]260#endif
[59]261 i = run_program_and_log_output(command, FALSE);
262 paranoid_free(command);
263 return (i);
[1]264}
265
266
267/**
268 * Determine whether the specified @p device (really, you can use any file)
269 * exists.
270 * @return TRUE if it exists, FALSE if it doesn't.
271 */
[59]272bool does_device_exist(char *device)
[1]273{
274
[59]275 /*@ buffers *********************************************************** */
276 char *tmp;
[146]277 bool ret;
[1]278
[59]279 assert_string_is_neither_NULL_nor_zerolength(device);
[1]280
[146]281 asprintf(&tmp, "ls %s > /dev/null 2> /dev/null", device);
[59]282
283 if (system(tmp)) {
[146]284 ret = FALSE;
[59]285 } else {
[146]286 ret = TRUE;
[59]287 }
[146]288 paranoid_free(tmp);
289 return(ret);
[1]290}
291
292
293/**
294 * Determine whether a non-Microsoft partition exists on any connected hard drive.
295 * @return TRUE (there's a Linux/FreeBSD partition) or FALSE (Microsoft has taken over yet another innocent PC).
296 */
[59]297bool does_nonMS_partition_exist(void)
[1]298{
299#if __FreeBSD__
[59]300 return
301 !system
302 ("for drive in /dev/ad? /dev/da?; do fdisk $drive | grep -q FreeBSD && exit 0; done; false");
[1]303#else
[59]304 return
305 !system
[687]306 ("parted2fdisk -l 2>/dev/null | grep '^/dev/' | grep -Eqv '(MS|DOS|FAT|NTFS)'");
[1]307#endif
308}
309
310/**
311 * Determine whether the specified @p partno exists on the specified @p drive.
312 * @param drive The drive to search for the partition in.
313 * @param partno The partition number to look for.
314 * @return 0 if it exists, nonzero otherwise.
315 */
[59]316int does_partition_exist(const char *drive, int partno)
[1]317{
[59]318 /*@ buffers **************************************************** */
319 char *program;
[146]320 char *incoming = NULL;
[59]321 char *searchstr;
[688]322 char *tmp;
[1]323
[59]324 /*@ ints ******************************************************* */
325 int res = 0;
[171]326 size_t n = 0;
[1]327
[59]328 /*@ pointers *************************************************** */
329 FILE *fin;
[1]330
331
[59]332 /*@ end vars *************************************************** */
333 assert_string_is_neither_NULL_nor_zerolength(drive);
334 assert(partno >= 0 && partno < 999);
[1]335
336#ifdef __FreeBSD__
[59]337 // We assume here that this is running from mondorestore. (It is.)
[146]338 asprintf(&program, "ls %s >/dev/null 2>&1", drive);
339 res = system(program);
340 paranoid_free(program);
341 return(res);
[1]342#endif
343
[146]344 asprintf(&program, "parted2fdisk -l %s 2> /dev/null", drive);
[59]345 fin = popen(program, "r");
346 if (!fin) {
347 log_it("program=%s", program);
348 log_OS_error("Cannot popen-in program");
[146]349 paranoid_free(program);
[59]350 return (0);
[1]351 }
[146]352 paranoid_free(program);
353
[688]354 searchstr = build_partition_name(drive, partno);
355 asprintf(&tmp, "%s ", searchstr);
356 paranoid_free(searchstr);
357
[146]358 for (res = 0; !res && getline(&incoming, &n, fin);) {
[688]359 if (strstr(incoming, tmp)) {
[59]360 res = 1;
361 }
362 }
[146]363 paranoid_free(incoming);
364
[59]365 if (pclose(fin)) {
366 log_OS_error("Cannot pclose fin");
367 }
[688]368 paranoid_free(tmp);
[59]369 return (res);
[1]370}
371
372
373/**
374 * Determine whether given NULL-terminated @p str exists in the MBR of @p dev.
375 * @param dev The device to look in.
376 * @param str The string to look for.
377 * @return TRUE if it exists, FALSE if it doesn't.
378 */
[59]379bool does_string_exist_in_boot_block(char *dev, char *str)
[1]380{
[59]381 /*@ buffers **************************************************** */
382 char *command;
[1]383
[59]384 /*@ end vars *************************************************** */
[146]385 int ret;
[1]386
[59]387 assert_string_is_neither_NULL_nor_zerolength(dev);
388 assert_string_is_neither_NULL_nor_zerolength(str);
[1]389
[146]390 asprintf(&command,
[59]391 "dd if=%s bs=446 count=1 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null",
392 dev, str);
[146]393 ret = system(command);
[59]394 paranoid_free(command);
[146]395 if (ret) {
[59]396 return (FALSE);
397 } else {
398 return (TRUE);
399 }
[1]400}
401
[146]402
[1]403/**
404 * Determine whether specified @p str exists in the first @p n sectors of
405 * @p dev.
406 * @param dev The device to look in.
407 * @param str The string to look for.
408 * @param n The number of 512-byte sectors to search.
409 */
[59]410bool does_string_exist_in_first_N_blocks(char *dev, char *str, int n)
[1]411{
[59]412 /*@ buffers **************************************************** */
413 char *command;
414 /*@ end vars *************************************************** */
[146]415 int ret;
[1]416
[146]417 asprintf(&command,
[59]418 "dd if=%s bs=512 count=%i 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null",
419 dev, n, str);
[146]420 ret = system(command);
[59]421 paranoid_free(command);
[146]422
423 if (ret) {
[59]424 return (FALSE);
425 } else {
426 return (TRUE);
427 }
[1]428}
429
430
431/**
432 * Try to mount CD-ROM at @p mountpoint. If the CD-ROM is not found or has
433 * not been specified, call find_cdrom_device() to find it.
434 * @param bkpinfo The backup information structure. The only field used is @c bkpinfo->media_device.
435 * @param mountpoint Where to mount the CD-ROM.
436 * @return 0 for success, nonzero for failure.
437 * @see mount_CDROM_here
438 */
[171]439bool find_and_mount_actual_cd(struct s_bkpinfo *bkpinfo, char *mountpoint)
[1]440{
[59]441 /*@ buffers ***************************************************** */
[1]442
[59]443 /*@ int's ****************************************************** */
[171]444 bool res = TRUE;
445 char *dev = NULL;
[1]446
[59]447 /*@ end vars **************************************************** */
[1]448
[59]449 assert(bkpinfo != NULL);
450 assert_string_is_neither_NULL_nor_zerolength(mountpoint);
[1]451
[59]452 if (g_backup_media_type == dvd) {
[171]453 if (g_dvd_drive_is_here != NULL) {
454 asprintf(&dev, g_dvd_drive_is_here);
455 } else {
456 dev = find_dvd_device();
[59]457 }
458 } else {
[171]459 if (g_cdrom_drive_is_here != NULL) {
460 asprintf(&dev, g_cdrom_drive_is_here);
461 } else {
[688]462 // find_cdrom_device allocates the string
[171]463 dev = find_cdrom_device(FALSE);
[59]464 }
465 }
[1]466
[59]467 if (bkpinfo->backup_media_type != iso) {
468 retract_CD_tray_and_defeat_autorun();
469 }
[1]470
[171]471 if ((dev == NULL) || (! mount_CDROM_here(dev, mountpoint))) {
[688]472 paranoid_free(dev);
[59]473 if (!popup_and_get_string
[688]474 (_("CD-ROM device"), _("Please enter your CD-ROM's /dev device"), dev)) {
[171]475 res = FALSE;
[59]476 } else {
477 res = mount_CDROM_here(dev, mountpoint);
478 }
479 }
480 if (res) {
[507]481 log_msg(1, _("mount failed"));
[59]482 } else {
[507]483 log_msg(1, _("mount succeeded with %s"), dev);
[59]484 }
485 paranoid_free(dev);
[171]486 return(res);
[1]487}
488
489
490/**
491 * Locate a CD-R/W writer's SCSI node.
[171]492 * @param cdrw_device SCSI node will be placed here. Caller needs to free it.
493 * @return the cdrw device or NULL if not found
[1]494 */
[171]495char *find_cdrw_device(void)
[1]496{
[59]497 /*@ buffers ************************ */
498 char *comment;
499 char *tmp;
500 char *cdr_exe;
501 char *command;
[171]502 char *cdrw_device;
[1]503
[171]504 if (g_cdrw_drive_is_here != NULL) {
505 asprintf(&cdrw_device, g_cdrw_drive_is_here);
[59]506 log_msg(3, "Been there, done that. Returning %s", cdrw_device);
[171]507 return(cdrw_device);
[59]508 }
509 if (g_backup_media_type == dvd) {
510 log_msg(1,
511 "This is dumb. You're calling find_cdrw_device() but you're backing up to DVD. WTF?");
[171]512 return(NULL);
[59]513 }
514 run_program_and_log_output("insmod ide-scsi", -1);
515 if (find_home_of_exe("cdrecord")) {
[146]516 asprintf(&cdr_exe, "cdrecord");
[59]517 } else {
[146]518 asprintf(&cdr_exe, "dvdrecord");
[59]519 }
520 if (find_home_of_exe(cdr_exe)) {
[146]521 asprintf(&command,
[59]522 "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep CD | cut -d' ' -f2 | head -n1",
523 cdr_exe);
[146]524 asprintf(&tmp, call_program_and_get_last_line_of_output(command));
525 paranoid_free(command);
526 } else {
[171]527 asprintf(&tmp, " ");
[59]528 }
[146]529 paranoid_free(cdr_exe);
530
[59]531 if (strlen(tmp) < 2) {
532 paranoid_free(tmp);
[171]533 return(NULL);
[59]534 } else {
[171]535 cdrw_device = tmp;
[146]536
537 asprintf(&comment, "Found CDRW device - %s", cdrw_device);
[59]538 log_it(comment);
[146]539 paranoid_free(comment);
540
[171]541 paranoid_free(g_cdrw_drive_is_here);
542 asprintf(&g_cdrw_drive_is_here, cdrw_device);
543 return(cdrw_device);
[59]544 }
[1]545}
546
547
548/**
549 * Attempt to locate a CD-ROM device's /dev entry.
550 * Several different methods may be used to find the device, including
551 * calling @c cdrecord, searching @c dmesg, and trial-and-error.
[171]552 * @param output Where to put the located /dev entry. Needs to be freed by the caller.
[1]553 * @param try_to_mount Whether to mount the CD as part of the test; if mount
554 * fails then return failure.
[171]555 * @return output if success or NULL otherwise.
[1]556 */
[171]557char *find_cdrom_device(bool try_to_mount)
[1]558{
[59]559 /*@ pointers **************************************************** */
[688]560 FILE *fin = NULL;
561 char *p = NULL;
562 char *q = NULL;
563 char *r = NULL;
[171]564 char *output = NULL;
565 size_t n = 0;
[1]566
[59]567 /*@ bool's ****************************************************** */
568 bool found_it = FALSE;
[1]569
[59]570 /*@ buffers ***************************************************** */
[146]571 char *tmp = NULL;
[688]572 char *cdr_exe = NULL;
[146]573#ifndef __FreeBSD__
574 char *phrase_two = NULL;
575 char *dvd_last_resort = NULL;
576#endif
[688]577 char *command = NULL;
578 char *mountpoint = NULL;
579 static char *the_last_place_i_found_it = NULL;
[1]580
[59]581 /*@ end vars **************************************************** */
[1]582
[171]583 if ((g_cdrom_drive_is_here != NULL) && !isdigit(g_cdrom_drive_is_here[0])) {
584 asprintf(&output, g_cdrom_drive_is_here);
[59]585 log_msg(3, "Been there, done that. Returning %s", output);
[171]586 return(output);
[59]587 }
[688]588 if ((the_last_place_i_found_it != NULL) && !try_to_mount) {
[171]589 asprintf(&output, the_last_place_i_found_it);
[59]590 log_msg(3,
591 "find_cdrom_device() --- returning last found location - '%s'",
592 output);
[171]593 return(output);
[59]594 }
[1]595
[59]596 if (find_home_of_exe("cdrecord")) {
[146]597 asprintf(&cdr_exe, "cdrecord");
[59]598 } else {
[146]599 asprintf(&cdr_exe, "dvdrecord");
[59]600 }
601 if (!find_home_of_exe(cdr_exe)) {
[171]602 asprintf(&output, "/dev/cdrom");
[59]603 log_msg(4, "Can't find cdrecord; assuming %s", output);
604 if (!does_device_exist(output)) {
605 log_msg(4, "That didn't work. Sorry.");
[146]606 paranoid_free(cdr_exe);
[171]607 paranoid_free(output);
608 return(NULL);
[59]609 } else {
[146]610 paranoid_free(cdr_exe);
[171]611 return(output);
[59]612 }
613 }
614
[146]615 asprintf(&command, "%s -scanbus 2> /dev/null", cdr_exe);
[59]616 fin = popen(command, "r");
617 if (!fin) {
618 log_msg(4, "command=%s", command);
619 log_OS_error("Cannot popen command");
[146]620 paranoid_free(cdr_exe);
621 paranoid_free(command);
[171]622 return (NULL);
[59]623 }
[146]624 paranoid_free(command);
625
626 for (getline(&tmp, &n, fin); !feof(fin);
627 getline(&tmp, &n, fin)) {
[59]628 p = strchr(tmp, '\'');
629 if (p) {
630 q = strchr(++p, '\'');
631 if (q) {
632 for (r = q; *(r - 1) == ' '; r--);
633 *r = '\0';
634 p = strchr(++q, '\'');
635 if (p) {
636 q = strchr(++p, '\'');
637 if (q) {
638 while (*(q - 1) == ' ') {
639 q--;
640 }
641 *q = '\0';
[146]642#ifndef __FreeBSD__
643 paranoid_free(phrase_two);
644 asprintf(&phrase_two, p);
645#endif
[59]646 }
647 }
[1]648 }
649 }
650 }
[59]651 paranoid_pclose(fin);
[146]652 paranoid_free(tmp);
653 tmp = NULL;
654 n = 0;
[1]655
656#ifndef __FreeBSD__
[59]657 if (strlen(phrase_two) == 0) {
658 log_msg(4, "Not running phase two. String is empty.");
659 } else {
[146]660 asprintf(&command, "dmesg | grep \"%s\" 2> /dev/null", phrase_two);
[59]661 fin = popen(command, "r");
662 if (!fin) {
663 log_msg(4, "Cannot run 2nd command - non-fatal, fortunately");
664 } else {
[146]665 for (getline(&tmp, &n, fin); !feof(fin);
666 getline(&tmp, &n, fin)) {
[59]667 log_msg(5, "--> '%s'", tmp);
668 if (tmp[0] != ' ' && tmp[1] != ' ') {
669 p = strchr(tmp, ':');
670 if (p) {
671 *p = '\0';
672 if (strstr(tmp, "DVD")) {
[146]673 paranoid_free(dvd_last_resort);
674 asprintf(&dvd_last_resort, "/dev/%s", tmp);
[59]675 log_msg(4,
676 "Ignoring '%s' because it's a DVD drive",
677 tmp);
678 } else {
[171]679 asprintf(&output, "/dev/%s", tmp);
[59]680 found_it = TRUE;
681 }
682 }
683 }
684 }
[146]685 paranoid_free(tmp);
[59]686 paranoid_pclose(fin);
687 }
[146]688 paranoid_free(command);
[59]689 }
[146]690 paranoid_free(phrase_two);
[1]691
692#endif
693#ifdef __FreeBSD__
[59]694 if (!found_it) {
695 log_msg(4, "OK, approach 2");
696 if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/cdrom"))) {
697 if (!
698 (found_it =
699 set_dev_to_this_if_rx_OK(output, "/dev/cdrom1"))) {
700 if (!
701 (found_it =
702 set_dev_to_this_if_rx_OK(output, "/dev/dvd"))) {
703 if (!
704 (found_it =
705 set_dev_to_this_if_rx_OK(output, "/dev/acd0"))) {
706 if (!
707 (found_it =
708 set_dev_to_this_if_rx_OK(output,
709 "/dev/cd01"))) {
710 if (!
711 (found_it =
712 set_dev_to_this_if_rx_OK(output,
713 "/dev/acd1"))) {
714 if (!
715 (found_it =
716 set_dev_to_this_if_rx_OK(output,
717 "/dev/cd1")))
718 {
[146]719 paranoid_free(cdr_exe);
[171]720 return(NULL);
[59]721 }
722 }
723 }
724 }
725 }
726 }
727 }
728 }
[1]729#else
[146]730 if (dvd_last_resort != NULL) {
731 if (!found_it && strlen(dvd_last_resort) > 0) {
732 log_msg(4, "Well, I'll use the DVD - %s - as a last resort",
733 dvd_last_resort);
[171]734 paranoid_free(output);
735 asprintf(&output, dvd_last_resort);
[146]736 found_it = TRUE;
737 }
[1]738 }
[146]739 paranoid_free(dvd_last_resort);
740
[59]741 if (found_it) {
[146]742 asprintf(&tmp, "grep \"%s=ide-scsi\" /proc/cmdline &> /dev/null",
[59]743 strrchr(output, '/') + 1);
744 if (system(tmp) == 0) {
745 log_msg(4,
746 "%s is not right. It's being SCSI-emulated. Continuing.",
747 output);
748 found_it = FALSE;
[171]749 paranoid_free(output);
[59]750 }
[146]751 paranoid_free(tmp);
[59]752 }
[1]753
[59]754 if (found_it) {
755 log_msg(4, "(find_cdrom_device) --> '%s'", output);
756 if (!does_device_exist(output)) {
[171]757 log_msg(4, "OK, I was wrong, I haven't found it... yet.");
[59]758 found_it = FALSE;
[171]759 paranoid_free(output);
[59]760 }
761 }
[1]762
[59]763 if (!found_it) {
764 log_msg(4, "OK, approach 2");
765 if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/scd0"))) {
766 if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/sr0"))) {
767 if (!
768 (found_it =
769 set_dev_to_this_if_rx_OK(output, "/dev/cdrom"))) {
770 if (!
771 (found_it =
772 set_dev_to_this_if_rx_OK(output,
773 "/dev/cdrom0"))) {
774 if (!
775 (found_it =
776 set_dev_to_this_if_rx_OK(output,
777 "/dev/cdrom1"))) {
778 if (!
779 (found_it =
780 set_dev_to_this_if_rx_OK(output,
781 "/dev/sr1"))) {
782 if (!
783 (found_it =
784 set_dev_to_this_if_rx_OK(output,
785 "/dev/dvd")))
786 {
787 if (!
788 (found_it =
789 set_dev_to_this_if_rx_OK(output,
790 g_cdrw_drive_is_here)))
791 {
[146]792 paranoid_free(cdr_exe);
[171]793 return(NULL);
[59]794 }
795 }
796 }
797 }
798 }
799 }
800 }
801 }
802 }
[1]803#endif
804
[146]805 asprintf(&mountpoint, "/tmp/cd.%d", (int) (random() % 32767));
806 make_hole_for_dir(mountpoint);
807
[59]808 if (found_it && try_to_mount) {
[171]809 if (! mount_CDROM_here(output, mountpoint)) {
[59]810 log_msg(4, "[Cardigans] I've changed my mind");
811 found_it = FALSE;
[171]812 paranoid_free(output);
[59]813 } else {
[146]814 asprintf(&tmp, "%s/archives", mountpoint);
[59]815 if (!does_file_exist(tmp)) {
816 log_msg(4, "[Cardigans] I'll take it back");
817 found_it = FALSE;
[171]818 paranoid_free(output);
[59]819 } else {
[146]820 asprintf(&command, "umount %s", output);
[59]821 paranoid_system(command);
[146]822 paranoid_free(command);
[59]823 log_msg(4, "I'm confident the Mondo CD is in %s", output);
824 }
[146]825 paranoid_free(tmp);
[59]826 }
827 }
828 unlink(mountpoint);
[146]829 paranoid_free(mountpoint);
[1]830
[59]831 if (found_it) {
832 if (!does_file_exist(output)) {
833 log_msg(3, "I still haven't found it.");
[171]834 paranoid_free(output);
835 return(NULL);
[59]836 }
837 log_msg(3, "(find_cdrom_device) --> '%s'", output);
[688]838 asprintf(&the_last_place_i_found_it, output);
[171]839 paranoid_free(g_cdrom_drive_is_here);
840 asprintf(&g_cdrom_drive_is_here, output);
841 return(output);
[59]842 }
[1]843
[146]844 asprintf(&command,
[59]845 "%s -scanbus | grep \"[0-9],[0-9],[0-9]\" | grep \"[D|C][V|D]\" | grep -n \"\" | grep \"%s\" | cut -d':' -f2",
846 cdr_exe, g_cdrw_drive_is_here);
[171]847 paranoid_free(cdr_exe);
848
[59]849 log_msg(1, "command=%s", command);
[146]850 asprintf(&tmp, call_program_and_get_last_line_of_output(command));
851 paranoid_free(command);
852
[59]853 if (tmp[0]) {
[171]854 output = tmp;
[59]855 log_msg(4, "Finally found it at %s", output);
856 } else {
[171]857 paranoid_free(tmp);
858 paranoid_free(output);
[59]859 log_msg(4, "Still couldn't find it.");
860 }
[171]861 return(output);
[1]862}
863
864
[171]865char *find_dvd_device()
[1]866{
[688]867 char *tmp = NULL;
[59]868 int retval = 0, devno = -1;
[171]869 char *output = NULL;
[1]870
[171]871 if (g_dvd_drive_is_here != NULL) {
872 asprintf(&output, g_dvd_drive_is_here);
[59]873 log_msg(3, "Been there, done that. Returning %s", output);
[171]874 return (output);
[59]875 }
[1]876
[146]877 asprintf(&tmp, call_program_and_get_last_line_of_output
[59]878 ("dvdrecord -scanbus 2> /dev/null | grep \") '\" | grep -n \"\" | grep DVD | cut -d':' -f1")
[1]879 );
[59]880 log_msg(5, "tmp = '%s'", tmp);
[146]881 if (!tmp[0]) {
882 paranoid_free(tmp);
883 asprintf(&tmp, call_program_and_get_last_line_of_output
[59]884 ("cdrecord -scanbus 2> /dev/null | grep \") '\" | grep -n \"\" | grep DVD | cut -d':' -f1")
885 );
[146]886 }
[59]887 if (tmp[0]) {
888 devno = atoi(tmp) - 1;
889 }
[146]890 paranoid_free(tmp);
891
[59]892 if (devno >= 0) {
893 retval = 0;
[171]894 asprintf(&output, "/dev/scd%d", devno);
895 paranoid_free(g_dvd_drive_is_here);
896 asprintf(&g_dvd_drive_is_here, output);
[59]897 log_msg(2, "I think DVD is at %s", output);
898 } else {
899 log_msg(2, "I cannot find DVD");
900 }
[1]901
[171]902 return(output);
[1]903}
904
905
906/**
907 * Find the size of the specified @p drive, in megabytes. Uses @c ioctl calls
908 * and @c dmesg.
909 * @param drive The device to find the size of.
910 * @return size in megabytes.
911 */
[59]912long get_phys_size_of_drive(char *drive)
[1]913{
[59]914 int fd;
[1]915#if linux
[59]916 unsigned long long s = 0;
917 int fileid, cylinders = 0, cylindersleft = 0;
918 int cylindersize = 0;
[1]919 int gotgeo = 0;
920
[59]921
922 struct hd_geometry hdgeo;
[1]923#elif __FreeBSD__
[59]924 off_t s;
[1]925#endif
926
[59]927 long outvalA = -1;
928 long outvalB = -1;
929 long outvalC = -1;
[1]930
[59]931 if ((fd = open(drive, O_RDONLY)) != -1) {
932 if (ioctl(fd,
[1]933#if linux
[59]934#ifdef BLKGETSIZE64
935 BLKGETSIZE64,
936#else
937 BLKGETSIZE,
938#endif
[1]939#elif __FreeBSD__
[59]940 DIOCGMEDIASIZE,
[1]941#endif
[59]942 &s) != -1) {
943 close(fd);
944 // s>>11 works for older disks but not for newer ones
945 outvalB =
[1]946#if linux
[59]947#ifdef BLKGETSIZE64
948 s >> 20
[1]949#else
[59]950 s >> 11
[1]951#endif
[59]952#else
953 s >> 20
954#endif
955 ;
956 }
[1]957 }
958
[59]959 if (outvalB <= 0) {
960 log_msg(1, "Error getting size of %s: %s", drive, strerror(errno));
[1]961#if linux
[59]962 fileid = open(drive, O_RDONLY);
[1]963 if (fileid) {
[59]964 if (ioctl(fileid, HDIO_GETGEO, &hdgeo) != -1) {
[1]965 if (hdgeo.cylinders && hdgeo.heads && hdgeo.sectors) {
966 cylindersleft = cylinders = hdgeo.cylinders;
967 cylindersize = hdgeo.heads * hdgeo.sectors / 2;
968 outvalA = cylindersize * cylinders / 1024;
[59]969 log_msg(2, "Got Harddisk geometry, C:%d, H:%d, S:%d",
970 hdgeo.cylinders, hdgeo.heads, hdgeo.sectors);
[1]971 gotgeo = 1;
972 } else {
[59]973 log_msg(1, "Harddisk geometry wrong");
[1]974 }
975 } else {
[59]976 log_msg(1,
977 "Error in ioctl() getting new hard disk geometry (%s), resizing in unsafe mode",
978 strerror(errno));
[1]979 }
980 close(fileid);
981 } else {
[59]982 log_msg(1, "Failed to open %s for reading: %s", drive,
983 strerror(errno));
[1]984 }
985 if (!gotgeo) {
[59]986 log_msg(1, "Failed to get harddisk geometry, using old mode");
[1]987 }
988#endif
[162]989 }
[1]990// OLDER DISKS will give ridiculously low value for outvalB (so outvalA is returned) :)
991// NEWER DISKS will give sane value for outvalB (close to outvalA, in other words) :)
992
[59]993 outvalC = (outvalA > outvalB) ? outvalA : outvalB;
994
[1]995// log_msg (5, "drive = %s, error = %s", drive, strerror (errno));
996// fatal_error ("GPSOD: Unable to get size of drive");
[59]997 log_msg(1, "%s --> %ld or %ld --> %ld", drive, outvalA, outvalB,
998 outvalC);
999
1000 return (outvalC);
[1]1001}
[59]1002
[1]1003
1004/**
1005 * Determine whether @p format is supported by the kernel. Uses /proc/filesystems
1006 * under Linux and @c lsvfs under FreeBSD.
1007 * @param format The format to test.
1008 * @return TRUE if the format is supported, FALSE if not.
1009 */
[59]1010bool is_this_a_valid_disk_format(char *format)
[1]1011{
[688]1012 char *good_formats = NULL;
1013 char *command = NULL;
1014 char *tmp = NULL;
1015 char *format_sz = NULL;
[1]1016
[688]1017 FILE *pin = NULL;
[146]1018 bool retval;
[688]1019 size_t n = 0;
[59]1020 assert_string_is_neither_NULL_nor_zerolength(format);
[1]1021
[146]1022 asprintf(&format_sz, "%s ", format);
[1]1023
1024#ifdef __FreeBSD__
[146]1025 asprintf(&command,
[59]1026 "lsvfs | tr -s '\t' ' ' | grep -v Filesys | grep -v -- -- | cut -d' ' -f1 | tr -s '\n' ' '");
[1]1027#else
[146]1028 asprintf(&command,
[274]1029 "grep -v nodev /proc/filesystems | tr -s '\t' ' ' | cut -d' ' -f2 | tr -s '\n' ' '");
[1]1030#endif
1031
[59]1032 pin = popen(command, "r");
[146]1033 paranoid_free(command);
1034
[59]1035 if (!pin) {
1036 log_OS_error("Unable to read good formats");
[146]1037 retval = FALSE;
[59]1038 } else {
[688]1039 getline(&good_formats, &n , pin);
[59]1040 if (pclose(pin)) {
1041 log_OS_error("Cannot pclose good formats");
1042 }
1043 strip_spaces(good_formats);
[688]1044 // " ntfs 7 " -- um, cheating much? :)
1045 asprintf(&tmp, " %s swap lvm raid ntfs 7 ",good_formats);
1046 paranoid_free(good_formats);
1047 good_formats = tmp;
1048
[59]1049 if (strstr(good_formats, format_sz)) {
[146]1050 retval = TRUE;
[59]1051 } else {
[146]1052 retval = FALSE;
[59]1053 }
[688]1054 paranoid_free(good_formats);
[59]1055 }
1056 paranoid_free(format_sz);
1057 return (retval);
[1]1058}
1059
1060
1061/** @def SWAPLIST_COMMAND The command to list the swap files/partitions in use. */
1062
1063/**
1064 * Determine whether @p device_raw is currently mounted.
1065 * @param device_raw The device to check.
1066 * @return TRUE if it's mounted, FALSE if not.
1067 */
[59]1068bool is_this_device_mounted(char *device_raw)
[1]1069{
1070
[59]1071 /*@ pointers **************************************************** */
1072 FILE *fin;
[1]1073
[59]1074 /*@ buffers ***************************************************** */
[146]1075 char *incoming = NULL;
[59]1076 char *device_with_tab;
1077 char *device_with_space;
1078 char *tmp;
[171]1079 size_t n = 0;
[59]1080
[1]1081#ifdef __FreeBSD__
[59]1082#define SWAPLIST_COMMAND "swapinfo"
[1]1083#else
[59]1084#define SWAPLIST_COMMAND "cat /proc/swaps"
[1]1085#endif
1086
[59]1087 /*@ end vars **************************************************** */
[1]1088
[59]1089 assert(device_raw != NULL);
[1]1090// assert_string_is_neither_NULL_nor_zerolength(device_raw);
[59]1091 if (device_raw[0] != '/' && !strstr(device_raw, ":/")) {
1092 log_msg(1, "%s needs to have a '/' prefixed - I'll do it",
1093 device_raw);
[146]1094 asprintf(&tmp, "/%s", device_raw);
[59]1095 } else {
[146]1096 asprintf(&tmp, device_raw);
[59]1097 }
1098 log_msg(1, "Is %s mounted?", tmp);
1099 if (!strcmp(tmp, "/proc") || !strcmp(tmp, "proc")) {
1100 log_msg(1,
1101 "I don't know how the heck /proc made it into the mountlist. I'll ignore it.");
[146]1102 return (FALSE);
[59]1103 }
[146]1104 asprintf(&device_with_tab, "%s\t", tmp);
1105 asprintf(&device_with_space, "%s ", tmp);
1106 paranoid_free(tmp);
[1]1107
[59]1108 if (!(fin = popen("mount", "r"))) {
1109 log_OS_error("Cannot popen 'mount'");
1110 return (FALSE);
[1]1111 }
[146]1112 for (getline(&incoming, &n, fin); !feof(fin);
1113 getline(&incoming, &n, fin)) {
[59]1114 if (strstr(incoming, device_with_space) //> incoming
1115 || strstr(incoming, device_with_tab)) // > incoming)
1116 {
1117 paranoid_pclose(fin);
[146]1118 return(TRUE);
[59]1119 }
1120 }
[146]1121 paranoid_free(incoming);
1122 paranoid_free(device_with_tab);
[59]1123 paranoid_pclose(fin);
[146]1124
1125 asprintf(&tmp, "%s | grep -w \"%s\" > /dev/null 2> /dev/null",
[59]1126 SWAPLIST_COMMAND, device_with_space);
[146]1127 paranoid_free(device_with_space);
1128
[59]1129 log_msg(4, "tmp (command) = '%s'", tmp);
1130 if (!system(tmp)) {
[146]1131 paranoid_free(tmp);
1132 return(TRUE);
[59]1133 }
1134 paranoid_free(tmp);
[146]1135 return (FALSE);
[1]1136}
1137
[146]1138
[1]1139#ifdef __FreeBSD__
1140// CODE IS FREEBSD-SPECIFIC
1141/**
1142 * Create a loopback device for specified @p fname.
1143 * @param fname The file to associate with a device.
[146]1144 * @return /dev entry for the device (to be freed by the caller),
1145 * or NULL if it couldn't be allocated.
[1]1146 */
[59]1147char *make_vn(char *fname)
[1]1148{
[688]1149 char *device = NULL;
[146]1150 char *mddevice = NULL;
1151 char *command = NULL;
[59]1152 int vndev = 2;
[146]1153
[59]1154 if (atoi
1155 (call_program_and_get_last_line_of_output
1156 ("/sbin/sysctl -n kern.osreldate")) < 500000) {
1157 do {
[146]1158 paranoid_free(mddevice);
1159 asprintf(&mddevice, "vn%ic", vndev++);
1160
1161 paranoid_free(command);
1162 asprintf(&command, "vnconfig %s %s", mddevice, fname);
1163
[59]1164 if (vndev > 10) {
[146]1165 paranoid_free(command);
1166 paranoid_free(mddevice);
[59]1167 return NULL;
1168 }
1169 }
1170 while (system(command));
[146]1171 paranoid_free(command);
[59]1172 } else {
[146]1173 asprintf(&command, "mdconfig -a -t vnode -f %s", fname);
1174 asprintf(&mddevice, call_program_and_get_last_line_of_output(command));
1175 paranoid_free(command);
1176
[59]1177 if (!strstr(mddevice, "md")) {
[146]1178 paranoid_free(mddevice);
[59]1179 return NULL;
1180 }
1181 }
[146]1182 asprintf(&device, "/dev/%s", mddevice);
1183 paranoid_free(mddevice);
1184 return(device);
[1]1185}
1186
1187
1188// CODE IS FREEBSD-SPECIFIC
1189/**
1190 * Deallocate specified @p dname.
1191 * This should be called when you are done with the device created by make_vn(),
1192 * so the system does not run out of @c vn devices.
1193 * @param dname The device to deallocate.
1194 * @return 0 for success, nonzero for failure.
1195 */
[59]1196int kick_vn(char *dname)
[1]1197{
[146]1198 char *command;
1199 int ret = 0;
[1]1200
[59]1201 if (strncmp(dname, "/dev/", 5) == 0) {
1202 dname += 5;
1203 }
[1]1204
[59]1205 if (atoi
1206 (call_program_and_get_last_line_of_output
1207 ("/sbin/sysctl -n kern.osreldate")) < 500000) {
[146]1208 asprintf(&command, "vnconfig -d %s", dname);
1209 ret = system(command);
1210 paranoid_free(command);
1211 return(ret);
[59]1212 } else {
[146]1213 asprintf(&command, "mdconfig -d -u %s", dname);
1214 ret = system(command);
1215 paranoid_free(command);
1216 return(ret);
[59]1217 }
1218 /*NOTREACHED*/ return 255;
[1]1219}
1220#endif
1221
1222
1223/**
1224 * Mount the CD-ROM at @p mountpoint.
1225 * @param device The device (or file if g_ISO_restore_mode) to mount.
1226 * @param mountpoint The place to mount it.
[171]1227 * @return TRUE for success, FALSE for failure.
[1]1228 */
[171]1229bool mount_CDROM_here(char *device, char *mountpoint)
[1]1230{
[59]1231 /*@ buffer ****************************************************** */
[688]1232 char *command = NULL;
1233 int retval = 0;
[1]1234
[59]1235 assert_string_is_neither_NULL_nor_zerolength(device);
1236 assert_string_is_neither_NULL_nor_zerolength(mountpoint);
[1]1237
[59]1238 make_hole_for_dir(mountpoint);
1239 if (isdigit(device[0])) {
[171]1240 paranoid_free(device);
1241 device = find_cdrom_device(FALSE);
[59]1242 }
1243 if (g_ISO_restore_mode) {
[1]1244
1245#ifdef __FreeBSD__
[688]1246 char *dev = NULL;
[146]1247
1248 dev = make_vn(device));
[59]1249 if (!dev) {
[146]1250 asprintf(&command, "Unable to mount ISO (make_vn(%s) failed)",
[59]1251 device);
1252 fatal_error(command);
1253 }
[171]1254 paranoid_free(device);
1255 device = dev;
[1]1256#endif
[146]1257 }
[1]1258
[59]1259 log_msg(4, "(mount_CDROM_here --- device=%s, mountpoint=%s", device,
1260 mountpoint);
1261 /*@ end vars *************************************************** */
[1]1262
1263#ifdef __FreeBSD__
[146]1264 asprintf(&command, "mount_cd9660 -r %s %s 2>> %s",
[59]1265 device, mountpoint, MONDO_LOGFILE);
[1]1266#else
[146]1267 asprintf(&command, "mount %s -o ro,loop -t iso9660 %s 2>> %s",
1268 device, mountpoint, MONDO_LOGFILE);
[1]1269#endif
1270
[59]1271 log_msg(4, command);
1272 if (strncmp(device, "/dev/", 5) == 0) {
1273 retract_CD_tray_and_defeat_autorun();
1274 }
1275 retval = system(command);
1276 log_msg(1, "system(%s) returned %d", command, retval);
[146]1277 paranoid_free(command);
[1]1278
[171]1279 if (retval == 0) {
1280 return(TRUE);
1281 } else {
1282 return(FALSE);
1283 }
[1]1284}
1285
1286
1287/**
1288 * Ask the user for CD number @p cd_number_i_want.
1289 * Sets g_current_media_number once the correct CD is inserted.
1290 * @param bkpinfo The backup information structure. Fields used:
1291 * - @c bkpinfo->backup_media_type
[20]1292 * - @c bkpinfo->prefix
[1]1293 * - @c bkpinfo->isodir
1294 * - @c bkpinfo->media_device
1295 * - @c bkpinfo->please_dont_eject_when_restoring
1296 * @param cd_number_i_want The CD number to ask for.
1297 */
1298void
[59]1299insist_on_this_cd_number(struct s_bkpinfo *bkpinfo, int cd_number_i_want)
[1]1300{
1301
[59]1302 /*@ int ************************************************************* */
1303 int res = 0;
[1]1304
1305
[59]1306 /*@ buffers ********************************************************* */
1307 char *tmp;
1308 char *request;
[1]1309
[59]1310 assert(bkpinfo != NULL);
1311 assert(cd_number_i_want > 0);
[1]1312
1313// log_msg(3, "Insisting on CD number %d", cd_number_i_want);
1314
[59]1315 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
1316 log_msg(3,
1317 "No need to insist_on_this_cd_number when the backup type isn't CD-R(W) or NFS or ISO");
1318 return;
1319 }
[146]1320
1321 asprintf(&tmp, "mkdir -p " MNT_CDROM);
[59]1322 run_program_and_log_output(tmp, 5);
[146]1323 paranoid_free(tmp);
1324
[59]1325 if (g_ISO_restore_mode || bkpinfo->backup_media_type == iso
1326 || bkpinfo->backup_media_type == nfs) {
1327 log_msg(3, "Remounting CD");
1328 g_ISO_restore_mode = TRUE;
[1]1329// FIXME --- I'm tempted to do something about this...
1330// Why unmount and remount again and again?
[59]1331 if (is_this_device_mounted(MNT_CDROM)) {
1332 run_program_and_log_output("umount " MNT_CDROM, 5);
1333 }
1334 system("mkdir -p /tmp/isodir &> /dev/null");
[146]1335 asprintf(&tmp, "%s/%s/%s-%d.iso", bkpinfo->isodir,
[59]1336 bkpinfo->nfs_remote_dir, bkpinfo->prefix,
1337 cd_number_i_want);
1338 if (!does_file_exist(tmp)) {
[146]1339 paranoid_free(tmp);
1340 asprintf(&tmp, "/tmp/isodir/%s/%s-%d.iso",
[59]1341 bkpinfo->nfs_remote_dir, bkpinfo->prefix,
1342 cd_number_i_want);
1343 if (does_file_exist(tmp)) {
1344 log_msg(1,
1345 "FIXME - hacking bkpinfo->isodir from '%s' to /tmp/isodir",
1346 bkpinfo->isodir);
1347 strcpy(bkpinfo->isodir, "/tmp/isodir");
1348 }
1349 }
1350 log_msg(3, "Mounting %s at %s", tmp, MNT_CDROM);
[171]1351 if (! mount_CDROM_here(tmp, MNT_CDROM)) {
[59]1352 fatal_error("Mommy!");
1353 }
[146]1354 paranoid_free(tmp);
[1]1355 }
[59]1356 if ((res = what_number_cd_is_this(bkpinfo)) != cd_number_i_want) {
1357 log_msg(3, "Currently, we hold %d but we want %d", res,
1358 cd_number_i_want);
[146]1359 asprintf(&tmp, "Insisting on %s #%d",
[59]1360 media_descriptor_string(bkpinfo->backup_media_type),
1361 cd_number_i_want);
[146]1362 asprintf(&request, "Please insert %s #%d and press Enter.",
[59]1363 media_descriptor_string(bkpinfo->backup_media_type),
1364 cd_number_i_want);
1365 log_msg(3, tmp);
[146]1366 paranoid_free(tmp);
1367
[59]1368 while (what_number_cd_is_this(bkpinfo) != cd_number_i_want) {
[688]1369 sync();
[59]1370 if (is_this_device_mounted(MNT_CDROM)) {
1371 res =
1372 run_program_and_log_output("umount " MNT_CDROM, FALSE);
1373 } else {
1374 res = 0;
1375 }
1376 if (res) {
[507]1377 log_to_screen(_("WARNING - failed to unmount CD-ROM drive"));
[59]1378 }
1379 if (!bkpinfo->please_dont_eject) {
1380 res = eject_device(bkpinfo->media_device);
1381 } else {
1382 res = 0;
1383 }
1384 if (res) {
[507]1385 log_to_screen(_("WARNING - failed to eject CD-ROM disk"));
[59]1386 }
1387 popup_and_OK(request);
1388 if (!bkpinfo->please_dont_eject) {
1389 inject_device(bkpinfo->media_device);
1390 }
[688]1391 sync();
[59]1392 }
[146]1393 paranoid_free(request);
1394
[59]1395 log_msg(1, "Thankyou. Proceeding...");
1396 g_current_media_number = cd_number_i_want;
1397 }
[1]1398}
1399/* @} - end of deviceGroup */
1400
1401
1402/**
1403 * Ask user for details of backup/restore information.
1404 * Called when @c mondoarchive doesn't get any parameters.
1405 * @param bkpinfo The backup information structure to fill out with the user's data.
1406 * @param archiving_to_media TRUE if archiving, FALSE if restoring.
1407 * @return 0, always.
1408 * @bug No point of `int' return value.
1409 * @ingroup archiveGroup
1410 */
[59]1411int interactively_obtain_media_parameters_from_user(struct s_bkpinfo
1412 *bkpinfo,
1413 bool
1414 archiving_to_media)
[1]1415// archiving_to_media is TRUE if I'm being called by mondoarchive
1416// archiving_to_media is FALSE if I'm being called by mondorestore
1417{
[688]1418 char *tmp = NULL;
1419 char *tmp1 = NULL;
1420 char *tmp2 = NULL;
[146]1421 char *sz_size = NULL;
[688]1422 char *command = NULL;
1423 char *comment = NULL;
[146]1424 char *prompt = NULL;
[688]1425 int i = 0;
1426 FILE *fin = NULL;
[1]1427
[59]1428 assert(bkpinfo != NULL);
1429 bkpinfo->nonbootable_backup = FALSE;
[1]1430
1431// Tape, CD, NFS, ...?
[59]1432 srandom(getpid());
1433 bkpinfo->backup_media_type =
1434 (g_restoring_live_from_cd) ? cdr :
1435 which_backup_media_type(bkpinfo->restore_data);
1436 if (bkpinfo->backup_media_type == none) {
[507]1437 log_to_screen(_("User has chosen not to backup the PC"));
[59]1438 finish(1);
1439 }
1440 if (bkpinfo->backup_media_type == tape && bkpinfo->restore_data) {
[507]1441 popup_and_OK(_("Please remove CD/floppy from drive(s)"));
[59]1442 }
1443 log_msg(3, "media type = %s",
1444 bkptype_to_string(bkpinfo->backup_media_type));
1445 if (archiving_to_media) {
1446 sensibly_set_tmpdir_and_scratchdir(bkpinfo);
1447 }
1448 bkpinfo->cdrw_speed = (bkpinfo->backup_media_type == cdstream) ? 2 : 4;
1449 bkpinfo->compression_level =
1450 (bkpinfo->backup_media_type == cdstream) ? 1 : 5;
1451 bkpinfo->use_lzo =
1452 (bkpinfo->backup_media_type == cdstream) ? TRUE : FALSE;
[1]1453
1454/*
1455 if (find_home_of_exe("star") && (!find_home_of_exe("afio") || find_home_of_exe("selinuxenabled")))
1456 {
1457 bkpinfo->use_star = FALSE;
1458 bkpinfo->use_lzo = FALSE;
1459 log_to_screen("Using star, not afio");
1460 if (!find_home_of_exe("afio"))
1461 { log_to_screen("...because afio not found"); }
1462 if (find_home_of_exe("selinuxenabled"))
1463 { log_to_screen("...because SELINUX found"); }
1464 }
1465*/
1466
[59]1467 mvaddstr_and_log_it(2, 0, " ");
[1]1468
1469// Find device's /dev (or SCSI) entry
[59]1470 switch (bkpinfo->backup_media_type) {
1471 case cdr:
1472 case cdrw:
1473 case dvd:
1474 if (archiving_to_media) {
[687]1475 if (bkpinfo->backup_media_type != dvd) {
1476 if (ask_me_yes_or_no
1477 (_("Is your computer a laptop, or does the CD writer incorporate BurnProof technology?")))
1478 {
1479 bkpinfo->manual_cd_tray = TRUE;
1480 }
[59]1481 }
1482 if ((bkpinfo->compression_level =
1483 which_compression_level()) == -1) {
[507]1484 log_to_screen(_("User has chosen not to backup the PC"));
[59]1485 finish(1);
1486 }
[507]1487 asprintf(&comment, _("What speed is your %s (re)writer?"),
[59]1488 media_descriptor_string(bkpinfo->backup_media_type));
1489 if (bkpinfo->backup_media_type == dvd) {
[171]1490 bkpinfo->media_device = find_dvd_device();
[146]1491 asprintf(&tmp, "1");
1492 asprintf(&sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4582 MB
[59]1493 log_msg(1, "Setting to DVD defaults");
1494 } else {
[171]1495 paranoid_alloc(bkpinfo->media_device,VANILLA_SCSI_CDROM );
[146]1496 asprintf(&tmp, "4");
1497 asprintf(&sz_size, "650");
[59]1498 log_msg(1, "Setting to CD defaults");
1499 }
1500 if (bkpinfo->backup_media_type != dvd) {
[688]1501 if (!popup_and_get_string(_("Speed"), comment, tmp)) {
[507]1502 log_to_screen(_("User has chosen not to backup the PC"));
[59]1503 finish(1);
1504 }
1505 }
[146]1506 paranoid_free(comment);
1507
[59]1508 bkpinfo->cdrw_speed = atoi(tmp); // if DVD then this shouldn't ever be used anyway :)
[146]1509 paranoid_free(tmp);
1510
1511 asprintf(&comment,
[507]1512 _("How much data (in Megabytes) will each %s store?"),
[59]1513 media_descriptor_string(bkpinfo->backup_media_type));
[146]1514
[688]1515 if (!popup_and_get_string("Size", comment, sz_size)) {
[507]1516 log_to_screen(_("User has chosen not to backup the PC"));
[59]1517 finish(1);
1518 }
[146]1519 paranoid_free(comment);
1520
[59]1521 for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
1522 bkpinfo->media_size[i] = atoi(sz_size);
1523 }
[688]1524 paranoid_free(sz_size);
1525
[59]1526 if (bkpinfo->media_size[0] <= 0) {
[507]1527 log_to_screen(_("User has chosen not to backup the PC"));
[59]1528 finish(1);
1529 }
1530 }
1531 case cdstream:
1532 if (bkpinfo->disaster_recovery) {
[171]1533 paranoid_alloc(bkpinfo->media_device, "/dev/cdrom");
[59]1534 log_msg(2, "CD-ROM device assumed to be at %s",
1535 bkpinfo->media_device);
1536 } else if (bkpinfo->restore_data
1537 || bkpinfo->backup_media_type == dvd) {
[171]1538 if (bkpinfo->media_device == NULL) {
[688]1539 asprintf(&bkpinfo->media_device, "/dev/cdrom");
[59]1540 } // just for the heck of it :)
1541 log_msg(1, "bkpinfo->media_device = %s",
1542 bkpinfo->media_device);
[171]1543 if ((bkpinfo->backup_media_type == dvd)
1544 || ((tmp = find_cdrom_device(FALSE)) != NULL)) {
1545 paranoid_free(bkpinfo->media_device);
1546 bkpinfo->media_device = tmp;
[59]1547 log_msg(1, "bkpinfo->media_device = %s",
1548 bkpinfo->media_device);
[146]1549 asprintf(&comment,
[507]1550 _("Please specify your %s drive's /dev entry"),
[59]1551 media_descriptor_string(bkpinfo->
1552 backup_media_type));
1553 if (!popup_and_get_string
[688]1554 (_("Device?"), comment, bkpinfo->media_device)) {
[507]1555 log_to_screen(_("User has chosen not to backup the PC"));
[59]1556 finish(1);
1557 }
[146]1558 paranoid_free(comment);
[59]1559 }
1560 log_msg(2, "%s device found at %s",
1561 media_descriptor_string(bkpinfo->backup_media_type),
1562 bkpinfo->media_device);
1563 } else {
[171]1564 bkpinfo->media_device = find_cdrw_device();
1565 if (bkpinfo->media_device != NULL) {
[146]1566 asprintf(&tmp,
[507]1567 _("I think I've found your %s burner at SCSI node %s; am I right on the money?"),
[59]1568 media_descriptor_string(bkpinfo->
1569 backup_media_type),
1570 bkpinfo->media_device);
1571 if (!ask_me_yes_or_no(tmp)) {
[171]1572 paranoid_free(bkpinfo->media_device);
[59]1573 }
[146]1574 paranoid_free(tmp);
[171]1575 } else {
[59]1576 if (g_kernel_version < 2.6) {
[507]1577 i = popup_and_get_string(_("Device node?"),
1578 _("What is the SCSI node of your CD (re)writer, please?"),
[688]1579 bkpinfo->media_device);
[59]1580 } else {
[507]1581 i = popup_and_get_string(_("/dev entry?"),
1582 _("What is the /dev entry of your CD (re)writer, please?"),
[688]1583 bkpinfo->media_device);
[59]1584 }
1585 if (!i) {
[507]1586 log_to_screen(_("User has chosen not to backup the PC"));
[59]1587 finish(1);
1588 }
1589 }
1590 }
1591 if (bkpinfo->backup_media_type == cdstream) {
1592 for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
1593 bkpinfo->media_size[i] = 650;
1594 }
1595 }
1596 break;
1597 case udev:
1598 if (!ask_me_yes_or_no
[507]1599 (_("This option is for advanced users only. Are you sure?"))) {
1600 log_to_screen(_("User has chosen not to backup the PC"));
[59]1601 finish(1);
1602 }
1603 case tape:
[1]1604
[171]1605 paranoid_free(bkpinfo->media_device);
[59]1606 if (find_tape_device_and_size(bkpinfo->media_device, sz_size)) {
[507]1607 log_msg(3, _("Ok, using vanilla scsi tape."));
[688]1608 paranoid_alloc(bkpinfo->media_device,VANILLA_SCSI_TAPE"0" );
[59]1609 if ((fin = fopen(bkpinfo->media_device, "r"))) {
1610 paranoid_fclose(fin);
1611 } else {
[171]1612 paranoid_alloc(bkpinfo->media_device,"/dev/osst0");
[59]1613 }
1614 }
[171]1615 if (bkpinfo->media_device != NULL) {
[59]1616 if ((fin = fopen(bkpinfo->media_device, "r"))) {
1617 paranoid_fclose(fin);
1618 } else {
1619 if (does_file_exist("/tmp/mondo-restore.cfg")) {
1620 read_cfg_var("/tmp/mondo-restore.cfg", "media-dev",
1621 bkpinfo->media_device);
1622 }
1623 }
[146]1624 asprintf(&tmp,
[507]1625 _("I think I've found your tape streamer at %s; am I right on the money?"),
[59]1626 bkpinfo->media_device);
1627 if (!ask_me_yes_or_no(tmp)) {
[171]1628 paranoid_free(bkpinfo->media_device);
[59]1629 }
[146]1630 paranoid_free(tmp);
[59]1631 }
[171]1632 if (bkpinfo->media_device == NULL) {
[59]1633 if (!popup_and_get_string
[507]1634 (_("Device name?"),
1635 _("What is the /dev entry of your tape streamer?"),
[688]1636 bkpinfo->media_device)) {
[507]1637 log_to_screen(_("User has chosen not to backup the PC"));
[59]1638 finish(1);
1639 }
1640 }
[146]1641 asprintf(&tmp, "ls -l %s", bkpinfo->media_device);
[59]1642 if (run_program_and_log_output(tmp, FALSE)) {
[507]1643 log_to_screen(_("User has not specified a valid /dev entry"));
[59]1644 finish(1);
1645 }
[146]1646 paranoid_free(tmp);
[59]1647 log_msg(4, "sz_size = %s", sz_size);
[688]1648 paranoid_free(sz_size);
[146]1649 bkpinfo->media_size[0] = 0;
[59]1650 log_msg(4, "media_size[0] = %ld", bkpinfo->media_size[0]);
1651 if (bkpinfo->media_size[0] <= 0) {
1652 bkpinfo->media_size[0] = 0;
1653 }
1654 for (i = 1; i <= MAX_NOOF_MEDIA; i++) {
1655 bkpinfo->media_size[i] = bkpinfo->media_size[0];
1656 }
1657 if (archiving_to_media) {
1658 if ((bkpinfo->compression_level =
1659 which_compression_level()) == -1) {
[507]1660 log_to_screen(_("User has chosen not to backup the PC"));
[59]1661 finish(1);
1662 }
1663 }
1664 break;
[1]1665
1666
1667
[59]1668 case nfs:
1669 if (!bkpinfo->nfs_mount[0]) {
1670 strcpy(bkpinfo->nfs_mount,
1671 call_program_and_get_last_line_of_output
1672 ("mount | grep \":\" | cut -d' ' -f1 | head -n1"));
1673 }
[1]1674#ifdef __FreeBSD__
[59]1675 if (TRUE)
[1]1676#else
[59]1677 if (!bkpinfo->disaster_recovery)
[1]1678#endif
[59]1679 {
1680 if (!popup_and_get_string
[507]1681 (_("NFS dir."),
1682 _("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.)"),
[688]1683 bkpinfo->nfs_mount)) {
[507]1684 log_to_screen(_("User has chosen not to backup the PC"));
[59]1685 finish(1);
1686 }
1687 if (!bkpinfo->restore_data) {
1688 if ((bkpinfo->compression_level =
1689 which_compression_level()) == -1) {
[507]1690 log_to_screen(_("User has chosen not to backup the PC"));
[59]1691 finish(1);
1692 }
1693 }
[75]1694 // check whether already mounted - we better remove
[89]1695 // surrounding spaces and trailing '/' for this
1696 strip_spaces(bkpinfo->nfs_mount);
[75]1697 if (bkpinfo->nfs_mount[strlen(bkpinfo->nfs_mount) - 1] == '/')
[89]1698 bkpinfo->nfs_mount[strlen(bkpinfo->nfs_mount) - 1] = '\0';
[146]1699 asprintf(&command, "mount | grep \"%s \" | cut -d' ' -f3",
[89]1700 bkpinfo->nfs_mount);
[59]1701 strcpy(bkpinfo->isodir,
1702 call_program_and_get_last_line_of_output(command));
[146]1703 paranoid_free(command);
[262]1704
1705 asprintf(&comment,
[507]1706 _("How much data (in Megabytes) will each media store?"));
[688]1707 if (!popup_and_get_string(_("Size"), comment, sz_size)) {
[507]1708 log_to_screen(_("User has chosen not to backup the PC"));
[262]1709 finish(1);
1710 }
1711 for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
1712 bkpinfo->media_size[i] = atoi(sz_size);
1713 }
1714 if (bkpinfo->media_size[0] <= 0) {
[507]1715 log_to_screen(_("User has chosen not to backup the PC"));
[262]1716 finish(1);
1717 }
1718 paranoid_free(comment);
[59]1719 }
1720 if (bkpinfo->disaster_recovery) {
1721 system("umount /tmp/isodir 2> /dev/null");
1722 if (!popup_and_get_string
[507]1723 (_("NFS share"), _("Which remote NFS share should I mount?"),
[688]1724 bkpinfo->nfs_mount)) {
[507]1725 log_to_screen(_("User has chosen not to backup the PC"));
[59]1726 finish(1);
1727 }
1728 }
1729 if (!is_this_device_mounted(bkpinfo->nfs_mount)) {
[89]1730 sprintf(bkpinfo->isodir, "/tmp/isodir.mondo.%d",
1731 (int) (random() % 32768));
[146]1732 asprintf(&command, "mkdir -p %s", bkpinfo->isodir);
[89]1733 run_program_and_log_output(command, 5);
[146]1734 paranoid_free(command);
1735
[236]1736 asprintf(&tmp, "mount -t nfs -o nolock %s %s", bkpinfo->nfs_mount,
[89]1737 bkpinfo->isodir);
1738 run_program_and_log_output(tmp, 5);
[146]1739 paranoid_free(tmp);
[89]1740 malloc_string(g_selfmounted_isodir);
1741 strcpy(g_selfmounted_isodir, bkpinfo->isodir);
[59]1742 }
1743 if (!is_this_device_mounted(bkpinfo->nfs_mount)) {
1744 popup_and_OK
[507]1745 (_("Please mount that partition before you try to backup to or restore from it."));
[59]1746 finish(1);
1747 }
1748 if (!popup_and_get_string
[688]1749 (_("Directory"), _("Which directory within that mountpoint?"),bkpinfo->nfs_remote_dir)) {
[507]1750 log_to_screen(_("User has chosen not to backup the PC"));
[59]1751 finish(1);
1752 }
[146]1753
[688]1754 asprintf(&command, "echo hi > '%s/%s/.dummy.txt'", bkpinfo->isodir,
[89]1755 bkpinfo->nfs_remote_dir);
1756 while (run_program_and_log_output(command, FALSE)) {
1757 asprintf(&prompt,
[507]1758 _("Directory '%s' under mountpoint '%s' does not exist or is not writable. You can fix this or change the directory and retry or cancel the backup."),
[89]1759 bkpinfo->nfs_remote_dir, bkpinfo->isodir);
1760 if (!popup_and_get_string
[688]1761 (_("Directory"), prompt, bkpinfo->nfs_remote_dir)) {
[507]1762 log_to_screen(_("User has chosen not to backup the PC"));
[89]1763 finish(1);
1764 }
[688]1765 paranoid_free(prompt);
1766
1767 paranoid_free(command);
[89]1768 asprintf(&command, "echo hi > %s/%s/.dummy.txt",
1769 bkpinfo->isodir, bkpinfo->nfs_remote_dir);
[75]1770 }
[146]1771 paranoid_free(command);
1772
[252]1773 if (!popup_and_get_string
[507]1774 (_("Prefix."),
1775 _("Please enter the prefix that will be prepended to your ISO filename. Example: machine1 to obtain machine1-[1-9]*.iso files"),
[688]1776 bkpinfo->prefix)) {
[507]1777 log_to_screen(_("User has chosen not to backup the PC"));
[252]1778 finish(1);
1779 }
1780 log_msg(3, "prefix set to %s", bkpinfo->prefix);
1781
[59]1782 for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
1783 bkpinfo->media_size[i] = 650;
1784 }
1785 log_msg(3, "Just set nfs_remote_dir to %s",
1786 bkpinfo->nfs_remote_dir);
1787 log_msg(3, "isodir is still %s", bkpinfo->isodir);
1788 break;
[1]1789
[59]1790 case iso:
1791 if (!bkpinfo->disaster_recovery) {
1792 if (!popup_and_get_string
[507]1793 (_("Storage dir."),
1794 _("Please enter the full path that contains your ISO images. Example: /mnt/raid0_0"),
[688]1795 bkpinfo->isodir)) {
[507]1796 log_to_screen(_("User has chosen not to backup the PC"));
[59]1797 finish(1);
1798 }
1799 if (archiving_to_media) {
1800 if ((bkpinfo->compression_level =
1801 which_compression_level()) == -1) {
[507]1802 log_to_screen(_("User has chosen not to backup the PC"));
[59]1803 finish(1);
1804 }
1805 if (!popup_and_get_string
[507]1806 (_("ISO size."),
[688]1807 _("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 or DVD's you plan to backup to."), sz_size)) {
[507]1808 log_to_screen(_("User has chosen not to backup the PC"));
[59]1809 finish(1);
1810 }
1811 for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
1812 bkpinfo->media_size[i] = atoi(sz_size);
1813 }
[146]1814 paranoid_free(sz_size);
1815
[59]1816 if (!popup_and_get_string
[507]1817 (_("Prefix."),
1818 _("Please enter the prefix that will be prepended to your ISO filename. Example: machine1 to obtain machine1-[1-9]*.iso files"),
[688]1819 bkpinfo->prefix)) {
[59]1820 log_to_screen("User has chosen not to backup the PC");
1821 finish(1);
1822 }
[252]1823 log_msg(3, "prefix set to %s", bkpinfo->prefix);
[59]1824 } else {
1825 for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
1826 bkpinfo->media_size[i] = 650;
1827 }
1828 }
1829 }
1830 break;
1831 default:
1832 fatal_error
1833 ("I, Mojo Jojo, shall defeat those pesky Powerpuff Girls!");
1834 }
1835 if (archiving_to_media) {
[1]1836
1837#ifdef __FreeBSD__
[688]1838 bkpinfo->boot_device = call_program_and_get_last_line_of_output
[59]1839 ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
[1]1840#else
[688]1841 bkpinfo->boot_device = call_program_and_get_last_line_of_output
[59]1842 ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
[1]1843#endif
[59]1844 i = which_boot_loader(bkpinfo->boot_device);
1845 if (i == 'U') // unknown
1846 {
[1]1847
1848#ifdef __FreeBSD__
[59]1849 if (!popup_and_get_string
[507]1850 (_("Boot device"),
1851 _("What is your boot device? (e.g. /dev/ad0)"),
[688]1852 bkpinfo->boot_device)) {
[507]1853 log_to_screen(_("User has chosen not to backup the PC"));
[59]1854 finish(1);
1855 }
1856 i = which_boot_loader(bkpinfo->boot_device);
[1]1857#else
[59]1858 if (!popup_and_get_string
[507]1859 (_("Boot device"),
1860 _("What is your boot device? (e.g. /dev/hda)"),
[688]1861 bkpinfo->boot_device)) {
[507]1862 log_to_screen(_("User has chosen not to backup the PC"));
[59]1863 finish(1);
1864 }
1865 if (does_string_exist_in_boot_block
1866 (bkpinfo->boot_device, "LILO")) {
1867 i = 'L';
1868 } else
1869 if (does_string_exist_in_boot_block
1870 (bkpinfo->boot_device, "ELILO")) {
1871 i = 'E';
1872 } else
1873 if (does_string_exist_in_boot_block
1874 (bkpinfo->boot_device, "GRUB")) {
1875 i = 'G';
1876 } else {
1877 i = 'U';
1878 }
[1]1879#endif
[59]1880 if (i == 'U') {
1881 if (ask_me_yes_or_no
[507]1882 (_("Unidentified boot loader. Shall I restore it byte-for-byte at restore time and hope for the best?")))
[59]1883 {
1884 i = 'R'; // raw
1885 } else {
1886 log_to_screen
[507]1887 (_("I cannot find your boot loader. Please run mondoarchive with parameters."));
[59]1888 finish(1);
1889 }
1890 }
[1]1891 }
[59]1892 bkpinfo->boot_loader = i;
[688]1893 asprintf(&bkpinfo->include_paths, "/");
[59]1894 if (!popup_and_get_string
[507]1895 (_("Backup paths"),
1896 _("Please enter paths which you want me to backup. The default is '/' (i.e. everything)."),
[688]1897 bkpinfo->include_paths)) {
[507]1898 log_to_screen(_("User has chosen not to backup the PC"));
[59]1899 finish(1);
[1]1900 }
[688]1901
[146]1902 tmp = list_of_NFS_mounts_only();
[59]1903 if (strlen(tmp) > 2) {
[688]1904 if (bkpinfo->exclude_paths != NULL) {
1905 tmp1 = bkpinfo->exclude_paths;
1906 asprintf(&bkpinfo->exclude_paths, "%s %s", tmp1, tmp);
1907 paranoid_free(tmp1);
1908 } else {
1909 bkpinfo->exclude_paths = tmp;
[59]1910 }
1911 }
[146]1912 paranoid_free(tmp);
[1]1913// NTFS
[688]1914 tmp = call_program_and_get_last_line_of_output
1915 ("parted2fdisk -l | grep -i ntfs | awk '{ print $1};' | tr -s '\\n' ' ' | awk '{ print $0};'");
[59]1916 if (strlen(tmp) > 2) {
1917 if (!popup_and_get_string
[507]1918 (_("NTFS partitions"),
1919 _("Please enter/confirm the NTFS partitions you wish to backup as well."),
[688]1920 tmp1)) {
[507]1921 log_to_screen(_("User has chosen not to backup the PC"));
[59]1922 finish(1);
1923 }
[688]1924 if (bkpinfo->image_devs != NULL) {
1925 tmp2 = bkpinfo->image_devs;
1926 asprintf(&bkpinfo->image_devs, "%s %s", tmp2, tmp1);
1927 paranoid_free(tmp2);
1928 } else {
1929 bkpinfo->image_devs = tmp1;
1930 }
1931 paranoid_free(tmp1);
[59]1932 }
[146]1933 paranoid_free(tmp);
[1]1934
[59]1935 if (!popup_and_get_string
[507]1936 (_("Exclude paths"),
1937 _("Please enter paths which you do NOT want to backup. Separate them with spaces. NB: /tmp and /proc are always excluded. :-) Just hit 'Enter' if you want to do a full system backup."),
[688]1938 bkpinfo->exclude_paths)) {
[507]1939 log_to_screen(_("User has chosen not to backup the PC"));
[59]1940 finish(1);
1941 }
1942 bkpinfo->make_cd_use_lilo = FALSE;
1943 bkpinfo->backup_data = TRUE;
1944 bkpinfo->verify_data =
1945 ask_me_yes_or_no
[507]1946 (_("Will you want to verify your backups after Mondo has created them?"));
[1]1947
1948#ifndef __FreeBSD__
[59]1949 if (!ask_me_yes_or_no
[507]1950 (_("Are you confident that your kernel is a sane, sensible, standard Linux kernel? Say 'no' if you are using a Gentoo <1.4 or Debian <3.0, please."))){
[171]1951 paranoid_alloc(bkpinfo->kernel_path, "FAILSAFE");
1952 }
[1]1953#endif
1954
[59]1955 if (!ask_me_yes_or_no
[507]1956 (_("Are you sure you want to proceed? Hit 'no' to abort."))) {
1957 log_to_screen(_("User has chosen not to backup the PC"));
[59]1958 finish(1);
1959 }
1960 } else {
1961 bkpinfo->restore_data = TRUE; // probably...
1962 }
[1]1963
[59]1964 if (bkpinfo->backup_media_type == iso
1965 || bkpinfo->backup_media_type == nfs) {
1966 g_ISO_restore_mode = TRUE;
1967 }
[1]1968#ifdef __FreeSD__
1969// skip
1970#else
[59]1971 if (bkpinfo->backup_media_type == nfs) {
1972 log_msg(3, "I think the NFS mount is mounted at %s",
1973 bkpinfo->isodir);
1974 }
1975 log_it("isodir = %s", bkpinfo->isodir);
1976 log_it("nfs_mount = '%s'", bkpinfo->nfs_mount);
[1]1977#endif
1978
[59]1979 log_it("media device = %s", bkpinfo->media_device);
1980 log_it("media size = %ld", bkpinfo->media_size[1]);
1981 log_it("media type = %s",
1982 bkptype_to_string(bkpinfo->backup_media_type));
[252]1983 log_it("prefix = %s", bkpinfo->prefix);
[59]1984 log_it("compression = %ld", bkpinfo->compression_level);
1985 log_it("include_paths = '%s'", bkpinfo->include_paths);
1986 log_it("exclude_paths = '%s'", bkpinfo->exclude_paths);
1987 log_it("scratchdir = '%s'", bkpinfo->scratchdir);
1988 log_it("tmpdir = '%s'", bkpinfo->tmpdir);
1989 log_it("boot_device = '%s' (loader=%c)", bkpinfo->boot_device,
1990 bkpinfo->boot_loader);
[87]1991 log_it("prefix = %s", bkpinfo->prefix);
[59]1992 if (bkpinfo->media_size[0] < 0) {
1993 if (archiving_to_media) {
1994 fatal_error("Media size is less than zero.");
1995 } else {
1996 log_msg(2, "Warning - media size is less than zero.");
1997 bkpinfo->media_size[0] = 0;
1998 }
[1]1999 }
[59]2000 return (0);
[1]2001}
2002
2003
2004/**
2005 * Get a space-separated list of NFS mounts.
2006 * @return The list created.
[688]2007 * @note The return value should be freed by caller
[1]2008 * @bug Even though we only want the mounts, the devices are still checked.
2009 */
2010char *list_of_NFS_mounts_only(void)
2011{
[688]2012 return(call_program_and_get_last_line_of_output
[133]2013 ("mount -t coda,ncpfs,nfs,smbfs,cifs | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' ' ' | awk '{print $0;}'"));
[688]2014 /* BERLIOS : Useless
[146]2015 asprintf(&exclude_these_devices,
[59]2016 call_program_and_get_last_line_of_output
[276]2017 ("tr -s '\t' ' ' < /etc/fstab | grep -E '( (coda|ncpfs|nfs|smbfs|cifs) )' | cut -d' ' -f1 | tr -s '\n' ' ' | awk '{print $0;}'"));
[688]2018 */
[1]2019}
2020
[146]2021
[1]2022/* @} - end of utilityGroup */
2023
2024/**
2025 * Create a randomly-named FIFO. The format is @p stub "." [random] [random] where
2026 * [random] is a random number between 1 and 32767.
2027 * @param store_name_here Where to store the new filename.
2028 * @param stub A random number will be appended to this to make the FIFO's name.
2029 * @ingroup deviceGroup
2030 */
[59]2031void make_fifo(char *store_name_here, char *stub)
[1]2032{
[59]2033 char *tmp;
[1]2034
[59]2035 assert_string_is_neither_NULL_nor_zerolength(stub);
[1]2036
[59]2037 sprintf(store_name_here, "%s%d%d", stub, (int) (random() % 32768),
2038 (int) (random() % 32768));
2039 make_hole_for_file(store_name_here);
2040 mkfifo(store_name_here, S_IRWXU | S_IRWXG);
[146]2041 asprintf(&tmp, "chmod 770 %s", store_name_here);
[59]2042 paranoid_system(tmp);
2043 paranoid_free(tmp);
[1]2044}
2045
2046
2047/**
2048 * Set the tmpdir and scratchdir to reside on the partition with the most free space.
2049 * Automatically excludes DOS, NTFS, SMB, and NFS filesystems.
2050 * @param bkpinfo The backup information structure. @c bkpinfo->tmpdir and @c bkpinfo->scratchdir will be set.
2051 * @ingroup utilityGroup
2052 */
2053void sensibly_set_tmpdir_and_scratchdir(struct s_bkpinfo *bkpinfo)
2054{
[688]2055 char *tmp = NULL;
2056 char *command = NULL;
2057 char *sz = NULL;
2058 int i = 0;
[1]2059
[59]2060 assert(bkpinfo != NULL);
[1]2061
2062#ifdef __FreeBSD__
[688]2063 tmp = call_program_and_get_last_line_of_output
2064 ("df -m -P -t nonfs,msdosfs,ntfs,smbfs,smb,cifs | tr -s '\t' ' ' | grep -vE \"none|Filesystem\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'");
[1]2065#else
[688]2066 tmp = call_program_and_get_last_line_of_output
2067 ("df -m -P -x nfs -x vfat -x ntfs -x smbfs -x smb -x cifs | sed 's/ /devdev/' | tr -s '\t' ' ' | grep -vE \"none|Filesystem|/dev/shm\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'");
[1]2068#endif
2069
[59]2070 if (tmp[0] != '/') {
[146]2071 asprintf(&sz, "/%s", tmp);
2072 paranoid_free(tmp);
2073 tmp = sz;
[59]2074 }
2075 if (!tmp[0]) {
2076 fatal_error("I couldn't figure out the tempdir!");
2077 }
[688]2078 i = (int) (random() % 32768);
2079 asprintf(&bkpinfo->tmpdir, "%s/mondo.tmp.%d", tmp, i);
[59]2080 log_it("bkpinfo->tmpdir is being set to %s", bkpinfo->tmpdir);
[1]2081
[688]2082 asprintf(&bkpinfo->scratchdir, "%s/mondo.scratch.%d", tmp, i);
[59]2083 log_it("bkpinfo->scratchdir is being set to %s", bkpinfo->scratchdir);
[1]2084
[688]2085 asprintf(&g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir,
[59]2086 bkpinfo->scratchdir);
2087
[688]2088 asprintf(&command, "rm -Rf %s/mondo.tmp.* %s/mondo.scratch.*", tmp, tmp);
[146]2089 paranoid_free(tmp);
2090
[59]2091 paranoid_system(command);
2092 paranoid_free(command);
[1]2093}
2094
2095
2096/**
2097 * @addtogroup deviceGroup
2098 * @{
2099 */
2100/**
2101 * If we can read @p dev, set @p output to it.
2102 * If @p dev cannot be read, set @p output to "".
2103 * @param dev The device to check for.
[171]2104 * @param output Set to @p dev if @p dev exists, NULL otherwise. Needs to be freed by caller
[1]2105 * @return TRUE if @p dev exists, FALSE if it doesn't.
2106 */
[59]2107bool set_dev_to_this_if_rx_OK(char *output, char *dev)
[1]2108{
[59]2109 char *command;
[1]2110
[171]2111 paranoid_free(output);
[59]2112 if (!dev || dev[0] == '\0') {
2113 return (FALSE);
2114 }
2115 log_msg(10, "Injecting %s", dev);
2116 inject_device(dev);
2117 if (!does_file_exist(dev)) {
2118 log_msg(10, "%s doesn't exist. Returning FALSE.", dev);
2119 return (FALSE);
2120 }
[146]2121 asprintf(&command, "dd bs=%ld count=1 if=%s of=/dev/null &> /dev/null",
[59]2122 512L, dev);
2123 if (!run_program_and_log_output(command, FALSE)
2124 && !run_program_and_log_output(command, FALSE)) {
[171]2125 asprintf(&output, dev);
[59]2126 log_msg(4, "Found it - %s", dev);
[146]2127 paranoid_free(command);
[59]2128 return (TRUE);
2129 } else {
2130 log_msg(4, "It's not %s", dev);
[146]2131 paranoid_free(command);
[59]2132 return (FALSE);
2133 }
[1]2134}
2135
2136
2137/**
2138 * Find out what number CD is in the drive.
2139 * @param bkpinfo The backup information structure. The @c bkpinfo->media_device field is the only one used.
2140 * @return The current CD number, or -1 if it could not be found.
2141 * @note If the CD is not mounted, it will be mounted
2142 * (and remain mounted after this function returns).
2143 */
2144int what_number_cd_is_this(struct s_bkpinfo *bkpinfo)
2145{
[59]2146 int cd_number = -1;
[688]2147 char *mountdev = NULL;
2148 char *tmp = NULL;
2149 char *tmp1 = NULL;
[1]2150
[59]2151 assert(bkpinfo != NULL);
2152 if (g_ISO_restore_mode) {
[146]2153 asprintf(&tmp, "mount | grep iso9660 | awk '{print $3;}'");
[1]2154
[688]2155 tmp1 = call_program_and_get_last_line_of_output(tmp);
[146]2156 paranoid_free(tmp);
2157
[688]2158 asprintf(&mountdev, "%s/archives/THIS-CD-NUMBER", tmp1);
2159 paranoid_free(tmp1);
2160
2161 tmp = last_line_of_file(mountdev);
2162 cd_number = atoi(tmp);
[59]2163 paranoid_free(mountdev);
[688]2164 paranoid_free(tmp);
[146]2165
[59]2166 return (cd_number);
2167 }
[1]2168
[171]2169 if (bkpinfo->media_device == NULL) {
[59]2170 log_it
2171 ("(what_number_cd_is_this) Warning - media_device unknown. Finding out...");
[171]2172 bkpinfo->media_device = find_cdrom_device(FALSE);
[59]2173 }
2174 if (!is_this_device_mounted(MNT_CDROM)) {
[171]2175 (void)mount_CDROM_here(bkpinfo->media_device, MNT_CDROM);
[59]2176 }
[688]2177 tmp = last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER");
2178 cd_number = atoi(tmp);
2179 paranoid_free(tmp);
[59]2180 return (cd_number);
[1]2181}
2182
2183
2184/**
2185 * Find out what device is mounted as root (/).
2186 * @return Root device.
2187 * @note The returned string points to static storage and will be overwritten with every call.
2188 * @bug A bit of a misnomer; it's actually finding out the root device.
2189 * The mountpoint (where it's mounted) will obviously be '/'.
2190 */
[59]2191char *where_is_root_mounted()
[1]2192{
[146]2193 char *tmp;
[1]2194
2195#ifdef __FreeBSD__
[688]2196 tmp = call_program_and_get_last_line_of_output
2197 ("mount | grep \" on / \" | cut -d' ' -f1");
[1]2198#else
[688]2199 tmp = call_program_and_get_last_line_of_output
2200 ("mount | grep \" on / \" | cut -d' ' -f1 | sed s/[0-9]// | sed s/[0-9]//");
[59]2201 if (strstr(tmp, "/dev/cciss/")) {
[146]2202 paranoid_free(tmp);
[688]2203 tmp = call_program_and_get_last_line_of_output
2204 ("mount | grep \" on / \" | cut -d' ' -f1 | cut -dp -f1");
[59]2205 }
2206 if (strstr(tmp, "/dev/md")) {
[146]2207 paranoid_free(tmp);
[688]2208 tmp = call_program_and_get_last_line_of_output
2209 ("mount | grep \" on / \" | cut -d' ' -f1");
[59]2210 }
[1]2211#endif
2212
[59]2213 return (tmp);
[1]2214}
2215
2216
2217/**
2218 * Find out which boot loader is in use.
2219 * @param which_device Device to look for the boot loader on.
2220 * @return 'L' for LILO, 'E'for ELILO, 'G' for GRUB, 'B' or 'D' for FreeBSD boot loaders, or 'U' for Unknown.
2221 * @note Under Linux, all drives are examined, not just @p which_device.
2222 */
2223#ifdef __FreeBSD__
[59]2224char which_boot_loader(char *which_device)
[1]2225{
[59]2226 int count_lilos = 0;
2227 int count_grubs = 0;
2228 int count_boot0s = 0;
2229 int count_dangerouslydedicated = 0;
[1]2230
[59]2231 log_it("looking at drive %s's MBR", which_device);
2232 if (does_string_exist_in_boot_block(which_device, "GRUB")) {
2233 count_grubs++;
2234 }
2235 if (does_string_exist_in_boot_block(which_device, "LILO")) {
2236 count_lilos++;
2237 }
2238 if (does_string_exist_in_boot_block(which_device, "Drive")) {
2239 count_boot0s++;
2240 }
2241 if (does_string_exist_in_first_N_blocks
2242 (which_device, "FreeBSD/i386", 17)) {
2243 count_dangerouslydedicated++;
2244 }
2245 log_it("%d grubs and %d lilos and %d elilos and %d boot0s and %d DD\n",
2246 count_grubs, count_lilos, count_elilos, count_boot0s,
2247 count_dangerouslydedicated);
[1]2248
[59]2249 if (count_grubs && !count_lilos) {
2250 return ('G');
2251 } else if (count_lilos && !count_grubs) {
2252 return ('L');
2253 } else if (count_grubs == 1 && count_lilos == 1) {
2254 log_it("I'll bet you used to use LILO but switched to GRUB...");
2255 return ('G');
2256 } else if (count_boot0s == 1) {
2257 return ('B');
2258 } else if (count_dangerouslydedicated) {
2259 return ('D');
2260 } else {
2261 log_it("Unknown boot loader");
2262 return ('U');
2263 }
[1]2264}
2265
2266#else
2267
[59]2268char which_boot_loader(char *which_device)
[1]2269{
[59]2270 /*@ buffer ***************************************************** */
2271 char *list_drives_cmd;
[146]2272 char *current_drive = NULL;
[1]2273
[59]2274 /*@ pointers *************************************************** */
2275 FILE *pdrives;
[1]2276
[59]2277 /*@ int ******************************************************** */
2278 int count_lilos = 0;
2279 int count_grubs = 0;
[171]2280 size_t n = 0;
[1]2281
[59]2282 /*@ end vars *************************************************** */
[1]2283
2284#ifdef __IA64__
[59]2285 /* No choice for it */
2286 return ('E');
[1]2287#endif
[59]2288 assert(which_device != NULL);
[146]2289 asprintf(&list_drives_cmd,
[197]2290 "parted2fdisk -l 2>/dev/null | grep \"/dev/.*:\" | tr -s ':' ' ' | tr -s ' ' '\n' | grep /dev/; echo %s",
[59]2291 where_is_root_mounted());
2292 log_it("list_drives_cmd = %s", list_drives_cmd);
[1]2293
[59]2294 if (!(pdrives = popen(list_drives_cmd, "r"))) {
2295 log_OS_error("Unable to open list of drives");
2296 paranoid_free(list_drives_cmd);
2297 return ('\0');
[1]2298 }
[146]2299 paranoid_free(list_drives_cmd);
2300
2301 for (getline(&current_drive, &n, pdrives); !feof(pdrives);
2302 getline(&current_drive, &n, pdrives)) {
[59]2303 strip_spaces(current_drive);
2304 log_it("looking at drive %s's MBR", current_drive);
2305 if (does_string_exist_in_boot_block(current_drive, "GRUB")) {
2306 count_grubs++;
2307 strcpy(which_device, current_drive);
2308 break;
2309 }
2310 if (does_string_exist_in_boot_block(current_drive, "LILO")) {
2311 count_lilos++;
2312 strcpy(which_device, current_drive);
2313 break;
2314 }
[1]2315 }
[146]2316 paranoid_free(current_drive);
2317
[59]2318 if (pclose(pdrives)) {
2319 log_OS_error("Cannot pclose pdrives");
2320 }
2321 log_it("%d grubs and %d lilos\n", count_grubs, count_lilos);
2322 if (count_grubs && !count_lilos) {
2323 return ('G');
2324 } else if (count_lilos && !count_grubs) {
2325 return ('L');
2326 } else if (count_grubs == 1 && count_lilos == 1) {
2327 log_it("I'll bet you used to use LILO but switched to GRUB...");
2328 return ('G');
2329 } else {
2330 log_it("Unknown boot loader");
2331 return ('U');
2332 }
[1]2333}
2334#endif
2335
2336
2337/**
2338 * Write zeroes over the first 16K of @p device.
2339 * @param device The device to zero.
2340 * @return 0 for success, 1 for failure.
2341 */
[59]2342int zero_out_a_device(char *device)
[1]2343{
[59]2344 FILE *fout;
2345 int i;
[1]2346
[59]2347 assert_string_is_neither_NULL_nor_zerolength(device);
[1]2348
[59]2349 log_it("Zeroing drive %s", device);
2350 if (!(fout = fopen(device, "w"))) {
2351 log_OS_error("Unable to open/write to device");
2352 return (1);
2353 }
2354 for (i = 0; i < 16384; i++) {
2355 fputc('\0', fout);
2356 }
2357 paranoid_fclose(fout);
2358 log_it("Device successfully zeroed.");
2359 return (0);
[1]2360}
2361
[146]2362
[1]2363/**
2364 * Return the device pointed to by @p incoming.
2365 * @param incoming The device to resolve symlinks for.
2366 * @return The path to the real device file.
[146]2367 * @note The returned string points to a storage that need to be freed by the caller
[1]2368 * @bug Won't work with file v4.0; needs to be written in C.
2369 */
[59]2370char *resolve_softlinks_to_get_to_actual_device_file(char *incoming)
[1]2371{
[688]2372 char *output = NULL;
2373 char *command = NULL;
2374 char *curr_fname = NULL;
2375 char *scratch = NULL;
2376 char *tmp = NULL;
2377 char *p = NULL;
[59]2378
2379 struct stat statbuf;
2380 if (!does_file_exist(incoming)) {
2381 log_it
2382 ("resolve_softlinks_to_get_to_actual_device_file --- device not found");
[146]2383 asprintf(&output, incoming);
[59]2384 } else {
[146]2385 asprintf(&curr_fname, incoming);
[59]2386 lstat(curr_fname, &statbuf);
2387 while (S_ISLNK(statbuf.st_mode)) {
2388 log_msg(1, "curr_fname = %s", curr_fname);
[146]2389 asprintf(&command, "file %s", curr_fname);
[688]2390 tmp = call_program_and_get_last_line_of_output(command);
[146]2391 paranoid_free(command);
2392
[59]2393 for (p = tmp + strlen(tmp); p != tmp && *p != '`' && *p != ' ';
2394 p--);
2395 p++;
[146]2396 asprintf(&scratch, p);
[59]2397 for (p = scratch; *p != '\0' && *p != '\''; p++);
2398 *p = '\0';
[688]2399 log_msg(0, "curr_fname %s --> '%s' --> %s", curr_fname, tmp, scratch);
[146]2400 paranoid_free(tmp);
2401
[59]2402 if (scratch[0] == '/') {
[146]2403 paranoid_free(curr_fname);
2404 asprintf(&curr_fname, scratch); // copy whole thing because it's an absolute softlink
[59]2405 } else { // copy over the basename cos it's a relative softlink
2406 p = curr_fname + strlen(curr_fname);
2407 while (p != curr_fname && *p != '/') {
2408 p--;
2409 }
2410 if (*p == '/') {
2411 p++;
2412 }
[146]2413 *p = '\0';
2414 asprintf(&tmp, "%s%s", curr_fname, scratch);
2415 paranoid_free(curr_fname);
2416 curr_fname = tmp;
[59]2417 }
[146]2418 paranoid_free(scratch);
[59]2419 lstat(curr_fname, &statbuf);
2420 }
[146]2421 asprintf(&output, curr_fname);
[59]2422 log_it("resolved %s to %s", incoming, output);
[146]2423 paranoid_free(curr_fname);
[1]2424 }
[59]2425 return (output);
[1]2426}
2427
2428/* @} - end of deviceGroup */
2429
2430
2431/**
2432 * Return the type of partition format (GPT or MBR)
[146]2433 * Caller needs to free the return value
[1]2434 */
2435char *which_partition_format(const char *drive)
2436{
[688]2437 char *output = NULL;
2438 char *tmp = NULL;
2439 char *command = NULL;
2440 char *fdisk = NULL;
[59]2441
2442 log_msg(0, "Looking for partition table format type");
[197]2443 asprintf(&fdisk, "/sbin/parted2fdisk");
[89]2444 log_msg(1, "Using %s", fdisk);
[146]2445 asprintf(&command, "%s -l %s | grep 'EFI GPT'", fdisk, drive);
2446 paranoid_free(fdisk);
2447
[688]2448 tmp = call_program_and_get_last_line_of_output(command);
[146]2449 paranoid_free(command);
2450
[59]2451 if (strstr(tmp, "GPT") == NULL) {
[146]2452 asprintf(&output, "MBR");
[59]2453 } else {
[146]2454 asprintf(&output, "GPT");
[59]2455 }
[146]2456 paranoid_free(tmp);
[59]2457 log_msg(0, "Found %s partition table format type", output);
2458 return (output);
[1]2459}
2460
2461/* @} - end of deviceGroup */
Note: See TracBrowser for help on using the repository browser.