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

Last change on this file since 49 was 49, checked in by bcornec, 19 years ago

some bugs corrected (size_t, & for getline, ...) + indent

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