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

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

manual_cd_tray => manual_tray and usage of conf file for that field

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