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

Last change on this file since 538 was 538, checked in by bcornec, 18 years ago

Begining of modifications => DOS NOT WORK FOR NOW.
This is done to be merged in trunk. stable will later point back to current 2.0.8 content

Use of mindi conf file in mindi + /var/cache/mindi as a default place
Use of mondo conf file in mondo + separation of messages.
Ultimate goal is to have a cleaner design of files vs functions.

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