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

Last change on this file since 839 was 815, checked in by Bruno Cornec, 18 years ago

merge -r807:814 $SVN_M/branches/stable

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