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

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

Huge memory management patch.
Still not finished but a lot as been done.
What remains is around some functions returning strings, and some structure members.
(Could not finish due to laptop failure !)

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