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