[1] | 1 | /* libmondo-archive.c
|
---|
[99] | 2 | $Id: libmondo-archive.c 1317 2007-04-16 16:26:55Z bruno $
|
---|
[1] | 3 |
|
---|
| 4 | subroutines to handle the archiving of files
|
---|
| 5 |
|
---|
| 6 |
|
---|
| 7 |
|
---|
| 8 | 07/14
|
---|
| 9 | - moved all ACL, xattr stuff here from libmondo-filelist.c
|
---|
| 10 |
|
---|
| 11 | 07/12
|
---|
| 12 | - when trying to find boot loader, look for /boot's /dev, not just /'s dev
|
---|
| 13 |
|
---|
| 14 | 07/10
|
---|
| 15 | - better detection of changed files
|
---|
| 16 | - added ACL, xattr support for afio
|
---|
| 17 |
|
---|
| 18 | 06/17
|
---|
| 19 | - backup with partimagehack if NTFS device; dd, if non-NTFS device
|
---|
| 20 |
|
---|
| 21 | 06/14
|
---|
| 22 | - use mondorescue.iso instead of mindi.iso
|
---|
| 23 |
|
---|
| 24 | 04/28
|
---|
| 25 | - cleaned up if/then architecture-specific stuff re: CD-R(W)s
|
---|
| 26 |
|
---|
| 27 | 04/03
|
---|
| 28 | - added star support
|
---|
| 29 |
|
---|
| 30 | 03/12
|
---|
| 31 | - modified offer_to_write_floppies() to support dual-disk boot/root thing
|
---|
| 32 |
|
---|
| 33 | 01/20/2004
|
---|
| 34 | - reformat dvd twice if necessary
|
---|
| 35 |
|
---|
| 36 | 12/01/2003
|
---|
| 37 | - added pause_for_N_seconds(5, "Letting DVD drive settle");
|
---|
| 38 |
|
---|
| 39 | 11/23
|
---|
| 40 | - added #define DVDRWFORMAT
|
---|
| 41 |
|
---|
| 42 | 11/20
|
---|
| 43 | - use --no-emul-boot -b isolinux.bin instead of -b mindi-boot.2880.img
|
---|
| 44 |
|
---|
| 45 | 10/23
|
---|
| 46 | - wipe DVD at start, whether or not disk is DVD-RW; this is
|
---|
| 47 | just a test, to see why dvd+rw-format followed by growiosfs
|
---|
| 48 | locks up the drive
|
---|
| 49 | - use the singlethreaded make_afioballs_and_images_OLD()
|
---|
| 50 | instead of the multithreaded make_afioballs_and_images()
|
---|
| 51 | if backing up to tape
|
---|
| 52 |
|
---|
| 53 | 10/21
|
---|
| 54 | - if backing up to dvd, look for relevant tools;
|
---|
| 55 | abort if missing
|
---|
| 56 |
|
---|
| 57 | 10/15
|
---|
| 58 | - UI tweaks
|
---|
| 59 |
|
---|
| 60 | 10/10
|
---|
| 61 | - eject/inject DVD after wiping it
|
---|
| 62 |
|
---|
| 63 | 09/27
|
---|
| 64 | - pause_and_ask_for_cdr() will now blank DVD if necessary
|
---|
| 65 |
|
---|
| 66 | 09/26
|
---|
| 67 | - proper reporting of media type in displayed strings
|
---|
| 68 | (i.e. DVD if DVD, CD if CD, etc.)
|
---|
| 69 |
|
---|
| 70 | 09/25
|
---|
| 71 | - add DVD support
|
---|
| 72 |
|
---|
| 73 | 09/23
|
---|
| 74 | - malloc/free global strings in new subroutines - malloc_libmondo_global_strings()
|
---|
| 75 | and free_libmondo_global_strings() - which are in libmondo-tools.c
|
---|
| 76 |
|
---|
| 77 | 09/15
|
---|
| 78 | - changed a bunch of char[MAX_STR_LEN]'s to char*; malloc; free;
|
---|
| 79 |
|
---|
| 80 | 09/14
|
---|
| 81 | - cosmetic bug re: call to 'which dvdrecord'
|
---|
| 82 |
|
---|
| 83 | 09/09
|
---|
| 84 | - copy `locate isolinux.bin | tail -n1` to CD before calling mkisfso
|
---|
| 85 | if file is missing (in which case, bug in Mindi.pl!)
|
---|
| 86 | - reduced noof_threads from 3 to 2
|
---|
| 87 | - fixed cosmetic bug in make_slices_and_images()
|
---|
| 88 |
|
---|
| 89 | 09/02
|
---|
| 90 | - fixed cosmetic bug in verify_data()
|
---|
| 91 |
|
---|
| 92 | 05/01 - 08/31
|
---|
| 93 | - added partimagehack hooks
|
---|
| 94 | - make twice as many archives at once as before
|
---|
| 95 | - fixed syntax error re: system(xxx,FALSE)
|
---|
| 96 | - unmount CD-ROM before burning (necessary for RH8/9)
|
---|
| 97 | - only ask for new media if sensible
|
---|
| 98 | - fixed mondoarchive -Vi multi-CD verify bug (Tom Mortell)
|
---|
| 99 | - use single-threaded make_afioballs_and_images() if FreeBSD
|
---|
| 100 | - fixed bug on line 476 (Joshua Oreman)
|
---|
| 101 | - re-enabled the pause, for people w/ weird CD-ROM drives
|
---|
| 102 | - added Joshua Oreman's FreeBSD patches
|
---|
| 103 | - don't listen to please_dont_eject_when_restoring
|
---|
| 104 | ...after all, we're not restoring :)
|
---|
| 105 |
|
---|
| 106 | 04/01 - 04/30
|
---|
| 107 | - cleaned up archive_this_fileset()
|
---|
| 108 | - decreased ARCH_THREADS from 3 to 2
|
---|
| 109 | - pause_and_ask_for_cd() --- calls retract_CD_tray_and_defeat_autorun()
|
---|
| 110 | - call assert() and log_OS_error() in various places
|
---|
| 111 | - cleaned up code a bit
|
---|
| 112 | - increased ARCH_THREADS from 2 to 3
|
---|
| 113 | - misc clean-up (Tom Mortell)
|
---|
| 114 |
|
---|
| 115 | 03/15/2003
|
---|
| 116 | - fixed problem w/ multi-ISO verify cycle (Tom Mortell)
|
---|
| 117 |
|
---|
| 118 | 11/01 - 12/31/2002
|
---|
| 119 | - removed references to make_afioballs_and_images_OLD()
|
---|
| 120 | - added some error-checking to make_afioballs_in_background
|
---|
| 121 | - make_iso_and_go_on() now copies Mondo's autorun file to CD
|
---|
| 122 | - set scratchdir dir to 1744 when burning CD
|
---|
| 123 | - cleaned up code a bit
|
---|
| 124 | - in call_mindi_...(), gracefully handle the user's input
|
---|
| 125 | if they specify the boot loader but not the boot device
|
---|
| 126 | - offer to abort if GRUB is boot loader and /dev/md* is
|
---|
| 127 | the boot device (bug in grub-install)
|
---|
| 128 | - if boot loader is R then write RAW as bootloader.name
|
---|
| 129 | - multithreaded make_afioballs_and_images()
|
---|
| 130 | - fixed slice_up_file_etc() for 0-compression users
|
---|
| 131 | - line 1198: added call to is_this_file_compressed() to stop
|
---|
| 132 | slice_up_file_etc() from compressing files which are
|
---|
| 133 | already compressed
|
---|
| 134 | - other hackery related to the above enhancement
|
---|
| 135 | - afio no longer forcibly compresses all files (i.e. I dropped
|
---|
| 136 | the -U following suggestions from users); let's see if
|
---|
| 137 | it works :)
|
---|
| 138 |
|
---|
| 139 | 10/01 - 10/31
|
---|
| 140 | - mondoarchive (with no parameters) wasn't working
|
---|
| 141 | if user said yes when asked if BurnProof drive; FIXED
|
---|
| 142 | - if manual CD tray and writing to ISO's then prompt
|
---|
| 143 | for each & every new CD
|
---|
| 144 | - moved a lot of subroutines here
|
---|
| 145 | from mondo-archive.c and mondo-floppies.c
|
---|
| 146 |
|
---|
| 147 | 09/01 - 09/30
|
---|
| 148 | - if CD not burned OK then don't try to verify
|
---|
| 149 | - change 64k to TAPE_BLOCK_SIZE
|
---|
| 150 | - run_program_and_log_output() now takes boolean operator to specify
|
---|
| 151 | whether it will log its activities in the event of _success_
|
---|
| 152 | - orig_vfy_flag_val added to write_iso_and_go_on, to restore bkpinfo->verify_data's
|
---|
| 153 | value if altered by verify_cd_image()
|
---|
| 154 |
|
---|
| 155 | 08/01 - 08/31
|
---|
| 156 | - use data structure to store the fname, checksum, mods & perms of each bigfile
|
---|
| 157 | ... biggiestruct :)
|
---|
| 158 | - bigger tmp[]'s in a few places
|
---|
| 159 | - cleaned up the (user-friendly) counting of biggiefiles a bit
|
---|
| 160 | - if media_size[N]<=0 then catch it & abort, unless it's tape,
|
---|
| 161 | in which case, allow it
|
---|
| 162 | - cleaned up a lot of log_it() calls
|
---|
| 163 | - fixed NULL filename-related bug in can_we_fit_these_files_on_media()
|
---|
| 164 | - deleted can_we_fit.....() subroutine because it was causing problems
|
---|
| 165 | --- moved its code into the one subroutine which called it
|
---|
| 166 | - created [08/01/2002]
|
---|
| 167 | */
|
---|
| 168 |
|
---|
| 169 | /**
|
---|
| 170 | * @file
|
---|
| 171 | * Functions to handle backing up data.
|
---|
| 172 | * This is the main file (at least the longest one) in libmondo.
|
---|
| 173 | */
|
---|
| 174 |
|
---|
[1316] | 175 | #include "my-stuff.h"
|
---|
| 176 | #include "mondostructures.h"
|
---|
[1] | 177 | #include "libmondo-string-EXT.h"
|
---|
| 178 | #include "libmondo-stream-EXT.h"
|
---|
| 179 | #include "libmondo-devices-EXT.h"
|
---|
| 180 | #include "libmondo-tools-EXT.h"
|
---|
[541] | 181 | #include "libmondo-gui-EXT.h"
|
---|
[1] | 182 | #include "libmondo-fork-EXT.h"
|
---|
| 183 | #include "libmondo-files-EXT.h"
|
---|
| 184 | #include "libmondo-filelist-EXT.h"
|
---|
| 185 | #include "libmondo-tools-EXT.h"
|
---|
| 186 | #include "libmondo-verify-EXT.h"
|
---|
| 187 | #include "libmondo-archive.h"
|
---|
[541] | 188 | #include "lib-common-externs.h"
|
---|
[1] | 189 | #include <sys/sem.h>
|
---|
| 190 | #include <sys/types.h>
|
---|
| 191 | #include <sys/ipc.h>
|
---|
| 192 | #include <stdarg.h>
|
---|
| 193 | #define DVDRWFORMAT 1
|
---|
| 194 |
|
---|
| 195 |
|
---|
| 196 |
|
---|
| 197 | /** @def DEFAULT_1722MB_DISK The default 1.722M floppy disk to write images to. */
|
---|
| 198 | /** @def BACKUP_1722MB_DISK The 1.722M floppy disk to try if the default fails. */
|
---|
| 199 |
|
---|
| 200 | #ifdef __FreeBSD__
|
---|
[128] | 201 | #define DEFAULT_1722MB_DISK "/dev/fd0.1722"
|
---|
| 202 | #define BACKUP_1722MB_DISK "/dev/fd0.1722"
|
---|
[1] | 203 | #else
|
---|
[128] | 204 | #define DEFAULT_1722MB_DISK "/dev/fd0u1722"
|
---|
| 205 | #define BACKUP_1722MB_DISK "/dev/fd0H1722"
|
---|
[1] | 206 | #ifndef _SEMUN_H
|
---|
[128] | 207 | #define _SEMUN_H
|
---|
[1] | 208 |
|
---|
| 209 | /**
|
---|
| 210 | * The semaphore union, provided only in case the user's system doesn't.
|
---|
| 211 | */
|
---|
[128] | 212 | union semun {
|
---|
| 213 | int val;
|
---|
| 214 | struct semid_ds *buf;
|
---|
| 215 | unsigned short int *array;
|
---|
| 216 | struct seminfo *__buf;
|
---|
| 217 | };
|
---|
[1] | 218 | #endif
|
---|
[128] | 219 | #endif /* __FreeBSD__ */
|
---|
[1] | 220 |
|
---|
| 221 | /*@unused@*/
|
---|
[99] | 222 | //static char cvsid[] = "$Id: libmondo-archive.c 1317 2007-04-16 16:26:55Z bruno $";
|
---|
[1] | 223 |
|
---|
| 224 | /* *************************** external global vars ******************/
|
---|
| 225 | extern int g_current_media_number;
|
---|
| 226 | extern int g_currentY;
|
---|
| 227 | extern bool g_text_mode;
|
---|
| 228 | extern bool g_exiting;
|
---|
| 229 | extern long g_current_progress;
|
---|
[128] | 230 | extern FILE *g_tape_stream;
|
---|
[1] | 231 | extern long long g_tape_posK;
|
---|
| 232 | extern char *g_mondo_home;
|
---|
| 233 | extern char *g_tmpfs_mountpt;
|
---|
| 234 | extern bool g_cd_recovery;
|
---|
| 235 | extern char *g_serial_string;
|
---|
| 236 |
|
---|
[948] | 237 | extern char *g_getfacl;
|
---|
| 238 | extern char *g_getfattr;
|
---|
[1316] | 239 | extern char *MONDO_LOGFILE;
|
---|
[948] | 240 |
|
---|
| 241 |
|
---|
| 242 |
|
---|
[1] | 243 | /**
|
---|
| 244 | * @addtogroup globalGroup
|
---|
| 245 | * @{
|
---|
| 246 | */
|
---|
| 247 | /**
|
---|
| 248 | * The current backup media type in use.
|
---|
| 249 | */
|
---|
[128] | 250 | t_bkptype g_backup_media_type = none;
|
---|
[1] | 251 |
|
---|
| 252 | /**
|
---|
| 253 | * Incremented by each archival thread when it starts up. After that,
|
---|
| 254 | * this is the number of threads running.
|
---|
| 255 | */
|
---|
| 256 | int g_current_thread_no = 0;
|
---|
| 257 |
|
---|
| 258 | /* @} - end of globalGroup */
|
---|
| 259 |
|
---|
| 260 | extern int g_noof_rows;
|
---|
| 261 |
|
---|
| 262 | /* Semaphore-related code */
|
---|
| 263 |
|
---|
| 264 | static int set_semvalue(void);
|
---|
| 265 | static void del_semvalue(void);
|
---|
| 266 | static int semaphore_p(void);
|
---|
| 267 | static int semaphore_v(void);
|
---|
| 268 |
|
---|
| 269 | static int g_sem_id;
|
---|
| 270 | static int g_sem_key;
|
---|
| 271 |
|
---|
| 272 |
|
---|
| 273 |
|
---|
| 274 |
|
---|
| 275 | /**
|
---|
| 276 | * Initialize the semaphore.
|
---|
| 277 | * @see del_semvalue
|
---|
| 278 | * @see semaphore_p
|
---|
| 279 | * @see semaphore_v
|
---|
| 280 | * @return 1 for success, 0 for failure.
|
---|
| 281 | */
|
---|
[128] | 282 | static int set_semvalue(void) // initializes semaphore
|
---|
[1] | 283 | {
|
---|
[128] | 284 | union semun sem_union;
|
---|
| 285 | sem_union.val = 1;
|
---|
| 286 | if (semctl(g_sem_id, 0, SETVAL, sem_union) == -1) {
|
---|
| 287 | return (0);
|
---|
| 288 | }
|
---|
| 289 | return (1);
|
---|
[1] | 290 | }
|
---|
| 291 |
|
---|
| 292 | /**
|
---|
| 293 | * Frees (deletes) the semaphore. Failure is indicated by a log
|
---|
| 294 | * message.
|
---|
| 295 | * @see set_semvalue
|
---|
| 296 | */
|
---|
[128] | 297 | static void del_semvalue(void) // deletes semaphore
|
---|
[1] | 298 | {
|
---|
[128] | 299 | union semun sem_union;
|
---|
[1] | 300 |
|
---|
[128] | 301 | if (semctl(g_sem_id, 0, IPC_RMID, sem_union) == -1) {
|
---|
| 302 | log_msg(3, "Failed to delete semaphore");
|
---|
| 303 | }
|
---|
[1] | 304 | }
|
---|
| 305 |
|
---|
| 306 | /**
|
---|
| 307 | * Acquire (increment) the semaphore (change status to P).
|
---|
| 308 | * @return 1 for success, 0 for failure.
|
---|
| 309 | * @see semaphore_v
|
---|
| 310 | */
|
---|
[128] | 311 | static int semaphore_p(void) // changes status to 'P' (waiting)
|
---|
[1] | 312 | {
|
---|
[128] | 313 | struct sembuf sem_b;
|
---|
[1] | 314 |
|
---|
[128] | 315 | sem_b.sem_num = 0;
|
---|
| 316 | sem_b.sem_op = -1; // P()
|
---|
| 317 | sem_b.sem_flg = SEM_UNDO;
|
---|
| 318 | if (semop(g_sem_id, &sem_b, 1) == -1) {
|
---|
| 319 | log_msg(3, "semaphore_p failed");
|
---|
| 320 | return (0);
|
---|
| 321 | }
|
---|
| 322 | return (1);
|
---|
[1] | 323 | }
|
---|
| 324 |
|
---|
| 325 | /**
|
---|
| 326 | * Free (decrement) the semaphore (change status to V).
|
---|
| 327 | * @return 1 for success, 0 for failure.
|
---|
| 328 | */
|
---|
[128] | 329 | static int semaphore_v(void) // changes status to 'V' (free)
|
---|
[1] | 330 | {
|
---|
[128] | 331 | struct sembuf sem_b;
|
---|
[1] | 332 |
|
---|
[128] | 333 | sem_b.sem_num = 0;
|
---|
| 334 | sem_b.sem_op = 1; // V()
|
---|
| 335 | sem_b.sem_flg = SEM_UNDO;
|
---|
| 336 | if (semop(g_sem_id, &sem_b, 1) == -1) {
|
---|
| 337 | log_msg(3, "semaphore_v failed");
|
---|
| 338 | return (0);
|
---|
| 339 | }
|
---|
| 340 | return (1);
|
---|
[1] | 341 | }
|
---|
| 342 |
|
---|
| 343 |
|
---|
| 344 | //------------------------------------------------------
|
---|
| 345 |
|
---|
| 346 |
|
---|
| 347 | /**
|
---|
| 348 | * Size in megabytes of the buffer afforded to the executable "buffer".
|
---|
| 349 | * This figure is used when we calculate how much data we have probably 'lost'
|
---|
| 350 | * when writing off the end of tape N, so that we can then figure out how much
|
---|
| 351 | * data we must recreate & write to the start of tape N+1.
|
---|
| 352 | */
|
---|
| 353 | extern int g_tape_buffer_size_MB;
|
---|
| 354 |
|
---|
| 355 |
|
---|
| 356 |
|
---|
| 357 |
|
---|
| 358 | int
|
---|
[128] | 359 | archive_this_fileset_with_star(struct s_bkpinfo *bkpinfo, char *filelist,
|
---|
| 360 | char *fname, int setno)
|
---|
[1] | 361 | {
|
---|
[128] | 362 | int retval = 0;
|
---|
| 363 | unsigned int res = 0;
|
---|
| 364 | int tries = 0;
|
---|
| 365 | char *command;
|
---|
| 366 | char *zipparams;
|
---|
| 367 | char *tmp;
|
---|
| 368 | char *p;
|
---|
[1] | 369 |
|
---|
[128] | 370 | malloc_string(command);
|
---|
| 371 | malloc_string(zipparams);
|
---|
| 372 | malloc_string(tmp);
|
---|
[1] | 373 |
|
---|
[128] | 374 | if (!does_file_exist(filelist)) {
|
---|
| 375 | sprintf(tmp, "(archive_this_fileset) - filelist %s does not exist",
|
---|
| 376 | filelist);
|
---|
| 377 | log_to_screen(tmp);
|
---|
| 378 | return (1);
|
---|
[1] | 379 | }
|
---|
| 380 |
|
---|
[128] | 381 | sprintf(tmp, "echo hi > %s 2> /dev/null", fname);
|
---|
| 382 | if (system(tmp)) {
|
---|
| 383 | fatal_error("Unable to write tarball to scratchdir");
|
---|
| 384 | }
|
---|
| 385 |
|
---|
| 386 | sprintf(command, "star H=star list=%s -c " STAR_ACL_SZ " file=%s",
|
---|
| 387 | filelist, fname);
|
---|
| 388 | if (bkpinfo->use_lzo) {
|
---|
| 389 | fatal_error("Can't use lzop");
|
---|
| 390 | }
|
---|
| 391 | if (bkpinfo->compression_level > 0) {
|
---|
| 392 | strcat(command, " -bz");
|
---|
| 393 | }
|
---|
| 394 | sprintf(command + strlen(command), " 2>> %s", MONDO_LOGFILE);
|
---|
| 395 | log_msg(4, "command = '%s'", command);
|
---|
| 396 |
|
---|
| 397 | for (res = 99, tries = 0; tries < 3 && res != 0; tries++) {
|
---|
| 398 | log_msg(5, "command='%s'", command);
|
---|
| 399 | res = system(command);
|
---|
| 400 | strcpy(tmp, last_line_of_file(MONDO_LOGFILE));
|
---|
| 401 | log_msg(1, "res=%d; tmp='%s'", res, tmp);
|
---|
| 402 | if (bkpinfo->use_star && (res == 254 || res == 65024)
|
---|
| 403 | && strstr(tmp, "star: Processed all possible files")
|
---|
| 404 | && tries > 0) {
|
---|
| 405 | log_msg(1, "Star returned nonfatal error");
|
---|
| 406 | res = 0;
|
---|
| 407 | }
|
---|
| 408 | if (res) {
|
---|
| 409 | log_OS_error(command);
|
---|
| 410 | p = strstr(command, "-acl ");
|
---|
| 411 | if (p) {
|
---|
| 412 | p[0] = p[1] = p[2] = p[3] = ' ';
|
---|
| 413 | log_msg(1, "new command = '%s'", command);
|
---|
| 414 | } else {
|
---|
| 415 | log_msg(3,
|
---|
| 416 | "Attempt #%d failed. Pausing 3 seconds and retrying...",
|
---|
| 417 | tries + 1);
|
---|
| 418 | sleep(3);
|
---|
| 419 | }
|
---|
| 420 | }
|
---|
| 421 | }
|
---|
| 422 | retval += res;
|
---|
| 423 | if (retval) {
|
---|
| 424 | log_msg(3, "Failed to write set %d", setno);
|
---|
| 425 | } else if (tries > 1) {
|
---|
| 426 | log_msg(3, "Succeeded in writing set %d, on try #%d", setno,
|
---|
| 427 | tries);
|
---|
| 428 | }
|
---|
| 429 |
|
---|
| 430 | paranoid_free(command);
|
---|
| 431 | paranoid_free(zipparams);
|
---|
| 432 | paranoid_free(tmp);
|
---|
| 433 | return (retval);
|
---|
[1] | 434 | }
|
---|
| 435 |
|
---|
| 436 |
|
---|
| 437 | /**
|
---|
| 438 | * Call @c afio to archive the filelist @c filelist to the file @c fname.
|
---|
| 439 | *
|
---|
| 440 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 441 | * - @c compression_level
|
---|
| 442 | * - @c scratchdir (only verifies existence)
|
---|
| 443 | * - @c tmpdir (only verifies existence)
|
---|
| 444 | * - @c zip_exe
|
---|
| 445 | * - @c zip_suffix
|
---|
| 446 | * @param filelist The path to a file containing a list of files to be archived
|
---|
| 447 | * in this fileset.
|
---|
| 448 | * @param fname The output file to archive to.
|
---|
| 449 | * @param setno This fileset number.
|
---|
| 450 | * @return The number of errors encountered (0 for success).
|
---|
| 451 | * @ingroup LLarchiveGroup
|
---|
| 452 | */
|
---|
| 453 | int
|
---|
[128] | 454 | archive_this_fileset(struct s_bkpinfo *bkpinfo, char *filelist,
|
---|
| 455 | char *fname, int setno)
|
---|
[1] | 456 | {
|
---|
| 457 |
|
---|
[128] | 458 | /*@ int *************************************************************** */
|
---|
| 459 | int retval = 0;
|
---|
| 460 | int res = 0;
|
---|
| 461 | int i = 0;
|
---|
| 462 | int tries = 0;
|
---|
| 463 | static int free_ramdisk_space = 9999;
|
---|
[1] | 464 |
|
---|
[128] | 465 | /*@ buffers ************************************************************ */
|
---|
| 466 | char *command;
|
---|
| 467 | char *zipparams;
|
---|
| 468 | char *tmp;
|
---|
[1] | 469 |
|
---|
[128] | 470 | assert(bkpinfo != NULL);
|
---|
| 471 | assert_string_is_neither_NULL_nor_zerolength(filelist);
|
---|
| 472 | assert_string_is_neither_NULL_nor_zerolength(fname);
|
---|
[1] | 473 |
|
---|
[128] | 474 | if (bkpinfo->compression_level > 0 && bkpinfo->use_star) {
|
---|
| 475 | return (archive_this_fileset_with_star
|
---|
| 476 | (bkpinfo, filelist, fname, setno));
|
---|
| 477 | }
|
---|
[1] | 478 |
|
---|
[128] | 479 | malloc_string(command);
|
---|
| 480 | malloc_string(zipparams);
|
---|
| 481 | malloc_string(tmp);
|
---|
| 482 |
|
---|
| 483 | if (!does_file_exist(filelist)) {
|
---|
| 484 | sprintf(tmp, "(archive_this_fileset) - filelist %s does not exist",
|
---|
| 485 | filelist);
|
---|
| 486 | log_to_screen(tmp);
|
---|
| 487 | return (1);
|
---|
| 488 | }
|
---|
| 489 | sprintf(tmp, "echo hi > %s 2> /dev/null", fname);
|
---|
| 490 | if (system(tmp)) {
|
---|
| 491 | fatal_error("Unable to write tarball to scratchdir");
|
---|
| 492 | }
|
---|
| 493 |
|
---|
| 494 |
|
---|
| 495 | if (bkpinfo->compression_level > 0) {
|
---|
| 496 | sprintf(tmp, "%s/do-not-compress-these", g_mondo_home);
|
---|
| 497 | // -b %ld, TAPE_BLOCK_SIZE
|
---|
| 498 | sprintf(zipparams, "-Z -P %s -G %d -T 3k", bkpinfo->zip_exe,
|
---|
| 499 | bkpinfo->compression_level);
|
---|
| 500 | if (does_file_exist(tmp)) {
|
---|
| 501 | strcat(zipparams, " -E ");
|
---|
| 502 | strcat(zipparams, tmp);
|
---|
| 503 | } else {
|
---|
| 504 | log_msg(3, "%s not found. Cannot exclude zipfiles, etc.", tmp);
|
---|
| 505 | }
|
---|
| 506 | } else {
|
---|
| 507 | zipparams[0] = '\0';
|
---|
| 508 | }
|
---|
| 509 |
|
---|
[1] | 510 | // make_hole_for_file(fname);
|
---|
| 511 |
|
---|
[128] | 512 | if (!does_file_exist(bkpinfo->tmpdir)) {
|
---|
| 513 | log_OS_error("tmpdir not found");
|
---|
| 514 | fatal_error("tmpdir not found");
|
---|
| 515 | }
|
---|
| 516 | if (!does_file_exist(bkpinfo->scratchdir)) {
|
---|
| 517 | log_OS_error("scratchdir not found");
|
---|
| 518 | fatal_error("scratchdir not found");
|
---|
| 519 | }
|
---|
| 520 | sprintf(command, "rm -f %s %s. %s.gz %s.%s", fname, fname, fname,
|
---|
| 521 | fname, bkpinfo->zip_suffix);
|
---|
| 522 | paranoid_system(command);
|
---|
[1] | 523 |
|
---|
[128] | 524 | sprintf(command, "afio -o -b %ld -M 16m %s %s < %s 2>> %s",
|
---|
| 525 | TAPE_BLOCK_SIZE, zipparams, fname, filelist, MONDO_LOGFILE);
|
---|
[1] | 526 |
|
---|
[128] | 527 | sprintf(tmp, "echo hi > %s 2> /dev/null", fname);
|
---|
| 528 | if (system(tmp)) {
|
---|
| 529 | fatal_error("Unable to write tarball to scratchdir");
|
---|
| 530 | }
|
---|
[1] | 531 |
|
---|
[128] | 532 | for (res = 99, tries = 0; tries < 3 && res != 0; tries++) {
|
---|
| 533 | log_msg(5, "command='%s'", command);
|
---|
| 534 | res = system(command);
|
---|
| 535 | if (res) {
|
---|
| 536 | log_OS_error(command);
|
---|
| 537 | log_msg(3,
|
---|
| 538 | "Attempt #%d failed. Pausing 3 seconds and retrying...",
|
---|
| 539 | tries + 1);
|
---|
| 540 | sleep(3);
|
---|
| 541 | }
|
---|
| 542 | }
|
---|
| 543 | retval += res;
|
---|
| 544 | if (retval) {
|
---|
| 545 | log_msg(3, "Failed to write set %d", setno);
|
---|
| 546 | } else if (tries > 1) {
|
---|
| 547 | log_msg(3, "Succeeded in writing set %d, on try #%d", setno,
|
---|
| 548 | tries);
|
---|
| 549 | }
|
---|
[1] | 550 |
|
---|
[128] | 551 | if (g_tmpfs_mountpt[0] != '\0') {
|
---|
| 552 | i = atoi(call_program_and_get_last_line_of_output
|
---|
[305] | 553 | ("df -m -P | grep dev/shm | grep -v none | tr -s ' ' '\t' | cut -f4"));
|
---|
[128] | 554 | if (i > 0) {
|
---|
| 555 | if (free_ramdisk_space > i) {
|
---|
| 556 | free_ramdisk_space = i;
|
---|
| 557 | log_msg(2, "min(free_ramdisk_space) is now %d",
|
---|
| 558 | free_ramdisk_space);
|
---|
| 559 | if (free_ramdisk_space < 10) {
|
---|
| 560 | fatal_error
|
---|
| 561 | ("Please increase PPCFG_RAMDISK_SIZE in my-stuff.h to increase size of ramdisk ");
|
---|
| 562 | }
|
---|
| 563 | }
|
---|
| 564 | }
|
---|
| 565 | }
|
---|
| 566 | paranoid_free(command);
|
---|
| 567 | paranoid_free(zipparams);
|
---|
| 568 | paranoid_free(tmp);
|
---|
| 569 | return (retval);
|
---|
[1] | 570 | }
|
---|
| 571 |
|
---|
| 572 |
|
---|
| 573 |
|
---|
| 574 |
|
---|
| 575 |
|
---|
| 576 |
|
---|
| 577 | /**
|
---|
| 578 | * Wrapper function for all the backup commands.
|
---|
| 579 | * Calls these other functions: @c prepare_filelist(),
|
---|
| 580 | * @c call_filelist_chopper(), @c copy_mondo_and_mindi_stuff_to_scratchdir(),
|
---|
| 581 | * @c call_mindi_to_supply_boot_disks(), @c do_that_initial_phase(),
|
---|
| 582 | * @c make_those_afios_phase(), @c make_those_slices_phase(), and
|
---|
| 583 | * @c do_that_final_phase(). If anything fails before @c do_that_initial_phase(),
|
---|
| 584 | * @c fatal_error is called with a suitable message.
|
---|
| 585 | * @param bkpinfo The backup information structure. Uses most fields.
|
---|
| 586 | * @return The number of non-fatal errors encountered (0 for success).
|
---|
| 587 | * @ingroup archiveGroup
|
---|
| 588 | */
|
---|
[541] | 589 | int backup_data(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 590 | {
|
---|
[128] | 591 | int retval = 0, res = 0;
|
---|
| 592 | char *tmp;
|
---|
[1] | 593 |
|
---|
[128] | 594 | assert(bkpinfo != NULL);
|
---|
| 595 | set_g_cdrom_and_g_dvd_to_bkpinfo_value(bkpinfo);
|
---|
| 596 | malloc_string(tmp);
|
---|
| 597 | if (bkpinfo->backup_media_type == dvd) {
|
---|
[1] | 598 | #ifdef DVDRWFORMAT
|
---|
[128] | 599 | if (!find_home_of_exe("dvd+rw-format")) {
|
---|
| 600 | fatal_error
|
---|
| 601 | ("Cannot find dvd+rw-format. Please install it or fix your PATH.");
|
---|
| 602 | }
|
---|
[1] | 603 | #endif
|
---|
[128] | 604 | if (!find_home_of_exe("growisofs")) {
|
---|
| 605 | fatal_error
|
---|
| 606 | ("Cannot find growisofs. Please install it or fix your PATH.");
|
---|
| 607 | }
|
---|
[1] | 608 | }
|
---|
| 609 |
|
---|
[128] | 610 | if ((res = prepare_filelist(bkpinfo))) { /* generate scratchdir/filelist.full */
|
---|
| 611 | fatal_error("Failed to generate filelist catalog");
|
---|
| 612 | }
|
---|
| 613 | if (call_filelist_chopper(bkpinfo)) {
|
---|
| 614 | fatal_error("Failed to run filelist chopper");
|
---|
| 615 | }
|
---|
[1] | 616 |
|
---|
| 617 | /*
|
---|
| 618 | sprintf(tmp, "wc -l %s/archives/filelist.full > %s/archives/filelist.count",bkpinfo->scratchdir, bkpinfo->scratchdir);
|
---|
| 619 | if (run_program_and_log_output(tmp, 2))
|
---|
| 620 | { fatal_error("Failed to count filelist.full"); }
|
---|
| 621 | */
|
---|
[128] | 622 | sprintf(tmp, "gzip -9 %s/archives/filelist.full", bkpinfo->scratchdir);
|
---|
| 623 | if (run_program_and_log_output(tmp, 2)) {
|
---|
| 624 | fatal_error("Failed to gzip filelist.full");
|
---|
| 625 | }
|
---|
| 626 | sprintf(tmp, "cp -f %s/archives/*list*.gz %s", bkpinfo->scratchdir,
|
---|
| 627 | bkpinfo->tmpdir);
|
---|
| 628 | if (run_program_and_log_output(tmp, 2)) {
|
---|
| 629 | fatal_error("Failed to copy to tmpdir");
|
---|
| 630 | }
|
---|
[1] | 631 |
|
---|
[128] | 632 | copy_mondo_and_mindi_stuff_to_scratchdir(bkpinfo); // payload, too, if it exists
|
---|
[1] | 633 | #if __FreeBSD__ == 5
|
---|
[128] | 634 | strcpy(bkpinfo->kernel_path, "/boot/kernel/kernel");
|
---|
[1] | 635 | #elif __FreeBSD__ == 4
|
---|
[128] | 636 | strcpy(bkpinfo->kernel_path, "/kernel");
|
---|
[1] | 637 | #elif linux
|
---|
[128] | 638 | if (figure_out_kernel_path_interactively_if_necessary
|
---|
| 639 | (bkpinfo->kernel_path)) {
|
---|
| 640 | fatal_error
|
---|
| 641 | ("Kernel not found. Please specify manually with the '-k' switch.");
|
---|
| 642 | }
|
---|
[1] | 643 | #else
|
---|
| 644 | #error "I don't know about this system!"
|
---|
| 645 | #endif
|
---|
[128] | 646 | if ((res = call_mindi_to_supply_boot_disks(bkpinfo))) {
|
---|
| 647 | fatal_error("Failed to generate boot+data disks");
|
---|
| 648 | }
|
---|
| 649 | retval += do_that_initial_phase(bkpinfo); // prepare
|
---|
| 650 | sprintf(tmp, "rm -f %s/images/*.iso", bkpinfo->scratchdir);
|
---|
| 651 | run_program_and_log_output(tmp, 1);
|
---|
[541] | 652 | retval += make_those_afios_phase(bkpinfo); // backup regular files
|
---|
[128] | 653 | retval += make_those_slices_phase(bkpinfo); // backup BIG files
|
---|
| 654 | retval += do_that_final_phase(bkpinfo); // clean up
|
---|
| 655 | log_msg(1, "Creation of archives... complete.");
|
---|
| 656 | if (bkpinfo->verify_data) {
|
---|
| 657 | sleep(2);
|
---|
| 658 | }
|
---|
| 659 | paranoid_free(tmp);
|
---|
| 660 | return (retval);
|
---|
[1] | 661 | }
|
---|
| 662 |
|
---|
| 663 |
|
---|
| 664 |
|
---|
| 665 |
|
---|
| 666 | /**
|
---|
| 667 | * Call Mindi to generate boot and data disks.
|
---|
| 668 | * @note This binds correctly to the new Perl version of mindi.
|
---|
| 669 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 670 | * - @c backup_media_type
|
---|
| 671 | * - @c boot_loader
|
---|
| 672 | * - @c boot_device
|
---|
| 673 | * - @c compression_level
|
---|
| 674 | * - @c differential
|
---|
| 675 | * - @c exclude_paths
|
---|
| 676 | * - @c image_devs
|
---|
| 677 | * - @c kernel_path
|
---|
| 678 | * - @c make_cd_use_lilo
|
---|
| 679 | * - @c media_device
|
---|
| 680 | * - @c media_size
|
---|
| 681 | * - @c nonbootable_backup
|
---|
| 682 | * - @c scratchdir
|
---|
| 683 | * - @c tmpdir
|
---|
| 684 | * - @c use_lzo
|
---|
| 685 | *
|
---|
| 686 | * @return The number of errors encountered (0 for success)
|
---|
| 687 | * @bug The code to automagically determine the boot drive
|
---|
| 688 | * is messy and system-dependent. In particular, it breaks
|
---|
| 689 | * for Linux RAID and LVM users.
|
---|
| 690 | * @ingroup MLarchiveGroup
|
---|
| 691 | */
|
---|
[128] | 692 | int call_mindi_to_supply_boot_disks(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 693 | {
|
---|
[128] | 694 | /*@ buffer ************************************************************ */
|
---|
| 695 | char *tmp;
|
---|
[949] | 696 | char *tmp1 = NULL;
|
---|
[128] | 697 | char *scratchdir;
|
---|
[1] | 698 | char *command;
|
---|
| 699 | char *use_lzo_sz;
|
---|
[998] | 700 | char *use_gzip_sz;
|
---|
[128] | 701 | char *use_comp_sz;
|
---|
[1] | 702 | char *use_star_sz;
|
---|
| 703 | char *bootldr_str;
|
---|
| 704 | char *tape_device;
|
---|
| 705 | char *last_filelist_number;
|
---|
| 706 | char *broken_bios_sz;
|
---|
| 707 | char *cd_recovery_sz;
|
---|
| 708 | char *tape_size_sz;
|
---|
| 709 | char *devs_to_exclude;
|
---|
[128] | 710 | char *use_lilo_sz;
|
---|
| 711 | char *value;
|
---|
[1] | 712 | char *bootdev;
|
---|
| 713 |
|
---|
| 714 |
|
---|
| 715 |
|
---|
[128] | 716 | /*@ char ************************************************************** */
|
---|
[1] | 717 | char ch = '\0';
|
---|
| 718 |
|
---|
[128] | 719 | /*@ long ********************************************************** */
|
---|
| 720 | long lines_in_filelist = 0;
|
---|
[1] | 721 |
|
---|
[128] | 722 | /*@ int ************************************************************* */
|
---|
| 723 | int res = 0;
|
---|
| 724 | long estimated_total_noof_slices = 0;
|
---|
[1] | 725 |
|
---|
[128] | 726 | assert(bkpinfo != NULL);
|
---|
| 727 | command = malloc(1200);
|
---|
| 728 | malloc_string(tmp);
|
---|
| 729 | malloc_string(scratchdir);
|
---|
| 730 | malloc_string(use_lzo_sz);
|
---|
[998] | 731 | malloc_string(use_gzip_sz);
|
---|
[128] | 732 | malloc_string(use_star_sz);
|
---|
| 733 | malloc_string(use_comp_sz);
|
---|
| 734 | malloc_string(bootldr_str);
|
---|
| 735 | malloc_string(tape_device);
|
---|
| 736 | malloc_string(last_filelist_number);
|
---|
| 737 | malloc_string(broken_bios_sz);
|
---|
| 738 | malloc_string(cd_recovery_sz);
|
---|
| 739 | malloc_string(tape_size_sz);
|
---|
| 740 | malloc_string(devs_to_exclude);
|
---|
| 741 | malloc_string(use_lilo_sz); /* BCO: shared between LILO/ELILO */
|
---|
| 742 | malloc_string(value);
|
---|
| 743 | malloc_string(bootdev);
|
---|
[1] | 744 |
|
---|
[128] | 745 | strcpy(scratchdir, bkpinfo->scratchdir);
|
---|
| 746 | sprintf(tmp,
|
---|
[911] | 747 | "echo '%s' | tr -s ' ' '\n' | grep -E '^/dev/.*$' | tr -s '\n' ' ' | awk '{print $0\"\\n\";}'",
|
---|
[128] | 748 | bkpinfo->exclude_paths);
|
---|
| 749 | strcpy(devs_to_exclude, call_program_and_get_last_line_of_output(tmp));
|
---|
| 750 | sprintf(tmp, "devs_to_exclude = '%s'", devs_to_exclude);
|
---|
| 751 | log_msg(2, tmp);
|
---|
| 752 | mvaddstr_and_log_it(g_currentY, 0,
|
---|
| 753 | "Calling MINDI to create boot+data disks");
|
---|
| 754 | sprintf(tmp, "%s/filelist.full", bkpinfo->tmpdir);
|
---|
| 755 | if (!does_file_exist(tmp)) {
|
---|
| 756 | sprintf(tmp, "%s/tmpfs/filelist.full", bkpinfo->tmpdir);
|
---|
| 757 | if (!does_file_exist(tmp)) {
|
---|
| 758 | fatal_error
|
---|
| 759 | ("Cannot find filelist.full, so I cannot count its lines");
|
---|
| 760 | }
|
---|
| 761 | }
|
---|
| 762 | lines_in_filelist = count_lines_in_file(tmp);
|
---|
| 763 | sprintf(tmp, "%s/LAST-FILELIST-NUMBER", bkpinfo->tmpdir);
|
---|
| 764 | strcpy(last_filelist_number, last_line_of_file(tmp));
|
---|
| 765 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 766 | sprintf(tape_size_sz, "%ld", bkpinfo->media_size[1]);
|
---|
| 767 | strcpy(tape_device, bkpinfo->media_device);
|
---|
| 768 | } else {
|
---|
| 769 | tape_size_sz[0] = '\0';
|
---|
| 770 | tape_device[0] = '\0';
|
---|
| 771 | }
|
---|
| 772 | if (bkpinfo->use_lzo) {
|
---|
| 773 | strcpy(use_lzo_sz, "yes");
|
---|
| 774 | } else {
|
---|
| 775 | strcpy(use_lzo_sz, "no");
|
---|
| 776 | }
|
---|
[998] | 777 | if (bkpinfo->use_gzip) {
|
---|
| 778 | strcpy(use_gzip_sz, "yes");
|
---|
| 779 | } else {
|
---|
| 780 | strcpy(use_gzip_sz, "no");
|
---|
| 781 | }
|
---|
[128] | 782 | if (bkpinfo->use_star) {
|
---|
| 783 | strcpy(use_star_sz, "yes");
|
---|
| 784 | } else {
|
---|
| 785 | strcpy(use_star_sz, "no");
|
---|
| 786 | }
|
---|
[1] | 787 |
|
---|
[128] | 788 | if (bkpinfo->compression_level > 0) {
|
---|
| 789 | strcpy(use_comp_sz, "yes");
|
---|
| 790 | } else {
|
---|
| 791 | strcpy(use_comp_sz, "no");
|
---|
| 792 | }
|
---|
[1] | 793 |
|
---|
[128] | 794 | strcpy(broken_bios_sz, "yes"); /* assume so */
|
---|
| 795 | if (g_cd_recovery) {
|
---|
| 796 | strcpy(cd_recovery_sz, "yes");
|
---|
| 797 | } else {
|
---|
| 798 | strcpy(cd_recovery_sz, "no");
|
---|
| 799 | }
|
---|
| 800 | if (bkpinfo->make_cd_use_lilo) {
|
---|
| 801 | strcpy(use_lilo_sz, "yes");
|
---|
| 802 | } else {
|
---|
| 803 | strcpy(use_lilo_sz, "no");
|
---|
| 804 | }
|
---|
| 805 |
|
---|
| 806 | if (!bkpinfo->nonbootable_backup
|
---|
| 807 | && (bkpinfo->boot_loader == '\0'
|
---|
| 808 | || bkpinfo->boot_device[0] == '\0')) {
|
---|
| 809 |
|
---|
[1] | 810 | #ifdef __FreeBSD__
|
---|
[128] | 811 | strcpy(bootdev, call_program_and_get_last_line_of_output
|
---|
| 812 | ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
|
---|
| 813 | if (!bootdev[0]) {
|
---|
| 814 | strcpy(bootdev, call_program_and_get_last_line_of_output
|
---|
| 815 | ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
|
---|
| 816 | }
|
---|
[1] | 817 | #else
|
---|
[128] | 818 | strcpy(bootdev, call_program_and_get_last_line_of_output
|
---|
| 819 | ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
|
---|
| 820 | if (strstr(bootdev, "/dev/cciss/")) {
|
---|
| 821 | strcpy(bootdev, call_program_and_get_last_line_of_output
|
---|
| 822 | ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | cut -dp -f1"));
|
---|
| 823 | }
|
---|
| 824 | if (!bootdev[0]) {
|
---|
| 825 | strcpy(bootdev, call_program_and_get_last_line_of_output
|
---|
| 826 | ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
|
---|
| 827 | if (strstr(bootdev, "/dev/cciss/")) {
|
---|
| 828 | strcpy(bootdev, call_program_and_get_last_line_of_output
|
---|
| 829 | ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | cut -dp -f1"));
|
---|
| 830 | }
|
---|
| 831 | }
|
---|
[1] | 832 | #endif
|
---|
[128] | 833 | if (bootdev[0])
|
---|
| 834 | ch = which_boot_loader(bootdev);
|
---|
| 835 | else
|
---|
| 836 | ch = 'U';
|
---|
| 837 | if (bkpinfo->boot_loader != '\0') {
|
---|
| 838 | sprintf(tmp, "User specified boot loader. It is '%c'.",
|
---|
| 839 | bkpinfo->boot_loader);
|
---|
| 840 | log_msg(2, tmp);
|
---|
| 841 | } else {
|
---|
| 842 | bkpinfo->boot_loader = ch;
|
---|
| 843 | }
|
---|
| 844 | if (bkpinfo->boot_device[0] != '\0') {
|
---|
| 845 | sprintf(tmp, "User specified boot device. It is '%s'.",
|
---|
| 846 | bkpinfo->boot_device);
|
---|
| 847 | log_msg(2, tmp);
|
---|
| 848 | } else {
|
---|
| 849 | strcpy(bkpinfo->boot_device, bootdev);
|
---|
| 850 | }
|
---|
| 851 | }
|
---|
[1] | 852 |
|
---|
[128] | 853 | if (
|
---|
[1] | 854 | #ifdef __FreeBSD__
|
---|
[128] | 855 | bkpinfo->boot_loader != 'B' && bkpinfo->boot_loader != 'D' &&
|
---|
[1] | 856 | #endif
|
---|
| 857 | #ifdef __IA64__
|
---|
[128] | 858 | bkpinfo->boot_loader != 'E' &&
|
---|
[1] | 859 | #endif
|
---|
[128] | 860 | bkpinfo->boot_loader != 'L' && bkpinfo->boot_loader != 'G'
|
---|
| 861 | && bkpinfo->boot_loader != 'R'
|
---|
| 862 | && !bkpinfo->nonbootable_backup) {
|
---|
| 863 | fatal_error
|
---|
| 864 | ("Please specify your boot loader and device, e.g. -l GRUB -f /dev/hda. Type 'man mondoarchive' to read the manual.");
|
---|
[1] | 865 | }
|
---|
[128] | 866 | if (bkpinfo->boot_loader == 'L') {
|
---|
| 867 | strcpy(bootldr_str, "LILO");
|
---|
| 868 | if (!does_file_exist("/etc/lilo.conf")) {
|
---|
| 869 | fatal_error
|
---|
| 870 | ("The de facto standard location for your boot loader's config file is /etc/lilo.conf but I cannot find it there. What is wrong with your Linux distribution?");
|
---|
| 871 | }
|
---|
| 872 | } else if (bkpinfo->boot_loader == 'G') {
|
---|
| 873 | strcpy(bootldr_str, "GRUB");
|
---|
| 874 | if (!does_file_exist("/etc/grub.conf")
|
---|
| 875 | && does_file_exist("/boot/grub/grub.conf")) {
|
---|
| 876 | run_program_and_log_output
|
---|
| 877 | ("ln -sf /boot/grub/grub.conf /etc/grub.conf", 5);
|
---|
| 878 | }
|
---|
| 879 | /* Detect Debian's grub config file */
|
---|
| 880 | else if (!does_file_exist("/etc/grub.conf")
|
---|
| 881 | && does_file_exist("/boot/grub/menu.lst")) {
|
---|
| 882 | run_program_and_log_output
|
---|
| 883 | ("ln -s /boot/grub/menu.lst /etc/grub.conf", 5);
|
---|
| 884 | }
|
---|
| 885 | if (!does_file_exist("/etc/grub.conf")) {
|
---|
| 886 | fatal_error
|
---|
| 887 | ("The de facto standard location for your boot loader's config file is /etc/grub.conf but I cannot find it there. What is wrong with your Linux distribution? Try 'ln -s /boot/grub/menu.lst /etc/grub.conf'...");
|
---|
| 888 | }
|
---|
| 889 | } else if (bkpinfo->boot_loader == 'E') {
|
---|
| 890 | strcpy(bootldr_str, "ELILO");
|
---|
| 891 | /* BCO: fix it for SuSE, Debian, Mandrake, ... */
|
---|
| 892 | if (!does_file_exist("/etc/elilo.conf")
|
---|
| 893 | && does_file_exist("/boot/efi/efi/redhat/elilo.conf")) {
|
---|
| 894 | run_program_and_log_output
|
---|
| 895 | ("ln -sf /boot/efi/efi/redhat/elilo.conf /etc/elilo.conf",
|
---|
| 896 | 5);
|
---|
| 897 | }
|
---|
| 898 | if (!does_file_exist("/etc/elilo.conf")) {
|
---|
| 899 | fatal_error
|
---|
| 900 | ("The de facto mondo standard location for your boot loader's config file is /etc/elilo.conf but I cannot find it there. What is wrong with your Linux distribution? Try finding it under /boot/efi and do 'ln -s /boot/efi/..../elilo.conf /etc/elilo.conf'");
|
---|
| 901 | }
|
---|
| 902 | } else if (bkpinfo->boot_loader == 'R') {
|
---|
| 903 | strcpy(bootldr_str, "RAW");
|
---|
[1] | 904 | }
|
---|
| 905 | #ifdef __FreeBSD__
|
---|
[128] | 906 | else if (bkpinfo->boot_loader == 'D') {
|
---|
| 907 | strcpy(bootldr_str, "DD");
|
---|
| 908 | }
|
---|
[1] | 909 |
|
---|
[128] | 910 | else if (bkpinfo->boot_loader == 'B') {
|
---|
| 911 | strcpy(bootldr_str, "BOOT0");
|
---|
| 912 | }
|
---|
[1] | 913 | #endif
|
---|
[128] | 914 | else {
|
---|
| 915 | strcpy(bootldr_str, "unknown");
|
---|
| 916 | }
|
---|
| 917 | sprintf(tmp, "Your boot loader is %s and it boots from %s",
|
---|
| 918 | bootldr_str, bkpinfo->boot_device);
|
---|
| 919 | log_to_screen(tmp);
|
---|
| 920 | sprintf(tmp, "%s/BOOTLOADER.DEVICE", bkpinfo->tmpdir);
|
---|
| 921 | if (write_one_liner_data_file(tmp, bkpinfo->boot_device)) {
|
---|
| 922 | log_msg(1, "%ld: Unable to write one-liner boot device", __LINE__);
|
---|
| 923 | }
|
---|
| 924 | switch (bkpinfo->backup_media_type) {
|
---|
| 925 | case cdr:
|
---|
| 926 | strcpy(value, "cdr");
|
---|
| 927 | break;
|
---|
| 928 | case cdrw:
|
---|
| 929 | strcpy(value, "cdrw");
|
---|
| 930 | break;
|
---|
| 931 | case cdstream:
|
---|
| 932 | strcpy(value, "cdstream");
|
---|
| 933 | break;
|
---|
| 934 | case tape:
|
---|
| 935 | strcpy(value, "tape");
|
---|
| 936 | break;
|
---|
| 937 | case udev:
|
---|
| 938 | strcpy(value, "udev");
|
---|
| 939 | break;
|
---|
| 940 | case iso:
|
---|
| 941 | strcpy(value, "iso");
|
---|
| 942 | break;
|
---|
| 943 | case nfs:
|
---|
| 944 | strcpy(value, "nfs");
|
---|
| 945 | break;
|
---|
| 946 | case dvd:
|
---|
| 947 | strcpy(value, "dvd");
|
---|
| 948 | break;
|
---|
| 949 | default:
|
---|
| 950 | fatal_error("Unknown backup_media_type");
|
---|
| 951 | }
|
---|
| 952 | sprintf(tmp, "%s/BACKUP-MEDIA-TYPE", bkpinfo->tmpdir);
|
---|
| 953 | if (write_one_liner_data_file(tmp, value)) {
|
---|
| 954 | res++;
|
---|
| 955 | log_msg(1, "%ld: Unable to write one-liner backup-media-type",
|
---|
| 956 | __LINE__);
|
---|
| 957 | }
|
---|
| 958 | log_to_screen(bkpinfo->tmpdir);
|
---|
| 959 | sprintf(tmp, "%s/BOOTLOADER.NAME", bkpinfo->tmpdir);
|
---|
| 960 | if (write_one_liner_data_file(tmp, bootldr_str)) {
|
---|
| 961 | res++;
|
---|
| 962 | log_msg(1, "%ld: Unable to write one-liner bootloader.name",
|
---|
| 963 | __LINE__);
|
---|
| 964 | }
|
---|
| 965 | sprintf(tmp, "%s/DIFFERENTIAL", bkpinfo->tmpdir);
|
---|
| 966 | if (bkpinfo->differential) {
|
---|
| 967 | res += write_one_liner_data_file(tmp, "1");
|
---|
| 968 | } else {
|
---|
| 969 | res += write_one_liner_data_file(tmp, "0");
|
---|
| 970 | }
|
---|
[1] | 971 |
|
---|
[949] | 972 | if (g_getfattr) {
|
---|
| 973 | asprintf(&tmp1, "%s/XATTR", bkpinfo->tmpdir);
|
---|
| 974 | if (write_one_liner_data_file(tmp1, "TRUE")) {
|
---|
| 975 | log_msg(1, "%ld: Unable to write one-liner XATTR",
|
---|
| 976 | __LINE__);
|
---|
| 977 | }
|
---|
| 978 | paranoid_free(tmp1);
|
---|
| 979 | }
|
---|
| 980 | if (g_getfacl) {
|
---|
| 981 | asprintf(&tmp1, "%s/ACL", bkpinfo->tmpdir);
|
---|
| 982 | if (write_one_liner_data_file(tmp1, "TRUE")) {
|
---|
| 983 | log_msg(1, "%ld: Unable to write one-liner ACL",
|
---|
| 984 | __LINE__);
|
---|
| 985 | }
|
---|
| 986 | paranoid_free(tmp1);
|
---|
| 987 | }
|
---|
| 988 |
|
---|
[128] | 989 | estimated_total_noof_slices =
|
---|
| 990 | size_of_all_biggiefiles_K(bkpinfo) / bkpinfo->optimal_set_size + 1;
|
---|
[1] | 991 | /* add nfs stuff here? */
|
---|
[128] | 992 | sprintf(command, "mkdir -p %s/images", bkpinfo->scratchdir);
|
---|
| 993 | if (system(command)) {
|
---|
| 994 | res++;
|
---|
| 995 | log_OS_error("Unable to make images directory");
|
---|
| 996 | }
|
---|
| 997 | sprintf(command, "mkdir -p %s%s", bkpinfo->scratchdir, MNT_FLOPPY);
|
---|
| 998 | if (system(command)) {
|
---|
| 999 | res++;
|
---|
| 1000 | log_OS_error("Unable to make mnt floppy directory");
|
---|
| 1001 | }
|
---|
| 1002 | sprintf(tmp, "BTW, I'm telling Mindi your kernel is '%s'",
|
---|
| 1003 | bkpinfo->kernel_path);
|
---|
[1] | 1004 |
|
---|
[128] | 1005 | log_msg(1, "lines_in_filelist = %ld", lines_in_filelist);
|
---|
[1] | 1006 |
|
---|
[128] | 1007 | sprintf(command,
|
---|
[1] | 1008 | /* "mindi --custom 2=%s 3=%s/images 4=\"%s\" 5=\"%s\" \
|
---|
| 1009 | 6=\"%s\" 7=%ld 8=\"%s\" 9=\"%s\" 10=\"%s\" \
|
---|
| 1010 | 11=\"%s\" 12=%s 13=%ld 14=\"%s\" 15=\"%s\" 16=\"%s\" 17=\"%s\" 18=%ld 19=%d",*/
|
---|
[128] | 1011 | "mindi --custom %s %s/images '%s' '%s' \
|
---|
[126] | 1012 | '%s' %ld '%s' '%s' '%s' \
|
---|
[998] | 1013 | '%s' %s %ld '%s' '%s' '%s' '%s' %ld %d '%s'", bkpinfo->tmpdir, // parameter #2
|
---|
[128] | 1014 | bkpinfo->scratchdir, // parameter #3
|
---|
| 1015 | bkpinfo->kernel_path, // parameter #4
|
---|
| 1016 | tape_device, // parameter #5
|
---|
| 1017 | tape_size_sz, // parameter #6
|
---|
| 1018 | lines_in_filelist, // parameter #7 (INT)
|
---|
| 1019 | use_lzo_sz, // parameter #8
|
---|
| 1020 | cd_recovery_sz, // parameter #9
|
---|
| 1021 | bkpinfo->image_devs, // parameter #10
|
---|
| 1022 | broken_bios_sz, // parameter #11
|
---|
| 1023 | last_filelist_number, // parameter #12 (STRING)
|
---|
| 1024 | estimated_total_noof_slices, // parameter #13 (INT)
|
---|
| 1025 | devs_to_exclude, // parameter #14
|
---|
| 1026 | use_comp_sz, // parameter #15
|
---|
| 1027 | use_lilo_sz, // parameter #16
|
---|
| 1028 | use_star_sz, // parameter #17
|
---|
| 1029 | bkpinfo->internal_tape_block_size, // parameter #18 (LONG)
|
---|
[998] | 1030 | bkpinfo->differential, // parameter #19 (INT)
|
---|
| 1031 | use_gzip_sz); // parameter #20 (STRING)
|
---|
[1] | 1032 |
|
---|
| 1033 | // Watch it! This next line adds a parameter...
|
---|
[128] | 1034 | if (bkpinfo->nonbootable_backup) {
|
---|
| 1035 | strcat(command, " NONBOOTABLE");
|
---|
| 1036 | }
|
---|
| 1037 | log_msg(2, command);
|
---|
[1] | 1038 |
|
---|
| 1039 | // popup_and_OK("Pausing");
|
---|
[128] | 1040 |
|
---|
| 1041 | res =
|
---|
| 1042 | run_program_and_log_to_screen(command,
|
---|
| 1043 | "Generating boot+data disks");
|
---|
| 1044 | if (bkpinfo->nonbootable_backup) {
|
---|
| 1045 | res = 0;
|
---|
| 1046 | } // hack
|
---|
| 1047 | if (!res) {
|
---|
| 1048 | log_to_screen("Boot+data disks were created OK");
|
---|
[541] | 1049 | sprintf(command, "mkdir -p /root/images/mindi/");
|
---|
[128] | 1050 | log_msg(2, command);
|
---|
| 1051 | run_program_and_log_output(command, FALSE);
|
---|
| 1052 | sprintf(command,
|
---|
[541] | 1053 | "cp -f %s/images/mindi.iso /root/images/mindi/mondorescue.iso",
|
---|
[128] | 1054 | bkpinfo->scratchdir);
|
---|
| 1055 | log_msg(2, command);
|
---|
| 1056 | run_program_and_log_output(command, FALSE);
|
---|
| 1057 | if (bkpinfo->nonbootable_backup) {
|
---|
| 1058 | sprintf(command, "cp -f %s/all.tar.gz %s/images",
|
---|
| 1059 | bkpinfo->tmpdir, bkpinfo->scratchdir);
|
---|
| 1060 | if (system(command)) {
|
---|
| 1061 | fatal_error("Unable to create temporary duff tarball");
|
---|
| 1062 | }
|
---|
| 1063 | }
|
---|
| 1064 | sprintf(command, "cp -f %s/mindi-*oot*.img %s/images",
|
---|
| 1065 | bkpinfo->tmpdir, bkpinfo->scratchdir);
|
---|
| 1066 | sprintf(tmp, "cp -f %s/images/all.tar.gz %s", bkpinfo->scratchdir,
|
---|
| 1067 | bkpinfo->tmpdir);
|
---|
| 1068 | if (system(tmp)) {
|
---|
| 1069 | fatal_error("Cannot find all.tar.gz in tmpdir");
|
---|
| 1070 | }
|
---|
| 1071 | if (res) {
|
---|
| 1072 | mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
|
---|
| 1073 | } else {
|
---|
| 1074 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
| 1075 | }
|
---|
| 1076 | } else {
|
---|
| 1077 | log_to_screen("Mindi failed to create your boot+data disks.");
|
---|
[143] | 1078 | strcpy(command, "grep 'Fatal error' /var/log/mindi.log");
|
---|
[128] | 1079 | strcpy(tmp, call_program_and_get_last_line_of_output(command));
|
---|
| 1080 | if (strlen(tmp) > 1) {
|
---|
[155] | 1081 | popup_and_OK(tmp);
|
---|
[128] | 1082 | }
|
---|
| 1083 | }
|
---|
| 1084 | paranoid_free(tmp);
|
---|
| 1085 | paranoid_free(use_lzo_sz);
|
---|
[998] | 1086 | paranoid_free(use_gzip_sz);
|
---|
[128] | 1087 | paranoid_free(scratchdir);
|
---|
| 1088 | paranoid_free(use_comp_sz);
|
---|
| 1089 | paranoid_free(bootldr_str);
|
---|
| 1090 | paranoid_free(tape_device);
|
---|
| 1091 | paranoid_free(last_filelist_number);
|
---|
| 1092 | paranoid_free(broken_bios_sz);
|
---|
| 1093 | paranoid_free(cd_recovery_sz);
|
---|
| 1094 | paranoid_free(tape_size_sz);
|
---|
| 1095 | paranoid_free(devs_to_exclude);
|
---|
| 1096 | paranoid_free(use_lilo_sz);
|
---|
| 1097 | paranoid_free(value);
|
---|
| 1098 | paranoid_free(bootdev);
|
---|
| 1099 | paranoid_free(command);
|
---|
| 1100 | paranoid_free(use_star_sz);
|
---|
| 1101 | return (res);
|
---|
[1] | 1102 | }
|
---|
| 1103 |
|
---|
| 1104 |
|
---|
| 1105 |
|
---|
| 1106 | /**
|
---|
| 1107 | * Maximum number of filesets allowed in this function.
|
---|
| 1108 | */
|
---|
| 1109 | #define MAX_NOOF_SETS_HERE 32767
|
---|
| 1110 |
|
---|
| 1111 | /**
|
---|
| 1112 | * Offset of the bkpinfo pointer (in bytes) from the
|
---|
| 1113 | * buffer passed to create_afio_files_in_background.
|
---|
| 1114 | */
|
---|
| 1115 | #define BKPINFO_LOC_OFFSET (16+MAX_NOOF_SETS_HERE/8+16)
|
---|
| 1116 |
|
---|
| 1117 | /**
|
---|
| 1118 | * Main function for each @c afio thread.
|
---|
| 1119 | * @param inbuf A transfer block containing:
|
---|
| 1120 | * - @c p_last_set_archived: [offset 0] pointer to an @c int
|
---|
| 1121 | * containing the last set archived.
|
---|
| 1122 | * - @c p_archival_threads_running: [offset 4] pointer to an @c int
|
---|
| 1123 | * containing the number of archival threads currently running.
|
---|
| 1124 | * - @c p_next_set_to_archive: [offset 8] pointer to an @c int containing
|
---|
| 1125 | * the next set that should be archived.
|
---|
| 1126 | * - @c p_list_of_fileset_flags: [offset 12] @c char pointer pointing to a
|
---|
| 1127 | * bit array, where each bit corresponds to a filelist (1=needs
|
---|
| 1128 | * to be archived, 0=archived).
|
---|
| 1129 | * - @c bkpinfo: [offset BKPINFO_LOC_OFFSET] pointer to backup information
|
---|
| 1130 | * structure. Fields used:
|
---|
| 1131 | * - @c tmpdir
|
---|
| 1132 | * - @c zip_suffix
|
---|
| 1133 | *
|
---|
| 1134 | * Any of the above may be modified by the caller at any time.
|
---|
| 1135 | *
|
---|
| 1136 | * @bug Assumes @c int pointers are 4 bytes.
|
---|
| 1137 | * @see archive_this_fileset
|
---|
| 1138 | * @see make_afioballs_and_images
|
---|
| 1139 | * @return NULL, always.
|
---|
| 1140 | * @ingroup LLarchiveGroup
|
---|
| 1141 | */
|
---|
[128] | 1142 | void *create_afio_files_in_background(void *inbuf)
|
---|
[1] | 1143 | {
|
---|
[128] | 1144 | long int archiving_set_no;
|
---|
| 1145 | char *archiving_filelist_fname;
|
---|
| 1146 | char *archiving_afioball_fname;
|
---|
[948] | 1147 | char *curr_xattr_list_fname = NULL;
|
---|
[128] | 1148 | char *curr_acl_list_fname;
|
---|
[1] | 1149 |
|
---|
[128] | 1150 | struct s_bkpinfo *bkpinfo;
|
---|
| 1151 | char *tmp;
|
---|
| 1152 | int res = 0, retval = 0;
|
---|
| 1153 | int *p_archival_threads_running;
|
---|
| 1154 | int *p_last_set_archived;
|
---|
| 1155 | int *p_next_set_to_archive;
|
---|
| 1156 | char *p_list_of_fileset_flags;
|
---|
| 1157 | int this_thread_no = g_current_thread_no++;
|
---|
[1] | 1158 |
|
---|
[128] | 1159 | malloc_string(curr_xattr_list_fname);
|
---|
| 1160 | malloc_string(curr_acl_list_fname);
|
---|
| 1161 | malloc_string(archiving_filelist_fname);
|
---|
| 1162 | malloc_string(archiving_afioball_fname);
|
---|
| 1163 | malloc_string(tmp);
|
---|
| 1164 | p_last_set_archived = (int *) inbuf;
|
---|
| 1165 | p_archival_threads_running = (int *) (inbuf + 4);
|
---|
| 1166 | p_next_set_to_archive = (int *) (inbuf + 8);
|
---|
| 1167 | p_list_of_fileset_flags = (char *) (inbuf + 12);
|
---|
| 1168 | bkpinfo = (struct s_bkpinfo *) (inbuf + BKPINFO_LOC_OFFSET);
|
---|
[1] | 1169 |
|
---|
[128] | 1170 | sprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ,
|
---|
| 1171 | bkpinfo->tmpdir, 0L);
|
---|
| 1172 | for (archiving_set_no = 0; does_file_exist(archiving_filelist_fname);
|
---|
| 1173 | sprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ,
|
---|
| 1174 | bkpinfo->tmpdir, archiving_set_no)) {
|
---|
| 1175 | if (g_exiting) {
|
---|
| 1176 | fatal_error("Execution run aborted (pthread)");
|
---|
| 1177 | }
|
---|
| 1178 | if (archiving_set_no >= MAX_NOOF_SETS_HERE) {
|
---|
| 1179 | fatal_error
|
---|
| 1180 | ("Maximum number of filesets exceeded. Adjust MAX_NOOF_SETS_HERE, please.");
|
---|
| 1181 | }
|
---|
| 1182 | if (!semaphore_p()) {
|
---|
| 1183 | log_msg(3, "P sem failed (pid=%d)", (int) getpid());
|
---|
| 1184 | fatal_error("Cannot get semaphore P");
|
---|
| 1185 | }
|
---|
| 1186 | if (archiving_set_no < *p_next_set_to_archive) {
|
---|
| 1187 | archiving_set_no = *p_next_set_to_archive;
|
---|
| 1188 | }
|
---|
| 1189 | *p_next_set_to_archive = *p_next_set_to_archive + 1;
|
---|
| 1190 | if (!semaphore_v()) {
|
---|
| 1191 | fatal_error("Cannot get semaphore V");
|
---|
| 1192 | }
|
---|
[1] | 1193 |
|
---|
[128] | 1194 | /* backup this set of files */
|
---|
| 1195 | sprintf(archiving_afioball_fname, AFIOBALL_FNAME_RAW_SZ,
|
---|
| 1196 | bkpinfo->tmpdir, archiving_set_no, bkpinfo->zip_suffix);
|
---|
| 1197 | sprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ,
|
---|
| 1198 | bkpinfo->tmpdir, archiving_set_no);
|
---|
| 1199 | if (!does_file_exist(archiving_filelist_fname)) {
|
---|
| 1200 | log_msg(3,
|
---|
| 1201 | "%s[%d:%d] - well, I would archive %d, except that it doesn't exist. I'll stop now.",
|
---|
| 1202 | FORTY_SPACES, getpid(), this_thread_no,
|
---|
| 1203 | archiving_set_no);
|
---|
| 1204 | break;
|
---|
| 1205 | }
|
---|
[1] | 1206 |
|
---|
[128] | 1207 | sprintf(tmp, AFIOBALL_FNAME_RAW_SZ, bkpinfo->tmpdir,
|
---|
| 1208 | archiving_set_no - ARCH_BUFFER_NUM, bkpinfo->zip_suffix);
|
---|
| 1209 | if (does_file_exist(tmp)) {
|
---|
| 1210 | log_msg(4, "%s[%d:%d] - waiting for storer", FORTY_SPACES,
|
---|
| 1211 | getpid(), this_thread_no);
|
---|
| 1212 | while (does_file_exist(tmp)) {
|
---|
| 1213 | sleep(1);
|
---|
| 1214 | }
|
---|
| 1215 | log_msg(4, "[%d] - continuing", getpid());
|
---|
| 1216 | }
|
---|
[1] | 1217 |
|
---|
[128] | 1218 | log_msg(4, "%s[%d:%d] - EXATing %d...", FORTY_SPACES, getpid(),
|
---|
| 1219 | this_thread_no, archiving_set_no);
|
---|
[948] | 1220 | if (g_getfattr) {
|
---|
| 1221 | sprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
|
---|
[128] | 1222 | bkpinfo->tmpdir, archiving_set_no);
|
---|
[948] | 1223 | get_fattr_list(archiving_filelist_fname, curr_xattr_list_fname);
|
---|
| 1224 | }
|
---|
| 1225 | if (g_getfacl) {
|
---|
| 1226 | sprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
|
---|
[128] | 1227 | bkpinfo->tmpdir, archiving_set_no);
|
---|
[948] | 1228 | get_acl_list(archiving_filelist_fname, curr_acl_list_fname);
|
---|
| 1229 | }
|
---|
[1] | 1230 |
|
---|
[128] | 1231 | log_msg(4, "%s[%d:%d] - archiving %d...", FORTY_SPACES, getpid(),
|
---|
| 1232 | this_thread_no, archiving_set_no);
|
---|
| 1233 | res =
|
---|
| 1234 | archive_this_fileset(bkpinfo, archiving_filelist_fname,
|
---|
| 1235 | archiving_afioball_fname,
|
---|
| 1236 | archiving_set_no);
|
---|
| 1237 | retval += res;
|
---|
[1] | 1238 |
|
---|
[128] | 1239 | if (res) {
|
---|
| 1240 | sprintf(tmp,
|
---|
| 1241 | "Errors occurred while archiving set %ld. Please review logs.",
|
---|
| 1242 | archiving_set_no);
|
---|
| 1243 | log_to_screen(tmp);
|
---|
| 1244 | }
|
---|
| 1245 | if (!semaphore_p()) {
|
---|
| 1246 | fatal_error("Cannot get semaphore P");
|
---|
| 1247 | }
|
---|
| 1248 |
|
---|
| 1249 | set_bit_N_of_array(p_list_of_fileset_flags, archiving_set_no, 5);
|
---|
| 1250 |
|
---|
| 1251 | if (*p_last_set_archived < archiving_set_no) {
|
---|
| 1252 | *p_last_set_archived = archiving_set_no;
|
---|
| 1253 | } // finished archiving this one
|
---|
| 1254 |
|
---|
| 1255 | if (!semaphore_v()) {
|
---|
| 1256 | fatal_error("Cannot get semaphore V");
|
---|
| 1257 | }
|
---|
| 1258 | log_msg(4, "%s[%d:%d] - archived %d OK", FORTY_SPACES, getpid(),
|
---|
| 1259 | this_thread_no, archiving_set_no);
|
---|
| 1260 | archiving_set_no++;
|
---|
| 1261 | }
|
---|
| 1262 | if (!semaphore_p()) {
|
---|
| 1263 | fatal_error("Cannot get semaphore P");
|
---|
| 1264 | }
|
---|
| 1265 | (*p_archival_threads_running)--;
|
---|
| 1266 | if (!semaphore_v()) {
|
---|
| 1267 | fatal_error("Cannot get semaphore V");
|
---|
| 1268 | }
|
---|
| 1269 | log_msg(3, "%s[%d:%d] - exiting", FORTY_SPACES, getpid(),
|
---|
| 1270 | this_thread_no);
|
---|
| 1271 | paranoid_free(archiving_filelist_fname);
|
---|
| 1272 | paranoid_free(archiving_afioball_fname);
|
---|
| 1273 | paranoid_free(curr_xattr_list_fname);
|
---|
| 1274 | paranoid_free(curr_acl_list_fname);
|
---|
| 1275 | paranoid_free(tmp);
|
---|
| 1276 | pthread_exit(NULL);
|
---|
[1] | 1277 | }
|
---|
| 1278 |
|
---|
| 1279 |
|
---|
| 1280 |
|
---|
| 1281 |
|
---|
| 1282 |
|
---|
| 1283 | /**
|
---|
| 1284 | * Finalize the backup.
|
---|
| 1285 | * For streaming backups, this writes the closing block
|
---|
| 1286 | * to the stream. For CD-based backups, this creates
|
---|
| 1287 | * the final ISO image.
|
---|
| 1288 | * @param bkpinfo The backup information structure, used only
|
---|
| 1289 | * for the @c backup_media_type.
|
---|
| 1290 | * @ingroup MLarchiveGroup
|
---|
| 1291 | */
|
---|
[541] | 1292 | int do_that_final_phase(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 1293 | {
|
---|
| 1294 |
|
---|
[128] | 1295 | /*@ int ************************************** */
|
---|
| 1296 | int res = 0;
|
---|
| 1297 | int retval = 0;
|
---|
[1] | 1298 |
|
---|
[128] | 1299 | /*@ buffers ********************************** */
|
---|
[1] | 1300 |
|
---|
[128] | 1301 | assert(bkpinfo != NULL);
|
---|
| 1302 | mvaddstr_and_log_it(g_currentY, 0,
|
---|
| 1303 | "Writing any remaining data to media ");
|
---|
[1] | 1304 |
|
---|
[128] | 1305 | log_msg(1, "Closing tape/CD ... ");
|
---|
| 1306 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
|
---|
| 1307 | /* write tape/cdstream */
|
---|
[1] | 1308 | {
|
---|
[128] | 1309 | closeout_tape(bkpinfo);
|
---|
| 1310 | } else
|
---|
| 1311 | /* write final ISO */
|
---|
| 1312 | {
|
---|
[541] | 1313 | res = write_final_iso_if_necessary(bkpinfo);
|
---|
[128] | 1314 | retval += res;
|
---|
| 1315 | if (res) {
|
---|
| 1316 | log_msg(1, "write_final_iso_if_necessary returned an error");
|
---|
| 1317 | }
|
---|
[1] | 1318 | }
|
---|
[128] | 1319 | log_msg(2, "Fork is exiting ... ");
|
---|
[1] | 1320 |
|
---|
[128] | 1321 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
[1] | 1322 |
|
---|
[128] | 1323 | /* final stuff */
|
---|
| 1324 | if (retval) {
|
---|
| 1325 | mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
|
---|
| 1326 | } else {
|
---|
| 1327 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
| 1328 | }
|
---|
[1] | 1329 |
|
---|
[128] | 1330 | return (retval);
|
---|
[1] | 1331 | }
|
---|
| 1332 |
|
---|
| 1333 |
|
---|
| 1334 | /**
|
---|
| 1335 | * Initialize the backup.
|
---|
| 1336 | * Does the following:
|
---|
| 1337 | * - Sets up the serial number.
|
---|
| 1338 | * - For streaming backups, opens the tape stream and writes the data disks
|
---|
| 1339 | * and backup headers.
|
---|
| 1340 | * - For CD-based backups, wipes the ISOs in the target directory.
|
---|
| 1341 | *
|
---|
| 1342 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 1343 | * - @c backup_media_type
|
---|
| 1344 | * - @c cdrw_speed
|
---|
[20] | 1345 | * - @c prefix
|
---|
[1] | 1346 | * - @c isodir
|
---|
| 1347 | * - @c media_device
|
---|
| 1348 | * - @c scratchdir
|
---|
| 1349 | * - @c tmpdir
|
---|
| 1350 | * @return The number of errors encountered (0 for success).
|
---|
| 1351 | * @ingroup MLarchiveGroup
|
---|
| 1352 | */
|
---|
[128] | 1353 | int do_that_initial_phase(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 1354 | {
|
---|
[128] | 1355 | /*@ int *************************************** */
|
---|
| 1356 | int retval = 0;
|
---|
[1] | 1357 |
|
---|
[128] | 1358 | /*@ buffers *********************************** */
|
---|
| 1359 | char *command, *tmpfile, *data_disks_file;
|
---|
[1] | 1360 |
|
---|
[128] | 1361 | assert(bkpinfo != NULL);
|
---|
| 1362 | malloc_string(command);
|
---|
| 1363 | malloc_string(tmpfile);
|
---|
| 1364 | malloc_string(data_disks_file);
|
---|
| 1365 | sprintf(data_disks_file, "%s/all.tar.gz", bkpinfo->tmpdir);
|
---|
| 1366 |
|
---|
| 1367 | snprintf(g_serial_string, MAX_STR_LEN - 1,
|
---|
| 1368 | call_program_and_get_last_line_of_output("dd \
|
---|
[1] | 1369 | if=/dev/urandom bs=16 count=1 2> /dev/null | \
|
---|
| 1370 | hexdump | tr -s ' ' '0' | head -n1"));
|
---|
[128] | 1371 | strip_spaces(g_serial_string);
|
---|
| 1372 | strcat(g_serial_string, "...word.");
|
---|
| 1373 | log_msg(2, "g_serial_string = '%s'", g_serial_string);
|
---|
| 1374 | assert(strlen(g_serial_string) < MAX_STR_LEN);
|
---|
[1] | 1375 |
|
---|
[128] | 1376 | sprintf(tmpfile, "%s/archives/SERIAL-STRING", bkpinfo->scratchdir);
|
---|
| 1377 | if (write_one_liner_data_file(tmpfile, g_serial_string)) {
|
---|
| 1378 | log_msg(1, "%ld: Failed to write serial string", __LINE__);
|
---|
| 1379 | }
|
---|
[1] | 1380 |
|
---|
[128] | 1381 | mvaddstr_and_log_it(g_currentY, 0, "Preparing to archive your data");
|
---|
| 1382 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 1383 | if (bkpinfo->backup_media_type == cdstream) {
|
---|
| 1384 | openout_cdstream(bkpinfo->media_device, bkpinfo->cdrw_speed);
|
---|
| 1385 | } else {
|
---|
| 1386 | openout_tape(bkpinfo->media_device, bkpinfo->internal_tape_block_size); /* sets g_tape_stream */
|
---|
| 1387 | }
|
---|
| 1388 | if (!g_tape_stream) {
|
---|
| 1389 | fatal_error("Cannot open backup (streaming) device");
|
---|
| 1390 | }
|
---|
| 1391 | log_msg(1, "Backup (stream) opened OK");
|
---|
| 1392 | write_data_disks_to_stream(data_disks_file);
|
---|
| 1393 | } else {
|
---|
| 1394 | log_msg(1, "Backing up to CD's");
|
---|
[1] | 1395 | }
|
---|
| 1396 |
|
---|
[128] | 1397 | sprintf(command, "rm -f %s/%s/%s-[1-9]*.iso", bkpinfo->isodir,
|
---|
| 1398 | bkpinfo->nfs_remote_dir, bkpinfo->prefix);
|
---|
| 1399 | paranoid_system(command);
|
---|
| 1400 | wipe_archives(bkpinfo->scratchdir);
|
---|
| 1401 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
| 1402 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
[684] | 1403 | write_header_block_to_stream((off_t)0, "start-of-tape",
|
---|
[128] | 1404 | BLK_START_OF_TAPE);
|
---|
[684] | 1405 | write_header_block_to_stream((off_t)0, "start-of-backup",
|
---|
[128] | 1406 | BLK_START_OF_BACKUP);
|
---|
| 1407 | }
|
---|
| 1408 | paranoid_free(command);
|
---|
| 1409 | paranoid_free(tmpfile);
|
---|
| 1410 | paranoid_free(data_disks_file);
|
---|
| 1411 | return (retval);
|
---|
[1] | 1412 | }
|
---|
| 1413 |
|
---|
| 1414 |
|
---|
| 1415 | /**
|
---|
| 1416 | * Calls floppy-formatting @c cmd and tracks its progress if possible.
|
---|
| 1417 | *
|
---|
| 1418 | * @param cmd The command to run (e.g. @c fdformat @c /dev/fd0).
|
---|
| 1419 | * @param title The human-friendly description of the floppy you are writing.
|
---|
| 1420 | * This will be used as the title in the progress bar window. Example:
|
---|
| 1421 | * "Formatting disk /dev/fd0".
|
---|
| 1422 | * @see format_disk
|
---|
| 1423 | * @return The exit code of fdformat/superformat.
|
---|
| 1424 | */
|
---|
[128] | 1425 | int format_disk_SUB(char *cmd, char *title)
|
---|
[1] | 1426 | {
|
---|
| 1427 |
|
---|
[128] | 1428 | /*@ int *************************************************************** */
|
---|
| 1429 | int res = 0;
|
---|
[1] | 1430 | int percentage = 0;
|
---|
| 1431 | int maxtracks = 0;
|
---|
| 1432 | int trackno = 0;
|
---|
| 1433 | int last_trkno = 0;
|
---|
| 1434 |
|
---|
[128] | 1435 | /*@ buffers *********************************************************** */
|
---|
| 1436 | char *command;
|
---|
| 1437 | char *tempfile;
|
---|
[1] | 1438 |
|
---|
[128] | 1439 | /*@ pointers ********************************************************** */
|
---|
| 1440 | FILE *pin;
|
---|
[1] | 1441 |
|
---|
[128] | 1442 | assert_string_is_neither_NULL_nor_zerolength(cmd);
|
---|
| 1443 | assert_string_is_neither_NULL_nor_zerolength(title);
|
---|
[1] | 1444 |
|
---|
[128] | 1445 | malloc_string(command);
|
---|
| 1446 | malloc_string(tempfile);
|
---|
[1] | 1447 | #ifdef __FreeBSD__
|
---|
| 1448 | /* Ugh. FreeBSD fdformat prints out this pretty progress indicator that's
|
---|
| 1449 | impossible to parse. It looks like
|
---|
| 1450 | VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVF-------------------
|
---|
| 1451 | where V means verified, E means error, F means formatted, and - means
|
---|
| 1452 | not done yet.
|
---|
| 1453 | */
|
---|
[128] | 1454 | return (run_program_and_log_to_screen(cmd, title));
|
---|
[1] | 1455 | #endif
|
---|
| 1456 |
|
---|
| 1457 | /* if Debian then do bog-standard superformat; don't be pretty */
|
---|
[128] | 1458 | if (strstr(cmd, "superformat")) {
|
---|
| 1459 | return (run_program_and_log_to_screen(cmd, title));
|
---|
| 1460 | }
|
---|
[1] | 1461 | /* if not Debian then go ahead & use fdformat */
|
---|
[128] | 1462 | strcpy(tempfile,
|
---|
| 1463 | call_program_and_get_last_line_of_output
|
---|
| 1464 | ("mktemp -q /tmp/mondo.XXXXXXXX"));
|
---|
| 1465 | sprintf(command, "%s >> %s 2>> %s; rm -f %s", cmd, tempfile, tempfile,
|
---|
| 1466 | tempfile);
|
---|
| 1467 | log_msg(3, command);
|
---|
| 1468 | open_evalcall_form(title);
|
---|
| 1469 | if (!(pin = popen(command, "r"))) {
|
---|
| 1470 | log_OS_error("fmt err");
|
---|
| 1471 | return (1);
|
---|
[1] | 1472 | }
|
---|
[128] | 1473 | if (strstr(command, "1722")) {
|
---|
| 1474 | maxtracks = 82;
|
---|
| 1475 | } else {
|
---|
| 1476 | maxtracks = 80;
|
---|
[1] | 1477 | }
|
---|
[128] | 1478 | for (sleep(1); does_file_exist(tempfile); sleep(1)) {
|
---|
| 1479 | trackno = get_trackno_from_logfile(tempfile);
|
---|
| 1480 | if (trackno < 0 || trackno > 80) {
|
---|
| 1481 | log_msg(1, "Weird track#");
|
---|
| 1482 | continue;
|
---|
| 1483 | }
|
---|
| 1484 | percentage = trackno * 100 / maxtracks;
|
---|
| 1485 | if (trackno <= 5 && last_trkno > 40) {
|
---|
| 1486 | close_evalcall_form();
|
---|
| 1487 | strcpy(title, "Verifying format");
|
---|
| 1488 | open_evalcall_form(title);
|
---|
| 1489 | }
|
---|
| 1490 | last_trkno = trackno;
|
---|
| 1491 | update_evalcall_form(percentage);
|
---|
| 1492 | }
|
---|
| 1493 | close_evalcall_form();
|
---|
| 1494 | if (pclose(pin)) {
|
---|
| 1495 | res++;
|
---|
| 1496 | log_OS_error("Unable to pclose");
|
---|
| 1497 | }
|
---|
| 1498 | unlink(tempfile);
|
---|
| 1499 | paranoid_free(command);
|
---|
| 1500 | paranoid_free(tempfile);
|
---|
| 1501 | return (res);
|
---|
[1] | 1502 | }
|
---|
| 1503 |
|
---|
| 1504 | /**
|
---|
| 1505 | * Wrapper around @c format_disk_SUB().
|
---|
| 1506 | * This function calls @c format_disk_SUB() with a @c device of its @c device
|
---|
| 1507 | * parameter and a @c title of Formatting disk @c device. If the format
|
---|
| 1508 | * fails, the user will be given the option of retrying.
|
---|
| 1509 | *
|
---|
| 1510 | * @param device The floppy drive to write to.
|
---|
| 1511 | * @see format_disk_SUB
|
---|
| 1512 | * @return The exit code of fdformat/superformat.
|
---|
| 1513 | * @ingroup deviceGroup
|
---|
| 1514 | */
|
---|
[128] | 1515 | int format_disk(char *device)
|
---|
[1] | 1516 | {
|
---|
| 1517 |
|
---|
[128] | 1518 | /*@ int ************************************************************** */
|
---|
| 1519 | int res = 0;
|
---|
[1] | 1520 |
|
---|
[128] | 1521 | /*@ buffer *********************************************************** */
|
---|
| 1522 | char *command;
|
---|
| 1523 | char *title;
|
---|
| 1524 |
|
---|
| 1525 |
|
---|
| 1526 | assert_string_is_neither_NULL_nor_zerolength(device);
|
---|
| 1527 | malloc_string(title);
|
---|
| 1528 | command = malloc(1000);
|
---|
| 1529 | if (!system("which superformat > /dev/null 2> /dev/null")) {
|
---|
| 1530 | sprintf(command, "superformat %s", device);
|
---|
| 1531 | } else {
|
---|
[1] | 1532 | #ifdef __FreeBSD__
|
---|
[128] | 1533 | sprintf(command, "fdformat -y %s", device);
|
---|
[1] | 1534 | #else
|
---|
[128] | 1535 | sprintf(command, "fdformat %s", device);
|
---|
[1] | 1536 | #endif
|
---|
| 1537 | }
|
---|
[128] | 1538 | sprintf(title, "Formatting disk %s", device);
|
---|
| 1539 | while ((res = format_disk_SUB(command, title))) {
|
---|
| 1540 | if (!ask_me_yes_or_no("Failed to format disk. Retry?")) {
|
---|
| 1541 | return (res);
|
---|
| 1542 | }
|
---|
| 1543 | }
|
---|
| 1544 | paranoid_free(title);
|
---|
| 1545 | paranoid_free(command);
|
---|
| 1546 | return (res);
|
---|
[1] | 1547 | }
|
---|
| 1548 |
|
---|
| 1549 | /**
|
---|
| 1550 | * Get the <tt>N</tt>th bit of @c array.
|
---|
| 1551 | * @param array The bit-array (as a @c char pointer).
|
---|
| 1552 | * @param N The number of the bit you want.
|
---|
| 1553 | * @return TRUE (bit is set) or FALSE (bit is not set).
|
---|
| 1554 | * @see set_bit_N_of_array
|
---|
| 1555 | * @ingroup utilityGroup
|
---|
| 1556 | */
|
---|
[128] | 1557 | bool get_bit_N_of_array(char *array, int N)
|
---|
[1] | 1558 | {
|
---|
[128] | 1559 | int element_number;
|
---|
| 1560 | int bit_number;
|
---|
| 1561 | int mask;
|
---|
| 1562 |
|
---|
| 1563 | element_number = N / 8;
|
---|
| 1564 | bit_number = N % 8;
|
---|
| 1565 | mask = 1 << bit_number;
|
---|
| 1566 | if (array[element_number] & mask) {
|
---|
| 1567 | return (TRUE);
|
---|
| 1568 | } else {
|
---|
| 1569 | return (FALSE);
|
---|
| 1570 | }
|
---|
[1] | 1571 | }
|
---|
| 1572 |
|
---|
| 1573 |
|
---|
| 1574 |
|
---|
| 1575 |
|
---|
| 1576 |
|
---|
| 1577 |
|
---|
| 1578 |
|
---|
| 1579 |
|
---|
| 1580 |
|
---|
| 1581 | /**
|
---|
| 1582 | * @addtogroup LLarchiveGroup
|
---|
| 1583 | * @{
|
---|
| 1584 | */
|
---|
| 1585 | /**
|
---|
| 1586 | * Start up threads to archive your files.
|
---|
| 1587 | *
|
---|
| 1588 | * This function starts @c ARCH_THREADS threads,
|
---|
| 1589 | * each starting execution in @c create_afio_files_in_background().
|
---|
| 1590 | * Each thread will archive individual filesets, based on the
|
---|
| 1591 | * pointers passed to it and continually updated, until all files
|
---|
| 1592 | * have been backed up. This function coordinates the threads
|
---|
| 1593 | * and copies their output to the @c scratchdir.
|
---|
| 1594 | *
|
---|
| 1595 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 1596 | * - @c backup_media_type
|
---|
| 1597 | * - @c scratchdir
|
---|
| 1598 | * - @c tmpdir
|
---|
| 1599 | * - @c zip_suffix
|
---|
| 1600 | *
|
---|
| 1601 | * @return The number of errors encountered (0 for success)
|
---|
| 1602 | */
|
---|
[541] | 1603 | int make_afioballs_and_images(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 1604 | {
|
---|
| 1605 |
|
---|
[128] | 1606 | /*@ int ************************************************** */
|
---|
| 1607 | int retval = 0;
|
---|
| 1608 | long int storing_set_no = 0;
|
---|
| 1609 | int res = 0;
|
---|
| 1610 | bool done_storing = FALSE;
|
---|
| 1611 | char *result_str;
|
---|
| 1612 | char *transfer_block;
|
---|
| 1613 | void *vp;
|
---|
| 1614 | void **pvp;
|
---|
[1] | 1615 |
|
---|
[128] | 1616 | /*@ buffers ********************************************** */
|
---|
| 1617 | char *storing_filelist_fname;
|
---|
| 1618 | char *storing_afioball_fname;
|
---|
| 1619 | char *tmp;
|
---|
| 1620 | char *media_usage_comment;
|
---|
| 1621 | pthread_t archival_thread[ARCH_THREADS];
|
---|
| 1622 | char *p_list_of_fileset_flags;
|
---|
| 1623 | int *p_archival_threads_running;
|
---|
| 1624 | int *p_last_set_archived;
|
---|
| 1625 | int *p_next_set_to_archive;
|
---|
| 1626 | int noof_threads;
|
---|
| 1627 | int i;
|
---|
[948] | 1628 | char *curr_xattr_list_fname = NULL;
|
---|
[128] | 1629 | char *curr_acl_list_fname;
|
---|
| 1630 | int misc_counter_that_is_not_important = 0;
|
---|
[1] | 1631 |
|
---|
[128] | 1632 | log_msg(8, "here");
|
---|
| 1633 | assert(bkpinfo != NULL);
|
---|
| 1634 | tmp = malloc(MAX_STR_LEN * 2);
|
---|
| 1635 | malloc_string(result_str);
|
---|
| 1636 | malloc_string(curr_xattr_list_fname);
|
---|
| 1637 | malloc_string(curr_acl_list_fname);
|
---|
| 1638 | malloc_string(storing_filelist_fname);
|
---|
| 1639 | malloc_string(media_usage_comment);
|
---|
| 1640 | malloc_string(storing_afioball_fname);
|
---|
| 1641 | transfer_block =
|
---|
| 1642 | malloc(sizeof(struct s_bkpinfo) + BKPINFO_LOC_OFFSET + 64);
|
---|
| 1643 | memset((void *) transfer_block, 0,
|
---|
| 1644 | sizeof(struct s_bkpinfo) + BKPINFO_LOC_OFFSET + 64);
|
---|
| 1645 | p_last_set_archived = (int *) transfer_block;
|
---|
| 1646 | p_archival_threads_running = (int *) (transfer_block + 4);
|
---|
| 1647 | p_next_set_to_archive = (int *) (transfer_block + 8);
|
---|
| 1648 | p_list_of_fileset_flags = (char *) (transfer_block + 12);
|
---|
| 1649 | memcpy((void *) (transfer_block + BKPINFO_LOC_OFFSET),
|
---|
| 1650 | (void *) bkpinfo, sizeof(struct s_bkpinfo));
|
---|
| 1651 | pvp = &vp;
|
---|
| 1652 | vp = (void *) result_str;
|
---|
| 1653 | *p_archival_threads_running = 0;
|
---|
| 1654 | *p_last_set_archived = -1;
|
---|
| 1655 | *p_next_set_to_archive = 0;
|
---|
| 1656 | sprintf(tmp, "%s/archives/filelist.full", bkpinfo->scratchdir);
|
---|
| 1657 | log_to_screen("Archiving regular files");
|
---|
| 1658 | log_msg(5, "Go, Shorty. It's your birthday.");
|
---|
[541] | 1659 | open_progress_form("Backing up filesystem",
|
---|
| 1660 | "I am backing up your live filesystem now.",
|
---|
| 1661 | "Please wait. This may take a couple of hours.",
|
---|
| 1662 | "Working...",
|
---|
[128] | 1663 | get_last_filelist_number(bkpinfo) + 1);
|
---|
[1] | 1664 |
|
---|
[128] | 1665 | log_msg(5, "We're gonna party like it's your birthday.");
|
---|
[1] | 1666 |
|
---|
[128] | 1667 | srand((unsigned int) getpid());
|
---|
| 1668 | g_sem_key = 1234 + random() % 30000;
|
---|
| 1669 | if ((g_sem_id =
|
---|
| 1670 | semget((key_t) g_sem_key, 1,
|
---|
| 1671 | IPC_CREAT | S_IREAD | S_IWRITE)) == -1) {
|
---|
| 1672 | fatal_error("MABAI - unable to semget");
|
---|
[1] | 1673 | }
|
---|
[128] | 1674 | if (!set_semvalue()) {
|
---|
| 1675 | fatal_error("Unable to init semaphore");
|
---|
| 1676 | } // initialize semaphore
|
---|
| 1677 | for (noof_threads = 0; noof_threads < ARCH_THREADS; noof_threads++) {
|
---|
| 1678 | log_msg(8, "Creating thread #%d", noof_threads);
|
---|
| 1679 | (*p_archival_threads_running)++;
|
---|
| 1680 | if ((res =
|
---|
| 1681 | pthread_create(&archival_thread[noof_threads], NULL,
|
---|
| 1682 | create_afio_files_in_background,
|
---|
| 1683 | (void *) transfer_block))) {
|
---|
| 1684 | fatal_error("Unable to create an archival thread");
|
---|
| 1685 | }
|
---|
[1] | 1686 | }
|
---|
| 1687 |
|
---|
[128] | 1688 | log_msg(8, "About to enter while() loop");
|
---|
| 1689 | while (!done_storing) {
|
---|
| 1690 | if (g_exiting) {
|
---|
| 1691 | fatal_error("Execution run aborted (main loop)");
|
---|
| 1692 | }
|
---|
| 1693 | if (*p_archival_threads_running == 0
|
---|
| 1694 | && *p_last_set_archived == storing_set_no - 1) {
|
---|
| 1695 | log_msg(2,
|
---|
| 1696 | "No archival threads are running. The last stored set was %d and I'm looking for %d. Take off your make-up; the party's over... :-)",
|
---|
| 1697 | *p_last_set_archived, storing_set_no);
|
---|
| 1698 | done_storing = TRUE;
|
---|
| 1699 | } else
|
---|
| 1700 | if (!get_bit_N_of_array
|
---|
| 1701 | (p_list_of_fileset_flags, storing_set_no)) {
|
---|
| 1702 | misc_counter_that_is_not_important =
|
---|
| 1703 | (misc_counter_that_is_not_important + 1) % 5;
|
---|
| 1704 | if (!misc_counter_that_is_not_important) {
|
---|
| 1705 | update_progress_form(media_usage_comment);
|
---|
| 1706 | }
|
---|
| 1707 | sleep(1);
|
---|
| 1708 | } else
|
---|
| 1709 | // store set N
|
---|
| 1710 | {
|
---|
| 1711 | sprintf(storing_filelist_fname, FILELIST_FNAME_RAW_SZ,
|
---|
| 1712 | bkpinfo->tmpdir, storing_set_no);
|
---|
| 1713 | sprintf(storing_afioball_fname, AFIOBALL_FNAME_RAW_SZ,
|
---|
| 1714 | bkpinfo->tmpdir, storing_set_no, bkpinfo->zip_suffix);
|
---|
[948] | 1715 | if (g_getfattr) {
|
---|
| 1716 | sprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
|
---|
[128] | 1717 | bkpinfo->tmpdir, storing_set_no);
|
---|
[948] | 1718 | }
|
---|
| 1719 | if (g_getfacl) {
|
---|
| 1720 | sprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
|
---|
[128] | 1721 | bkpinfo->tmpdir, storing_set_no);
|
---|
[948] | 1722 | }
|
---|
[128] | 1723 |
|
---|
| 1724 | log_msg(2, "Storing set %d", storing_set_no);
|
---|
| 1725 | while (!does_file_exist(storing_filelist_fname)
|
---|
| 1726 | || !does_file_exist(storing_afioball_fname)) {
|
---|
| 1727 | log_msg(2,
|
---|
| 1728 | "Warning - either %s or %s doesn't exist yet. I'll pause 5 secs.",
|
---|
| 1729 | storing_filelist_fname, storing_afioball_fname);
|
---|
| 1730 | sleep(5);
|
---|
| 1731 | }
|
---|
| 1732 | strcpy(media_usage_comment,
|
---|
| 1733 | percent_media_full_comment(bkpinfo));
|
---|
| 1734 | /* copy to CD (scratchdir) ... and an actual CD-R if necessary */
|
---|
| 1735 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 1736 | register_in_tape_catalog(fileset, storing_set_no, -1,
|
---|
| 1737 | storing_afioball_fname);
|
---|
| 1738 | maintain_collection_of_recent_archives(bkpinfo->tmpdir,
|
---|
| 1739 | storing_afioball_fname);
|
---|
| 1740 | iamhere("Writing EXAT files");
|
---|
| 1741 | res +=
|
---|
| 1742 | write_EXAT_files_to_tape(bkpinfo,
|
---|
| 1743 | curr_xattr_list_fname,
|
---|
| 1744 | curr_acl_list_fname);
|
---|
[1] | 1745 | // archives themselves
|
---|
[128] | 1746 | res +=
|
---|
| 1747 | move_files_to_stream(bkpinfo, storing_afioball_fname,
|
---|
| 1748 | NULL);
|
---|
| 1749 | } else {
|
---|
[948] | 1750 | if (g_getfacl) {
|
---|
| 1751 | if (g_getfattr) {
|
---|
| 1752 | res = move_files_to_cd(bkpinfo, storing_filelist_fname,
|
---|
[128] | 1753 | curr_xattr_list_fname,
|
---|
| 1754 | curr_acl_list_fname,
|
---|
| 1755 | storing_afioball_fname, NULL);
|
---|
[948] | 1756 | } else {
|
---|
| 1757 | res = move_files_to_cd(bkpinfo, storing_filelist_fname,
|
---|
| 1758 | curr_acl_list_fname,
|
---|
| 1759 | storing_afioball_fname, NULL);
|
---|
| 1760 | }
|
---|
| 1761 | } else {
|
---|
| 1762 | if (g_getfattr) {
|
---|
| 1763 | res = move_files_to_cd(bkpinfo, storing_filelist_fname,
|
---|
| 1764 | curr_xattr_list_fname,
|
---|
| 1765 | storing_afioball_fname, NULL);
|
---|
| 1766 | } else {
|
---|
| 1767 | res = move_files_to_cd(bkpinfo, storing_filelist_fname,
|
---|
| 1768 | storing_afioball_fname, NULL);
|
---|
| 1769 | }
|
---|
| 1770 | }
|
---|
[128] | 1771 | }
|
---|
| 1772 | retval += res;
|
---|
| 1773 | g_current_progress++;
|
---|
| 1774 | update_progress_form(media_usage_comment);
|
---|
| 1775 | if (res) {
|
---|
| 1776 | sprintf(tmp,
|
---|
| 1777 | "Failed to add archive %ld's files to CD dir\n",
|
---|
| 1778 | storing_set_no);
|
---|
| 1779 | log_to_screen(tmp);
|
---|
| 1780 | fatal_error
|
---|
| 1781 | ("Is your hard disk full? If not, please send the author the logfile.");
|
---|
| 1782 | }
|
---|
| 1783 | storing_set_no++;
|
---|
| 1784 | // sleep(2);
|
---|
[1] | 1785 | }
|
---|
| 1786 | }
|
---|
[128] | 1787 | close_progress_form();
|
---|
[1] | 1788 |
|
---|
[128] | 1789 | sprintf(tmp, "Your regular files have been archived ");
|
---|
| 1790 | log_msg(2, "Joining background threads to foreground thread");
|
---|
| 1791 | for (i = 0; i < noof_threads; i++) {
|
---|
| 1792 | pthread_join(archival_thread[i], pvp);
|
---|
| 1793 | log_msg(3, "Thread %d of %d: closed OK", i + 1, noof_threads);
|
---|
| 1794 | }
|
---|
| 1795 | del_semvalue();
|
---|
| 1796 | log_msg(2, "Done.");
|
---|
| 1797 | if (retval) {
|
---|
| 1798 | strcat(tmp, "(with errors).");
|
---|
| 1799 | } else {
|
---|
| 1800 | strcat(tmp, "successfully.");
|
---|
| 1801 | }
|
---|
| 1802 | log_to_screen(tmp);
|
---|
| 1803 | paranoid_free(transfer_block);
|
---|
| 1804 | paranoid_free(result_str);
|
---|
| 1805 | paranoid_free(storing_filelist_fname);
|
---|
| 1806 | paranoid_free(media_usage_comment);
|
---|
| 1807 | paranoid_free(storing_afioball_fname);
|
---|
| 1808 | paranoid_free(curr_xattr_list_fname);
|
---|
| 1809 | paranoid_free(curr_acl_list_fname);
|
---|
| 1810 | return (retval);
|
---|
[1] | 1811 | }
|
---|
| 1812 |
|
---|
| 1813 |
|
---|
[128] | 1814 | void pause_for_N_seconds(int how_long, char *msg)
|
---|
[1] | 1815 | {
|
---|
[128] | 1816 | int i;
|
---|
| 1817 | open_evalcall_form(msg);
|
---|
| 1818 | for (i = 0; i < how_long; i++) {
|
---|
| 1819 | update_evalcall_form((int) ((100.0 / (float) (how_long) * i)));
|
---|
| 1820 | sleep(1);
|
---|
| 1821 | }
|
---|
| 1822 | close_evalcall_form();
|
---|
[1] | 1823 | }
|
---|
| 1824 |
|
---|
| 1825 |
|
---|
| 1826 |
|
---|
| 1827 |
|
---|
| 1828 | /**
|
---|
| 1829 | * Create an ISO image in @c destfile, from files in @c bkpinfo->scratchdir.
|
---|
| 1830 | *
|
---|
| 1831 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 1832 | * - @c backup_media_type
|
---|
| 1833 | * - @c call_after_iso
|
---|
| 1834 | * - @c call_before_iso
|
---|
| 1835 | * - @c call_burn_iso
|
---|
| 1836 | * - @c call_make_iso
|
---|
| 1837 | * - @c make_cd_use_lilo
|
---|
| 1838 | * - @c manual_cd_tray
|
---|
| 1839 | * - @c nonbootable_backup
|
---|
| 1840 | * - @c scratchdir
|
---|
| 1841 | *
|
---|
| 1842 | * @param destfile Where to put the generated ISO image.
|
---|
| 1843 | * @return The number of errors encountered (0 for success)
|
---|
| 1844 | */
|
---|
[541] | 1845 | int make_iso_fs(struct s_bkpinfo *bkpinfo, char *destfile)
|
---|
[1] | 1846 | {
|
---|
[128] | 1847 | /*@ int ********************************************** */
|
---|
| 1848 | int retval = 0;
|
---|
| 1849 | int res;
|
---|
[1] | 1850 |
|
---|
[128] | 1851 | /*@ buffers ****************************************** */
|
---|
| 1852 | char *tmp;
|
---|
| 1853 | char *old_pwd;
|
---|
| 1854 | char *result_sz;
|
---|
| 1855 | char *message_to_screen;
|
---|
| 1856 | char *sz_blank_disk;
|
---|
| 1857 | char *fnam;
|
---|
| 1858 | char *tmp2;
|
---|
| 1859 | char *tmp3;
|
---|
| 1860 | bool cd_is_mountable;
|
---|
[1] | 1861 |
|
---|
[128] | 1862 | malloc_string(old_pwd);
|
---|
| 1863 | malloc_string(result_sz);
|
---|
| 1864 | malloc_string(message_to_screen);
|
---|
| 1865 | malloc_string(sz_blank_disk);
|
---|
| 1866 | malloc_string(fnam);
|
---|
| 1867 | tmp = malloc(1200);
|
---|
| 1868 | tmp2 = malloc(1200);
|
---|
| 1869 | tmp3 = malloc(1200);
|
---|
| 1870 | assert(bkpinfo != NULL);
|
---|
| 1871 | assert_string_is_neither_NULL_nor_zerolength(destfile);
|
---|
[1] | 1872 |
|
---|
[128] | 1873 | sprintf(tmp, "%s/isolinux.bin", bkpinfo->scratchdir);
|
---|
| 1874 | sprintf(tmp2, "%s/isolinux.bin", bkpinfo->tmpdir);
|
---|
| 1875 | if (does_file_exist(tmp)) {
|
---|
| 1876 | sprintf(tmp3, "cp -f %s %s", tmp, tmp2);
|
---|
| 1877 | paranoid_system(tmp3);
|
---|
[1] | 1878 | }
|
---|
[128] | 1879 | if (!does_file_exist(tmp) && does_file_exist(tmp2)) {
|
---|
| 1880 | sprintf(tmp3, "cp -f %s %s", tmp2, tmp);
|
---|
| 1881 | paranoid_system(tmp3);
|
---|
[1] | 1882 | }
|
---|
[128] | 1883 | /*
|
---|
| 1884 | if (!does_file_exist(tmp))
|
---|
| 1885 | {
|
---|
| 1886 | log_msg (2, "Silly bug in Mindi.pl; workaround in progress...");
|
---|
| 1887 | strcpy(fnam, call_program_and_get_last_line_of_output("locate isolinux.bin | tail -n1"));
|
---|
| 1888 | if (strlen(fnam)>0 && does_file_exist(fnam))
|
---|
| 1889 | {
|
---|
| 1890 | sprintf(tmp, "cp -f %s %s", fnam, bkpinfo->scratchdir);
|
---|
| 1891 | res = run_program_and_log_output(tmp, FALSE);
|
---|
| 1892 | }
|
---|
| 1893 | else
|
---|
| 1894 | {
|
---|
| 1895 | res = 1;
|
---|
| 1896 | }
|
---|
| 1897 | if (res)
|
---|
| 1898 | {
|
---|
| 1899 | log_msg (2, "Could not work around silly bug in Mindi.pl - sorry! Isolinux.bin missing");
|
---|
| 1900 | }
|
---|
| 1901 | }
|
---|
| 1902 | */
|
---|
| 1903 | free(tmp2);
|
---|
| 1904 | free(tmp3);
|
---|
| 1905 | tmp2 = NULL;
|
---|
| 1906 | tmp3 = NULL;
|
---|
| 1907 | if (bkpinfo->backup_media_type == iso && bkpinfo->manual_cd_tray) {
|
---|
[541] | 1908 | popup_and_OK("Please insert new media and press Enter.");
|
---|
[128] | 1909 | }
|
---|
[1] | 1910 |
|
---|
[128] | 1911 | log_msg(2, "make_iso_fs --- scratchdir=%s --- destfile=%s",
|
---|
| 1912 | bkpinfo->scratchdir, destfile);
|
---|
| 1913 | (void) getcwd(old_pwd, MAX_STR_LEN - 1);
|
---|
| 1914 | sprintf(tmp, "chmod 744 %s", bkpinfo->scratchdir);
|
---|
| 1915 | run_program_and_log_output(tmp, FALSE);
|
---|
| 1916 | chdir(bkpinfo->scratchdir);
|
---|
[1] | 1917 |
|
---|
[128] | 1918 | if (bkpinfo->call_before_iso[0] != '\0') {
|
---|
| 1919 | sprintf(message_to_screen, "Running pre-ISO call for CD#%d",
|
---|
| 1920 | g_current_media_number);
|
---|
| 1921 | res =
|
---|
| 1922 | eval_call_to_make_ISO(bkpinfo, bkpinfo->call_before_iso,
|
---|
| 1923 | destfile, g_current_media_number,
|
---|
| 1924 | MONDO_LOGFILE, message_to_screen);
|
---|
| 1925 | if (res) {
|
---|
| 1926 | strcat(message_to_screen, "...failed");
|
---|
| 1927 | } else {
|
---|
| 1928 | strcat(message_to_screen, "...OK");
|
---|
| 1929 | }
|
---|
| 1930 | log_to_screen(message_to_screen);
|
---|
| 1931 | retval += res;
|
---|
[1] | 1932 | }
|
---|
| 1933 |
|
---|
[128] | 1934 | if (bkpinfo->call_make_iso[0] != '\0') {
|
---|
| 1935 | log_msg(2, "bkpinfo->call_make_iso = %s", bkpinfo->call_make_iso);
|
---|
| 1936 | sprintf(tmp, "%s/archives/NOT-THE-LAST", bkpinfo->scratchdir);
|
---|
| 1937 | sprintf(message_to_screen, "Making an ISO (%s #%d)",
|
---|
| 1938 | media_descriptor_string(bkpinfo->backup_media_type),
|
---|
| 1939 | g_current_media_number);
|
---|
[1] | 1940 |
|
---|
[128] | 1941 | pause_and_ask_for_cdr(2, &cd_is_mountable); /* if g_current_media_number >= 2 then pause & ask */
|
---|
| 1942 | if (retval) {
|
---|
| 1943 | log_to_screen
|
---|
| 1944 | ("Serious error(s) occurred already. I shan't try to write to media.");
|
---|
| 1945 | } else {
|
---|
| 1946 | res =
|
---|
| 1947 | eval_call_to_make_ISO(bkpinfo, bkpinfo->call_make_iso,
|
---|
| 1948 | bkpinfo->scratchdir,
|
---|
| 1949 | g_current_media_number,
|
---|
| 1950 | MONDO_LOGFILE, message_to_screen);
|
---|
| 1951 | if (res) {
|
---|
| 1952 | log_to_screen("%s...failed to write", message_to_screen);
|
---|
| 1953 | } else {
|
---|
| 1954 | log_to_screen("%s...OK", message_to_screen);
|
---|
[1315] | 1955 | sprintf(tmp, "tail -n10 %s | grep -F ':-('", MONDO_LOGFILE);
|
---|
| 1956 | if (!run_program_and_log_output(tmp, 1)) {
|
---|
[128] | 1957 | log_to_screen
|
---|
| 1958 | ("Despite nonfatal errors, growisofs confirms the write was successful.");
|
---|
| 1959 | }
|
---|
| 1960 | }
|
---|
| 1961 | retval += res;
|
---|
[1] | 1962 | #ifdef DVDRWFORMAT
|
---|
[128] | 1963 | sprintf(tmp,
|
---|
| 1964 | "tail -n8 %s | grep 'blank=full.*dvd-compat.*DAO'",
|
---|
| 1965 | MONDO_LOGFILE);
|
---|
| 1966 | if (g_backup_media_type == dvd
|
---|
| 1967 | && (res || !run_program_and_log_output(tmp, 1))) {
|
---|
| 1968 | log_to_screen
|
---|
| 1969 | ("Failed to write to disk. I shall blank it and then try again.");
|
---|
| 1970 | sleep(5);
|
---|
| 1971 | system("sync");
|
---|
| 1972 | pause_for_N_seconds(5, "Letting DVD drive settle");
|
---|
[1] | 1973 |
|
---|
| 1974 | // dvd+rw-format --- OPTION 2
|
---|
[128] | 1975 | if (!bkpinfo->please_dont_eject) {
|
---|
| 1976 | log_to_screen("Ejecting media to clear drive status.");
|
---|
| 1977 | eject_device(bkpinfo->media_device);
|
---|
| 1978 | inject_device(bkpinfo->media_device);
|
---|
| 1979 | }
|
---|
| 1980 | pause_for_N_seconds(5, "Letting DVD drive settle");
|
---|
[908] | 1981 | sprintf(sz_blank_disk, "dvd+rw-format -force %s",
|
---|
[128] | 1982 | bkpinfo->media_device);
|
---|
| 1983 | log_msg(3, "sz_blank_disk = '%s'", sz_blank_disk);
|
---|
| 1984 | res =
|
---|
| 1985 | run_external_binary_with_percentage_indicator_NEW
|
---|
| 1986 | ("Blanking DVD disk", sz_blank_disk);
|
---|
| 1987 | if (res) {
|
---|
| 1988 | log_to_screen
|
---|
| 1989 | ("Warning - format failed. (Was it a DVD-R?) Sleeping for 5 seconds to take a breath...");
|
---|
| 1990 | pause_for_N_seconds(5,
|
---|
| 1991 | "Letting DVD drive settle... and trying again.");
|
---|
| 1992 | res =
|
---|
| 1993 | run_external_binary_with_percentage_indicator_NEW
|
---|
| 1994 | ("Blanking DVD disk", sz_blank_disk);
|
---|
| 1995 | if (res) {
|
---|
| 1996 | log_to_screen("Format failed a second time.");
|
---|
| 1997 | }
|
---|
| 1998 | } else {
|
---|
| 1999 | log_to_screen
|
---|
| 2000 | ("Format succeeded. Sleeping for 5 seconds to take a breath...");
|
---|
| 2001 | }
|
---|
| 2002 | pause_for_N_seconds(5, "Letting DVD drive settle");
|
---|
| 2003 | if (!bkpinfo->please_dont_eject) {
|
---|
| 2004 | log_to_screen("Ejecting media to clear drive status.");
|
---|
| 2005 | eject_device(bkpinfo->media_device);
|
---|
| 2006 | inject_device(bkpinfo->media_device);
|
---|
| 2007 | }
|
---|
| 2008 | pause_for_N_seconds(5, "Letting DVD drive settle");
|
---|
| 2009 | res =
|
---|
| 2010 | eval_call_to_make_ISO(bkpinfo, bkpinfo->call_make_iso,
|
---|
| 2011 | bkpinfo->scratchdir,
|
---|
| 2012 | g_current_media_number,
|
---|
| 2013 | MONDO_LOGFILE,
|
---|
| 2014 | message_to_screen);
|
---|
| 2015 | retval += res;
|
---|
| 2016 | if (!bkpinfo->please_dont_eject) {
|
---|
| 2017 | log_to_screen("Ejecting media.");
|
---|
| 2018 | eject_device(bkpinfo->media_device);
|
---|
| 2019 | }
|
---|
| 2020 | if (res) {
|
---|
| 2021 | log_to_screen("Dagnabbit. It still failed.");
|
---|
| 2022 | } else {
|
---|
| 2023 | log_to_screen
|
---|
| 2024 | ("OK, this time I successfully backed up to DVD.");
|
---|
| 2025 | }
|
---|
| 2026 | }
|
---|
| 2027 | #endif
|
---|
| 2028 | if (g_backup_media_type == dvd && !bkpinfo->please_dont_eject) {
|
---|
| 2029 | eject_device(bkpinfo->media_device);
|
---|
| 2030 | }
|
---|
[1] | 2031 | }
|
---|
[128] | 2032 | } else {
|
---|
| 2033 | sprintf(message_to_screen, "Running mkisofs to make %s #%d",
|
---|
| 2034 | media_descriptor_string(bkpinfo->backup_media_type),
|
---|
| 2035 | g_current_media_number);
|
---|
| 2036 | log_msg(1, message_to_screen);
|
---|
| 2037 | sprintf(result_sz, "Call to mkisofs to make ISO (%s #%d) ",
|
---|
| 2038 | media_descriptor_string(bkpinfo->backup_media_type),
|
---|
| 2039 | g_current_media_number);
|
---|
| 2040 | if (bkpinfo->nonbootable_backup) {
|
---|
| 2041 | log_msg(1, "Making nonbootable backup");
|
---|
[1] | 2042 | // FIXME --- change mkisofs string to MONDO_MKISOFS_NONBOOTABLE and add ' .' at end
|
---|
[128] | 2043 | res =
|
---|
| 2044 | eval_call_to_make_ISO(bkpinfo,
|
---|
[906] | 2045 | "mkisofs -o '_ISO_' -r -p MondoRescue -publisher www.mondorescue.org -A MondoRescue_GPL -V _CD#_ .",
|
---|
[128] | 2046 | destfile, g_current_media_number,
|
---|
| 2047 | MONDO_LOGFILE, message_to_screen);
|
---|
| 2048 | } else {
|
---|
| 2049 | log_msg(1, "Making bootable backup");
|
---|
[1] | 2050 |
|
---|
| 2051 | #ifdef __FreeBSD__
|
---|
[128] | 2052 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
[1] | 2053 | #endif
|
---|
| 2054 |
|
---|
| 2055 |
|
---|
[128] | 2056 | log_msg(1, "make_cd_use_lilo is actually %d",
|
---|
| 2057 | bkpinfo->make_cd_use_lilo);
|
---|
| 2058 | if (bkpinfo->make_cd_use_lilo) {
|
---|
| 2059 | log_msg(1, "make_cd_use_lilo = TRUE");
|
---|
[1] | 2060 | // FIXME --- change mkisofs string to MONDO_MKISOFS_REGULAR_SYSLINUX/LILO depending on bkpinfo->make_cd_usE_lilo
|
---|
| 2061 | // and add ' .' at end
|
---|
| 2062 | #ifdef __IA64__
|
---|
[128] | 2063 | log_msg(1, "IA64 --> elilo");
|
---|
| 2064 | res = eval_call_to_make_ISO(bkpinfo,
|
---|
| 2065 | //-b images/mindi-boot.2880.img
|
---|
[541] | 2066 | "mkisofs -no-emul-boot -b images/mindi-bootroot."
|
---|
| 2067 | IA64_BOOT_SIZE
|
---|
[906] | 2068 | ".img -c boot.cat -o '_ISO_' -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .",
|
---|
[128] | 2069 | destfile,
|
---|
| 2070 | g_current_media_number,
|
---|
| 2071 | MONDO_LOGFILE,
|
---|
| 2072 | message_to_screen);
|
---|
[1] | 2073 | #else
|
---|
| 2074 | // FIXME --- change mkisofs string to MONDO_MKISOFS_REGULAR_SYSLINUX/LILO depending on bkpinfo->make_cd_usE_lilo
|
---|
| 2075 | // and add ' .' at end
|
---|
[128] | 2076 | log_msg(1, "Non-ia64 --> lilo");
|
---|
| 2077 | res =
|
---|
| 2078 | eval_call_to_make_ISO(bkpinfo,
|
---|
[906] | 2079 | "mkisofs -b images/mindi-bootroot.2880.img -c boot.cat -o '_ISO_' -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .",
|
---|
[128] | 2080 | destfile, g_current_media_number,
|
---|
| 2081 | MONDO_LOGFILE,
|
---|
| 2082 | message_to_screen);
|
---|
[1] | 2083 | #endif
|
---|
[128] | 2084 | } else {
|
---|
| 2085 | log_msg(1, "make_cd_use_lilo = FALSE");
|
---|
| 2086 | log_msg(1, "Isolinux");
|
---|
| 2087 | res =
|
---|
| 2088 | eval_call_to_make_ISO(bkpinfo,
|
---|
[906] | 2089 | "mkisofs -no-emul-boot -b isolinux.bin -boot-load-size 4 -boot-info-table -c boot.cat -o '_ISO_' -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .",
|
---|
[128] | 2090 | destfile, g_current_media_number,
|
---|
| 2091 | MONDO_LOGFILE,
|
---|
| 2092 | message_to_screen);
|
---|
| 2093 | }
|
---|
| 2094 | }
|
---|
| 2095 | if (res) {
|
---|
| 2096 | strcat(result_sz, "...failed");
|
---|
| 2097 | } else {
|
---|
| 2098 | strcat(result_sz, "...OK");
|
---|
| 2099 | }
|
---|
| 2100 | log_to_screen(result_sz);
|
---|
| 2101 | retval += res;
|
---|
[1] | 2102 | }
|
---|
[128] | 2103 |
|
---|
| 2104 | if (bkpinfo->backup_media_type == cdr
|
---|
| 2105 | || bkpinfo->backup_media_type == cdrw) {
|
---|
| 2106 | if (is_this_device_mounted(bkpinfo->media_device)) {
|
---|
| 2107 | log_msg(2,
|
---|
| 2108 | "Warning - %s mounted. I'm unmounting it before I burn to it.",
|
---|
| 2109 | bkpinfo->media_device);
|
---|
| 2110 | sprintf(tmp, "umount %s", bkpinfo->media_device);
|
---|
| 2111 | run_program_and_log_output(tmp, FALSE);
|
---|
| 2112 | }
|
---|
[1] | 2113 | }
|
---|
| 2114 |
|
---|
[128] | 2115 | if (bkpinfo->call_burn_iso[0] != '\0') {
|
---|
| 2116 | log_msg(2, "bkpinfo->call_burn_iso = %s", bkpinfo->call_burn_iso);
|
---|
| 2117 | sprintf(message_to_screen, "Burning %s #%d",
|
---|
| 2118 | media_descriptor_string(bkpinfo->backup_media_type),
|
---|
| 2119 | g_current_media_number);
|
---|
| 2120 | pause_and_ask_for_cdr(2, &cd_is_mountable);
|
---|
| 2121 | res =
|
---|
| 2122 | eval_call_to_make_ISO(bkpinfo, bkpinfo->call_burn_iso,
|
---|
| 2123 | destfile, g_current_media_number,
|
---|
| 2124 | MONDO_LOGFILE, message_to_screen);
|
---|
| 2125 | if (res) {
|
---|
| 2126 | strcat(message_to_screen, "...failed");
|
---|
| 2127 | } else {
|
---|
| 2128 | strcat(message_to_screen, "...OK");
|
---|
| 2129 | }
|
---|
| 2130 | log_to_screen(message_to_screen);
|
---|
| 2131 | retval += res;
|
---|
| 2132 | }
|
---|
[1] | 2133 |
|
---|
[128] | 2134 | if (bkpinfo->call_after_iso[0] != '\0') {
|
---|
| 2135 | sprintf(message_to_screen, "Running post-ISO call (%s #%d)",
|
---|
| 2136 | media_descriptor_string(bkpinfo->backup_media_type),
|
---|
| 2137 | g_current_media_number);
|
---|
| 2138 | res =
|
---|
| 2139 | eval_call_to_make_ISO(bkpinfo, bkpinfo->call_after_iso,
|
---|
| 2140 | destfile, g_current_media_number,
|
---|
| 2141 | MONDO_LOGFILE, message_to_screen);
|
---|
| 2142 | if (res) {
|
---|
| 2143 | strcat(message_to_screen, "...failed");
|
---|
| 2144 | } else {
|
---|
| 2145 | strcat(message_to_screen, "...OK");
|
---|
| 2146 | }
|
---|
| 2147 | log_to_screen(message_to_screen);
|
---|
| 2148 | retval += res;
|
---|
[1] | 2149 | }
|
---|
| 2150 |
|
---|
[128] | 2151 | chdir(old_pwd);
|
---|
| 2152 | if (retval) {
|
---|
| 2153 | log_msg(1, "WARNING - make_iso_fs returned an error");
|
---|
[1] | 2154 | }
|
---|
[128] | 2155 | paranoid_free(old_pwd);
|
---|
| 2156 | paranoid_free(result_sz);
|
---|
| 2157 | paranoid_free(message_to_screen);
|
---|
| 2158 | paranoid_free(sz_blank_disk);
|
---|
| 2159 | paranoid_free(fnam);
|
---|
| 2160 | paranoid_free(tmp);
|
---|
| 2161 | return (retval);
|
---|
[1] | 2162 | }
|
---|
| 2163 |
|
---|
| 2164 |
|
---|
| 2165 |
|
---|
| 2166 |
|
---|
| 2167 |
|
---|
| 2168 |
|
---|
| 2169 |
|
---|
| 2170 |
|
---|
| 2171 |
|
---|
| 2172 | bool is_dev_an_NTFS_dev(char *bigfile_fname)
|
---|
| 2173 | {
|
---|
[128] | 2174 | char *tmp;
|
---|
| 2175 | char *command;
|
---|
| 2176 | malloc_string(tmp);
|
---|
| 2177 | malloc_string(command);
|
---|
| 2178 | sprintf(command,
|
---|
| 2179 | "dd if=%s bs=512 count=1 2> /dev/null | strings | head -n1",
|
---|
| 2180 | bigfile_fname);
|
---|
| 2181 | log_msg(1, "command = '%s'", command);
|
---|
| 2182 | strcpy(tmp, call_program_and_get_last_line_of_output(command));
|
---|
| 2183 | log_msg(1, "--> tmp = '%s'", tmp);
|
---|
| 2184 | if (strstr(tmp, "NTFS")) {
|
---|
| 2185 | iamhere("TRUE");
|
---|
| 2186 | return (TRUE);
|
---|
| 2187 | } else {
|
---|
| 2188 | iamhere("FALSE");
|
---|
| 2189 | return (FALSE);
|
---|
| 2190 | }
|
---|
[1] | 2191 | }
|
---|
| 2192 |
|
---|
| 2193 |
|
---|
| 2194 | /**
|
---|
| 2195 | * Back up big files by chopping them up.
|
---|
| 2196 | * This function backs up all "big" files (where "big" depends
|
---|
| 2197 | * on your backup media) in "chunks" (whose size again depends
|
---|
| 2198 | * on your media).
|
---|
| 2199 | *
|
---|
| 2200 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 2201 | * - @c backup_media_type
|
---|
| 2202 | * - @c optimal_set_size
|
---|
| 2203 | * @param biggielist_fname The path to a file containing a list of
|
---|
| 2204 | * all "big" files.
|
---|
| 2205 | * @return The number of errors encountered (0 for success)
|
---|
| 2206 | * @see slice_up_file_etc
|
---|
| 2207 | */
|
---|
| 2208 | int
|
---|
[541] | 2209 | make_slices_and_images(struct s_bkpinfo *bkpinfo, char *biggielist_fname)
|
---|
[1] | 2210 | {
|
---|
| 2211 |
|
---|
[128] | 2212 | /*@ pointers ******************************************* */
|
---|
| 2213 | FILE *fin;
|
---|
| 2214 | char *p;
|
---|
[1] | 2215 |
|
---|
[128] | 2216 | /*@ buffers ******************************************** */
|
---|
| 2217 | char *tmp;
|
---|
| 2218 | char *bigfile_fname;
|
---|
| 2219 | char *sz_devfile;
|
---|
[296] | 2220 | char *ntfsprog_fifo = NULL;
|
---|
[128] | 2221 | /*@ long *********************************************** */
|
---|
| 2222 | long biggie_file_number = 0;
|
---|
| 2223 | long noof_biggie_files = 0;
|
---|
| 2224 | long estimated_total_noof_slices = 0;
|
---|
[1] | 2225 |
|
---|
[128] | 2226 | /*@ int ************************************************ */
|
---|
| 2227 | int retval = 0;
|
---|
| 2228 | int res = 0;
|
---|
| 2229 | pid_t pid;
|
---|
| 2230 | FILE *ftmp = NULL;
|
---|
| 2231 | bool delete_when_done;
|
---|
[296] | 2232 | bool use_ntfsprog;
|
---|
[684] | 2233 | off_t biggie_fsize;
|
---|
[1] | 2234 |
|
---|
[128] | 2235 | assert(bkpinfo != NULL);
|
---|
| 2236 | assert_string_is_neither_NULL_nor_zerolength(biggielist_fname);
|
---|
[1] | 2237 |
|
---|
[128] | 2238 | malloc_string(tmp);
|
---|
| 2239 | malloc_string(bigfile_fname);
|
---|
| 2240 | malloc_string(sz_devfile);
|
---|
| 2241 | estimated_total_noof_slices =
|
---|
| 2242 | size_of_all_biggiefiles_K(bkpinfo) / bkpinfo->optimal_set_size + 1;
|
---|
[1] | 2243 |
|
---|
[128] | 2244 | log_msg(1, "size of all biggiefiles = %ld",
|
---|
| 2245 | size_of_all_biggiefiles_K(bkpinfo));
|
---|
| 2246 | log_msg(1, "estimated_total_noof_slices = %ld KB / %ld KB = %ld",
|
---|
| 2247 | size_of_all_biggiefiles_K(bkpinfo), bkpinfo->optimal_set_size,
|
---|
| 2248 | estimated_total_noof_slices);
|
---|
[1] | 2249 |
|
---|
[128] | 2250 | if (length_of_file(biggielist_fname) < 6) {
|
---|
| 2251 | log_msg(1, "No biggiefiles; fair enough...");
|
---|
| 2252 | return (0);
|
---|
[1] | 2253 | }
|
---|
[128] | 2254 | sprintf(tmp, "I am now backing up all large files.");
|
---|
| 2255 | log_to_screen(tmp);
|
---|
| 2256 | noof_biggie_files = count_lines_in_file(biggielist_fname);
|
---|
| 2257 | open_progress_form("Backing up big files", tmp,
|
---|
| 2258 | "Please wait. This may take some time.", "",
|
---|
| 2259 | estimated_total_noof_slices);
|
---|
| 2260 | if (!(fin = fopen(biggielist_fname, "r"))) {
|
---|
| 2261 | log_OS_error("Unable to openin biggielist");
|
---|
| 2262 | return (1);
|
---|
[1] | 2263 | }
|
---|
[128] | 2264 | for (fgets(bigfile_fname, MAX_STR_LEN, fin); !feof(fin);
|
---|
| 2265 | fgets(bigfile_fname, MAX_STR_LEN, fin), biggie_file_number++) {
|
---|
[296] | 2266 | use_ntfsprog = FALSE;
|
---|
[128] | 2267 | if (bigfile_fname[strlen(bigfile_fname) - 1] < 32) {
|
---|
| 2268 | bigfile_fname[strlen(bigfile_fname) - 1] = '\0';
|
---|
| 2269 | }
|
---|
| 2270 | biggie_fsize = length_of_file(bigfile_fname);
|
---|
| 2271 | delete_when_done = FALSE;
|
---|
| 2272 |
|
---|
| 2273 | if (!does_file_exist(bigfile_fname)) {
|
---|
| 2274 | ftmp = fopen(bigfile_fname, "w");
|
---|
[1299] | 2275 | if (ftmp == NULL) {
|
---|
| 2276 | log_msg("Unable to write to %s", bigfile_fname);
|
---|
| 2277 | // So skip it as it doesn't exist
|
---|
| 2278 | continue;
|
---|
| 2279 | } else {
|
---|
| 2280 | paranoid_fclose(ftmp);
|
---|
| 2281 | }
|
---|
[128] | 2282 | delete_when_done = TRUE;
|
---|
| 2283 | } else {
|
---|
[812] | 2284 | // Call ntfsclone (formerly partimagehack) if it's a /dev entry
|
---|
| 2285 | // (i.e. a partition to be imaged)
|
---|
[541] | 2286 | log_msg(2, "bigfile_fname = %s", bigfile_fname);
|
---|
[296] | 2287 | use_ntfsprog = FALSE;
|
---|
[128] | 2288 | if (!strncmp(bigfile_fname, "/dev/", 5)
|
---|
| 2289 | && is_dev_an_NTFS_dev(bigfile_fname)) {
|
---|
[296] | 2290 | use_ntfsprog = TRUE;
|
---|
[128] | 2291 | log_msg(2,
|
---|
[296] | 2292 | "Calling ntfsclone in background because %s is an NTFS partition",
|
---|
[128] | 2293 | bigfile_fname);
|
---|
[812] | 2294 | sprintf(sz_devfile, "%s/%d.%d.000",
|
---|
| 2295 | bkpinfo->tmpdir,
|
---|
[128] | 2296 | (int) (random() % 32768),
|
---|
| 2297 | (int) (random() % 32768));
|
---|
| 2298 | mkfifo(sz_devfile, 0x770);
|
---|
[296] | 2299 | ntfsprog_fifo = sz_devfile;
|
---|
[128] | 2300 | switch (pid = fork()) {
|
---|
| 2301 | case -1:
|
---|
| 2302 | fatal_error("Fork failure");
|
---|
| 2303 | case 0:
|
---|
| 2304 | log_msg(2,
|
---|
[296] | 2305 | "CHILD - fip - calling feed_into_ntfsprog(%s, %s)",
|
---|
[128] | 2306 | bigfile_fname, sz_devfile);
|
---|
[296] | 2307 | res = feed_into_ntfsprog(bigfile_fname, sz_devfile);
|
---|
[128] | 2308 | exit(res);
|
---|
| 2309 | break;
|
---|
| 2310 | default:
|
---|
| 2311 | log_msg(2,
|
---|
[296] | 2312 | "feed_into_ntfsprog() called in background --- pid=%ld",
|
---|
[128] | 2313 | (long int) (pid));
|
---|
| 2314 | }
|
---|
| 2315 | }
|
---|
[1] | 2316 | // Otherwise, use good old 'dd' and 'bzip2'
|
---|
[128] | 2317 | else {
|
---|
| 2318 | sz_devfile[0] = '\0';
|
---|
[296] | 2319 | ntfsprog_fifo = NULL;
|
---|
[128] | 2320 | }
|
---|
[1] | 2321 |
|
---|
| 2322 | // Whether partition or biggiefile, just do your thang :-)
|
---|
[128] | 2323 | sprintf(tmp, "Bigfile #%ld is '%s' (%ld KB)",
|
---|
| 2324 | biggie_file_number + 1, bigfile_fname,
|
---|
| 2325 | (long) biggie_fsize >> 10);
|
---|
| 2326 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 2327 | write_header_block_to_stream(biggie_fsize, bigfile_fname,
|
---|
[296] | 2328 | use_ntfsprog ?
|
---|
[128] | 2329 | BLK_START_A_PIHBIGGIE :
|
---|
| 2330 | BLK_START_A_NORMBIGGIE);
|
---|
| 2331 | }
|
---|
| 2332 | res =
|
---|
[541] | 2333 | slice_up_file_etc(bkpinfo, bigfile_fname,
|
---|
[296] | 2334 | ntfsprog_fifo, biggie_file_number,
|
---|
| 2335 | noof_biggie_files, use_ntfsprog);
|
---|
[128] | 2336 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
[684] | 2337 | write_header_block_to_stream((off_t)0,
|
---|
[128] | 2338 | calc_checksum_of_file
|
---|
| 2339 | (bigfile_fname),
|
---|
| 2340 | BLK_STOP_A_BIGGIE);
|
---|
| 2341 | }
|
---|
| 2342 | retval += res;
|
---|
| 2343 | p = strrchr(bigfile_fname, '/');
|
---|
| 2344 | if (p) {
|
---|
| 2345 | p++;
|
---|
| 2346 | } else {
|
---|
| 2347 | p = bigfile_fname;
|
---|
| 2348 | }
|
---|
| 2349 | sprintf(tmp, "Archiving %s ... ", bigfile_fname);
|
---|
| 2350 | if (res) {
|
---|
| 2351 | strcat(tmp, "Failed!");
|
---|
| 2352 | } else {
|
---|
| 2353 | strcat(tmp, "OK");
|
---|
| 2354 | }
|
---|
| 2355 | if (delete_when_done) {
|
---|
| 2356 | unlink(bigfile_fname);
|
---|
| 2357 | delete_when_done = FALSE;
|
---|
| 2358 | }
|
---|
| 2359 | }
|
---|
[1] | 2360 | #ifndef _XWIN
|
---|
[128] | 2361 | if (!g_text_mode) {
|
---|
| 2362 | newtDrawRootText(0, g_noof_rows - 2, tmp);
|
---|
| 2363 | newtRefresh();
|
---|
| 2364 | }
|
---|
[1] | 2365 | #endif
|
---|
[128] | 2366 | }
|
---|
| 2367 | log_msg(1, "Finished backing up bigfiles");
|
---|
| 2368 | log_msg(1, "estimated slices = %ld; actual slices = %ld",
|
---|
| 2369 | estimated_total_noof_slices, g_current_progress);
|
---|
| 2370 | close_progress_form();
|
---|
| 2371 | paranoid_fclose(fin);
|
---|
| 2372 | paranoid_free(tmp);
|
---|
| 2373 | paranoid_free(bigfile_fname);
|
---|
| 2374 | paranoid_free(sz_devfile);
|
---|
| 2375 | return (retval);
|
---|
[1] | 2376 | }
|
---|
| 2377 |
|
---|
| 2378 |
|
---|
| 2379 |
|
---|
| 2380 |
|
---|
| 2381 | /**
|
---|
| 2382 | * Single-threaded version of @c make_afioballs_and_images().
|
---|
| 2383 | * @see make_afioballs_and_images
|
---|
| 2384 | */
|
---|
[541] | 2385 | int make_afioballs_and_images_OLD(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 2386 | {
|
---|
| 2387 |
|
---|
[128] | 2388 | /*@ int ************************************************** */
|
---|
| 2389 | int retval = 0;
|
---|
| 2390 | long int curr_set_no = 0;
|
---|
| 2391 | int res = 0;
|
---|
[1] | 2392 |
|
---|
[128] | 2393 | /*@ buffers ********************************************** */
|
---|
| 2394 | char *curr_filelist_fname;
|
---|
| 2395 | char *curr_afioball_fname;
|
---|
| 2396 | char *curr_xattr_list_fname;
|
---|
| 2397 | char *curr_acl_list_fname;
|
---|
| 2398 | char *tmp;
|
---|
| 2399 | char *media_usage_comment;
|
---|
[1] | 2400 |
|
---|
[128] | 2401 | malloc_string(curr_afioball_fname);
|
---|
| 2402 | malloc_string(media_usage_comment);
|
---|
| 2403 | malloc_string(curr_filelist_fname);
|
---|
| 2404 | malloc_string(curr_xattr_list_fname);
|
---|
| 2405 | malloc_string(curr_acl_list_fname);
|
---|
[1] | 2406 |
|
---|
[128] | 2407 | tmp = malloc(MAX_STR_LEN * 2);
|
---|
[1] | 2408 |
|
---|
[128] | 2409 | sprintf(tmp, "%s/archives/filelist.full", bkpinfo->scratchdir);
|
---|
[1] | 2410 |
|
---|
[128] | 2411 | log_to_screen("Archiving regular files");
|
---|
[1] | 2412 |
|
---|
[541] | 2413 | open_progress_form("Backing up filesystem",
|
---|
| 2414 | "I am backing up your live filesystem now.",
|
---|
| 2415 | "Please wait. This may take a couple of hours.",
|
---|
| 2416 | "Working...",
|
---|
[128] | 2417 | get_last_filelist_number(bkpinfo) + 1);
|
---|
| 2418 |
|
---|
| 2419 | sprintf(curr_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir,
|
---|
| 2420 | 0L);
|
---|
| 2421 |
|
---|
| 2422 | for (curr_set_no = 0; does_file_exist(curr_filelist_fname);
|
---|
| 2423 | sprintf(curr_filelist_fname, FILELIST_FNAME_RAW_SZ,
|
---|
| 2424 | bkpinfo->tmpdir, ++curr_set_no)) {
|
---|
| 2425 | /* backup this set of files */
|
---|
| 2426 | sprintf(curr_filelist_fname, FILELIST_FNAME_RAW_SZ,
|
---|
| 2427 | bkpinfo->tmpdir, curr_set_no);
|
---|
| 2428 | sprintf(curr_afioball_fname, AFIOBALL_FNAME_RAW_SZ,
|
---|
| 2429 | bkpinfo->tmpdir, curr_set_no, bkpinfo->zip_suffix);
|
---|
| 2430 |
|
---|
| 2431 | log_msg(1, "EXAT'g set %ld", curr_set_no);
|
---|
[948] | 2432 | if (g_getfattr) {
|
---|
| 2433 | sprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
|
---|
[128] | 2434 | bkpinfo->tmpdir, curr_set_no);
|
---|
[948] | 2435 | get_fattr_list(curr_filelist_fname, curr_xattr_list_fname);
|
---|
| 2436 | }
|
---|
| 2437 | if (g_getfacl) {
|
---|
| 2438 | sprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
|
---|
[128] | 2439 | bkpinfo->tmpdir, curr_set_no);
|
---|
[948] | 2440 | get_acl_list(curr_filelist_fname, curr_acl_list_fname);
|
---|
| 2441 | }
|
---|
[128] | 2442 |
|
---|
| 2443 | log_msg(1, "Archiving set %ld", curr_set_no);
|
---|
| 2444 | res =
|
---|
| 2445 | archive_this_fileset(bkpinfo, curr_filelist_fname,
|
---|
| 2446 | curr_afioball_fname, curr_set_no);
|
---|
| 2447 | retval += res;
|
---|
| 2448 | if (res) {
|
---|
| 2449 | sprintf(tmp,
|
---|
| 2450 | "Errors occurred while archiving set %ld. Perhaps your live filesystem changed?",
|
---|
| 2451 | curr_set_no);
|
---|
| 2452 | log_to_screen(tmp);
|
---|
| 2453 | }
|
---|
| 2454 |
|
---|
| 2455 | strcpy(media_usage_comment, percent_media_full_comment(bkpinfo));
|
---|
| 2456 |
|
---|
| 2457 | /* copy to CD (scratchdir) ... and an actual CD-R if necessary */
|
---|
| 2458 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 2459 | register_in_tape_catalog(fileset, curr_set_no, -1,
|
---|
| 2460 | curr_afioball_fname);
|
---|
| 2461 | maintain_collection_of_recent_archives(bkpinfo->tmpdir,
|
---|
| 2462 | curr_afioball_fname);
|
---|
| 2463 | iamhere("Writing EXAT files");
|
---|
| 2464 | res +=
|
---|
| 2465 | write_EXAT_files_to_tape(bkpinfo, curr_xattr_list_fname,
|
---|
| 2466 | curr_acl_list_fname);
|
---|
[1] | 2467 | // archives themselves
|
---|
[128] | 2468 | res = move_files_to_stream(bkpinfo, curr_afioball_fname, NULL);
|
---|
| 2469 | } else {
|
---|
[948] | 2470 | if (g_getfacl) {
|
---|
| 2471 | if (g_getfattr) {
|
---|
| 2472 | res = move_files_to_cd(bkpinfo, curr_filelist_fname,
|
---|
| 2473 | curr_xattr_list_fname,
|
---|
| 2474 | curr_acl_list_fname,
|
---|
| 2475 | curr_afioball_fname, NULL);
|
---|
| 2476 | } else {
|
---|
| 2477 | res = move_files_to_cd(bkpinfo, curr_filelist_fname,
|
---|
| 2478 | curr_acl_list_fname,
|
---|
| 2479 | curr_afioball_fname, NULL);
|
---|
| 2480 | }
|
---|
| 2481 | } else {
|
---|
| 2482 | if (g_getfattr) {
|
---|
| 2483 | res = move_files_to_cd(bkpinfo, curr_filelist_fname,
|
---|
| 2484 | curr_xattr_list_fname,
|
---|
| 2485 | curr_afioball_fname, NULL);
|
---|
| 2486 | } else {
|
---|
| 2487 | res = move_files_to_cd(bkpinfo, curr_filelist_fname,
|
---|
| 2488 | curr_afioball_fname, NULL);
|
---|
| 2489 | }
|
---|
| 2490 | }
|
---|
[128] | 2491 | }
|
---|
| 2492 | retval += res;
|
---|
| 2493 | g_current_progress++;
|
---|
| 2494 | update_progress_form(media_usage_comment);
|
---|
[1] | 2495 |
|
---|
[128] | 2496 | if (res) {
|
---|
| 2497 | sprintf(tmp, "Failed to add archive %ld's files to CD dir\n",
|
---|
| 2498 | curr_set_no);
|
---|
| 2499 | log_to_screen(tmp);
|
---|
| 2500 | fatal_error
|
---|
| 2501 | ("Is your hard disk is full? If not, please send the author the logfile.");
|
---|
| 2502 | }
|
---|
[1] | 2503 | }
|
---|
[128] | 2504 | close_progress_form();
|
---|
| 2505 | sprintf(tmp, "Your regular files have been archived ");
|
---|
| 2506 | if (retval) {
|
---|
| 2507 | strcat(tmp, "(with errors).");
|
---|
| 2508 | } else {
|
---|
| 2509 | strcat(tmp, "successfully.");
|
---|
| 2510 | }
|
---|
| 2511 | log_to_screen(tmp);
|
---|
| 2512 | paranoid_free(tmp);
|
---|
| 2513 | paranoid_free(curr_filelist_fname);
|
---|
| 2514 | paranoid_free(curr_afioball_fname);
|
---|
| 2515 | paranoid_free(media_usage_comment);
|
---|
| 2516 | paranoid_free(curr_xattr_list_fname);
|
---|
| 2517 | paranoid_free(curr_acl_list_fname);
|
---|
| 2518 | return (retval);
|
---|
[1] | 2519 | }
|
---|
| 2520 |
|
---|
[128] | 2521 | /* @} - end of LLarchiveGroup */
|
---|
| 2522 |
|
---|
| 2523 |
|
---|
[1] | 2524 | /**
|
---|
| 2525 | * Wrapper around @c make_afioballs_and_images().
|
---|
| 2526 | * @param bkpinfo the backup information structure. Only the
|
---|
| 2527 | * @c backup_media_type field is used within this function.
|
---|
| 2528 | * @return return code of make_afioballs_and_images
|
---|
| 2529 | * @see make_afioballs_and_images
|
---|
| 2530 | * @ingroup MLarchiveGroup
|
---|
| 2531 | */
|
---|
[541] | 2532 | int make_those_afios_phase(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 2533 | {
|
---|
[128] | 2534 | /*@ int ******************************************* */
|
---|
| 2535 | int res = 0;
|
---|
| 2536 | int retval = 0;
|
---|
[1] | 2537 |
|
---|
[128] | 2538 | assert(bkpinfo != NULL);
|
---|
[1] | 2539 |
|
---|
[128] | 2540 | mvaddstr_and_log_it(g_currentY, 0,
|
---|
| 2541 | "Archiving regular files to media ");
|
---|
[1] | 2542 |
|
---|
[128] | 2543 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
[684] | 2544 | write_header_block_to_stream((off_t)0, "start-of-afioballs",
|
---|
[128] | 2545 | BLK_START_AFIOBALLS);
|
---|
[1] | 2546 | #if __FreeBSD__ == 5
|
---|
[128] | 2547 | log_msg(1,
|
---|
| 2548 | "Using single-threaded make_afioballs_and_images() to suit b0rken FreeBSD 5.0");
|
---|
[541] | 2549 | res = make_afioballs_and_images_OLD(bkpinfo);
|
---|
[1] | 2550 | #else
|
---|
[541] | 2551 | res = make_afioballs_and_images_OLD(bkpinfo);
|
---|
[1] | 2552 | #endif
|
---|
[684] | 2553 | write_header_block_to_stream((off_t)0, "stop-afioballs",
|
---|
[128] | 2554 | BLK_STOP_AFIOBALLS);
|
---|
| 2555 | } else {
|
---|
[541] | 2556 | res = make_afioballs_and_images(bkpinfo);
|
---|
[128] | 2557 | }
|
---|
[1] | 2558 |
|
---|
[128] | 2559 | retval += res;
|
---|
| 2560 | if (res) {
|
---|
| 2561 | mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
|
---|
| 2562 | log_msg(1, "make_afioballs_and_images returned an error");
|
---|
| 2563 | } else {
|
---|
| 2564 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
| 2565 | }
|
---|
| 2566 | return (retval);
|
---|
[1] | 2567 | }
|
---|
| 2568 |
|
---|
| 2569 | /**
|
---|
| 2570 | * Wrapper around @c make_slices_and_images().
|
---|
| 2571 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 2572 | * - @c backup_media_type
|
---|
| 2573 | * - @c scratchdir
|
---|
| 2574 | * - @c tmpdir
|
---|
| 2575 | * @return The number of errors encountered (0 for success)
|
---|
| 2576 | * @ingroup MLarchiveGroup
|
---|
| 2577 | */
|
---|
[128] | 2578 | int make_those_slices_phase(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 2579 | {
|
---|
| 2580 |
|
---|
[128] | 2581 | /*@ int ***************************************************** */
|
---|
| 2582 | int res = 0;
|
---|
| 2583 | int retval = 0;
|
---|
[1] | 2584 |
|
---|
[128] | 2585 | /*@ buffers ************************************************** */
|
---|
| 2586 | char *biggielist;
|
---|
| 2587 | char *command;
|
---|
| 2588 | char *blah;
|
---|
| 2589 | char *xattr_fname;
|
---|
| 2590 | char *acl_fname;
|
---|
[1] | 2591 |
|
---|
[128] | 2592 | assert(bkpinfo != NULL);
|
---|
| 2593 | /* slice big files */
|
---|
| 2594 | malloc_string(biggielist);
|
---|
| 2595 | malloc_string(xattr_fname);
|
---|
| 2596 | malloc_string(acl_fname);
|
---|
| 2597 | mvaddstr_and_log_it(g_currentY, 0,
|
---|
| 2598 | "Archiving large files to media ");
|
---|
| 2599 | sprintf(biggielist, "%s/archives/biggielist.txt", bkpinfo->scratchdir);
|
---|
[948] | 2600 | if (g_getfattr) {
|
---|
| 2601 | sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
|
---|
| 2602 | }
|
---|
| 2603 | if (g_getfacl) {
|
---|
| 2604 | sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
|
---|
| 2605 | }
|
---|
[1] | 2606 |
|
---|
[1236] | 2607 | asprintf(&command, "cp %s/biggielist.txt %s", bkpinfo->tmpdir,
|
---|
[128] | 2608 | biggielist);
|
---|
| 2609 | paranoid_system(command);
|
---|
[1236] | 2610 | paranoid_free(command);
|
---|
| 2611 |
|
---|
| 2612 | asprintf(&blah, "biggielist = %s", biggielist);
|
---|
[128] | 2613 | log_msg(2, blah);
|
---|
[1236] | 2614 | paranoid_free(blah);
|
---|
[128] | 2615 |
|
---|
| 2616 | if (!does_file_exist(biggielist)) {
|
---|
| 2617 | log_msg(1, "BTW, the biggielist does not exist");
|
---|
| 2618 | }
|
---|
| 2619 |
|
---|
[948] | 2620 | if (g_getfattr) {
|
---|
| 2621 | get_fattr_list(biggielist, xattr_fname);
|
---|
[1236] | 2622 | asprintf(&command, "cp %s %s/archives/", xattr_fname,
|
---|
[128] | 2623 | bkpinfo->scratchdir);
|
---|
[948] | 2624 | paranoid_system(command);
|
---|
[1236] | 2625 | paranoid_free(command);
|
---|
[948] | 2626 | }
|
---|
| 2627 | if (g_getfacl) {
|
---|
| 2628 | get_acl_list(biggielist, acl_fname);
|
---|
[1236] | 2629 | asprintf(&command, "cp %s %s/archives/", acl_fname,
|
---|
| 2630 | bkpinfo->scratchdir);
|
---|
[948] | 2631 | paranoid_system(command);
|
---|
[1236] | 2632 | paranoid_free(command);
|
---|
[948] | 2633 | }
|
---|
[128] | 2634 |
|
---|
| 2635 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 2636 | res += write_EXAT_files_to_tape(bkpinfo, xattr_fname, acl_fname);
|
---|
[1236] | 2637 | asprintf(&blah, "%ld", count_lines_in_file(biggielist));
|
---|
[684] | 2638 | write_header_block_to_stream((off_t)0, blah, BLK_START_BIGGIEFILES);
|
---|
[1236] | 2639 | paranoid_free(blah);
|
---|
[128] | 2640 | }
|
---|
| 2641 | res = make_slices_and_images(bkpinfo, biggielist);
|
---|
| 2642 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
[684] | 2643 | write_header_block_to_stream((off_t)0, "end-of-biggiefiles",
|
---|
[128] | 2644 | BLK_STOP_BIGGIEFILES);
|
---|
| 2645 | }
|
---|
| 2646 | retval += res;
|
---|
| 2647 | if (res) {
|
---|
| 2648 | log_msg(1, "make_slices_and_images returned an error");
|
---|
| 2649 | mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
|
---|
| 2650 | } else {
|
---|
| 2651 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
| 2652 | }
|
---|
| 2653 | paranoid_free(blah);
|
---|
| 2654 | paranoid_free(biggielist);
|
---|
| 2655 | paranoid_free(command);
|
---|
| 2656 | paranoid_free(xattr_fname);
|
---|
| 2657 | paranoid_free(acl_fname);
|
---|
| 2658 | return (retval);
|
---|
[1] | 2659 | }
|
---|
| 2660 |
|
---|
| 2661 |
|
---|
| 2662 | /**
|
---|
| 2663 | * @addtogroup LLarchiveGroup
|
---|
| 2664 | * @{
|
---|
| 2665 | */
|
---|
| 2666 | /**
|
---|
| 2667 | * Function pointer to an appropriate @c move_files_to_cd routine.
|
---|
| 2668 | * You can set this to your own function (for example, one to
|
---|
| 2669 | * transfer files over the network) or leave it as is.
|
---|
| 2670 | */
|
---|
[541] | 2671 | int (*move_files_to_cd) (struct s_bkpinfo *, char *, ...) =
|
---|
[128] | 2672 | _move_files_to_cd;
|
---|
[1] | 2673 |
|
---|
| 2674 | /**
|
---|
| 2675 | * Move some files to the ISO scratch directory.
|
---|
| 2676 | * This function moves files specified as parameters, into the directory
|
---|
| 2677 | * @c bkpinfo->scratchdir, where the files that will be stored on the next
|
---|
| 2678 | * CD are waiting.
|
---|
| 2679 | *
|
---|
| 2680 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 2681 | * - @c media_size
|
---|
| 2682 | * - @c scratchdir
|
---|
| 2683 | * @param files_to_add The files to add to the scratchdir.
|
---|
| 2684 | * @warning The list of @c files_to_add must be terminated with @c NULL.
|
---|
| 2685 | * @note If and when the space occupied by the scratchdir would exceed
|
---|
| 2686 | * the capacity of the current CD,
|
---|
| 2687 | * <tt>write_iso_and_go_on(bkpinfo, FALSE)</tt> is called and the
|
---|
| 2688 | * scratchdir is emptied.
|
---|
| 2689 | *
|
---|
| 2690 | * @return The number of errors encountered (0 for success)
|
---|
| 2691 | */
|
---|
[541] | 2692 | int _move_files_to_cd(struct s_bkpinfo *bkpinfo, char *files_to_add, ...)
|
---|
[1] | 2693 | {
|
---|
| 2694 |
|
---|
[128] | 2695 | /*@ int ************************************************************ */
|
---|
| 2696 | int retval = 0;
|
---|
[1] | 2697 | int res = 0;
|
---|
| 2698 |
|
---|
[128] | 2699 | /*@ buffers ******************************************************** */
|
---|
| 2700 | char *tmp, *curr_file, *cf;
|
---|
[1] | 2701 |
|
---|
[128] | 2702 | /*@ long ************************************************************ */
|
---|
| 2703 | va_list ap;
|
---|
| 2704 | long long would_occupy;
|
---|
[1] | 2705 |
|
---|
[128] | 2706 | assert(bkpinfo != NULL);
|
---|
| 2707 | malloc_string(curr_file);
|
---|
| 2708 | tmp = malloc(1200);
|
---|
| 2709 | would_occupy = space_occupied_by_cd(bkpinfo->scratchdir);
|
---|
| 2710 | va_start(ap, files_to_add); // initialize the variable arguments
|
---|
| 2711 | for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) {
|
---|
| 2712 | if (!cf) {
|
---|
| 2713 | continue;
|
---|
| 2714 | }
|
---|
| 2715 | strcpy(curr_file, cf);
|
---|
| 2716 | if (!does_file_exist(curr_file)) {
|
---|
| 2717 | log_msg(1,
|
---|
| 2718 | "Warning - you're trying to add a non-existent file - '%s' to the CD",
|
---|
| 2719 | curr_file);
|
---|
| 2720 | } else {
|
---|
| 2721 | log_msg(8, "Trying to add file %s to CD", curr_file);
|
---|
| 2722 | would_occupy += length_of_file(curr_file) / 1024;
|
---|
| 2723 | }
|
---|
[1] | 2724 | }
|
---|
[128] | 2725 | va_end(ap);
|
---|
[1] | 2726 |
|
---|
[128] | 2727 | if (bkpinfo->media_size[g_current_media_number] <= 0) {
|
---|
| 2728 | fatal_error("move_files_to_cd() - unknown media size");
|
---|
[1] | 2729 | }
|
---|
[128] | 2730 | if (would_occupy / 1024 > bkpinfo->media_size[g_current_media_number]) {
|
---|
[541] | 2731 | res = write_iso_and_go_on(bkpinfo, FALSE); /* FALSE because this is not the last CD we'll write */
|
---|
[128] | 2732 | retval += res;
|
---|
| 2733 | if (res) {
|
---|
| 2734 | log_msg(1, "WARNING - write_iso_and_go_on returned an error");
|
---|
| 2735 | }
|
---|
| 2736 | }
|
---|
[1] | 2737 |
|
---|
[128] | 2738 | va_start(ap, files_to_add); // initialize the variable arguments
|
---|
| 2739 | for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) {
|
---|
| 2740 | if (!cf) {
|
---|
| 2741 | continue;
|
---|
| 2742 | }
|
---|
| 2743 | strcpy(curr_file, cf);
|
---|
[1] | 2744 |
|
---|
[128] | 2745 | sprintf(tmp, "mv -f %s %s/archives/", curr_file,
|
---|
| 2746 | bkpinfo->scratchdir);
|
---|
| 2747 | res = run_program_and_log_output(tmp, 5);
|
---|
| 2748 | retval += res;
|
---|
| 2749 | if (res) {
|
---|
| 2750 | log_msg(1, "(move_files_to_cd) '%s' failed", tmp);
|
---|
| 2751 | } else {
|
---|
| 2752 | log_msg(8, "Moved %s to CD OK", tmp);
|
---|
| 2753 | }
|
---|
| 2754 | // unlink (curr_file);
|
---|
[1] | 2755 | }
|
---|
[128] | 2756 | va_end(ap);
|
---|
| 2757 |
|
---|
| 2758 | if (retval) {
|
---|
| 2759 | log_msg(1,
|
---|
| 2760 | "Warning - errors occurred while I was adding files to CD dir");
|
---|
[1] | 2761 | }
|
---|
[128] | 2762 | paranoid_free(tmp);
|
---|
| 2763 | paranoid_free(curr_file);
|
---|
| 2764 | return (retval);
|
---|
[1] | 2765 | }
|
---|
| 2766 |
|
---|
| 2767 | /* @} - end of LLarchiveGroup */
|
---|
| 2768 |
|
---|
| 2769 |
|
---|
| 2770 |
|
---|
| 2771 |
|
---|
| 2772 |
|
---|
| 2773 |
|
---|
| 2774 |
|
---|
| 2775 |
|
---|
| 2776 | /**
|
---|
| 2777 | * Offer to write boot and data disk images to 3.5" floppy disks.
|
---|
| 2778 | * @param bkpinfo The backup information structure. Only the
|
---|
| 2779 | * @c backup_media_type field is used in this function.
|
---|
| 2780 | * @param imagesdir The directory containing the floppy images (usually
|
---|
[541] | 2781 | * /root/images/mindi).
|
---|
[1] | 2782 | *
|
---|
| 2783 | * @return The number of errors encountered (0 for success)
|
---|
| 2784 | * @see write_image_to_floppy
|
---|
| 2785 | * @see format_disk
|
---|
| 2786 | * @ingroup MLarchiveGroup
|
---|
| 2787 | */
|
---|
[128] | 2788 | int offer_to_write_floppies(struct s_bkpinfo *bkpinfo, char *imagesdir)
|
---|
[1] | 2789 | {
|
---|
[128] | 2790 | /*@ buffer ************************************************************ */
|
---|
| 2791 | char *tmp;
|
---|
[1] | 2792 | char *comment;
|
---|
| 2793 | char *bootdisk_dev;
|
---|
| 2794 | char *datadisk_dev;
|
---|
| 2795 | char *bootdisk_file;
|
---|
| 2796 | char *rootdisk_file;
|
---|
| 2797 |
|
---|
[128] | 2798 | /*@ int *************************************************************** */
|
---|
| 2799 | int i = 0;
|
---|
[1] | 2800 | int res = 0;
|
---|
| 2801 |
|
---|
[128] | 2802 | /*@ bool ************************************************************** */
|
---|
| 2803 | bool format_first;
|
---|
| 2804 | bool root_disk_exists = FALSE;
|
---|
[1] | 2805 |
|
---|
[128] | 2806 | malloc_string(tmp);
|
---|
| 2807 | malloc_string(comment);
|
---|
| 2808 | malloc_string(bootdisk_dev);
|
---|
| 2809 | malloc_string(datadisk_dev);
|
---|
| 2810 | malloc_string(rootdisk_file);
|
---|
| 2811 | malloc_string(bootdisk_file);
|
---|
| 2812 | assert(bkpinfo != NULL);
|
---|
| 2813 | assert_string_is_neither_NULL_nor_zerolength(imagesdir);
|
---|
[1] | 2814 |
|
---|
| 2815 |
|
---|
[128] | 2816 | if (!ask_me_yes_or_no
|
---|
| 2817 | ("Write boot and data disk images to 3.5\" floppy disks?")) {
|
---|
| 2818 | return (0);
|
---|
| 2819 | }
|
---|
| 2820 | if (does_device_exist(DEFAULT_1722MB_DISK)) {
|
---|
[1] | 2821 | #ifdef __FreeBSD__
|
---|
[128] | 2822 | // tell the system that this is a 1.72m floppy
|
---|
| 2823 | system("/usr/sbin/fdcontrol -F 1722 /dev/fd0.1722");
|
---|
[1] | 2824 | #endif
|
---|
[128] | 2825 | strcpy(bootdisk_dev, DEFAULT_1722MB_DISK);
|
---|
| 2826 | } else if (does_device_exist(BACKUP_1722MB_DISK)) {
|
---|
| 2827 | sprintf(bootdisk_dev, "/dev/fd0H1722");
|
---|
| 2828 | } else {
|
---|
| 2829 | log_msg(1, "Warning - can't find a 1.72MB floppy device *sigh*");
|
---|
| 2830 | strcpy(bootdisk_dev, DEFAULT_1722MB_DISK);
|
---|
[1] | 2831 | // return (1);
|
---|
[128] | 2832 | }
|
---|
| 2833 | strcpy(datadisk_dev, "/dev/fd0");
|
---|
| 2834 | if (!does_device_exist(datadisk_dev)) {
|
---|
| 2835 | log_msg(1, "Warning - can't find a 1.44MB floppy device *sigh*");
|
---|
| 2836 | strcpy(datadisk_dev, "/dev/fd0");
|
---|
[1] | 2837 | // return (1);
|
---|
[128] | 2838 | }
|
---|
| 2839 | format_first =
|
---|
| 2840 | ask_me_yes_or_no
|
---|
| 2841 | ("Do you want me to format the disks before I write to them?");
|
---|
[1] | 2842 |
|
---|
| 2843 | /* boot disk */
|
---|
[128] | 2844 | if (ask_me_OK_or_cancel("About to write boot disk")) {
|
---|
| 2845 | log_to_screen("Writing boot floppy");
|
---|
[1] | 2846 | #ifdef __FreeBSD__
|
---|
[128] | 2847 | sprintf(tmp, "%s/mindi-kern.1722.img", imagesdir);
|
---|
| 2848 | if (format_first) {
|
---|
| 2849 | format_disk(bootdisk_dev);
|
---|
| 2850 | }
|
---|
| 2851 | res += write_image_to_floppy(bootdisk_dev, tmp);
|
---|
| 2852 | if (ask_me_OK_or_cancel("About to write 1.44MB mfsroot disk")) {
|
---|
| 2853 | log_to_screen("Writing mfsroot floppy");
|
---|
| 2854 | if (format_first) {
|
---|
| 2855 | format_disk(datadisk_dev);
|
---|
| 2856 | }
|
---|
| 2857 | sprintf(tmp, "%s/mindi-mfsroot.1440.img", imagesdir);
|
---|
| 2858 | write_image_to_floppy(datadisk_dev, tmp);
|
---|
| 2859 | }
|
---|
[1] | 2860 | #else
|
---|
[128] | 2861 | sprintf(bootdisk_file, "%s/mindi-bootroot.1722.img", imagesdir);
|
---|
| 2862 | if (does_file_exist(bootdisk_file)) {
|
---|
| 2863 | if (format_first) {
|
---|
| 2864 | format_disk(bootdisk_dev);
|
---|
| 2865 | }
|
---|
| 2866 | res += write_image_to_floppy(bootdisk_dev, bootdisk_file);
|
---|
| 2867 | } else {
|
---|
| 2868 | sprintf(bootdisk_file, "%s/mindi-boot.1440.img", imagesdir);
|
---|
| 2869 | sprintf(rootdisk_file, "%s/mindi-root.1440.img", imagesdir);
|
---|
| 2870 | root_disk_exists = TRUE;
|
---|
| 2871 | if (!does_file_exist(rootdisk_file)
|
---|
| 2872 | || !does_file_exist(bootdisk_file)) {
|
---|
| 2873 | popup_and_OK
|
---|
| 2874 | ("Cannot write boot/root floppies. Files not found.");
|
---|
| 2875 | log_to_screen
|
---|
| 2876 | ("Failed to find boot/root floppy images. Oh dear.");
|
---|
| 2877 | return (1);
|
---|
| 2878 | }
|
---|
| 2879 | if (format_first) {
|
---|
| 2880 | format_disk(datadisk_dev);
|
---|
| 2881 | }
|
---|
| 2882 | /*
|
---|
| 2883 | sprintf(tmp, "cat %s > %s", bootdisk_file, datadisk_dev);
|
---|
| 2884 | res += run_external_binary_with_percentage_indicator_NEW("Writing boot floppy", tmp);
|
---|
| 2885 | */
|
---|
| 2886 | res += write_image_to_floppy(datadisk_dev, bootdisk_file);
|
---|
| 2887 | if (ask_me_OK_or_cancel("About to write root disk")) {
|
---|
| 2888 | log_to_screen("Writing root floppy");
|
---|
| 2889 | if (format_first) {
|
---|
| 2890 | format_disk(datadisk_dev);
|
---|
| 2891 | }
|
---|
| 2892 | sprintf(tmp, "cat %s > %s", rootdisk_file, datadisk_dev);
|
---|
| 2893 | log_msg(1, "tmp = '%s'", tmp);
|
---|
| 2894 | res +=
|
---|
| 2895 | run_external_binary_with_percentage_indicator_NEW
|
---|
| 2896 | ("Writing root floppy", tmp);
|
---|
[1] | 2897 | // res += write_image_to_floppy (datadisk_dev, rootdisk_file);
|
---|
[128] | 2898 | }
|
---|
| 2899 | }
|
---|
[1] | 2900 | #endif
|
---|
| 2901 | }
|
---|
[128] | 2902 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 2903 | log_to_screen
|
---|
| 2904 | ("FYI, the data disks are stored on tape/CD for your convenience.");
|
---|
| 2905 | return (0);
|
---|
[1] | 2906 | }
|
---|
[128] | 2907 | for (i = 1; i < 99; i++) {
|
---|
| 2908 | sprintf(tmp, "%s/mindi-data-%d.img", imagesdir, i);
|
---|
| 2909 | log_msg(3, tmp);
|
---|
| 2910 | if (!does_file_exist(tmp)) {
|
---|
| 2911 | log_msg(3, "...not found");
|
---|
| 2912 | break;
|
---|
| 2913 | }
|
---|
| 2914 | sprintf(comment, "About to write data disk #%d", i);
|
---|
| 2915 | if (ask_me_OK_or_cancel(comment)) {
|
---|
| 2916 | sprintf(comment, "Writing data disk #%3d", i);
|
---|
| 2917 | log_to_screen(comment);
|
---|
| 2918 | if (format_first) {
|
---|
| 2919 | res += format_disk(datadisk_dev);
|
---|
| 2920 | }
|
---|
| 2921 | res += write_image_to_floppy(datadisk_dev, tmp);
|
---|
| 2922 | }
|
---|
| 2923 | }
|
---|
| 2924 | paranoid_free(tmp);
|
---|
| 2925 | paranoid_free(comment);
|
---|
| 2926 | paranoid_free(bootdisk_dev);
|
---|
| 2927 | paranoid_free(datadisk_dev);
|
---|
| 2928 | return (res);
|
---|
[1] | 2929 | }
|
---|
| 2930 |
|
---|
| 2931 |
|
---|
| 2932 |
|
---|
| 2933 |
|
---|
| 2934 |
|
---|
| 2935 |
|
---|
| 2936 |
|
---|
| 2937 |
|
---|
| 2938 | /**
|
---|
| 2939 | * Wrapper around @c offer_to_write_floppies().
|
---|
| 2940 | * @param bkpinfo The backup information structure. Used only
|
---|
| 2941 | * in the call to @c offer_to_write_floppies().
|
---|
| 2942 | * @return 0 if the boot floppies were found (not necessarily written OK),
|
---|
| 2943 | * 1 otherwise.
|
---|
| 2944 | * @see offer_to_write_floppies
|
---|
| 2945 | * @ingroup MLarchiveGroup
|
---|
| 2946 | */
|
---|
| 2947 |
|
---|
[128] | 2948 | int offer_to_write_boot_floppies_to_physical_disks(struct s_bkpinfo
|
---|
| 2949 | *bkpinfo)
|
---|
[1] | 2950 | {
|
---|
[128] | 2951 | int res = 0;
|
---|
[1] | 2952 |
|
---|
[128] | 2953 | assert(bkpinfo != NULL);
|
---|
[1] | 2954 |
|
---|
[128] | 2955 | mvaddstr_and_log_it(g_currentY, 0,
|
---|
| 2956 | "Writing boot+data floppy images to disk");
|
---|
[1] | 2957 |
|
---|
[128] | 2958 | if (!bkpinfo->nonbootable_backup) {
|
---|
[1] | 2959 | #ifdef __FreeBSD__
|
---|
[541] | 2960 | if (!does_file_exist("/root/images/mindi/mindi-kern.1722.img"))
|
---|
[1] | 2961 | #else
|
---|
[541] | 2962 | if (!does_file_exist("/root/images/mindi/mindi-bootroot.1722.img")
|
---|
| 2963 | && !does_file_exist("/root/images/mindi/mindi-boot.1440.img"))
|
---|
[1] | 2964 | #endif
|
---|
[128] | 2965 | {
|
---|
| 2966 | mvaddstr_and_log_it(g_currentY++, 74, "No Imgs");
|
---|
[541] | 2967 | if (does_file_exist("/root/images/mindi/mondorescue.iso")) {
|
---|
[128] | 2968 | popup_and_OK
|
---|
[541] | 2969 | ("Boot+data floppy creation failed. However, FYI, you may burn /root/images/mindi/mondorescue.iso to a CD and boot from that instead if you wish.");
|
---|
[128] | 2970 | res++;
|
---|
| 2971 | }
|
---|
| 2972 | } else {
|
---|
[541] | 2973 | offer_to_write_floppies(bkpinfo, "/root/images/mindi");
|
---|
[128] | 2974 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
| 2975 | }
|
---|
| 2976 | } else {
|
---|
| 2977 | popup_and_OK
|
---|
| 2978 | ("Since you opted for a nonbootable backup, no boot floppies were created.");
|
---|
| 2979 | }
|
---|
| 2980 |
|
---|
| 2981 | return (res);
|
---|
[1] | 2982 | }
|
---|
| 2983 |
|
---|
| 2984 |
|
---|
| 2985 |
|
---|
| 2986 |
|
---|
| 2987 | /**
|
---|
| 2988 | * @addtogroup LLarchiveGroup
|
---|
| 2989 | * @{
|
---|
| 2990 | */
|
---|
| 2991 | /**
|
---|
| 2992 | * Function pointer to an appropriate @c move_files_to_stream routine.
|
---|
| 2993 | * You can set this to your own function (for example, one to
|
---|
| 2994 | * transfer files over the network) or leave it as is.
|
---|
| 2995 | */
|
---|
[128] | 2996 | int (*move_files_to_stream) (struct s_bkpinfo *, char *, ...) =
|
---|
| 2997 | _move_files_to_stream;
|
---|
[1] | 2998 |
|
---|
| 2999 | /**
|
---|
| 3000 | * Copy some files to tape.
|
---|
| 3001 | * This function copies the files specified as parameters into the tape stream.
|
---|
| 3002 | *
|
---|
| 3003 | * @param bkpinfo The backup information structure. Used only in the call to
|
---|
| 3004 | * @c write_file_to_stream_from_file().
|
---|
| 3005 | *
|
---|
| 3006 | * @param files_to_add The files to copy to the tape stream.
|
---|
| 3007 | * @warning The list of @c files_to_add must be terminated with @c NULL.
|
---|
| 3008 | * @note Files may be split across multiple tapes if necessary.
|
---|
| 3009 | *
|
---|
| 3010 | * @return The number of errors encountered (0 for success)
|
---|
| 3011 | */
|
---|
| 3012 | int
|
---|
[128] | 3013 | _move_files_to_stream(struct s_bkpinfo *bkpinfo, char *files_to_add, ...)
|
---|
[1] | 3014 | {
|
---|
| 3015 |
|
---|
[128] | 3016 | /*@ int ************************************************************ */
|
---|
| 3017 | int retval = 0;
|
---|
[1] | 3018 | int res = 0;
|
---|
[128] | 3019 | /*@ buffers ******************************************************** */
|
---|
[1] | 3020 |
|
---|
[128] | 3021 | /*@ char *********************************************************** */
|
---|
[1] | 3022 | char start_chr;
|
---|
| 3023 | char stop_chr;
|
---|
[128] | 3024 | char *curr_file, *cf;
|
---|
| 3025 | /*@ long long ****************************************************** */
|
---|
[684] | 3026 | off_t length_of_incoming_file = (off_t)0;
|
---|
[128] | 3027 | t_archtype type;
|
---|
| 3028 | va_list ap;
|
---|
[1] | 3029 |
|
---|
[128] | 3030 | assert(bkpinfo != NULL);
|
---|
| 3031 | malloc_string(curr_file);
|
---|
| 3032 | va_start(ap, files_to_add);
|
---|
| 3033 | for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) {
|
---|
| 3034 | if (!cf) {
|
---|
| 3035 | continue;
|
---|
| 3036 | }
|
---|
| 3037 | strcpy(curr_file, cf);
|
---|
| 3038 | if (!does_file_exist(curr_file)) {
|
---|
| 3039 | log_msg(1,
|
---|
| 3040 | "Warning - you're trying to add a non-existent file - '%s' to the tape",
|
---|
| 3041 | curr_file);
|
---|
| 3042 | }
|
---|
[1] | 3043 | /* create header chars */
|
---|
[128] | 3044 | start_chr = BLK_START_AN_AFIO_OR_SLICE;
|
---|
| 3045 | stop_chr = BLK_STOP_AN_AFIO_OR_SLICE;
|
---|
[1] | 3046 | /* ask for new tape if necessary */
|
---|
[128] | 3047 | length_of_incoming_file = length_of_file(curr_file);
|
---|
| 3048 | write_header_block_to_stream(length_of_incoming_file, curr_file,
|
---|
| 3049 | start_chr);
|
---|
| 3050 | if (strstr(curr_file, ".afio.") || strstr(curr_file, ".star.")) {
|
---|
| 3051 | type = fileset;
|
---|
| 3052 | } else if (strstr(curr_file, "slice")) {
|
---|
| 3053 | type = biggieslice;
|
---|
| 3054 | } else {
|
---|
| 3055 | type = other;
|
---|
| 3056 | }
|
---|
| 3057 | res = write_file_to_stream_from_file(bkpinfo, curr_file);
|
---|
| 3058 | retval += res;
|
---|
| 3059 | unlink(curr_file);
|
---|
[1] | 3060 | /* write closing header */
|
---|
[684] | 3061 | write_header_block_to_stream((off_t)0, "finished-writing-file", stop_chr);
|
---|
[128] | 3062 | }
|
---|
| 3063 | va_end(ap);
|
---|
[1] | 3064 |
|
---|
[128] | 3065 | if (retval) {
|
---|
| 3066 | log_msg(1,
|
---|
| 3067 | "Warning - errors occurred while I was adding file to tape");
|
---|
| 3068 | }
|
---|
| 3069 | paranoid_free(curr_file);
|
---|
| 3070 | return (retval);
|
---|
[1] | 3071 | }
|
---|
| 3072 |
|
---|
| 3073 | /* @} - end of LLarchiveGroup */
|
---|
| 3074 |
|
---|
| 3075 |
|
---|
| 3076 |
|
---|
| 3077 | /**
|
---|
| 3078 | * @addtogroup utilityGroup
|
---|
| 3079 | * @{
|
---|
| 3080 | */
|
---|
| 3081 | /**
|
---|
| 3082 | * Make sure the user has a valid CD-R(W) in the CD drive.
|
---|
| 3083 | * @param cdrw_dev Set to the CD-R(W) device checked.
|
---|
| 3084 | * @param keep_looping If TRUE, keep pestering user until they insist
|
---|
| 3085 | * or insert a correct CD; if FALSE, only check once.
|
---|
| 3086 | * @return 0 (there was an OK CD in the drive) or 1 (there wasn't).
|
---|
| 3087 | */
|
---|
[128] | 3088 | int interrogate_disk_currently_in_cdrw_drive(char *cdrw_dev,
|
---|
| 3089 | bool keep_looping)
|
---|
[1] | 3090 | {
|
---|
[128] | 3091 | char *tmp;
|
---|
| 3092 | int res = 0;
|
---|
| 3093 | char *bkp;
|
---|
| 3094 | char *cdrecord;
|
---|
[1] | 3095 |
|
---|
[128] | 3096 | malloc_string(tmp);
|
---|
| 3097 | malloc_string(bkp);
|
---|
| 3098 | malloc_string(cdrecord);
|
---|
| 3099 | strcpy(bkp, cdrw_dev);
|
---|
| 3100 | if (find_cdrw_device(cdrw_dev)) {
|
---|
| 3101 | strcpy(cdrw_dev, bkp);
|
---|
| 3102 | } else {
|
---|
| 3103 | if (!system("which cdrecord > /dev/null 2> /dev/null")) {
|
---|
| 3104 | sprintf(cdrecord, "cdrecord dev=%s -atip", cdrw_dev);
|
---|
| 3105 | } else if (!system("which dvdrecord > /dev/null 2> /dev/null")) {
|
---|
| 3106 | sprintf(cdrecord, "cdrecord dev=%s -atip", cdrw_dev);
|
---|
| 3107 | } else {
|
---|
| 3108 | cdrecord[0] = '\0';
|
---|
| 3109 | log_msg(2, "Oh well. I guess I'll just pray then.");
|
---|
| 3110 | }
|
---|
| 3111 | if (cdrecord[0]) {
|
---|
| 3112 | if (!keep_looping) {
|
---|
| 3113 | retract_CD_tray_and_defeat_autorun();
|
---|
| 3114 | res = run_program_and_log_output(cdrecord, 5);
|
---|
| 3115 | } else {
|
---|
| 3116 | while ((res = run_program_and_log_output(cdrecord, 5))) {
|
---|
| 3117 | retract_CD_tray_and_defeat_autorun();
|
---|
| 3118 | if (ask_me_yes_or_no
|
---|
| 3119 | ("Unable to examine CD. Are you sure this is a valid CD-R(W) CD?"))
|
---|
| 3120 | {
|
---|
| 3121 | log_msg(1, "Well, he insisted...");
|
---|
| 3122 | break;
|
---|
| 3123 | }
|
---|
| 3124 | }
|
---|
| 3125 | }
|
---|
| 3126 | }
|
---|
| 3127 | }
|
---|
[1] | 3128 | // retract_CD_tray_and_defeat_autorun();
|
---|
[128] | 3129 | paranoid_free(tmp);
|
---|
| 3130 | paranoid_free(cdrecord);
|
---|
| 3131 | paranoid_free(bkp);
|
---|
| 3132 | return (res);
|
---|
[1] | 3133 | }
|
---|
| 3134 |
|
---|
| 3135 |
|
---|
| 3136 |
|
---|
| 3137 |
|
---|
| 3138 |
|
---|
| 3139 |
|
---|
| 3140 |
|
---|
| 3141 |
|
---|
| 3142 |
|
---|
| 3143 | /**
|
---|
| 3144 | * Asks the user to put a CD-R(W) in the drive.
|
---|
| 3145 | * @param ask_for_one_if_more_than_this (unused)
|
---|
| 3146 | * @param pmountable If non-NULL, pointed-to value is set to TRUE if the CD is mountable, FALSE otherwise.
|
---|
| 3147 | */
|
---|
| 3148 | void
|
---|
[128] | 3149 | pause_and_ask_for_cdr(int ask_for_one_if_more_than_this, bool * pmountable)
|
---|
[1] | 3150 | {
|
---|
| 3151 |
|
---|
[128] | 3152 | /*@ buffers ********************************************* */
|
---|
| 3153 | char *tmp;
|
---|
| 3154 | char *szmsg;
|
---|
| 3155 | char *cdrom_dev;
|
---|
| 3156 | char *cdrw_dev;
|
---|
| 3157 | char *our_serial_str;
|
---|
| 3158 | bool ok_go_ahead_burn_it;
|
---|
| 3159 | int cd_number = -1;
|
---|
| 3160 | int attempt_to_mount_returned_this = 999;
|
---|
| 3161 | char *mtpt;
|
---|
| 3162 | char *szcdno;
|
---|
| 3163 | char *szserfname;
|
---|
| 3164 | char *szunmount;
|
---|
[1] | 3165 |
|
---|
[128] | 3166 | malloc_string(tmp);
|
---|
| 3167 | malloc_string(szmsg);
|
---|
| 3168 | malloc_string(cdrom_dev);
|
---|
| 3169 | malloc_string(cdrw_dev);
|
---|
| 3170 | malloc_string(mtpt);
|
---|
| 3171 | malloc_string(szcdno);
|
---|
| 3172 | malloc_string(szserfname);
|
---|
| 3173 | malloc_string(our_serial_str);
|
---|
| 3174 | malloc_string(szunmount);
|
---|
[1] | 3175 |
|
---|
[128] | 3176 | sprintf(szmsg, "I am about to burn %s #%d",
|
---|
| 3177 | media_descriptor_string(g_backup_media_type),
|
---|
| 3178 | g_current_media_number);
|
---|
| 3179 | log_to_screen(szmsg);
|
---|
| 3180 | if (g_current_media_number < ask_for_one_if_more_than_this) {
|
---|
| 3181 | return;
|
---|
| 3182 | }
|
---|
| 3183 | log_to_screen("Scanning CD-ROM drive...");
|
---|
| 3184 | sprintf(mtpt, "/tmp/cd.mtpt.%ld.%ld", (long int) random(),
|
---|
| 3185 | (long int) random());
|
---|
| 3186 | make_hole_for_dir(mtpt);
|
---|
[1] | 3187 |
|
---|
[128] | 3188 | gotos_make_me_puke:
|
---|
| 3189 | ok_go_ahead_burn_it = TRUE;
|
---|
| 3190 | if (!find_cdrom_device(cdrom_dev, FALSE)) {
|
---|
[1] | 3191 | /* When enabled, it made CD eject-and-retract when wrong CD inserted.. Weird
|
---|
| 3192 | log_msg(2, "paafcd: Retracting CD-ROM drive if possible" );
|
---|
| 3193 | retract_CD_tray_and_defeat_autorun();
|
---|
| 3194 | */
|
---|
[128] | 3195 | sprintf(tmp, "umount %s", cdrom_dev);
|
---|
| 3196 | run_program_and_log_output(tmp, 1);
|
---|
| 3197 | sprintf(szcdno, "%s/archives/THIS-CD-NUMBER", mtpt);
|
---|
| 3198 | sprintf(szserfname, "%s/archives/SERIAL-STRING", mtpt);
|
---|
| 3199 | sprintf(szunmount, "umount %s", mtpt);
|
---|
| 3200 | cd_number = -1;
|
---|
| 3201 | our_serial_str[0] = '\0';
|
---|
| 3202 | sprintf(tmp, "mount %s %s", cdrom_dev, mtpt);
|
---|
| 3203 | if ((attempt_to_mount_returned_this =
|
---|
| 3204 | run_program_and_log_output(tmp, 1))) {
|
---|
| 3205 | log_msg(4, "Failed to mount %s at %s", cdrom_dev, mtpt);
|
---|
| 3206 | log_to_screen("If there's a CD/DVD in the drive, it's blank.");
|
---|
| 3207 | /*
|
---|
| 3208 | if (interrogate_disk_currently_in_cdrw_drive(cdrw_dev, FALSE))
|
---|
| 3209 | {
|
---|
| 3210 | ok_go_ahead_burn_it = FALSE;
|
---|
| 3211 | log_to_screen("There isn't a writable CD/DVD in the drive.");
|
---|
| 3212 | }
|
---|
| 3213 | else
|
---|
| 3214 | {
|
---|
| 3215 | log_to_screen("Confirmed. There is a blank CD/DVD in the drive.");
|
---|
| 3216 | }
|
---|
| 3217 | */
|
---|
| 3218 | } else if (!does_file_exist(szcdno)
|
---|
| 3219 | || !does_file_exist(szserfname)) {
|
---|
| 3220 | log_to_screen
|
---|
| 3221 | ("%s has data on it but it's probably not a Mondo CD.",
|
---|
| 3222 | media_descriptor_string(g_backup_media_type));
|
---|
| 3223 | } else {
|
---|
| 3224 | log_to_screen("%s found in drive. It's a Mondo disk.",
|
---|
| 3225 | media_descriptor_string(g_backup_media_type));
|
---|
| 3226 | cd_number = atoi(last_line_of_file(szcdno));
|
---|
| 3227 | sprintf(tmp, "cat %s 2> /dev/null", szserfname);
|
---|
| 3228 | strcpy(our_serial_str,
|
---|
| 3229 | call_program_and_get_last_line_of_output(tmp));
|
---|
| 3230 | // FIXME - should be able to use last_line_of_file(), surely?
|
---|
| 3231 | }
|
---|
| 3232 | run_program_and_log_output(szunmount, 1);
|
---|
| 3233 | log_msg(2, "paafcd: cd_number = %d", cd_number);
|
---|
| 3234 | log_msg(2, "our serial str = %s; g_serial_string = %s",
|
---|
| 3235 | our_serial_str, g_serial_string);
|
---|
| 3236 | if (cd_number > 0 && !strcmp(our_serial_str, g_serial_string)) {
|
---|
| 3237 | log_msg(2, "This %s is part of this backup set!",
|
---|
| 3238 | media_descriptor_string(g_backup_media_type));
|
---|
| 3239 | ok_go_ahead_burn_it = FALSE;
|
---|
| 3240 | if (cd_number == g_current_media_number - 1) {
|
---|
| 3241 | log_to_screen
|
---|
| 3242 | ("I think you've left the previous %s in the drive.",
|
---|
| 3243 | media_descriptor_string(g_backup_media_type));
|
---|
| 3244 | } else {
|
---|
| 3245 | log_to_screen
|
---|
| 3246 | ("Please remove this %s. It is part of the backup set you're making now.",
|
---|
| 3247 | media_descriptor_string(g_backup_media_type));
|
---|
| 3248 | }
|
---|
| 3249 | } else {
|
---|
| 3250 | log_to_screen("...but not part of _our_ backup set.");
|
---|
| 3251 | }
|
---|
| 3252 | } else {
|
---|
| 3253 | log_msg(2,
|
---|
| 3254 | "paafcd: Can't find CD-ROM drive. Perhaps it has a blank %s in it?",
|
---|
| 3255 | media_descriptor_string(g_backup_media_type));
|
---|
| 3256 | if (interrogate_disk_currently_in_cdrw_drive(cdrw_dev, FALSE)) {
|
---|
| 3257 | ok_go_ahead_burn_it = FALSE;
|
---|
| 3258 | log_to_screen("There isn't a writable %s in the drive.",
|
---|
| 3259 | media_descriptor_string(g_backup_media_type));
|
---|
| 3260 | }
|
---|
[1] | 3261 | }
|
---|
| 3262 |
|
---|
| 3263 | /*
|
---|
| 3264 | if (g_current_media_number > ask_for_one_if_more_than_this)
|
---|
| 3265 | {
|
---|
| 3266 | ok_go_ahead_burn_it = FALSE;
|
---|
| 3267 | log_it("paafcd: %d > %d, so I'll definitely pause.", g_current_media_number > ask_for_one_if_more_than_this);
|
---|
| 3268 | }
|
---|
| 3269 | */
|
---|
| 3270 |
|
---|
[128] | 3271 | if (!ok_go_ahead_burn_it) {
|
---|
| 3272 | eject_device(cdrom_dev);
|
---|
| 3273 | sprintf(tmp,
|
---|
| 3274 | "I am about to burn %s #%d of the backup set. Please insert %s and press Enter.",
|
---|
| 3275 | media_descriptor_string(g_backup_media_type),
|
---|
| 3276 | g_current_media_number,
|
---|
| 3277 | media_descriptor_string(g_backup_media_type));
|
---|
| 3278 | popup_and_OK(tmp);
|
---|
| 3279 | goto gotos_make_me_puke;
|
---|
| 3280 | } else {
|
---|
| 3281 | log_msg(2, "paafcd: OK, going ahead and burning it.");
|
---|
| 3282 | }
|
---|
[1] | 3283 |
|
---|
[128] | 3284 | log_msg(2,
|
---|
| 3285 | "paafcd: OK, I assume I have a blank/reusable %s in the drive...",
|
---|
| 3286 | media_descriptor_string(g_backup_media_type));
|
---|
[1] | 3287 |
|
---|
[128] | 3288 | // if (ask_for_one_if_more_than_this>1) { popup_and_OK(szmsg); }
|
---|
[1] | 3289 |
|
---|
[128] | 3290 | log_to_screen("Proceeding w/ %s in drive.",
|
---|
| 3291 | media_descriptor_string(g_backup_media_type));
|
---|
| 3292 | paranoid_free(tmp);
|
---|
| 3293 | paranoid_free(szmsg);
|
---|
| 3294 | paranoid_free(cdrom_dev);
|
---|
| 3295 | paranoid_free(cdrw_dev);
|
---|
| 3296 | paranoid_free(mtpt);
|
---|
| 3297 | paranoid_free(szcdno);
|
---|
| 3298 | paranoid_free(szserfname);
|
---|
| 3299 | paranoid_free(our_serial_str);
|
---|
| 3300 | paranoid_free(szunmount);
|
---|
| 3301 | if (pmountable) {
|
---|
| 3302 | if (attempt_to_mount_returned_this) {
|
---|
| 3303 | *pmountable = FALSE;
|
---|
| 3304 | } else {
|
---|
| 3305 | *pmountable = TRUE;
|
---|
| 3306 | }
|
---|
| 3307 | }
|
---|
[1] | 3308 |
|
---|
| 3309 | }
|
---|
| 3310 |
|
---|
| 3311 |
|
---|
| 3312 |
|
---|
| 3313 |
|
---|
| 3314 |
|
---|
| 3315 |
|
---|
| 3316 |
|
---|
| 3317 |
|
---|
| 3318 | /**
|
---|
| 3319 | * Set the <tt>N</tt>th bit of @c array to @c true_or_false.
|
---|
| 3320 | * @param array The bit array (as a @c char pointer).
|
---|
| 3321 | * @param N The bit number to set or reset.
|
---|
| 3322 | * @param true_or_false If TRUE then set bit @c N, if FALSE then reset bit @c N.
|
---|
| 3323 | * @see get_bit_N_of_array
|
---|
| 3324 | */
|
---|
[128] | 3325 | void set_bit_N_of_array(char *array, int N, bool true_or_false)
|
---|
[1] | 3326 | {
|
---|
[128] | 3327 | int bit_number;
|
---|
| 3328 | int mask, orig_val, to_add;
|
---|
| 3329 | int element_number;
|
---|
[1] | 3330 |
|
---|
[128] | 3331 | assert(array != NULL);
|
---|
[1] | 3332 |
|
---|
[128] | 3333 | element_number = N / 8;
|
---|
| 3334 | bit_number = N % 8;
|
---|
| 3335 | to_add = (1 << bit_number);
|
---|
| 3336 | mask = 255 - to_add;
|
---|
| 3337 | orig_val = array[element_number] & mask;
|
---|
| 3338 | // log_it("array[%d]=%02x; %02x&%02x = %02x", element_number, array[element_number], mask, orig_val);
|
---|
| 3339 | if (true_or_false) {
|
---|
| 3340 | array[element_number] = orig_val | to_add;
|
---|
| 3341 | }
|
---|
[1] | 3342 | }
|
---|
| 3343 |
|
---|
| 3344 | /* @} - end of utilityGroup */
|
---|
| 3345 |
|
---|
| 3346 |
|
---|
| 3347 |
|
---|
| 3348 |
|
---|
| 3349 |
|
---|
| 3350 |
|
---|
| 3351 |
|
---|
| 3352 |
|
---|
| 3353 | /**
|
---|
| 3354 | * Chop up @c filename.
|
---|
| 3355 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 3356 | * - @c backup_media_type
|
---|
| 3357 | * - @c compression_level
|
---|
| 3358 | * - @c optimal_set_size
|
---|
| 3359 | * - @c tmpdir
|
---|
| 3360 | * - @c use_lzo
|
---|
| 3361 | * - @c zip_exe
|
---|
| 3362 | * - @c zip_suffix
|
---|
| 3363 | *
|
---|
| 3364 | * @param biggie_filename The file to chop up.
|
---|
[296] | 3365 | * @param ntfsprog_fifo The FIFO to ntfsclone if this is an imagedev, NULL otherwise.
|
---|
[1] | 3366 | * @param biggie_file_number The sequence number of this biggie file (starting from 0).
|
---|
| 3367 | * @param noof_biggie_files The number of biggie files there are total.
|
---|
| 3368 | * @return The number of errors encountered (0 for success)
|
---|
| 3369 | * @see make_slices_and_images
|
---|
| 3370 | * @ingroup LLarchiveGroup
|
---|
| 3371 | */
|
---|
| 3372 | int
|
---|
[541] | 3373 | slice_up_file_etc(struct s_bkpinfo *bkpinfo, char *biggie_filename,
|
---|
[296] | 3374 | char *ntfsprog_fifo, long biggie_file_number,
|
---|
| 3375 | long noof_biggie_files, bool use_ntfsprog)
|
---|
[1] | 3376 | {
|
---|
| 3377 |
|
---|
[128] | 3378 | /*@ buffers ************************************************** */
|
---|
| 3379 | char *tmp, *checksum_line, *command;
|
---|
| 3380 | char *tempblock;
|
---|
| 3381 | char *curr_slice_fname_uncompressed;
|
---|
| 3382 | char *curr_slice_fname_compressed;
|
---|
| 3383 | char *file_to_archive;
|
---|
| 3384 | char *file_to_openin;
|
---|
| 3385 | /*@ pointers ************************************************** */
|
---|
| 3386 | char *pB;
|
---|
| 3387 | FILE *fin, *fout;
|
---|
[1] | 3388 |
|
---|
[128] | 3389 | /*@ bool ****************************************************** */
|
---|
| 3390 | bool finished = FALSE;
|
---|
[1] | 3391 |
|
---|
[128] | 3392 | /*@ long ****************************************************** */
|
---|
| 3393 | size_t blksize = 0;
|
---|
| 3394 | long slice_num = 0;
|
---|
| 3395 | long i;
|
---|
| 3396 | long optimal_set_size;
|
---|
| 3397 | bool should_I_compress_slices;
|
---|
| 3398 | char *suffix; // for compressed slices
|
---|
[1] | 3399 |
|
---|
[128] | 3400 | /*@ long long ************************************************** */
|
---|
[684] | 3401 | off_t totalread = (off_t)0;
|
---|
| 3402 | off_t totallength = (off_t)0;
|
---|
| 3403 | off_t length;
|
---|
[1] | 3404 |
|
---|
[128] | 3405 | /*@ int ******************************************************** */
|
---|
| 3406 | int retval = 0;
|
---|
| 3407 | int res = 0;
|
---|
[1] | 3408 |
|
---|
[128] | 3409 | /*@ structures ************************************************** */
|
---|
| 3410 | struct s_filename_and_lstat_info biggiestruct;
|
---|
[1] | 3411 | // struct stat statbuf;
|
---|
| 3412 |
|
---|
[128] | 3413 | assert(bkpinfo != NULL);
|
---|
| 3414 | assert_string_is_neither_NULL_nor_zerolength(biggie_filename);
|
---|
| 3415 | malloc_string(tmp);
|
---|
| 3416 | malloc_string(checksum_line);
|
---|
| 3417 | malloc_string(curr_slice_fname_uncompressed);
|
---|
| 3418 | malloc_string(curr_slice_fname_compressed);
|
---|
| 3419 | malloc_string(file_to_archive);
|
---|
| 3420 | malloc_string(suffix);
|
---|
| 3421 | command = malloc(MAX_STR_LEN * 8);
|
---|
[1] | 3422 |
|
---|
[128] | 3423 | biggiestruct.for_backward_compatibility = '\n';
|
---|
[296] | 3424 | biggiestruct.use_ntfsprog = use_ntfsprog;
|
---|
[128] | 3425 | if (!(tempblock = (char *) malloc(256 * 1024))) {
|
---|
| 3426 | fatal_error("malloc error 256*1024");
|
---|
| 3427 | }
|
---|
| 3428 | optimal_set_size = bkpinfo->optimal_set_size;
|
---|
| 3429 | if (is_this_file_compressed(biggie_filename)
|
---|
| 3430 | || bkpinfo->compression_level == 0) {
|
---|
| 3431 | suffix[0] = '\0';
|
---|
| 3432 | // log_it("%s is indeed compressed :-)", filename);
|
---|
| 3433 | should_I_compress_slices = FALSE;
|
---|
| 3434 | } else {
|
---|
| 3435 | strcpy(suffix, bkpinfo->zip_suffix);
|
---|
| 3436 | should_I_compress_slices = TRUE;
|
---|
| 3437 | }
|
---|
[1] | 3438 |
|
---|
[128] | 3439 | if (optimal_set_size < 999) {
|
---|
| 3440 | fatal_error("bkpinfo->optimal_set_size is insanely small");
|
---|
| 3441 | }
|
---|
[296] | 3442 | if (ntfsprog_fifo) {
|
---|
| 3443 | file_to_openin = ntfsprog_fifo;
|
---|
[128] | 3444 | strcpy(checksum_line, "IGNORE");
|
---|
| 3445 | log_msg(2,
|
---|
| 3446 | "Not calculating checksum for %s: it would take too long",
|
---|
| 3447 | biggie_filename);
|
---|
[296] | 3448 | if ( !find_home_of_exe("ntfsresize")) {
|
---|
| 3449 | fatal_error("ntfsresize not found");
|
---|
| 3450 | }
|
---|
| 3451 | sprintf(command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", biggie_filename);
|
---|
| 3452 | log_it("command = %s", command);
|
---|
| 3453 | strcpy (tmp, call_program_and_get_last_line_of_output(command));
|
---|
| 3454 | log_it("res of it = %s", tmp);
|
---|
[684] | 3455 | totallength = (off_t)atoll(tmp);
|
---|
[128] | 3456 | } else {
|
---|
| 3457 | file_to_openin = biggie_filename;
|
---|
[693] | 3458 | if (strchr(biggie_filename,'\'') != NULL) {
|
---|
| 3459 | sprintf(command, "md5sum \"%s\"", biggie_filename);
|
---|
| 3460 | } else {
|
---|
| 3461 | sprintf(command, "md5sum '%s'", biggie_filename);
|
---|
| 3462 | }
|
---|
[128] | 3463 | if (!(fin = popen(command, "r"))) {
|
---|
| 3464 | log_OS_error("Unable to popen-in command");
|
---|
| 3465 | return (1);
|
---|
| 3466 | }
|
---|
| 3467 | (void) fgets(checksum_line, MAX_STR_LEN, fin);
|
---|
| 3468 | pclose(fin);
|
---|
[167] | 3469 | totallength = length_of_file (biggie_filename);
|
---|
[128] | 3470 | }
|
---|
| 3471 | lstat(biggie_filename, &biggiestruct.properties);
|
---|
| 3472 | strcpy(biggiestruct.filename, biggie_filename);
|
---|
| 3473 | pB = strchr(checksum_line, ' ');
|
---|
| 3474 | if (!pB) {
|
---|
| 3475 | pB = strchr(checksum_line, '\t');
|
---|
| 3476 | }
|
---|
| 3477 | if (pB) {
|
---|
| 3478 | *pB = '\0';
|
---|
| 3479 | }
|
---|
| 3480 | strcpy(biggiestruct.checksum, checksum_line);
|
---|
[1] | 3481 |
|
---|
[128] | 3482 | strcpy(tmp, slice_fname(biggie_file_number, 0, bkpinfo->tmpdir, ""));
|
---|
| 3483 | fout = fopen(tmp, "w");
|
---|
[1236] | 3484 | if (fout == NULL) {
|
---|
[1261] | 3485 | log_msg(1, "Unable to open and write to %s\n", tmp);
|
---|
[1236] | 3486 | paranoid_free(tmp);
|
---|
| 3487 | paranoid_free(suffix);
|
---|
| 3488 | return (1);
|
---|
| 3489 | }
|
---|
| 3490 |
|
---|
[128] | 3491 | (void) fwrite((void *) &biggiestruct, 1, sizeof(biggiestruct), fout);
|
---|
[1274] | 3492 | fclose(fout);
|
---|
[128] | 3493 | length = totallength / optimal_set_size / 1024;
|
---|
| 3494 | log_msg(1, "Opening in %s; slicing it and writing to CD/tape",
|
---|
| 3495 | file_to_openin);
|
---|
| 3496 | if (!(fin = fopen(file_to_openin, "r"))) {
|
---|
| 3497 | log_OS_error("Unable to openin biggie_filename");
|
---|
| 3498 | sprintf(tmp, "Cannot archive bigfile '%s': not found",
|
---|
| 3499 | biggie_filename);
|
---|
| 3500 | log_to_screen(tmp);
|
---|
| 3501 | paranoid_free(tempblock);
|
---|
| 3502 | paranoid_free(tmp);
|
---|
| 3503 | paranoid_free(checksum_line);
|
---|
| 3504 | paranoid_free(command);
|
---|
| 3505 | return (1);
|
---|
| 3506 | }
|
---|
| 3507 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 3508 | res =
|
---|
| 3509 | move_files_to_stream(bkpinfo,
|
---|
| 3510 | slice_fname(biggie_file_number, 0,
|
---|
| 3511 | bkpinfo->tmpdir, ""), NULL);
|
---|
| 3512 | } else {
|
---|
| 3513 | res =
|
---|
[541] | 3514 | move_files_to_cd(bkpinfo,
|
---|
[128] | 3515 | slice_fname(biggie_file_number, 0,
|
---|
| 3516 | bkpinfo->tmpdir, ""), NULL);
|
---|
| 3517 | }
|
---|
| 3518 | i = bkpinfo->optimal_set_size / 256;
|
---|
| 3519 | for (slice_num = 1; !finished; slice_num++) {
|
---|
| 3520 | strcpy(curr_slice_fname_uncompressed,
|
---|
| 3521 | slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir,
|
---|
| 3522 | ""));
|
---|
| 3523 | strcpy(curr_slice_fname_compressed,
|
---|
| 3524 | slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir,
|
---|
| 3525 | suffix));
|
---|
[1] | 3526 |
|
---|
[128] | 3527 | strcpy(tmp, percent_media_full_comment(bkpinfo));
|
---|
| 3528 | update_progress_form(tmp);
|
---|
| 3529 | if (!(fout = fopen(curr_slice_fname_uncompressed, "w"))) {
|
---|
| 3530 | log_OS_error(curr_slice_fname_uncompressed);
|
---|
| 3531 | return (1);
|
---|
[1] | 3532 | }
|
---|
[128] | 3533 | if ((i == bkpinfo->optimal_set_size / 256)
|
---|
| 3534 | && (totalread < 1.1 * totallength)) {
|
---|
| 3535 | for (i = 0; i < bkpinfo->optimal_set_size / 256; i++) {
|
---|
| 3536 | blksize = fread(tempblock, 1, 256 * 1024, fin);
|
---|
| 3537 | if (blksize > 0) {
|
---|
| 3538 | totalread = totalread + blksize;
|
---|
| 3539 | (void) fwrite(tempblock, 1, blksize, fout);
|
---|
| 3540 | } else {
|
---|
| 3541 | break;
|
---|
| 3542 | }
|
---|
| 3543 | }
|
---|
| 3544 | } else {
|
---|
| 3545 | i = 0;
|
---|
| 3546 | }
|
---|
| 3547 | paranoid_fclose(fout);
|
---|
| 3548 | if (i > 0) // length_of_file (curr_slice_fname_uncompressed)
|
---|
[1] | 3549 | {
|
---|
[128] | 3550 | if (!does_file_exist(curr_slice_fname_uncompressed)) {
|
---|
| 3551 | log_msg(2,
|
---|
| 3552 | "Warning - '%s' doesn't exist. How can I compress slice?",
|
---|
| 3553 | curr_slice_fname_uncompressed);
|
---|
| 3554 | }
|
---|
| 3555 | if (should_I_compress_slices && bkpinfo->compression_level > 0) {
|
---|
| 3556 | sprintf(command, "%s -%d %s", bkpinfo->zip_exe,
|
---|
| 3557 | bkpinfo->compression_level,
|
---|
| 3558 | curr_slice_fname_uncompressed);
|
---|
| 3559 | log_msg(2, command);
|
---|
| 3560 | if ((res = system(command))) {
|
---|
| 3561 | log_OS_error(command);
|
---|
| 3562 | }
|
---|
| 3563 | // did_I_compress_slice = TRUE;
|
---|
| 3564 | } else {
|
---|
| 3565 | sprintf(command, "mv %s %s 2>> %s",
|
---|
| 3566 | curr_slice_fname_uncompressed,
|
---|
| 3567 | curr_slice_fname_compressed, MONDO_LOGFILE);
|
---|
| 3568 | res = 0; // don't do it :)
|
---|
| 3569 | // did_I_compress_slice = FALSE;
|
---|
| 3570 | }
|
---|
| 3571 | retval += res;
|
---|
| 3572 | if (res) {
|
---|
| 3573 | log_msg(2, "Failed to compress the slice");
|
---|
| 3574 | }
|
---|
| 3575 | if (bkpinfo->use_lzo
|
---|
| 3576 | && strcmp(curr_slice_fname_compressed,
|
---|
| 3577 | curr_slice_fname_uncompressed)) {
|
---|
| 3578 | unlink(curr_slice_fname_uncompressed);
|
---|
| 3579 | }
|
---|
| 3580 | if (res) {
|
---|
| 3581 | sprintf(tmp, "Problem with slice # %ld", slice_num);
|
---|
| 3582 | } else {
|
---|
| 3583 | sprintf(tmp,
|
---|
| 3584 | "%s - Bigfile #%ld, slice #%ld compressed OK ",
|
---|
| 3585 | biggie_filename, biggie_file_number + 1,
|
---|
| 3586 | slice_num);
|
---|
| 3587 | }
|
---|
[1] | 3588 | #ifndef _XWIN
|
---|
[128] | 3589 | if (!g_text_mode) {
|
---|
| 3590 | newtDrawRootText(0, g_noof_rows - 2, tmp);
|
---|
| 3591 | newtRefresh();
|
---|
| 3592 | } else {
|
---|
| 3593 | log_msg(2, tmp);
|
---|
| 3594 | }
|
---|
[1] | 3595 | #else
|
---|
[128] | 3596 | log_msg(2, tmp);
|
---|
[1] | 3597 | #endif
|
---|
[128] | 3598 | strcpy(file_to_archive, curr_slice_fname_compressed);
|
---|
| 3599 | g_current_progress++;
|
---|
| 3600 | } else { /* if i==0 then ... */
|
---|
[1] | 3601 |
|
---|
[128] | 3602 | finished = TRUE;
|
---|
| 3603 | strcpy(file_to_archive, curr_slice_fname_uncompressed);
|
---|
| 3604 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 3605 | break;
|
---|
| 3606 | }
|
---|
| 3607 | }
|
---|
| 3608 |
|
---|
| 3609 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 3610 | register_in_tape_catalog(biggieslice, biggie_file_number,
|
---|
| 3611 | slice_num, file_to_archive);
|
---|
| 3612 | maintain_collection_of_recent_archives(bkpinfo->tmpdir,
|
---|
| 3613 | file_to_archive);
|
---|
| 3614 | res = move_files_to_stream(bkpinfo, file_to_archive, NULL);
|
---|
| 3615 | } else {
|
---|
[541] | 3616 | res = move_files_to_cd(bkpinfo, file_to_archive, NULL);
|
---|
[128] | 3617 | }
|
---|
| 3618 | retval += res;
|
---|
| 3619 | if (res) {
|
---|
| 3620 | sprintf(tmp,
|
---|
| 3621 | "Failed to add slice %ld of bigfile %ld to scratchdir",
|
---|
| 3622 | slice_num, biggie_file_number + 1);
|
---|
| 3623 | log_to_screen(tmp);
|
---|
| 3624 | fatal_error
|
---|
| 3625 | ("Hard disk full. You should have bought a bigger one.");
|
---|
| 3626 | }
|
---|
[1] | 3627 | }
|
---|
[128] | 3628 | paranoid_fclose(fin);
|
---|
| 3629 | sprintf(tmp, "Sliced bigfile #%ld", biggie_file_number + 1);
|
---|
| 3630 | if (retval) {
|
---|
| 3631 | strcat(tmp, "...FAILED");
|
---|
| 3632 | } else {
|
---|
| 3633 | strcat(tmp, "...OK!");
|
---|
[1] | 3634 | }
|
---|
[128] | 3635 | log_msg(1, tmp);
|
---|
| 3636 | paranoid_free(tempblock);
|
---|
| 3637 | paranoid_free(tmp);
|
---|
| 3638 | paranoid_free(checksum_line);
|
---|
| 3639 | paranoid_free(command);
|
---|
| 3640 | paranoid_free(curr_slice_fname_uncompressed);
|
---|
| 3641 | paranoid_free(curr_slice_fname_compressed);
|
---|
| 3642 | paranoid_free(file_to_archive);
|
---|
| 3643 | paranoid_free(suffix);
|
---|
| 3644 | return (retval);
|
---|
[1] | 3645 | }
|
---|
| 3646 |
|
---|
| 3647 |
|
---|
| 3648 |
|
---|
| 3649 |
|
---|
| 3650 |
|
---|
| 3651 |
|
---|
| 3652 | /**
|
---|
| 3653 | * Remove the archives in @c d.
|
---|
| 3654 | * This could possibly include any of:
|
---|
| 3655 | * - all afioballs (compressed and not)
|
---|
| 3656 | * - all filelists
|
---|
| 3657 | * - all slices
|
---|
| 3658 | * - all checksums
|
---|
| 3659 | * - a zero filler file
|
---|
| 3660 | *
|
---|
| 3661 | * @param d The directory to wipe the archives from.
|
---|
| 3662 | * @ingroup utilityGroup
|
---|
| 3663 | */
|
---|
[128] | 3664 | void wipe_archives(char *d)
|
---|
[1] | 3665 | {
|
---|
[128] | 3666 | /*@ buffers ********************************************* */
|
---|
| 3667 | char *tmp;
|
---|
| 3668 | char *dir;
|
---|
[1] | 3669 |
|
---|
[128] | 3670 | malloc_string(tmp);
|
---|
| 3671 | malloc_string(dir);
|
---|
| 3672 | assert_string_is_neither_NULL_nor_zerolength(d);
|
---|
[1] | 3673 |
|
---|
[128] | 3674 | sprintf(dir, "%s/archives", d);
|
---|
| 3675 | sprintf(tmp, "find %s -name '*.afio*' -exec rm -f '{}' \\;", dir);
|
---|
| 3676 | run_program_and_log_output(tmp, FALSE);
|
---|
| 3677 | sprintf(tmp, "find %s -name '*list.[0-9]*' -exec rm -f '{}' \\;", dir);
|
---|
| 3678 | run_program_and_log_output(tmp, FALSE);
|
---|
| 3679 | sprintf(tmp, "find %s -name 'slice*' -exec rm -f '{}' \\;", dir);
|
---|
| 3680 | run_program_and_log_output(tmp, FALSE);
|
---|
| 3681 | sprintf(tmp, "rm -f %s/cklist*", dir);
|
---|
| 3682 | run_program_and_log_output(tmp, FALSE);
|
---|
| 3683 | sprintf(tmp, "rm -f %s/zero", dir);
|
---|
| 3684 | run_program_and_log_output(tmp, FALSE);
|
---|
| 3685 | log_msg(1, "Wiped %s's archives", dir);
|
---|
| 3686 | sprintf(tmp, "ls -l %s", dir);
|
---|
| 3687 | run_program_and_log_output(tmp, FALSE);
|
---|
| 3688 | paranoid_free(tmp);
|
---|
| 3689 | paranoid_free(dir);
|
---|
[1] | 3690 | }
|
---|
| 3691 |
|
---|
| 3692 |
|
---|
| 3693 |
|
---|
| 3694 | /**
|
---|
| 3695 | * @addtogroup LLarchiveGroup
|
---|
| 3696 | * @{
|
---|
| 3697 | */
|
---|
| 3698 | /**
|
---|
| 3699 | * Write the final ISO image.
|
---|
| 3700 | * @param bkpinfo The backup information structure. Used only
|
---|
| 3701 | * in the call to @c write_iso_and_go_on().
|
---|
| 3702 | * @return The number of errors encountered (0 for success)
|
---|
| 3703 | * @see write_iso_and_go_on
|
---|
| 3704 | * @see make_iso_fs
|
---|
| 3705 | * @bug The final ISO is written even if there are no files on it. In practice,
|
---|
| 3706 | * however, this occurs rarely.
|
---|
| 3707 | */
|
---|
[541] | 3708 | int write_final_iso_if_necessary(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 3709 | {
|
---|
[128] | 3710 | /*@ int ***************************************************** */
|
---|
| 3711 | int res;
|
---|
[1] | 3712 |
|
---|
[128] | 3713 | /*@ buffers ************************************************** */
|
---|
| 3714 | char *tmp;
|
---|
[1] | 3715 |
|
---|
[128] | 3716 | malloc_string(tmp);
|
---|
| 3717 | assert(bkpinfo != NULL);
|
---|
[1] | 3718 |
|
---|
| 3719 | // I should really check if there are any slices or tarballs to be copied to CD-R(W)'s; the odds are approx. 1 in a million that there are no files here, so I'll just go ahead & make one more CD anyway
|
---|
| 3720 |
|
---|
[128] | 3721 | sprintf(tmp, "Writing the final ISO");
|
---|
| 3722 | log_msg(2, tmp);
|
---|
| 3723 | center_string(tmp, 80);
|
---|
[1] | 3724 | #ifndef _XWIN
|
---|
[128] | 3725 | if (!g_text_mode) {
|
---|
| 3726 | newtPushHelpLine(tmp);
|
---|
| 3727 | }
|
---|
[1] | 3728 | #endif
|
---|
[541] | 3729 | res = write_iso_and_go_on(bkpinfo, TRUE);
|
---|
[1] | 3730 | #ifndef _XWIN
|
---|
[128] | 3731 | if (!g_text_mode) {
|
---|
| 3732 | newtPopHelpLine();
|
---|
| 3733 | }
|
---|
[1] | 3734 | #endif
|
---|
[128] | 3735 | log_msg(2, "Returning from writing final ISO (res=%d)", res);
|
---|
| 3736 | paranoid_free(tmp);
|
---|
| 3737 | return (res);
|
---|
[1] | 3738 | }
|
---|
| 3739 |
|
---|
| 3740 |
|
---|
| 3741 | /**
|
---|
[20] | 3742 | * Write an ISO image to <tt>[bkpinfo->isodir]/bkpinfo->prefix-[g_current_media_number].iso</tt>.
|
---|
[1] | 3743 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 3744 | * - @c backup_media_type
|
---|
[20] | 3745 | * - @c prefix
|
---|
[1] | 3746 | * - @c isodir
|
---|
| 3747 | * - @c manual_cd_tray
|
---|
| 3748 | * - @c media_size
|
---|
| 3749 | * - @c nfs_mount
|
---|
| 3750 | * - @c nfs_remote_dir
|
---|
| 3751 | * - @c scratchdir
|
---|
| 3752 | * - @c verify_data
|
---|
| 3753 | *
|
---|
| 3754 | * @param last_cd If TRUE, this is the last CD to write; if FALSE, it's not.
|
---|
| 3755 | * @return The number of errors encountered (0 for success)
|
---|
| 3756 | * @see make_iso_fs
|
---|
| 3757 | */
|
---|
[541] | 3758 | int write_iso_and_go_on(struct s_bkpinfo *bkpinfo, bool last_cd)
|
---|
[1] | 3759 | {
|
---|
[128] | 3760 | /*@ pointers **************************************************** */
|
---|
| 3761 | FILE *fout;
|
---|
[1] | 3762 |
|
---|
[128] | 3763 | /*@ buffers ***************************************************** */
|
---|
| 3764 | char *tmp;
|
---|
| 3765 | char *cdno_fname;
|
---|
| 3766 | char *lastcd_fname;
|
---|
| 3767 | char *isofile;
|
---|
[1] | 3768 |
|
---|
[128] | 3769 | /*@ bool ******************************************************** */
|
---|
| 3770 | bool that_one_was_ok;
|
---|
| 3771 | bool using_nfs;
|
---|
| 3772 | bool orig_vfy_flag_val;
|
---|
[1] | 3773 |
|
---|
[128] | 3774 | /*@ int *********************************************************** */
|
---|
| 3775 | int res = 0;
|
---|
[1] | 3776 |
|
---|
[128] | 3777 | malloc_string(tmp);
|
---|
| 3778 | malloc_string(cdno_fname);
|
---|
| 3779 | malloc_string(lastcd_fname);
|
---|
| 3780 | malloc_string(isofile);
|
---|
[1] | 3781 |
|
---|
[128] | 3782 | assert(bkpinfo != NULL);
|
---|
| 3783 | orig_vfy_flag_val = bkpinfo->verify_data;
|
---|
| 3784 | if (bkpinfo->media_size[g_current_media_number] <= 0) {
|
---|
| 3785 | fatal_error("write_iso_and_go_on() - unknown media size");
|
---|
| 3786 | }
|
---|
[1] | 3787 |
|
---|
[128] | 3788 | if (strlen(bkpinfo->nfs_mount) > 1) {
|
---|
| 3789 | using_nfs = TRUE;
|
---|
| 3790 | } else {
|
---|
| 3791 | using_nfs = FALSE;
|
---|
| 3792 | }
|
---|
| 3793 | log_msg(1, "OK, time to make %s #%d",
|
---|
| 3794 | media_descriptor_string(bkpinfo->backup_media_type),
|
---|
| 3795 | g_current_media_number);
|
---|
[1] | 3796 |
|
---|
[128] | 3797 | /* label the ISO with its number */
|
---|
[1] | 3798 |
|
---|
[128] | 3799 | sprintf(cdno_fname, "%s/archives/THIS-CD-NUMBER", bkpinfo->scratchdir);
|
---|
| 3800 | fout = fopen(cdno_fname, "w");
|
---|
| 3801 | fprintf(fout, "%d", g_current_media_number);
|
---|
| 3802 | paranoid_fclose(fout);
|
---|
[1] | 3803 |
|
---|
[128] | 3804 | sprintf(tmp, "cp -f %s/autorun %s/", g_mondo_home,
|
---|
| 3805 | bkpinfo->scratchdir);
|
---|
| 3806 | if (run_program_and_log_output(tmp, FALSE)) {
|
---|
| 3807 | log_msg(2, "Warning - unable to copy autorun to scratchdir");
|
---|
[1] | 3808 | }
|
---|
[128] | 3809 |
|
---|
| 3810 | /* last CD or not? Label accordingly */
|
---|
| 3811 | sprintf(lastcd_fname, "%s/archives/NOT-THE-LAST", bkpinfo->scratchdir);
|
---|
| 3812 | if (last_cd) {
|
---|
| 3813 | unlink(lastcd_fname);
|
---|
| 3814 | log_msg(2,
|
---|
| 3815 | "OK, you're telling me this is the last CD. Fair enough.");
|
---|
| 3816 | } else {
|
---|
| 3817 | fout = fopen(lastcd_fname, "w");
|
---|
| 3818 | fprintf(fout,
|
---|
| 3819 | "You're listening to 90.3 WPLN, Nashville Public Radio.\n");
|
---|
| 3820 | paranoid_fclose(fout);
|
---|
[1] | 3821 | }
|
---|
[128] | 3822 | if (space_occupied_by_cd(bkpinfo->scratchdir) / 1024 >
|
---|
| 3823 | bkpinfo->media_size[g_current_media_number]) {
|
---|
| 3824 | sprintf(tmp,
|
---|
| 3825 | "Warning! CD is too big. It occupies %ld KB, which is more than the %ld KB allowed.",
|
---|
| 3826 | (long) space_occupied_by_cd(bkpinfo->scratchdir),
|
---|
| 3827 | (long) bkpinfo->media_size[g_current_media_number]);
|
---|
| 3828 | log_to_screen(tmp);
|
---|
| 3829 | }
|
---|
| 3830 | sprintf(isofile, "%s/%s/%s-%d.iso", bkpinfo->isodir,
|
---|
| 3831 | bkpinfo->nfs_remote_dir, bkpinfo->prefix,
|
---|
| 3832 | g_current_media_number);
|
---|
| 3833 | for (that_one_was_ok = FALSE; !that_one_was_ok;) {
|
---|
[541] | 3834 | res = make_iso_fs(bkpinfo, isofile);
|
---|
[128] | 3835 | if (g_current_media_number == 1 && !res
|
---|
| 3836 | && (bkpinfo->backup_media_type == cdr
|
---|
| 3837 | || bkpinfo->backup_media_type == cdrw)) {
|
---|
| 3838 | if (find_cdrom_device(tmp, FALSE)) // make sure find_cdrom_device() finds, records CD-R's loc
|
---|
| 3839 | {
|
---|
| 3840 | log_msg(3, "*Sigh* Mike, I hate your computer.");
|
---|
| 3841 | bkpinfo->manual_cd_tray = TRUE;
|
---|
| 3842 | } // if it can't be found then force pausing
|
---|
| 3843 | else {
|
---|
| 3844 | log_msg(3, "Great. Found Mike's CD-ROM drive.");
|
---|
| 3845 | }
|
---|
[1] | 3846 | }
|
---|
[128] | 3847 | if (bkpinfo->verify_data && !res) {
|
---|
| 3848 | log_to_screen
|
---|
| 3849 | ("Please reboot from the 1st %s in Compare Mode, as a precaution.",
|
---|
| 3850 | media_descriptor_string(g_backup_media_type));
|
---|
| 3851 | chdir("/");
|
---|
| 3852 | iamhere("Before calling verify_cd_image()");
|
---|
| 3853 | res += verify_cd_image(bkpinfo);
|
---|
| 3854 | iamhere("After calling verify_cd_image()");
|
---|
[1] | 3855 | }
|
---|
[128] | 3856 | if (!res) {
|
---|
| 3857 | that_one_was_ok = TRUE;
|
---|
| 3858 | } else {
|
---|
| 3859 | sprintf(tmp, "Failed to burn %s #%d. Retry?",
|
---|
| 3860 | media_descriptor_string(bkpinfo->backup_media_type),
|
---|
| 3861 | g_current_media_number);
|
---|
| 3862 | res = ask_me_yes_or_no(tmp);
|
---|
| 3863 | if (!res) {
|
---|
| 3864 | if (ask_me_yes_or_no("Abort the backup?")) {
|
---|
| 3865 | fatal_error("FAILED TO BACKUP");
|
---|
| 3866 | } else {
|
---|
| 3867 | break;
|
---|
| 3868 | }
|
---|
| 3869 | } else {
|
---|
| 3870 | log_msg(2, "Retrying, at user's request...");
|
---|
| 3871 | res = 0;
|
---|
| 3872 | }
|
---|
| 3873 | }
|
---|
[1] | 3874 | }
|
---|
| 3875 | /*
|
---|
| 3876 | if (using_nfs)
|
---|
| 3877 | {
|
---|
| 3878 | sprintf(tmp,"mv -f %s %s/%s/", isofile, bkpinfo->isodir, bkpinfo->nfs_remote_dir);
|
---|
| 3879 | if (run_program_and_log_output(tmp, FALSE))
|
---|
| 3880 | { log_to_screen("Unable to move ISO to NFS dir"); }
|
---|
| 3881 | }
|
---|
| 3882 | */
|
---|
[128] | 3883 | g_current_media_number++;
|
---|
| 3884 | if (g_current_media_number > MAX_NOOF_MEDIA) {
|
---|
| 3885 | fatal_error("Too many CD-R(W)'s. Use tape or net.");
|
---|
| 3886 | }
|
---|
| 3887 | wipe_archives(bkpinfo->scratchdir);
|
---|
| 3888 | sprintf(tmp, "rm -Rf %s/images/*gz %s/images/*data*img",
|
---|
| 3889 | bkpinfo->scratchdir, bkpinfo->scratchdir);
|
---|
| 3890 | if (system(tmp)) {
|
---|
| 3891 | log_msg
|
---|
| 3892 | (2,
|
---|
| 3893 | "Error occurred when I tried to delete the redundant IMGs and GZs");
|
---|
| 3894 | }
|
---|
[1] | 3895 |
|
---|
[128] | 3896 | if (last_cd) {
|
---|
| 3897 | log_msg(2, "This was your last CD.");
|
---|
| 3898 | } else {
|
---|
| 3899 | log_msg(2, "Continuing to backup your data...");
|
---|
| 3900 | }
|
---|
[1] | 3901 |
|
---|
[128] | 3902 | bkpinfo->verify_data = orig_vfy_flag_val;
|
---|
| 3903 | paranoid_free(tmp);
|
---|
| 3904 | paranoid_free(cdno_fname);
|
---|
| 3905 | paranoid_free(lastcd_fname);
|
---|
| 3906 | paranoid_free(isofile);
|
---|
| 3907 | return (0);
|
---|
[1] | 3908 | }
|
---|
| 3909 |
|
---|
| 3910 | /* @} - end of LLarchiveGroup */
|
---|
| 3911 |
|
---|
| 3912 |
|
---|
| 3913 |
|
---|
| 3914 |
|
---|
| 3915 | /**
|
---|
| 3916 | * Verify the user's data.
|
---|
| 3917 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 3918 | * - @c backup_data
|
---|
| 3919 | * - @c backup_media_type
|
---|
| 3920 | * - @c media_device
|
---|
| 3921 | * - @c verify_data
|
---|
| 3922 | *
|
---|
| 3923 | * @return The number of errors encountered (0 for success)
|
---|
| 3924 | * @ingroup verifyGroup
|
---|
| 3925 | */
|
---|
| 3926 | int verify_data(struct s_bkpinfo *bkpinfo)
|
---|
| 3927 | {
|
---|
[128] | 3928 | int res = 0, retval = 0, cdno = 0;
|
---|
| 3929 | char *tmp;
|
---|
| 3930 | long diffs = 0;
|
---|
[1] | 3931 |
|
---|
[128] | 3932 | malloc_string(tmp);
|
---|
| 3933 | assert(bkpinfo != NULL);
|
---|
| 3934 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 3935 | chdir("/");
|
---|
| 3936 | mvaddstr_and_log_it(g_currentY, 0,
|
---|
| 3937 | "Verifying archives against live filesystem");
|
---|
| 3938 | if (bkpinfo->backup_media_type == cdstream) {
|
---|
| 3939 | strcpy(bkpinfo->media_device, "/dev/cdrom");
|
---|
| 3940 | }
|
---|
| 3941 | verify_tape_backups(bkpinfo);
|
---|
| 3942 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
| 3943 | } else if (bkpinfo->backup_data)
|
---|
| 3944 | //bkpinfo->backup_media_type == cdrw || bkpinfo->backup_media_type == cdr))
|
---|
[1] | 3945 | {
|
---|
[128] | 3946 | log_msg(2,
|
---|
| 3947 | "Not verifying again. Per-CD/ISO verification already carried out.");
|
---|
| 3948 | paranoid_system
|
---|
| 3949 | ("cat /tmp/changed.files.* > /tmp/changed.files 2> /dev/null");
|
---|
| 3950 | } else {
|
---|
| 3951 | g_current_media_number = cdno;
|
---|
| 3952 | if (bkpinfo->backup_media_type != iso) {
|
---|
| 3953 | find_cdrom_device(bkpinfo->media_device, FALSE); // replace 0,0,0 with /dev/cdrom
|
---|
[1] | 3954 | }
|
---|
[128] | 3955 | chdir("/");
|
---|
| 3956 | for (cdno = 1; cdno < 99 && bkpinfo->verify_data; cdno++) {
|
---|
| 3957 | if (cdno != g_current_media_number) {
|
---|
| 3958 | log_msg(2,
|
---|
| 3959 | "Warning - had to change g_current_media_number from %d to %d",
|
---|
| 3960 | g_current_media_number, cdno);
|
---|
| 3961 | g_current_media_number = cdno;
|
---|
| 3962 | }
|
---|
| 3963 | if (bkpinfo->backup_media_type != iso) {
|
---|
| 3964 | insist_on_this_cd_number(bkpinfo, cdno);
|
---|
| 3965 | }
|
---|
| 3966 | res = verify_cd_image(bkpinfo); // sets verify_data to FALSE if it's time to stop verifying
|
---|
| 3967 | retval += res;
|
---|
| 3968 | if (res) {
|
---|
| 3969 | sprintf(tmp,
|
---|
| 3970 | "Warnings/errors were reported while checking %s #%d",
|
---|
| 3971 | media_descriptor_string(bkpinfo->
|
---|
| 3972 | backup_media_type),
|
---|
| 3973 | g_current_media_number);
|
---|
| 3974 | log_to_screen(tmp);
|
---|
[1] | 3975 |
|
---|
[128] | 3976 | }
|
---|
[1] | 3977 | }
|
---|
| 3978 | /*
|
---|
| 3979 | sprintf (tmp,
|
---|
| 3980 | "cat %s | grep \"afio: \" | cut -d'\"' -f2 | sort -u | awk '{print \"/\"$0;};' | tr -s '/' '/' | grep -vx \"/afio:.*\" > /tmp/changed.files",
|
---|
| 3981 | MONDO_LOGFILE);
|
---|
| 3982 | system (tmp);
|
---|
| 3983 | */
|
---|
[128] | 3984 | sprintf(tmp,
|
---|
[911] | 3985 | "grep 'afio: ' %s | sed 's/afio: //' | grep -vE '^/dev/.*$' >> /tmp/changed.files",
|
---|
[128] | 3986 | MONDO_LOGFILE);
|
---|
| 3987 | system(tmp);
|
---|
| 3988 |
|
---|
| 3989 | sprintf(tmp,
|
---|
[911] | 3990 | "grep 'star: ' %s | sed 's/star: //' | grep -vE '^/dev/.*$' >> /tmp/changed.files",
|
---|
[128] | 3991 | MONDO_LOGFILE);
|
---|
| 3992 | system(tmp);
|
---|
| 3993 | run_program_and_log_output("umount " MNT_CDROM, FALSE);
|
---|
| 3994 | // if (bkpinfo->backup_media_type != iso && !bkpinfo->please_dont_eject_when_restoring)
|
---|
[1] | 3995 | //{
|
---|
[128] | 3996 | eject_device(bkpinfo->media_device);
|
---|
[1] | 3997 | //}
|
---|
| 3998 | }
|
---|
[128] | 3999 | diffs = count_lines_in_file("/tmp/changed.files");
|
---|
[1] | 4000 |
|
---|
[128] | 4001 | if (diffs > 0) {
|
---|
| 4002 | if (retval == 0) {
|
---|
| 4003 | retval = (int) (-diffs);
|
---|
| 4004 | }
|
---|
[1] | 4005 | }
|
---|
[128] | 4006 | paranoid_free(tmp);
|
---|
| 4007 | return (retval);
|
---|
[1] | 4008 | }
|
---|
| 4009 |
|
---|
| 4010 |
|
---|
| 4011 |
|
---|
| 4012 |
|
---|
| 4013 |
|
---|
| 4014 | /**
|
---|
| 4015 | * @addtogroup utilityGroup
|
---|
| 4016 | * @{
|
---|
| 4017 | */
|
---|
| 4018 | /**
|
---|
| 4019 | * Write an image to a real 3.5" floppy disk.
|
---|
| 4020 | * @param device The device to write to (e.g. @c /dev/fd0)
|
---|
| 4021 | * @param datafile The image to write to @p device.
|
---|
| 4022 | * @return The number of errors encountered (0 for success)
|
---|
| 4023 | * @see write_image_to_floppy
|
---|
| 4024 | */
|
---|
[128] | 4025 | int write_image_to_floppy_SUB(char *device, char *datafile)
|
---|
[1] | 4026 | {
|
---|
[128] | 4027 | /*@ int *************************************************************** */
|
---|
| 4028 | int res = 0;
|
---|
[1] | 4029 | int percentage = 0;
|
---|
| 4030 | int blockno = 0;
|
---|
[128] | 4031 | int maxblocks = 0;
|
---|
[1] | 4032 |
|
---|
[128] | 4033 | /*@ buffers************************************************************ */
|
---|
| 4034 | char *tmp;
|
---|
[1] | 4035 | char blk[1024];
|
---|
| 4036 | char *title;
|
---|
| 4037 |
|
---|
[128] | 4038 | /*@ pointers ********************************************************** */
|
---|
[1] | 4039 | char *p;
|
---|
[128] | 4040 | FILE *fout, *fin;
|
---|
[1] | 4041 |
|
---|
| 4042 |
|
---|
[128] | 4043 | malloc_string(tmp);
|
---|
| 4044 | malloc_string(title);
|
---|
| 4045 | /* pretty stuff */
|
---|
| 4046 | if (!(p = strrchr(datafile, '/'))) {
|
---|
| 4047 | p = datafile;
|
---|
| 4048 | } else {
|
---|
| 4049 | p++;
|
---|
[1] | 4050 | }
|
---|
[128] | 4051 | sprintf(title, "Writing %s to floppy", p);
|
---|
| 4052 | open_evalcall_form(title);
|
---|
| 4053 | /* functional stuff */
|
---|
| 4054 | for (p = device + strlen(device); p != device && isdigit(*(p - 1));
|
---|
| 4055 | p--);
|
---|
| 4056 | maxblocks = atoi(p);
|
---|
| 4057 | if (!maxblocks) {
|
---|
| 4058 | maxblocks = 1440;
|
---|
[1] | 4059 | }
|
---|
[128] | 4060 | sprintf(tmp, "maxblocks = %d; p=%s", maxblocks, p);
|
---|
| 4061 | log_msg(2, tmp);
|
---|
| 4062 | /* copy data from image to floppy */
|
---|
| 4063 | if (!(fin = fopen(datafile, "r"))) {
|
---|
| 4064 | log_OS_error("Cannot open img");
|
---|
| 4065 | return (1);
|
---|
[1] | 4066 | }
|
---|
[128] | 4067 | if (!(fout = fopen(device, "w"))) {
|
---|
| 4068 | log_OS_error("Cannot open fdd");
|
---|
| 4069 | return (1);
|
---|
| 4070 | }
|
---|
| 4071 | for (blockno = 0; blockno < maxblocks; blockno++) {
|
---|
| 4072 | percentage = blockno * 100 / maxblocks;
|
---|
| 4073 | if (fread(blk, 1, 1024, fin) != 1024) {
|
---|
| 4074 | if (feof(fin)) {
|
---|
| 4075 | log_msg(1,
|
---|
| 4076 | "img read err - img ended prematurely - non-fatal error");
|
---|
| 4077 | sleep(3);
|
---|
| 4078 | return (res);
|
---|
| 4079 | }
|
---|
| 4080 | res++;
|
---|
| 4081 | log_to_screen("img read err");
|
---|
| 4082 | }
|
---|
| 4083 | if (fwrite(blk, 1, 1024, fout) != 1024) {
|
---|
| 4084 | res++;
|
---|
| 4085 | log_to_screen("fdd write err");
|
---|
| 4086 | }
|
---|
| 4087 | if (((blockno + 1) % 128) == 0) {
|
---|
| 4088 | paranoid_system("sync"); /* fflush doesn't work; dunno why */
|
---|
| 4089 | update_evalcall_form(percentage);
|
---|
| 4090 | }
|
---|
| 4091 | }
|
---|
| 4092 | paranoid_fclose(fin);
|
---|
| 4093 | paranoid_fclose(fout);
|
---|
| 4094 | paranoid_free(tmp);
|
---|
| 4095 | paranoid_free(title);
|
---|
| 4096 | close_evalcall_form();
|
---|
| 4097 | return (res);
|
---|
[1] | 4098 | }
|
---|
| 4099 |
|
---|
| 4100 |
|
---|
| 4101 |
|
---|
| 4102 |
|
---|
| 4103 |
|
---|
| 4104 |
|
---|
| 4105 |
|
---|
| 4106 |
|
---|
| 4107 |
|
---|
| 4108 | /**
|
---|
| 4109 | * Wrapper around @c write_image_to_floppy_SUB().
|
---|
| 4110 | * This function, unlike @c write_image_to_floppy_SUB(),
|
---|
| 4111 | * gives the user the opportunity to retry if the write fails.
|
---|
| 4112 | * @see write_image_to_floppy_SUB
|
---|
| 4113 | */
|
---|
[128] | 4114 | int write_image_to_floppy(char *device, char *datafile)
|
---|
[1] | 4115 | {
|
---|
[128] | 4116 | /*@ int ************************************************************** */
|
---|
| 4117 | int res = 0;
|
---|
[1] | 4118 |
|
---|
[128] | 4119 | assert_string_is_neither_NULL_nor_zerolength(device);
|
---|
| 4120 | assert_string_is_neither_NULL_nor_zerolength(datafile);
|
---|
[1] | 4121 |
|
---|
[128] | 4122 | while ((res = write_image_to_floppy_SUB(device, datafile))) {
|
---|
| 4123 | if (!ask_me_yes_or_no("Failed to write image to floppy. Retry?")) {
|
---|
| 4124 | return (res);
|
---|
| 4125 | }
|
---|
[1] | 4126 | }
|
---|
[128] | 4127 | return (res);
|
---|
[1] | 4128 | }
|
---|
| 4129 |
|
---|
| 4130 | /* @} - end of utilityGroup */
|
---|
[259] | 4131 |
|
---|
[424] | 4132 | void setenv_mondo_share(void) {
|
---|
[259] | 4133 |
|
---|
[424] | 4134 | setenv("MONDO_SHARE", MONDO_SHARE, 1);
|
---|
[259] | 4135 | }
|
---|