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

Last change on this file since 795 was 783, checked in by Bruno Cornec, 18 years ago
  • Massive rewrite continues for memory management.
  • main structure should now have all parameters allocated dynamically
  • new lib libmr.a + dir + build process reviewed to support it.
  • new include subdir to host external definitions of the new lib
  • code now compiles. Still one remaining link issues for mondorestore. This should allow for some tests soon.

(goal is to separate completely reviewed code and functions and provide clean interfaces)

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