[1] | 1 | /* libmondo-archive.c
|
---|
[99] | 2 | $Id: libmondo-archive.c 1567 2007-07-25 16:13:51Z 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 1567 2007-07-25 16:13:51Z 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");
|
---|
[1563] | 891 | /* BCO: fix it for Debian, Mandrake, ... */
|
---|
[128] | 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 | }
|
---|
[1563] | 898 | if (!does_file_exist("/etc/elilo.conf")
|
---|
| 899 | && does_file_exist("/boot/efi/efi/SuSE/elilo.conf")) {
|
---|
| 900 | run_program_and_log_output
|
---|
| 901 | ("ln -sf /boot/efi/efi/SuSE/elilo.conf /etc/elilo.conf",
|
---|
| 902 | 5);
|
---|
| 903 | }
|
---|
[1567] | 904 | if (!does_file_exist("/etc/elilo.conf")
|
---|
| 905 | && does_file_exist("/boot/efi/efi/debian/elilo.conf")) {
|
---|
| 906 | run_program_and_log_output
|
---|
| 907 | ("ln -sf /boot/efi/efi/debian/elilo.conf /etc/elilo.conf",
|
---|
| 908 | 5);
|
---|
| 909 | if (!does_file_exist("/etc/elilo.conf")
|
---|
| 910 | && does_file_exist("/boot//efi/debian/elilo.conf")) {
|
---|
| 911 | run_program_and_log_output
|
---|
| 912 | ("ln -sf /boot/efi/debian/elilo.conf /etc/elilo.conf",
|
---|
| 913 | 5);
|
---|
| 914 | }
|
---|
[128] | 915 | if (!does_file_exist("/etc/elilo.conf")) {
|
---|
| 916 | fatal_error
|
---|
| 917 | ("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'");
|
---|
| 918 | }
|
---|
| 919 | } else if (bkpinfo->boot_loader == 'R') {
|
---|
| 920 | strcpy(bootldr_str, "RAW");
|
---|
[1] | 921 | }
|
---|
| 922 | #ifdef __FreeBSD__
|
---|
[128] | 923 | else if (bkpinfo->boot_loader == 'D') {
|
---|
| 924 | strcpy(bootldr_str, "DD");
|
---|
| 925 | }
|
---|
[1] | 926 |
|
---|
[128] | 927 | else if (bkpinfo->boot_loader == 'B') {
|
---|
| 928 | strcpy(bootldr_str, "BOOT0");
|
---|
| 929 | }
|
---|
[1] | 930 | #endif
|
---|
[128] | 931 | else {
|
---|
| 932 | strcpy(bootldr_str, "unknown");
|
---|
| 933 | }
|
---|
| 934 | sprintf(tmp, "Your boot loader is %s and it boots from %s",
|
---|
| 935 | bootldr_str, bkpinfo->boot_device);
|
---|
| 936 | log_to_screen(tmp);
|
---|
| 937 | sprintf(tmp, "%s/BOOTLOADER.DEVICE", bkpinfo->tmpdir);
|
---|
| 938 | if (write_one_liner_data_file(tmp, bkpinfo->boot_device)) {
|
---|
| 939 | log_msg(1, "%ld: Unable to write one-liner boot device", __LINE__);
|
---|
| 940 | }
|
---|
| 941 | switch (bkpinfo->backup_media_type) {
|
---|
| 942 | case cdr:
|
---|
| 943 | strcpy(value, "cdr");
|
---|
| 944 | break;
|
---|
| 945 | case cdrw:
|
---|
| 946 | strcpy(value, "cdrw");
|
---|
| 947 | break;
|
---|
| 948 | case cdstream:
|
---|
| 949 | strcpy(value, "cdstream");
|
---|
| 950 | break;
|
---|
| 951 | case tape:
|
---|
| 952 | strcpy(value, "tape");
|
---|
| 953 | break;
|
---|
| 954 | case udev:
|
---|
| 955 | strcpy(value, "udev");
|
---|
| 956 | break;
|
---|
| 957 | case iso:
|
---|
| 958 | strcpy(value, "iso");
|
---|
| 959 | break;
|
---|
| 960 | case nfs:
|
---|
| 961 | strcpy(value, "nfs");
|
---|
| 962 | break;
|
---|
| 963 | case dvd:
|
---|
| 964 | strcpy(value, "dvd");
|
---|
| 965 | break;
|
---|
| 966 | default:
|
---|
| 967 | fatal_error("Unknown backup_media_type");
|
---|
| 968 | }
|
---|
| 969 | sprintf(tmp, "%s/BACKUP-MEDIA-TYPE", bkpinfo->tmpdir);
|
---|
| 970 | if (write_one_liner_data_file(tmp, value)) {
|
---|
| 971 | res++;
|
---|
| 972 | log_msg(1, "%ld: Unable to write one-liner backup-media-type",
|
---|
| 973 | __LINE__);
|
---|
| 974 | }
|
---|
| 975 | log_to_screen(bkpinfo->tmpdir);
|
---|
| 976 | sprintf(tmp, "%s/BOOTLOADER.NAME", bkpinfo->tmpdir);
|
---|
| 977 | if (write_one_liner_data_file(tmp, bootldr_str)) {
|
---|
| 978 | res++;
|
---|
| 979 | log_msg(1, "%ld: Unable to write one-liner bootloader.name",
|
---|
| 980 | __LINE__);
|
---|
| 981 | }
|
---|
| 982 | sprintf(tmp, "%s/DIFFERENTIAL", bkpinfo->tmpdir);
|
---|
| 983 | if (bkpinfo->differential) {
|
---|
| 984 | res += write_one_liner_data_file(tmp, "1");
|
---|
| 985 | } else {
|
---|
| 986 | res += write_one_liner_data_file(tmp, "0");
|
---|
| 987 | }
|
---|
[1] | 988 |
|
---|
[949] | 989 | if (g_getfattr) {
|
---|
| 990 | asprintf(&tmp1, "%s/XATTR", bkpinfo->tmpdir);
|
---|
| 991 | if (write_one_liner_data_file(tmp1, "TRUE")) {
|
---|
| 992 | log_msg(1, "%ld: Unable to write one-liner XATTR",
|
---|
| 993 | __LINE__);
|
---|
| 994 | }
|
---|
| 995 | paranoid_free(tmp1);
|
---|
| 996 | }
|
---|
| 997 | if (g_getfacl) {
|
---|
| 998 | asprintf(&tmp1, "%s/ACL", bkpinfo->tmpdir);
|
---|
| 999 | if (write_one_liner_data_file(tmp1, "TRUE")) {
|
---|
| 1000 | log_msg(1, "%ld: Unable to write one-liner ACL",
|
---|
| 1001 | __LINE__);
|
---|
| 1002 | }
|
---|
| 1003 | paranoid_free(tmp1);
|
---|
| 1004 | }
|
---|
| 1005 |
|
---|
[128] | 1006 | estimated_total_noof_slices =
|
---|
| 1007 | size_of_all_biggiefiles_K(bkpinfo) / bkpinfo->optimal_set_size + 1;
|
---|
[1] | 1008 | /* add nfs stuff here? */
|
---|
[128] | 1009 | sprintf(command, "mkdir -p %s/images", bkpinfo->scratchdir);
|
---|
| 1010 | if (system(command)) {
|
---|
| 1011 | res++;
|
---|
| 1012 | log_OS_error("Unable to make images directory");
|
---|
| 1013 | }
|
---|
| 1014 | sprintf(command, "mkdir -p %s%s", bkpinfo->scratchdir, MNT_FLOPPY);
|
---|
| 1015 | if (system(command)) {
|
---|
| 1016 | res++;
|
---|
| 1017 | log_OS_error("Unable to make mnt floppy directory");
|
---|
| 1018 | }
|
---|
| 1019 | sprintf(tmp, "BTW, I'm telling Mindi your kernel is '%s'",
|
---|
| 1020 | bkpinfo->kernel_path);
|
---|
[1] | 1021 |
|
---|
[128] | 1022 | log_msg(1, "lines_in_filelist = %ld", lines_in_filelist);
|
---|
[1] | 1023 |
|
---|
[128] | 1024 | sprintf(command,
|
---|
[1] | 1025 | /* "mindi --custom 2=%s 3=%s/images 4=\"%s\" 5=\"%s\" \
|
---|
| 1026 | 6=\"%s\" 7=%ld 8=\"%s\" 9=\"%s\" 10=\"%s\" \
|
---|
| 1027 | 11=\"%s\" 12=%s 13=%ld 14=\"%s\" 15=\"%s\" 16=\"%s\" 17=\"%s\" 18=%ld 19=%d",*/
|
---|
[128] | 1028 | "mindi --custom %s %s/images '%s' '%s' \
|
---|
[126] | 1029 | '%s' %ld '%s' '%s' '%s' \
|
---|
[998] | 1030 | '%s' %s %ld '%s' '%s' '%s' '%s' %ld %d '%s'", bkpinfo->tmpdir, // parameter #2
|
---|
[128] | 1031 | bkpinfo->scratchdir, // parameter #3
|
---|
| 1032 | bkpinfo->kernel_path, // parameter #4
|
---|
| 1033 | tape_device, // parameter #5
|
---|
| 1034 | tape_size_sz, // parameter #6
|
---|
| 1035 | lines_in_filelist, // parameter #7 (INT)
|
---|
| 1036 | use_lzo_sz, // parameter #8
|
---|
| 1037 | cd_recovery_sz, // parameter #9
|
---|
| 1038 | bkpinfo->image_devs, // parameter #10
|
---|
| 1039 | broken_bios_sz, // parameter #11
|
---|
| 1040 | last_filelist_number, // parameter #12 (STRING)
|
---|
| 1041 | estimated_total_noof_slices, // parameter #13 (INT)
|
---|
| 1042 | devs_to_exclude, // parameter #14
|
---|
| 1043 | use_comp_sz, // parameter #15
|
---|
| 1044 | use_lilo_sz, // parameter #16
|
---|
| 1045 | use_star_sz, // parameter #17
|
---|
| 1046 | bkpinfo->internal_tape_block_size, // parameter #18 (LONG)
|
---|
[998] | 1047 | bkpinfo->differential, // parameter #19 (INT)
|
---|
| 1048 | use_gzip_sz); // parameter #20 (STRING)
|
---|
[1] | 1049 |
|
---|
| 1050 | // Watch it! This next line adds a parameter...
|
---|
[128] | 1051 | if (bkpinfo->nonbootable_backup) {
|
---|
| 1052 | strcat(command, " NONBOOTABLE");
|
---|
| 1053 | }
|
---|
| 1054 | log_msg(2, command);
|
---|
[1] | 1055 |
|
---|
| 1056 | // popup_and_OK("Pausing");
|
---|
[128] | 1057 |
|
---|
| 1058 | res =
|
---|
| 1059 | run_program_and_log_to_screen(command,
|
---|
| 1060 | "Generating boot+data disks");
|
---|
| 1061 | if (bkpinfo->nonbootable_backup) {
|
---|
| 1062 | res = 0;
|
---|
| 1063 | } // hack
|
---|
| 1064 | if (!res) {
|
---|
| 1065 | log_to_screen("Boot+data disks were created OK");
|
---|
[1437] | 1066 | sprintf(command, "cp -f %s/images/mindi.iso %s/mondorescue.iso",
|
---|
| 1067 | bkpinfo->scratchdir, MINDI_CACHE);
|
---|
[128] | 1068 | log_msg(2, command);
|
---|
| 1069 | run_program_and_log_output(command, FALSE);
|
---|
| 1070 | if (bkpinfo->nonbootable_backup) {
|
---|
| 1071 | sprintf(command, "cp -f %s/all.tar.gz %s/images",
|
---|
| 1072 | bkpinfo->tmpdir, bkpinfo->scratchdir);
|
---|
| 1073 | if (system(command)) {
|
---|
| 1074 | fatal_error("Unable to create temporary duff tarball");
|
---|
| 1075 | }
|
---|
| 1076 | }
|
---|
| 1077 | sprintf(command, "cp -f %s/mindi-*oot*.img %s/images",
|
---|
| 1078 | bkpinfo->tmpdir, bkpinfo->scratchdir);
|
---|
| 1079 | sprintf(tmp, "cp -f %s/images/all.tar.gz %s", bkpinfo->scratchdir,
|
---|
| 1080 | bkpinfo->tmpdir);
|
---|
| 1081 | if (system(tmp)) {
|
---|
| 1082 | fatal_error("Cannot find all.tar.gz in tmpdir");
|
---|
| 1083 | }
|
---|
| 1084 | if (res) {
|
---|
| 1085 | mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
|
---|
| 1086 | } else {
|
---|
| 1087 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
| 1088 | }
|
---|
| 1089 | } else {
|
---|
| 1090 | log_to_screen("Mindi failed to create your boot+data disks.");
|
---|
[143] | 1091 | strcpy(command, "grep 'Fatal error' /var/log/mindi.log");
|
---|
[128] | 1092 | strcpy(tmp, call_program_and_get_last_line_of_output(command));
|
---|
| 1093 | if (strlen(tmp) > 1) {
|
---|
[155] | 1094 | popup_and_OK(tmp);
|
---|
[128] | 1095 | }
|
---|
| 1096 | }
|
---|
| 1097 | paranoid_free(tmp);
|
---|
| 1098 | paranoid_free(use_lzo_sz);
|
---|
[998] | 1099 | paranoid_free(use_gzip_sz);
|
---|
[128] | 1100 | paranoid_free(scratchdir);
|
---|
| 1101 | paranoid_free(use_comp_sz);
|
---|
| 1102 | paranoid_free(bootldr_str);
|
---|
| 1103 | paranoid_free(tape_device);
|
---|
| 1104 | paranoid_free(last_filelist_number);
|
---|
| 1105 | paranoid_free(broken_bios_sz);
|
---|
| 1106 | paranoid_free(cd_recovery_sz);
|
---|
| 1107 | paranoid_free(tape_size_sz);
|
---|
| 1108 | paranoid_free(devs_to_exclude);
|
---|
| 1109 | paranoid_free(use_lilo_sz);
|
---|
| 1110 | paranoid_free(value);
|
---|
| 1111 | paranoid_free(bootdev);
|
---|
| 1112 | paranoid_free(command);
|
---|
| 1113 | paranoid_free(use_star_sz);
|
---|
| 1114 | return (res);
|
---|
[1] | 1115 | }
|
---|
| 1116 |
|
---|
| 1117 |
|
---|
| 1118 |
|
---|
| 1119 | /**
|
---|
| 1120 | * Maximum number of filesets allowed in this function.
|
---|
| 1121 | */
|
---|
| 1122 | #define MAX_NOOF_SETS_HERE 32767
|
---|
| 1123 |
|
---|
| 1124 | /**
|
---|
| 1125 | * Offset of the bkpinfo pointer (in bytes) from the
|
---|
| 1126 | * buffer passed to create_afio_files_in_background.
|
---|
| 1127 | */
|
---|
| 1128 | #define BKPINFO_LOC_OFFSET (16+MAX_NOOF_SETS_HERE/8+16)
|
---|
| 1129 |
|
---|
| 1130 | /**
|
---|
| 1131 | * Main function for each @c afio thread.
|
---|
| 1132 | * @param inbuf A transfer block containing:
|
---|
| 1133 | * - @c p_last_set_archived: [offset 0] pointer to an @c int
|
---|
| 1134 | * containing the last set archived.
|
---|
| 1135 | * - @c p_archival_threads_running: [offset 4] pointer to an @c int
|
---|
| 1136 | * containing the number of archival threads currently running.
|
---|
| 1137 | * - @c p_next_set_to_archive: [offset 8] pointer to an @c int containing
|
---|
| 1138 | * the next set that should be archived.
|
---|
| 1139 | * - @c p_list_of_fileset_flags: [offset 12] @c char pointer pointing to a
|
---|
| 1140 | * bit array, where each bit corresponds to a filelist (1=needs
|
---|
| 1141 | * to be archived, 0=archived).
|
---|
| 1142 | * - @c bkpinfo: [offset BKPINFO_LOC_OFFSET] pointer to backup information
|
---|
| 1143 | * structure. Fields used:
|
---|
| 1144 | * - @c tmpdir
|
---|
| 1145 | * - @c zip_suffix
|
---|
| 1146 | *
|
---|
| 1147 | * Any of the above may be modified by the caller at any time.
|
---|
| 1148 | *
|
---|
| 1149 | * @bug Assumes @c int pointers are 4 bytes.
|
---|
| 1150 | * @see archive_this_fileset
|
---|
| 1151 | * @see make_afioballs_and_images
|
---|
| 1152 | * @return NULL, always.
|
---|
| 1153 | * @ingroup LLarchiveGroup
|
---|
| 1154 | */
|
---|
[128] | 1155 | void *create_afio_files_in_background(void *inbuf)
|
---|
[1] | 1156 | {
|
---|
[128] | 1157 | long int archiving_set_no;
|
---|
| 1158 | char *archiving_filelist_fname;
|
---|
| 1159 | char *archiving_afioball_fname;
|
---|
[948] | 1160 | char *curr_xattr_list_fname = NULL;
|
---|
[128] | 1161 | char *curr_acl_list_fname;
|
---|
[1] | 1162 |
|
---|
[128] | 1163 | struct s_bkpinfo *bkpinfo;
|
---|
| 1164 | char *tmp;
|
---|
| 1165 | int res = 0, retval = 0;
|
---|
| 1166 | int *p_archival_threads_running;
|
---|
| 1167 | int *p_last_set_archived;
|
---|
| 1168 | int *p_next_set_to_archive;
|
---|
| 1169 | char *p_list_of_fileset_flags;
|
---|
| 1170 | int this_thread_no = g_current_thread_no++;
|
---|
[1] | 1171 |
|
---|
[128] | 1172 | malloc_string(curr_xattr_list_fname);
|
---|
| 1173 | malloc_string(curr_acl_list_fname);
|
---|
| 1174 | malloc_string(archiving_filelist_fname);
|
---|
| 1175 | malloc_string(archiving_afioball_fname);
|
---|
| 1176 | malloc_string(tmp);
|
---|
| 1177 | p_last_set_archived = (int *) inbuf;
|
---|
| 1178 | p_archival_threads_running = (int *) (inbuf + 4);
|
---|
| 1179 | p_next_set_to_archive = (int *) (inbuf + 8);
|
---|
| 1180 | p_list_of_fileset_flags = (char *) (inbuf + 12);
|
---|
| 1181 | bkpinfo = (struct s_bkpinfo *) (inbuf + BKPINFO_LOC_OFFSET);
|
---|
[1] | 1182 |
|
---|
[128] | 1183 | sprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ,
|
---|
| 1184 | bkpinfo->tmpdir, 0L);
|
---|
| 1185 | for (archiving_set_no = 0; does_file_exist(archiving_filelist_fname);
|
---|
| 1186 | sprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ,
|
---|
| 1187 | bkpinfo->tmpdir, archiving_set_no)) {
|
---|
| 1188 | if (g_exiting) {
|
---|
| 1189 | fatal_error("Execution run aborted (pthread)");
|
---|
| 1190 | }
|
---|
| 1191 | if (archiving_set_no >= MAX_NOOF_SETS_HERE) {
|
---|
| 1192 | fatal_error
|
---|
| 1193 | ("Maximum number of filesets exceeded. Adjust MAX_NOOF_SETS_HERE, please.");
|
---|
| 1194 | }
|
---|
| 1195 | if (!semaphore_p()) {
|
---|
| 1196 | log_msg(3, "P sem failed (pid=%d)", (int) getpid());
|
---|
| 1197 | fatal_error("Cannot get semaphore P");
|
---|
| 1198 | }
|
---|
| 1199 | if (archiving_set_no < *p_next_set_to_archive) {
|
---|
| 1200 | archiving_set_no = *p_next_set_to_archive;
|
---|
| 1201 | }
|
---|
| 1202 | *p_next_set_to_archive = *p_next_set_to_archive + 1;
|
---|
| 1203 | if (!semaphore_v()) {
|
---|
| 1204 | fatal_error("Cannot get semaphore V");
|
---|
| 1205 | }
|
---|
[1] | 1206 |
|
---|
[128] | 1207 | /* backup this set of files */
|
---|
| 1208 | sprintf(archiving_afioball_fname, AFIOBALL_FNAME_RAW_SZ,
|
---|
| 1209 | bkpinfo->tmpdir, archiving_set_no, bkpinfo->zip_suffix);
|
---|
| 1210 | sprintf(archiving_filelist_fname, FILELIST_FNAME_RAW_SZ,
|
---|
| 1211 | bkpinfo->tmpdir, archiving_set_no);
|
---|
| 1212 | if (!does_file_exist(archiving_filelist_fname)) {
|
---|
| 1213 | log_msg(3,
|
---|
| 1214 | "%s[%d:%d] - well, I would archive %d, except that it doesn't exist. I'll stop now.",
|
---|
| 1215 | FORTY_SPACES, getpid(), this_thread_no,
|
---|
| 1216 | archiving_set_no);
|
---|
| 1217 | break;
|
---|
| 1218 | }
|
---|
[1] | 1219 |
|
---|
[128] | 1220 | sprintf(tmp, AFIOBALL_FNAME_RAW_SZ, bkpinfo->tmpdir,
|
---|
| 1221 | archiving_set_no - ARCH_BUFFER_NUM, bkpinfo->zip_suffix);
|
---|
| 1222 | if (does_file_exist(tmp)) {
|
---|
| 1223 | log_msg(4, "%s[%d:%d] - waiting for storer", FORTY_SPACES,
|
---|
| 1224 | getpid(), this_thread_no);
|
---|
| 1225 | while (does_file_exist(tmp)) {
|
---|
| 1226 | sleep(1);
|
---|
| 1227 | }
|
---|
| 1228 | log_msg(4, "[%d] - continuing", getpid());
|
---|
| 1229 | }
|
---|
[1] | 1230 |
|
---|
[128] | 1231 | log_msg(4, "%s[%d:%d] - EXATing %d...", FORTY_SPACES, getpid(),
|
---|
| 1232 | this_thread_no, archiving_set_no);
|
---|
[948] | 1233 | if (g_getfattr) {
|
---|
| 1234 | sprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
|
---|
[128] | 1235 | bkpinfo->tmpdir, archiving_set_no);
|
---|
[948] | 1236 | get_fattr_list(archiving_filelist_fname, curr_xattr_list_fname);
|
---|
| 1237 | }
|
---|
| 1238 | if (g_getfacl) {
|
---|
| 1239 | sprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
|
---|
[128] | 1240 | bkpinfo->tmpdir, archiving_set_no);
|
---|
[948] | 1241 | get_acl_list(archiving_filelist_fname, curr_acl_list_fname);
|
---|
| 1242 | }
|
---|
[1] | 1243 |
|
---|
[128] | 1244 | log_msg(4, "%s[%d:%d] - archiving %d...", FORTY_SPACES, getpid(),
|
---|
| 1245 | this_thread_no, archiving_set_no);
|
---|
| 1246 | res =
|
---|
| 1247 | archive_this_fileset(bkpinfo, archiving_filelist_fname,
|
---|
| 1248 | archiving_afioball_fname,
|
---|
| 1249 | archiving_set_no);
|
---|
| 1250 | retval += res;
|
---|
[1] | 1251 |
|
---|
[128] | 1252 | if (res) {
|
---|
| 1253 | sprintf(tmp,
|
---|
| 1254 | "Errors occurred while archiving set %ld. Please review logs.",
|
---|
| 1255 | archiving_set_no);
|
---|
| 1256 | log_to_screen(tmp);
|
---|
| 1257 | }
|
---|
| 1258 | if (!semaphore_p()) {
|
---|
| 1259 | fatal_error("Cannot get semaphore P");
|
---|
| 1260 | }
|
---|
| 1261 |
|
---|
| 1262 | set_bit_N_of_array(p_list_of_fileset_flags, archiving_set_no, 5);
|
---|
| 1263 |
|
---|
| 1264 | if (*p_last_set_archived < archiving_set_no) {
|
---|
| 1265 | *p_last_set_archived = archiving_set_no;
|
---|
| 1266 | } // finished archiving this one
|
---|
| 1267 |
|
---|
| 1268 | if (!semaphore_v()) {
|
---|
| 1269 | fatal_error("Cannot get semaphore V");
|
---|
| 1270 | }
|
---|
| 1271 | log_msg(4, "%s[%d:%d] - archived %d OK", FORTY_SPACES, getpid(),
|
---|
| 1272 | this_thread_no, archiving_set_no);
|
---|
| 1273 | archiving_set_no++;
|
---|
| 1274 | }
|
---|
| 1275 | if (!semaphore_p()) {
|
---|
| 1276 | fatal_error("Cannot get semaphore P");
|
---|
| 1277 | }
|
---|
| 1278 | (*p_archival_threads_running)--;
|
---|
| 1279 | if (!semaphore_v()) {
|
---|
| 1280 | fatal_error("Cannot get semaphore V");
|
---|
| 1281 | }
|
---|
| 1282 | log_msg(3, "%s[%d:%d] - exiting", FORTY_SPACES, getpid(),
|
---|
| 1283 | this_thread_no);
|
---|
| 1284 | paranoid_free(archiving_filelist_fname);
|
---|
| 1285 | paranoid_free(archiving_afioball_fname);
|
---|
| 1286 | paranoid_free(curr_xattr_list_fname);
|
---|
| 1287 | paranoid_free(curr_acl_list_fname);
|
---|
| 1288 | paranoid_free(tmp);
|
---|
| 1289 | pthread_exit(NULL);
|
---|
[1] | 1290 | }
|
---|
| 1291 |
|
---|
| 1292 |
|
---|
| 1293 |
|
---|
| 1294 |
|
---|
| 1295 |
|
---|
| 1296 | /**
|
---|
| 1297 | * Finalize the backup.
|
---|
| 1298 | * For streaming backups, this writes the closing block
|
---|
| 1299 | * to the stream. For CD-based backups, this creates
|
---|
| 1300 | * the final ISO image.
|
---|
| 1301 | * @param bkpinfo The backup information structure, used only
|
---|
| 1302 | * for the @c backup_media_type.
|
---|
| 1303 | * @ingroup MLarchiveGroup
|
---|
| 1304 | */
|
---|
[541] | 1305 | int do_that_final_phase(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 1306 | {
|
---|
| 1307 |
|
---|
[128] | 1308 | /*@ int ************************************** */
|
---|
| 1309 | int res = 0;
|
---|
| 1310 | int retval = 0;
|
---|
[1] | 1311 |
|
---|
[128] | 1312 | /*@ buffers ********************************** */
|
---|
[1] | 1313 |
|
---|
[128] | 1314 | assert(bkpinfo != NULL);
|
---|
| 1315 | mvaddstr_and_log_it(g_currentY, 0,
|
---|
| 1316 | "Writing any remaining data to media ");
|
---|
[1] | 1317 |
|
---|
[128] | 1318 | log_msg(1, "Closing tape/CD ... ");
|
---|
| 1319 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type))
|
---|
| 1320 | /* write tape/cdstream */
|
---|
[1] | 1321 | {
|
---|
[128] | 1322 | closeout_tape(bkpinfo);
|
---|
| 1323 | } else
|
---|
| 1324 | /* write final ISO */
|
---|
| 1325 | {
|
---|
[541] | 1326 | res = write_final_iso_if_necessary(bkpinfo);
|
---|
[128] | 1327 | retval += res;
|
---|
| 1328 | if (res) {
|
---|
| 1329 | log_msg(1, "write_final_iso_if_necessary returned an error");
|
---|
| 1330 | }
|
---|
[1] | 1331 | }
|
---|
[128] | 1332 | log_msg(2, "Fork is exiting ... ");
|
---|
[1] | 1333 |
|
---|
[128] | 1334 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
[1] | 1335 |
|
---|
[128] | 1336 | /* final stuff */
|
---|
| 1337 | if (retval) {
|
---|
| 1338 | mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
|
---|
| 1339 | } else {
|
---|
| 1340 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
| 1341 | }
|
---|
[1] | 1342 |
|
---|
[128] | 1343 | return (retval);
|
---|
[1] | 1344 | }
|
---|
| 1345 |
|
---|
| 1346 |
|
---|
| 1347 | /**
|
---|
| 1348 | * Initialize the backup.
|
---|
| 1349 | * Does the following:
|
---|
| 1350 | * - Sets up the serial number.
|
---|
| 1351 | * - For streaming backups, opens the tape stream and writes the data disks
|
---|
| 1352 | * and backup headers.
|
---|
| 1353 | * - For CD-based backups, wipes the ISOs in the target directory.
|
---|
| 1354 | *
|
---|
| 1355 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 1356 | * - @c backup_media_type
|
---|
| 1357 | * - @c cdrw_speed
|
---|
[20] | 1358 | * - @c prefix
|
---|
[1] | 1359 | * - @c isodir
|
---|
| 1360 | * - @c media_device
|
---|
| 1361 | * - @c scratchdir
|
---|
| 1362 | * - @c tmpdir
|
---|
| 1363 | * @return The number of errors encountered (0 for success).
|
---|
| 1364 | * @ingroup MLarchiveGroup
|
---|
| 1365 | */
|
---|
[128] | 1366 | int do_that_initial_phase(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 1367 | {
|
---|
[128] | 1368 | /*@ int *************************************** */
|
---|
| 1369 | int retval = 0;
|
---|
[1] | 1370 |
|
---|
[128] | 1371 | /*@ buffers *********************************** */
|
---|
| 1372 | char *command, *tmpfile, *data_disks_file;
|
---|
[1] | 1373 |
|
---|
[128] | 1374 | assert(bkpinfo != NULL);
|
---|
| 1375 | malloc_string(command);
|
---|
| 1376 | malloc_string(tmpfile);
|
---|
| 1377 | malloc_string(data_disks_file);
|
---|
| 1378 | sprintf(data_disks_file, "%s/all.tar.gz", bkpinfo->tmpdir);
|
---|
| 1379 |
|
---|
| 1380 | snprintf(g_serial_string, MAX_STR_LEN - 1,
|
---|
| 1381 | call_program_and_get_last_line_of_output("dd \
|
---|
[1] | 1382 | if=/dev/urandom bs=16 count=1 2> /dev/null | \
|
---|
| 1383 | hexdump | tr -s ' ' '0' | head -n1"));
|
---|
[128] | 1384 | strip_spaces(g_serial_string);
|
---|
| 1385 | strcat(g_serial_string, "...word.");
|
---|
| 1386 | log_msg(2, "g_serial_string = '%s'", g_serial_string);
|
---|
| 1387 | assert(strlen(g_serial_string) < MAX_STR_LEN);
|
---|
[1] | 1388 |
|
---|
[128] | 1389 | sprintf(tmpfile, "%s/archives/SERIAL-STRING", bkpinfo->scratchdir);
|
---|
| 1390 | if (write_one_liner_data_file(tmpfile, g_serial_string)) {
|
---|
| 1391 | log_msg(1, "%ld: Failed to write serial string", __LINE__);
|
---|
| 1392 | }
|
---|
[1] | 1393 |
|
---|
[128] | 1394 | mvaddstr_and_log_it(g_currentY, 0, "Preparing to archive your data");
|
---|
| 1395 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 1396 | if (bkpinfo->backup_media_type == cdstream) {
|
---|
| 1397 | openout_cdstream(bkpinfo->media_device, bkpinfo->cdrw_speed);
|
---|
| 1398 | } else {
|
---|
| 1399 | openout_tape(bkpinfo->media_device, bkpinfo->internal_tape_block_size); /* sets g_tape_stream */
|
---|
| 1400 | }
|
---|
| 1401 | if (!g_tape_stream) {
|
---|
| 1402 | fatal_error("Cannot open backup (streaming) device");
|
---|
| 1403 | }
|
---|
| 1404 | log_msg(1, "Backup (stream) opened OK");
|
---|
| 1405 | write_data_disks_to_stream(data_disks_file);
|
---|
| 1406 | } else {
|
---|
| 1407 | log_msg(1, "Backing up to CD's");
|
---|
[1] | 1408 | }
|
---|
| 1409 |
|
---|
[128] | 1410 | sprintf(command, "rm -f %s/%s/%s-[1-9]*.iso", bkpinfo->isodir,
|
---|
| 1411 | bkpinfo->nfs_remote_dir, bkpinfo->prefix);
|
---|
| 1412 | paranoid_system(command);
|
---|
| 1413 | wipe_archives(bkpinfo->scratchdir);
|
---|
| 1414 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
| 1415 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
[684] | 1416 | write_header_block_to_stream((off_t)0, "start-of-tape",
|
---|
[128] | 1417 | BLK_START_OF_TAPE);
|
---|
[684] | 1418 | write_header_block_to_stream((off_t)0, "start-of-backup",
|
---|
[128] | 1419 | BLK_START_OF_BACKUP);
|
---|
| 1420 | }
|
---|
| 1421 | paranoid_free(command);
|
---|
| 1422 | paranoid_free(tmpfile);
|
---|
| 1423 | paranoid_free(data_disks_file);
|
---|
| 1424 | return (retval);
|
---|
[1] | 1425 | }
|
---|
| 1426 |
|
---|
| 1427 |
|
---|
| 1428 | /**
|
---|
| 1429 | * Calls floppy-formatting @c cmd and tracks its progress if possible.
|
---|
| 1430 | *
|
---|
| 1431 | * @param cmd The command to run (e.g. @c fdformat @c /dev/fd0).
|
---|
| 1432 | * @param title The human-friendly description of the floppy you are writing.
|
---|
| 1433 | * This will be used as the title in the progress bar window. Example:
|
---|
| 1434 | * "Formatting disk /dev/fd0".
|
---|
| 1435 | * @see format_disk
|
---|
| 1436 | * @return The exit code of fdformat/superformat.
|
---|
| 1437 | */
|
---|
[128] | 1438 | int format_disk_SUB(char *cmd, char *title)
|
---|
[1] | 1439 | {
|
---|
| 1440 |
|
---|
[128] | 1441 | /*@ int *************************************************************** */
|
---|
| 1442 | int res = 0;
|
---|
[1] | 1443 | int percentage = 0;
|
---|
| 1444 | int maxtracks = 0;
|
---|
| 1445 | int trackno = 0;
|
---|
| 1446 | int last_trkno = 0;
|
---|
| 1447 |
|
---|
[128] | 1448 | /*@ buffers *********************************************************** */
|
---|
| 1449 | char *command;
|
---|
| 1450 | char *tempfile;
|
---|
[1] | 1451 |
|
---|
[128] | 1452 | /*@ pointers ********************************************************** */
|
---|
| 1453 | FILE *pin;
|
---|
[1] | 1454 |
|
---|
[128] | 1455 | assert_string_is_neither_NULL_nor_zerolength(cmd);
|
---|
| 1456 | assert_string_is_neither_NULL_nor_zerolength(title);
|
---|
[1] | 1457 |
|
---|
[128] | 1458 | malloc_string(command);
|
---|
| 1459 | malloc_string(tempfile);
|
---|
[1] | 1460 | #ifdef __FreeBSD__
|
---|
| 1461 | /* Ugh. FreeBSD fdformat prints out this pretty progress indicator that's
|
---|
| 1462 | impossible to parse. It looks like
|
---|
| 1463 | VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVF-------------------
|
---|
| 1464 | where V means verified, E means error, F means formatted, and - means
|
---|
| 1465 | not done yet.
|
---|
| 1466 | */
|
---|
[128] | 1467 | return (run_program_and_log_to_screen(cmd, title));
|
---|
[1] | 1468 | #endif
|
---|
| 1469 |
|
---|
| 1470 | /* if Debian then do bog-standard superformat; don't be pretty */
|
---|
[128] | 1471 | if (strstr(cmd, "superformat")) {
|
---|
| 1472 | return (run_program_and_log_to_screen(cmd, title));
|
---|
| 1473 | }
|
---|
[1] | 1474 | /* if not Debian then go ahead & use fdformat */
|
---|
[128] | 1475 | strcpy(tempfile,
|
---|
| 1476 | call_program_and_get_last_line_of_output
|
---|
| 1477 | ("mktemp -q /tmp/mondo.XXXXXXXX"));
|
---|
| 1478 | sprintf(command, "%s >> %s 2>> %s; rm -f %s", cmd, tempfile, tempfile,
|
---|
| 1479 | tempfile);
|
---|
| 1480 | log_msg(3, command);
|
---|
| 1481 | open_evalcall_form(title);
|
---|
| 1482 | if (!(pin = popen(command, "r"))) {
|
---|
| 1483 | log_OS_error("fmt err");
|
---|
| 1484 | return (1);
|
---|
[1] | 1485 | }
|
---|
[128] | 1486 | if (strstr(command, "1722")) {
|
---|
| 1487 | maxtracks = 82;
|
---|
| 1488 | } else {
|
---|
| 1489 | maxtracks = 80;
|
---|
[1] | 1490 | }
|
---|
[128] | 1491 | for (sleep(1); does_file_exist(tempfile); sleep(1)) {
|
---|
| 1492 | trackno = get_trackno_from_logfile(tempfile);
|
---|
| 1493 | if (trackno < 0 || trackno > 80) {
|
---|
| 1494 | log_msg(1, "Weird track#");
|
---|
| 1495 | continue;
|
---|
| 1496 | }
|
---|
| 1497 | percentage = trackno * 100 / maxtracks;
|
---|
| 1498 | if (trackno <= 5 && last_trkno > 40) {
|
---|
| 1499 | close_evalcall_form();
|
---|
| 1500 | strcpy(title, "Verifying format");
|
---|
| 1501 | open_evalcall_form(title);
|
---|
| 1502 | }
|
---|
| 1503 | last_trkno = trackno;
|
---|
| 1504 | update_evalcall_form(percentage);
|
---|
| 1505 | }
|
---|
| 1506 | close_evalcall_form();
|
---|
| 1507 | if (pclose(pin)) {
|
---|
| 1508 | res++;
|
---|
| 1509 | log_OS_error("Unable to pclose");
|
---|
| 1510 | }
|
---|
| 1511 | unlink(tempfile);
|
---|
| 1512 | paranoid_free(command);
|
---|
| 1513 | paranoid_free(tempfile);
|
---|
| 1514 | return (res);
|
---|
[1] | 1515 | }
|
---|
| 1516 |
|
---|
| 1517 | /**
|
---|
| 1518 | * Wrapper around @c format_disk_SUB().
|
---|
| 1519 | * This function calls @c format_disk_SUB() with a @c device of its @c device
|
---|
| 1520 | * parameter and a @c title of Formatting disk @c device. If the format
|
---|
| 1521 | * fails, the user will be given the option of retrying.
|
---|
| 1522 | *
|
---|
| 1523 | * @param device The floppy drive to write to.
|
---|
| 1524 | * @see format_disk_SUB
|
---|
| 1525 | * @return The exit code of fdformat/superformat.
|
---|
| 1526 | * @ingroup deviceGroup
|
---|
| 1527 | */
|
---|
[128] | 1528 | int format_disk(char *device)
|
---|
[1] | 1529 | {
|
---|
| 1530 |
|
---|
[128] | 1531 | /*@ int ************************************************************** */
|
---|
| 1532 | int res = 0;
|
---|
[1] | 1533 |
|
---|
[128] | 1534 | /*@ buffer *********************************************************** */
|
---|
| 1535 | char *command;
|
---|
| 1536 | char *title;
|
---|
| 1537 |
|
---|
| 1538 |
|
---|
| 1539 | assert_string_is_neither_NULL_nor_zerolength(device);
|
---|
| 1540 | malloc_string(title);
|
---|
| 1541 | command = malloc(1000);
|
---|
| 1542 | if (!system("which superformat > /dev/null 2> /dev/null")) {
|
---|
| 1543 | sprintf(command, "superformat %s", device);
|
---|
| 1544 | } else {
|
---|
[1] | 1545 | #ifdef __FreeBSD__
|
---|
[128] | 1546 | sprintf(command, "fdformat -y %s", device);
|
---|
[1] | 1547 | #else
|
---|
[128] | 1548 | sprintf(command, "fdformat %s", device);
|
---|
[1] | 1549 | #endif
|
---|
| 1550 | }
|
---|
[128] | 1551 | sprintf(title, "Formatting disk %s", device);
|
---|
| 1552 | while ((res = format_disk_SUB(command, title))) {
|
---|
| 1553 | if (!ask_me_yes_or_no("Failed to format disk. Retry?")) {
|
---|
| 1554 | return (res);
|
---|
| 1555 | }
|
---|
| 1556 | }
|
---|
| 1557 | paranoid_free(title);
|
---|
| 1558 | paranoid_free(command);
|
---|
| 1559 | return (res);
|
---|
[1] | 1560 | }
|
---|
| 1561 |
|
---|
| 1562 | /**
|
---|
| 1563 | * Get the <tt>N</tt>th bit of @c array.
|
---|
| 1564 | * @param array The bit-array (as a @c char pointer).
|
---|
| 1565 | * @param N The number of the bit you want.
|
---|
| 1566 | * @return TRUE (bit is set) or FALSE (bit is not set).
|
---|
| 1567 | * @see set_bit_N_of_array
|
---|
| 1568 | * @ingroup utilityGroup
|
---|
| 1569 | */
|
---|
[128] | 1570 | bool get_bit_N_of_array(char *array, int N)
|
---|
[1] | 1571 | {
|
---|
[128] | 1572 | int element_number;
|
---|
| 1573 | int bit_number;
|
---|
| 1574 | int mask;
|
---|
| 1575 |
|
---|
| 1576 | element_number = N / 8;
|
---|
| 1577 | bit_number = N % 8;
|
---|
| 1578 | mask = 1 << bit_number;
|
---|
| 1579 | if (array[element_number] & mask) {
|
---|
| 1580 | return (TRUE);
|
---|
| 1581 | } else {
|
---|
| 1582 | return (FALSE);
|
---|
| 1583 | }
|
---|
[1] | 1584 | }
|
---|
| 1585 |
|
---|
| 1586 |
|
---|
| 1587 |
|
---|
| 1588 |
|
---|
| 1589 |
|
---|
| 1590 |
|
---|
| 1591 |
|
---|
| 1592 |
|
---|
| 1593 |
|
---|
| 1594 | /**
|
---|
| 1595 | * @addtogroup LLarchiveGroup
|
---|
| 1596 | * @{
|
---|
| 1597 | */
|
---|
| 1598 | /**
|
---|
| 1599 | * Start up threads to archive your files.
|
---|
| 1600 | *
|
---|
| 1601 | * This function starts @c ARCH_THREADS threads,
|
---|
| 1602 | * each starting execution in @c create_afio_files_in_background().
|
---|
| 1603 | * Each thread will archive individual filesets, based on the
|
---|
| 1604 | * pointers passed to it and continually updated, until all files
|
---|
| 1605 | * have been backed up. This function coordinates the threads
|
---|
| 1606 | * and copies their output to the @c scratchdir.
|
---|
| 1607 | *
|
---|
| 1608 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 1609 | * - @c backup_media_type
|
---|
| 1610 | * - @c scratchdir
|
---|
| 1611 | * - @c tmpdir
|
---|
| 1612 | * - @c zip_suffix
|
---|
| 1613 | *
|
---|
| 1614 | * @return The number of errors encountered (0 for success)
|
---|
| 1615 | */
|
---|
[541] | 1616 | int make_afioballs_and_images(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 1617 | {
|
---|
| 1618 |
|
---|
[128] | 1619 | /*@ int ************************************************** */
|
---|
| 1620 | int retval = 0;
|
---|
| 1621 | long int storing_set_no = 0;
|
---|
| 1622 | int res = 0;
|
---|
| 1623 | bool done_storing = FALSE;
|
---|
| 1624 | char *result_str;
|
---|
| 1625 | char *transfer_block;
|
---|
| 1626 | void *vp;
|
---|
| 1627 | void **pvp;
|
---|
[1] | 1628 |
|
---|
[128] | 1629 | /*@ buffers ********************************************** */
|
---|
| 1630 | char *storing_filelist_fname;
|
---|
| 1631 | char *storing_afioball_fname;
|
---|
| 1632 | char *tmp;
|
---|
| 1633 | char *media_usage_comment;
|
---|
| 1634 | pthread_t archival_thread[ARCH_THREADS];
|
---|
| 1635 | char *p_list_of_fileset_flags;
|
---|
| 1636 | int *p_archival_threads_running;
|
---|
| 1637 | int *p_last_set_archived;
|
---|
| 1638 | int *p_next_set_to_archive;
|
---|
| 1639 | int noof_threads;
|
---|
| 1640 | int i;
|
---|
[948] | 1641 | char *curr_xattr_list_fname = NULL;
|
---|
[128] | 1642 | char *curr_acl_list_fname;
|
---|
| 1643 | int misc_counter_that_is_not_important = 0;
|
---|
[1] | 1644 |
|
---|
[128] | 1645 | log_msg(8, "here");
|
---|
| 1646 | assert(bkpinfo != NULL);
|
---|
| 1647 | tmp = malloc(MAX_STR_LEN * 2);
|
---|
| 1648 | malloc_string(result_str);
|
---|
| 1649 | malloc_string(curr_xattr_list_fname);
|
---|
| 1650 | malloc_string(curr_acl_list_fname);
|
---|
| 1651 | malloc_string(storing_filelist_fname);
|
---|
| 1652 | malloc_string(media_usage_comment);
|
---|
| 1653 | malloc_string(storing_afioball_fname);
|
---|
| 1654 | transfer_block =
|
---|
| 1655 | malloc(sizeof(struct s_bkpinfo) + BKPINFO_LOC_OFFSET + 64);
|
---|
| 1656 | memset((void *) transfer_block, 0,
|
---|
| 1657 | sizeof(struct s_bkpinfo) + BKPINFO_LOC_OFFSET + 64);
|
---|
| 1658 | p_last_set_archived = (int *) transfer_block;
|
---|
| 1659 | p_archival_threads_running = (int *) (transfer_block + 4);
|
---|
| 1660 | p_next_set_to_archive = (int *) (transfer_block + 8);
|
---|
| 1661 | p_list_of_fileset_flags = (char *) (transfer_block + 12);
|
---|
| 1662 | memcpy((void *) (transfer_block + BKPINFO_LOC_OFFSET),
|
---|
| 1663 | (void *) bkpinfo, sizeof(struct s_bkpinfo));
|
---|
| 1664 | pvp = &vp;
|
---|
| 1665 | vp = (void *) result_str;
|
---|
| 1666 | *p_archival_threads_running = 0;
|
---|
| 1667 | *p_last_set_archived = -1;
|
---|
| 1668 | *p_next_set_to_archive = 0;
|
---|
| 1669 | sprintf(tmp, "%s/archives/filelist.full", bkpinfo->scratchdir);
|
---|
| 1670 | log_to_screen("Archiving regular files");
|
---|
| 1671 | log_msg(5, "Go, Shorty. It's your birthday.");
|
---|
[541] | 1672 | open_progress_form("Backing up filesystem",
|
---|
| 1673 | "I am backing up your live filesystem now.",
|
---|
| 1674 | "Please wait. This may take a couple of hours.",
|
---|
| 1675 | "Working...",
|
---|
[128] | 1676 | get_last_filelist_number(bkpinfo) + 1);
|
---|
[1] | 1677 |
|
---|
[128] | 1678 | log_msg(5, "We're gonna party like it's your birthday.");
|
---|
[1] | 1679 |
|
---|
[128] | 1680 | srand((unsigned int) getpid());
|
---|
| 1681 | g_sem_key = 1234 + random() % 30000;
|
---|
| 1682 | if ((g_sem_id =
|
---|
| 1683 | semget((key_t) g_sem_key, 1,
|
---|
| 1684 | IPC_CREAT | S_IREAD | S_IWRITE)) == -1) {
|
---|
| 1685 | fatal_error("MABAI - unable to semget");
|
---|
[1] | 1686 | }
|
---|
[128] | 1687 | if (!set_semvalue()) {
|
---|
| 1688 | fatal_error("Unable to init semaphore");
|
---|
| 1689 | } // initialize semaphore
|
---|
| 1690 | for (noof_threads = 0; noof_threads < ARCH_THREADS; noof_threads++) {
|
---|
| 1691 | log_msg(8, "Creating thread #%d", noof_threads);
|
---|
| 1692 | (*p_archival_threads_running)++;
|
---|
| 1693 | if ((res =
|
---|
| 1694 | pthread_create(&archival_thread[noof_threads], NULL,
|
---|
| 1695 | create_afio_files_in_background,
|
---|
| 1696 | (void *) transfer_block))) {
|
---|
| 1697 | fatal_error("Unable to create an archival thread");
|
---|
| 1698 | }
|
---|
[1] | 1699 | }
|
---|
| 1700 |
|
---|
[128] | 1701 | log_msg(8, "About to enter while() loop");
|
---|
| 1702 | while (!done_storing) {
|
---|
| 1703 | if (g_exiting) {
|
---|
| 1704 | fatal_error("Execution run aborted (main loop)");
|
---|
| 1705 | }
|
---|
| 1706 | if (*p_archival_threads_running == 0
|
---|
| 1707 | && *p_last_set_archived == storing_set_no - 1) {
|
---|
| 1708 | log_msg(2,
|
---|
| 1709 | "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... :-)",
|
---|
| 1710 | *p_last_set_archived, storing_set_no);
|
---|
| 1711 | done_storing = TRUE;
|
---|
| 1712 | } else
|
---|
| 1713 | if (!get_bit_N_of_array
|
---|
| 1714 | (p_list_of_fileset_flags, storing_set_no)) {
|
---|
| 1715 | misc_counter_that_is_not_important =
|
---|
| 1716 | (misc_counter_that_is_not_important + 1) % 5;
|
---|
| 1717 | if (!misc_counter_that_is_not_important) {
|
---|
| 1718 | update_progress_form(media_usage_comment);
|
---|
| 1719 | }
|
---|
| 1720 | sleep(1);
|
---|
| 1721 | } else
|
---|
| 1722 | // store set N
|
---|
| 1723 | {
|
---|
| 1724 | sprintf(storing_filelist_fname, FILELIST_FNAME_RAW_SZ,
|
---|
| 1725 | bkpinfo->tmpdir, storing_set_no);
|
---|
| 1726 | sprintf(storing_afioball_fname, AFIOBALL_FNAME_RAW_SZ,
|
---|
| 1727 | bkpinfo->tmpdir, storing_set_no, bkpinfo->zip_suffix);
|
---|
[948] | 1728 | if (g_getfattr) {
|
---|
| 1729 | sprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
|
---|
[128] | 1730 | bkpinfo->tmpdir, storing_set_no);
|
---|
[948] | 1731 | }
|
---|
| 1732 | if (g_getfacl) {
|
---|
| 1733 | sprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
|
---|
[128] | 1734 | bkpinfo->tmpdir, storing_set_no);
|
---|
[948] | 1735 | }
|
---|
[128] | 1736 |
|
---|
| 1737 | log_msg(2, "Storing set %d", storing_set_no);
|
---|
| 1738 | while (!does_file_exist(storing_filelist_fname)
|
---|
| 1739 | || !does_file_exist(storing_afioball_fname)) {
|
---|
| 1740 | log_msg(2,
|
---|
| 1741 | "Warning - either %s or %s doesn't exist yet. I'll pause 5 secs.",
|
---|
| 1742 | storing_filelist_fname, storing_afioball_fname);
|
---|
| 1743 | sleep(5);
|
---|
| 1744 | }
|
---|
| 1745 | strcpy(media_usage_comment,
|
---|
| 1746 | percent_media_full_comment(bkpinfo));
|
---|
| 1747 | /* copy to CD (scratchdir) ... and an actual CD-R if necessary */
|
---|
| 1748 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 1749 | register_in_tape_catalog(fileset, storing_set_no, -1,
|
---|
| 1750 | storing_afioball_fname);
|
---|
| 1751 | maintain_collection_of_recent_archives(bkpinfo->tmpdir,
|
---|
| 1752 | storing_afioball_fname);
|
---|
| 1753 | iamhere("Writing EXAT files");
|
---|
| 1754 | res +=
|
---|
| 1755 | write_EXAT_files_to_tape(bkpinfo,
|
---|
| 1756 | curr_xattr_list_fname,
|
---|
| 1757 | curr_acl_list_fname);
|
---|
[1] | 1758 | // archives themselves
|
---|
[128] | 1759 | res +=
|
---|
| 1760 | move_files_to_stream(bkpinfo, storing_afioball_fname,
|
---|
| 1761 | NULL);
|
---|
| 1762 | } else {
|
---|
[948] | 1763 | if (g_getfacl) {
|
---|
| 1764 | if (g_getfattr) {
|
---|
| 1765 | res = move_files_to_cd(bkpinfo, storing_filelist_fname,
|
---|
[128] | 1766 | curr_xattr_list_fname,
|
---|
| 1767 | curr_acl_list_fname,
|
---|
| 1768 | storing_afioball_fname, NULL);
|
---|
[948] | 1769 | } else {
|
---|
| 1770 | res = move_files_to_cd(bkpinfo, storing_filelist_fname,
|
---|
| 1771 | curr_acl_list_fname,
|
---|
| 1772 | storing_afioball_fname, NULL);
|
---|
| 1773 | }
|
---|
| 1774 | } else {
|
---|
| 1775 | if (g_getfattr) {
|
---|
| 1776 | res = move_files_to_cd(bkpinfo, storing_filelist_fname,
|
---|
| 1777 | curr_xattr_list_fname,
|
---|
| 1778 | storing_afioball_fname, NULL);
|
---|
| 1779 | } else {
|
---|
| 1780 | res = move_files_to_cd(bkpinfo, storing_filelist_fname,
|
---|
| 1781 | storing_afioball_fname, NULL);
|
---|
| 1782 | }
|
---|
| 1783 | }
|
---|
[128] | 1784 | }
|
---|
| 1785 | retval += res;
|
---|
| 1786 | g_current_progress++;
|
---|
| 1787 | update_progress_form(media_usage_comment);
|
---|
| 1788 | if (res) {
|
---|
| 1789 | sprintf(tmp,
|
---|
| 1790 | "Failed to add archive %ld's files to CD dir\n",
|
---|
| 1791 | storing_set_no);
|
---|
| 1792 | log_to_screen(tmp);
|
---|
| 1793 | fatal_error
|
---|
| 1794 | ("Is your hard disk full? If not, please send the author the logfile.");
|
---|
| 1795 | }
|
---|
| 1796 | storing_set_no++;
|
---|
| 1797 | // sleep(2);
|
---|
[1] | 1798 | }
|
---|
| 1799 | }
|
---|
[128] | 1800 | close_progress_form();
|
---|
[1] | 1801 |
|
---|
[128] | 1802 | sprintf(tmp, "Your regular files have been archived ");
|
---|
| 1803 | log_msg(2, "Joining background threads to foreground thread");
|
---|
| 1804 | for (i = 0; i < noof_threads; i++) {
|
---|
| 1805 | pthread_join(archival_thread[i], pvp);
|
---|
| 1806 | log_msg(3, "Thread %d of %d: closed OK", i + 1, noof_threads);
|
---|
| 1807 | }
|
---|
| 1808 | del_semvalue();
|
---|
| 1809 | log_msg(2, "Done.");
|
---|
| 1810 | if (retval) {
|
---|
| 1811 | strcat(tmp, "(with errors).");
|
---|
| 1812 | } else {
|
---|
| 1813 | strcat(tmp, "successfully.");
|
---|
| 1814 | }
|
---|
| 1815 | log_to_screen(tmp);
|
---|
| 1816 | paranoid_free(transfer_block);
|
---|
| 1817 | paranoid_free(result_str);
|
---|
| 1818 | paranoid_free(storing_filelist_fname);
|
---|
| 1819 | paranoid_free(media_usage_comment);
|
---|
| 1820 | paranoid_free(storing_afioball_fname);
|
---|
| 1821 | paranoid_free(curr_xattr_list_fname);
|
---|
| 1822 | paranoid_free(curr_acl_list_fname);
|
---|
| 1823 | return (retval);
|
---|
[1] | 1824 | }
|
---|
| 1825 |
|
---|
| 1826 |
|
---|
[128] | 1827 | void pause_for_N_seconds(int how_long, char *msg)
|
---|
[1] | 1828 | {
|
---|
[128] | 1829 | int i;
|
---|
| 1830 | open_evalcall_form(msg);
|
---|
| 1831 | for (i = 0; i < how_long; i++) {
|
---|
| 1832 | update_evalcall_form((int) ((100.0 / (float) (how_long) * i)));
|
---|
| 1833 | sleep(1);
|
---|
| 1834 | }
|
---|
| 1835 | close_evalcall_form();
|
---|
[1] | 1836 | }
|
---|
| 1837 |
|
---|
| 1838 |
|
---|
| 1839 |
|
---|
| 1840 |
|
---|
| 1841 | /**
|
---|
| 1842 | * Create an ISO image in @c destfile, from files in @c bkpinfo->scratchdir.
|
---|
| 1843 | *
|
---|
| 1844 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 1845 | * - @c backup_media_type
|
---|
| 1846 | * - @c call_after_iso
|
---|
| 1847 | * - @c call_before_iso
|
---|
| 1848 | * - @c call_burn_iso
|
---|
| 1849 | * - @c call_make_iso
|
---|
| 1850 | * - @c make_cd_use_lilo
|
---|
| 1851 | * - @c manual_cd_tray
|
---|
| 1852 | * - @c nonbootable_backup
|
---|
| 1853 | * - @c scratchdir
|
---|
| 1854 | *
|
---|
| 1855 | * @param destfile Where to put the generated ISO image.
|
---|
| 1856 | * @return The number of errors encountered (0 for success)
|
---|
| 1857 | */
|
---|
[541] | 1858 | int make_iso_fs(struct s_bkpinfo *bkpinfo, char *destfile)
|
---|
[1] | 1859 | {
|
---|
[128] | 1860 | /*@ int ********************************************** */
|
---|
| 1861 | int retval = 0;
|
---|
| 1862 | int res;
|
---|
[1] | 1863 |
|
---|
[128] | 1864 | /*@ buffers ****************************************** */
|
---|
| 1865 | char *tmp;
|
---|
| 1866 | char *old_pwd;
|
---|
| 1867 | char *result_sz;
|
---|
| 1868 | char *message_to_screen;
|
---|
| 1869 | char *sz_blank_disk;
|
---|
| 1870 | char *fnam;
|
---|
| 1871 | char *tmp2;
|
---|
| 1872 | char *tmp3;
|
---|
| 1873 | bool cd_is_mountable;
|
---|
[1] | 1874 |
|
---|
[128] | 1875 | malloc_string(old_pwd);
|
---|
| 1876 | malloc_string(result_sz);
|
---|
| 1877 | malloc_string(message_to_screen);
|
---|
| 1878 | malloc_string(sz_blank_disk);
|
---|
| 1879 | malloc_string(fnam);
|
---|
| 1880 | tmp = malloc(1200);
|
---|
| 1881 | tmp2 = malloc(1200);
|
---|
| 1882 | tmp3 = malloc(1200);
|
---|
| 1883 | assert(bkpinfo != NULL);
|
---|
| 1884 | assert_string_is_neither_NULL_nor_zerolength(destfile);
|
---|
[1] | 1885 |
|
---|
[128] | 1886 | sprintf(tmp, "%s/isolinux.bin", bkpinfo->scratchdir);
|
---|
| 1887 | sprintf(tmp2, "%s/isolinux.bin", bkpinfo->tmpdir);
|
---|
| 1888 | if (does_file_exist(tmp)) {
|
---|
| 1889 | sprintf(tmp3, "cp -f %s %s", tmp, tmp2);
|
---|
| 1890 | paranoid_system(tmp3);
|
---|
[1] | 1891 | }
|
---|
[128] | 1892 | if (!does_file_exist(tmp) && does_file_exist(tmp2)) {
|
---|
| 1893 | sprintf(tmp3, "cp -f %s %s", tmp2, tmp);
|
---|
| 1894 | paranoid_system(tmp3);
|
---|
[1] | 1895 | }
|
---|
[128] | 1896 | /*
|
---|
| 1897 | if (!does_file_exist(tmp))
|
---|
| 1898 | {
|
---|
| 1899 | log_msg (2, "Silly bug in Mindi.pl; workaround in progress...");
|
---|
| 1900 | strcpy(fnam, call_program_and_get_last_line_of_output("locate isolinux.bin | tail -n1"));
|
---|
| 1901 | if (strlen(fnam)>0 && does_file_exist(fnam))
|
---|
| 1902 | {
|
---|
| 1903 | sprintf(tmp, "cp -f %s %s", fnam, bkpinfo->scratchdir);
|
---|
| 1904 | res = run_program_and_log_output(tmp, FALSE);
|
---|
| 1905 | }
|
---|
| 1906 | else
|
---|
| 1907 | {
|
---|
| 1908 | res = 1;
|
---|
| 1909 | }
|
---|
| 1910 | if (res)
|
---|
| 1911 | {
|
---|
| 1912 | log_msg (2, "Could not work around silly bug in Mindi.pl - sorry! Isolinux.bin missing");
|
---|
| 1913 | }
|
---|
| 1914 | }
|
---|
| 1915 | */
|
---|
| 1916 | free(tmp2);
|
---|
| 1917 | free(tmp3);
|
---|
| 1918 | tmp2 = NULL;
|
---|
| 1919 | tmp3 = NULL;
|
---|
| 1920 | if (bkpinfo->backup_media_type == iso && bkpinfo->manual_cd_tray) {
|
---|
[541] | 1921 | popup_and_OK("Please insert new media and press Enter.");
|
---|
[128] | 1922 | }
|
---|
[1] | 1923 |
|
---|
[128] | 1924 | log_msg(2, "make_iso_fs --- scratchdir=%s --- destfile=%s",
|
---|
| 1925 | bkpinfo->scratchdir, destfile);
|
---|
| 1926 | (void) getcwd(old_pwd, MAX_STR_LEN - 1);
|
---|
| 1927 | sprintf(tmp, "chmod 744 %s", bkpinfo->scratchdir);
|
---|
| 1928 | run_program_and_log_output(tmp, FALSE);
|
---|
| 1929 | chdir(bkpinfo->scratchdir);
|
---|
[1] | 1930 |
|
---|
[128] | 1931 | if (bkpinfo->call_before_iso[0] != '\0') {
|
---|
| 1932 | sprintf(message_to_screen, "Running pre-ISO call for CD#%d",
|
---|
| 1933 | g_current_media_number);
|
---|
| 1934 | res =
|
---|
| 1935 | eval_call_to_make_ISO(bkpinfo, bkpinfo->call_before_iso,
|
---|
| 1936 | destfile, g_current_media_number,
|
---|
| 1937 | MONDO_LOGFILE, message_to_screen);
|
---|
| 1938 | if (res) {
|
---|
| 1939 | strcat(message_to_screen, "...failed");
|
---|
| 1940 | } else {
|
---|
| 1941 | strcat(message_to_screen, "...OK");
|
---|
| 1942 | }
|
---|
| 1943 | log_to_screen(message_to_screen);
|
---|
| 1944 | retval += res;
|
---|
[1] | 1945 | }
|
---|
| 1946 |
|
---|
[128] | 1947 | if (bkpinfo->call_make_iso[0] != '\0') {
|
---|
| 1948 | log_msg(2, "bkpinfo->call_make_iso = %s", bkpinfo->call_make_iso);
|
---|
| 1949 | sprintf(tmp, "%s/archives/NOT-THE-LAST", bkpinfo->scratchdir);
|
---|
| 1950 | sprintf(message_to_screen, "Making an ISO (%s #%d)",
|
---|
| 1951 | media_descriptor_string(bkpinfo->backup_media_type),
|
---|
| 1952 | g_current_media_number);
|
---|
[1] | 1953 |
|
---|
[128] | 1954 | pause_and_ask_for_cdr(2, &cd_is_mountable); /* if g_current_media_number >= 2 then pause & ask */
|
---|
| 1955 | if (retval) {
|
---|
| 1956 | log_to_screen
|
---|
| 1957 | ("Serious error(s) occurred already. I shan't try to write to media.");
|
---|
| 1958 | } else {
|
---|
| 1959 | res =
|
---|
| 1960 | eval_call_to_make_ISO(bkpinfo, bkpinfo->call_make_iso,
|
---|
| 1961 | bkpinfo->scratchdir,
|
---|
| 1962 | g_current_media_number,
|
---|
| 1963 | MONDO_LOGFILE, message_to_screen);
|
---|
| 1964 | if (res) {
|
---|
| 1965 | log_to_screen("%s...failed to write", message_to_screen);
|
---|
| 1966 | } else {
|
---|
| 1967 | log_to_screen("%s...OK", message_to_screen);
|
---|
[1315] | 1968 | sprintf(tmp, "tail -n10 %s | grep -F ':-('", MONDO_LOGFILE);
|
---|
| 1969 | if (!run_program_and_log_output(tmp, 1)) {
|
---|
[128] | 1970 | log_to_screen
|
---|
| 1971 | ("Despite nonfatal errors, growisofs confirms the write was successful.");
|
---|
| 1972 | }
|
---|
| 1973 | }
|
---|
| 1974 | retval += res;
|
---|
[1] | 1975 | #ifdef DVDRWFORMAT
|
---|
[128] | 1976 | sprintf(tmp,
|
---|
| 1977 | "tail -n8 %s | grep 'blank=full.*dvd-compat.*DAO'",
|
---|
| 1978 | MONDO_LOGFILE);
|
---|
| 1979 | if (g_backup_media_type == dvd
|
---|
| 1980 | && (res || !run_program_and_log_output(tmp, 1))) {
|
---|
| 1981 | log_to_screen
|
---|
| 1982 | ("Failed to write to disk. I shall blank it and then try again.");
|
---|
| 1983 | sleep(5);
|
---|
| 1984 | system("sync");
|
---|
| 1985 | pause_for_N_seconds(5, "Letting DVD drive settle");
|
---|
[1] | 1986 |
|
---|
| 1987 | // dvd+rw-format --- OPTION 2
|
---|
[128] | 1988 | if (!bkpinfo->please_dont_eject) {
|
---|
| 1989 | log_to_screen("Ejecting media to clear drive status.");
|
---|
| 1990 | eject_device(bkpinfo->media_device);
|
---|
| 1991 | inject_device(bkpinfo->media_device);
|
---|
| 1992 | }
|
---|
| 1993 | pause_for_N_seconds(5, "Letting DVD drive settle");
|
---|
[908] | 1994 | sprintf(sz_blank_disk, "dvd+rw-format -force %s",
|
---|
[128] | 1995 | bkpinfo->media_device);
|
---|
| 1996 | log_msg(3, "sz_blank_disk = '%s'", sz_blank_disk);
|
---|
| 1997 | res =
|
---|
| 1998 | run_external_binary_with_percentage_indicator_NEW
|
---|
| 1999 | ("Blanking DVD disk", sz_blank_disk);
|
---|
| 2000 | if (res) {
|
---|
| 2001 | log_to_screen
|
---|
| 2002 | ("Warning - format failed. (Was it a DVD-R?) Sleeping for 5 seconds to take a breath...");
|
---|
| 2003 | pause_for_N_seconds(5,
|
---|
| 2004 | "Letting DVD drive settle... and trying again.");
|
---|
| 2005 | res =
|
---|
| 2006 | run_external_binary_with_percentage_indicator_NEW
|
---|
| 2007 | ("Blanking DVD disk", sz_blank_disk);
|
---|
| 2008 | if (res) {
|
---|
| 2009 | log_to_screen("Format failed a second time.");
|
---|
| 2010 | }
|
---|
| 2011 | } else {
|
---|
| 2012 | log_to_screen
|
---|
| 2013 | ("Format succeeded. Sleeping for 5 seconds to take a breath...");
|
---|
| 2014 | }
|
---|
| 2015 | pause_for_N_seconds(5, "Letting DVD drive settle");
|
---|
| 2016 | if (!bkpinfo->please_dont_eject) {
|
---|
| 2017 | log_to_screen("Ejecting media to clear drive status.");
|
---|
| 2018 | eject_device(bkpinfo->media_device);
|
---|
| 2019 | inject_device(bkpinfo->media_device);
|
---|
| 2020 | }
|
---|
| 2021 | pause_for_N_seconds(5, "Letting DVD drive settle");
|
---|
| 2022 | res =
|
---|
| 2023 | eval_call_to_make_ISO(bkpinfo, bkpinfo->call_make_iso,
|
---|
| 2024 | bkpinfo->scratchdir,
|
---|
| 2025 | g_current_media_number,
|
---|
| 2026 | MONDO_LOGFILE,
|
---|
| 2027 | message_to_screen);
|
---|
| 2028 | retval += res;
|
---|
| 2029 | if (!bkpinfo->please_dont_eject) {
|
---|
| 2030 | log_to_screen("Ejecting media.");
|
---|
| 2031 | eject_device(bkpinfo->media_device);
|
---|
| 2032 | }
|
---|
| 2033 | if (res) {
|
---|
| 2034 | log_to_screen("Dagnabbit. It still failed.");
|
---|
| 2035 | } else {
|
---|
| 2036 | log_to_screen
|
---|
| 2037 | ("OK, this time I successfully backed up to DVD.");
|
---|
| 2038 | }
|
---|
| 2039 | }
|
---|
| 2040 | #endif
|
---|
| 2041 | if (g_backup_media_type == dvd && !bkpinfo->please_dont_eject) {
|
---|
| 2042 | eject_device(bkpinfo->media_device);
|
---|
| 2043 | }
|
---|
[1] | 2044 | }
|
---|
[128] | 2045 | } else {
|
---|
| 2046 | sprintf(message_to_screen, "Running mkisofs to make %s #%d",
|
---|
| 2047 | media_descriptor_string(bkpinfo->backup_media_type),
|
---|
| 2048 | g_current_media_number);
|
---|
| 2049 | log_msg(1, message_to_screen);
|
---|
| 2050 | sprintf(result_sz, "Call to mkisofs to make ISO (%s #%d) ",
|
---|
| 2051 | media_descriptor_string(bkpinfo->backup_media_type),
|
---|
| 2052 | g_current_media_number);
|
---|
| 2053 | if (bkpinfo->nonbootable_backup) {
|
---|
| 2054 | log_msg(1, "Making nonbootable backup");
|
---|
[1] | 2055 | // FIXME --- change mkisofs string to MONDO_MKISOFS_NONBOOTABLE and add ' .' at end
|
---|
[128] | 2056 | res =
|
---|
| 2057 | eval_call_to_make_ISO(bkpinfo,
|
---|
[906] | 2058 | "mkisofs -o '_ISO_' -r -p MondoRescue -publisher www.mondorescue.org -A MondoRescue_GPL -V _CD#_ .",
|
---|
[128] | 2059 | destfile, g_current_media_number,
|
---|
| 2060 | MONDO_LOGFILE, message_to_screen);
|
---|
| 2061 | } else {
|
---|
| 2062 | log_msg(1, "Making bootable backup");
|
---|
[1] | 2063 |
|
---|
| 2064 | #ifdef __FreeBSD__
|
---|
[128] | 2065 | bkpinfo->make_cd_use_lilo = TRUE;
|
---|
[1] | 2066 | #endif
|
---|
| 2067 |
|
---|
| 2068 |
|
---|
[128] | 2069 | log_msg(1, "make_cd_use_lilo is actually %d",
|
---|
| 2070 | bkpinfo->make_cd_use_lilo);
|
---|
| 2071 | if (bkpinfo->make_cd_use_lilo) {
|
---|
| 2072 | log_msg(1, "make_cd_use_lilo = TRUE");
|
---|
[1] | 2073 | // FIXME --- change mkisofs string to MONDO_MKISOFS_REGULAR_SYSLINUX/LILO depending on bkpinfo->make_cd_usE_lilo
|
---|
| 2074 | // and add ' .' at end
|
---|
| 2075 | #ifdef __IA64__
|
---|
[128] | 2076 | log_msg(1, "IA64 --> elilo");
|
---|
| 2077 | res = eval_call_to_make_ISO(bkpinfo,
|
---|
| 2078 | //-b images/mindi-boot.2880.img
|
---|
[541] | 2079 | "mkisofs -no-emul-boot -b images/mindi-bootroot."
|
---|
| 2080 | IA64_BOOT_SIZE
|
---|
[906] | 2081 | ".img -c boot.cat -o '_ISO_' -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .",
|
---|
[128] | 2082 | destfile,
|
---|
| 2083 | g_current_media_number,
|
---|
| 2084 | MONDO_LOGFILE,
|
---|
| 2085 | message_to_screen);
|
---|
[1] | 2086 | #else
|
---|
| 2087 | // FIXME --- change mkisofs string to MONDO_MKISOFS_REGULAR_SYSLINUX/LILO depending on bkpinfo->make_cd_usE_lilo
|
---|
| 2088 | // and add ' .' at end
|
---|
[128] | 2089 | log_msg(1, "Non-ia64 --> lilo");
|
---|
| 2090 | res =
|
---|
| 2091 | eval_call_to_make_ISO(bkpinfo,
|
---|
[906] | 2092 | "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] | 2093 | destfile, g_current_media_number,
|
---|
| 2094 | MONDO_LOGFILE,
|
---|
| 2095 | message_to_screen);
|
---|
[1] | 2096 | #endif
|
---|
[128] | 2097 | } else {
|
---|
| 2098 | log_msg(1, "make_cd_use_lilo = FALSE");
|
---|
| 2099 | log_msg(1, "Isolinux");
|
---|
| 2100 | res =
|
---|
| 2101 | eval_call_to_make_ISO(bkpinfo,
|
---|
[906] | 2102 | "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] | 2103 | destfile, g_current_media_number,
|
---|
| 2104 | MONDO_LOGFILE,
|
---|
| 2105 | message_to_screen);
|
---|
| 2106 | }
|
---|
| 2107 | }
|
---|
| 2108 | if (res) {
|
---|
| 2109 | strcat(result_sz, "...failed");
|
---|
| 2110 | } else {
|
---|
| 2111 | strcat(result_sz, "...OK");
|
---|
| 2112 | }
|
---|
| 2113 | log_to_screen(result_sz);
|
---|
| 2114 | retval += res;
|
---|
[1] | 2115 | }
|
---|
[128] | 2116 |
|
---|
| 2117 | if (bkpinfo->backup_media_type == cdr
|
---|
| 2118 | || bkpinfo->backup_media_type == cdrw) {
|
---|
| 2119 | if (is_this_device_mounted(bkpinfo->media_device)) {
|
---|
| 2120 | log_msg(2,
|
---|
| 2121 | "Warning - %s mounted. I'm unmounting it before I burn to it.",
|
---|
| 2122 | bkpinfo->media_device);
|
---|
| 2123 | sprintf(tmp, "umount %s", bkpinfo->media_device);
|
---|
| 2124 | run_program_and_log_output(tmp, FALSE);
|
---|
| 2125 | }
|
---|
[1] | 2126 | }
|
---|
| 2127 |
|
---|
[128] | 2128 | if (bkpinfo->call_burn_iso[0] != '\0') {
|
---|
| 2129 | log_msg(2, "bkpinfo->call_burn_iso = %s", bkpinfo->call_burn_iso);
|
---|
| 2130 | sprintf(message_to_screen, "Burning %s #%d",
|
---|
| 2131 | media_descriptor_string(bkpinfo->backup_media_type),
|
---|
| 2132 | g_current_media_number);
|
---|
| 2133 | pause_and_ask_for_cdr(2, &cd_is_mountable);
|
---|
| 2134 | res =
|
---|
| 2135 | eval_call_to_make_ISO(bkpinfo, bkpinfo->call_burn_iso,
|
---|
| 2136 | destfile, g_current_media_number,
|
---|
| 2137 | MONDO_LOGFILE, message_to_screen);
|
---|
| 2138 | if (res) {
|
---|
| 2139 | strcat(message_to_screen, "...failed");
|
---|
| 2140 | } else {
|
---|
| 2141 | strcat(message_to_screen, "...OK");
|
---|
| 2142 | }
|
---|
| 2143 | log_to_screen(message_to_screen);
|
---|
| 2144 | retval += res;
|
---|
| 2145 | }
|
---|
[1] | 2146 |
|
---|
[128] | 2147 | if (bkpinfo->call_after_iso[0] != '\0') {
|
---|
| 2148 | sprintf(message_to_screen, "Running post-ISO call (%s #%d)",
|
---|
| 2149 | media_descriptor_string(bkpinfo->backup_media_type),
|
---|
| 2150 | g_current_media_number);
|
---|
| 2151 | res =
|
---|
| 2152 | eval_call_to_make_ISO(bkpinfo, bkpinfo->call_after_iso,
|
---|
| 2153 | destfile, g_current_media_number,
|
---|
| 2154 | MONDO_LOGFILE, message_to_screen);
|
---|
| 2155 | if (res) {
|
---|
| 2156 | strcat(message_to_screen, "...failed");
|
---|
| 2157 | } else {
|
---|
| 2158 | strcat(message_to_screen, "...OK");
|
---|
| 2159 | }
|
---|
| 2160 | log_to_screen(message_to_screen);
|
---|
| 2161 | retval += res;
|
---|
[1] | 2162 | }
|
---|
| 2163 |
|
---|
[128] | 2164 | chdir(old_pwd);
|
---|
| 2165 | if (retval) {
|
---|
| 2166 | log_msg(1, "WARNING - make_iso_fs returned an error");
|
---|
[1] | 2167 | }
|
---|
[128] | 2168 | paranoid_free(old_pwd);
|
---|
| 2169 | paranoid_free(result_sz);
|
---|
| 2170 | paranoid_free(message_to_screen);
|
---|
| 2171 | paranoid_free(sz_blank_disk);
|
---|
| 2172 | paranoid_free(fnam);
|
---|
| 2173 | paranoid_free(tmp);
|
---|
| 2174 | return (retval);
|
---|
[1] | 2175 | }
|
---|
| 2176 |
|
---|
| 2177 |
|
---|
| 2178 |
|
---|
| 2179 |
|
---|
| 2180 |
|
---|
| 2181 |
|
---|
| 2182 |
|
---|
| 2183 |
|
---|
| 2184 |
|
---|
| 2185 | bool is_dev_an_NTFS_dev(char *bigfile_fname)
|
---|
| 2186 | {
|
---|
[128] | 2187 | char *tmp;
|
---|
| 2188 | char *command;
|
---|
| 2189 | malloc_string(tmp);
|
---|
| 2190 | malloc_string(command);
|
---|
| 2191 | sprintf(command,
|
---|
| 2192 | "dd if=%s bs=512 count=1 2> /dev/null | strings | head -n1",
|
---|
| 2193 | bigfile_fname);
|
---|
| 2194 | log_msg(1, "command = '%s'", command);
|
---|
| 2195 | strcpy(tmp, call_program_and_get_last_line_of_output(command));
|
---|
| 2196 | log_msg(1, "--> tmp = '%s'", tmp);
|
---|
| 2197 | if (strstr(tmp, "NTFS")) {
|
---|
| 2198 | iamhere("TRUE");
|
---|
| 2199 | return (TRUE);
|
---|
| 2200 | } else {
|
---|
| 2201 | iamhere("FALSE");
|
---|
| 2202 | return (FALSE);
|
---|
| 2203 | }
|
---|
[1] | 2204 | }
|
---|
| 2205 |
|
---|
| 2206 |
|
---|
| 2207 | /**
|
---|
| 2208 | * Back up big files by chopping them up.
|
---|
| 2209 | * This function backs up all "big" files (where "big" depends
|
---|
| 2210 | * on your backup media) in "chunks" (whose size again depends
|
---|
| 2211 | * on your media).
|
---|
| 2212 | *
|
---|
| 2213 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 2214 | * - @c backup_media_type
|
---|
| 2215 | * - @c optimal_set_size
|
---|
| 2216 | * @param biggielist_fname The path to a file containing a list of
|
---|
| 2217 | * all "big" files.
|
---|
| 2218 | * @return The number of errors encountered (0 for success)
|
---|
| 2219 | * @see slice_up_file_etc
|
---|
| 2220 | */
|
---|
| 2221 | int
|
---|
[541] | 2222 | make_slices_and_images(struct s_bkpinfo *bkpinfo, char *biggielist_fname)
|
---|
[1] | 2223 | {
|
---|
| 2224 |
|
---|
[128] | 2225 | /*@ pointers ******************************************* */
|
---|
| 2226 | FILE *fin;
|
---|
| 2227 | char *p;
|
---|
[1] | 2228 |
|
---|
[128] | 2229 | /*@ buffers ******************************************** */
|
---|
| 2230 | char *tmp;
|
---|
| 2231 | char *bigfile_fname;
|
---|
| 2232 | char *sz_devfile;
|
---|
[296] | 2233 | char *ntfsprog_fifo = NULL;
|
---|
[128] | 2234 | /*@ long *********************************************** */
|
---|
| 2235 | long biggie_file_number = 0;
|
---|
| 2236 | long noof_biggie_files = 0;
|
---|
| 2237 | long estimated_total_noof_slices = 0;
|
---|
[1] | 2238 |
|
---|
[128] | 2239 | /*@ int ************************************************ */
|
---|
| 2240 | int retval = 0;
|
---|
| 2241 | int res = 0;
|
---|
| 2242 | pid_t pid;
|
---|
| 2243 | FILE *ftmp = NULL;
|
---|
| 2244 | bool delete_when_done;
|
---|
[296] | 2245 | bool use_ntfsprog;
|
---|
[684] | 2246 | off_t biggie_fsize;
|
---|
[1] | 2247 |
|
---|
[128] | 2248 | assert(bkpinfo != NULL);
|
---|
| 2249 | assert_string_is_neither_NULL_nor_zerolength(biggielist_fname);
|
---|
[1] | 2250 |
|
---|
[128] | 2251 | malloc_string(tmp);
|
---|
| 2252 | malloc_string(bigfile_fname);
|
---|
| 2253 | malloc_string(sz_devfile);
|
---|
| 2254 | estimated_total_noof_slices =
|
---|
| 2255 | size_of_all_biggiefiles_K(bkpinfo) / bkpinfo->optimal_set_size + 1;
|
---|
[1] | 2256 |
|
---|
[128] | 2257 | log_msg(1, "size of all biggiefiles = %ld",
|
---|
| 2258 | size_of_all_biggiefiles_K(bkpinfo));
|
---|
| 2259 | log_msg(1, "estimated_total_noof_slices = %ld KB / %ld KB = %ld",
|
---|
| 2260 | size_of_all_biggiefiles_K(bkpinfo), bkpinfo->optimal_set_size,
|
---|
| 2261 | estimated_total_noof_slices);
|
---|
[1] | 2262 |
|
---|
[128] | 2263 | if (length_of_file(biggielist_fname) < 6) {
|
---|
| 2264 | log_msg(1, "No biggiefiles; fair enough...");
|
---|
| 2265 | return (0);
|
---|
[1] | 2266 | }
|
---|
[128] | 2267 | sprintf(tmp, "I am now backing up all large files.");
|
---|
| 2268 | log_to_screen(tmp);
|
---|
| 2269 | noof_biggie_files = count_lines_in_file(biggielist_fname);
|
---|
| 2270 | open_progress_form("Backing up big files", tmp,
|
---|
| 2271 | "Please wait. This may take some time.", "",
|
---|
| 2272 | estimated_total_noof_slices);
|
---|
| 2273 | if (!(fin = fopen(biggielist_fname, "r"))) {
|
---|
| 2274 | log_OS_error("Unable to openin biggielist");
|
---|
| 2275 | return (1);
|
---|
[1] | 2276 | }
|
---|
[128] | 2277 | for (fgets(bigfile_fname, MAX_STR_LEN, fin); !feof(fin);
|
---|
| 2278 | fgets(bigfile_fname, MAX_STR_LEN, fin), biggie_file_number++) {
|
---|
[296] | 2279 | use_ntfsprog = FALSE;
|
---|
[128] | 2280 | if (bigfile_fname[strlen(bigfile_fname) - 1] < 32) {
|
---|
| 2281 | bigfile_fname[strlen(bigfile_fname) - 1] = '\0';
|
---|
| 2282 | }
|
---|
| 2283 | biggie_fsize = length_of_file(bigfile_fname);
|
---|
| 2284 | delete_when_done = FALSE;
|
---|
| 2285 |
|
---|
| 2286 | if (!does_file_exist(bigfile_fname)) {
|
---|
| 2287 | ftmp = fopen(bigfile_fname, "w");
|
---|
[1299] | 2288 | if (ftmp == NULL) {
|
---|
[1437] | 2289 | log_msg(3, "Unable to write to %s", bigfile_fname);
|
---|
[1299] | 2290 | // So skip it as it doesn't exist
|
---|
| 2291 | continue;
|
---|
| 2292 | } else {
|
---|
| 2293 | paranoid_fclose(ftmp);
|
---|
| 2294 | }
|
---|
[128] | 2295 | delete_when_done = TRUE;
|
---|
| 2296 | } else {
|
---|
[812] | 2297 | // Call ntfsclone (formerly partimagehack) if it's a /dev entry
|
---|
| 2298 | // (i.e. a partition to be imaged)
|
---|
[541] | 2299 | log_msg(2, "bigfile_fname = %s", bigfile_fname);
|
---|
[296] | 2300 | use_ntfsprog = FALSE;
|
---|
[128] | 2301 | if (!strncmp(bigfile_fname, "/dev/", 5)
|
---|
| 2302 | && is_dev_an_NTFS_dev(bigfile_fname)) {
|
---|
[296] | 2303 | use_ntfsprog = TRUE;
|
---|
[128] | 2304 | log_msg(2,
|
---|
[296] | 2305 | "Calling ntfsclone in background because %s is an NTFS partition",
|
---|
[128] | 2306 | bigfile_fname);
|
---|
[812] | 2307 | sprintf(sz_devfile, "%s/%d.%d.000",
|
---|
| 2308 | bkpinfo->tmpdir,
|
---|
[128] | 2309 | (int) (random() % 32768),
|
---|
| 2310 | (int) (random() % 32768));
|
---|
| 2311 | mkfifo(sz_devfile, 0x770);
|
---|
[296] | 2312 | ntfsprog_fifo = sz_devfile;
|
---|
[128] | 2313 | switch (pid = fork()) {
|
---|
| 2314 | case -1:
|
---|
| 2315 | fatal_error("Fork failure");
|
---|
| 2316 | case 0:
|
---|
| 2317 | log_msg(2,
|
---|
[296] | 2318 | "CHILD - fip - calling feed_into_ntfsprog(%s, %s)",
|
---|
[128] | 2319 | bigfile_fname, sz_devfile);
|
---|
[296] | 2320 | res = feed_into_ntfsprog(bigfile_fname, sz_devfile);
|
---|
[128] | 2321 | exit(res);
|
---|
| 2322 | break;
|
---|
| 2323 | default:
|
---|
| 2324 | log_msg(2,
|
---|
[296] | 2325 | "feed_into_ntfsprog() called in background --- pid=%ld",
|
---|
[128] | 2326 | (long int) (pid));
|
---|
| 2327 | }
|
---|
| 2328 | }
|
---|
[1] | 2329 | // Otherwise, use good old 'dd' and 'bzip2'
|
---|
[128] | 2330 | else {
|
---|
| 2331 | sz_devfile[0] = '\0';
|
---|
[296] | 2332 | ntfsprog_fifo = NULL;
|
---|
[128] | 2333 | }
|
---|
[1] | 2334 |
|
---|
| 2335 | // Whether partition or biggiefile, just do your thang :-)
|
---|
[128] | 2336 | sprintf(tmp, "Bigfile #%ld is '%s' (%ld KB)",
|
---|
| 2337 | biggie_file_number + 1, bigfile_fname,
|
---|
| 2338 | (long) biggie_fsize >> 10);
|
---|
| 2339 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 2340 | write_header_block_to_stream(biggie_fsize, bigfile_fname,
|
---|
[296] | 2341 | use_ntfsprog ?
|
---|
[128] | 2342 | BLK_START_A_PIHBIGGIE :
|
---|
| 2343 | BLK_START_A_NORMBIGGIE);
|
---|
| 2344 | }
|
---|
| 2345 | res =
|
---|
[541] | 2346 | slice_up_file_etc(bkpinfo, bigfile_fname,
|
---|
[296] | 2347 | ntfsprog_fifo, biggie_file_number,
|
---|
| 2348 | noof_biggie_files, use_ntfsprog);
|
---|
[128] | 2349 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
[684] | 2350 | write_header_block_to_stream((off_t)0,
|
---|
[128] | 2351 | calc_checksum_of_file
|
---|
| 2352 | (bigfile_fname),
|
---|
| 2353 | BLK_STOP_A_BIGGIE);
|
---|
| 2354 | }
|
---|
| 2355 | retval += res;
|
---|
| 2356 | p = strrchr(bigfile_fname, '/');
|
---|
| 2357 | if (p) {
|
---|
| 2358 | p++;
|
---|
| 2359 | } else {
|
---|
| 2360 | p = bigfile_fname;
|
---|
| 2361 | }
|
---|
| 2362 | sprintf(tmp, "Archiving %s ... ", bigfile_fname);
|
---|
| 2363 | if (res) {
|
---|
| 2364 | strcat(tmp, "Failed!");
|
---|
| 2365 | } else {
|
---|
| 2366 | strcat(tmp, "OK");
|
---|
| 2367 | }
|
---|
| 2368 | if (delete_when_done) {
|
---|
| 2369 | unlink(bigfile_fname);
|
---|
| 2370 | delete_when_done = FALSE;
|
---|
| 2371 | }
|
---|
| 2372 | }
|
---|
[1] | 2373 | #ifndef _XWIN
|
---|
[128] | 2374 | if (!g_text_mode) {
|
---|
| 2375 | newtDrawRootText(0, g_noof_rows - 2, tmp);
|
---|
| 2376 | newtRefresh();
|
---|
| 2377 | }
|
---|
[1] | 2378 | #endif
|
---|
[128] | 2379 | }
|
---|
| 2380 | log_msg(1, "Finished backing up bigfiles");
|
---|
| 2381 | log_msg(1, "estimated slices = %ld; actual slices = %ld",
|
---|
| 2382 | estimated_total_noof_slices, g_current_progress);
|
---|
| 2383 | close_progress_form();
|
---|
| 2384 | paranoid_fclose(fin);
|
---|
| 2385 | paranoid_free(tmp);
|
---|
| 2386 | paranoid_free(bigfile_fname);
|
---|
| 2387 | paranoid_free(sz_devfile);
|
---|
| 2388 | return (retval);
|
---|
[1] | 2389 | }
|
---|
| 2390 |
|
---|
| 2391 |
|
---|
| 2392 |
|
---|
| 2393 |
|
---|
| 2394 | /**
|
---|
| 2395 | * Single-threaded version of @c make_afioballs_and_images().
|
---|
| 2396 | * @see make_afioballs_and_images
|
---|
| 2397 | */
|
---|
[541] | 2398 | int make_afioballs_and_images_OLD(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 2399 | {
|
---|
| 2400 |
|
---|
[128] | 2401 | /*@ int ************************************************** */
|
---|
| 2402 | int retval = 0;
|
---|
| 2403 | long int curr_set_no = 0;
|
---|
| 2404 | int res = 0;
|
---|
[1] | 2405 |
|
---|
[128] | 2406 | /*@ buffers ********************************************** */
|
---|
| 2407 | char *curr_filelist_fname;
|
---|
| 2408 | char *curr_afioball_fname;
|
---|
| 2409 | char *curr_xattr_list_fname;
|
---|
| 2410 | char *curr_acl_list_fname;
|
---|
| 2411 | char *tmp;
|
---|
| 2412 | char *media_usage_comment;
|
---|
[1] | 2413 |
|
---|
[128] | 2414 | malloc_string(curr_afioball_fname);
|
---|
| 2415 | malloc_string(media_usage_comment);
|
---|
| 2416 | malloc_string(curr_filelist_fname);
|
---|
| 2417 | malloc_string(curr_xattr_list_fname);
|
---|
| 2418 | malloc_string(curr_acl_list_fname);
|
---|
[1] | 2419 |
|
---|
[128] | 2420 | tmp = malloc(MAX_STR_LEN * 2);
|
---|
[1] | 2421 |
|
---|
[128] | 2422 | sprintf(tmp, "%s/archives/filelist.full", bkpinfo->scratchdir);
|
---|
[1] | 2423 |
|
---|
[128] | 2424 | log_to_screen("Archiving regular files");
|
---|
[1] | 2425 |
|
---|
[541] | 2426 | open_progress_form("Backing up filesystem",
|
---|
| 2427 | "I am backing up your live filesystem now.",
|
---|
| 2428 | "Please wait. This may take a couple of hours.",
|
---|
| 2429 | "Working...",
|
---|
[128] | 2430 | get_last_filelist_number(bkpinfo) + 1);
|
---|
| 2431 |
|
---|
| 2432 | sprintf(curr_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir,
|
---|
| 2433 | 0L);
|
---|
| 2434 |
|
---|
| 2435 | for (curr_set_no = 0; does_file_exist(curr_filelist_fname);
|
---|
| 2436 | sprintf(curr_filelist_fname, FILELIST_FNAME_RAW_SZ,
|
---|
| 2437 | bkpinfo->tmpdir, ++curr_set_no)) {
|
---|
| 2438 | /* backup this set of files */
|
---|
| 2439 | sprintf(curr_filelist_fname, FILELIST_FNAME_RAW_SZ,
|
---|
| 2440 | bkpinfo->tmpdir, curr_set_no);
|
---|
| 2441 | sprintf(curr_afioball_fname, AFIOBALL_FNAME_RAW_SZ,
|
---|
| 2442 | bkpinfo->tmpdir, curr_set_no, bkpinfo->zip_suffix);
|
---|
| 2443 |
|
---|
| 2444 | log_msg(1, "EXAT'g set %ld", curr_set_no);
|
---|
[948] | 2445 | if (g_getfattr) {
|
---|
| 2446 | sprintf(curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
|
---|
[128] | 2447 | bkpinfo->tmpdir, curr_set_no);
|
---|
[948] | 2448 | get_fattr_list(curr_filelist_fname, curr_xattr_list_fname);
|
---|
| 2449 | }
|
---|
| 2450 | if (g_getfacl) {
|
---|
| 2451 | sprintf(curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
|
---|
[128] | 2452 | bkpinfo->tmpdir, curr_set_no);
|
---|
[948] | 2453 | get_acl_list(curr_filelist_fname, curr_acl_list_fname);
|
---|
| 2454 | }
|
---|
[128] | 2455 |
|
---|
| 2456 | log_msg(1, "Archiving set %ld", curr_set_no);
|
---|
| 2457 | res =
|
---|
| 2458 | archive_this_fileset(bkpinfo, curr_filelist_fname,
|
---|
| 2459 | curr_afioball_fname, curr_set_no);
|
---|
| 2460 | retval += res;
|
---|
| 2461 | if (res) {
|
---|
| 2462 | sprintf(tmp,
|
---|
| 2463 | "Errors occurred while archiving set %ld. Perhaps your live filesystem changed?",
|
---|
| 2464 | curr_set_no);
|
---|
| 2465 | log_to_screen(tmp);
|
---|
| 2466 | }
|
---|
| 2467 |
|
---|
| 2468 | strcpy(media_usage_comment, percent_media_full_comment(bkpinfo));
|
---|
| 2469 |
|
---|
| 2470 | /* copy to CD (scratchdir) ... and an actual CD-R if necessary */
|
---|
| 2471 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 2472 | register_in_tape_catalog(fileset, curr_set_no, -1,
|
---|
| 2473 | curr_afioball_fname);
|
---|
| 2474 | maintain_collection_of_recent_archives(bkpinfo->tmpdir,
|
---|
| 2475 | curr_afioball_fname);
|
---|
| 2476 | iamhere("Writing EXAT files");
|
---|
| 2477 | res +=
|
---|
| 2478 | write_EXAT_files_to_tape(bkpinfo, curr_xattr_list_fname,
|
---|
| 2479 | curr_acl_list_fname);
|
---|
[1] | 2480 | // archives themselves
|
---|
[128] | 2481 | res = move_files_to_stream(bkpinfo, curr_afioball_fname, NULL);
|
---|
| 2482 | } else {
|
---|
[948] | 2483 | if (g_getfacl) {
|
---|
| 2484 | if (g_getfattr) {
|
---|
| 2485 | res = move_files_to_cd(bkpinfo, curr_filelist_fname,
|
---|
| 2486 | curr_xattr_list_fname,
|
---|
| 2487 | curr_acl_list_fname,
|
---|
| 2488 | curr_afioball_fname, NULL);
|
---|
| 2489 | } else {
|
---|
| 2490 | res = move_files_to_cd(bkpinfo, curr_filelist_fname,
|
---|
| 2491 | curr_acl_list_fname,
|
---|
| 2492 | curr_afioball_fname, NULL);
|
---|
| 2493 | }
|
---|
| 2494 | } else {
|
---|
| 2495 | if (g_getfattr) {
|
---|
| 2496 | res = move_files_to_cd(bkpinfo, curr_filelist_fname,
|
---|
| 2497 | curr_xattr_list_fname,
|
---|
| 2498 | curr_afioball_fname, NULL);
|
---|
| 2499 | } else {
|
---|
| 2500 | res = move_files_to_cd(bkpinfo, curr_filelist_fname,
|
---|
| 2501 | curr_afioball_fname, NULL);
|
---|
| 2502 | }
|
---|
| 2503 | }
|
---|
[128] | 2504 | }
|
---|
| 2505 | retval += res;
|
---|
| 2506 | g_current_progress++;
|
---|
| 2507 | update_progress_form(media_usage_comment);
|
---|
[1] | 2508 |
|
---|
[128] | 2509 | if (res) {
|
---|
| 2510 | sprintf(tmp, "Failed to add archive %ld's files to CD dir\n",
|
---|
| 2511 | curr_set_no);
|
---|
| 2512 | log_to_screen(tmp);
|
---|
| 2513 | fatal_error
|
---|
| 2514 | ("Is your hard disk is full? If not, please send the author the logfile.");
|
---|
| 2515 | }
|
---|
[1] | 2516 | }
|
---|
[128] | 2517 | close_progress_form();
|
---|
| 2518 | sprintf(tmp, "Your regular files have been archived ");
|
---|
| 2519 | if (retval) {
|
---|
| 2520 | strcat(tmp, "(with errors).");
|
---|
| 2521 | } else {
|
---|
| 2522 | strcat(tmp, "successfully.");
|
---|
| 2523 | }
|
---|
| 2524 | log_to_screen(tmp);
|
---|
| 2525 | paranoid_free(tmp);
|
---|
| 2526 | paranoid_free(curr_filelist_fname);
|
---|
| 2527 | paranoid_free(curr_afioball_fname);
|
---|
| 2528 | paranoid_free(media_usage_comment);
|
---|
| 2529 | paranoid_free(curr_xattr_list_fname);
|
---|
| 2530 | paranoid_free(curr_acl_list_fname);
|
---|
| 2531 | return (retval);
|
---|
[1] | 2532 | }
|
---|
| 2533 |
|
---|
[128] | 2534 | /* @} - end of LLarchiveGroup */
|
---|
| 2535 |
|
---|
| 2536 |
|
---|
[1] | 2537 | /**
|
---|
| 2538 | * Wrapper around @c make_afioballs_and_images().
|
---|
| 2539 | * @param bkpinfo the backup information structure. Only the
|
---|
| 2540 | * @c backup_media_type field is used within this function.
|
---|
| 2541 | * @return return code of make_afioballs_and_images
|
---|
| 2542 | * @see make_afioballs_and_images
|
---|
| 2543 | * @ingroup MLarchiveGroup
|
---|
| 2544 | */
|
---|
[541] | 2545 | int make_those_afios_phase(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 2546 | {
|
---|
[128] | 2547 | /*@ int ******************************************* */
|
---|
| 2548 | int res = 0;
|
---|
| 2549 | int retval = 0;
|
---|
[1] | 2550 |
|
---|
[128] | 2551 | assert(bkpinfo != NULL);
|
---|
[1] | 2552 |
|
---|
[128] | 2553 | mvaddstr_and_log_it(g_currentY, 0,
|
---|
| 2554 | "Archiving regular files to media ");
|
---|
[1] | 2555 |
|
---|
[128] | 2556 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
[684] | 2557 | write_header_block_to_stream((off_t)0, "start-of-afioballs",
|
---|
[128] | 2558 | BLK_START_AFIOBALLS);
|
---|
[1] | 2559 | #if __FreeBSD__ == 5
|
---|
[128] | 2560 | log_msg(1,
|
---|
| 2561 | "Using single-threaded make_afioballs_and_images() to suit b0rken FreeBSD 5.0");
|
---|
[541] | 2562 | res = make_afioballs_and_images_OLD(bkpinfo);
|
---|
[1] | 2563 | #else
|
---|
[541] | 2564 | res = make_afioballs_and_images_OLD(bkpinfo);
|
---|
[1] | 2565 | #endif
|
---|
[684] | 2566 | write_header_block_to_stream((off_t)0, "stop-afioballs",
|
---|
[128] | 2567 | BLK_STOP_AFIOBALLS);
|
---|
| 2568 | } else {
|
---|
[541] | 2569 | res = make_afioballs_and_images(bkpinfo);
|
---|
[128] | 2570 | }
|
---|
[1] | 2571 |
|
---|
[128] | 2572 | retval += res;
|
---|
| 2573 | if (res) {
|
---|
| 2574 | mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
|
---|
| 2575 | log_msg(1, "make_afioballs_and_images returned an error");
|
---|
| 2576 | } else {
|
---|
| 2577 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
| 2578 | }
|
---|
| 2579 | return (retval);
|
---|
[1] | 2580 | }
|
---|
| 2581 |
|
---|
| 2582 | /**
|
---|
| 2583 | * Wrapper around @c make_slices_and_images().
|
---|
| 2584 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 2585 | * - @c backup_media_type
|
---|
| 2586 | * - @c scratchdir
|
---|
| 2587 | * - @c tmpdir
|
---|
| 2588 | * @return The number of errors encountered (0 for success)
|
---|
| 2589 | * @ingroup MLarchiveGroup
|
---|
| 2590 | */
|
---|
[128] | 2591 | int make_those_slices_phase(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 2592 | {
|
---|
| 2593 |
|
---|
[128] | 2594 | /*@ int ***************************************************** */
|
---|
| 2595 | int res = 0;
|
---|
| 2596 | int retval = 0;
|
---|
[1] | 2597 |
|
---|
[128] | 2598 | /*@ buffers ************************************************** */
|
---|
| 2599 | char *biggielist;
|
---|
| 2600 | char *command;
|
---|
| 2601 | char *blah;
|
---|
| 2602 | char *xattr_fname;
|
---|
| 2603 | char *acl_fname;
|
---|
[1] | 2604 |
|
---|
[128] | 2605 | assert(bkpinfo != NULL);
|
---|
| 2606 | /* slice big files */
|
---|
| 2607 | malloc_string(biggielist);
|
---|
| 2608 | malloc_string(xattr_fname);
|
---|
| 2609 | malloc_string(acl_fname);
|
---|
| 2610 | mvaddstr_and_log_it(g_currentY, 0,
|
---|
| 2611 | "Archiving large files to media ");
|
---|
| 2612 | sprintf(biggielist, "%s/archives/biggielist.txt", bkpinfo->scratchdir);
|
---|
[948] | 2613 | if (g_getfattr) {
|
---|
| 2614 | sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
|
---|
| 2615 | }
|
---|
| 2616 | if (g_getfacl) {
|
---|
| 2617 | sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
|
---|
| 2618 | }
|
---|
[1] | 2619 |
|
---|
[1236] | 2620 | asprintf(&command, "cp %s/biggielist.txt %s", bkpinfo->tmpdir,
|
---|
[128] | 2621 | biggielist);
|
---|
| 2622 | paranoid_system(command);
|
---|
[1236] | 2623 | paranoid_free(command);
|
---|
| 2624 |
|
---|
| 2625 | asprintf(&blah, "biggielist = %s", biggielist);
|
---|
[128] | 2626 | log_msg(2, blah);
|
---|
[1236] | 2627 | paranoid_free(blah);
|
---|
[128] | 2628 |
|
---|
| 2629 | if (!does_file_exist(biggielist)) {
|
---|
| 2630 | log_msg(1, "BTW, the biggielist does not exist");
|
---|
| 2631 | }
|
---|
| 2632 |
|
---|
[948] | 2633 | if (g_getfattr) {
|
---|
| 2634 | get_fattr_list(biggielist, xattr_fname);
|
---|
[1236] | 2635 | asprintf(&command, "cp %s %s/archives/", xattr_fname,
|
---|
[128] | 2636 | bkpinfo->scratchdir);
|
---|
[948] | 2637 | paranoid_system(command);
|
---|
[1236] | 2638 | paranoid_free(command);
|
---|
[948] | 2639 | }
|
---|
| 2640 | if (g_getfacl) {
|
---|
| 2641 | get_acl_list(biggielist, acl_fname);
|
---|
[1236] | 2642 | asprintf(&command, "cp %s %s/archives/", acl_fname,
|
---|
| 2643 | bkpinfo->scratchdir);
|
---|
[948] | 2644 | paranoid_system(command);
|
---|
[1236] | 2645 | paranoid_free(command);
|
---|
[948] | 2646 | }
|
---|
[128] | 2647 |
|
---|
| 2648 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 2649 | res += write_EXAT_files_to_tape(bkpinfo, xattr_fname, acl_fname);
|
---|
[1236] | 2650 | asprintf(&blah, "%ld", count_lines_in_file(biggielist));
|
---|
[684] | 2651 | write_header_block_to_stream((off_t)0, blah, BLK_START_BIGGIEFILES);
|
---|
[1236] | 2652 | paranoid_free(blah);
|
---|
[128] | 2653 | }
|
---|
| 2654 | res = make_slices_and_images(bkpinfo, biggielist);
|
---|
| 2655 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
[684] | 2656 | write_header_block_to_stream((off_t)0, "end-of-biggiefiles",
|
---|
[128] | 2657 | BLK_STOP_BIGGIEFILES);
|
---|
| 2658 | }
|
---|
| 2659 | retval += res;
|
---|
| 2660 | if (res) {
|
---|
| 2661 | log_msg(1, "make_slices_and_images returned an error");
|
---|
| 2662 | mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
|
---|
| 2663 | } else {
|
---|
| 2664 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
| 2665 | }
|
---|
| 2666 | paranoid_free(blah);
|
---|
| 2667 | paranoid_free(biggielist);
|
---|
| 2668 | paranoid_free(command);
|
---|
| 2669 | paranoid_free(xattr_fname);
|
---|
| 2670 | paranoid_free(acl_fname);
|
---|
| 2671 | return (retval);
|
---|
[1] | 2672 | }
|
---|
| 2673 |
|
---|
| 2674 |
|
---|
| 2675 | /**
|
---|
| 2676 | * @addtogroup LLarchiveGroup
|
---|
| 2677 | * @{
|
---|
| 2678 | */
|
---|
| 2679 | /**
|
---|
| 2680 | * Function pointer to an appropriate @c move_files_to_cd routine.
|
---|
| 2681 | * You can set this to your own function (for example, one to
|
---|
| 2682 | * transfer files over the network) or leave it as is.
|
---|
| 2683 | */
|
---|
[541] | 2684 | int (*move_files_to_cd) (struct s_bkpinfo *, char *, ...) =
|
---|
[128] | 2685 | _move_files_to_cd;
|
---|
[1] | 2686 |
|
---|
| 2687 | /**
|
---|
| 2688 | * Move some files to the ISO scratch directory.
|
---|
| 2689 | * This function moves files specified as parameters, into the directory
|
---|
| 2690 | * @c bkpinfo->scratchdir, where the files that will be stored on the next
|
---|
| 2691 | * CD are waiting.
|
---|
| 2692 | *
|
---|
| 2693 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 2694 | * - @c media_size
|
---|
| 2695 | * - @c scratchdir
|
---|
| 2696 | * @param files_to_add The files to add to the scratchdir.
|
---|
| 2697 | * @warning The list of @c files_to_add must be terminated with @c NULL.
|
---|
| 2698 | * @note If and when the space occupied by the scratchdir would exceed
|
---|
| 2699 | * the capacity of the current CD,
|
---|
| 2700 | * <tt>write_iso_and_go_on(bkpinfo, FALSE)</tt> is called and the
|
---|
| 2701 | * scratchdir is emptied.
|
---|
| 2702 | *
|
---|
| 2703 | * @return The number of errors encountered (0 for success)
|
---|
| 2704 | */
|
---|
[541] | 2705 | int _move_files_to_cd(struct s_bkpinfo *bkpinfo, char *files_to_add, ...)
|
---|
[1] | 2706 | {
|
---|
| 2707 |
|
---|
[128] | 2708 | /*@ int ************************************************************ */
|
---|
| 2709 | int retval = 0;
|
---|
[1] | 2710 | int res = 0;
|
---|
| 2711 |
|
---|
[128] | 2712 | /*@ buffers ******************************************************** */
|
---|
| 2713 | char *tmp, *curr_file, *cf;
|
---|
[1] | 2714 |
|
---|
[128] | 2715 | /*@ long ************************************************************ */
|
---|
| 2716 | va_list ap;
|
---|
| 2717 | long long would_occupy;
|
---|
[1] | 2718 |
|
---|
[128] | 2719 | assert(bkpinfo != NULL);
|
---|
| 2720 | malloc_string(curr_file);
|
---|
| 2721 | tmp = malloc(1200);
|
---|
| 2722 | would_occupy = space_occupied_by_cd(bkpinfo->scratchdir);
|
---|
| 2723 | va_start(ap, files_to_add); // initialize the variable arguments
|
---|
| 2724 | for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) {
|
---|
| 2725 | if (!cf) {
|
---|
| 2726 | continue;
|
---|
| 2727 | }
|
---|
| 2728 | strcpy(curr_file, cf);
|
---|
| 2729 | if (!does_file_exist(curr_file)) {
|
---|
| 2730 | log_msg(1,
|
---|
| 2731 | "Warning - you're trying to add a non-existent file - '%s' to the CD",
|
---|
| 2732 | curr_file);
|
---|
| 2733 | } else {
|
---|
| 2734 | log_msg(8, "Trying to add file %s to CD", curr_file);
|
---|
| 2735 | would_occupy += length_of_file(curr_file) / 1024;
|
---|
| 2736 | }
|
---|
[1] | 2737 | }
|
---|
[128] | 2738 | va_end(ap);
|
---|
[1] | 2739 |
|
---|
[128] | 2740 | if (bkpinfo->media_size[g_current_media_number] <= 0) {
|
---|
| 2741 | fatal_error("move_files_to_cd() - unknown media size");
|
---|
[1] | 2742 | }
|
---|
[128] | 2743 | if (would_occupy / 1024 > bkpinfo->media_size[g_current_media_number]) {
|
---|
[541] | 2744 | res = write_iso_and_go_on(bkpinfo, FALSE); /* FALSE because this is not the last CD we'll write */
|
---|
[128] | 2745 | retval += res;
|
---|
| 2746 | if (res) {
|
---|
| 2747 | log_msg(1, "WARNING - write_iso_and_go_on returned an error");
|
---|
| 2748 | }
|
---|
| 2749 | }
|
---|
[1] | 2750 |
|
---|
[128] | 2751 | va_start(ap, files_to_add); // initialize the variable arguments
|
---|
| 2752 | for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) {
|
---|
| 2753 | if (!cf) {
|
---|
| 2754 | continue;
|
---|
| 2755 | }
|
---|
| 2756 | strcpy(curr_file, cf);
|
---|
[1] | 2757 |
|
---|
[128] | 2758 | sprintf(tmp, "mv -f %s %s/archives/", curr_file,
|
---|
| 2759 | bkpinfo->scratchdir);
|
---|
| 2760 | res = run_program_and_log_output(tmp, 5);
|
---|
| 2761 | retval += res;
|
---|
| 2762 | if (res) {
|
---|
| 2763 | log_msg(1, "(move_files_to_cd) '%s' failed", tmp);
|
---|
| 2764 | } else {
|
---|
| 2765 | log_msg(8, "Moved %s to CD OK", tmp);
|
---|
| 2766 | }
|
---|
| 2767 | // unlink (curr_file);
|
---|
[1] | 2768 | }
|
---|
[128] | 2769 | va_end(ap);
|
---|
| 2770 |
|
---|
| 2771 | if (retval) {
|
---|
| 2772 | log_msg(1,
|
---|
| 2773 | "Warning - errors occurred while I was adding files to CD dir");
|
---|
[1] | 2774 | }
|
---|
[128] | 2775 | paranoid_free(tmp);
|
---|
| 2776 | paranoid_free(curr_file);
|
---|
| 2777 | return (retval);
|
---|
[1] | 2778 | }
|
---|
| 2779 |
|
---|
| 2780 | /* @} - end of LLarchiveGroup */
|
---|
| 2781 |
|
---|
| 2782 |
|
---|
| 2783 |
|
---|
| 2784 |
|
---|
| 2785 |
|
---|
| 2786 |
|
---|
| 2787 |
|
---|
| 2788 |
|
---|
| 2789 | /**
|
---|
| 2790 | * Offer to write boot and data disk images to 3.5" floppy disks.
|
---|
| 2791 | * @param bkpinfo The backup information structure. Only the
|
---|
| 2792 | * @c backup_media_type field is used in this function.
|
---|
| 2793 | * @param imagesdir The directory containing the floppy images (usually
|
---|
[1437] | 2794 | * /root/images/mindi).
|
---|
[1] | 2795 | *
|
---|
| 2796 | * @return The number of errors encountered (0 for success)
|
---|
| 2797 | * @see write_image_to_floppy
|
---|
| 2798 | * @see format_disk
|
---|
| 2799 | * @ingroup MLarchiveGroup
|
---|
| 2800 | */
|
---|
[128] | 2801 | int offer_to_write_floppies(struct s_bkpinfo *bkpinfo, char *imagesdir)
|
---|
[1] | 2802 | {
|
---|
[128] | 2803 | /*@ buffer ************************************************************ */
|
---|
| 2804 | char *tmp;
|
---|
[1] | 2805 | char *comment;
|
---|
| 2806 | char *bootdisk_dev;
|
---|
| 2807 | char *datadisk_dev;
|
---|
| 2808 | char *bootdisk_file;
|
---|
| 2809 | char *rootdisk_file;
|
---|
| 2810 |
|
---|
[128] | 2811 | /*@ int *************************************************************** */
|
---|
| 2812 | int i = 0;
|
---|
[1] | 2813 | int res = 0;
|
---|
| 2814 |
|
---|
[128] | 2815 | /*@ bool ************************************************************** */
|
---|
| 2816 | bool format_first;
|
---|
| 2817 | bool root_disk_exists = FALSE;
|
---|
[1] | 2818 |
|
---|
[128] | 2819 | malloc_string(tmp);
|
---|
| 2820 | malloc_string(comment);
|
---|
| 2821 | malloc_string(bootdisk_dev);
|
---|
| 2822 | malloc_string(datadisk_dev);
|
---|
| 2823 | malloc_string(rootdisk_file);
|
---|
| 2824 | malloc_string(bootdisk_file);
|
---|
| 2825 | assert(bkpinfo != NULL);
|
---|
| 2826 | assert_string_is_neither_NULL_nor_zerolength(imagesdir);
|
---|
[1] | 2827 |
|
---|
| 2828 |
|
---|
[128] | 2829 | if (!ask_me_yes_or_no
|
---|
| 2830 | ("Write boot and data disk images to 3.5\" floppy disks?")) {
|
---|
| 2831 | return (0);
|
---|
| 2832 | }
|
---|
| 2833 | if (does_device_exist(DEFAULT_1722MB_DISK)) {
|
---|
[1] | 2834 | #ifdef __FreeBSD__
|
---|
[128] | 2835 | // tell the system that this is a 1.72m floppy
|
---|
| 2836 | system("/usr/sbin/fdcontrol -F 1722 /dev/fd0.1722");
|
---|
[1] | 2837 | #endif
|
---|
[128] | 2838 | strcpy(bootdisk_dev, DEFAULT_1722MB_DISK);
|
---|
| 2839 | } else if (does_device_exist(BACKUP_1722MB_DISK)) {
|
---|
| 2840 | sprintf(bootdisk_dev, "/dev/fd0H1722");
|
---|
| 2841 | } else {
|
---|
| 2842 | log_msg(1, "Warning - can't find a 1.72MB floppy device *sigh*");
|
---|
| 2843 | strcpy(bootdisk_dev, DEFAULT_1722MB_DISK);
|
---|
[1] | 2844 | // return (1);
|
---|
[128] | 2845 | }
|
---|
| 2846 | strcpy(datadisk_dev, "/dev/fd0");
|
---|
| 2847 | if (!does_device_exist(datadisk_dev)) {
|
---|
| 2848 | log_msg(1, "Warning - can't find a 1.44MB floppy device *sigh*");
|
---|
| 2849 | strcpy(datadisk_dev, "/dev/fd0");
|
---|
[1] | 2850 | // return (1);
|
---|
[128] | 2851 | }
|
---|
| 2852 | format_first =
|
---|
| 2853 | ask_me_yes_or_no
|
---|
| 2854 | ("Do you want me to format the disks before I write to them?");
|
---|
[1] | 2855 |
|
---|
| 2856 | /* boot disk */
|
---|
[128] | 2857 | if (ask_me_OK_or_cancel("About to write boot disk")) {
|
---|
| 2858 | log_to_screen("Writing boot floppy");
|
---|
[1] | 2859 | #ifdef __FreeBSD__
|
---|
[128] | 2860 | sprintf(tmp, "%s/mindi-kern.1722.img", imagesdir);
|
---|
| 2861 | if (format_first) {
|
---|
| 2862 | format_disk(bootdisk_dev);
|
---|
| 2863 | }
|
---|
| 2864 | res += write_image_to_floppy(bootdisk_dev, tmp);
|
---|
| 2865 | if (ask_me_OK_or_cancel("About to write 1.44MB mfsroot disk")) {
|
---|
| 2866 | log_to_screen("Writing mfsroot floppy");
|
---|
| 2867 | if (format_first) {
|
---|
| 2868 | format_disk(datadisk_dev);
|
---|
| 2869 | }
|
---|
| 2870 | sprintf(tmp, "%s/mindi-mfsroot.1440.img", imagesdir);
|
---|
| 2871 | write_image_to_floppy(datadisk_dev, tmp);
|
---|
| 2872 | }
|
---|
[1] | 2873 | #else
|
---|
[128] | 2874 | sprintf(bootdisk_file, "%s/mindi-bootroot.1722.img", imagesdir);
|
---|
| 2875 | if (does_file_exist(bootdisk_file)) {
|
---|
| 2876 | if (format_first) {
|
---|
| 2877 | format_disk(bootdisk_dev);
|
---|
| 2878 | }
|
---|
| 2879 | res += write_image_to_floppy(bootdisk_dev, bootdisk_file);
|
---|
| 2880 | } else {
|
---|
| 2881 | sprintf(bootdisk_file, "%s/mindi-boot.1440.img", imagesdir);
|
---|
| 2882 | sprintf(rootdisk_file, "%s/mindi-root.1440.img", imagesdir);
|
---|
| 2883 | root_disk_exists = TRUE;
|
---|
| 2884 | if (!does_file_exist(rootdisk_file)
|
---|
| 2885 | || !does_file_exist(bootdisk_file)) {
|
---|
| 2886 | popup_and_OK
|
---|
| 2887 | ("Cannot write boot/root floppies. Files not found.");
|
---|
| 2888 | log_to_screen
|
---|
| 2889 | ("Failed to find boot/root floppy images. Oh dear.");
|
---|
| 2890 | return (1);
|
---|
| 2891 | }
|
---|
| 2892 | if (format_first) {
|
---|
| 2893 | format_disk(datadisk_dev);
|
---|
| 2894 | }
|
---|
| 2895 | /*
|
---|
| 2896 | sprintf(tmp, "cat %s > %s", bootdisk_file, datadisk_dev);
|
---|
| 2897 | res += run_external_binary_with_percentage_indicator_NEW("Writing boot floppy", tmp);
|
---|
| 2898 | */
|
---|
| 2899 | res += write_image_to_floppy(datadisk_dev, bootdisk_file);
|
---|
| 2900 | if (ask_me_OK_or_cancel("About to write root disk")) {
|
---|
| 2901 | log_to_screen("Writing root floppy");
|
---|
| 2902 | if (format_first) {
|
---|
| 2903 | format_disk(datadisk_dev);
|
---|
| 2904 | }
|
---|
| 2905 | sprintf(tmp, "cat %s > %s", rootdisk_file, datadisk_dev);
|
---|
| 2906 | log_msg(1, "tmp = '%s'", tmp);
|
---|
| 2907 | res +=
|
---|
| 2908 | run_external_binary_with_percentage_indicator_NEW
|
---|
| 2909 | ("Writing root floppy", tmp);
|
---|
[1] | 2910 | // res += write_image_to_floppy (datadisk_dev, rootdisk_file);
|
---|
[128] | 2911 | }
|
---|
| 2912 | }
|
---|
[1] | 2913 | #endif
|
---|
| 2914 | }
|
---|
[128] | 2915 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 2916 | log_to_screen
|
---|
| 2917 | ("FYI, the data disks are stored on tape/CD for your convenience.");
|
---|
| 2918 | return (0);
|
---|
[1] | 2919 | }
|
---|
[128] | 2920 | for (i = 1; i < 99; i++) {
|
---|
| 2921 | sprintf(tmp, "%s/mindi-data-%d.img", imagesdir, i);
|
---|
| 2922 | log_msg(3, tmp);
|
---|
| 2923 | if (!does_file_exist(tmp)) {
|
---|
| 2924 | log_msg(3, "...not found");
|
---|
| 2925 | break;
|
---|
| 2926 | }
|
---|
| 2927 | sprintf(comment, "About to write data disk #%d", i);
|
---|
| 2928 | if (ask_me_OK_or_cancel(comment)) {
|
---|
| 2929 | sprintf(comment, "Writing data disk #%3d", i);
|
---|
| 2930 | log_to_screen(comment);
|
---|
| 2931 | if (format_first) {
|
---|
| 2932 | res += format_disk(datadisk_dev);
|
---|
| 2933 | }
|
---|
| 2934 | res += write_image_to_floppy(datadisk_dev, tmp);
|
---|
| 2935 | }
|
---|
| 2936 | }
|
---|
| 2937 | paranoid_free(tmp);
|
---|
| 2938 | paranoid_free(comment);
|
---|
| 2939 | paranoid_free(bootdisk_dev);
|
---|
| 2940 | paranoid_free(datadisk_dev);
|
---|
| 2941 | return (res);
|
---|
[1] | 2942 | }
|
---|
| 2943 |
|
---|
| 2944 |
|
---|
| 2945 |
|
---|
| 2946 |
|
---|
| 2947 |
|
---|
| 2948 |
|
---|
| 2949 |
|
---|
| 2950 |
|
---|
| 2951 | /**
|
---|
| 2952 | * Wrapper around @c offer_to_write_floppies().
|
---|
| 2953 | * @param bkpinfo The backup information structure. Used only
|
---|
| 2954 | * in the call to @c offer_to_write_floppies().
|
---|
| 2955 | * @return 0 if the boot floppies were found (not necessarily written OK),
|
---|
| 2956 | * 1 otherwise.
|
---|
| 2957 | * @see offer_to_write_floppies
|
---|
| 2958 | * @ingroup MLarchiveGroup
|
---|
| 2959 | */
|
---|
| 2960 |
|
---|
[128] | 2961 | int offer_to_write_boot_floppies_to_physical_disks(struct s_bkpinfo
|
---|
| 2962 | *bkpinfo)
|
---|
[1] | 2963 | {
|
---|
[128] | 2964 | int res = 0;
|
---|
[1] | 2965 |
|
---|
[128] | 2966 | assert(bkpinfo != NULL);
|
---|
[1] | 2967 |
|
---|
[128] | 2968 | mvaddstr_and_log_it(g_currentY, 0,
|
---|
| 2969 | "Writing boot+data floppy images to disk");
|
---|
[1] | 2970 |
|
---|
[128] | 2971 | if (!bkpinfo->nonbootable_backup) {
|
---|
[1] | 2972 | #ifdef __FreeBSD__
|
---|
[1437] | 2973 | if (!does_file_exist(MINDI_CACHE"/mindi-kern.1722.img"))
|
---|
[1] | 2974 | #else
|
---|
[1437] | 2975 | if (!does_file_exist(MINDI_CACHE"/mindi-bootroot.1722.img") && !does_file_exist(MINDI_CACHE"/mindi-boot.1440.img"))
|
---|
[1] | 2976 | #endif
|
---|
[128] | 2977 | {
|
---|
| 2978 | mvaddstr_and_log_it(g_currentY++, 74, "No Imgs");
|
---|
[1437] | 2979 | if (does_file_exist(MINDI_CACHE"/mondorescue.iso")) {
|
---|
| 2980 | popup_and_OK
|
---|
| 2981 | ("No regular Boot+data floppies were created due of space constraints. However, you can burn "MINDI_CACHE"/mondorescue.iso to a CD and boot from that.");
|
---|
[128] | 2982 | res++;
|
---|
| 2983 | }
|
---|
| 2984 | } else {
|
---|
[1437] | 2985 | offer_to_write_floppies(bkpinfo, MINDI_CACHE);
|
---|
[128] | 2986 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
| 2987 | }
|
---|
| 2988 | } else {
|
---|
| 2989 | popup_and_OK
|
---|
| 2990 | ("Since you opted for a nonbootable backup, no boot floppies were created.");
|
---|
| 2991 | }
|
---|
| 2992 |
|
---|
| 2993 | return (res);
|
---|
[1] | 2994 | }
|
---|
| 2995 |
|
---|
| 2996 |
|
---|
| 2997 |
|
---|
| 2998 |
|
---|
| 2999 | /**
|
---|
| 3000 | * @addtogroup LLarchiveGroup
|
---|
| 3001 | * @{
|
---|
| 3002 | */
|
---|
| 3003 | /**
|
---|
| 3004 | * Function pointer to an appropriate @c move_files_to_stream routine.
|
---|
| 3005 | * You can set this to your own function (for example, one to
|
---|
| 3006 | * transfer files over the network) or leave it as is.
|
---|
| 3007 | */
|
---|
[128] | 3008 | int (*move_files_to_stream) (struct s_bkpinfo *, char *, ...) =
|
---|
| 3009 | _move_files_to_stream;
|
---|
[1] | 3010 |
|
---|
| 3011 | /**
|
---|
| 3012 | * Copy some files to tape.
|
---|
| 3013 | * This function copies the files specified as parameters into the tape stream.
|
---|
| 3014 | *
|
---|
| 3015 | * @param bkpinfo The backup information structure. Used only in the call to
|
---|
| 3016 | * @c write_file_to_stream_from_file().
|
---|
| 3017 | *
|
---|
| 3018 | * @param files_to_add The files to copy to the tape stream.
|
---|
| 3019 | * @warning The list of @c files_to_add must be terminated with @c NULL.
|
---|
| 3020 | * @note Files may be split across multiple tapes if necessary.
|
---|
| 3021 | *
|
---|
| 3022 | * @return The number of errors encountered (0 for success)
|
---|
| 3023 | */
|
---|
| 3024 | int
|
---|
[128] | 3025 | _move_files_to_stream(struct s_bkpinfo *bkpinfo, char *files_to_add, ...)
|
---|
[1] | 3026 | {
|
---|
| 3027 |
|
---|
[128] | 3028 | /*@ int ************************************************************ */
|
---|
| 3029 | int retval = 0;
|
---|
[1] | 3030 | int res = 0;
|
---|
[128] | 3031 | /*@ buffers ******************************************************** */
|
---|
[1] | 3032 |
|
---|
[128] | 3033 | /*@ char *********************************************************** */
|
---|
[1] | 3034 | char start_chr;
|
---|
| 3035 | char stop_chr;
|
---|
[128] | 3036 | char *curr_file, *cf;
|
---|
| 3037 | /*@ long long ****************************************************** */
|
---|
[684] | 3038 | off_t length_of_incoming_file = (off_t)0;
|
---|
[128] | 3039 | t_archtype type;
|
---|
| 3040 | va_list ap;
|
---|
[1] | 3041 |
|
---|
[128] | 3042 | assert(bkpinfo != NULL);
|
---|
| 3043 | malloc_string(curr_file);
|
---|
| 3044 | va_start(ap, files_to_add);
|
---|
| 3045 | for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) {
|
---|
| 3046 | if (!cf) {
|
---|
| 3047 | continue;
|
---|
| 3048 | }
|
---|
| 3049 | strcpy(curr_file, cf);
|
---|
| 3050 | if (!does_file_exist(curr_file)) {
|
---|
| 3051 | log_msg(1,
|
---|
| 3052 | "Warning - you're trying to add a non-existent file - '%s' to the tape",
|
---|
| 3053 | curr_file);
|
---|
| 3054 | }
|
---|
[1] | 3055 | /* create header chars */
|
---|
[128] | 3056 | start_chr = BLK_START_AN_AFIO_OR_SLICE;
|
---|
| 3057 | stop_chr = BLK_STOP_AN_AFIO_OR_SLICE;
|
---|
[1] | 3058 | /* ask for new tape if necessary */
|
---|
[128] | 3059 | length_of_incoming_file = length_of_file(curr_file);
|
---|
| 3060 | write_header_block_to_stream(length_of_incoming_file, curr_file,
|
---|
| 3061 | start_chr);
|
---|
| 3062 | if (strstr(curr_file, ".afio.") || strstr(curr_file, ".star.")) {
|
---|
| 3063 | type = fileset;
|
---|
| 3064 | } else if (strstr(curr_file, "slice")) {
|
---|
| 3065 | type = biggieslice;
|
---|
| 3066 | } else {
|
---|
| 3067 | type = other;
|
---|
| 3068 | }
|
---|
| 3069 | res = write_file_to_stream_from_file(bkpinfo, curr_file);
|
---|
| 3070 | retval += res;
|
---|
| 3071 | unlink(curr_file);
|
---|
[1] | 3072 | /* write closing header */
|
---|
[684] | 3073 | write_header_block_to_stream((off_t)0, "finished-writing-file", stop_chr);
|
---|
[128] | 3074 | }
|
---|
| 3075 | va_end(ap);
|
---|
[1] | 3076 |
|
---|
[128] | 3077 | if (retval) {
|
---|
| 3078 | log_msg(1,
|
---|
| 3079 | "Warning - errors occurred while I was adding file to tape");
|
---|
| 3080 | }
|
---|
| 3081 | paranoid_free(curr_file);
|
---|
| 3082 | return (retval);
|
---|
[1] | 3083 | }
|
---|
| 3084 |
|
---|
| 3085 | /* @} - end of LLarchiveGroup */
|
---|
| 3086 |
|
---|
| 3087 |
|
---|
| 3088 |
|
---|
| 3089 | /**
|
---|
| 3090 | * @addtogroup utilityGroup
|
---|
| 3091 | * @{
|
---|
| 3092 | */
|
---|
| 3093 | /**
|
---|
| 3094 | * Make sure the user has a valid CD-R(W) in the CD drive.
|
---|
| 3095 | * @param cdrw_dev Set to the CD-R(W) device checked.
|
---|
| 3096 | * @param keep_looping If TRUE, keep pestering user until they insist
|
---|
| 3097 | * or insert a correct CD; if FALSE, only check once.
|
---|
| 3098 | * @return 0 (there was an OK CD in the drive) or 1 (there wasn't).
|
---|
| 3099 | */
|
---|
[128] | 3100 | int interrogate_disk_currently_in_cdrw_drive(char *cdrw_dev,
|
---|
| 3101 | bool keep_looping)
|
---|
[1] | 3102 | {
|
---|
[128] | 3103 | char *tmp;
|
---|
| 3104 | int res = 0;
|
---|
| 3105 | char *bkp;
|
---|
| 3106 | char *cdrecord;
|
---|
[1] | 3107 |
|
---|
[128] | 3108 | malloc_string(tmp);
|
---|
| 3109 | malloc_string(bkp);
|
---|
| 3110 | malloc_string(cdrecord);
|
---|
| 3111 | strcpy(bkp, cdrw_dev);
|
---|
| 3112 | if (find_cdrw_device(cdrw_dev)) {
|
---|
| 3113 | strcpy(cdrw_dev, bkp);
|
---|
| 3114 | } else {
|
---|
| 3115 | if (!system("which cdrecord > /dev/null 2> /dev/null")) {
|
---|
| 3116 | sprintf(cdrecord, "cdrecord dev=%s -atip", cdrw_dev);
|
---|
| 3117 | } else if (!system("which dvdrecord > /dev/null 2> /dev/null")) {
|
---|
| 3118 | sprintf(cdrecord, "cdrecord dev=%s -atip", cdrw_dev);
|
---|
| 3119 | } else {
|
---|
| 3120 | cdrecord[0] = '\0';
|
---|
| 3121 | log_msg(2, "Oh well. I guess I'll just pray then.");
|
---|
| 3122 | }
|
---|
| 3123 | if (cdrecord[0]) {
|
---|
| 3124 | if (!keep_looping) {
|
---|
| 3125 | retract_CD_tray_and_defeat_autorun();
|
---|
| 3126 | res = run_program_and_log_output(cdrecord, 5);
|
---|
| 3127 | } else {
|
---|
| 3128 | while ((res = run_program_and_log_output(cdrecord, 5))) {
|
---|
| 3129 | retract_CD_tray_and_defeat_autorun();
|
---|
| 3130 | if (ask_me_yes_or_no
|
---|
| 3131 | ("Unable to examine CD. Are you sure this is a valid CD-R(W) CD?"))
|
---|
| 3132 | {
|
---|
| 3133 | log_msg(1, "Well, he insisted...");
|
---|
| 3134 | break;
|
---|
| 3135 | }
|
---|
| 3136 | }
|
---|
| 3137 | }
|
---|
| 3138 | }
|
---|
| 3139 | }
|
---|
[1] | 3140 | // retract_CD_tray_and_defeat_autorun();
|
---|
[128] | 3141 | paranoid_free(tmp);
|
---|
| 3142 | paranoid_free(cdrecord);
|
---|
| 3143 | paranoid_free(bkp);
|
---|
| 3144 | return (res);
|
---|
[1] | 3145 | }
|
---|
| 3146 |
|
---|
| 3147 |
|
---|
| 3148 |
|
---|
| 3149 |
|
---|
| 3150 |
|
---|
| 3151 |
|
---|
| 3152 |
|
---|
| 3153 |
|
---|
| 3154 |
|
---|
| 3155 | /**
|
---|
| 3156 | * Asks the user to put a CD-R(W) in the drive.
|
---|
| 3157 | * @param ask_for_one_if_more_than_this (unused)
|
---|
| 3158 | * @param pmountable If non-NULL, pointed-to value is set to TRUE if the CD is mountable, FALSE otherwise.
|
---|
| 3159 | */
|
---|
| 3160 | void
|
---|
[128] | 3161 | pause_and_ask_for_cdr(int ask_for_one_if_more_than_this, bool * pmountable)
|
---|
[1] | 3162 | {
|
---|
| 3163 |
|
---|
[128] | 3164 | /*@ buffers ********************************************* */
|
---|
| 3165 | char *tmp;
|
---|
| 3166 | char *szmsg;
|
---|
| 3167 | char *cdrom_dev;
|
---|
| 3168 | char *cdrw_dev;
|
---|
| 3169 | char *our_serial_str;
|
---|
| 3170 | bool ok_go_ahead_burn_it;
|
---|
| 3171 | int cd_number = -1;
|
---|
| 3172 | int attempt_to_mount_returned_this = 999;
|
---|
| 3173 | char *mtpt;
|
---|
| 3174 | char *szcdno;
|
---|
| 3175 | char *szserfname;
|
---|
| 3176 | char *szunmount;
|
---|
[1] | 3177 |
|
---|
[128] | 3178 | malloc_string(tmp);
|
---|
| 3179 | malloc_string(szmsg);
|
---|
| 3180 | malloc_string(cdrom_dev);
|
---|
| 3181 | malloc_string(cdrw_dev);
|
---|
| 3182 | malloc_string(mtpt);
|
---|
| 3183 | malloc_string(szcdno);
|
---|
| 3184 | malloc_string(szserfname);
|
---|
| 3185 | malloc_string(our_serial_str);
|
---|
| 3186 | malloc_string(szunmount);
|
---|
[1] | 3187 |
|
---|
[128] | 3188 | sprintf(szmsg, "I am about to burn %s #%d",
|
---|
| 3189 | media_descriptor_string(g_backup_media_type),
|
---|
| 3190 | g_current_media_number);
|
---|
| 3191 | log_to_screen(szmsg);
|
---|
| 3192 | if (g_current_media_number < ask_for_one_if_more_than_this) {
|
---|
| 3193 | return;
|
---|
| 3194 | }
|
---|
| 3195 | log_to_screen("Scanning CD-ROM drive...");
|
---|
| 3196 | sprintf(mtpt, "/tmp/cd.mtpt.%ld.%ld", (long int) random(),
|
---|
| 3197 | (long int) random());
|
---|
| 3198 | make_hole_for_dir(mtpt);
|
---|
[1] | 3199 |
|
---|
[128] | 3200 | gotos_make_me_puke:
|
---|
| 3201 | ok_go_ahead_burn_it = TRUE;
|
---|
| 3202 | if (!find_cdrom_device(cdrom_dev, FALSE)) {
|
---|
[1] | 3203 | /* When enabled, it made CD eject-and-retract when wrong CD inserted.. Weird
|
---|
| 3204 | log_msg(2, "paafcd: Retracting CD-ROM drive if possible" );
|
---|
| 3205 | retract_CD_tray_and_defeat_autorun();
|
---|
| 3206 | */
|
---|
[128] | 3207 | sprintf(tmp, "umount %s", cdrom_dev);
|
---|
| 3208 | run_program_and_log_output(tmp, 1);
|
---|
| 3209 | sprintf(szcdno, "%s/archives/THIS-CD-NUMBER", mtpt);
|
---|
| 3210 | sprintf(szserfname, "%s/archives/SERIAL-STRING", mtpt);
|
---|
| 3211 | sprintf(szunmount, "umount %s", mtpt);
|
---|
| 3212 | cd_number = -1;
|
---|
| 3213 | our_serial_str[0] = '\0';
|
---|
| 3214 | sprintf(tmp, "mount %s %s", cdrom_dev, mtpt);
|
---|
| 3215 | if ((attempt_to_mount_returned_this =
|
---|
| 3216 | run_program_and_log_output(tmp, 1))) {
|
---|
| 3217 | log_msg(4, "Failed to mount %s at %s", cdrom_dev, mtpt);
|
---|
| 3218 | log_to_screen("If there's a CD/DVD in the drive, it's blank.");
|
---|
| 3219 | /*
|
---|
| 3220 | if (interrogate_disk_currently_in_cdrw_drive(cdrw_dev, FALSE))
|
---|
| 3221 | {
|
---|
| 3222 | ok_go_ahead_burn_it = FALSE;
|
---|
| 3223 | log_to_screen("There isn't a writable CD/DVD in the drive.");
|
---|
| 3224 | }
|
---|
| 3225 | else
|
---|
| 3226 | {
|
---|
| 3227 | log_to_screen("Confirmed. There is a blank CD/DVD in the drive.");
|
---|
| 3228 | }
|
---|
| 3229 | */
|
---|
| 3230 | } else if (!does_file_exist(szcdno)
|
---|
| 3231 | || !does_file_exist(szserfname)) {
|
---|
| 3232 | log_to_screen
|
---|
| 3233 | ("%s has data on it but it's probably not a Mondo CD.",
|
---|
| 3234 | media_descriptor_string(g_backup_media_type));
|
---|
| 3235 | } else {
|
---|
| 3236 | log_to_screen("%s found in drive. It's a Mondo disk.",
|
---|
| 3237 | media_descriptor_string(g_backup_media_type));
|
---|
| 3238 | cd_number = atoi(last_line_of_file(szcdno));
|
---|
| 3239 | sprintf(tmp, "cat %s 2> /dev/null", szserfname);
|
---|
| 3240 | strcpy(our_serial_str,
|
---|
| 3241 | call_program_and_get_last_line_of_output(tmp));
|
---|
| 3242 | // FIXME - should be able to use last_line_of_file(), surely?
|
---|
| 3243 | }
|
---|
| 3244 | run_program_and_log_output(szunmount, 1);
|
---|
| 3245 | log_msg(2, "paafcd: cd_number = %d", cd_number);
|
---|
| 3246 | log_msg(2, "our serial str = %s; g_serial_string = %s",
|
---|
| 3247 | our_serial_str, g_serial_string);
|
---|
| 3248 | if (cd_number > 0 && !strcmp(our_serial_str, g_serial_string)) {
|
---|
| 3249 | log_msg(2, "This %s is part of this backup set!",
|
---|
| 3250 | media_descriptor_string(g_backup_media_type));
|
---|
| 3251 | ok_go_ahead_burn_it = FALSE;
|
---|
| 3252 | if (cd_number == g_current_media_number - 1) {
|
---|
| 3253 | log_to_screen
|
---|
| 3254 | ("I think you've left the previous %s in the drive.",
|
---|
| 3255 | media_descriptor_string(g_backup_media_type));
|
---|
| 3256 | } else {
|
---|
| 3257 | log_to_screen
|
---|
| 3258 | ("Please remove this %s. It is part of the backup set you're making now.",
|
---|
| 3259 | media_descriptor_string(g_backup_media_type));
|
---|
| 3260 | }
|
---|
| 3261 | } else {
|
---|
| 3262 | log_to_screen("...but not part of _our_ backup set.");
|
---|
| 3263 | }
|
---|
| 3264 | } else {
|
---|
| 3265 | log_msg(2,
|
---|
| 3266 | "paafcd: Can't find CD-ROM drive. Perhaps it has a blank %s in it?",
|
---|
| 3267 | media_descriptor_string(g_backup_media_type));
|
---|
| 3268 | if (interrogate_disk_currently_in_cdrw_drive(cdrw_dev, FALSE)) {
|
---|
| 3269 | ok_go_ahead_burn_it = FALSE;
|
---|
| 3270 | log_to_screen("There isn't a writable %s in the drive.",
|
---|
| 3271 | media_descriptor_string(g_backup_media_type));
|
---|
| 3272 | }
|
---|
[1] | 3273 | }
|
---|
| 3274 |
|
---|
| 3275 | /*
|
---|
| 3276 | if (g_current_media_number > ask_for_one_if_more_than_this)
|
---|
| 3277 | {
|
---|
| 3278 | ok_go_ahead_burn_it = FALSE;
|
---|
| 3279 | log_it("paafcd: %d > %d, so I'll definitely pause.", g_current_media_number > ask_for_one_if_more_than_this);
|
---|
| 3280 | }
|
---|
| 3281 | */
|
---|
| 3282 |
|
---|
[128] | 3283 | if (!ok_go_ahead_burn_it) {
|
---|
| 3284 | eject_device(cdrom_dev);
|
---|
| 3285 | sprintf(tmp,
|
---|
| 3286 | "I am about to burn %s #%d of the backup set. Please insert %s and press Enter.",
|
---|
| 3287 | media_descriptor_string(g_backup_media_type),
|
---|
| 3288 | g_current_media_number,
|
---|
| 3289 | media_descriptor_string(g_backup_media_type));
|
---|
| 3290 | popup_and_OK(tmp);
|
---|
| 3291 | goto gotos_make_me_puke;
|
---|
| 3292 | } else {
|
---|
| 3293 | log_msg(2, "paafcd: OK, going ahead and burning it.");
|
---|
| 3294 | }
|
---|
[1] | 3295 |
|
---|
[128] | 3296 | log_msg(2,
|
---|
| 3297 | "paafcd: OK, I assume I have a blank/reusable %s in the drive...",
|
---|
| 3298 | media_descriptor_string(g_backup_media_type));
|
---|
[1] | 3299 |
|
---|
[128] | 3300 | // if (ask_for_one_if_more_than_this>1) { popup_and_OK(szmsg); }
|
---|
[1] | 3301 |
|
---|
[128] | 3302 | log_to_screen("Proceeding w/ %s in drive.",
|
---|
| 3303 | media_descriptor_string(g_backup_media_type));
|
---|
| 3304 | paranoid_free(tmp);
|
---|
| 3305 | paranoid_free(szmsg);
|
---|
| 3306 | paranoid_free(cdrom_dev);
|
---|
| 3307 | paranoid_free(cdrw_dev);
|
---|
| 3308 | paranoid_free(mtpt);
|
---|
| 3309 | paranoid_free(szcdno);
|
---|
| 3310 | paranoid_free(szserfname);
|
---|
| 3311 | paranoid_free(our_serial_str);
|
---|
| 3312 | paranoid_free(szunmount);
|
---|
| 3313 | if (pmountable) {
|
---|
| 3314 | if (attempt_to_mount_returned_this) {
|
---|
| 3315 | *pmountable = FALSE;
|
---|
| 3316 | } else {
|
---|
| 3317 | *pmountable = TRUE;
|
---|
| 3318 | }
|
---|
| 3319 | }
|
---|
[1] | 3320 |
|
---|
| 3321 | }
|
---|
| 3322 |
|
---|
| 3323 |
|
---|
| 3324 |
|
---|
| 3325 |
|
---|
| 3326 |
|
---|
| 3327 |
|
---|
| 3328 |
|
---|
| 3329 |
|
---|
| 3330 | /**
|
---|
| 3331 | * Set the <tt>N</tt>th bit of @c array to @c true_or_false.
|
---|
| 3332 | * @param array The bit array (as a @c char pointer).
|
---|
| 3333 | * @param N The bit number to set or reset.
|
---|
| 3334 | * @param true_or_false If TRUE then set bit @c N, if FALSE then reset bit @c N.
|
---|
| 3335 | * @see get_bit_N_of_array
|
---|
| 3336 | */
|
---|
[128] | 3337 | void set_bit_N_of_array(char *array, int N, bool true_or_false)
|
---|
[1] | 3338 | {
|
---|
[128] | 3339 | int bit_number;
|
---|
| 3340 | int mask, orig_val, to_add;
|
---|
| 3341 | int element_number;
|
---|
[1] | 3342 |
|
---|
[128] | 3343 | assert(array != NULL);
|
---|
[1] | 3344 |
|
---|
[128] | 3345 | element_number = N / 8;
|
---|
| 3346 | bit_number = N % 8;
|
---|
| 3347 | to_add = (1 << bit_number);
|
---|
| 3348 | mask = 255 - to_add;
|
---|
| 3349 | orig_val = array[element_number] & mask;
|
---|
| 3350 | // log_it("array[%d]=%02x; %02x&%02x = %02x", element_number, array[element_number], mask, orig_val);
|
---|
| 3351 | if (true_or_false) {
|
---|
| 3352 | array[element_number] = orig_val | to_add;
|
---|
| 3353 | }
|
---|
[1] | 3354 | }
|
---|
| 3355 |
|
---|
| 3356 | /* @} - end of utilityGroup */
|
---|
| 3357 |
|
---|
| 3358 |
|
---|
| 3359 |
|
---|
| 3360 |
|
---|
| 3361 |
|
---|
| 3362 |
|
---|
| 3363 |
|
---|
| 3364 |
|
---|
| 3365 | /**
|
---|
| 3366 | * Chop up @c filename.
|
---|
| 3367 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 3368 | * - @c backup_media_type
|
---|
| 3369 | * - @c compression_level
|
---|
| 3370 | * - @c optimal_set_size
|
---|
| 3371 | * - @c tmpdir
|
---|
| 3372 | * - @c use_lzo
|
---|
| 3373 | * - @c zip_exe
|
---|
| 3374 | * - @c zip_suffix
|
---|
| 3375 | *
|
---|
| 3376 | * @param biggie_filename The file to chop up.
|
---|
[296] | 3377 | * @param ntfsprog_fifo The FIFO to ntfsclone if this is an imagedev, NULL otherwise.
|
---|
[1] | 3378 | * @param biggie_file_number The sequence number of this biggie file (starting from 0).
|
---|
| 3379 | * @param noof_biggie_files The number of biggie files there are total.
|
---|
| 3380 | * @return The number of errors encountered (0 for success)
|
---|
| 3381 | * @see make_slices_and_images
|
---|
| 3382 | * @ingroup LLarchiveGroup
|
---|
| 3383 | */
|
---|
| 3384 | int
|
---|
[541] | 3385 | slice_up_file_etc(struct s_bkpinfo *bkpinfo, char *biggie_filename,
|
---|
[296] | 3386 | char *ntfsprog_fifo, long biggie_file_number,
|
---|
| 3387 | long noof_biggie_files, bool use_ntfsprog)
|
---|
[1] | 3388 | {
|
---|
| 3389 |
|
---|
[128] | 3390 | /*@ buffers ************************************************** */
|
---|
| 3391 | char *tmp, *checksum_line, *command;
|
---|
| 3392 | char *tempblock;
|
---|
| 3393 | char *curr_slice_fname_uncompressed;
|
---|
| 3394 | char *curr_slice_fname_compressed;
|
---|
| 3395 | char *file_to_archive;
|
---|
| 3396 | char *file_to_openin;
|
---|
| 3397 | /*@ pointers ************************************************** */
|
---|
| 3398 | char *pB;
|
---|
[1552] | 3399 | FILE *fin = NULL, *fout = NULL;
|
---|
[1] | 3400 |
|
---|
[128] | 3401 | /*@ bool ****************************************************** */
|
---|
| 3402 | bool finished = FALSE;
|
---|
[1] | 3403 |
|
---|
[128] | 3404 | /*@ long ****************************************************** */
|
---|
| 3405 | size_t blksize = 0;
|
---|
| 3406 | long slice_num = 0;
|
---|
| 3407 | long i;
|
---|
| 3408 | long optimal_set_size;
|
---|
| 3409 | bool should_I_compress_slices;
|
---|
| 3410 | char *suffix; // for compressed slices
|
---|
[1] | 3411 |
|
---|
[128] | 3412 | /*@ long long ************************************************** */
|
---|
[684] | 3413 | off_t totalread = (off_t)0;
|
---|
| 3414 | off_t totallength = (off_t)0;
|
---|
| 3415 | off_t length;
|
---|
[1] | 3416 |
|
---|
[128] | 3417 | /*@ int ******************************************************** */
|
---|
| 3418 | int retval = 0;
|
---|
| 3419 | int res = 0;
|
---|
[1] | 3420 |
|
---|
[128] | 3421 | /*@ structures ************************************************** */
|
---|
| 3422 | struct s_filename_and_lstat_info biggiestruct;
|
---|
[1] | 3423 | // struct stat statbuf;
|
---|
| 3424 |
|
---|
[128] | 3425 | assert(bkpinfo != NULL);
|
---|
| 3426 | assert_string_is_neither_NULL_nor_zerolength(biggie_filename);
|
---|
| 3427 | malloc_string(tmp);
|
---|
| 3428 | malloc_string(checksum_line);
|
---|
| 3429 | malloc_string(curr_slice_fname_uncompressed);
|
---|
| 3430 | malloc_string(curr_slice_fname_compressed);
|
---|
| 3431 | malloc_string(file_to_archive);
|
---|
| 3432 | malloc_string(suffix);
|
---|
| 3433 | command = malloc(MAX_STR_LEN * 8);
|
---|
[1] | 3434 |
|
---|
[128] | 3435 | biggiestruct.for_backward_compatibility = '\n';
|
---|
[296] | 3436 | biggiestruct.use_ntfsprog = use_ntfsprog;
|
---|
[128] | 3437 | if (!(tempblock = (char *) malloc(256 * 1024))) {
|
---|
| 3438 | fatal_error("malloc error 256*1024");
|
---|
| 3439 | }
|
---|
| 3440 | optimal_set_size = bkpinfo->optimal_set_size;
|
---|
| 3441 | if (is_this_file_compressed(biggie_filename)
|
---|
| 3442 | || bkpinfo->compression_level == 0) {
|
---|
| 3443 | suffix[0] = '\0';
|
---|
| 3444 | // log_it("%s is indeed compressed :-)", filename);
|
---|
| 3445 | should_I_compress_slices = FALSE;
|
---|
| 3446 | } else {
|
---|
| 3447 | strcpy(suffix, bkpinfo->zip_suffix);
|
---|
| 3448 | should_I_compress_slices = TRUE;
|
---|
| 3449 | }
|
---|
[1] | 3450 |
|
---|
[128] | 3451 | if (optimal_set_size < 999) {
|
---|
| 3452 | fatal_error("bkpinfo->optimal_set_size is insanely small");
|
---|
| 3453 | }
|
---|
[296] | 3454 | if (ntfsprog_fifo) {
|
---|
| 3455 | file_to_openin = ntfsprog_fifo;
|
---|
[128] | 3456 | strcpy(checksum_line, "IGNORE");
|
---|
| 3457 | log_msg(2,
|
---|
| 3458 | "Not calculating checksum for %s: it would take too long",
|
---|
| 3459 | biggie_filename);
|
---|
[296] | 3460 | if ( !find_home_of_exe("ntfsresize")) {
|
---|
| 3461 | fatal_error("ntfsresize not found");
|
---|
| 3462 | }
|
---|
| 3463 | sprintf(command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", biggie_filename);
|
---|
| 3464 | log_it("command = %s", command);
|
---|
| 3465 | strcpy (tmp, call_program_and_get_last_line_of_output(command));
|
---|
| 3466 | log_it("res of it = %s", tmp);
|
---|
[684] | 3467 | totallength = (off_t)atoll(tmp);
|
---|
[128] | 3468 | } else {
|
---|
| 3469 | file_to_openin = biggie_filename;
|
---|
[693] | 3470 | if (strchr(biggie_filename,'\'') != NULL) {
|
---|
| 3471 | sprintf(command, "md5sum \"%s\"", biggie_filename);
|
---|
| 3472 | } else {
|
---|
| 3473 | sprintf(command, "md5sum '%s'", biggie_filename);
|
---|
| 3474 | }
|
---|
[128] | 3475 | if (!(fin = popen(command, "r"))) {
|
---|
| 3476 | log_OS_error("Unable to popen-in command");
|
---|
| 3477 | return (1);
|
---|
| 3478 | }
|
---|
| 3479 | (void) fgets(checksum_line, MAX_STR_LEN, fin);
|
---|
| 3480 | pclose(fin);
|
---|
[167] | 3481 | totallength = length_of_file (biggie_filename);
|
---|
[128] | 3482 | }
|
---|
| 3483 | lstat(biggie_filename, &biggiestruct.properties);
|
---|
| 3484 | strcpy(biggiestruct.filename, biggie_filename);
|
---|
| 3485 | pB = strchr(checksum_line, ' ');
|
---|
| 3486 | if (!pB) {
|
---|
| 3487 | pB = strchr(checksum_line, '\t');
|
---|
| 3488 | }
|
---|
| 3489 | if (pB) {
|
---|
| 3490 | *pB = '\0';
|
---|
| 3491 | }
|
---|
| 3492 | strcpy(biggiestruct.checksum, checksum_line);
|
---|
[1] | 3493 |
|
---|
[128] | 3494 | strcpy(tmp, slice_fname(biggie_file_number, 0, bkpinfo->tmpdir, ""));
|
---|
| 3495 | fout = fopen(tmp, "w");
|
---|
[1236] | 3496 | if (fout == NULL) {
|
---|
[1261] | 3497 | log_msg(1, "Unable to open and write to %s\n", tmp);
|
---|
[1236] | 3498 | paranoid_free(tmp);
|
---|
| 3499 | paranoid_free(suffix);
|
---|
| 3500 | return (1);
|
---|
| 3501 | }
|
---|
| 3502 |
|
---|
[128] | 3503 | (void) fwrite((void *) &biggiestruct, 1, sizeof(biggiestruct), fout);
|
---|
[1552] | 3504 | paranoid_fclose(fout);
|
---|
[128] | 3505 | length = totallength / optimal_set_size / 1024;
|
---|
| 3506 | log_msg(1, "Opening in %s; slicing it and writing to CD/tape",
|
---|
| 3507 | file_to_openin);
|
---|
| 3508 | if (!(fin = fopen(file_to_openin, "r"))) {
|
---|
| 3509 | log_OS_error("Unable to openin biggie_filename");
|
---|
| 3510 | sprintf(tmp, "Cannot archive bigfile '%s': not found",
|
---|
| 3511 | biggie_filename);
|
---|
| 3512 | log_to_screen(tmp);
|
---|
| 3513 | paranoid_free(tempblock);
|
---|
| 3514 | paranoid_free(tmp);
|
---|
| 3515 | paranoid_free(checksum_line);
|
---|
| 3516 | paranoid_free(command);
|
---|
| 3517 | return (1);
|
---|
| 3518 | }
|
---|
| 3519 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 3520 | res =
|
---|
| 3521 | move_files_to_stream(bkpinfo,
|
---|
| 3522 | slice_fname(biggie_file_number, 0,
|
---|
| 3523 | bkpinfo->tmpdir, ""), NULL);
|
---|
| 3524 | } else {
|
---|
| 3525 | res =
|
---|
[541] | 3526 | move_files_to_cd(bkpinfo,
|
---|
[128] | 3527 | slice_fname(biggie_file_number, 0,
|
---|
| 3528 | bkpinfo->tmpdir, ""), NULL);
|
---|
| 3529 | }
|
---|
| 3530 | i = bkpinfo->optimal_set_size / 256;
|
---|
| 3531 | for (slice_num = 1; !finished; slice_num++) {
|
---|
| 3532 | strcpy(curr_slice_fname_uncompressed,
|
---|
| 3533 | slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir,
|
---|
| 3534 | ""));
|
---|
| 3535 | strcpy(curr_slice_fname_compressed,
|
---|
| 3536 | slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir,
|
---|
| 3537 | suffix));
|
---|
[1] | 3538 |
|
---|
[128] | 3539 | strcpy(tmp, percent_media_full_comment(bkpinfo));
|
---|
| 3540 | update_progress_form(tmp);
|
---|
| 3541 | if (!(fout = fopen(curr_slice_fname_uncompressed, "w"))) {
|
---|
| 3542 | log_OS_error(curr_slice_fname_uncompressed);
|
---|
| 3543 | return (1);
|
---|
[1] | 3544 | }
|
---|
[128] | 3545 | if ((i == bkpinfo->optimal_set_size / 256)
|
---|
| 3546 | && (totalread < 1.1 * totallength)) {
|
---|
| 3547 | for (i = 0; i < bkpinfo->optimal_set_size / 256; i++) {
|
---|
| 3548 | blksize = fread(tempblock, 1, 256 * 1024, fin);
|
---|
| 3549 | if (blksize > 0) {
|
---|
| 3550 | totalread = totalread + blksize;
|
---|
| 3551 | (void) fwrite(tempblock, 1, blksize, fout);
|
---|
| 3552 | } else {
|
---|
| 3553 | break;
|
---|
| 3554 | }
|
---|
| 3555 | }
|
---|
| 3556 | } else {
|
---|
| 3557 | i = 0;
|
---|
| 3558 | }
|
---|
| 3559 | paranoid_fclose(fout);
|
---|
| 3560 | if (i > 0) // length_of_file (curr_slice_fname_uncompressed)
|
---|
[1] | 3561 | {
|
---|
[128] | 3562 | if (!does_file_exist(curr_slice_fname_uncompressed)) {
|
---|
| 3563 | log_msg(2,
|
---|
| 3564 | "Warning - '%s' doesn't exist. How can I compress slice?",
|
---|
| 3565 | curr_slice_fname_uncompressed);
|
---|
| 3566 | }
|
---|
| 3567 | if (should_I_compress_slices && bkpinfo->compression_level > 0) {
|
---|
| 3568 | sprintf(command, "%s -%d %s", bkpinfo->zip_exe,
|
---|
| 3569 | bkpinfo->compression_level,
|
---|
| 3570 | curr_slice_fname_uncompressed);
|
---|
| 3571 | log_msg(2, command);
|
---|
| 3572 | if ((res = system(command))) {
|
---|
| 3573 | log_OS_error(command);
|
---|
| 3574 | }
|
---|
| 3575 | // did_I_compress_slice = TRUE;
|
---|
| 3576 | } else {
|
---|
| 3577 | sprintf(command, "mv %s %s 2>> %s",
|
---|
| 3578 | curr_slice_fname_uncompressed,
|
---|
| 3579 | curr_slice_fname_compressed, MONDO_LOGFILE);
|
---|
| 3580 | res = 0; // don't do it :)
|
---|
| 3581 | // did_I_compress_slice = FALSE;
|
---|
| 3582 | }
|
---|
| 3583 | retval += res;
|
---|
| 3584 | if (res) {
|
---|
| 3585 | log_msg(2, "Failed to compress the slice");
|
---|
| 3586 | }
|
---|
| 3587 | if (bkpinfo->use_lzo
|
---|
| 3588 | && strcmp(curr_slice_fname_compressed,
|
---|
| 3589 | curr_slice_fname_uncompressed)) {
|
---|
| 3590 | unlink(curr_slice_fname_uncompressed);
|
---|
| 3591 | }
|
---|
| 3592 | if (res) {
|
---|
| 3593 | sprintf(tmp, "Problem with slice # %ld", slice_num);
|
---|
| 3594 | } else {
|
---|
| 3595 | sprintf(tmp,
|
---|
| 3596 | "%s - Bigfile #%ld, slice #%ld compressed OK ",
|
---|
| 3597 | biggie_filename, biggie_file_number + 1,
|
---|
| 3598 | slice_num);
|
---|
| 3599 | }
|
---|
[1] | 3600 | #ifndef _XWIN
|
---|
[128] | 3601 | if (!g_text_mode) {
|
---|
| 3602 | newtDrawRootText(0, g_noof_rows - 2, tmp);
|
---|
| 3603 | newtRefresh();
|
---|
| 3604 | } else {
|
---|
| 3605 | log_msg(2, tmp);
|
---|
| 3606 | }
|
---|
[1] | 3607 | #else
|
---|
[128] | 3608 | log_msg(2, tmp);
|
---|
[1] | 3609 | #endif
|
---|
[128] | 3610 | strcpy(file_to_archive, curr_slice_fname_compressed);
|
---|
| 3611 | g_current_progress++;
|
---|
| 3612 | } else { /* if i==0 then ... */
|
---|
[1] | 3613 |
|
---|
[128] | 3614 | finished = TRUE;
|
---|
| 3615 | strcpy(file_to_archive, curr_slice_fname_uncompressed);
|
---|
| 3616 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 3617 | break;
|
---|
| 3618 | }
|
---|
| 3619 | }
|
---|
| 3620 |
|
---|
| 3621 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 3622 | register_in_tape_catalog(biggieslice, biggie_file_number,
|
---|
| 3623 | slice_num, file_to_archive);
|
---|
| 3624 | maintain_collection_of_recent_archives(bkpinfo->tmpdir,
|
---|
| 3625 | file_to_archive);
|
---|
| 3626 | res = move_files_to_stream(bkpinfo, file_to_archive, NULL);
|
---|
| 3627 | } else {
|
---|
[541] | 3628 | res = move_files_to_cd(bkpinfo, file_to_archive, NULL);
|
---|
[128] | 3629 | }
|
---|
| 3630 | retval += res;
|
---|
| 3631 | if (res) {
|
---|
| 3632 | sprintf(tmp,
|
---|
| 3633 | "Failed to add slice %ld of bigfile %ld to scratchdir",
|
---|
| 3634 | slice_num, biggie_file_number + 1);
|
---|
| 3635 | log_to_screen(tmp);
|
---|
| 3636 | fatal_error
|
---|
| 3637 | ("Hard disk full. You should have bought a bigger one.");
|
---|
| 3638 | }
|
---|
[1] | 3639 | }
|
---|
[128] | 3640 | paranoid_fclose(fin);
|
---|
| 3641 | sprintf(tmp, "Sliced bigfile #%ld", biggie_file_number + 1);
|
---|
| 3642 | if (retval) {
|
---|
| 3643 | strcat(tmp, "...FAILED");
|
---|
| 3644 | } else {
|
---|
| 3645 | strcat(tmp, "...OK!");
|
---|
[1] | 3646 | }
|
---|
[128] | 3647 | log_msg(1, tmp);
|
---|
| 3648 | paranoid_free(tempblock);
|
---|
| 3649 | paranoid_free(tmp);
|
---|
| 3650 | paranoid_free(checksum_line);
|
---|
| 3651 | paranoid_free(command);
|
---|
| 3652 | paranoid_free(curr_slice_fname_uncompressed);
|
---|
| 3653 | paranoid_free(curr_slice_fname_compressed);
|
---|
| 3654 | paranoid_free(file_to_archive);
|
---|
| 3655 | paranoid_free(suffix);
|
---|
| 3656 | return (retval);
|
---|
[1] | 3657 | }
|
---|
| 3658 |
|
---|
| 3659 |
|
---|
| 3660 |
|
---|
| 3661 |
|
---|
| 3662 |
|
---|
| 3663 |
|
---|
| 3664 | /**
|
---|
| 3665 | * Remove the archives in @c d.
|
---|
| 3666 | * This could possibly include any of:
|
---|
| 3667 | * - all afioballs (compressed and not)
|
---|
| 3668 | * - all filelists
|
---|
| 3669 | * - all slices
|
---|
| 3670 | * - all checksums
|
---|
| 3671 | * - a zero filler file
|
---|
| 3672 | *
|
---|
| 3673 | * @param d The directory to wipe the archives from.
|
---|
| 3674 | * @ingroup utilityGroup
|
---|
| 3675 | */
|
---|
[128] | 3676 | void wipe_archives(char *d)
|
---|
[1] | 3677 | {
|
---|
[128] | 3678 | /*@ buffers ********************************************* */
|
---|
| 3679 | char *tmp;
|
---|
| 3680 | char *dir;
|
---|
[1] | 3681 |
|
---|
[128] | 3682 | malloc_string(tmp);
|
---|
| 3683 | malloc_string(dir);
|
---|
| 3684 | assert_string_is_neither_NULL_nor_zerolength(d);
|
---|
[1] | 3685 |
|
---|
[128] | 3686 | sprintf(dir, "%s/archives", d);
|
---|
| 3687 | sprintf(tmp, "find %s -name '*.afio*' -exec rm -f '{}' \\;", dir);
|
---|
| 3688 | run_program_and_log_output(tmp, FALSE);
|
---|
| 3689 | sprintf(tmp, "find %s -name '*list.[0-9]*' -exec rm -f '{}' \\;", dir);
|
---|
| 3690 | run_program_and_log_output(tmp, FALSE);
|
---|
| 3691 | sprintf(tmp, "find %s -name 'slice*' -exec rm -f '{}' \\;", dir);
|
---|
| 3692 | run_program_and_log_output(tmp, FALSE);
|
---|
| 3693 | sprintf(tmp, "rm -f %s/cklist*", dir);
|
---|
| 3694 | run_program_and_log_output(tmp, FALSE);
|
---|
| 3695 | sprintf(tmp, "rm -f %s/zero", dir);
|
---|
| 3696 | run_program_and_log_output(tmp, FALSE);
|
---|
| 3697 | log_msg(1, "Wiped %s's archives", dir);
|
---|
| 3698 | sprintf(tmp, "ls -l %s", dir);
|
---|
| 3699 | run_program_and_log_output(tmp, FALSE);
|
---|
| 3700 | paranoid_free(tmp);
|
---|
| 3701 | paranoid_free(dir);
|
---|
[1] | 3702 | }
|
---|
| 3703 |
|
---|
| 3704 |
|
---|
| 3705 |
|
---|
| 3706 | /**
|
---|
| 3707 | * @addtogroup LLarchiveGroup
|
---|
| 3708 | * @{
|
---|
| 3709 | */
|
---|
| 3710 | /**
|
---|
| 3711 | * Write the final ISO image.
|
---|
| 3712 | * @param bkpinfo The backup information structure. Used only
|
---|
| 3713 | * in the call to @c write_iso_and_go_on().
|
---|
| 3714 | * @return The number of errors encountered (0 for success)
|
---|
| 3715 | * @see write_iso_and_go_on
|
---|
| 3716 | * @see make_iso_fs
|
---|
| 3717 | * @bug The final ISO is written even if there are no files on it. In practice,
|
---|
| 3718 | * however, this occurs rarely.
|
---|
| 3719 | */
|
---|
[541] | 3720 | int write_final_iso_if_necessary(struct s_bkpinfo *bkpinfo)
|
---|
[1] | 3721 | {
|
---|
[128] | 3722 | /*@ int ***************************************************** */
|
---|
| 3723 | int res;
|
---|
[1] | 3724 |
|
---|
[128] | 3725 | /*@ buffers ************************************************** */
|
---|
| 3726 | char *tmp;
|
---|
[1] | 3727 |
|
---|
[128] | 3728 | malloc_string(tmp);
|
---|
| 3729 | assert(bkpinfo != NULL);
|
---|
[1] | 3730 |
|
---|
| 3731 | // 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
|
---|
| 3732 |
|
---|
[128] | 3733 | sprintf(tmp, "Writing the final ISO");
|
---|
| 3734 | log_msg(2, tmp);
|
---|
| 3735 | center_string(tmp, 80);
|
---|
[1] | 3736 | #ifndef _XWIN
|
---|
[128] | 3737 | if (!g_text_mode) {
|
---|
| 3738 | newtPushHelpLine(tmp);
|
---|
| 3739 | }
|
---|
[1] | 3740 | #endif
|
---|
[541] | 3741 | res = write_iso_and_go_on(bkpinfo, TRUE);
|
---|
[1] | 3742 | #ifndef _XWIN
|
---|
[128] | 3743 | if (!g_text_mode) {
|
---|
| 3744 | newtPopHelpLine();
|
---|
| 3745 | }
|
---|
[1] | 3746 | #endif
|
---|
[128] | 3747 | log_msg(2, "Returning from writing final ISO (res=%d)", res);
|
---|
| 3748 | paranoid_free(tmp);
|
---|
| 3749 | return (res);
|
---|
[1] | 3750 | }
|
---|
| 3751 |
|
---|
| 3752 |
|
---|
| 3753 | /**
|
---|
[20] | 3754 | * Write an ISO image to <tt>[bkpinfo->isodir]/bkpinfo->prefix-[g_current_media_number].iso</tt>.
|
---|
[1] | 3755 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 3756 | * - @c backup_media_type
|
---|
[20] | 3757 | * - @c prefix
|
---|
[1] | 3758 | * - @c isodir
|
---|
| 3759 | * - @c manual_cd_tray
|
---|
| 3760 | * - @c media_size
|
---|
| 3761 | * - @c nfs_mount
|
---|
| 3762 | * - @c nfs_remote_dir
|
---|
| 3763 | * - @c scratchdir
|
---|
| 3764 | * - @c verify_data
|
---|
| 3765 | *
|
---|
| 3766 | * @param last_cd If TRUE, this is the last CD to write; if FALSE, it's not.
|
---|
| 3767 | * @return The number of errors encountered (0 for success)
|
---|
| 3768 | * @see make_iso_fs
|
---|
| 3769 | */
|
---|
[541] | 3770 | int write_iso_and_go_on(struct s_bkpinfo *bkpinfo, bool last_cd)
|
---|
[1] | 3771 | {
|
---|
[128] | 3772 | /*@ pointers **************************************************** */
|
---|
| 3773 | FILE *fout;
|
---|
[1] | 3774 |
|
---|
[128] | 3775 | /*@ buffers ***************************************************** */
|
---|
| 3776 | char *tmp;
|
---|
| 3777 | char *cdno_fname;
|
---|
| 3778 | char *lastcd_fname;
|
---|
| 3779 | char *isofile;
|
---|
[1] | 3780 |
|
---|
[128] | 3781 | /*@ bool ******************************************************** */
|
---|
| 3782 | bool that_one_was_ok;
|
---|
| 3783 | bool using_nfs;
|
---|
| 3784 | bool orig_vfy_flag_val;
|
---|
[1] | 3785 |
|
---|
[128] | 3786 | /*@ int *********************************************************** */
|
---|
| 3787 | int res = 0;
|
---|
[1] | 3788 |
|
---|
[128] | 3789 | malloc_string(tmp);
|
---|
| 3790 | malloc_string(cdno_fname);
|
---|
| 3791 | malloc_string(lastcd_fname);
|
---|
| 3792 | malloc_string(isofile);
|
---|
[1] | 3793 |
|
---|
[128] | 3794 | assert(bkpinfo != NULL);
|
---|
| 3795 | orig_vfy_flag_val = bkpinfo->verify_data;
|
---|
| 3796 | if (bkpinfo->media_size[g_current_media_number] <= 0) {
|
---|
| 3797 | fatal_error("write_iso_and_go_on() - unknown media size");
|
---|
| 3798 | }
|
---|
[1] | 3799 |
|
---|
[128] | 3800 | if (strlen(bkpinfo->nfs_mount) > 1) {
|
---|
| 3801 | using_nfs = TRUE;
|
---|
| 3802 | } else {
|
---|
| 3803 | using_nfs = FALSE;
|
---|
| 3804 | }
|
---|
| 3805 | log_msg(1, "OK, time to make %s #%d",
|
---|
| 3806 | media_descriptor_string(bkpinfo->backup_media_type),
|
---|
| 3807 | g_current_media_number);
|
---|
[1] | 3808 |
|
---|
[128] | 3809 | /* label the ISO with its number */
|
---|
[1] | 3810 |
|
---|
[128] | 3811 | sprintf(cdno_fname, "%s/archives/THIS-CD-NUMBER", bkpinfo->scratchdir);
|
---|
| 3812 | fout = fopen(cdno_fname, "w");
|
---|
| 3813 | fprintf(fout, "%d", g_current_media_number);
|
---|
| 3814 | paranoid_fclose(fout);
|
---|
[1] | 3815 |
|
---|
[128] | 3816 | sprintf(tmp, "cp -f %s/autorun %s/", g_mondo_home,
|
---|
| 3817 | bkpinfo->scratchdir);
|
---|
| 3818 | if (run_program_and_log_output(tmp, FALSE)) {
|
---|
| 3819 | log_msg(2, "Warning - unable to copy autorun to scratchdir");
|
---|
[1] | 3820 | }
|
---|
[128] | 3821 |
|
---|
| 3822 | /* last CD or not? Label accordingly */
|
---|
| 3823 | sprintf(lastcd_fname, "%s/archives/NOT-THE-LAST", bkpinfo->scratchdir);
|
---|
| 3824 | if (last_cd) {
|
---|
| 3825 | unlink(lastcd_fname);
|
---|
| 3826 | log_msg(2,
|
---|
| 3827 | "OK, you're telling me this is the last CD. Fair enough.");
|
---|
| 3828 | } else {
|
---|
| 3829 | fout = fopen(lastcd_fname, "w");
|
---|
| 3830 | fprintf(fout,
|
---|
| 3831 | "You're listening to 90.3 WPLN, Nashville Public Radio.\n");
|
---|
| 3832 | paranoid_fclose(fout);
|
---|
[1] | 3833 | }
|
---|
[128] | 3834 | if (space_occupied_by_cd(bkpinfo->scratchdir) / 1024 >
|
---|
| 3835 | bkpinfo->media_size[g_current_media_number]) {
|
---|
| 3836 | sprintf(tmp,
|
---|
| 3837 | "Warning! CD is too big. It occupies %ld KB, which is more than the %ld KB allowed.",
|
---|
| 3838 | (long) space_occupied_by_cd(bkpinfo->scratchdir),
|
---|
| 3839 | (long) bkpinfo->media_size[g_current_media_number]);
|
---|
| 3840 | log_to_screen(tmp);
|
---|
| 3841 | }
|
---|
| 3842 | sprintf(isofile, "%s/%s/%s-%d.iso", bkpinfo->isodir,
|
---|
| 3843 | bkpinfo->nfs_remote_dir, bkpinfo->prefix,
|
---|
| 3844 | g_current_media_number);
|
---|
| 3845 | for (that_one_was_ok = FALSE; !that_one_was_ok;) {
|
---|
[541] | 3846 | res = make_iso_fs(bkpinfo, isofile);
|
---|
[128] | 3847 | if (g_current_media_number == 1 && !res
|
---|
| 3848 | && (bkpinfo->backup_media_type == cdr
|
---|
| 3849 | || bkpinfo->backup_media_type == cdrw)) {
|
---|
| 3850 | if (find_cdrom_device(tmp, FALSE)) // make sure find_cdrom_device() finds, records CD-R's loc
|
---|
| 3851 | {
|
---|
| 3852 | log_msg(3, "*Sigh* Mike, I hate your computer.");
|
---|
| 3853 | bkpinfo->manual_cd_tray = TRUE;
|
---|
| 3854 | } // if it can't be found then force pausing
|
---|
| 3855 | else {
|
---|
| 3856 | log_msg(3, "Great. Found Mike's CD-ROM drive.");
|
---|
| 3857 | }
|
---|
[1] | 3858 | }
|
---|
[128] | 3859 | if (bkpinfo->verify_data && !res) {
|
---|
| 3860 | log_to_screen
|
---|
| 3861 | ("Please reboot from the 1st %s in Compare Mode, as a precaution.",
|
---|
| 3862 | media_descriptor_string(g_backup_media_type));
|
---|
| 3863 | chdir("/");
|
---|
| 3864 | iamhere("Before calling verify_cd_image()");
|
---|
| 3865 | res += verify_cd_image(bkpinfo);
|
---|
| 3866 | iamhere("After calling verify_cd_image()");
|
---|
[1] | 3867 | }
|
---|
[128] | 3868 | if (!res) {
|
---|
| 3869 | that_one_was_ok = TRUE;
|
---|
| 3870 | } else {
|
---|
| 3871 | sprintf(tmp, "Failed to burn %s #%d. Retry?",
|
---|
| 3872 | media_descriptor_string(bkpinfo->backup_media_type),
|
---|
| 3873 | g_current_media_number);
|
---|
| 3874 | res = ask_me_yes_or_no(tmp);
|
---|
| 3875 | if (!res) {
|
---|
| 3876 | if (ask_me_yes_or_no("Abort the backup?")) {
|
---|
| 3877 | fatal_error("FAILED TO BACKUP");
|
---|
| 3878 | } else {
|
---|
| 3879 | break;
|
---|
| 3880 | }
|
---|
| 3881 | } else {
|
---|
| 3882 | log_msg(2, "Retrying, at user's request...");
|
---|
| 3883 | res = 0;
|
---|
| 3884 | }
|
---|
| 3885 | }
|
---|
[1] | 3886 | }
|
---|
| 3887 | /*
|
---|
| 3888 | if (using_nfs)
|
---|
| 3889 | {
|
---|
| 3890 | sprintf(tmp,"mv -f %s %s/%s/", isofile, bkpinfo->isodir, bkpinfo->nfs_remote_dir);
|
---|
| 3891 | if (run_program_and_log_output(tmp, FALSE))
|
---|
| 3892 | { log_to_screen("Unable to move ISO to NFS dir"); }
|
---|
| 3893 | }
|
---|
| 3894 | */
|
---|
[128] | 3895 | g_current_media_number++;
|
---|
| 3896 | if (g_current_media_number > MAX_NOOF_MEDIA) {
|
---|
| 3897 | fatal_error("Too many CD-R(W)'s. Use tape or net.");
|
---|
| 3898 | }
|
---|
| 3899 | wipe_archives(bkpinfo->scratchdir);
|
---|
| 3900 | sprintf(tmp, "rm -Rf %s/images/*gz %s/images/*data*img",
|
---|
| 3901 | bkpinfo->scratchdir, bkpinfo->scratchdir);
|
---|
| 3902 | if (system(tmp)) {
|
---|
| 3903 | log_msg
|
---|
| 3904 | (2,
|
---|
| 3905 | "Error occurred when I tried to delete the redundant IMGs and GZs");
|
---|
| 3906 | }
|
---|
[1] | 3907 |
|
---|
[128] | 3908 | if (last_cd) {
|
---|
| 3909 | log_msg(2, "This was your last CD.");
|
---|
| 3910 | } else {
|
---|
| 3911 | log_msg(2, "Continuing to backup your data...");
|
---|
| 3912 | }
|
---|
[1] | 3913 |
|
---|
[128] | 3914 | bkpinfo->verify_data = orig_vfy_flag_val;
|
---|
| 3915 | paranoid_free(tmp);
|
---|
| 3916 | paranoid_free(cdno_fname);
|
---|
| 3917 | paranoid_free(lastcd_fname);
|
---|
| 3918 | paranoid_free(isofile);
|
---|
| 3919 | return (0);
|
---|
[1] | 3920 | }
|
---|
| 3921 |
|
---|
| 3922 | /* @} - end of LLarchiveGroup */
|
---|
| 3923 |
|
---|
| 3924 |
|
---|
| 3925 |
|
---|
| 3926 |
|
---|
| 3927 | /**
|
---|
| 3928 | * Verify the user's data.
|
---|
| 3929 | * @param bkpinfo The backup information structure. Fields used:
|
---|
| 3930 | * - @c backup_data
|
---|
| 3931 | * - @c backup_media_type
|
---|
| 3932 | * - @c media_device
|
---|
| 3933 | * - @c verify_data
|
---|
| 3934 | *
|
---|
| 3935 | * @return The number of errors encountered (0 for success)
|
---|
| 3936 | * @ingroup verifyGroup
|
---|
| 3937 | */
|
---|
| 3938 | int verify_data(struct s_bkpinfo *bkpinfo)
|
---|
| 3939 | {
|
---|
[128] | 3940 | int res = 0, retval = 0, cdno = 0;
|
---|
| 3941 | char *tmp;
|
---|
| 3942 | long diffs = 0;
|
---|
[1] | 3943 |
|
---|
[128] | 3944 | malloc_string(tmp);
|
---|
| 3945 | assert(bkpinfo != NULL);
|
---|
| 3946 | if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
|
---|
| 3947 | chdir("/");
|
---|
| 3948 | mvaddstr_and_log_it(g_currentY, 0,
|
---|
| 3949 | "Verifying archives against live filesystem");
|
---|
| 3950 | if (bkpinfo->backup_media_type == cdstream) {
|
---|
| 3951 | strcpy(bkpinfo->media_device, "/dev/cdrom");
|
---|
| 3952 | }
|
---|
| 3953 | verify_tape_backups(bkpinfo);
|
---|
| 3954 | mvaddstr_and_log_it(g_currentY++, 74, "Done.");
|
---|
| 3955 | } else if (bkpinfo->backup_data)
|
---|
| 3956 | //bkpinfo->backup_media_type == cdrw || bkpinfo->backup_media_type == cdr))
|
---|
[1] | 3957 | {
|
---|
[128] | 3958 | log_msg(2,
|
---|
| 3959 | "Not verifying again. Per-CD/ISO verification already carried out.");
|
---|
| 3960 | paranoid_system
|
---|
| 3961 | ("cat /tmp/changed.files.* > /tmp/changed.files 2> /dev/null");
|
---|
| 3962 | } else {
|
---|
| 3963 | g_current_media_number = cdno;
|
---|
| 3964 | if (bkpinfo->backup_media_type != iso) {
|
---|
| 3965 | find_cdrom_device(bkpinfo->media_device, FALSE); // replace 0,0,0 with /dev/cdrom
|
---|
[1] | 3966 | }
|
---|
[128] | 3967 | chdir("/");
|
---|
| 3968 | for (cdno = 1; cdno < 99 && bkpinfo->verify_data; cdno++) {
|
---|
| 3969 | if (cdno != g_current_media_number) {
|
---|
| 3970 | log_msg(2,
|
---|
| 3971 | "Warning - had to change g_current_media_number from %d to %d",
|
---|
| 3972 | g_current_media_number, cdno);
|
---|
| 3973 | g_current_media_number = cdno;
|
---|
| 3974 | }
|
---|
| 3975 | if (bkpinfo->backup_media_type != iso) {
|
---|
| 3976 | insist_on_this_cd_number(bkpinfo, cdno);
|
---|
| 3977 | }
|
---|
| 3978 | res = verify_cd_image(bkpinfo); // sets verify_data to FALSE if it's time to stop verifying
|
---|
| 3979 | retval += res;
|
---|
| 3980 | if (res) {
|
---|
| 3981 | sprintf(tmp,
|
---|
| 3982 | "Warnings/errors were reported while checking %s #%d",
|
---|
| 3983 | media_descriptor_string(bkpinfo->
|
---|
| 3984 | backup_media_type),
|
---|
| 3985 | g_current_media_number);
|
---|
| 3986 | log_to_screen(tmp);
|
---|
[1] | 3987 |
|
---|
[128] | 3988 | }
|
---|
[1] | 3989 | }
|
---|
| 3990 | /*
|
---|
| 3991 | sprintf (tmp,
|
---|
| 3992 | "cat %s | grep \"afio: \" | cut -d'\"' -f2 | sort -u | awk '{print \"/\"$0;};' | tr -s '/' '/' | grep -vx \"/afio:.*\" > /tmp/changed.files",
|
---|
| 3993 | MONDO_LOGFILE);
|
---|
| 3994 | system (tmp);
|
---|
| 3995 | */
|
---|
[128] | 3996 | sprintf(tmp,
|
---|
[911] | 3997 | "grep 'afio: ' %s | sed 's/afio: //' | grep -vE '^/dev/.*$' >> /tmp/changed.files",
|
---|
[128] | 3998 | MONDO_LOGFILE);
|
---|
| 3999 | system(tmp);
|
---|
| 4000 |
|
---|
| 4001 | sprintf(tmp,
|
---|
[911] | 4002 | "grep 'star: ' %s | sed 's/star: //' | grep -vE '^/dev/.*$' >> /tmp/changed.files",
|
---|
[128] | 4003 | MONDO_LOGFILE);
|
---|
| 4004 | system(tmp);
|
---|
| 4005 | run_program_and_log_output("umount " MNT_CDROM, FALSE);
|
---|
| 4006 | // if (bkpinfo->backup_media_type != iso && !bkpinfo->please_dont_eject_when_restoring)
|
---|
[1] | 4007 | //{
|
---|
[128] | 4008 | eject_device(bkpinfo->media_device);
|
---|
[1] | 4009 | //}
|
---|
| 4010 | }
|
---|
[128] | 4011 | diffs = count_lines_in_file("/tmp/changed.files");
|
---|
[1] | 4012 |
|
---|
[128] | 4013 | if (diffs > 0) {
|
---|
| 4014 | if (retval == 0) {
|
---|
| 4015 | retval = (int) (-diffs);
|
---|
| 4016 | }
|
---|
[1] | 4017 | }
|
---|
[128] | 4018 | paranoid_free(tmp);
|
---|
| 4019 | return (retval);
|
---|
[1] | 4020 | }
|
---|
| 4021 |
|
---|
| 4022 |
|
---|
| 4023 |
|
---|
| 4024 |
|
---|
| 4025 |
|
---|
| 4026 | /**
|
---|
| 4027 | * @addtogroup utilityGroup
|
---|
| 4028 | * @{
|
---|
| 4029 | */
|
---|
| 4030 | /**
|
---|
| 4031 | * Write an image to a real 3.5" floppy disk.
|
---|
| 4032 | * @param device The device to write to (e.g. @c /dev/fd0)
|
---|
| 4033 | * @param datafile The image to write to @p device.
|
---|
| 4034 | * @return The number of errors encountered (0 for success)
|
---|
| 4035 | * @see write_image_to_floppy
|
---|
| 4036 | */
|
---|
[128] | 4037 | int write_image_to_floppy_SUB(char *device, char *datafile)
|
---|
[1] | 4038 | {
|
---|
[128] | 4039 | /*@ int *************************************************************** */
|
---|
| 4040 | int res = 0;
|
---|
[1] | 4041 | int percentage = 0;
|
---|
| 4042 | int blockno = 0;
|
---|
[128] | 4043 | int maxblocks = 0;
|
---|
[1] | 4044 |
|
---|
[128] | 4045 | /*@ buffers************************************************************ */
|
---|
| 4046 | char *tmp;
|
---|
[1] | 4047 | char blk[1024];
|
---|
| 4048 | char *title;
|
---|
| 4049 |
|
---|
[128] | 4050 | /*@ pointers ********************************************************** */
|
---|
[1] | 4051 | char *p;
|
---|
[128] | 4052 | FILE *fout, *fin;
|
---|
[1] | 4053 |
|
---|
| 4054 |
|
---|
[128] | 4055 | malloc_string(tmp);
|
---|
| 4056 | malloc_string(title);
|
---|
| 4057 | /* pretty stuff */
|
---|
| 4058 | if (!(p = strrchr(datafile, '/'))) {
|
---|
| 4059 | p = datafile;
|
---|
| 4060 | } else {
|
---|
| 4061 | p++;
|
---|
[1] | 4062 | }
|
---|
[128] | 4063 | sprintf(title, "Writing %s to floppy", p);
|
---|
| 4064 | open_evalcall_form(title);
|
---|
| 4065 | /* functional stuff */
|
---|
| 4066 | for (p = device + strlen(device); p != device && isdigit(*(p - 1));
|
---|
| 4067 | p--);
|
---|
| 4068 | maxblocks = atoi(p);
|
---|
| 4069 | if (!maxblocks) {
|
---|
| 4070 | maxblocks = 1440;
|
---|
[1] | 4071 | }
|
---|
[128] | 4072 | sprintf(tmp, "maxblocks = %d; p=%s", maxblocks, p);
|
---|
| 4073 | log_msg(2, tmp);
|
---|
| 4074 | /* copy data from image to floppy */
|
---|
| 4075 | if (!(fin = fopen(datafile, "r"))) {
|
---|
| 4076 | log_OS_error("Cannot open img");
|
---|
| 4077 | return (1);
|
---|
[1] | 4078 | }
|
---|
[128] | 4079 | if (!(fout = fopen(device, "w"))) {
|
---|
| 4080 | log_OS_error("Cannot open fdd");
|
---|
| 4081 | return (1);
|
---|
| 4082 | }
|
---|
| 4083 | for (blockno = 0; blockno < maxblocks; blockno++) {
|
---|
| 4084 | percentage = blockno * 100 / maxblocks;
|
---|
| 4085 | if (fread(blk, 1, 1024, fin) != 1024) {
|
---|
| 4086 | if (feof(fin)) {
|
---|
| 4087 | log_msg(1,
|
---|
| 4088 | "img read err - img ended prematurely - non-fatal error");
|
---|
| 4089 | sleep(3);
|
---|
| 4090 | return (res);
|
---|
| 4091 | }
|
---|
| 4092 | res++;
|
---|
| 4093 | log_to_screen("img read err");
|
---|
| 4094 | }
|
---|
| 4095 | if (fwrite(blk, 1, 1024, fout) != 1024) {
|
---|
| 4096 | res++;
|
---|
| 4097 | log_to_screen("fdd write err");
|
---|
| 4098 | }
|
---|
| 4099 | if (((blockno + 1) % 128) == 0) {
|
---|
| 4100 | paranoid_system("sync"); /* fflush doesn't work; dunno why */
|
---|
| 4101 | update_evalcall_form(percentage);
|
---|
| 4102 | }
|
---|
| 4103 | }
|
---|
| 4104 | paranoid_fclose(fin);
|
---|
| 4105 | paranoid_fclose(fout);
|
---|
| 4106 | paranoid_free(tmp);
|
---|
| 4107 | paranoid_free(title);
|
---|
| 4108 | close_evalcall_form();
|
---|
| 4109 | return (res);
|
---|
[1] | 4110 | }
|
---|
| 4111 |
|
---|
| 4112 |
|
---|
| 4113 |
|
---|
| 4114 |
|
---|
| 4115 |
|
---|
| 4116 |
|
---|
| 4117 |
|
---|
| 4118 |
|
---|
| 4119 |
|
---|
| 4120 | /**
|
---|
| 4121 | * Wrapper around @c write_image_to_floppy_SUB().
|
---|
| 4122 | * This function, unlike @c write_image_to_floppy_SUB(),
|
---|
| 4123 | * gives the user the opportunity to retry if the write fails.
|
---|
| 4124 | * @see write_image_to_floppy_SUB
|
---|
| 4125 | */
|
---|
[128] | 4126 | int write_image_to_floppy(char *device, char *datafile)
|
---|
[1] | 4127 | {
|
---|
[128] | 4128 | /*@ int ************************************************************** */
|
---|
| 4129 | int res = 0;
|
---|
[1] | 4130 |
|
---|
[128] | 4131 | assert_string_is_neither_NULL_nor_zerolength(device);
|
---|
| 4132 | assert_string_is_neither_NULL_nor_zerolength(datafile);
|
---|
[1] | 4133 |
|
---|
[128] | 4134 | while ((res = write_image_to_floppy_SUB(device, datafile))) {
|
---|
| 4135 | if (!ask_me_yes_or_no("Failed to write image to floppy. Retry?")) {
|
---|
| 4136 | return (res);
|
---|
| 4137 | }
|
---|
[1] | 4138 | }
|
---|
[128] | 4139 | return (res);
|
---|
[1] | 4140 | }
|
---|
| 4141 |
|
---|
| 4142 | /* @} - end of utilityGroup */
|
---|
[259] | 4143 |
|
---|
[424] | 4144 | void setenv_mondo_share(void) {
|
---|
[259] | 4145 |
|
---|
[424] | 4146 | setenv("MONDO_SHARE", MONDO_SHARE, 1);
|
---|
[259] | 4147 | }
|
---|