source: MondoRescue/branches/3.3/mondo/src/common/libmondo-archive.c@ 3867

Last change on this file since 3867 was 3866, checked in by Bruno Cornec, 4 months ago

Change find_my_editor and find_home_of_exe to return dynamically assigned stringsi - adapt whine_if_not_found

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