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