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

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