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

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

merge -r 125:126 $SVN_M/branches/2.05

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