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