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

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

Improve ia64 support for SLES

(merge -r1562:1563 $SVN_M/branches/2.2.5)

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