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

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

Memory management improvements for libmondo-archive.c (trunk merge again) TBC

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