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

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

mr_fclose improved + fixes for libmondo-archive.c

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