Changeset 783 in MondoRescue for trunk/mondo/mondo/common/libmondo-archive.c


Ignore:
Timestamp:
Aug 31, 2006, 5:09:20 PM (18 years ago)
Author:
Bruno Cornec
Message:
  • Massive rewrite continues for memory management.
  • main structure should now have all parameters allocated dynamically
  • new lib libmr.a + dir + build process reviewed to support it.
  • new include subdir to host external definitions of the new lib
  • code now compiles. Still one remaining link issues for mondorestore. This should allow for some tests soon.

(goal is to separate completely reviewed code and functions and provide clean interfaces)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/mondo/mondo/common/libmondo-archive.c

    r729 r783  
    1010 */
    1111
    12 #include "../common/my-stuff.h"
     12#include "my-stuff.h"
    1313#include "../common/mondostructures.h"
     14#include "mr_conf.h"
    1415#include "libmondo-string-EXT.h"
    1516#include "libmondo-stream-EXT.h"
     
    8081 */
    8182t_bkptype g_backup_media_type = none;
     83char *g_backup_media_string = NULL;
    8284
    8385/**
     
    231233        log_msg(5, "command='%s'", command);
    232234        res = system(command);
    233         tmp = last_line_of_file(MONDO_LOGFILE));
     235        tmp = last_line_of_file(MONDO_LOGFILE);
    234236        log_msg(1, "res=%d; tmp='%s'", res, tmp);
    235237        if (bkpinfo->use_star && (res == 254 || res == 65024)
     
    390392    }
    391393
    392     if (g_tmpfs_mountpt[0] != '\0') {
     394    if (g_tmpfs_mountpt != NULL) {
    393395        tmp = call_program_and_get_last_line_of_output
    394396                 ("df -m -P | grep dev/shm | grep -v none | tr -s ' ' '\t' | cut -f4");
     
    424426 * @ingroup archiveGroup
    425427 */
    426 int backup_data(struct s_bkpinfo *bkpinfo, struct s_mrconf *mrconf)
     428int backup_data(struct s_bkpinfo *bkpinfo)
    427429{
    428430    int retval = 0, res = 0;
     
    651653        else
    652654            ch = 'U';
     655
    653656        if (bkpinfo->boot_loader != '\0') {
    654657            asprintf(&tmp, "User specified boot loader. It is '%c'.",
     
    743746    }
    744747    paranoid_free(tmp);
     748    /* BERLIOS: Use bkptype_to_string without LANG */
    745749    switch (bkpinfo->backup_media_type) {
    746750    case cdr:
     
    11061110 * @ingroup MLarchiveGroup
    11071111 */
    1108 int do_that_final_phase(struct s_bkpinfo *bkpinfo, struct s_mrconf *mrconf)
     1112int do_that_final_phase(struct s_bkpinfo *bkpinfo)
    11091113{
    11101114
     
    11251129    } else {
    11261130        /* write final ISO */
    1127         res = write_final_iso_if_necessary(bkpinfo, mrconf);
     1131        res = write_final_iso_if_necessary(bkpinfo);
    11281132        retval += res;
    11291133        if (res) {
     
    11781182    g_serial_string = call_program_and_get_last_line_of_output("dd \
    11791183if=/dev/urandom bs=16 count=1 2> /dev/null | \
    1180 hexdump | tr -s ' ' '0' | head -n1"));
     1184hexdump | tr -s ' ' '0' | head -n1");
    11811185    asprintf(&tmp, "%s...word.", g_serial_string);
    11821186    paranoid_free(g_serial_string);
     
    12691273    }
    12701274/* if not Debian then go ahead & use fdformat */
    1271     tempfile = call_program_and_get_last_line_of_output("mktemp -q /tmp/mondo.XXXXXXXX"));
     1275    tempfile = call_program_and_get_last_line_of_output("mktemp -q /tmp/mondo.XXXXXXXX");
    12721276    asprintf(&command, "%s >> %s 2>> %s; rm -f %s", cmd, tempfile,
    12731277             tempfile, tempfile);
     
    12941298        if (trackno <= 5 && last_trkno > 40) {
    12951299            close_evalcall_form();
    1296             strcpy(title, "Verifying format");
    1297             open_evalcall_form(title);
     1300            open_evalcall_form("Verifying format");
    12981301        }
    12991302        last_trkno = trackno;
     
    14011404 * @return The number of errors encountered (0 for success)
    14021405 */
    1403 int make_afioballs_and_images(struct s_bkpinfo *bkpinfo, struct s_mrconf *mrconf)
     1406int make_afioballs_and_images(struct s_bkpinfo *bkpinfo)
    14041407{
    14051408
     
    15441547            } else {
    15451548                res =
    1546                     move_files_to_cd(bkpinfo, mrconf, storing_filelist_fname,
     1549                    move_files_to_cd(bkpinfo, storing_filelist_fname,
    15471550                                     curr_xattr_list_fname,
    15481551                                     curr_acl_list_fname,
     
    16241627 * @return The number of errors encountered (0 for success)
    16251628 */
    1626 int make_iso_fs(struct s_bkpinfo *bkpinfo, struct s_mrconf *mrconf, char *destfile)
     1629int make_iso_fs(struct s_bkpinfo *bkpinfo, char *destfile)
    16271630{
    16281631    /*@ int ********************************************** */
     
    16671670    /* BERLIOS: Do not ignore getcwd result */
    16681671    (void) getcwd(old_pwd, MAX_STR_LEN - 1);
    1669     asprintf(&tmp, "chmod 744 %s", bkpinfo->scratchdir);
     1672    asprintf(&tmp, "chmod 755 %s", bkpinfo->scratchdir);
    16701673    run_program_and_log_output(tmp, FALSE);
    16711674    paranoid_free(tmp);
    16721675    chdir(bkpinfo->scratchdir);
    16731676
    1674     if (bkpinfo->call_before_iso[0] != '\0') {
     1677    if (bkpinfo->call_before_iso != NULL) {
    16751678        asprintf(&message_to_screen, "Running pre-ISO call for CD#%d",
    16761679                 g_current_media_number);
     
    16871690    }
    16881691
    1689     if (bkpinfo->call_make_iso[0] != '\0') {
     1692    if (bkpinfo->call_make_iso != NULL) {
    16901693        log_msg(2, "bkpinfo->call_make_iso = %s", bkpinfo->call_make_iso);
    16911694        asprintf(&tmp, "%s/archives/NOT-THE-LAST", bkpinfo->scratchdir);
    16921695        asprintf(&message_to_screen, "Making an ISO (%s #%d)",
    1693                  media_descriptor_string(bkpinfo->backup_media_type),
     1696                 bkpinfo->backup_media_string,
    16941697                 g_current_media_number);
    16951698
     
    17891792    } else {
    17901793        asprintf(&message_to_screen, "Running mkisofs to make %s #%d",
    1791                  media_descriptor_string(bkpinfo->backup_media_type),
     1794                 bkpinfo->backup_media_string,
    17921795                 g_current_media_number);
    17931796        log_msg(1, message_to_screen);
    17941797        asprintf(&result_sz, "Call to mkisofs to make ISO (%s #%d) ",
    1795                  media_descriptor_string(bkpinfo->backup_media_type),
     1798                 bkpinfo->backup_media_string,
    17961799                 g_current_media_number);
    17971800        if (bkpinfo->nonbootable_backup) {
     
    18181821#ifdef __IA64__
    18191822                log_msg(1, "IA64 --> elilo");
    1820                 asprintf(&tmp2,"mkisofs -no-emul-boot -b images/mindi-bootroot.%s.img -c boot.cat -o _ISO_ -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .", mrconf->ia64_boot_size);
     1823                asprintf(&tmp2,"mkisofs -no-emul-boot -b images/mindi-bootroot.%s.img -c boot.cat -o _ISO_ -J -r -p MondoRescue -publisher www.mondorescue.org -A Mondo_Rescue_GPL -V _CD#_ .", bkpinfo->mrconf->mindi_ia64_boot_size);
    18211824                res = eval_call_to_make_ISO(bkpinfo,
    18221825                                            tmp2,
     
    18701873    }
    18711874
    1872     if (bkpinfo->call_burn_iso[0] != '\0') {
     1875    if (bkpinfo->call_burn_iso != NULL) {
    18731876        log_msg(2, "bkpinfo->call_burn_iso = %s", bkpinfo->call_burn_iso);
    18741877        asprintf(&message_to_screen, "Burning %s #%d",
    1875                  media_descriptor_string(bkpinfo->backup_media_type),
     1878                 bkpinfo->backup_media_string,
    18761879                 g_current_media_number);
    18771880        pause_and_ask_for_cdr(2, &cd_is_mountable);
     
    18881891    }
    18891892
    1890     if (bkpinfo->call_after_iso[0] != '\0') {
     1893    if (bkpinfo->call_after_iso != NULL) {
    18911894        asprintf(&message_to_screen, "Running post-ISO call (%s #%d)",
    1892                  media_descriptor_string(bkpinfo->backup_media_type),
     1895                 bkpinfo->backup_media_string,
    18931896                 g_current_media_number);
    18941897        res = eval_call_to_make_ISO(bkpinfo, bkpinfo->call_after_iso,
     
    19221925             bigfile_fname);
    19231926    log_msg(1, "command = '%s'", command);
    1924     tmp = call_program_and_get_last_line_of_output(command));
     1927    tmp = call_program_and_get_last_line_of_output(command);
    19251928    log_msg(1, "--> tmp = '%s'", tmp);
    19261929    paranoid_free(command);
     
    19511954 */
    19521955int
    1953 make_slices_and_images(struct s_bkpinfo *bkpinfo, struct s_mrconf *mrconf, char *biggielist_fname)
     1956make_slices_and_images(struct s_bkpinfo *bkpinfo, char *biggielist_fname)
    19541957{
    19551958
     
    20702073            }
    20712074            res =
    2072                 slice_up_file_etc(bkpinfo, mrconf, bigfile_fname,
     2075                slice_up_file_etc(bkpinfo, bigfile_fname,
    20732076                                  ntfsprog_fifo, biggie_file_number,
    20742077                                  noof_biggie_files, use_ntfsprog);
     
    21192122 * @see make_afioballs_and_images
    21202123 */
    2121 int make_afioballs_and_images_OLD(struct s_bkpinfo *bkpinfo, struct s_mrconf *mrconf)
     2124int make_afioballs_and_images_OLD(struct s_bkpinfo *bkpinfo)
    21222125{
    21232126
     
    21932196        } else {
    21942197            res =
    2195                 move_files_to_cd(bkpinfo, mrconf, curr_filelist_fname,
     2198                move_files_to_cd(bkpinfo, curr_filelist_fname,
    21962199                                 curr_xattr_list_fname,
    21972200                                 curr_acl_list_fname, curr_afioball_fname,
     
    22412244 * @ingroup MLarchiveGroup
    22422245 */
    2243 int make_those_afios_phase(struct s_bkpinfo *bkpinfo, struct s_mrconf *mrconf)
     2246int make_those_afios_phase(struct s_bkpinfo *bkpinfo)
    22442247{
    22452248    /*@ int ******************************************* */
     
    22582261        log_msg(1,
    22592262                "Using single-threaded make_afioballs_and_images() to suit b0rken FreeBSD 5.0");
    2260         res = make_afioballs_and_images_OLD(bkpinfo, mrconf);
     2263        res = make_afioballs_and_images_OLD(bkpinfo);
    22612264#else
    2262         res = make_afioballs_and_images_OLD(bkpinfo, mrconf);
     2265        res = make_afioballs_and_images_OLD(bkpinfo);
    22632266#endif
    22642267        write_header_block_to_stream((off_t)0, "stop-afioballs",
    22652268                                     BLK_STOP_AFIOBALLS);
    22662269    } else {
    2267         res = make_afioballs_and_images(bkpinfo, mrconf);
     2270        res = make_afioballs_and_images(bkpinfo);
    22682271    }
    22692272
     
    23712374 * transfer files over the network) or leave it as is.
    23722375 */
    2373 int (*move_files_to_cd) (struct s_bkpinfo *, struct s_mrconf *mrconf, char *, ...) =
     2376int (*move_files_to_cd) (struct s_bkpinfo *, char *, ...) =
    23742377    _move_files_to_cd;
    23752378
     
    23922395 * @return The number of errors encountered (0 for success)
    23932396 */
    2394 int _move_files_to_cd(struct s_bkpinfo *bkpinfo, struct s_mrconf *mrconf, char *files_to_add, ...)
     2397int _move_files_to_cd(struct s_bkpinfo *bkpinfo, char *files_to_add, ...)
    23952398{
    23962399
     
    24312434    if (would_occupy / 1024 > bkpinfo->media_size[g_current_media_number]) {
    24322435        /* FALSE because this is not the last CD we'll write */
    2433         res = write_iso_and_go_on(bkpinfo, mrconf, FALSE);
     2436        res = write_iso_and_go_on(bkpinfo, FALSE);
    24342437        retval += res;
    24352438        if (res) {
     
    28232826
    28242827    asprintf(&szmsg, "I am about to burn %s #%d",
    2825              media_descriptor_string(g_backup_media_type),
     2828             g_backup_media_string,
    28262829             g_current_media_number);
    28272830    log_to_screen(szmsg);
     
    28602863            log_to_screen
    28612864                ("%s has data on it but it's probably not a Mondo CD.",
    2862                  media_descriptor_string(g_backup_media_type));
     2865                 g_backup_media_string);
    28632866            asprintf(&our_serial_str, "%s", "");
    28642867        } else {
    28652868            log_to_screen("%s found in drive. It's a Mondo disk.",
    2866                           media_descriptor_string(g_backup_media_type));
     2869                          g_backup_media_string);
    28672870            tmp1 = last_line_of_file(szcdno);
    28682871            cd_number = atoi(tmp1);
     
    28852888        if (cd_number > 0 && !strcmp(our_serial_str, g_serial_string)) {
    28862889            log_msg(2, "This %s is part of this backup set!",
    2887                     media_descriptor_string(g_backup_media_type));
     2890                    g_backup_media_string);
    28882891            ok_go_ahead_burn_it = FALSE;
    28892892            if (cd_number == g_current_media_number - 1) {
    28902893                log_to_screen
    28912894                    ("I think you've left the previous %s in the drive.",
    2892                      media_descriptor_string(g_backup_media_type));
     2895                     g_backup_media_string);
    28932896            } else {
    28942897                log_to_screen
    28952898                    ("Please remove this %s. It is part of the backup set you're making now.",
    2896                      media_descriptor_string(g_backup_media_type));
     2899                     g_backup_media_string);
    28972900            }
    28982901        } else {
     
    29032906        log_msg(2,
    29042907                "paafcd: Can't find CD-ROM drive. Perhaps it has a blank %s in it?",
    2905                 media_descriptor_string(g_backup_media_type));
     2908                g_backup_media_string);
    29062909        if ((cdrw_device = interrogate_disk_currently_in_cdrw_drive(cdrw_device)) != NULL) {
    29072910            ok_go_ahead_burn_it = FALSE;
    29082911            log_to_screen("There isn't a writable %s in the drive.",
    2909                           media_descriptor_string(g_backup_media_type));
     2912                          g_backup_media_string);
    29102913        }
    29112914        paranoid_free(cdrw_device);
     
    29172920        asprintf(&tmp,
    29182921                 "I am about to burn %s #%d of the backup set. Please insert %s and press Enter.",
    2919                  media_descriptor_string(g_backup_media_type),
     2922                 g_backup_media_string,
    29202923                 g_current_media_number,
    2921                  media_descriptor_string(g_backup_media_type));
     2924                 g_backup_media_string);
    29222925        popup_and_OK(tmp);
    29232926        paranoid_free(tmp);
     
    29302933    log_msg(2,
    29312934            "paafcd: OK, I assume I have a blank/reusable %s in the drive...",
    2932             media_descriptor_string(g_backup_media_type));
     2935            g_backup_media_string);
    29332936
    29342937    log_to_screen("Proceeding w/ %s in drive.",
    2935                   media_descriptor_string(g_backup_media_type));
     2938                  g_backup_media_string);
    29362939    if (pmountable) {
    29372940        if (attempt_to_mount_returned_this) {
     
    29942997 */
    29952998int
    2996 slice_up_file_etc(struct s_bkpinfo *bkpinfo, struct s_mrconf *mrconf, char *biggie_filename,
     2999slice_up_file_etc(struct s_bkpinfo *bkpinfo, char *biggie_filename,
    29973000                  char *ntfsprog_fifo, long biggie_file_number,
    29983001                  long noof_biggie_files, bool use_ntfsprog)
     
    30923095    }
    30933096    lstat(biggie_filename, &biggiestruct.properties);
    3094     strcpy(biggiestruct.filename, biggie_filename);
     3097    if (strlen(checksum_line) <= MAX_STR_LEN) {
     3098        strcpy(biggiestruct.filename, biggie_filename);
     3099    } else {
     3100        fatal_error("biggie_filename too big");
     3101    }
    30953102    pB = strchr(checksum_line, ' ');
    30963103    if (!pB) {
     
    31003107        *pB = '\0';
    31013108    }
    3102     strcpy(biggiestruct.checksum, checksum_line);
     3109    if (strlen(checksum_line) <= 64) {
     3110        strcpy(biggiestruct.checksum, checksum_line);
     3111    } else {
     3112        fatal_error("checksum_line too big");
     3113    }
    31033114    paranoid_free(checksum_line);
    31043115
     
    31253136        res = move_files_to_stream(bkpinfo,tmp,NULL);
    31263137    } else {
    3127         res = move_files_to_cd(bkpinfo, mrconf, tmp, NULL);
     3138        res = move_files_to_cd(bkpinfo, tmp, NULL);
    31283139    }
    31293140    paranoid_free(tmp);
     
    31313142    for (slice_num = 1; !finished; slice_num++) {
    31323143        curr_slice_fname_uncompressed = slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir, "");
    3133         curr_slice_fname_compressed = slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir, suffix));
     3144        curr_slice_fname_compressed = slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir, suffix);
    31343145
    31353146        tmp = percent_media_full_comment(bkpinfo);
     
    32363247            res = move_files_to_stream(bkpinfo, file_to_archive, NULL);
    32373248        } else {
    3238             res = move_files_to_cd(bkpinfo, mrconf, file_to_archive, NULL);
     3249            res = move_files_to_cd(bkpinfo, file_to_archive, NULL);
    32393250        }
    32403251        paranoid_free(file_to_archive);
     
    33323343 * however, this occurs rarely.
    33333344 */
    3334 int write_final_iso_if_necessary(struct s_bkpinfo *bkpinfo, struct s_mrconf *mrconf)
     3345int write_final_iso_if_necessary(struct s_bkpinfo *bkpinfo)
    33353346{
    33363347    /*@ int ***************************************************** */
     
    33553366#endif
    33563367    paranoid_free(tmp);
    3357     res = write_iso_and_go_on(bkpinfo, mrconf, TRUE);
     3368    res = write_iso_and_go_on(bkpinfo, TRUE);
    33583369#ifndef _XWIN
    33593370    if (!g_text_mode) {
     
    33833394 * @see make_iso_fs
    33843395 */
    3385 int write_iso_and_go_on(struct s_bkpinfo *bkpinfo, struct s_mrconf *mrconf, bool last_cd)
     3396int write_iso_and_go_on(struct s_bkpinfo *bkpinfo, bool last_cd)
    33863397{
    33873398    /*@ pointers **************************************************** */
     
    34143425    }
    34153426    log_msg(1, "OK, time to make %s #%d",
    3416             media_descriptor_string(bkpinfo->backup_media_type),
     3427            bkpinfo->backup_media_string,
    34173428            g_current_media_number);
    34183429
     
    34613472             g_current_media_number);
    34623473    for (that_one_was_ok = FALSE; !that_one_was_ok;) {
    3463         res = make_iso_fs(bkpinfo, mrconf, isofile);
     3474        res = make_iso_fs(bkpinfo, isofile);
    34643475        if (g_current_media_number == 1 && !res
    34653476            && (bkpinfo->backup_media_type == cdr
     
    34783489            log_to_screen
    34793490                ("Please reboot from the 1st %s in Compare Mode, as a precaution.",
    3480                  media_descriptor_string(g_backup_media_type));
     3491                 g_backup_media_string);
    34813492            chdir("/");
    34823493            iamhere("Before calling verify_cd_image()");
     
    34883499        } else {
    34893500            asprintf(&tmp, "Failed to burn %s #%d. Retry?",
    3490                      media_descriptor_string(bkpinfo->backup_media_type),
     3501                     bkpinfo->backup_media_string,
    34913502                     g_current_media_number);
    34923503            res = ask_me_yes_or_no(tmp);
     
    35773588        g_current_media_number = cdno;
    35783589        if (bkpinfo->backup_media_type != iso) {
    3579             bkpinfo->media_device = find_cdrom_device(FALSE));
     3590            bkpinfo->media_device = find_cdrom_device(FALSE);
    35803591        }
    35813592        chdir("/");
     
    35953606                asprintf(&tmp,
    35963607                         "Warnings/errors were reported while checking %s #%d",
    3597                          media_descriptor_string(bkpinfo->
    3598                                                  backup_media_type),
     3608                         bkpinfo->backup_media_string,
    35993609                         g_current_media_number);
    36003610                log_to_screen(tmp);
     
    37453755}
    37463756
    3747 void mrarchive_init_conf(struct s_mrconf *mrconf) {
     3757void mr_archive_init_conf(struct s_mr_conf *mr_conf) {
    37483758    char *command = NULL;
    3749     FILE *conffd = NULL;
    37503759    FILE *fin = NULL;
    3751     int n = 0;
     3760    size_t n = 0;
    37523761    char *param = NULL;
    37533762
    3754     mrconf = (struct s_mrconf *)malloc(sizeof(struct s_mrconf));
    3755     if (mrconf == NULL) {
    3756             fatal_error("Unable to malloc mrconf");
     3763    mr_conf = (struct s_mr_conf *)malloc(sizeof(struct s_mr_conf));
     3764    if (mr_conf == NULL) {
     3765            fatal_error("Unable to malloc mr_conf");
    37573766    }
    37583767    /* Default for everything int : 0 char * : NULL */
    37593768
    37603769    /* mindi conf parameters also needed in mondo */
    3761     mrconf->ia64_boot_size = 0;
     3770    mr_conf->mindi_ia64_boot_size = 0;
    37623771
    37633772    asprintf(&command, "mindi -printvar IA64_BOOT_SIZE");
     
    37663775    pclose(fin);
    37673776    paranoid_free(command);
    3768     mrconf->ia64_boot_size = atoi(param);
     3777    mr_conf->mindi_ia64_boot_size = atoi(param);
    37693778    paranoid_free(param);
    37703779
    3771     mrconf->iso_creation_cmd = NULL;
     3780    mr_conf->mondo_iso_creation_cmd = NULL;
    37723781
    37733782    /* Finds mondo conf file */
    3774     mrconf_open(MONDO_CONF_DIR"/mondo.conf");
     3783    mr_conf_open(MONDO_CONF_DIR"/mondo.conf");
    37753784
    37763785    /* mondo conf parameters needed */
    3777     mrconf->iso_creation_cmd = mrconf_sread(iso_creation_cmd);
    3778 
    3779     mrconf_close();
     3786    mr_conf->mondo_iso_creation_cmd = mr_conf_sread("mondo_iso_creation_cmd");
     3787
     3788    mr_conf_close();
     3789}
Note: See TracChangeset for help on using the changeset viewer.