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

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

merge -r489:506 $SVN_M/branches/stable

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