Changeset 3879 in MondoRescue for branches/3.3/mondo/src/mondorestore/mondo-rstr-mountlist.c
- Timestamp:
- Mar 9, 2024, 3:10:04 AM (3 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mondo/src/mondorestore/mondo-rstr-mountlist.c
r3871 r3879 12 12 #include "mr_mem.h" 13 13 #include "mondostructures.h" 14 #include "libmondo-mountlist.h"15 16 14 #include "libmondo-raid-EXT.h" 17 15 #include "libmondo-devices-EXT.h" … … 535 533 536 534 /** 535 * Make a list of the drives mentioned in the mountlist. 536 * @param mountlist The mountlist to examine. 537 * @param drivelist Where to put the list of drives found. 538 * @return The number of physical (non-RAID non-LVM) drives found, or \<= 0 for error. 539 */ 540 int 541 make_list_of_drives_in_mountlist(struct mountlist_itself *mountlist, 542 struct list_of_disks *drivelist) 543 { 544 545 /*@ int ************************************************************* */ 546 int lino; 547 int noof_drives; 548 int j; 549 550 /*@ buffers ********************************************************* */ 551 char *drive = NULL; 552 char *truncdrive = NULL; 553 554 long long size; 555 556 assert(mountlist != NULL); 557 assert(drivelist != NULL); 558 log_it("Making list of drives"); 559 for (lino = 0, noof_drives = 0; lino < mountlist->entries; lino++) { 560 561 mr_asprintf(drive, "%s", mountlist->el[lino].device); 562 if (!strncmp(drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) { 563 log_msg(8, "Not putting %s in list of drives: it's a virtual drive", drive); 564 mr_free(drive); 565 continue; 566 } 567 568 size = mountlist->el[lino].size; 569 if (size == 0) { 570 log_msg(8, "Not putting %s in list of drives: it has zero size (maybe an LVM volume)", drive); 571 mr_free(drive); 572 continue; 573 } 574 575 log_msg(8, "Putting %s with size %lli in list of drives", drive, size); 576 577 /* memory allocation */ 578 truncdrive = truncate_to_drive_name(drive); 579 mr_free(drive); 580 581 log_msg(8, "drive truncated to %s", truncdrive); 582 583 for (j = 0; 584 j < noof_drives 585 && strcmp(drivelist->el[j].device, truncdrive) != 0; j++) { 586 continue; 587 } 588 if (j == noof_drives) { 589 strncpy(drivelist->el[noof_drives].device, truncdrive, 63); 590 drivelist->el[noof_drives].device[63] = '\0'; 591 log_msg(8,"Adding drive %s to list", drivelist->el[noof_drives].device); 592 noof_drives++; 593 } 594 paranoid_free(truncdrive); 595 if (noof_drives >= MAXIMUM_DISKS_PER_RAID_DEV) { 596 log_msg(0, "Unable to handle mountlist with more than %d lines", MAXIMUM_DISKS_PER_RAID_DEV); 597 log_to_screen("Unable to handle a so big mountlist"); 598 finish(1); 599 } 600 } 601 drivelist->entries = noof_drives; 602 log_msg(8, "Made list of %d drives",noof_drives); 603 604 return (noof_drives); 605 } 606 607 608 /** 537 609 * Evaluate a whole mountlist for flaws. Calls evaluate_drive_within_mountlist() 538 610 * for each drive, and then spreads the flaws across three lines. … … 642 714 return (i); 643 715 } 644 }645 646 647 /**648 * Make a list of the drives mentioned in the mountlist.649 * @param mountlist The mountlist to examine.650 * @param drivelist Where to put the list of drives found.651 * @return The number of physical (non-RAID non-LVM) drives found, or \<= 0 for error.652 */653 int654 make_list_of_drives_in_mountlist(struct mountlist_itself *mountlist,655 struct list_of_disks *drivelist)656 {657 658 /*@ int ************************************************************* */659 int lino;660 int noof_drives;661 int j;662 663 /*@ buffers ********************************************************* */664 char *drive = NULL;665 char *truncdrive = NULL;666 667 long long size;668 669 assert(mountlist != NULL);670 assert(drivelist != NULL);671 log_it("Making list of drives");672 for (lino = 0, noof_drives = 0; lino < mountlist->entries; lino++) {673 674 mr_asprintf(drive, "%s", mountlist->el[lino].device);675 if (!strncmp(drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) {676 log_msg(8, "Not putting %s in list of drives: it's a virtual drive", drive);677 mr_free(drive);678 continue;679 }680 681 size = mountlist->el[lino].size;682 if (size == 0) {683 log_msg(8, "Not putting %s in list of drives: it has zero size (maybe an LVM volume)", drive);684 mr_free(drive);685 continue;686 }687 688 log_msg(8, "Putting %s with size %lli in list of drives", drive, size);689 690 /* memory allocation */691 truncdrive = truncate_to_drive_name(drive);692 mr_free(drive);693 694 log_msg(8, "drive truncated to %s", truncdrive);695 696 for (j = 0;697 j < noof_drives698 && strcmp(drivelist->el[j].device, truncdrive) != 0; j++) {699 continue;700 }701 if (j == noof_drives) {702 strncpy(drivelist->el[noof_drives].device, truncdrive, 63);703 drivelist->el[noof_drives].device[63] = '\0';704 log_msg(8,"Adding drive %s to list", drivelist->el[noof_drives].device);705 noof_drives++;706 }707 paranoid_free(truncdrive);708 if (noof_drives >= MAXIMUM_DISKS_PER_RAID_DEV) {709 log_msg(0, "Unable to handle mountlist with more than %d lines", MAXIMUM_DISKS_PER_RAID_DEV);710 log_to_screen("Unable to handle a so big mountlist");711 finish(1);712 }713 }714 drivelist->entries = noof_drives;715 log_msg(8, "Made list of %d drives",noof_drives);716 717 return (noof_drives);718 716 } 719 717 … … 938 936 939 937 /** 938 * Swap two entries in the mountlist in-place. 939 * @param mountlist The mountlist to swap the entries in. 940 * @param a The index number of the first entry. 941 * @param b The index number of the second entry. 942 */ 943 void 944 swap_mountlist_entries(struct mountlist_itself *mountlist, int a, int b) 945 { 946 /*@ mallocs *** */ 947 char *device = NULL; 948 char *mountpoint = NULL; 949 char *format = NULL; 950 951 long long size; 952 953 assert(mountlist != NULL); 954 assert(a >= 0); 955 assert(b >= 0); 956 957 mr_asprintf(device, "%s", mountlist->el[a].device); 958 mr_asprintf(mountpoint, "%s", mountlist->el[a].mountpoint); 959 mr_asprintf(format, "%s", mountlist->el[a].format); 960 961 size = mountlist->el[a].size; 962 963 strcpy(mountlist->el[a].device, mountlist->el[b].device); 964 strcpy(mountlist->el[a].mountpoint, mountlist->el[b].mountpoint); 965 strcpy(mountlist->el[a].format, mountlist->el[b].format); 966 967 mountlist->el[a].size = mountlist->el[b].size; 968 969 strcpy(mountlist->el[b].device, device); 970 strcpy(mountlist->el[b].mountpoint, mountpoint); 971 strcpy(mountlist->el[b].format, format); 972 973 mountlist->el[b].size = size; 974 mr_free(device); 975 mr_free(mountpoint); 976 mr_free(format); 977 } 978 979 980 981 /** 940 982 * Sort the mountlist alphabetically by device. 941 983 * The sorting is done in-place. … … 991 1033 } 992 1034 993 994 /**995 * Swap two entries in the mountlist in-place.996 * @param mountlist The mountlist to swap the entries in.997 * @param a The index number of the first entry.998 * @param b The index number of the second entry.999 */1000 void1001 swap_mountlist_entries(struct mountlist_itself *mountlist, int a, int b)1002 {1003 /*@ mallocs *** */1004 char *device = NULL;1005 char *mountpoint = NULL;1006 char *format = NULL;1007 1008 long long size;1009 1010 assert(mountlist != NULL);1011 assert(a >= 0);1012 assert(b >= 0);1013 1014 mr_asprintf(device, "%s", mountlist->el[a].device);1015 mr_asprintf(mountpoint, "%s", mountlist->el[a].mountpoint);1016 mr_asprintf(format, "%s", mountlist->el[a].format);1017 1018 size = mountlist->el[a].size;1019 1020 strcpy(mountlist->el[a].device, mountlist->el[b].device);1021 strcpy(mountlist->el[a].mountpoint, mountlist->el[b].mountpoint);1022 strcpy(mountlist->el[a].format, mountlist->el[b].format);1023 1024 mountlist->el[a].size = mountlist->el[b].size;1025 1026 strcpy(mountlist->el[b].device, device);1027 strcpy(mountlist->el[b].mountpoint, mountpoint);1028 strcpy(mountlist->el[b].format, format);1029 1030 mountlist->el[b].size = size;1031 mr_free(device);1032 mr_free(mountpoint);1033 mr_free(format);1034 }1035 1036 1035 /* @} - end of mountlistGroup */
Note:
See TracChangeset
for help on using the changeset viewer.