Changeset 1080 in MondoRescue for branches/stable/mondo/src/mondorestore/mondo-prep.c
- Timestamp:
- Jan 28, 2007, 7:04:41 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mondo/src/mondorestore/mondo-prep.c
r1067 r1080 1 1 /*************************************************************************** 2 mondo-prep.c - description 3 ----------------- 4 5 begin: Fri Apr 19 16:40:35 EDT 2002 6 copyright : (C) 2002 Mondo Hugo Rabson 7 email : Hugo Rabson <hugorabson@msn.com> 8 edited by : by Stan Benoit 4/2002 9 email : troff@nakedsoul.org 10 cvsid : $Id$ 11 ***************************************************************************/ 12 13 /*************************************************************************** 14 * * 15 * This program is free software; you can redistribute it and/or modify * 16 * it under the terms of the GNU General Public License as published by * 17 * the Free Software Foundation; either version 2 of the License, or * 18 * (at your option) any later version. * 19 * * 20 ***************************************************************************/ 21 22 /* mondo-prep.c Hugo Rabson 23 24 25 26 07/20 27 - when starting RAID, don't do it twice :) 28 - moved Joshua's new get_phys_size_of_drive() code 29 from resize_drive... into get_phys_size_of_drive() 30 31 06/29 32 - make sure software RAID devices are formatted IF user says they're to be 33 - drivelist is struct now, not char[][] 34 35 06/26 36 - drop make_relevant_partition_bootable(); do it yourself in C (mostly) 37 - offer to reboot if partition table is locked up by the kernel 38 39 06/22 40 - be sure not to resize non-NTFS images when restoring 41 - set non-NTFS images' partition types properly 42 43 06/19 44 - shut down all LVMs and VGs before prepping 45 46 05/07 47 - usage of parted2fdisk instead of fdisk alone (ia32/ia64 compatibility) 48 BCO 49 50 03/31 51 - rewrote partitioning and formatting code to call fdisk once per disk 52 53 10/21/2003 54 - suspend/resume Newt gui before/after calling do_my_funky_lvm_stuff() 55 56 10/20 57 - rewrote format_everything() - what a mess it was. 58 It now does things in three phases:- 59 - formats software RAID devices (/dev/md0, etc.) 60 - formats and configures LVM devices 61 - formats regular partitions (/dev/hda1, /dev/sdb2, etc.) 62 and any LVMs recently prepped 63 64 10/07 65 - use strstr(format, "raid") instead of strcmp(format,"raid") to determin 66 if partition is a RAID component 67 68 09/23 69 - better comments 70 71 09/18 72 - better logging of RAID activity 73 74 05/05 75 - added Joshua Oreman's FreeBSD patches 76 77 04/30 78 - added textonly mode 79 80 04/24 81 - added lots of assert()'s and log_OS_error()'s 82 83 04/21 84 - format_everything() --- don't let bar go too far 85 - mkfs -c to check for bad blocks when formatting 86 87 04/04 88 - misc clean-up (Tom Mortell) 89 90 01/15/2003 91 - added code for LVM and SW Raid (Brian Borgeson) 92 93 12/10/2002 94 - line 1238: friendlier output 95 96 11/20 97 - when wiping a given device in preparation for partitioning + formatting 98 it, don't wipe the MBR; just the partition table. That allows for 99 stupid-ass Compaq users who like to play with their MBR's. 100 - disable mountlist.txt-->mountlist.txt.pre-resize copying (superfluous) 101 102 09/09 103 - run_program_and_log_output() now takes boolean operator to specify 104 whether it will log its activities in the event of _success_ 105 106 07/01 - 07/31 107 - added hooks to libmondo 108 - RAID enhancements (Philippe de Muyter) 109 110 01/01 - 03/31 111 - partition_device() will refuse to partition /dev/mdX now (cos it's a 112 virtual drive); however, it will return 0 (i.e. not an error) 113 - make_list_of_drives() will exclude /dev/md* from list 114 - mkreiserfs -ff instead of -q (Andy Glass) 115 - don't resize drive if drive not found (or if its size cannot be det'd) 116 - when generating list of drives from mountlist, skip the 'p' at the end 117 of drive name if /dev/ida/ or /dev/cciss/; just do it (Michael Eisenberg) 118 - don't specify journal size when formatting ext3 119 (used to have -Jsize=10 in the call to mkfs) 120 - handles files >2GB in size 121 - format interactively, if Interactive Mode 122 - removed reference to g_tape_size 123 - when executing /tmp/i-want-my-lvm, only record the error# if the command 124 was _not_ an 'insmod' command 125 - pass partition size to fdisk in Kilobytes now, not Megabytes 126 - log fdisk's output to /tmp/mondo-restore.log if it fails 127 - don't try to format partitions of type 'image' 128 - don't type to set types of 'image' partitions 129 - if format code is 1 or 2 chars then assume it is a hex string 130 - took out all '/ /' comments 131 - don't extrapolate/add partition from RAID dev to mountlist if it's already 132 present in mountlist 133 - less repetitive logging in the event of vacuum-packing of last part'n 134 - no extrapolation at all: RAID partitions should be listed in mountlist 135 already, thanks to either Mindi v0.5x or the mountlist editor itself 136 - no longer say, 'and logging to...' when setting a partition's type 137 - don't run mkfs on RAID partitions (/dev/hd*, /dev/sd*); just set type 138 - the setting of a partition's type now takes place in a separate subroutine 139 from the subroutine that actually creates the partition 140 - no need to set type if 83: 83 is the default (under fdisk) 141 - turned on '-Wall'; cleaned up some cruft 142 - if vacuum-packing partition (i.e. size=0MB --> max) then say, "(maximum)" 143 not, "(0 MB)" 144 145 11/22/2001 146 - preliminary code review 147 - created on Nov 22nd, 2001 2 * $Id$ 148 3 */ 149 4 … … 162 17 #include <linux/hdreg.h> 163 18 #include <math.h> 19 #include "mr_mem.h" 164 20 165 21 … … 220 76 malloc_string(command); 221 77 malloc_string(tmp); 222 buf = m alloc(blocksize);78 buf = mr_malloc(blocksize); 223 79 if (does_file_exist("/tmp/i-want-my-lvm")) // FIXME - cheating :) 224 80 { 225 drivelist = m alloc(sizeof(struct list_of_disks));81 drivelist = mr_malloc(sizeof(struct list_of_disks)); 226 82 make_list_of_drives_in_mountlist(mountlist, drivelist); 227 83 for (lino = 0; lino < drivelist->entries; lino++) { … … 274 130 } 275 131 // Still here? Cool! 276 paranoid_free(command);277 paranoid_free(tmp);132 mr_free(command); 133 mr_free(tmp); 278 134 log_msg(1, "Cool. I didn't have to wipe anything."); 279 135 } … … 384 240 malloc_string(vgremove_sz); 385 241 // malloc_string(do_this_last); // postpone lvcreate call if necessary 386 command = m alloc(512);242 command = mr_malloc(512); 387 243 388 244 // do_this_last[0] = '\0'; … … 549 405 log_msg(1, "Closed i-want-my-lvm. Finished doing funky stuff."); 550 406 end_of_i_want_my_lvm: 551 paranoid_free(tmp);552 paranoid_free(incoming);553 paranoid_free(command);554 paranoid_free(lvscan_sz);555 paranoid_free(lvremove_sz);556 paranoid_free(vgscan_sz);557 paranoid_free(pvscan_sz);558 paranoid_free(vgcreate_sz);559 paranoid_free(vgchange_sz);560 paranoid_free(vgremove_sz);561 // paranoid_free(do_this_last);407 mr_free(tmp); 408 mr_free(incoming); 409 mr_free(command); 410 mr_free(lvscan_sz); 411 mr_free(lvremove_sz); 412 mr_free(vgscan_sz); 413 mr_free(pvscan_sz); 414 mr_free(vgcreate_sz); 415 mr_free(vgchange_sz); 416 mr_free(vgremove_sz); 417 // mr_free(do_this_last); 562 418 system("sync"); 563 419 system("sync"); … … 686 542 } 687 543 } 688 paranoid_free(incoming);689 paranoid_free(tmp);544 mr_free(incoming); 545 mr_free(tmp); 690 546 691 547 return (0); … … 734 590 for (j = 1; j < raidlist->el[i].data_disks.entries; j++) { 735 591 asprintf(&strtmp, "%s", devices); 736 paranoid_free(devices);592 mr_free(devices); 737 593 asprintf(&devices, "%s %s", strtmp, 738 594 raidlist->el[i].data_disks.el[j].device); 739 paranoid_free(strtmp);595 mr_free(strtmp); 740 596 } 741 597 for (j = 0; j < raidlist->el[i].spare_disks.entries; j++) { 742 598 asprintf(&strtmp, "%s", devices); 743 paranoid_free(devices);599 mr_free(devices); 744 600 asprintf(&devices, "%s %s", strtmp, 745 601 raidlist->el[i].spare_disks.el[j].device); 746 paranoid_free(strtmp);602 mr_free(strtmp); 747 603 } 748 604 // translate RAID level … … 765 621 if (raidlist->el[i].parity != -1) { 766 622 asprintf(&strtmp, "%s", program); 767 paranoid_free(program);623 mr_free(program); 768 624 switch(raidlist->el[i].parity) { 769 625 case 0: … … 783 639 break; 784 640 } 785 paranoid_free(strtmp);641 mr_free(strtmp); 786 642 } 787 643 if (raidlist->el[i].chunk_size != -1) { 788 644 asprintf(&strtmp, "%s", program); 789 paranoid_free(program);645 mr_free(program); 790 646 asprintf(&program, "%s --chunk=%d", strtmp, raidlist->el[i].chunk_size); 791 paranoid_free(strtmp);647 mr_free(strtmp); 792 648 } 793 649 if (raidlist->el[i].spare_disks.entries > 0) { 794 650 asprintf(&strtmp, "%s", program); 795 paranoid_free(program);651 mr_free(program); 796 652 asprintf(&program, "%s --spare-devices=%d", strtmp, 797 653 raidlist->el[i].spare_disks.entries); 798 paranoid_free(strtmp);654 mr_free(strtmp); 799 655 } 800 656 asprintf(&strtmp, "%s", program); 801 paranoid_free(program);657 mr_free(program); 802 658 asprintf(&program, "%s %s", strtmp, devices); 803 paranoid_free(strtmp);659 mr_free(strtmp); 804 660 res = run_program_and_log_output(program, 1); 805 661 // free memory 806 paranoid_free(devices);807 paranoid_free(level);808 paranoid_free(program);662 mr_free(devices); 663 mr_free(level); 664 mr_free(program); 809 665 // return to calling instance 810 666 return res; … … 845 701 sprintf(tmp, "Not formatting %s (it is a RAID disk)", device); 846 702 log_it(tmp); 847 paranoid_free(program);848 paranoid_free(tmp);703 mr_free(program); 704 mr_free(tmp); 849 705 return (0); 850 706 } … … 852 708 if (strcmp(format, "swap") == 0) { 853 709 log_it("Not formatting %s - it's swap", device); 854 paranoid_free(program);855 paranoid_free(tmp);710 mr_free(program); 711 mr_free(tmp); 856 712 return (0); 857 713 } … … 862 718 device, format); 863 719 log_it(tmp); 864 paranoid_free(program);865 paranoid_free(tmp);720 mr_free(program); 721 mr_free(tmp); 866 722 return (0); 867 723 } … … 869 725 sprintf(tmp, "%s is mounted - cannot format it ", device); 870 726 log_to_screen(tmp); 871 paranoid_free(program);872 paranoid_free(tmp);727 mr_free(program); 728 mr_free(tmp); 873 729 return (1); 874 730 } … … 986 842 if (!strcmp(format, "lvm")) { 987 843 log_msg(1, "Don't format %s - it's part of an lvm volume", device); 988 paranoid_free(program);989 paranoid_free(tmp);844 mr_free(program); 845 mr_free(tmp); 990 846 return (0); 991 847 } … … 1026 882 1027 883 log_to_screen(tmp); 1028 paranoid_free(program);1029 paranoid_free(tmp);884 mr_free(program); 885 mr_free(tmp); 1030 886 system("sync"); 1031 887 sleep(1); … … 1253 1109 system("clear"); 1254 1110 newtResume(); 1255 paranoid_free(tmp);1111 mr_free(tmp); 1256 1112 return (retval); 1257 1113 } … … 1308 1164 previous_devno = current_devno; 1309 1165 } 1310 paranoid_free(tmp);1166 mr_free(tmp); 1311 1167 return (previous_devno); 1312 1168 } … … 1649 1505 if (!pout_to_fdisk) { 1650 1506 log_to_screen("Cannot call parted2fdisk to configure %s", drivename); 1651 paranoid_free(device_str);1652 paranoid_free(format);1653 paranoid_free(tmp);1507 mr_free(device_str); 1508 mr_free(format); 1509 mr_free(tmp); 1654 1510 return (1); 1655 1511 } … … 1686 1542 ("Warning! Unable to make the drive bootable."); 1687 1543 } 1688 paranoid_free(device_str);1689 paranoid_free(format);1690 paranoid_free(tmp);1544 mr_free(device_str); 1545 mr_free(format); 1546 mr_free(tmp); 1691 1547 return r; 1692 1548 } … … 1777 1633 log_to_screen 1778 1634 ("You must leave at least one partition spare as the Extended partition."); 1779 paranoid_free(device_str);1780 paranoid_free(format);1781 paranoid_free(tmp);1635 mr_free(device_str); 1636 mr_free(format); 1637 mr_free(tmp); 1782 1638 return (1); 1783 1639 } … … 1825 1681 } 1826 1682 } 1827 paranoid_free(device_str);1828 paranoid_free(format);1829 paranoid_free(tmp);1683 mr_free(device_str); 1684 mr_free(format); 1685 mr_free(tmp); 1830 1686 return (retval); 1831 1687 } … … 1877 1733 sprintf(tmp, "Not partitioning %s - it is a virtual drive", drive); 1878 1734 log_it(tmp); 1879 paranoid_free(program);1880 paranoid_free(partition_name);1881 paranoid_free(tmp);1882 paranoid_free(logfile);1883 paranoid_free(output);1735 mr_free(program); 1736 mr_free(partition_name); 1737 mr_free(tmp); 1738 mr_free(logfile); 1739 mr_free(output); 1884 1740 return (0); 1885 1741 } … … 1898 1754 partition_name); 1899 1755 log_to_screen(tmp); 1900 paranoid_free(program);1901 paranoid_free(partition_name);1902 paranoid_free(tmp);1903 paranoid_free(logfile);1904 paranoid_free(output);1756 mr_free(program); 1757 mr_free(partition_name); 1758 mr_free(tmp); 1759 mr_free(logfile); 1760 mr_free(output); 1905 1761 return (1); 1906 1762 /* … … 1933 1789 log_to_screen 1934 1790 ("You need to leave at least one partition free, for 'extended/logical'"); 1935 paranoid_free(program);1936 paranoid_free(partition_name);1937 paranoid_free(tmp);1938 paranoid_free(logfile);1939 paranoid_free(output);1791 mr_free(program); 1792 mr_free(partition_name); 1793 mr_free(tmp); 1794 mr_free(logfile); 1795 mr_free(output); 1940 1796 return (1); 1941 1797 } else { … … 2056 1912 g_current_progress++; 2057 1913 log_it("partition_device() --- leaving"); 2058 paranoid_free(program);2059 paranoid_free(partition_name);2060 paranoid_free(tmp);2061 paranoid_free(logfile);2062 paranoid_free(output);1914 mr_free(program); 1915 mr_free(partition_name); 1916 mr_free(tmp); 1917 mr_free(logfile); 1918 mr_free(output); 2063 1919 return (retval); 2064 1920 } … … 2087 1943 /** end ************************************************************/ 2088 1944 2089 drivelist = m alloc(sizeof(struct list_of_disks));1945 drivelist = mr_malloc(sizeof(struct list_of_disks)); 2090 1946 assert(mountlist != NULL); 2091 1947 … … 2146 2002 system("clear"); 2147 2003 newtResume(); 2148 paranoid_free(drivelist);2004 mr_free(drivelist); 2149 2005 return (retval); 2150 2006 } … … 2290 2146 } 2291 2147 2292 paranoid_free(partition);2293 paranoid_free(command);2294 paranoid_free(output);2295 paranoid_free(tmp);2296 paranoid_free(partcode);2297 paranoid_free(logfile);2148 mr_free(partition); 2149 mr_free(command); 2150 mr_free(output); 2151 mr_free(tmp); 2152 mr_free(partcode); 2153 mr_free(logfile); 2298 2154 2299 2155 return (res); … … 2448 2304 "r"); 2449 2305 if (!fin) { 2450 paranoid_free(dev);2451 paranoid_free(incoming);2306 mr_free(dev); 2307 mr_free(incoming); 2452 2308 return (1); 2453 2309 } … … 2460 2316 if (!fin) { 2461 2317 log_OS_error("/proc/mdstat"); 2462 paranoid_free(dev);2463 paranoid_free(incoming);2318 mr_free(dev); 2319 mr_free(incoming); 2464 2320 return (1); 2465 2321 } … … 2482 2338 log_msg(1, "Warning - unable to stop some RAID devices"); 2483 2339 } 2484 paranoid_free(dev);2485 paranoid_free(incoming);2340 mr_free(dev); 2341 mr_free(incoming); 2486 2342 system("sync"); 2487 2343 system("sync"); … … 2546 2402 res = 0; 2547 2403 } 2548 paranoid_free(tmp);2404 mr_free(tmp); 2549 2405 return (res); 2550 2406 } … … 2588 2444 } 2589 2445 original_size_of_drive = original_size_of_drive / 1024; 2590 paranoid_free(tmp);2446 mr_free(tmp); 2591 2447 return (original_size_of_drive); 2592 2448 } … … 2638 2494 if (strncmp(drive_name, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB)) 2639 2495 == 0) { 2640 paranoid_free(tmp);2496 mr_free(tmp); 2641 2497 return; 2642 2498 } … … 2652 2508 if (current_size_of_drive <= 0) { 2653 2509 log_it("Not resizing to match %s - can't find drive", drive_name); 2654 paranoid_free(tmp);2510 mr_free(tmp); 2655 2511 return; 2656 2512 } … … 2659 2515 log_to_screen(tmp); 2660 2516 2661 drivemntlist = m alloc(sizeof(struct mountlist_reference));2517 drivemntlist = mr_malloc(sizeof(struct mountlist_reference)); 2662 2518 drivemntlist->el = 2663 malloc(sizeof(struct mountlist_line *) * MAX_TAPECATALOG_ENTRIES); 2664 2665 if (!drivemntlist) { 2666 fatal_error("Cannot malloc temporary mountlist\n"); 2667 } 2519 mr_malloc(sizeof(struct mountlist_line *) * MAX_TAPECATALOG_ENTRIES); 2520 2668 2521 create_mountlist_for_drive(mountlist, drive_name, drivemntlist); 2669 2522 … … 2677 2530 drive_name); 2678 2531 log_to_screen(tmp); 2679 paranoid_free(tmp);2532 mr_free(tmp); 2680 2533 return; 2681 2534 } … … 2712 2565 final_size = get_phys_size_of_drive(drive_name); 2713 2566 sprintf(tmp, "final_size = %ld MB", final_size); 2714 paranoid_free(tmp);2567 mr_free(tmp); 2715 2568 log_to_screen(tmp); 2716 2569 } … … 2734 2587 /** end *************************************************************/ 2735 2588 2736 drivelist = malloc(sizeof(struct list_of_disks)); 2737 assert(mountlist != NULL); 2589 drivelist = mr_malloc(sizeof(struct list_of_disks)); 2738 2590 2739 2591 if (g_mountlist_fname[0] == '\0') { … … 2753 2605 } 2754 2606 log_to_screen("Mountlist adjusted to suit current hard drive(s)"); 2755 paranoid_free(drivelist);2607 mr_free(drivelist); 2756 2608 } 2757 2609 … … 2798 2650 } 2799 2651 if (tmp_drive_name) 2800 free(tmp_drive_name);2652 mr_free(tmp_drive_name); 2801 2653 } 2802 2654
Note:
See TracChangeset
for help on using the changeset viewer.