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

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

log_msg => mr_msg for common files

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