Changeset 2204 in MondoRescue for branches/2.2.9/mondo/src/common
- Timestamp:
- May 13, 2009, 12:26:33 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mondo/src/common/libmondo-mountlist.c
r2202 r2204 357 357 358 358 /*@ pointers ******************************************************* */ 359 char *part_table_fmt ;359 char *part_table_fmt = NULL; 360 360 361 361 /*@ initialize ***************************************************** */ … … 490 490 491 491 492 493 492 /** 494 493 * Evaluate a whole mountlist for flaws. Calls evaluate_drive_within_mountlist() … … 565 564 /*@ int ************************************************************** */ 566 565 int i = 0; 567 char *tmp;568 char *flaws_str;569 570 malloc_string(tmp);571 malloc_string(flaws_str);572 566 573 567 assert(mountlist != NULL); … … 577 571 && strcmp(mountlist->el[i].device, device) != 0; i++); 578 572 579 paranoid_free(tmp);580 paranoid_free(flaws_str);581 582 573 if (i == mountlist->entries) { 583 574 return (-1); … … 586 577 } 587 578 } 588 589 590 591 579 592 580 … … 610 598 611 599 /*@ buffetr ********************************************************* */ 612 char *curr_mountpoint; 613 char *tmp; 614 615 malloc_string(curr_mountpoint); 616 malloc_string(tmp); 600 char *curr_mountpoint = NULL; 601 char *tmp = NULL; 602 617 603 assert(mountlist != NULL); 618 604 assert(flaws_str != NULL); 605 619 606 for (currline = 0; currline < mountlist->entries; currline++) { 620 strcpy(curr_mountpoint, mountlist->el[currline].mountpoint);607 asprintf(&curr_mountpoint, "%s", mountlist->el[currline].mountpoint); 621 608 for (i = 0, copies = 0, last_copy = -1; i < mountlist->entries; 622 609 i++) { … … 630 617 if (copies > 1 && last_copy == currline 631 618 && strcmp(curr_mountpoint, "raid")) { 632 sprintf(tmp, " %s %s's.", number_to_text(copies),619 asprintf(&tmp, " %s %s's.", number_to_text(copies), 633 620 curr_mountpoint); 634 621 strcat(flaws_str, tmp); 635 622 log_it(tmp); 623 paranoid_free(tmp); 636 624 res++; 637 625 } 638 } 639 paranoid_free(curr_mountpoint); 640 paranoid_free(tmp); 626 paranoid_free(curr_mountpoint); 627 } 641 628 return (res); 642 629 } … … 660 647 661 648 /*@ buffers ********************************************************* */ 662 char *drive; 663 char *tmp; 649 char *drive = NULL; 664 650 665 651 long long size; 666 652 667 malloc_string(drive);668 malloc_string(tmp);669 653 assert(mountlist != NULL); 670 654 assert(drivelist != NULL); … … 672 656 for (lino = 0, noof_drives = 0; lino < mountlist->entries; lino++) { 673 657 674 strcpy(drive, mountlist->el[lino].device);658 asprintf(&drive, "%s", mountlist->el[lino].device); 675 659 if (!strncmp(drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) { 676 sprintf(tmp, 677 "Not putting %s in list of drives: it's a virtual drive", 660 log_msg(8, "Not putting %s in list of drives: it's a virtual drive", 678 661 drive); 679 log_msg(8, tmp);680 662 continue; 681 663 } … … 683 665 size = mountlist->el[lino].size; 684 666 if (size == 0) { 685 sprintf(tmp,667 log_msg(8, 686 668 "Not putting %s in list of drives: it has zero size (maybe an LVM volume)", 687 669 drive); 688 log_msg(8, tmp);689 670 continue; 690 671 } 691 672 692 sprintf(tmp, 693 "Putting %s with size %lli in list of drives", 673 log_msg(8, "Putting %s with size %lli in list of drives", 694 674 drive, size); 695 log_msg(8, tmp);696 675 697 676 (void) truncate_to_drive_name(drive); … … 706 685 drivelist->entries = noof_drives; 707 686 log_msg(8, "Made list of drives"); 708 paranoid_free(drive);709 paranoid_free(tmp);710 687 711 688 return (noof_drives); 712 689 } 713 714 715 716 717 690 718 691 … … 738 711 739 712 /*@ buffers ********************************************************* */ 740 char *tmp; 741 742 malloc_string(tmp); 713 char *tmp = NULL; 714 743 715 assert(output_list != NULL); 744 716 assert(mountlist != NULL); … … 758 730 (void *) &mountlist->el[i], 759 731 sizeof(struct mountlist_line)); 760 sprintf(tmp, 761 "%s is available; user may choose to add it to raid device", 762 output_list->el[items - 1].device); 763 log_it(tmp); 732 asprintf(&tmp, 733 "%s is available; user may choose to add it to raid device", 734 output_list->el[items - 1].device); 735 log_it(tmp); 736 paranoid_free(tmp); 764 737 } 765 738 } … … 767 740 output_list->entries = items; 768 741 log_it("MLUORP -- ending"); 769 paranoid_free(tmp); 770 } 771 772 773 742 } 774 743 775 744 … … 800 769 } 801 770 } 802 803 804 771 805 772 … … 816 783 int load_mountlist(struct mountlist_itself *mountlist, char *fname) 817 784 { 818 FILE *fin ;785 FILE *fin = NULL; 819 786 /* malloc ** */ 820 char *incoming; 821 char *siz; 822 char *tmp; 823 char *p; 824 825 int items; 826 int j; 787 char *incoming = NULL; 788 char *siz = NULL; 789 char *tmp = NULL; 790 char *p = NULL; 791 792 int items = 0; 793 int j = 0; 794 int res = 0; 827 795 828 796 assert(mountlist != NULL); 829 797 assert_string_is_neither_NULL_nor_zerolength(fname); 830 malloc_string(incoming); 831 malloc_string(siz); 832 malloc_string(tmp); 798 833 799 if (!(fin = fopen(fname, "r"))) { 834 800 log_it("Unable to open mountlist - '%s'", fname); 835 801 log_to_screen("Cannot open mountlist"); 836 paranoid_free(incoming);837 paranoid_free(siz);838 paranoid_free(tmp);839 802 return (1); 840 803 } 841 items = 0; 804 malloc_string(incoming); 805 malloc_string(siz); 842 806 (void) fgets(incoming, MAX_STR_LEN - 1, fin); 843 807 log_it("Loading mountlist..."); 844 808 while (!feof(fin)) { 845 809 #if linux 846 sscanf(incoming,810 res = sscanf(incoming, 847 811 "%s %s %s %s %s", 848 812 mountlist->el[items].device, … … 850 814 mountlist->el[items].format, 851 815 siz, mountlist->el[items].label); 816 if (res < 5) { 817 /* no label found */ 818 asprintf(&(mountlist->el[items].label), "%s", ""); 819 } 852 820 #elif __FreeBSD__ 853 sscanf(incoming,821 res = sscanf(incoming, 854 822 "%s %s %s %s", 855 823 mountlist->el[items].device, 856 824 mountlist->el[items].mountpoint, 857 825 mountlist->el[items].format, siz); 858 strcpy(mountlist->el[items].label, "");826 asprintf(&(mountlist->el[items].label), "%s", ""); 859 827 #endif 860 828 … … 885 853 if (j < items) { 886 854 strcat(mountlist->el[items].device, "_dup"); 887 sprintf(tmp, 888 "Duplicate entry in mountlist - renaming to %s", 889 mountlist->el[items].device); 890 log_it(tmp); 891 } 892 strcpy(tmp, mountlist->el[items].device); 855 asprintf(&tmp, 856 "Duplicate entry in mountlist - renaming to %s", 857 mountlist->el[items].device); 858 log_it(tmp); 859 paranoid_free(tmp); 860 } 861 asprintf(&tmp, "%s", mountlist->el[items].device); 893 862 if (strstr(tmp, "/dev/md/")) { 894 863 log_it("format_device() --- Contracting %s", tmp); … … 903 872 strcpy(mountlist->el[items].device, tmp); 904 873 } 905 906 sprintf(tmp, 907 "%s %s %s %lld %s", 908 mountlist->el[items].device, 909 mountlist->el[items].mountpoint, 910 mountlist->el[items].format, 911 mountlist->el[items].size, 912 mountlist->el[items].label); 913 914 log_it(tmp); 874 paranoid_free(tmp); 875 876 log_it("%s %s %s %lld %s", 877 mountlist->el[items].device, 878 mountlist->el[items].mountpoint, 879 mountlist->el[items].format, 880 mountlist->el[items].size, 881 mountlist->el[items].label); 915 882 items++; 916 883 } … … 921 888 922 889 log_it("Mountlist loaded successfully."); 923 sprintf(tmp,"%d entries in mountlist", items);924 log_it(tmp); 890 log_it("%d entries in mountlist", items); 891 925 892 paranoid_free(incoming); 926 893 paranoid_free(siz); 927 paranoid_free(tmp);928 894 return (0); 929 895 } … … 961 927 return (0); 962 928 } 963 964 929 965 930 … … 989 954 } 990 955 956 991 957 /** 992 958 * Sort the mountlist alphabetically by mountpoint. … … 1028 994 { 1029 995 /*@ mallocs *** */ 1030 char device[64];1031 char mountpoint[256];1032 char format[64];996 char *device = NULL; 997 char *mountpoint = NULL; 998 char *format = NULL; 1033 999 1034 1000 long long size; … … 1038 1004 assert(b >= 0); 1039 1005 1040 strcpy(device, mountlist->el[a].device);1041 strcpy(mountpoint, mountlist->el[a].mountpoint);1042 strcpy(format, mountlist->el[a].format);1006 asprintf(&device, "%s", mountlist->el[a].device); 1007 asprintf(&mountpoint, "%s", mountlist->el[a].mountpoint); 1008 asprintf(&format, "%s", mountlist->el[a].format); 1043 1009 1044 1010 size = mountlist->el[a].size; … … 1055 1021 1056 1022 mountlist->el[b].size = size; 1023 paranoid_free(device); 1024 paranoid_free(mountpoint); 1025 paranoid_free(format); 1057 1026 } 1058 1027
Note:
See TracChangeset
for help on using the changeset viewer.