Changeset 2009 in MondoRescue for trunk/mondo/src/mondorestore/mondo-prep.c
- Timestamp:
- Aug 11, 2008, 3:05:15 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mondo/src/mondorestore/mondo-prep.c
r1106 r2009 10 10 11 11 #include "my-stuff.h" 12 #include " ../common/mondostructures.h"12 #include "mondostructures.h" 13 13 #include "mondoprep.h" 14 #include " ../common/libmondo.h"14 #include "libmondo.h" 15 15 #include "mondo-rstr-tools-EXT.h" 16 16 … … 20 20 #include <unistd.h> 21 21 #include "mr_mem.h" 22 #include "mr_msg.h" 22 23 23 24 … … 52 53 void wipe_MBRs_and_reboot_if_necessary(struct mountlist_itself *mountlist) 53 54 { 54 char *command; 55 int lino; 56 FILE *fout; 57 char *buf; 55 char *command = NULL; 56 int lino = 0; 57 int res = 0; 58 FILE *fout = NULL; 59 char *buf = NULL; 58 60 struct list_of_disks *drivelist = NULL; 59 // If LVMs are present and a zero-and-reboot wasn't recently undertaken 60 // then zero & insist on reboot. 61 62 // If LVMs are present and a zero-and-reboot wasn't recently undertaken 63 // then zero & insist on reboot. 61 64 if (does_file_exist("/tmp/i-want-my-lvm")) // FIXME - cheating :) 62 65 { … … 67 70 "dd if=%s bs=512 count=1 2> /dev/null | grep \"%s\"", 68 71 drivelist->el[lino].device, MONDO_WAS_HERE); 69 if (!run_program_and_log_output(command, 1)) { 72 res = run_program_and_log_output(command, 1); 73 mr_free(command); 74 if (!res) { 70 75 mr_msg(1, "Found MONDO_WAS_HERE marker on drive#%d (%s)", 71 76 lino, drivelist->el[lino].device); 72 mr_free(command);73 77 break; 74 78 } 75 mr_free(command);76 79 } 77 80 78 81 if (lino == drivelist->entries) { 79 // zero & reboot82 // zero & reboot 80 83 log_to_screen 81 84 (_ … … 120 123 int fput_string_one_char_at_a_time(FILE * fout, char *str) 121 124 { 122 int i , j;123 FILE *fq ;125 int i = 0, j = 0; 126 FILE *fq = NULL; 124 127 125 128 if (ferror(fout)) { … … 159 162 bool vacuum_pack) 160 163 { 161 /** char **************************************************/162 164 char *tmp = NULL; 163 165 char *tmp1 = NULL; … … 178 180 int i = 0; 179 181 int lvmversion = 1; 180 long extents ;182 long extents = 0L; 181 183 fpos_t orig_pos; 182 184 size_t n = 0; … … 184 186 185 187 /** pointers **********************************************/ 186 FILE *fin ;188 FILE *fin = NULL; 187 189 188 190 /** end *****************************************************/ … … 257 259 continue; 258 260 } 259 if (res && strstr(command, "create") && vacuum_pack) {260 sleep(2);261 sync();262 sync();263 sync();264 }265 261 if ((p = strstr(incoming, "vgcreate"))) { 266 262 // include next line(s) if they end in /dev (cos we've got a broken i-want-my-lvm) … … 271 267 } else { 272 268 fgetpos(fin, &orig_pos); 273 mr_asprintf(&tmp1, "%s%s", incoming, tmp); 274 mr_free(incoming); 275 incoming = tmp1; 269 mr_strcat(incoming, tmp); 276 270 } 277 271 } … … 287 281 *q = '\0'; 288 282 mr_msg(1, "Deleting old entries at /dev/%s", tmp1); 289 mr_asprintf(& tmp, "rm -Rf /dev/%s", tmp1);283 mr_asprintf(&command, "rm -Rf /dev/%s", tmp1); 290 284 mr_free(tmp1); 291 285 292 run_program_and_log_output( tmp, 1);293 mr_free( tmp);286 run_program_and_log_output(command, 1); 287 mr_free(command); 294 288 295 289 run_program_and_log_output(vgscan_sz, 1); … … 300 294 } 301 295 for (p = incoming + 1; *p == ' '; p++); 302 mr_a llocstr(command,p);296 mr_asprintf(&command,p); 303 297 for (p = command; *p != '\0'; p++); 304 for (; *(p - 1) < 32; p--);298 for (; (*(p - 1) < 32) && (p > command) ; p--); 305 299 *p = '\0'; 306 300 … … 319 313 if (strstr(command, "lvm lvcreate")) 320 314 lvmversion = 2; 321 /* BERLIOS : this tmp may be uninitialized ?322 log_it("%s... so I'll get creative.", tmp);323 */324 315 if (lvmversion == 2) { 325 316 tmp = call_program_and_get_last_line_of_output 326 ("tail -n5 " MONDO_LOGFILE 327 " | grep Insufficient | tail -n1"); 317 ("tail -n5 " MONDO_LOGFILE " | grep Insufficient | tail -n1"); 328 318 } else { 329 319 tmp = call_program_and_get_last_line_of_output 330 ("tail -n5 " MONDO_LOGFILE 331 " | grep lvcreate | tail -n1"); 320 ("tail -n5 " MONDO_LOGFILE " | grep lvcreate | tail -n1"); 332 321 } 333 322 for (p = tmp; *p != '\0' && !isdigit(*p); p++); … … 373 362 mr_msg(0, "%s --> %d", command, res); 374 363 if (!res) { 375 mr_msg(5, "Y AY! This time, it succeeded.");364 mr_msg(5, "Yep! This time, it succeeded."); 376 365 } 377 366 } … … 429 418 int j = 0; 430 419 char *incoming = NULL; 431 char *tmp = NULL;432 420 char *p = NULL; 433 421 size_t n = 0; … … 465 453 mr_getline(&incoming, &n, fin)); 466 454 if (!feof(fin)) { 467 mr_asprintf(&tmp,"Investigating %s",455 log_it("Investigating %s", 468 456 old_mountlist->el[lino].device); 469 log_it(tmp);470 mr_free(tmp);471 472 457 for (mr_getline(&incoming, &n, fin); !feof(fin) 473 458 && !strstr(incoming, "raiddev"); … … 476 461 && !strchr(incoming, '#')) { 477 462 for (p = incoming + strlen(incoming); 478 *(p - 1) <= 32; p--);463 (*(p - 1) <= 32) && (p >= incoming) ; p--); 479 464 *p = '\0'; 480 for (p--; p > incoming && *(p - 1) > 32; p--); 481 mr_asprintf(&tmp, "Extrapolating %s", p); 482 log_it(tmp); 483 mr_free(tmp); 484 465 for (p--; (p >= incoming) && (*(p - 1) > 32); p--); 466 log_it("Extrapolating %s", p); 485 467 for (j = 0; 486 468 j < new_mountlist->entries … … 500 482 new_mountlist->entries++; 501 483 } else { 502 mr_asprintf(&tmp, 503 "Not adding %s to mountlist: it's already there", p); 504 log_it(tmp); 505 mr_free(tmp); 484 log_it("Not adding %s to mountlist: it's already there", p); 506 485 } 507 486 } … … 509 488 } 510 489 mr_free(incoming); 490 511 491 paranoid_fclose(fin); 512 492 } else { … … 534 514 * @return 0 for success, nonzero for failure. 535 515 */ 536 int create_raid_device_via_mdadm(struct raidlist_itself *raidlist, 537 char *device) 516 int create_raid_device_via_mdadm(struct raidlist_itself *raidlist, char *device) 538 517 { 539 518 /** int **************************************************************/ … … 567 546 mr_asprintf(&devices, raidlist->el[i].data_disks.el[0].device); 568 547 for (j = 1; j < raidlist->el[i].data_disks.entries; j++) { 569 mr_asprintf(&strtmp, "%s", devices); 570 mr_free(devices); 571 mr_asprintf(&devices, "%s %s", strtmp, 572 raidlist->el[i].data_disks.el[j].device); 573 mr_free(strtmp); 548 mr_strcat(devices, " %s", raidlist->el[i].data_disks.el[j].device); 574 549 } 575 550 for (j = 0; j < raidlist->el[i].spare_disks.entries; j++) { 576 mr_asprintf(&strtmp, "%s", devices); 577 mr_free(devices); 578 mr_asprintf(&devices, "%s %s", strtmp, 579 raidlist->el[i].spare_disks.el[j].device); 580 mr_free(strtmp); 551 mr_strcat(devices, " %s", raidlist->el[i].spare_disks.el[j].device); 581 552 } 582 553 // translate RAID level … … 597 568 raidlist->el[i].raid_device, level, 598 569 raidlist->el[i].data_disks.entries); 570 mr_free(level); 599 571 if (raidlist->el[i].parity != -1) { 600 asprintf(&strtmp, "%s", program);601 mr_free(program);602 572 switch(raidlist->el[i].parity) { 603 573 case 0: 604 mr_ asprintf(&program, "%s --parity=%s", strtmp, "la");574 mr_strcat(program, " --parity=%s", "la"); 605 575 break; 606 576 case 1: 607 mr_ asprintf(&program, "%s --parity=%s", strtmp, "ra");577 mr_strcat(program, " --parity=%s", "ra"); 608 578 break; 609 579 case 2: 610 mr_ asprintf(&program, "%s --parity=%s", strtmp, "ls");580 mr_strcat(program, " --parity=%s", "ls"); 611 581 break; 612 582 case 3: 613 mr_ asprintf(&program, "%s --parity=%s", strtmp, "rs");583 mr_strcat(program, " --parity=%s", "rs"); 614 584 break; 615 585 default: … … 617 587 break; 618 588 } 619 mr_free(strtmp);620 589 } 621 590 if (raidlist->el[i].chunk_size != -1) { 622 mr_asprintf(&strtmp, "%s", program); 623 mr_free(program); 624 mr_asprintf(&program, "%s --chunk=%d", strtmp, raidlist->el[i].chunk_size); 625 mr_free(strtmp); 591 mr_strcat(program, " --chunk=%d", raidlist->el[i].chunk_size); 626 592 } 627 593 if (raidlist->el[i].spare_disks.entries > 0) { 628 mr_asprintf(&strtmp, "%s", program); 629 mr_free(program); 630 mr_asprintf(&program, "%s --spare-devices=%d", strtmp, 631 raidlist->el[i].spare_disks.entries); 632 mr_free(strtmp); 594 mr_strcat(program, " --spare-devices=%d", raidlist->el[i].spare_disks.entries); 633 595 } 634 mr_asprintf(&strtmp, "%s", program); 635 mr_free(program); 636 mr_asprintf(&program, "%s %s", strtmp, devices); 637 mr_free(strtmp); 596 mr_strcat(program, " %s", devices); 638 597 res = run_program_and_log_output(program, 1); 639 598 // free memory 640 599 mr_free(devices); 641 mr_free(level);642 600 mr_free(program); 643 601 // return to calling instance 644 return res;602 return(res); 645 603 } 646 604 … … 656 614 * @return 0 for success, nonzero for failure. 657 615 */ 658 int format_device(char *device, char *format, 659 struct raidlist_itself *raidlist) 616 int format_device(char *device, char *format, struct raidlist_itself *raidlist) 660 617 { 661 618 /** int **************************************************************/ … … 673 630 char *line = NULL; 674 631 char *status = NULL; 675 FILE *pin ;676 FILE *fin ;632 FILE *pin = NULL; 633 FILE *fin = NULL; 677 634 size_t n = 0; 678 635 size_t n1 = 0; … … 685 642 686 643 if (strstr(format, "raid")) { // do not form RAID disks; do it to /dev/md* instead 687 mr_asprintf(&tmp, "Not formatting %s (it is a RAID disk)", device); 688 log_it(tmp); 689 mr_free(tmp); 644 log_it("Not formatting %s (it is a RAID disk)", device); 690 645 return (0); 691 646 } … … 700 655 "%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", 701 656 device, format); 702 log_it(tmp);703 mr_free(tmp);704 657 return (0); 705 658 } 706 659 if (is_this_device_mounted(device)) { 707 mr_asprintf(&tmp, _("%s is mounted - cannot format it "), device); 708 log_to_screen(tmp); 709 mr_free(tmp); 660 log_to_screen(_("%s is mounted - cannot format it "), device); 710 661 return (1); 711 662 } … … 734 685 735 686 if (vinum_started_yet) { 736 mr_asprintf(&tmp, 737 _ 738 ("Initializing Vinum device %s (this may take a *long* time)"), 687 log_to_screen(_("Initializing Vinum device %s (this may take a *long* time)"), 739 688 device); 740 log_to_screen(tmp);741 mr_free(tmp);742 689 743 690 /* format raid partition */ … … 785 732 } 786 733 mr_free(line); 734 787 735 fclose(fin); 788 736 unlink("/tmp/plexes"); … … 790 738 } 791 739 #else 792 mr_asprintf(&tmp, _("Initializing RAID device %s"), device); 793 log_to_screen(tmp); 794 mr_free(tmp); 795 796 // Shouldn't be necessary. 740 log_to_screen(_("Initializing RAID device %s"), device); 741 742 // Shouldn't be necessary. 797 743 log_to_screen(_("Stopping %s"), device); 798 744 stop_raid_device(device); 799 745 sync(); 800 746 sleep(1); 801 /* BERLIOS: This code is wrong as program has not been initialized802 if (g_fprep) {803 fprintf(g_fprep, "%s\n", program);804 }805 */806 747 807 748 mr_msg(1, "Making %s", device); 808 749 // use mkraid if it exists, otherwise use mdadm 809 if (run_program_and_log_output("which mkraid", FALSE)) { 810 res = create_raid_device_via_mdadm(raidlist, device); 811 mr_msg(1, "Creating RAID device %s via mdadm returned %d", 812 device, res); 750 if (run_program_and_log_output("which mkraid", FALSE)) { 751 res = create_raid_device_via_mdadm(raidlist, device); 752 mr_msg(1, "Creating RAID device %s via mdadm returned %d", device, res); 813 753 } else { 814 754 mr_asprintf(&program, "mkraid --really-force %s", device); … … 830 770 newtResume(); 831 771 } 832 //#ifndef __FreeBSD__833 //#endif834 772 835 773 if (!strcmp(format, "lvm")) { … … 849 787 mr_free(tmp); 850 788 851 mr_asprintf(&tmp, "Formatting %s as %s", device, format);789 mr_asprintf(&tmp, _("Formatting %s as %s"), device, format); 852 790 update_progress_form(tmp); 853 791 854 792 res = run_program_and_log_output(program, FALSE); 855 793 if (res && strstr(program, "kludge")) { 794 mr_free(tmp); 795 mr_asprintf(&tmp, _("Kludge failed; using regular mkfs.%s to format %s"), format, device); 796 mr_free(program); 856 797 #ifdef __FreeBSD__ 857 mr_free(program);858 798 mr_asprintf(&program, "newfs_msdos -F 32 %s", device); 859 799 #else … … 861 801 /* For EFI partitions take fat16 862 802 * as we want to make small ones */ 863 mr_free(program);864 803 mr_asprintf(&program, "mkfs -t %s -F 16 %s", format, device); 865 804 #else 866 mr_free(program);867 805 mr_asprintf(&program, "mkfs -t %s -F 32 %s", format, device); 868 806 #endif … … 877 815 retval += res; 878 816 if (retval) { 879 mr_ asprintf(&tmp1, "%s%s",tmp, _("...failed"));817 mr_strcat(tmp, _("...failed")); 880 818 } else { 881 mr_asprintf(&tmp1, "%s%s",tmp, _("...OK")); 882 } 819 mr_strcat(tmp, _("...OK")); 820 } 821 log_to_screen(tmp); 883 822 mr_free(tmp); 884 823 885 log_to_screen(tmp1);886 mr_free(tmp1);887 824 sync(); 888 825 sleep(1); … … 902 839 /** int **************************************************************/ 903 840 int retval = 0; 904 int lino; 905 int res; 906 // int i; 907 // struct list_of_disks *drivelist; 841 int lino = 0; 842 int res = 0; 908 843 909 844 /** long *************************************************************/ 910 long progress_step ;845 long progress_step = 0L; 911 846 912 847 /** bools ************************************************************/ 913 bool do_it ;848 bool do_it = FALSE; 914 849 915 850 /** buffers **********************************************************/ 916 char *tmp ;851 char *tmp = NULL; 917 852 918 853 /** pointers *********************************************************/ 919 struct mountlist_line *me ; // mountlist entry854 struct mountlist_line *me = NULL; // mountlist entry 920 855 /** end **************************************************************/ 921 856 922 857 assert(mountlist != NULL); 923 mr_asprintf(&tmp,"format_everything (mountlist, interactively = %s",858 log_it("format_everything (mountlist, interactively = %s", 924 859 (interactively) ? "true" : "false"); 925 log_it(tmp);926 mr_free(tmp);927 928 860 mvaddstr_and_log_it(g_currentY, 0, _("Formatting partitions ")); 929 861 open_progress_form(_("Formatting partitions"), … … 935 867 (mountlist->entries > 936 868 0) ? g_maximum_progress / mountlist->entries : 1; 937 // start soft-raids now (because LVM might depend on them)938 // ...and for simplicity's sake, let's format them at the same time :)869 // start soft-raids now (because LVM might depend on them) 870 // ...and for simplicity's sake, let's format them at the same time :) 939 871 mr_msg(1, "Stopping all RAID devices"); 940 872 stop_all_raid_devices(mountlist); … … 968 900 sync(); 969 901 sleep(2); 970 // This last step is probably necessary971 // log_to_screen("Re-starting software RAIDs...");972 // start_all_raid_devices(mountlist);973 // system("sync"); system("sync"); system("sync");974 // sleep(5);975 // do LVMs now902 // This last step is probably necessary 903 // log_to_screen("Re-starting software RAIDs..."); 904 // start_all_raid_devices(mountlist); 905 // system("sync"); system("sync"); system("sync"); 906 // sleep(5); 907 // do LVMs now 976 908 mr_msg(1, "Creating LVMs"); 977 909 if (does_file_exist("/tmp/i-want-my-lvm")) { … … 995 927 sleep(3); 996 928 } 997 // do regulars at last929 // do regulars at last 998 930 sleep(2); // woo! 999 931 mr_msg(1, "Formatting regulars"); … … 1001 933 me = &mountlist->el[lino]; // the current mountlist entry 1002 934 if (!strcmp(me->mountpoint, "image")) { 1003 mr_asprintf(&tmp, "Not formatting %s - it's an image", me->device); 1004 log_it(tmp); 1005 mr_free(tmp); 935 log_it("Not formatting %s - it's an image", me->device); 1006 936 } else if (!strcmp(me->format, "raid")) { 1007 mr_asprintf(&tmp, "Not formatting %s - it's a raid-let", 1008 me->device); 1009 log_it(tmp); 1010 mr_free(tmp); 937 log_it("Not formatting %s - it's a raid-let", me->device); 1011 938 continue; 1012 939 } else if (!strcmp(me->format, "lvm")) { 1013 mr_asprintf(&tmp, "Not formatting %s - it's an LVM", me->device); 1014 log_it(tmp); 1015 mr_free(tmp); 940 log_it("Not formatting %s - it's an LVM", me->device); 1016 941 continue; 1017 942 } else if (!strncmp(me->device, "/dev/md", 7)) { 1018 mr_asprintf(&tmp, "Already formatted %s - it's a soft-RAID dev", 1019 me->device); 1020 log_it(tmp); 1021 mr_free(tmp); 943 log_it("Already formatted %s - it's a soft-RAID dev", me->device); 1022 944 continue; 1023 945 } else if (!does_file_exist(me->device) 1024 946 && strncmp(me->device, "/dev/hd", 7) 1025 947 && strncmp(me->device, "/dev/sd", 7)) { 1026 mr_asprintf(&tmp, 1027 "Not formatting %s yet - doesn't exist - probably an LVM", 1028 me->device); 1029 log_it(tmp); 1030 mr_free(tmp); 948 log_it("Not formatting %s yet - doesn't exist - probably an LVM", me->device); 1031 949 continue; 1032 950 } else { … … 1066 984 } 1067 985 1068 mr_asprintf(&tmp,"format_everything () - %s",986 log_it("format_everything () - %s", 1069 987 (retval) ? "failed!" : "finished successfully"); 1070 log_it(tmp);1071 mr_free(tmp);1072 988 1073 989 if (g_partition_table_locked_up > 0) { … … 1120 1036 { 1121 1037 /** int **************************************************************/ 1122 int current_devno ;1123 int previous_devno ;1038 int current_devno = 0; 1039 int previous_devno = 0; 1124 1040 int retval = 0; 1125 int res; 1126 1127 /** buffers **********************************************************/ 1128 char *tmp; 1041 int res = 0; 1129 1042 1130 1043 /** end **************************************************************/ … … 1133 1046 1134 1047 if (devno_we_must_allow_for >= 5) { 1135 mr_asprintf(&tmp, "Making dummy primary %s%d", drivename, 1); 1136 log_it(tmp); 1137 mr_free(tmp); 1138 1048 log_it("Making dummy primary %s%d", drivename, 1); 1139 1049 g_maximum_progress++; 1140 1050 res = … … 1149 1059 } 1150 1060 for (; current_devno < devno_we_must_allow_for; current_devno++) { 1151 mr_asprintf(&tmp, "Creating dummy partition %s%d", drivename, 1152 current_devno); 1153 log_it(tmp); 1154 mr_free(tmp); 1155 1061 log_it("Creating dummy partition %s%d", drivename, current_devno); 1156 1062 g_maximum_progress++; 1157 1063 res = … … 1293 1199 { 1294 1200 static struct disklabel loclab; 1295 struct partition *dp ;1296 char *lnamebuf ;1201 struct partition *dp = NULL; 1202 char *lnamebuf = NULL; 1297 1203 int f; 1298 1204 u_int secsize, u; … … 1376 1282 char *drivename, struct disklabel *ret) 1377 1283 { 1378 char *subdev_str ;1379 char *command ;1380 struct disklabel *lp ;1284 char *subdev_str = NULL; 1285 char *command = NULL; 1286 struct disklabel *lp = NULL; 1381 1287 int i, lo = 0; 1382 1288 int retval = 0; 1383 char c ;1384 FILE *ftmp ;1289 char c = ' '; 1290 FILE *ftmp = NULL; 1385 1291 1386 1292 lp = get_virgin_disklabel(drivename); … … 1493 1399 assert_string_is_neither_NULL_nor_zerolength(drivename); 1494 1400 1495 mr_asprintf(&tmp, "Partitioning drive %s", drivename); 1496 log_it(tmp); 1497 mr_free(tmp); 1401 log_it("Partitioning drive %s", drivename); 1498 1402 1499 1403 #if __FreeBSD__ … … 1523 1427 // then see if the user has picked 'dangerously-dedicated' mode. 1524 1428 // If so, then we just call label_drive_or_slice() and return. 1525 char c ;1526 char *command ;1429 char c = ' '; 1430 char *command = NULL; 1527 1431 1528 1432 if (current_devno == 1) { … … 1593 1497 file = open(drivename, O_WRONLY); 1594 1498 if (!file) { 1595 mr_asprintf(&tmp, 1596 _("Warning - unable to open %s for wiping it's partition table"), 1597 drivename); 1598 log_to_screen(tmp); 1599 mr_free(tmp); 1499 log_to_screen(_("Warning - unable to open %s for wiping it's partition table"), drivename); 1600 1500 } 1601 1501 1602 1502 for (i = 0; i < 512; i++) { 1603 1503 if (!write(file, "\0", 1)) { 1604 mr_asprintf(&tmp, _("Warning - unable to write to %s"), 1605 drivename); 1606 log_to_screen(tmp); 1607 mr_free(tmp); 1504 log_to_screen(_("Warning - unable to write to %s"), drivename); 1608 1505 } 1609 1506 } … … 1625 1522 if (!fbsd_part) { 1626 1523 #endif 1627 1524 mr_free(format); 1628 1525 mr_asprintf(&format, mountlist->el[lino].format); 1629 1526 partsize = mountlist->el[lino].size; … … 1633 1530 #endif 1634 1531 1532 #ifndef __IA64__ 1635 1533 if (current_devno == 5 && previous_devno == 4) { 1636 1534 log_to_screen … … 1641 1539 return (1); 1642 1540 } 1541 #endif 1643 1542 1644 1543 retval += … … 1716 1615 1717 1616 /** buffers **********************************************************/ 1718 char *program ;1719 char *partition_name ;1720 char *tmp ;1721 char *output ;1617 char *program = NULL; 1618 char *partition_name = NULL; 1619 char *tmp = NULL; 1620 char *output = NULL; 1722 1621 1723 1622 /** pointers **********************************************************/ 1724 char *p ;1725 char *part_table_fmt ;1726 FILE *fout ;1623 char *p = NULL; 1624 char *part_table_fmt = NULL; 1625 FILE *fout = NULL; 1727 1626 1728 1627 /** end ***************************************************************/ … … 1735 1634 1736 1635 if (!strncmp(drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) { 1737 mr_asprintf(&tmp, "Not partitioning %s - it is a virtual drive", drive); 1738 log_it(tmp); 1739 mr_free(tmp); 1636 log_it("Not partitioning %s - it is a virtual drive", drive); 1740 1637 return (0); 1741 1638 } … … 1752 1649 1753 1650 if (is_this_device_mounted(partition_name)) { 1754 mr_asprintf(&tmp, _("%s is mounted, and should not be partitioned"),1651 log_to_screen("%s is mounted, and should not be partitioned", 1755 1652 partition_name); 1756 1653 mr_free(partition_name); 1757 1758 log_to_screen(tmp);1759 mr_free(tmp);1760 1654 return (1); 1761 1655 } 1762 1656 1763 1657 p = (char *) strrchr(partition_name, '/'); 1764 mr_asprintf(&program, "parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE,1765 MONDO_LOGFILE);1766 1658 1767 1659 /* BERLIOS: should not be called each time */ … … 1779 1671 ("You need to leave at least one partition free, for 'extended/logical'")); 1780 1672 mr_free(partition_name); 1781 mr_free(program);1782 1783 mr_free(output);1784 1673 return (1); 1785 1674 } else { … … 1787 1676 } 1788 1677 } 1789 mr_asprintf(&tmp,"%sn\nl\n",output); 1790 mr_free(output); 1791 output = tmp; 1678 mr_strcat(output, "n\nl\n"); 1792 1679 } else { 1793 1680 /* GPT allows more than 4 primary partitions */ … … 1797 1684 mr_free(part_table_fmt); 1798 1685 /*start block (ENTER for next free blk */ 1799 mr_asprintf(&tmp,"%s\n",output); 1800 mr_free(output); 1801 output = tmp; 1802 1686 mr_strcat(output, "\n"); 1803 1687 if (partsize > 0) { 1804 1688 if (!strcmp(format, "7")) { … … 1806 1690 partsize += 512; 1807 1691 } 1808 mr_asprintf(&tmp,"%s+%lldK", output, (long long) (partsize)); 1809 mr_free(output); 1810 output = tmp; 1811 } 1812 mr_asprintf(&tmp,"%s\n",output); 1813 mr_free(output); 1814 output = tmp; 1692 mr_strcat(output, "+%lldK", (long long) (partsize)); 1693 } 1694 mr_strcat(output, "\n"); 1815 1695 #if 0 1816 1696 /* 1817 1697 #endif 1818 mr_asprintf(&tmp,"PARTSIZE = +%ld",(long)partsize); 1819 log_it(tmp); 1820 mr_free(tmp); 1821 1698 log_it("PARTSIZE = +%ld",(long)partsize); 1822 1699 log_it("---fdisk command---"); 1823 1700 log_it(output); … … 1860 1737 } 1861 1738 } else { 1862 mr_ asprintf(&tmp,"%sw\n\n",output);1863 mr_ free(output);1864 output = tmp;1739 mr_strcat(output, "w\n\n"); 1740 mr_asprintf(&program, "parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE, 1741 MONDO_LOGFILE); 1865 1742 1866 1743 if (g_fprep) { … … 1874 1751 paranoid_pclose(fout); 1875 1752 } 1753 mr_free(program); 1754 1876 1755 if (!does_partition_exist(drive, partno) && partsize > 0) { 1877 1756 log_it("Vaccum-packing"); … … 1881 1760 format, -1); 1882 1761 if (res) { 1883 mr_asprintf(&tmp, "Failed to vacuum-pack %s", partition_name); 1884 log_it(tmp); 1885 mr_free(tmp); 1886 1762 log_it("Failed to vacuum-pack %s", partition_name); 1887 1763 retval++; 1888 1764 } else { … … 1895 1771 partsize); 1896 1772 if (retval) { 1897 mr_asprintf(&tmp,"Partitioned %s but failed to set its type",1773 log_it("Partitioned %s but failed to set its type", 1898 1774 partition_name); 1899 log_it(tmp);1900 mr_free(tmp);1901 1775 } else { 1902 1776 if (partsize > 0) { 1903 mr_asprintf(&tmp, "Partition %s created+configured OK",1777 log_to_screen(_("Partition %s created+configured OK"), 1904 1778 partition_name); 1905 log_to_screen(tmp);1906 mr_free(tmp);1907 1779 } else { 1908 1780 log_it("Returning from a successful vacuum-pack"); … … 1923 1795 log_it("partition_device() --- leaving"); 1924 1796 mr_free(partition_name); 1925 mr_free(program);1926 1797 mr_free(output); 1927 1798 return (retval); … … 1939 1810 { 1940 1811 /** int ************************************************************/ 1941 int lino ;1812 int lino = 0; 1942 1813 int retval = 0; 1943 int i ;1944 int res ;1814 int i = 0; 1815 int res = 0; 1945 1816 1946 1817 /** buffer *********************************************************/ 1947 struct list_of_disks *drivelist; 1948 /* struct mountlist_itself new_mtlist, *mountlist; */ 1818 struct list_of_disks *drivelist = NULL; 1949 1819 1950 1820 /** end ************************************************************/ … … 1955 1825 log_it("partition_everything() --- starting"); 1956 1826 mvaddstr_and_log_it(g_currentY, 0, "Partitioning hard drives "); 1957 /* mountlist=orig_mtlist; */1958 1827 if (mountlist_contains_raid_devices(mountlist)) { 1959 1828 /* mountlist=&new_mtlist; */ … … 1977 1846 stop_all_raid_devices(mountlist); 1978 1847 mr_msg(0, "Done."); 1979 1980 /*1981 if (does_file_exist("/tmp/i-want-my-lvm"))1982 {1983 wipe_MBRs_and_reboot_if_necessary(mountlist); // i.e. if it wasn't done recently1984 }1985 */1986 1848 1987 1849 open_progress_form(_("Partitioning devices"), … … 2010 1872 system("clear"); 2011 1873 newtResume(); 2012 mr_free( (void*)drivelist);1874 mr_free(drivelist); 2013 1875 return (retval); 2014 1876 } 2015 2016 2017 2018 2019 1877 2020 1878 … … 2076 1934 mr_asprintf(&partcode, "8e"); 2077 1935 } else if (format[0] == '\0') { /* LVM physical partition */ 2078 mr_asprintf(&partcode, " %s", "");1936 mr_asprintf(&partcode, ""); 2079 1937 } else if (strlen(format) >= 1 && strlen(format) <= 2) { 2080 1938 mr_asprintf(&partcode, format); … … 2098 1956 mr_msg(1, tmp); 2099 1957 mr_free(tmp); 1958 2100 1959 if (partcode[0] != '\0' && strcmp(partcode, "83")) { /* no need to set type if 83: 83 is default */ 2101 1960 … … 2119 1978 fput_string_one_char_at_a_time(pout_to_fdisk, tmp); 2120 1979 mr_free(tmp); 1980 2121 1981 tmp1 = last_line_of_file(FDISK_LOG); 2122 1982 mr_msg(5, "B - last line = '%s'",tmp1); … … 2170 2030 { 2171 2031 /** int *************************************************************/ 2172 int res ;2032 int res = 0; 2173 2033 int retval = 0; 2174 2034 2175 2035 /** buffers *********************************************************/ 2176 char *program ;2036 char *program = NULL; 2177 2037 2178 2038 /** end *************************************************************/ … … 2187 2047 mr_asprintf(&program, "vinum start -f %s", raid_device); 2188 2048 #else 2189 mr_asprintf(&program, "raidstart %s", raid_device); 2049 // use raidstart if it exists, otherwise use mdadm 2050 if (run_program_and_log_output("which raidstart", FALSE)) { 2051 // BERLIOS: Not sure it's sufficient 2052 mr_asprintf(&program, "mdadm -A %s", raid_device); 2053 } else { 2054 mr_asprintf(&program, "raidstart %s", raid_device); 2055 } 2190 2056 #endif 2191 2057 mr_msg(1, "program = %s", program); … … 2214 2080 { 2215 2081 /** int *************************************************************/ 2216 int res ;2082 int res = 0; 2217 2083 int retval = 0; 2218 2084 2219 2085 /** buffers *********************************************************/ 2220 char *program ;2086 char *program = NULL; 2221 2087 2222 2088 /** end *************************************************************/ … … 2255 2121 int start_all_raid_devices(struct mountlist_itself *mountlist) 2256 2122 { 2257 int i ;2123 int i = 0; 2258 2124 int retval = 0; 2259 int res ;2125 int res = 0; 2260 2126 2261 2127 for (i = 0; i < mountlist->entries; i++) { … … 2366 2232 /** int *************************************************************/ 2367 2233 int res = 0; 2368 2369 /** buffers *********************************************************/2370 char *tmp;2371 2234 2372 2235 /** end ***************************************************************/ … … 2402 2265 mr_asprintf(&program, "mkfs -t %s -c", format); // -c checks for bad blocks 2403 2266 #endif 2404 mr_asprintf(&tmp,"Unknown format (%s) - assuming '%s' will do", format,2267 log_it("Unknown format (%s) - assuming '%s' will do", format, 2405 2268 program); 2406 log_it(tmp);2407 mr_free(tmp);2408 2269 res = 0; 2409 2270 } … … 2423 2284 { 2424 2285 /** long ************************************************************/ 2425 long original_size_of_drive ;2286 long original_size_of_drive = 0L; 2426 2287 2427 2288 /** int *************************************************************/ 2428 int partno; 2429 2430 /** buffers *********************************************************/ 2431 char *tmp; 2289 int partno = 0; 2432 2290 2433 2291 /** end *************************************************************/ … … 2442 2300 strlen(drive_name)) == 0) { 2443 2301 original_size_of_drive += mountlist->el[partno].size; 2444 } else {2445 mr_asprintf(&tmp, "Skipping %s", mountlist->el[partno].device);2446 // log_to_screen(tmp);2447 mr_free(tmp);2448 2302 } 2449 2303 } … … 2468 2322 char *drive_name) 2469 2323 { 2470 /**buffers **********************************************************/2471 char *tmp;2472 2473 2324 /** int *************************************************************/ 2474 int partno , lastpart;2325 int partno = 0, lastpart = 0; 2475 2326 /** remove driveno, noof_drives stan benoit apr 2002**/ 2476 2327 … … 2478 2329 float factor; 2479 2330 float new_size; 2480 // float newcylinderno;2481 2331 2482 2332 /** long *************************************************************/ 2483 long newsizL ;2484 long current_size_of_drive = 0 ;2485 long original_size_of_drive = 0 ;2486 long final_size ; /* all in Megabytes */2487 struct mountlist_reference *drivemntlist ;2333 long newsizL = 0L; 2334 long current_size_of_drive = 0L; 2335 long original_size_of_drive = 0L; 2336 long final_size = 0L; /* all in Megabytes */ 2337 struct mountlist_reference *drivemntlist = NULL; 2488 2338 2489 2339 /** structures *******************************************************/ … … 2507 2357 return; 2508 2358 } 2509 mr_asprintf(&tmp, _("Expanding entries to suit drive %s (%ld MB)"), 2510 drive_name, current_size_of_drive); 2511 log_to_screen(tmp); 2512 mr_free(tmp); 2359 log_to_screen("Expanding entries to suit drive %s (%ld MB)", drive_name, 2360 current_size_of_drive); 2513 2361 2514 2362 drivemntlist = mr_malloc(sizeof(struct mountlist_reference)); … … 2524 2372 2525 2373 if (original_size_of_drive <= 0) { 2526 mr_asprintf(&tmp,_("Cannot resize %s's entries. Drive not found."),2374 log_to_screen(_("Cannot resize %s's entries. Drive not found."), 2527 2375 drive_name); 2528 log_to_screen(tmp);2529 mr_free(tmp);2530 2376 return; 2531 2377 } 2532 2378 factor = 2533 2379 (float) (current_size_of_drive) / (float) (original_size_of_drive); 2534 mr_asprintf(&tmp, "Disk %s was %ld MB; is now %ld MB; factor = %f",2380 log_to_screen(_("Disk %s was %ld MB; is now %ld MB; factor = %f"), 2535 2381 drive_name, original_size_of_drive, current_size_of_drive, 2536 2382 factor); 2537 log_to_screen(tmp);2538 mr_free(tmp);2539 2383 2540 2384 lastpart = drivemntlist->entries - 1; … … 2555 2399 newsizL = (long) new_size; 2556 2400 } 2557 mr_asprintf(&tmp,_("Changing %s from %lld KB to %ld KB"),2401 log_to_screen(_("Changing %s from %lld KB to %ld KB"), 2558 2402 drivemntlist->el[partno]->device, 2559 2403 drivemntlist->el[partno]->size, newsizL); 2560 log_to_screen(tmp);2561 mr_free(tmp);2562 2404 drivemntlist->el[partno]->size = newsizL; 2563 2405 } 2564 2406 final_size = get_phys_size_of_drive(drive_name); 2565 mr_asprintf(&tmp, _("final_size = %ld MB"), final_size); 2566 log_to_screen(tmp); 2567 mr_free(tmp); 2407 log_to_screen(_("final_size = %ld MB"), final_size); 2568 2408 } 2569 2409 … … 2579 2419 { 2580 2420 /** buffers *********************************************************/ 2581 struct list_of_disks *drivelist ;2421 struct list_of_disks *drivelist = NULL; 2582 2422 2583 2423 /** int *************************************************************/ 2584 int driveno ;2424 int driveno = 0; 2585 2425 2586 2426 /** end *************************************************************/ … … 2592 2432 ("resize_mountlist_prop...() - warning - mountlist fname is blank"); 2593 2433 log_it("That does NOT affect the functioning of this subroutine."); 2594 log_it("--- Hugo, 2002/11/20");2595 2434 } 2596 2435 iamhere("Resizing mountlist"); … … 2604 2443 } 2605 2444 log_to_screen(_("Mountlist adjusted to suit current hard drive(s)")); 2606 mr_free( (void*)drivelist);2445 mr_free(drivelist); 2607 2446 } 2608 2447 … … 2619 2458 struct mountlist_reference *drivemntlist) 2620 2459 { 2621 int partno ;2622 char *tmp_drive_name , *c;2460 int partno = 0; 2461 char *tmp_drive_name = NULL, *c = NULL; 2623 2462 2624 2463 assert(mountlist != NULL); … … 2628 2467 mr_msg(1, "Creating list of partitions for drive %s", drive_name); 2629 2468 2630 mr_asprintf(&tmp_drive_name,drive_name); 2631 if (!tmp_drive_name) 2632 fatal_error("Out of memory"); 2469 mr_asprintf(&tmp_drive_name, drive_name); 2633 2470 2634 2471 /* devfs devices? */
Note:
See TracChangeset
for help on using the changeset viewer.