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

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

Typo again :-(

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