source: MondoRescue/trunk/mondo/mondo/common/libmondo-archive.c@ 1

Last change on this file since 1 was 1, checked in by bcornec, 19 years ago

Initial import from latest mondo-2.04_cvs_20050503/mindi-1.04_cvs_20050503 on http://www.mondorescue.org

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