Changeset 128 in MondoRescue for branches/2.05/mondo/mondo/mondorestore/mondo-prep.c
- Timestamp:
- Nov 19, 2005, 2:27:41 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.05/mondo/mondo/mondorestore/mondo-prep.c
r126 r128 188 188 extern bool g_text_mode; 189 189 190 extern void pause_for_N_seconds(int, char *);191 192 193 FILE *g_fprep =NULL;194 195 196 197 int g_partition_table_locked_up =0;190 extern void pause_for_N_seconds(int, char *); 191 192 193 FILE *g_fprep = NULL; 194 195 196 197 int g_partition_table_locked_up = 0; 198 198 199 199 … … 208 208 void wipe_MBRs_and_reboot_if_necessary(struct mountlist_itself *mountlist) 209 209 { 210 211 212 213 214 FILE*fout;215 216 const int blocksize=512; 217 struct list_of_disks *drivelist=NULL;210 char *command; 211 char *tmp; 212 int lino; 213 int i; 214 FILE *fout; 215 char *buf; 216 const int blocksize = 512; 217 struct list_of_disks *drivelist = NULL; 218 218 // If LVMs are present and a zero-and-reboot wasn't recently undertaken 219 219 // then zero & insist on reboot. 220 221 222 223 if (does_file_exist("/tmp/i-want-my-lvm"))// FIXME - cheating :)224 225 226 227 for (lino = 0; lino < drivelist->entries; lino++)228 {229 sprintf(command, "dd if=%s bs=512 count=1 2> /dev/null | grep \"%s\"", drivelist->el[lino].device, MONDO_WAS_HERE);230 if (!run_program_and_log_output(command, 1))231 232 log_msg(1, "Found MONDO_WAS_HERE marker on drive#%d (%s)", lino, drivelist->el[lino].device);233 break;234 }235 236 237 if (lino==drivelist->entries) 238 220 malloc_string(command); 221 malloc_string(tmp); 222 buf = malloc(blocksize); 223 if (does_file_exist("/tmp/i-want-my-lvm")) // FIXME - cheating :) 224 { 225 drivelist = malloc(sizeof(struct list_of_disks)); 226 make_list_of_drives_in_mountlist(mountlist, drivelist); 227 for (lino = 0; lino < drivelist->entries; lino++) { 228 sprintf(command, 229 "dd if=%s bs=512 count=1 2> /dev/null | grep \"%s\"", 230 drivelist->el[lino].device, MONDO_WAS_HERE); 231 if (!run_program_and_log_output(command, 1)) { 232 log_msg(1, "Found MONDO_WAS_HERE marker on drive#%d (%s)", 233 lino, drivelist->el[lino].device); 234 break; 235 } 236 } 237 238 if (lino == drivelist->entries) { 239 239 // zero & reboot 240 log_to_screen("I am sorry for the inconvenience but I must ask you to reboot."); 241 log_to_screen("I need to reset the Master Boot Record; in order to be"); 242 log_to_screen("sure the kernel notices, I must reboot after doing it."); 243 log_to_screen("Please hit 'Enter' to reboot."); 244 for (lino = 0; lino < drivelist->entries; lino++) 245 { 246 for(i=0;i<blocksize; i++) 247 { buf[i] = 0; } 248 sprintf(buf, "%s\n", MONDO_WAS_HERE); 249 fout = fopen(drivelist->el[lino].device, "w+"); 250 if (!fout) 251 { 252 log_msg(1, "Unable to open+wipe %s", drivelist->el[lino].device); 253 } 254 else 255 { 256 if (1!=fwrite(buf, blocksize, 1, fout)) 257 { 258 log_msg(1, "Failed to wipe %s", drivelist->el[lino].device); 259 } 260 else 261 { 262 log_msg(1, "Successfully wiped %s", drivelist->el[lino].device); 263 } 264 fclose(fout); 265 } 266 } 267 system("sync"); system("sync"); system("sync"); 268 popup_and_OK("I must now reboot. Please leave the boot media in the drive and repeat your actions - e.g. type 'nuke' - and it should work fine."); 269 system("reboot"); 270 } 271 } 272 240 log_to_screen 241 ("I am sorry for the inconvenience but I must ask you to reboot."); 242 log_to_screen 243 ("I need to reset the Master Boot Record; in order to be"); 244 log_to_screen 245 ("sure the kernel notices, I must reboot after doing it."); 246 log_to_screen("Please hit 'Enter' to reboot."); 247 for (lino = 0; lino < drivelist->entries; lino++) { 248 for (i = 0; i < blocksize; i++) { 249 buf[i] = 0; 250 } 251 sprintf(buf, "%s\n", MONDO_WAS_HERE); 252 fout = fopen(drivelist->el[lino].device, "w+"); 253 if (!fout) { 254 log_msg(1, "Unable to open+wipe %s", 255 drivelist->el[lino].device); 256 } else { 257 if (1 != fwrite(buf, blocksize, 1, fout)) { 258 log_msg(1, "Failed to wipe %s", 259 drivelist->el[lino].device); 260 } else { 261 log_msg(1, "Successfully wiped %s", 262 drivelist->el[lino].device); 263 } 264 fclose(fout); 265 } 266 } 267 system("sync"); 268 system("sync"); 269 system("sync"); 270 popup_and_OK 271 ("I must now reboot. Please leave the boot media in the drive and repeat your actions - e.g. type 'nuke' - and it should work fine."); 272 system("reboot"); 273 } 274 } 273 275 // Still here? Cool! 274 275 276 276 paranoid_free(command); 277 paranoid_free(tmp); 278 log_msg(1, "Cool. I didn't have to wipe anything."); 277 279 } 278 280 … … 282 284 283 285 284 int fput_string_one_char_at_a_time(FILE *fout, char*str)286 int fput_string_one_char_at_a_time(FILE * fout, char *str) 285 287 { 286 int i, j; 287 FILE*fq; 288 289 if (ferror(fout)) 290 { 291 return(-1); 292 } 293 log_msg(5, "Writing string '%s', one char at a time", str); 294 j = strlen(str); 295 for(i=0; i<j; i++) 296 { 297 log_msg(6, "Writing %d ('%c')", str[i], str[i]); 298 if ((fq = fopen(FDISK_LOG, "a+"))) { fputc(str[i], fq);fclose(fq); } 299 fputc(str[i], fout); 300 fflush(fout); 301 usleep(1000L*100L); 302 if (str[i]<32) { usleep(1000L*10L); } 303 } 304 log_msg(5, "Returning"); 305 306 return(i); 288 int i, j; 289 FILE *fq; 290 291 if (ferror(fout)) { 292 return (-1); 293 } 294 log_msg(5, "Writing string '%s', one char at a time", str); 295 j = strlen(str); 296 for (i = 0; i < j; i++) { 297 log_msg(6, "Writing %d ('%c')", str[i], str[i]); 298 if ((fq = fopen(FDISK_LOG, "a+"))) { 299 fputc(str[i], fq); 300 fclose(fq); 301 } 302 fputc(str[i], fout); 303 fflush(fout); 304 usleep(1000L * 100L); 305 if (str[i] < 32) { 306 usleep(1000L * 10L); 307 } 308 } 309 log_msg(5, "Returning"); 310 311 return (i); 307 312 } 308 313 … … 325 330 * @return The number of errors encountered (0 for success). 326 331 */ 327 328 329 int do_my_funky_lvm_stuff(bool just_erase_existing_volumes, bool vacuum_pack) 332 333 334 int do_my_funky_lvm_stuff(bool just_erase_existing_volumes, 335 bool vacuum_pack) 330 336 { 331 337 /** buffers **********************************************/ … … 340 346 char *vgchange_sz; 341 347 char *vgremove_sz; 342 // 348 // char *do_this_last; 343 349 344 350 /** char **************************************************/ … … 353 359 long extents; 354 360 fpos_t orig_pos; 355 361 356 362 /** pointers **********************************************/ 357 363 FILE *fin; … … 377 383 malloc_string(vgchange_sz); 378 384 malloc_string(vgremove_sz); 379 // 385 // malloc_string(do_this_last); // postpone lvcreate call if necessary 380 386 command = malloc(512); 381 387 382 // 383 iamhere("STARTING");388 // do_this_last[0] = '\0'; 389 iamhere("STARTING"); 384 390 log_msg(1, "OK, opened i-want-my-lvm. Shutting down LVM volumes..."); 385 if (find_home_of_exe("lvm")) // found it :) cool 386 { 387 strcpy(lvscan_sz, "lvm lvscan"); 388 strcpy(lvremove_sz, "lvm lvremove"); 389 strcpy(vgscan_sz, "lvm vgscan"); 390 strcpy(pvscan_sz, "lvm pvscan"); 391 strcpy(vgcreate_sz, "lvm vgcreate"); 392 strcpy(vgchange_sz, "lvm vgchange"); 393 strcpy(vgremove_sz, "lvm vgremove"); 394 } 395 else 396 { 397 strcpy(lvscan_sz, "lvscan"); 398 strcpy(lvremove_sz, "lvremove"); 399 strcpy(vgscan_sz, "vgscan"); 400 strcpy(pvscan_sz, "pvscan"); 401 strcpy(vgcreate_sz, "vgcreate"); 402 strcpy(vgchange_sz, "vgchange"); 403 strcpy(vgremove_sz, "vgremove"); 404 } 405 sprintf(command, "for i in `%s | cut -d\"'\" -f2 | sort -r` ; do echo \"Shutting down lv $i\" >> " MONDO_LOGFILE "; %s -f $i; done", 406 lvscan_sz, lvremove_sz); 391 if (find_home_of_exe("lvm")) // found it :) cool 392 { 393 strcpy(lvscan_sz, "lvm lvscan"); 394 strcpy(lvremove_sz, "lvm lvremove"); 395 strcpy(vgscan_sz, "lvm vgscan"); 396 strcpy(pvscan_sz, "lvm pvscan"); 397 strcpy(vgcreate_sz, "lvm vgcreate"); 398 strcpy(vgchange_sz, "lvm vgchange"); 399 strcpy(vgremove_sz, "lvm vgremove"); 400 } else { 401 strcpy(lvscan_sz, "lvscan"); 402 strcpy(lvremove_sz, "lvremove"); 403 strcpy(vgscan_sz, "vgscan"); 404 strcpy(pvscan_sz, "pvscan"); 405 strcpy(vgcreate_sz, "vgcreate"); 406 strcpy(vgchange_sz, "vgchange"); 407 strcpy(vgremove_sz, "vgremove"); 408 } 409 sprintf(command, 410 "for i in `%s | cut -d\"'\" -f2 | sort -r` ; do echo \"Shutting down lv $i\" >> " 411 MONDO_LOGFILE "; %s -f $i; done", lvscan_sz, lvremove_sz); 407 412 run_program_and_log_output(command, 5); 408 413 sleep(1); 409 sprintf(command, "for i in `%s | grep -i lvm | cut -d'\"' -f2` ; do %s -a n $i ; %s $i; echo \"Shutting down vg $i\" >> " MONDO_LOGFILE "; done; %s -a n", vgscan_sz, vgchange_sz, vgremove_sz, vgremove_sz); 414 sprintf(command, 415 "for i in `%s | grep -i lvm | cut -d'\"' -f2` ; do %s -a n $i ; %s $i; echo \"Shutting down vg $i\" >> " 416 MONDO_LOGFILE "; done; %s -a n", vgscan_sz, vgchange_sz, 417 vgremove_sz, vgremove_sz); 410 418 run_program_and_log_output(command, 5); 411 419 if (just_erase_existing_volumes) { 412 420 paranoid_fclose(fin); 413 421 log_msg(1, "Closed i-want-my-lvm. Finished erasing LVMs."); 414 retval =0;422 retval = 0; 415 423 goto end_of_i_want_my_lvm; 416 424 } … … 423 431 continue; 424 432 } 425 if (res && strstr(command, "create") && vacuum_pack) 426 {427 sleep(2);428 system("sync"); system("sync");system("sync");429 }430 if ((p=strstr(incoming, "vgcreate")))431 433 if (res && strstr(command, "create") && vacuum_pack) { 434 sleep(2); 435 system("sync"); 436 system("sync"); 437 system("sync"); 438 } 439 if ((p = strstr(incoming, "vgcreate"))) { 432 440 // include next line(s) if they end in /dev (cos we've got a broken i-want-my-lvm) 433 for (fgets(tmp, 512, fin); !feof(fin); fgets(tmp, 512, fin)) { 434 if (tmp[0] == '#') { 435 fsetpos(fin, &orig_pos); 436 break; 437 } else { 438 fgetpos(fin, &orig_pos); 439 strcat(incoming, tmp); 440 } 441 } 442 for(q=incoming; *q!='\0'; q++) 443 { 444 if (*q<32) { *q=' '; } 445 } 446 strcpy(tmp, p+strlen("vgcreate")+1); 447 for(q=tmp; *q>32; q++); 448 *q = '\0'; 449 log_msg(1, "Deleting old entries at /dev/%s", tmp); 450 // sprintf(command, "%s -f %s", vgremove_sz, tmp); 451 // run_program_and_log_output(command, 1); 452 sprintf(command, "rm -Rf /dev/%s", tmp); 453 run_program_and_log_output(command, 1); 454 run_program_and_log_output(vgscan_sz, 1); 455 run_program_and_log_output(pvscan_sz, 1); 456 log_msg(3, "After working around potentially broken i-want-my-lvm, incoming[] is now '%s'", incoming); 457 } 441 for (fgets(tmp, 512, fin); !feof(fin); fgets(tmp, 512, fin)) { 442 if (tmp[0] == '#') { 443 fsetpos(fin, &orig_pos); 444 break; 445 } else { 446 fgetpos(fin, &orig_pos); 447 strcat(incoming, tmp); 448 } 449 } 450 for (q = incoming; *q != '\0'; q++) { 451 if (*q < 32) { 452 *q = ' '; 453 } 454 } 455 strcpy(tmp, p + strlen("vgcreate") + 1); 456 for (q = tmp; *q > 32; q++); 457 *q = '\0'; 458 log_msg(1, "Deleting old entries at /dev/%s", tmp); 459 // sprintf(command, "%s -f %s", vgremove_sz, tmp); 460 // run_program_and_log_output(command, 1); 461 sprintf(command, "rm -Rf /dev/%s", tmp); 462 run_program_and_log_output(command, 1); 463 run_program_and_log_output(vgscan_sz, 1); 464 run_program_and_log_output(pvscan_sz, 1); 465 log_msg(3, 466 "After working around potentially broken i-want-my-lvm, incoming[] is now '%s'", 467 incoming); 468 } 458 469 for (p = incoming + 1; *p == ' '; p++); 459 470 strcpy(command, p); … … 462 473 *p = '\0'; 463 474 res = run_program_and_log_output(command, 5); 464 if (res>0 && (p=strstr(command, "lvm "))) 465 { 466 *p = *(p+1) = *(p+2) = ' '; 467 res = run_program_and_log_output(command, 5); 468 } 475 if (res > 0 && (p = strstr(command, "lvm "))) { 476 *p = *(p + 1) = *(p + 2) = ' '; 477 res = run_program_and_log_output(command, 5); 478 } 469 479 log_msg(0, "%s --> %d", command, res); 470 if (res>0) {res=1;} 471 if (res && strstr(command, "lvcreate") && vacuum_pack) 472 { 473 res=0; 474 if (strstr(command, "lvm lvcreate")) 475 lvmversion = 2; 476 log_it("%s... so I'll get creative.", tmp); 477 if (lvmversion == 2) 478 { 479 strcpy(tmp, call_program_and_get_last_line_of_output 480 ("tail -n5 /var/log/mondo-archive.log | grep Insufficient | tail -n1")); 481 } 482 else 483 { 484 strcpy(tmp, call_program_and_get_last_line_of_output 485 ("tail -n5 /var/log/mondo-archive.log | grep lvcreate | tail -n1")); 486 } 487 for(p=tmp; *p!='\0' && !isdigit(*p); p++); 488 extents = atol(p); 489 log_msg(5, "p='%s' --> extents=%ld", p, extents); 490 p = strstr(command, "-L"); 491 if (!p) 492 { 493 log_msg(0, "Fiddlesticks. '%s' returned %d", command, res); 494 } 495 else 496 { 497 if (lvmversion == 2) 498 { 499 *p++ = '-'; *p++ = 'l'; *p++ = ' '; 500 for(q=p; *q!=' '; q++) { *q = ' '; } 501 sprintf(p, "%ld", extents); 502 i = strlen(p); 503 *(p+i) = ' '; 504 } 505 else 506 { 507 p++; p++; p++; 508 for(q=p; *q!=' '; q++) { *(q-1) = ' '; } 509 sprintf(p, "%ld%c", extents, 'm'); 510 i = strlen(p); 511 *(p+i) = ' '; 512 } 513 log_msg(5, "Retrying with '%s'", command); 514 res = run_program_and_log_output(command, 5); 515 if (res>0) { res=1; } 516 if (g_fprep) { fprintf(g_fprep, "%s\n", command); } 517 log_msg(0, "%s --> %d", command, res); 518 if (!res) 519 { 520 log_msg(5, "YAY! This time, it succeeded."); 521 } 522 } 523 } 524 if (strstr(command, "vgcreate")) 525 { 526 log_msg(0, "In case you're interested..."); 527 run_program_and_log_output(vgscan_sz, 1); 528 run_program_and_log_output(pvscan_sz, 1); 529 } 530 if (res!=0 && !strstr(command, "insmod")) { 531 retval ++; 480 if (res > 0) { 481 res = 1; 482 } 483 if (res && strstr(command, "lvcreate") && vacuum_pack) { 484 res = 0; 485 if (strstr(command, "lvm lvcreate")) 486 lvmversion = 2; 487 log_it("%s... so I'll get creative.", tmp); 488 if (lvmversion == 2) { 489 strcpy(tmp, call_program_and_get_last_line_of_output 490 ("tail -n5 /var/log/mondo-archive.log | grep Insufficient | tail -n1")); 491 } else { 492 strcpy(tmp, call_program_and_get_last_line_of_output 493 ("tail -n5 /var/log/mondo-archive.log | grep lvcreate | tail -n1")); 494 } 495 for (p = tmp; *p != '\0' && !isdigit(*p); p++); 496 extents = atol(p); 497 log_msg(5, "p='%s' --> extents=%ld", p, extents); 498 p = strstr(command, "-L"); 499 if (!p) { 500 log_msg(0, "Fiddlesticks. '%s' returned %d", command, res); 501 } else { 502 if (lvmversion == 2) { 503 *p++ = '-'; 504 *p++ = 'l'; 505 *p++ = ' '; 506 for (q = p; *q != ' '; q++) { 507 *q = ' '; 508 } 509 sprintf(p, "%ld", extents); 510 i = strlen(p); 511 *(p + i) = ' '; 512 } else { 513 p++; 514 p++; 515 p++; 516 for (q = p; *q != ' '; q++) { 517 *(q - 1) = ' '; 518 } 519 sprintf(p, "%ld%c", extents, 'm'); 520 i = strlen(p); 521 *(p + i) = ' '; 522 } 523 log_msg(5, "Retrying with '%s'", command); 524 res = run_program_and_log_output(command, 5); 525 if (res > 0) { 526 res = 1; 527 } 528 if (g_fprep) { 529 fprintf(g_fprep, "%s\n", command); 530 } 531 log_msg(0, "%s --> %d", command, res); 532 if (!res) { 533 log_msg(5, "YAY! This time, it succeeded."); 534 } 535 } 536 } 537 if (strstr(command, "vgcreate")) { 538 log_msg(0, "In case you're interested..."); 539 run_program_and_log_output(vgscan_sz, 1); 540 run_program_and_log_output(pvscan_sz, 1); 541 } 542 if (res != 0 && !strstr(command, "insmod")) { 543 retval++; 532 544 } 533 545 sprintf(tmp, "echo \"%s\" >> /tmp/out.sh", command); … … 537 549 paranoid_fclose(fin); 538 550 log_msg(1, "Closed i-want-my-lvm. Finished doing funky stuff."); 539 end_of_i_want_my_lvm:551 end_of_i_want_my_lvm: 540 552 paranoid_free(tmp); 541 553 paranoid_free(incoming); … … 548 560 paranoid_free(vgchange_sz); 549 561 paranoid_free(vgremove_sz); 550 // paranoid_free(do_this_last); 551 system("sync"); system("sync"); system("sync"); 562 // paranoid_free(do_this_last); 563 system("sync"); 564 system("sync"); 565 system("sync"); 552 566 sleep(1); 553 iamhere("ENDING"); 554 if (retval>2) 555 { 556 log_msg(1, "%d errors. I'm reporting this.", retval); 557 return(retval); 558 } 559 else 560 { 561 log_msg(1, "Not many errors. Returning 0."); 562 return(0); 563 } 567 iamhere("ENDING"); 568 if (retval > 2) { 569 log_msg(1, "%d errors. I'm reporting this.", retval); 570 return (retval); 571 } else { 572 log_msg(1, "Not many errors. Returning 0."); 573 return (0); 574 } 564 575 } 565 576 … … 574 585 * @return 0 for success, nonzero for failure. 575 586 */ 576 577 578 587 int extrapolate_mountlist_to_include_raid_partitions(struct mountlist_itself 588 *new_mountlist, struct mountlist_itself 589 *old_mountlist) 579 590 { 580 591 /** pointers *********************************************************/ … … 603 614 604 615 #ifdef __FreeBSD__ 605 log_to_screen ("I don't know how to extrapolate the mountlist on FreeBSD. Sorry."); 606 return(1); 616 log_to_screen 617 ("I don't know how to extrapolate the mountlist on FreeBSD. Sorry."); 618 return (1); 607 619 #endif 608 620 … … 611 623 { 612 624 if (!does_file_exist("/etc/raidtab")) { 613 log_to_screen("Cannot find /etc/raidtab - cannot extrapolate the fdisk entries"); 625 log_to_screen 626 ("Cannot find /etc/raidtab - cannot extrapolate the fdisk entries"); 614 627 finish(1); 615 628 } … … 619 632 } 620 633 for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin) 621 && !strstr(incoming, old_mountlist->el[lino].device); fgets(incoming, MAX_STR_LEN - 1, fin)); 634 && !strstr(incoming, old_mountlist->el[lino].device); 635 fgets(incoming, MAX_STR_LEN - 1, fin)); 622 636 if (!feof(fin)) { 623 sprintf(tmp, "Investigating %s", old_mountlist->el[lino].device); 637 sprintf(tmp, "Investigating %s", 638 old_mountlist->el[lino].device); 624 639 log_it(tmp); 625 640 for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin) 626 && !strstr(incoming, "raiddev"); fgets(incoming, MAX_STR_LEN - 1, fin)) { 641 && !strstr(incoming, "raiddev"); 642 fgets(incoming, MAX_STR_LEN - 1, fin)) { 627 643 if (strstr(incoming, OSSWAP("device", "drive")) 628 && !strchr(incoming, '#')) { 629 for (p = incoming + strlen(incoming); *(p - 1) <= 32; p--); 644 && !strchr(incoming, '#')) { 645 for (p = incoming + strlen(incoming); 646 *(p - 1) <= 32; p--); 630 647 *p = '\0'; 631 648 for (p--; p > incoming && *(p - 1) > 32; p--); 632 649 sprintf(tmp, "Extrapolating %s", p); 633 650 log_it(tmp); 634 for (j = 0; j < new_mountlist->entries && strcmp(new_mountlist->el[j].device, p); 635 j++); 651 for (j = 0; 652 j < new_mountlist->entries 653 && strcmp(new_mountlist->el[j].device, p); 654 j++); 636 655 if (j >= new_mountlist->entries) { 637 strcpy(new_mountlist->el[new_mountlist->entries].device, p); 638 strcpy(new_mountlist->el[new_mountlist->entries].mountpoint, "raid"); 639 strcpy(new_mountlist->el[new_mountlist->entries].format, "raid"); 640 new_mountlist->el[new_mountlist->entries].size = 641 old_mountlist->el[lino].size; 656 strcpy(new_mountlist-> 657 el[new_mountlist->entries].device, p); 658 strcpy(new_mountlist-> 659 el[new_mountlist->entries].mountpoint, 660 "raid"); 661 strcpy(new_mountlist-> 662 el[new_mountlist->entries].format, 663 "raid"); 664 new_mountlist->el[new_mountlist->entries]. 665 size = old_mountlist->el[lino].size; 642 666 new_mountlist->entries++; 643 667 } else { 644 sprintf(tmp, "Not adding %s to mountlist: it's already there", p); 668 sprintf(tmp, 669 "Not adding %s to mountlist: it's already there", 670 p); 645 671 log_it(tmp); 646 672 } … … 650 676 paranoid_fclose(fin); 651 677 } else { 652 strcpy(new_mountlist->el[new_mountlist->entries].device, old_mountlist->el[lino].device); 653 strcpy(new_mountlist->el[new_mountlist->entries].mountpoint, old_mountlist->el[lino].mountpoint); 654 strcpy(new_mountlist->el[new_mountlist->entries].format, old_mountlist->el[lino].format); 655 new_mountlist->el[new_mountlist->entries].size = old_mountlist->el[lino].size; 678 strcpy(new_mountlist->el[new_mountlist->entries].device, 679 old_mountlist->el[lino].device); 680 strcpy(new_mountlist->el[new_mountlist->entries].mountpoint, 681 old_mountlist->el[lino].mountpoint); 682 strcpy(new_mountlist->el[new_mountlist->entries].format, 683 old_mountlist->el[lino].format); 684 new_mountlist->el[new_mountlist->entries].size = 685 old_mountlist->el[lino].size; 656 686 new_mountlist->entries++; 657 687 } … … 697 727 sprintf(tmp, "Not formatting %s (it is a RAID disk)", device); 698 728 log_it(tmp); 699 paranoid_free(program); paranoid_free(tmp); 729 paranoid_free(program); 730 paranoid_free(tmp); 700 731 return (0); 701 732 } … … 703 734 if (strcmp(format, "swap") == 0) { 704 735 log_it("Not formatting %s - it's swap", device); 705 paranoid_free(program); paranoid_free(tmp); 736 paranoid_free(program); 737 paranoid_free(tmp); 706 738 return (0); 707 739 } … … 709 741 if (strlen(format) <= 2) { 710 742 sprintf(tmp, 711 "%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",712 device, format);743 "%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", 744 device, format); 713 745 log_it(tmp); 714 paranoid_free(program); paranoid_free(tmp); 746 paranoid_free(program); 747 paranoid_free(tmp); 715 748 return (0); 716 749 } … … 718 751 sprintf(tmp, "%s is mounted - cannot format it ", device); 719 752 log_to_screen(tmp); 720 paranoid_free(program); paranoid_free(tmp); 753 paranoid_free(program); 754 paranoid_free(tmp); 721 755 return (1); 722 756 } … … 726 760 if (!vinum_started_yet) { 727 761 if (!does_file_exist("/tmp/raidconf.txt")) { 728 log_to_screen("/tmp/raidconf.txt does not exist. I therefore cannot start Vinum."); 762 log_to_screen 763 ("/tmp/raidconf.txt does not exist. I therefore cannot start Vinum."); 729 764 } else { 730 765 int res; 731 res = run_program_and_log_output("vinum create /tmp/raidconf.txt", TRUE); 766 res = 767 run_program_and_log_output 768 ("vinum create /tmp/raidconf.txt", TRUE); 732 769 if (res) { 733 770 log_to_screen 734 771 ("`vinum create /tmp/raidconf.txt' returned errors. Please fix them and re-run mondorestore."); 735 772 finish(1); 736 773 } … … 742 779 FILE *fin; 743 780 char line[MAX_STR_LEN]; 744 sprintf(tmp, "Initializing Vinum device %s (this may take a *long* time)", device); 781 sprintf(tmp, 782 "Initializing Vinum device %s (this may take a *long* time)", 783 device); 745 784 log_to_screen(tmp); 746 785 /* format raid partition */ 747 786 // sprintf (program, "mkraid --really-force %s", device); --- disabled -- BB, 02/12/2003 748 787 sprintf(program, 749 "for plex in `vinum lv -r %s | grep '^P' | tr '\t' ' ' | tr -s ' ' | cut -d' ' -f2`; do echo $plex; done > /tmp/plexes",750 basename(device));788 "for plex in `vinum lv -r %s | grep '^P' | tr '\t' ' ' | tr -s ' ' | cut -d' ' -f2`; do echo $plex; done > /tmp/plexes", 789 basename(device)); 751 790 system(program); 752 if (g_fprep) { fprintf(g_fprep, "%s\n", program); } 791 if (g_fprep) { 792 fprintf(g_fprep, "%s\n", program); 793 } 753 794 fin = fopen("/tmp/plexes", "r"); 754 795 while (fgets(line, MAX_STR_LEN - 1, fin)) { … … 762 803 while (1) { 763 804 sprintf(tmp, 764 "vinum lp -r %s | grep '^S' | head -1 | tr -s ' ' | cut -d: -f2 | cut -f1 | sed 's/^ //' | sed 's/I //' | sed 's/%%//'",765 line);805 "vinum lp -r %s | grep '^S' | head -1 | tr -s ' ' | cut -d: -f2 | cut -f1 | sed 's/^ //' | sed 's/I //' | sed 's/%%//'", 806 line); 766 807 FILE *pin = popen(tmp, "r"); 767 808 char status[MAX_STR_LEN / 4]; … … 788 829 log_to_screen("Stopping %s", device); 789 830 stop_raid_device(device); 790 system("sync"); sleep(1); 791 if (g_fprep) { fprintf(g_fprep, "%s\n", program); } 831 system("sync"); 832 sleep(1); 833 if (g_fprep) { 834 fprintf(g_fprep, "%s\n", program); 835 } 792 836 793 837 log_msg(1, "Making %s", device); … … 795 839 res = run_program_and_log_output(program, 1); 796 840 log_msg(1, "%s returned %d", program, res); 797 system("sync"); sleep(3); 841 system("sync"); 842 sleep(3); 798 843 start_raid_device(device); 799 if (g_fprep) { fprintf(g_fprep, "%s\n", program); } 800 system("sync"); sleep(2); 801 802 // log_to_screen("Starting %s", device); 803 // sprintf(program, "raidstart %s", device); 804 // res = run_program_and_log_output(program, 1); 805 // log_msg(1, "%s returned %d", program, res); 806 // system("sync"); sleep(1); 807 if (g_fprep) { fprintf(g_fprep, "%s\n", program); } 808 809 #endif 810 system("sync"); sleep(1); 844 if (g_fprep) { 845 fprintf(g_fprep, "%s\n", program); 846 } 847 system("sync"); 848 sleep(2); 849 850 // log_to_screen("Starting %s", device); 851 // sprintf(program, "raidstart %s", device); 852 // res = run_program_and_log_output(program, 1); 853 // log_msg(1, "%s returned %d", program, res); 854 // system("sync"); sleep(1); 855 if (g_fprep) { 856 fprintf(g_fprep, "%s\n", program); 857 } 858 #endif 859 system("sync"); 860 sleep(1); 811 861 newtResume(); 812 862 } … … 814 864 //#endif 815 865 816 if (!strcmp(format, "lvm")) 817 {818 log_msg(1, "Don't format %s - it's part of an lvm volume", device);819 paranoid_free(program);paranoid_free(tmp);820 return(0);821 866 if (!strcmp(format, "lvm")) { 867 log_msg(1, "Don't format %s - it's part of an lvm volume", device); 868 paranoid_free(program); 869 paranoid_free(tmp); 870 return (0); 871 } 822 872 res = which_format_command_do_i_need(format, program); 823 873 sprintf(tmp, "%s %s", program, device); … … 830 880 res = run_program_and_log_output(program, FALSE); 831 881 if (res && strstr(program, "kludge")) { 832 sprintf(tmp, "Kludge failed; using regular mkfs.%s to format %s", format, device); 882 sprintf(tmp, "Kludge failed; using regular mkfs.%s to format %s", 883 format, device); 833 884 #ifdef __FreeBSD__ 834 885 sprintf(program, "newfs_msdos -F 32 %s", device); … … 843 894 #endif 844 895 res = run_program_and_log_output(program, FALSE); 845 if (g_fprep) { fprintf(g_fprep, "%s\n", program); } 896 if (g_fprep) { 897 fprintf(g_fprep, "%s\n", program); 898 } 846 899 } 847 900 retval += res; … … 853 906 854 907 log_to_screen(tmp); 855 paranoid_free(program); paranoid_free(tmp); 856 system("sync"); sleep(1); 908 paranoid_free(program); 909 paranoid_free(tmp); 910 system("sync"); 911 sleep(1); 857 912 return (retval); 858 913 } … … 868 923 * @return The number of errors encountered (0 for success). 869 924 */ 870 int format_everything(struct mountlist_itself *mountlist, bool interactively) 925 int format_everything(struct mountlist_itself *mountlist, 926 bool interactively) 871 927 { 872 928 /** int **************************************************************/ … … 874 930 int lino; 875 931 int res; 876 // 877 // 932 // int i; 933 // struct list_of_disks *drivelist; 878 934 879 935 /** long *************************************************************/ … … 890 946 /** end **************************************************************/ 891 947 892 assert(mountlist !=NULL);948 assert(mountlist != NULL); 893 949 malloc_string(tmp); 894 sprintf(tmp, "format_everything (mountlist, interactively = %s", (interactively) ? "true" : "false"); 950 sprintf(tmp, "format_everything (mountlist, interactively = %s", 951 (interactively) ? "true" : "false"); 895 952 log_it(tmp); 896 953 mvaddstr_and_log_it(g_currentY, 0, "Formatting partitions "); 897 open_progress_form("Formatting partitions", "I am now formatting your hard disk partitions.", 898 "This may take up to five minutes.", "", mountlist->entries + 1); 899 900 progress_step = (mountlist->entries > 0) ? g_maximum_progress / mountlist->entries : 1; 954 open_progress_form("Formatting partitions", 955 "I am now formatting your hard disk partitions.", 956 "This may take up to five minutes.", "", 957 mountlist->entries + 1); 958 959 progress_step = 960 (mountlist->entries > 961 0) ? g_maximum_progress / mountlist->entries : 1; 901 962 // start soft-raids now (because LVM might depend on them) 902 963 // ...and for simplicity's sake, let's format them at the same time :) 903 964 log_msg(1, "Stopping all RAID devices"); 904 965 stop_all_raid_devices(mountlist); 905 system("sync"); system("sync"); system("sync"); 966 system("sync"); 967 system("sync"); 968 system("sync"); 906 969 sleep(2); 907 log_msg(1, "Prepare soft-RAIDs"); 970 log_msg(1, "Prepare soft-RAIDs"); // prep and format too 908 971 for (lino = 0; lino < mountlist->entries; lino++) { 909 972 me = &mountlist->el[lino]; // the current mountlist entry … … 912 975 if (interactively) { 913 976 // ask user if we should format the current device 914 sprintf(tmp, "Shall I format %s (%s) ?", me->device, me->mountpoint); 977 sprintf(tmp, "Shall I format %s (%s) ?", me->device, 978 me->mountpoint); 915 979 do_it = ask_me_yes_or_no(tmp); 916 980 } else { … … 918 982 } 919 983 if (do_it) { 920 // NB: format_device() also stops/starts RAID device if necessary984 // NB: format_device() also stops/starts RAID device if necessary 921 985 retval += format_device(me->device, me->format); 922 986 } … … 924 988 } 925 989 } 926 system("sync"); system("sync"); system("sync"); 990 system("sync"); 991 system("sync"); 992 system("sync"); 927 993 sleep(2); 928 994 // This last step is probably necessary 929 // 930 // 931 // 932 // 995 // log_to_screen("Re-starting software RAIDs..."); 996 // start_all_raid_devices(mountlist); 997 // system("sync"); system("sync"); system("sync"); 998 // sleep(5); 933 999 // do LVMs now 934 1000 log_msg(1, "Creating LVMs"); … … 936 1002 wait_until_software_raids_are_prepped("/proc/mdstat", 10); 937 1003 log_to_screen("Configuring LVM"); 938 if (!g_text_mode) { newtSuspend(); } 1004 if (!g_text_mode) { 1005 newtSuspend(); 1006 } 939 1007 /* 940 1008 for(i=0; i<3; i++) … … 949 1017 log_msg(1, "Vacuum-packing..."); 950 1018 */ 951 1019 res = do_my_funky_lvm_stuff(FALSE, TRUE); 952 1020 /* 953 1021 } 954 1022 */ 955 if (!g_text_mode) { newtResume(); } 956 if (!res) { log_to_screen("LVM initialized OK"); } 957 else { log_to_screen("Failed to initialize LVM"); } 1023 if (!g_text_mode) { 1024 newtResume(); 1025 } 1026 if (!res) { 1027 log_to_screen("LVM initialized OK"); 1028 } else { 1029 log_to_screen("Failed to initialize LVM"); 1030 } 958 1031 // retval += res; 959 1032 if (res) { 960 retval ++; 961 } 962 sleep(3); 963 } 964 1033 retval++; 1034 } 1035 sleep(3); 1036 } 965 1037 // do regulars at last 966 sleep(2); 967 1038 sleep(2); // woo! 1039 log_msg(1, "Formatting regulars"); 968 1040 for (lino = 0; lino < mountlist->entries; lino++) { 969 1041 me = &mountlist->el[lino]; // the current mountlist entry … … 972 1044 log_it(tmp); 973 1045 } else if (!strcmp(me->format, "raid")) { 974 sprintf(tmp, "Not formatting %s - it's a raid-let", me->device); 1046 sprintf(tmp, "Not formatting %s - it's a raid-let", 1047 me->device); 975 1048 log_it(tmp); 976 1049 continue; … … 980 1053 continue; 981 1054 } else if (!strncmp(me->device, "/dev/md", 7)) { 982 sprintf(tmp, "Already formatted %s - it's a soft-RAID dev", me->device); 1055 sprintf(tmp, "Already formatted %s - it's a soft-RAID dev", 1056 me->device); 983 1057 log_it(tmp); 984 1058 continue; 985 1059 } else if (!does_file_exist(me->device) 986 && strncmp(me->device, "/dev/hd", 7) 987 && strncmp(me->device, "/dev/sd", 7)) { 988 sprintf(tmp, "Not formatting %s yet - doesn't exist - probably an LVM", me->device); 1060 && strncmp(me->device, "/dev/hd", 7) 1061 && strncmp(me->device, "/dev/sd", 7)) { 1062 sprintf(tmp, 1063 "Not formatting %s yet - doesn't exist - probably an LVM", 1064 me->device); 989 1065 log_it(tmp); 990 1066 continue; … … 992 1068 if (interactively) { 993 1069 // ask user if we should format the current device 994 sprintf(tmp, "Shall I format %s (%s) ?", me->device, me->mountpoint); 1070 sprintf(tmp, "Shall I format %s (%s) ?", me->device, 1071 me->mountpoint); 995 1072 do_it = ask_me_yes_or_no(tmp); 996 1073 } else { … … 1016 1093 if (retval) { 1017 1094 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 1018 log_to_screen("Errors occurred during the formatting of your hard drives."); 1095 log_to_screen 1096 ("Errors occurred during the formatting of your hard drives."); 1019 1097 } else { 1020 1098 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 1021 1099 } 1022 1100 1023 sprintf(tmp, "format_everything () - %s", (retval) ? "failed!" : "finished successfully"); 1101 sprintf(tmp, "format_everything () - %s", 1102 (retval) ? "failed!" : "finished successfully"); 1024 1103 log_it(tmp); 1025 1104 1026 if (g_partition_table_locked_up > 0) 1027 { 1028 if (retval > 0 && !interactively) 1029 { 1105 if (g_partition_table_locked_up > 0) { 1106 if (retval > 0 && !interactively) { 1030 1107 //123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1031 log_to_screen( 1032 "Partition table locked up %d times. At least one 'mkfs' (format) command", g_partition_table_locked_up); 1033 log_to_screen( 1034 "failed. I think these two events are related. Sometimes, fdisk's ioctl() call"); 1035 log_to_screen( 1036 "to refresh its copy of the partition table causes the kernel to lock the "); 1037 log_to_screen( 1038 "partition table. I believe this has just happened."); 1039 if (ask_me_yes_or_no("Please choose 'yes' to reboot and try again; or 'no' to ignore this warning and continue.")) 1040 { 1041 system("sync"); 1042 system("sync"); 1043 system("sync"); 1044 system("reboot"); 1045 } 1046 } 1047 else 1048 { 1049 log_to_screen( 1050 "Partition table locked up %d time%c. However, disk formatting succeeded.", g_partition_table_locked_up, (g_partition_table_locked_up==1)?'.':'s'); 1051 } 1052 } 1053 newtSuspend(); 1108 log_to_screen 1109 ("Partition table locked up %d times. At least one 'mkfs' (format) command", 1110 g_partition_table_locked_up); 1111 log_to_screen 1112 ("failed. I think these two events are related. Sometimes, fdisk's ioctl() call"); 1113 log_to_screen 1114 ("to refresh its copy of the partition table causes the kernel to lock the "); 1115 log_to_screen 1116 ("partition table. I believe this has just happened."); 1117 if (ask_me_yes_or_no 1118 ("Please choose 'yes' to reboot and try again; or 'no' to ignore this warning and continue.")) 1119 { 1120 system("sync"); 1121 system("sync"); 1122 system("sync"); 1123 system("reboot"); 1124 } 1125 } else { 1126 log_to_screen 1127 ("Partition table locked up %d time%c. However, disk formatting succeeded.", 1128 g_partition_table_locked_up, 1129 (g_partition_table_locked_up == 1) ? '.' : 's'); 1130 } 1131 } 1132 newtSuspend(); 1054 1133 system("clear"); 1055 1134 newtResume(); … … 1067 1146 * @return The number of errors encountered (0 for success). 1068 1147 */ 1069 int make_dummy_partitions(FILE*pout_to_fdisk, char *drivename, int devno_we_must_allow_for) 1148 int make_dummy_partitions(FILE * pout_to_fdisk, char *drivename, 1149 int devno_we_must_allow_for) 1070 1150 { 1071 1151 /** int **************************************************************/ … … 1087 1167 log_it(tmp); 1088 1168 g_maximum_progress++; 1089 res = partition_device(pout_to_fdisk,drivename, 1, 0, "ext2", 32000); 1169 res = 1170 partition_device(pout_to_fdisk, drivename, 1, 0, "ext2", 1171 32000); 1090 1172 retval += res; 1091 1173 previous_devno = 1; … … 1096 1178 } 1097 1179 for (; current_devno < devno_we_must_allow_for; current_devno++) { 1098 sprintf(tmp, "Creating dummy partition %s%d", drivename, current_devno); 1180 sprintf(tmp, "Creating dummy partition %s%d", drivename, 1181 current_devno); 1099 1182 log_it(tmp); 1100 1183 g_maximum_progress++; 1101 res = partition_device(pout_to_fdisk,drivename, current_devno, previous_devno, OSSWAP("ext2", "ufs"), 32000); 1184 res = 1185 partition_device(pout_to_fdisk, drivename, current_devno, 1186 previous_devno, OSSWAP("ext2", "ufs"), 32000); 1102 1187 retval += res; 1103 1188 previous_devno = current_devno; … … 1147 1232 else 1148 1233 fprintf(f, "type: %u\n", lp->d_type); 1149 fprintf(f, "disk: %.*s\n", (int) sizeof(lp->d_typename), lp->d_typename); 1150 fprintf(f, "label: %.*s\n", (int) sizeof(lp->d_packname), lp->d_packname); 1234 fprintf(f, "disk: %.*s\n", (int) sizeof(lp->d_typename), 1235 lp->d_typename); 1236 fprintf(f, "label: %.*s\n", (int) sizeof(lp->d_packname), 1237 lp->d_packname); 1151 1238 fprintf(f, "flags:"); 1152 1239 if (lp->d_flags & D_REMOVABLE) … … 1167 1254 fprintf(f, "trackskew: %u\n", lp->d_trackskew); 1168 1255 fprintf(f, "cylinderskew: %u\n", lp->d_cylskew); 1169 fprintf(f, "headswitch: %lu\t\t# milliseconds\n", (u_long) lp->d_headswitch); 1170 fprintf(f, "track-to-track seek: %ld\t# milliseconds\n", (u_long) lp->d_trkseek); 1256 fprintf(f, "headswitch: %lu\t\t# milliseconds\n", 1257 (u_long) lp->d_headswitch); 1258 fprintf(f, "track-to-track seek: %ld\t# milliseconds\n", 1259 (u_long) lp->d_trkseek); 1171 1260 fprintf(f, "drivedata: "); 1172 1261 for (i = NDDATA - 1; i >= 0; i--) … … 1178 1267 fprintf(f, "%lu ", (u_long) lp->d_drivedata[j]); 1179 1268 fprintf(f, "\n\n%u partitions:\n", lp->d_npartitions); 1180 fprintf(f, "# size offset fstype [fsize bsize bps/cpg]\n"); 1269 fprintf(f, 1270 "# size offset fstype [fsize bsize bps/cpg]\n"); 1181 1271 pp = lp->d_partitions; 1182 1272 for (i = 0; i < lp->d_npartitions; i++, pp++) { 1183 1273 if (pp->p_size) { 1184 fprintf(f, " %c: %8lu %8lu ", 'a' + i, (u_long) pp->p_size, (u_long) pp->p_offset); 1274 fprintf(f, " %c: %8lu %8lu ", 'a' + i, (u_long) pp->p_size, 1275 (u_long) pp->p_offset); 1185 1276 if (pp->p_fstype < FSMAXTYPES) 1186 1277 fprintf(f, "%8.8s", fstypenames[pp->p_fstype]); … … 1190 1281 1191 1282 case FS_UNUSED: /* XXX */ 1192 fprintf(f, " %5lu %5lu %5.5s ", (u_long) pp->p_fsize, (u_long) (pp->p_fsize * pp->p_frag), ""); 1283 fprintf(f, " %5lu %5lu %5.5s ", (u_long) pp->p_fsize, 1284 (u_long) (pp->p_fsize * pp->p_frag), ""); 1193 1285 break; 1194 1286 1195 1287 case FS_BSDFFS: 1196 fprintf(f, " %5lu %5lu %5u ", (u_long) pp->p_fsize, (u_long) (pp->p_fsize * pp->p_frag),1197 pp->p_cpg);1288 fprintf(f, " %5lu %5lu %5u ", (u_long) pp->p_fsize, 1289 (u_long) (pp->p_fsize * pp->p_frag), pp->p_cpg); 1198 1290 break; 1199 1291 1200 1292 case FS_BSDLFS: 1201 fprintf(f, " %5lu %5lu %5d", (u_long) pp->p_fsize, (u_long) (pp->p_fsize * pp->p_frag),1202 pp->p_cpg);1293 fprintf(f, " %5lu %5lu %5d", (u_long) pp->p_fsize, 1294 (u_long) (pp->p_fsize * pp->p_frag), pp->p_cpg); 1203 1295 break; 1204 1296 … … 1207 1299 break; 1208 1300 } 1209 fprintf(f, "\t# (Cyl. %4lu", (u_long) (pp->p_offset / lp->d_secpercyl)); 1301 fprintf(f, "\t# (Cyl. %4lu", 1302 (u_long) (pp->p_offset / lp->d_secpercyl)); 1210 1303 if (pp->p_offset % lp->d_secpercyl) 1211 1304 putc('*', f); 1212 1305 else 1213 1306 putc(' ', f); 1214 fprintf(f, "- %lu", (u_long) ((pp->p_offset + pp->p_size + lp->d_secpercyl - 1) / lp->d_secpercyl - 1)); 1307 fprintf(f, "- %lu", 1308 (u_long) ((pp->p_offset + pp->p_size + 1309 lp->d_secpercyl - 1) / lp->d_secpercyl - 1310 1)); 1215 1311 if (pp->p_size % lp->d_secpercyl) 1216 1312 putc('*', f); … … 1238 1334 /* New world order */ 1239 1335 if ((ioctl(f, DIOCGMEDIASIZE, &mediasize) != 0) 1240 1336 || (ioctl(f, DIOCGSECTORSIZE, &secsize) != 0)) { 1241 1337 close(f); 1242 1338 return (NULL); … … 1282 1378 return (&loclab); 1283 1379 } 1380 1284 1381 /* End stolen from /usr/src/sbin/disklabel/disklabel.c. */ 1285 1382 … … 1301 1398 * @return The number of errors encountered (0 for success). 1302 1399 */ 1303 int label_drive_or_slice(struct mountlist_itself *mountlist, char *drivename, struct disklabel *ret) 1400 int label_drive_or_slice(struct mountlist_itself *mountlist, 1401 char *drivename, struct disklabel *ret) 1304 1402 { 1305 1403 char subdev_str[MAX_STR_LEN]; … … 1325 1423 lp->d_partitions[c - 'a'].p_cpg = 0; 1326 1424 if (!strcmp(mountlist->el[idx].format, "ufs") 1327 1328 1425 || !strcmp(mountlist->el[idx].format, "ffs") 1426 || !strcmp(mountlist->el[idx].format, "4.2BSD")) { 1329 1427 lp->d_partitions[c - 'a'].p_fstype = FS_BSDFFS; 1330 1428 lp->d_partitions[c - 'a'].p_fsize = 2048; … … 1332 1430 lp->d_partitions[c - 'a'].p_cpg = 64; 1333 1431 } else if (!strcasecmp(mountlist->el[idx].format, "raid") 1334 || !strcasecmp(mountlist->el[idx].format, "vinum")) {1432 || !strcasecmp(mountlist->el[idx].format, "vinum")) { 1335 1433 lp->d_partitions[c - 'a'].p_fstype = FS_VINUM; 1336 1434 } else if (!strcmp(mountlist->el[idx].format, "swap")) { … … 1353 1451 for (lastone = i - 1; lastone >= 0; lastone--) { 1354 1452 if ((lp->d_partitions[lastone].p_size) 1355 1453 && (lastone != RAW_PART)) 1356 1454 break; 1357 1455 } 1358 lp->d_partitions[i].p_offset = lp->d_partitions[lastone].p_offset + lp->d_partitions[lastone].p_size; 1359 } 1360 if (lp->d_partitions[lo].p_offset + lp->d_partitions[lo].p_size > lp->d_secperunit) { 1361 lp->d_partitions[lo].p_size = lp->d_secperunit - lp->d_partitions[lo].p_offset; 1456 lp->d_partitions[i].p_offset = 1457 lp->d_partitions[lastone].p_offset + 1458 lp->d_partitions[lastone].p_size; 1459 } 1460 if (lp->d_partitions[lo].p_offset + lp->d_partitions[lo].p_size > 1461 lp->d_secperunit) { 1462 lp->d_partitions[lo].p_size = 1463 lp->d_secperunit - lp->d_partitions[lo].p_offset; 1362 1464 } 1363 1465 … … 1367 1469 sprintf(command, "disklabel -wr %s auto", canonical_name(drivename)); 1368 1470 retval += run_program_and_log_output(command, TRUE); 1369 sprintf(command, "disklabel -R %s /tmp/disklabel", canonical_name(drivename)); 1471 sprintf(command, "disklabel -R %s /tmp/disklabel", 1472 canonical_name(drivename)); 1370 1473 retval += run_program_and_log_output(command, TRUE); 1371 1474 if (ret) … … 1390 1493 int retval = 0; 1391 1494 int i; 1392 FILE *pout_to_fdisk=NULL;1393 1495 FILE *pout_to_fdisk = NULL; 1496 1394 1497 #ifdef __FreeBSD__ 1395 1498 bool fbsd_part = FALSE; … … 1413 1516 malloc_string(format); 1414 1517 malloc_string(tmp); 1415 1518 1416 1519 sprintf(tmp, "Partitioning drive %s", drivename); 1417 1520 log_it(tmp); 1418 1521 1419 #if __FreeBSD__ 1420 1522 #if __FreeBSD__ 1523 log_it("(Not opening fdisk now; that's the Linux guy's job)"); 1421 1524 pout_to_fdisk = NULL; 1422 1525 #else 1423 1526 make_hole_for_file(FDISK_LOG); 1424 1527 #ifdef __IA64__ 1425 sprintf(tmp, "parted2fdisk %s >> %s 2>> %s", drivename, FDISK_LOG, FDISK_LOG); 1528 sprintf(tmp, "parted2fdisk %s >> %s 2>> %s", drivename, FDISK_LOG, 1529 FDISK_LOG); 1426 1530 #else 1427 1531 sprintf(tmp, "fdisk %s >> %s 2>> %s", drivename, FDISK_LOG, FDISK_LOG); 1428 1532 #endif 1429 1533 pout_to_fdisk = popen(tmp, "w"); 1430 if (!pout_to_fdisk) { 1431 log_to_screen("Cannot call fdisk to configure %s", drivename); 1534 if (!pout_to_fdisk) { 1535 log_to_screen("Cannot call fdisk to configure %s", drivename); 1432 1536 paranoid_free(device_str); 1433 1537 paranoid_free(format); 1434 1538 paranoid_free(tmp); 1435 return (1);1539 return (1); 1436 1540 } 1437 1541 #endif … … 1451 1555 for (c = 'a'; c <= 'z'; c++) { 1452 1556 sprintf(subdev_str, "%s%c", drivename, c); 1453 if (find_device_in_mountlist(mountlist, subdev_str) > 0) { 1557 if (find_device_in_mountlist(mountlist, subdev_str) > 1558 0) { 1454 1559 fbsd_part = TRUE; 1455 1560 } … … 1457 1562 if (fbsd_part) { 1458 1563 int r = label_drive_or_slice(mountlist, 1459 1460 1564 drivename, 1565 0); 1461 1566 char command[MAX_STR_LEN]; 1462 sprintf(command, "disklabel -B %s", basename(drivename)); 1567 sprintf(command, "disklabel -B %s", 1568 basename(drivename)); 1463 1569 if (system(command)) { 1464 log_to_screen("Warning! Unable to make the drive bootable."); 1570 log_to_screen 1571 ("Warning! Unable to make the drive bootable."); 1465 1572 } 1466 1573 paranoid_free(device_str); … … 1507 1614 #if __FreeBSD__ 1508 1615 // FreeBSD doesn't let you write to blk devices in <512byte chunks. 1509 // 1510 // 1616 // sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename); 1617 // if (run_program_and_log_output(tmp, TRUE)) { 1511 1618 file = open(drivename, O_WRONLY); 1512 1619 if (!file) { 1513 sprintf(tmp, "Warning - unable to open %s for wiping it's partition table", drivename); 1620 sprintf(tmp, 1621 "Warning - unable to open %s for wiping it's partition table", 1622 drivename); 1514 1623 log_to_screen(tmp); 1515 1624 } 1516 1625 1517 for (i=0; i<512; i++) { 1518 if ( !write(file, "\0", 1) ) { 1519 sprintf(tmp, "Warning - unable to write to %s", drivename); 1626 for (i = 0; i < 512; i++) { 1627 if (!write(file, "\0", 1)) { 1628 sprintf(tmp, "Warning - unable to write to %s", 1629 drivename); 1520 1630 log_to_screen(tmp); 1521 1631 } … … 1524 1634 #else 1525 1635 iamhere("New, kernel-friendly partition remover"); 1526 for(i=20;i>0;i--) 1527 { 1528 fprintf(pout_to_fdisk, "d\n%d\n", i); 1529 fflush(pout_to_fdisk); 1530 } 1531 // sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename); 1532 // run_program_and_log_output(tmp, 1); 1533 #endif 1636 for (i = 20; i > 0; i--) { 1637 fprintf(pout_to_fdisk, "d\n%d\n", i); 1638 fflush(pout_to_fdisk); 1639 } 1640 // sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename); 1641 // run_program_and_log_output(tmp, 1); 1642 #endif 1534 1643 if (current_devno > 1) { 1535 previous_devno = make_dummy_partitions(pout_to_fdisk,drivename, current_devno); 1644 previous_devno = 1645 make_dummy_partitions(pout_to_fdisk, drivename, 1646 current_devno); 1536 1647 } 1537 1648 } … … 1540 1651 #endif 1541 1652 1542 strcpy(format, mountlist->el[lino].format);1543 partsize = mountlist->el[lino].size;1653 strcpy(format, mountlist->el[lino].format); 1654 partsize = mountlist->el[lino].size; 1544 1655 1545 1656 #ifdef __FreeBSD__ … … 1549 1660 #ifndef __IA64__ 1550 1661 if (current_devno == 5 && previous_devno == 4) { 1551 log_to_screen("You must leave at least one partition spare as the Extended partition."); 1662 log_to_screen 1663 ("You must leave at least one partition spare as the Extended partition."); 1552 1664 paranoid_free(device_str); 1553 1665 paranoid_free(format); … … 1557 1669 #endif 1558 1670 1559 retval += partition_device(pout_to_fdisk, drivename, current_devno, previous_devno, format, partsize); 1671 retval += 1672 partition_device(pout_to_fdisk, drivename, current_devno, 1673 previous_devno, format, partsize); 1560 1674 1561 1675 #ifdef __FreeBSD__ … … 1564 1678 retval += label_drive_or_slice(mountlist, device_str, 0); 1565 1679 if (system(tmp)) { 1566 log_to_screen("Warning! Unable to make the slice bootable."); 1680 log_to_screen 1681 ("Warning! Unable to make the slice bootable."); 1567 1682 } 1568 1683 } … … 1572 1687 } 1573 1688 1574 if (pout_to_fdisk) 1575 { 1689 if (pout_to_fdisk) { 1576 1690 // mark relevant partition as bootable 1577 sprintf(tmp, "a\n%s\n", call_program_and_get_last_line_of_output("make-me-bootable /tmp/mountlist.txt dummy")); 1691 sprintf(tmp, "a\n%s\n", 1692 call_program_and_get_last_line_of_output 1693 ("make-me-bootable /tmp/mountlist.txt dummy")); 1578 1694 fput_string_one_char_at_a_time(pout_to_fdisk, tmp); 1579 1695 // close fdisk 1580 1696 fput_string_one_char_at_a_time(pout_to_fdisk, "w\n"); 1581 1697 system("sync"); 1582 paranoid_pclose(pout_to_fdisk); 1583 log_msg(0, "------------------- fdisk.log looks like this ------------------"); 1698 paranoid_pclose(pout_to_fdisk); 1699 log_msg(0, 1700 "------------------- fdisk.log looks like this ------------------"); 1584 1701 sprintf(tmp, "cat %s >> %s", FDISK_LOG, MONDO_LOGFILE); 1585 1702 system(tmp); 1586 log_msg(0, "------------------- end of fdisk.log... word! ------------------"); 1703 log_msg(0, 1704 "------------------- end of fdisk.log... word! ------------------"); 1587 1705 sprintf(tmp, "tail -n6 %s | fgrep \"16: \"", FDISK_LOG); 1588 if (!run_program_and_log_output(tmp, 5)) 1589 {1590 g_partition_table_locked_up++;1591 log_to_screen("A flaw in the Linux kernel has locked the partition table.");1592 1706 if (!run_program_and_log_output(tmp, 5)) { 1707 g_partition_table_locked_up++; 1708 log_to_screen 1709 ("A flaw in the Linux kernel has locked the partition table."); 1710 } 1593 1711 } 1594 1712 paranoid_free(device_str); … … 1607 1725 * @return 0 for success, nonzero for failure. 1608 1726 */ 1609 int partition_device(FILE*pout_to_fdisk, const char *drive, int partno, int prev_partno, const char *format, long long partsize) 1727 int partition_device(FILE * pout_to_fdisk, const char *drive, int partno, 1728 int prev_partno, const char *format, 1729 long long partsize) 1610 1730 { 1611 1731 /** int **************************************************************/ … … 1632 1752 malloc_string(logfile); 1633 1753 malloc_string(output); 1634 1754 1635 1755 assert_string_is_neither_NULL_nor_zerolength(drive); 1636 1756 assert(format != NULL); 1637 1757 1638 log_it("partition_device('%s', %d, %d, '%s', %lld) --- starting", drive, partno, prev_partno, format, partsize); 1758 log_it("partition_device('%s', %d, %d, '%s', %lld) --- starting", 1759 drive, partno, prev_partno, format, partsize); 1639 1760 1640 1761 if (!strncmp(drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) { … … 1652 1773 sprintf(tmp, "Partitioning device %s (max size)", partition_name); 1653 1774 } else { 1654 sprintf(tmp, "Partitioning device %s (%lld MB)", partition_name, (long long) partsize / 1024); 1775 sprintf(tmp, "Partitioning device %s (%lld MB)", partition_name, 1776 (long long) partsize / 1024); 1655 1777 } 1656 1778 update_progress_form(tmp); … … 1658 1780 1659 1781 if (is_this_device_mounted(partition_name)) { 1660 sprintf(tmp, "%s is mounted, and should not be partitioned", partition_name); 1782 sprintf(tmp, "%s is mounted, and should not be partitioned", 1783 partition_name); 1661 1784 log_to_screen(tmp); 1662 1785 paranoid_free(program); … … 1679 1802 p = (char *) strrchr(partition_name, '/'); 1680 1803 sprintf(logfile, "/tmp/fdisk.log.%s", ++p); 1681 sprintf(program, "parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE, MONDO_LOGFILE); 1804 sprintf(program, "parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE, 1805 MONDO_LOGFILE); 1682 1806 1683 1807 /* BERLIOS: shoould not be called each time */ … … 1689 1813 } else { 1690 1814 /* MBR needs an extended partition if more than 4 partitions */ 1691 if (strcmp(part_table_fmt, "MBR") == 0) {1815 if (strcmp(part_table_fmt, "MBR") == 0) { 1692 1816 if (partno == 5) { 1693 1817 if (prev_partno >= 4) { 1694 log_to_screen("You need to leave at least one partition free, for 'extended/logical'"); 1818 log_to_screen 1819 ("You need to leave at least one partition free, for 'extended/logical'"); 1695 1820 paranoid_free(program); 1696 1821 paranoid_free(partition_name); … … 1700 1825 return (1); 1701 1826 } else { 1702 sprintf(output + strlen(output), "n\ne\n%d\n\n\n", prev_partno + 1); 1827 sprintf(output + strlen(output), "n\ne\n%d\n\n\n", 1828 prev_partno + 1); 1703 1829 } 1704 1830 } … … 1711 1837 strcat(output + strlen(output), "\n"); /*start block (ENTER for next free blk */ 1712 1838 if (partsize > 0) { 1713 if (!strcmp(format, "7")) { log_msg(1, "Adding 512K, just in case"); partsize+=512; } 1839 if (!strcmp(format, "7")) { 1840 log_msg(1, "Adding 512K, just in case"); 1841 partsize += 512; 1842 } 1714 1843 sprintf(output + strlen(output), "+%lldK", (long long) (partsize)); 1715 1844 } … … 1728 1857 1729 1858 1730 if (pout_to_fdisk) 1731 { 1859 if (pout_to_fdisk) { 1732 1860 log_msg(1, "Doing the new all-in-one fdisk thing"); 1733 1861 log_msg(1, "output = '%s'", output); … … 1735 1863 fput_string_one_char_at_a_time(pout_to_fdisk, "\n\np\n"); 1736 1864 strcpy(tmp, last_line_of_file(FDISK_LOG)); 1737 if (strstr(tmp, " (m ")) 1738 { 1865 if (strstr(tmp, " (m ")) { 1739 1866 log_msg(1, "Successfully created %s%d", drive, partno); 1740 } 1741 else 1742 { 1867 } else { 1743 1868 log_msg(1, "last line = %s", tmp); 1744 log_msg(1, "Failed to create %s%d; sending 'Enter'...", drive, partno); 1745 } 1746 if (!retval) 1747 { 1748 log_msg(1, "Trying to set %s%d's partition type now", drive, partno); 1749 retval = set_partition_type(pout_to_fdisk, drive, partno, format, partsize); 1750 if (retval) 1751 { 1869 log_msg(1, "Failed to create %s%d; sending 'Enter'...", drive, 1870 partno); 1871 } 1872 if (!retval) { 1873 log_msg(1, "Trying to set %s%d's partition type now", drive, 1874 partno); 1875 retval = 1876 set_partition_type(pout_to_fdisk, drive, partno, format, 1877 partsize); 1878 if (retval) { 1752 1879 log_msg(1, "Failed. Trying again..."); 1753 retval = set_partition_type(pout_to_fdisk, drive, partno, format, partsize); 1754 } 1755 } 1756 if (retval) { log_msg(1, "...but failed to set type"); } 1757 } 1758 else 1759 { 1880 retval = 1881 set_partition_type(pout_to_fdisk, drive, partno, 1882 format, partsize); 1883 } 1884 } 1885 if (retval) { 1886 log_msg(1, "...but failed to set type"); 1887 } 1888 } else { 1760 1889 strcat(output, "w\n\n"); 1761 if (g_fprep) { fprintf(g_fprep, "echo \"%s\" | %s\n", output, program); } 1890 if (g_fprep) { 1891 fprintf(g_fprep, "echo \"%s\" | %s\n", output, program); 1892 } 1762 1893 /* write to disk; close fdisk's stream */ 1763 1894 if (!(fout = popen(program, "w"))) { … … 1770 1901 log_it("Vaccum-packing"); 1771 1902 g_current_progress--; 1772 res = partition_device(pout_to_fdisk, drive, partno, prev_partno, format, -1); 1903 res = 1904 partition_device(pout_to_fdisk, drive, partno, prev_partno, 1905 format, -1); 1773 1906 if (res) { 1774 1907 sprintf(tmp, "Failed to vacuum-pack %s", partition_name); … … 1780 1913 } 1781 1914 if (does_partition_exist(drive, partno)) { 1782 retval = set_partition_type(pout_to_fdisk, drive, partno, format, partsize); 1915 retval = 1916 set_partition_type(pout_to_fdisk, drive, partno, format, 1917 partsize); 1783 1918 if (retval) { 1784 sprintf(tmp, "Partitioned %s but failed to set its type", partition_name); 1919 sprintf(tmp, "Partitioned %s but failed to set its type", 1920 partition_name); 1785 1921 log_it(tmp); 1786 1922 } else { 1787 1923 if (partsize > 0) { 1788 sprintf(tmp, "Partition %s created+configured OK", partition_name); 1924 sprintf(tmp, "Partition %s created+configured OK", 1925 partition_name); 1789 1926 log_to_screen(tmp); 1790 1927 } else { … … 1792 1929 } 1793 1930 } 1794 1931 } else { 1795 1932 sprintf(tmp, "Failed to partition %s", partition_name); 1796 1933 if (partsize > 0) { … … 1844 1981 /* mountlist=&new_mtlist; */ 1845 1982 /* extrapolate_mountlist_to_include_raid_partitions(mountlist,orig_mtlist); */ 1846 log_msg(0,"Mountlist, including the partitions incorporated in RAID devices:-"); 1983 log_msg(0, 1984 "Mountlist, including the partitions incorporated in RAID devices:-"); 1847 1985 for (i = 0; i < mountlist->entries; i++) { 1848 1986 log_it(mountlist->el[i].device); … … 1851 1989 } 1852 1990 log_msg(0, "Stopping all LVMs, just in case"); 1853 if (!g_text_mode) { newtSuspend(); } 1854 do_my_funky_lvm_stuff(TRUE, FALSE); // just remove old partitions 1855 if (!g_text_mode) { newtResume(); } 1991 if (!g_text_mode) { 1992 newtSuspend(); 1993 } 1994 do_my_funky_lvm_stuff(TRUE, FALSE); // just remove old partitions 1995 if (!g_text_mode) { 1996 newtResume(); 1997 } 1856 1998 log_msg(0, "Stopping all software RAID devices, just in case"); 1857 1999 stop_all_raid_devices(mountlist); 1858 2000 log_msg(0, "Done."); 1859 2001 1860 2002 /* 1861 2003 if (does_file_exist("/tmp/i-want-my-lvm")) … … 1865 2007 */ 1866 2008 1867 open_progress_form("Partitioning devices", "I am now going to partition all your drives.", 1868 "This should not take more than five minutes.", "", mountlist->entries); 2009 open_progress_form("Partitioning devices", 2010 "I am now going to partition all your drives.", 2011 "This should not take more than five minutes.", "", 2012 mountlist->entries); 1869 2013 1870 2014 make_list_of_drives_in_mountlist(mountlist, drivelist); … … 1878 2022 if (retval) { 1879 2023 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 1880 log_to_screen("Errors occurred during the partitioning of your hard drives."); 2024 log_to_screen 2025 ("Errors occurred during the partitioning of your hard drives."); 1881 2026 } else { 1882 2027 mvaddstr_and_log_it(g_currentY++, 74, "Done."); … … 1904 2049 * @return 0 for success, nonzero for failure. 1905 2050 */ 1906 int set_partition_type(FILE *pout_to_fdisk, const char *drive, int partno, const char *format, long long partsize) 2051 int set_partition_type(FILE * pout_to_fdisk, const char *drive, int partno, 2052 const char *format, long long partsize) 1907 2053 { 1908 2054 /** buffers *********************************************************/ 1909 1910 1911 1912 1913 1914 2055 char *partition; 2056 char *command; 2057 char *output; 2058 char *tmp; 2059 char *partcode; 2060 char *logfile; 1915 2061 1916 2062 /** pointers *********************************************************/ … … 1926 2072 assert(format != NULL); 1927 2073 1928 1929 1930 1931 1932 1933 2074 malloc_string(partition); 2075 malloc_string(command); 2076 malloc_string(output); 2077 malloc_string(tmp); 2078 malloc_string(partcode); 2079 malloc_string(logfile); 1934 2080 1935 2081 build_partition_name(partition, drive, partno); … … 1944 2090 strcpy(partcode, "b"); 1945 2091 } 1946 } else if (strcmp(format, "ext2") == 0 || strcmp(format, "reiserfs") == 0 || strcmp(format, "ext3") == 0 1947 || strcmp(format, "xfs") == 0 || strcmp(format, "jfs") == 0) { 2092 } else if (strcmp(format, "ext2") == 0 2093 || strcmp(format, "reiserfs") == 0 2094 || strcmp(format, "ext3") == 0 || strcmp(format, "xfs") == 0 2095 || strcmp(format, "jfs") == 0) { 1948 2096 strcpy(partcode, "83"); 1949 2097 } else if (strcmp(format, "minix") == 0) { … … 1952 2100 strcpy(partcode, "fd"); 1953 2101 } else if ((strcmp(format, "ufs") == 0) 1954 || (strcmp(format, "ffs") == 0)) { /* raid autodetect */2102 || (strcmp(format, "ffs") == 0)) { /* raid autodetect */ 1955 2103 strcpy(partcode, "a5"); 1956 2104 } else if (strcmp(format, "lvm") == 0) { … … 1962 2110 } else { 1963 2111 /* probably an image */ 1964 sprintf(tmp, "Unknown format ('%s') - using supplied string anyway", format); 2112 sprintf(tmp, 2113 "Unknown format ('%s') - using supplied string anyway", 2114 format); 1965 2115 mvaddstr_and_log_it(g_currentY++, 0, tmp); 1966 2116 #ifdef __FreeBSD__ 1967 strcpy(partcode, format); 2117 strcpy(partcode, format); // was a5 1968 2118 #else 1969 strcpy(partcode, format); // was 83 1970 #endif 1971 } 1972 sprintf(tmp, "Setting %s's type to %s (%s)", partition, format, partcode); 2119 strcpy(partcode, format); // was 83 2120 #endif 2121 } 2122 sprintf(tmp, "Setting %s's type to %s (%s)", partition, format, 2123 partcode); 1973 2124 log_msg(1, tmp); 1974 2125 if (partcode[0] != '\0' && strcmp(partcode, "83")) { /* no need to set type if 83: 83 is default */ 1975 1976 if (pout_to_fdisk) 1977 { 2126 2127 if (pout_to_fdisk) { 1978 2128 res = 0; 1979 2129 fput_string_one_char_at_a_time(pout_to_fdisk, "t\n"); 1980 if (partno > 1 || strstr(last_line_of_file(FDISK_LOG), " (1-4)"))1981 {2130 if (partno > 1 2131 || strstr(last_line_of_file(FDISK_LOG), " (1-4)")) { 1982 2132 log_msg(5, "Specifying partno (%d) - yay", partno); 1983 2133 sprintf(tmp, "%d\n", partno); 1984 2134 fput_string_one_char_at_a_time(pout_to_fdisk, tmp); 1985 log_msg(5, "A - last line = '%s'", last_line_of_file(FDISK_LOG)); 1986 } 1987 2135 log_msg(5, "A - last line = '%s'", 2136 last_line_of_file(FDISK_LOG)); 2137 } 2138 1988 2139 sprintf(tmp, "%s\n", partcode); 1989 2140 fput_string_one_char_at_a_time(pout_to_fdisk, tmp); 1990 log_msg(5, "B - last line = '%s'", last_line_of_file(FDISK_LOG)); 2141 log_msg(5, "B - last line = '%s'", 2142 last_line_of_file(FDISK_LOG)); 1991 2143 fput_string_one_char_at_a_time(pout_to_fdisk, "\n"); 1992 log_msg(5, "C - last line = '%s'", last_line_of_file(FDISK_LOG)); 1993 2144 log_msg(5, "C - last line = '%s'", 2145 last_line_of_file(FDISK_LOG)); 2146 1994 2147 strcpy(tmp, last_line_of_file(FDISK_LOG)); 1995 if (!strstr(tmp, " (m ")) 1996 { 1997 log_msg(1, "last line = '%s'; part type set failed", tmp); 1998 res++; 1999 fput_string_one_char_at_a_time(pout_to_fdisk,"\n"); 2000 } 2001 fput_string_one_char_at_a_time(pout_to_fdisk,"p\n"); 2002 } 2003 else 2004 { 2148 if (!strstr(tmp, " (m ")) { 2149 log_msg(1, "last line = '%s'; part type set failed", tmp); 2150 res++; 2151 fput_string_one_char_at_a_time(pout_to_fdisk, "\n"); 2152 } 2153 fput_string_one_char_at_a_time(pout_to_fdisk, "p\n"); 2154 } else { 2005 2155 sprintf(output, "t\n%d\n%s\n", partno, partcode); 2006 2156 strcat(output, "w\n"); 2007 sprintf(command, "parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE, MONDO_LOGFILE); 2157 sprintf(command, "parted2fdisk %s >> %s 2>> %s", drive, 2158 MONDO_LOGFILE, MONDO_LOGFILE); 2008 2159 log_msg(5, "output = '%s'", output); 2009 2160 log_msg(5, "partno=%d; partcode=%s", partno, partcode); … … 2019 2170 } 2020 2171 } 2021 if (res) 2022 { 2023 log_OS_error(command); 2024 } 2025 } 2026 2027 paranoid_free(partition); 2028 paranoid_free(command); 2029 paranoid_free(output); 2030 paranoid_free(tmp); 2031 paranoid_free(partcode); 2032 paranoid_free(logfile); 2033 2034 return (res); 2172 if (res) { 2173 log_OS_error(command); 2174 } 2175 } 2176 2177 paranoid_free(partition); 2178 paranoid_free(command); 2179 paranoid_free(output); 2180 paranoid_free(tmp); 2181 paranoid_free(partcode); 2182 paranoid_free(logfile); 2183 2184 return (res); 2035 2185 } 2036 2186 … … 2049 2199 assert_string_is_neither_NULL_nor_zerolength(raid_device); 2050 2200 malloc_string(program); 2051 2201 2052 2202 #ifdef __FreeBSD__ 2053 2203 if (is_this_device_mounted(raid_device)) { … … 2062 2212 log_msg(1, "program = %s", program); 2063 2213 res = run_program_and_log_output(program, 1); 2064 if (g_fprep) { fprintf(g_fprep, "%s\n", program); } 2065 if (res) { log_msg(1, "Warning - failed to start RAID device %s", raid_device); } 2214 if (g_fprep) { 2215 fprintf(g_fprep, "%s\n", program); 2216 } 2217 if (res) { 2218 log_msg(1, "Warning - failed to start RAID device %s", 2219 raid_device); 2220 } 2066 2221 retval += res; 2067 2222 sleep(1); … … 2089 2244 assert_string_is_neither_NULL_nor_zerolength(raid_device); 2090 2245 malloc_string(program); 2091 2246 2092 2247 #ifdef __FreeBSD__ 2093 2248 if (is_this_device_mounted(raid_device)) { … … 2102 2257 log_msg(1, "program = %s", program); 2103 2258 res = run_program_and_log_output(program, 1); 2104 if (g_fprep) { fprintf(g_fprep, "%s\n", program); } 2105 if (res) { log_msg(1, "Warning - failed to stop RAID device %s", raid_device); } 2259 if (g_fprep) { 2260 fprintf(g_fprep, "%s\n", program); 2261 } 2262 if (res) { 2263 log_msg(1, "Warning - failed to stop RAID device %s", raid_device); 2264 } 2106 2265 retval += res; 2107 2266 return (retval); … … 2112 2271 { 2113 2272 int i; 2114 int retval =0;2273 int retval = 0; 2115 2274 int res; 2116 2117 for(i=0; i<mountlist->entries; i++) 2118 { 2119 if (!strncmp(mountlist->el[i].device, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) 2120 { 2121 log_msg(1, "Starting %s", mountlist->el[i].device); 2122 res = start_raid_device(mountlist->el[i].device); 2123 retval += res; 2124 } 2125 } 2126 if (retval) { log_msg(1, "Started all s/w raid devices OK"); } 2127 else { log_msg(1, "Failed to start some/all s/w raid devices"); } 2128 return(retval); 2275 2276 for (i = 0; i < mountlist->entries; i++) { 2277 if (!strncmp 2278 (mountlist->el[i].device, RAID_DEVICE_STUB, 2279 strlen(RAID_DEVICE_STUB))) { 2280 log_msg(1, "Starting %s", mountlist->el[i].device); 2281 res = start_raid_device(mountlist->el[i].device); 2282 retval += res; 2283 } 2284 } 2285 if (retval) { 2286 log_msg(1, "Started all s/w raid devices OK"); 2287 } else { 2288 log_msg(1, "Failed to start some/all s/w raid devices"); 2289 } 2290 return (retval); 2129 2291 } 2130 2292 … … 2163 2325 for (i = 0; i < 3; i++) { 2164 2326 #ifdef __FreeBSD__ 2165 fin = popen("vinum list | grep '^[PVS]' | sed 's/S/1/;s/P/2/;s/V/3/' | sort | cut -d' ' -f2", "r"); 2327 fin = 2328 popen 2329 ("vinum list | grep '^[PVS]' | sed 's/S/1/;s/P/2/;s/V/3/' | sort | cut -d' ' -f2", 2330 "r"); 2166 2331 if (!fin) { 2167 2332 paranoid_free(dev); … … 2169 2334 return (1); 2170 2335 } 2171 for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin); fgets(incoming, MAX_STR_LEN - 1, fin)) { 2336 for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin); 2337 fgets(incoming, MAX_STR_LEN - 1, fin)) { 2172 2338 retval += stop_raid_device(incoming); 2173 2339 } … … 2180 2346 return (1); 2181 2347 } 2182 for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin); fgets(incoming, MAX_STR_LEN - 1, fin)) { 2183 for (p = incoming; *p != '\0' && (*p != 'm' || *(p + 1) != 'd' || !isdigit(*(p + 2))); p++); 2348 for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin); 2349 fgets(incoming, MAX_STR_LEN - 1, fin)) { 2350 for (p = incoming; 2351 *p != '\0' && (*p != 'm' || *(p + 1) != 'd' 2352 || !isdigit(*(p + 2))); p++); 2184 2353 if (*p != '\0') { 2185 2354 sprintf(dev, "/dev/%s", p); … … 2192 2361 } 2193 2362 paranoid_fclose(fin); 2194 if (retval) { log_msg(1, "Warning - unable to stop some RAID devices"); } 2363 if (retval) { 2364 log_msg(1, "Warning - unable to stop some RAID devices"); 2365 } 2195 2366 paranoid_free(dev); 2196 2367 paranoid_free(incoming); 2197 system("sync"); system("sync"); system("sync"); 2368 system("sync"); 2369 system("sync"); 2370 system("sync"); 2198 2371 sleep(1); 2199 2372 return (retval); … … 2250 2423 sprintf(program, "mkfs -t %s -c", format); // -c checks for bad blocks 2251 2424 #endif 2252 sprintf(tmp, "Unknown format (%s) - assuming '%s' will do", format, program); 2425 sprintf(tmp, "Unknown format (%s) - assuming '%s' will do", format, 2426 program); 2253 2427 log_it(tmp); 2254 2428 res = 0; … … 2267 2441 */ 2268 2442 long calc_orig_size_of_drive_from_mountlist(struct mountlist_itself 2269 2443 *mountlist, char *drive_name) 2270 2444 { 2271 2445 /** long ************************************************************/ … … 2284 2458 assert_string_is_neither_NULL_nor_zerolength(drive_name); 2285 2459 2286 for (original_size_of_drive = 0, partno = 0; partno < mountlist->entries; partno++) { 2287 if (strncmp(mountlist->el[partno].device, drive_name, strlen(drive_name)) == 0) { 2460 for (original_size_of_drive = 0, partno = 0; 2461 partno < mountlist->entries; partno++) { 2462 if (strncmp 2463 (mountlist->el[partno].device, drive_name, 2464 strlen(drive_name)) == 0) { 2288 2465 original_size_of_drive += mountlist->el[partno].size; 2289 2466 } else { … … 2310 2487 */ 2311 2488 void resize_drive_proportionately_to_suit_new_drives(struct mountlist_itself 2312 *mountlist, char *drive_name) 2489 *mountlist, 2490 char *drive_name) 2313 2491 { 2314 2492 /**buffers **********************************************************/ … … 2317 2495 /** int *************************************************************/ 2318 2496 int partno, lastpart; 2319 2497 /** remove driveno, noof_drives stan benoit apr 2002**/ 2320 2498 2321 2499 /** float ***********************************************************/ 2322 2500 float factor; 2323 2501 float new_size; 2324 // 2502 // float newcylinderno; 2325 2503 2326 2504 /** long *************************************************************/ … … 2328 2506 long current_size_of_drive = 0; 2329 2507 long original_size_of_drive = 0; 2330 long final_size; /* all in Megabytes */2508 long final_size; /* all in Megabytes */ 2331 2509 struct mountlist_reference *drivemntlist; 2332 2510 … … 2340 2518 2341 2519 if (strlen(drive_name) >= strlen(RAID_DEVICE_STUB)) { 2342 if (strncmp(drive_name, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB)) == 0) { 2520 if (strncmp(drive_name, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB)) 2521 == 0) { 2343 2522 paranoid_free(tmp); 2344 2523 return; … … 2352 2531 2353 2532 current_size_of_drive = get_phys_size_of_drive(drive_name); 2354 2533 2355 2534 if (current_size_of_drive <= 0) { 2356 2535 log_it("Not resizing to match %s - can't find drive", drive_name); … … 2358 2537 return; 2359 2538 } 2360 sprintf(tmp, "Expanding entries to suit drive %s (%ld MB)", drive_name, current_size_of_drive); 2539 sprintf(tmp, "Expanding entries to suit drive %s (%ld MB)", drive_name, 2540 current_size_of_drive); 2361 2541 log_to_screen(tmp); 2362 2542 2363 drivemntlist = malloc(sizeof (struct mountlist_reference)); 2364 drivemntlist->el = malloc(sizeof(struct mountlist_line *) * MAX_TAPECATALOG_ENTRIES); 2543 drivemntlist = malloc(sizeof(struct mountlist_reference)); 2544 drivemntlist->el = 2545 malloc(sizeof(struct mountlist_line *) * MAX_TAPECATALOG_ENTRIES); 2365 2546 2366 2547 if (!drivemntlist) { … … 2375 2556 2376 2557 if (original_size_of_drive <= 0) { 2377 sprintf(tmp, "Cannot resize %s's entries. Drive not found.", drive_name); 2558 sprintf(tmp, "Cannot resize %s's entries. Drive not found.", 2559 drive_name); 2378 2560 log_to_screen(tmp); 2379 2561 paranoid_free(tmp); 2380 2562 return; 2381 2563 } 2382 factor = (float) (current_size_of_drive) / (float) (original_size_of_drive); 2383 sprintf(tmp, "Disk %s was %ld MB; is now %ld MB; factor = %f", drive_name, original_size_of_drive, current_size_of_drive, 2384 factor); 2564 factor = 2565 (float) (current_size_of_drive) / (float) (original_size_of_drive); 2566 sprintf(tmp, "Disk %s was %ld MB; is now %ld MB; factor = %f", 2567 drive_name, original_size_of_drive, current_size_of_drive, 2568 factor); 2385 2569 log_to_screen(tmp); 2386 2570 2387 lastpart = drivemntlist->entries -1;2571 lastpart = drivemntlist->entries - 1; 2388 2572 for (partno = 0; partno < drivemntlist->entries; partno++) { 2389 2573 /* the 'atoi' thing is to make sure we don't try to resize _images_, whose formats will be numeric */ 2390 if ( !atoi(drivemntlist->el[partno]->format)) {2574 if (!atoi(drivemntlist->el[partno]->format)) { 2391 2575 new_size = (float) (drivemntlist->el[partno]->size) * factor; 2392 2576 } else { 2393 2577 new_size = drivemntlist->el[partno]->size; 2394 2578 } 2395 2579 2396 2580 if (!strcmp(drivemntlist->el[partno]->mountpoint, "image")) { 2397 2581 log_msg(1, "Skipping %s (%s) because it's an image", 2398 2399 2400 newsizL = (long) new_size; 2582 drivemntlist->el[partno]->device, 2583 drivemntlist->el[partno]->mountpoint); 2584 newsizL = (long) new_size; // It looks wrong but it's not 2401 2585 } else { 2402 2586 newsizL = (long) new_size; 2403 2587 } 2404 sprintf(tmp, "Changing %s from %lld KB to %ld KB", drivemntlist->el[partno]->device, drivemntlist->el[partno]->size,newsizL); 2588 sprintf(tmp, "Changing %s from %lld KB to %ld KB", 2589 drivemntlist->el[partno]->device, 2590 drivemntlist->el[partno]->size, newsizL); 2405 2591 log_to_screen(tmp); 2406 2592 drivemntlist->el[partno]->size = newsizL; … … 2420 2606 */ 2421 2607 void resize_mountlist_proportionately_to_suit_new_drives(struct mountlist_itself 2422 *mountlist)2608 *mountlist) 2423 2609 { 2424 2610 /** buffers *********************************************************/ … … 2434 2620 2435 2621 if (g_mountlist_fname[0] == '\0') { 2436 log_it ("resize_mountlist_prop...() - warning - mountlist fname is blank"); 2437 log_it ("That does NOT affect the functioning of this subroutine."); 2438 log_it ("--- Hugo, 2002/11/20"); 2622 log_it 2623 ("resize_mountlist_prop...() - warning - mountlist fname is blank"); 2624 log_it("That does NOT affect the functioning of this subroutine."); 2625 log_it("--- Hugo, 2002/11/20"); 2439 2626 } 2440 2627 iamhere("Resizing mountlist"); … … 2442 2629 iamhere("Back from MLoDiM"); 2443 2630 for (driveno = 0; driveno < drivelist->entries; driveno++) { 2444 resize_drive_proportionately_to_suit_new_drives(mountlist, drivelist->el[driveno].device); 2631 resize_drive_proportionately_to_suit_new_drives(mountlist, 2632 drivelist-> 2633 el[driveno]. 2634 device); 2445 2635 } 2446 2636 log_to_screen("Mountlist adjusted to suit current hard drive(s)"); … … 2456 2646 * @author Ralph Grewe 2457 2647 */ 2458 void create_mountlist_for_drive(struct mountlist_itself *mountlist, char *drive_name, struct mountlist_reference *drivemntlist) { 2648 void create_mountlist_for_drive(struct mountlist_itself *mountlist, 2649 char *drive_name, 2650 struct mountlist_reference *drivemntlist) 2651 { 2459 2652 int partno; 2460 2653 char *tmp_drive_name, *c; … … 2464 2657 assert(drivemntlist != NULL); 2465 2658 2466 log_msg (1, "Creating list of partitions for drive %s",drive_name); 2467 2468 tmp_drive_name = strdup (drive_name); 2469 if (!tmp_drive_name) fatal_error ("Out of memory"); 2470 2659 log_msg(1, "Creating list of partitions for drive %s", drive_name); 2660 2661 tmp_drive_name = strdup(drive_name); 2662 if (!tmp_drive_name) 2663 fatal_error("Out of memory"); 2664 2471 2665 /* devfs devices? */ 2472 c = strrchr 2473 if (c && strncmp 2474 2475 strcpy(c + 1, "part");2476 } 2477 drivemntlist->entries =0;2666 c = strrchr(tmp_drive_name, '/'); 2667 if (c && strncmp(c, "/disc", 5) == 0) { 2668 /* yup its devfs, change the "disc" to "part" so the existing code works */ 2669 strcpy(c + 1, "part"); 2670 } 2671 drivemntlist->entries = 0; 2478 2672 for (partno = 0; partno < mountlist->entries; partno++) { 2479 if (strncmp (mountlist->el[partno].device, tmp_drive_name, strlen(tmp_drive_name)) == 0) { 2480 drivemntlist->el[drivemntlist->entries] = &mountlist->el[partno]; 2673 if (strncmp 2674 (mountlist->el[partno].device, tmp_drive_name, 2675 strlen(tmp_drive_name)) == 0) { 2676 drivemntlist->el[drivemntlist->entries] = 2677 &mountlist->el[partno]; 2481 2678 drivemntlist->entries++; 2482 2679 } 2483 2680 } 2484 2681 if (tmp_drive_name) 2485 free(tmp_drive_name);2682 free(tmp_drive_name); 2486 2683 } 2487 2684
Note:
See TracChangeset
for help on using the changeset viewer.