Changeset 2211 in MondoRescue for branches/2.2.9/mondo/src/mondorestore/mondo-prep.c
- Timestamp:
- Jun 3, 2009, 7:10:19 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mondo/src/mondorestore/mondo-prep.c
r2205 r2211 1 1 /*************************************************************************** 2 2 $Id$ 3 ***************************************************************************/ 4 5 /*************************************************************************** 6 * * 7 * This program is free software; you can redistribute it and/or modify * 8 * it under the terms of the GNU General Public License as published by * 9 * the Free Software Foundation; either version 2 of the License, or * 10 * (at your option) any later version. * 11 * * 12 ***************************************************************************/ 13 14 /** 15 * @file 16 * Functions for prepping hard drives: partitioning, formatting, etc. 17 */ 3 * Functions for prepping hard drives: partitioning, formatting, etc. 4 */ 18 5 19 6 20 7 #include "my-stuff.h" 8 #include "mr_mem.h" 21 9 #include "../common/mondostructures.h" 22 10 #include "mondoprep.h" … … 349 337 log_it("%s... so I'll get creative.", tmp); 350 338 if (lvmversion == 2) { 351 asprintf(&tmp1, "tail -n5 %s | grep Insufficient | tail -n1", MONDO_LOGFILE);339 mr_asprintf(&tmp1, "tail -n5 %s | grep Insufficient | tail -n1", MONDO_LOGFILE); 352 340 strcpy(tmp, call_program_and_get_last_line_of_output(tmp1)); 353 341 free(tmp1); 354 342 } else { 355 asprintf(&tmp1, "tail -n5 %s | grep lvcreate | tail -n1", MONDO_LOGFILE);343 mr_asprintf(&tmp1, "tail -n5 %s | grep lvcreate | tail -n1", MONDO_LOGFILE); 356 344 strcpy(tmp, call_program_and_get_last_line_of_output(tmp1)); 357 345 free(tmp1); … … 596 584 } 597 585 // create device list from normal disks followed by spare ones 598 asprintf(&devices, "%s", raidlist->el[i].data_disks.el[0].device);586 mr_asprintf(&devices, "%s", raidlist->el[i].data_disks.el[0].device); 599 587 for (j = 1; j < raidlist->el[i].data_disks.entries; j++) { 600 asprintf(&strtmp, "%s", devices);588 mr_asprintf(&strtmp, "%s", devices); 601 589 paranoid_free(devices); 602 asprintf(&devices, "%s %s", strtmp,590 mr_asprintf(&devices, "%s %s", strtmp, 603 591 raidlist->el[i].data_disks.el[j].device); 604 592 paranoid_free(strtmp); 605 593 } 606 594 for (j = 0; j < raidlist->el[i].spare_disks.entries; j++) { 607 asprintf(&strtmp, "%s", devices);595 mr_asprintf(&strtmp, "%s", devices); 608 596 paranoid_free(devices); 609 asprintf(&devices, "%s %s", strtmp,597 mr_asprintf(&devices, "%s %s", strtmp, 610 598 raidlist->el[i].spare_disks.el[j].device); 611 599 paranoid_free(strtmp); … … 613 601 // translate RAID level 614 602 if (raidlist->el[i].raid_level == -2) { 615 asprintf(&level, "multipath");603 mr_asprintf(&level, "multipath"); 616 604 } else if (raidlist->el[i].raid_level == -1) { 617 asprintf(&level, "linear");605 mr_asprintf(&level, "linear"); 618 606 } else { 619 asprintf(&level, "raid%d", raidlist->el[i].raid_level);607 mr_asprintf(&level, "raid%d", raidlist->el[i].raid_level); 620 608 } 621 609 // create RAID device: … … 624 612 // - faulty devices ignored 625 613 // - persistent superblock always used as this is recommended 626 asprintf(&program,614 mr_asprintf(&program, 627 615 "mdadm --create --force --run --auto=yes %s --level=%s --raid-devices=%d", 628 616 raidlist->el[i].raid_device, level, 629 617 raidlist->el[i].data_disks.entries); 630 618 if (raidlist->el[i].parity != -1) { 631 asprintf(&strtmp, "%s", program);619 mr_asprintf(&strtmp, "%s", program); 632 620 paranoid_free(program); 633 621 switch(raidlist->el[i].parity) { 634 622 case 0: 635 asprintf(&program, "%s --parity=%s", strtmp, "la");623 mr_asprintf(&program, "%s --parity=%s", strtmp, "la"); 636 624 break; 637 625 case 1: 638 asprintf(&program, "%s --parity=%s", strtmp, "ra");626 mr_asprintf(&program, "%s --parity=%s", strtmp, "ra"); 639 627 break; 640 628 case 2: 641 asprintf(&program, "%s --parity=%s", strtmp, "ls");629 mr_asprintf(&program, "%s --parity=%s", strtmp, "ls"); 642 630 break; 643 631 case 3: 644 asprintf(&program, "%s --parity=%s", strtmp, "rs");632 mr_asprintf(&program, "%s --parity=%s", strtmp, "rs"); 645 633 break; 646 634 default: … … 651 639 } 652 640 if (raidlist->el[i].chunk_size != -1) { 653 asprintf(&strtmp, "%s", program);641 mr_asprintf(&strtmp, "%s", program); 654 642 paranoid_free(program); 655 asprintf(&program, "%s --chunk=%d", strtmp, raidlist->el[i].chunk_size);643 mr_asprintf(&program, "%s --chunk=%d", strtmp, raidlist->el[i].chunk_size); 656 644 paranoid_free(strtmp); 657 645 } 658 646 if (raidlist->el[i].spare_disks.entries > 0) { 659 asprintf(&strtmp, "%s", program);647 mr_asprintf(&strtmp, "%s", program); 660 648 paranoid_free(program); 661 asprintf(&program, "%s --spare-devices=%d", strtmp,649 mr_asprintf(&program, "%s --spare-devices=%d", strtmp, 662 650 raidlist->el[i].spare_disks.entries); 663 651 paranoid_free(strtmp); 664 652 } 665 asprintf(&strtmp, "%s", program);653 mr_asprintf(&strtmp, "%s", program); 666 654 paranoid_free(program); 667 asprintf(&program, "%s %s", strtmp, devices);655 mr_asprintf(&program, "%s %s", strtmp, devices); 668 656 paranoid_free(strtmp); 669 657 res = run_program_and_log_output(program, 1); … … 690 678 { 691 679 /** int **************************************************************/ 692 int res;693 int retval = 0;694 680 #ifdef __FreeBSD__ 695 681 static bool vinum_started_yet = FALSE; … … 698 684 /** buffers ***********************************************************/ 699 685 char *program; 700 char *tmp; 686 char *tmp = NULL; 687 int res = 0; 688 int retval = 0; 701 689 702 690 /** end ****************************************************************/ 703 691 704 692 malloc_string(program); 705 malloc_string(tmp);706 693 assert_string_is_neither_NULL_nor_zerolength(device); 707 694 assert(format != NULL); 708 695 709 696 if (strstr(format, "raid")) { // do not form RAID disks; do it to /dev/md* instead 710 sprintf(tmp, "Not formatting %s (it is a RAID disk)", device);697 mr_asprintf(&tmp, "Not formatting %s (it is a RAID disk)", device); 711 698 log_it(tmp); 699 paranoid_free(tmp); 712 700 paranoid_free(program); 713 paranoid_free(tmp);714 701 return (0); 715 702 } … … 723 710 #endif 724 711 if (strlen(format) <= 2) { 725 sprintf(tmp,712 mr_asprintf(&tmp, 726 713 "%s has a really small format type ('%s') - this is probably a hexadecimal string, which would suggest the partition is an image --- I shouldn't format it", 727 714 device, format); 728 715 log_it(tmp); 716 paranoid_free(tmp); 729 717 paranoid_free(program); 718 return (0); 719 } 720 if (is_this_device_mounted(device)) { 721 mr_asprintf(&tmp, "%s is mounted - cannot format it ", device); 722 log_to_screen(tmp); 730 723 paranoid_free(tmp); 731 return (0);732 }733 if (is_this_device_mounted(device)) {734 sprintf(tmp, "%s is mounted - cannot format it ", device);735 log_to_screen(tmp);736 724 paranoid_free(program); 737 paranoid_free(tmp);738 725 return (1); 739 726 } … … 762 749 FILE *fin; 763 750 char line[MAX_STR_LEN]; 764 sprintf(tmp, 765 "Initializing Vinum device %s (this may take a *long* time)", 766 device); 751 752 mr_asprintf(&tmp, "Initializing Vinum device %s (this may take a *long* time)", device); 767 753 log_to_screen(tmp); 754 paranoid_free(tmp); 755 768 756 /* format raid partition */ 769 757 // sprintf (program, "mkraid --really-force %s", device); --- disabled -- BB, 02/12/2003 … … 780 768 *(strchr(line, '\n')) = '\0'; // get rid of the \n on the end 781 769 782 sprintf(tmp, "Initializing plex: %s", line);770 mr_asprintf(&tmp, "Initializing plex: %s", line); 783 771 open_evalcall_form(tmp); 784 sprintf(tmp, "vinum init %s", line); 772 paranoid_free(tmp); 773 774 mr_asprintf(&tmp, "vinum init %s", line); 785 775 system(tmp); 776 paranoid_free(tmp); 777 786 778 while (1) { 787 sprintf(tmp,779 mr_asprintf(&tmp, 788 780 "vinum lp -r %s | grep '^S' | head -1 | tr -s ' ' | cut -d: -f2 | cut -f1 | sed 's/^ //' | sed 's/I //' | sed 's/%%//'", 789 781 line); 790 782 FILE *pin = popen(tmp, "r"); 783 paranoid_free(tmp); 784 791 785 char status[MAX_STR_LEN / 4]; 792 786 fgets(status, MAX_STR_LEN / 4 - 1, pin); … … 806 800 } 807 801 #else 808 sprintf(tmp, "Initializing RAID device %s", device);802 mr_asprintf(&tmp, "Initializing RAID device %s", device); 809 803 log_to_screen(tmp); 804 paranoid_free(tmp); 810 805 811 806 // Shouldn't be necessary. … … 856 851 } 857 852 res = which_format_command_do_i_need(format, program); 858 sprintf(tmp, "%s %s", program, device);853 mr_asprintf(&tmp, "%s %s", program, device); 859 854 if (strstr(program, "kludge")) { 860 strcat(tmp, " /");855 mr_strcat(tmp, " /"); 861 856 } 862 857 sprintf(program, "sh -c 'echo -en \"y\\ny\\ny\\n\" | %s'", tmp); 863 sprintf(tmp, "Formatting %s as %s", device, format); 858 paranoid_free(tmp); 859 860 mr_asprintf(&tmp, "Formatting %s as %s", device, format); 864 861 update_progress_form(tmp); 862 paranoid_free(tmp); 863 865 864 res = run_program_and_log_output(program, FALSE); 865 mr_asprintf(&tmp, ""); 866 866 if (res && strstr(program, "kludge")) { 867 sprintf(tmp, "Kludge failed; using regular mkfs.%s to format %s",867 mr_strcat(tmp, "Kludge failed; using regular mkfs.%s to format %s", 868 868 format, device); 869 869 #ifdef __FreeBSD__ … … 885 885 retval += res; 886 886 if (retval) { 887 strcat(tmp, "...failed");887 mr_strcat(tmp, "...failed"); 888 888 } else { 889 strcat(tmp, "...OK");889 mr_strcat(tmp, "...OK"); 890 890 } 891 891 892 892 log_to_screen(tmp); 893 paranoid_free(tmp); 894 893 895 paranoid_free(program); 894 paranoid_free(tmp);895 896 system("sync"); 896 897 sleep(1); … … 1717 1718 char *tmp; 1718 1719 char *logfile; 1719 char *output ;1720 char *output = NULL; 1720 1721 1721 1722 /** pointers **********************************************************/ … … 1730 1731 malloc_string(tmp); 1731 1732 malloc_string(logfile); 1732 malloc_string(output);1733 1733 1734 1734 assert_string_is_neither_NULL_nor_zerolength(drive); … … 1745 1745 paranoid_free(tmp); 1746 1746 paranoid_free(logfile); 1747 paranoid_free(output);1748 1747 return (0); 1749 1748 } … … 1766 1765 paranoid_free(tmp); 1767 1766 paranoid_free(logfile); 1768 paranoid_free(output);1769 1767 return (1); 1770 1768 /* … … 1786 1784 /* BERLIOS: should not be called each time */ 1787 1785 part_table_fmt = which_partition_format(drive); 1788 output[0] = '\0';1786 mr_asprintf(&output, ""); 1789 1787 /* make it a primary/extended/logical */ 1790 1788 if (partno <= 4) { 1791 sprintf(output + strlen(output), "n\np\n%d\n", partno);1789 mr_strcat(output, "n\np\n%d\n", partno); 1792 1790 } else { 1793 1791 /* MBR needs an extended partition if more than 4 partitions */ … … 1804 1802 return (1); 1805 1803 } else { 1806 sprintf(output + strlen(output), "n\ne\n%d\n\n\n", 1807 prev_partno + 1); 1804 mr_strcat(output, "n\ne\n%d\n\n\n", prev_partno + 1); 1808 1805 } 1809 1806 } 1810 strcat(output + strlen(output), "n\nl\n");1807 mr_strcat(output, "n\nl\n"); 1811 1808 } else { 1812 1809 /* GPT allows more than 4 primary partitions */ 1813 sprintf(output + strlen(output), "n\np\n%d\n", partno);1814 } 1815 } 1816 strcat(output + strlen(output), "\n"); /*start block (ENTER for next free blk */1810 mr_strcat(output, "n\np\n%d\n", partno); 1811 } 1812 } 1813 mr_strcat(output, "\n"); /*start block (ENTER for next free blk */ 1817 1814 if (partsize > 0) { 1818 1815 if (!strcmp(format, "7")) { … … 1820 1817 partsize += 512; 1821 1818 } 1822 sprintf(output + strlen(output), "+%lldK", (long long) (partsize));1823 } 1824 strcat(output + strlen(output), "\n");1819 mr_strcat(output, "+%lldK", (long long) (partsize)); 1820 } 1821 mr_strcat(output, "\n"); 1825 1822 #if 0 1826 1823 /* … … 1864 1861 } 1865 1862 } else { 1866 strcat(output, "w\n\n");1863 mr_strcat(output, "w\n\n"); 1867 1864 if (g_fprep) { 1868 1865 fprintf(g_fprep, "echo \"%s\" | %s\n", output, program); … … 1916 1913 } 1917 1914 } 1915 paranoid_free(output); 1916 1918 1917 g_current_progress++; 1919 1918 log_it("partition_device() --- leaving"); … … 1922 1921 paranoid_free(tmp); 1923 1922 paranoid_free(logfile); 1924 paranoid_free(output);1925 1923 return (retval); 1926 1924 } … … 2032 2030 char *partition; 2033 2031 char *command; 2034 char *output ;2032 char *output = NULL; 2035 2033 char *tmp; 2036 2034 char *partcode; … … 2051 2049 malloc_string(partition); 2052 2050 malloc_string(command); 2053 malloc_string(output);2054 2051 malloc_string(tmp); 2055 2052 malloc_string(partcode); … … 2138 2135 fput_string_one_char_at_a_time(pout_to_fdisk, "p\n"); 2139 2136 } else { 2140 sprintf(output, "t\n%d\n%s\n", partno, partcode); 2141 strcat(output, "w\n"); 2137 mr_asprintf(&output, "t\n%d\n%s\nw\n", partno, partcode); 2142 2138 sprintf(command, "parted2fdisk %s >> %s 2>> %s", drive, 2143 2139 MONDO_LOGFILE, MONDO_LOGFILE); … … 2154 2150 paranoid_pclose(fout); 2155 2151 } 2152 paranoid_free(output); 2156 2153 } 2157 2154 if (res) { … … 2162 2159 paranoid_free(partition); 2163 2160 paranoid_free(command); 2164 paranoid_free(output);2165 2161 paranoid_free(tmp); 2166 2162 paranoid_free(partcode);
Note:
See TracChangeset
for help on using the changeset viewer.