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

Last change on this file since 689 was 689, checked in by bcornec, 18 years ago

Still other memory management improvements ( I hope :-)

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