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