source: MondoRescue/branches/2.2.10/mondo/src/common/libmondo-archive.c@ 2428

Last change on this file since 2428 was 2428, checked in by Bruno Cornec, 15 years ago
  • Attempt to stay backward compatible without protocol for -n option
  • Improving ssh support at restore time by providing a shadow file
  • analyze-my-lvm now removes excluded devices from list coming from mondoarchive
  • new mr_make_devlist_from_pathlist which handle the new bkpinfo->exclude_devs field containing the excluded devices and remove corresponding code from libmondo-cli.c
  • Move DSF code into libmondo-devices.c for coherency, and only the previous function is made externally available
  • Remove dev_to_exclude in libmondo-archive.c which wasn't working correctly and replace it with bkpinfo->exclude_devs
  • Fix an issue in is_this_device_mounted (string freed before last usage)
  • Adds support for bnx2x (BL 460 G6) and auth_rpcgss (Debian 2.6.31)

(Backport from 2.2.9)

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