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

Last change on this file since 808 was 783, checked in by Bruno Cornec, 18 years ago
  • Massive rewrite continues for memory management.
  • main structure should now have all parameters allocated dynamically
  • new lib libmr.a + dir + build process reviewed to support it.
  • new include subdir to host external definitions of the new lib
  • code now compiles. Still one remaining link issues for mondorestore. This should allow for some tests soon.

(goal is to separate completely reviewed code and functions and provide clean interfaces)

  • Property svn:keywords set to Id
File size: 108.6 KB
Line 
1/* $Id: libmondo-archive.c 783 2006-08-31 15:09:20Z 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 783 2006-08-31 15:09:20Z 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 (i.e. a partition to be imaged)
2028 log_msg(2, "bigfile_fname = '%s'", bigfile_fname);
2029 use_ntfsprog = FALSE;
2030 if (!strncmp(bigfile_fname, "/dev/", 5)
2031 && is_dev_an_NTFS_dev(bigfile_fname)) {
2032 use_ntfsprog = TRUE;
2033 log_msg(2,
2034 "Calling ntfsclone in background because %s is an NTFS partition",
2035 bigfile_fname);
2036 asprintf(&sz_devfile, "/tmp/%d.%d.000",
2037 (int) (random() % 32768),
2038 (int) (random() % 32768));
2039 mkfifo(sz_devfile, 0x770);
2040 ntfsprog_fifo = sz_devfile;
2041 switch (pid = fork()) {
2042 case -1:
2043 fatal_error("Fork failure");
2044 case 0:
2045 log_msg(2,
2046 "CHILD - fip - calling feed_into_ntfsprog(%s, %s)",
2047 bigfile_fname, sz_devfile);
2048 res = feed_into_ntfsprog(bigfile_fname, sz_devfile);
2049 exit(res);
2050 break;
2051 default:
2052 log_msg(2,
2053 "feed_into_ntfsprog() called in background --- pid=%ld",
2054 (long int) (pid));
2055
2056 paranoid_free(sz_devfile);
2057 }
2058 }
2059 // Otherwise, use good old 'dd' and 'bzip2'
2060 else {
2061 ntfsprog_fifo = NULL;
2062 }
2063
2064 // Whether partition or biggiefile, just do your thang :-)
2065 log_msg(2, "Bigfile #%ld is '%s' (%ld KB)",
2066 biggie_file_number + 1, bigfile_fname,
2067 (long) biggie_fsize >> 10);
2068 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2069 write_header_block_to_stream(biggie_fsize, bigfile_fname,
2070 use_ntfsprog ?
2071 BLK_START_A_PIHBIGGIE :
2072 BLK_START_A_NORMBIGGIE);
2073 }
2074 res =
2075 slice_up_file_etc(bkpinfo, bigfile_fname,
2076 ntfsprog_fifo, biggie_file_number,
2077 noof_biggie_files, use_ntfsprog);
2078 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2079 tmp = calc_checksum_of_file(bigfile_fname);
2080 write_header_block_to_stream((off_t)0, tmp, BLK_STOP_A_BIGGIE);
2081 paranoid_free(tmp);
2082 }
2083 retval += res;
2084 p = strrchr(bigfile_fname, '/');
2085 if (p) {
2086 p++;
2087 } else {
2088 p = bigfile_fname;
2089 }
2090 if (res) {
2091 asprintf(&tmp, "Archiving %s ... Failed!", bigfile_fname);
2092 } else {
2093 asprintf(&tmp, "Archiving %s ... OK!", bigfile_fname);
2094 }
2095
2096 if (delete_when_done) {
2097 unlink(bigfile_fname);
2098 delete_when_done = FALSE;
2099 }
2100 }
2101#ifndef _XWIN
2102 if (!g_text_mode) {
2103 newtDrawRootText(0, g_noof_rows - 2, tmp);
2104 newtRefresh();
2105 }
2106#endif
2107 }
2108 paranoid_free(tmp);
2109 paranoid_free(bigfile_fname);
2110 paranoid_fclose(fin);
2111
2112 log_msg(1, "Finished backing up bigfiles");
2113 log_msg(1, "estimated slices = %ld; actual slices = %ld",
2114 estimated_total_noof_slices, g_current_progress);
2115 close_progress_form();
2116 return (retval);
2117}
2118
2119
2120/**
2121 * Single-threaded version of @c make_afioballs_and_images().
2122 * @see make_afioballs_and_images
2123 */
2124int make_afioballs_and_images_OLD(struct s_bkpinfo *bkpinfo)
2125{
2126
2127 /*@ int ************************************************** */
2128 int retval = 0;
2129 long int curr_set_no = 0;
2130 int res = 0;
2131
2132 /*@ buffers ********************************************** */
2133 char *curr_filelist_fname;
2134 char *curr_afioball_fname;
2135 char *curr_xattr_list_fname;
2136 char *curr_acl_list_fname;
2137 char *tmp;
2138 char *media_usage_comment;
2139
2140 /* BERLIOS: Useless ?
2141 asprintf(&tmp, "%s/archives/filelist.full", bkpinfo->scratchdir);
2142 */
2143
2144 log_to_screen("Archiving regular files");
2145
2146 open_progress_form(_("Backing up filesystem"),
2147 _("I am backing up your live filesystem now."),
2148 _("Please wait. This may take a couple of hours."),
2149 _("Working..."),
2150 get_last_filelist_number(bkpinfo) + 1);
2151
2152 asprintf(&curr_filelist_fname, FILELIST_FNAME_RAW_SZ, bkpinfo->tmpdir,
2153 0L);
2154
2155 curr_set_no = 0;
2156 while (does_file_exist(curr_filelist_fname)) {
2157 /* backup this set of files */
2158 asprintf(&curr_afioball_fname, AFIOBALL_FNAME_RAW_SZ,
2159 bkpinfo->tmpdir, curr_set_no, bkpinfo->zip_suffix);
2160
2161 log_msg(1, "EXAT'g set %ld", curr_set_no);
2162 asprintf(&curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
2163 bkpinfo->tmpdir, curr_set_no);
2164 asprintf(&curr_acl_list_fname, ACL_LIST_FNAME_RAW_SZ,
2165 bkpinfo->tmpdir, curr_set_no);
2166 get_fattr_list(curr_filelist_fname, curr_xattr_list_fname);
2167 get_acl_list(curr_filelist_fname, curr_acl_list_fname);
2168
2169 log_msg(1, "Archiving set %ld", curr_set_no);
2170 res = archive_this_fileset(bkpinfo, curr_filelist_fname,
2171 curr_afioball_fname, curr_set_no);
2172 retval += res;
2173 if (res) {
2174 asprintf(&tmp,
2175 "Errors occurred while archiving set %ld. Perhaps your live filesystem changed?",
2176 curr_set_no);
2177 log_to_screen(tmp);
2178 paranoid_free(tmp);
2179 }
2180
2181 tmp = percent_media_full_comment(bkpinfo);
2182 asprintf(&media_usage_comment, "%s", tmp);
2183 paranoid_free(tmp);
2184
2185 /* copy to CD (scratchdir) ... and an actual CD-R if necessary */
2186 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2187 register_in_tape_catalog(fileset, curr_set_no, -1,
2188 curr_afioball_fname);
2189 maintain_collection_of_recent_archives(bkpinfo->tmpdir,
2190 curr_afioball_fname);
2191 iamhere("Writing EXAT files");
2192 res += write_EXAT_files_to_tape(bkpinfo, curr_xattr_list_fname,
2193 curr_acl_list_fname);
2194 // archives themselves
2195 res = move_files_to_stream(bkpinfo, curr_afioball_fname, NULL);
2196 } else {
2197 res =
2198 move_files_to_cd(bkpinfo, curr_filelist_fname,
2199 curr_xattr_list_fname,
2200 curr_acl_list_fname, curr_afioball_fname,
2201 NULL);
2202 }
2203 retval += res;
2204 g_current_progress++;
2205 update_progress_form(media_usage_comment);
2206 paranoid_free(media_usage_comment);
2207
2208 if (res) {
2209 asprintf(&tmp, "Failed to add archive %ld's files to CD dir\n",
2210 curr_set_no);
2211 log_to_screen(tmp);
2212 paranoid_free(tmp);
2213 fatal_error
2214 ("Is your hard disk is full? If not, please send the author the logfile.");
2215 }
2216 paranoid_free(curr_filelist_fname);
2217 paranoid_free(curr_afioball_fname);
2218 paranoid_free(curr_xattr_list_fname);
2219 paranoid_free(curr_acl_list_fname);
2220 asprintf(&curr_filelist_fname, FILELIST_FNAME_RAW_SZ,
2221 bkpinfo->tmpdir, ++curr_set_no);
2222 }
2223 paranoid_free(curr_filelist_fname);
2224 close_progress_form();
2225 if (retval) {
2226 log_to_screen
2227 ("Your regular files have been archived (with errors).");
2228 } else {
2229 log_to_screen
2230 ("Your regular files have been archived successfully.");
2231 }
2232 return (retval);
2233}
2234
2235/* @} - end of LLarchiveGroup */
2236
2237
2238/**
2239 * Wrapper around @c make_afioballs_and_images().
2240 * @param bkpinfo the backup information structure. Only the
2241 * @c backup_media_type field is used within this function.
2242 * @return return code of make_afioballs_and_images
2243 * @see make_afioballs_and_images
2244 * @ingroup MLarchiveGroup
2245 */
2246int make_those_afios_phase(struct s_bkpinfo *bkpinfo)
2247{
2248 /*@ int ******************************************* */
2249 int res = 0;
2250 int retval = 0;
2251
2252 assert(bkpinfo != NULL);
2253
2254 mvaddstr_and_log_it(g_currentY, 0,
2255 "Archiving regular files to media ");
2256
2257 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2258 write_header_block_to_stream((off_t)0, "start-of-afioballs",
2259 BLK_START_AFIOBALLS);
2260#if __FreeBSD__ == 5
2261 log_msg(1,
2262 "Using single-threaded make_afioballs_and_images() to suit b0rken FreeBSD 5.0");
2263 res = make_afioballs_and_images_OLD(bkpinfo);
2264#else
2265 res = make_afioballs_and_images_OLD(bkpinfo);
2266#endif
2267 write_header_block_to_stream((off_t)0, "stop-afioballs",
2268 BLK_STOP_AFIOBALLS);
2269 } else {
2270 res = make_afioballs_and_images(bkpinfo);
2271 }
2272
2273 retval += res;
2274 if (res) {
2275 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2276 log_msg(1, "make_afioballs_and_images returned an error");
2277 } else {
2278 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2279 }
2280 return (retval);
2281}
2282
2283/**
2284 * Wrapper around @c make_slices_and_images().
2285 * @param bkpinfo The backup information structure. Fields used:
2286 * - @c backup_media_type
2287 * - @c scratchdir
2288 * - @c tmpdir
2289 * @return The number of errors encountered (0 for success)
2290 * @ingroup MLarchiveGroup
2291 */
2292int make_those_slices_phase(struct s_bkpinfo *bkpinfo)
2293{
2294
2295 /*@ int ***************************************************** */
2296 int res = 0;
2297 int retval = 0;
2298
2299 /*@ buffers ************************************************** */
2300 char *biggielist;
2301 char *command;
2302 char *blah;
2303 char *xattr_fname;
2304 char *acl_fname;
2305
2306 assert(bkpinfo != NULL);
2307 /* slice big files */
2308 mvaddstr_and_log_it(g_currentY, 0,
2309 "Archiving large files to media ");
2310 asprintf(&biggielist, "%s/archives/biggielist.txt",
2311 bkpinfo->scratchdir);
2312 asprintf(&xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
2313 asprintf(&acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir);
2314
2315 asprintf(&command, "cp %s/biggielist.txt %s", bkpinfo->tmpdir,
2316 biggielist);
2317 paranoid_system(command);
2318 paranoid_free(command);
2319
2320 asprintf(&blah, "biggielist = %s", biggielist);
2321 log_msg(2, blah);
2322 paranoid_free(blah);
2323
2324 if (!does_file_exist(biggielist)) {
2325 log_msg(1, "BTW, the biggielist does not exist");
2326 }
2327
2328 get_fattr_list(biggielist, xattr_fname);
2329 get_acl_list(biggielist, acl_fname);
2330 asprintf(&command, "cp %s %s/archives/", xattr_fname,
2331 bkpinfo->scratchdir);
2332 paranoid_system(command);
2333 paranoid_free(command);
2334
2335 asprintf(&command, "cp %s %s/archives/", acl_fname,
2336 bkpinfo->scratchdir);
2337 paranoid_system(command);
2338 paranoid_free(command);
2339
2340 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2341 res += write_EXAT_files_to_tape(bkpinfo, xattr_fname, acl_fname);
2342 asprintf(&blah, "%ld", count_lines_in_file(biggielist));
2343 write_header_block_to_stream((off_t)0, blah, BLK_START_BIGGIEFILES);
2344 paranoid_free(blah);
2345 }
2346 paranoid_free(xattr_fname);
2347 paranoid_free(acl_fname);
2348
2349 res = make_slices_and_images(bkpinfo, biggielist);
2350 paranoid_free(biggielist);
2351
2352 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2353 write_header_block_to_stream((off_t)0, "end-of-biggiefiles",
2354 BLK_STOP_BIGGIEFILES);
2355 }
2356 retval += res;
2357 if (res) {
2358 log_msg(1, "make_slices_and_images returned an error");
2359 mvaddstr_and_log_it(g_currentY++, 74, "Errors.");
2360 } else {
2361 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2362 }
2363 return (retval);
2364}
2365
2366
2367/**
2368 * @addtogroup LLarchiveGroup
2369 * @{
2370 */
2371/**
2372 * Function pointer to an appropriate @c move_files_to_cd routine.
2373 * You can set this to your own function (for example, one to
2374 * transfer files over the network) or leave it as is.
2375 */
2376int (*move_files_to_cd) (struct s_bkpinfo *, char *, ...) =
2377 _move_files_to_cd;
2378
2379/**
2380 * Move some files to the ISO scratch directory.
2381 * This function moves files specified as parameters, into the directory
2382 * @c bkpinfo->scratchdir, where the files that will be stored on the next
2383 * CD are waiting.
2384 *
2385 * @param bkpinfo The backup information structure. Fields used:
2386 * - @c media_size
2387 * - @c scratchdir
2388 * @param files_to_add The files to add to the scratchdir.
2389 * @warning The list of @c files_to_add must be terminated with @c NULL.
2390 * @note If and when the space occupied by the scratchdir would exceed
2391 * the capacity of the current CD,
2392 * <tt>write_iso_and_go_on(bkpinfo, FALSE)</tt> is called and the
2393 * scratchdir is emptied.
2394 *
2395 * @return The number of errors encountered (0 for success)
2396 */
2397int _move_files_to_cd(struct s_bkpinfo *bkpinfo, char *files_to_add, ...)
2398{
2399
2400 /*@ int ************************************************************ */
2401 int retval = 0;
2402 int res = 0;
2403
2404 /*@ buffers ******************************************************** */
2405 char *tmp, *curr_file, *cf;
2406
2407 /*@ long ************************************************************ */
2408 va_list ap;
2409 long long would_occupy;
2410
2411 assert(bkpinfo != NULL);
2412 would_occupy = space_occupied_by_cd(bkpinfo->scratchdir);
2413 va_start(ap, files_to_add); // initialize the variable arguments
2414 for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) {
2415 if (!cf) {
2416 continue;
2417 }
2418 asprintf(&curr_file, "%s", cf);
2419 if (!does_file_exist(curr_file)) {
2420 log_msg(1,
2421 "Warning - you're trying to add a non-existent file - '%s' to the CD",
2422 curr_file);
2423 } else {
2424 log_msg(8, "Trying to add file %s to CD", curr_file);
2425 would_occupy += length_of_file(curr_file) / 1024;
2426 }
2427 paranoid_free(curr_file);
2428 }
2429 va_end(ap);
2430
2431 if (bkpinfo->media_size[g_current_media_number] <= 0) {
2432 fatal_error("move_files_to_cd() - unknown media size");
2433 }
2434 if (would_occupy / 1024 > bkpinfo->media_size[g_current_media_number]) {
2435 /* FALSE because this is not the last CD we'll write */
2436 res = write_iso_and_go_on(bkpinfo, FALSE);
2437 retval += res;
2438 if (res) {
2439 log_msg(1, "WARNING - write_iso_and_go_on returned an error");
2440 }
2441 }
2442
2443 va_start(ap, files_to_add); // initialize the variable arguments
2444 for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) {
2445 if (!cf) {
2446 continue;
2447 }
2448 asprintf(&curr_file, "%s", cf);
2449
2450 asprintf(&tmp, "mv -f %s %s/archives/", curr_file,
2451 bkpinfo->scratchdir);
2452 res = run_program_and_log_output(tmp, 5);
2453 retval += res;
2454 if (res) {
2455 log_msg(1, "(move_files_to_cd) '%s' failed", tmp);
2456 } else {
2457 log_msg(8, "Moved %s to CD OK", tmp);
2458 }
2459 paranoid_free(tmp);
2460 paranoid_free(curr_file);
2461 // unlink (curr_file);
2462 }
2463 va_end(ap);
2464
2465 if (retval) {
2466 log_msg(1,
2467 "Warning - errors occurred while I was adding files to CD dir");
2468 }
2469 return (retval);
2470}
2471
2472/* @} - end of LLarchiveGroup */
2473
2474
2475/**
2476 * Offer to write boot and data disk images to 3.5" floppy disks.
2477 * @param bkpinfo The backup information structure. Only the
2478 * @c backup_media_type field is used in this function.
2479 * @param imagesdir The directory containing the floppy images (usually
2480 * /var/cache/mindi).
2481 *
2482 * @return The number of errors encountered (0 for success)
2483 * @see write_image_to_floppy
2484 * @see format_disk
2485 * @ingroup MLarchiveGroup
2486 */
2487int offer_to_write_floppies(struct s_bkpinfo *bkpinfo, char *imagesdir)
2488{
2489 /*@ buffer ************************************************************ */
2490 char *tmp;
2491 char *comment;
2492 char *bootdisk_dev;
2493 char *datadisk_dev;
2494 char *bootdisk_file;
2495 char *rootdisk_file;
2496
2497 /*@ int *************************************************************** */
2498 int i = 0;
2499 int res = 0;
2500
2501 /*@ bool ************************************************************** */
2502 bool format_first;
2503 bool root_disk_exists = FALSE;
2504
2505 assert(bkpinfo != NULL);
2506 assert_string_is_neither_NULL_nor_zerolength(imagesdir);
2507
2508
2509 if (!ask_me_yes_or_no
2510 ("Write boot and data disk images to 3.5\" floppy disks?")) {
2511 return (0);
2512 }
2513 if (does_device_exist(DEFAULT_1722MB_DISK)) {
2514#ifdef __FreeBSD__
2515 // tell the system that this is a 1.72m floppy
2516 system("/usr/sbin/fdcontrol -F 1722 /dev/fd0.1722");
2517#endif
2518 asprintf(&bootdisk_dev, "%s", DEFAULT_1722MB_DISK);
2519 } else if (does_device_exist(BACKUP_1722MB_DISK)) {
2520 asprintf(&bootdisk_dev, "/dev/fd0H1722");
2521 } else {
2522 log_msg(1, "Warning - can't find a 1.72MB floppy device *sigh*");
2523 asprintf(&bootdisk_dev, DEFAULT_1722MB_DISK);
2524 }
2525 asprintf(&datadisk_dev, "%s", "/dev/fd0");
2526 if (!does_device_exist(datadisk_dev)) {
2527 log_msg(1, "Warning - can't find a 1.44MB floppy device *sigh*");
2528 paranoid_free(datadisk_dev);
2529 asprintf(&datadisk_dev, "%s", "/dev/fd0");
2530 }
2531 format_first = ask_me_yes_or_no
2532 ("Do you want me to format the disks before I write to them?");
2533
2534/* boot disk */
2535 if (ask_me_OK_or_cancel("About to write boot disk")) {
2536 log_to_screen("Writing boot floppy");
2537#ifdef __FreeBSD__
2538 asprintf(&tmp, "%s/mindi-kern.1722.img", imagesdir);
2539 if (format_first) {
2540 format_disk(bootdisk_dev);
2541 }
2542 res += write_image_to_floppy(bootdisk_dev, tmp);
2543 paranoid_free(tmp);
2544
2545 if (ask_me_OK_or_cancel("About to write 1.44MB mfsroot disk")) {
2546 log_to_screen("Writing mfsroot floppy");
2547 if (format_first) {
2548 format_disk(datadisk_dev);
2549 }
2550 asprintf(&tmp, "%s/mindi-mfsroot.1440.img", imagesdir);
2551 write_image_to_floppy(datadisk_dev, tmp);
2552 paranoid_free(tmp);
2553 }
2554#else
2555 asprintf(&bootdisk_file, "%s/mindi-bootroot.1722.img", imagesdir);
2556 if (does_file_exist(bootdisk_file)) {
2557 if (format_first) {
2558 format_disk(bootdisk_dev);
2559 }
2560 res += write_image_to_floppy(bootdisk_dev, bootdisk_file);
2561 } else {
2562 paranoid_free(bootdisk_file);
2563 asprintf(&bootdisk_file, "%s/mindi-boot.1440.img", imagesdir);
2564 asprintf(&rootdisk_file, "%s/mindi-root.1440.img", imagesdir);
2565 root_disk_exists = TRUE;
2566 if (!does_file_exist(rootdisk_file)
2567 || !does_file_exist(bootdisk_file)) {
2568 popup_and_OK
2569 ("Cannot write boot/root floppies. Files not found.");
2570 log_to_screen
2571 ("Failed to find boot/root floppy images. Oh dear.");
2572 paranoid_free(bootdisk_file);
2573 paranoid_free(rootdisk_file);
2574 paranoid_free(bootdisk_dev);
2575 return (1);
2576 }
2577 if (format_first) {
2578 format_disk(datadisk_dev);
2579 }
2580 res += write_image_to_floppy(datadisk_dev, bootdisk_file);
2581 if (ask_me_OK_or_cancel("About to write root disk")) {
2582 log_to_screen("Writing root floppy");
2583 if (format_first) {
2584 format_disk(datadisk_dev);
2585 }
2586 asprintf(&tmp, "cat %s > %s", rootdisk_file, datadisk_dev);
2587 log_msg(1, "tmp = '%s'", tmp);
2588 res +=
2589 run_external_binary_with_percentage_indicator_NEW
2590 ("Writing root floppy", tmp);
2591// res += write_image_to_floppy (datadisk_dev, rootdisk_file);
2592 paranoid_free(tmp);
2593 }
2594 paranoid_free(rootdisk_file);
2595 paranoid_free(bootdisk_file);
2596 }
2597#endif
2598 }
2599 paranoid_free(bootdisk_dev);
2600
2601 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
2602 log_to_screen
2603 ("FYI, the data disks are stored on tape/CD for your convenience.");
2604 return (0);
2605 }
2606 for (i = 1; i < 99; i++) {
2607 asprintf(&tmp, "%s/mindi-data-%d.img", imagesdir, i);
2608 log_msg(3, tmp);
2609 if (!does_file_exist(tmp)) {
2610 log_msg(3, "...not found");
2611 break;
2612 }
2613 asprintf(&comment, "About to write data disk #%d", i);
2614 if (ask_me_OK_or_cancel(comment)) {
2615 paranoid_free(comment);
2616 asprintf(&comment, "Writing data disk #%3d", i);
2617 log_to_screen(comment);
2618 paranoid_free(comment);
2619 if (format_first) {
2620 res += format_disk(datadisk_dev);
2621 }
2622 res += write_image_to_floppy(datadisk_dev, tmp);
2623 }
2624 }
2625 paranoid_free(tmp);
2626 paranoid_free(datadisk_dev);
2627 return (res);
2628}
2629
2630
2631/**
2632 * Wrapper around @c offer_to_write_floppies().
2633 * @param bkpinfo The backup information structure. Used only
2634 * in the call to @c offer_to_write_floppies().
2635 * @return 0 if the boot floppies were found (not necessarily written OK),
2636 * 1 otherwise.
2637 * @see offer_to_write_floppies
2638 * @ingroup MLarchiveGroup
2639 */
2640
2641int
2642offer_to_write_boot_floppies_to_physical_disks(struct s_bkpinfo *bkpinfo)
2643{
2644 int res = 0;
2645
2646 assert(bkpinfo != NULL);
2647
2648 mvaddstr_and_log_it(g_currentY, 0,
2649 "Writing boot+data floppy images to disk");
2650
2651 if (!bkpinfo->nonbootable_backup) {
2652#ifdef __FreeBSD__
2653 if (!does_file_exist("/var/cache/mindi/mindi-kern.1722.img"))
2654#else
2655 if (!does_file_exist("/var/cache/mindi/mindi-bootroot.1722.img")
2656 && !does_file_exist("/var/cache/mindi/mindi-boot.1440.img")
2657 && !does_file_exist("/var/cache/mindi/mindi-boot.2880.img")
2658 && !does_file_exist("/var/cache/mindi/mindi-boot.5760.img"))
2659#endif
2660 {
2661 mvaddstr_and_log_it(g_currentY++, 74, "No Imgs");
2662 if (does_file_exist("/var/cache/mindi/mondorescue.iso")) {
2663 popup_and_OK
2664 ("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.");
2665 res++;
2666 }
2667 } else {
2668 offer_to_write_floppies(bkpinfo, "/var/cache/mindi");
2669 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
2670 }
2671 } else {
2672 popup_and_OK
2673 ("Since you opted for a nonbootable backup, no boot floppies were created.");
2674 }
2675
2676 return (res);
2677}
2678
2679
2680/**
2681 * @addtogroup LLarchiveGroup
2682 * @{
2683 */
2684/**
2685 * Function pointer to an appropriate @c move_files_to_stream routine.
2686 * You can set this to your own function (for example, one to
2687 * transfer files over the network) or leave it as is.
2688 */
2689int (*move_files_to_stream) (struct s_bkpinfo *, char *, ...) =
2690 _move_files_to_stream;
2691
2692/**
2693 * Copy some files to tape.
2694 * This function copies the files specified as parameters into the tape stream.
2695 *
2696 * @param bkpinfo The backup information structure. Used only in the call to
2697 * @c write_file_to_stream_from_file().
2698 *
2699 * @param files_to_add The files to copy to the tape stream.
2700 * @warning The list of @c files_to_add must be terminated with @c NULL.
2701 * @note Files may be split across multiple tapes if necessary.
2702 *
2703 * @return The number of errors encountered (0 for success)
2704 */
2705int
2706_move_files_to_stream(struct s_bkpinfo *bkpinfo, char *files_to_add, ...)
2707{
2708
2709 /*@ int ************************************************************ */
2710 int retval = 0;
2711 int res = 0;
2712 /*@ buffers ******************************************************** */
2713
2714 /*@ char *********************************************************** */
2715 char start_chr;
2716 char stop_chr;
2717 char *curr_file, *cf;
2718 /*@ long long ****************************************************** */
2719 off_t length_of_incoming_file = (off_t)0;
2720 t_archtype type;
2721 va_list ap;
2722
2723 assert(bkpinfo != NULL);
2724 va_start(ap, files_to_add);
2725 for (cf = files_to_add; cf != NULL; cf = va_arg(ap, char *)) {
2726 if (!cf) {
2727 continue;
2728 }
2729 asprintf(&curr_file, "%s", cf);
2730 if (!does_file_exist(curr_file)) {
2731 log_msg(1,
2732 "Warning - you're trying to add a non-existent file - '%s' to the tape",
2733 curr_file);
2734 }
2735 /* create header chars */
2736 start_chr = BLK_START_AN_AFIO_OR_SLICE;
2737 stop_chr = BLK_STOP_AN_AFIO_OR_SLICE;
2738 /* ask for new tape if necessary */
2739 length_of_incoming_file = length_of_file(curr_file);
2740 write_header_block_to_stream(length_of_incoming_file, curr_file,
2741 start_chr);
2742 if (strstr(curr_file, ".afio.") || strstr(curr_file, ".star.")) {
2743 type = fileset;
2744 } else if (strstr(curr_file, "slice")) {
2745 type = biggieslice;
2746 } else {
2747 type = other;
2748 }
2749 res = write_file_to_stream_from_file(bkpinfo, curr_file);
2750 retval += res;
2751 unlink(curr_file);
2752 paranoid_free(curr_file);
2753 /* write closing header */
2754 write_header_block_to_stream((off_t)0, "finished-writing-file", stop_chr);
2755 }
2756 va_end(ap);
2757
2758 if (retval) {
2759 log_msg(1,
2760 "Warning - errors occurred while I was adding file to tape");
2761 }
2762 return (retval);
2763}
2764
2765/* @} - end of LLarchiveGroup */
2766
2767
2768/**
2769 * @addtogroup utilityGroup
2770 * @{
2771 */
2772/**
2773 * Make sure the user has a valid CD-R(W) in the CD drive.
2774 * @param cdrw_device Set to the CD-R(W) device checked.
2775 * @param keep_looping If TRUE, keep pestering user until they insist
2776 * or insert a correct CD; if FALSE, only check once.
2777 * @return 0 (there was an OK CD in the drive) or 1 (there wasn't).
2778 */
2779char *interrogate_disk_currently_in_cdrw_drive()
2780{
2781 char *cdrecord;
2782 char *cdrw_device;
2783
2784 if ((cdrw_device = find_cdrw_device()) != NULL) {
2785 if (!system("which cdrecord > /dev/null 2> /dev/null")) {
2786 asprintf(&cdrecord, "cdrecord dev=%s -atip", cdrw_device);
2787 } else if (!system("which dvdrecord > /dev/null 2> /dev/null")) {
2788 asprintf(&cdrecord, "cdrecord dev=%s -atip", cdrw_device);
2789 } else {
2790 asprintf(&cdrecord, " ");
2791 log_msg(2, "Found no cdrecord nor dvdrecord in path.");
2792 }
2793 if (cdrecord[0]) {
2794 retract_CD_tray_and_defeat_autorun();
2795 run_program_and_log_output(cdrecord, 5);
2796 }
2797 paranoid_free(cdrecord);
2798 }
2799 return(cdrw_device);
2800}
2801
2802
2803/**
2804 * Asks the user to put a CD-R(W) in the drive.
2805 * @param ask_for_one_if_more_than_this (unused)
2806 * @param pmountable If non-NULL, pointed-to value is set to TRUE if the CD is mountable, FALSE otherwise.
2807 */
2808void
2809pause_and_ask_for_cdr(int ask_for_one_if_more_than_this, bool * pmountable)
2810{
2811
2812 /*@ buffers ********************************************* */
2813 char *tmp;
2814 char *tmp1;
2815 char *szmsg;
2816 char *cdrom_dev;
2817 char *cdrw_device = NULL;
2818 char *our_serial_str;
2819 bool ok_go_ahead_burn_it;
2820 int cd_number = -1;
2821 int attempt_to_mount_returned_this = 999;
2822 char *mtpt;
2823 char *szcdno;
2824 char *szserfname;
2825 char *szunmount;
2826
2827 asprintf(&szmsg, "I am about to burn %s #%d",
2828 g_backup_media_string,
2829 g_current_media_number);
2830 log_to_screen(szmsg);
2831 paranoid_free(szmsg);
2832 if (g_current_media_number < ask_for_one_if_more_than_this) {
2833 return;
2834 }
2835 log_to_screen("Scanning CD-ROM drive...");
2836 asprintf(&mtpt, "/tmp/cd.mtpt.%ld.%ld", (long int) random(),
2837 (long int) random());
2838 make_hole_for_dir(mtpt);
2839
2840 gotos_make_me_puke:
2841 ok_go_ahead_burn_it = TRUE;
2842 cdrom_dev = find_cdrom_device(FALSE);
2843 if (cdrom_dev != NULL) {
2844/* When enabled, it made CD eject-and-retract when wrong CD inserted.. Weird
2845 log_msg(2, "paafcd: Retracting CD-ROM drive if possible" );
2846 retract_CD_tray_and_defeat_autorun();
2847*/
2848 asprintf(&tmp, "umount %s", cdrom_dev);
2849 run_program_and_log_output(tmp, 1);
2850 paranoid_free(tmp);
2851 asprintf(&szcdno, "%s/archives/THIS-CD-NUMBER", mtpt);
2852 asprintf(&szserfname, "%s/archives/SERIAL-STRING", mtpt);
2853 asprintf(&szunmount, "umount %s", mtpt);
2854 cd_number = -1;
2855 asprintf(&tmp, "mount %s %s", cdrom_dev, mtpt);
2856 if ((attempt_to_mount_returned_this =
2857 run_program_and_log_output(tmp, 1))) {
2858 log_msg(4, "Failed to mount %s at %s", cdrom_dev, mtpt);
2859 log_to_screen("If there's a CD/DVD in the drive, it's blank.");
2860 asprintf(&our_serial_str, "%s", "");
2861 } else if (!does_file_exist(szcdno)
2862 || !does_file_exist(szserfname)) {
2863 log_to_screen
2864 ("%s has data on it but it's probably not a Mondo CD.",
2865 g_backup_media_string);
2866 asprintf(&our_serial_str, "%s", "");
2867 } else {
2868 log_to_screen("%s found in drive. It's a Mondo disk.",
2869 g_backup_media_string);
2870 tmp1 = last_line_of_file(szcdno);
2871 cd_number = atoi(tmp1);
2872 paranoid_free(tmp1);
2873 asprintf(&tmp1, "cat %s 2> /dev/null", szserfname);
2874 our_serial_str = call_program_and_get_last_line_of_output(tmp1);
2875 paranoid_free(tmp1);
2876 // FIXME - should be able to use last_line_of_file(), surely?
2877 }
2878 paranoid_free(szcdno);
2879 paranoid_free(szserfname);
2880 paranoid_free(tmp);
2881
2882 run_program_and_log_output(szunmount, 1);
2883 paranoid_free(szunmount);
2884
2885 log_msg(2, "paafcd: cd_number = %d", cd_number);
2886 log_msg(2, "our serial str = %s; g_serial_string = %s",
2887 our_serial_str, g_serial_string);
2888 if (cd_number > 0 && !strcmp(our_serial_str, g_serial_string)) {
2889 log_msg(2, "This %s is part of this backup set!",
2890 g_backup_media_string);
2891 ok_go_ahead_burn_it = FALSE;
2892 if (cd_number == g_current_media_number - 1) {
2893 log_to_screen
2894 ("I think you've left the previous %s in the drive.",
2895 g_backup_media_string);
2896 } else {
2897 log_to_screen
2898 ("Please remove this %s. It is part of the backup set you're making now.",
2899 g_backup_media_string);
2900 }
2901 } else {
2902 log_to_screen("...but not part of _our_ backup set.");
2903 }
2904 paranoid_free(our_serial_str);
2905 } else {
2906 log_msg(2,
2907 "paafcd: Can't find CD-ROM drive. Perhaps it has a blank %s in it?",
2908 g_backup_media_string);
2909 if ((cdrw_device = interrogate_disk_currently_in_cdrw_drive(cdrw_device)) != NULL) {
2910 ok_go_ahead_burn_it = FALSE;
2911 log_to_screen("There isn't a writable %s in the drive.",
2912 g_backup_media_string);
2913 }
2914 paranoid_free(cdrw_device);
2915 }
2916 paranoid_free(mtpt);
2917
2918 if (!ok_go_ahead_burn_it) {
2919 eject_device(cdrom_dev);
2920 asprintf(&tmp,
2921 "I am about to burn %s #%d of the backup set. Please insert %s and press Enter.",
2922 g_backup_media_string,
2923 g_current_media_number,
2924 g_backup_media_string);
2925 popup_and_OK(tmp);
2926 paranoid_free(tmp);
2927 goto gotos_make_me_puke;
2928 } else {
2929 log_msg(2, "paafcd: OK, going ahead and burning it.");
2930 }
2931 paranoid_free(cdrom_dev);
2932
2933 log_msg(2,
2934 "paafcd: OK, I assume I have a blank/reusable %s in the drive...",
2935 g_backup_media_string);
2936
2937 log_to_screen("Proceeding w/ %s in drive.",
2938 g_backup_media_string);
2939 if (pmountable) {
2940 if (attempt_to_mount_returned_this) {
2941 *pmountable = FALSE;
2942 } else {
2943 *pmountable = TRUE;
2944 }
2945 }
2946
2947}
2948
2949
2950/**
2951 * Set the <tt>N</tt>th bit of @c array to @c true_or_false.
2952 * @param array The bit array (as a @c char pointer).
2953 * @param N The bit number to set or reset.
2954 * @param true_or_false If TRUE then set bit @c N, if FALSE then reset bit @c N.
2955 * @see get_bit_N_of_array
2956 */
2957void set_bit_N_of_array(char *array, int N, bool true_or_false)
2958{
2959 int bit_number;
2960 int mask, orig_val, to_add;
2961 int element_number;
2962
2963 assert(array != NULL);
2964
2965 element_number = N / 8;
2966 bit_number = N % 8;
2967 to_add = (1 << bit_number);
2968 mask = 255 - to_add;
2969 orig_val = array[element_number] & mask;
2970 // log_it("array[%d]=%02x; %02x&%02x = %02x", element_number, array[element_number], mask, orig_val);
2971 if (true_or_false) {
2972 array[element_number] = orig_val | to_add;
2973 }
2974}
2975
2976/* @} - end of utilityGroup */
2977
2978
2979/**
2980 * Chop up @c filename.
2981 * @param bkpinfo The backup information structure. Fields used:
2982 * - @c backup_media_type
2983 * - @c compression_level
2984 * - @c optimal_set_size
2985 * - @c tmpdir
2986 * - @c use_lzo
2987 * - @c zip_exe
2988 * - @c zip_suffix
2989 *
2990 * @param biggie_filename The file to chop up.
2991 * @param ntfsprog_fifo The FIFO to ntfsclone if this is an imagedev, NULL otherwise.
2992 * @param biggie_file_number The sequence number of this biggie file (starting from 0).
2993 * @param noof_biggie_files The number of biggie files there are total.
2994 * @return The number of errors encountered (0 for success)
2995 * @see make_slices_and_images
2996 * @ingroup LLarchiveGroup
2997 */
2998int
2999slice_up_file_etc(struct s_bkpinfo *bkpinfo, char *biggie_filename,
3000 char *ntfsprog_fifo, long biggie_file_number,
3001 long noof_biggie_files, bool use_ntfsprog)
3002{
3003
3004 /*@ buffers ************************************************** */
3005 char *tmp, *checksum_line = NULL, *command;
3006 char *tempblock;
3007 char *curr_slice_fname_uncompressed;
3008 char *curr_slice_fname_compressed;
3009 char *file_to_archive;
3010 char *file_to_openin;
3011 /*@ pointers ************************************************** */
3012 char *pB;
3013 FILE *fin, *fout;
3014
3015 /*@ bool ****************************************************** */
3016 bool finished = FALSE;
3017
3018 /*@ long ****************************************************** */
3019 size_t blksize = 0;
3020 long slice_num = 0;
3021 long i;
3022 long optimal_set_size;
3023 bool should_I_compress_slices;
3024 char *suffix; // for compressed slices
3025
3026 /*@ long long ************************************************** */
3027 off_t totalread = (off_t)0;
3028 off_t totallength = (off_t)0;
3029 off_t length;
3030
3031 /*@ int ******************************************************** */
3032 int retval = 0;
3033 int res = 0;
3034 size_t n = 0;
3035
3036 /*@ structures ************************************************** */
3037 struct s_filename_and_lstat_info biggiestruct;
3038// struct stat statbuf;
3039
3040 assert(bkpinfo != NULL);
3041 assert_string_is_neither_NULL_nor_zerolength(biggie_filename);
3042
3043 biggiestruct.for_backward_compatibility = '\n';
3044 biggiestruct.use_ntfsprog = use_ntfsprog;
3045 optimal_set_size = bkpinfo->optimal_set_size;
3046 if (is_this_file_compressed(biggie_filename)
3047 || bkpinfo->compression_level == 0) {
3048 asprintf(&suffix, "%s", "");
3049 // log_it("%s is indeed compressed :-)", filename);
3050 should_I_compress_slices = FALSE;
3051 } else {
3052 asprintf(&suffix, "%s", bkpinfo->zip_suffix);
3053 should_I_compress_slices = TRUE;
3054 }
3055
3056 if (optimal_set_size < 999) {
3057 fatal_error("bkpinfo->optimal_set_size is insanely small");
3058 }
3059 if (ntfsprog_fifo) {
3060 file_to_openin = ntfsprog_fifo;
3061 asprintf(&checksum_line, "IGNORE");
3062 log_msg(2,
3063 "Not calculating checksum for %s: it would take too long",
3064 biggie_filename);
3065 tmp = find_home_of_exe("ntfsresize");
3066 if ( !tmp) {
3067 fatal_error("ntfsresize not found");
3068 }
3069 paranoid_free(tmp);
3070
3071 asprintf(&command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", biggie_filename);
3072 log_it("command = %s", command);
3073 tmp = call_program_and_get_last_line_of_output(command);
3074 paranoid_free(command);
3075
3076 log_it("res of it = %s", tmp);
3077 totallength = (off_t)atoll(tmp);
3078 paranoid_free(tmp);
3079 } else {
3080 file_to_openin = biggie_filename;
3081 if (strchr(biggie_filename,'\'') != NULL) {
3082 asprintf(&command, "md5sum \"%s\"", biggie_filename);
3083 } else {
3084 asprintf(&command, "md5sum '%s'", biggie_filename);
3085 }
3086 if (!(fin = popen(command, "r"))) {
3087 log_OS_error("Unable to popen-in command");
3088 paranoid_free(command);
3089 return (1);
3090 }
3091 paranoid_free(command);
3092 (void) getline(&checksum_line, &n, fin);
3093 pclose(fin);
3094 totallength = length_of_file (biggie_filename);
3095 }
3096 lstat(biggie_filename, &biggiestruct.properties);
3097 if (strlen(checksum_line) <= MAX_STR_LEN) {
3098 strcpy(biggiestruct.filename, biggie_filename);
3099 } else {
3100 fatal_error("biggie_filename too big");
3101 }
3102 pB = strchr(checksum_line, ' ');
3103 if (!pB) {
3104 pB = strchr(checksum_line, '\t');
3105 }
3106 if (pB) {
3107 *pB = '\0';
3108 }
3109 if (strlen(checksum_line) <= 64) {
3110 strcpy(biggiestruct.checksum, checksum_line);
3111 } else {
3112 fatal_error("checksum_line too big");
3113 }
3114 paranoid_free(checksum_line);
3115
3116 tmp = slice_fname(biggie_file_number, 0, bkpinfo->tmpdir, "");
3117 fout = fopen(tmp, "w");
3118 paranoid_free(tmp);
3119 (void) fwrite((void *) &biggiestruct, 1, sizeof(biggiestruct), fout);
3120 paranoid_fclose(fout);
3121 length = totallength / optimal_set_size / 1024;
3122 log_msg(1, "Opening in %s; slicing it and writing to CD/tape",
3123 file_to_openin);
3124 if (!(fin = fopen(file_to_openin, "r"))) {
3125 log_OS_error("Unable to openin biggie_filename");
3126 asprintf(&tmp, "Cannot archive bigfile '%s': not found",
3127 biggie_filename);
3128 log_to_screen(tmp);
3129 paranoid_free(tmp);
3130
3131 paranoid_free(suffix);
3132 return (1);
3133 }
3134 tmp = slice_fname(biggie_file_number, 0,bkpinfo->tmpdir, "");
3135 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
3136 res = move_files_to_stream(bkpinfo,tmp,NULL);
3137 } else {
3138 res = move_files_to_cd(bkpinfo, tmp, NULL);
3139 }
3140 paranoid_free(tmp);
3141 i = bkpinfo->optimal_set_size / 256;
3142 for (slice_num = 1; !finished; slice_num++) {
3143 curr_slice_fname_uncompressed = slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir, "");
3144 curr_slice_fname_compressed = slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir, suffix);
3145
3146 tmp = percent_media_full_comment(bkpinfo);
3147 update_progress_form(tmp);
3148 paranoid_free(tmp);
3149
3150 if (!(fout = fopen(curr_slice_fname_uncompressed, "w"))) {
3151 log_OS_error(curr_slice_fname_uncompressed);
3152
3153 paranoid_free(curr_slice_fname_uncompressed);
3154 paranoid_free(curr_slice_fname_compressed);
3155 paranoid_free(suffix);
3156 return (1);
3157 }
3158 if (!(tempblock = (char *) malloc(256 * 1024))) {
3159 fatal_error("malloc error 256*1024");
3160 }
3161 if ((i == bkpinfo->optimal_set_size / 256)
3162 && (totalread < 1.1 * totallength)) {
3163 for (i = 0; i < bkpinfo->optimal_set_size / 256; i++) {
3164 blksize = fread(tempblock, 1, 256 * 1024, fin);
3165 if (blksize > 0) {
3166 totalread = totalread + blksize;
3167 (void) fwrite(tempblock, 1, blksize, fout);
3168 } else {
3169 break;
3170 }
3171 }
3172 } else {
3173 i = 0;
3174 }
3175 paranoid_free(tempblock);
3176 paranoid_fclose(fout);
3177 if (i > 0) // length_of_file (curr_slice_fname_uncompressed)
3178 {
3179 if (!does_file_exist(curr_slice_fname_uncompressed)) {
3180 log_msg(2,
3181 "Warning - '%s' doesn't exist. How can I compress slice?",
3182 curr_slice_fname_uncompressed);
3183 }
3184 if (should_I_compress_slices && bkpinfo->compression_level > 0) {
3185 asprintf(&command, "%s -%d %s", bkpinfo->zip_exe,
3186 bkpinfo->compression_level,
3187 curr_slice_fname_uncompressed);
3188 log_msg(2, command);
3189 if ((res = system(command))) {
3190 log_OS_error(command);
3191 }
3192 // did_I_compress_slice = TRUE;
3193 } else {
3194 /* BERLIOS: Useless
3195 asprintf(&command, "mv %s %s 2>> %s",
3196 curr_slice_fname_uncompressed,
3197 curr_slice_fname_compressed, MONDO_LOGFILE);
3198 */
3199 res = 0; // don't do it :)
3200 // did_I_compress_slice = FALSE;
3201 }
3202 retval += res;
3203 if (res) {
3204 log_msg(2, "Failed to compress the slice");
3205 }
3206 if (bkpinfo->use_lzo
3207 && strcmp(curr_slice_fname_compressed,
3208 curr_slice_fname_uncompressed)) {
3209 unlink(curr_slice_fname_uncompressed);
3210 }
3211 if (res) {
3212 asprintf(&tmp, "Problem with slice # %ld", slice_num);
3213 } else {
3214 asprintf(&tmp,
3215 "%s - Bigfile #%ld, slice #%ld compressed OK ",
3216 biggie_filename, biggie_file_number + 1,
3217 slice_num);
3218 }
3219#ifndef _XWIN
3220 if (!g_text_mode) {
3221 newtDrawRootText(0, g_noof_rows - 2, tmp);
3222 newtRefresh();
3223 } else {
3224 log_msg(2, tmp);
3225 }
3226#else
3227 log_msg(2, tmp);
3228#endif
3229 paranoid_free(tmp);
3230 asprintf(&file_to_archive, "%s", curr_slice_fname_compressed);
3231 g_current_progress++;
3232 } else { /* if i==0 then ... */
3233
3234 finished = TRUE;
3235 asprintf(&file_to_archive, "%s",
3236 curr_slice_fname_uncompressed);
3237 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
3238 break;
3239 }
3240 }
3241
3242 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
3243 register_in_tape_catalog(biggieslice, biggie_file_number,
3244 slice_num, file_to_archive);
3245 maintain_collection_of_recent_archives(bkpinfo->tmpdir,
3246 file_to_archive);
3247 res = move_files_to_stream(bkpinfo, file_to_archive, NULL);
3248 } else {
3249 res = move_files_to_cd(bkpinfo, file_to_archive, NULL);
3250 }
3251 paranoid_free(file_to_archive);
3252 retval += res;
3253 if (res) {
3254 asprintf(&tmp,
3255 "Failed to add slice %ld of bigfile %ld to scratchdir",
3256 slice_num, biggie_file_number + 1);
3257 log_to_screen(tmp);
3258 paranoid_free(tmp);
3259 fatal_error
3260 ("Hard disk full. You should have bought a bigger one.");
3261 }
3262 paranoid_free(curr_slice_fname_uncompressed);
3263 paranoid_free(curr_slice_fname_compressed);
3264 }
3265 paranoid_free(suffix);
3266 paranoid_fclose(fin);
3267 if (retval) {
3268 asprintf(&tmp, "Sliced bigfile #%ld...FAILED",
3269 biggie_file_number + 1);
3270 } else {
3271 asprintf(&tmp, "Sliced bigfile #%ld...OK!",
3272 biggie_file_number + 1);
3273 }
3274 log_msg(1, tmp);
3275 paranoid_free(tmp);
3276 return (retval);
3277}
3278
3279
3280/**
3281 * Remove the archives in @c d.
3282 * This could possibly include any of:
3283 * - all afioballs (compressed and not)
3284 * - all filelists
3285 * - all slices
3286 * - all checksums
3287 * - a zero filler file
3288 *
3289 * @param d The directory to wipe the archives from.
3290 * @ingroup utilityGroup
3291 */
3292void wipe_archives(char *d)
3293{
3294 /*@ buffers ********************************************* */
3295 char *tmp;
3296 char *dir;
3297
3298 assert_string_is_neither_NULL_nor_zerolength(d);
3299
3300 asprintf(&dir, "%s/archives", d);
3301 asprintf(&tmp, "find %s -name '*.afio*' -exec rm -f '{}' \\;", dir);
3302 run_program_and_log_output(tmp, FALSE);
3303 paranoid_free(tmp);
3304
3305 asprintf(&tmp, "find %s -name '*list.[0-9]*' -exec rm -f '{}' \\;",
3306 dir);
3307 run_program_and_log_output(tmp, FALSE);
3308 paranoid_free(tmp);
3309
3310 asprintf(&tmp, "find %s -name 'slice*' -exec rm -f '{}' \\;", dir);
3311 run_program_and_log_output(tmp, FALSE);
3312 paranoid_free(tmp);
3313
3314 asprintf(&tmp, "rm -f %s/cklist*", dir);
3315 run_program_and_log_output(tmp, FALSE);
3316 paranoid_free(tmp);
3317
3318 asprintf(&tmp, "rm -f %s/zero", dir);
3319 run_program_and_log_output(tmp, FALSE);
3320 paranoid_free(tmp);
3321
3322 log_msg(1, "Wiped %s's archives", dir);
3323 asprintf(&tmp, "ls -l %s", dir);
3324 run_program_and_log_output(tmp, FALSE);
3325 paranoid_free(tmp);
3326
3327 paranoid_free(dir);
3328}
3329
3330
3331/**
3332 * @addtogroup LLarchiveGroup
3333 * @{
3334 */
3335/**
3336 * Write the final ISO image.
3337 * @param bkpinfo The backup information structure. Used only
3338 * in the call to @c write_iso_and_go_on().
3339 * @return The number of errors encountered (0 for success)
3340 * @see write_iso_and_go_on
3341 * @see make_iso_fs
3342 * @bug The final ISO is written even if there are no files on it. In practice,
3343 * however, this occurs rarely.
3344 */
3345int write_final_iso_if_necessary(struct s_bkpinfo *bkpinfo)
3346{
3347 /*@ int ***************************************************** */
3348 int res;
3349
3350 /*@ buffers ************************************************** */
3351 char *tmp;
3352
3353 assert(bkpinfo != NULL);
3354
3355// 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
3356
3357 asprintf(&tmp, "Writing the final ISO");
3358 log_msg(2, tmp);
3359 /* BERLIOS: center_string is now broken
3360 center_string(tmp, 80);
3361 */
3362#ifndef _XWIN
3363 if (!g_text_mode) {
3364 newtPushHelpLine(tmp);
3365 }
3366#endif
3367 paranoid_free(tmp);
3368 res = write_iso_and_go_on(bkpinfo, TRUE);
3369#ifndef _XWIN
3370 if (!g_text_mode) {
3371 newtPopHelpLine();
3372 }
3373#endif
3374 log_msg(2, "Returning from writing final ISO (res=%d)", res);
3375 return (res);
3376}
3377
3378
3379/**
3380 * Write an ISO image to <tt>[bkpinfo->isodir]/bkpinfo->prefix-[g_current_media_number].iso</tt>.
3381 * @param bkpinfo The backup information structure. Fields used:
3382 * - @c backup_media_type
3383 * - @c prefix
3384 * - @c isodir
3385 * - @c manual_cd_tray
3386 * - @c media_size
3387 * - @c nfs_mount
3388 * - @c nfs_remote_dir
3389 * - @c scratchdir
3390 * - @c verify_data
3391 *
3392 * @param last_cd If TRUE, this is the last CD to write; if FALSE, it's not.
3393 * @return The number of errors encountered (0 for success)
3394 * @see make_iso_fs
3395 */
3396int write_iso_and_go_on(struct s_bkpinfo *bkpinfo, bool last_cd)
3397{
3398 /*@ pointers **************************************************** */
3399 FILE *fout;
3400
3401 /*@ buffers ***************************************************** */
3402 char *tmp;
3403 char *cdno_fname;
3404 char *lastcd_fname;
3405 char *isofile;
3406
3407 /*@ bool ******************************************************** */
3408 bool that_one_was_ok;
3409 bool using_nfs;
3410 bool orig_vfy_flag_val;
3411
3412 /*@ int *********************************************************** */
3413 int res = 0;
3414
3415 assert(bkpinfo != NULL);
3416 orig_vfy_flag_val = bkpinfo->verify_data;
3417 if (bkpinfo->media_size[g_current_media_number] <= 0) {
3418 fatal_error("write_iso_and_go_on() - unknown media size");
3419 }
3420
3421 if (strlen(bkpinfo->nfs_mount) > 1) {
3422 using_nfs = TRUE;
3423 } else {
3424 using_nfs = FALSE;
3425 }
3426 log_msg(1, "OK, time to make %s #%d",
3427 bkpinfo->backup_media_string,
3428 g_current_media_number);
3429
3430 /* label the ISO with its number */
3431
3432 asprintf(&cdno_fname, "%s/archives/THIS-CD-NUMBER",
3433 bkpinfo->scratchdir);
3434 fout = fopen(cdno_fname, "w");
3435 fprintf(fout, "%d", g_current_media_number);
3436 paranoid_fclose(fout);
3437 paranoid_free(cdno_fname);
3438
3439 asprintf(&tmp, "cp -f %s/autorun %s/", g_mondo_home,
3440 bkpinfo->scratchdir);
3441 if (run_program_and_log_output(tmp, FALSE)) {
3442 log_msg(2, "Warning - unable to copy autorun to scratchdir");
3443 }
3444 paranoid_free(tmp);
3445
3446 /* last CD or not? Label accordingly */
3447 asprintf(&lastcd_fname, "%s/archives/NOT-THE-LAST",
3448 bkpinfo->scratchdir);
3449 if (last_cd) {
3450 unlink(lastcd_fname);
3451 log_msg(2,
3452 "OK, you're telling me this is the last CD. Fair enough.");
3453 } else {
3454 fout = fopen(lastcd_fname, "w");
3455 fprintf(fout,
3456 "You're listening to 90.3 WPLN, Nashville Public Radio.\n");
3457 paranoid_fclose(fout);
3458 }
3459 paranoid_free(lastcd_fname);
3460
3461 if (space_occupied_by_cd(bkpinfo->scratchdir) / 1024 >
3462 bkpinfo->media_size[g_current_media_number]) {
3463 asprintf(&tmp,
3464 "Warning! CD is too big. It occupies %ld KB, which is more than the %ld KB allowed.",
3465 (long) space_occupied_by_cd(bkpinfo->scratchdir),
3466 (long) bkpinfo->media_size[g_current_media_number]);
3467 log_to_screen(tmp);
3468 paranoid_free(tmp);
3469 }
3470 asprintf(&isofile, "%s/%s/%s-%d.iso", bkpinfo->isodir,
3471 bkpinfo->nfs_remote_dir, bkpinfo->prefix,
3472 g_current_media_number);
3473 for (that_one_was_ok = FALSE; !that_one_was_ok;) {
3474 res = make_iso_fs(bkpinfo, isofile);
3475 if (g_current_media_number == 1 && !res
3476 && (bkpinfo->backup_media_type == cdr
3477 || bkpinfo->backup_media_type == cdrw)) {
3478 if ((tmp = find_cdrom_device(FALSE)) == NULL) // make sure find_cdrom_device() finds, records CD-R's loc
3479 {
3480 log_msg(3, "*Sigh* Mike, I hate your computer.");
3481 bkpinfo->manual_cd_tray = TRUE;
3482 } // if it can't be found then force pausing
3483 else {
3484 log_msg(3, "Great. Found Mike's CD-ROM drive.");
3485 paranoid_free(tmp);
3486 }
3487 }
3488 if (bkpinfo->verify_data && !res) {
3489 log_to_screen
3490 ("Please reboot from the 1st %s in Compare Mode, as a precaution.",
3491 g_backup_media_string);
3492 chdir("/");
3493 iamhere("Before calling verify_cd_image()");
3494 res += verify_cd_image(bkpinfo);
3495 iamhere("After calling verify_cd_image()");
3496 }
3497 if (!res) {
3498 that_one_was_ok = TRUE;
3499 } else {
3500 asprintf(&tmp, "Failed to burn %s #%d. Retry?",
3501 bkpinfo->backup_media_string,
3502 g_current_media_number);
3503 res = ask_me_yes_or_no(tmp);
3504 paranoid_free(tmp);
3505 if (!res) {
3506 if (ask_me_yes_or_no("Abort the backup?")) {
3507 fatal_error("FAILED TO BACKUP");
3508 } else {
3509 break;
3510 }
3511 } else {
3512 log_msg(2, "Retrying, at user's request...");
3513 res = 0;
3514 }
3515 }
3516 }
3517/*
3518 if (using_nfs)
3519 {
3520 asprintf(&tmp,"mv -f %s %s/%s/", isofile, bkpinfo->isodir, bkpinfo->nfs_remote_dir);
3521 if (run_program_and_log_output(tmp, FALSE))
3522 { log_to_screen("Unable to move ISO to NFS dir"); }
3523 }
3524*/
3525 paranoid_free(isofile);
3526
3527 g_current_media_number++;
3528 if (g_current_media_number > MAX_NOOF_MEDIA) {
3529 fatal_error("Too many CD-R(W)'s. Use tape or net.");
3530 }
3531 wipe_archives(bkpinfo->scratchdir);
3532 asprintf(&tmp, "rm -Rf %s/images/*gz %s/images/*data*img",
3533 bkpinfo->scratchdir, bkpinfo->scratchdir);
3534 if (system(tmp)) {
3535 log_msg(2,
3536 "Error occurred when I tried to delete the redundant IMGs and GZs");
3537 }
3538 paranoid_free(tmp);
3539
3540 if (last_cd) {
3541 log_msg(2, "This was your last CD.");
3542 } else {
3543 log_msg(2, "Continuing to backup your data...");
3544 }
3545
3546 bkpinfo->verify_data = orig_vfy_flag_val;
3547 return (0);
3548}
3549
3550/* @} - end of LLarchiveGroup */
3551
3552
3553/**
3554 * Verify the user's data.
3555 * @param bkpinfo The backup information structure. Fields used:
3556 * - @c backup_data
3557 * - @c backup_media_type
3558 * - @c media_device
3559 * - @c verify_data
3560 *
3561 * @return The number of errors encountered (0 for success)
3562 * @ingroup verifyGroup
3563 */
3564int verify_data(struct s_bkpinfo *bkpinfo)
3565{
3566 int res = 0, retval = 0, cdno = 0;
3567 char *tmp;
3568 long diffs = 0;
3569
3570 assert(bkpinfo != NULL);
3571 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
3572 chdir("/");
3573 mvaddstr_and_log_it(g_currentY, 0,
3574 "Verifying archives against live filesystem");
3575 if (bkpinfo->backup_media_type == cdstream) {
3576 paranoid_alloc(bkpinfo->media_device,"/dev/cdrom");
3577 }
3578 verify_tape_backups(bkpinfo);
3579 mvaddstr_and_log_it(g_currentY++, 74, "Done.");
3580 } else if (bkpinfo->backup_data)
3581 //bkpinfo->backup_media_type == cdrw || bkpinfo->backup_media_type == cdr))
3582 {
3583 log_msg(2,
3584 "Not verifying again. Per-CD/ISO verification already carried out.");
3585 paranoid_system
3586 ("cat /tmp/changed.files.* > /tmp/changed.files 2> /dev/null");
3587 } else {
3588 g_current_media_number = cdno;
3589 if (bkpinfo->backup_media_type != iso) {
3590 bkpinfo->media_device = find_cdrom_device(FALSE);
3591 }
3592 chdir("/");
3593 for (cdno = 1; cdno < 99 && bkpinfo->verify_data; cdno++) {
3594 if (cdno != g_current_media_number) {
3595 log_msg(2,
3596 "Warning - had to change g_current_media_number from %d to %d",
3597 g_current_media_number, cdno);
3598 g_current_media_number = cdno;
3599 }
3600 if (bkpinfo->backup_media_type != iso) {
3601 insist_on_this_cd_number(bkpinfo, cdno);
3602 }
3603 res = verify_cd_image(bkpinfo); // sets verify_data to FALSE if it's time to stop verifying
3604 retval += res;
3605 if (res) {
3606 asprintf(&tmp,
3607 "Warnings/errors were reported while checking %s #%d",
3608 bkpinfo->backup_media_string,
3609 g_current_media_number);
3610 log_to_screen(tmp);
3611 paranoid_free(tmp);
3612
3613 }
3614 }
3615 asprintf(&tmp,
3616 "grep 'afio: ' %s | sed 's/afio: //' | grep -vx '/dev/.*' >> /tmp/changed.files",
3617 MONDO_LOGFILE);
3618 system(tmp);
3619 paranoid_free(tmp);
3620
3621 asprintf(&tmp,
3622 "grep 'star: ' %s | sed 's/star: //' | grep -vx '/dev/.*' >> /tmp/changed.files",
3623 MONDO_LOGFILE);
3624 system(tmp);
3625 paranoid_free(tmp);
3626
3627 run_program_and_log_output("umount " MNT_CDROM, FALSE);
3628 eject_device(bkpinfo->media_device);
3629 }
3630 diffs = count_lines_in_file("/tmp/changed.files");
3631
3632 if (diffs > 0) {
3633 if (retval == 0) {
3634 retval = (int) (-diffs);
3635 }
3636 }
3637 return (retval);
3638}
3639
3640
3641/**
3642 * @addtogroup utilityGroup
3643 * @{
3644 */
3645/**
3646 * Write an image to a real 3.5" floppy disk.
3647 * @param device The device to write to (e.g. @c /dev/fd0)
3648 * @param datafile The image to write to @p device.
3649 * @return The number of errors encountered (0 for success)
3650 * @see write_image_to_floppy
3651 */
3652int write_image_to_floppy_SUB(char *device, char *datafile)
3653{
3654 /*@ int *************************************************************** */
3655 int res = 0;
3656 int percentage = 0;
3657 int blockno = 0;
3658 int maxblocks = 0;
3659
3660 /*@ buffers************************************************************ */
3661 char *tmp;
3662 char blk[1024];
3663 char *title;
3664
3665 /*@ pointers ********************************************************** */
3666 char *p;
3667 FILE *fout, *fin;
3668
3669
3670 /* pretty stuff */
3671 if (!(p = strrchr(datafile, '/'))) {
3672 p = datafile;
3673 } else {
3674 p++;
3675 }
3676 asprintf(&title, "Writing %s to floppy", p);
3677 open_evalcall_form(title);
3678 paranoid_free(title);
3679
3680 /* functional stuff */
3681 for (p = device + strlen(device); p != device && isdigit(*(p - 1));
3682 p--);
3683 maxblocks = atoi(p);
3684 if (!maxblocks) {
3685 maxblocks = 1440;
3686 }
3687 asprintf(&tmp, "maxblocks = %d; p=%s", maxblocks, p);
3688 log_msg(2, tmp);
3689 paranoid_free(tmp);
3690
3691 /* copy data from image to floppy */
3692 if (!(fin = fopen(datafile, "r"))) {
3693 log_OS_error("Cannot open img");
3694 return (1);
3695 }
3696 if (!(fout = fopen(device, "w"))) {
3697 log_OS_error("Cannot open fdd");
3698 return (1);
3699 }
3700 for (blockno = 0; blockno < maxblocks; blockno++) {
3701 percentage = blockno * 100 / maxblocks;
3702 if (fread(blk, 1, 1024, fin) != 1024) {
3703 if (feof(fin)) {
3704 log_msg(1,
3705 "img read err - img ended prematurely - non-fatal error");
3706 sleep(3);
3707 return (res);
3708 }
3709 res++;
3710 log_to_screen("img read err");
3711 }
3712 if (fwrite(blk, 1, 1024, fout) != 1024) {
3713 res++;
3714 log_to_screen("fdd write err");
3715 }
3716 if (((blockno + 1) % 128) == 0) {
3717 sync(); /* fflush doesn't work; dunno why */
3718 update_evalcall_form(percentage);
3719 }
3720 }
3721 paranoid_fclose(fin);
3722 paranoid_fclose(fout);
3723 close_evalcall_form();
3724 return (res);
3725}
3726
3727
3728/**
3729 * Wrapper around @c write_image_to_floppy_SUB().
3730 * This function, unlike @c write_image_to_floppy_SUB(),
3731 * gives the user the opportunity to retry if the write fails.
3732 * @see write_image_to_floppy_SUB
3733 */
3734int write_image_to_floppy(char *device, char *datafile)
3735{
3736 /*@ int ************************************************************** */
3737 int res = 0;
3738
3739 assert_string_is_neither_NULL_nor_zerolength(device);
3740 assert_string_is_neither_NULL_nor_zerolength(datafile);
3741
3742 while ((res = write_image_to_floppy_SUB(device, datafile))) {
3743 if (!ask_me_yes_or_no("Failed to write image to floppy. Retry?")) {
3744 return (res);
3745 }
3746 }
3747 return (res);
3748}
3749
3750/* @} - end of utilityGroup */
3751
3752void setenv_mondo_share(void) {
3753
3754setenv("MONDO_SHARE", MONDO_SHARE, 1);
3755}
3756
3757void mr_archive_init_conf(struct s_mr_conf *mr_conf) {
3758 char *command = NULL;
3759 FILE *fin = NULL;
3760 size_t n = 0;
3761 char *param = NULL;
3762
3763 mr_conf = (struct s_mr_conf *)malloc(sizeof(struct s_mr_conf));
3764 if (mr_conf == NULL) {
3765 fatal_error("Unable to malloc mr_conf");
3766 }
3767 /* Default for everything int : 0 char * : NULL */
3768
3769 /* mindi conf parameters also needed in mondo */
3770 mr_conf->mindi_ia64_boot_size = 0;
3771
3772 asprintf(&command, "mindi -printvar IA64_BOOT_SIZE");
3773 fin = popen(command, "r");
3774 getline(&param, &n, fin);
3775 pclose(fin);
3776 paranoid_free(command);
3777 mr_conf->mindi_ia64_boot_size = atoi(param);
3778 paranoid_free(param);
3779
3780 mr_conf->mondo_iso_creation_cmd = NULL;
3781
3782 /* Finds mondo conf file */
3783 mr_conf_open(MONDO_CONF_DIR"/mondo.conf");
3784
3785 /* mondo conf parameters needed */
3786 mr_conf->mondo_iso_creation_cmd = mr_conf_sread("mondo_iso_creation_cmd");
3787
3788 mr_conf_close();
3789}
Note: See TracBrowser for help on using the repository browser.