source: MondoRescue/branches/2.2.2/mondo/src/common/libmondo-archive.c@ 1316

Last change on this file since 1316 was 1316, checked in by Bruno Cornec, 17 years ago

MONDO_LOGFILE is rather a char* exported by each main program (consolidation of those mecanisms in .h files with ps_*)

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