Changeset 3188 in MondoRescue for branches/3.0/mondo/src/common/libmondo-raid.c
- Timestamp:
- Sep 25, 2013, 8:55:39 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.0/mondo/src/common/libmondo-raid.c
r3185 r3188 335 335 #ifdef __FreeBSD__ 336 336 int i, j; 337 char *org = NULL; 337 338 338 339 fprintf(fout, "\nvolume %s\n", raidrec->volname); 339 340 for (i = 0; i < raidrec->plexes; ++i) { 340 char org[24];341 341 switch (raidrec->plex[i].raidlevel) { 342 342 case -1: 343 strcpy(org, "concat");343 mr_asprintf(org, "concat"); 344 344 break; 345 345 case 0: 346 strcpy(org, "striped");346 mr_asprintf(org, "striped"); 347 347 break; 348 348 case 5: 349 strcpy(org, "raid5");349 mr_asprintf(org, "raid5"); 350 350 break; 351 351 } 352 352 fprintf(fout, " plex org %s", org); 353 mr_free(org); 354 353 355 if (raidrec->plex[i].raidlevel != -1) { 354 356 fprintf(fout, " %ik", raidrec->plex[i].stripesize); … … 357 359 358 360 for (j = 0; j < raidrec->plex[i].subdisks; ++j) { 359 fprintf(fout, " sd drive %s size 0\n", 360 raidrec->plex[i].sd[j].which_device); 361 fprintf(fout, " sd drive %s size 0\n", raidrec->plex[i].sd[j].which_device); 361 362 } 362 363 } … … 427 428 int get_next_raidtab_line(FILE * fin, char *label, char *value) 428 429 { 429 char *incoming ;430 char *incoming = NULL; 430 431 char *p; 431 char *q; 432 433 malloc_string(incoming); 432 434 433 assert(fin != NULL); 435 434 assert(label != NULL); … … 438 437 label[0] = value[0] = '\0'; 439 438 if (feof(fin)) { 440 paranoid_free(incoming);441 439 return (1); 442 440 } 443 for (q = fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin) && (q != NULL); 444 q = fgets(incoming, MAX_STR_LEN - 1, fin)) { 445 strip_spaces(incoming); 441 for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) { 442 mr_strip_spaces(incoming); 446 443 p = strchr(incoming, ' '); 447 444 if (strlen(incoming) < 3 || incoming[0] == '#' || !p) { 445 mr_free(incoming); 448 446 continue; 449 447 } … … 454 452 strcpy(label, incoming); 455 453 strcpy(value, p); 456 paranoid_free(incoming);454 mr_free(incoming); 457 455 return (0); 458 456 } 457 mr_free(incoming); 459 458 return (1); 460 459 } … … 473 472 { 474 473 FILE *fin; 475 char *tmp1 = NULL;476 474 int items; 477 475 … … 504 502 505 503 if (get_option_state(argc, argv, "hotspare")) { 506 strcpy(raidlist->spares.el[raidlist->spares.entries].name, 507 drivename); 508 strcpy(raidlist->spares.el[raidlist->spares.entries]. 509 device, devname); 504 strcpy(raidlist->spares.el[raidlist->spares.entries].name, drivename); 505 strcpy(raidlist->spares.el[raidlist->spares.entries]. device, devname); 510 506 raidlist->spares.el[raidlist->spares.entries].index = 511 507 raidlist->disks.entries; 512 508 raidlist->spares.entries++; 513 509 } else { 514 strcpy(raidlist->disks.el[raidlist->disks.entries].name, 515 drivename); 516 strcpy(raidlist->disks.el[raidlist->disks.entries].device, 517 devname); 510 strcpy(raidlist->disks.el[raidlist->disks.entries].name, drivename); 511 strcpy(raidlist->disks.el[raidlist->disks.entries].device, devname); 518 512 raidlist->disks.el[raidlist->disks.entries].index = 519 513 raidlist->disks.entries; … … 587 581 fclose(fin); 588 582 log_it("Raidtab loaded successfully."); 589 mr_asprintf(tmp1, "%d RAID devices in raidtab", raidlist->entries); 590 log_it(tmp1); 591 mr_free(tmp1); 583 log_it("%d RAID devices in raidtab", raidlist->entries); 592 584 return (0); 593 585 } … … 596 588 #else 597 589 598 int load_raidtab_into_raidlist(struct raidlist_itself *raidlist, 599 char *fname) 600 { 601 FILE *fin; 602 char *label; 603 char *value; 590 int load_raidtab_into_raidlist(struct raidlist_itself *raidlist, char *fname) { 591 592 FILE *fin = NULL; 593 char *label = NULL; 594 char *value = NULL; 604 595 int items; 605 596 int v; … … 680 671 681 672 /*@ add mallocs * */ 682 char *tmp = NULL;683 673 char *labelB; 684 674 char *valueB; … … 739 729 } 740 730 if (!disklist) { 741 mr_asprintf(tmp, "Ignoring '%s %s' pair of disk %s", labelB, valueB, label); 742 log_it(tmp); 743 mr_free(tmp); 731 log_it("Ignoring '%s %s' pair of disk %s", labelB, valueB, label); 744 732 } else { 745 733 index = atoi(valueB); … … 811 799 static char *argv[64]; 812 800 char **ap; 813 char *q; 814 char *line = (char *) malloc(MAX_STR_LEN); 815 816 if (!line) 817 errx(1, 818 "unable to allocate %i bytes of memory for `char *line' at %s:%i", 819 MAX_STR_LEN, __FILE__, __LINE__); 820 q = fgets(line, MAX_STR_LEN, f); 821 if (feof(f) && (q != NULL)) { 801 char *line = NULL; 802 803 mr_getline(line, f); 804 if (feof(f)) { 822 805 log_it("[GNVCL] Uh... I reached the EOF."); 823 806 return 0; … … 830 813 cnt++; 831 814 } 815 mr_free(line); 832 816 833 817 if (strchr(argv[cnt - 1], '\n')) { … … 1119 1103 while((token = mr_strtok (string, delims, &lastpos))) { 1120 1104 if ((pos = strstr(token, "("))) { 1121 1105 type = *(pos+1); 1122 1106 } else { 1123 1107 type = ' '; 1124 1108 } 1125 1109 pos = strstr(token, "["); … … 1127 1111 switch(type) { 1128 1112 case ' ': // normal data disks 1129 1130 1131 1132 1133 1134 1113 raidlist->el[raidlist->entries].data_disks.el[raidlist->el[raidlist->entries].data_disks.entries].index = atoi(pos + 1); 1114 mr_asprintf(strtmp,"%s%s", device_prefix, token); 1115 strcpy(raidlist->el[raidlist->entries].data_disks.el[raidlist->el[raidlist->entries].data_disks.entries].device, strtmp); 1116 mr_free(strtmp); 1117 raidlist->el[raidlist->entries].data_disks.entries++; 1118 break; 1135 1119 case 'S': // spare disks 1136 1137 1138 1139 1140 1141 1120 raidlist->el[raidlist->entries].spare_disks.el[raidlist->el[raidlist->entries].spare_disks.entries].index = atoi(pos + 1); 1121 mr_asprintf(strtmp,"%s%s", device_prefix, token); 1122 strcpy(raidlist->el[raidlist->entries].spare_disks.el[raidlist->el[raidlist->entries].spare_disks.entries].device, strtmp); 1123 mr_free(strtmp); 1124 raidlist->el[raidlist->entries].spare_disks.entries++; 1125 break; 1142 1126 case 'F': // failed disks 1143 1144 1145 1146 1147 1148 1149 1127 raidlist->el[raidlist->entries].failed_disks.el[raidlist->el[raidlist->entries].failed_disks.entries].index = atoi(pos + 1); 1128 mr_asprintf(strtmp,"%s%s", device_prefix, token); 1129 strcpy(raidlist->el[raidlist->entries].failed_disks.el[raidlist->el[raidlist->entries].failed_disks.entries].device, strtmp); 1130 mr_free(strtmp); 1131 raidlist->el[raidlist->entries].failed_disks.entries++; 1132 log_it("At least one failed disk found in RAID array.\n"); 1133 break; 1150 1134 default: // error 1151 1152 1153 1154 1155 1135 log_msg(1, "Unknown device type '%c'\n", type); 1136 mr_free(string); 1137 mr_free(token); 1138 return 1; 1139 break; 1156 1140 } 1157 1141 mr_free(token); … … 1162 1146 for (i=0; i<raidlist->el[raidlist->entries].data_disks.entries;i++) { 1163 1147 if (raidlist->el[raidlist->entries].data_disks.el[i].index < index_min) { 1164 1148 index_min = raidlist->el[raidlist->entries].data_disks.el[i].index; 1165 1149 } 1166 1150 } 1167 1151 if (index_min > 0) { 1168 1152 for (i=0; i<raidlist->el[raidlist->entries].data_disks.entries;i++) { 1169 1153 raidlist->el[raidlist->entries].data_disks.el[i].index = raidlist->el[raidlist->entries].data_disks.el[i].index - index_min; 1170 1154 } 1171 1155 } … … 1173 1157 for (i=0; i<raidlist->el[raidlist->entries].spare_disks.entries;i++) { 1174 1158 if (raidlist->el[raidlist->entries].spare_disks.el[i].index < index_min) { 1175 1159 index_min = raidlist->el[raidlist->entries].spare_disks.el[i].index; 1176 1160 } 1177 1161 } 1178 1162 if (index_min > 0) { 1179 1163 for (i=0; i<raidlist->el[raidlist->entries].spare_disks.entries;i++) { 1180 1164 raidlist->el[raidlist->entries].spare_disks.el[i].index = raidlist->el[raidlist->entries].spare_disks.el[i].index - index_min; 1181 1165 } 1182 1166 } … … 1184 1168 for (i=0; i<raidlist->el[raidlist->entries].failed_disks.entries;i++) { 1185 1169 if (raidlist->el[raidlist->entries].failed_disks.el[i].index < index_min) { 1186 1170 index_min = raidlist->el[raidlist->entries].failed_disks.el[i].index; 1187 1171 } 1188 1172 } 1189 1173 if (index_min > 0) { 1190 1174 for (i=0; i<raidlist->el[raidlist->entries].failed_disks.entries;i++) { 1191 1175 raidlist->el[raidlist->entries].failed_disks.el[i].index = raidlist->el[raidlist->entries].failed_disks.el[i].index - index_min; 1192 1176 } 1193 1177 } … … 1205 1189 } else { 1206 1190 while (*pos != ' ') { 1207 1208 1209 1210 1211 1212 1191 pos -= 1; 1192 if (pos < string) { 1193 log_it("String underflow!\n"); 1194 mr_free(string); 1195 return 1; 1196 } 1213 1197 } 1214 1198 raidlist->el[raidlist->entries].chunk_size = atoi(pos + 1); … … 1224 1208 if (!(pos = strchr(string, '\%'))) { 1225 1209 if (strcasestr(string, "delayed")) { 1226 1210 raidlist->el[raidlist->entries].progress = -1; // delayed (therefore, stuck at 0%) 1227 1211 } else { 1228 1212 raidlist->el[raidlist->entries].progress = 999; // not found 1229 1213 } 1230 1214 } else { 1231 1215 while (*pos != ' ') { 1232 1233 1234 1235 1236 1237 1216 pos -= 1; 1217 if (pos < string) { 1218 printf("ERROR: String underflow!\n"); 1219 mr_free(string); 1220 return 1; 1221 } 1238 1222 } 1239 1223 raidlist->el[raidlist->entries].progress = atoi(pos); 1240 1224 } 1241 1225 break; 1242 1226 default: // error or IN PROGRESS 1243 1227 if (raidlist->el[raidlist->entries].progress != -1 && 1244 1228 raidlist->el[raidlist->entries].progress != 999) { … … 1246 1230 } 1247 1231 break; 1248 1249 1232 } 1233 row++; 1250 1234 } 1251 1235 // free string
Note:
See TracChangeset
for help on using the changeset viewer.