source: MondoRescue/branches/3.2/mondo/src/common/libmondo-archive.c@ 3379

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