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

Last change on this file since 1079 was 1079, checked in by Bruno Cornec, 17 years ago

merge -r1045:1078 £SVN_M/branches/stable

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