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