Changeset 59 in MondoRescue for trunk/mondo/mondo/mondorestore/mondo-prep.c
- Timestamp:
- Oct 11, 2005, 1:34:31 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mondo/mondo/mondorestore/mondo-prep.c
r30 r59 8 8 edited by : by Stan Benoit 4/2002 9 9 email : troff@nakedsoul.org 10 cvsid : $Id : mondo-prep.c,v 1.14 2004/06/21 20:20:36 hugo Exp$10 cvsid : $Id$ 11 11 ***************************************************************************/ 12 12 … … 181 181 #define MONDO_WAS_HERE "MONDOWOZEREMONDOWOZEREMONDOWOZEREhahahaMOJOJOJO" 182 182 183 //static char cvsid[] = "$Id : mondo-prep.c,v 1.14 2004/06/21 20:20:36 hugo Exp$";183 //static char cvsid[] = "$Id$"; 184 184 185 185 extern char *g_mountlist_fname; … … 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 ("cat /var/log/mondo-archive.log | tail -n5 | grep Insufficient | tail -n1")); 481 } 482 else 483 { 484 strcpy(tmp, call_program_and_get_last_line_of_output 485 ("cat /var/log/mondo-archive.log | tail -n5 | 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 ("cat /var/log/mondo-archive.log | tail -n5 | grep Insufficient | tail -n1")); 491 } else { 492 strcpy(tmp, call_program_and_get_last_line_of_output 493 ("cat /var/log/mondo-archive.log | tail -n5 | 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); … … 837 888 #endif 838 889 res = run_program_and_log_output(program, FALSE); 839 if (g_fprep) { fprintf(g_fprep, "%s\n", program); } 890 if (g_fprep) { 891 fprintf(g_fprep, "%s\n", program); 892 } 840 893 } 841 894 retval += res; … … 847 900 848 901 log_to_screen(tmp); 849 paranoid_free(program); paranoid_free(tmp); 850 system("sync"); sleep(1); 902 paranoid_free(program); 903 paranoid_free(tmp); 904 system("sync"); 905 sleep(1); 851 906 return (retval); 852 907 } … … 862 917 * @return The number of errors encountered (0 for success). 863 918 */ 864 int format_everything(struct mountlist_itself *mountlist, bool interactively) 919 int format_everything(struct mountlist_itself *mountlist, 920 bool interactively) 865 921 { 866 922 /** int **************************************************************/ … … 868 924 int lino; 869 925 int res; 870 // 871 // 926 // int i; 927 // struct list_of_disks *drivelist; 872 928 873 929 /** long *************************************************************/ … … 884 940 /** end **************************************************************/ 885 941 886 assert(mountlist !=NULL);942 assert(mountlist != NULL); 887 943 malloc_string(tmp); 888 sprintf(tmp, "format_everything (mountlist, interactively = %s", (interactively) ? "true" : "false"); 944 sprintf(tmp, "format_everything (mountlist, interactively = %s", 945 (interactively) ? "true" : "false"); 889 946 log_it(tmp); 890 947 mvaddstr_and_log_it(g_currentY, 0, "Formatting partitions "); 891 open_progress_form("Formatting partitions", "I am now formatting your hard disk partitions.", 892 "This may take up to five minutes.", "", mountlist->entries + 1); 893 894 progress_step = (mountlist->entries > 0) ? g_maximum_progress / mountlist->entries : 1; 948 open_progress_form("Formatting partitions", 949 "I am now formatting your hard disk partitions.", 950 "This may take up to five minutes.", "", 951 mountlist->entries + 1); 952 953 progress_step = 954 (mountlist->entries > 955 0) ? g_maximum_progress / mountlist->entries : 1; 895 956 // start soft-raids now (because LVM might depend on them) 896 957 // ...and for simplicity's sake, let's format them at the same time :) 897 958 log_msg(1, "Stopping all RAID devices"); 898 959 stop_all_raid_devices(mountlist); 899 system("sync"); system("sync"); system("sync"); 960 system("sync"); 961 system("sync"); 962 system("sync"); 900 963 sleep(2); 901 log_msg(1, "Prepare soft-RAIDs"); 964 log_msg(1, "Prepare soft-RAIDs"); // prep and format too 902 965 for (lino = 0; lino < mountlist->entries; lino++) { 903 966 me = &mountlist->el[lino]; // the current mountlist entry … … 906 969 if (interactively) { 907 970 // ask user if we should format the current device 908 sprintf(tmp, "Shall I format %s (%s) ?", me->device, me->mountpoint); 971 sprintf(tmp, "Shall I format %s (%s) ?", me->device, 972 me->mountpoint); 909 973 do_it = ask_me_yes_or_no(tmp); 910 974 } else { … … 912 976 } 913 977 if (do_it) { 914 // NB: format_device() also stops/starts RAID device if necessary978 // NB: format_device() also stops/starts RAID device if necessary 915 979 retval += format_device(me->device, me->format); 916 980 } … … 918 982 } 919 983 } 920 system("sync"); system("sync"); system("sync"); 984 system("sync"); 985 system("sync"); 986 system("sync"); 921 987 sleep(2); 922 988 // This last step is probably necessary 923 // 924 // 925 // 926 // 989 // log_to_screen("Re-starting software RAIDs..."); 990 // start_all_raid_devices(mountlist); 991 // system("sync"); system("sync"); system("sync"); 992 // sleep(5); 927 993 // do LVMs now 928 994 log_msg(1, "Creating LVMs"); … … 930 996 wait_until_software_raids_are_prepped("/proc/mdstat", 10); 931 997 log_to_screen("Configuring LVM"); 932 if (!g_text_mode) { newtSuspend(); } 998 if (!g_text_mode) { 999 newtSuspend(); 1000 } 933 1001 /* 934 1002 for(i=0; i<3; i++) … … 943 1011 log_msg(1, "Vacuum-packing..."); 944 1012 */ 945 1013 res = do_my_funky_lvm_stuff(FALSE, TRUE); 946 1014 /* 947 1015 } 948 1016 */ 949 if (!g_text_mode) { newtResume(); } 950 if (!res) { log_to_screen("LVM initialized OK"); } 951 else { log_to_screen("Failed to initialize LVM"); } 1017 if (!g_text_mode) { 1018 newtResume(); 1019 } 1020 if (!res) { 1021 log_to_screen("LVM initialized OK"); 1022 } else { 1023 log_to_screen("Failed to initialize LVM"); 1024 } 952 1025 // retval += res; 953 1026 if (res) { 954 retval ++; 955 } 956 sleep(3); 957 } 958 1027 retval++; 1028 } 1029 sleep(3); 1030 } 959 1031 // do regulars at last 960 sleep(2); 961 1032 sleep(2); // woo! 1033 log_msg(1, "Formatting regulars"); 962 1034 for (lino = 0; lino < mountlist->entries; lino++) { 963 1035 me = &mountlist->el[lino]; // the current mountlist entry … … 966 1038 log_it(tmp); 967 1039 } else if (!strcmp(me->format, "raid")) { 968 sprintf(tmp, "Not formatting %s - it's a raid-let", me->device); 1040 sprintf(tmp, "Not formatting %s - it's a raid-let", 1041 me->device); 969 1042 log_it(tmp); 970 1043 continue; … … 974 1047 continue; 975 1048 } else if (!strncmp(me->device, "/dev/md", 7)) { 976 sprintf(tmp, "Already formatted %s - it's a soft-RAID dev", me->device); 1049 sprintf(tmp, "Already formatted %s - it's a soft-RAID dev", 1050 me->device); 977 1051 log_it(tmp); 978 1052 continue; 979 1053 } else if (!does_file_exist(me->device) 980 && strncmp(me->device, "/dev/hd", 7) 981 && strncmp(me->device, "/dev/sd", 7)) { 982 sprintf(tmp, "Not formatting %s yet - doesn't exist - probably an LVM", me->device); 1054 && strncmp(me->device, "/dev/hd", 7) 1055 && strncmp(me->device, "/dev/sd", 7)) { 1056 sprintf(tmp, 1057 "Not formatting %s yet - doesn't exist - probably an LVM", 1058 me->device); 983 1059 log_it(tmp); 984 1060 continue; … … 986 1062 if (interactively) { 987 1063 // ask user if we should format the current device 988 sprintf(tmp, "Shall I format %s (%s) ?", me->device, me->mountpoint); 1064 sprintf(tmp, "Shall I format %s (%s) ?", me->device, 1065 me->mountpoint); 989 1066 do_it = ask_me_yes_or_no(tmp); 990 1067 } else { … … 1010 1087 if (retval) { 1011 1088 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 1012 log_to_screen("Errors occurred during the formatting of your hard drives."); 1089 log_to_screen 1090 ("Errors occurred during the formatting of your hard drives."); 1013 1091 } else { 1014 1092 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 1015 1093 } 1016 1094 1017 sprintf(tmp, "format_everything () - %s", (retval) ? "failed!" : "finished successfully"); 1095 sprintf(tmp, "format_everything () - %s", 1096 (retval) ? "failed!" : "finished successfully"); 1018 1097 log_it(tmp); 1019 1098 1020 if (g_partition_table_locked_up > 0) 1021 { 1022 if (retval > 0 && !interactively) 1023 { 1099 if (g_partition_table_locked_up > 0) { 1100 if (retval > 0 && !interactively) { 1024 1101 //123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1025 log_to_screen( 1026 "Partition table locked up %d times. At least one 'mkfs' (format) command", g_partition_table_locked_up); 1027 log_to_screen( 1028 "failed. I think these two events are related. Sometimes, fdisk's ioctl() call"); 1029 log_to_screen( 1030 "to refresh its copy of the partition table causes the kernel to lock the "); 1031 log_to_screen( 1032 "partition table. I believe this has just happened."); 1033 if (ask_me_yes_or_no("Please choose 'yes' to reboot and try again; or 'no' to ignore this warning and continue.")) 1034 { 1035 system("sync"); 1036 system("sync"); 1037 system("sync"); 1038 system("reboot"); 1039 } 1040 } 1041 else 1042 { 1043 log_to_screen( 1044 "Partition table locked up %d time%c. However, disk formatting succeeded.", g_partition_table_locked_up, (g_partition_table_locked_up==1)?'.':'s'); 1045 } 1046 } 1047 newtSuspend(); 1102 log_to_screen 1103 ("Partition table locked up %d times. At least one 'mkfs' (format) command", 1104 g_partition_table_locked_up); 1105 log_to_screen 1106 ("failed. I think these two events are related. Sometimes, fdisk's ioctl() call"); 1107 log_to_screen 1108 ("to refresh its copy of the partition table causes the kernel to lock the "); 1109 log_to_screen 1110 ("partition table. I believe this has just happened."); 1111 if (ask_me_yes_or_no 1112 ("Please choose 'yes' to reboot and try again; or 'no' to ignore this warning and continue.")) 1113 { 1114 system("sync"); 1115 system("sync"); 1116 system("sync"); 1117 system("reboot"); 1118 } 1119 } else { 1120 log_to_screen 1121 ("Partition table locked up %d time%c. However, disk formatting succeeded.", 1122 g_partition_table_locked_up, 1123 (g_partition_table_locked_up == 1) ? '.' : 's'); 1124 } 1125 } 1126 newtSuspend(); 1048 1127 system("clear"); 1049 1128 newtResume(); … … 1061 1140 * @return The number of errors encountered (0 for success). 1062 1141 */ 1063 int make_dummy_partitions(FILE*pout_to_fdisk, char *drivename, int devno_we_must_allow_for) 1142 int make_dummy_partitions(FILE * pout_to_fdisk, char *drivename, 1143 int devno_we_must_allow_for) 1064 1144 { 1065 1145 /** int **************************************************************/ … … 1081 1161 log_it(tmp); 1082 1162 g_maximum_progress++; 1083 res = partition_device(pout_to_fdisk,drivename, 1, 0, "ext2", 32000); 1163 res = 1164 partition_device(pout_to_fdisk, drivename, 1, 0, "ext2", 1165 32000); 1084 1166 retval += res; 1085 1167 previous_devno = 1; … … 1090 1172 } 1091 1173 for (; current_devno < devno_we_must_allow_for; current_devno++) { 1092 sprintf(tmp, "Creating dummy partition %s%d", drivename, current_devno); 1174 sprintf(tmp, "Creating dummy partition %s%d", drivename, 1175 current_devno); 1093 1176 log_it(tmp); 1094 1177 g_maximum_progress++; 1095 res = partition_device(pout_to_fdisk,drivename, current_devno, previous_devno, OSSWAP("ext2", "ufs"), 32000); 1178 res = 1179 partition_device(pout_to_fdisk, drivename, current_devno, 1180 previous_devno, OSSWAP("ext2", "ufs"), 32000); 1096 1181 retval += res; 1097 1182 previous_devno = current_devno; … … 1141 1226 else 1142 1227 fprintf(f, "type: %u\n", lp->d_type); 1143 fprintf(f, "disk: %.*s\n", (int) sizeof(lp->d_typename), lp->d_typename); 1144 fprintf(f, "label: %.*s\n", (int) sizeof(lp->d_packname), lp->d_packname); 1228 fprintf(f, "disk: %.*s\n", (int) sizeof(lp->d_typename), 1229 lp->d_typename); 1230 fprintf(f, "label: %.*s\n", (int) sizeof(lp->d_packname), 1231 lp->d_packname); 1145 1232 fprintf(f, "flags:"); 1146 1233 if (lp->d_flags & D_REMOVABLE) … … 1161 1248 fprintf(f, "trackskew: %u\n", lp->d_trackskew); 1162 1249 fprintf(f, "cylinderskew: %u\n", lp->d_cylskew); 1163 fprintf(f, "headswitch: %lu\t\t# milliseconds\n", (u_long) lp->d_headswitch); 1164 fprintf(f, "track-to-track seek: %ld\t# milliseconds\n", (u_long) lp->d_trkseek); 1250 fprintf(f, "headswitch: %lu\t\t# milliseconds\n", 1251 (u_long) lp->d_headswitch); 1252 fprintf(f, "track-to-track seek: %ld\t# milliseconds\n", 1253 (u_long) lp->d_trkseek); 1165 1254 fprintf(f, "drivedata: "); 1166 1255 for (i = NDDATA - 1; i >= 0; i--) … … 1172 1261 fprintf(f, "%lu ", (u_long) lp->d_drivedata[j]); 1173 1262 fprintf(f, "\n\n%u partitions:\n", lp->d_npartitions); 1174 fprintf(f, "# size offset fstype [fsize bsize bps/cpg]\n"); 1263 fprintf(f, 1264 "# size offset fstype [fsize bsize bps/cpg]\n"); 1175 1265 pp = lp->d_partitions; 1176 1266 for (i = 0; i < lp->d_npartitions; i++, pp++) { 1177 1267 if (pp->p_size) { 1178 fprintf(f, " %c: %8lu %8lu ", 'a' + i, (u_long) pp->p_size, (u_long) pp->p_offset); 1268 fprintf(f, " %c: %8lu %8lu ", 'a' + i, (u_long) pp->p_size, 1269 (u_long) pp->p_offset); 1179 1270 if (pp->p_fstype < FSMAXTYPES) 1180 1271 fprintf(f, "%8.8s", fstypenames[pp->p_fstype]); … … 1184 1275 1185 1276 case FS_UNUSED: /* XXX */ 1186 fprintf(f, " %5lu %5lu %5.5s ", (u_long) pp->p_fsize, (u_long) (pp->p_fsize * pp->p_frag), ""); 1277 fprintf(f, " %5lu %5lu %5.5s ", (u_long) pp->p_fsize, 1278 (u_long) (pp->p_fsize * pp->p_frag), ""); 1187 1279 break; 1188 1280 1189 1281 case FS_BSDFFS: 1190 fprintf(f, " %5lu %5lu %5u ", (u_long) pp->p_fsize, (u_long) (pp->p_fsize * pp->p_frag),1191 pp->p_cpg);1282 fprintf(f, " %5lu %5lu %5u ", (u_long) pp->p_fsize, 1283 (u_long) (pp->p_fsize * pp->p_frag), pp->p_cpg); 1192 1284 break; 1193 1285 1194 1286 case FS_BSDLFS: 1195 fprintf(f, " %5lu %5lu %5d", (u_long) pp->p_fsize, (u_long) (pp->p_fsize * pp->p_frag),1196 pp->p_cpg);1287 fprintf(f, " %5lu %5lu %5d", (u_long) pp->p_fsize, 1288 (u_long) (pp->p_fsize * pp->p_frag), pp->p_cpg); 1197 1289 break; 1198 1290 … … 1201 1293 break; 1202 1294 } 1203 fprintf(f, "\t# (Cyl. %4lu", (u_long) (pp->p_offset / lp->d_secpercyl)); 1295 fprintf(f, "\t# (Cyl. %4lu", 1296 (u_long) (pp->p_offset / lp->d_secpercyl)); 1204 1297 if (pp->p_offset % lp->d_secpercyl) 1205 1298 putc('*', f); 1206 1299 else 1207 1300 putc(' ', f); 1208 fprintf(f, "- %lu", (u_long) ((pp->p_offset + pp->p_size + lp->d_secpercyl - 1) / lp->d_secpercyl - 1)); 1301 fprintf(f, "- %lu", 1302 (u_long) ((pp->p_offset + pp->p_size + 1303 lp->d_secpercyl - 1) / lp->d_secpercyl - 1304 1)); 1209 1305 if (pp->p_size % lp->d_secpercyl) 1210 1306 putc('*', f); … … 1232 1328 /* New world order */ 1233 1329 if ((ioctl(f, DIOCGMEDIASIZE, &mediasize) != 0) 1234 1330 || (ioctl(f, DIOCGSECTORSIZE, &secsize) != 0)) { 1235 1331 close(f); 1236 1332 return (NULL); … … 1276 1372 return (&loclab); 1277 1373 } 1374 1278 1375 /* End stolen from /usr/src/sbin/disklabel/disklabel.c. */ 1279 1376 … … 1295 1392 * @return The number of errors encountered (0 for success). 1296 1393 */ 1297 int label_drive_or_slice(struct mountlist_itself *mountlist, char *drivename, struct disklabel *ret) 1394 int label_drive_or_slice(struct mountlist_itself *mountlist, 1395 char *drivename, struct disklabel *ret) 1298 1396 { 1299 1397 char subdev_str[MAX_STR_LEN]; … … 1319 1417 lp->d_partitions[c - 'a'].p_cpg = 0; 1320 1418 if (!strcmp(mountlist->el[idx].format, "ufs") 1321 1322 1419 || !strcmp(mountlist->el[idx].format, "ffs") 1420 || !strcmp(mountlist->el[idx].format, "4.2BSD")) { 1323 1421 lp->d_partitions[c - 'a'].p_fstype = FS_BSDFFS; 1324 1422 lp->d_partitions[c - 'a'].p_fsize = 2048; … … 1326 1424 lp->d_partitions[c - 'a'].p_cpg = 64; 1327 1425 } else if (!strcasecmp(mountlist->el[idx].format, "raid") 1328 || !strcasecmp(mountlist->el[idx].format, "vinum")) {1426 || !strcasecmp(mountlist->el[idx].format, "vinum")) { 1329 1427 lp->d_partitions[c - 'a'].p_fstype = FS_VINUM; 1330 1428 } else if (!strcmp(mountlist->el[idx].format, "swap")) { … … 1347 1445 for (lastone = i - 1; lastone >= 0; lastone--) { 1348 1446 if ((lp->d_partitions[lastone].p_size) 1349 1447 && (lastone != RAW_PART)) 1350 1448 break; 1351 1449 } 1352 lp->d_partitions[i].p_offset = lp->d_partitions[lastone].p_offset + lp->d_partitions[lastone].p_size; 1353 } 1354 if (lp->d_partitions[lo].p_offset + lp->d_partitions[lo].p_size > lp->d_secperunit) { 1355 lp->d_partitions[lo].p_size = lp->d_secperunit - lp->d_partitions[lo].p_offset; 1450 lp->d_partitions[i].p_offset = 1451 lp->d_partitions[lastone].p_offset + 1452 lp->d_partitions[lastone].p_size; 1453 } 1454 if (lp->d_partitions[lo].p_offset + lp->d_partitions[lo].p_size > 1455 lp->d_secperunit) { 1456 lp->d_partitions[lo].p_size = 1457 lp->d_secperunit - lp->d_partitions[lo].p_offset; 1356 1458 } 1357 1459 … … 1361 1463 sprintf(command, "disklabel -wr %s auto", canonical_name(drivename)); 1362 1464 retval += run_program_and_log_output(command, TRUE); 1363 sprintf(command, "disklabel -R %s /tmp/disklabel", canonical_name(drivename)); 1465 sprintf(command, "disklabel -R %s /tmp/disklabel", 1466 canonical_name(drivename)); 1364 1467 retval += run_program_and_log_output(command, TRUE); 1365 1468 if (ret) … … 1384 1487 int retval = 0; 1385 1488 int i; 1386 FILE *pout_to_fdisk=NULL;1387 1489 FILE *pout_to_fdisk = NULL; 1490 1388 1491 #ifdef __FreeBSD__ 1389 1492 bool fbsd_part = FALSE; … … 1407 1510 malloc_string(format); 1408 1511 malloc_string(tmp); 1409 1512 1410 1513 sprintf(tmp, "Partitioning drive %s", drivename); 1411 1514 log_it(tmp); 1412 1515 1413 #if __FreeBSD__ 1414 1516 #if __FreeBSD__ 1517 log_it("(Not opening fdisk now; that's the Linux guy's job)"); 1415 1518 pout_to_fdisk = NULL; 1416 1519 #else 1417 1520 make_hole_for_file(FDISK_LOG); 1418 1521 #ifdef __IA64__ 1419 sprintf(tmp, "parted2fdisk %s >> %s 2>> %s", drivename, FDISK_LOG, FDISK_LOG); 1522 sprintf(tmp, "parted2fdisk %s >> %s 2>> %s", drivename, FDISK_LOG, 1523 FDISK_LOG); 1420 1524 #else 1421 1525 sprintf(tmp, "fdisk %s >> %s 2>> %s", drivename, FDISK_LOG, FDISK_LOG); 1422 1526 #endif 1423 1527 pout_to_fdisk = popen(tmp, "w"); 1424 if (!pout_to_fdisk) { 1425 log_to_screen("Cannot call fdisk to configure %s", drivename); 1528 if (!pout_to_fdisk) { 1529 log_to_screen("Cannot call fdisk to configure %s", drivename); 1426 1530 paranoid_free(device_str); 1427 1531 paranoid_free(format); 1428 1532 paranoid_free(tmp); 1429 return (1);1533 return (1); 1430 1534 } 1431 1535 #endif … … 1445 1549 for (c = 'a'; c <= 'z'; c++) { 1446 1550 sprintf(subdev_str, "%s%c", drivename, c); 1447 if (find_device_in_mountlist(mountlist, subdev_str) > 0) { 1551 if (find_device_in_mountlist(mountlist, subdev_str) > 1552 0) { 1448 1553 fbsd_part = TRUE; 1449 1554 } … … 1451 1556 if (fbsd_part) { 1452 1557 int r = label_drive_or_slice(mountlist, 1453 1454 1558 drivename, 1559 0); 1455 1560 char command[MAX_STR_LEN]; 1456 sprintf(command, "disklabel -B %s", basename(drivename)); 1561 sprintf(command, "disklabel -B %s", 1562 basename(drivename)); 1457 1563 if (system(command)) { 1458 log_to_screen("Warning! Unable to make the drive bootable."); 1564 log_to_screen 1565 ("Warning! Unable to make the drive bootable."); 1459 1566 } 1460 1567 paranoid_free(device_str); … … 1501 1608 #if __FreeBSD__ 1502 1609 // FreeBSD doesn't let you write to blk devices in <512byte chunks. 1503 // 1504 // 1610 // sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename); 1611 // if (run_program_and_log_output(tmp, TRUE)) { 1505 1612 file = open(drivename, O_WRONLY); 1506 1613 if (!file) { 1507 sprintf(tmp, "Warning - unable to open %s for wiping it's partition table", drivename); 1614 sprintf(tmp, 1615 "Warning - unable to open %s for wiping it's partition table", 1616 drivename); 1508 1617 log_to_screen(tmp); 1509 1618 } 1510 1619 1511 for (i=0; i<512; i++) { 1512 if ( !write(file, "\0", 1) ) { 1513 sprintf(tmp, "Warning - unable to write to %s", drivename); 1620 for (i = 0; i < 512; i++) { 1621 if (!write(file, "\0", 1)) { 1622 sprintf(tmp, "Warning - unable to write to %s", 1623 drivename); 1514 1624 log_to_screen(tmp); 1515 1625 } … … 1518 1628 #else 1519 1629 iamhere("New, kernel-friendly partition remover"); 1520 for(i=20;i>0;i--) 1521 { 1522 fprintf(pout_to_fdisk, "d\n%d\n", i); 1523 fflush(pout_to_fdisk); 1524 } 1525 // sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename); 1526 // run_program_and_log_output(tmp, 1); 1527 #endif 1630 for (i = 20; i > 0; i--) { 1631 fprintf(pout_to_fdisk, "d\n%d\n", i); 1632 fflush(pout_to_fdisk); 1633 } 1634 // sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename); 1635 // run_program_and_log_output(tmp, 1); 1636 #endif 1528 1637 if (current_devno > 1) { 1529 previous_devno = make_dummy_partitions(pout_to_fdisk,drivename, current_devno); 1638 previous_devno = 1639 make_dummy_partitions(pout_to_fdisk, drivename, 1640 current_devno); 1530 1641 } 1531 1642 } … … 1534 1645 #endif 1535 1646 1536 strcpy(format, mountlist->el[lino].format);1537 partsize = mountlist->el[lino].size;1647 strcpy(format, mountlist->el[lino].format); 1648 partsize = mountlist->el[lino].size; 1538 1649 1539 1650 #ifdef __FreeBSD__ … … 1542 1653 1543 1654 if (current_devno == 5 && previous_devno == 4) { 1544 log_to_screen("You must leave at least one partition spare as the Extended partition."); 1655 log_to_screen 1656 ("You must leave at least one partition spare as the Extended partition."); 1545 1657 paranoid_free(device_str); 1546 1658 paranoid_free(format); … … 1549 1661 } 1550 1662 1551 retval += partition_device(pout_to_fdisk, drivename, current_devno, previous_devno, format, partsize); 1663 retval += 1664 partition_device(pout_to_fdisk, drivename, current_devno, 1665 previous_devno, format, partsize); 1552 1666 1553 1667 #ifdef __FreeBSD__ … … 1556 1670 retval += label_drive_or_slice(mountlist, device_str, 0); 1557 1671 if (system(tmp)) { 1558 log_to_screen("Warning! Unable to make the slice bootable."); 1672 log_to_screen 1673 ("Warning! Unable to make the slice bootable."); 1559 1674 } 1560 1675 } … … 1564 1679 } 1565 1680 1566 if (pout_to_fdisk) 1567 { 1681 if (pout_to_fdisk) { 1568 1682 // mark relevant partition as bootable 1569 sprintf(tmp, "a\n%s\n", call_program_and_get_last_line_of_output("make-me-bootable /tmp/mountlist.txt dummy")); 1683 sprintf(tmp, "a\n%s\n", 1684 call_program_and_get_last_line_of_output 1685 ("make-me-bootable /tmp/mountlist.txt dummy")); 1570 1686 fput_string_one_char_at_a_time(pout_to_fdisk, tmp); 1571 1687 // close fdisk 1572 1688 fput_string_one_char_at_a_time(pout_to_fdisk, "w\n"); 1573 1689 system("sync"); 1574 paranoid_pclose(pout_to_fdisk); 1575 log_msg(0, "------------------- fdisk.log looks like this ------------------"); 1690 paranoid_pclose(pout_to_fdisk); 1691 log_msg(0, 1692 "------------------- fdisk.log looks like this ------------------"); 1576 1693 sprintf(tmp, "cat %s >> %s", FDISK_LOG, MONDO_LOGFILE); 1577 1694 system(tmp); 1578 log_msg(0, "------------------- end of fdisk.log... word! ------------------"); 1695 log_msg(0, 1696 "------------------- end of fdisk.log... word! ------------------"); 1579 1697 sprintf(tmp, "tail -n6 %s | fgrep \"16: \"", FDISK_LOG); 1580 if (!run_program_and_log_output(tmp, 5)) 1581 {1582 g_partition_table_locked_up++;1583 log_to_screen("A flaw in the Linux kernel has locked the partition table.");1584 1698 if (!run_program_and_log_output(tmp, 5)) { 1699 g_partition_table_locked_up++; 1700 log_to_screen 1701 ("A flaw in the Linux kernel has locked the partition table."); 1702 } 1585 1703 } 1586 1704 paranoid_free(device_str); … … 1599 1717 * @return 0 for success, nonzero for failure. 1600 1718 */ 1601 int partition_device(FILE*pout_to_fdisk, const char *drive, int partno, int prev_partno, const char *format, long long partsize) 1719 int partition_device(FILE * pout_to_fdisk, const char *drive, int partno, 1720 int prev_partno, const char *format, 1721 long long partsize) 1602 1722 { 1603 1723 /** int **************************************************************/ … … 1624 1744 malloc_string(logfile); 1625 1745 malloc_string(output); 1626 1746 1627 1747 assert_string_is_neither_NULL_nor_zerolength(drive); 1628 1748 assert(format != NULL); 1629 1749 1630 log_it("partition_device('%s', %d, %d, '%s', %lld) --- starting", drive, partno, prev_partno, format, partsize); 1750 log_it("partition_device('%s', %d, %d, '%s', %lld) --- starting", 1751 drive, partno, prev_partno, format, partsize); 1631 1752 1632 1753 if (!strncmp(drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) { … … 1644 1765 sprintf(tmp, "Partitioning device %s (max size)", partition_name); 1645 1766 } else { 1646 sprintf(tmp, "Partitioning device %s (%lld MB)", partition_name, (long long) partsize / 1024); 1767 sprintf(tmp, "Partitioning device %s (%lld MB)", partition_name, 1768 (long long) partsize / 1024); 1647 1769 } 1648 1770 update_progress_form(tmp); … … 1650 1772 1651 1773 if (is_this_device_mounted(partition_name)) { 1652 sprintf(tmp, "%s is mounted, and should not be partitioned", partition_name); 1774 sprintf(tmp, "%s is mounted, and should not be partitioned", 1775 partition_name); 1653 1776 log_to_screen(tmp); 1654 1777 paranoid_free(program); … … 1671 1794 p = (char *) strrchr(partition_name, '/'); 1672 1795 sprintf(logfile, "/tmp/fdisk.log.%s", ++p); 1673 sprintf(program, "parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE, MONDO_LOGFILE); 1796 sprintf(program, "parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE, 1797 MONDO_LOGFILE); 1674 1798 1675 1799 output[0] = '\0'; … … 1681 1805 part_table_fmt = which_partition_format(drive); 1682 1806 /* GPT allows more than 4 primary partitions */ 1683 if ((prev_partno >= 4) && (strcmp(part_table_fmt,"MBR") == 0)) { 1684 log_to_screen("You need to leave at least one partition free, for 'extended/logical'"); 1807 if ((prev_partno >= 4) && (strcmp(part_table_fmt, "MBR") == 0)) { 1808 log_to_screen 1809 ("You need to leave at least one partition free, for 'extended/logical'"); 1685 1810 paranoid_free(program); 1686 1811 paranoid_free(partition_name); … … 1690 1815 return (1); 1691 1816 } else { 1692 sprintf(output + strlen(output), "n\ne\n%d\n\n\n", prev_partno + 1); 1817 sprintf(output + strlen(output), "n\ne\n%d\n\n\n", 1818 prev_partno + 1); 1693 1819 } 1694 1820 } … … 1697 1823 strcat(output + strlen(output), "\n"); /*start block (ENTER for next free blk */ 1698 1824 if (partsize > 0) { 1699 if (!strcmp(format, "7")) { log_msg(1, "Adding 512K, just in case"); partsize+=512; } 1825 if (!strcmp(format, "7")) { 1826 log_msg(1, "Adding 512K, just in case"); 1827 partsize += 512; 1828 } 1700 1829 sprintf(output + strlen(output), "+%lldK", (long long) (partsize)); 1701 1830 } … … 1714 1843 1715 1844 1716 if (pout_to_fdisk) 1717 { 1845 if (pout_to_fdisk) { 1718 1846 log_msg(1, "Doing the new all-in-one fdisk thing"); 1719 1847 log_msg(1, "output = '%s'", output); … … 1721 1849 fput_string_one_char_at_a_time(pout_to_fdisk, "\n\np\n"); 1722 1850 strcpy(tmp, last_line_of_file(FDISK_LOG)); 1723 if (strstr(tmp, " (m ")) 1724 { 1851 if (strstr(tmp, " (m ")) { 1725 1852 log_msg(1, "Successfully created %s%d", drive, partno); 1726 } 1727 else 1728 { 1853 } else { 1729 1854 log_msg(1, "last line = %s", tmp); 1730 log_msg(1, "Failed to create %s%d; sending 'Enter'...", drive, partno); 1731 } 1732 if (!retval) 1733 { 1734 log_msg(1, "Trying to set %s%d's partition type now", drive, partno); 1735 retval = set_partition_type(pout_to_fdisk, drive, partno, format, partsize); 1736 if (retval) 1737 { 1855 log_msg(1, "Failed to create %s%d; sending 'Enter'...", drive, 1856 partno); 1857 } 1858 if (!retval) { 1859 log_msg(1, "Trying to set %s%d's partition type now", drive, 1860 partno); 1861 retval = 1862 set_partition_type(pout_to_fdisk, drive, partno, format, 1863 partsize); 1864 if (retval) { 1738 1865 log_msg(1, "Failed. Trying again..."); 1739 retval = set_partition_type(pout_to_fdisk, drive, partno, format, partsize); 1740 } 1741 } 1742 if (retval) { log_msg(1, "...but failed to set type"); } 1743 } 1744 else 1745 { 1866 retval = 1867 set_partition_type(pout_to_fdisk, drive, partno, 1868 format, partsize); 1869 } 1870 } 1871 if (retval) { 1872 log_msg(1, "...but failed to set type"); 1873 } 1874 } else { 1746 1875 strcat(output, "w\n\n"); 1747 if (g_fprep) { fprintf(g_fprep, "echo \"%s\" | %s\n", output, program); } 1876 if (g_fprep) { 1877 fprintf(g_fprep, "echo \"%s\" | %s\n", output, program); 1878 } 1748 1879 /* write to disk; close fdisk's stream */ 1749 1880 if (!(fout = popen(program, "w"))) { … … 1756 1887 log_it("Vaccum-packing"); 1757 1888 g_current_progress--; 1758 res = partition_device(pout_to_fdisk, drive, partno, prev_partno, format, -1); 1889 res = 1890 partition_device(pout_to_fdisk, drive, partno, prev_partno, 1891 format, -1); 1759 1892 if (res) { 1760 1893 sprintf(tmp, "Failed to vacuum-pack %s", partition_name); … … 1766 1899 } 1767 1900 if (does_partition_exist(drive, partno)) { 1768 retval = set_partition_type(pout_to_fdisk, drive, partno, format, partsize); 1901 retval = 1902 set_partition_type(pout_to_fdisk, drive, partno, format, 1903 partsize); 1769 1904 if (retval) { 1770 sprintf(tmp, "Partitioned %s but failed to set its type", partition_name); 1905 sprintf(tmp, "Partitioned %s but failed to set its type", 1906 partition_name); 1771 1907 log_it(tmp); 1772 1908 } else { 1773 1909 if (partsize > 0) { 1774 sprintf(tmp, "Partition %s created+configured OK", partition_name); 1910 sprintf(tmp, "Partition %s created+configured OK", 1911 partition_name); 1775 1912 log_to_screen(tmp); 1776 1913 } else { … … 1778 1915 } 1779 1916 } 1780 1917 } else { 1781 1918 sprintf(tmp, "Failed to partition %s", partition_name); 1782 1919 if (partsize > 0) { … … 1830 1967 /* mountlist=&new_mtlist; */ 1831 1968 /* extrapolate_mountlist_to_include_raid_partitions(mountlist,orig_mtlist); */ 1832 log_msg(0,"Mountlist, including the partitions incorporated in RAID devices:-"); 1969 log_msg(0, 1970 "Mountlist, including the partitions incorporated in RAID devices:-"); 1833 1971 for (i = 0; i < mountlist->entries; i++) { 1834 1972 log_it(mountlist->el[i].device); … … 1837 1975 } 1838 1976 log_msg(0, "Stopping all LVMs, just in case"); 1839 if (!g_text_mode) { newtSuspend(); } 1840 do_my_funky_lvm_stuff(TRUE, FALSE); // just remove old partitions 1841 if (!g_text_mode) { newtResume(); } 1977 if (!g_text_mode) { 1978 newtSuspend(); 1979 } 1980 do_my_funky_lvm_stuff(TRUE, FALSE); // just remove old partitions 1981 if (!g_text_mode) { 1982 newtResume(); 1983 } 1842 1984 log_msg(0, "Stopping all software RAID devices, just in case"); 1843 1985 stop_all_raid_devices(mountlist); 1844 1986 log_msg(0, "Done."); 1845 1987 1846 1988 /* 1847 1989 if (does_file_exist("/tmp/i-want-my-lvm")) … … 1851 1993 */ 1852 1994 1853 open_progress_form("Partitioning devices", "I am now going to partition all your drives.", 1854 "This should not take more than five minutes.", "", mountlist->entries); 1995 open_progress_form("Partitioning devices", 1996 "I am now going to partition all your drives.", 1997 "This should not take more than five minutes.", "", 1998 mountlist->entries); 1855 1999 1856 2000 make_list_of_drives_in_mountlist(mountlist, drivelist); … … 1864 2008 if (retval) { 1865 2009 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 1866 log_to_screen("Errors occurred during the partitioning of your hard drives."); 2010 log_to_screen 2011 ("Errors occurred during the partitioning of your hard drives."); 1867 2012 } else { 1868 2013 mvaddstr_and_log_it(g_currentY++, 74, "Done."); … … 1890 2035 * @return 0 for success, nonzero for failure. 1891 2036 */ 1892 int set_partition_type(FILE *pout_to_fdisk, const char *drive, int partno, const char *format, long long partsize) 2037 int set_partition_type(FILE * pout_to_fdisk, const char *drive, int partno, 2038 const char *format, long long partsize) 1893 2039 { 1894 2040 /** buffers *********************************************************/ 1895 1896 1897 1898 1899 1900 2041 char *partition; 2042 char *command; 2043 char *output; 2044 char *tmp; 2045 char *partcode; 2046 char *logfile; 1901 2047 1902 2048 /** pointers *********************************************************/ … … 1912 2058 assert(format != NULL); 1913 2059 1914 1915 1916 1917 1918 1919 2060 malloc_string(partition); 2061 malloc_string(command); 2062 malloc_string(output); 2063 malloc_string(tmp); 2064 malloc_string(partcode); 2065 malloc_string(logfile); 1920 2066 1921 2067 build_partition_name(partition, drive, partno); … … 1930 2076 strcpy(partcode, "b"); 1931 2077 } 1932 } else if (strcmp(format, "ext2") == 0 || strcmp(format, "reiserfs") == 0 || strcmp(format, "ext3") == 0 1933 || strcmp(format, "xfs") == 0 || strcmp(format, "jfs") == 0) { 2078 } else if (strcmp(format, "ext2") == 0 2079 || strcmp(format, "reiserfs") == 0 2080 || strcmp(format, "ext3") == 0 || strcmp(format, "xfs") == 0 2081 || strcmp(format, "jfs") == 0) { 1934 2082 strcpy(partcode, "83"); 1935 2083 } else if (strcmp(format, "minix") == 0) { … … 1938 2086 strcpy(partcode, "fd"); 1939 2087 } else if ((strcmp(format, "ufs") == 0) 1940 || (strcmp(format, "ffs") == 0)) { /* raid autodetect */2088 || (strcmp(format, "ffs") == 0)) { /* raid autodetect */ 1941 2089 strcpy(partcode, "a5"); 1942 2090 } else if (strcmp(format, "lvm") == 0) { … … 1948 2096 } else { 1949 2097 /* probably an image */ 1950 sprintf(tmp, "Unknown format ('%s') - using supplied string anyway", format); 2098 sprintf(tmp, 2099 "Unknown format ('%s') - using supplied string anyway", 2100 format); 1951 2101 mvaddstr_and_log_it(g_currentY++, 0, tmp); 1952 2102 #ifdef __FreeBSD__ 1953 strcpy(partcode, format); 2103 strcpy(partcode, format); // was a5 1954 2104 #else 1955 strcpy(partcode, format); // was 83 1956 #endif 1957 } 1958 sprintf(tmp, "Setting %s's type to %s (%s)", partition, format, partcode); 2105 strcpy(partcode, format); // was 83 2106 #endif 2107 } 2108 sprintf(tmp, "Setting %s's type to %s (%s)", partition, format, 2109 partcode); 1959 2110 log_msg(1, tmp); 1960 2111 if (partcode[0] != '\0' && strcmp(partcode, "83")) { /* no need to set type if 83: 83 is default */ 1961 1962 if (pout_to_fdisk) 1963 { 2112 2113 if (pout_to_fdisk) { 1964 2114 res = 0; 1965 2115 fput_string_one_char_at_a_time(pout_to_fdisk, "t\n"); 1966 if (partno > 1 || strstr(last_line_of_file(FDISK_LOG), " (1-4)"))1967 {2116 if (partno > 1 2117 || strstr(last_line_of_file(FDISK_LOG), " (1-4)")) { 1968 2118 log_msg(5, "Specifying partno (%d) - yay", partno); 1969 2119 sprintf(tmp, "%d\n", partno); 1970 2120 fput_string_one_char_at_a_time(pout_to_fdisk, tmp); 1971 log_msg(5, "A - last line = '%s'", last_line_of_file(FDISK_LOG)); 1972 } 1973 2121 log_msg(5, "A - last line = '%s'", 2122 last_line_of_file(FDISK_LOG)); 2123 } 2124 1974 2125 sprintf(tmp, "%s\n", partcode); 1975 2126 fput_string_one_char_at_a_time(pout_to_fdisk, tmp); 1976 log_msg(5, "B - last line = '%s'", last_line_of_file(FDISK_LOG)); 2127 log_msg(5, "B - last line = '%s'", 2128 last_line_of_file(FDISK_LOG)); 1977 2129 fput_string_one_char_at_a_time(pout_to_fdisk, "\n"); 1978 log_msg(5, "C - last line = '%s'", last_line_of_file(FDISK_LOG)); 1979 2130 log_msg(5, "C - last line = '%s'", 2131 last_line_of_file(FDISK_LOG)); 2132 1980 2133 strcpy(tmp, last_line_of_file(FDISK_LOG)); 1981 if (!strstr(tmp, " (m ")) 1982 { 1983 log_msg(1, "last line = '%s'; part type set failed", tmp); 1984 res++; 1985 fput_string_one_char_at_a_time(pout_to_fdisk,"\n"); 1986 } 1987 fput_string_one_char_at_a_time(pout_to_fdisk,"p\n"); 1988 } 1989 else 1990 { 2134 if (!strstr(tmp, " (m ")) { 2135 log_msg(1, "last line = '%s'; part type set failed", tmp); 2136 res++; 2137 fput_string_one_char_at_a_time(pout_to_fdisk, "\n"); 2138 } 2139 fput_string_one_char_at_a_time(pout_to_fdisk, "p\n"); 2140 } else { 1991 2141 sprintf(output, "t\n%d\n%s\n", partno, partcode); 1992 2142 strcat(output, "w\n"); 1993 sprintf(command, "parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE, MONDO_LOGFILE); 2143 sprintf(command, "parted2fdisk %s >> %s 2>> %s", drive, 2144 MONDO_LOGFILE, MONDO_LOGFILE); 1994 2145 log_msg(5, "output = '%s'", output); 1995 2146 log_msg(5, "partno=%d; partcode=%s", partno, partcode); … … 2005 2156 } 2006 2157 } 2007 if (res) 2008 { 2009 log_OS_error(command); 2010 } 2011 } 2012 2013 paranoid_free(partition); 2014 paranoid_free(command); 2015 paranoid_free(output); 2016 paranoid_free(tmp); 2017 paranoid_free(partcode); 2018 paranoid_free(logfile); 2019 2020 return (res); 2158 if (res) { 2159 log_OS_error(command); 2160 } 2161 } 2162 2163 paranoid_free(partition); 2164 paranoid_free(command); 2165 paranoid_free(output); 2166 paranoid_free(tmp); 2167 paranoid_free(partcode); 2168 paranoid_free(logfile); 2169 2170 return (res); 2021 2171 } 2022 2172 … … 2035 2185 assert_string_is_neither_NULL_nor_zerolength(raid_device); 2036 2186 malloc_string(program); 2037 2187 2038 2188 #ifdef __FreeBSD__ 2039 2189 if (is_this_device_mounted(raid_device)) { … … 2048 2198 log_msg(1, "program = %s", program); 2049 2199 res = run_program_and_log_output(program, 1); 2050 if (g_fprep) { fprintf(g_fprep, "%s\n", program); } 2051 if (res) { log_msg(1, "Warning - failed to start RAID device %s", raid_device); } 2200 if (g_fprep) { 2201 fprintf(g_fprep, "%s\n", program); 2202 } 2203 if (res) { 2204 log_msg(1, "Warning - failed to start RAID device %s", 2205 raid_device); 2206 } 2052 2207 retval += res; 2053 2208 sleep(1); … … 2075 2230 assert_string_is_neither_NULL_nor_zerolength(raid_device); 2076 2231 malloc_string(program); 2077 2232 2078 2233 #ifdef __FreeBSD__ 2079 2234 if (is_this_device_mounted(raid_device)) { … … 2088 2243 log_msg(1, "program = %s", program); 2089 2244 res = run_program_and_log_output(program, 1); 2090 if (g_fprep) { fprintf(g_fprep, "%s\n", program); } 2091 if (res) { log_msg(1, "Warning - failed to stop RAID device %s", raid_device); } 2245 if (g_fprep) { 2246 fprintf(g_fprep, "%s\n", program); 2247 } 2248 if (res) { 2249 log_msg(1, "Warning - failed to stop RAID device %s", raid_device); 2250 } 2092 2251 retval += res; 2093 2252 return (retval); … … 2098 2257 { 2099 2258 int i; 2100 int retval =0;2259 int retval = 0; 2101 2260 int res; 2102 2103 for(i=0; i<mountlist->entries; i++) 2104 { 2105 if (!strncmp(mountlist->el[i].device, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) 2106 { 2107 log_msg(1, "Starting %s", mountlist->el[i].device); 2108 res = start_raid_device(mountlist->el[i].device); 2109 retval += res; 2110 } 2111 } 2112 if (retval) { log_msg(1, "Started all s/w raid devices OK"); } 2113 else { log_msg(1, "Failed to start some/all s/w raid devices"); } 2114 return(retval); 2261 2262 for (i = 0; i < mountlist->entries; i++) { 2263 if (!strncmp 2264 (mountlist->el[i].device, RAID_DEVICE_STUB, 2265 strlen(RAID_DEVICE_STUB))) { 2266 log_msg(1, "Starting %s", mountlist->el[i].device); 2267 res = start_raid_device(mountlist->el[i].device); 2268 retval += res; 2269 } 2270 } 2271 if (retval) { 2272 log_msg(1, "Started all s/w raid devices OK"); 2273 } else { 2274 log_msg(1, "Failed to start some/all s/w raid devices"); 2275 } 2276 return (retval); 2115 2277 } 2116 2278 … … 2149 2311 for (i = 0; i < 3; i++) { 2150 2312 #ifdef __FreeBSD__ 2151 fin = popen("vinum list | grep '^[PVS]' | sed 's/S/1/;s/P/2/;s/V/3/' | sort | cut -d' ' -f2", "r"); 2313 fin = 2314 popen 2315 ("vinum list | grep '^[PVS]' | sed 's/S/1/;s/P/2/;s/V/3/' | sort | cut -d' ' -f2", 2316 "r"); 2152 2317 if (!fin) { 2153 2318 paranoid_free(dev); … … 2155 2320 return (1); 2156 2321 } 2157 for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin); fgets(incoming, MAX_STR_LEN - 1, fin)) { 2322 for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin); 2323 fgets(incoming, MAX_STR_LEN - 1, fin)) { 2158 2324 retval += stop_raid_device(incoming); 2159 2325 } … … 2166 2332 return (1); 2167 2333 } 2168 for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin); fgets(incoming, MAX_STR_LEN - 1, fin)) { 2169 for (p = incoming; *p != '\0' && (*p != 'm' || *(p + 1) != 'd' || !isdigit(*(p + 2))); p++); 2334 for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin); 2335 fgets(incoming, MAX_STR_LEN - 1, fin)) { 2336 for (p = incoming; 2337 *p != '\0' && (*p != 'm' || *(p + 1) != 'd' 2338 || !isdigit(*(p + 2))); p++); 2170 2339 if (*p != '\0') { 2171 2340 sprintf(dev, "/dev/%s", p); … … 2178 2347 } 2179 2348 paranoid_fclose(fin); 2180 if (retval) { log_msg(1, "Warning - unable to stop some RAID devices"); } 2349 if (retval) { 2350 log_msg(1, "Warning - unable to stop some RAID devices"); 2351 } 2181 2352 paranoid_free(dev); 2182 2353 paranoid_free(incoming); 2183 system("sync"); system("sync"); system("sync"); 2354 system("sync"); 2355 system("sync"); 2356 system("sync"); 2184 2357 sleep(1); 2185 2358 return (retval); … … 2236 2409 sprintf(program, "mkfs -t %s -c", format); // -c checks for bad blocks 2237 2410 #endif 2238 sprintf(tmp, "Unknown format (%s) - assuming '%s' will do", format, program); 2411 sprintf(tmp, "Unknown format (%s) - assuming '%s' will do", format, 2412 program); 2239 2413 log_it(tmp); 2240 2414 res = 0; … … 2253 2427 */ 2254 2428 long calc_orig_size_of_drive_from_mountlist(struct mountlist_itself 2255 2429 *mountlist, char *drive_name) 2256 2430 { 2257 2431 /** long ************************************************************/ … … 2270 2444 assert_string_is_neither_NULL_nor_zerolength(drive_name); 2271 2445 2272 for (original_size_of_drive = 0, partno = 0; partno < mountlist->entries; partno++) { 2273 if (strncmp(mountlist->el[partno].device, drive_name, strlen(drive_name)) == 0) { 2446 for (original_size_of_drive = 0, partno = 0; 2447 partno < mountlist->entries; partno++) { 2448 if (strncmp 2449 (mountlist->el[partno].device, drive_name, 2450 strlen(drive_name)) == 0) { 2274 2451 original_size_of_drive += mountlist->el[partno].size; 2275 2452 } else { … … 2296 2473 */ 2297 2474 void resize_drive_proportionately_to_suit_new_drives(struct mountlist_itself 2298 *mountlist, char *drive_name) 2475 *mountlist, 2476 char *drive_name) 2299 2477 { 2300 2478 /**buffers **********************************************************/ … … 2303 2481 /** int *************************************************************/ 2304 2482 int partno, lastpart; 2305 2483 /** remove driveno, noof_drives stan benoit apr 2002**/ 2306 2484 2307 2485 /** float ***********************************************************/ 2308 2486 float factor; 2309 2487 float new_size; 2310 // 2488 // float newcylinderno; 2311 2489 2312 2490 /** long *************************************************************/ … … 2314 2492 long current_size_of_drive = 0; 2315 2493 long original_size_of_drive = 0; 2316 long final_size; /* all in Megabytes */2494 long final_size; /* all in Megabytes */ 2317 2495 struct mountlist_reference *drivemntlist; 2318 2496 … … 2326 2504 2327 2505 if (strlen(drive_name) >= strlen(RAID_DEVICE_STUB)) { 2328 if (strncmp(drive_name, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB)) == 0) { 2506 if (strncmp(drive_name, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB)) 2507 == 0) { 2329 2508 paranoid_free(tmp); 2330 2509 return; … … 2338 2517 2339 2518 current_size_of_drive = get_phys_size_of_drive(drive_name); 2340 2519 2341 2520 if (current_size_of_drive <= 0) { 2342 2521 log_it("Not resizing to match %s - can't find drive", drive_name); … … 2344 2523 return; 2345 2524 } 2346 sprintf(tmp, "Expanding entries to suit drive %s (%ld MB)", drive_name, current_size_of_drive); 2525 sprintf(tmp, "Expanding entries to suit drive %s (%ld MB)", drive_name, 2526 current_size_of_drive); 2347 2527 log_to_screen(tmp); 2348 2528 2349 drivemntlist = malloc(sizeof (struct mountlist_reference)); 2350 drivemntlist->el = malloc(sizeof(struct mountlist_line *) * MAX_TAPECATALOG_ENTRIES); 2529 drivemntlist = malloc(sizeof(struct mountlist_reference)); 2530 drivemntlist->el = 2531 malloc(sizeof(struct mountlist_line *) * MAX_TAPECATALOG_ENTRIES); 2351 2532 2352 2533 if (!drivemntlist) { … … 2361 2542 2362 2543 if (original_size_of_drive <= 0) { 2363 sprintf(tmp, "Cannot resize %s's entries. Drive not found.", drive_name); 2544 sprintf(tmp, "Cannot resize %s's entries. Drive not found.", 2545 drive_name); 2364 2546 log_to_screen(tmp); 2365 2547 paranoid_free(tmp); 2366 2548 return; 2367 2549 } 2368 factor = (float) (current_size_of_drive) / (float) (original_size_of_drive); 2369 sprintf(tmp, "Disk %s was %ld MB; is now %ld MB; factor = %f", drive_name, original_size_of_drive, current_size_of_drive, 2370 factor); 2550 factor = 2551 (float) (current_size_of_drive) / (float) (original_size_of_drive); 2552 sprintf(tmp, "Disk %s was %ld MB; is now %ld MB; factor = %f", 2553 drive_name, original_size_of_drive, current_size_of_drive, 2554 factor); 2371 2555 log_to_screen(tmp); 2372 2556 2373 lastpart = drivemntlist->entries -1;2557 lastpart = drivemntlist->entries - 1; 2374 2558 for (partno = 0; partno < drivemntlist->entries; partno++) { 2375 2559 /* the 'atoi' thing is to make sure we don't try to resize _images_, whose formats will be numeric */ 2376 if ( !atoi(drivemntlist->el[partno]->format)) {2560 if (!atoi(drivemntlist->el[partno]->format)) { 2377 2561 new_size = (float) (drivemntlist->el[partno]->size) * factor; 2378 2562 } else { 2379 2563 new_size = drivemntlist->el[partno]->size; 2380 2564 } 2381 2565 2382 2566 if (!strcmp(drivemntlist->el[partno]->mountpoint, "image")) { 2383 2567 log_msg(1, "Skipping %s (%s) because it's an image", 2384 2385 2386 newsizL = (long) new_size; 2568 drivemntlist->el[partno]->device, 2569 drivemntlist->el[partno]->mountpoint); 2570 newsizL = (long) new_size; // It looks wrong but it's not 2387 2571 } else { 2388 2572 newsizL = (long) new_size; 2389 2573 } 2390 sprintf(tmp, "Changing %s from %lld KB to %ld KB", drivemntlist->el[partno]->device, drivemntlist->el[partno]->size,newsizL); 2574 sprintf(tmp, "Changing %s from %lld KB to %ld KB", 2575 drivemntlist->el[partno]->device, 2576 drivemntlist->el[partno]->size, newsizL); 2391 2577 log_to_screen(tmp); 2392 2578 drivemntlist->el[partno]->size = newsizL; … … 2406 2592 */ 2407 2593 void resize_mountlist_proportionately_to_suit_new_drives(struct mountlist_itself 2408 *mountlist)2594 *mountlist) 2409 2595 { 2410 2596 /** buffers *********************************************************/ … … 2420 2606 2421 2607 if (g_mountlist_fname[0] == '\0') { 2422 log_it ("resize_mountlist_prop...() - warning - mountlist fname is blank"); 2423 log_it ("That does NOT affect the functioning of this subroutine."); 2424 log_it ("--- Hugo, 2002/11/20"); 2608 log_it 2609 ("resize_mountlist_prop...() - warning - mountlist fname is blank"); 2610 log_it("That does NOT affect the functioning of this subroutine."); 2611 log_it("--- Hugo, 2002/11/20"); 2425 2612 } 2426 2613 iamhere("Resizing mountlist"); … … 2428 2615 iamhere("Back from MLoDiM"); 2429 2616 for (driveno = 0; driveno < drivelist->entries; driveno++) { 2430 resize_drive_proportionately_to_suit_new_drives(mountlist, drivelist->el[driveno].device); 2617 resize_drive_proportionately_to_suit_new_drives(mountlist, 2618 drivelist-> 2619 el[driveno]. 2620 device); 2431 2621 } 2432 2622 log_to_screen("Mountlist adjusted to suit current hard drive(s)"); … … 2442 2632 * @author Ralph Grewe 2443 2633 */ 2444 void create_mountlist_for_drive(struct mountlist_itself *mountlist, char *drive_name, struct mountlist_reference *drivemntlist) { 2634 void create_mountlist_for_drive(struct mountlist_itself *mountlist, 2635 char *drive_name, 2636 struct mountlist_reference *drivemntlist) 2637 { 2445 2638 int partno; 2446 2639 char *tmp_drive_name, *c; … … 2450 2643 assert(drivemntlist != NULL); 2451 2644 2452 log_msg (1, "Creating list of partitions for drive %s",drive_name); 2453 2454 tmp_drive_name = strdup (drive_name); 2455 if (!tmp_drive_name) fatal_error ("Out of memory"); 2456 2645 log_msg(1, "Creating list of partitions for drive %s", drive_name); 2646 2647 tmp_drive_name = strdup(drive_name); 2648 if (!tmp_drive_name) 2649 fatal_error("Out of memory"); 2650 2457 2651 /* devfs devices? */ 2458 c = strrchr 2459 if (c && strncmp 2460 2461 strcpy(c + 1, "part");2462 } 2463 drivemntlist->entries =0;2652 c = strrchr(tmp_drive_name, '/'); 2653 if (c && strncmp(c, "/disc", 5) == 0) { 2654 /* yup its devfs, change the "disc" to "part" so the existing code works */ 2655 strcpy(c + 1, "part"); 2656 } 2657 drivemntlist->entries = 0; 2464 2658 for (partno = 0; partno < mountlist->entries; partno++) { 2465 if (strncmp (mountlist->el[partno].device, tmp_drive_name, strlen(tmp_drive_name)) == 0) { 2466 drivemntlist->el[drivemntlist->entries] = &mountlist->el[partno]; 2659 if (strncmp 2660 (mountlist->el[partno].device, tmp_drive_name, 2661 strlen(tmp_drive_name)) == 0) { 2662 drivemntlist->el[drivemntlist->entries] = 2663 &mountlist->el[partno]; 2467 2664 drivemntlist->entries++; 2468 2665 } 2469 2666 } 2470 2667 if (tmp_drive_name) 2471 free(tmp_drive_name);2668 free(tmp_drive_name); 2472 2669 } 2473 2670
Note:
See TracChangeset
for help on using the changeset viewer.