source: MondoRescue/branches/stable/mondo/src/common/libmondo-archive.c@ 948

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