Changeset 59 in MondoRescue for trunk/mondo/mondo/mondorestore
- Timestamp:
- Oct 11, 2005, 1:34:31 AM (18 years ago)
- Location:
- trunk/mondo/mondo/mondorestore
- Files:
-
- 14 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 -
trunk/mondo/mondo/mondorestore/mondo-restore-EXT.h
r30 r59 6 6 7 7 extern bool g_sigpipe_caught; 8 extern bool g_ISO_restore_mode; 8 extern bool g_ISO_restore_mode; /* are we in Iso Mode? */ 9 9 extern bool g_I_have_just_nuked; 10 10 extern char *g_tmpfs_mountpt; … … 13 13 14 14 extern struct s_bkpinfo *g_bkpinfo_DONTUSETHIS; 15 extern char 16 extern char 17 extern char 18 extern char 19 extern char *g_filelist_imagedevs;20 extern char *g_filelist_restthese;21 extern char 22 extern char *g_imagedevs_restthese;23 extern char 24 extern char 25 extern char 15 extern char *g_biggielist_txt; 16 extern char *g_filelist_full; 17 extern char *g_biggielist_pot; 18 extern char *g_filelist_potential; 19 extern char *g_filelist_imagedevs; 20 extern char *g_filelist_restthese; 21 extern char *g_biggielist_restthese; 22 extern char *g_imagedevs_restthese; 23 extern char *g_mondo_cfg_file; 24 extern char *g_mountlist_fname; 25 extern char *g_mondo_home; 26 26 27 27 28 extern void ask_about_these_imagedevs(char*,char*); 29 extern int catchall_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself*); 30 extern void sort_mountlist_by_device(struct mountlist_itself*); 31 extern void find_pathname_of_executable_preferably_in_RESTORING(char *, char*, char*); 32 extern int interactive_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself *); 33 extern int nuke_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself *); 34 extern int compare_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself *); 28 extern void ask_about_these_imagedevs(char *, char *); 29 extern int catchall_mode(struct s_bkpinfo *, struct mountlist_itself *, 30 struct raidlist_itself *); 31 extern void sort_mountlist_by_device(struct mountlist_itself *); 32 extern void find_pathname_of_executable_preferably_in_RESTORING(char *, 33 char *, 34 char *); 35 extern int interactive_mode(struct s_bkpinfo *, struct mountlist_itself *, 36 struct raidlist_itself *); 37 extern int nuke_mode(struct s_bkpinfo *, struct mountlist_itself *, 38 struct raidlist_itself *); 39 extern int compare_mode(struct s_bkpinfo *, struct mountlist_itself *, 40 struct raidlist_itself *); 35 41 extern int iso_mode(struct s_bkpinfo *bkpinfo, 36 struct mountlist_itself *mountlist, 37 struct raidlist_itself *raidlist, 38 bool nuke_me_please); 39 extern int load_mountlist(struct mountlist_itself*,char*); 40 extern int load_raidtab_into_raidlist(struct raidlist_itself*,char*); 41 extern int restore_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself *); 42 extern int save_raidlist_to_raidtab(struct raidlist_itself*,char*); 43 extern void process_raidtab_line(FILE*, struct raid_device_record *, char*, char*); 44 extern int restore_a_biggiefile_from_CD(struct s_bkpinfo *, long, struct s_node*); 45 extern int restore_a_biggiefile_from_stream(struct s_bkpinfo*, char*, long , char*, long long, struct s_node*); 46 extern int restore_a_tarball_from_CD(char *, int, struct s_node*); 47 extern int restore_a_tarball_from_stream(struct s_bkpinfo*, char *, int, struct s_node*, long long); 48 extern int restore_all_biggiefiles_from_CD(struct s_bkpinfo*, struct s_node*); 49 extern int restore_all_biggiefiles_from_stream(struct s_bkpinfo*, struct s_node*); 50 extern int restore_all_tarballs_from_CD(struct s_bkpinfo*, struct s_node*); 51 extern int restore_all_tarballs_from_stream(struct s_bkpinfo*, struct s_node*); 52 extern int restore_everything(struct s_bkpinfo*, struct s_node*); 53 extern int restore_live_from_monitas_server(struct s_bkpinfo *, char*, char*, char*); 54 extern int restore_to_live_filesystem(struct s_bkpinfo*); 55 extern void swap_mountlist_entries(struct mountlist_itself*,int,int); 56 extern void sort_mountlist_by_mountpoint(struct mountlist_itself*,bool); 57 extern void sort_mountlist_by_device(struct mountlist_itself*); 42 struct mountlist_itself *mountlist, 43 struct raidlist_itself *raidlist, bool nuke_me_please); 44 extern int load_mountlist(struct mountlist_itself *, char *); 45 extern int load_raidtab_into_raidlist(struct raidlist_itself *, char *); 46 extern int restore_mode(struct s_bkpinfo *, struct mountlist_itself *, 47 struct raidlist_itself *); 48 extern int save_raidlist_to_raidtab(struct raidlist_itself *, char *); 49 extern void process_raidtab_line(FILE *, struct raid_device_record *, 50 char *, char *); 51 extern int restore_a_biggiefile_from_CD(struct s_bkpinfo *, long, 52 struct s_node *); 53 extern int restore_a_biggiefile_from_stream(struct s_bkpinfo *, char *, 54 long, char *, long long, 55 struct s_node *); 56 extern int restore_a_tarball_from_CD(char *, int, struct s_node *); 57 extern int restore_a_tarball_from_stream(struct s_bkpinfo *, char *, int, 58 struct s_node *, long long); 59 extern int restore_all_biggiefiles_from_CD(struct s_bkpinfo *, 60 struct s_node *); 61 extern int restore_all_biggiefiles_from_stream(struct s_bkpinfo *, 62 struct s_node *); 63 extern int restore_all_tarballs_from_CD(struct s_bkpinfo *, 64 struct s_node *); 65 extern int restore_all_tarballs_from_stream(struct s_bkpinfo *, 66 struct s_node *); 67 extern int restore_everything(struct s_bkpinfo *, struct s_node *); 68 extern int restore_live_from_monitas_server(struct s_bkpinfo *, char *, 69 char *, char *); 70 extern int restore_to_live_filesystem(struct s_bkpinfo *); 71 extern void swap_mountlist_entries(struct mountlist_itself *, int, int); 72 extern void sort_mountlist_by_mountpoint(struct mountlist_itself *, bool); 73 extern void sort_mountlist_by_device(struct mountlist_itself *); 58 74 extern void success_message(void); 59 75 extern void twenty_seconds_til_yikes(void); 60 extern int run_raw_mbr(bool offer_to_hack_scripts, char*bd); 61 extern int save_mountlist_to_disk(struct mountlist_itself*, char*); 62 extern void save_raidrec_to_file(struct raid_device_record *raidrec, FILE*fout); 63 extern int save_raidlist_to_raidtab(struct raidlist_itself *raidlist, char*fname); 64 extern int what_number_cd_is_this(struct s_bkpinfo*); 76 extern int run_raw_mbr(bool offer_to_hack_scripts, char *bd); 77 extern int save_mountlist_to_disk(struct mountlist_itself *, char *); 78 extern void save_raidrec_to_file(struct raid_device_record *raidrec, 79 FILE * fout); 80 extern int save_raidlist_to_raidtab(struct raidlist_itself *raidlist, 81 char *fname); 82 extern int what_number_cd_is_this(struct s_bkpinfo *); 65 83 66 84 #ifdef __FreeBSD__ -
trunk/mondo/mondo/mondorestore/mondo-restore.c
r30 r59 5 5 copyright : (C) 2000 by Hugo Rabson 6 6 email : Hugo Rabson <hugorabson@msn.com> 7 cvsid : $Id : mondo-restore.c,v 1.42 2004/06/21 20:20:37 hugo Exp$7 cvsid : $Id$ 8 8 ***************************************************************************/ 9 9 … … 407 407 408 408 409 //static char cvsid[] = "$Id : mondo-restore.c,v 1.42 2004/06/21 20:20:37 hugo Exp$";409 //static char cvsid[] = "$Id$"; 410 410 411 411 /************************************************************************** 412 412 * Globals * 413 413 **************************************************************************/ 414 extern char *g_tmpfs_mountpt; 415 extern struct s_bkpinfo *g_bkpinfo_DONTUSETHIS; 416 414 extern char *g_tmpfs_mountpt; // declared in libmondo-tools.c 415 extern struct s_bkpinfo *g_bkpinfo_DONTUSETHIS; // used by finish() to free 416 // up global bkpinfo struct 417 417 extern bool g_text_mode; 418 418 extern FILE *g_fprep; … … 433 433 * Set by the signal handler; cleared after it's handled. 434 434 */ 435 bool g_sigpipe_caught=FALSE;435 bool g_sigpipe_caught = FALSE; 436 436 437 437 /** … … 439 439 * If FALSE, then we're restoring from some kind of real media (tape, CD, etc.) 440 440 */ 441 bool g_ISO_restore_mode = FALSE;/* are we in Iso Mode? */441 bool g_ISO_restore_mode = FALSE; /* are we in Iso Mode? */ 442 442 443 443 /** 444 444 * If TRUE, then we have had a successful "nuke" restore. 445 445 */ 446 bool 446 bool g_I_have_just_nuked = FALSE; 447 447 448 448 /** 449 449 * The device to mount to get at the ISO images. Ignored unless @p g_ISO_restore_mode. 450 450 */ 451 char 451 char *g_isodir_device; 452 452 453 453 /** 454 454 * The format of @p g_isodir_device. Ignored unless @p g_ISO_restore_mode. 455 455 */ 456 char 456 char *g_isodir_format; 457 457 458 458 /** 459 459 * The location of 'biggielist.txt', containing the biggiefiles on the current archive set. 460 460 */ 461 char 461 char *g_biggielist_txt; 462 462 463 463 /** … … 465 465 * the current archive set. 466 466 */ 467 char 467 char *g_filelist_full; 468 468 469 469 /** … … 471 471 * as images, not as individual files. 472 472 */ 473 char 473 char *g_filelist_imagedevs; 474 474 475 475 /** … … 477 477 * @see g_filelist_imagedevs 478 478 */ 479 char 479 char *g_imagedevs_restthese; 480 480 481 481 /** … … 483 483 * information for this backup. 484 484 */ 485 char 485 char *g_mondo_cfg_file; 486 486 487 487 /** … … 489 489 * user's partitions and hard drives. 490 490 */ 491 char 491 char *g_mountlist_fname; 492 492 493 493 /** … … 495 495 * to avoid link errors. 496 496 */ 497 char 497 char *g_mondo_home; 498 498 499 499 /* @} - end of "Restore-Time Globals" in globalGroup */ … … 501 501 502 502 503 extern int copy_from_src_to_dest(FILE*f_orig, FILE*f_archived, char direction); 503 extern int copy_from_src_to_dest(FILE * f_orig, FILE * f_archived, 504 char direction); 504 505 505 506 … … 525 526 * @ingroup restoreGuiGroup 526 527 */ 527 int let_user_edit_the_mountlist(struct s_bkpinfo *bkpinfo, struct mountlist_itself *mountlist, struct raidlist_itself *raidlist) 528 int let_user_edit_the_mountlist(struct s_bkpinfo *bkpinfo, 529 struct mountlist_itself *mountlist, 530 struct raidlist_itself *raidlist) 528 531 { 529 int retval=0, res=0;530 531 532 533 assert(bkpinfo!=NULL);534 assert(mountlist!=NULL);535 assert(raidlist!=NULL);536 if ( !bkpinfo->disaster_recovery ) 537 { 538 strcpy( g_mountlist_fname, "/tmp/mountlist.txt");539 log_msg(2, "I guess you're testing edit_mountlist()" ); 540 } 541 if (!does_file_exist(g_mountlist_fname)) 542 { 543 log_to_screen(g_mountlist_fname);544 log_to_screen("does not exist"); 545 return(1); 546 } 547 548 retval = load_mountlist( mountlist, g_mountlist_fname ); 549 load_raidtab_into_raidlist( raidlist, RAIDTAB_FNAME ); 550 if ( retval ) { log_to_screen( "Warning - load_raidtab_into_raidlist returned an error" ); } 551 res = edit_mountlist( g_mountlist_fname, mountlist, raidlist ); 552 if ( res ) 553 {554 return( 1 );555 } 556 557 save_mountlist_to_disk( mountlist, g_mountlist_fname);558 save_raidlist_to_raidtab( raidlist, RAIDTAB_FNAME);559 560 561 562 return( retval);563 532 int retval = 0, res = 0; 533 534 log_msg(2, "let_user_edit_the_mountlist() --- starting"); 535 536 assert(bkpinfo != NULL); 537 assert(mountlist != NULL); 538 assert(raidlist != NULL); 539 if (!bkpinfo->disaster_recovery) { 540 strcpy(g_mountlist_fname, "/tmp/mountlist.txt"); 541 log_msg(2, "I guess you're testing edit_mountlist()"); 542 } 543 if (!does_file_exist(g_mountlist_fname)) { 544 log_to_screen(g_mountlist_fname); 545 log_to_screen("does not exist"); 546 return (1); 547 } 548 549 retval = load_mountlist(mountlist, g_mountlist_fname); 550 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME); 551 if (retval) { 552 log_to_screen 553 ("Warning - load_raidtab_into_raidlist returned an error"); 554 } 555 res = edit_mountlist(g_mountlist_fname, mountlist, raidlist); 556 if (res) { 557 return (1); 558 } 559 560 save_mountlist_to_disk(mountlist, g_mountlist_fname); 561 save_raidlist_to_raidtab(raidlist, RAIDTAB_FNAME); 562 563 log_to_screen("I have finished editing the mountlist for you."); 564 565 return (retval); 566 } 564 567 565 568 … … 573 576 * @ingroup restoreUtilityGroup 574 577 */ 575 bool 576 partition_table_contains_Compaq_diagnostic_partition(struct mountlist_itself *mountlist) 578 bool 579 partition_table_contains_Compaq_diagnostic_partition(struct 580 mountlist_itself * 581 mountlist) 577 582 { 578 int i; 579 580 assert(mountlist!=NULL); 581 582 for( i = 0; i < mountlist->entries; i++ ) 583 { 584 if ( strstr( mountlist->el[i].format, "ompaq" ) ) 585 { 586 log_msg(2, "mountlist[%d] (%s) is %s (Compaq alert!)", 587 i, 588 mountlist->el[i].device, 589 mountlist->el[i].format ); 590 591 return( TRUE ); 592 } 593 } 594 return( FALSE ); 583 int i; 584 585 assert(mountlist != NULL); 586 587 for (i = 0; i < mountlist->entries; i++) { 588 if (strstr(mountlist->el[i].format, "ompaq")) { 589 log_msg(2, "mountlist[%d] (%s) is %s (Compaq alert!)", 590 i, mountlist->el[i].device, mountlist->el[i].format); 591 592 return (TRUE); 593 } 594 } 595 return (FALSE); 595 596 } 597 596 598 /************************************************************************** 597 599 *END_PARTITION_TABLE_CONTAINS_COMPAQ_DIAGNOSTIC_PARTITION * … … 604 606 * @ingroup restoreUtilityGroup 605 607 */ 606 void 607 offer_to_abort_because_Compaq_Proliants_suck(void) 608 void offer_to_abort_because_Compaq_Proliants_suck(void) 608 609 { 609 popup_and_OK( COMPAQ_PROLIANTS_SUCK ); 610 if ( ask_me_yes_or_no("Would you like to reboot and use your Compaq CD to prep your hard drive?") ) 611 { 612 fatal_error( "Aborting. Please reboot and prep your hard drive with your Compaq CD." ); 613 } 610 popup_and_OK(COMPAQ_PROLIANTS_SUCK); 611 if (ask_me_yes_or_no 612 ("Would you like to reboot and use your Compaq CD to prep your hard drive?")) 613 { 614 fatal_error 615 ("Aborting. Please reboot and prep your hard drive with your Compaq CD."); 616 } 614 617 } 618 615 619 /************************************************************************** 616 620 *END_OFFER_TO_ABORT_BECAUSE_COMPAQ_PROLIANTS_SUCK * … … 627 631 * @ingroup restoreGroup 628 632 */ 629 int 630 catchall_mode( struct s_bkpinfo *bkpinfo,631 struct mountlist_itself *mountlist,632 struct raidlist_itself*raidlist)633 int 634 catchall_mode(struct s_bkpinfo *bkpinfo, 635 struct mountlist_itself *mountlist, 636 struct raidlist_itself *raidlist) 633 637 { 634 char c, *tmp; 635 int retval = 0; 636 637 iamhere("inside catchall"); 638 assert(bkpinfo!=NULL); 639 assert(mountlist!=NULL); 640 assert(raidlist!=NULL); 641 malloc_string(tmp); 642 iamhere("pre wrm"); 643 c = which_restore_mode(); 644 iamhere("post wrm"); 645 if ( c == 'I' || c == 'N' || c == 'C') 646 { 647 interactively_obtain_media_parameters_from_user( bkpinfo, FALSE); 648 } 649 else 650 { 651 popup_and_OK( "No restoring or comparing will take place today." ); 652 if ( is_this_device_mounted( "/mnt/cdrom" ) ) 653 { 654 run_program_and_log_output( "umount /mnt/cdrom", FALSE); 655 } 656 if ( g_ISO_restore_mode ) 657 { 658 sprintf(tmp, "umount %s", bkpinfo->isodir); 659 run_program_and_log_output( tmp, FALSE); 660 } 661 paranoid_MR_finish( 0 ); 662 } 663 664 iamhere("post int"); 665 666 if (bkpinfo->backup_media_type == iso) 667 { 668 if (iso_fiddly_bits(bkpinfo, (c=='N')?TRUE:FALSE)) 669 { log_msg(2, "catchall_mode --- iso_fiddly_bits returned w/ error"); return(1); } 670 else 671 { log_msg(2, "catchall_mode --- iso_fiddly_bits ok"); } 672 } 673 674 if (c == 'I' ) 675 { 676 log_msg(2, "IM selected" ); 677 retval += interactive_mode( bkpinfo,mountlist,raidlist ); 678 } 679 else if 680 ( c == 'N' ) 681 { 682 log_msg(2, "NM selected"); 683 retval += nuke_mode( bkpinfo, mountlist, raidlist ); } 684 else if 685 ( c == 'C' ) 686 { 687 log_msg(2, "CM selected" ); 688 retval += compare_mode( bkpinfo, mountlist, raidlist); 689 } 690 paranoid_free(tmp); 691 return( retval ); 638 char c, *tmp; 639 int retval = 0; 640 641 iamhere("inside catchall"); 642 assert(bkpinfo != NULL); 643 assert(mountlist != NULL); 644 assert(raidlist != NULL); 645 malloc_string(tmp); 646 iamhere("pre wrm"); 647 c = which_restore_mode(); 648 iamhere("post wrm"); 649 if (c == 'I' || c == 'N' || c == 'C') { 650 interactively_obtain_media_parameters_from_user(bkpinfo, FALSE); 651 } else { 652 popup_and_OK("No restoring or comparing will take place today."); 653 if (is_this_device_mounted("/mnt/cdrom")) { 654 run_program_and_log_output("umount /mnt/cdrom", FALSE); 655 } 656 if (g_ISO_restore_mode) { 657 sprintf(tmp, "umount %s", bkpinfo->isodir); 658 run_program_and_log_output(tmp, FALSE); 659 } 660 paranoid_MR_finish(0); 661 } 662 663 iamhere("post int"); 664 665 if (bkpinfo->backup_media_type == iso) { 666 if (iso_fiddly_bits(bkpinfo, (c == 'N') ? TRUE : FALSE)) { 667 log_msg(2, 668 "catchall_mode --- iso_fiddly_bits returned w/ error"); 669 return (1); 670 } else { 671 log_msg(2, "catchall_mode --- iso_fiddly_bits ok"); 672 } 673 } 674 675 if (c == 'I') { 676 log_msg(2, "IM selected"); 677 retval += interactive_mode(bkpinfo, mountlist, raidlist); 678 } else if (c == 'N') { 679 log_msg(2, "NM selected"); 680 retval += nuke_mode(bkpinfo, mountlist, raidlist); 681 } else if (c == 'C') { 682 log_msg(2, "CM selected"); 683 retval += compare_mode(bkpinfo, mountlist, raidlist); 684 } 685 paranoid_free(tmp); 686 return (retval); 692 687 } 688 693 689 /************************************************************************** 694 690 *END_CATCHALL_MODE * … … 709 705 */ 710 706 void 711 find_pathname_of_executable_preferably_in_RESTORING( char *out_path, char *fname, char*restg ) 707 find_pathname_of_executable_preferably_in_RESTORING(char *out_path, 708 char *fname, 709 char *restg) 712 710 { 713 assert(out_path!=NULL); 714 assert_string_is_neither_NULL_nor_zerolength(fname); 715 716 sprintf( out_path, "%s/sbin/%s", restg, fname ); 717 if ( does_file_exist(out_path) ) 718 { 719 sprintf( out_path, "%s/usr/sbin/%s", restg, fname ); 720 if ( does_file_exist( out_path ) ) 721 { 722 sprintf( out_path, "%s/bin/%s", restg, fname ); 723 if ( does_file_exist( out_path ) ) 724 { 725 sprintf( out_path, "%s/usr/bin/%s", restg, fname ); 726 if ( does_file_exist( out_path ) ) 727 { 728 strcpy( out_path, fname ); 729 } 730 } 731 } 732 } 711 assert(out_path != NULL); 712 assert_string_is_neither_NULL_nor_zerolength(fname); 713 714 sprintf(out_path, "%s/sbin/%s", restg, fname); 715 if (does_file_exist(out_path)) { 716 sprintf(out_path, "%s/usr/sbin/%s", restg, fname); 717 if (does_file_exist(out_path)) { 718 sprintf(out_path, "%s/bin/%s", restg, fname); 719 if (does_file_exist(out_path)) { 720 sprintf(out_path, "%s/usr/bin/%s", restg, fname); 721 if (does_file_exist(out_path)) { 722 strcpy(out_path, fname); 723 } 724 } 725 } 726 } 733 727 } 734 728 … … 753 747 * @return 0 for success, or the number of errors encountered. 754 748 */ 755 int 756 interactive_mode( struct s_bkpinfo *bkpinfo,757 struct mountlist_itself *mountlist,758 749 int 750 interactive_mode(struct s_bkpinfo *bkpinfo, 751 struct mountlist_itself *mountlist, 752 struct raidlist_itself *raidlist) 759 753 { 760 761 762 763 764 765 766 754 int retval = 0; 755 int res; 756 int ptn_errs = 0; 757 int fmt_errs = 0; 758 759 bool done; 760 bool restore_all; 767 761 768 762 /** needs malloc **********/ 769 char *tmp; 770 char *fstab_fname; 771 char *old_restpath; 772 773 struct s_node *filelist; 774 775 /* try to partition and format */ 776 777 log_msg(2,"interactive_mode --- starting (great, assertions OK)"); 778 779 malloc_string(tmp); 780 malloc_string(fstab_fname); 781 malloc_string(old_restpath); 782 assert(bkpinfo!=NULL); 783 assert(mountlist!=NULL); 784 assert(raidlist!=NULL); 785 786 log_msg(2,"interactive_mode --- assertions OK"); 787 788 if (g_text_mode) 789 { 790 if (!ask_me_yes_or_no("Interactive Mode + textonly = experimental! Proceed anyway?")) 791 { fatal_error("Wise move."); } 792 } 793 794 iamhere("About to load config file"); 795 get_cfg_file_from_archive_or_bust(bkpinfo); 796 read_cfg_file_into_bkpinfo( g_mondo_cfg_file, bkpinfo ); 797 iamhere("Done loading config file; resizing ML"); 763 char *tmp; 764 char *fstab_fname; 765 char *old_restpath; 766 767 struct s_node *filelist; 768 769 /* try to partition and format */ 770 771 log_msg(2, "interactive_mode --- starting (great, assertions OK)"); 772 773 malloc_string(tmp); 774 malloc_string(fstab_fname); 775 malloc_string(old_restpath); 776 assert(bkpinfo != NULL); 777 assert(mountlist != NULL); 778 assert(raidlist != NULL); 779 780 log_msg(2, "interactive_mode --- assertions OK"); 781 782 if (g_text_mode) { 783 if (!ask_me_yes_or_no 784 ("Interactive Mode + textonly = experimental! Proceed anyway?")) 785 { 786 fatal_error("Wise move."); 787 } 788 } 789 790 iamhere("About to load config file"); 791 get_cfg_file_from_archive_or_bust(bkpinfo); 792 read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo); 793 iamhere("Done loading config file; resizing ML"); 798 794 #ifdef __FreeBSD__ 799 if (strstr(call_program_and_get_last_line_of_output("cat /tmp/cmdline"), "noresize")) 795 if (strstr 796 (call_program_and_get_last_line_of_output("cat /tmp/cmdline"), 797 "noresize")) 800 798 #else 801 if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "noresize")) 799 if (strstr 800 (call_program_and_get_last_line_of_output("cat /proc/cmdline"), 801 "noresize")) 802 802 #endif 803 { log_msg(1,"Not resizing mountlist."); } 804 else 805 { resize_mountlist_proportionately_to_suit_new_drives(mountlist); } 806 for( done = FALSE; !done; ) 807 { 808 iamhere("About to edit mountlist"); 809 if (g_text_mode) 810 { 811 save_mountlist_to_disk (mountlist, g_mountlist_fname); 812 sprintf(tmp, "%s %s", find_my_editor(), g_mountlist_fname); 813 res = system(tmp); 814 load_mountlist (mountlist, g_mountlist_fname); 815 } 816 else 817 { 818 res = edit_mountlist( g_mountlist_fname, mountlist, raidlist ); 819 } 820 iamhere("Finished editing mountlist"); 821 if ( res ) 822 { 823 paranoid_MR_finish( 1 ); 824 } 825 log_msg(2, "Proceeding..." ); 826 save_mountlist_to_disk( mountlist, g_mountlist_fname ); 827 save_raidlist_to_raidtab( raidlist, RAIDTAB_FNAME ); 828 mvaddstr_and_log_it( 1, 30, "Restoring Interactively" ); 829 if ( bkpinfo->differential ) 830 { 831 log_to_screen( "Because this is a differential backup, disk" ); 832 log_to_screen(" partitioning and formatting will not take place." ); 833 done=TRUE; 834 } 835 else 836 { 837 if ( ask_me_yes_or_no( "Do you want to erase and partition your hard drives?" ) ) 838 { 839 if ( partition_table_contains_Compaq_diagnostic_partition( mountlist ) ) 840 { offer_to_abort_because_Compaq_Proliants_suck(); done=TRUE; } 841 else 842 { 843 twenty_seconds_til_yikes(); 844 g_fprep = fopen("/tmp/prep.sh", "w"); 845 ptn_errs = partition_everything( mountlist ); 846 if (ptn_errs) 847 { 848 log_to_screen("Warning. Errors occurred during disk partitioning."); 849 } 850 851 fmt_errs = format_everything( mountlist, FALSE ); 852 if (!fmt_errs) 853 { 854 log_to_screen("Errors during disk partitioning were handled OK."); 855 log_to_screen("Partitions were formatted OK despite those errors."); 856 ptn_errs = 0; 857 } 858 if ( !ptn_errs && !fmt_errs) 859 { 860 done = TRUE; 861 } 862 } 863 paranoid_fclose(g_fprep); 864 } 865 else 866 { 867 mvaddstr_and_log_it( g_currentY++, 0, "User opted not to partition the devices" ); 868 if ( ask_me_yes_or_no( "Do you want to format your hard drives?" ) ) 869 { 870 fmt_errs = format_everything( mountlist, TRUE ); 871 if (!fmt_errs) 872 { 873 done = TRUE; 874 } 875 } 876 else 877 { 878 ptn_errs = fmt_errs = 0; 879 done = TRUE; 880 } 881 } 882 if (fmt_errs) 883 { 884 mvaddstr_and_log_it( g_currentY++, 885 0, 886 "Errors occurred. Please repartition and format drives manually."); 887 done = FALSE; 888 } 889 if ( ptn_errs & !fmt_errs ) 890 { 891 mvaddstr_and_log_it( g_currentY++, 892 0, 893 "Errors occurred during partitioning. Formatting, however, went OK."); 894 done = TRUE; 895 } 896 if ( !done ) 897 { 898 if ( !ask_me_yes_or_no( "Re-edit the mountlist?" ) ) 899 { 900 retval++; 901 goto end_of_func; 902 } 903 } 904 } 905 } 906 907 /* mount */ 908 if ( mount_all_devices( mountlist, TRUE ) ) 909 { 910 unmount_all_devices( mountlist ); 911 retval++; 912 goto end_of_func; 913 } 914 /* restore */ 915 if ( ( restore_all = ask_me_yes_or_no( "Do you want me to restore all of your data?" ) ) ) 916 { 917 log_msg(1, "Restoring all data"); 918 retval += restore_everything( bkpinfo, NULL ); 919 } 920 else if ( ( restore_all = ask_me_yes_or_no( "Do you want me to restore _some_ of your data?") ) ) 921 { 922 strcpy( old_restpath, bkpinfo->restore_path ); 923 for( done = FALSE; !done; ) 924 { 925 unlink("/tmp/filelist.full"); 926 filelist = process_filelist_and_biggielist( bkpinfo ); 927 /* Now you have /tmp/tmpfs/filelist.restore-these and /tmp/tmpfs/biggielist.restore-these; 928 the former is a list of regular files; the latter, biggiefiles and imagedevs. 929 */ 930 if ( filelist ) 931 { 932 gotos_suck: 933 strcpy( tmp, old_restpath ); 803 { 804 log_msg(1, "Not resizing mountlist."); 805 } else { 806 resize_mountlist_proportionately_to_suit_new_drives(mountlist); 807 } 808 for (done = FALSE; !done;) { 809 iamhere("About to edit mountlist"); 810 if (g_text_mode) { 811 save_mountlist_to_disk(mountlist, g_mountlist_fname); 812 sprintf(tmp, "%s %s", find_my_editor(), g_mountlist_fname); 813 res = system(tmp); 814 load_mountlist(mountlist, g_mountlist_fname); 815 } else { 816 res = edit_mountlist(g_mountlist_fname, mountlist, raidlist); 817 } 818 iamhere("Finished editing mountlist"); 819 if (res) { 820 paranoid_MR_finish(1); 821 } 822 log_msg(2, "Proceeding..."); 823 save_mountlist_to_disk(mountlist, g_mountlist_fname); 824 save_raidlist_to_raidtab(raidlist, RAIDTAB_FNAME); 825 mvaddstr_and_log_it(1, 30, "Restoring Interactively"); 826 if (bkpinfo->differential) { 827 log_to_screen("Because this is a differential backup, disk"); 828 log_to_screen 829 (" partitioning and formatting will not take place."); 830 done = TRUE; 831 } else { 832 if (ask_me_yes_or_no 833 ("Do you want to erase and partition your hard drives?")) { 834 if (partition_table_contains_Compaq_diagnostic_partition 835 (mountlist)) { 836 offer_to_abort_because_Compaq_Proliants_suck(); 837 done = TRUE; 838 } else { 839 twenty_seconds_til_yikes(); 840 g_fprep = fopen("/tmp/prep.sh", "w"); 841 ptn_errs = partition_everything(mountlist); 842 if (ptn_errs) { 843 log_to_screen 844 ("Warning. Errors occurred during disk partitioning."); 845 } 846 847 fmt_errs = format_everything(mountlist, FALSE); 848 if (!fmt_errs) { 849 log_to_screen 850 ("Errors during disk partitioning were handled OK."); 851 log_to_screen 852 ("Partitions were formatted OK despite those errors."); 853 ptn_errs = 0; 854 } 855 if (!ptn_errs && !fmt_errs) { 856 done = TRUE; 857 } 858 } 859 paranoid_fclose(g_fprep); 860 } else { 861 mvaddstr_and_log_it(g_currentY++, 0, 862 "User opted not to partition the devices"); 863 if (ask_me_yes_or_no 864 ("Do you want to format your hard drives?")) { 865 fmt_errs = format_everything(mountlist, TRUE); 866 if (!fmt_errs) { 867 done = TRUE; 868 } 869 } else { 870 ptn_errs = fmt_errs = 0; 871 done = TRUE; 872 } 873 } 874 if (fmt_errs) { 875 mvaddstr_and_log_it(g_currentY++, 876 0, 877 "Errors occurred. Please repartition and format drives manually."); 878 done = FALSE; 879 } 880 if (ptn_errs & !fmt_errs) { 881 mvaddstr_and_log_it(g_currentY++, 882 0, 883 "Errors occurred during partitioning. Formatting, however, went OK."); 884 done = TRUE; 885 } 886 if (!done) { 887 if (!ask_me_yes_or_no("Re-edit the mountlist?")) { 888 retval++; 889 goto end_of_func; 890 } 891 } 892 } 893 } 894 895 /* mount */ 896 if (mount_all_devices(mountlist, TRUE)) { 897 unmount_all_devices(mountlist); 898 retval++; 899 goto end_of_func; 900 } 901 /* restore */ 902 if ((restore_all = 903 ask_me_yes_or_no("Do you want me to restore all of your data?"))) 904 { 905 log_msg(1, "Restoring all data"); 906 retval += restore_everything(bkpinfo, NULL); 907 } else 908 if ((restore_all = 909 ask_me_yes_or_no 910 ("Do you want me to restore _some_ of your data?"))) { 911 strcpy(old_restpath, bkpinfo->restore_path); 912 for (done = FALSE; !done;) { 913 unlink("/tmp/filelist.full"); 914 filelist = process_filelist_and_biggielist(bkpinfo); 915 /* Now you have /tmp/tmpfs/filelist.restore-these and /tmp/tmpfs/biggielist.restore-these; 916 the former is a list of regular files; the latter, biggiefiles and imagedevs. 917 */ 918 if (filelist) { 919 gotos_suck: 920 strcpy(tmp, old_restpath); 934 921 // (NB: %s is where your filesystem is mounted now, by default)", MNT_RESTORING); 935 if ( popup_and_get_string( "Restore path", "Restore files to where?", tmp, MAX_STR_LEN/4 ) ) 936 { 937 if ( !strcmp( tmp, "/" ) ) 938 { 939 if ( !ask_me_yes_or_no( "Are you sure?" ) ) 940 { 941 goto gotos_suck; 942 } 943 tmp[0] = '\0'; // so we restore to [blank]/file/name :) 944 } 945 strcpy( bkpinfo->restore_path, tmp ); 946 log_msg(1, "Restoring subset"); 947 retval += restore_everything( bkpinfo, filelist ); 948 free_filelist( filelist ); 949 } 950 else 951 { 952 strcpy( bkpinfo->restore_path, old_restpath ); 953 free_filelist( filelist ); 954 } 955 if ( !ask_me_yes_or_no( "Restore another subset of your backup?" ) ) 956 { 957 done = TRUE; 958 } 959 } 960 else 961 { 962 done = TRUE; 963 } 964 } 965 strcpy( old_restpath, bkpinfo->restore_path ); 966 } 967 else 968 { 969 mvaddstr_and_log_it( g_currentY++, 970 0, 971 "User opted not to restore any data. "); 972 } 973 if ( retval ) 974 { 975 mvaddstr_and_log_it( g_currentY++, 976 0, 977 "Errors occurred during the restore phase. "); 978 } 979 980 if (ask_me_yes_or_no( "Initialize the boot loader?" ) ) 981 { 982 run_boot_loader( TRUE ); 983 } 984 else 985 { 986 mvaddstr_and_log_it( g_currentY++, 987 0, 988 "User opted not to initialize the boot loader."); 989 } 922 if (popup_and_get_string 923 ("Restore path", "Restore files to where?", tmp, 924 MAX_STR_LEN / 4)) { 925 if (!strcmp(tmp, "/")) { 926 if (!ask_me_yes_or_no("Are you sure?")) { 927 goto gotos_suck; 928 } 929 tmp[0] = '\0'; // so we restore to [blank]/file/name :) 930 } 931 strcpy(bkpinfo->restore_path, tmp); 932 log_msg(1, "Restoring subset"); 933 retval += restore_everything(bkpinfo, filelist); 934 free_filelist(filelist); 935 } else { 936 strcpy(bkpinfo->restore_path, old_restpath); 937 free_filelist(filelist); 938 } 939 if (!ask_me_yes_or_no 940 ("Restore another subset of your backup?")) { 941 done = TRUE; 942 } 943 } else { 944 done = TRUE; 945 } 946 } 947 strcpy(old_restpath, bkpinfo->restore_path); 948 } else { 949 mvaddstr_and_log_it(g_currentY++, 950 0, 951 "User opted not to restore any data. "); 952 } 953 if (retval) { 954 mvaddstr_and_log_it(g_currentY++, 955 0, 956 "Errors occurred during the restore phase. "); 957 } 958 959 if (ask_me_yes_or_no("Initialize the boot loader?")) { 960 run_boot_loader(TRUE); 961 } else { 962 mvaddstr_and_log_it(g_currentY++, 963 0, 964 "User opted not to initialize the boot loader."); 965 } 990 966 991 967 // run_program_and_log_output("cp -af /etc/lvm " MNT_RESTORING "/etc/", 1); 992 protect_against_braindead_sysadmins(); 993 // modify_rclocal_one_time( MNT_RESTORING "/etc" ); 994 retval += unmount_all_devices( mountlist ); 995 /* if (restore_some || restore_all || */ 996 if ( ask_me_yes_or_no( "Label your ext2 and ext3 partitions if necessary?" ) ) 997 { 998 mvaddstr_and_log_it( g_currentY, 999 0, 1000 "Using e2label to label your ext2,3 partitions" ); 1001 if ( does_file_exist( "/tmp/fstab.new" ) ) 1002 { 1003 strcpy( fstab_fname, "/tmp/fstab.new"); 1004 } 1005 else 1006 { 1007 strcpy( fstab_fname, "/tmp/fstab"); 1008 } 1009 sprintf( tmp, 1010 "label-partitions-as-necessary %s < %s >> %s 2>> %s", g_mountlist_fname, 1011 fstab_fname, MONDO_LOGFILE, MONDO_LOGFILE); 1012 res=system( tmp ); 1013 if ( res ) 1014 { 1015 log_to_screen("label-partitions-as-necessary returned an error"); 1016 mvaddstr_and_log_it( g_currentY++, 74, "Failed."); 1017 } 1018 else 1019 { 1020 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 1021 } 1022 retval += res; 1023 } 1024 1025 iamhere("About to leave interactive_mode()"); 1026 if ( retval ) 1027 { 1028 mvaddstr_and_log_it(g_currentY++, 1029 0, 1030 "Warning - errors occurred during the restore phase."); 1031 } 1032 end_of_func: 1033 paranoid_free(tmp); 1034 paranoid_free(fstab_fname); 1035 paranoid_free(old_restpath); 1036 iamhere("Leaving interactive_mode()"); 1037 return( retval ); 968 protect_against_braindead_sysadmins(); 969 // modify_rclocal_one_time( MNT_RESTORING "/etc" ); 970 retval += unmount_all_devices(mountlist); 971 /* if (restore_some || restore_all || */ 972 if (ask_me_yes_or_no 973 ("Label your ext2 and ext3 partitions if necessary?")) { 974 mvaddstr_and_log_it(g_currentY, 0, 975 "Using e2label to label your ext2,3 partitions"); 976 if (does_file_exist("/tmp/fstab.new")) { 977 strcpy(fstab_fname, "/tmp/fstab.new"); 978 } else { 979 strcpy(fstab_fname, "/tmp/fstab"); 980 } 981 sprintf(tmp, 982 "label-partitions-as-necessary %s < %s >> %s 2>> %s", 983 g_mountlist_fname, fstab_fname, MONDO_LOGFILE, 984 MONDO_LOGFILE); 985 res = system(tmp); 986 if (res) { 987 log_to_screen 988 ("label-partitions-as-necessary returned an error"); 989 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 990 } else { 991 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 992 } 993 retval += res; 994 } 995 996 iamhere("About to leave interactive_mode()"); 997 if (retval) { 998 mvaddstr_and_log_it(g_currentY++, 999 0, 1000 "Warning - errors occurred during the restore phase."); 1001 } 1002 end_of_func: 1003 paranoid_free(tmp); 1004 paranoid_free(fstab_fname); 1005 paranoid_free(old_restpath); 1006 iamhere("Leaving interactive_mode()"); 1007 return (retval); 1038 1008 } 1009 1039 1010 /************************************************************************** 1040 1011 *END_INTERACTIVE_MODE * … … 1052 1023 * @return 0 for success, or the number of errors encountered. 1053 1024 */ 1054 int 1055 iso_mode(struct s_bkpinfo *bkpinfo, 1056 struct mountlist_itself *mountlist, 1057 struct raidlist_itself *raidlist, 1058 bool nuke_me_please) 1025 int 1026 iso_mode(struct s_bkpinfo *bkpinfo, 1027 struct mountlist_itself *mountlist, 1028 struct raidlist_itself *raidlist, bool nuke_me_please) 1059 1029 { 1060 char c; 1061 int retval=0; 1062 1063 assert(bkpinfo!=NULL); 1064 assert(mountlist!=NULL); 1065 assert(raidlist!=NULL); 1066 if (iso_fiddly_bits(bkpinfo, nuke_me_please)) 1067 { log_msg(1,"iso_mode --- returning w/ error"); return(1); } 1068 else 1069 { 1070 c=which_restore_mode(); 1071 if (c=='I' || c=='N' || c=='C') 1072 { interactively_obtain_media_parameters_from_user(bkpinfo, FALSE); } 1073 if (c=='I') { retval+=interactive_mode(bkpinfo,mountlist,raidlist); } 1074 else if (c=='N') { retval+=nuke_mode(bkpinfo,mountlist,raidlist); } 1075 else if (c=='C') { retval+=compare_mode(bkpinfo,mountlist,raidlist); } 1076 else 1077 { log_to_screen("OK, I shan't restore/compare any files."); } 1078 } 1079 if (is_this_device_mounted(MNT_CDROM)) { paranoid_system("umount "MNT_CDROM); } 1030 char c; 1031 int retval = 0; 1032 1033 assert(bkpinfo != NULL); 1034 assert(mountlist != NULL); 1035 assert(raidlist != NULL); 1036 if (iso_fiddly_bits(bkpinfo, nuke_me_please)) { 1037 log_msg(1, "iso_mode --- returning w/ error"); 1038 return (1); 1039 } else { 1040 c = which_restore_mode(); 1041 if (c == 'I' || c == 'N' || c == 'C') { 1042 interactively_obtain_media_parameters_from_user(bkpinfo, 1043 FALSE); 1044 } 1045 if (c == 'I') { 1046 retval += interactive_mode(bkpinfo, mountlist, raidlist); 1047 } else if (c == 'N') { 1048 retval += nuke_mode(bkpinfo, mountlist, raidlist); 1049 } else if (c == 'C') { 1050 retval += compare_mode(bkpinfo, mountlist, raidlist); 1051 } else { 1052 log_to_screen("OK, I shan't restore/compare any files."); 1053 } 1054 } 1055 if (is_this_device_mounted(MNT_CDROM)) { 1056 paranoid_system("umount " MNT_CDROM); 1057 } 1080 1058 // if (! already_mounted) 1081 1059 // { 1082 if (system("umount /tmp/isodir 2> /dev/null")) { log_to_screen("WARNING - unable to unmount device where the ISO files are stored."); } 1060 if (system("umount /tmp/isodir 2> /dev/null")) { 1061 log_to_screen 1062 ("WARNING - unable to unmount device where the ISO files are stored."); 1063 } 1083 1064 // } 1084 return( retval);1065 return (retval); 1085 1066 } 1067 1086 1068 /************************************************************************** 1087 1069 *END_ISO_MODE * … … 1103 1085 * @warning <b><i>THIS WILL ERASE ALL EXISTING DATA!</i></b> 1104 1086 */ 1105 int 1106 nuke_mode( struct s_bkpinfo *bkpinfo,1107 1108 struct raidlist_itself *raidlist)1087 int 1088 nuke_mode(struct s_bkpinfo *bkpinfo, 1089 struct mountlist_itself *mountlist, 1090 struct raidlist_itself *raidlist) 1109 1091 { 1110 1111 1112 1092 int retval = 0; 1093 int res = 0; 1094 bool boot_loader_installed = FALSE; 1113 1095 /** malloc **/ 1114 char tmp[MAX_STR_LEN], tmpA[MAX_STR_LEN], tmpB[MAX_STR_LEN], tmpC[MAX_STR_LEN]; 1115 1116 assert(bkpinfo!=NULL); 1117 assert(mountlist!=NULL); 1118 assert(raidlist!=NULL); 1119 1120 log_msg(2, "nuke_mode --- starting"); 1121 1122 get_cfg_file_from_archive_or_bust(bkpinfo); 1123 load_mountlist( mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo updated the mountlist 1096 char tmp[MAX_STR_LEN], tmpA[MAX_STR_LEN], tmpB[MAX_STR_LEN], 1097 tmpC[MAX_STR_LEN]; 1098 1099 assert(bkpinfo != NULL); 1100 assert(mountlist != NULL); 1101 assert(raidlist != NULL); 1102 1103 log_msg(2, "nuke_mode --- starting"); 1104 1105 get_cfg_file_from_archive_or_bust(bkpinfo); 1106 load_mountlist(mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo updated the mountlist 1124 1107 #ifdef __FreeBSD__ 1125 if (strstr(call_program_and_get_last_line_of_output("cat /tmp/cmdline"), "noresize")) 1108 if (strstr 1109 (call_program_and_get_last_line_of_output("cat /tmp/cmdline"), 1110 "noresize")) 1126 1111 #else 1127 if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "noresize")) 1112 if (strstr 1113 (call_program_and_get_last_line_of_output("cat /proc/cmdline"), 1114 "noresize")) 1128 1115 #endif 1129 { log_msg(2, "Not resizing mountlist."); }1130 else1131 { resize_mountlist_proportionately_to_suit_new_drives(mountlist); }1132 if (!evaluate_mountlist( mountlist, tmpA, tmpB, tmpC ))1133 {1134 sprintf(tmp, "Mountlist analyzed. Result: \"%s %s %s\" Switch to Interactive Mode?", tmpA, tmpB, tmpC);1135 if (ask_me_yes_or_no(tmp) )1136 1116 { 1137 retval = interactive_mode( bkpinfo, mountlist, raidlist ); 1138 finish(retval); 1139 } 1140 else 1117 log_msg(2, "Not resizing mountlist."); 1118 } else { 1119 resize_mountlist_proportionately_to_suit_new_drives(mountlist); 1120 } 1121 if (!evaluate_mountlist(mountlist, tmpA, tmpB, tmpC)) { 1122 sprintf(tmp, 1123 "Mountlist analyzed. Result: \"%s %s %s\" Switch to Interactive Mode?", 1124 tmpA, tmpB, tmpC); 1125 if (ask_me_yes_or_no(tmp)) { 1126 retval = interactive_mode(bkpinfo, mountlist, raidlist); 1127 finish(retval); 1128 } else { 1129 fatal_error("Nuke Mode aborted. "); 1130 } 1131 } 1132 save_mountlist_to_disk(mountlist, g_mountlist_fname); 1133 mvaddstr_and_log_it(1, 30, "Restoring Automatically"); 1134 if (bkpinfo->differential) { 1135 log_to_screen("Because this is a differential backup, disk"); 1136 log_to_screen("partitioning and formatting will not take place."); 1137 res = 0; 1138 } else { 1139 if (partition_table_contains_Compaq_diagnostic_partition 1140 (mountlist)) { 1141 offer_to_abort_because_Compaq_Proliants_suck(); 1142 } else { 1143 twenty_seconds_til_yikes(); 1144 g_fprep = fopen("/tmp/prep.sh", "w"); 1145 #ifdef __FreeBSD__ 1146 if (strstr 1147 (call_program_and_get_last_line_of_output 1148 ("cat /tmp/cmdline"), "nopart")) 1149 #else 1150 if (strstr 1151 (call_program_and_get_last_line_of_output 1152 ("cat /proc/cmdline"), "nopart")) 1153 #endif 1154 { 1155 log_msg(2, 1156 "Not partitioning drives due to 'nopart' option."); 1157 res = 0; 1158 } else { 1159 res = partition_everything(mountlist); 1160 if (res) { 1161 log_to_screen 1162 ("Warning. Errors occurred during partitioning."); 1163 res = 0; 1164 } 1165 } 1166 retval += res; 1167 if (!res) { 1168 log_to_screen("Preparing to format your disk(s)"); 1169 sleep(1); 1170 system("sync"); 1171 log_to_screen("Please wait. This may take a few minutes."); 1172 res += format_everything(mountlist, FALSE); 1173 } 1174 paranoid_fclose(g_fprep); 1175 } 1176 } 1177 retval += res; 1178 if (res) { 1179 mvaddstr_and_log_it(g_currentY++, 1180 0, 1181 "Failed to partition and/or format your hard drives."); 1182 1183 if (ask_me_yes_or_no("Try in interactive mode instead?")) { 1184 retval = interactive_mode(bkpinfo, mountlist, raidlist); 1185 goto after_the_nuke; 1186 } else 1187 if (!ask_me_yes_or_no 1188 ("Would you like to try to proceed anyway?")) { 1189 return (retval); 1190 } 1191 } 1192 retval = mount_all_devices(mountlist, TRUE); 1193 if (retval) { 1194 unmount_all_devices(mountlist); 1195 log_to_screen 1196 ("Unable to mount all partitions. Sorry, I cannot proceed."); 1197 return (retval); 1198 } 1199 iamhere("Restoring everything"); 1200 retval += restore_everything(bkpinfo, NULL); 1201 if (!run_boot_loader(FALSE)) { 1202 log_msg(1, 1203 "Great! Boot loader was installed. No need for msg at end."); 1204 boot_loader_installed = TRUE; 1205 } 1206 protect_against_braindead_sysadmins(); 1207 // run_program_and_log_output("cp -af /etc/lvm " MNT_RESTORING "/etc/", 1); 1208 // modify_rclocal_one_time( MNT_RESTORING "/etc" ); 1209 retval += unmount_all_devices(mountlist); 1210 mvaddstr_and_log_it(g_currentY, 1211 0, 1212 "Using e2label to label your ext2,3 partitions"); 1213 1214 sprintf(tmp, "label-partitions-as-necessary %s < /tmp/fstab", 1215 g_mountlist_fname); 1216 res = run_program_and_log_output(tmp, TRUE); 1217 if (res) { 1218 log_to_screen("label-partitions-as-necessary returned an error"); 1219 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 1220 } else { 1221 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 1222 } 1223 retval += res; 1224 1225 after_the_nuke: 1226 if (retval) { 1227 log_to_screen("Errors occurred during the nuke phase."); 1228 } else if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "RESTORE")) // Bruno's thing 1141 1229 { 1142 fatal_error( "Nuke Mode aborted. "); 1143 } 1144 } 1145 save_mountlist_to_disk( mountlist, g_mountlist_fname ); 1146 mvaddstr_and_log_it( 1, 30, "Restoring Automatically" ); 1147 if ( bkpinfo->differential ) 1148 { 1149 log_to_screen( "Because this is a differential backup, disk" ); 1150 log_to_screen( "partitioning and formatting will not take place." ); 1151 res = 0; 1152 } 1153 else 1154 { 1155 if ( partition_table_contains_Compaq_diagnostic_partition( mountlist ) ) 1156 { 1157 offer_to_abort_because_Compaq_Proliants_suck(); 1158 } 1159 else 1160 { 1161 twenty_seconds_til_yikes(); 1162 g_fprep = fopen("/tmp/prep.sh", "w"); 1163 #ifdef __FreeBSD__ 1164 if (strstr (call_program_and_get_last_line_of_output ("cat /tmp/cmdline"), "nopart")) 1230 log_to_screen 1231 ("PC was restored successfully. Thank you for using Mondo Rescue."); 1232 log_to_screen 1233 ("Please visit http://www.mondorescue.org and thank the dev team."); 1234 } else { 1235 #ifdef FREELOADER 1236 success_message(); 1165 1237 #else 1166 if (strstr (call_program_and_get_last_line_of_output ("cat /proc/cmdline"), "nopart"))1238 log_to_screen("PC was restored successfully!"); 1167 1239 #endif 1168 { 1169 log_msg (2, "Not partitioning drives due to 'nopart' option."); 1170 res = 0; 1171 } 1172 else 1173 { 1174 res = partition_everything( mountlist ); 1175 if (res) 1176 { 1177 log_to_screen("Warning. Errors occurred during partitioning."); 1178 res = 0; 1179 } 1180 } 1181 retval += res; 1182 if ( !res ) 1183 { 1184 log_to_screen("Preparing to format your disk(s)"); 1185 sleep(1); 1186 system("sync"); 1187 log_to_screen("Please wait. This may take a few minutes."); 1188 res += format_everything( mountlist, FALSE ); 1189 } 1190 paranoid_fclose(g_fprep); 1191 } 1192 } 1193 retval += res; 1194 if ( res ) 1195 { 1196 mvaddstr_and_log_it( g_currentY++, 1197 0, 1198 "Failed to partition and/or format your hard drives."); 1199 1200 if ( ask_me_yes_or_no( "Try in interactive mode instead?" ) ) 1201 { 1202 retval = interactive_mode( bkpinfo, mountlist, raidlist ); 1203 goto after_the_nuke; 1204 } 1205 else if ( !ask_me_yes_or_no( "Would you like to try to proceed anyway?" ) ) 1206 { 1207 return( retval ); 1208 } 1209 } 1210 retval = mount_all_devices( mountlist, TRUE ); 1211 if ( retval ) 1212 { 1213 unmount_all_devices( mountlist ); 1214 log_to_screen("Unable to mount all partitions. Sorry, I cannot proceed."); 1215 return( retval ); 1216 } 1217 iamhere("Restoring everything"); 1218 retval += restore_everything( bkpinfo, NULL ); 1219 if (!run_boot_loader( FALSE )) 1220 { 1221 log_msg(1, "Great! Boot loader was installed. No need for msg at end."); 1222 boot_loader_installed = TRUE; 1223 } 1224 protect_against_braindead_sysadmins(); 1225 // run_program_and_log_output("cp -af /etc/lvm " MNT_RESTORING "/etc/", 1); 1226 // modify_rclocal_one_time( MNT_RESTORING "/etc" ); 1227 retval += unmount_all_devices( mountlist ); 1228 mvaddstr_and_log_it( g_currentY, 1229 0, 1230 "Using e2label to label your ext2,3 partitions"); 1231 1232 sprintf( tmp, "label-partitions-as-necessary %s < /tmp/fstab", g_mountlist_fname ); 1233 res = run_program_and_log_output( tmp, TRUE ); 1234 if ( res ) 1235 { 1236 log_to_screen( "label-partitions-as-necessary returned an error" ); 1237 mvaddstr_and_log_it( g_currentY++, 74, "Failed." ); 1238 } 1239 else 1240 { 1241 mvaddstr_and_log_it( g_currentY++, 74, "Done." ); 1242 } 1243 retval += res; 1244 1245 after_the_nuke: 1246 if (retval) 1247 { 1248 log_to_screen("Errors occurred during the nuke phase."); 1249 } 1250 else if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "RESTORE")) // Bruno's thing 1251 { 1252 log_to_screen("PC was restored successfully. Thank you for using Mondo Rescue."); 1253 log_to_screen("Please visit http://www.mondorescue.org and thank the dev team."); 1254 } 1255 else 1256 { 1257 #ifdef FREELOADER 1258 success_message(); 1259 #else 1260 log_to_screen("PC was restored successfully!"); 1261 #endif 1262 } 1263 g_I_have_just_nuked = TRUE; 1240 } 1241 g_I_have_just_nuked = TRUE; 1264 1242 /* 1265 1243 if (!boot_loader_installed && !does_file_exist(DO_MBR_PLEASE)) … … 1269 1247 } 1270 1248 */ 1271 return( retval);1249 return (retval); 1272 1250 } 1273 1251 … … 1284 1262 * @return 0 for success, or the number of errors encountered. 1285 1263 */ 1286 int 1287 restore_to_live_filesystem( struct s_bkpinfo *bkpinfo ) 1264 int restore_to_live_filesystem(struct s_bkpinfo *bkpinfo) 1288 1265 { 1289 1266 int retval = 0; 1290 1267 1291 1268 /** malloc **/ 1292 1293 1294 1269 char *old_restpath; 1270 1271 struct mountlist_itself *mountlist; 1295 1272 // static 1296 struct raidlist_itself *raidlist; 1297 struct s_node *filelist; 1298 1299 log_msg(1, "restore_to_live_filesystem() - starting"); 1300 assert(bkpinfo!=NULL); 1301 malloc_string(old_restpath); 1302 mountlist = malloc(sizeof(struct mountlist_itself)); 1303 raidlist = malloc(sizeof(struct raidlist_itself)); 1304 if (!mountlist || !raidlist) { fatal_error("Cannot malloc() mountlist and/or raidlist"); } 1305 1306 strcpy(bkpinfo->restore_path, "/"); 1307 if ( !g_restoring_live_from_cd) 1308 { 1309 popup_and_OK("Please insert tape/CD/boot floppy, then hit 'OK' to continue."); 1310 sleep( 1 ); 1311 } 1312 interactively_obtain_media_parameters_from_user(bkpinfo, FALSE); 1313 log_msg(2, "bkpinfo->media_device = %s", bkpinfo->media_device ); 1314 if ( !bkpinfo->media_device[0] ) 1315 { 1316 log_msg(2, "Warning - failed to find media dev"); 1317 } 1318 1319 1320 log_msg(2, "bkpinfo->isodir = %s", bkpinfo->isodir); 1321 1322 open_evalcall_form("Thinking..."); 1323 1324 get_cfg_file_from_archive_or_bust ( bkpinfo ); 1325 read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo); 1326 load_mountlist( mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo 1327 1328 close_evalcall_form(); 1329 retval = load_mountlist(mountlist, g_mountlist_fname ); 1330 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME ); 1331 filelist = process_filelist_and_biggielist( bkpinfo ); 1332 if ( filelist ) 1333 { 1334 save_filelist(filelist, "/tmp/selected-files.txt"); 1335 strcpy( old_restpath, bkpinfo->restore_path ); 1336 if ( popup_and_get_string( "Restore path", 1337 "Restore files to where? )", 1338 bkpinfo->restore_path, MAX_STR_LEN/4 ) ) 1339 { 1340 iamhere("Restoring everything"); 1341 retval += restore_everything( bkpinfo, filelist ); 1342 free_filelist( filelist ); 1343 strcpy(bkpinfo->restore_path, old_restpath); 1344 } 1345 else 1346 { 1347 free_filelist(filelist); 1348 } 1349 strcpy(bkpinfo->restore_path, old_restpath); 1350 } 1351 if ( IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type ) ) 1352 { 1353 log_msg(2, "I probably don't need to unmount or eject the CD-ROM but I'm doing it anyway."); 1354 } 1355 run_program_and_log_output( "umount "MNT_CDROM, FALSE ); 1356 if (!bkpinfo->please_dont_eject) { eject_device( bkpinfo->media_device ); } 1357 paranoid_free(old_restpath); 1358 free(mountlist); 1359 free(raidlist); 1360 return( retval ); 1273 struct raidlist_itself *raidlist; 1274 struct s_node *filelist; 1275 1276 log_msg(1, "restore_to_live_filesystem() - starting"); 1277 assert(bkpinfo != NULL); 1278 malloc_string(old_restpath); 1279 mountlist = malloc(sizeof(struct mountlist_itself)); 1280 raidlist = malloc(sizeof(struct raidlist_itself)); 1281 if (!mountlist || !raidlist) { 1282 fatal_error("Cannot malloc() mountlist and/or raidlist"); 1283 } 1284 1285 strcpy(bkpinfo->restore_path, "/"); 1286 if (!g_restoring_live_from_cd) { 1287 popup_and_OK 1288 ("Please insert tape/CD/boot floppy, then hit 'OK' to continue."); 1289 sleep(1); 1290 } 1291 interactively_obtain_media_parameters_from_user(bkpinfo, FALSE); 1292 log_msg(2, "bkpinfo->media_device = %s", bkpinfo->media_device); 1293 if (!bkpinfo->media_device[0]) { 1294 log_msg(2, "Warning - failed to find media dev"); 1295 } 1296 1297 1298 log_msg(2, "bkpinfo->isodir = %s", bkpinfo->isodir); 1299 1300 open_evalcall_form("Thinking..."); 1301 1302 get_cfg_file_from_archive_or_bust(bkpinfo); 1303 read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo); 1304 load_mountlist(mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo 1305 1306 close_evalcall_form(); 1307 retval = load_mountlist(mountlist, g_mountlist_fname); 1308 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME); 1309 filelist = process_filelist_and_biggielist(bkpinfo); 1310 if (filelist) { 1311 save_filelist(filelist, "/tmp/selected-files.txt"); 1312 strcpy(old_restpath, bkpinfo->restore_path); 1313 if (popup_and_get_string("Restore path", 1314 "Restore files to where? )", 1315 bkpinfo->restore_path, MAX_STR_LEN / 4)) { 1316 iamhere("Restoring everything"); 1317 retval += restore_everything(bkpinfo, filelist); 1318 free_filelist(filelist); 1319 strcpy(bkpinfo->restore_path, old_restpath); 1320 } else { 1321 free_filelist(filelist); 1322 } 1323 strcpy(bkpinfo->restore_path, old_restpath); 1324 } 1325 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 1326 log_msg(2, 1327 "I probably don't need to unmount or eject the CD-ROM but I'm doing it anyway."); 1328 } 1329 run_program_and_log_output("umount " MNT_CDROM, FALSE); 1330 if (!bkpinfo->please_dont_eject) { 1331 eject_device(bkpinfo->media_device); 1332 } 1333 paranoid_free(old_restpath); 1334 free(mountlist); 1335 free(raidlist); 1336 return (retval); 1361 1337 } 1362 1338 … … 1386 1362 int 1387 1363 restore_a_biggiefile_from_CD(struct s_bkpinfo *bkpinfo, 1388 long bigfileno, 1389 struct s_node*filelist, char*pathname_of_last_file_restored) 1364 long bigfileno, 1365 struct s_node *filelist, 1366 char *pathname_of_last_file_restored) 1390 1367 { 1391 1392 1393 1394 1368 FILE *fin; 1369 FILE *fout; 1370 FILE *fbzip2; 1371 1395 1372 /** malloc ***/ 1396 char *checksum, *outfile_fname, *tmp, *bzip2_command, *partimagehack_command, *suffix, *sz_devfile; 1397 char *bigblk;1398 char *p;1399 int retval = 0;1400 int finished = FALSE;1401 long sliceno;1402 long siz;1403 char partimagehack_fifo[MAX_STR_LEN];1404 char *file_to_openout = NULL;1405 struct s_filename_and_lstat_info biggiestruct;1406 struct utimbuf the_utime_buf, *ubuf;1407 bool use_partimage_hack=FALSE;1408 pid_t pid;1409 int res=0;1410 int old_loglevel;1411 char sz_msg[MAX_STR_LEN];1412 struct s_node *node;1413 1414 old_loglevel = g_loglevel; 1415 ubuf = &the_utime_buf;1416 assert(bkpinfo!=NULL);1417 1418 malloc_string(checksum); 1419 malloc_string(outfile_fname);1420 malloc_string(tmp);1421 malloc_string(bzip2_command);1422 malloc_string(partimagehack_command);1423 malloc_string(suffix);1424 malloc_string(sz_devfile);1425 1426 pathname_of_last_file_restored[0] = '\0'; 1427 if( !(bigblk = malloc( TAPE_BLOCK_SIZE ) ) ) 1428 1429 1430 1431 1432 if ( !(fin = fopen( slice_fname( bigfileno, 0, ARCHIVES_PATH, ""), "r" ) ) ) 1433 { 1434 log_to_screen( "Cannot even open bigfile's info file");1435 return( 1 ); 1436 } 1437 1438 memset((void*)&biggiestruct, 0, sizeof(biggiestruct)); 1439 if ( fread((void*)&biggiestruct, 1, sizeof(biggiestruct), fin) < sizeof(biggiestruct)) 1440 { 1441 log_msg(2, "Warning - unable to get biggiestruct of bigfile #%d", bigfileno+1);1442 1443 1444 1445 1446 1447 if ( !checksum[0]) 1448 { 1449 sprintf(tmp,"Warning - bigfile %ld does not have a checksum",bigfileno+1);1450 1451 1452 1453 1454 if (!strncmp ( biggiestruct.filename, "/dev/", 5))// Whether NTFS or not :)1455 { strcpy( outfile_fname, biggiestruct.filename); } 1456 else 1457 { sprintf( outfile_fname, "%s/%s", bkpinfo->restore_path, biggiestruct.filename ); } 1458 1459 /* skip file if we have a selective restore subset & it doesn't match */ 1460 if (filelist != NULL) 1461 { 1462 node = find_string_at_node(filelist, biggiestruct.filename); 1463 if (!node) 1464 { 1465 log_msg(0, "Skipping %s (name isn't in filelist)", biggiestruct.filename); 1466 pathname_of_last_file_restored[0] = '\0'; 1467 return (0);1468 } 1469 else if (!(node->selected)) 1470 1471 log_msg(1, "Skipping %s (name isn't in biggielist subset)", biggiestruct.filename);1472 pathname_of_last_file_restored[0] = '\0';1473 return( 0 );1474 } 1475 1476 /* otherwise, continue */ 1477 1478 log_msg(1, "DEFINITELY restoring %s", biggiestruct.filename); 1479 if (biggiestruct.use_partimagehack) 1480 1481 if (strncmp ( biggiestruct.filename, "/dev/", 5)) 1482 { 1483 log_msg(1,"I was in error when I set biggiestruct.use_partimagehack to TRUE.");1484 1485 1486 }1487 1488 1489 if (biggiestruct.use_partimagehack)// if it's an NTFS device1373 char *checksum, *outfile_fname, *tmp, *bzip2_command, 1374 *partimagehack_command, *suffix, *sz_devfile; 1375 char *bigblk; 1376 char *p; 1377 int retval = 0; 1378 int finished = FALSE; 1379 long sliceno; 1380 long siz; 1381 char partimagehack_fifo[MAX_STR_LEN]; 1382 char *file_to_openout = NULL; 1383 struct s_filename_and_lstat_info biggiestruct; 1384 struct utimbuf the_utime_buf, *ubuf; 1385 bool use_partimage_hack = FALSE; 1386 pid_t pid; 1387 int res = 0; 1388 int old_loglevel; 1389 char sz_msg[MAX_STR_LEN]; 1390 struct s_node *node; 1391 1392 old_loglevel = g_loglevel; 1393 ubuf = &the_utime_buf; 1394 assert(bkpinfo != NULL); 1395 1396 malloc_string(checksum); 1397 malloc_string(outfile_fname); 1398 malloc_string(tmp); 1399 malloc_string(bzip2_command); 1400 malloc_string(partimagehack_command); 1401 malloc_string(suffix); 1402 malloc_string(sz_devfile); 1403 1404 pathname_of_last_file_restored[0] = '\0'; 1405 if (!(bigblk = malloc(TAPE_BLOCK_SIZE))) { 1406 fatal_error("Cannot malloc bigblk"); 1407 } 1408 1409 if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) { 1410 log_to_screen("Cannot even open bigfile's info file"); 1411 return (1); 1412 } 1413 1414 memset((void *) &biggiestruct, 0, sizeof(biggiestruct)); 1415 if (fread((void *) &biggiestruct, 1, sizeof(biggiestruct), fin) < 1416 sizeof(biggiestruct)) { 1417 log_msg(2, "Warning - unable to get biggiestruct of bigfile #%d", 1418 bigfileno + 1); 1419 } 1420 paranoid_fclose(fin); 1421 1422 strcpy(checksum, biggiestruct.checksum); 1423 1424 if (!checksum[0]) { 1425 sprintf(tmp, "Warning - bigfile %ld does not have a checksum", 1426 bigfileno + 1); 1427 log_msg(3, tmp); 1428 p = checksum; 1429 } 1430 1431 if (!strncmp(biggiestruct.filename, "/dev/", 5)) // Whether NTFS or not :) 1432 { 1433 strcpy(outfile_fname, biggiestruct.filename); 1434 } else { 1435 sprintf(outfile_fname, "%s/%s", bkpinfo->restore_path, 1436 biggiestruct.filename); 1437 } 1438 1439 /* skip file if we have a selective restore subset & it doesn't match */ 1440 if (filelist != NULL) { 1441 node = find_string_at_node(filelist, biggiestruct.filename); 1442 if (!node) { 1443 log_msg(0, "Skipping %s (name isn't in filelist)", 1444 biggiestruct.filename); 1445 pathname_of_last_file_restored[0] = '\0'; 1446 return (0); 1447 } else if (!(node->selected)) { 1448 log_msg(1, "Skipping %s (name isn't in biggielist subset)", 1449 biggiestruct.filename); 1450 pathname_of_last_file_restored[0] = '\0'; 1451 return (0); 1452 } 1453 } 1454 /* otherwise, continue */ 1455 1456 log_msg(1, "DEFINITELY restoring %s", biggiestruct.filename); 1457 if (biggiestruct.use_partimagehack) { 1458 if (strncmp(biggiestruct.filename, "/dev/", 5)) { 1459 log_msg(1, 1460 "I was in error when I set biggiestruct.use_partimagehack to TRUE."); 1461 log_msg(1, "%s isn't even in /dev", biggiestruct.filename); 1462 biggiestruct.use_partimagehack = FALSE; 1463 } 1464 } 1465 1466 if (biggiestruct.use_partimagehack) // if it's an NTFS device 1490 1467 // if (!strncmp ( biggiestruct.filename, "/dev/", 5)) 1491 {1492 g_loglevel = 4;1493 use_partimage_hack = TRUE;1494 log_msg(2, "Calling partimagehack in background because %s is an NTFS /dev entry", outfile_fname);1495 sprintf(sz_devfile, "/tmp/%d.%d.000", (int)(random()%32768), (int)(random()%32768));1496 mkfifo(sz_devfile, 0x770);1497 strcpy(partimagehack_fifo, sz_devfile);1498 file_to_openout = partimagehack_fifo;1499 switch(pid=fork())1500 {1501 case -1: fatal_error("Fork failure");1502 case 0:1503 log_msg(3, "CHILD - fip - calling feed_outfrom_partimage(%s, %s)", biggiestruct.filename, partimagehack_fifo);1504 res=feed_outfrom_partimage(biggiestruct.filename, partimagehack_fifo);1505 // log_msg(3, "CHILD - fip - exiting");1506 exit(res);1507 break;1508 default:1509 log_msg(3, "feed_into_partimage() called in background --- pid=%ld", (long int)(pid));1510 }1511 }1512 else1513 {1514 use_partimage_hack = FALSE;1515 partimagehack_fifo[0] = '\0';1516 file_to_openout = outfile_fname;1517 if ( !does_file_exist( outfile_fname ) ) // yes, it looks weird with the '!' but it's correct that way1518 { make_hole_for_file( outfile_fname ); }1519 }1520 1521 sprintf( tmp, "Reassembling big file %ld (%s)", bigfileno+1, outfile_fname );1522 log_msg(2, tmp );1523 1524 /*1525 last slice is zero-length and uncompressed; when we find it, we stop.1526 We DON'T wait until there are no more slices; if we did that,1527 We might stop at end of CD, not at last slice (which is 0-len and uncompd)1528 */1529 1530 strncpy(pathname_of_last_file_restored, biggiestruct.filename, MAX_STR_LEN-1);1531 pathname_of_last_file_restored[MAX_STR_LEN-1] = '\0';1532 1533 log_msg(3, "file_to_openout = %s", file_to_openout);1534 if ( !(fout = fopen( file_to_openout, "w" ) ) )1535 {1536 log_to_screen( "Cannot openout outfile_fname - hard disk full?");1537 return(1);1538 }1539 log_msg(3, "Opened out to %s", outfile_fname); // CD/DVD --> mondorestore --> partimagehack --> hard disk itself1540 1541 for( sliceno = 1, finished = FALSE; !finished; )1542 {1543 if ( !does_file_exist(slice_fname(bigfileno,sliceno,ARCHIVES_PATH,"")) && !does_file_exist(slice_fname(bigfileno,sliceno,ARCHIVES_PATH,"lzo")) && !does_file_exist(slice_fname(bigfileno,sliceno,ARCHIVES_PATH,"bz2")))1544 1468 { 1545 log_msg(3, "Cannot find a data slice or terminator slice on CD %d", g_current_media_number); 1546 g_current_media_number++; 1547 sprintf( tmp, "Asking for %s #%d so that I may read slice #%ld\n",media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number,sliceno); 1548 log_msg(2, tmp ); 1549 sprintf( tmp, "Restoring from %s #%d", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number ); 1550 log_to_screen( tmp ); 1551 insist_on_this_cd_number( bkpinfo, g_current_media_number ); 1552 log_to_screen( "Continuing to restore."); 1553 } 1554 else 1555 { 1556 strcpy(tmp, slice_fname(bigfileno,sliceno,ARCHIVES_PATH,"")); 1557 if (does_file_exist(tmp) && length_of_file(tmp) == 0) 1558 { 1559 log_msg(2, "End of bigfile # %ld (slice %ld is the terminator)", bigfileno + 1, sliceno ); 1560 finished = TRUE; 1561 continue; 1562 } 1563 else 1564 { 1565 if ( does_file_exist(slice_fname(bigfileno, sliceno,ARCHIVES_PATH, "lzo" ) ) ) 1469 g_loglevel = 4; 1470 use_partimage_hack = TRUE; 1471 log_msg(2, 1472 "Calling partimagehack in background because %s is an NTFS /dev entry", 1473 outfile_fname); 1474 sprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768), 1475 (int) (random() % 32768)); 1476 mkfifo(sz_devfile, 0x770); 1477 strcpy(partimagehack_fifo, sz_devfile); 1478 file_to_openout = partimagehack_fifo; 1479 switch (pid = fork()) { 1480 case -1: 1481 fatal_error("Fork failure"); 1482 case 0: 1483 log_msg(3, 1484 "CHILD - fip - calling feed_outfrom_partimage(%s, %s)", 1485 biggiestruct.filename, partimagehack_fifo); 1486 res = 1487 feed_outfrom_partimage(biggiestruct.filename, 1488 partimagehack_fifo); 1489 // log_msg(3, "CHILD - fip - exiting"); 1490 exit(res); 1491 break; 1492 default: 1493 log_msg(3, 1494 "feed_into_partimage() called in background --- pid=%ld", 1495 (long int) (pid)); 1496 } 1497 } else { 1498 use_partimage_hack = FALSE; 1499 partimagehack_fifo[0] = '\0'; 1500 file_to_openout = outfile_fname; 1501 if (!does_file_exist(outfile_fname)) // yes, it looks weird with the '!' but it's correct that way 1566 1502 { 1567 strcpy( bzip2_command, "lzop" ); 1568 strcpy( suffix, "lzo"); 1569 } 1570 else if ( does_file_exist( slice_fname( bigfileno, sliceno, ARCHIVES_PATH, "bz2" ) ) ) 1571 { 1572 strcpy( bzip2_command, "bzip2" ); 1573 strcpy( suffix, "bz2"); 1574 } 1575 else if ( does_file_exist( slice_fname( bigfileno, sliceno, ARCHIVES_PATH, "" ) ) ) 1576 { 1577 strcpy( bzip2_command, "" ); 1578 strcpy( suffix, ""); 1579 } 1580 else 1581 { 1582 log_to_screen( "OK, that's pretty fsck0red..."); 1583 return( 1 ); 1584 } 1585 } 1586 if ( bzip2_command[0] != '\0' ) 1587 { 1588 sprintf( bzip2_command + strlen( bzip2_command ), 1589 " -dc %s 2>> %s", 1590 slice_fname( bigfileno, sliceno, ARCHIVES_PATH, suffix), 1591 MONDO_LOGFILE); 1592 } 1593 else 1594 { 1595 sprintf( bzip2_command, "cat %s 2>> %s", 1596 slice_fname(bigfileno, sliceno, ARCHIVES_PATH, suffix ), 1597 MONDO_LOGFILE ); 1598 } 1599 sprintf(tmp, "Working on %s #%d, file #%ld, slice #%ld ", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number, bigfileno + 1, sliceno ); 1600 log_msg(2, tmp ); 1601 1602 if (!g_text_mode) 1603 { 1604 newtDrawRootText( 0, g_noof_rows - 2, tmp ); 1605 newtRefresh(); 1606 strip_spaces( tmp ); 1607 update_progress_form( tmp ); 1608 } 1609 if ( !(fbzip2 = popen( bzip2_command, "r" ) ) ) 1610 { 1611 fatal_error( "Can't run popen command"); 1612 } 1613 while( !feof( fbzip2 ) ) 1614 { 1615 siz = fread( bigblk, 1, TAPE_BLOCK_SIZE, fbzip2 ); 1616 if (siz > 0) 1617 { 1618 sprintf(sz_msg, "Read %ld from fbzip2", siz); 1619 siz = fwrite( bigblk, 1, siz, fout); 1620 sprintf(sz_msg + strlen(sz_msg), "; written %ld to fout", siz); 1621 // log_msg(2. sz_msg); 1622 } 1623 } 1624 paranoid_pclose(fbzip2); 1625 1626 1627 sliceno++; 1628 g_current_progress++; 1629 } 1630 } 1503 make_hole_for_file(outfile_fname); 1504 } 1505 } 1506 1507 sprintf(tmp, "Reassembling big file %ld (%s)", bigfileno + 1, 1508 outfile_fname); 1509 log_msg(2, tmp); 1510 1511 /* 1512 last slice is zero-length and uncompressed; when we find it, we stop. 1513 We DON'T wait until there are no more slices; if we did that, 1514 We might stop at end of CD, not at last slice (which is 0-len and uncompd) 1515 */ 1516 1517 strncpy(pathname_of_last_file_restored, biggiestruct.filename, 1518 MAX_STR_LEN - 1); 1519 pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0'; 1520 1521 log_msg(3, "file_to_openout = %s", file_to_openout); 1522 if (!(fout = fopen(file_to_openout, "w"))) { 1523 log_to_screen("Cannot openout outfile_fname - hard disk full?"); 1524 return (1); 1525 } 1526 log_msg(3, "Opened out to %s", outfile_fname); // CD/DVD --> mondorestore --> partimagehack --> hard disk itself 1527 1528 for (sliceno = 1, finished = FALSE; !finished;) { 1529 if (!does_file_exist 1530 (slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "")) 1531 && 1532 !does_file_exist(slice_fname 1533 (bigfileno, sliceno, ARCHIVES_PATH, "lzo")) 1534 && 1535 !does_file_exist(slice_fname 1536 (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) { 1537 log_msg(3, 1538 "Cannot find a data slice or terminator slice on CD %d", 1539 g_current_media_number); 1540 g_current_media_number++; 1541 sprintf(tmp, 1542 "Asking for %s #%d so that I may read slice #%ld\n", 1543 media_descriptor_string(bkpinfo->backup_media_type), 1544 g_current_media_number, sliceno); 1545 log_msg(2, tmp); 1546 sprintf(tmp, "Restoring from %s #%d", 1547 media_descriptor_string(bkpinfo->backup_media_type), 1548 g_current_media_number); 1549 log_to_screen(tmp); 1550 insist_on_this_cd_number(bkpinfo, g_current_media_number); 1551 log_to_screen("Continuing to restore."); 1552 } else { 1553 strcpy(tmp, 1554 slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "")); 1555 if (does_file_exist(tmp) && length_of_file(tmp) == 0) { 1556 log_msg(2, 1557 "End of bigfile # %ld (slice %ld is the terminator)", 1558 bigfileno + 1, sliceno); 1559 finished = TRUE; 1560 continue; 1561 } else { 1562 if (does_file_exist 1563 (slice_fname 1564 (bigfileno, sliceno, ARCHIVES_PATH, "lzo"))) { 1565 strcpy(bzip2_command, "lzop"); 1566 strcpy(suffix, "lzo"); 1567 } else 1568 if (does_file_exist 1569 (slice_fname 1570 (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) { 1571 strcpy(bzip2_command, "bzip2"); 1572 strcpy(suffix, "bz2"); 1573 } else 1574 if (does_file_exist 1575 (slice_fname 1576 (bigfileno, sliceno, ARCHIVES_PATH, ""))) { 1577 strcpy(bzip2_command, ""); 1578 strcpy(suffix, ""); 1579 } else { 1580 log_to_screen("OK, that's pretty fsck0red..."); 1581 return (1); 1582 } 1583 } 1584 if (bzip2_command[0] != '\0') { 1585 sprintf(bzip2_command + strlen(bzip2_command), 1586 " -dc %s 2>> %s", 1587 slice_fname(bigfileno, sliceno, ARCHIVES_PATH, 1588 suffix), MONDO_LOGFILE); 1589 } else { 1590 sprintf(bzip2_command, "cat %s 2>> %s", 1591 slice_fname(bigfileno, sliceno, ARCHIVES_PATH, 1592 suffix), MONDO_LOGFILE); 1593 } 1594 sprintf(tmp, "Working on %s #%d, file #%ld, slice #%ld ", 1595 media_descriptor_string(bkpinfo->backup_media_type), 1596 g_current_media_number, bigfileno + 1, sliceno); 1597 log_msg(2, tmp); 1598 1599 if (!g_text_mode) { 1600 newtDrawRootText(0, g_noof_rows - 2, tmp); 1601 newtRefresh(); 1602 strip_spaces(tmp); 1603 update_progress_form(tmp); 1604 } 1605 if (!(fbzip2 = popen(bzip2_command, "r"))) { 1606 fatal_error("Can't run popen command"); 1607 } 1608 while (!feof(fbzip2)) { 1609 siz = fread(bigblk, 1, TAPE_BLOCK_SIZE, fbzip2); 1610 if (siz > 0) { 1611 sprintf(sz_msg, "Read %ld from fbzip2", siz); 1612 siz = fwrite(bigblk, 1, siz, fout); 1613 sprintf(sz_msg + strlen(sz_msg), 1614 "; written %ld to fout", siz); 1615 // log_msg(2. sz_msg); 1616 } 1617 } 1618 paranoid_pclose(fbzip2); 1619 1620 1621 sliceno++; 1622 g_current_progress++; 1623 } 1624 } 1631 1625 /* 1632 1626 memset(bigblk, TAPE_BLOCK_SIZE, 1); // This all looks very fishy... … … 1636 1630 fwrite( bigblk, 1, TAPE_BLOCK_SIZE, fout); 1637 1631 */ 1638 paranoid_fclose( fout ); 1639 g_loglevel = old_loglevel; 1640 1641 if (use_partimage_hack) 1642 { 1643 log_msg(3, "Waiting for partimage to finish"); 1644 sprintf(tmp, " ps ax | grep \" partimagehack \" | grep -v grep > /dev/null 2> /dev/null"); 1645 while(system(tmp) == 0) 1646 { sleep(1); } 1647 log_it("OK, partimage has really finished"); 1648 } 1649 1650 if (strcmp(outfile_fname, "/dev/null")) 1651 { 1652 chown( outfile_fname, biggiestruct.properties.st_uid, biggiestruct.properties.st_gid ); 1653 chmod( outfile_fname, biggiestruct.properties.st_mode ); 1654 ubuf->actime = biggiestruct.properties.st_atime; 1655 ubuf->modtime= biggiestruct.properties.st_mtime; 1656 utime( outfile_fname, ubuf ); 1657 } 1658 paranoid_free( bigblk ); 1659 paranoid_free(checksum); 1660 paranoid_free(outfile_fname); 1661 paranoid_free(tmp); 1662 paranoid_free(bzip2_command); 1663 paranoid_free(partimagehack_command); 1664 paranoid_free(suffix); 1665 paranoid_free(sz_devfile); 1666 1667 return( retval ); 1632 paranoid_fclose(fout); 1633 g_loglevel = old_loglevel; 1634 1635 if (use_partimage_hack) { 1636 log_msg(3, "Waiting for partimage to finish"); 1637 sprintf(tmp, 1638 " ps ax | grep \" partimagehack \" | grep -v grep > /dev/null 2> /dev/null"); 1639 while (system(tmp) == 0) { 1640 sleep(1); 1641 } 1642 log_it("OK, partimage has really finished"); 1643 } 1644 1645 if (strcmp(outfile_fname, "/dev/null")) { 1646 chown(outfile_fname, biggiestruct.properties.st_uid, 1647 biggiestruct.properties.st_gid); 1648 chmod(outfile_fname, biggiestruct.properties.st_mode); 1649 ubuf->actime = biggiestruct.properties.st_atime; 1650 ubuf->modtime = biggiestruct.properties.st_mtime; 1651 utime(outfile_fname, ubuf); 1652 } 1653 paranoid_free(bigblk); 1654 paranoid_free(checksum); 1655 paranoid_free(outfile_fname); 1656 paranoid_free(tmp); 1657 paranoid_free(bzip2_command); 1658 paranoid_free(partimagehack_command); 1659 paranoid_free(suffix); 1660 paranoid_free(sz_devfile); 1661 1662 return (retval); 1668 1663 } 1669 1664 … … 1688 1683 * @bug orig_checksum and biggiefile_size are unused (except to check that they are non-NULL). 1689 1684 */ 1690 int 1691 restore_a_biggiefile_from_stream(struct s_bkpinfo *bkpinfo, 1692 char *orig_bf_fname, 1693 long biggiefile_number, 1694 char *orig_checksum, //UNUSED 1695 long long biggiefile_size, //UNUSED 1696 struct s_node *filelist, int use_partimagehack, 1697 char*pathname_of_last_file_restored) 1685 int restore_a_biggiefile_from_stream(struct s_bkpinfo *bkpinfo, char *orig_bf_fname, long biggiefile_number, char *orig_checksum, //UNUSED 1686 long long biggiefile_size, //UNUSED 1687 struct s_node *filelist, 1688 int use_partimagehack, 1689 char *pathname_of_last_file_restored) 1698 1690 { 1699 1700 1691 FILE *pout; 1692 FILE *fin; 1701 1693 1702 1694 /** mallocs ********/ 1703 char *tmp; 1704 char *command; 1705 char *outfile_fname; 1706 char *partimagehack_command; 1707 char *sz_devfile; 1708 char *partimagehack_fifo; 1709 char *file_to_openout = NULL; 1710 1711 struct s_node *node; 1712 1713 int old_loglevel; 1714 long current_slice_number = 0; 1715 int retval = 0; 1716 int res = 0; 1717 int ctrl_chr = '\0'; 1718 long long slice_siz; 1719 bool dummy_restore = FALSE; 1720 bool use_partimage_hack=FALSE; 1721 pid_t pid; 1722 struct s_filename_and_lstat_info biggiestruct; 1723 struct utimbuf the_utime_buf, *ubuf; 1724 ubuf = &the_utime_buf; 1725 1726 malloc_string(tmp); 1727 malloc_string(partimagehack_fifo); 1728 malloc_string(outfile_fname); 1729 malloc_string(command); 1730 malloc_string(sz_devfile); 1731 malloc_string(partimagehack_command); 1732 old_loglevel = g_loglevel; 1733 assert(bkpinfo!=NULL); 1734 assert(orig_bf_fname!=NULL); 1735 assert(orig_checksum!=NULL); 1736 1737 pathname_of_last_file_restored[0] = '\0'; 1738 if (use_partimagehack == BLK_START_A_PIHBIGGIE) 1739 { 1740 use_partimagehack = 1; 1741 log_msg(1, "%s --- pih=YES", orig_bf_fname); 1742 } 1743 else if (use_partimagehack == BLK_START_A_NORMBIGGIE) 1744 { 1745 use_partimagehack = 0; 1746 log_msg(1, "%s --- pih=NO", orig_bf_fname); 1747 } 1748 else 1749 { 1750 use_partimagehack = 0; 1751 log_msg(1, "%s --- pih=NO (weird marker though)", orig_bf_fname); 1752 } 1753 1754 strncpy(pathname_of_last_file_restored, orig_bf_fname, MAX_STR_LEN-1); 1755 pathname_of_last_file_restored[MAX_STR_LEN-1] = '\0'; 1756 1757 /* open out to biggiefile to be restored (or /dev/null if biggiefile is not to be restored) */ 1758 1759 if (filelist != NULL) 1760 { 1761 node = find_string_at_node(filelist, orig_bf_fname); 1762 if (!node) 1763 { 1764 dummy_restore = TRUE; 1765 log_msg(1, "Skipping big file %ld (%s) - not in biggielist subset", biggiefile_number+1, orig_bf_fname); 1766 pathname_of_last_file_restored[0] = '\0'; 1767 } 1768 else if (!(node->selected)) 1769 { 1770 dummy_restore = TRUE; 1771 log_msg(1, "Skipping %s (name isn't in biggielist subset)", orig_bf_fname); 1772 pathname_of_last_file_restored[0] = '\0'; 1773 } 1774 } 1775 1776 if (use_partimagehack) 1777 { 1778 if (strncmp ( orig_bf_fname, "/dev/", 5)) 1779 { 1780 log_msg(1, "I was in error when I set use_partimagehack to TRUE."); 1781 log_msg(1, "%s isn't even in /dev", orig_bf_fname); 1782 use_partimagehack = FALSE; 1783 } 1784 } 1785 1786 if (use_partimagehack) 1787 { 1788 g_loglevel = 4; 1789 strcpy(outfile_fname, orig_bf_fname); 1790 use_partimage_hack = TRUE; 1791 log_msg(2, "Calling partimagehack in background because %s is a /dev entry", outfile_fname); 1792 sprintf(sz_devfile, "/tmp/%d.%d.000", (int)(random()%32768), (int)(random()%32768)); 1793 mkfifo(sz_devfile, 0x770); 1794 strcpy(partimagehack_fifo, sz_devfile); 1795 file_to_openout = partimagehack_fifo; 1796 switch(pid=fork()) 1797 { 1798 case -1: fatal_error("Fork failure"); 1799 case 0: 1800 log_msg(3, "CHILD - fip - calling feed_outfrom_partimage(%s, %s)", outfile_fname, partimagehack_fifo); 1801 res=feed_outfrom_partimage(outfile_fname, partimagehack_fifo); 1802 // log_msg(3, "CHILD - fip - exiting"); 1803 exit(res); 1804 break; 1805 default: 1806 log_msg(3, "feed_into_partimage() called in background --- pid=%ld", (long int)(pid)); 1807 } 1808 } 1809 else 1810 { 1811 if (!strncmp ( orig_bf_fname, "/dev/", 5)) // non-NTFS partition 1812 { strcpy(outfile_fname, orig_bf_fname); } 1813 else // biggiefile 1814 { sprintf( outfile_fname, "%s/%s", bkpinfo->restore_path, orig_bf_fname ); } 1815 use_partimage_hack = FALSE; 1816 partimagehack_fifo[0] = '\0'; 1817 file_to_openout = outfile_fname; 1818 if ( !does_file_exist( outfile_fname ) ) // yes, it looks weird with the '!' but it's correct that way 1819 { make_hole_for_file( outfile_fname ); } 1820 sprintf(tmp, "Reassembling big file %ld (%s)", biggiefile_number + 1, orig_bf_fname ); 1821 log_msg(2, tmp ); 1822 } 1823 1824 if (dummy_restore) 1825 { sprintf( outfile_fname, "/dev/null" ); } 1826 1827 if ( !bkpinfo->zip_exe[0] ) 1828 { 1829 sprintf(command, "cat > \"%s\"", file_to_openout); 1830 } 1831 else 1832 { 1833 sprintf(command,"%s -dc > \"%s\" 2>> %s",bkpinfo->zip_exe, file_to_openout, MONDO_LOGFILE); 1834 } 1835 sprintf(tmp,"Pipe command = '%s'",command); 1836 log_msg(3, tmp); 1837 1838 /* restore biggiefile, one slice at a time */ 1839 if ( !( pout = popen(command, "w" ) ) ) 1840 { 1841 fatal_error( "Cannot pipe out" ); 1842 } 1843 for( res = read_header_block_from_stream( &slice_siz, tmp, &ctrl_chr); ctrl_chr!=BLK_STOP_A_BIGGIE; res=read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr ) ) 1844 { 1845 if ( ctrl_chr != BLK_START_AN_AFIO_OR_SLICE ) 1846 { 1847 wrong_marker( BLK_START_AN_AFIO_OR_SLICE,ctrl_chr ); 1848 } 1849 sprintf( tmp,"Working on file #%ld, slice #%ld ", 1850 biggiefile_number + 1, 1851 current_slice_number); 1852 log_msg(2, tmp); 1853 if (!g_text_mode) 1854 { 1855 newtDrawRootText( 0, g_noof_rows - 2, tmp); 1856 newtRefresh(); 1857 } 1858 strip_spaces( tmp ); 1859 update_progress_form( tmp ); 1860 if ( current_slice_number == 0 ) 1861 { 1862 res = read_file_from_stream_to_file( bkpinfo,"/tmp/biggie-blah.txt",slice_siz); 1863 if (!(fin = fopen("/tmp/biggie-blah.txt", "r"))) 1864 { log_OS_error("blah blah"); } 1865 else 1866 { 1867 if ( fread( (void*)&biggiestruct, 1, sizeof(biggiestruct), fin) < sizeof(biggiestruct)) 1868 { 1869 log_msg(2, "Warning - unable to get biggiestruct of bigfile #%d", biggiefile_number + 1); 1870 } 1871 paranoid_fclose(fin); 1872 } 1873 } 1874 else 1875 { 1876 res = read_file_from_stream_to_stream( bkpinfo, pout, slice_siz ); 1877 } 1878 retval += res; 1879 res = read_header_block_from_stream( &slice_siz, tmp, &ctrl_chr ); 1880 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) 1881 { 1882 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr); 1883 } 1884 current_slice_number++; 1885 g_current_progress++; 1886 } 1887 paranoid_pclose(pout); 1888 1889 log_msg(1, "pathname_of_last_file_restored is now %s", pathname_of_last_file_restored); 1890 1891 if (use_partimage_hack) 1892 { 1893 log_msg(3, "Waiting for partimage to finish"); 1894 sprintf(tmp, " ps ax | grep \" partimagehack \" | grep -v grep > /dev/null 2> /dev/null"); 1895 while(system(tmp) == 0) 1896 { sleep(1); } 1897 log_msg(3, "OK, partimage has really finished"); 1898 } 1899 1900 log_msg(3, "biggiestruct.filename = %s", biggiestruct.filename); 1901 log_msg(3, "biggiestruct.checksum = %s", biggiestruct.checksum); 1902 if (strcmp(outfile_fname, "/dev/null")) 1903 { 1904 chmod(outfile_fname, biggiestruct.properties.st_mode); 1905 chown(outfile_fname, biggiestruct.properties.st_uid, biggiestruct.properties.st_gid); 1906 ubuf->actime = biggiestruct.properties.st_atime; 1907 ubuf->modtime= biggiestruct.properties.st_mtime; 1908 utime( outfile_fname, ubuf ); 1909 } 1910 1911 paranoid_free(tmp); 1912 paranoid_free(outfile_fname); 1913 paranoid_free(command); 1914 paranoid_free(partimagehack_command); 1915 paranoid_free(sz_devfile); 1916 paranoid_free(partimagehack_fifo); 1917 g_loglevel = old_loglevel; 1918 return(retval); 1695 char *tmp; 1696 char *command; 1697 char *outfile_fname; 1698 char *partimagehack_command; 1699 char *sz_devfile; 1700 char *partimagehack_fifo; 1701 char *file_to_openout = NULL; 1702 1703 struct s_node *node; 1704 1705 int old_loglevel; 1706 long current_slice_number = 0; 1707 int retval = 0; 1708 int res = 0; 1709 int ctrl_chr = '\0'; 1710 long long slice_siz; 1711 bool dummy_restore = FALSE; 1712 bool use_partimage_hack = FALSE; 1713 pid_t pid; 1714 struct s_filename_and_lstat_info biggiestruct; 1715 struct utimbuf the_utime_buf, *ubuf; 1716 ubuf = &the_utime_buf; 1717 1718 malloc_string(tmp); 1719 malloc_string(partimagehack_fifo); 1720 malloc_string(outfile_fname); 1721 malloc_string(command); 1722 malloc_string(sz_devfile); 1723 malloc_string(partimagehack_command); 1724 old_loglevel = g_loglevel; 1725 assert(bkpinfo != NULL); 1726 assert(orig_bf_fname != NULL); 1727 assert(orig_checksum != NULL); 1728 1729 pathname_of_last_file_restored[0] = '\0'; 1730 if (use_partimagehack == BLK_START_A_PIHBIGGIE) { 1731 use_partimagehack = 1; 1732 log_msg(1, "%s --- pih=YES", orig_bf_fname); 1733 } else if (use_partimagehack == BLK_START_A_NORMBIGGIE) { 1734 use_partimagehack = 0; 1735 log_msg(1, "%s --- pih=NO", orig_bf_fname); 1736 } else { 1737 use_partimagehack = 0; 1738 log_msg(1, "%s --- pih=NO (weird marker though)", orig_bf_fname); 1739 } 1740 1741 strncpy(pathname_of_last_file_restored, orig_bf_fname, 1742 MAX_STR_LEN - 1); 1743 pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0'; 1744 1745 /* open out to biggiefile to be restored (or /dev/null if biggiefile is not to be restored) */ 1746 1747 if (filelist != NULL) { 1748 node = find_string_at_node(filelist, orig_bf_fname); 1749 if (!node) { 1750 dummy_restore = TRUE; 1751 log_msg(1, 1752 "Skipping big file %ld (%s) - not in biggielist subset", 1753 biggiefile_number + 1, orig_bf_fname); 1754 pathname_of_last_file_restored[0] = '\0'; 1755 } else if (!(node->selected)) { 1756 dummy_restore = TRUE; 1757 log_msg(1, "Skipping %s (name isn't in biggielist subset)", 1758 orig_bf_fname); 1759 pathname_of_last_file_restored[0] = '\0'; 1760 } 1761 } 1762 1763 if (use_partimagehack) { 1764 if (strncmp(orig_bf_fname, "/dev/", 5)) { 1765 log_msg(1, 1766 "I was in error when I set use_partimagehack to TRUE."); 1767 log_msg(1, "%s isn't even in /dev", orig_bf_fname); 1768 use_partimagehack = FALSE; 1769 } 1770 } 1771 1772 if (use_partimagehack) { 1773 g_loglevel = 4; 1774 strcpy(outfile_fname, orig_bf_fname); 1775 use_partimage_hack = TRUE; 1776 log_msg(2, 1777 "Calling partimagehack in background because %s is a /dev entry", 1778 outfile_fname); 1779 sprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768), 1780 (int) (random() % 32768)); 1781 mkfifo(sz_devfile, 0x770); 1782 strcpy(partimagehack_fifo, sz_devfile); 1783 file_to_openout = partimagehack_fifo; 1784 switch (pid = fork()) { 1785 case -1: 1786 fatal_error("Fork failure"); 1787 case 0: 1788 log_msg(3, 1789 "CHILD - fip - calling feed_outfrom_partimage(%s, %s)", 1790 outfile_fname, partimagehack_fifo); 1791 res = 1792 feed_outfrom_partimage(outfile_fname, partimagehack_fifo); 1793 // log_msg(3, "CHILD - fip - exiting"); 1794 exit(res); 1795 break; 1796 default: 1797 log_msg(3, 1798 "feed_into_partimage() called in background --- pid=%ld", 1799 (long int) (pid)); 1800 } 1801 } else { 1802 if (!strncmp(orig_bf_fname, "/dev/", 5)) // non-NTFS partition 1803 { 1804 strcpy(outfile_fname, orig_bf_fname); 1805 } else // biggiefile 1806 { 1807 sprintf(outfile_fname, "%s/%s", bkpinfo->restore_path, 1808 orig_bf_fname); 1809 } 1810 use_partimage_hack = FALSE; 1811 partimagehack_fifo[0] = '\0'; 1812 file_to_openout = outfile_fname; 1813 if (!does_file_exist(outfile_fname)) // yes, it looks weird with the '!' but it's correct that way 1814 { 1815 make_hole_for_file(outfile_fname); 1816 } 1817 sprintf(tmp, "Reassembling big file %ld (%s)", 1818 biggiefile_number + 1, orig_bf_fname); 1819 log_msg(2, tmp); 1820 } 1821 1822 if (dummy_restore) { 1823 sprintf(outfile_fname, "/dev/null"); 1824 } 1825 1826 if (!bkpinfo->zip_exe[0]) { 1827 sprintf(command, "cat > \"%s\"", file_to_openout); 1828 } else { 1829 sprintf(command, "%s -dc > \"%s\" 2>> %s", bkpinfo->zip_exe, 1830 file_to_openout, MONDO_LOGFILE); 1831 } 1832 sprintf(tmp, "Pipe command = '%s'", command); 1833 log_msg(3, tmp); 1834 1835 /* restore biggiefile, one slice at a time */ 1836 if (!(pout = popen(command, "w"))) { 1837 fatal_error("Cannot pipe out"); 1838 } 1839 for (res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr); 1840 ctrl_chr != BLK_STOP_A_BIGGIE; 1841 res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr)) { 1842 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) { 1843 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr); 1844 } 1845 sprintf(tmp, "Working on file #%ld, slice #%ld ", 1846 biggiefile_number + 1, current_slice_number); 1847 log_msg(2, tmp); 1848 if (!g_text_mode) { 1849 newtDrawRootText(0, g_noof_rows - 2, tmp); 1850 newtRefresh(); 1851 } 1852 strip_spaces(tmp); 1853 update_progress_form(tmp); 1854 if (current_slice_number == 0) { 1855 res = 1856 read_file_from_stream_to_file(bkpinfo, 1857 "/tmp/biggie-blah.txt", 1858 slice_siz); 1859 if (!(fin = fopen("/tmp/biggie-blah.txt", "r"))) { 1860 log_OS_error("blah blah"); 1861 } else { 1862 if (fread 1863 ((void *) &biggiestruct, 1, sizeof(biggiestruct), 1864 fin) < sizeof(biggiestruct)) { 1865 log_msg(2, 1866 "Warning - unable to get biggiestruct of bigfile #%d", 1867 biggiefile_number + 1); 1868 } 1869 paranoid_fclose(fin); 1870 } 1871 } else { 1872 res = 1873 read_file_from_stream_to_stream(bkpinfo, pout, slice_siz); 1874 } 1875 retval += res; 1876 res = read_header_block_from_stream(&slice_siz, tmp, &ctrl_chr); 1877 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) { 1878 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr); 1879 } 1880 current_slice_number++; 1881 g_current_progress++; 1882 } 1883 paranoid_pclose(pout); 1884 1885 log_msg(1, "pathname_of_last_file_restored is now %s", 1886 pathname_of_last_file_restored); 1887 1888 if (use_partimage_hack) { 1889 log_msg(3, "Waiting for partimage to finish"); 1890 sprintf(tmp, 1891 " ps ax | grep \" partimagehack \" | grep -v grep > /dev/null 2> /dev/null"); 1892 while (system(tmp) == 0) { 1893 sleep(1); 1894 } 1895 log_msg(3, "OK, partimage has really finished"); 1896 } 1897 1898 log_msg(3, "biggiestruct.filename = %s", biggiestruct.filename); 1899 log_msg(3, "biggiestruct.checksum = %s", biggiestruct.checksum); 1900 if (strcmp(outfile_fname, "/dev/null")) { 1901 chmod(outfile_fname, biggiestruct.properties.st_mode); 1902 chown(outfile_fname, biggiestruct.properties.st_uid, 1903 biggiestruct.properties.st_gid); 1904 ubuf->actime = biggiestruct.properties.st_atime; 1905 ubuf->modtime = biggiestruct.properties.st_mtime; 1906 utime(outfile_fname, ubuf); 1907 } 1908 1909 paranoid_free(tmp); 1910 paranoid_free(outfile_fname); 1911 paranoid_free(command); 1912 paranoid_free(partimagehack_command); 1913 paranoid_free(sz_devfile); 1914 paranoid_free(partimagehack_fifo); 1915 g_loglevel = old_loglevel; 1916 return (retval); 1919 1917 } 1920 1918 … … 1938 1936 int 1939 1937 restore_a_tarball_from_CD(char *tarball_fname, 1940 long current_tarball_number,1941 struct s_node*filelist)1938 long current_tarball_number, 1939 struct s_node *filelist) 1942 1940 { 1943 1944 1945 1941 int retval = 0; 1942 int res; 1943 char *p; 1946 1944 1947 1945 /** malloc **/ 1948 1949 1950 1951 1952 1953 1954 1955 long matches=0;1956 1957 1958 1946 char *command; 1947 char *tmp; 1948 char *filelist_name; 1949 char *filelist_subset_fname; 1950 char *executable; 1951 char *temp_log; 1952 char screen_message[100]; 1953 long matches = 0; 1954 bool use_star; 1955 char *xattr_fname; 1956 char *acl_fname; 1959 1957 // char files_to_restore_this_time_fname[MAX_STR_LEN]; 1960 1958 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 use_star = (strstr(tarball_fname, ".star"))?TRUE:FALSE;1959 assert_string_is_neither_NULL_nor_zerolength(tarball_fname); 1960 malloc_string(command); 1961 malloc_string(tmp); 1962 malloc_string(filelist_name); 1963 malloc_string(filelist_subset_fname); 1964 malloc_string(executable); 1965 malloc_string(temp_log); 1966 malloc_string(xattr_fname); 1967 malloc_string(acl_fname); 1968 1969 log_msg(5, "Entering"); 1970 filelist_subset_fname[0] = '\0'; 1971 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE; 1974 1972 // sprintf(files_to_restore_this_time_fname, "/tmp/ftrttf.%d.%d", (int)getpid(), (int)random()); 1975 1976 1977 sprintf(temp_log, "/tmp/%d.%d", (int)(random()%32768), (int)(random()%32768)); 1978 1979 sprintf(filelist_name, MNT_CDROM"/archives/filelist.%ld",current_tarball_number); 1980 if ( length_of_file( filelist_name ) <= 2 ) 1981 { 1982 log_msg(2, "There are _zero_ files in filelist '%s'", filelist_name); 1983 log_msg(2, "This is a bit silly (ask Hugo to fix mondo-makefilelist, please)"); 1984 log_msg(2, "but it's non-critical. It's cosmetic. Don't worry about it.");1985 retval=0; 1986 goto leave_sub;1987 } 1988 if ( count_lines_in_file(filelist_name) <= 0 || length_of_file( tarball_fname ) <= 0 ) 1989 { 1990 log_msg(3, "length_of_file(%s) = %ld", tarball_fname, length_of_file(tarball_fname));1991 sprintf(tmp,"Unable to restore fileset #%ld (CD I/O error)",current_tarball_number); 1992 log_to_screen(tmp); 1993 retval=1; 1994 goto leave_sub; 1995 } 1996 1997 if (filelist) 1998 { 1999 sprintf(filelist_subset_fname, "/tmp/filelist-subset-%ld.tmp", current_tarball_number);2000 if ((matches=save_filelist_entries_in_common 2001 (filelist_name, filelist, filelist_subset_fname, use_star)) 2002 <= 0) 2003 {2004 sprintf(tmp, "Skipping fileset %ld", current_tarball_number);2005 log_msg(1, tmp);2006 }2007 else 2008 { 2009 log_msg(3, "Saved fileset %ld's subset to %s", current_tarball_number, filelist_subset_fname);2010 }2011 sprintf(screen_message, "Tarball #%ld --- %ld matches", current_tarball_number, matches);2012 log_to_screen(screen_message);2013 } 2014 else 2015 { 2016 filelist_subset_fname[0] = '\0'; 2017 } 2018 2019 if (filelist == NULL || matches>0) 2020 2021 sprintf(xattr_fname, XATTR_LIST_FNAME_RAW_SZ, MNT_CDROM"/archives", current_tarball_number);2022 sprintf(acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM"/archives", current_tarball_number); 2023 if ( strstr( tarball_fname, ".bz2" ) ) 2024 2025 strcpy(executable,"bzip2"); 2026 } 2027 else if ( strstr( tarball_fname, ".lzo") ) 2028 { 2029 strcpy( executable,"lzop"); 2030 } 2031 else 2032 { 2033 executable[0] = '\0'; 2034 } 2035 if (executable[0]) 2036 2037 sprintf( tmp, "which %s > /dev/null 2> /dev/null", executable);2038 if ( run_program_and_log_output( tmp, FALSE ) ) 2039 { 2040 log_to_screen("(compare_a_tarball) Compression program not found - oh no!");2041 2042 2043 2044 2045 1973 sprintf(command, "mkdir -p %s/tmp", MNT_RESTORING); 1974 run_program_and_log_output(command, 9); 1975 sprintf(temp_log, "/tmp/%d.%d", (int) (random() % 32768), 1976 (int) (random() % 32768)); 1977 1978 sprintf(filelist_name, MNT_CDROM "/archives/filelist.%ld", 1979 current_tarball_number); 1980 if (length_of_file(filelist_name) <= 2) { 1981 log_msg(2, "There are _zero_ files in filelist '%s'", 1982 filelist_name); 1983 log_msg(2, 1984 "This is a bit silly (ask Hugo to fix mondo-makefilelist, please)"); 1985 log_msg(2, 1986 "but it's non-critical. It's cosmetic. Don't worry about it."); 1987 retval = 0; 1988 goto leave_sub; 1989 } 1990 if (count_lines_in_file(filelist_name) <= 0 1991 || length_of_file(tarball_fname) <= 0) { 1992 log_msg(3, "length_of_file(%s) = %ld", tarball_fname, 1993 length_of_file(tarball_fname)); 1994 sprintf(tmp, "Unable to restore fileset #%ld (CD I/O error)", 1995 current_tarball_number); 1996 log_to_screen(tmp); 1997 retval = 1; 1998 goto leave_sub; 1999 } 2000 2001 if (filelist) { 2002 sprintf(filelist_subset_fname, "/tmp/filelist-subset-%ld.tmp", 2003 current_tarball_number); 2004 if ((matches = 2005 save_filelist_entries_in_common(filelist_name, filelist, 2006 filelist_subset_fname, 2007 use_star)) 2008 <= 0) { 2009 sprintf(tmp, "Skipping fileset %ld", current_tarball_number); 2010 log_msg(1, tmp); 2011 } else { 2012 log_msg(3, "Saved fileset %ld's subset to %s", 2013 current_tarball_number, filelist_subset_fname); 2014 } 2015 sprintf(screen_message, "Tarball #%ld --- %ld matches", 2016 current_tarball_number, matches); 2017 log_to_screen(screen_message); 2018 } else { 2019 filelist_subset_fname[0] = '\0'; 2020 } 2021 2022 if (filelist == NULL || matches > 0) { 2023 sprintf(xattr_fname, XATTR_LIST_FNAME_RAW_SZ, 2024 MNT_CDROM "/archives", current_tarball_number); 2025 sprintf(acl_fname, ACL_LIST_FNAME_RAW_SZ, MNT_CDROM "/archives", 2026 current_tarball_number); 2027 if (strstr(tarball_fname, ".bz2")) { 2028 strcpy(executable, "bzip2"); 2029 } else if (strstr(tarball_fname, ".lzo")) { 2030 strcpy(executable, "lzop"); 2031 } else { 2032 executable[0] = '\0'; 2033 } 2034 if (executable[0]) { 2035 sprintf(tmp, "which %s > /dev/null 2> /dev/null", executable); 2036 if (run_program_and_log_output(tmp, FALSE)) { 2037 log_to_screen 2038 ("(compare_a_tarball) Compression program not found - oh no!"); 2039 paranoid_MR_finish(1); 2040 } 2041 strcpy(tmp, executable); 2042 sprintf(executable, "-P %s -Z", tmp); 2043 } 2046 2044 #ifdef __FreeBSD__ 2047 2045 #define BUFSIZE 512 … … 2051 2049 2052 2050 // if (strstr(tarball_fname, ".star.")) 2053 if (use_star) 2054 { 2055 sprintf( command, "star -x -force-remove -U " STAR_ACL_SZ " errctl= file=%s", tarball_fname); 2056 if (strstr (tarball_fname, ".bz2")) 2057 { strcat( command, " -bz"); } 2058 } 2059 else 2060 { 2061 if ( filelist_subset_fname[0] != '\0' ) 2062 { 2063 sprintf( command, 2064 "afio -i -M 8m -b %ld -c %ld %s -w %s %s", 2065 TAPE_BLOCK_SIZE, 2066 BUFSIZE, 2067 executable, 2068 filelist_subset_fname, 2069 // files_to_restore_this_time_fname, 2070 tarball_fname); 2071 } 2072 else 2073 { 2074 sprintf( command, 2075 "afio -i -b %ld -c %ld -M 8m %s %s", 2076 TAPE_BLOCK_SIZE, 2077 BUFSIZE, 2078 executable, 2079 tarball_fname); 2080 } 2081 } 2051 if (use_star) { 2052 sprintf(command, 2053 "star -x -force-remove -U " STAR_ACL_SZ 2054 " errctl= file=%s", tarball_fname); 2055 if (strstr(tarball_fname, ".bz2")) { 2056 strcat(command, " -bz"); 2057 } 2058 } else { 2059 if (filelist_subset_fname[0] != '\0') { 2060 sprintf(command, 2061 "afio -i -M 8m -b %ld -c %ld %s -w %s %s", 2062 TAPE_BLOCK_SIZE, 2063 BUFSIZE, executable, filelist_subset_fname, 2064 // files_to_restore_this_time_fname, 2065 tarball_fname); 2066 } else { 2067 sprintf(command, 2068 "afio -i -b %ld -c %ld -M 8m %s %s", 2069 TAPE_BLOCK_SIZE, 2070 BUFSIZE, executable, tarball_fname); 2071 } 2072 } 2082 2073 #undef BUFSIZE 2083 sprintf(command+strlen(command), " 2>> %s >> %s", temp_log, temp_log); 2084 log_msg(1,"command = '%s'", command); 2085 unlink(temp_log); 2086 res = system(command); 2087 if (res) 2088 { 2089 p = strstr(command, "-acl "); 2090 if (p) 2091 { 2092 p[0]=p[1]=p[2]=p[3]=' '; 2093 log_msg(1,"new command = '%s'", command); 2094 res = system(command); 2095 } 2096 } 2097 if (res && length_of_file(temp_log)<5) { res=0; } 2098 2099 log_msg(1, "Setting fattr list %s", xattr_fname); 2100 if (length_of_file(xattr_fname)>0) 2101 { 2102 res=set_fattr_list(filelist_subset_fname, xattr_fname); 2103 if (res) { log_to_screen("Errors occurred while setting extended attributes"); } 2104 else { log_msg(1, "I set xattr OK"); } 2105 retval += res; 2106 } 2107 if (length_of_file(acl_fname)>0) 2108 { 2109 log_msg(1, "Setting acl list %s", acl_fname); 2110 res=set_acl_list(filelist_subset_fname, acl_fname); 2111 if (res) { log_to_screen("Errors occurred while setting access control lists"); } 2112 else { log_msg(1, "I set ACL OK"); } 2113 retval += res; 2114 } 2115 if ( retval ) 2116 { 2117 sprintf(command, "cat %s >> %s", temp_log, MONDO_LOGFILE); 2118 system(command); 2119 log_msg(2, "Errors occurred while processing fileset #%d",current_tarball_number); 2120 } 2121 else 2122 { 2123 log_msg(2, "Fileset #%d processed OK", current_tarball_number); 2124 } 2125 } 2126 if (does_file_exist("/PAUSE")) 2127 { popup_and_OK("Press ENTER to go on. Delete /PAUSE to stop these pauses."); } 2128 unlink(filelist_subset_fname); 2129 unlink(xattr_fname); 2130 unlink(acl_fname); 2131 unlink(temp_log); 2132 2133 leave_sub: 2134 paranoid_free(command); paranoid_free(tmp); 2135 paranoid_free(filelist_name); paranoid_free(filelist_subset_fname); 2136 paranoid_free(executable); paranoid_free(temp_log); 2137 paranoid_free(xattr_fname); paranoid_free(acl_fname); 2138 log_msg(5, "Leaving"); 2139 return(retval); 2074 sprintf(command + strlen(command), " 2>> %s >> %s", temp_log, 2075 temp_log); 2076 log_msg(1, "command = '%s'", command); 2077 unlink(temp_log); 2078 res = system(command); 2079 if (res) { 2080 p = strstr(command, "-acl "); 2081 if (p) { 2082 p[0] = p[1] = p[2] = p[3] = ' '; 2083 log_msg(1, "new command = '%s'", command); 2084 res = system(command); 2085 } 2086 } 2087 if (res && length_of_file(temp_log) < 5) { 2088 res = 0; 2089 } 2090 2091 log_msg(1, "Setting fattr list %s", xattr_fname); 2092 if (length_of_file(xattr_fname) > 0) { 2093 res = set_fattr_list(filelist_subset_fname, xattr_fname); 2094 if (res) { 2095 log_to_screen 2096 ("Errors occurred while setting extended attributes"); 2097 } else { 2098 log_msg(1, "I set xattr OK"); 2099 } 2100 retval += res; 2101 } 2102 if (length_of_file(acl_fname) > 0) { 2103 log_msg(1, "Setting acl list %s", acl_fname); 2104 res = set_acl_list(filelist_subset_fname, acl_fname); 2105 if (res) { 2106 log_to_screen 2107 ("Errors occurred while setting access control lists"); 2108 } else { 2109 log_msg(1, "I set ACL OK"); 2110 } 2111 retval += res; 2112 } 2113 if (retval) { 2114 sprintf(command, "cat %s >> %s", temp_log, MONDO_LOGFILE); 2115 system(command); 2116 log_msg(2, "Errors occurred while processing fileset #%d", 2117 current_tarball_number); 2118 } else { 2119 log_msg(2, "Fileset #%d processed OK", current_tarball_number); 2120 } 2121 } 2122 if (does_file_exist("/PAUSE")) { 2123 popup_and_OK 2124 ("Press ENTER to go on. Delete /PAUSE to stop these pauses."); 2125 } 2126 unlink(filelist_subset_fname); 2127 unlink(xattr_fname); 2128 unlink(acl_fname); 2129 unlink(temp_log); 2130 2131 leave_sub: 2132 paranoid_free(command); 2133 paranoid_free(tmp); 2134 paranoid_free(filelist_name); 2135 paranoid_free(filelist_subset_fname); 2136 paranoid_free(executable); 2137 paranoid_free(temp_log); 2138 paranoid_free(xattr_fname); 2139 paranoid_free(acl_fname); 2140 log_msg(5, "Leaving"); 2141 return (retval); 2140 2142 } 2141 2143 … … 2162 2164 int 2163 2165 restore_a_tarball_from_stream(struct s_bkpinfo *bkpinfo, 2164 char *tarball_fname, 2165 long current_tarball_number, 2166 struct s_node*filelist, 2167 long long size, char*xattr_fname, char*acl_fname) 2166 char *tarball_fname, 2167 long current_tarball_number, 2168 struct s_node *filelist, 2169 long long size, char *xattr_fname, 2170 char *acl_fname) 2168 2171 { 2169 2170 2172 int retval = 0; 2173 int res = 0; 2171 2174 2172 2175 /** malloc add ***/ 2173 2174 2175 2176 2177 2178 2179 long matches=0;2180 2181 2182 2183 assert(bkpinfo!=NULL);2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 use_star = (strstr(tarball_fname, ".star"))?TRUE:FALSE;2194 sprintf(tmp,2195 "Restoring from fileset #%ld (%ld KB) on %s #%d",current_tarball_number,2196 (long) size>>10,2197 2198 g_current_media_number);2199 log_msg(2, tmp);2200 run_program_and_log_output( "mkdir -p " MNT_RESTORING "/tmp", FALSE);2176 char *tmp; 2177 char *command; 2178 char *afio_fname; 2179 char *filelist_fname; 2180 char *filelist_subset_fname; 2181 char *executable; 2182 long matches = 0; 2183 bool restore_this_fileset = FALSE; 2184 bool use_star; 2185 2186 assert(bkpinfo != NULL); 2187 assert_string_is_neither_NULL_nor_zerolength(tarball_fname); 2188 malloc_string(filelist_subset_fname); 2189 malloc_string(filelist_fname); 2190 malloc_string(afio_fname); 2191 malloc_string(executable); 2192 malloc_string(command); 2193 malloc_string(tmp); 2194 filelist_subset_fname[0] = '\0'; 2195 /* to do it with a file... */ 2196 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE; 2197 sprintf(tmp, 2198 "Restoring from fileset #%ld (%ld KB) on %s #%d", 2199 current_tarball_number, (long) size >> 10, 2200 media_descriptor_string(bkpinfo->backup_media_type), 2201 g_current_media_number); 2202 log_msg(2, tmp); 2203 run_program_and_log_output("mkdir -p " MNT_RESTORING "/tmp", FALSE); 2201 2204 2202 2205 /**************************************************************************** … … 2205 2208 * in afio or someting; oh darn.. OK, use tmpfs :-) * 2206 2209 ****************************************************************************/ 2207 filelist_fname[0] = filelist_subset_fname[0] = '\0'; 2208 sprintf(afio_fname, "/tmp/tmpfs/archive.tmp.%ld", current_tarball_number); 2209 sprintf(filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir, current_tarball_number); 2210 sprintf(filelist_subset_fname, "%s/filelist-subset-%ld.tmp", bkpinfo->tmpdir, current_tarball_number); 2210 filelist_fname[0] = filelist_subset_fname[0] = '\0'; 2211 sprintf(afio_fname, "/tmp/tmpfs/archive.tmp.%ld", 2212 current_tarball_number); 2213 sprintf(filelist_fname, "%s/filelist.%ld", bkpinfo->tmpdir, 2214 current_tarball_number); 2215 sprintf(filelist_subset_fname, "%s/filelist-subset-%ld.tmp", 2216 bkpinfo->tmpdir, current_tarball_number); 2211 2217 // sprintf(filelist_fname, "/tmp/tmpfs/temp-filelist.%ld", current_tarball_number); 2212 res = read_file_from_stream_to_file( bkpinfo, afio_fname,size ); 2213 if (strstr(tarball_fname, ".star")) { bkpinfo->use_star = TRUE; } 2214 if (res) { log_msg(1, "Warning - error reading afioball from tape"); } 2215 if (bkpinfo->compression_level == 0) 2216 { 2217 executable[0] = '\0'; 2218 } 2219 else 2220 { 2221 if (bkpinfo->use_star) 2222 { strcpy(executable, " -bz"); } 2223 else 2224 { sprintf(executable, "-P %s -Z", bkpinfo->zip_exe); } 2225 } 2226 2227 if (!filelist) // if unconditional restore then restore entire fileset 2228 { 2229 restore_this_fileset = TRUE; 2230 } 2231 else // If restoring selectively then get TOC from tarball 2232 { 2233 if (strstr(tarball_fname, ".star.")) 2234 { 2235 use_star = TRUE; 2236 sprintf( command, "star -t file=%s %s", afio_fname, executable); 2237 } 2238 else 2239 { 2240 use_star = FALSE; 2241 sprintf( command, "afio -t -M 8m -b %ld %s %s", TAPE_BLOCK_SIZE, 2242 executable, afio_fname); 2243 } 2244 sprintf(command+strlen(command), " > %s 2>> %s", filelist_fname, MONDO_LOGFILE); 2245 log_msg(1, "command = %s", command); 2246 if (system(command)) { log_msg(4, "Warning - error occurred while retrieving TOC"); } 2247 if ((matches=save_filelist_entries_in_common(filelist_fname, filelist, filelist_subset_fname, use_star)) 2248 <= 0 2249 || length_of_file(filelist_subset_fname)<2) 2250 { 2251 if (length_of_file(filelist_subset_fname)<2) 2252 { log_msg(1, "No matches found in fileset %ld", current_tarball_number); } 2253 sprintf(tmp, "Skipping fileset %ld", current_tarball_number); 2254 log_msg(2, tmp); 2255 restore_this_fileset = FALSE; 2256 } 2257 else 2258 { 2259 log_msg(5, "%ld matches. Saved fileset %ld's subset to %s", matches, current_tarball_number, filelist_subset_fname); 2260 restore_this_fileset = TRUE; 2261 } 2262 } 2218 res = read_file_from_stream_to_file(bkpinfo, afio_fname, size); 2219 if (strstr(tarball_fname, ".star")) { 2220 bkpinfo->use_star = TRUE; 2221 } 2222 if (res) { 2223 log_msg(1, "Warning - error reading afioball from tape"); 2224 } 2225 if (bkpinfo->compression_level == 0) { 2226 executable[0] = '\0'; 2227 } else { 2228 if (bkpinfo->use_star) { 2229 strcpy(executable, " -bz"); 2230 } else { 2231 sprintf(executable, "-P %s -Z", bkpinfo->zip_exe); 2232 } 2233 } 2234 2235 if (!filelist) // if unconditional restore then restore entire fileset 2236 { 2237 restore_this_fileset = TRUE; 2238 } else // If restoring selectively then get TOC from tarball 2239 { 2240 if (strstr(tarball_fname, ".star.")) { 2241 use_star = TRUE; 2242 sprintf(command, "star -t file=%s %s", afio_fname, executable); 2243 } else { 2244 use_star = FALSE; 2245 sprintf(command, "afio -t -M 8m -b %ld %s %s", TAPE_BLOCK_SIZE, 2246 executable, afio_fname); 2247 } 2248 sprintf(command + strlen(command), " > %s 2>> %s", filelist_fname, 2249 MONDO_LOGFILE); 2250 log_msg(1, "command = %s", command); 2251 if (system(command)) { 2252 log_msg(4, "Warning - error occurred while retrieving TOC"); 2253 } 2254 if ((matches = 2255 save_filelist_entries_in_common(filelist_fname, filelist, 2256 filelist_subset_fname, 2257 use_star)) 2258 <= 0 || length_of_file(filelist_subset_fname) < 2) { 2259 if (length_of_file(filelist_subset_fname) < 2) { 2260 log_msg(1, "No matches found in fileset %ld", 2261 current_tarball_number); 2262 } 2263 sprintf(tmp, "Skipping fileset %ld", current_tarball_number); 2264 log_msg(2, tmp); 2265 restore_this_fileset = FALSE; 2266 } else { 2267 log_msg(5, "%ld matches. Saved fileset %ld's subset to %s", 2268 matches, current_tarball_number, 2269 filelist_subset_fname); 2270 restore_this_fileset = TRUE; 2271 } 2272 } 2263 2273 2264 2274 // Concoct the call to star/afio to restore files 2265 if (strstr(tarball_fname, ".star.")) // star 2266 { 2267 sprintf( command, "star -x file=%s %s", afio_fname, executable); 2268 if (filelist) 2269 { sprintf(command+strlen(command), " list=%s", filelist_subset_fname); } 2270 } 2271 else // afio 2272 { 2273 sprintf( command, "afio -i -M 8m -b %ld %s", TAPE_BLOCK_SIZE, executable); 2274 if (filelist) 2275 { sprintf(command+strlen(command), " -w %s", filelist_subset_fname); } 2276 sprintf(command+strlen(command), " %s", afio_fname); 2277 } 2278 sprintf( command+strlen(command), " 2>> %s", MONDO_LOGFILE); 2275 if (strstr(tarball_fname, ".star.")) // star 2276 { 2277 sprintf(command, "star -x file=%s %s", afio_fname, executable); 2278 if (filelist) { 2279 sprintf(command + strlen(command), " list=%s", 2280 filelist_subset_fname); 2281 } 2282 } else // afio 2283 { 2284 sprintf(command, "afio -i -M 8m -b %ld %s", TAPE_BLOCK_SIZE, 2285 executable); 2286 if (filelist) { 2287 sprintf(command + strlen(command), " -w %s", 2288 filelist_subset_fname); 2289 } 2290 sprintf(command + strlen(command), " %s", afio_fname); 2291 } 2292 sprintf(command + strlen(command), " 2>> %s", MONDO_LOGFILE); 2279 2293 2280 2294 // Call if IF there are files to restore (selectively/unconditionally) 2281 if (restore_this_fileset) 2282 { 2283 log_msg(1, "Calling command='%s'", command); 2284 paranoid_system(command); 2285 2286 iamhere("Restoring xattr, acl stuff"); 2287 res=set_fattr_list(filelist_subset_fname, xattr_fname); 2288 if (res) { log_msg(1, "Errors occurred while setting xattr"); } 2289 else { log_msg(1, "I set xattr OK"); } 2290 retval += res; 2291 2292 res=set_acl_list(filelist_subset_fname, acl_fname); 2293 if (res) { log_msg(1, "Errors occurred while setting ACL"); } 2294 else { log_msg(1, "I set ACL OK"); } 2295 retval += res; 2296 2297 } 2298 else 2299 { 2300 log_msg(1, "NOT CALLING '%s'", command); 2301 } 2302 2303 if (does_file_exist("/PAUSE") && current_tarball_number >= 50) 2304 { 2305 log_to_screen("Paused after set %ld", current_tarball_number); 2306 popup_and_OK("Pausing. Press ENTER to continue."); 2307 } 2308 2309 unlink(filelist_subset_fname); 2310 unlink(filelist_fname); 2311 unlink(afio_fname); 2312 2313 paranoid_free(filelist_subset_fname); 2314 paranoid_free(filelist_fname); 2315 paranoid_free(afio_fname); 2316 paranoid_free(command); 2317 paranoid_free(tmp); 2318 return(retval); 2295 if (restore_this_fileset) { 2296 log_msg(1, "Calling command='%s'", command); 2297 paranoid_system(command); 2298 2299 iamhere("Restoring xattr, acl stuff"); 2300 res = set_fattr_list(filelist_subset_fname, xattr_fname); 2301 if (res) { 2302 log_msg(1, "Errors occurred while setting xattr"); 2303 } else { 2304 log_msg(1, "I set xattr OK"); 2305 } 2306 retval += res; 2307 2308 res = set_acl_list(filelist_subset_fname, acl_fname); 2309 if (res) { 2310 log_msg(1, "Errors occurred while setting ACL"); 2311 } else { 2312 log_msg(1, "I set ACL OK"); 2313 } 2314 retval += res; 2315 2316 } else { 2317 log_msg(1, "NOT CALLING '%s'", command); 2318 } 2319 2320 if (does_file_exist("/PAUSE") && current_tarball_number >= 50) { 2321 log_to_screen("Paused after set %ld", current_tarball_number); 2322 popup_and_OK("Pausing. Press ENTER to continue."); 2323 } 2324 2325 unlink(filelist_subset_fname); 2326 unlink(filelist_fname); 2327 unlink(afio_fname); 2328 2329 paranoid_free(filelist_subset_fname); 2330 paranoid_free(filelist_fname); 2331 paranoid_free(afio_fname); 2332 paranoid_free(command); 2333 paranoid_free(tmp); 2334 return (retval); 2319 2335 } 2336 2320 2337 /************************************************************************** 2321 2338 *END_RESTORE_A_TARBALL_FROM_STREAM * … … 2335 2352 */ 2336 2353 int 2337 restore_all_biggiefiles_from_CD(struct s_bkpinfo *bkpinfo, struct s_node* filelist) 2354 restore_all_biggiefiles_from_CD(struct s_bkpinfo *bkpinfo, 2355 struct s_node *filelist) 2338 2356 { 2339 2340 2341 2357 int retval = 0; 2358 int res; 2359 long noof_biggiefiles, bigfileno = 0, total_slices; 2342 2360 /** malloc **/ 2343 char *tmp; 2344 bool just_changed_cds = FALSE, finished; 2345 char *xattr_fname; 2346 char *acl_fname; 2347 char *biggies_whose_EXATs_we_should_set; // EXtended ATtributes 2348 char *pathname_of_last_biggie_restored; 2349 FILE *fbw = NULL; 2350 2351 malloc_string(xattr_fname); 2352 malloc_string(acl_fname); 2353 malloc_string(tmp); 2354 malloc_string(biggies_whose_EXATs_we_should_set); 2355 malloc_string(pathname_of_last_biggie_restored); 2356 assert(bkpinfo!=NULL); 2357 2358 sprintf(biggies_whose_EXATs_we_should_set, "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir); 2359 if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) 2360 { log_msg(1, "Warning - cannot openout %s", biggies_whose_EXATs_we_should_set); } 2361 2362 read_cfg_var( g_mondo_cfg_file, "total-slices", tmp); 2363 total_slices = atol( tmp ); 2364 sprintf(tmp,"Reassembling large files "); 2365 mvaddstr_and_log_it( g_currentY, 0, tmp ); 2366 if (length_of_file(BIGGIELIST) < 6) 2367 { 2368 log_msg(1, "OK, no biggielist; not restoring biggiefiles"); 2369 return(0); 2370 } 2371 noof_biggiefiles = count_lines_in_file(BIGGIELIST); 2372 if ( noof_biggiefiles <= 0 ) 2373 { 2374 log_msg(2, "OK, no biggiefiles in biggielist; not restoring biggiefiles"); 2375 return(0); 2376 } 2377 sprintf( tmp,"OK, there are %ld biggiefiles in the archives",noof_biggiefiles); 2378 log_msg(2, tmp ); 2379 2380 open_progress_form( "Reassembling large files", 2381 "I am now reassembling all the large files." , 2382 "Please wait. This may take some time.", 2383 "", 2384 total_slices); 2385 for( bigfileno = 0, finished = FALSE; !finished;) 2386 { 2387 log_msg( 2, "Thinking about restoring bigfile %ld", bigfileno + 1 ); 2388 if ( !does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, "" ) ) ) 2389 { 2390 log_msg(3, "...but its first slice isn't on this CD. Perhaps this was a selective restore?"); 2391 log_msg(3, "Cannot find bigfile #%ld 's first slice on %s #%d", bigfileno+1, media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number); 2392 log_msg(3, "Slicename would have been %s", slice_fname(bigfileno+1,0,ARCHIVES_PATH,"")); 2393 // I'm not positive 'just_changed_cds' is even necessary... 2394 if (just_changed_cds) 2395 { 2396 just_changed_cds = FALSE; 2397 log_msg(3, "I'll continue to scan this CD for bigfiles to be restored."); 2398 } 2399 else if (does_file_exist( MNT_CDROM"/archives/NOT-THE-LAST")) 2400 { 2401 insist_on_this_cd_number(bkpinfo, ++g_current_media_number); 2402 sprintf(tmp,"Restoring from %s #%d", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number); 2403 log_to_screen(tmp); 2404 just_changed_cds = TRUE; 2405 } 2406 else 2407 { 2408 log_msg(2, "There was no bigfile #%ld. That's OK." ,bigfileno+1); 2409 log_msg(2, "I'm going to stop restoring bigfiles now."); 2410 finished = TRUE; 2411 } 2412 } 2413 else 2414 { 2415 just_changed_cds = FALSE; 2416 sprintf(tmp,"Restoring big file %ld",bigfileno + 1); 2417 update_progress_form(tmp); 2418 res = restore_a_biggiefile_from_CD(bkpinfo, bigfileno, filelist, pathname_of_last_biggie_restored); 2419 iamhere(pathname_of_last_biggie_restored); 2420 if (fbw && pathname_of_last_biggie_restored[0]) 2421 { fprintf(fbw, "%s\n", pathname_of_last_biggie_restored); } 2422 retval += res; 2423 bigfileno++; 2424 2425 } 2426 } 2427 2428 if (fbw) 2429 { 2430 fclose(fbw); 2431 sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH); 2432 sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH); 2433 if (length_of_file(acl_fname) >0 && find_home_of_exe("setfacl")) 2434 { 2435 set_acl_list (biggies_whose_EXATs_we_should_set, acl_fname); 2436 } 2437 if (length_of_file(xattr_fname)>0 && find_home_of_exe("setfattr")) 2438 { 2439 set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname); 2440 } 2441 } 2442 if (does_file_exist("/PAUSE")) 2443 { popup_and_OK("Press ENTER to go on. Delete /PAUSE to stop these pauses."); } 2444 close_progress_form(); 2445 if (retval) 2446 { 2447 mvaddstr_and_log_it(g_currentY++, 74, "Errors."); 2448 } 2449 else 2450 { 2451 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 2452 } 2453 paranoid_free(xattr_fname); 2454 paranoid_free(acl_fname); 2455 paranoid_free(tmp); 2456 paranoid_free(biggies_whose_EXATs_we_should_set); 2457 paranoid_free(pathname_of_last_biggie_restored); 2458 return( retval ); 2361 char *tmp; 2362 bool just_changed_cds = FALSE, finished; 2363 char *xattr_fname; 2364 char *acl_fname; 2365 char *biggies_whose_EXATs_we_should_set; // EXtended ATtributes 2366 char *pathname_of_last_biggie_restored; 2367 FILE *fbw = NULL; 2368 2369 malloc_string(xattr_fname); 2370 malloc_string(acl_fname); 2371 malloc_string(tmp); 2372 malloc_string(biggies_whose_EXATs_we_should_set); 2373 malloc_string(pathname_of_last_biggie_restored); 2374 assert(bkpinfo != NULL); 2375 2376 sprintf(biggies_whose_EXATs_we_should_set, 2377 "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir); 2378 if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) { 2379 log_msg(1, "Warning - cannot openout %s", 2380 biggies_whose_EXATs_we_should_set); 2381 } 2382 2383 read_cfg_var(g_mondo_cfg_file, "total-slices", tmp); 2384 total_slices = atol(tmp); 2385 sprintf(tmp, "Reassembling large files "); 2386 mvaddstr_and_log_it(g_currentY, 0, tmp); 2387 if (length_of_file(BIGGIELIST) < 6) { 2388 log_msg(1, "OK, no biggielist; not restoring biggiefiles"); 2389 return (0); 2390 } 2391 noof_biggiefiles = count_lines_in_file(BIGGIELIST); 2392 if (noof_biggiefiles <= 0) { 2393 log_msg(2, 2394 "OK, no biggiefiles in biggielist; not restoring biggiefiles"); 2395 return (0); 2396 } 2397 sprintf(tmp, "OK, there are %ld biggiefiles in the archives", 2398 noof_biggiefiles); 2399 log_msg(2, tmp); 2400 2401 open_progress_form("Reassembling large files", 2402 "I am now reassembling all the large files.", 2403 "Please wait. This may take some time.", 2404 "", total_slices); 2405 for (bigfileno = 0, finished = FALSE; !finished;) { 2406 log_msg(2, "Thinking about restoring bigfile %ld", bigfileno + 1); 2407 if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) { 2408 log_msg(3, 2409 "...but its first slice isn't on this CD. Perhaps this was a selective restore?"); 2410 log_msg(3, "Cannot find bigfile #%ld 's first slice on %s #%d", 2411 bigfileno + 1, 2412 media_descriptor_string(bkpinfo->backup_media_type), 2413 g_current_media_number); 2414 log_msg(3, "Slicename would have been %s", 2415 slice_fname(bigfileno + 1, 0, ARCHIVES_PATH, "")); 2416 // I'm not positive 'just_changed_cds' is even necessary... 2417 if (just_changed_cds) { 2418 just_changed_cds = FALSE; 2419 log_msg(3, 2420 "I'll continue to scan this CD for bigfiles to be restored."); 2421 } else if (does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")) { 2422 insist_on_this_cd_number(bkpinfo, 2423 ++g_current_media_number); 2424 sprintf(tmp, "Restoring from %s #%d", 2425 media_descriptor_string(bkpinfo-> 2426 backup_media_type), 2427 g_current_media_number); 2428 log_to_screen(tmp); 2429 just_changed_cds = TRUE; 2430 } else { 2431 log_msg(2, "There was no bigfile #%ld. That's OK.", 2432 bigfileno + 1); 2433 log_msg(2, "I'm going to stop restoring bigfiles now."); 2434 finished = TRUE; 2435 } 2436 } else { 2437 just_changed_cds = FALSE; 2438 sprintf(tmp, "Restoring big file %ld", bigfileno + 1); 2439 update_progress_form(tmp); 2440 res = 2441 restore_a_biggiefile_from_CD(bkpinfo, bigfileno, filelist, 2442 pathname_of_last_biggie_restored); 2443 iamhere(pathname_of_last_biggie_restored); 2444 if (fbw && pathname_of_last_biggie_restored[0]) { 2445 fprintf(fbw, "%s\n", pathname_of_last_biggie_restored); 2446 } 2447 retval += res; 2448 bigfileno++; 2449 2450 } 2451 } 2452 2453 if (fbw) { 2454 fclose(fbw); 2455 sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH); 2456 sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, ARCHIVES_PATH); 2457 if (length_of_file(acl_fname) > 0 && find_home_of_exe("setfacl")) { 2458 set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname); 2459 } 2460 if (length_of_file(xattr_fname) > 0 2461 && find_home_of_exe("setfattr")) { 2462 set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname); 2463 } 2464 } 2465 if (does_file_exist("/PAUSE")) { 2466 popup_and_OK 2467 ("Press ENTER to go on. Delete /PAUSE to stop these pauses."); 2468 } 2469 close_progress_form(); 2470 if (retval) { 2471 mvaddstr_and_log_it(g_currentY++, 74, "Errors."); 2472 } else { 2473 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 2474 } 2475 paranoid_free(xattr_fname); 2476 paranoid_free(acl_fname); 2477 paranoid_free(tmp); 2478 paranoid_free(biggies_whose_EXATs_we_should_set); 2479 paranoid_free(pathname_of_last_biggie_restored); 2480 return (retval); 2459 2481 } 2482 2460 2483 /************************************************************************** 2461 2484 *END_RESTORE_ALL_BIGGIFILES_FROM_CD * … … 2475 2498 */ 2476 2499 int 2477 restore_all_tarballs_from_CD(struct s_bkpinfo *bkpinfo, struct s_node* filelist) 2500 restore_all_tarballs_from_CD(struct s_bkpinfo *bkpinfo, 2501 struct s_node *filelist) 2478 2502 { 2479 2480 2481 2482 2483 2503 int retval = 0; 2504 int res; 2505 int attempts; 2506 long current_tarball_number = 0; 2507 long max_val; 2484 2508 /**malloc ***/ 2485 char *tmp; 2486 char *tarball_fname; 2487 char *progress_str; 2488 char *comment; 2489 2490 malloc_string(tmp); 2491 malloc_string(tarball_fname); 2492 malloc_string(progress_str); 2493 malloc_string(comment); 2494 2495 assert(bkpinfo!=NULL); 2496 2497 mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives"); 2498 log_msg(2, "Insisting on 1st CD, so that I can have a look at LAST-FILELIST-NUMBER"); 2499 if ( g_current_media_number != 1) 2500 { 2501 log_msg(3, "OK, that's jacked up."); 2502 g_current_media_number = 1; 2503 } 2504 insist_on_this_cd_number( bkpinfo, g_current_media_number); 2505 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp); 2506 max_val = atol(tmp) + 1; 2507 sprintf(progress_str,"Restoring from %s #%d", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number); 2508 log_to_screen(progress_str); 2509 open_progress_form("Restoring from archives", 2510 "Restoring data from the archives." , 2511 "Please wait. This may take some time.", 2512 progress_str,max_val); 2513 for(;;) 2514 { 2515 insist_on_this_cd_number(bkpinfo, g_current_media_number); 2516 update_progress_form(progress_str); 2517 sprintf(tarball_fname, MNT_CDROM"/archives/%ld.afio.bz2",current_tarball_number); 2518 if (!does_file_exist(tarball_fname)) 2519 { 2520 sprintf(tarball_fname, MNT_CDROM"/archives/%ld.afio.lzo",current_tarball_number); 2521 } 2522 if (!does_file_exist(tarball_fname)) 2523 { 2524 sprintf(tarball_fname, MNT_CDROM"/archives/%ld.afio.",current_tarball_number); 2525 } 2526 if (!does_file_exist(tarball_fname)) 2527 { 2528 sprintf(tarball_fname, MNT_CDROM"/archives/%ld.star.bz2", current_tarball_number); 2529 } 2530 if (!does_file_exist(tarball_fname)) 2531 { 2532 sprintf(tarball_fname, MNT_CDROM"/archives/%ld.star.", current_tarball_number); 2533 } 2534 if (!does_file_exist(tarball_fname)) 2535 { 2536 if (current_tarball_number == 0) 2537 { 2538 log_to_screen("No tarballs. Strange. Maybe you only backed up freakin' big files?"); 2539 return(0); 2540 } 2541 if (!does_file_exist( MNT_CDROM"/archives/NOT-THE-LAST") || system("find "MNT_CDROM"/archives/slice* > /dev/null 2> /dev/null") == 0 ) 2542 { 2543 break; 2544 } 2545 g_current_media_number++; 2546 sprintf(progress_str,"Restoring from %s #%d",media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number); 2547 log_to_screen(progress_str); 2548 } 2549 else 2550 { 2551 sprintf(progress_str,"Restoring from fileset #%ld on %s #%d", 2552 current_tarball_number, 2553 media_descriptor_string(bkpinfo->backup_media_type), 2554 g_current_media_number); 2555 // log_msg(3, "progress_str = %s", progress_str); 2556 for(res = 999, attempts = 0; attempts < 3 && res != 0; attempts++) 2557 { 2558 res = restore_a_tarball_from_CD(tarball_fname,current_tarball_number, filelist); 2559 } 2560 sprintf(tmp,"%s #%d, fileset #%ld - restore ", 2561 media_descriptor_string(bkpinfo->backup_media_type), 2562 g_current_media_number, 2563 current_tarball_number); 2564 if (res) 2565 { 2566 strcat(tmp,"reported errors"); 2567 } 2568 else if (attempts > 1) 2569 { 2570 strcat(tmp,"succeeded"); 2571 } 2572 else 2573 { 2574 strcat(tmp,"succeeded"); 2575 } 2576 if (attempts > 1) 2577 { 2578 sprintf( tmp + strlen(tmp)," (%d attempts) - review logs",attempts); 2579 } 2580 strcpy(comment, tmp); 2581 if (attempts > 1) 2582 { 2583 log_to_screen(comment); 2584 } 2585 2586 retval += res; 2587 current_tarball_number++; 2588 g_current_progress++; 2589 } 2590 } 2591 close_progress_form(); 2592 if (retval) 2593 { 2594 mvaddstr_and_log_it(g_currentY++,74,"Errors."); 2595 } 2596 else 2597 { 2598 mvaddstr_and_log_it(g_currentY++,74,"Done."); 2599 } 2600 paranoid_free(tmp); 2601 paranoid_free(tarball_fname); 2602 paranoid_free(progress_str); 2603 paranoid_free(comment); 2604 2605 return(retval); 2509 char *tmp; 2510 char *tarball_fname; 2511 char *progress_str; 2512 char *comment; 2513 2514 malloc_string(tmp); 2515 malloc_string(tarball_fname); 2516 malloc_string(progress_str); 2517 malloc_string(comment); 2518 2519 assert(bkpinfo != NULL); 2520 2521 mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives"); 2522 log_msg(2, 2523 "Insisting on 1st CD, so that I can have a look at LAST-FILELIST-NUMBER"); 2524 if (g_current_media_number != 1) { 2525 log_msg(3, "OK, that's jacked up."); 2526 g_current_media_number = 1; 2527 } 2528 insist_on_this_cd_number(bkpinfo, g_current_media_number); 2529 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp); 2530 max_val = atol(tmp) + 1; 2531 sprintf(progress_str, "Restoring from %s #%d", 2532 media_descriptor_string(bkpinfo->backup_media_type), 2533 g_current_media_number); 2534 log_to_screen(progress_str); 2535 open_progress_form("Restoring from archives", 2536 "Restoring data from the archives.", 2537 "Please wait. This may take some time.", 2538 progress_str, max_val); 2539 for (;;) { 2540 insist_on_this_cd_number(bkpinfo, g_current_media_number); 2541 update_progress_form(progress_str); 2542 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.bz2", 2543 current_tarball_number); 2544 if (!does_file_exist(tarball_fname)) { 2545 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.lzo", 2546 current_tarball_number); 2547 } 2548 if (!does_file_exist(tarball_fname)) { 2549 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.afio.", 2550 current_tarball_number); 2551 } 2552 if (!does_file_exist(tarball_fname)) { 2553 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.bz2", 2554 current_tarball_number); 2555 } 2556 if (!does_file_exist(tarball_fname)) { 2557 sprintf(tarball_fname, MNT_CDROM "/archives/%ld.star.", 2558 current_tarball_number); 2559 } 2560 if (!does_file_exist(tarball_fname)) { 2561 if (current_tarball_number == 0) { 2562 log_to_screen 2563 ("No tarballs. Strange. Maybe you only backed up freakin' big files?"); 2564 return (0); 2565 } 2566 if (!does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST") 2567 || system("find " MNT_CDROM 2568 "/archives/slice* > /dev/null 2> /dev/null") == 2569 0) { 2570 break; 2571 } 2572 g_current_media_number++; 2573 sprintf(progress_str, "Restoring from %s #%d", 2574 media_descriptor_string(bkpinfo->backup_media_type), 2575 g_current_media_number); 2576 log_to_screen(progress_str); 2577 } else { 2578 sprintf(progress_str, "Restoring from fileset #%ld on %s #%d", 2579 current_tarball_number, 2580 media_descriptor_string(bkpinfo->backup_media_type), 2581 g_current_media_number); 2582 // log_msg(3, "progress_str = %s", progress_str); 2583 for (res = 999, attempts = 0; attempts < 3 && res != 0; 2584 attempts++) { 2585 res = 2586 restore_a_tarball_from_CD(tarball_fname, 2587 current_tarball_number, 2588 filelist); 2589 } 2590 sprintf(tmp, "%s #%d, fileset #%ld - restore ", 2591 media_descriptor_string(bkpinfo->backup_media_type), 2592 g_current_media_number, current_tarball_number); 2593 if (res) { 2594 strcat(tmp, "reported errors"); 2595 } else if (attempts > 1) { 2596 strcat(tmp, "succeeded"); 2597 } else { 2598 strcat(tmp, "succeeded"); 2599 } 2600 if (attempts > 1) { 2601 sprintf(tmp + strlen(tmp), " (%d attempts) - review logs", 2602 attempts); 2603 } 2604 strcpy(comment, tmp); 2605 if (attempts > 1) { 2606 log_to_screen(comment); 2607 } 2608 2609 retval += res; 2610 current_tarball_number++; 2611 g_current_progress++; 2612 } 2613 } 2614 close_progress_form(); 2615 if (retval) { 2616 mvaddstr_and_log_it(g_currentY++, 74, "Errors."); 2617 } else { 2618 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 2619 } 2620 paranoid_free(tmp); 2621 paranoid_free(tarball_fname); 2622 paranoid_free(progress_str); 2623 paranoid_free(comment); 2624 2625 return (retval); 2606 2626 } 2607 2627 … … 2620 2640 */ 2621 2641 int 2622 restore_all_biggiefiles_from_stream(struct s_bkpinfo *bkpinfo, struct s_node*filelist) 2642 restore_all_biggiefiles_from_stream(struct s_bkpinfo *bkpinfo, 2643 struct s_node *filelist) 2623 2644 { 2624 2625 2626 2627 2628 2629 2630 2645 long noof_biggiefiles; 2646 long current_bigfile_number = 0; 2647 long total_slices; 2648 2649 int retval = 0; 2650 int res = 0; 2651 int ctrl_chr; 2631 2652 2632 2653 /** malloc add ****/ 2633 char *tmp; 2634 char *biggie_fname; 2635 char *biggie_cksum; 2636 char *xattr_fname; 2637 char *acl_fname; 2638 char *p; 2639 char *pathname_of_last_biggie_restored; 2640 char *biggies_whose_EXATs_we_should_set; // EXtended ATtributes 2641 long long biggie_size; 2642 FILE *fbw = NULL; 2643 2644 malloc_string(tmp); 2645 malloc_string(biggie_fname); 2646 malloc_string(biggie_cksum); 2647 malloc_string(xattr_fname); 2648 malloc_string(acl_fname); 2649 malloc_string(biggies_whose_EXATs_we_should_set); 2650 malloc_string(pathname_of_last_biggie_restored); 2651 assert(bkpinfo!=NULL); 2652 2653 read_cfg_var(g_mondo_cfg_file, "total-slices", tmp); 2654 2655 total_slices = atol(tmp); 2656 sprintf(tmp, "Reassembling large files "); 2657 sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir); 2658 sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir); 2659 mvaddstr_and_log_it( g_currentY, 0, tmp ); 2660 sprintf(biggies_whose_EXATs_we_should_set, "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir); 2661 if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) 2662 { log_msg(1, "Warning - cannot openout %s", biggies_whose_EXATs_we_should_set); } 2663 2654 char *tmp; 2655 char *biggie_fname; 2656 char *biggie_cksum; 2657 char *xattr_fname; 2658 char *acl_fname; 2659 char *p; 2660 char *pathname_of_last_biggie_restored; 2661 char *biggies_whose_EXATs_we_should_set; // EXtended ATtributes 2662 long long biggie_size; 2663 FILE *fbw = NULL; 2664 2665 malloc_string(tmp); 2666 malloc_string(biggie_fname); 2667 malloc_string(biggie_cksum); 2668 malloc_string(xattr_fname); 2669 malloc_string(acl_fname); 2670 malloc_string(biggies_whose_EXATs_we_should_set); 2671 malloc_string(pathname_of_last_biggie_restored); 2672 assert(bkpinfo != NULL); 2673 2674 read_cfg_var(g_mondo_cfg_file, "total-slices", tmp); 2675 2676 total_slices = atol(tmp); 2677 sprintf(tmp, "Reassembling large files "); 2678 sprintf(xattr_fname, XATTR_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir); 2679 sprintf(acl_fname, ACL_BIGGLST_FNAME_RAW_SZ, bkpinfo->tmpdir); 2680 mvaddstr_and_log_it(g_currentY, 0, tmp); 2681 sprintf(biggies_whose_EXATs_we_should_set, 2682 "%s/biggies-whose-EXATs-we-should-set", bkpinfo->tmpdir); 2683 if (!(fbw = fopen(biggies_whose_EXATs_we_should_set, "w"))) { 2684 log_msg(1, "Warning - cannot openout %s", 2685 biggies_whose_EXATs_we_should_set); 2686 } 2664 2687 // get xattr and acl files if they're there 2665 res = read_header_block_from_stream( &biggie_size, biggie_fname, &ctrl_chr); 2666 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) 2667 { 2668 res = read_EXAT_files_from_tape(bkpinfo, &biggie_size, biggie_fname, &ctrl_chr, xattr_fname, acl_fname); 2669 } 2670 2671 noof_biggiefiles = atol( biggie_fname ); 2672 sprintf( tmp, "OK, there are %ld biggiefiles in the archives", noof_biggiefiles ); 2673 log_msg(2, tmp ); 2674 open_progress_form( "Reassembling large files", 2675 "I am now reassembling all the large files." , 2676 "Please wait. This may take some time.", 2677 "", 2678 total_slices); 2679 2680 for( res = read_header_block_from_stream( &biggie_size, biggie_fname, &ctrl_chr); ctrl_chr!=BLK_STOP_BIGGIEFILES; res=read_header_block_from_stream(&biggie_size, biggie_fname, &ctrl_chr)) 2681 { 2682 if (ctrl_chr != BLK_START_A_NORMBIGGIE && ctrl_chr != BLK_START_A_PIHBIGGIE) 2683 { 2684 wrong_marker(BLK_START_A_NORMBIGGIE,ctrl_chr); 2685 } 2686 p = strrchr(biggie_fname,'/'); 2687 if (!p) 2688 { 2689 p = biggie_fname; 2690 } 2691 else 2692 { 2693 p++; 2694 } 2695 sprintf(tmp,"Restoring big file %ld (%lld K)",current_bigfile_number+1, biggie_size/1024); 2696 update_progress_form(tmp); 2697 res = restore_a_biggiefile_from_stream(bkpinfo,biggie_fname, 2698 current_bigfile_number, 2699 biggie_cksum, 2700 biggie_size, 2701 filelist, ctrl_chr, 2702 pathname_of_last_biggie_restored); 2703 log_msg(1, "I believe I have restored %s", pathname_of_last_biggie_restored); 2704 if (fbw && pathname_of_last_biggie_restored[0]) 2705 { fprintf(fbw, "%s\n", pathname_of_last_biggie_restored); } 2706 retval += res; 2707 current_bigfile_number++; 2708 2709 } 2710 if (current_bigfile_number != noof_biggiefiles && noof_biggiefiles != 0 ) 2711 { 2712 sprintf( tmp, 2713 "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n",current_bigfile_number, 2714 noof_biggiefiles); 2715 } 2716 else 2717 { 2718 sprintf( tmp,"%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.", 2719 noof_biggiefiles, 2720 current_bigfile_number); 2721 } 2722 log_msg(1, tmp); 2723 2724 if (fbw) 2725 { 2726 fclose(fbw); 2727 if (length_of_file(biggies_whose_EXATs_we_should_set) >2) 2728 { 2729 iamhere("Setting biggie-EXATs"); 2730 if (length_of_file(acl_fname) >0) 2731 { 2732 log_msg(1, "set_acl_list(%s,%s)", biggies_whose_EXATs_we_should_set, acl_fname); 2733 set_acl_list (biggies_whose_EXATs_we_should_set, acl_fname); 2734 } 2735 if (length_of_file(xattr_fname)>0) 2736 { 2737 log_msg(1, "set_fattr_List(%s,%s)", biggies_whose_EXATs_we_should_set, xattr_fname); 2738 set_fattr_list(biggies_whose_EXATs_we_should_set, xattr_fname); 2739 } 2740 } 2741 else 2742 { 2743 iamhere("No biggiefiles selected. So, no biggie-EXATs to set."); 2744 } 2745 } 2746 if (does_file_exist("/PAUSE")) 2747 { popup_and_OK("Press ENTER to go on. Delete /PAUSE to stop these pauses."); } 2748 2749 close_progress_form(); 2750 if (retval) 2751 { 2752 mvaddstr_and_log_it(g_currentY++, 74, "Errors."); 2753 } 2754 else 2755 { 2756 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 2757 } 2758 paranoid_free(biggies_whose_EXATs_we_should_set); 2759 paranoid_free(pathname_of_last_biggie_restored); 2760 paranoid_free(biggie_fname); 2761 paranoid_free(biggie_cksum); 2762 paranoid_free(xattr_fname); 2763 paranoid_free(acl_fname); 2764 paranoid_free(tmp); 2765 return(retval); 2688 res = 2689 read_header_block_from_stream(&biggie_size, biggie_fname, 2690 &ctrl_chr); 2691 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) { 2692 res = 2693 read_EXAT_files_from_tape(bkpinfo, &biggie_size, biggie_fname, 2694 &ctrl_chr, xattr_fname, acl_fname); 2695 } 2696 2697 noof_biggiefiles = atol(biggie_fname); 2698 sprintf(tmp, "OK, there are %ld biggiefiles in the archives", 2699 noof_biggiefiles); 2700 log_msg(2, tmp); 2701 open_progress_form("Reassembling large files", 2702 "I am now reassembling all the large files.", 2703 "Please wait. This may take some time.", 2704 "", total_slices); 2705 2706 for (res = 2707 read_header_block_from_stream(&biggie_size, biggie_fname, 2708 &ctrl_chr); 2709 ctrl_chr != BLK_STOP_BIGGIEFILES; 2710 res = 2711 read_header_block_from_stream(&biggie_size, biggie_fname, 2712 &ctrl_chr)) { 2713 if (ctrl_chr != BLK_START_A_NORMBIGGIE 2714 && ctrl_chr != BLK_START_A_PIHBIGGIE) { 2715 wrong_marker(BLK_START_A_NORMBIGGIE, ctrl_chr); 2716 } 2717 p = strrchr(biggie_fname, '/'); 2718 if (!p) { 2719 p = biggie_fname; 2720 } else { 2721 p++; 2722 } 2723 sprintf(tmp, "Restoring big file %ld (%lld K)", 2724 current_bigfile_number + 1, biggie_size / 1024); 2725 update_progress_form(tmp); 2726 res = restore_a_biggiefile_from_stream(bkpinfo, biggie_fname, 2727 current_bigfile_number, 2728 biggie_cksum, 2729 biggie_size, 2730 filelist, ctrl_chr, 2731 pathname_of_last_biggie_restored); 2732 log_msg(1, "I believe I have restored %s", 2733 pathname_of_last_biggie_restored); 2734 if (fbw && pathname_of_last_biggie_restored[0]) { 2735 fprintf(fbw, "%s\n", pathname_of_last_biggie_restored); 2736 } 2737 retval += res; 2738 current_bigfile_number++; 2739 2740 } 2741 if (current_bigfile_number != noof_biggiefiles 2742 && noof_biggiefiles != 0) { 2743 sprintf(tmp, "Warning - bigfileno=%ld but noof_biggiefiles=%ld\n", 2744 current_bigfile_number, noof_biggiefiles); 2745 } else { 2746 sprintf(tmp, 2747 "%ld biggiefiles in biggielist.txt; %ld biggiefiles processed today.", 2748 noof_biggiefiles, current_bigfile_number); 2749 } 2750 log_msg(1, tmp); 2751 2752 if (fbw) { 2753 fclose(fbw); 2754 if (length_of_file(biggies_whose_EXATs_we_should_set) > 2) { 2755 iamhere("Setting biggie-EXATs"); 2756 if (length_of_file(acl_fname) > 0) { 2757 log_msg(1, "set_acl_list(%s,%s)", 2758 biggies_whose_EXATs_we_should_set, acl_fname); 2759 set_acl_list(biggies_whose_EXATs_we_should_set, acl_fname); 2760 } 2761 if (length_of_file(xattr_fname) > 0) { 2762 log_msg(1, "set_fattr_List(%s,%s)", 2763 biggies_whose_EXATs_we_should_set, xattr_fname); 2764 set_fattr_list(biggies_whose_EXATs_we_should_set, 2765 xattr_fname); 2766 } 2767 } else { 2768 iamhere 2769 ("No biggiefiles selected. So, no biggie-EXATs to set."); 2770 } 2771 } 2772 if (does_file_exist("/PAUSE")) { 2773 popup_and_OK 2774 ("Press ENTER to go on. Delete /PAUSE to stop these pauses."); 2775 } 2776 2777 close_progress_form(); 2778 if (retval) { 2779 mvaddstr_and_log_it(g_currentY++, 74, "Errors."); 2780 } else { 2781 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 2782 } 2783 paranoid_free(biggies_whose_EXATs_we_should_set); 2784 paranoid_free(pathname_of_last_biggie_restored); 2785 paranoid_free(biggie_fname); 2786 paranoid_free(biggie_cksum); 2787 paranoid_free(xattr_fname); 2788 paranoid_free(acl_fname); 2789 paranoid_free(tmp); 2790 return (retval); 2766 2791 } 2792 2767 2793 /************************************************************************** 2768 2794 *END_RESTORE_ALL_BIGGIEFILES_FROM_STREAM * … … 2785 2811 */ 2786 2812 int 2787 restore_all_tarballs_from_stream(struct s_bkpinfo *bkpinfo, struct s_node *filelist) 2813 restore_all_tarballs_from_stream(struct s_bkpinfo *bkpinfo, 2814 struct s_node *filelist) 2788 2815 { 2789 2790 2791 2792 2793 long max_val /*, total_noof_files */;2816 int retval = 0; 2817 int res; 2818 long current_afioball_number = 0; 2819 int ctrl_chr; 2820 long max_val /*, total_noof_files */ ; 2794 2821 2795 2822 /** malloc **/ 2796 char *tmp; 2797 char *progress_str; 2798 char *tmp_fname; 2799 char *xattr_fname; 2800 char *acl_fname; 2801 2802 long long tmp_size; 2803 2804 malloc_string(tmp); 2805 malloc_string(progress_str); 2806 malloc_string(tmp_fname); 2807 assert(bkpinfo!=NULL); 2808 malloc_string(xattr_fname); 2809 malloc_string(acl_fname); 2810 mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives"); 2811 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp); 2812 max_val = atol(tmp) + 1; 2813 2814 chdir(bkpinfo->restore_path); /* I don't know why this is needed _here_ but it seems to be. -HR, 02/04/2002 */ 2815 2816 run_program_and_log_output("pwd", 5); 2817 2818 sprintf(progress_str,"Restoring from media #%d",g_current_media_number); 2819 log_to_screen(progress_str); 2820 open_progress_form("Restoring from archives", 2821 "Restoring data from the archives." , 2822 "Please wait. This may take some time.", 2823 progress_str,max_val); 2824 2825 log_msg(3, "hey"); 2826 2827 res = read_header_block_from_stream( &tmp_size, tmp_fname, &ctrl_chr); 2828 if (res) 2829 { 2830 log_msg(2, "Warning - error reading afioball from tape"); 2831 } 2832 retval += res; 2833 if ( ctrl_chr != BLK_START_AFIOBALLS) 2834 { 2835 wrong_marker(BLK_START_AFIOBALLS,ctrl_chr); 2836 } 2837 log_msg(2, "ho"); 2838 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr); 2839 while(ctrl_chr!=BLK_STOP_AFIOBALLS) 2840 { 2841 update_progress_form(progress_str); 2842 sprintf(xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir, current_afioball_number); 2843 sprintf(acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir, current_afioball_number); 2844 unlink(xattr_fname); 2845 unlink(acl_fname); 2846 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) 2847 { 2848 iamhere("Reading EXAT files from tape"); 2849 res = read_EXAT_files_from_tape(bkpinfo, &tmp_size, tmp_fname, &ctrl_chr, xattr_fname, acl_fname); 2850 } 2851 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) 2852 { wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr); } 2853 sprintf(tmp, 2854 "Restoring from fileset #%ld (name=%s, size=%ld K)", 2855 current_afioball_number, 2856 tmp_fname, 2857 (long) tmp_size>>10); 2858 res = restore_a_tarball_from_stream(bkpinfo,tmp_fname,current_afioball_number,filelist,tmp_size, xattr_fname, acl_fname); 2859 retval += res; 2860 if ( res ) 2861 { 2862 sprintf(tmp,"Fileset %ld - errors occurred",current_afioball_number); 2863 log_to_screen(tmp); 2864 } 2865 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr); 2866 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) 2867 { 2868 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE,ctrl_chr); 2869 } 2870 2871 current_afioball_number++; 2872 g_current_progress++; 2873 sprintf(progress_str,"Restoring from fileset #%ld on %s #%d",current_afioball_number, media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number); 2874 res=read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr); 2875 unlink(xattr_fname); 2876 unlink(acl_fname); 2877 } // next 2878 log_msg(1, "All done with afioballs"); 2879 close_progress_form(); 2880 if (retval) 2881 { 2882 mvaddstr_and_log_it(g_currentY++,74,"Errors."); } 2883 else 2884 { 2885 mvaddstr_and_log_it(g_currentY++,74,"Done."); } 2886 paranoid_free(tmp); 2887 paranoid_free(progress_str); 2888 paranoid_free(tmp_fname); 2889 paranoid_free(xattr_fname); 2890 paranoid_free(acl_fname); 2891 return(retval); 2823 char *tmp; 2824 char *progress_str; 2825 char *tmp_fname; 2826 char *xattr_fname; 2827 char *acl_fname; 2828 2829 long long tmp_size; 2830 2831 malloc_string(tmp); 2832 malloc_string(progress_str); 2833 malloc_string(tmp_fname); 2834 assert(bkpinfo != NULL); 2835 malloc_string(xattr_fname); 2836 malloc_string(acl_fname); 2837 mvaddstr_and_log_it(g_currentY, 0, "Restoring from archives"); 2838 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp); 2839 max_val = atol(tmp) + 1; 2840 2841 chdir(bkpinfo->restore_path); /* I don't know why this is needed _here_ but it seems to be. -HR, 02/04/2002 */ 2842 2843 run_program_and_log_output("pwd", 5); 2844 2845 sprintf(progress_str, "Restoring from media #%d", 2846 g_current_media_number); 2847 log_to_screen(progress_str); 2848 open_progress_form("Restoring from archives", 2849 "Restoring data from the archives.", 2850 "Please wait. This may take some time.", 2851 progress_str, max_val); 2852 2853 log_msg(3, "hey"); 2854 2855 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr); 2856 if (res) { 2857 log_msg(2, "Warning - error reading afioball from tape"); 2858 } 2859 retval += res; 2860 if (ctrl_chr != BLK_START_AFIOBALLS) { 2861 wrong_marker(BLK_START_AFIOBALLS, ctrl_chr); 2862 } 2863 log_msg(2, "ho"); 2864 res = read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr); 2865 while (ctrl_chr != BLK_STOP_AFIOBALLS) { 2866 update_progress_form(progress_str); 2867 sprintf(xattr_fname, "%s/xattr-subset-%ld.tmp", bkpinfo->tmpdir, 2868 current_afioball_number); 2869 sprintf(acl_fname, "%s/acl-subset-%ld.tmp", bkpinfo->tmpdir, 2870 current_afioball_number); 2871 unlink(xattr_fname); 2872 unlink(acl_fname); 2873 if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) { 2874 iamhere("Reading EXAT files from tape"); 2875 res = 2876 read_EXAT_files_from_tape(bkpinfo, &tmp_size, tmp_fname, 2877 &ctrl_chr, xattr_fname, 2878 acl_fname); 2879 } 2880 if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) { 2881 wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr); 2882 } 2883 sprintf(tmp, 2884 "Restoring from fileset #%ld (name=%s, size=%ld K)", 2885 current_afioball_number, tmp_fname, (long) tmp_size >> 10); 2886 res = 2887 restore_a_tarball_from_stream(bkpinfo, tmp_fname, 2888 current_afioball_number, 2889 filelist, tmp_size, xattr_fname, 2890 acl_fname); 2891 retval += res; 2892 if (res) { 2893 sprintf(tmp, "Fileset %ld - errors occurred", 2894 current_afioball_number); 2895 log_to_screen(tmp); 2896 } 2897 res = 2898 read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr); 2899 if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) { 2900 wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr); 2901 } 2902 2903 current_afioball_number++; 2904 g_current_progress++; 2905 sprintf(progress_str, "Restoring from fileset #%ld on %s #%d", 2906 current_afioball_number, 2907 media_descriptor_string(bkpinfo->backup_media_type), 2908 g_current_media_number); 2909 res = 2910 read_header_block_from_stream(&tmp_size, tmp_fname, &ctrl_chr); 2911 unlink(xattr_fname); 2912 unlink(acl_fname); 2913 } // next 2914 log_msg(1, "All done with afioballs"); 2915 close_progress_form(); 2916 if (retval) { 2917 mvaddstr_and_log_it(g_currentY++, 74, "Errors."); 2918 } else { 2919 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 2920 } 2921 paranoid_free(tmp); 2922 paranoid_free(progress_str); 2923 paranoid_free(tmp_fname); 2924 paranoid_free(xattr_fname); 2925 paranoid_free(acl_fname); 2926 return (retval); 2892 2927 } 2928 2893 2929 /************************************************************************** 2894 2930 *END_ RESTORE_ALL_TARBALLS_FROM_STREAM * … … 2906 2942 * @ingroup restoreGroup 2907 2943 */ 2908 int 2909 restore_everything(struct s_bkpinfo*bkpinfo, 2910 struct s_node *filelist) 2944 int restore_everything(struct s_bkpinfo *bkpinfo, struct s_node *filelist) 2911 2945 { 2912 2913 2946 int resA; 2947 int resB; 2914 2948 2915 2949 /** mallco ***/ 2916 char *cwd; 2917 char *newpath; 2918 char *tmp; 2919 assert(bkpinfo!=NULL); 2920 2921 malloc_string(cwd); 2922 malloc_string(newpath); 2923 malloc_string(tmp); 2924 log_msg(2, "restore_everything() --- starting"); 2925 g_current_media_number = 1; 2926 getcwd(cwd, MAX_STR_LEN - 1); 2927 sprintf(tmp, "mkdir -p %s", bkpinfo->restore_path); 2928 run_program_and_log_output(tmp, FALSE); 2929 log_msg(1, "Changing dir to %s", bkpinfo->restore_path); 2930 chdir(bkpinfo->restore_path); 2931 getcwd(newpath,MAX_STR_LEN-1); 2932 log_msg(1, "path is now %s", newpath); 2933 log_msg(1, "restoring everything"); 2934 if (!find_home_of_exe("petris") && !g_text_mode) 2935 { 2936 newtDrawRootText(0, g_noof_rows-2, "Press ALT-<left cursor> twice to play Petris :-) "); 2937 newtRefresh(); 2938 } 2939 mvaddstr_and_log_it (g_currentY, 0, "Preparing to read your archives"); 2940 if ( IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type ) ) 2941 { 2942 mount_cdrom( bkpinfo ); 2943 mvaddstr_and_log_it ( g_currentY++, 0, "Restoring OS and data from streaming media"); 2944 if (bkpinfo->backup_media_type == cdstream) 2945 { 2946 openin_cdstream( bkpinfo ); 2947 } 2948 else 2949 { 2950 assert_string_is_neither_NULL_nor_zerolength(bkpinfo->media_device); 2951 openin_tape(bkpinfo); 2952 } 2953 resA = restore_all_tarballs_from_stream(bkpinfo, filelist); 2954 resB = restore_all_biggiefiles_from_stream(bkpinfo, filelist); 2955 if (bkpinfo->backup_media_type == cdstream) 2956 { 2957 closein_cdstream(bkpinfo); 2958 } 2959 else 2960 { 2961 closein_tape(bkpinfo); 2962 } 2963 } 2964 else 2965 { 2966 mvaddstr_and_log_it (g_currentY++, 0, "Restoring OS and data from CD "); 2967 mount_cdrom(bkpinfo); 2968 resA = restore_all_tarballs_from_CD(bkpinfo, filelist); 2969 resB = restore_all_biggiefiles_from_CD(bkpinfo, filelist); 2970 } 2971 chdir(cwd); 2972 if ( resA + resB ) 2973 { 2974 log_to_screen("Errors occurred while data was being restored."); 2975 } 2976 if ( length_of_file("/etc/raidtab") > 0 ) 2977 { 2978 log_msg(2, "Copying local raidtab to restored filesystem"); 2979 run_program_and_log_output("cp -f /etc/raidtab " MNT_RESTORING "/etc/raidtab", FALSE); 2980 } 2981 kill_petris(); 2982 log_msg(2, "restore_everything() --- leaving"); 2983 paranoid_free(cwd); 2984 paranoid_free(newpath); 2985 paranoid_free(tmp); 2986 return(resA+resB); 2950 char *cwd; 2951 char *newpath; 2952 char *tmp; 2953 assert(bkpinfo != NULL); 2954 2955 malloc_string(cwd); 2956 malloc_string(newpath); 2957 malloc_string(tmp); 2958 log_msg(2, "restore_everything() --- starting"); 2959 g_current_media_number = 1; 2960 getcwd(cwd, MAX_STR_LEN - 1); 2961 sprintf(tmp, "mkdir -p %s", bkpinfo->restore_path); 2962 run_program_and_log_output(tmp, FALSE); 2963 log_msg(1, "Changing dir to %s", bkpinfo->restore_path); 2964 chdir(bkpinfo->restore_path); 2965 getcwd(newpath, MAX_STR_LEN - 1); 2966 log_msg(1, "path is now %s", newpath); 2967 log_msg(1, "restoring everything"); 2968 if (!find_home_of_exe("petris") && !g_text_mode) { 2969 newtDrawRootText(0, g_noof_rows - 2, 2970 "Press ALT-<left cursor> twice to play Petris :-) "); 2971 newtRefresh(); 2972 } 2973 mvaddstr_and_log_it(g_currentY, 0, "Preparing to read your archives"); 2974 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 2975 mount_cdrom(bkpinfo); 2976 mvaddstr_and_log_it(g_currentY++, 0, 2977 "Restoring OS and data from streaming media"); 2978 if (bkpinfo->backup_media_type == cdstream) { 2979 openin_cdstream(bkpinfo); 2980 } else { 2981 assert_string_is_neither_NULL_nor_zerolength(bkpinfo-> 2982 media_device); 2983 openin_tape(bkpinfo); 2984 } 2985 resA = restore_all_tarballs_from_stream(bkpinfo, filelist); 2986 resB = restore_all_biggiefiles_from_stream(bkpinfo, filelist); 2987 if (bkpinfo->backup_media_type == cdstream) { 2988 closein_cdstream(bkpinfo); 2989 } else { 2990 closein_tape(bkpinfo); 2991 } 2992 } else { 2993 mvaddstr_and_log_it(g_currentY++, 0, 2994 "Restoring OS and data from CD "); 2995 mount_cdrom(bkpinfo); 2996 resA = restore_all_tarballs_from_CD(bkpinfo, filelist); 2997 resB = restore_all_biggiefiles_from_CD(bkpinfo, filelist); 2998 } 2999 chdir(cwd); 3000 if (resA + resB) { 3001 log_to_screen("Errors occurred while data was being restored."); 3002 } 3003 if (length_of_file("/etc/raidtab") > 0) { 3004 log_msg(2, "Copying local raidtab to restored filesystem"); 3005 run_program_and_log_output("cp -f /etc/raidtab " MNT_RESTORING 3006 "/etc/raidtab", FALSE); 3007 } 3008 kill_petris(); 3009 log_msg(2, "restore_everything() --- leaving"); 3010 paranoid_free(cwd); 3011 paranoid_free(newpath); 3012 paranoid_free(tmp); 3013 return (resA + resB); 2987 3014 } 2988 3015 … … 2997 3024 */ 2998 3025 int 2999 restore_live_from_monitas_server(struct s_bkpinfo *bkpinfo, 3000 char *monitas_device,3001 char *restore_this_directory,3002 char *restore_here)3003 3026 restore_live_from_monitas_server(struct s_bkpinfo *bkpinfo, 3027 char *monitas_device, 3028 char *restore_this_directory, 3029 char *restore_here) 3030 /* NB: bkpinfo hasn't been populated yet, except for ->tmp which is "/tmp" */ 3004 3031 { 3005 3006 3007 3008 3009 3010 3032 FILE *fout; 3033 int retval = 0; 3034 int i; 3035 int j; 3036 struct mountlist_itself the_mountlist; 3037 static struct raidlist_itself the_raidlist; 3011 3038 /** malloc **/ 3012 char tmp[ MAX_STR_LEN + 1 ]; 3013 char command[ MAX_STR_LEN + 1 ]; 3014 char datablock[ 256 * 1024 ]; 3015 char datadisks_fname[ MAX_STR_LEN + 1 ]; 3016 long k; 3017 long length; 3018 long long llt; 3019 struct s_node *filelist = NULL; 3020 assert(bkpinfo!=NULL); 3021 assert_string_is_neither_NULL_nor_zerolength(monitas_device); 3022 assert(restore_this_directory != NULL); 3023 assert(restore_here != NULL); 3024 3025 sprintf(tmp, "restore_here = '%s'", restore_here); 3026 3027 log_msg(2, tmp); 3028 3029 log_msg(2, "restore_live_from_monitas_server() - starting"); 3030 unlink("/tmp/mountlist.txt"); unlink("/tmp/filelist.full"); 3031 unlink("/tmp/biggielist.txt"); 3032 if ( restore_here[0] == '\0' ) 3033 { 3034 strcpy(bkpinfo->restore_path, MNT_RESTORING); 3035 } 3036 else 3037 { 3038 strcpy(bkpinfo->restore_path, restore_here); 3039 } 3040 log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI"); 3041 sprintf(tmp, "FYI - data will be restored to %s", bkpinfo->restore_path); 3042 log_msg(3, tmp); 3043 log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI"); 3044 sprintf(datadisks_fname, "/tmp/mondorestore.datadisks.%d", (int)(random()%32768)); 3045 chdir(bkpinfo->tmpdir); 3046 3047 sprintf(command, "cat %s", monitas_device); 3048 g_tape_stream=popen(command, "r"); // for compatibility with openin_tape() 3049 if (!(fout = fopen(datadisks_fname, "w"))) { log_OS_error(datadisks_fname); return(1); } 3050 for (i = 0; i < 32; i++) 3051 { 3052 for (j = 0; j < 4; j++) 3053 { 3054 for( length = k = 0; length < 256 * 1024; length += k) 3055 { 3056 k = fread( datablock + length, 1, 256 * 1024 - length, g_tape_stream); 3057 } 3058 fwrite (datablock, 1, length, fout); 3059 g_tape_posK += length; 3060 } 3061 } 3062 paranoid_fclose(fout); 3063 sprintf( command, 3064 "tar -zxvf %s tmp/mondo-restore.cfg tmp/mountlist.txt tmp/filelist.full tmp/biggielist.txt", 3065 datadisks_fname); 3066 run_program_and_log_output(command, 4); 3067 read_header_block_from_stream (&llt, tmp, &i); 3068 read_header_block_from_stream (&llt, tmp, &i); 3069 3070 unlink(datadisks_fname); 3071 read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo); 3072 retval = load_mountlist( &the_mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo strcpy(bkpinfo->media_device, monitas_device); 3073 3074 3075 load_raidtab_into_raidlist(&the_raidlist, RAIDTAB_FNAME ); 3076 iamhere("FIXME"); 3077 fatal_error("This will fail"); 3078 sprintf( command, 3079 "cat %s | grep -x \"%s.*\" > %s", 3080 g_filelist_full, 3081 restore_this_directory, 3082 g_filelist_full); 3083 if (system(command)) 3084 { 3085 retval++; 3086 log_to_screen("Error(s) occurred while processing filelist and wildcard"); 3087 } 3088 iamhere("FIXME"); 3089 fatal_error("This will fail"); 3090 sprintf(command, 3091 "cat %s | grep -x \"%s.*\" > %s", 3092 g_biggielist_txt, 3093 restore_this_directory, 3094 g_biggielist_txt); 3095 if (system(command)) 3096 { 3097 log_msg(1, "Error(s) occurred while processing biggielist and wildcard"); 3098 } 3099 sprintf(command, "touch %s", g_biggielist_txt); 3100 run_program_and_log_output(command, FALSE); 3039 char tmp[MAX_STR_LEN + 1]; 3040 char command[MAX_STR_LEN + 1]; 3041 char datablock[256 * 1024]; 3042 char datadisks_fname[MAX_STR_LEN + 1]; 3043 long k; 3044 long length; 3045 long long llt; 3046 struct s_node *filelist = NULL; 3047 assert(bkpinfo != NULL); 3048 assert_string_is_neither_NULL_nor_zerolength(monitas_device); 3049 assert(restore_this_directory != NULL); 3050 assert(restore_here != NULL); 3051 3052 sprintf(tmp, "restore_here = '%s'", restore_here); 3053 3054 log_msg(2, tmp); 3055 3056 log_msg(2, "restore_live_from_monitas_server() - starting"); 3057 unlink("/tmp/mountlist.txt"); 3058 unlink("/tmp/filelist.full"); 3059 unlink("/tmp/biggielist.txt"); 3060 if (restore_here[0] == '\0') { 3061 strcpy(bkpinfo->restore_path, MNT_RESTORING); 3062 } else { 3063 strcpy(bkpinfo->restore_path, restore_here); 3064 } 3065 log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI"); 3066 sprintf(tmp, "FYI - data will be restored to %s", 3067 bkpinfo->restore_path); 3068 log_msg(3, tmp); 3069 log_msg(3, "FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI FYI"); 3070 sprintf(datadisks_fname, "/tmp/mondorestore.datadisks.%d", 3071 (int) (random() % 32768)); 3072 chdir(bkpinfo->tmpdir); 3073 3074 sprintf(command, "cat %s", monitas_device); 3075 g_tape_stream = popen(command, "r"); // for compatibility with openin_tape() 3076 if (!(fout = fopen(datadisks_fname, "w"))) { 3077 log_OS_error(datadisks_fname); 3078 return (1); 3079 } 3080 for (i = 0; i < 32; i++) { 3081 for (j = 0; j < 4; j++) { 3082 for (length = k = 0; length < 256 * 1024; length += k) { 3083 k = fread(datablock + length, 1, 256 * 1024 - length, 3084 g_tape_stream); 3085 } 3086 fwrite(datablock, 1, length, fout); 3087 g_tape_posK += length; 3088 } 3089 } 3090 paranoid_fclose(fout); 3091 sprintf(command, 3092 "tar -zxvf %s tmp/mondo-restore.cfg tmp/mountlist.txt tmp/filelist.full tmp/biggielist.txt", 3093 datadisks_fname); 3094 run_program_and_log_output(command, 4); 3095 read_header_block_from_stream(&llt, tmp, &i); 3096 read_header_block_from_stream(&llt, tmp, &i); 3097 3098 unlink(datadisks_fname); 3099 read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo); 3100 retval = load_mountlist(&the_mountlist, g_mountlist_fname); // in case read_cfg_file_into_bkpinfo strcpy(bkpinfo->media_device, monitas_device); 3101 3102 3103 load_raidtab_into_raidlist(&the_raidlist, RAIDTAB_FNAME); 3104 iamhere("FIXME"); 3105 fatal_error("This will fail"); 3106 sprintf(command, 3107 "cat %s | grep -x \"%s.*\" > %s", 3108 g_filelist_full, restore_this_directory, g_filelist_full); 3109 if (system(command)) { 3110 retval++; 3111 log_to_screen 3112 ("Error(s) occurred while processing filelist and wildcard"); 3113 } 3114 iamhere("FIXME"); 3115 fatal_error("This will fail"); 3116 sprintf(command, 3117 "cat %s | grep -x \"%s.*\" > %s", 3118 g_biggielist_txt, restore_this_directory, g_biggielist_txt); 3119 if (system(command)) { 3120 log_msg(1, 3121 "Error(s) occurred while processing biggielist and wildcard"); 3122 } 3123 sprintf(command, "touch %s", g_biggielist_txt); 3124 run_program_and_log_output(command, FALSE); 3101 3125 // filelist = load_filelist(g_filelist_restthese); // FIXME --- this probably doesn't work because it doesn't include the biggiefiles 3102 3103 3104 3105 return(retval);3126 retval += restore_everything(bkpinfo, filelist); 3127 free_filelist(filelist); 3128 log_msg(2, "--------End of restore_live_from_monitas_server--------"); 3129 return (retval); 3106 3130 } 3131 3107 3132 /************************************************************************** 3108 3133 *END_RESTORE_LIVE_FROM_MONITAS_SERVER * … … 3112 3137 3113 3138 3114 extern void wait_until_software_raids_are_prepped(char *, int);3139 extern void wait_until_software_raids_are_prepped(char *, int); 3115 3140 3116 3141 … … 3123 3148 void welcome_to_mondorestore() 3124 3149 { 3125 log_msg(0, "-------------- Mondo Restore v%s -------------", VERSION); 3126 log_msg(0, "DON'T PANIC! Mondorestore logs almost everything, so please " ); 3127 log_msg(0, "don't break out in a cold sweat just because you see a few " ); 3128 log_msg(0, "error messages in the log. Read them; analyze them; see if " ); 3129 log_msg(0, "they are significant; above all, verify your backups! Please" ); 3130 log_msg(0, "attach a compressed copy of this log to any e-mail you send " ); 3131 log_msg(0, "to the Mondo mailing list when you are seeking technical " ); 3132 log_msg(0, "support. Without it, we can't help you. - Hugo" ); 3133 log_msg(0, "------------------------------------------------------------" ); 3134 log_msg(0, "BTW, despite (or perhaps because of) the wealth of messages," ); 3135 log_msg(0, "some users are inclined to stop reading this log. If Mondo " ); 3136 log_msg(0, "stopped for some reason, chances are it's detailed here. " ); 3137 log_msg(0, "More than likely there's a message at the very end of this " ); 3138 log_msg(0, "log that will tell you what is wrong. Please read it! " ); 3139 log_msg(0, "------------------------------------------------------------"); 3150 log_msg(0, "-------------- Mondo Restore v%s -------------", VERSION); 3151 log_msg(0, 3152 "DON'T PANIC! Mondorestore logs almost everything, so please "); 3153 log_msg(0, 3154 "don't break out in a cold sweat just because you see a few "); 3155 log_msg(0, 3156 "error messages in the log. Read them; analyze them; see if "); 3157 log_msg(0, 3158 "they are significant; above all, verify your backups! Please"); 3159 log_msg(0, 3160 "attach a compressed copy of this log to any e-mail you send "); 3161 log_msg(0, 3162 "to the Mondo mailing list when you are seeking technical "); 3163 log_msg(0, 3164 "support. Without it, we can't help you. - Hugo"); 3165 log_msg(0, 3166 "------------------------------------------------------------"); 3167 log_msg(0, 3168 "BTW, despite (or perhaps because of) the wealth of messages,"); 3169 log_msg(0, 3170 "some users are inclined to stop reading this log. If Mondo "); 3171 log_msg(0, 3172 "stopped for some reason, chances are it's detailed here. "); 3173 log_msg(0, 3174 "More than likely there's a message at the very end of this "); 3175 log_msg(0, 3176 "log that will tell you what is wrong. Please read it! "); 3177 log_msg(0, 3178 "------------------------------------------------------------"); 3140 3179 } 3141 3180 … … 3146 3185 * What did you think it did, anyway? :-) 3147 3186 */ 3148 int 3149 main(int argc, char*argv[]) 3187 int main(int argc, char *argv[]) 3150 3188 { 3151 FILE*fin;3152 FILE*fout;3153 3154 3189 FILE *fin; 3190 FILE *fout; 3191 int retval = 0; 3192 int res; 3155 3193 // int c; 3156 3194 char *tmp; 3157 3195 3158 3196 #ifndef VERSION … … 3160 3198 #endif 3161 3199 3162 struct mountlist_itself*mountlist;3163 struct raidlist_itself*raidlist;3164 struct s_bkpinfo*bkpinfo;3165 3166 3200 struct mountlist_itself *mountlist; 3201 struct raidlist_itself *raidlist; 3202 struct s_bkpinfo *bkpinfo; 3203 struct s_node *filelist; 3204 char *a, *b; 3167 3205 3168 3206 /************************************************************************** … … 3171 3209 * * 3172 3210 **************************************************************************/ 3173 if (getuid () != 0) 3174 { 3175 fprintf (stderr, "Please run as root.\r\n"); 3176 exit (127); 3177 } 3178 3179 g_loglevel = DEFAULT_MR_LOGLEVEL; 3180 malloc_string(tmp); 3181 3211 if (getuid() != 0) { 3212 fprintf(stderr, "Please run as root.\r\n"); 3213 exit(127); 3214 } 3215 3216 g_loglevel = DEFAULT_MR_LOGLEVEL; 3217 malloc_string(tmp); 3218 3182 3219 /* Configure global variables */ 3183 3220 #ifdef __FreeBSD__ 3184 if (strstr(call_program_and_get_last_line_of_output("cat /tmp/cmdline"), "textonly")) 3221 if (strstr 3222 (call_program_and_get_last_line_of_output("cat /tmp/cmdline"), 3223 "textonly")) 3185 3224 #else 3186 if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "textonly")) 3225 if (strstr 3226 (call_program_and_get_last_line_of_output("cat /proc/cmdline"), 3227 "textonly")) 3187 3228 #endif 3188 { g_text_mode = TRUE; log_msg(1, "TEXTONLY MODE"); } 3189 else 3190 { g_text_mode = FALSE; } // newt :-) 3191 if ( ! ( bkpinfo = g_bkpinfo_DONTUSETHIS = malloc( sizeof(struct s_bkpinfo)))) 3192 { fatal_error( "Cannot malloc bkpinfo" ); } 3193 if ( ! ( mountlist = malloc (sizeof(struct mountlist_itself)))) 3194 { fatal_error ("Cannot malloc mountlist" ); } 3195 if ( ! ( raidlist = malloc (sizeof(struct raidlist_itself)))) 3196 { fatal_error ("Cannot malloc raidlist" ); } 3197 3198 malloc_libmondo_global_strings(); 3199 3200 strcpy( g_mondo_home, call_program_and_get_last_line_of_output("which mondorestore") ); 3201 sprintf(g_tmpfs_mountpt, "/tmp/tmpfs"); 3202 make_hole_for_dir(g_tmpfs_mountpt); 3203 g_current_media_number = 1; // precaution 3204 3205 run_program_and_log_output ("mkdir -p " MNT_CDROM, FALSE); 3206 run_program_and_log_output ("mkdir -p /mnt/floppy", FALSE); 3207 3208 malloc_string(tmp); 3209 malloc_string(a); 3210 malloc_string(b); 3211 setup_MR_global_filenames( bkpinfo ); // malloc() and set globals, using bkpinfo->tmpdir etc. 3212 reset_bkpinfo( bkpinfo ); 3213 bkpinfo->backup_media_type = none; // in case boot disk was made for one backup type but user wants to restore from another backup type 3214 bkpinfo->restore_data = TRUE; // Well, yeah :-) 3215 if (am_I_in_disaster_recovery_mode()) 3216 { run_program_and_log_output("mount / -o remount,rw",2); } // for b0rken distros 3217 g_main_pid = getpid(); 3218 srandom( (int)(time(NULL)) ); 3219 register_pid( getpid(), "mondo" ); 3220 set_signals(TRUE); 3221 g_kernel_version = get_kernel_version(); 3222 3223 log_msg(1, "FYI - g_mountlist_fname = %s", g_mountlist_fname); 3224 if (strlen(g_mountlist_fname) < 3) 3225 { fatal_error("Serious error in malloc()'ing. Could be a bug in your glibc."); } 3226 mkdir(MNT_CDROM, 0x770); 3227 3229 { 3230 g_text_mode = TRUE; 3231 log_msg(1, "TEXTONLY MODE"); 3232 } else { 3233 g_text_mode = FALSE; 3234 } // newt :-) 3235 if (! 3236 (bkpinfo = g_bkpinfo_DONTUSETHIS = 3237 malloc(sizeof(struct s_bkpinfo)))) { 3238 fatal_error("Cannot malloc bkpinfo"); 3239 } 3240 if (!(mountlist = malloc(sizeof(struct mountlist_itself)))) { 3241 fatal_error("Cannot malloc mountlist"); 3242 } 3243 if (!(raidlist = malloc(sizeof(struct raidlist_itself)))) { 3244 fatal_error("Cannot malloc raidlist"); 3245 } 3246 3247 malloc_libmondo_global_strings(); 3248 3249 strcpy(g_mondo_home, 3250 call_program_and_get_last_line_of_output("which mondorestore")); 3251 sprintf(g_tmpfs_mountpt, "/tmp/tmpfs"); 3252 make_hole_for_dir(g_tmpfs_mountpt); 3253 g_current_media_number = 1; // precaution 3254 3255 run_program_and_log_output("mkdir -p " MNT_CDROM, FALSE); 3256 run_program_and_log_output("mkdir -p /mnt/floppy", FALSE); 3257 3258 malloc_string(tmp); 3259 malloc_string(a); 3260 malloc_string(b); 3261 setup_MR_global_filenames(bkpinfo); // malloc() and set globals, using bkpinfo->tmpdir etc. 3262 reset_bkpinfo(bkpinfo); 3263 bkpinfo->backup_media_type = none; // in case boot disk was made for one backup type but user wants to restore from another backup type 3264 bkpinfo->restore_data = TRUE; // Well, yeah :-) 3265 if (am_I_in_disaster_recovery_mode()) { 3266 run_program_and_log_output("mount / -o remount,rw", 2); 3267 } // for b0rken distros 3268 g_main_pid = getpid(); 3269 srandom((int) (time(NULL))); 3270 register_pid(getpid(), "mondo"); 3271 set_signals(TRUE); 3272 g_kernel_version = get_kernel_version(); 3273 3274 log_msg(1, "FYI - g_mountlist_fname = %s", g_mountlist_fname); 3275 if (strlen(g_mountlist_fname) < 3) { 3276 fatal_error 3277 ("Serious error in malloc()'ing. Could be a bug in your glibc."); 3278 } 3279 mkdir(MNT_CDROM, 0x770); 3280 3228 3281 /* Backup original mountlist.txt */ 3229 sprintf(tmp, "%s.orig", g_mountlist_fname);3230 if (!does_file_exist(g_mountlist_fname)) 3231 { 3232 log_msg(2, "%ld: Warning - g_mountlist_fname (%s) does not exist yet", __LINE__, g_mountlist_fname); 3233 } 3234 else if ( !does_file_exist(tmp) ) 3235 { 3236 sprintf(tmp, "cp -f %s %s.orig", g_mountlist_fname,g_mountlist_fname);3237 3238 3282 sprintf(tmp, "%s.orig", g_mountlist_fname); 3283 if (!does_file_exist(g_mountlist_fname)) { 3284 log_msg(2, 3285 "%ld: Warning - g_mountlist_fname (%s) does not exist yet", 3286 __LINE__, g_mountlist_fname); 3287 } else if (!does_file_exist(tmp)) { 3288 sprintf(tmp, "cp -f %s %s.orig", g_mountlist_fname, 3289 g_mountlist_fname); 3290 run_program_and_log_output(tmp, FALSE); 3291 } 3239 3292 3240 3293 /* Init directories */ 3241 make_hole_for_dir(bkpinfo->tmpdir); 3242 sprintf( tmp, "mkdir -p %s", bkpinfo->tmpdir ); 3243 run_program_and_log_output( tmp, FALSE ); 3244 make_hole_for_dir( "/var/log"); 3245 make_hole_for_dir( "/tmp/tmpfs"); /* just in case... */ 3246 run_program_and_log_output( "umount "MNT_CDROM, FALSE ); 3247 run_program_and_log_output( "ln -sf /var/log/mondo-archive.log /tmp/mondo-restore.log", FALSE ); 3248 3249 run_program_and_log_output( "rm -Rf /tmp/tmpfs/mondo.tmp.*", FALSE); 3294 make_hole_for_dir(bkpinfo->tmpdir); 3295 sprintf(tmp, "mkdir -p %s", bkpinfo->tmpdir); 3296 run_program_and_log_output(tmp, FALSE); 3297 make_hole_for_dir("/var/log"); 3298 make_hole_for_dir("/tmp/tmpfs"); /* just in case... */ 3299 run_program_and_log_output("umount " MNT_CDROM, FALSE); 3300 run_program_and_log_output 3301 ("ln -sf /var/log/mondo-archive.log /tmp/mondo-restore.log", 3302 FALSE); 3303 3304 run_program_and_log_output("rm -Rf /tmp/tmpfs/mondo.tmp.*", FALSE); 3250 3305 3251 3306 /* Init GUI */ 3252 malloc_libmondo_global_strings(); 3253 setup_newt_stuff(); /* call newtInit and setup screen log */ 3254 welcome_to_mondorestore(); 3255 if ( bkpinfo->disaster_recovery ) 3256 { log_msg(1, "I am in disaster recovery mode" ); } 3257 else 3258 { log_msg(1, "I am in normal, live mode" ); } 3259 3260 iamhere("what time is it"); 3307 malloc_libmondo_global_strings(); 3308 setup_newt_stuff(); /* call newtInit and setup screen log */ 3309 welcome_to_mondorestore(); 3310 if (bkpinfo->disaster_recovery) { 3311 log_msg(1, "I am in disaster recovery mode"); 3312 } else { 3313 log_msg(1, "I am in normal, live mode"); 3314 } 3315 3316 iamhere("what time is it"); 3261 3317 3262 3318 /* Process command-line parameters */ 3263 if (argc == 2 && strcmp( argv[1], "--edit-mountlist" ) == 0 ) 3264 { 3319 if (argc == 2 && strcmp(argv[1], "--edit-mountlist") == 0) { 3265 3320 #ifdef __FreeBSD__ 3266 system("mv -f /tmp/raidconf.txt /etc/raidtab");3267 if (!does_file_exist("/etc/raidtab"))3268 system("vinum printconfig > /etc/raidtab");3321 system("mv -f /tmp/raidconf.txt /etc/raidtab"); 3322 if (!does_file_exist("/etc/raidtab")) 3323 system("vinum printconfig > /etc/raidtab"); 3269 3324 #endif 3270 load_raidtab_into_raidlist( raidlist, RAIDTAB_FNAME ); 3271 if (!does_file_exist(g_mountlist_fname)) { strcpy(g_mountlist_fname, "/tmp/mountlist.txt"); } 3272 res = let_user_edit_the_mountlist(bkpinfo, mountlist, raidlist); 3325 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME); 3326 if (!does_file_exist(g_mountlist_fname)) { 3327 strcpy(g_mountlist_fname, "/tmp/mountlist.txt"); 3328 } 3329 res = let_user_edit_the_mountlist(bkpinfo, mountlist, raidlist); 3273 3330 #ifdef __FreeBSD__ 3274 system("mv -f /etc/raidtab /tmp/raidconf.txt");3331 system("mv -f /etc/raidtab /tmp/raidconf.txt"); 3275 3332 #endif 3276 paranoid_MR_finish(res); 3277 } 3278 3279 g_loglevel = DEFAULT_MR_LOGLEVEL; 3280 if (argc == 3 && strcmp(argv[1], "--echo-to-screen") == 0) 3281 { 3282 fout = fopen("/tmp/out.txt", "w"); 3283 fput_string_one_char_at_a_time(stderr, argv[2]); 3284 finish(0); 3285 } 3286 3287 if (argc == 3 && strcmp( argv[1], "--gendf" ) == 0 ) 3288 { 3289 make_grub_install_scriptlet(argv[2]); 3290 finish(0); 3291 } 3292 3293 if (argc >= 2 && strcmp(argv[1], "--pih" ) == 0 ) 3294 { 3295 if (system("mount | grep cdrom 2> /dev/null > /dev/null")) 3296 { system("mount "MNT_CDROM); } 3297 bkpinfo->compression_level = 1; 3298 g_current_media_number = 2; 3299 strcpy(bkpinfo->restore_path, "/tmp/TESTING"); 3300 bkpinfo->backup_media_type = dvd; 3301 open_progress_form( "Reassembling /dev/hda1", 3302 "Shark is a bit of a silly person." , 3303 "Please wait. This may take some time.", 3304 "", 3305 1999); 3306 system("rm -Rf /tmp/*pih*"); 3307 3308 restore_a_biggiefile_from_CD(bkpinfo, 42, NULL, tmp); 3309 } 3310 3311 if (argc == 5 && strcmp( argv[1], "--common") == 0 ) 3312 { 3313 g_loglevel = 6; 3314 filelist = load_filelist(argv[2]); 3315 if (!filelist) { fatal_error("Failed to load filelist"); } 3316 toggle_node_selection (filelist, FALSE); 3317 toggle_all_root_dirs_on (filelist); 3318 toggle_path_selection (filelist, "/usr/share", TRUE); 3333 paranoid_MR_finish(res); 3334 } 3335 3336 g_loglevel = DEFAULT_MR_LOGLEVEL; 3337 if (argc == 3 && strcmp(argv[1], "--echo-to-screen") == 0) { 3338 fout = fopen("/tmp/out.txt", "w"); 3339 fput_string_one_char_at_a_time(stderr, argv[2]); 3340 finish(0); 3341 } 3342 3343 if (argc == 3 && strcmp(argv[1], "--gendf") == 0) { 3344 make_grub_install_scriptlet(argv[2]); 3345 finish(0); 3346 } 3347 3348 if (argc >= 2 && strcmp(argv[1], "--pih") == 0) { 3349 if (system("mount | grep cdrom 2> /dev/null > /dev/null")) { 3350 system("mount " MNT_CDROM); 3351 } 3352 bkpinfo->compression_level = 1; 3353 g_current_media_number = 2; 3354 strcpy(bkpinfo->restore_path, "/tmp/TESTING"); 3355 bkpinfo->backup_media_type = dvd; 3356 open_progress_form("Reassembling /dev/hda1", 3357 "Shark is a bit of a silly person.", 3358 "Please wait. This may take some time.", 3359 "", 1999); 3360 system("rm -Rf /tmp/*pih*"); 3361 3362 restore_a_biggiefile_from_CD(bkpinfo, 42, NULL, tmp); 3363 } 3364 3365 if (argc == 5 && strcmp(argv[1], "--common") == 0) { 3366 g_loglevel = 6; 3367 filelist = load_filelist(argv[2]); 3368 if (!filelist) { 3369 fatal_error("Failed to load filelist"); 3370 } 3371 toggle_node_selection(filelist, FALSE); 3372 toggle_all_root_dirs_on(filelist); 3373 toggle_path_selection(filelist, "/usr/share", TRUE); 3319 3374 // show_filelist(filelist); 3320 3375 save_filelist(filelist, "/tmp/out.txt"); 3321 3376 // finish(0); 3322 3377 // toggle_path_selection (filelist, "/root/stuff", TRUE); 3323 strcpy(a, argv[3]); 3324 strcpy(b, argv[4]); 3325 3326 res = save_filelist_entries_in_common( 3327 a, filelist, b, FALSE); 3328 free_filelist(filelist); 3329 printf("res = %d", res); 3330 finish(0); 3331 } 3332 3333 if (argc == 3 && strcmp( argv[1], "--popuplist" ) == 0 ) 3334 { 3335 popup_changelist_from_file( argv[2] ); 3336 paranoid_MR_finish(0); 3337 } 3338 3339 if (argc == 5 && strcmp( argv[1], "--copy" ) == 0 ) 3340 { 3341 log_msg(1, "SCORE"); 3342 g_loglevel = 10; 3343 if (strstr(argv[2], "save")) 3344 { 3345 log_msg(1, "Saving from %s to %s", argv[3], argv[4]); 3346 fin = fopen(argv[3], "r"); 3347 fout = fopen(argv[4], "w"); 3348 copy_from_src_to_dest(fin, fout, 'w'); 3349 fclose(fin); 3350 fin = fopen(argv[3], "r"); 3351 copy_from_src_to_dest(fin, fout, 'w'); 3352 fclose(fout); 3353 fclose(fin); 3354 } 3355 else if (strstr(argv[2], "restore")) 3356 { 3357 fout = fopen(argv[3], "w"); 3358 fin = fopen(argv[4], "r"); 3359 copy_from_src_to_dest(fout, fin, 'r'); 3360 fclose(fin); 3361 fin = fopen(argv[4], "r"); 3362 copy_from_src_to_dest(fout, fin, 'r'); 3363 fclose(fout); 3364 fclose(fin); 3365 } 3366 else 3367 { fatal_error("Unknown additional param"); } 3368 finish(0); 3369 } 3370 3371 if (argc == 3 && strcmp(argv[1], "--mdstat") == 0) 3372 { 3373 wait_until_software_raids_are_prepped(argv[2], 100); 3374 finish(0); 3375 } 3376 3377 if (argc == 4 && strcmp(argv[1], "--mdconv") == 0) 3378 { 3379 finish(create_raidtab_from_mdstat(argv[2], argv[3])); 3380 } 3381 3382 3383 if ( argc == 2 && strcmp( argv[1],"--live-grub" ) == 0 ) 3384 { 3385 retval = run_grub( FALSE, "/dev/hda" ); 3386 if ( retval ) 3387 { 3388 log_to_screen("Failed to write Master Boot Record"); 3389 } 3390 paranoid_MR_finish(0); 3391 } 3392 if (argc == 3 && strcmp( argv[1], "--paa" ) == 0 ) 3393 { 3394 g_current_media_number = atoi(argv[2]); 3395 pause_and_ask_for_cdr(5, NULL); 3396 paranoid_MR_finish(0); 3397 } 3398 else if ( !bkpinfo->disaster_recovery ) 3399 { // live! 3400 if (argc!=1) 3401 { 3402 popup_and_OK("Live mode doesn't support command-line parameters yet."); 3403 paranoid_MR_finish(1); 3404 // return(1); 3405 } 3406 log_msg (1, "I am in normal, live mode."); 3407 log_msg (2, "FYI, MOUNTLIST_FNAME = %s", g_mountlist_fname); 3408 mount_boot_if_necessary(); /* for Gentoo users */ 3409 log_msg (2, "Still here."); 3410 if ( argc>1 && strcmp( argv[argc-1], "--live-from-cd" ) == 0 ) 3411 { g_restoring_live_from_cd = TRUE; } 3412 if ( argc == 5 && strcmp(argv[1], "--monitas-live" ) == 0 ) 3413 { 3414 retval = 3415 restore_live_from_monitas_server( bkpinfo, 3416 argv[2], 3417 argv[3], 3418 argv[4] ); 3419 } 3420 else 3421 { 3422 log_msg(2, "Calling restore_to_live_filesystem()"); 3423 retval = restore_to_live_filesystem( bkpinfo ); 3424 } 3425 log_msg(2, "Still here. Yay."); 3426 if (strlen(bkpinfo->tmpdir) > 0) 3427 { 3428 sprintf( tmp, "rm -Rf %s/*", bkpinfo->tmpdir ); 3429 run_program_and_log_output ( tmp, FALSE ); 3430 } 3431 unmount_boot_if_necessary(); /* for Gentoo users */ 3432 paranoid_MR_finish( retval ); 3433 } 3434 else 3435 { 3378 strcpy(a, argv[3]); 3379 strcpy(b, argv[4]); 3380 3381 res = save_filelist_entries_in_common(a, filelist, b, FALSE); 3382 free_filelist(filelist); 3383 printf("res = %d", res); 3384 finish(0); 3385 } 3386 3387 if (argc == 3 && strcmp(argv[1], "--popuplist") == 0) { 3388 popup_changelist_from_file(argv[2]); 3389 paranoid_MR_finish(0); 3390 } 3391 3392 if (argc == 5 && strcmp(argv[1], "--copy") == 0) { 3393 log_msg(1, "SCORE"); 3394 g_loglevel = 10; 3395 if (strstr(argv[2], "save")) { 3396 log_msg(1, "Saving from %s to %s", argv[3], argv[4]); 3397 fin = fopen(argv[3], "r"); 3398 fout = fopen(argv[4], "w"); 3399 copy_from_src_to_dest(fin, fout, 'w'); 3400 fclose(fin); 3401 fin = fopen(argv[3], "r"); 3402 copy_from_src_to_dest(fin, fout, 'w'); 3403 fclose(fout); 3404 fclose(fin); 3405 } else if (strstr(argv[2], "restore")) { 3406 fout = fopen(argv[3], "w"); 3407 fin = fopen(argv[4], "r"); 3408 copy_from_src_to_dest(fout, fin, 'r'); 3409 fclose(fin); 3410 fin = fopen(argv[4], "r"); 3411 copy_from_src_to_dest(fout, fin, 'r'); 3412 fclose(fout); 3413 fclose(fin); 3414 } else { 3415 fatal_error("Unknown additional param"); 3416 } 3417 finish(0); 3418 } 3419 3420 if (argc == 3 && strcmp(argv[1], "--mdstat") == 0) { 3421 wait_until_software_raids_are_prepped(argv[2], 100); 3422 finish(0); 3423 } 3424 3425 if (argc == 4 && strcmp(argv[1], "--mdconv") == 0) { 3426 finish(create_raidtab_from_mdstat(argv[2], argv[3])); 3427 } 3428 3429 3430 if (argc == 2 && strcmp(argv[1], "--live-grub") == 0) { 3431 retval = run_grub(FALSE, "/dev/hda"); 3432 if (retval) { 3433 log_to_screen("Failed to write Master Boot Record"); 3434 } 3435 paranoid_MR_finish(0); 3436 } 3437 if (argc == 3 && strcmp(argv[1], "--paa") == 0) { 3438 g_current_media_number = atoi(argv[2]); 3439 pause_and_ask_for_cdr(5, NULL); 3440 paranoid_MR_finish(0); 3441 } else if (!bkpinfo->disaster_recovery) { // live! 3442 if (argc != 1) { 3443 popup_and_OK 3444 ("Live mode doesn't support command-line parameters yet."); 3445 paranoid_MR_finish(1); 3446 // return(1); 3447 } 3448 log_msg(1, "I am in normal, live mode."); 3449 log_msg(2, "FYI, MOUNTLIST_FNAME = %s", g_mountlist_fname); 3450 mount_boot_if_necessary(); /* for Gentoo users */ 3451 log_msg(2, "Still here."); 3452 if (argc > 1 && strcmp(argv[argc - 1], "--live-from-cd") == 0) { 3453 g_restoring_live_from_cd = TRUE; 3454 } 3455 if (argc == 5 && strcmp(argv[1], "--monitas-live") == 0) { 3456 retval = 3457 restore_live_from_monitas_server(bkpinfo, 3458 argv[2], 3459 argv[3], argv[4]); 3460 } else { 3461 log_msg(2, "Calling restore_to_live_filesystem()"); 3462 retval = restore_to_live_filesystem(bkpinfo); 3463 } 3464 log_msg(2, "Still here. Yay."); 3465 if (strlen(bkpinfo->tmpdir) > 0) { 3466 sprintf(tmp, "rm -Rf %s/*", bkpinfo->tmpdir); 3467 run_program_and_log_output(tmp, FALSE); 3468 } 3469 unmount_boot_if_necessary(); /* for Gentoo users */ 3470 paranoid_MR_finish(retval); 3471 } else { 3436 3472 /* Disaster recovery mode (must be) */ 3437 log_msg(1, "I must be in disaster recovery mode."); 3438 log_msg(2, "FYI, MOUNTLIST_FNAME = %s ", g_mountlist_fname ); 3439 if (argc == 3 && strcmp(argv[1], "--monitas-memorex" ) == 0 ) 3440 { 3441 log_to_screen( "Uh, that hasn't been implemented yet." ); 3442 paranoid_MR_finish( 1 ); 3443 } 3444 3445 iamhere("About to call load_mountlist and load_raidtab"); 3446 strcpy( bkpinfo->restore_path, MNT_RESTORING ); 3447 read_cfg_file_into_bkpinfo( g_mondo_cfg_file, bkpinfo ); 3448 retval = load_mountlist( mountlist, g_mountlist_fname ); 3449 retval += load_raidtab_into_raidlist( raidlist, RAIDTAB_FNAME ); 3450 iamhere("Returned from calling load_mountlist and load_raidtab successfully"); 3451 3452 if (argc>1 && (strcmp( argv[1], "--compare" ) == 0 || strcmp( argv[1], "--nuke" ) == 0 )) 3453 { 3454 if (bkpinfo->backup_media_type == nfs && !is_this_device_mounted(bkpinfo->nfs_mount)) 3455 { 3456 log_msg(1, "Mounting nfs dir"); 3457 sprintf(bkpinfo->isodir, "/tmp/isodir"); 3458 run_program_and_log_output("mkdir -p /tmp/isodir", 5); 3459 sprintf(tmp, "mount %s -t nfs -o nolock /tmp/isodir", bkpinfo->nfs_mount); 3460 run_program_and_log_output(tmp, 1); 3461 } 3462 } 3463 3464 3465 if ( retval ) 3466 { 3467 log_to_screen( "Warning - load_raidtab_into_raidlist returned an error" ); 3468 } 3469 3470 3471 log_msg(1, "Send in the clowns."); 3472 3473 if (argc == 2 && strcmp(argv[1], "--partition-only") == 0) 3474 { 3475 log_msg(0, "Partitioning only."); 3476 load_raidtab_into_raidlist( raidlist, RAIDTAB_FNAME ); 3477 strcpy(g_mountlist_fname, "/tmp/mountlist.txt"); 3478 load_mountlist( mountlist, g_mountlist_fname ); 3479 res = partition_everything(mountlist); 3480 finish(res); 3481 } 3482 3483 if (argc == 2 && strcmp(argv[1], "--format-only") == 0) 3484 { 3485 log_msg(0, "Formatting only."); 3486 load_raidtab_into_raidlist( raidlist, RAIDTAB_FNAME ); 3487 strcpy(g_mountlist_fname, "/tmp/mountlist.txt"); 3488 load_mountlist( mountlist, g_mountlist_fname ); 3489 res = format_everything(mountlist, FALSE); 3490 finish(res); 3491 } 3492 3493 if (argc == 2 && strcmp(argv[1], "--stop-lvm-and-raid") == 0) 3494 { 3495 log_msg(0, "Stopping LVM and RAID"); 3496 load_raidtab_into_raidlist( raidlist, RAIDTAB_FNAME ); 3497 strcpy(g_mountlist_fname, "/tmp/mountlist.txt"); 3498 load_mountlist( mountlist, g_mountlist_fname ); 3499 res = do_my_funky_lvm_stuff(TRUE, FALSE); 3500 res += stop_all_raid_devices(mountlist); 3501 finish(res); 3502 } 3503 3504 if (argc == 2 && strcmp( argv[1], "--nuke" ) == 0 ) 3505 { 3506 iamhere("nuking"); 3507 retval += nuke_mode( bkpinfo, mountlist, raidlist); 3508 } 3509 else if (argc == 2 && strcmp( argv[1], "--interactive" ) == 0 ) 3510 { 3511 iamhere("catchall"); 3512 retval += catchall_mode( bkpinfo, mountlist,raidlist ); 3513 } 3514 else if (argc == 2 && strcmp( argv[1], "--compare" ) == 0 ) 3515 { 3516 iamhere("compare"); 3517 retval += compare_mode( bkpinfo, mountlist, raidlist ); 3518 } 3519 else if (argc == 2 && strcmp( argv[1], "--iso" ) == 0 ) 3520 { 3521 iamhere("iso"); 3522 retval = iso_mode( bkpinfo, mountlist, raidlist, FALSE ); 3523 } 3524 else if ( argc == 2 && strcmp( argv[1],"--mbr" ) == 0 ) 3525 { 3526 iamhere("mbr"); 3527 retval = mount_all_devices( mountlist, TRUE ); 3528 if ( !retval ) 3529 { 3530 retval += run_boot_loader( FALSE ); 3531 retval += unmount_all_devices( mountlist ); 3532 } 3533 if ( retval ) 3534 { 3535 log_to_screen("Failed to write Master Boot Record"); 3536 } 3537 } 3538 else if ( argc == 2 && strcmp( argv[1],"--isonuke") ==0 ) 3539 { 3540 iamhere("isonuke"); 3541 retval = iso_mode( bkpinfo, 3542 mountlist, 3543 raidlist, 3544 TRUE ); 3545 } 3546 else if ( argc != 1 ) 3547 { 3548 log_to_screen( "Invalid paremeters" ); 3549 paranoid_MR_finish( 1 ); 3550 } 3551 else 3552 { 3553 iamhere("catchall (no mode specified in command-line call"); 3554 retval += catchall_mode( bkpinfo, mountlist, raidlist); 3555 } 3556 } 3557 3558 /* clean up at the end */ 3559 if (retval) 3560 { 3561 if (does_file_exist("/tmp/changed.files")) 3562 { 3563 log_to_screen( "See /tmp/changed.files for list of files that have changed." ); 3564 } 3565 mvaddstr_and_log_it ( g_currentY++, 3566 0, 3567 "Run complete. Errors were reported. Please review the logfile." ); 3568 } 3569 else 3570 { 3571 if (IS_THIS_A_STREAMING_BACKUP ( bkpinfo->backup_media_type ) ) 3572 { 3573 mvaddstr_and_log_it( g_currentY++, 3574 0, 3575 "Run complete. Please remove floppy/CD/media and reboot." ); 3576 } 3577 else 3578 { 3579 run_program_and_log_output ( "sync", FALSE ); 3580 if ( is_this_device_mounted( MNT_CDROM ) ) 3581 { 3582 res = run_program_and_log_output( "umount "MNT_CDROM, FALSE ); 3583 } 3584 else 3585 { 3586 res = 0; 3587 } 3588 3589 if ( !bkpinfo->please_dont_eject) 3590 { 3591 res = eject_device("/dev/cdrom"); 3473 log_msg(1, "I must be in disaster recovery mode."); 3474 log_msg(2, "FYI, MOUNTLIST_FNAME = %s ", g_mountlist_fname); 3475 if (argc == 3 && strcmp(argv[1], "--monitas-memorex") == 0) { 3476 log_to_screen("Uh, that hasn't been implemented yet."); 3477 paranoid_MR_finish(1); 3478 } 3479 3480 iamhere("About to call load_mountlist and load_raidtab"); 3481 strcpy(bkpinfo->restore_path, MNT_RESTORING); 3482 read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo); 3483 retval = load_mountlist(mountlist, g_mountlist_fname); 3484 retval += load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME); 3485 iamhere 3486 ("Returned from calling load_mountlist and load_raidtab successfully"); 3487 3488 if (argc > 1 3489 && (strcmp(argv[1], "--compare") == 0 3490 || strcmp(argv[1], "--nuke") == 0)) { 3491 if (bkpinfo->backup_media_type == nfs 3492 && !is_this_device_mounted(bkpinfo->nfs_mount)) { 3493 log_msg(1, "Mounting nfs dir"); 3494 sprintf(bkpinfo->isodir, "/tmp/isodir"); 3495 run_program_and_log_output("mkdir -p /tmp/isodir", 5); 3496 sprintf(tmp, "mount %s -t nfs -o nolock /tmp/isodir", 3497 bkpinfo->nfs_mount); 3498 run_program_and_log_output(tmp, 1); 3499 } 3500 } 3501 3502 3503 if (retval) { 3504 log_to_screen 3505 ("Warning - load_raidtab_into_raidlist returned an error"); 3506 } 3507 3508 3509 log_msg(1, "Send in the clowns."); 3510 3511 if (argc == 2 && strcmp(argv[1], "--partition-only") == 0) { 3512 log_msg(0, "Partitioning only."); 3513 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME); 3514 strcpy(g_mountlist_fname, "/tmp/mountlist.txt"); 3515 load_mountlist(mountlist, g_mountlist_fname); 3516 res = partition_everything(mountlist); 3517 finish(res); 3518 } 3519 3520 if (argc == 2 && strcmp(argv[1], "--format-only") == 0) { 3521 log_msg(0, "Formatting only."); 3522 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME); 3523 strcpy(g_mountlist_fname, "/tmp/mountlist.txt"); 3524 load_mountlist(mountlist, g_mountlist_fname); 3525 res = format_everything(mountlist, FALSE); 3526 finish(res); 3527 } 3528 3529 if (argc == 2 && strcmp(argv[1], "--stop-lvm-and-raid") == 0) { 3530 log_msg(0, "Stopping LVM and RAID"); 3531 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME); 3532 strcpy(g_mountlist_fname, "/tmp/mountlist.txt"); 3533 load_mountlist(mountlist, g_mountlist_fname); 3534 res = do_my_funky_lvm_stuff(TRUE, FALSE); 3535 res += stop_all_raid_devices(mountlist); 3536 finish(res); 3537 } 3538 3539 if (argc == 2 && strcmp(argv[1], "--nuke") == 0) { 3540 iamhere("nuking"); 3541 retval += nuke_mode(bkpinfo, mountlist, raidlist); 3542 } else if (argc == 2 && strcmp(argv[1], "--interactive") == 0) { 3543 iamhere("catchall"); 3544 retval += catchall_mode(bkpinfo, mountlist, raidlist); 3545 } else if (argc == 2 && strcmp(argv[1], "--compare") == 0) { 3546 iamhere("compare"); 3547 retval += compare_mode(bkpinfo, mountlist, raidlist); 3548 } else if (argc == 2 && strcmp(argv[1], "--iso") == 0) { 3549 iamhere("iso"); 3550 retval = iso_mode(bkpinfo, mountlist, raidlist, FALSE); 3551 } else if (argc == 2 && strcmp(argv[1], "--mbr") == 0) { 3552 iamhere("mbr"); 3553 retval = mount_all_devices(mountlist, TRUE); 3554 if (!retval) { 3555 retval += run_boot_loader(FALSE); 3556 retval += unmount_all_devices(mountlist); 3557 } 3558 if (retval) { 3559 log_to_screen("Failed to write Master Boot Record"); 3560 } 3561 } else if (argc == 2 && strcmp(argv[1], "--isonuke") == 0) { 3562 iamhere("isonuke"); 3563 retval = iso_mode(bkpinfo, mountlist, raidlist, TRUE); 3564 } else if (argc != 1) { 3565 log_to_screen("Invalid paremeters"); 3566 paranoid_MR_finish(1); 3567 } else { 3568 iamhere("catchall (no mode specified in command-line call"); 3569 retval += catchall_mode(bkpinfo, mountlist, raidlist); 3570 } 3571 } 3572 3573 /* clean up at the end */ 3574 if (retval) { 3575 if (does_file_exist("/tmp/changed.files")) { 3576 log_to_screen 3577 ("See /tmp/changed.files for list of files that have changed."); 3578 } 3579 mvaddstr_and_log_it(g_currentY++, 3580 0, 3581 "Run complete. Errors were reported. Please review the logfile."); 3582 } else { 3583 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 3584 mvaddstr_and_log_it(g_currentY++, 3585 0, 3586 "Run complete. Please remove floppy/CD/media and reboot."); 3587 } else { 3588 run_program_and_log_output("sync", FALSE); 3589 if (is_this_device_mounted(MNT_CDROM)) { 3590 res = 3591 run_program_and_log_output("umount " MNT_CDROM, FALSE); 3592 } else { 3593 res = 0; 3594 } 3595 3596 if (!bkpinfo->please_dont_eject) { 3597 res = eject_device("/dev/cdrom"); 3592 3598 /* 3593 3599 if (res) … … 3596 3602 } 3597 3603 */ 3598 3599 mvaddstr_and_log_it(g_currentY++,3600 3601 "Run complete. Please remove media and reboot.");3602 }3603 3604 } 3605 mvaddstr_and_log_it(g_currentY++, 3606 0, 3607 "Run complete. Please remove media and reboot."); 3608 } 3609 } 3604 3610 3605 3611 // g_I_have_just_nuked is set true by nuke_mode() just before it returns 3606 if ( g_I_have_just_nuked || does_file_exist("/POST-NUKE-ANYWAY")) 3607 { 3608 if (!system("which post-nuke > /dev/null 2> /dev/null")) 3609 { 3610 log_msg(1, "post-nuke found; running..."); 3611 if (mount_all_devices(mountlist, TRUE)) 3612 { 3613 log_to_screen("Unable to re-mount partitions for post-nuke stuff"); 3614 } 3615 else 3616 { 3617 log_msg(1, "Re-mounted partitions for post-nuke stuff"); 3618 sprintf(tmp, "post-nuke %s %d", bkpinfo->restore_path, retval); 3619 if (!g_text_mode) { newtSuspend(); } 3620 log_msg(2, "Calling '%s'", tmp); 3621 if ((res=system(tmp))) { log_OS_error(tmp); } 3622 if (!g_text_mode) { newtResume(); } 3612 if (g_I_have_just_nuked || does_file_exist("/POST-NUKE-ANYWAY")) { 3613 if (!system("which post-nuke > /dev/null 2> /dev/null")) { 3614 log_msg(1, "post-nuke found; running..."); 3615 if (mount_all_devices(mountlist, TRUE)) { 3616 log_to_screen 3617 ("Unable to re-mount partitions for post-nuke stuff"); 3618 } else { 3619 log_msg(1, "Re-mounted partitions for post-nuke stuff"); 3620 sprintf(tmp, "post-nuke %s %d", bkpinfo->restore_path, 3621 retval); 3622 if (!g_text_mode) { 3623 newtSuspend(); 3624 } 3625 log_msg(2, "Calling '%s'", tmp); 3626 if ((res = system(tmp))) { 3627 log_OS_error(tmp); 3628 } 3629 if (!g_text_mode) { 3630 newtResume(); 3631 } 3623 3632 // newtCls(); 3624 3625 3626 3627 3628 3629 3633 log_msg(1, "post-nuke returned w/ res=%d", res); 3634 } 3635 unmount_all_devices(mountlist); 3636 log_msg(1, "I've finished post-nuking."); 3637 } 3638 } 3630 3639 /* 3631 3640 log_to_screen("If you are REALLY in a hurry, hit Ctrl-Alt-Del now."); … … 3633 3642 wait_until_software_raids_are_prepped("/proc/mdstat", 100); 3634 3643 log_to_screen("Thank you."); 3635 */ 3636 unlink( "/tmp/mondo-run-prog.tmp" ); 3637 set_signals( FALSE ); 3638 sprintf( tmp, "rm -Rf %s", bkpinfo->tmpdir ); 3639 run_program_and_log_output ( tmp, FALSE ); 3640 log_to_screen( "Restore log copied to /tmp/mondo-restore.log on your hard disk" ); 3641 sprintf( tmp, "Mondo-restore is exiting (retval=%d) ",retval); 3642 log_to_screen( tmp ); 3643 sprintf(tmp, "umount %s", bkpinfo->isodir); 3644 run_program_and_log_output(tmp, 5); 3645 paranoid_free(mountlist); 3646 paranoid_free(raidlist); 3647 if (am_I_in_disaster_recovery_mode()) 3648 { run_program_and_log_output("mount / -o remount,rw",2); } // for b0rken distros 3649 paranoid_MR_finish( retval ); // frees global stuff plus bkpinfo 3650 free_libmondo_global_strings(); // it's fine to have this here :) really :) 3651 paranoid_free(a); 3652 paranoid_free(b); 3653 paranoid_free(tmp); 3654 3655 unlink("/tmp/filelist.full"); 3656 unlink("/tmp/filelist.full.gz"); 3657 3658 exit( retval ); 3644 */ 3645 unlink("/tmp/mondo-run-prog.tmp"); 3646 set_signals(FALSE); 3647 sprintf(tmp, "rm -Rf %s", bkpinfo->tmpdir); 3648 run_program_and_log_output(tmp, FALSE); 3649 log_to_screen 3650 ("Restore log copied to /tmp/mondo-restore.log on your hard disk"); 3651 sprintf(tmp, 3652 "Mondo-restore is exiting (retval=%d) ", 3653 retval); 3654 log_to_screen(tmp); 3655 sprintf(tmp, "umount %s", bkpinfo->isodir); 3656 run_program_and_log_output(tmp, 5); 3657 paranoid_free(mountlist); 3658 paranoid_free(raidlist); 3659 if (am_I_in_disaster_recovery_mode()) { 3660 run_program_and_log_output("mount / -o remount,rw", 2); 3661 } // for b0rken distros 3662 paranoid_MR_finish(retval); // frees global stuff plus bkpinfo 3663 free_libmondo_global_strings(); // it's fine to have this here :) really :) 3664 paranoid_free(a); 3665 paranoid_free(b); 3666 paranoid_free(tmp); 3667 3668 unlink("/tmp/filelist.full"); 3669 unlink("/tmp/filelist.full.gz"); 3670 3671 exit(retval); 3659 3672 } 3660 3673 … … 3670 3683 *END_MONDO-RESTORE.C * 3671 3684 **************************************************************************/ 3672 -
trunk/mondo/mondo/mondorestore/mondo-restore.h
r30 r59 1 1 /* mondo-restore.h 2 * $Id : mondo-restore.h,v 1.3 2004/06/21 20:20:37 hugo Exp$2 * $Id$ 3 3 */ 4 4 … … 7 7 **************************************************************************/ 8 8 9 void ask_about_these_imagedevs(char*,char*); 10 int catchall_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself*); 11 void find_pathname_of_executable_preferably_in_RESTORING(char *, char*, char*); 12 int interactive_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself *); 13 int nuke_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself *); 14 int compare_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself *); 15 int iso_mode(struct s_bkpinfo *bkpinfo, 16 struct mountlist_itself *mountlist, 17 struct raidlist_itself *raidlist, 18 bool nuke_me_please); 19 int restore_mode(struct s_bkpinfo *, struct mountlist_itself *, struct raidlist_itself *); 20 int restore_a_biggiefile_from_CD(struct s_bkpinfo *, long, struct s_node*, char*); 21 int restore_a_biggiefile_from_stream(struct s_bkpinfo*, char*, long , char*, long long, struct s_node*, int, char*); 22 int restore_a_tarball_from_CD(char *, long, struct s_node*); 23 int restore_a_tarball_from_stream(struct s_bkpinfo*, char *, long, struct s_node*, long long, char*, char*); 24 int restore_all_biggiefiles_from_CD(struct s_bkpinfo*, struct s_node*); 25 int restore_all_biggiefiles_from_stream(struct s_bkpinfo*, struct s_node*); 26 int restore_all_tarballs_from_CD(struct s_bkpinfo*, struct s_node*); 27 int restore_all_tarballs_from_stream(struct s_bkpinfo*, struct s_node*); 28 int restore_everything(struct s_bkpinfo*,struct s_node*); 29 int restore_live_from_monitas_server(struct s_bkpinfo *, char*, char*, char*); 30 int restore_to_live_filesystem(struct s_bkpinfo*); 31 void swap_mountlist_entries(struct mountlist_itself*,int,int); 32 void sort_mountlist_by_mountpoint(struct mountlist_itself*,bool); 33 void sort_mountlist_by_device(struct mountlist_itself*); 34 int what_number_cd_is_this(struct s_bkpinfo*); 9 void ask_about_these_imagedevs(char *, char *); 10 int catchall_mode(struct s_bkpinfo *, struct mountlist_itself *, 11 struct raidlist_itself *); 12 void find_pathname_of_executable_preferably_in_RESTORING(char *, char *, 13 char *); 14 int interactive_mode(struct s_bkpinfo *, struct mountlist_itself *, 15 struct raidlist_itself *); 16 int nuke_mode(struct s_bkpinfo *, struct mountlist_itself *, 17 struct raidlist_itself *); 18 int compare_mode(struct s_bkpinfo *, struct mountlist_itself *, 19 struct raidlist_itself *); 20 int iso_mode(struct s_bkpinfo *bkpinfo, struct mountlist_itself *mountlist, 21 struct raidlist_itself *raidlist, bool nuke_me_please); 22 int restore_mode(struct s_bkpinfo *, struct mountlist_itself *, 23 struct raidlist_itself *); 24 int restore_a_biggiefile_from_CD(struct s_bkpinfo *, long, struct s_node *, 25 char *); 26 int restore_a_biggiefile_from_stream(struct s_bkpinfo *, char *, long, 27 char *, long long, struct s_node *, 28 int, char *); 29 int restore_a_tarball_from_CD(char *, long, struct s_node *); 30 int restore_a_tarball_from_stream(struct s_bkpinfo *, char *, long, 31 struct s_node *, long long, char *, 32 char *); 33 int restore_all_biggiefiles_from_CD(struct s_bkpinfo *, struct s_node *); 34 int restore_all_biggiefiles_from_stream(struct s_bkpinfo *, 35 struct s_node *); 36 int restore_all_tarballs_from_CD(struct s_bkpinfo *, struct s_node *); 37 int restore_all_tarballs_from_stream(struct s_bkpinfo *, struct s_node *); 38 int restore_everything(struct s_bkpinfo *, struct s_node *); 39 int restore_live_from_monitas_server(struct s_bkpinfo *, char *, char *, 40 char *); 41 int restore_to_live_filesystem(struct s_bkpinfo *); 42 void swap_mountlist_entries(struct mountlist_itself *, int, int); 43 void sort_mountlist_by_mountpoint(struct mountlist_itself *, bool); 44 void sort_mountlist_by_device(struct mountlist_itself *); 45 int what_number_cd_is_this(struct s_bkpinfo *); -
trunk/mondo/mondo/mondorestore/mondo-rstr-compare-EXT.h
r30 r59 2 2 3 3 4 extern int compare_to_CD(struct s_bkpinfo *);5 extern int compare_to_cdstream(struct s_bkpinfo *);6 extern int compare_to_tape(struct s_bkpinfo *);7 extern int compare_mode( struct s_bkpinfo *bkpinfo,8 struct mountlist_itself *mountlist,9 4 extern int compare_to_CD(struct s_bkpinfo *); 5 extern int compare_to_cdstream(struct s_bkpinfo *); 6 extern int compare_to_tape(struct s_bkpinfo *); 7 extern int compare_mode(struct s_bkpinfo *bkpinfo, 8 struct mountlist_itself *mountlist, 9 struct raidlist_itself *raidlist); -
trunk/mondo/mondo/mondorestore/mondo-rstr-compare.c
r30 r59 5 5 copyright : (C) 2000 by Hugo Rabson 6 6 email : Hugo Rabson <hugorabson@msn.com> 7 cvsid : $Id : mondo-rstr-compare.c,v 1.1 2004/06/10 15:29:13 hugo Exp$7 cvsid : $Id$ 8 8 ***************************************************************************/ 9 9 … … 65 65 #include "mondo-rstr-tools-EXT.h" 66 66 67 //static char cvsid[] = "$Id : mondo-rstr-compare.c,v 1.1 2004/06/10 15:29:13 hugo Exp$";68 69 void popup_changelist_from_file(char *);67 //static char cvsid[] = "$Id$"; 68 69 void popup_changelist_from_file(char *); 70 70 71 71 … … 80 80 * @note This function uses an MD5 checksum. 81 81 */ 82 int 83 compare_a_biggiefile(struct s_bkpinfo *bkpinfo, long bigfileno) 82 int compare_a_biggiefile(struct s_bkpinfo *bkpinfo, long bigfileno) 84 83 { 85 84 86 87 85 FILE *fin; 86 FILE *fout; 88 87 89 88 /** needs malloc *******/ 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 89 char *checksum_ptr; 90 char *original_cksum_ptr; 91 char *bigfile_fname_ptr; 92 char *tmp_ptr; 93 char *command_ptr; 94 95 char *checksum, *original_cksum, *bigfile_fname, *tmp, *command; 96 97 char *p; 98 int i; 99 int retval = 0; 100 101 struct s_filename_and_lstat_info biggiestruct; 102 103 malloc_string(checksum); 104 malloc_string(original_cksum); 105 malloc_string(bigfile_fname); 106 malloc_string(tmp); 107 malloc_string(command); 108 malloc_string(checksum_ptr); 109 malloc_string(original_cksum_ptr); 110 malloc_string(bigfile_fname_ptr); 111 malloc_string(command_ptr); 112 malloc_string(tmp_ptr); 113 115 114 /********************************************************************* 116 115 * allocate memory clear test sab 16 feb 2003 * 117 116 *********************************************************************/ 118 assert(bkpinfo!=NULL);119 memset(checksum_ptr, '\0', sizeof(checksum));120 memset (original_cksum_ptr, '\0', sizeof(original_cksum));121 memset(bigfile_fname_ptr, '\0', sizeof(bigfile_fname));122 memset(tmp_ptr, '\0', sizeof(tmp));123 memset ( command_ptr, '\0', sizeof( command ));117 assert(bkpinfo != NULL); 118 memset(checksum_ptr, '\0', sizeof(checksum)); 119 memset(original_cksum_ptr, '\0', sizeof(original_cksum)); 120 memset(bigfile_fname_ptr, '\0', sizeof(bigfile_fname)); 121 memset(tmp_ptr, '\0', sizeof(tmp)); 122 memset(command_ptr, '\0', sizeof(command)); 124 123 /** end **/ 125 124 126 if ( !does_file_exist( slice_fname(bigfileno, 0, ARCHIVES_PATH, "" ) ) ) 127 { 128 if ( does_file_exist( MNT_CDROM"/archives/NOT-THE-LAST" ) ) 129 { 130 insist_on_this_cd_number(bkpinfo, ( ++g_current_media_number ) ); 131 } 132 else 133 { 134 sprintf(tmp_ptr, "No CD's left. No biggiefiles left. No prob, Bob." ); 135 log_msg(2, tmp_ptr ); 136 return( 0 ); 137 } 138 } 139 if ( !( fin = fopen(slice_fname( bigfileno, 0, ARCHIVES_PATH, "" ), "r" ) ) ) 140 { 141 sprintf( tmp_ptr, 142 "Cannot open bigfile %ld (%s)'s info file", 143 bigfileno + 1, bigfile_fname_ptr); 144 log_to_screen( tmp_ptr ); 145 return( 1 ); 146 } 147 fread( ( void* )&biggiestruct, 1, sizeof( biggiestruct ), fin); 148 paranoid_fclose( fin ); 149 150 strcpy( checksum_ptr, biggiestruct.checksum ); 151 strcpy( bigfile_fname_ptr, biggiestruct.filename ); 152 153 log_msg(2, "biggiestruct.filename = %s", biggiestruct.filename ); 154 log_msg(2, "biggiestruct.checksum = %s", biggiestruct.checksum ); 155 156 sprintf( tmp_ptr, "Comparing %s", bigfile_fname_ptr); 157 158 if (!g_text_mode) 159 { 160 newtDrawRootText( 0, 22, tmp_ptr); 161 newtRefresh(); 162 } 163 if ( !checksum[0] ) { 164 log_msg(2, "Warning - %s has no checksum", bigfile_fname_ptr ); 165 } 166 if ( !strncmp( bigfile_fname_ptr, "/dev/", 5 ) ) 167 { 168 strcpy( original_cksum_ptr, "IGNORE" ); 169 } 170 else 171 { 172 sprintf( command_ptr, 173 "md5sum \"%s%s\" > /tmp/md5sum.txt 2> /tmp/errors.txt", 174 MNT_RESTORING, bigfile_fname_ptr); 175 } 176 log_msg(2, command_ptr ); 177 paranoid_system( "cat /tmp/errors >> /tmp/mondo-restore.log 2> /dev/null" ); 178 if ( system( command_ptr ) ) 179 { 180 log_OS_error( "Warning - command failed" ); 181 original_cksum[0] = '\0'; 182 return( 1 ); 183 } 184 else 185 { 186 if ( !(fin = fopen( "/tmp/md5sum.txt", "r" ) ) ) 187 { 188 log_msg(2, "Unable to open /tmp/md5sum.txt; can't get live checksum" ); 189 original_cksum[0] = '\0'; 190 return( 1 ); 191 } 192 else 193 { 194 fgets( original_cksum_ptr, MAX_STR_LEN - 1, fin ); 195 paranoid_fclose( fin ); 196 for(i = strlen( original_cksum_ptr ); i > 0 && original_cksum[i-1] < 32; i-- ); 197 original_cksum[i] = '\0'; 198 p = ( char* ) strchr( original_cksum_ptr, ' ' ); 199 if ( p ) 200 { 201 *p = '\0'; 202 } 203 } 204 } 205 sprintf( tmp_ptr, "bigfile #%ld ('%s') ", bigfileno + 1, bigfile_fname_ptr); 206 if ( !strcmp(checksum_ptr, original_cksum_ptr ) != 0 ) 207 { 208 strcat( tmp_ptr," ... OK"); 209 } 210 else 211 { 212 strcat( tmp_ptr, "... changed" ); 213 retval++; 214 } 215 log_msg(1, tmp_ptr ); 216 if ( retval ) 217 { 218 if ( !( fout = fopen("/tmp/changed.txt", "a") ) ) 219 { 220 fatal_error( "Cannot openout changed.txt"); 221 } 222 fprintf( fout, "%s\n", bigfile_fname_ptr ); 223 paranoid_fclose( fout ); 224 } 225 226 paranoid_free (original_cksum_ptr); 227 paranoid_free (original_cksum); 228 paranoid_free (bigfile_fname_ptr); 229 paranoid_free (bigfile_fname); 230 paranoid_free (checksum_ptr); 231 paranoid_free (checksum); 232 paranoid_free (command_ptr); 233 paranoid_free (command); 234 paranoid_free (tmp_ptr); 235 paranoid_free (tmp); 236 237 return( retval ); 125 if (!does_file_exist(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""))) { 126 if (does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST")) { 127 insist_on_this_cd_number(bkpinfo, (++g_current_media_number)); 128 } else { 129 sprintf(tmp_ptr, 130 "No CD's left. No biggiefiles left. No prob, Bob."); 131 log_msg(2, tmp_ptr); 132 return (0); 133 } 134 } 135 if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) { 136 sprintf(tmp_ptr, 137 "Cannot open bigfile %ld (%s)'s info file", 138 bigfileno + 1, bigfile_fname_ptr); 139 log_to_screen(tmp_ptr); 140 return (1); 141 } 142 fread((void *) &biggiestruct, 1, sizeof(biggiestruct), fin); 143 paranoid_fclose(fin); 144 145 strcpy(checksum_ptr, biggiestruct.checksum); 146 strcpy(bigfile_fname_ptr, biggiestruct.filename); 147 148 log_msg(2, "biggiestruct.filename = %s", biggiestruct.filename); 149 log_msg(2, "biggiestruct.checksum = %s", biggiestruct.checksum); 150 151 sprintf(tmp_ptr, "Comparing %s", bigfile_fname_ptr); 152 153 if (!g_text_mode) { 154 newtDrawRootText(0, 22, tmp_ptr); 155 newtRefresh(); 156 } 157 if (!checksum[0]) { 158 log_msg(2, "Warning - %s has no checksum", bigfile_fname_ptr); 159 } 160 if (!strncmp(bigfile_fname_ptr, "/dev/", 5)) { 161 strcpy(original_cksum_ptr, "IGNORE"); 162 } else { 163 sprintf(command_ptr, 164 "md5sum \"%s%s\" > /tmp/md5sum.txt 2> /tmp/errors.txt", 165 MNT_RESTORING, bigfile_fname_ptr); 166 } 167 log_msg(2, command_ptr); 168 paranoid_system 169 ("cat /tmp/errors >> /tmp/mondo-restore.log 2> /dev/null"); 170 if (system(command_ptr)) { 171 log_OS_error("Warning - command failed"); 172 original_cksum[0] = '\0'; 173 return (1); 174 } else { 175 if (!(fin = fopen("/tmp/md5sum.txt", "r"))) { 176 log_msg(2, 177 "Unable to open /tmp/md5sum.txt; can't get live checksum"); 178 original_cksum[0] = '\0'; 179 return (1); 180 } else { 181 fgets(original_cksum_ptr, MAX_STR_LEN - 1, fin); 182 paranoid_fclose(fin); 183 for (i = strlen(original_cksum_ptr); 184 i > 0 && original_cksum[i - 1] < 32; i--); 185 original_cksum[i] = '\0'; 186 p = (char *) strchr(original_cksum_ptr, ' '); 187 if (p) { 188 *p = '\0'; 189 } 190 } 191 } 192 sprintf(tmp_ptr, "bigfile #%ld ('%s') ", bigfileno + 1, 193 bigfile_fname_ptr); 194 if (!strcmp(checksum_ptr, original_cksum_ptr) != 0) { 195 strcat(tmp_ptr, " ... OK"); 196 } else { 197 strcat(tmp_ptr, "... changed"); 198 retval++; 199 } 200 log_msg(1, tmp_ptr); 201 if (retval) { 202 if (!(fout = fopen("/tmp/changed.txt", "a"))) { 203 fatal_error("Cannot openout changed.txt"); 204 } 205 fprintf(fout, "%s\n", bigfile_fname_ptr); 206 paranoid_fclose(fout); 207 } 208 209 paranoid_free(original_cksum_ptr); 210 paranoid_free(original_cksum); 211 paranoid_free(bigfile_fname_ptr); 212 paranoid_free(bigfile_fname); 213 paranoid_free(checksum_ptr); 214 paranoid_free(checksum); 215 paranoid_free(command_ptr); 216 paranoid_free(command); 217 paranoid_free(tmp_ptr); 218 paranoid_free(tmp); 219 220 return (retval); 238 221 } 239 222 … … 248 231 * @return 0 for success, nonzero for failure. 249 232 */ 250 int 251 compare_all_biggiefiles(struct s_bkpinfo*bkpinfo) 233 int compare_all_biggiefiles(struct s_bkpinfo *bkpinfo) 252 234 { 253 int retval = 0; 254 int res; 255 long noof_biggiefiles,bigfileno = 0; 256 char tmp[MAX_STR_LEN]; 257 258 assert(bkpinfo!=NULL); 259 log_msg(1, "Comparing biggiefiles" ); 260 261 if ( length_of_file(BIGGIELIST) < 6 ) 262 { 263 log_msg(1, "OK, really teeny-tiny biggielist; not comparing biggiefiles" ); 264 return( 0 ); 265 } 266 noof_biggiefiles = count_lines_in_file(BIGGIELIST); 267 if (noof_biggiefiles <= 0 ) 268 { 269 log_msg(1, "OK, no biggiefiles; not comparing biggiefiles"); 270 return( 0 ); 271 } 272 mvaddstr_and_log_it( g_currentY, 0, "Comparing large files "); 273 open_progress_form("Comparing large files", "I am now comparing the large files" , "against the filesystem. Please wait.", 274 "", 275 noof_biggiefiles ); 276 for( bigfileno = 0; bigfileno < noof_biggiefiles; bigfileno++ ) 277 { 278 sprintf( tmp, "Comparing big file #%ld", bigfileno + 1 ); 279 log_msg(1, tmp ); 280 update_progress_form( tmp ); 281 res = compare_a_biggiefile( bkpinfo, bigfileno ); 282 retval += res; 283 g_current_progress++; 284 } 285 close_progress_form(); 286 return( 0 ); 287 if ( retval ) 288 { 289 mvaddstr_and_log_it( g_currentY++, 74, "Errors." ); 290 } 291 else 292 { 293 mvaddstr_and_log_it( g_currentY++,74, "Done." ); 294 } 295 return( retval ); 235 int retval = 0; 236 int res; 237 long noof_biggiefiles, bigfileno = 0; 238 char tmp[MAX_STR_LEN]; 239 240 assert(bkpinfo != NULL); 241 log_msg(1, "Comparing biggiefiles"); 242 243 if (length_of_file(BIGGIELIST) < 6) { 244 log_msg(1, 245 "OK, really teeny-tiny biggielist; not comparing biggiefiles"); 246 return (0); 247 } 248 noof_biggiefiles = count_lines_in_file(BIGGIELIST); 249 if (noof_biggiefiles <= 0) { 250 log_msg(1, "OK, no biggiefiles; not comparing biggiefiles"); 251 return (0); 252 } 253 mvaddstr_and_log_it(g_currentY, 0, 254 "Comparing large files "); 255 open_progress_form("Comparing large files", 256 "I am now comparing the large files", 257 "against the filesystem. Please wait.", "", 258 noof_biggiefiles); 259 for (bigfileno = 0; bigfileno < noof_biggiefiles; bigfileno++) { 260 sprintf(tmp, "Comparing big file #%ld", bigfileno + 1); 261 log_msg(1, tmp); 262 update_progress_form(tmp); 263 res = compare_a_biggiefile(bkpinfo, bigfileno); 264 retval += res; 265 g_current_progress++; 266 } 267 close_progress_form(); 268 return (0); 269 if (retval) { 270 mvaddstr_and_log_it(g_currentY++, 74, "Errors."); 271 } else { 272 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 273 } 274 return (retval); 296 275 } 276 297 277 /************************************************************************** 298 278 *END_COMPARE_ALL_BIGGIEFILES * … … 308 288 * @return 0 for success, nonzero for failure. 309 289 */ 310 int 311 compare_a_tarball( char *tarball_fname, int current_tarball_number ) 290 int compare_a_tarball(char *tarball_fname, int current_tarball_number) 312 291 { 313 314 315 316 317 318 292 int retval = 0; 293 int res; 294 long noof_lines; 295 long archiver_errors; 296 bool use_star; 297 319 298 /*** needs malloc *********/ 320 char *command, *tmp, *filelist_name, *logfile, *archiver_exe, *compressor_exe; 321 322 malloc_string(command); 323 malloc_string(tmp);324 malloc_string(filelist_name);325 malloc_string(logfile);326 malloc_string(archiver_exe);327 malloc_string(compressor_exe);328 329 use_star = (strstr(tarball_fname, ".star"))?TRUE:FALSE; 330 assert_string_is_neither_NULL_nor_zerolength(tarball_fname);331 sprintf( logfile, "/tmp/afio.log.%d", current_tarball_number);332 sprintf( filelist_name, MNT_CDROM"/archives/filelist.%d", current_tarball_number);333 334 noof_lines = count_lines_in_file( filelist_name);335 336 if ( strstr( tarball_fname, ".bz2") ) 337 { 338 strcpy( compressor_exe, "bzip2"); 339 } 340 else if ( strstr (tarball_fname, ".lzo") ) 341 { 342 strcpy( compressor_exe, "lzop" ); 343 } 344 else 345 { 346 compressor_exe[0] = '\0'; 347 } 348 349 if (use_star) 350 { strcpy(archiver_exe, "star");}351 else 352 { strcpy(archiver_exe, "afio"); } 353 354 if (compressor_exe[0]) 355 { 356 strcpy(tmp, compressor_exe); 357 if (!find_home_of_exe(tmp)) 358 { fatal_error("(compare_a_tarball) Compression program missing"); } 359 if (use_star) // star 360 { 361 if (!strcmp(compressor_exe, "bzip2"))362 { strcat(archiver_exe, " -bz"); }363 else { fatal_error("(compare_a_tarball) Please use only bzip2 with star"); }364 }365 else// afio366 367 368 }369 299 char *command, *tmp, *filelist_name, *logfile, *archiver_exe, 300 *compressor_exe; 301 302 malloc_string(command); 303 malloc_string(tmp); 304 malloc_string(filelist_name); 305 malloc_string(logfile); 306 malloc_string(archiver_exe); 307 malloc_string(compressor_exe); 308 309 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE; 310 assert_string_is_neither_NULL_nor_zerolength(tarball_fname); 311 sprintf(logfile, "/tmp/afio.log.%d", current_tarball_number); 312 sprintf(filelist_name, MNT_CDROM "/archives/filelist.%d", 313 current_tarball_number); 314 315 noof_lines = count_lines_in_file(filelist_name); 316 317 if (strstr(tarball_fname, ".bz2")) { 318 strcpy(compressor_exe, "bzip2"); 319 } else if (strstr(tarball_fname, ".lzo")) { 320 strcpy(compressor_exe, "lzop"); 321 } else { 322 compressor_exe[0] = '\0'; 323 } 324 325 if (use_star) { 326 strcpy(archiver_exe, "star"); 327 } else { 328 strcpy(archiver_exe, "afio"); 329 } 330 331 if (compressor_exe[0]) { 332 strcpy(tmp, compressor_exe); 333 if (!find_home_of_exe(tmp)) { 334 fatal_error("(compare_a_tarball) Compression program missing"); 335 } 336 if (use_star) // star 337 { 338 if (!strcmp(compressor_exe, "bzip2")) { 339 strcat(archiver_exe, " -bz"); 340 } else { 341 fatal_error 342 ("(compare_a_tarball) Please use only bzip2 with star"); 343 } 344 } else // afio 345 { 346 sprintf(compressor_exe, "-P %s -Z", tmp); 347 } 348 } 370 349 // star -diff H=star -bz file=.... 371 350 … … 375 354 #define BUFSIZE (1024L*1024L)/TAPE_BLOCK_SIZE 376 355 #endif 377 if (use_star) // doesn't use compressor_exe 378 { 379 sprintf( command, 380 "%s -diff H=star file=%s >> %s 2>> %s", 381 archiver_exe, tarball_fname, logfile, logfile); 382 } 383 else 384 { 385 sprintf( command, 386 "%s -r -b %ld -M 16m -c %ld %s %s >> %s 2>> %s", 387 archiver_exe, 388 TAPE_BLOCK_SIZE, 389 BUFSIZE, 390 compressor_exe, tarball_fname, 391 logfile, 392 logfile); 393 } 356 if (use_star) // doesn't use compressor_exe 357 { 358 sprintf(command, 359 "%s -diff H=star file=%s >> %s 2>> %s", 360 archiver_exe, tarball_fname, logfile, logfile); 361 } else { 362 sprintf(command, 363 "%s -r -b %ld -M 16m -c %ld %s %s >> %s 2>> %s", 364 archiver_exe, 365 TAPE_BLOCK_SIZE, 366 BUFSIZE, compressor_exe, tarball_fname, logfile, logfile); 367 } 394 368 #undef BUFSIZE 395 369 396 res = system( command ); 397 retval += res; 398 if ( res ) 399 { 400 log_OS_error( command ); 401 sprintf( tmp, "Warning - afio returned error = %d", res ); 402 } 403 if (length_of_file(logfile)>5) 404 { 405 sprintf(command, 406 "cat %s | sed s/': \\\"'/\\|/ | sed s/'\\\": '/\\|/ | cut -d'|' -f2 | sort | uniq | grep -vx \"dev/.*\" >> /tmp/changed.txt", 407 logfile); 408 system(command); 409 archiver_errors = count_lines_in_file( logfile ); 410 } 411 else 412 { 413 archiver_errors = 0; 414 } 415 sprintf(tmp, "%ld difference%c in fileset #%d ", 416 archiver_errors, (archiver_errors != 1) ? 's' : ' ', current_tarball_number); 417 if (archiver_errors) 418 { 419 sprintf(tmp, 420 "Differences found while processing fileset #%d ", 421 current_tarball_number); 422 log_msg(1, tmp ); 423 } 424 unlink( logfile ); 425 paranoid_free(command); 426 paranoid_free(tmp); 427 paranoid_free(filelist_name); 428 paranoid_free(logfile); 429 malloc_string(archiver_exe); 430 malloc_string(compressor_exe); 431 return( retval ); 370 res = system(command); 371 retval += res; 372 if (res) { 373 log_OS_error(command); 374 sprintf(tmp, "Warning - afio returned error = %d", res); 375 } 376 if (length_of_file(logfile) > 5) { 377 sprintf(command, 378 "cat %s | sed s/': \\\"'/\\|/ | sed s/'\\\": '/\\|/ | cut -d'|' -f2 | sort | uniq | grep -vx \"dev/.*\" >> /tmp/changed.txt", 379 logfile); 380 system(command); 381 archiver_errors = count_lines_in_file(logfile); 382 } else { 383 archiver_errors = 0; 384 } 385 sprintf(tmp, "%ld difference%c in fileset #%d ", 386 archiver_errors, (archiver_errors != 1) ? 's' : ' ', 387 current_tarball_number); 388 if (archiver_errors) { 389 sprintf(tmp, 390 "Differences found while processing fileset #%d ", 391 current_tarball_number); 392 log_msg(1, tmp); 393 } 394 unlink(logfile); 395 paranoid_free(command); 396 paranoid_free(tmp); 397 paranoid_free(filelist_name); 398 paranoid_free(logfile); 399 malloc_string(archiver_exe); 400 malloc_string(compressor_exe); 401 return (retval); 432 402 } 403 433 404 /************************************************************************** 434 405 *END_COMPARE_A_TARBALL * … … 441 412 * @return 0 for success, nonzero for failure. 442 413 */ 443 int 444 compare_all_tarballs( struct s_bkpinfo *bkpinfo ) 414 int compare_all_tarballs(struct s_bkpinfo *bkpinfo) 445 415 { 446 447 448 416 int retval = 0; 417 int res; 418 int current_tarball_number = 0; 449 419 450 420 /** needs malloc **********/ 451 452 char *tarball_fname, *progress_str, *tmp; 453 long max_val; 454 455 malloc_string(tarball_fname); 456 malloc_string(progress_str); 457 malloc_string(tmp); 458 459 assert(bkpinfo!=NULL); 460 mvaddstr_and_log_it( g_currentY,0, "Comparing archives" ); 461 read_cfg_var( g_mondo_cfg_file, "last-filelist-number", tmp ); 462 463 max_val = atol( tmp ); 464 sprintf( progress_str, "Comparing with %s #%d ", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number ); 465 466 open_progress_form("Comparing files", 467 "Comparing tarballs against filesystem.", 468 "Please wait. This may take some time.", 469 progress_str, 470 max_val); 471 472 log_to_screen( progress_str ); 473 474 for( ;; ) 475 { 476 insist_on_this_cd_number( bkpinfo, g_current_media_number ); 477 update_progress_form( progress_str ); 478 sprintf( tarball_fname, 479 MNT_CDROM"/archives/%d.afio.bz2", 480 current_tarball_number); 481 482 if ( !does_file_exist( tarball_fname ) ) 483 { 484 sprintf( tarball_fname, MNT_CDROM"/archives/%d.afio.lzo", current_tarball_number ); 485 } 486 if (!does_file_exist ( tarball_fname ) ) 487 { 488 sprintf(tarball_fname, MNT_CDROM"/archives/%d.afio.", 489 current_tarball_number); 490 } 491 if (!does_file_exist ( tarball_fname ) ) 492 { 493 sprintf(tarball_fname, MNT_CDROM"/archives/%d.star.bz2", 494 current_tarball_number); 495 } 496 if (!does_file_exist ( tarball_fname ) ) 497 { 498 sprintf(tarball_fname, MNT_CDROM"/archives/%d.star.", 499 current_tarball_number); 500 } 501 if ( !does_file_exist( tarball_fname ) ) 502 { 503 if ( !does_file_exist( MNT_CDROM"/archives/NOT-THE-LAST" ) || 504 system( "find "MNT_CDROM"/archives/slice* > /dev/null 2> /dev/null" ) 505 == 0 ) 506 { 507 log_msg(2, "OK, I think I'm done with tarballs..." ); 508 break; 509 } 510 log_msg(2, "OK, I think it's time for another CD..." ); 511 g_current_media_number++; 512 sprintf( progress_str, "Comparing with %s #%d ", media_descriptor_string(bkpinfo->backup_media_type), g_current_media_number ); 513 log_to_screen( progress_str ); 514 } 515 else 516 { 517 res = 518 compare_a_tarball( tarball_fname, current_tarball_number ); 519 520 g_current_progress++; 521 current_tarball_number++; 522 } 523 } 524 close_progress_form(); 525 if ( retval ) 526 { 527 mvaddstr_and_log_it( g_currentY++,74, "Errors." ); 528 } 529 else 530 { 531 mvaddstr_and_log_it( g_currentY++, 532 74, 533 "Done."); 534 } 535 paranoid_free(tarball_fname); 536 paranoid_free(progress_str); 537 paranoid_free(tmp); 538 return(retval); 421 422 char *tarball_fname, *progress_str, *tmp; 423 long max_val; 424 425 malloc_string(tarball_fname); 426 malloc_string(progress_str); 427 malloc_string(tmp); 428 429 assert(bkpinfo != NULL); 430 mvaddstr_and_log_it(g_currentY, 0, "Comparing archives"); 431 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp); 432 433 max_val = atol(tmp); 434 sprintf(progress_str, "Comparing with %s #%d ", 435 media_descriptor_string(bkpinfo->backup_media_type), 436 g_current_media_number); 437 438 open_progress_form("Comparing files", 439 "Comparing tarballs against filesystem.", 440 "Please wait. This may take some time.", 441 progress_str, max_val); 442 443 log_to_screen(progress_str); 444 445 for (;;) { 446 insist_on_this_cd_number(bkpinfo, g_current_media_number); 447 update_progress_form(progress_str); 448 sprintf(tarball_fname, 449 MNT_CDROM "/archives/%d.afio.bz2", current_tarball_number); 450 451 if (!does_file_exist(tarball_fname)) { 452 sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.lzo", 453 current_tarball_number); 454 } 455 if (!does_file_exist(tarball_fname)) { 456 sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.", 457 current_tarball_number); 458 } 459 if (!does_file_exist(tarball_fname)) { 460 sprintf(tarball_fname, MNT_CDROM "/archives/%d.star.bz2", 461 current_tarball_number); 462 } 463 if (!does_file_exist(tarball_fname)) { 464 sprintf(tarball_fname, MNT_CDROM "/archives/%d.star.", 465 current_tarball_number); 466 } 467 if (!does_file_exist(tarball_fname)) { 468 if (!does_file_exist(MNT_CDROM "/archives/NOT-THE-LAST") || 469 system("find " MNT_CDROM 470 "/archives/slice* > /dev/null 2> /dev/null") 471 == 0) { 472 log_msg(2, "OK, I think I'm done with tarballs..."); 473 break; 474 } 475 log_msg(2, "OK, I think it's time for another CD..."); 476 g_current_media_number++; 477 sprintf(progress_str, "Comparing with %s #%d ", 478 media_descriptor_string(bkpinfo->backup_media_type), 479 g_current_media_number); 480 log_to_screen(progress_str); 481 } else { 482 res = compare_a_tarball(tarball_fname, current_tarball_number); 483 484 g_current_progress++; 485 current_tarball_number++; 486 } 487 } 488 close_progress_form(); 489 if (retval) { 490 mvaddstr_and_log_it(g_currentY++, 74, "Errors."); 491 } else { 492 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 493 } 494 paranoid_free(tarball_fname); 495 paranoid_free(progress_str); 496 paranoid_free(tmp); 497 return (retval); 539 498 } 499 540 500 /************************************************************************** 541 501 *END_COMPARE_ALL_TARBALLS * … … 554 514 * @return 0 for success, nonzero for failure. 555 515 */ 556 int 557 compare_to_CD( struct s_bkpinfo *bkpinfo ) 516 int compare_to_CD(struct s_bkpinfo *bkpinfo) 558 517 { 559 518 /** needs malloc *********/ 560 char *tmp, *cwd, *new, *command; 561 int resA = 0; 562 int resB = 0; 563 long noof_changed_files; 564 565 malloc_string(tmp); 566 malloc_string(cwd); 567 malloc_string(new); 568 malloc_string(command); 569 570 assert(bkpinfo!=NULL); 571 572 getcwd( cwd, MAX_STR_LEN - 1 ); 573 chdir( bkpinfo->restore_path ); 574 getcwd( new, MAX_STR_LEN - 1 ); 575 sprintf( tmp, "new path is %s", new ); 576 insist_on_this_cd_number( bkpinfo, g_current_media_number ); 577 unlink( "/tmp/changed.txt" ); 578 579 resA = compare_all_tarballs( bkpinfo ); 580 resB = compare_all_biggiefiles( bkpinfo ); 581 chdir( cwd ); 582 noof_changed_files = count_lines_in_file( "/tmp/changed.txt" ); 583 if ( noof_changed_files ) 584 { 585 sprintf( tmp, "%ld files do not match the backup ", 586 noof_changed_files ); 587 // mvaddstr_and_log_it( g_currentY++, 0, tmp ); 588 log_to_screen (tmp); 589 sprintf(command, "cat /tmp/changed.txt >> %s", MONDO_LOGFILE ); 590 paranoid_system( command ); 591 } 592 else 593 { 594 sprintf( tmp, "All files match the backup "); 595 mvaddstr_and_log_it( g_currentY++, 0, tmp ); 596 log_to_screen( tmp ); 597 } 598 599 paranoid_free(tmp); 600 paranoid_free(cwd); 601 paranoid_free(new); 602 paranoid_free(command); 603 604 return( resA + resB ); 519 char *tmp, *cwd, *new, *command; 520 int resA = 0; 521 int resB = 0; 522 long noof_changed_files; 523 524 malloc_string(tmp); 525 malloc_string(cwd); 526 malloc_string(new); 527 malloc_string(command); 528 529 assert(bkpinfo != NULL); 530 531 getcwd(cwd, MAX_STR_LEN - 1); 532 chdir(bkpinfo->restore_path); 533 getcwd(new, MAX_STR_LEN - 1); 534 sprintf(tmp, "new path is %s", new); 535 insist_on_this_cd_number(bkpinfo, g_current_media_number); 536 unlink("/tmp/changed.txt"); 537 538 resA = compare_all_tarballs(bkpinfo); 539 resB = compare_all_biggiefiles(bkpinfo); 540 chdir(cwd); 541 noof_changed_files = count_lines_in_file("/tmp/changed.txt"); 542 if (noof_changed_files) { 543 sprintf(tmp, "%ld files do not match the backup ", 544 noof_changed_files); 545 // mvaddstr_and_log_it( g_currentY++, 0, tmp ); 546 log_to_screen(tmp); 547 sprintf(command, "cat /tmp/changed.txt >> %s", MONDO_LOGFILE); 548 paranoid_system(command); 549 } else { 550 sprintf(tmp, "All files match the backup "); 551 mvaddstr_and_log_it(g_currentY++, 0, tmp); 552 log_to_screen(tmp); 553 } 554 555 paranoid_free(tmp); 556 paranoid_free(cwd); 557 paranoid_free(new); 558 paranoid_free(command); 559 560 return (resA + resB); 605 561 } 606 562 … … 622 578 */ 623 579 int 624 compare_mode( struct s_bkpinfo *bkpinfo,625 struct mountlist_itself *mountlist,626 580 compare_mode(struct s_bkpinfo *bkpinfo, 581 struct mountlist_itself *mountlist, 582 struct raidlist_itself *raidlist) 627 583 { 628 629 630 631 632 584 int retval = 0; 585 long q; 586 char *tmp; 587 588 malloc_string(tmp); 633 589 634 590 /************************************************************************** … … 636 592 * restore them from start of tape, if available * 637 593 **************************************************************************/ 638 assert(bkpinfo!=NULL); 639 assert(mountlist!=NULL); 640 assert(raidlist!=NULL); 641 642 while (get_cfg_file_from_archive( bkpinfo )) 643 { 644 if (!ask_me_yes_or_no("Failed to find config file/archives. Choose another source?")) 645 { fatal_error("Unable to find config file/archives. Aborting."); } 646 interactively_obtain_media_parameters_from_user(bkpinfo, FALSE); 647 } 648 649 read_cfg_file_into_bkpinfo( g_mondo_cfg_file, bkpinfo ); 650 g_current_media_number = 1; 651 mvaddstr_and_log_it( 1, 30, "Comparing Automatically" ); 652 iamhere("Pre-MAD"); 653 retval = mount_all_devices( mountlist, FALSE ); 654 iamhere("Post-MAD"); 655 if ( retval ) 656 { 657 unmount_all_devices( mountlist ); 658 return( retval ); 659 } 660 if ( bkpinfo->backup_media_type == tape || bkpinfo->backup_media_type == udev) 661 { 662 retval += compare_to_tape( bkpinfo ); 663 } 664 else if ( bkpinfo->backup_media_type == cdstream ) 665 { 666 retval += compare_to_cdstream( bkpinfo ); 667 } 668 else 669 { 670 retval += compare_to_CD( bkpinfo ); 671 } 672 if ( retval ) 673 { 674 mvaddstr_and_log_it( g_currentY++, 675 0, 676 "Warning - differences found during the compare phase"); 677 } 678 679 retval += unmount_all_devices( mountlist ); 680 681 if ( count_lines_in_file("/tmp/changed.txt") > 0 ) 682 { 683 mvaddstr_and_log_it( g_currentY++, 0, 684 "Differences found while files were being compared." ); 685 streamline_changes_file( "/tmp/changed.files", "/tmp/changed.txt" ); 686 if (count_lines_in_file( "/tmp/changed.files" ) <= 0 ) 687 { 688 mvaddstr_and_log_it( g_currentY++,0, 689 "...but they were logfiles and temporary files. Your archives are fine."); 690 log_to_screen( "The differences were logfiles and temporary files. Your archives are fine."); 691 } 692 else 693 { 694 q = count_lines_in_file("/tmp/changed.files"); 695 sprintf( tmp, "%ld significant difference%s found.", q, (q!=1) ? "s" : ""); 696 mvaddstr_and_log_it( g_currentY++, 0, tmp); 697 log_to_screen (tmp); 698 699 strcpy( tmp, "Type 'less /tmp/changed.files' for a list of non-matching files" ); 700 mvaddstr_and_log_it( g_currentY++, 0, tmp ); 701 log_to_screen( tmp ); 702 703 log_msg(2, "calling popup_changelist_from_file()"); 704 popup_changelist_from_file("/tmp/changed.files"); 705 log_msg(2, "Returning from popup_changelist_from_file()"); 706 } 707 } 708 else 709 { 710 log_to_screen( "No significant differences were found. Your backup is perfect." ); 711 } 712 kill_petris(); 713 paranoid_free(tmp); 714 return( retval ); 594 assert(bkpinfo != NULL); 595 assert(mountlist != NULL); 596 assert(raidlist != NULL); 597 598 while (get_cfg_file_from_archive(bkpinfo)) { 599 if (!ask_me_yes_or_no 600 ("Failed to find config file/archives. Choose another source?")) 601 { 602 fatal_error("Unable to find config file/archives. Aborting."); 603 } 604 interactively_obtain_media_parameters_from_user(bkpinfo, FALSE); 605 } 606 607 read_cfg_file_into_bkpinfo(g_mondo_cfg_file, bkpinfo); 608 g_current_media_number = 1; 609 mvaddstr_and_log_it(1, 30, "Comparing Automatically"); 610 iamhere("Pre-MAD"); 611 retval = mount_all_devices(mountlist, FALSE); 612 iamhere("Post-MAD"); 613 if (retval) { 614 unmount_all_devices(mountlist); 615 return (retval); 616 } 617 if (bkpinfo->backup_media_type == tape 618 || bkpinfo->backup_media_type == udev) { 619 retval += compare_to_tape(bkpinfo); 620 } else if (bkpinfo->backup_media_type == cdstream) { 621 retval += compare_to_cdstream(bkpinfo); 622 } else { 623 retval += compare_to_CD(bkpinfo); 624 } 625 if (retval) { 626 mvaddstr_and_log_it(g_currentY++, 627 0, 628 "Warning - differences found during the compare phase"); 629 } 630 631 retval += unmount_all_devices(mountlist); 632 633 if (count_lines_in_file("/tmp/changed.txt") > 0) { 634 mvaddstr_and_log_it(g_currentY++, 0, 635 "Differences found while files were being compared."); 636 streamline_changes_file("/tmp/changed.files", "/tmp/changed.txt"); 637 if (count_lines_in_file("/tmp/changed.files") <= 0) { 638 mvaddstr_and_log_it(g_currentY++, 0, 639 "...but they were logfiles and temporary files. Your archives are fine."); 640 log_to_screen 641 ("The differences were logfiles and temporary files. Your archives are fine."); 642 } else { 643 q = count_lines_in_file("/tmp/changed.files"); 644 sprintf(tmp, "%ld significant difference%s found.", q, 645 (q != 1) ? "s" : ""); 646 mvaddstr_and_log_it(g_currentY++, 0, tmp); 647 log_to_screen(tmp); 648 649 strcpy(tmp, 650 "Type 'less /tmp/changed.files' for a list of non-matching files"); 651 mvaddstr_and_log_it(g_currentY++, 0, tmp); 652 log_to_screen(tmp); 653 654 log_msg(2, "calling popup_changelist_from_file()"); 655 popup_changelist_from_file("/tmp/changed.files"); 656 log_msg(2, "Returning from popup_changelist_from_file()"); 657 } 658 } else { 659 log_to_screen 660 ("No significant differences were found. Your backup is perfect."); 661 } 662 kill_petris(); 663 paranoid_free(tmp); 664 return (retval); 715 665 } 716 666 … … 727 677 * @return 0 for success, nonzero for failure. 728 678 */ 729 int 730 compare_to_cdstream(struct s_bkpinfo *bkpinfo) 679 int compare_to_cdstream(struct s_bkpinfo *bkpinfo) 731 680 { 732 681 int res; 733 682 734 683 /** needs malloc **/ 735 char *dir, *command; 736 737 assert(bkpinfo!=NULL); 738 malloc_string(dir); 739 malloc_string(command); 740 getcwd( dir, MAX_STR_LEN ); 741 chdir( bkpinfo->restore_path ); 742 743 sprintf( command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", bkpinfo->restore_path ); 744 run_program_and_log_output( command, FALSE ); 745 mvaddstr_and_log_it(g_currentY, 746 0, 747 "Verifying archives against filesystem" ); 748 749 if (bkpinfo->disaster_recovery && does_file_exist("/tmp/CDROM-LIVES-HERE")) 750 { strcpy(bkpinfo->media_device, last_line_of_file("/tmp/CDROM-LIVES-HERE")); } 751 else 752 { find_cdrom_device( bkpinfo->media_device, FALSE ); } 753 res = verify_tape_backups( bkpinfo ); 754 chdir( dir ); 755 if ( length_of_file ( "/tmp/changed.txt" ) > 2 && length_of_file ( "/tmp/changed.files" ) > 2 ) 756 { 757 log_msg(0, "Type 'less /tmp/changed.files' to see which files don't match the archives" ); 758 log_msg(2, "Calling popup_changelist_from_file()" ); 759 popup_changelist_from_file( "/tmp/changed.files" ); 760 log_msg(2, "Returned from popup_changelist_from_file()" ); 761 } 762 763 mvaddstr_and_log_it( g_currentY++, 74, "Done." ); 764 paranoid_free(dir); 765 paranoid_free(command); 766 return( res ); 684 char *dir, *command; 685 686 assert(bkpinfo != NULL); 687 malloc_string(dir); 688 malloc_string(command); 689 getcwd(dir, MAX_STR_LEN); 690 chdir(bkpinfo->restore_path); 691 692 sprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", 693 bkpinfo->restore_path); 694 run_program_and_log_output(command, FALSE); 695 mvaddstr_and_log_it(g_currentY, 696 0, "Verifying archives against filesystem"); 697 698 if (bkpinfo->disaster_recovery 699 && does_file_exist("/tmp/CDROM-LIVES-HERE")) { 700 strcpy(bkpinfo->media_device, 701 last_line_of_file("/tmp/CDROM-LIVES-HERE")); 702 } else { 703 find_cdrom_device(bkpinfo->media_device, FALSE); 704 } 705 res = verify_tape_backups(bkpinfo); 706 chdir(dir); 707 if (length_of_file("/tmp/changed.txt") > 2 708 && length_of_file("/tmp/changed.files") > 2) { 709 log_msg(0, 710 "Type 'less /tmp/changed.files' to see which files don't match the archives"); 711 log_msg(2, "Calling popup_changelist_from_file()"); 712 popup_changelist_from_file("/tmp/changed.files"); 713 log_msg(2, "Returned from popup_changelist_from_file()"); 714 } 715 716 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 717 paranoid_free(dir); 718 paranoid_free(command); 719 return (res); 767 720 } 721 768 722 /************************************************************************** 769 723 *END_COMPARE_CD_STREAM * … … 782 736 * returns: int * 783 737 **************************************************************************/ 784 int 785 compare_to_tape( struct s_bkpinfo *bkpinfo ) 738 int compare_to_tape(struct s_bkpinfo *bkpinfo) 786 739 { 787 int res; 788 char *dir, *command; 789 790 assert(bkpinfo!=NULL); 791 malloc_string(dir); 792 malloc_string(command); 793 794 getcwd( dir, MAX_STR_LEN ); 795 chdir( bkpinfo->restore_path ); 796 sprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", bkpinfo->restore_path); 797 run_program_and_log_output( command, FALSE ); 798 mvaddstr_and_log_it( g_currentY, 799 0, 800 "Verifying archives against filesystem"); 801 res = verify_tape_backups( bkpinfo ); 802 chdir( dir ); 803 if ( res ) 804 { 805 mvaddstr_and_log_it( g_currentY++, 74, "Failed." ); 806 } 807 else 808 { 809 mvaddstr_and_log_it( g_currentY++, 74, "Done." ); 810 } 811 paranoid_free(dir); 812 paranoid_free(command); 813 return( res ); 740 int res; 741 char *dir, *command; 742 743 assert(bkpinfo != NULL); 744 malloc_string(dir); 745 malloc_string(command); 746 747 getcwd(dir, MAX_STR_LEN); 748 chdir(bkpinfo->restore_path); 749 sprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", 750 bkpinfo->restore_path); 751 run_program_and_log_output(command, FALSE); 752 mvaddstr_and_log_it(g_currentY, 753 0, "Verifying archives against filesystem"); 754 res = verify_tape_backups(bkpinfo); 755 chdir(dir); 756 if (res) { 757 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 758 } else { 759 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 760 } 761 paranoid_free(dir); 762 paranoid_free(command); 763 return (res); 814 764 } 815 765 … … 819 769 820 770 /* @} - end compareGroup */ 821 -
trunk/mondo/mondo/mondorestore/mondo-rstr-compare.h
r30 r59 1 1 /* mondo-rstr-compare.h 2 * $Id : mondo-rstr-compare.h,v 1.1 2004/06/10 15:29:13 hugo Exp$2 * $Id$ 3 3 */ 4 4 5 5 6 int compare_to_CD(struct s_bkpinfo *);7 int compare_to_cdstream(struct s_bkpinfo *);8 int compare_to_tape(struct s_bkpinfo *);6 int compare_to_CD(struct s_bkpinfo *); 7 int compare_to_cdstream(struct s_bkpinfo *); 8 int compare_to_tape(struct s_bkpinfo *); 9 9 10 int 11 compare_mode( struct s_bkpinfo *bkpinfo,12 struct mountlist_itself *mountlist,13 10 int 11 compare_mode(struct s_bkpinfo *bkpinfo, 12 struct mountlist_itself *mountlist, 13 struct raidlist_itself *raidlist); -
trunk/mondo/mondo/mondorestore/mondo-rstr-newt.c
r30 r59 8 8 edited by : by Stan Benoit 4/2002 9 9 email : troff@nakedsoul.org 10 cvsid : $Id : mondo-rstr-newt.c,v 1.5 2004/06/10 15:29:13 hugo Exp$10 cvsid : $Id$ 11 11 ***************************************************************************/ 12 12 … … 92 92 #include "mondo-rstr-newt.h" 93 93 94 //static char cvsid[] = "$Id : mondo-rstr-newt.c,v 1.5 2004/06/10 15:29:13 hugo Exp$";94 //static char cvsid[] = "$Id$"; 95 95 96 96 extern char err_log_lines[NOOF_ERR_LINES][MAX_STR_LEN]; … … 127 127 */ 128 128 void 129 add_disklist_entry 130 129 add_disklist_entry(struct list_of_disks *disklist, char *raid_device, 130 struct mountlist_itself *unallocated_raid_partitions) 131 131 { 132 132 /** buffers ***********************************************************/ 133 133 char tmp[MAX_STR_LEN]; 134 134 135 135 /** newt **************************************************************/ 136 136 newtComponent myForm; 137 137 newtComponent bOK; 138 138 newtComponent bCancel; … … 140 140 newtComponent partitionsListbox; 141 141 newtComponent headerMsg; 142 142 143 143 /** prototypes *********************************************************/ 144 145 144 void *keylist[ARBITRARY_MAXIMUM]; 145 void *curr_choice; 146 146 147 147 /** int ****************************************************************/ 148 148 int i = 0; 149 149 int index = 0; 150 150 int currline = 0; 151 151 int items = 0; 152 152 153 assert(disklist!=NULL); 154 assert_string_is_neither_NULL_nor_zerolength(raid_device); 155 assert(unallocated_raid_partitions!=NULL); 156 157 newtPushHelpLine 158 (" Add one of the following unallocated RAID partitions to this RAID device."); 159 sprintf (tmp, "%-26s %s", "Device", "Size"); 160 headerMsg = newtLabel (1, 1, tmp); 161 partitionsListbox = 162 newtListbox (1, 2, 6, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 163 redraw_unallocpartnslist (unallocated_raid_partitions, keylist, 164 partitionsListbox); 165 i = 7; 166 bOK = newtCompactButton (i, 9, " OK "); 167 bCancel = newtCompactButton (i += 9, 9, "Cancel"); 168 newtOpenWindow (22, 6, 36, 10, "Unallocated RAID partitions"); 169 myForm = newtForm (NULL, NULL, 0); 170 newtFormAddComponents (myForm, headerMsg, partitionsListbox, bOK, bCancel, 171 NULL); 172 b_res = newtRunForm (myForm); 173 if (b_res != bCancel) 174 { 175 curr_choice = newtListboxGetCurrent (partitionsListbox); 176 for (currline = 0; 177 currline < unallocated_raid_partitions->entries 178 && keylist[currline] != curr_choice; currline++); 179 if (currline == unallocated_raid_partitions->entries 180 && unallocated_raid_partitions->entries > 0) 181 { 182 log_it ("I don't know what this button does"); 183 } 184 else 185 { 186 index = find_next_free_index_in_disklist (disklist); 187 188 items = disklist->entries; 189 strcpy (disklist->el[items].device, 190 unallocated_raid_partitions->el[currline].device); 191 disklist->el[items].index = index; 192 disklist->entries = ++items; 193 194 } 195 } 196 newtFormDestroy (myForm); 197 newtPopWindow (); 198 newtPopHelpLine (); 153 assert(disklist != NULL); 154 assert_string_is_neither_NULL_nor_zerolength(raid_device); 155 assert(unallocated_raid_partitions != NULL); 156 157 newtPushHelpLine 158 (" Add one of the following unallocated RAID partitions to this RAID device."); 159 sprintf(tmp, "%-26s %s", "Device", "Size"); 160 headerMsg = newtLabel(1, 1, tmp); 161 partitionsListbox = 162 newtListbox(1, 2, 6, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 163 redraw_unallocpartnslist(unallocated_raid_partitions, keylist, 164 partitionsListbox); 165 i = 7; 166 bOK = newtCompactButton(i, 9, " OK "); 167 bCancel = newtCompactButton(i += 9, 9, "Cancel"); 168 newtOpenWindow(22, 6, 36, 10, "Unallocated RAID partitions"); 169 myForm = newtForm(NULL, NULL, 0); 170 newtFormAddComponents(myForm, headerMsg, partitionsListbox, bOK, 171 bCancel, NULL); 172 b_res = newtRunForm(myForm); 173 if (b_res != bCancel) { 174 curr_choice = newtListboxGetCurrent(partitionsListbox); 175 for (currline = 0; 176 currline < unallocated_raid_partitions->entries 177 && keylist[currline] != curr_choice; currline++); 178 if (currline == unallocated_raid_partitions->entries 179 && unallocated_raid_partitions->entries > 0) { 180 log_it("I don't know what this button does"); 181 } else { 182 index = find_next_free_index_in_disklist(disklist); 183 184 items = disklist->entries; 185 strcpy(disklist->el[items].device, 186 unallocated_raid_partitions->el[currline].device); 187 disklist->el[items].index = index; 188 disklist->entries = ++items; 189 190 } 191 } 192 newtFormDestroy(myForm); 193 newtPopWindow(); 194 newtPopHelpLine(); 199 195 } 200 196 … … 212 208 */ 213 209 void 214 add_mountlist_entry 215 struct raidlist_itself *raidlist, newtComponent listbox,216 210 add_mountlist_entry(struct mountlist_itself *mountlist, 211 struct raidlist_itself *raidlist, 212 newtComponent listbox, int currline, void *keylist[]) 217 213 { 218 214 219 215 /** int **************************************************************/ 220 int i= 0;216 int i = 0; 221 217 int num_to_add = 0; 222 218 223 219 /** newt *************************************************************/ 224 220 newtComponent myForm; 225 221 newtComponent bOK; 226 222 newtComponent bCancel; … … 236 232 237 233 /** buffers **********************************************************/ 238 234 char drive_to_add[MAX_STR_LEN]; 239 235 char mountpoint_str[MAX_STR_LEN]; 240 236 char size_str[MAX_STR_LEN]; 241 237 char device_str[MAX_STR_LEN]; 242 238 char format_str[MAX_STR_LEN]; 243 239 … … 248 244 char *format_here; 249 245 250 assert(mountlist!=NULL);251 assert(raidlist!=NULL);252 assert(listbox!=NULL);253 assert(keylist!=NULL);254 255 strcpy 256 strcpy 246 assert(mountlist != NULL); 247 assert(raidlist != NULL); 248 assert(listbox != NULL); 249 assert(keylist != NULL); 250 251 strcpy(device_str, "/dev/"); 252 strcpy(mountpoint_str, "/"); 257 253 #ifdef __FreeBSD__ 258 strcpy 254 strcpy(format_str, "ufs"); 259 255 #else 260 strcpy(format_str, "ext2");256 strcpy(format_str, "ext2"); 261 257 #endif 262 size_str[0] = '\0'; 263 /* sprintf(size_str,""); */ 264 newtOpenWindow (20, 5, 48, 10, "Add entry"); 265 label0 = newtLabel (2, 1, "Device: "); 266 label1 = newtLabel (2, 2, "Mountpoint:"); 267 label2 = newtLabel (2, 3, "Size (MB): "); 268 label3 = newtLabel (2, 4, "Format: "); 269 deviceComp = newtEntry (14, 1, device_str, 30, (void*)&device_here, 0); 270 mountpointComp = newtEntry (14, 2, mountpoint_str, 30, (void*)&mountpoint_here, 0); 271 formatComp = newtEntry (14, 4, format_str, 15, (void*)&format_here, 0); 272 sizeComp = newtEntry (14, 3, size_str, 10, (void*)&size_here, 0); 273 bOK = newtButton (5, 6, " OK "); 274 bCancel = newtButton (17, 6, "Cancel"); 275 newtPushHelpLine 276 ("To add an entry to the mountlist, please fill in these fields and then hit 'OK'"); 277 myForm = newtForm (NULL, NULL, 0); 278 newtFormAddComponents (myForm, deviceComp, mountpointComp, sizeComp, 279 formatComp, label0, label1, label2, label3, bOK, 280 bCancel, NULL); 281 for (b_res = NULL; b_res != bOK && b_res != bCancel;) 282 { 283 b_res = newtRunForm (myForm); 284 strcpy (device_str, device_here); 285 strcpy (mountpoint_str, mountpoint_here); 286 strcpy (format_str, format_here); 287 strcpy (size_str, size_here); 258 size_str[0] = '\0'; 259 /* sprintf(size_str,""); */ 260 newtOpenWindow(20, 5, 48, 10, "Add entry"); 261 label0 = newtLabel(2, 1, "Device: "); 262 label1 = newtLabel(2, 2, "Mountpoint:"); 263 label2 = newtLabel(2, 3, "Size (MB): "); 264 label3 = newtLabel(2, 4, "Format: "); 265 deviceComp = 266 newtEntry(14, 1, device_str, 30, (void *) &device_here, 0); 267 mountpointComp = 268 newtEntry(14, 2, mountpoint_str, 30, (void *) &mountpoint_here, 0); 269 formatComp = 270 newtEntry(14, 4, format_str, 15, (void *) &format_here, 0); 271 sizeComp = newtEntry(14, 3, size_str, 10, (void *) &size_here, 0); 272 bOK = newtButton(5, 6, " OK "); 273 bCancel = newtButton(17, 6, "Cancel"); 274 newtPushHelpLine 275 ("To add an entry to the mountlist, please fill in these fields and then hit 'OK'"); 276 myForm = newtForm(NULL, NULL, 0); 277 newtFormAddComponents(myForm, deviceComp, mountpointComp, sizeComp, 278 formatComp, label0, label1, label2, label3, bOK, 279 bCancel, NULL); 280 for (b_res = NULL; b_res != bOK && b_res != bCancel;) { 281 b_res = newtRunForm(myForm); 282 strcpy(device_str, device_here); 283 strcpy(mountpoint_str, mountpoint_here); 284 strcpy(format_str, format_here); 285 strcpy(size_str, size_here); 288 286 // log_it ("Originals = %s,%s,%s,%s", device_str, mountpoint_str, format_str, size_str); 289 strip_spaces(device_str);290 strip_spaces(mountpoint_str);291 strip_spaces(format_str);292 strip_spaces(size_str);287 strip_spaces(device_str); 288 strip_spaces(mountpoint_str); 289 strip_spaces(format_str); 290 strip_spaces(size_str); 293 291 // log_it ("Modified = %s,%s,%s,%s", device_str, mountpoint_str, format_str, size_str); 294 if (b_res == bOK) 295 { 296 if (device_str[strlen (device_str) - 1] == '/') 297 { 298 popup_and_OK ("You left the device nearly blank!"); 299 b_res = NULL; 300 } 301 if (size_of_specific_device_in_mountlist (mountlist, device_str) >= 0) 302 { 303 popup_and_OK ("Can't add this - you've got one already!"); 304 b_res = NULL; 305 } 306 } 307 } 308 newtFormDestroy (myForm); 309 newtPopHelpLine (); 310 newtPopWindow (); 311 if (b_res == bCancel) 312 { 313 return; 314 } 315 strcpy (drive_to_add, device_str); 316 for (i = strlen (drive_to_add); isdigit (drive_to_add[i - 1]); i--); 317 num_to_add = atoi (drive_to_add + i); 318 drive_to_add[i] = '\0'; 319 currline = mountlist->entries; 320 strcpy (mountlist->el[currline].device, device_str); 321 strcpy (mountlist->el[currline].mountpoint, mountpoint_str); 322 strcpy (mountlist->el[currline].format, format_str); 323 mountlist->el[currline].size = atol (size_str) * 1024; 324 mountlist->entries++; 325 if (strstr (mountlist->el[currline].device, RAID_DEVICE_STUB)) 326 { 327 initiate_new_raidlist_entry (raidlist, mountlist, currline, device_str); 328 } 329 redraw_mountlist (mountlist, keylist, listbox); 292 if (b_res == bOK) { 293 if (device_str[strlen(device_str) - 1] == '/') { 294 popup_and_OK("You left the device nearly blank!"); 295 b_res = NULL; 296 } 297 if (size_of_specific_device_in_mountlist(mountlist, device_str) 298 >= 0) { 299 popup_and_OK("Can't add this - you've got one already!"); 300 b_res = NULL; 301 } 302 } 303 } 304 newtFormDestroy(myForm); 305 newtPopHelpLine(); 306 newtPopWindow(); 307 if (b_res == bCancel) { 308 return; 309 } 310 strcpy(drive_to_add, device_str); 311 for (i = strlen(drive_to_add); isdigit(drive_to_add[i - 1]); i--); 312 num_to_add = atoi(drive_to_add + i); 313 drive_to_add[i] = '\0'; 314 currline = mountlist->entries; 315 strcpy(mountlist->el[currline].device, device_str); 316 strcpy(mountlist->el[currline].mountpoint, mountpoint_str); 317 strcpy(mountlist->el[currline].format, format_str); 318 mountlist->el[currline].size = atol(size_str) * 1024; 319 mountlist->entries++; 320 if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)) { 321 initiate_new_raidlist_entry(raidlist, mountlist, currline, 322 device_str); 323 } 324 redraw_mountlist(mountlist, keylist, listbox); 330 325 } 331 326 … … 337 332 * @ingroup restoreGuiVarslist 338 333 */ 339 void 340 add_varslist_entry (struct raid_device_record *raidrec) 334 void add_varslist_entry(struct raid_device_record *raidrec) 341 335 { 342 336 343 337 /** buffers ***********************************************************/ 344 338 char sz_out[MAX_STR_LEN]; 345 339 346 340 /** int ****************************************************************/ 347 int items= 0;341 int items = 0; 348 342 int i = 0; 349 343 350 assert(raidrec!=NULL); 351 352 sz_out[0] = '\0'; 353 if (popup_and_get_string 354 ("Add variable", "Enter the name of the variable to add", sz_out, MAX_STR_LEN)) 355 { 356 strip_spaces (sz_out); 357 items = raidrec->additional_vars.entries; 358 for (i = 0; 359 i < items && strcmp (raidrec->additional_vars.el[i].label, sz_out); 360 i++); 361 if (i < items) 362 { 363 popup_and_OK 364 ("No need to add that variable. It is already listed here."); 365 } 366 else 367 { 368 strcpy (raidrec->additional_vars.el[items].label, sz_out); 369 edit_varslist_entry (raidrec, items); 370 raidrec->additional_vars.entries = ++items; 371 } 372 } 344 assert(raidrec != NULL); 345 346 sz_out[0] = '\0'; 347 if (popup_and_get_string 348 ("Add variable", "Enter the name of the variable to add", sz_out, 349 MAX_STR_LEN)) { 350 strip_spaces(sz_out); 351 items = raidrec->additional_vars.entries; 352 for (i = 0; 353 i < items 354 && strcmp(raidrec->additional_vars.el[i].label, sz_out); i++); 355 if (i < items) { 356 popup_and_OK 357 ("No need to add that variable. It is already listed here."); 358 } else { 359 strcpy(raidrec->additional_vars.el[items].label, sz_out); 360 edit_varslist_entry(raidrec, items); 361 raidrec->additional_vars.entries = ++items; 362 } 363 } 373 364 } 374 365 #endif … … 383 374 */ 384 375 long 385 calculate_raid_device_size 386 387 376 calculate_raid_device_size(struct mountlist_itself *mountlist, 377 struct raidlist_itself *raidlist, 378 char *raid_device) 388 379 { 389 380 #ifdef __FreeBSD__ 390 381 /** FreeBSD-specific version of calculate_raid_device_size() **/ 391 382 392 383 /** structures ********************************************************/ 393 384 struct vinum_volume *raidrec; 394 385 395 386 /** int ***************************************************************/ 396 387 int i = 0, j = 0; 397 388 int noof_partitions = 0; 398 389 399 390 /** long **************************************************************/ 400 401 402 403 long smallest_plex= 999999999;391 long total_size = 0; 392 long plex_size = 0; 393 long smallest_partition = 999999999; 394 long smallest_plex = 999999999; 404 395 long sp = 0; 405 396 406 397 /** buffers ***********************************************************/ 407 char tmp[MAX_STR_LEN]; 408 409 410 411 412 for (i = 0; 413 i < raidlist->entries 414 && strcmp (raidlist->el[i].volname, basename (raid_device)); i++); 415 if (i == raidlist->entries) 416 { 417 sprintf (tmp, 418 "Cannot calc size of raid device %s - cannot find it in raidlist", 419 raid_device); 420 log_it (tmp); 421 return (0); // Isn't this more sensible than 999999999? If the raid dev !exists, 422 // then it has no size, right? 423 } 424 raidrec = &raidlist->el[i]; 425 total_size = 0; 426 if (raidrec->plexes == 0) return 0; 427 for (j = 0; j < raidrec->plexes; j++) { 428 plex_size = 0; 429 int k = 0, l = 0; 430 for (k = 0; k < raidrec->plex[j].subdisks; ++k) { 431 char devname[64]; 432 strcpy (devname, raidrec->plex[j].sd[k].which_device); 433 for (l = 0; l < raidlist->disks.entries; ++l) { 434 if (!strcmp (devname, raidlist->disks.el[l].name)) { 435 switch (raidrec->plex[j].raidlevel) { 436 case -1: 437 plex_size += 438 size_of_specific_device_in_mountlist (mountlist, 439 raidlist->disks.el[l].device); 440 break; 441 case 0: 442 case 5: 443 if (size_of_specific_device_in_mountlist (mountlist, 444 raidlist->disks.el[l].device) < smallest_partition) { 445 smallest_partition = size_of_specific_device_in_mountlist (mountlist, 446 raidlist->disks.el[l].device); 447 } 448 break; 449 } 450 } 451 } 452 } 453 454 if (!is_this_raid_personality_registered (raidrec->plex[j].raidlevel)) { 455 log_it ("%s has a really weird RAID level - couldn't calc size :(", raid_device); 456 return (999999999); 457 } 458 if (raidrec->plex[j].raidlevel != -1) { 459 plex_size = smallest_partition * (raidrec->plex[j].subdisks - 460 (raidrec->plex[j].raidlevel == 5 ? 1 : 0)); 461 } 462 if (plex_size < smallest_plex) 463 smallest_plex = plex_size; 464 465 smallest_partition = 999999999; 466 } 467 468 sprintf (tmp, "I have calculated %s's real size to be %ld", raid_device, 469 (long) smallest_plex); 470 log_it (tmp); 471 return (smallest_plex); 398 char tmp[MAX_STR_LEN]; 399 400 401 402 403 for (i = 0; 404 i < raidlist->entries 405 && strcmp(raidlist->el[i].volname, basename(raid_device)); i++); 406 if (i == raidlist->entries) { 407 sprintf(tmp, 408 "Cannot calc size of raid device %s - cannot find it in raidlist", 409 raid_device); 410 log_it(tmp); 411 return (0); // Isn't this more sensible than 999999999? If the raid dev !exists, 412 // then it has no size, right? 413 } 414 raidrec = &raidlist->el[i]; 415 total_size = 0; 416 if (raidrec->plexes == 0) 417 return 0; 418 for (j = 0; j < raidrec->plexes; j++) { 419 plex_size = 0; 420 int k = 0, l = 0; 421 for (k = 0; k < raidrec->plex[j].subdisks; ++k) { 422 char devname[64]; 423 strcpy(devname, raidrec->plex[j].sd[k].which_device); 424 for (l = 0; l < raidlist->disks.entries; ++l) { 425 if (!strcmp(devname, raidlist->disks.el[l].name)) { 426 switch (raidrec->plex[j].raidlevel) { 427 case -1: 428 plex_size += 429 size_of_specific_device_in_mountlist(mountlist, 430 raidlist-> 431 disks. 432 el[l]. 433 device); 434 break; 435 case 0: 436 case 5: 437 if (size_of_specific_device_in_mountlist(mountlist, 438 raidlist-> 439 disks. 440 el[l]. 441 device) < 442 smallest_partition) { 443 smallest_partition = 444 size_of_specific_device_in_mountlist 445 (mountlist, raidlist->disks.el[l].device); 446 } 447 break; 448 } 449 } 450 } 451 } 452 453 if (!is_this_raid_personality_registered 454 (raidrec->plex[j].raidlevel)) { 455 log_it 456 ("%s has a really weird RAID level - couldn't calc size :(", 457 raid_device); 458 return (999999999); 459 } 460 if (raidrec->plex[j].raidlevel != -1) { 461 plex_size = smallest_partition * (raidrec->plex[j].subdisks - 462 (raidrec->plex[j]. 463 raidlevel == 5 ? 1 : 0)); 464 } 465 if (plex_size < smallest_plex) 466 smallest_plex = plex_size; 467 468 smallest_partition = 999999999; 469 } 470 471 sprintf(tmp, "I have calculated %s's real size to be %ld", raid_device, 472 (long) smallest_plex); 473 log_it(tmp); 474 return (smallest_plex); 472 475 #else 473 476 /** Linux-specific version of calculate_raid_device_size() **/ 474 477 475 478 /** structures ********************************************************/ 476 479 struct raid_device_record *raidrec; 477 480 478 481 /** int ***************************************************************/ 479 482 int i = 0; 480 483 int noof_partitions = 0; 481 484 482 485 /** long **************************************************************/ 483 486 long total_size = 0; 484 487 long smallest_partition = 999999999; 485 488 long sp = 0; 486 489 487 490 /** buffers ***********************************************************/ 488 char tmp[MAX_STR_LEN]; 489 490 assert(mountlist!=NULL); 491 assert(raidlist!=NULL); 492 assert_string_is_neither_NULL_nor_zerolength(raid_device); 493 494 for (i = 0; 495 i < raidlist->entries 496 && strcmp (raidlist->el[i].raid_device, raid_device); i++); 497 if (i == raidlist->entries) 498 { 499 sprintf (tmp, 500 "Cannot calc size of raid device %s - cannot find it in raidlist", 501 raid_device); 502 log_it (tmp); 503 return (999999999); 504 } 505 raidrec = &raidlist->el[i]; 506 noof_partitions = raidrec->data_disks.entries; 507 if (raidrec->raid_level == -1 || raidrec->raid_level == 0) 508 { 509 for (total_size = 0, i = 0; i < noof_partitions; i++) 510 { 511 total_size += 512 size_of_specific_device_in_mountlist (mountlist, 513 raidrec->data_disks.el[i].device); 514 } 515 } 516 else 517 { 518 for (i = 0; i < noof_partitions; i++) 519 { 520 sp = 521 size_of_specific_device_in_mountlist (mountlist, 522 raidrec->data_disks.el[i].device); 523 if (smallest_partition > sp) 524 { 525 smallest_partition = sp; 526 } 527 } 528 total_size = smallest_partition * (noof_partitions - 1); 529 } 530 sprintf (tmp, "I have calculated %s's real size to be %ld", raid_device, 531 (long) total_size); 532 log_it (tmp); 533 return (total_size); 491 char tmp[MAX_STR_LEN]; 492 493 assert(mountlist != NULL); 494 assert(raidlist != NULL); 495 assert_string_is_neither_NULL_nor_zerolength(raid_device); 496 497 for (i = 0; 498 i < raidlist->entries 499 && strcmp(raidlist->el[i].raid_device, raid_device); i++); 500 if (i == raidlist->entries) { 501 sprintf(tmp, 502 "Cannot calc size of raid device %s - cannot find it in raidlist", 503 raid_device); 504 log_it(tmp); 505 return (999999999); 506 } 507 raidrec = &raidlist->el[i]; 508 noof_partitions = raidrec->data_disks.entries; 509 if (raidrec->raid_level == -1 || raidrec->raid_level == 0) { 510 for (total_size = 0, i = 0; i < noof_partitions; i++) { 511 total_size += 512 size_of_specific_device_in_mountlist(mountlist, 513 raidrec->data_disks. 514 el[i].device); 515 } 516 } else { 517 for (i = 0; i < noof_partitions; i++) { 518 sp = size_of_specific_device_in_mountlist(mountlist, 519 raidrec->data_disks. 520 el[i].device); 521 if (smallest_partition > sp) { 522 smallest_partition = sp; 523 } 524 } 525 total_size = smallest_partition * (noof_partitions - 1); 526 } 527 sprintf(tmp, "I have calculated %s's real size to be %ld", raid_device, 528 (long) total_size); 529 log_it(tmp); 530 return (total_size); 534 531 #endif 535 532 } … … 543 540 */ 544 541 void 545 choose_raid_level (struct OSSWAP (raid_device_record, vinum_plex) *raidrec)542 choose_raid_level(struct OSSWAP (raid_device_record, vinum_plex) * raidrec) 546 543 { 547 544 548 545 #ifdef __FreeBSD__ 549 546 550 547 /** int ***************************************************************/ 551 548 int res = 0; 552 549 int out = 0; 553 550 554 551 /** buffers ***********************************************************/ 555 char tmp[MAX_STR_LEN]; 556 char prompt[MAX_STR_LEN]; 557 char sz[MAX_STR_LEN]; 558 559 sprintf (prompt, "Please enter the RAID level you want. (concat, striped, raid5)"); 560 if (raidrec->raidlevel == -1) 561 { 562 strcpy (tmp, "concat"); 563 } 564 else if (raidrec->raidlevel == 0) 565 { 566 strcpy (tmp, "striped"); 567 } else { 568 sprintf (tmp, "raid%i", raidrec->raidlevel); 569 } 570 for (out = 999; out == 999;) 571 { 572 res = popup_and_get_string ("Specify RAID level", prompt, tmp, 10); 573 if (!res) 574 { 575 return; 576 } 577 strip_spaces (tmp); 578 if (tmp[0] == '[' && tmp[strlen (tmp) - 1] == ']') 579 { 580 strcpy (sz, tmp); 581 strncpy (tmp, sz + 1, strlen (sz) - 2); 582 tmp[strlen (sz) - 2] = '\0'; 583 } 584 if (!strcmp (tmp, "concat")) 585 { 586 out = -1; 587 } 588 else if (!strcmp (tmp, "striped")) 589 { 590 out = 0; 591 } 592 else if (!strcmp (tmp, "raid5")) 593 { 594 out = 5; 595 } 596 log_it (tmp); 597 if (is_this_raid_personality_registered (out)) 598 { 599 log_it 600 ("Groovy. You've picked a RAID personality which is registered."); 601 } 602 else 603 { 604 if (ask_me_yes_or_no 605 ("You have chosen a RAID personality which is not registered with the kernel. Make another selection?")) 606 { 607 out = 999; 608 } 609 } 610 } 611 raidrec->raidlevel = out; 552 char tmp[MAX_STR_LEN]; 553 char prompt[MAX_STR_LEN]; 554 char sz[MAX_STR_LEN]; 555 556 sprintf(prompt, 557 "Please enter the RAID level you want. (concat, striped, raid5)"); 558 if (raidrec->raidlevel == -1) { 559 strcpy(tmp, "concat"); 560 } else if (raidrec->raidlevel == 0) { 561 strcpy(tmp, "striped"); 562 } else { 563 sprintf(tmp, "raid%i", raidrec->raidlevel); 564 } 565 for (out = 999; out == 999;) { 566 res = popup_and_get_string("Specify RAID level", prompt, tmp, 10); 567 if (!res) { 568 return; 569 } 570 strip_spaces(tmp); 571 if (tmp[0] == '[' && tmp[strlen(tmp) - 1] == ']') { 572 strcpy(sz, tmp); 573 strncpy(tmp, sz + 1, strlen(sz) - 2); 574 tmp[strlen(sz) - 2] = '\0'; 575 } 576 if (!strcmp(tmp, "concat")) { 577 out = -1; 578 } else if (!strcmp(tmp, "striped")) { 579 out = 0; 580 } else if (!strcmp(tmp, "raid5")) { 581 out = 5; 582 } 583 log_it(tmp); 584 if (is_this_raid_personality_registered(out)) { 585 log_it 586 ("Groovy. You've picked a RAID personality which is registered."); 587 } else { 588 if (ask_me_yes_or_no 589 ("You have chosen a RAID personality which is not registered with the kernel. Make another selection?")) 590 { 591 out = 999; 592 } 593 } 594 } 595 raidrec->raidlevel = out; 612 596 #else 613 597 /** buffers ***********************************************************/ 614 598 char tmp[MAX_STR_LEN]; 615 599 char personalities[MAX_STR_LEN]; 616 600 char prompt[MAX_STR_LEN]; 617 601 char sz[MAX_STR_LEN]; 618 int out=0, res=0; 619 620 621 assert(raidrec!=NULL); 622 system 623 ("cat /proc/mdstat | grep Pers > /tmp/raid-personalities.txt 2> /dev/null"); 624 strcpy (personalities, last_line_of_file ("/tmp/raid-personalities.txt")); 625 sprintf (prompt, "Please enter the RAID level you want. %s", personalities); 626 if (raidrec->raid_level == -1) 627 { 628 strcpy (tmp, "linear"); 629 } 630 else 631 { 632 sprintf (tmp, "%d", raidrec->raid_level); 633 } 634 for (out = 999; 635 out != -1 && out != 0 && out != 1 && out != 4 && out != 5 636 && out != 10;) 637 { 638 res = popup_and_get_string ("Specify RAID level", prompt, tmp, 10); 639 if (!res) 640 { 641 return; 642 } 643 strip_spaces (tmp); 644 if (tmp[0] == '[' && tmp[strlen (tmp) - 1] == ']') 645 { 646 strcpy (sz, tmp); 647 strncpy (tmp, sz + 1, strlen (sz) - 2); 648 tmp[strlen (sz) - 2] = '\0'; 649 } 650 if (!strcmp (tmp, "linear")) 651 { 652 out = -1; 653 } 654 else if (!strncmp (tmp, "raid", 4)) 655 { 656 out = atoi (tmp + 4); 657 } 658 else 659 { 660 out = atoi (tmp); 661 } 662 log_it (tmp); 663 if (is_this_raid_personality_registered (out)) 664 { 665 log_it 666 ("Groovy. You've picked a RAID personality which is registered."); 667 } 668 else 669 { 670 if (ask_me_yes_or_no 671 ("You have chosen a RAID personality which is not registered with the kernel. Make another selection?")) 672 { 673 out = 999; 674 } 675 } 676 } 677 raidrec->raid_level = out; 602 int out = 0, res = 0; 603 604 605 assert(raidrec != NULL); 606 system 607 ("cat /proc/mdstat | grep Pers > /tmp/raid-personalities.txt 2> /dev/null"); 608 strcpy(personalities, 609 last_line_of_file("/tmp/raid-personalities.txt")); 610 sprintf(prompt, "Please enter the RAID level you want. %s", 611 personalities); 612 if (raidrec->raid_level == -1) { 613 strcpy(tmp, "linear"); 614 } else { 615 sprintf(tmp, "%d", raidrec->raid_level); 616 } 617 for (out = 999; 618 out != -1 && out != 0 && out != 1 && out != 4 && out != 5 619 && out != 10;) { 620 res = popup_and_get_string("Specify RAID level", prompt, tmp, 10); 621 if (!res) { 622 return; 623 } 624 strip_spaces(tmp); 625 if (tmp[0] == '[' && tmp[strlen(tmp) - 1] == ']') { 626 strcpy(sz, tmp); 627 strncpy(tmp, sz + 1, strlen(sz) - 2); 628 tmp[strlen(sz) - 2] = '\0'; 629 } 630 if (!strcmp(tmp, "linear")) { 631 out = -1; 632 } else if (!strncmp(tmp, "raid", 4)) { 633 out = atoi(tmp + 4); 634 } else { 635 out = atoi(tmp); 636 } 637 log_it(tmp); 638 if (is_this_raid_personality_registered(out)) { 639 log_it 640 ("Groovy. You've picked a RAID personality which is registered."); 641 } else { 642 if (ask_me_yes_or_no 643 ("You have chosen a RAID personality which is not registered with the kernel. Make another selection?")) 644 { 645 out = 999; 646 } 647 } 648 } 649 raidrec->raid_level = out; 678 650 #endif 679 651 } … … 690 662 */ 691 663 void 692 del_partns_listed_in_disklist 693 694 664 del_partns_listed_in_disklist(struct mountlist_itself *mountlist, 665 struct raidlist_itself *raidlist, 666 struct list_of_disks *disklist) 695 667 { 696 668 697 669 /** int ***************************************************************/ 698 670 int i = 0; 699 671 int pos = 0; 700 672 701 673 /** buffers ***********************************************************/ 702 char tmp[MAX_STR_LEN]; 703 704 assert(mountlist!=NULL); 705 assert(raidlist!=NULL); 706 assert(disklist!=NULL); 707 708 for (i = 0; i < disklist->entries; i++) 709 { 710 for (pos = 0; 711 pos < mountlist->entries 712 && strcmp (mountlist->el[pos].device, disklist->el[i].device); 713 pos++); 714 if (pos < mountlist->entries) 715 { 716 sprintf (tmp, 717 "Deleting partition %s cos it was part of a now-defunct RAID", 718 mountlist->el[pos].device); 719 log_it (tmp); 720 memcpy ((void *) &mountlist->el[pos], 721 (void *) &mountlist->el[mountlist->entries - 1], 722 sizeof (struct mountlist_line)); 723 mountlist->entries--; 724 } 725 } 674 char tmp[MAX_STR_LEN]; 675 676 assert(mountlist != NULL); 677 assert(raidlist != NULL); 678 assert(disklist != NULL); 679 680 for (i = 0; i < disklist->entries; i++) { 681 for (pos = 0; 682 pos < mountlist->entries 683 && strcmp(mountlist->el[pos].device, disklist->el[i].device); 684 pos++); 685 if (pos < mountlist->entries) { 686 sprintf(tmp, 687 "Deleting partition %s cos it was part of a now-defunct RAID", 688 mountlist->el[pos].device); 689 log_it(tmp); 690 memcpy((void *) &mountlist->el[pos], 691 (void *) &mountlist->el[mountlist->entries - 1], 692 sizeof(struct mountlist_line)); 693 mountlist->entries--; 694 } 695 } 726 696 } 727 697 … … 737 707 */ 738 708 void 739 delete_disklist_entry 740 709 delete_disklist_entry(struct list_of_disks *disklist, char *raid_device, 710 int currline) 741 711 { 742 712 743 713 /** int ***************************************************************/ 744 714 int pos = 0; 745 715 746 716 /** buffers ***********************************************************/ 747 char tmp[MAX_STR_LEN]; 748 749 assert(disklist!=NULL); 750 assert_string_is_neither_NULL_nor_zerolength(raid_device); 751 752 sprintf (tmp, "Delete %s from RAID device %s - are you sure?", 753 disklist->el[currline].device, raid_device); 754 if (!ask_me_yes_or_no (tmp)) 755 { 756 return; 757 } 758 for (pos = currline; pos < disklist->entries - 1; pos++) 759 { 760 /* memcpy((void*)&disklist->el[pos], (void*)&disklist->el[pos+1], sizeof(struct s_disk)); */ 761 strcpy (disklist->el[pos].device, disklist->el[pos + 1].device); 762 } 763 disklist->entries--; 717 char tmp[MAX_STR_LEN]; 718 719 assert(disklist != NULL); 720 assert_string_is_neither_NULL_nor_zerolength(raid_device); 721 722 sprintf(tmp, "Delete %s from RAID device %s - are you sure?", 723 disklist->el[currline].device, raid_device); 724 if (!ask_me_yes_or_no(tmp)) { 725 return; 726 } 727 for (pos = currline; pos < disklist->entries - 1; pos++) { 728 /* memcpy((void*)&disklist->el[pos], (void*)&disklist->el[pos+1], sizeof(struct s_disk)); */ 729 strcpy(disklist->el[pos].device, disklist->el[pos + 1].device); 730 } 731 disklist->entries--; 764 732 } 765 733 … … 776 744 */ 777 745 void 778 delete_mountlist_entry (struct mountlist_itself *mountlist, 779 struct raidlist_itself *raidlist, 780 newtComponent listbox, int currline, void *keylist[]) 746 delete_mountlist_entry(struct mountlist_itself *mountlist, 747 struct raidlist_itself *raidlist, 748 newtComponent listbox, int currline, 749 void *keylist[]) 781 750 { 782 751 783 752 /** int ***************************************************************/ 784 753 int pos = 0; 785 754 786 755 /** buffers ***********************************************************/ 787 756 char tmp[MAX_STR_LEN]; 788 757 char device[MAX_STR_LEN]; 789 758 790 759 791 assert(mountlist!=NULL); 792 assert(raidlist!=NULL); 793 assert(listbox!=NULL); 794 assert(keylist!=NULL); 795 796 pos = 797 which_raid_device_is_using_this_partition (raidlist, 798 mountlist->el[currline]. 799 device); 800 if (pos >= 0) 801 { 802 sprintf (tmp, "Cannot delete %s: it is in use by RAID device %s", 803 mountlist->el[currline].device, raidlist->el[pos].OSSWAP (raid_device, volname)); 804 popup_and_OK (tmp); 805 return; 806 } 807 sprintf (tmp, "Delete %s - are you sure?", mountlist->el[currline].device); 808 if (!ask_me_yes_or_no (tmp)) 809 { 810 return; 811 } 812 if (strstr (mountlist->el[currline].device, RAID_DEVICE_STUB)) 813 { 814 strcpy (device, mountlist->el[currline].device); 815 delete_raidlist_entry (mountlist, raidlist, device); 816 for (currline = 0; 817 currline < mountlist->entries 818 && strcmp (mountlist->el[currline].device, device); currline++); 819 if (currline == mountlist->entries) 820 { 821 log_it ("Dev is gone. I can't delete it. Ho-hum"); 822 return; 823 } 824 } 825 memcpy ((void *) &mountlist->el[currline], 826 (void *) &mountlist->el[mountlist->entries - 1], 827 sizeof (struct mountlist_line)); 828 mountlist->entries--; 829 redraw_mountlist (mountlist, keylist, listbox); 760 assert(mountlist != NULL); 761 assert(raidlist != NULL); 762 assert(listbox != NULL); 763 assert(keylist != NULL); 764 765 pos = 766 which_raid_device_is_using_this_partition(raidlist, 767 mountlist->el[currline]. 768 device); 769 if (pos >= 0) { 770 sprintf(tmp, "Cannot delete %s: it is in use by RAID device %s", 771 mountlist->el[currline].device, 772 raidlist->el[pos].OSSWAP(raid_device, volname)); 773 popup_and_OK(tmp); 774 return; 775 } 776 sprintf(tmp, "Delete %s - are you sure?", 777 mountlist->el[currline].device); 778 if (!ask_me_yes_or_no(tmp)) { 779 return; 780 } 781 if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)) { 782 strcpy(device, mountlist->el[currline].device); 783 delete_raidlist_entry(mountlist, raidlist, device); 784 for (currline = 0; 785 currline < mountlist->entries 786 && strcmp(mountlist->el[currline].device, device); 787 currline++); 788 if (currline == mountlist->entries) { 789 log_it("Dev is gone. I can't delete it. Ho-hum"); 790 return; 791 } 792 } 793 memcpy((void *) &mountlist->el[currline], 794 (void *) &mountlist->el[mountlist->entries - 1], 795 sizeof(struct mountlist_line)); 796 mountlist->entries--; 797 redraw_mountlist(mountlist, keylist, listbox); 830 798 } 831 799 … … 839 807 */ 840 808 void 841 delete_raidlist_entry 842 843 { 844 809 delete_raidlist_entry(struct mountlist_itself *mountlist, 810 struct raidlist_itself *raidlist, char *device) 811 { 812 845 813 /** int ***************************************************************/ 846 847 int items = 0;814 int i = 0; 815 int items = 0; 848 816 849 817 /** bool **************************************************************/ 850 818 bool delete_partitions_too; 851 819 852 820 /** buffers ***********************************************************/ 853 char tmp[MAX_STR_LEN]; 854 855 assert(mountlist!=NULL); 856 assert(raidlist!=NULL); 857 assert_string_is_neither_NULL_nor_zerolength(device); 858 859 i = find_raid_device_in_raidlist (raidlist, device); 860 if (i < 0) 861 { 862 return; 863 } 864 sprintf (tmp, "Do you want me to delete %s's partitions, too?", device); 865 delete_partitions_too = ask_me_yes_or_no (tmp); 866 if (delete_partitions_too) 867 { 821 char tmp[MAX_STR_LEN]; 822 823 assert(mountlist != NULL); 824 assert(raidlist != NULL); 825 assert_string_is_neither_NULL_nor_zerolength(device); 826 827 i = find_raid_device_in_raidlist(raidlist, device); 828 if (i < 0) { 829 return; 830 } 831 sprintf(tmp, "Do you want me to delete %s's partitions, too?", device); 832 delete_partitions_too = ask_me_yes_or_no(tmp); 833 if (delete_partitions_too) { 868 834 #ifdef __FreeBSD__ 869 // static so it's zeroed 870 static struct list_of_disks d; 871 int x, y, z; 872 873 for (x = 0; x < raidlist->el[i].plexes; ++x) { 874 for (y = 0; y < raidlist->el[i].plex[x].subdisks; ++y) { 875 for (z = 0; z < raidlist->disks.entries; ++z) { 876 if (!strcmp (raidlist->el[i].plex[x].sd[y].which_device, 877 raidlist->disks.el[z].name)) { 878 strcpy (d.el [d.entries ].name, raidlist->disks.el[z].name); 879 strcpy (d.el [d.entries++].device, raidlist->disks.el[z].device); 880 } 881 } 882 } 883 } 884 885 del_partns_listed_in_disklist (mountlist, raidlist, &d); 835 // static so it's zeroed 836 static struct list_of_disks d; 837 int x, y, z; 838 839 for (x = 0; x < raidlist->el[i].plexes; ++x) { 840 for (y = 0; y < raidlist->el[i].plex[x].subdisks; ++y) { 841 for (z = 0; z < raidlist->disks.entries; ++z) { 842 if (!strcmp(raidlist->el[i].plex[x].sd[y].which_device, 843 raidlist->disks.el[z].name)) { 844 strcpy(d.el[d.entries].name, 845 raidlist->disks.el[z].name); 846 strcpy(d.el[d.entries++].device, 847 raidlist->disks.el[z].device); 848 } 849 } 850 } 851 } 852 853 del_partns_listed_in_disklist(mountlist, raidlist, &d); 886 854 #else 887 del_partns_listed_in_disklist(mountlist, raidlist,888 889 del_partns_listed_in_disklist(mountlist, raidlist,890 891 del_partns_listed_in_disklist(mountlist, raidlist,892 893 del_partns_listed_in_disklist(mountlist, raidlist,894 855 del_partns_listed_in_disklist(mountlist, raidlist, 856 &raidlist->el[i].data_disks); 857 del_partns_listed_in_disklist(mountlist, raidlist, 858 &raidlist->el[i].spare_disks); 859 del_partns_listed_in_disklist(mountlist, raidlist, 860 &raidlist->el[i].parity_disks); 861 del_partns_listed_in_disklist(mountlist, raidlist, 862 &raidlist->el[i].failed_disks); 895 863 #endif 896 } 897 items = raidlist->entries; 898 if (items == 1) 899 { 900 items = 0; 901 } 902 else 903 { 904 log_it (tmp); 905 memcpy ((void *) &raidlist->el[i], (void *) &raidlist->el[items - 1], 906 sizeof (struct OSSWAP(raid_device_record, vinum_volume))); 907 items--; 908 } 909 raidlist->entries = items; 864 } 865 items = raidlist->entries; 866 if (items == 1) { 867 items = 0; 868 } else { 869 log_it(tmp); 870 memcpy((void *) &raidlist->el[i], 871 (void *) &raidlist->el[items - 1], 872 sizeof(struct OSSWAP (raid_device_record, vinum_volume))); 873 items--; 874 } 875 raidlist->entries = items; 910 876 } 911 877 … … 918 884 * @ingroup restoreGuiVarslist 919 885 */ 920 void 921 delete_varslist_entry (struct raid_device_record *raidrec, int lino) 886 void delete_varslist_entry(struct raid_device_record *raidrec, int lino) 922 887 { 923 888 924 889 /** buffers ************************************************************/ 925 890 char tmp[MAX_STR_LEN]; 926 891 927 892 /** structures *********************************************************/ 928 struct additional_raid_variables *av; 929 930 assert(raidrec!=NULL); 931 932 av = &raidrec->additional_vars; 933 sprintf (tmp, "Delete %s - are you sure?", av->el[lino].label); 934 if (ask_me_yes_or_no (tmp)) 935 { 936 if (!strcmp (av->el[lino].label, "persistent-superblock") 937 || !strcmp (av->el[lino].label, "chunk-size")) 938 { 939 sprintf (tmp, "%s must not be deleted. It would be bad.", 940 av->el[lino].label); 941 popup_and_OK (tmp); 942 } 943 else 944 { 945 memcpy ((void *) &av->el[lino], (void *) &av->el[av->entries--], 946 sizeof (struct raid_var_line)); 947 } 948 } 893 struct additional_raid_variables *av; 894 895 assert(raidrec != NULL); 896 897 av = &raidrec->additional_vars; 898 sprintf(tmp, "Delete %s - are you sure?", av->el[lino].label); 899 if (ask_me_yes_or_no(tmp)) { 900 if (!strcmp(av->el[lino].label, "persistent-superblock") 901 || !strcmp(av->el[lino].label, "chunk-size")) { 902 sprintf(tmp, "%s must not be deleted. It would be bad.", 903 av->el[lino].label); 904 popup_and_OK(tmp); 905 } else { 906 memcpy((void *) &av->el[lino], (void *) &av->el[av->entries--], 907 sizeof(struct raid_var_line)); 908 } 909 } 949 910 } 950 911 #endif … … 960 921 */ 961 922 int 962 redraw_filelist 963 923 redraw_filelist(struct s_node *filelist, void *keylist[ARBITRARY_MAXIMUM], 924 newtComponent listbox) 964 925 { 965 926 966 927 /** int ***************************************************************/ 967 968 969 928 static int lines_in_flist_window = 0; 929 static int depth = 0; 930 int i = 0; 970 931 971 932 /** structures *******************************************************/ 972 933 struct s_node *node; 973 934 974 935 /** buffers **********************************************************/ 975 976 936 static char current_filename[MAX_STR_LEN]; 937 char tmp[MAX_STR_LEN + 2]; 977 938 978 939 /** bool *************************************************************/ 979 940 /* void*dummyptr; */ 980 bool dummybool; 981 static bool warned_already; 982 983 assert(filelist!=NULL); 984 assert(keylist!=NULL); 985 assert(listbox!=NULL); 986 987 988 if (depth == 0) 989 { 990 lines_in_flist_window = 0; 991 warned_already = FALSE; 992 for (i = 0; i < ARBITRARY_MAXIMUM; i++) 993 { 994 g_strings_of_flist_window[i][0] = '\0'; 995 g_is_path_selected[i] = FALSE; 996 } 997 } 998 for (node = filelist; node != NULL; node = node->right) 999 { 1000 current_filename[depth] = node->ch; 1001 if (node->down) 1002 { 1003 depth++; 1004 i = redraw_filelist (node->down, keylist, listbox); 1005 depth--; 1006 } 1007 if (node->ch == '\0' && node->expanded) 1008 { 1009 if (lines_in_flist_window == ARBITRARY_MAXIMUM) 1010 { 1011 if (!warned_already) 1012 { 1013 warned_already = TRUE; 1014 sprintf (tmp, 1015 "Too many lines. Displaying first %d entries only. Close a directory to see more.", 1016 ARBITRARY_MAXIMUM); 1017 popup_and_OK (tmp); 1018 } 1019 } 1020 else 1021 { 1022 strcpy (g_strings_of_flist_window[lines_in_flist_window], 1023 current_filename); 1024 g_is_path_selected[lines_in_flist_window] = node->selected; 1025 lines_in_flist_window++; 1026 } 1027 } 1028 } 1029 if (depth == 0) 1030 { 1031 if (lines_in_flist_window > ARBITRARY_MAXIMUM) 1032 { 1033 lines_in_flist_window = ARBITRARY_MAXIMUM; 1034 } 941 bool dummybool; 942 static bool warned_already; 943 944 assert(filelist != NULL); 945 assert(keylist != NULL); 946 assert(listbox != NULL); 947 948 949 if (depth == 0) { 950 lines_in_flist_window = 0; 951 warned_already = FALSE; 952 for (i = 0; i < ARBITRARY_MAXIMUM; i++) { 953 g_strings_of_flist_window[i][0] = '\0'; 954 g_is_path_selected[i] = FALSE; 955 } 956 } 957 for (node = filelist; node != NULL; node = node->right) { 958 current_filename[depth] = node->ch; 959 if (node->down) { 960 depth++; 961 i = redraw_filelist(node->down, keylist, listbox); 962 depth--; 963 } 964 if (node->ch == '\0' && node->expanded) { 965 if (lines_in_flist_window == ARBITRARY_MAXIMUM) { 966 if (!warned_already) { 967 warned_already = TRUE; 968 sprintf(tmp, 969 "Too many lines. Displaying first %d entries only. Close a directory to see more.", 970 ARBITRARY_MAXIMUM); 971 popup_and_OK(tmp); 972 } 973 } else { 974 strcpy(g_strings_of_flist_window[lines_in_flist_window], 975 current_filename); 976 g_is_path_selected[lines_in_flist_window] = node->selected; 977 lines_in_flist_window++; 978 } 979 } 980 } 981 if (depth == 0) { 982 if (lines_in_flist_window > ARBITRARY_MAXIMUM) { 983 lines_in_flist_window = ARBITRARY_MAXIMUM; 984 } 1035 985 /* do an elementary sort */ 1036 for (i = 1; i < lines_in_flist_window; i++) 1037 { 1038 if (strcmp 1039 (g_strings_of_flist_window[i], 1040 g_strings_of_flist_window[i - 1]) < 0) 1041 { 1042 strcpy (tmp, g_strings_of_flist_window[i]); 1043 strcpy (g_strings_of_flist_window[i], 1044 g_strings_of_flist_window[i - 1]); 1045 strcpy (g_strings_of_flist_window[i - 1], tmp); 1046 dummybool = g_is_path_selected[i]; 1047 g_is_path_selected[i] = g_is_path_selected[i - 1]; 1048 g_is_path_selected[i - 1] = dummybool; 1049 i = 0; 1050 } 1051 } 986 for (i = 1; i < lines_in_flist_window; i++) { 987 if (strcmp 988 (g_strings_of_flist_window[i], 989 g_strings_of_flist_window[i - 1]) < 0) { 990 strcpy(tmp, g_strings_of_flist_window[i]); 991 strcpy(g_strings_of_flist_window[i], 992 g_strings_of_flist_window[i - 1]); 993 strcpy(g_strings_of_flist_window[i - 1], tmp); 994 dummybool = g_is_path_selected[i]; 995 g_is_path_selected[i] = g_is_path_selected[i - 1]; 996 g_is_path_selected[i - 1] = dummybool; 997 i = 0; 998 } 999 } 1052 1000 /* write list to screen */ 1053 newtListboxClear (listbox); 1054 for (i = 0; i < lines_in_flist_window; i++) 1055 { 1056 sprintf (tmp, "%c%c %-80s", (g_is_path_selected[i] ? '*' : ' '), 1057 (g_is_path_expanded[i] ? '+' : '-'), 1058 strip_path(g_strings_of_flist_window[i])); 1059 tmp[70] = '\0'; 1060 keylist[i] = (void *) i; 1061 newtListboxAppendEntry (listbox, tmp, keylist[i]); 1062 } 1063 return (lines_in_flist_window); 1064 } 1065 else 1066 { 1067 return (0); 1068 } 1001 newtListboxClear(listbox); 1002 for (i = 0; i < lines_in_flist_window; i++) { 1003 sprintf(tmp, "%c%c %-80s", (g_is_path_selected[i] ? '*' : ' '), 1004 (g_is_path_expanded[i] ? '+' : '-'), 1005 strip_path(g_strings_of_flist_window[i])); 1006 tmp[70] = '\0'; 1007 keylist[i] = (void *) i; 1008 newtListboxAppendEntry(listbox, tmp, keylist[i]); 1009 } 1010 return (lines_in_flist_window); 1011 } else { 1012 return (0); 1013 } 1069 1014 } 1070 1015 … … 1077 1022 * @ingroup restoreUtilityGroup 1078 1023 */ 1079 char *strip_path(char *tmp) 1024 char *strip_path(char *tmp) 1080 1025 { 1081 1026 … … 1083 1028 int slashloc = 0, lastslashloc = 0; 1084 1029 1085 while(tmp[i] != '\0') 1086 { /* Count the slashes in tmp 1087 1 slash per dir */ 1088 if( tmp[i] == '/') 1089 { 1090 slashcount++; 1091 lastslashloc = slashloc; 1092 slashloc = i; 1093 if(tmp[i + 1] == '\0') 1094 { /* if this slash is last char, back off */ 1095 slashcount--; 1096 slashloc = lastslashloc; 1097 } 1098 } 1099 i++; 1100 } 1101 if(slashcount > 0) slashcount--; /* Keep one slash 'cos Hugh does... */ 1102 1103 for(i=0; i<slashcount; i++) 1104 { /* Replace each dir with a space char */ 1105 tmpnopath[i] = ' '; 1030 while (tmp[i] != '\0') { /* Count the slashes in tmp 1031 1 slash per dir */ 1032 if (tmp[i] == '/') { 1033 slashcount++; 1034 lastslashloc = slashloc; 1035 slashloc = i; 1036 if (tmp[i + 1] == '\0') { /* if this slash is last char, back off */ 1037 slashcount--; 1038 slashloc = lastslashloc; 1039 } 1040 } 1041 i++; 1042 } 1043 if (slashcount > 0) 1044 slashcount--; /* Keep one slash 'cos Hugh does... */ 1045 1046 for (i = 0; i < slashcount; i++) { /* Replace each dir with a space char */ 1047 tmpnopath[i] = ' '; 1106 1048 } 1107 1049 1108 1050 i = slashloc; 1109 1051 j = slashcount; 1110 while(tmp[i] != '\0') 1111 { /* Now add what's left of tmp */ 1112 if( (tmpprevpath[j] == ' ' || tmpprevpath[j] == '^') 1113 && tmp[i] == '/' 1114 && tmpnopath[j - 1] != '^' 1115 && j != 0) 1116 { /* Add a pointer upwards if this is not in the same dir as line above */ 1117 tmpnopath[j - 1] = '^'; 1118 } else { 1119 tmpnopath[j++] = tmp[i++]; 1120 } 1052 while (tmp[i] != '\0') { /* Now add what's left of tmp */ 1053 if ((tmpprevpath[j] == ' ' || tmpprevpath[j] == '^') 1054 && tmp[i] == '/' && tmpnopath[j - 1] != '^' && j != 0) { /* Add a pointer upwards if this is not in the same dir as line above */ 1055 tmpnopath[j - 1] = '^'; 1056 } else { 1057 tmpnopath[j++] = tmp[i++]; 1058 } 1121 1059 } 1122 1060 tmpnopath[j] = '\0'; 1123 1061 1124 strcpy(tmpprevpath, tmpnopath); 1125 1126 return (tmpnopath);1062 strcpy(tmpprevpath, tmpnopath); /* Make a copy for next iteration */ 1063 1064 return (tmpnopath); 1127 1065 } 1128 1066 … … 1133 1071 * @return 0 if the user pressed OK, 1 if they pressed Cancel. 1134 1072 */ 1135 int 1136 edit_filelist (struct s_node *filelist) 1073 int edit_filelist(struct s_node *filelist) 1137 1074 { 1138 1075 1139 1076 /** newt **************************************************************/ 1140 1141 newtComponent bLess =NULL;1142 newtComponent bMore =NULL;1143 newtComponent bToggle =NULL;1144 newtComponent bOK =NULL;1145 newtComponent bCancel =NULL;1146 newtComponent b_res =NULL;1147 newtComponent filelistListbox =NULL;1148 newtComponent bRegex =NULL;1077 newtComponent myForm; 1078 newtComponent bLess = NULL; 1079 newtComponent bMore = NULL; 1080 newtComponent bToggle = NULL; 1081 newtComponent bOK = NULL; 1082 newtComponent bCancel = NULL; 1083 newtComponent b_res = NULL; 1084 newtComponent filelistListbox = NULL; 1085 newtComponent bRegex = NULL; 1149 1086 1150 1087 /** int ***************************************************************/ … … 1155 1092 1156 1093 /** ???? **************************************************************/ 1157 1158 1094 void *curr_choice; 1095 void *keylist[ARBITRARY_MAXIMUM]; 1159 1096 1160 1097 /** buffers ***********************************************************/ 1161 1098 char tmp[MAX_STR_LEN]; 1162 1099 1163 1100 /** bool **************************************************************/ 1164 1101 bool dummybool; 1165 1102 1166 1103 /* struct s_node *node; */ 1167 1104 1168 assert(filelist!=NULL); 1169 1170 log_to_screen ("Editing filelist"); 1171 newtPushHelpLine 1172 (" Please edit the filelist to your satisfaction, then click OK or Cancel."); 1173 j = 4; 1174 bLess = newtCompactButton (j, 17, " Less "); 1175 bMore = newtCompactButton (j += 12, 17, " More "); 1176 bToggle = newtCompactButton (j += 12, 17, "Toggle"); 1177 bRegex = newtCompactButton (j += 12, 17, "RegEx"); 1178 bCancel = newtCompactButton (j += 12, 17, "Cancel"); 1179 bOK = newtCompactButton (j += 12, 17, " OK "); 1180 filelistListbox = 1181 newtListbox (2, 1, 15, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 1182 toggle_all_root_dirs_on (filelist); 1183 lines_in_flist_window = 1184 redraw_filelist (filelist, keylist, filelistListbox); 1185 newtOpenWindow (1, 3, 77, 18, "Editing filelist"); 1186 myForm = newtForm (NULL, NULL, 0); 1187 newtFormAddComponents (myForm, filelistListbox, bLess, bMore, bToggle, 1188 bRegex, bCancel, bOK, NULL); 1189 while (!finished) 1190 { 1191 b_res = newtRunForm (myForm); 1192 if (b_res == bOK) 1193 { 1194 finished = 1195 ask_me_yes_or_no ("Are you happy with your file selection?"); 1196 } 1197 else if (b_res == bCancel) 1198 { 1199 finished = TRUE; 1200 } 1201 else if (b_res == bRegex) 1202 { 1203 popup_and_OK ("I haven't implemented this yet..."); 1204 } 1205 else 1206 { 1207 curr_choice = newtListboxGetCurrent (filelistListbox); 1208 for (indexno = 0; 1209 indexno < lines_in_flist_window 1210 && keylist[indexno] != curr_choice; indexno++); 1211 if (indexno == lines_in_flist_window) 1212 { 1213 log_it 1214 ("I don't know what this button does; assuming I am to toggle 1st entry"); 1215 indexno = 0; 1216 } 1217 sprintf (tmp, "You selected '%s'", 1218 g_strings_of_flist_window[indexno]); 1219 log_it (tmp); 1220 if (b_res == bMore) 1221 { 1222 g_is_path_expanded[indexno] = TRUE; 1223 toggle_path_expandability (filelist, 1224 g_strings_of_flist_window[indexno], 1225 TRUE); 1226 lines_in_flist_window = 1227 redraw_filelist (filelist, keylist, filelistListbox); 1228 newtListboxSetCurrentByKey (filelistListbox, curr_choice); 1229 } 1230 else if (b_res == bLess) 1231 { 1232 g_is_path_expanded[indexno] = FALSE; 1233 toggle_path_expandability (filelist, 1234 g_strings_of_flist_window[indexno], 1235 FALSE); 1236 lines_in_flist_window = 1237 redraw_filelist (filelist, keylist, filelistListbox); 1238 newtListboxSetCurrentByKey (filelistListbox, curr_choice); 1239 } 1240 else 1241 { 1242 if (!strcmp (g_strings_of_flist_window[indexno], "/")) 1243 { 1244 dummybool = !g_is_path_selected[indexno]; 1245 for (j = 1; j < lines_in_flist_window; j++) 1246 { 1247 toggle_path_selection (filelist, 1248 g_strings_of_flist_window[j], 1249 dummybool); 1250 } 1251 } 1252 else 1253 { 1254 toggle_path_selection (filelist, 1255 g_strings_of_flist_window[indexno], 1256 !g_is_path_selected[indexno]); 1257 lines_in_flist_window = 1258 redraw_filelist (filelist, keylist, filelistListbox); 1259 } 1260 newtListboxSetCurrentByKey (filelistListbox, curr_choice); 1261 } 1262 for (indexno = 0; 1263 indexno < lines_in_flist_window 1264 && keylist[indexno] != curr_choice; indexno++); 1265 if (indexno == lines_in_flist_window) 1266 { 1267 log_it 1268 ("Layout of table has changed. Y pointer is reverting to zero."); 1269 indexno = 0; 1270 } 1271 } 1272 } 1273 newtFormDestroy (myForm); 1274 newtPopWindow (); 1275 newtPopHelpLine (); 1276 if (b_res == bOK) 1277 { 1278 return (0); 1279 } 1280 else 1281 { 1105 assert(filelist != NULL); 1106 1107 log_to_screen("Editing filelist"); 1108 newtPushHelpLine 1109 (" Please edit the filelist to your satisfaction, then click OK or Cancel."); 1110 j = 4; 1111 bLess = newtCompactButton(j, 17, " Less "); 1112 bMore = newtCompactButton(j += 12, 17, " More "); 1113 bToggle = newtCompactButton(j += 12, 17, "Toggle"); 1114 bRegex = newtCompactButton(j += 12, 17, "RegEx"); 1115 bCancel = newtCompactButton(j += 12, 17, "Cancel"); 1116 bOK = newtCompactButton(j += 12, 17, " OK "); 1117 filelistListbox = 1118 newtListbox(2, 1, 15, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 1119 toggle_all_root_dirs_on(filelist); 1120 lines_in_flist_window = 1121 redraw_filelist(filelist, keylist, filelistListbox); 1122 newtOpenWindow(1, 3, 77, 18, "Editing filelist"); 1123 myForm = newtForm(NULL, NULL, 0); 1124 newtFormAddComponents(myForm, filelistListbox, bLess, bMore, bToggle, 1125 bRegex, bCancel, bOK, NULL); 1126 while (!finished) { 1127 b_res = newtRunForm(myForm); 1128 if (b_res == bOK) { 1129 finished = 1130 ask_me_yes_or_no 1131 ("Are you happy with your file selection?"); 1132 } else if (b_res == bCancel) { 1133 finished = TRUE; 1134 } else if (b_res == bRegex) { 1135 popup_and_OK("I haven't implemented this yet..."); 1136 } else { 1137 curr_choice = newtListboxGetCurrent(filelistListbox); 1138 for (indexno = 0; 1139 indexno < lines_in_flist_window 1140 && keylist[indexno] != curr_choice; indexno++); 1141 if (indexno == lines_in_flist_window) { 1142 log_it 1143 ("I don't know what this button does; assuming I am to toggle 1st entry"); 1144 indexno = 0; 1145 } 1146 sprintf(tmp, "You selected '%s'", 1147 g_strings_of_flist_window[indexno]); 1148 log_it(tmp); 1149 if (b_res == bMore) { 1150 g_is_path_expanded[indexno] = TRUE; 1151 toggle_path_expandability(filelist, 1152 g_strings_of_flist_window 1153 [indexno], TRUE); 1154 lines_in_flist_window = 1155 redraw_filelist(filelist, keylist, filelistListbox); 1156 newtListboxSetCurrentByKey(filelistListbox, curr_choice); 1157 } else if (b_res == bLess) { 1158 g_is_path_expanded[indexno] = FALSE; 1159 toggle_path_expandability(filelist, 1160 g_strings_of_flist_window 1161 [indexno], FALSE); 1162 lines_in_flist_window = 1163 redraw_filelist(filelist, keylist, filelistListbox); 1164 newtListboxSetCurrentByKey(filelistListbox, curr_choice); 1165 } else { 1166 if (!strcmp(g_strings_of_flist_window[indexno], "/")) { 1167 dummybool = !g_is_path_selected[indexno]; 1168 for (j = 1; j < lines_in_flist_window; j++) { 1169 toggle_path_selection(filelist, 1170 g_strings_of_flist_window[j], 1171 dummybool); 1172 } 1173 } else { 1174 toggle_path_selection(filelist, 1175 g_strings_of_flist_window 1176 [indexno], 1177 !g_is_path_selected[indexno]); 1178 lines_in_flist_window = 1179 redraw_filelist(filelist, keylist, 1180 filelistListbox); 1181 } 1182 newtListboxSetCurrentByKey(filelistListbox, curr_choice); 1183 } 1184 for (indexno = 0; 1185 indexno < lines_in_flist_window 1186 && keylist[indexno] != curr_choice; indexno++); 1187 if (indexno == lines_in_flist_window) { 1188 log_it 1189 ("Layout of table has changed. Y pointer is reverting to zero."); 1190 indexno = 0; 1191 } 1192 } 1193 } 1194 newtFormDestroy(myForm); 1195 newtPopWindow(); 1196 newtPopHelpLine(); 1197 if (b_res == bOK) { 1198 return (0); 1199 } else { 1282 1200 /* popup_and_OK("You pushed 'cancel'. I shall now abort."); */ 1283 1284 1201 return (1); 1202 } 1285 1203 } 1286 1204 … … 1296 1214 */ 1297 1215 void 1298 edit_mountlist_entry 1299 struct raidlist_itself *raidlist, newtComponent listbox,1300 1216 edit_mountlist_entry(struct mountlist_itself *mountlist, 1217 struct raidlist_itself *raidlist, 1218 newtComponent listbox, int currline, void *keylist[]) 1301 1219 { 1302 1220 1303 1221 /** structures ********************************************************/ 1304 1222 static struct raidlist_itself bkp_raidlist; 1305 1223 1306 1224 /** newt **************************************************************/ 1307 1225 newtComponent myForm; 1308 1226 newtComponent bOK; 1309 1227 newtComponent bCancel; … … 1324 1242 char size_str[MAX_STR_LEN]; 1325 1243 char format_str[MAX_STR_LEN]; 1326 1327 1244 char tmp[MAX_STR_LEN]; 1245 char device_used_to_be[MAX_STR_LEN]; 1328 1246 char mountpt_used_to_be[MAX_STR_LEN]; 1329 1247 … … 1335 1253 1336 1254 /** int ***************************************************************/ 1337 int j = 0; 1338 1339 assert(mountlist!=NULL); 1340 assert(raidlist!=NULL); 1341 assert(listbox!=NULL); 1342 assert(keylist!=NULL); 1343 1344 memcpy ((void *) &bkp_raidlist, (void *) raidlist, 1345 sizeof (struct raidlist_itself)); 1346 strcpy (device_str, mountlist->el[currline].device); 1347 strcpy (device_used_to_be, mountlist->el[currline].device); 1348 strcpy (mountpoint_str, mountlist->el[currline].mountpoint); 1349 strcpy (mountpt_used_to_be, mountlist->el[currline].mountpoint); 1350 strcpy (format_str, mountlist->el[currline].format); 1351 sprintf (size_str, "%lld", mountlist->el[currline].size / 1024); 1352 newtOpenWindow (20, 5, 48, 10, "Edit entry"); 1353 label0 = newtLabel (2, 1, "Device:"); 1354 label1 = newtLabel (2, 2, "Mountpoint:"); 1355 label2 = newtLabel (2, 3, "Size (MB): "); 1356 label3 = newtLabel (2, 4, "Format: "); 1357 deviceComp = newtEntry (14, 1, device_str, 30, (void*)&device_here, 0); 1358 mountpointComp = newtEntry (14, 2, mountpoint_str, 30, (void*)&mountpoint_here, 0); 1359 formatComp = newtEntry (14, 4, format_str, 15, (void*)&format_here, 0); 1360 if (strstr (mountlist->el[currline].device, RAID_DEVICE_STUB) 1361 || !strcmp (mountlist->el[currline].mountpoint, "image")) 1362 { 1363 sizeComp = newtLabel (14, 3, size_str); 1364 } 1365 else 1366 { 1367 sizeComp = newtEntry (14, 3, size_str, 10, (void*)&size_here, 0); 1368 } 1369 bOK = newtButton (2, 6, " OK "); 1370 bCancel = newtButton (14, 6, "Cancel"); 1371 if (strstr (mountlist->el[currline].device, RAID_DEVICE_STUB)) 1372 { 1373 b_raid = newtButton (26, 6, "RAID.."); 1374 } 1375 newtPushHelpLine 1376 (" Edit this partition's mountpoint, size and format; then click 'OK'."); 1377 myForm = newtForm (NULL, NULL, 0); 1378 newtFormAddComponents (myForm, deviceComp, mountpointComp, sizeComp, 1379 formatComp, label0, label1, label2, label3, bOK, 1380 bCancel, b_raid, NULL); 1381 for (b_res = NULL; b_res != bOK && b_res != bCancel;) 1382 { 1383 b_res = newtRunForm (myForm); 1384 strcpy (device_str, device_here); 1385 strip_spaces (device_str); 1386 strcpy (mountpoint_str, mountpoint_here); 1387 strip_spaces (mountpoint_str); 1388 strcpy (format_str, format_here); 1389 strip_spaces (format_str); 1390 if (b_res == bOK && strstr (device_str, RAID_DEVICE_STUB) 1391 && strstr (device_used_to_be, RAID_DEVICE_STUB) 1392 && strcmp (device_str, device_used_to_be)) 1393 { 1394 popup_and_OK ("You can't change /dev/mdX to /dev/mdY."); 1395 b_res = NULL; 1396 continue; 1397 } 1398 else if (b_res == bOK && !strcmp (mountpoint_str, "image") 1399 && strcmp (mountpt_used_to_be, "image")) 1400 { 1401 popup_and_OK ("You can't change a regular device to an image."); 1402 b_res = NULL; 1403 continue; 1404 } 1405 if (!strstr (mountlist->el[currline].device, RAID_DEVICE_STUB) 1406 && strcmp (mountlist->el[currline].mountpoint, "image")) 1407 { 1408 strcpy (size_str, size_here); 1409 strip_spaces (size_str); 1410 } 1411 else 1412 { 1413 sprintf (size_str, "%ld", 1414 calculate_raid_device_size (mountlist, raidlist, 1415 mountlist->el[currline]. 1416 device) / 1024); 1417 newtLabelSetText (sizeComp, size_str); 1418 } 1419 /* do not let user click RAID button if user has changed device_str */ 1420 if (b_res == b_raid) 1421 { 1422 if (strcmp (device_str, mountlist->el[currline].device)) 1423 { 1424 /* 1425 can't change mountlist's entry from /dex/mdX to /dev/mdY: it would ugly 1426 when you try to map the changes over to the raidtab list, trust me 1427 */ 1428 popup_and_OK 1429 ("You cannot edit the RAID settings until you have OK'd your change to the device node."); 1430 } 1431 else 1432 { 1433 j = 1434 find_raid_device_in_raidlist (raidlist, 1435 mountlist->el[currline].device); 1436 if (j < 0) 1437 { 1438 sprintf (tmp, 1439 "/etc/raidtab does not have an entry for %s; please delete it and add it again", 1440 mountlist->el[currline].device); 1441 popup_and_OK (tmp); 1442 } 1443 else 1444 { 1445 log_it ("edit_raidlist_entry - calling"); 1446 edit_raidlist_entry (mountlist, raidlist, &raidlist->el[j], 1447 currline); 1448 } 1449 } 1450 } 1451 } 1452 newtFormDestroy (myForm); 1453 newtPopHelpLine (); 1454 newtPopWindow (); 1455 if (b_res == bCancel) 1456 { 1457 memcpy ((void *) raidlist, (void *) &bkp_raidlist, 1458 sizeof (struct raidlist_itself)); 1459 return; 1460 } 1461 strcpy (mountlist->el[currline].device, device_str); 1462 strcpy (mountlist->el[currline].mountpoint, mountpoint_str); 1463 strcpy (mountlist->el[currline].format, format_str); 1464 if (strstr (mountlist->el[currline].device, RAID_DEVICE_STUB) 1465 || !strcmp (mountlist->el[currline].mountpoint, "image")) 1466 { 1467 mountlist->el[currline].size = 1468 calculate_raid_device_size (mountlist, raidlist, 1469 mountlist->el[currline].device); 1470 } 1471 else 1472 { 1473 mountlist->el[currline].size = atol (size_str) * 1024; 1474 } 1475 newtListboxSetEntry (listbox, (int) keylist[currline], 1476 mountlist_entry_to_string (mountlist, currline)); 1477 /* if new /dev/md RAID device then do funky stuff */ 1478 if (strstr (mountlist->el[currline].device, RAID_DEVICE_STUB) 1479 && !strstr (device_used_to_be, RAID_DEVICE_STUB)) 1480 { 1481 initiate_new_raidlist_entry (raidlist, mountlist, currline, device_str); 1482 } 1483 /* if moving from RAID to non-RAID then do funky stuff */ 1484 else if (strstr (device_used_to_be, RAID_DEVICE_STUB) 1485 && !strstr (device_str, RAID_DEVICE_STUB)) 1486 { 1487 delete_raidlist_entry (mountlist, raidlist, device_str); 1488 } 1489 /* if moving a non-RAID to another non-RAID then re-jig any RAID disks, if necessary */ 1490 else if (!strstr (device_used_to_be, RAID_DEVICE_STUB) 1491 && !strstr (device_str, RAID_DEVICE_STUB)) 1492 { 1493 rejig_partition_name_in_raidlist_if_necessary (raidlist, 1494 device_used_to_be, 1495 device_str); 1496 } 1255 int j = 0; 1256 1257 assert(mountlist != NULL); 1258 assert(raidlist != NULL); 1259 assert(listbox != NULL); 1260 assert(keylist != NULL); 1261 1262 memcpy((void *) &bkp_raidlist, (void *) raidlist, 1263 sizeof(struct raidlist_itself)); 1264 strcpy(device_str, mountlist->el[currline].device); 1265 strcpy(device_used_to_be, mountlist->el[currline].device); 1266 strcpy(mountpoint_str, mountlist->el[currline].mountpoint); 1267 strcpy(mountpt_used_to_be, mountlist->el[currline].mountpoint); 1268 strcpy(format_str, mountlist->el[currline].format); 1269 sprintf(size_str, "%lld", mountlist->el[currline].size / 1024); 1270 newtOpenWindow(20, 5, 48, 10, "Edit entry"); 1271 label0 = newtLabel(2, 1, "Device:"); 1272 label1 = newtLabel(2, 2, "Mountpoint:"); 1273 label2 = newtLabel(2, 3, "Size (MB): "); 1274 label3 = newtLabel(2, 4, "Format: "); 1275 deviceComp = 1276 newtEntry(14, 1, device_str, 30, (void *) &device_here, 0); 1277 mountpointComp = 1278 newtEntry(14, 2, mountpoint_str, 30, (void *) &mountpoint_here, 0); 1279 formatComp = 1280 newtEntry(14, 4, format_str, 15, (void *) &format_here, 0); 1281 if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB) 1282 || !strcmp(mountlist->el[currline].mountpoint, "image")) { 1283 sizeComp = newtLabel(14, 3, size_str); 1284 } else { 1285 sizeComp = newtEntry(14, 3, size_str, 10, (void *) &size_here, 0); 1286 } 1287 bOK = newtButton(2, 6, " OK "); 1288 bCancel = newtButton(14, 6, "Cancel"); 1289 if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)) { 1290 b_raid = newtButton(26, 6, "RAID.."); 1291 } 1292 newtPushHelpLine 1293 (" Edit this partition's mountpoint, size and format; then click 'OK'."); 1294 myForm = newtForm(NULL, NULL, 0); 1295 newtFormAddComponents(myForm, deviceComp, mountpointComp, sizeComp, 1296 formatComp, label0, label1, label2, label3, bOK, 1297 bCancel, b_raid, NULL); 1298 for (b_res = NULL; b_res != bOK && b_res != bCancel;) { 1299 b_res = newtRunForm(myForm); 1300 strcpy(device_str, device_here); 1301 strip_spaces(device_str); 1302 strcpy(mountpoint_str, mountpoint_here); 1303 strip_spaces(mountpoint_str); 1304 strcpy(format_str, format_here); 1305 strip_spaces(format_str); 1306 if (b_res == bOK && strstr(device_str, RAID_DEVICE_STUB) 1307 && strstr(device_used_to_be, RAID_DEVICE_STUB) 1308 && strcmp(device_str, device_used_to_be)) { 1309 popup_and_OK("You can't change /dev/mdX to /dev/mdY."); 1310 b_res = NULL; 1311 continue; 1312 } else if (b_res == bOK && !strcmp(mountpoint_str, "image") 1313 && strcmp(mountpt_used_to_be, "image")) { 1314 popup_and_OK("You can't change a regular device to an image."); 1315 b_res = NULL; 1316 continue; 1317 } 1318 if (!strstr(mountlist->el[currline].device, RAID_DEVICE_STUB) 1319 && strcmp(mountlist->el[currline].mountpoint, "image")) { 1320 strcpy(size_str, size_here); 1321 strip_spaces(size_str); 1322 } else { 1323 sprintf(size_str, "%ld", 1324 calculate_raid_device_size(mountlist, raidlist, 1325 mountlist->el[currline]. 1326 device) / 1024); 1327 newtLabelSetText(sizeComp, size_str); 1328 } 1329 /* do not let user click RAID button if user has changed device_str */ 1330 if (b_res == b_raid) { 1331 if (strcmp(device_str, mountlist->el[currline].device)) { 1332 /* 1333 can't change mountlist's entry from /dex/mdX to /dev/mdY: it would ugly 1334 when you try to map the changes over to the raidtab list, trust me 1335 */ 1336 popup_and_OK 1337 ("You cannot edit the RAID settings until you have OK'd your change to the device node."); 1338 } else { 1339 j = find_raid_device_in_raidlist(raidlist, 1340 mountlist->el[currline]. 1341 device); 1342 if (j < 0) { 1343 sprintf(tmp, 1344 "/etc/raidtab does not have an entry for %s; please delete it and add it again", 1345 mountlist->el[currline].device); 1346 popup_and_OK(tmp); 1347 } else { 1348 log_it("edit_raidlist_entry - calling"); 1349 edit_raidlist_entry(mountlist, raidlist, 1350 &raidlist->el[j], currline); 1351 } 1352 } 1353 } 1354 } 1355 newtFormDestroy(myForm); 1356 newtPopHelpLine(); 1357 newtPopWindow(); 1358 if (b_res == bCancel) { 1359 memcpy((void *) raidlist, (void *) &bkp_raidlist, 1360 sizeof(struct raidlist_itself)); 1361 return; 1362 } 1363 strcpy(mountlist->el[currline].device, device_str); 1364 strcpy(mountlist->el[currline].mountpoint, mountpoint_str); 1365 strcpy(mountlist->el[currline].format, format_str); 1366 if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB) 1367 || !strcmp(mountlist->el[currline].mountpoint, "image")) { 1368 mountlist->el[currline].size = 1369 calculate_raid_device_size(mountlist, raidlist, 1370 mountlist->el[currline].device); 1371 } else { 1372 mountlist->el[currline].size = atol(size_str) * 1024; 1373 } 1374 newtListboxSetEntry(listbox, (int) keylist[currline], 1375 mountlist_entry_to_string(mountlist, currline)); 1376 /* if new /dev/md RAID device then do funky stuff */ 1377 if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB) 1378 && !strstr(device_used_to_be, RAID_DEVICE_STUB)) { 1379 initiate_new_raidlist_entry(raidlist, mountlist, currline, 1380 device_str); 1381 } 1382 /* if moving from RAID to non-RAID then do funky stuff */ 1383 else if (strstr(device_used_to_be, RAID_DEVICE_STUB) 1384 && !strstr(device_str, RAID_DEVICE_STUB)) { 1385 delete_raidlist_entry(mountlist, raidlist, device_str); 1386 } 1387 /* if moving a non-RAID to another non-RAID then re-jig any RAID disks, if necessary */ 1388 else if (!strstr(device_used_to_be, RAID_DEVICE_STUB) 1389 && !strstr(device_str, RAID_DEVICE_STUB)) { 1390 rejig_partition_name_in_raidlist_if_necessary(raidlist, 1391 device_used_to_be, 1392 device_str); 1393 } 1497 1394 /* else, moving a RAID to another RAID; bad idea, or so I thought */ 1498 #ifndef __FreeBSD__ /* It works fine under FBSD. */ 1499 else if (strcmp (device_used_to_be, device_str)) 1500 { 1501 popup_and_OK 1502 ("You are renaming a RAID device as another RAID device. I don't like it but I'll allow it."); 1503 } 1395 #ifndef __FreeBSD__ /* It works fine under FBSD. */ 1396 else if (strcmp(device_used_to_be, device_str)) { 1397 popup_and_OK 1398 ("You are renaming a RAID device as another RAID device. I don't like it but I'll allow it."); 1399 } 1504 1400 #endif 1505 redraw_mountlist(mountlist, keylist, listbox);1401 redraw_mountlist(mountlist, keylist, listbox); 1506 1402 } 1507 1403 … … 1517 1413 */ 1518 1414 void 1519 add_raid_subdisk (struct raidlist_itself *raidlist, struct vinum_plex *raidrec, char *temp) 1520 { 1521 int i; 1522 bool found = FALSE; 1523 1524 for (i = 0; i < raidlist->disks.entries; ++i) { 1525 if (!strcmp (raidlist->disks.el[i].device, temp)) { 1526 strcpy (raidrec->sd [raidrec->subdisks].which_device, 1527 raidlist->disks.el[i].name); 1528 found = TRUE; 1529 } 1530 } 1531 if (!found) { 1532 sprintf (raidlist->disks.el[raidlist->disks.entries].name, "drive%i", raidlist->disks.entries); 1533 sprintf (raidrec->sd [raidrec->subdisks].which_device, "drive%i", raidlist->disks.entries); 1534 strcpy (raidlist->disks.el[raidlist->disks.entries++].device, temp); 1535 } 1536 raidrec->subdisks++; 1415 add_raid_subdisk(struct raidlist_itself *raidlist, 1416 struct vinum_plex *raidrec, char *temp) 1417 { 1418 int i; 1419 bool found = FALSE; 1420 1421 for (i = 0; i < raidlist->disks.entries; ++i) { 1422 if (!strcmp(raidlist->disks.el[i].device, temp)) { 1423 strcpy(raidrec->sd[raidrec->subdisks].which_device, 1424 raidlist->disks.el[i].name); 1425 found = TRUE; 1426 } 1427 } 1428 if (!found) { 1429 sprintf(raidlist->disks.el[raidlist->disks.entries].name, 1430 "drive%i", raidlist->disks.entries); 1431 sprintf(raidrec->sd[raidrec->subdisks].which_device, "drive%i", 1432 raidlist->disks.entries); 1433 strcpy(raidlist->disks.el[raidlist->disks.entries++].device, temp); 1434 } 1435 raidrec->subdisks++; 1537 1436 } 1538 1437 … … 1547 1446 * @ingroup restoreUtilityGroup 1548 1447 */ 1549 char * 1550 find_dev_entry_for_raid_device_name (struct raidlist_itself *raidlist, char *vinum_name) 1551 { 1552 1553 1554 if (!strcmp(raidlist->disks.el[i].name, vinum_name)) {1555 1556 }1557 1558 1448 char *find_dev_entry_for_raid_device_name(struct raidlist_itself *raidlist, 1449 char *vinum_name) 1450 { 1451 int i; 1452 for (i = 0; i < raidlist->disks.entries; ++i) { 1453 if (!strcmp(raidlist->disks.el[i].name, vinum_name)) { 1454 return raidlist->disks.el[i].device; 1455 } 1456 } 1457 return NULL; 1559 1458 } 1560 1459 1561 1460 void 1562 edit_raidlist_plex (struct mountlist_itself *mountlist, 1563 struct raidlist_itself *raidlist, 1564 struct vinum_plex *raidrec, int currline, int currline2); 1461 edit_raidlist_plex(struct mountlist_itself *mountlist, 1462 struct raidlist_itself *raidlist, 1463 struct vinum_plex *raidrec, int currline, 1464 int currline2); 1565 1465 1566 1466 #endif … … 1576 1476 */ 1577 1477 void 1578 edit_raidlist_entry (struct mountlist_itself *mountlist, 1579 struct raidlist_itself *raidlist, 1580 struct OSSWAP (raid_device_record, vinum_volume) *raidrec, int currline) 1478 edit_raidlist_entry(struct mountlist_itself *mountlist, 1479 struct raidlist_itself *raidlist, 1480 struct OSSWAP (raid_device_record, 1481 vinum_volume) * raidrec, int currline) 1581 1482 { 1582 1483 1583 1484 #ifdef __FreeBSD__ 1584 1485 /** structures ********************************************************/ 1585 1486 struct vinum_volume bkp_raidrec; 1586 1487 1587 1488 1588 1489 /** buffers ***********************************************************/ 1589 1490 char title_of_editraidForm_window[MAX_STR_LEN]; 1590 1491 1591 1492 /** newt **************************************************************/ 1592 newtComponent editraidForm; 1593 newtComponent bOK; 1594 newtComponent bCancel; 1595 newtComponent bEdit; 1596 newtComponent bAdd; 1597 newtComponent bDelete; 1598 newtComponent b_res; 1599 newtComponent plexesListbox; 1600 newtComponent plexesHeader; 1601 1602 void *keylist[10]; 1603 void *curr_choice; 1604 1605 int currline2 = 0; 1606 1607 log_it ("Started edit_raidlist_entry"); 1608 memcpy ((void *) &bkp_raidrec, (void *) raidrec, 1609 sizeof (struct vinum_volume)); 1610 sprintf (title_of_editraidForm_window, "Plexes on %s", raidrec->volname); 1611 newtPushHelpLine (" Please select a plex to edit"); 1612 newtOpenWindow (13, 5, 54, 15, title_of_editraidForm_window); 1613 for (;;) 1614 { 1615 int i; 1616 char headerstr[MAX_STR_LEN]; 1617 snprintf (headerstr, MAX_STR_LEN, "%-14s %-8s %11s %8s", 1618 "Plex", "Level", "Stripe Size", "Subdisks"); 1619 1620 bOK = newtCompactButton (2, 13, " OK "); 1621 bCancel = newtCompactButton (12, 13, "Cancel"); 1622 bAdd = newtCompactButton (22, 13, " Add "); 1623 bEdit = newtCompactButton (32, 13, " Edit "); 1624 bDelete = newtCompactButton (42, 13, "Delete"); 1625 1626 plexesListbox = newtListbox (2, 3, 9, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 1627 plexesHeader = newtLabel (2, 2, headerstr); 1628 editraidForm = newtForm (NULL, NULL, 0); 1629 1630 newtListboxClear (plexesListbox); 1631 for (i = 0; i < 10; ++i) { 1632 keylist[i] = (void *) i; 1633 if (i < raidrec->plexes) { 1634 char pname[64], entry[MAX_STR_LEN], raidlevel[64], chunksize[64]; 1635 switch (raidrec->plex[i].raidlevel) { 1636 case -1: 1637 strcpy (raidlevel, "concat"); 1638 break; 1639 case 0: 1640 strcpy (raidlevel, "striped"); 1641 break; 1642 case 5: 1643 strcpy (raidlevel, "raid5"); 1644 break; 1645 default: 1646 sprintf (raidlevel, "raid%i", raidrec->plex[i].raidlevel); 1647 break; 1648 } 1649 1650 if (raidrec->plex[i].raidlevel == -1) { 1651 strcpy (chunksize, "N/A"); 1652 } else { 1653 sprintf (chunksize, "%dk", raidrec->plex[i].stripesize); 1654 } 1655 snprintf (pname, 64, "%s.p%i", raidrec->volname, i); 1656 snprintf (entry, MAX_STR_LEN, "%-14s %-8s %11s %8d", pname, raidlevel, chunksize, 1657 raidrec->plex[i].subdisks); 1658 newtListboxAppendEntry (plexesListbox, entry, keylist[i]); 1659 } 1660 } 1661 1662 newtFormAddComponents (editraidForm, bOK, bCancel, bAdd, bEdit, 1663 bDelete, plexesListbox, plexesHeader, NULL); 1664 1665 b_res = newtRunForm (editraidForm); 1666 if (b_res == bOK || b_res == bCancel) 1667 { 1668 break; 1669 } 1670 1671 curr_choice = newtListboxGetCurrent (plexesListbox); 1672 for (currline2 = 0; currline2 < raidrec->plexes; ++currline2) { 1673 if (currline2 > 9) break; 1674 if (keylist[currline2] == curr_choice) break; 1675 } 1676 1677 if (b_res == bDelete) { 1678 char msg[MAX_STR_LEN]; 1679 sprintf (msg, "Are you sure you want to delete %s.p%i?", raidrec->volname, currline2); 1680 if (ask_me_yes_or_no (msg)) { 1681 log_it ("Deleting RAID plex"); 1682 memcpy ((void *) &raidrec->plex[currline2], 1683 (void *) &raidrec->plex[raidrec->plexes - 1], 1684 sizeof (struct vinum_plex)); 1685 raidrec->plexes--; 1686 } 1687 continue; 1688 } 1689 if (b_res == bAdd) { 1690 raidrec->plex[raidrec->plexes].raidlevel = 0; 1691 raidrec->plex[raidrec->plexes].stripesize = 279; 1692 raidrec->plex[raidrec->plexes].subdisks = 0; 1693 currline2 = raidrec->plexes++; 1694 } 1695 edit_raidlist_plex (mountlist, raidlist, &raidrec->plex[currline2], currline, currline2); 1696 newtFormDestroy (editraidForm); 1697 } 1698 if (b_res == bCancel) 1699 { 1700 memcpy ((void *) raidrec, (void *) &bkp_raidrec, 1701 sizeof (struct vinum_volume)); 1702 } 1703 newtPopHelpLine (); 1704 newtPopWindow (); 1705 mountlist->el[currline].size = 1706 calculate_raid_device_size (mountlist, raidlist, raidrec->volname); 1493 newtComponent editraidForm; 1494 newtComponent bOK; 1495 newtComponent bCancel; 1496 newtComponent bEdit; 1497 newtComponent bAdd; 1498 newtComponent bDelete; 1499 newtComponent b_res; 1500 newtComponent plexesListbox; 1501 newtComponent plexesHeader; 1502 1503 void *keylist[10]; 1504 void *curr_choice; 1505 1506 int currline2 = 0; 1507 1508 log_it("Started edit_raidlist_entry"); 1509 memcpy((void *) &bkp_raidrec, (void *) raidrec, 1510 sizeof(struct vinum_volume)); 1511 sprintf(title_of_editraidForm_window, "Plexes on %s", 1512 raidrec->volname); 1513 newtPushHelpLine(" Please select a plex to edit"); 1514 newtOpenWindow(13, 5, 54, 15, title_of_editraidForm_window); 1515 for (;;) { 1516 int i; 1517 char headerstr[MAX_STR_LEN]; 1518 snprintf(headerstr, MAX_STR_LEN, "%-14s %-8s %11s %8s", 1519 "Plex", "Level", "Stripe Size", "Subdisks"); 1520 1521 bOK = newtCompactButton(2, 13, " OK "); 1522 bCancel = newtCompactButton(12, 13, "Cancel"); 1523 bAdd = newtCompactButton(22, 13, " Add "); 1524 bEdit = newtCompactButton(32, 13, " Edit "); 1525 bDelete = newtCompactButton(42, 13, "Delete"); 1526 1527 plexesListbox = 1528 newtListbox(2, 3, 9, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 1529 plexesHeader = newtLabel(2, 2, headerstr); 1530 editraidForm = newtForm(NULL, NULL, 0); 1531 1532 newtListboxClear(plexesListbox); 1533 for (i = 0; i < 10; ++i) { 1534 keylist[i] = (void *) i; 1535 if (i < raidrec->plexes) { 1536 char pname[64], entry[MAX_STR_LEN], raidlevel[64], 1537 chunksize[64]; 1538 switch (raidrec->plex[i].raidlevel) { 1539 case -1: 1540 strcpy(raidlevel, "concat"); 1541 break; 1542 case 0: 1543 strcpy(raidlevel, "striped"); 1544 break; 1545 case 5: 1546 strcpy(raidlevel, "raid5"); 1547 break; 1548 default: 1549 sprintf(raidlevel, "raid%i", 1550 raidrec->plex[i].raidlevel); 1551 break; 1552 } 1553 1554 if (raidrec->plex[i].raidlevel == -1) { 1555 strcpy(chunksize, "N/A"); 1556 } else { 1557 sprintf(chunksize, "%dk", raidrec->plex[i].stripesize); 1558 } 1559 snprintf(pname, 64, "%s.p%i", raidrec->volname, i); 1560 snprintf(entry, MAX_STR_LEN, "%-14s %-8s %11s %8d", 1561 pname, raidlevel, chunksize, 1562 raidrec->plex[i].subdisks); 1563 newtListboxAppendEntry(plexesListbox, entry, keylist[i]); 1564 } 1565 } 1566 1567 newtFormAddComponents(editraidForm, bOK, bCancel, bAdd, bEdit, 1568 bDelete, plexesListbox, plexesHeader, NULL); 1569 1570 b_res = newtRunForm(editraidForm); 1571 if (b_res == bOK || b_res == bCancel) { 1572 break; 1573 } 1574 1575 curr_choice = newtListboxGetCurrent(plexesListbox); 1576 for (currline2 = 0; currline2 < raidrec->plexes; ++currline2) { 1577 if (currline2 > 9) 1578 break; 1579 if (keylist[currline2] == curr_choice) 1580 break; 1581 } 1582 1583 if (b_res == bDelete) { 1584 char msg[MAX_STR_LEN]; 1585 sprintf(msg, "Are you sure you want to delete %s.p%i?", 1586 raidrec->volname, currline2); 1587 if (ask_me_yes_or_no(msg)) { 1588 log_it("Deleting RAID plex"); 1589 memcpy((void *) &raidrec->plex[currline2], 1590 (void *) &raidrec->plex[raidrec->plexes - 1], 1591 sizeof(struct vinum_plex)); 1592 raidrec->plexes--; 1593 } 1594 continue; 1595 } 1596 if (b_res == bAdd) { 1597 raidrec->plex[raidrec->plexes].raidlevel = 0; 1598 raidrec->plex[raidrec->plexes].stripesize = 279; 1599 raidrec->plex[raidrec->plexes].subdisks = 0; 1600 currline2 = raidrec->plexes++; 1601 } 1602 edit_raidlist_plex(mountlist, raidlist, &raidrec->plex[currline2], 1603 currline, currline2); 1604 newtFormDestroy(editraidForm); 1605 } 1606 if (b_res == bCancel) { 1607 memcpy((void *) raidrec, (void *) &bkp_raidrec, 1608 sizeof(struct vinum_volume)); 1609 } 1610 newtPopHelpLine(); 1611 newtPopWindow(); 1612 mountlist->el[currline].size = 1613 calculate_raid_device_size(mountlist, raidlist, raidrec->volname); 1707 1614 #else 1708 1615 /** structures ********************************************************/ 1709 1616 struct raid_device_record *bkp_raidrec; 1710 1617 1711 1618 1712 1619 /** buffers ***********************************************************/ 1713 1620 char *title_of_editraidForm_window; 1714 1621 char *sz_raid_level; 1715 1622 char *sz_data_disks; … … 1719 1626 1720 1627 /** newt **************************************************************/ 1721 1628 newtComponent editraidForm; 1722 1629 newtComponent bOK; 1723 1630 newtComponent bCancel; … … 1730 1637 newtComponent b_res; 1731 1638 1732 assert(mountlist!=NULL); 1733 assert(raidlist!=NULL); 1734 assert(raidrec!=NULL); 1735 1736 malloc_string(title_of_editraidForm_window); 1737 malloc_string(sz_raid_level); 1738 malloc_string(sz_data_disks); 1739 malloc_string(sz_spare_disks); 1740 malloc_string(sz_parity_disks); 1741 malloc_string(sz_failed_disks); 1742 if (!(bkp_raidrec = malloc(sizeof(struct raid_device_record)))) 1743 { fatal_error("Cannot malloc space for raidrec"); } 1744 1745 log_it ("Started edit_raidlist_entry"); 1746 1747 memcpy ((void *) bkp_raidrec, (void *) raidrec, 1748 sizeof (struct raid_device_record)); 1749 sprintf (title_of_editraidForm_window, "%s", raidrec->raid_device); 1750 log_msg(2, "Opening newt window"); 1751 newtOpenWindow (20, 5, 40, 14, title_of_editraidForm_window); 1752 for (;;) 1753 { 1754 log_msg(2, "Main loop"); 1755 sprintf (title_of_editraidForm_window, "Edit %s", raidrec->raid_device); 1756 strcpy (sz_raid_level, 1757 turn_raid_level_number_to_string (raidrec->raid_level)); 1758 strcpy (sz_data_disks, 1759 number_of_disks_as_string (raidrec->data_disks.entries, 1760 "data")); 1761 strcpy (sz_spare_disks, 1762 number_of_disks_as_string (raidrec->spare_disks.entries, 1763 "spare")); 1764 strcpy (sz_parity_disks, 1765 number_of_disks_as_string (raidrec->parity_disks.entries, 1766 "parity")); 1767 strcpy (sz_failed_disks, 1768 number_of_disks_as_string (raidrec->failed_disks.entries, 1769 "failed")); 1770 bSelectData = newtButton (1, 1, sz_data_disks); 1771 bSelectSpare = newtButton (20, 1, sz_spare_disks); 1772 bSelectParity = newtButton (1, 5, sz_parity_disks); 1773 bSelectFailed = newtButton (20, 5, sz_failed_disks); 1774 bChangeRaid = newtButton (1, 9, sz_raid_level); 1775 bOK = newtButton (16 + (raidrec->raid_level == -1), 9, " OK "); 1776 bCancel = newtButton (28, 9, "Cancel"); 1777 bAdditional = 1778 newtCompactButton (1, 13, "Additional settings and information"); 1779 newtPushHelpLine 1780 (" Edit the RAID device's settings to your heart's content, then hit OK/Cancel."); 1781 editraidForm = newtForm (NULL, NULL, 0); 1782 newtFormAddComponents (editraidForm, bSelectData, bSelectParity, 1783 bChangeRaid, bSelectSpare, bSelectFailed, bOK, 1784 bCancel, bAdditional); 1785 b_res = newtRunForm (editraidForm); 1786 if (b_res == bChangeRaid) 1787 { 1788 choose_raid_level (raidrec); 1789 } 1790 else if (b_res == bSelectData) 1791 { 1792 select_raid_disks (mountlist, raidlist, raidrec, "data", 1793 &raidrec->data_disks); 1794 } 1795 else if (b_res == bSelectSpare) 1796 { 1797 select_raid_disks (mountlist, raidlist, raidrec, "spare", 1798 &raidrec->spare_disks); 1799 } 1800 else if (b_res == bSelectParity) 1801 { 1802 select_raid_disks (mountlist, raidlist, raidrec, "parity", 1803 &raidrec->parity_disks); 1804 } 1805 else if (b_res == bSelectFailed) 1806 { 1807 select_raid_disks (mountlist, raidlist, raidrec, "failed", 1808 &raidrec->failed_disks); 1809 } 1810 else if (b_res == bAdditional) 1811 { 1812 edit_raidrec_additional_vars (raidrec); 1813 } 1814 newtFormDestroy (editraidForm); 1815 if (b_res == bOK || b_res == bCancel) 1816 { 1817 break; 1818 } 1819 } 1820 if (b_res == bCancel) 1821 { 1822 memcpy ((void *) raidrec, (void *) bkp_raidrec, 1823 sizeof (struct raid_device_record)); 1824 } 1825 newtPopHelpLine (); 1826 newtPopWindow (); 1827 mountlist->el[currline].size = 1828 calculate_raid_device_size (mountlist, raidlist, raidrec->raid_device); 1829 paranoid_free(title_of_editraidForm_window); 1830 paranoid_free(sz_raid_level); 1831 paranoid_free(sz_data_disks); 1832 paranoid_free(sz_spare_disks); 1833 paranoid_free(sz_parity_disks); 1834 paranoid_free(sz_failed_disks); 1835 paranoid_free(bkp_raidrec); 1639 assert(mountlist != NULL); 1640 assert(raidlist != NULL); 1641 assert(raidrec != NULL); 1642 1643 malloc_string(title_of_editraidForm_window); 1644 malloc_string(sz_raid_level); 1645 malloc_string(sz_data_disks); 1646 malloc_string(sz_spare_disks); 1647 malloc_string(sz_parity_disks); 1648 malloc_string(sz_failed_disks); 1649 if (!(bkp_raidrec = malloc(sizeof(struct raid_device_record)))) { 1650 fatal_error("Cannot malloc space for raidrec"); 1651 } 1652 1653 log_it("Started edit_raidlist_entry"); 1654 1655 memcpy((void *) bkp_raidrec, (void *) raidrec, 1656 sizeof(struct raid_device_record)); 1657 sprintf(title_of_editraidForm_window, "%s", raidrec->raid_device); 1658 log_msg(2, "Opening newt window"); 1659 newtOpenWindow(20, 5, 40, 14, title_of_editraidForm_window); 1660 for (;;) { 1661 log_msg(2, "Main loop"); 1662 sprintf(title_of_editraidForm_window, "Edit %s", 1663 raidrec->raid_device); 1664 strcpy(sz_raid_level, 1665 turn_raid_level_number_to_string(raidrec->raid_level)); 1666 strcpy(sz_data_disks, 1667 number_of_disks_as_string(raidrec->data_disks.entries, 1668 "data")); 1669 strcpy(sz_spare_disks, 1670 number_of_disks_as_string(raidrec->spare_disks.entries, 1671 "spare")); 1672 strcpy(sz_parity_disks, 1673 number_of_disks_as_string(raidrec->parity_disks.entries, 1674 "parity")); 1675 strcpy(sz_failed_disks, 1676 number_of_disks_as_string(raidrec->failed_disks.entries, 1677 "failed")); 1678 bSelectData = newtButton(1, 1, sz_data_disks); 1679 bSelectSpare = newtButton(20, 1, sz_spare_disks); 1680 bSelectParity = newtButton(1, 5, sz_parity_disks); 1681 bSelectFailed = newtButton(20, 5, sz_failed_disks); 1682 bChangeRaid = newtButton(1, 9, sz_raid_level); 1683 bOK = newtButton(16 + (raidrec->raid_level == -1), 9, " OK "); 1684 bCancel = newtButton(28, 9, "Cancel"); 1685 bAdditional = 1686 newtCompactButton(1, 13, 1687 "Additional settings and information"); 1688 newtPushHelpLine 1689 (" Edit the RAID device's settings to your heart's content, then hit OK/Cancel."); 1690 editraidForm = newtForm(NULL, NULL, 0); 1691 newtFormAddComponents(editraidForm, bSelectData, bSelectParity, 1692 bChangeRaid, bSelectSpare, bSelectFailed, 1693 bOK, bCancel, bAdditional); 1694 b_res = newtRunForm(editraidForm); 1695 if (b_res == bChangeRaid) { 1696 choose_raid_level(raidrec); 1697 } else if (b_res == bSelectData) { 1698 select_raid_disks(mountlist, raidlist, raidrec, "data", 1699 &raidrec->data_disks); 1700 } else if (b_res == bSelectSpare) { 1701 select_raid_disks(mountlist, raidlist, raidrec, "spare", 1702 &raidrec->spare_disks); 1703 } else if (b_res == bSelectParity) { 1704 select_raid_disks(mountlist, raidlist, raidrec, "parity", 1705 &raidrec->parity_disks); 1706 } else if (b_res == bSelectFailed) { 1707 select_raid_disks(mountlist, raidlist, raidrec, "failed", 1708 &raidrec->failed_disks); 1709 } else if (b_res == bAdditional) { 1710 edit_raidrec_additional_vars(raidrec); 1711 } 1712 newtFormDestroy(editraidForm); 1713 if (b_res == bOK || b_res == bCancel) { 1714 break; 1715 } 1716 } 1717 if (b_res == bCancel) { 1718 memcpy((void *) raidrec, (void *) bkp_raidrec, 1719 sizeof(struct raid_device_record)); 1720 } 1721 newtPopHelpLine(); 1722 newtPopWindow(); 1723 mountlist->el[currline].size = 1724 calculate_raid_device_size(mountlist, raidlist, 1725 raidrec->raid_device); 1726 paranoid_free(title_of_editraidForm_window); 1727 paranoid_free(sz_raid_level); 1728 paranoid_free(sz_data_disks); 1729 paranoid_free(sz_spare_disks); 1730 paranoid_free(sz_parity_disks); 1731 paranoid_free(sz_failed_disks); 1732 paranoid_free(bkp_raidrec); 1836 1733 #endif 1837 1734 } … … 1850 1747 */ 1851 1748 void 1852 edit_raidlist_plex 1853 1854 1749 edit_raidlist_plex(struct mountlist_itself *mountlist, 1750 struct raidlist_itself *raidlist, 1751 struct vinum_plex *raidrec, int currline, int currline2) 1855 1752 { 1856 1753 1857 1754 /** structures ********************************************************/ 1858 1755 struct vinum_plex bkp_raidrec; 1859 1756 1860 1757 1861 1758 /** buffers ***********************************************************/ 1862 1759 char title_of_editraidForm_window[MAX_STR_LEN]; 1863 1760 1864 1761 /** newt **************************************************************/ 1865 newtComponent editraidForm; 1866 newtComponent bOK; 1867 newtComponent bCancel; 1868 newtComponent bEdit; 1869 newtComponent bAdd; 1870 newtComponent bDelete; 1871 newtComponent b_res; 1872 newtComponent unallocListbox, allocListbox; 1873 newtComponent bLevel, sLevel; 1874 newtComponent bStripeSize, sStripeSize; 1875 newtComponent bAlloc, bUnalloc; 1876 1877 void *keylist[ARBITRARY_MAXIMUM]; 1878 void *curr_choice_a, *curr_choice_u; 1879 int currline_a, currline_u; 1880 1881 struct mountlist_itself *unallocparts; 1882 1883 unallocparts = malloc (sizeof (struct mountlist_itself)); 1884 1885 log_it ("Started edit_raidlist_entry"); 1886 memcpy ((void *) &bkp_raidrec, (void *) raidrec, 1887 sizeof (struct vinum_plex)); 1888 sprintf (title_of_editraidForm_window, "%s.p%i", raidlist->el[currline].volname, currline2); 1889 newtPushHelpLine (" Please select a subdisk to edit, or edit this plex's parameters"); 1890 newtOpenWindow (13, 3, 54, 18, title_of_editraidForm_window); 1891 for (;;) 1892 { 1893 int i; 1894 char headerstr[MAX_STR_LEN]; 1895 char tmp[64]; 1896 snprintf (headerstr, MAX_STR_LEN, "%-24s %s", 1897 "Subdisk", "Device"); 1898 1899 1900 switch (raidrec->raidlevel) { 1901 case -1: 1902 strcpy (tmp, "concat"); 1903 break; 1904 case 0: 1905 strcpy (tmp, "striped"); 1906 break; 1907 case 5: 1908 strcpy (tmp, "raid5"); 1909 break; 1910 default: 1911 sprintf (tmp, "unknown (%i)", raidrec->raidlevel); 1912 break; 1913 } 1914 bLevel = newtCompactButton (2, 2, " RAID level "); 1915 sLevel = newtLabel (19, 2, tmp); 1916 1917 if (raidrec->raidlevel >= 0) { 1918 sprintf (tmp, "%ik", raidrec->stripesize); 1919 bStripeSize = newtCompactButton (2, 4, " Stripe size "); 1920 } else { 1921 strcpy (tmp, "N/A"); 1922 bStripeSize = newtLabel (2, 4, "Stripe size:"); 1923 } 1924 sStripeSize = newtLabel (19, 4, tmp); 1925 1926 bOK = newtCompactButton (2, 16, " OK "); 1927 bCancel = newtCompactButton (12, 16, "Cancel"); 1928 bAdd = newtCompactButton (22, 16, " Add "); 1929 bEdit = newtCompactButton (32, 16, " Edit "); 1930 bDelete = newtCompactButton (42, 16, "Delete"); 1931 1932 1933 // plexesListbox = newtListbox (2, 7, 9, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 1934 // plexesHeader = newtLabel (2, 6, headerstr); 1935 unallocListbox = newtListbox (2, 7, 7, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 1936 allocListbox = newtListbox (33, 7, 7, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 1937 bAlloc = newtButton (23, 7, " -> "); 1938 bUnalloc = newtButton (23, 11, " <- "); 1939 1940 editraidForm = newtForm (NULL, NULL, 0); 1941 1942 newtListboxClear (allocListbox); 1943 newtListboxClear (unallocListbox); 1944 bzero (unallocparts, sizeof (struct mountlist_itself)); 1945 make_list_of_unallocated_raid_partitions (unallocparts, mountlist, raidlist); 1946 for (i = 0; i < ARBITRARY_MAXIMUM; ++i) { 1947 char entry[MAX_STR_LEN]; 1948 keylist[i] = (void *) i; 1949 if (i < raidrec->subdisks) { 1950 snprintf (entry, MAX_STR_LEN, "%-17s", find_dev_entry_for_raid_device_name (raidlist, raidrec->sd[i].which_device)); 1951 newtListboxAppendEntry (allocListbox, entry, keylist[i]); 1952 } 1953 if (i < unallocparts->entries) { 1954 snprintf (entry, MAX_STR_LEN, "%-17s", unallocparts->el[i].device); 1955 newtListboxAppendEntry (unallocListbox, entry, keylist[i]); 1956 } 1957 } 1958 1762 newtComponent editraidForm; 1763 newtComponent bOK; 1764 newtComponent bCancel; 1765 newtComponent bEdit; 1766 newtComponent bAdd; 1767 newtComponent bDelete; 1768 newtComponent b_res; 1769 newtComponent unallocListbox, allocListbox; 1770 newtComponent bLevel, sLevel; 1771 newtComponent bStripeSize, sStripeSize; 1772 newtComponent bAlloc, bUnalloc; 1773 1774 void *keylist[ARBITRARY_MAXIMUM]; 1775 void *curr_choice_a, *curr_choice_u; 1776 int currline_a, currline_u; 1777 1778 struct mountlist_itself *unallocparts; 1779 1780 unallocparts = malloc(sizeof(struct mountlist_itself)); 1781 1782 log_it("Started edit_raidlist_entry"); 1783 memcpy((void *) &bkp_raidrec, (void *) raidrec, 1784 sizeof(struct vinum_plex)); 1785 sprintf(title_of_editraidForm_window, "%s.p%i", 1786 raidlist->el[currline].volname, currline2); 1787 newtPushHelpLine 1788 (" Please select a subdisk to edit, or edit this plex's parameters"); 1789 newtOpenWindow(13, 3, 54, 18, title_of_editraidForm_window); 1790 for (;;) { 1791 int i; 1792 char headerstr[MAX_STR_LEN]; 1793 char tmp[64]; 1794 snprintf(headerstr, MAX_STR_LEN, "%-24s %s", "Subdisk", "Device"); 1795 1796 1797 switch (raidrec->raidlevel) { 1798 case -1: 1799 strcpy(tmp, "concat"); 1800 break; 1801 case 0: 1802 strcpy(tmp, "striped"); 1803 break; 1804 case 5: 1805 strcpy(tmp, "raid5"); 1806 break; 1807 default: 1808 sprintf(tmp, "unknown (%i)", raidrec->raidlevel); 1809 break; 1810 } 1811 bLevel = newtCompactButton(2, 2, " RAID level "); 1812 sLevel = newtLabel(19, 2, tmp); 1813 1814 if (raidrec->raidlevel >= 0) { 1815 sprintf(tmp, "%ik", raidrec->stripesize); 1816 bStripeSize = newtCompactButton(2, 4, " Stripe size "); 1817 } else { 1818 strcpy(tmp, "N/A"); 1819 bStripeSize = newtLabel(2, 4, "Stripe size:"); 1820 } 1821 sStripeSize = newtLabel(19, 4, tmp); 1822 1823 bOK = newtCompactButton(2, 16, " OK "); 1824 bCancel = newtCompactButton(12, 16, "Cancel"); 1825 bAdd = newtCompactButton(22, 16, " Add "); 1826 bEdit = newtCompactButton(32, 16, " Edit "); 1827 bDelete = newtCompactButton(42, 16, "Delete"); 1828 1829 1830 // plexesListbox = newtListbox (2, 7, 9, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 1831 // plexesHeader = newtLabel (2, 6, headerstr); 1832 unallocListbox = 1833 newtListbox(2, 7, 7, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 1834 allocListbox = 1835 newtListbox(33, 7, 7, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 1836 bAlloc = newtButton(23, 7, " -> "); 1837 bUnalloc = newtButton(23, 11, " <- "); 1838 1839 editraidForm = newtForm(NULL, NULL, 0); 1840 1841 newtListboxClear(allocListbox); 1842 newtListboxClear(unallocListbox); 1843 bzero(unallocparts, sizeof(struct mountlist_itself)); 1844 make_list_of_unallocated_raid_partitions(unallocparts, mountlist, 1845 raidlist); 1846 for (i = 0; i < ARBITRARY_MAXIMUM; ++i) { 1847 char entry[MAX_STR_LEN]; 1848 keylist[i] = (void *) i; 1849 if (i < raidrec->subdisks) { 1850 snprintf(entry, MAX_STR_LEN, "%-17s", 1851 find_dev_entry_for_raid_device_name(raidlist, 1852 raidrec-> 1853 sd[i]. 1854 which_device)); 1855 newtListboxAppendEntry(allocListbox, entry, keylist[i]); 1856 } 1857 if (i < unallocparts->entries) { 1858 snprintf(entry, MAX_STR_LEN, "%-17s", 1859 unallocparts->el[i].device); 1860 newtListboxAppendEntry(unallocListbox, entry, keylist[i]); 1861 } 1862 } 1863 1959 1864 #define COMP(x) newtFormAddComponent (editraidForm, x) 1960 1865 #define UCOMP(x) if (unallocparts->entries > 0) COMP(x) 1961 1866 #define ACOMP(x) if (raidrec->subdisks > 0) COMP(x) 1962 editraidForm = newtForm(NULL, NULL, 0);1963 UCOMP(unallocListbox);1964 UCOMP(bAlloc);1965 ACOMP(allocListbox);1966 ACOMP(bUnalloc);1967 COMP(bOK);1968 COMP(bCancel);1969 COMP(bLevel);1970 COMP(sLevel);1971 if (raidrec->raidlevel != -1) {1972 COMP(bStripeSize);1973 COMP(sStripeSize);1974 }1867 editraidForm = newtForm(NULL, NULL, 0); 1868 UCOMP(unallocListbox); 1869 UCOMP(bAlloc); 1870 ACOMP(allocListbox); 1871 ACOMP(bUnalloc); 1872 COMP(bOK); 1873 COMP(bCancel); 1874 COMP(bLevel); 1875 COMP(sLevel); 1876 if (raidrec->raidlevel != -1) { 1877 COMP(bStripeSize); 1878 COMP(sStripeSize); 1879 } 1975 1880 #undef COMP 1976 1881 #undef UCOMP 1977 1882 #undef ACOMP 1978 1883 1884 newtRefresh(); 1885 b_res = newtRunForm(editraidForm); 1886 if (b_res == bOK || b_res == bCancel) { 1887 break; 1888 } 1889 1890 curr_choice_a = (raidrec->subdisks > 0) ? 1891 newtListboxGetCurrent(allocListbox) : (void *) 1234; 1892 curr_choice_u = (unallocparts->entries > 0) ? 1893 newtListboxGetCurrent(unallocListbox) : (void *) 1234; 1894 for (currline_a = 0; currline_a < raidrec->subdisks; ++currline_a) { 1895 if (currline_a > ARBITRARY_MAXIMUM) 1896 break; 1897 if (keylist[currline_a] == curr_choice_a) 1898 break; 1899 } 1900 for (currline_u = 0; currline_u < unallocparts->entries; 1901 ++currline_u) { 1902 if (currline_u > ARBITRARY_MAXIMUM) 1903 break; 1904 if (keylist[currline_u] == curr_choice_u) 1905 break; 1906 } 1907 if (b_res == bLevel) { 1908 choose_raid_level(raidrec); 1909 } else if (b_res == bStripeSize) { 1910 char tmp[64]; 1911 sprintf(tmp, "%i", raidrec->stripesize); 1912 if (popup_and_get_string 1913 ("Stripe size", 1914 "Please enter the stripe size in kilobytes.", tmp, 20)) { 1915 raidrec->stripesize = atoi(tmp); 1916 } 1917 } else if ((b_res == bAlloc) || (b_res == unallocListbox)) { 1918 if (currline_u <= unallocparts->entries) 1919 add_raid_subdisk(raidlist, raidrec, 1920 unallocparts->el[currline_u].device); 1921 } else if ((b_res == bUnalloc) || (b_res == allocListbox)) { 1922 if (currline_a <= raidrec->subdisks) { 1923 memcpy((void *) &raidrec->sd[currline_a], 1924 (void *) &raidrec->sd[raidrec->subdisks - 1], 1925 sizeof(struct vinum_subdisk)); 1926 raidrec->subdisks--; 1927 } 1928 } 1929 #if 0 1930 } else { 1931 edit_raid_subdisk(raidlist, raidrec, &raidrec->sd[currline3], 1932 currline3); 1933 } 1934 #endif 1935 newtFormDestroy(editraidForm); 1979 1936 newtRefresh(); 1980 b_res = newtRunForm (editraidForm); 1981 if (b_res == bOK || b_res == bCancel) 1982 { 1983 break; 1984 } 1985 1986 curr_choice_a = (raidrec->subdisks > 0) ? 1987 newtListboxGetCurrent (allocListbox) : (void *)1234; 1988 curr_choice_u = (unallocparts->entries > 0) ? 1989 newtListboxGetCurrent (unallocListbox) : (void *)1234; 1990 for (currline_a = 0; currline_a < raidrec->subdisks; ++currline_a) { 1991 if (currline_a > ARBITRARY_MAXIMUM) break; 1992 if (keylist[currline_a] == curr_choice_a) break; 1993 } 1994 for (currline_u = 0; currline_u < unallocparts->entries; ++currline_u) { 1995 if (currline_u > ARBITRARY_MAXIMUM) break; 1996 if (keylist[currline_u] == curr_choice_u) break; 1997 } 1998 if (b_res == bLevel) { 1999 choose_raid_level (raidrec); 2000 } 2001 else if (b_res == bStripeSize) { 2002 char tmp[64]; 2003 sprintf (tmp, "%i", raidrec->stripesize); 2004 if (popup_and_get_string ("Stripe size", "Please enter the stripe size in kilobytes.", 2005 tmp, 20)) { 2006 raidrec->stripesize = atoi (tmp); 2007 } 2008 } 2009 else if ((b_res == bAlloc) || (b_res == unallocListbox)) { 2010 if (currline_u <= unallocparts->entries) 2011 add_raid_subdisk (raidlist, raidrec, unallocparts->el[currline_u].device); 2012 } 2013 else if ((b_res == bUnalloc) || (b_res == allocListbox)) { 2014 if (currline_a <= raidrec->subdisks) { 2015 memcpy ((void *) &raidrec->sd[currline_a], 2016 (void *) &raidrec->sd[raidrec->subdisks - 1], 2017 sizeof (struct vinum_subdisk)); 2018 raidrec->subdisks--; 2019 } 2020 } 2021 #if 0 2022 } else { 2023 edit_raid_subdisk (raidlist, raidrec, &raidrec->sd[currline3], currline3); 2024 } 2025 #endif 2026 newtFormDestroy (editraidForm); 2027 newtRefresh(); 2028 } 2029 if (b_res == bCancel) 2030 { 2031 memcpy ((void *) raidrec, (void *) &bkp_raidrec, 2032 sizeof (struct vinum_plex)); 2033 } 2034 newtPopWindow(); 2035 newtPopHelpLine (); 1937 } 1938 1939 if (b_res == bCancel) { 1940 memcpy((void *) raidrec, (void *) &bkp_raidrec, 1941 sizeof(struct vinum_plex)); 1942 } 1943 newtPopWindow(); 1944 newtPopHelpLine(); 2036 1945 } 2037 1946 #else … … 2042 1951 * @ingroup restoreGuiVarslist 2043 1952 */ 2044 void 2045 edit_varslist_entry (struct raid_device_record *raidrec, int lino) 1953 void edit_varslist_entry(struct raid_device_record *raidrec, int lino) 2046 1954 { 2047 1955 2048 1956 /** buffers ***********************************************************/ 2049 1957 char header[MAX_STR_LEN]; 2050 1958 char comment[MAX_STR_LEN]; 2051 1959 char sz_out[MAX_STR_LEN]; 2052 1960 2053 assert(raidrec!=0); 2054 assert(lino>=0); 2055 2056 strcpy (sz_out, raidrec->additional_vars.el[lino].value); 2057 sprintf (header, "Edit %s", raidrec->additional_vars.el[lino].label); 2058 sprintf (comment, "Please set %s's value (currently '%s')", 2059 raidrec->additional_vars.el[lino].label, sz_out); 2060 if (popup_and_get_string (header, comment, sz_out, MAX_STR_LEN)) 2061 { 2062 strip_spaces (sz_out); 2063 strcpy (raidrec->additional_vars.el[lino].value, sz_out); 2064 } 1961 assert(raidrec != 0); 1962 assert(lino >= 0); 1963 1964 strcpy(sz_out, raidrec->additional_vars.el[lino].value); 1965 sprintf(header, "Edit %s", raidrec->additional_vars.el[lino].label); 1966 sprintf(comment, "Please set %s's value (currently '%s')", 1967 raidrec->additional_vars.el[lino].label, sz_out); 1968 if (popup_and_get_string(header, comment, sz_out, MAX_STR_LEN)) { 1969 strip_spaces(sz_out); 1970 strcpy(raidrec->additional_vars.el[lino].value, sz_out); 1971 } 2065 1972 } 2066 1973 … … 2077 1984 */ 2078 1985 int 2079 edit_mountlist_in_newt (char*mountlist_fname, struct mountlist_itself *mountlist, 2080 struct raidlist_itself *raidlist) 1986 edit_mountlist_in_newt(char *mountlist_fname, 1987 struct mountlist_itself *mountlist, 1988 struct raidlist_itself *raidlist) 2081 1989 { 2082 1990 2083 1991 /** newt **************************************************************/ 2084 1992 newtComponent myForm; 2085 1993 newtComponent bAdd; 2086 1994 newtComponent bEdit; … … 2097 2005 2098 2006 /** ???? *************************************************************/ 2099 2100 2007 void *curr_choice; 2008 void *keylist[ARBITRARY_MAXIMUM]; 2101 2009 2102 2010 /** int **************************************************************/ 2103 int i= 0;2011 int i = 0; 2104 2012 int currline = 0; 2105 2013 int finished = FALSE; … … 2111 2019 char flaws_str_C[MAX_STR_LEN]; 2112 2020 2113 assert(mountlist!=NULL); 2114 assert(raidlist!=NULL); 2115 2116 strcpy (flaws_str_A, "xxxxxxxxx"); 2117 strcpy (flaws_str_B, "xxxxxxxxx"); 2118 strcpy (flaws_str_C, "xxxxxxxxx"); 2119 if (mountlist->entries > ARBITRARY_MAXIMUM) 2120 { 2121 log_to_screen ("Arbitrary limits suck, man!"); 2122 finish (1); 2123 } 2124 newtPushHelpLine 2125 (" Please edit the mountlist to your satisfaction, then click OK or Cancel."); 2126 i = 4; 2127 bAdd = newtCompactButton (i, 17, " Add "); 2128 bEdit = newtCompactButton (i += 11, 17, " Edit "); 2129 bDelete = newtCompactButton (i += 12, 17, "Delete"); 2130 bReload = newtCompactButton (i += 12, 17, "Reload"); 2131 bCancel = newtCompactButton (i += 12, 17, "Cancel"); 2132 bOK = newtCompactButton (i += 12, 17, " OK "); 2133 sprintf (tmp, "%-24s %-24s %-8s %s", "Device", "Mountpoint", "Format", 2134 "Size (MB)"); 2135 headerMsg = newtLabel (2, 1, tmp); 2136 flawsLabelA = newtLabel (2, 13, flaws_str_A); 2137 flawsLabelB = newtLabel (2, 14, flaws_str_B); 2138 flawsLabelC = newtLabel (2, 15, flaws_str_C); 2139 partitionsListbox = 2140 newtListbox (2, 2, 10, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 2141 redraw_mountlist (mountlist, keylist, partitionsListbox); 2142 newtOpenWindow (1, 3, 77, 18, "Editing mountlist"); 2143 myForm = newtForm (NULL, NULL, 0); 2144 newtFormAddComponents (myForm, headerMsg, partitionsListbox, flawsLabelA, 2145 flawsLabelB, flawsLabelC, bAdd, bEdit, bDelete, 2146 bReload, bCancel, bOK, NULL); 2147 while (!finished) 2148 { 2149 evaluate_mountlist (mountlist, flaws_str_A, flaws_str_B, flaws_str_C); 2150 newtLabelSetText (flawsLabelA, flaws_str_A); 2151 newtLabelSetText (flawsLabelB, flaws_str_B); 2152 newtLabelSetText (flawsLabelC, flaws_str_C); 2153 b_res = newtRunForm (myForm); 2154 if (b_res == bOK) 2155 { 2156 if (!evaluate_mountlist 2157 (mountlist, flaws_str_A, flaws_str_B, flaws_str_C)) 2158 { 2159 finished = 2160 ask_me_yes_or_no 2161 ("Your mountlist might not work. Continue anyway?"); 2162 } 2163 else 2164 { 2165 finished = 2166 ask_me_yes_or_no 2167 ("Are you sure you want to save your mountlist and continue? (No changes will be made to your partition table at this time.)"); 2168 } 2169 } 2170 else if (b_res == bCancel) 2171 { 2172 finished = TRUE; 2173 } 2174 else if (b_res == bReload) 2175 { 2176 if (ask_me_yes_or_no ("Reload original mountlist?")) 2177 { 2021 assert(mountlist != NULL); 2022 assert(raidlist != NULL); 2023 2024 strcpy(flaws_str_A, "xxxxxxxxx"); 2025 strcpy(flaws_str_B, "xxxxxxxxx"); 2026 strcpy(flaws_str_C, "xxxxxxxxx"); 2027 if (mountlist->entries > ARBITRARY_MAXIMUM) { 2028 log_to_screen("Arbitrary limits suck, man!"); 2029 finish(1); 2030 } 2031 newtPushHelpLine 2032 (" Please edit the mountlist to your satisfaction, then click OK or Cancel."); 2033 i = 4; 2034 bAdd = newtCompactButton(i, 17, " Add "); 2035 bEdit = newtCompactButton(i += 11, 17, " Edit "); 2036 bDelete = newtCompactButton(i += 12, 17, "Delete"); 2037 bReload = newtCompactButton(i += 12, 17, "Reload"); 2038 bCancel = newtCompactButton(i += 12, 17, "Cancel"); 2039 bOK = newtCompactButton(i += 12, 17, " OK "); 2040 sprintf(tmp, "%-24s %-24s %-8s %s", "Device", "Mountpoint", "Format", 2041 "Size (MB)"); 2042 headerMsg = newtLabel(2, 1, tmp); 2043 flawsLabelA = newtLabel(2, 13, flaws_str_A); 2044 flawsLabelB = newtLabel(2, 14, flaws_str_B); 2045 flawsLabelC = newtLabel(2, 15, flaws_str_C); 2046 partitionsListbox = 2047 newtListbox(2, 2, 10, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 2048 redraw_mountlist(mountlist, keylist, partitionsListbox); 2049 newtOpenWindow(1, 3, 77, 18, "Editing mountlist"); 2050 myForm = newtForm(NULL, NULL, 0); 2051 newtFormAddComponents(myForm, headerMsg, partitionsListbox, 2052 flawsLabelA, flawsLabelB, flawsLabelC, bAdd, 2053 bEdit, bDelete, bReload, bCancel, bOK, NULL); 2054 while (!finished) { 2055 evaluate_mountlist(mountlist, flaws_str_A, flaws_str_B, 2056 flaws_str_C); 2057 newtLabelSetText(flawsLabelA, flaws_str_A); 2058 newtLabelSetText(flawsLabelB, flaws_str_B); 2059 newtLabelSetText(flawsLabelC, flaws_str_C); 2060 b_res = newtRunForm(myForm); 2061 if (b_res == bOK) { 2062 if (!evaluate_mountlist 2063 (mountlist, flaws_str_A, flaws_str_B, flaws_str_C)) { 2064 finished = 2065 ask_me_yes_or_no 2066 ("Your mountlist might not work. Continue anyway?"); 2067 } else { 2068 finished = 2069 ask_me_yes_or_no 2070 ("Are you sure you want to save your mountlist and continue? (No changes will be made to your partition table at this time.)"); 2071 } 2072 } else if (b_res == bCancel) { 2073 finished = TRUE; 2074 } else if (b_res == bReload) { 2075 if (ask_me_yes_or_no("Reload original mountlist?")) { 2178 2076 /* 2179 2077 This would be really dumb. RAIDTAB_FNAME is #define'd. --- Hugo, 2003/04/24 … … 2184 2082 } 2185 2083 */ 2186 load_mountlist (mountlist, mountlist_fname); 2187 load_raidtab_into_raidlist (raidlist, RAIDTAB_FNAME); 2188 redraw_mountlist (mountlist, keylist, partitionsListbox); 2189 } 2190 } 2191 else 2192 { 2193 curr_choice = newtListboxGetCurrent (partitionsListbox); 2194 for (i = 0; i < mountlist->entries && keylist[i] != curr_choice; 2195 i++); 2196 if (i == mountlist->entries && mountlist->entries > 0) 2197 { 2198 log_to_screen ("I don't know what that button does!"); 2199 } 2200 else 2201 { 2202 currline = i; 2203 if (b_res == bAdd) 2204 { 2205 add_mountlist_entry (mountlist, raidlist, partitionsListbox, 2206 currline, keylist); 2207 } 2208 else if (b_res == bDelete) 2209 { 2210 delete_mountlist_entry (mountlist, raidlist, 2211 partitionsListbox, currline, 2212 keylist); 2213 } 2214 else 2215 { 2216 if (mountlist->entries > 0) 2217 { 2218 edit_mountlist_entry (mountlist, raidlist, 2219 partitionsListbox, currline, 2220 keylist); 2221 } 2222 else 2223 { 2224 popup_and_OK 2225 ("Please add an entry. Then press ENTER to edit it."); 2226 } 2227 } 2228 } 2229 } 2230 } 2231 newtFormDestroy (myForm); 2232 newtPopWindow (); 2233 newtPopHelpLine (); 2234 if (b_res == bOK) 2235 { 2236 log_it("You pushed 'OK'. I shall now continue."); 2237 return (0); 2238 } 2239 else 2240 { 2241 /* popup_and_OK("You pushed 'cancel'. I shall now abort."); */ 2242 return (1); 2243 } 2084 load_mountlist(mountlist, mountlist_fname); 2085 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME); 2086 redraw_mountlist(mountlist, keylist, partitionsListbox); 2087 } 2088 } else { 2089 curr_choice = newtListboxGetCurrent(partitionsListbox); 2090 for (i = 0; 2091 i < mountlist->entries && keylist[i] != curr_choice; i++); 2092 if (i == mountlist->entries && mountlist->entries > 0) { 2093 log_to_screen("I don't know what that button does!"); 2094 } else { 2095 currline = i; 2096 if (b_res == bAdd) { 2097 add_mountlist_entry(mountlist, raidlist, 2098 partitionsListbox, currline, 2099 keylist); 2100 } else if (b_res == bDelete) { 2101 delete_mountlist_entry(mountlist, raidlist, 2102 partitionsListbox, currline, 2103 keylist); 2104 } else { 2105 if (mountlist->entries > 0) { 2106 edit_mountlist_entry(mountlist, raidlist, 2107 partitionsListbox, currline, 2108 keylist); 2109 } else { 2110 popup_and_OK 2111 ("Please add an entry. Then press ENTER to edit it."); 2112 } 2113 } 2114 } 2115 } 2116 } 2117 newtFormDestroy(myForm); 2118 newtPopWindow(); 2119 newtPopHelpLine(); 2120 if (b_res == bOK) { 2121 log_it("You pushed 'OK'. I shall now continue."); 2122 return (0); 2123 } else { 2124 /* popup_and_OK("You pushed 'cancel'. I shall now abort."); */ 2125 return (1); 2126 } 2244 2127 } 2245 2128 … … 2253 2136 */ 2254 2137 int 2255 edit_mountlist 2256 struct raidlist_itself *raidlist)2257 { 2258 int res=0;2138 edit_mountlist(char *mountlist_fname, struct mountlist_itself *mountlist, 2139 struct raidlist_itself *raidlist) 2140 { 2141 int res = 0; 2259 2142 // char tmp[MAX_STR_LEN]; 2260 2143 2261 iamhere("entering eml"); 2262 2263 if (g_text_mode) 2264 { 2265 fatal_error("Don't call edit_mountlist() in text mode"); 2266 } 2267 else 2268 { 2269 log_it("I'm in GUI mode, so I shall edit mountlist using edit_mountlist()"); 2270 res = edit_mountlist_in_newt(mountlist_fname, mountlist, raidlist); 2271 } 2272 iamhere("leaving eml"); 2273 return(res); 2144 iamhere("entering eml"); 2145 2146 if (g_text_mode) { 2147 fatal_error("Don't call edit_mountlist() in text mode"); 2148 } else { 2149 log_it 2150 ("I'm in GUI mode, so I shall edit mountlist using edit_mountlist()"); 2151 res = edit_mountlist_in_newt(mountlist_fname, mountlist, raidlist); 2152 } 2153 iamhere("leaving eml"); 2154 return (res); 2274 2155 } 2275 2156 … … 2283 2164 * @ingroup restoreGuiVarslist 2284 2165 */ 2285 void 2286 edit_raidrec_additional_vars (struct raid_device_record *raidrec) 2166 void edit_raidrec_additional_vars(struct raid_device_record *raidrec) 2287 2167 { 2288 2168 2289 2169 /** structure *********************************************************/ 2290 2170 struct raid_device_record bkp_raidrec; 2291 2171 2292 2172 /** newt **************************************************************/ 2293 2173 newtComponent myForm; 2294 2174 newtComponent bAdd; 2295 2175 newtComponent bEdit; … … 2302 2182 2303 2183 /** ?? ***************************************************************/ 2304 2184 void *keylist[ARBITRARY_MAXIMUM], *curr_choice; 2305 2185 2306 2186 /** buffers **********************************************************/ 2307 2187 char title_of_window[MAX_STR_LEN]; 2308 2188 2309 2189 /** int **************************************************************/ 2310 2190 int i = 0; 2311 2191 int currline = 0; 2312 2192 2313 2193 2314 assert(raidrec!=NULL); 2315 2316 memcpy ((void *) &bkp_raidrec, (void *) raidrec, 2317 sizeof (struct raid_device_record)); 2318 sprintf (title_of_window, "Additional variables"); 2319 newtPushHelpLine 2320 (" Edit the additional fields to your heart's content, then click OK or Cancel."); 2321 headerMsg = newtLabel (1, 1, "Label Value"); 2322 varsListbox = 2323 newtListbox (1, 2, 6, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 2324 i = 1; 2325 bAdd = newtCompactButton (i, 9, " Add "); 2326 bEdit = newtCompactButton (i += 8, 9, " Edit "); 2327 bDelete = newtCompactButton (i += 9, 9, "Delete"); 2328 bOK = newtCompactButton (i += 9, 9, " OK "); 2329 bCancel = newtCompactButton (i += 9, 9, "Cancel"); 2330 newtOpenWindow (17, 7, 46, 10, title_of_window); 2331 myForm = newtForm (NULL, NULL, 0); 2332 newtFormAddComponents (myForm, headerMsg, varsListbox, bAdd, bEdit, bDelete, 2333 bOK, bCancel, NULL); 2334 insert_essential_additionalvars (raidrec); 2335 redraw_varslist (&raidrec->additional_vars, keylist, varsListbox); 2336 for (b_res = NULL; b_res != bOK && b_res != bCancel;) 2337 { 2338 b_res = newtRunForm (myForm); 2339 curr_choice = newtListboxGetCurrent (varsListbox); 2340 for (currline = 0; 2341 currline < raidrec->additional_vars.entries 2342 && keylist[currline] != curr_choice; currline++); 2343 if (currline == raidrec->additional_vars.entries 2344 && raidrec->additional_vars.entries > 0) 2345 { 2346 log_it ("Warning - I don't know what this button does"); 2347 } 2348 if (b_res == bOK) 2349 { /* do nothing */ 2350 } 2351 else if (b_res == bCancel) 2352 { /* do nothing */ 2353 } 2354 else if (b_res == bAdd) 2355 { 2356 add_varslist_entry (raidrec); 2357 } 2358 else if (b_res == bDelete) 2359 { 2360 delete_varslist_entry (raidrec, currline); 2361 } 2362 else 2363 { 2364 edit_varslist_entry (raidrec, currline); 2365 } 2366 redraw_varslist (&raidrec->additional_vars, keylist, varsListbox); 2367 } 2368 remove_essential_additionalvars (raidrec); 2369 newtFormDestroy (myForm); 2370 newtPopWindow (); 2371 newtPopHelpLine (); 2372 if (b_res == bCancel) 2373 { 2374 memcpy ((void *) raidrec, (void *) &bkp_raidrec, 2375 sizeof (struct raid_device_record)); 2376 } 2377 return; 2194 assert(raidrec != NULL); 2195 2196 memcpy((void *) &bkp_raidrec, (void *) raidrec, 2197 sizeof(struct raid_device_record)); 2198 sprintf(title_of_window, "Additional variables"); 2199 newtPushHelpLine 2200 (" Edit the additional fields to your heart's content, then click OK or Cancel."); 2201 headerMsg = newtLabel(1, 1, "Label Value"); 2202 varsListbox = 2203 newtListbox(1, 2, 6, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 2204 i = 1; 2205 bAdd = newtCompactButton(i, 9, " Add "); 2206 bEdit = newtCompactButton(i += 8, 9, " Edit "); 2207 bDelete = newtCompactButton(i += 9, 9, "Delete"); 2208 bOK = newtCompactButton(i += 9, 9, " OK "); 2209 bCancel = newtCompactButton(i += 9, 9, "Cancel"); 2210 newtOpenWindow(17, 7, 46, 10, title_of_window); 2211 myForm = newtForm(NULL, NULL, 0); 2212 newtFormAddComponents(myForm, headerMsg, varsListbox, bAdd, bEdit, 2213 bDelete, bOK, bCancel, NULL); 2214 insert_essential_additionalvars(raidrec); 2215 redraw_varslist(&raidrec->additional_vars, keylist, varsListbox); 2216 for (b_res = NULL; b_res != bOK && b_res != bCancel;) { 2217 b_res = newtRunForm(myForm); 2218 curr_choice = newtListboxGetCurrent(varsListbox); 2219 for (currline = 0; 2220 currline < raidrec->additional_vars.entries 2221 && keylist[currline] != curr_choice; currline++); 2222 if (currline == raidrec->additional_vars.entries 2223 && raidrec->additional_vars.entries > 0) { 2224 log_it("Warning - I don't know what this button does"); 2225 } 2226 if (b_res == bOK) { /* do nothing */ 2227 } else if (b_res == bCancel) { /* do nothing */ 2228 } else if (b_res == bAdd) { 2229 add_varslist_entry(raidrec); 2230 } else if (b_res == bDelete) { 2231 delete_varslist_entry(raidrec, currline); 2232 } else { 2233 edit_varslist_entry(raidrec, currline); 2234 } 2235 redraw_varslist(&raidrec->additional_vars, keylist, varsListbox); 2236 } 2237 remove_essential_additionalvars(raidrec); 2238 newtFormDestroy(myForm); 2239 newtPopWindow(); 2240 newtPopHelpLine(); 2241 if (b_res == bCancel) { 2242 memcpy((void *) raidrec, (void *) &bkp_raidrec, 2243 sizeof(struct raid_device_record)); 2244 } 2245 return; 2378 2246 } 2379 2247 #endif … … 2386 2254 * @ingroup restoreGuiDisklist 2387 2255 */ 2388 int 2389 find_next_free_index_in_disklist (struct list_of_disks *disklist) 2256 int find_next_free_index_in_disklist(struct list_of_disks *disklist) 2390 2257 { 2391 2258 2392 2259 /** int ***************************************************************/ 2393 2260 int index = -1; 2394 2261 int pos = 0; 2395 2262 2396 2263 /** bool **************************************************************/ 2397 bool done; 2398 2399 assert(disklist!=NULL); 2400 2401 for (done = FALSE; !done;) 2402 { 2403 for (pos = 0; 2404 pos < disklist->entries && disklist->el[pos].index <= index; 2405 pos++); 2406 if (pos >= disklist->entries) 2407 { 2408 done = TRUE; 2409 } 2410 else 2411 { 2412 index = disklist->el[pos].index; 2413 } 2414 } 2415 return (index + 1); 2264 bool done; 2265 2266 assert(disklist != NULL); 2267 2268 for (done = FALSE; !done;) { 2269 for (pos = 0; 2270 pos < disklist->entries && disklist->el[pos].index <= index; 2271 pos++); 2272 if (pos >= disklist->entries) { 2273 done = TRUE; 2274 } else { 2275 index = disklist->el[pos].index; 2276 } 2277 } 2278 return (index + 1); 2416 2279 } 2417 2280 … … 2426 2289 */ 2427 2290 int 2428 find_raid_device_in_raidlist (struct raidlist_itself *raidlist, char *device) 2291 find_raid_device_in_raidlist(struct raidlist_itself *raidlist, 2292 char *device) 2429 2293 { 2430 2294 2431 2295 /** int ***************************************************************/ 2432 2296 int i = 0; 2433 2297 #ifdef __FreeBSD__ 2434 char vdev[64];2298 char vdev[64]; 2435 2299 #else 2436 2300 // Linux 2437 2301 #endif 2438 2439 assert(raidlist!=NULL);2440 2302 2303 assert(raidlist != NULL); 2304 assert_string_is_neither_NULL_nor_zerolength(device); 2441 2305 2442 2306 #ifdef __FreeBSD__ 2443 for (i = 0; i < raidlist->entries; i++) { 2444 sprintf (vdev, "/dev/vinum/%s", raidlist->el[i].volname); 2445 if (!strcmp (device, vdev)) break; 2446 } 2307 for (i = 0; i < raidlist->entries; i++) { 2308 sprintf(vdev, "/dev/vinum/%s", raidlist->el[i].volname); 2309 if (!strcmp(device, vdev)) 2310 break; 2311 } 2447 2312 #else 2448 2313 2449 2450 strcmp (raidlist->el[i].raid_device, device) && i < raidlist->entries; 2451 2314 for (i = 0; 2315 strcmp(raidlist->el[i].raid_device, device) 2316 && i < raidlist->entries; i++); 2452 2317 #endif 2453 if (i == raidlist->entries) 2454 { 2455 return (-1); 2456 } 2457 else 2458 { 2459 return (i); 2460 } 2318 if (i == raidlist->entries) { 2319 return (-1); 2320 } else { 2321 return (i); 2322 } 2461 2323 } 2462 2324 … … 2471 2333 */ 2472 2334 bool 2473 get_isodir_info (char *isodir_device, char *isodir_format, char *isodir_path, bool nuke_me_please) 2335 get_isodir_info(char *isodir_device, char *isodir_format, 2336 char *isodir_path, bool nuke_me_please) 2474 2337 { 2475 2338 2476 2339 /** initialize ********************************************************/ 2477 2340 2478 assert(isodir_device!=NULL); 2479 assert(isodir_format!=NULL); 2480 assert(isodir_path!=NULL); 2481 2482 log_it("%d - AAA - isodir_path = %s", isodir_path); 2483 isodir_format[0] = '\0'; 2484 if (isodir_device[0]=='\0') { strcpy (isodir_device, "/dev/"); } 2485 if (isodir_path[0]=='\0') { strcpy (isodir_path, "/"); } 2486 if (does_file_exist ("/tmp/NFS-SERVER-PATH")) 2487 { 2488 strcpy (isodir_device, last_line_of_file ("/tmp/NFS-SERVER-MOUNT")); 2489 strcpy (isodir_format, "nfs"); 2490 strcpy (isodir_path, last_line_of_file ("/tmp/NFS-SERVER-PATH")); 2491 } 2492 if (nuke_me_please) { return(TRUE); } 2493 2494 if (popup_and_get_string 2495 ("ISO Mode - device", "On what device do the ISO files live?", 2496 isodir_device, MAX_STR_LEN/4)) 2497 { 2498 if (popup_and_get_string 2499 ("ISO Mode - format", 2500 "What is the disk format of the device? (Hit ENTER if you don't know.)", 2501 isodir_format, 16)) 2502 { 2503 if (popup_and_get_string 2504 ("ISO Mode - path", 2505 "At what path on this device can the ISO files be found?", 2506 isodir_path, MAX_STR_LEN/4)) 2507 { 2508 strip_spaces (isodir_device); 2509 strip_spaces (isodir_format); 2510 strip_spaces (isodir_path); 2511 log_it("%d - BBB - isodir_path = %s", isodir_path); 2512 return (TRUE); 2513 } 2514 } 2515 } 2516 return (FALSE); 2341 assert(isodir_device != NULL); 2342 assert(isodir_format != NULL); 2343 assert(isodir_path != NULL); 2344 2345 log_it("%d - AAA - isodir_path = %s", isodir_path); 2346 isodir_format[0] = '\0'; 2347 if (isodir_device[0] == '\0') { 2348 strcpy(isodir_device, "/dev/"); 2349 } 2350 if (isodir_path[0] == '\0') { 2351 strcpy(isodir_path, "/"); 2352 } 2353 if (does_file_exist("/tmp/NFS-SERVER-PATH")) { 2354 strcpy(isodir_device, last_line_of_file("/tmp/NFS-SERVER-MOUNT")); 2355 strcpy(isodir_format, "nfs"); 2356 strcpy(isodir_path, last_line_of_file("/tmp/NFS-SERVER-PATH")); 2357 } 2358 if (nuke_me_please) { 2359 return (TRUE); 2360 } 2361 2362 if (popup_and_get_string 2363 ("ISO Mode - device", "On what device do the ISO files live?", 2364 isodir_device, MAX_STR_LEN / 4)) { 2365 if (popup_and_get_string 2366 ("ISO Mode - format", 2367 "What is the disk format of the device? (Hit ENTER if you don't know.)", 2368 isodir_format, 16)) { 2369 if (popup_and_get_string 2370 ("ISO Mode - path", 2371 "At what path on this device can the ISO files be found?", 2372 isodir_path, MAX_STR_LEN / 4)) { 2373 strip_spaces(isodir_device); 2374 strip_spaces(isodir_format); 2375 strip_spaces(isodir_path); 2376 log_it("%d - BBB - isodir_path = %s", isodir_path); 2377 return (TRUE); 2378 } 2379 } 2380 } 2381 return (FALSE); 2517 2382 } 2518 2383 … … 2527 2392 */ 2528 2393 void 2529 initiate_new_raidlist_entry 2530 struct mountlist_itself *mountlist, int currline,2531 2394 initiate_new_raidlist_entry(struct raidlist_itself *raidlist, 2395 struct mountlist_itself *mountlist, 2396 int currline, char *device) 2532 2397 { 2533 2398 2534 2399 /** structure *********************************************************/ 2535 struct OSSWAP (raid_device_record, vinum_volume) *raidrec;2400 struct OSSWAP (raid_device_record, vinum_volume) * raidrec; 2536 2401 2537 2402 /** int ***************************************************************/ 2538 int pos_in_raidlist = 0; 2539 2540 assert(raidlist!=NULL); 2541 assert(mountlist!=NULL); 2542 assert_string_is_neither_NULL_nor_zerolength(device); 2543 2544 pos_in_raidlist = 2545 find_raid_device_in_raidlist (raidlist, mountlist->el[currline].device); 2546 if (pos_in_raidlist >= 0) 2547 { 2548 fatal_error ("Sorry, that RAID device already exists. Weird."); 2549 } 2550 pos_in_raidlist = raidlist->entries++; 2551 raidrec = &raidlist->el[pos_in_raidlist]; 2552 initialize_raidrec (raidrec); 2553 strcpy (raidrec->OSSWAP (raid_device, volname), OSSWAP (device, basename (device))); 2403 int pos_in_raidlist = 0; 2404 2405 assert(raidlist != NULL); 2406 assert(mountlist != NULL); 2407 assert_string_is_neither_NULL_nor_zerolength(device); 2408 2409 pos_in_raidlist = 2410 find_raid_device_in_raidlist(raidlist, 2411 mountlist->el[currline].device); 2412 if (pos_in_raidlist >= 0) { 2413 fatal_error("Sorry, that RAID device already exists. Weird."); 2414 } 2415 pos_in_raidlist = raidlist->entries++; 2416 raidrec = &raidlist->el[pos_in_raidlist]; 2417 initialize_raidrec(raidrec); 2418 strcpy(raidrec->OSSWAP(raid_device, volname), 2419 OSSWAP(device, basename(device))); 2554 2420 #ifndef __FreeBSD__ 2555 choose_raid_level(raidrec);2556 select_raid_disks(mountlist, raidlist, raidrec, "data",2557 2421 choose_raid_level(raidrec); 2422 select_raid_disks(mountlist, raidlist, raidrec, "data", 2423 &raidrec->data_disks); 2558 2424 #endif 2559 edit_raidlist_entry(mountlist, raidlist, raidrec, currline);2425 edit_raidlist_entry(mountlist, raidlist, raidrec, currline); 2560 2426 } 2561 2427 … … 2567 2433 * @ingroup restoreGuiVarslist 2568 2434 */ 2569 void 2570 insert_essential_additionalvars (struct raid_device_record *raidrec) 2435 void insert_essential_additionalvars(struct raid_device_record *raidrec) 2571 2436 { 2572 2437 2573 2438 /** int **************************************************************/ 2574 2575 2576 assert(raidrec!=NULL);2577 2578 2579 write_variableINT_to_raid_var_line(raidrec, items++,2580 2581 2582 write_variableINT_to_raid_var_line(raidrec, items++, "chunk-size",2583 2584 2439 int items = 0; 2440 2441 assert(raidrec != NULL); 2442 2443 items = raidrec->additional_vars.entries; 2444 write_variableINT_to_raid_var_line(raidrec, items++, 2445 "persistent-superblock", 2446 raidrec->persistent_superblock); 2447 write_variableINT_to_raid_var_line(raidrec, items++, "chunk-size", 2448 raidrec->chunk_size); 2449 raidrec->additional_vars.entries = items; 2585 2450 } 2586 2451 … … 2590 2455 * Dummy function that proves that we can get to the point where Mondo is run. 2591 2456 */ 2592 void 2593 nuke_mode_dummy () 2457 void nuke_mode_dummy() 2594 2458 { 2595 2459 2596 2460 /** newt *************************************************************/ 2597 2461 newtComponent myForm; 2598 2462 newtComponent b1; 2599 2463 newtComponent b2; … … 2602 2466 2603 2467 2604 2605 2606 newtOpenWindow(24, 3, 32, 13, "Nuking");2607 b1 = newtButton(7, 1, "Slowly");2608 b2 = newtButton(7, 5, "Medium");2609 b3 = newtButton(7, 9, "Quickly");2610 myForm = newtForm(NULL, NULL, 0);2611 newtFormAddComponents(myForm, b1, b2, b3, NULL);2612 b_res = newtRunForm(myForm);2613 newtFormDestroy(myForm);2614 newtPopWindow();2615 newtPopHelpLine();2468 newtPushHelpLine 2469 ("This is where I nuke your hard drives. Mhahahahaha. No-one can stop Mojo Jojo!"); 2470 newtOpenWindow(24, 3, 32, 13, "Nuking"); 2471 b1 = newtButton(7, 1, "Slowly"); 2472 b2 = newtButton(7, 5, "Medium"); 2473 b3 = newtButton(7, 9, "Quickly"); 2474 myForm = newtForm(NULL, NULL, 0); 2475 newtFormAddComponents(myForm, b1, b2, b3, NULL); 2476 b_res = newtRunForm(myForm); 2477 newtFormDestroy(myForm); 2478 newtPopWindow(); 2479 newtPopHelpLine(); 2616 2480 } 2617 2481 … … 2626 2490 */ 2627 2491 void 2628 redraw_disklist 2629 2492 redraw_disklist(struct list_of_disks *disklist, 2493 void *keylist[ARBITRARY_MAXIMUM], newtComponent listbox) 2630 2494 { 2631 2495 2632 2496 /** int *************************************************************/ 2633 int i = 0; 2634 2635 assert(disklist!=NULL); 2636 assert(keylist!=NULL); 2637 assert(listbox!=NULL); 2638 2639 newtListboxClear (listbox); 2640 2641 for (i = 0; i < ARBITRARY_MAXIMUM; i++) 2642 { 2643 keylist[i] = (void *) i; 2644 } 2645 for (i = 0; i < disklist->entries; i++) 2646 { 2647 newtListboxAppendEntry (listbox, disklist_entry_to_string (disklist, i), 2648 keylist[i]); 2649 } 2497 int i = 0; 2498 2499 assert(disklist != NULL); 2500 assert(keylist != NULL); 2501 assert(listbox != NULL); 2502 2503 newtListboxClear(listbox); 2504 2505 for (i = 0; i < ARBITRARY_MAXIMUM; i++) { 2506 keylist[i] = (void *) i; 2507 } 2508 for (i = 0; i < disklist->entries; i++) { 2509 newtListboxAppendEntry(listbox, 2510 disklist_entry_to_string(disklist, i), 2511 keylist[i]); 2512 } 2650 2513 } 2651 2514 … … 2659 2522 */ 2660 2523 void 2661 redraw_mountlist 2662 2663 { 2664 2524 redraw_mountlist(struct mountlist_itself *mountlist, 2525 void *keylist[ARBITRARY_MAXIMUM], newtComponent listbox) 2526 { 2527 2665 2528 /** int **************************************************************/ 2666 2667 2668 assert(mountlist!=NULL);2669 assert(keylist!=NULL);2670 assert(listbox!=NULL);2671 2672 newtListboxClear(listbox);2529 int i = 0; 2530 2531 assert(mountlist != NULL); 2532 assert(keylist != NULL); 2533 assert(listbox != NULL); 2534 2535 newtListboxClear(listbox); 2673 2536 // sort_mountlist_by_device (mountlist); 2674 for (i = 0; i < ARBITRARY_MAXIMUM; i++) 2675 { 2676 keylist[i] = (void *) i; 2677 } 2678 for (i = 0; i < mountlist->entries; i++) 2679 { 2680 newtListboxAppendEntry (listbox, 2681 mountlist_entry_to_string (mountlist, i), 2682 keylist[i]); 2683 } 2537 for (i = 0; i < ARBITRARY_MAXIMUM; i++) { 2538 keylist[i] = (void *) i; 2539 } 2540 for (i = 0; i < mountlist->entries; i++) { 2541 newtListboxAppendEntry(listbox, 2542 mountlist_entry_to_string(mountlist, i), 2543 keylist[i]); 2544 } 2684 2545 } 2685 2546 … … 2694 2555 * @ingroup restoreGuiDisklist 2695 2556 */ 2696 void 2697 redraw_unallocpartnslist (struct mountlist_itself 2698 *unallocated_raid_partitions, 2699 void *keylist[ARBITRARY_MAXIMUM], 2700 newtComponent listbox) 2557 void redraw_unallocpartnslist(struct mountlist_itself 2558 *unallocated_raid_partitions, 2559 void *keylist[ARBITRARY_MAXIMUM], 2560 newtComponent listbox) 2701 2561 { 2702 2562 2703 2563 /** int **************************************************************/ 2704 2564 int i = 0; 2705 2565 2706 2566 /** buffers **********************************************************/ 2707 char tmp[MAX_STR_LEN]; 2708 2709 assert(unallocated_raid_partitions!=NULL); 2710 assert(keylist!=NULL); 2711 assert(listbox!=NULL); 2712 2713 newtListboxClear (listbox); 2714 for (i = 0; i < ARBITRARY_MAXIMUM; i++) 2715 { 2716 keylist[i] = (void *) i; 2717 } 2718 for (i = 0; i < unallocated_raid_partitions->entries; i++) 2719 { 2720 sprintf (tmp, "%-22s %8lld", unallocated_raid_partitions->el[i].device, 2721 unallocated_raid_partitions->el[i].size / 1024); 2722 newtListboxAppendEntry (listbox, tmp, keylist[i]); 2723 } 2567 char tmp[MAX_STR_LEN]; 2568 2569 assert(unallocated_raid_partitions != NULL); 2570 assert(keylist != NULL); 2571 assert(listbox != NULL); 2572 2573 newtListboxClear(listbox); 2574 for (i = 0; i < ARBITRARY_MAXIMUM; i++) { 2575 keylist[i] = (void *) i; 2576 } 2577 for (i = 0; i < unallocated_raid_partitions->entries; i++) { 2578 sprintf(tmp, "%-22s %8lld", 2579 unallocated_raid_partitions->el[i].device, 2580 unallocated_raid_partitions->el[i].size / 1024); 2581 newtListboxAppendEntry(listbox, tmp, keylist[i]); 2582 } 2724 2583 } 2725 2584 … … 2733 2592 */ 2734 2593 void 2735 redraw_varslist 2736 2594 redraw_varslist(struct additional_raid_variables *additional_vars, 2595 void *keylist[], newtComponent listbox) 2737 2596 { 2738 2597 /** int *************************************************************/ 2739 int i= 0;2598 int i = 0; 2740 2599 2741 2600 /** buffers *********************************************************/ 2742 char tmp[MAX_STR_LEN]; 2743 2744 assert(additional_vars!=NULL); 2745 assert(keylist!=NULL); 2746 assert(listbox!=NULL); 2747 2748 newtListboxClear (listbox); 2749 2750 for (i = 0; i < ARBITRARY_MAXIMUM; i++) 2751 { 2752 keylist[i] = (void *) i; 2753 } 2754 for (i = 0; i < additional_vars->entries; i++) 2755 { 2756 sprintf (tmp, "%-32s %-8s", additional_vars->el[i].label, 2757 additional_vars->el[i].value); 2758 newtListboxAppendEntry (listbox, tmp, keylist[i]); 2759 } 2601 char tmp[MAX_STR_LEN]; 2602 2603 assert(additional_vars != NULL); 2604 assert(keylist != NULL); 2605 assert(listbox != NULL); 2606 2607 newtListboxClear(listbox); 2608 2609 for (i = 0; i < ARBITRARY_MAXIMUM; i++) { 2610 keylist[i] = (void *) i; 2611 } 2612 for (i = 0; i < additional_vars->entries; i++) { 2613 sprintf(tmp, "%-32s %-8s", additional_vars->el[i].label, 2614 additional_vars->el[i].value); 2615 newtListboxAppendEntry(listbox, tmp, keylist[i]); 2616 } 2760 2617 } 2761 2618 … … 2769 2626 */ 2770 2627 int 2771 read_variableINT_and_remove_from_raidvars (struct OSSWAP (raid_device_record, vinum_volume) *raidrec, 2772 char *label) 2628 read_variableINT_and_remove_from_raidvars(struct 2629 OSSWAP (raid_device_record, 2630 vinum_volume) * raidrec, 2631 char *label) 2773 2632 { 2774 2633 /** int ***************************************************************/ 2775 int i= 0;2634 int i = 0; 2776 2635 int res = 0; 2777 2636 2778 2637 2779 assert(raidrec!=NULL); 2780 assert(label!=NULL); 2781 2782 for (i = 0; 2783 i < raidrec->additional_vars.entries 2784 && strcmp (raidrec->additional_vars.el[i].label, label); i++); 2785 if (i == raidrec->additional_vars.entries) 2786 { 2787 res = -1; 2788 } 2789 else 2790 { 2791 res = atoi (raidrec->additional_vars.el[i].value); 2792 for (i++; i < raidrec->additional_vars.entries; i++) 2793 { 2794 memcpy ((void *) &raidrec->additional_vars.el[i - 1], 2795 (void *) &raidrec->additional_vars.el[i], 2796 sizeof (struct raid_var_line)); 2797 } 2798 raidrec->additional_vars.entries--; 2799 } 2800 return (res); 2638 assert(raidrec != NULL); 2639 assert(label != NULL); 2640 2641 for (i = 0; 2642 i < raidrec->additional_vars.entries 2643 && strcmp(raidrec->additional_vars.el[i].label, label); i++); 2644 if (i == raidrec->additional_vars.entries) { 2645 res = -1; 2646 } else { 2647 res = atoi(raidrec->additional_vars.el[i].value); 2648 for (i++; i < raidrec->additional_vars.entries; i++) { 2649 memcpy((void *) &raidrec->additional_vars.el[i - 1], 2650 (void *) &raidrec->additional_vars.el[i], 2651 sizeof(struct raid_var_line)); 2652 } 2653 raidrec->additional_vars.entries--; 2654 } 2655 return (res); 2801 2656 } 2802 2657 #endif … … 2809 2664 * @ingroup restoreGuiMountlist 2810 2665 */ 2811 void 2812 rejig_partition_name_in_raidlist_if_necessary (struct raidlist_itself 2813 *raidlist,char *old_dev,2814 2666 void rejig_partition_name_in_raidlist_if_necessary(struct raidlist_itself 2667 *raidlist, 2668 char *old_dev, 2669 char *new_dev) 2815 2670 { 2816 2671 /** buffers ********************************************************/ 2817 2672 char tmp[MAX_STR_LEN]; 2818 2673 2819 2674 /** int ************************************************************/ 2820 2675 int pos = 0; 2821 2676 int j = 0; 2822 2677 2823 assert(raidlist!=NULL); 2824 assert_string_is_neither_NULL_nor_zerolength(old_dev); 2825 assert_string_is_neither_NULL_nor_zerolength(new_dev); 2826 2827 pos = which_raid_device_is_using_this_partition (raidlist, old_dev); 2828 if (pos < 0) 2829 { 2830 sprintf (tmp, "No need to rejig %s in raidlist: it's not listed.", 2831 old_dev); 2832 log_it (tmp); 2833 } 2834 else 2835 { 2836 if ((j = 2837 where_in_drivelist_is_drive (&raidlist->OSSWAP (el[pos].data_disks, disks), 2838 old_dev)) >= 0) 2839 { 2840 strcpy (raidlist->OSSWAP (el[pos].data_disks, disks).el[j].device, new_dev); 2841 } 2842 else 2843 if ((j = 2844 where_in_drivelist_is_drive (&raidlist->OSSWAP (el[pos].spare_disks, spares), 2845 old_dev)) >= 0) 2846 { 2847 strcpy (raidlist->OSSWAP (el[pos].spare_disks, spares).el[j].device, new_dev); 2848 } 2678 assert(raidlist != NULL); 2679 assert_string_is_neither_NULL_nor_zerolength(old_dev); 2680 assert_string_is_neither_NULL_nor_zerolength(new_dev); 2681 2682 pos = which_raid_device_is_using_this_partition(raidlist, old_dev); 2683 if (pos < 0) { 2684 sprintf(tmp, "No need to rejig %s in raidlist: it's not listed.", 2685 old_dev); 2686 log_it(tmp); 2687 } else { 2688 if ((j = 2689 where_in_drivelist_is_drive(&raidlist-> 2690 OSSWAP(el[pos].data_disks, disks), 2691 old_dev)) >= 0) { 2692 strcpy(raidlist->OSSWAP(el[pos].data_disks, disks).el[j]. 2693 device, new_dev); 2694 } else 2695 if ((j = 2696 where_in_drivelist_is_drive(&raidlist-> 2697 OSSWAP(el[pos].spare_disks, 2698 spares), 2699 old_dev)) >= 0) { 2700 strcpy(raidlist->OSSWAP(el[pos].spare_disks, spares).el[j]. 2701 device, new_dev); 2702 } 2849 2703 #ifndef __FreeBSD__ 2850 else 2851 if ((j = 2852 where_in_drivelist_is_drive (&raidlist->el[pos].parity_disks, 2853 old_dev)) >= 0) 2854 { 2855 strcpy (raidlist->el[pos].parity_disks.el[j].device, new_dev); 2856 } 2857 else 2858 if ((j = 2859 where_in_drivelist_is_drive (&raidlist->el[pos].failed_disks, 2860 old_dev)) >= 0) 2861 { 2862 strcpy (raidlist->el[pos].failed_disks.el[j].device, new_dev); 2863 } 2704 else if ((j = 2705 where_in_drivelist_is_drive(&raidlist->el[pos]. 2706 parity_disks, 2707 old_dev)) >= 0) { 2708 strcpy(raidlist->el[pos].parity_disks.el[j].device, new_dev); 2709 } else 2710 if ((j = 2711 where_in_drivelist_is_drive(&raidlist->el[pos]. 2712 failed_disks, 2713 old_dev)) >= 0) { 2714 strcpy(raidlist->el[pos].failed_disks.el[j].device, new_dev); 2715 } 2864 2716 #endif 2865 else 2866 { 2867 sprintf (tmp, 2868 "%s is supposed to be listed in this raid dev but it's not...", 2869 old_dev); 2870 log_it (tmp); 2871 } 2872 } 2717 else { 2718 sprintf(tmp, 2719 "%s is supposed to be listed in this raid dev but it's not...", 2720 old_dev); 2721 log_it(tmp); 2722 } 2723 } 2873 2724 } 2874 2725 … … 2881 2732 * @ingroup restoreUtilityVarslist 2882 2733 */ 2883 void 2884 remove_essential_additionalvars (struct raid_device_record *raidrec) 2734 void remove_essential_additionalvars(struct raid_device_record *raidrec) 2885 2735 { 2886 2736 2887 2737 /** int **************************************************************/ 2888 int res = 0; 2889 2890 assert(raidrec!=NULL); 2891 2892 res = 2893 read_variableINT_and_remove_from_raidvars (raidrec, 2894 "persistent-superblock"); 2895 if (res > 0) 2896 { 2897 raidrec->persistent_superblock = res; 2898 } 2899 res = read_variableINT_and_remove_from_raidvars (raidrec, "chunk-size"); 2900 if (res > 0) 2901 { 2902 raidrec->chunk_size = res; 2903 } 2904 res = read_variableINT_and_remove_from_raidvars (raidrec, "block-size"); 2738 int res = 0; 2739 2740 assert(raidrec != NULL); 2741 2742 res = 2743 read_variableINT_and_remove_from_raidvars(raidrec, 2744 "persistent-superblock"); 2745 if (res > 0) { 2746 raidrec->persistent_superblock = res; 2747 } 2748 res = read_variableINT_and_remove_from_raidvars(raidrec, "chunk-size"); 2749 if (res > 0) { 2750 raidrec->chunk_size = res; 2751 } 2752 res = read_variableINT_and_remove_from_raidvars(raidrec, "block-size"); 2905 2753 } 2906 2754 … … 2915 2763 */ 2916 2764 void 2917 select_raid_disks (struct mountlist_itself *mountlist_dontedit, 2918 struct raidlist_itself *raidlist, 2919 struct raid_device_record *raidrec, 2920 char *description_of_list, struct list_of_disks *disklist) 2921 { 2922 void *curr_choice; 2765 select_raid_disks(struct mountlist_itself *mountlist_dontedit, 2766 struct raidlist_itself *raidlist, 2767 struct raid_device_record *raidrec, 2768 char *description_of_list, 2769 struct list_of_disks *disklist) 2770 { 2771 void *curr_choice; 2923 2772 2924 2773 /** ??? ***************************************************************/ 2925 2774 2926 2775 /** structures ********************************************************/ 2927 2928 2929 2930 2776 struct raidlist_itself *bkp_raidlist; 2777 struct raid_device_record *bkp_raidrec; 2778 struct list_of_disks *bkp_disklist; 2779 struct mountlist_itself *unallocated_raid_partitions; 2931 2780 2932 2781 /** newt **************************************************************/ 2933 newtComponent myForm=NULL;2934 newtComponent bAdd=NULL;2935 newtComponent bDelete =NULL;2936 newtComponent bOK =NULL;2937 newtComponent bCancel =NULL;2938 newtComponent b_res =NULL;2939 newtComponent partitionsListbox =NULL;2940 newtComponent headerMsg =NULL;2782 newtComponent myForm = NULL; 2783 newtComponent bAdd = NULL; 2784 newtComponent bDelete = NULL; 2785 newtComponent bOK = NULL; 2786 newtComponent bCancel = NULL; 2787 newtComponent b_res = NULL; 2788 newtComponent partitionsListbox = NULL; 2789 newtComponent headerMsg = NULL; 2941 2790 2942 2791 /** buffers **********************************************************/ 2943 2944 2945 2946 2947 2948 2792 void *keylist[ARBITRARY_MAXIMUM]; 2793 char *tmp; 2794 char *help_text; 2795 char *title_of_window; 2796 char *sz_res; 2797 char *header_text; 2949 2798 2950 2799 /** int **************************************************************/ 2951 int i = 0; 2952 int currline = 0; 2953 2954 assert(mountlist_dontedit!=NULL); 2955 assert(raidlist!=NULL); 2956 assert(raidrec!=NULL); 2957 assert(description_of_list!=NULL); 2958 assert(disklist!=NULL); 2959 2960 iamhere("malloc'ing"); 2961 malloc_string(tmp); 2962 malloc_string(help_text); 2963 malloc_string(title_of_window); 2964 malloc_string(sz_res); 2965 malloc_string(header_text); 2966 if (!(bkp_raidrec = malloc(sizeof(struct raid_device_record)))) 2967 { fatal_error("Cannot malloc space for raidrec"); } 2968 if (!(bkp_disklist = malloc(sizeof(struct list_of_disks)))) 2969 { fatal_error("Cannot malloc space for disklist"); } 2970 if (!(bkp_raidlist = malloc(sizeof(struct raidlist_itself)))) 2971 { fatal_error("Cannot malloc space for raidlist"); } 2972 if (!(unallocated_raid_partitions = malloc(sizeof(struct mountlist_itself)))) 2973 { fatal_error("Cannot malloc space for unallocated_raid_partitions"); } 2974 2975 memcpy ((void *) bkp_raidlist, (void *) raidlist, 2976 sizeof (struct raidlist_itself)); 2977 memcpy ((void *) bkp_raidrec, (void *) raidrec, 2978 sizeof (struct raid_device_record)); 2979 memcpy ((void *) bkp_disklist, (void *) disklist, 2980 sizeof (struct list_of_disks)); 2981 2982 iamhere("Post-malloc"); 2983 strcpy (help_text, 2984 " Edit this RAID device's list of partitions. Choose OK or Cancel when done."); 2985 sprintf (header_text, "%-24s %s", "Device", "Index"); 2986 sprintf (title_of_window, "%s contains...", raidrec->raid_device); 2987 newtPushHelpLine (help_text); 2988 for (b_res = (newtComponent) 12345; b_res != bOK && b_res != bCancel;) 2989 { 2990 headerMsg = newtLabel (1, 1, header_text); 2991 partitionsListbox = 2992 newtListbox (1, 2, 6, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 2993 redraw_disklist (disklist, keylist, partitionsListbox); 2994 i = 1; 2995 bAdd = newtCompactButton (i, 9, " Add "); 2996 bDelete = newtCompactButton (i += 8, 9, "Delete"); 2997 bOK = newtCompactButton (i += 9, 9, " OK "); 2998 bCancel = newtCompactButton (i += 9, 9, "Cancel"); 2999 newtOpenWindow (21, 7, 38, 10, title_of_window); 3000 myForm = newtForm (NULL, NULL, 0); 3001 if (disklist->entries == 0) 3002 { 3003 newtFormAddComponents (myForm, headerMsg, bAdd, bDelete, bOK, 3004 bCancel, NULL); 3005 } 3006 else 3007 { 3008 newtFormAddComponents (myForm, headerMsg, partitionsListbox, bAdd, 3009 bDelete, bOK, bCancel, NULL); 3010 } 3011 b_res = newtRunForm (myForm); 3012 if (b_res == bOK || b_res == bCancel) 3013 { /* do nothing */ 2800 int i = 0; 2801 int currline = 0; 2802 2803 assert(mountlist_dontedit != NULL); 2804 assert(raidlist != NULL); 2805 assert(raidrec != NULL); 2806 assert(description_of_list != NULL); 2807 assert(disklist != NULL); 2808 2809 iamhere("malloc'ing"); 2810 malloc_string(tmp); 2811 malloc_string(help_text); 2812 malloc_string(title_of_window); 2813 malloc_string(sz_res); 2814 malloc_string(header_text); 2815 if (!(bkp_raidrec = malloc(sizeof(struct raid_device_record)))) { 2816 fatal_error("Cannot malloc space for raidrec"); 2817 } 2818 if (!(bkp_disklist = malloc(sizeof(struct list_of_disks)))) { 2819 fatal_error("Cannot malloc space for disklist"); 2820 } 2821 if (!(bkp_raidlist = malloc(sizeof(struct raidlist_itself)))) { 2822 fatal_error("Cannot malloc space for raidlist"); 2823 } 2824 if (! 2825 (unallocated_raid_partitions = 2826 malloc(sizeof(struct mountlist_itself)))) { 2827 fatal_error("Cannot malloc space for unallocated_raid_partitions"); 2828 } 2829 2830 memcpy((void *) bkp_raidlist, (void *) raidlist, 2831 sizeof(struct raidlist_itself)); 2832 memcpy((void *) bkp_raidrec, (void *) raidrec, 2833 sizeof(struct raid_device_record)); 2834 memcpy((void *) bkp_disklist, (void *) disklist, 2835 sizeof(struct list_of_disks)); 2836 2837 iamhere("Post-malloc"); 2838 strcpy(help_text, 2839 " Edit this RAID device's list of partitions. Choose OK or Cancel when done."); 2840 sprintf(header_text, "%-24s %s", "Device", "Index"); 2841 sprintf(title_of_window, "%s contains...", raidrec->raid_device); 2842 newtPushHelpLine(help_text); 2843 for (b_res = (newtComponent) 12345; b_res != bOK && b_res != bCancel;) { 2844 headerMsg = newtLabel(1, 1, header_text); 2845 partitionsListbox = 2846 newtListbox(1, 2, 6, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); 2847 redraw_disklist(disklist, keylist, partitionsListbox); 2848 i = 1; 2849 bAdd = newtCompactButton(i, 9, " Add "); 2850 bDelete = newtCompactButton(i += 8, 9, "Delete"); 2851 bOK = newtCompactButton(i += 9, 9, " OK "); 2852 bCancel = newtCompactButton(i += 9, 9, "Cancel"); 2853 newtOpenWindow(21, 7, 38, 10, title_of_window); 2854 myForm = newtForm(NULL, NULL, 0); 2855 if (disklist->entries == 0) { 2856 newtFormAddComponents(myForm, headerMsg, bAdd, bDelete, bOK, 2857 bCancel, NULL); 2858 } else { 2859 newtFormAddComponents(myForm, headerMsg, partitionsListbox, 2860 bAdd, bDelete, bOK, bCancel, NULL); 2861 } 2862 b_res = newtRunForm(myForm); 2863 if (b_res == bOK || b_res == bCancel) { /* do nothing */ 3014 2864 // That's OK. At the end of this subroutine (after this do/while loop), 3015 2865 // we'll throw away the changes if Cancel was pushed. 3016 } 3017 else 3018 { 3019 curr_choice = newtListboxGetCurrent (partitionsListbox); 3020 for (i = 0; i < disklist->entries && keylist[i] != curr_choice; 3021 i++); 3022 if (i == disklist->entries && disklist->entries > 0) 3023 { 3024 log_to_screen ("I don't know what that button does!"); 3025 } 3026 else 3027 { 3028 currline = i; 3029 if (b_res == bAdd) 3030 { 3031 log_it ("Making list of unallocated RAID slices"); 3032 make_list_of_unallocated_raid_partitions 3033 (unallocated_raid_partitions, mountlist_dontedit, 3034 raidlist); 3035 if (unallocated_raid_partitions->entries <= 0) 3036 { 3037 popup_and_OK 3038 ("There are no unallocated partitions marked for RAID."); 3039 } 3040 else 3041 { 3042 log_it 3043 ("Done. The user may add one or more of the above to RAID device"); 3044 add_disklist_entry (disklist, raidrec->raid_device, 3045 unallocated_raid_partitions); 3046 log_it ("I have finished adding a disklist entry."); 3047 redraw_disklist (disklist, keylist, partitionsListbox); 3048 } 3049 } 3050 else if (b_res == bDelete) 3051 { 3052 delete_disklist_entry (disklist, raidrec->raid_device, 3053 currline); 3054 redraw_disklist (disklist, keylist, partitionsListbox); 3055 } 3056 else 3057 { 3058 sprintf (tmp, "%s's index is %d. What should it be?", 3059 raidrec->raid_device, 3060 disklist->el[currline].index); 3061 sprintf (sz_res, "%d", disklist->el[currline].index); 3062 if (popup_and_get_string ("Set index", tmp, sz_res, 10)) 3063 { 3064 disklist->el[currline].index = atoi (sz_res); 3065 } 3066 redraw_disklist (disklist, keylist, partitionsListbox); 3067 } 3068 } 3069 } 3070 newtFormDestroy (myForm); 3071 newtPopWindow (); 3072 } 3073 newtPopHelpLine (); 3074 if (b_res == bCancel) 3075 { 3076 memcpy ((void *) raidlist, (void *) bkp_raidlist, 3077 sizeof (struct raidlist_itself)); 3078 memcpy ((void *) raidrec, (void *) bkp_raidrec, 3079 sizeof (struct raid_device_record)); 3080 memcpy ((void *) disklist, (void *) bkp_disklist, 3081 sizeof (struct list_of_disks)); 3082 } 3083 paranoid_free(tmp); 3084 paranoid_free(help_text); 3085 paranoid_free(title_of_window); 3086 paranoid_free(sz_res); 3087 paranoid_free(header_text); 3088 paranoid_free(bkp_raidrec); 3089 paranoid_free(bkp_disklist); 3090 paranoid_free(bkp_raidlist); 3091 paranoid_free(unallocated_raid_partitions); 2866 } else { 2867 curr_choice = newtListboxGetCurrent(partitionsListbox); 2868 for (i = 0; i < disklist->entries && keylist[i] != curr_choice; 2869 i++); 2870 if (i == disklist->entries && disklist->entries > 0) { 2871 log_to_screen("I don't know what that button does!"); 2872 } else { 2873 currline = i; 2874 if (b_res == bAdd) { 2875 log_it("Making list of unallocated RAID slices"); 2876 make_list_of_unallocated_raid_partitions 2877 (unallocated_raid_partitions, mountlist_dontedit, 2878 raidlist); 2879 if (unallocated_raid_partitions->entries <= 0) { 2880 popup_and_OK 2881 ("There are no unallocated partitions marked for RAID."); 2882 } else { 2883 log_it 2884 ("Done. The user may add one or more of the above to RAID device"); 2885 add_disklist_entry(disklist, raidrec->raid_device, 2886 unallocated_raid_partitions); 2887 log_it("I have finished adding a disklist entry."); 2888 redraw_disklist(disklist, keylist, 2889 partitionsListbox); 2890 } 2891 } else if (b_res == bDelete) { 2892 delete_disklist_entry(disklist, raidrec->raid_device, 2893 currline); 2894 redraw_disklist(disklist, keylist, partitionsListbox); 2895 } else { 2896 sprintf(tmp, "%s's index is %d. What should it be?", 2897 raidrec->raid_device, 2898 disklist->el[currline].index); 2899 sprintf(sz_res, "%d", disklist->el[currline].index); 2900 if (popup_and_get_string("Set index", tmp, sz_res, 10)) { 2901 disklist->el[currline].index = atoi(sz_res); 2902 } 2903 redraw_disklist(disklist, keylist, partitionsListbox); 2904 } 2905 } 2906 } 2907 newtFormDestroy(myForm); 2908 newtPopWindow(); 2909 } 2910 newtPopHelpLine(); 2911 if (b_res == bCancel) { 2912 memcpy((void *) raidlist, (void *) bkp_raidlist, 2913 sizeof(struct raidlist_itself)); 2914 memcpy((void *) raidrec, (void *) bkp_raidrec, 2915 sizeof(struct raid_device_record)); 2916 memcpy((void *) disklist, (void *) bkp_disklist, 2917 sizeof(struct list_of_disks)); 2918 } 2919 paranoid_free(tmp); 2920 paranoid_free(help_text); 2921 paranoid_free(title_of_window); 2922 paranoid_free(sz_res); 2923 paranoid_free(header_text); 2924 paranoid_free(bkp_raidrec); 2925 paranoid_free(bkp_disklist); 2926 paranoid_free(bkp_raidlist); 2927 paranoid_free(unallocated_raid_partitions); 3092 2928 } 3093 2929 #endif … … 3100 2936 * or 'E' (or any other letter) for exit. 3101 2937 */ 3102 char 3103 which_restore_mode () 3104 { 3105 2938 char which_restore_mode() 2939 { 2940 3106 2941 /** char *************************************************************/ 3107 3108 3109 2942 char output = '\0'; 2943 char tmp[MAX_STR_LEN]; 2944 3110 2945 /** newt *************************************************************/ 3111 2946 3112 newtComponent b1; 3113 newtComponent b2; 3114 newtComponent b3; 3115 newtComponent b4; 3116 newtComponent b_res; 3117 newtComponent myForm; 3118 3119 if (g_text_mode) 3120 { 3121 for(output='z'; !strchr("AICE", output); output=tmp[0]) 3122 { 3123 printf("Which mode - (A)utomatic, (I)nteractive, \n(C)ompare only, or (E)xit to shell?\n--> "); 3124 fgets(tmp, MAX_STR_LEN-1, stdin); 3125 } 3126 return(output); 3127 } 3128 3129 newtPushHelpLine 3130 (" Do you want to 'nuke' your system, restore interactively, or just compare?"); 3131 newtOpenWindow (24, 3, 32, 17, "How should I restore?"); 3132 b1 = newtButton (7, 1, "Automatically"); 3133 b2 = newtButton (7, 5, "Interactively"); 3134 b3 = newtButton (7, 9, "Compare only!"); 3135 b4 = newtButton (7, 13, "Exit to shell"); 3136 myForm = newtForm (NULL, NULL, 0); 3137 newtFormAddComponents (myForm, b1, b2, b3, b4, NULL); 3138 b_res = newtRunForm (myForm); 3139 newtFormDestroy (myForm); 3140 newtPopWindow (); 3141 if (b_res == b1) 3142 { 3143 output = 'N'; 3144 } 3145 if (b_res == b2) 3146 { 3147 output = 'I'; 3148 } 3149 if (b_res == b3) 3150 { 3151 output = 'C'; 3152 } 3153 if (b_res == b4) 3154 { 3155 output = 'E'; 3156 } 3157 newtPopHelpLine (); 3158 return (output); 3159 } 3160 2947 newtComponent b1; 2948 newtComponent b2; 2949 newtComponent b3; 2950 newtComponent b4; 2951 newtComponent b_res; 2952 newtComponent myForm; 2953 2954 if (g_text_mode) { 2955 for (output = 'z'; !strchr("AICE", output); output = tmp[0]) { 2956 printf 2957 ("Which mode - (A)utomatic, (I)nteractive, \n(C)ompare only, or (E)xit to shell?\n--> "); 2958 fgets(tmp, MAX_STR_LEN - 1, stdin); 2959 } 2960 return (output); 2961 } 2962 2963 newtPushHelpLine 2964 (" Do you want to 'nuke' your system, restore interactively, or just compare?"); 2965 newtOpenWindow(24, 3, 32, 17, "How should I restore?"); 2966 b1 = newtButton(7, 1, "Automatically"); 2967 b2 = newtButton(7, 5, "Interactively"); 2968 b3 = newtButton(7, 9, "Compare only!"); 2969 b4 = newtButton(7, 13, "Exit to shell"); 2970 myForm = newtForm(NULL, NULL, 0); 2971 newtFormAddComponents(myForm, b1, b2, b3, b4, NULL); 2972 b_res = newtRunForm(myForm); 2973 newtFormDestroy(myForm); 2974 newtPopWindow(); 2975 if (b_res == b1) { 2976 output = 'N'; 2977 } 2978 if (b_res == b2) { 2979 output = 'I'; 2980 } 2981 if (b_res == b3) { 2982 output = 'C'; 2983 } 2984 if (b_res == b4) { 2985 output = 'E'; 2986 } 2987 newtPopHelpLine(); 2988 return (output); 2989 } -
trunk/mondo/mondo/mondorestore/mondo-rstr-newt.h
r30 r59 5 5 copyright : (C) 2002 by Stan Benoit 6 6 email : troff@nakedsoul.org 7 cvsid : $Id : mondo-rstr-newt.h,v 1.3 2004/06/10 15:29:13 hugo Exp$7 cvsid : $Id$ 8 8 ***************************************************************************/ 9 9 … … 37 37 /* external subroutines and global vars */ 38 38 39 extern long get_time (void); 40 extern char *last_line_of_file (char *); 41 extern void center_string (char *, int); 42 extern bool does_file_exist (char *); 43 extern void finish (int); 44 extern long get_phys_size_of_drive (char *); 45 extern bool is_this_device_mounted (char *); 46 extern void strip_spaces (char *); 47 extern void initialize_raidrec (struct raid_device_record *); 48 extern int make_list_of_drives (struct mountlist_itself *, 49 char[ARBITRARY_MAXIMUM][MAX_STR_LEN]); 50 char *number_to_text (int); 51 extern void reload_filelist (struct s_node *); 52 extern void toggle_all_root_dirs_on (struct s_node *); 53 extern void toggle_path_expandability (struct s_node *, char *, bool); 54 extern void toggle_path_selection (struct s_node *, char *, bool); 55 extern void toggle_node_selection (struct s_node *, bool); 56 extern struct s_node *find_node_in_filelist (struct s_node *, char *filename); 57 extern int what_number_cd_is_this (struct s_bkpinfo*); 39 extern long get_time(void); 40 extern char *last_line_of_file(char *); 41 extern void center_string(char *, int); 42 extern bool does_file_exist(char *); 43 extern void finish(int); 44 extern long get_phys_size_of_drive(char *); 45 extern bool is_this_device_mounted(char *); 46 extern void strip_spaces(char *); 47 extern void initialize_raidrec(struct raid_device_record *); 48 extern int make_list_of_drives(struct mountlist_itself *, 49 char[ARBITRARY_MAXIMUM][MAX_STR_LEN]); 50 char *number_to_text(int); 51 extern void reload_filelist(struct s_node *); 52 extern void toggle_all_root_dirs_on(struct s_node *); 53 extern void toggle_path_expandability(struct s_node *, char *, bool); 54 extern void toggle_path_selection(struct s_node *, char *, bool); 55 extern void toggle_node_selection(struct s_node *, bool); 56 extern struct s_node *find_node_in_filelist(struct s_node *, 57 char *filename); 58 extern int what_number_cd_is_this(struct s_bkpinfo *); 58 59 //extern void fatal_error (char *); 59 extern void sort_mountlist_by_device 60 extern int load_mountlist 60 extern void sort_mountlist_by_device(struct mountlist_itself *); 61 extern int load_mountlist(struct mountlist_itself *a, char *b); 61 62 extern bool g_text_mode; 62 63 63 64 64 65 /* hacks */ 65 extern int load_raidtab_into_raidlist 66 extern int load_raidtab_into_raidlist(struct raidlist_itself *a, char *b); 66 67 67 68 68 69 69 70 extern long g_start_time, g_minimum_progress, g_maximum_progress, 70 71 g_current_progress, g_currentY; 71 72 extern bool g_ISO_restore_mode; 72 73 … … 92 93 /* my subroutines */ 93 94 94 void add_disklist_entry (struct list_of_disks *, char *, 95 struct mountlist_itself *); 96 void add_mountlist_entry (struct mountlist_itself *, struct raidlist_itself *, 97 newtComponent, int, void *keylist[]); 98 void add_varslist_entry (struct raid_device_record *); 99 bool ask_me_yes_or_no (char *); 100 bool ask_me_OK_or_cancel (char *); 101 long calculate_raid_device_size (struct mountlist_itself *, 102 struct raidlist_itself *, char *); 103 void choose_raid_level (struct 95 void add_disklist_entry(struct list_of_disks *, char *, 96 struct mountlist_itself *); 97 void add_mountlist_entry(struct mountlist_itself *, 98 struct raidlist_itself *, newtComponent, int, 99 void *keylist[]); 100 void add_varslist_entry(struct raid_device_record *); 101 bool ask_me_yes_or_no(char *); 102 bool ask_me_OK_or_cancel(char *); 103 long calculate_raid_device_size(struct mountlist_itself *, 104 struct raidlist_itself *, char *); 105 void choose_raid_level(struct 104 106 #ifdef __FreeBSD__ 105 vinum_plex107 vinum_plex 106 108 #else 107 raid_device_record109 raid_device_record 108 110 #endif 109 *); 110 void close_evalcall_form (void); 111 void close_progress_form (void); 112 void del_partns_listed_in_disklist (struct mountlist_itself *, 113 struct raidlist_itself *, 114 struct list_of_disks *); 115 void delete_disklist_entry (struct list_of_disks *, char *, int); 116 void delete_mountlist_entry (struct mountlist_itself *, 117 struct raidlist_itself *, newtComponent, int, 118 void *keylist[]); 119 void delete_raidlist_entry (struct mountlist_itself *, 120 struct raidlist_itself *, char *); 121 void delete_varslist_entry (struct raid_device_record *, int); 122 char *disklist_entry_to_string (struct list_of_disks *, int); 123 int edit_filelist (struct s_node *); 124 void edit_mountlist_entry (struct mountlist_itself *, 125 struct raidlist_itself *, newtComponent, int, 126 void *keylist[]); 127 void edit_raidlist_entry (struct mountlist_itself *, struct raidlist_itself *, 128 struct raid_device_record *, int); 129 void edit_varslist_entry (struct raid_device_record *, int); 130 int edit_mountlist_in_newt (char *mountlist_fname, struct mountlist_itself *, struct raidlist_itself *); 131 int edit_mountlist (char *mountlist_fname, struct mountlist_itself *, struct raidlist_itself *); 132 void edit_raidrec_additional_vars (struct raid_device_record *); 133 int evaluate_drive_within_mountlist (struct mountlist_itself *, char *, 134 char *); 135 int evaluate_mountlist (struct mountlist_itself *, char *, char *, char *); 136 int find_device_in_mountlist (struct mountlist_itself *, char *); 137 int find_next_free_index_in_disklist (struct list_of_disks *); 138 int find_raid_device_in_raidlist (struct raidlist_itself *, char *); 139 bool get_isodir_info (char *, char *, char *, bool); 140 void initiate_new_raidlist_entry (struct raidlist_itself *, 141 struct mountlist_itself *, int, char *); 142 void insert_essential_additionalvars (struct raid_device_record *); 143 bool is_this_raid_personality_registered (int); 144 void log_file_end_to_screen (char *, char *); 145 void log_to_screen (const char *fmt, ...); 146 int look_for_duplicate_mountpoints (struct mountlist_itself *, char *); 147 int look_for_weird_formats (struct mountlist_itself *, char *); 148 void make_list_of_unallocated_raid_partitions (struct mountlist_itself *, 149 struct mountlist_itself *, 150 struct raidlist_itself *); 151 char *mountlist_entry_to_string (struct mountlist_itself *, int); 152 void mvaddstr_and_log_it (int, int, char *); 153 void nuke_mode_dummy (); 154 char *number_of_disks_as_string (int, char *); 155 void open_evalcall_form (char *); 156 void open_progress_form (char *, char *, char *, char *, long); 157 void popup_and_OK (char *); 158 bool popup_and_get_string (char *, char *, char *, int); 159 bool popup_with_buttons (char *, char *, char *); 160 void redraw_disklist (struct list_of_disks *, void *keylist[], newtComponent); 161 void redraw_mountlist (struct mountlist_itself *, void *keylist[], 162 newtComponent); 163 void redraw_unallocpartnslist (struct mountlist_itself *, void *keylist[], 164 newtComponent); 165 void redraw_varslist (struct additional_raid_variables *, void *keylist[], 166 newtComponent); 167 int read_variableINT_and_remove_from_raidvars (struct raid_device_record *, 168 char *); 169 void refresh_log_screen (void); 170 void rejig_partition_name_in_raidlist_if_necessary (struct raidlist_itself *, 171 char *, char *); 172 void remove_essential_additionalvars (struct raid_device_record *); 173 void select_raid_disks (struct mountlist_itself *, struct raidlist_itself *, 174 struct raid_device_record *, char *, 175 struct list_of_disks *); 176 void setup_newt_stuff (void); 177 long size_of_specific_device (struct mountlist_itself *, char *); 178 bool spread_flaws_across_three_lines (char *, char *, char *, char *, int); 179 char *turn_raid_level_number_to_string (int); 180 void update_evalcall_form (int); 181 void update_progress_form (char *); 182 void update_progress_form_full (char *, char *, char *); 183 char which_restore_mode (void); 184 void write_variableINT_to_raid_var_line (struct raid_device_record *, int, 185 char *, int); 186 int where_in_drivelist_is_drive (struct list_of_disks *, char *); 111 *); 112 void close_evalcall_form(void); 113 void close_progress_form(void); 114 void del_partns_listed_in_disklist(struct mountlist_itself *, 115 struct raidlist_itself *, 116 struct list_of_disks *); 117 void delete_disklist_entry(struct list_of_disks *, char *, int); 118 void delete_mountlist_entry(struct mountlist_itself *, 119 struct raidlist_itself *, newtComponent, int, 120 void *keylist[]); 121 void delete_raidlist_entry(struct mountlist_itself *, 122 struct raidlist_itself *, char *); 123 void delete_varslist_entry(struct raid_device_record *, int); 124 char *disklist_entry_to_string(struct list_of_disks *, int); 125 int edit_filelist(struct s_node *); 126 void edit_mountlist_entry(struct mountlist_itself *, 127 struct raidlist_itself *, newtComponent, int, 128 void *keylist[]); 129 void edit_raidlist_entry(struct mountlist_itself *, 130 struct raidlist_itself *, 131 struct raid_device_record *, int); 132 void edit_varslist_entry(struct raid_device_record *, int); 133 int edit_mountlist_in_newt(char *mountlist_fname, 134 struct mountlist_itself *, 135 struct raidlist_itself *); 136 int edit_mountlist(char *mountlist_fname, struct mountlist_itself *, 137 struct raidlist_itself *); 138 void edit_raidrec_additional_vars(struct raid_device_record *); 139 int evaluate_drive_within_mountlist(struct mountlist_itself *, char *, 140 char *); 141 int evaluate_mountlist(struct mountlist_itself *, char *, char *, char *); 142 int find_device_in_mountlist(struct mountlist_itself *, char *); 143 int find_next_free_index_in_disklist(struct list_of_disks *); 144 int find_raid_device_in_raidlist(struct raidlist_itself *, char *); 145 bool get_isodir_info(char *, char *, char *, bool); 146 void initiate_new_raidlist_entry(struct raidlist_itself *, 147 struct mountlist_itself *, int, char *); 148 void insert_essential_additionalvars(struct raid_device_record *); 149 bool is_this_raid_personality_registered(int); 150 void log_file_end_to_screen(char *, char *); 151 void log_to_screen(const char *fmt, ...); 152 int look_for_duplicate_mountpoints(struct mountlist_itself *, char *); 153 int look_for_weird_formats(struct mountlist_itself *, char *); 154 void make_list_of_unallocated_raid_partitions(struct mountlist_itself *, 155 struct mountlist_itself *, 156 struct raidlist_itself *); 157 char *mountlist_entry_to_string(struct mountlist_itself *, int); 158 void mvaddstr_and_log_it(int, int, char *); 159 void nuke_mode_dummy(); 160 char *number_of_disks_as_string(int, char *); 161 void open_evalcall_form(char *); 162 void open_progress_form(char *, char *, char *, char *, long); 163 void popup_and_OK(char *); 164 bool popup_and_get_string(char *, char *, char *, int); 165 bool popup_with_buttons(char *, char *, char *); 166 void redraw_disklist(struct list_of_disks *, void *keylist[], 167 newtComponent); 168 void redraw_mountlist(struct mountlist_itself *, void *keylist[], 169 newtComponent); 170 void redraw_unallocpartnslist(struct mountlist_itself *, void *keylist[], 171 newtComponent); 172 void redraw_varslist(struct additional_raid_variables *, void *keylist[], 173 newtComponent); 174 int read_variableINT_and_remove_from_raidvars(struct raid_device_record *, 175 char *); 176 void refresh_log_screen(void); 177 void rejig_partition_name_in_raidlist_if_necessary(struct raidlist_itself 178 *, char *, char *); 179 void remove_essential_additionalvars(struct raid_device_record *); 180 void select_raid_disks(struct mountlist_itself *, struct raidlist_itself *, 181 struct raid_device_record *, char *, 182 struct list_of_disks *); 183 void setup_newt_stuff(void); 184 long size_of_specific_device(struct mountlist_itself *, char *); 185 bool spread_flaws_across_three_lines(char *, char *, char *, char *, int); 186 char *turn_raid_level_number_to_string(int); 187 void update_evalcall_form(int); 188 void update_progress_form(char *); 189 void update_progress_form_full(char *, char *, char *); 190 char which_restore_mode(void); 191 void write_variableINT_to_raid_var_line(struct raid_device_record *, int, 192 char *, int); 193 int where_in_drivelist_is_drive(struct list_of_disks *, char *); 187 194 char *strip_path(char *); 188 195 -
trunk/mondo/mondo/mondorestore/mondo-rstr-tools-EXT.h
r30 r59 4 4 5 5 extern void free_MR_global_filenames(); 6 extern void get_cfg_file_from_archive_or_bust(struct s_bkpinfo *);7 extern bool is_file_in_list(char *, char*, char*);/* needle, haystack, preamble */6 extern void get_cfg_file_from_archive_or_bust(struct s_bkpinfo *); 7 extern bool is_file_in_list(char *, char *, char *); /* needle, haystack, preamble */ 8 8 extern int iso_fiddly_bits(struct s_bkpinfo *bkpinfo, bool nuke_me_please); 9 9 extern void kill_petris(void); 10 extern int modify_rclocal_one_time( char *path);10 extern int modify_rclocal_one_time(char *path); 11 11 extern int mount_cdrom(struct s_bkpinfo *bkpinfo); 12 extern int mount_device(char *,char*,char*,bool);13 extern int mount_all_devices(struct mountlist_itself *, bool);12 extern int mount_device(char *, char *, char *, bool); 13 extern int mount_all_devices(struct mountlist_itself *, bool); 14 14 extern void protect_against_braindead_sysadmins(void); 15 extern int read_cfg_file_into_bkpinfo( char* cfg_file, struct s_bkpinfo *bkpinfo); 15 extern int read_cfg_file_into_bkpinfo(char *cfg_file, 16 struct s_bkpinfo *bkpinfo); 16 17 struct s_node *process_filelist_and_biggielist(struct s_bkpinfo *); 17 extern int backup_crucial_file(char *path_root, char *filename);18 extern int backup_crucial_file(char *path_root, char *filename); 18 19 extern int run_boot_loader(bool); 19 extern int run_grub(bool, char *);20 extern int run_grub(bool, char *); 20 21 extern int run_lilo(bool); 21 22 extern int run_elilo(bool); … … 23 24 extern char *find_my_editor(void); 24 25 25 extern void streamline_changes_file(char *,char*);26 extern void set_signals( int on);26 extern void streamline_changes_file(char *, char *); 27 extern void set_signals(int on); 27 28 extern void setup_MR_global_filenames(struct s_bkpinfo *bkpinfo); 28 29 //extern void setup_signals(int); 29 30 extern void terminate_daemon(int); 30 31 extern void termination_in_progress(int); 31 extern int unmount_all_devices(struct mountlist_itself *);32 extern int unmount_all_devices(struct mountlist_itself *); 32 33 extern int get_cfg_file_from_archive(struct s_bkpinfo *bkpinfo); 33 extern int 34 extract_config_file_from_ramdisk( struct s_bkpinfo *bkpinfo,35 char *ramdisk_fname,36 char *output_cfg_file,37 34 extern int 35 extract_config_file_from_ramdisk(struct s_bkpinfo *bkpinfo, 36 char *ramdisk_fname, 37 char *output_cfg_file, 38 char *output_mountlist_file); 38 39 39 extern void ask_about_these_imagedevs( char *infname, char *outfname);40 extern void ask_about_these_imagedevs(char *infname, char *outfname); 40 41 41 extern void wait_until_software_raids_are_prepped(char*mdstat_file, int wait_for_percentage); 42 extern void wait_until_software_raids_are_prepped(char *mdstat_file, 43 int wait_for_percentage); -
trunk/mondo/mondo/mondorestore/mondo-rstr-tools.c
r30 r59 134 134 135 135 extern bool g_sigpipe_caught; 136 extern bool g_ISO_restore_mode; 136 extern bool g_ISO_restore_mode; /* are we in Iso Mode? */ 137 137 extern bool g_I_have_just_nuked; 138 138 extern char *g_tmpfs_mountpt; … … 140 140 extern char *g_isodir_format; 141 141 extern long g_current_progress, g_maximum_progress; 142 extern char *g_biggielist_txt;// where 'biggielist.txt' is stored, on ramdisk / tempdir;143 144 145 extern char *g_filelist_full;// filelist.full.gz is the list of all regular files146 147 extern char *g_biggielist_pot;// list of big files which _could_ be restored, if the148 149 extern char *g_filelist_imagedevs;// list of devices (e.g. /dev/hda1, /dev/sda5) which150 151 152 extern char *g_imagedevs_restthese;// of the imagedevs listed in FILELIST_IMAGEDEVS,153 154 extern char *g_mondo_cfg_file;// where m*ndo-restore.cfg (the config file) is stored155 extern char *g_mountlist_fname;// where mountlist.txt (the mountlist file) is stored156 extern char *g_mondo_home;// homedir of Mondo; usually /usr/local/share/mondo142 extern char *g_biggielist_txt; // where 'biggielist.txt' is stored, on ramdisk / tempdir; 143 // biggielist.txt is the list of big files stored on the 144 // backup media set in question 145 extern char *g_filelist_full; // filelist.full.gz is the list of all regular files 146 // (excluding big files) stored on the backup media set 147 extern char *g_biggielist_pot; // list of big files which _could_ be restored, if the 148 // user chooses them 149 extern char *g_filelist_imagedevs; // list of devices (e.g. /dev/hda1, /dev/sda5) which 150 // were archived as images, not just /dev entries 151 // ... e.g. NTFS, BeOS partitions 152 extern char *g_imagedevs_restthese; // of the imagedevs listed in FILELIST_IMAGEDEVS, 153 // restore only these 154 extern char *g_mondo_cfg_file; // where m*ndo-restore.cfg (the config file) is stored 155 extern char *g_mountlist_fname; // where mountlist.txt (the mountlist file) is stored 156 extern char *g_mondo_home; // homedir of Mondo; usually /usr/local/share/mondo 157 157 extern struct s_bkpinfo *g_bkpinfo_DONTUSETHIS; 158 158 … … 170 170 void free_MR_global_filenames() 171 171 { 172 paranoid_free ( g_biggielist_txt);173 paranoid_free ( g_filelist_full);174 paranoid_free ( g_filelist_imagedevs);172 paranoid_free(g_biggielist_txt); 173 paranoid_free(g_filelist_full); 174 paranoid_free(g_filelist_imagedevs); 175 175 // paranoid_free (g_imagedevs_pot ); 176 paranoid_free ( g_imagedevs_restthese);177 paranoid_free ( g_mondo_cfg_file);178 paranoid_free ( g_mountlist_fname);179 paranoid_free ( g_mondo_home);180 paranoid_free ( g_tmpfs_mountpt);181 paranoid_free ( g_isodir_device);182 paranoid_free ( g_isodir_format);176 paranoid_free(g_imagedevs_restthese); 177 paranoid_free(g_mondo_cfg_file); 178 paranoid_free(g_mountlist_fname); 179 paranoid_free(g_mondo_home); 180 paranoid_free(g_tmpfs_mountpt); 181 paranoid_free(g_isodir_device); 182 paranoid_free(g_isodir_format); 183 183 184 184 } … … 193 193 * @ingroup restoreUtilityGroup 194 194 */ 195 void 196 ask_about_these_imagedevs( char *infname, char *outfname ) 197 { 198 FILE *fin; 199 FILE *fout; 195 void ask_about_these_imagedevs(char *infname, char *outfname) 196 { 197 FILE *fin; 198 FILE *fout; 200 199 /************************************************************************ 201 200 * allocate memory regions. test and set -sab 16 feb 2003 * 202 201 ************************************************************************/ 203 char *incoming_ptr; 204 char *question_ptr; 205 206 char incoming[ MAX_STR_LEN ]; 207 char question[ MAX_STR_LEN ]; 208 209 assert_string_is_neither_NULL_nor_zerolength(infname); 210 assert_string_is_neither_NULL_nor_zerolength(outfname); 211 212 incoming_ptr = malloc(sizeof(incoming)); 213 if ( incoming_ptr == NULL ) 214 { 215 fprintf(stderr, "Out of Memory\n"); 216 exit (EXIT_FAILURE); 217 } 218 219 question_ptr = malloc(sizeof(question)); 220 if ( question_ptr == NULL) 221 { 222 fprintf(stderr, "Out of Memory\n"); 223 exit (EXIT_FAILURE); 224 } 225 226 memset (incoming_ptr, '\0', sizeof(incoming)); 227 memset (question_ptr, '\0', sizeof(question)); 228 229 230 231 if (!( fin = fopen( infname,"r") ) ) 232 { 233 fatal_error( "Cannot openin infname" ); 234 } 235 if ( !( fout = fopen( outfname, "w" ) ) ) 236 { 237 fatal_error( "Cannot openin outfname"); 238 } 239 for( fgets( incoming_ptr, MAX_STR_LEN, fin); 240 !feof( fin ); 241 fgets( incoming_ptr, MAX_STR_LEN, fin ) ) 242 { 243 strip_spaces( incoming_ptr ); 244 245 if ( incoming[0] == '\0') 246 { 247 continue; 248 } 249 250 sprintf( question_ptr, 251 "Should I restore the image of %s ?", 252 incoming_ptr ); 253 254 if ( ask_me_yes_or_no( question_ptr ) ) 255 { 256 fprintf( fout, "%s\n", incoming_ptr ); 257 } 258 } 259 202 char *incoming_ptr; 203 char *question_ptr; 204 205 char incoming[MAX_STR_LEN]; 206 char question[MAX_STR_LEN]; 207 208 assert_string_is_neither_NULL_nor_zerolength(infname); 209 assert_string_is_neither_NULL_nor_zerolength(outfname); 210 211 incoming_ptr = malloc(sizeof(incoming)); 212 if (incoming_ptr == NULL) { 213 fprintf(stderr, "Out of Memory\n"); 214 exit(EXIT_FAILURE); 215 } 216 217 question_ptr = malloc(sizeof(question)); 218 if (question_ptr == NULL) { 219 fprintf(stderr, "Out of Memory\n"); 220 exit(EXIT_FAILURE); 221 } 222 223 memset(incoming_ptr, '\0', sizeof(incoming)); 224 memset(question_ptr, '\0', sizeof(question)); 225 226 227 228 if (!(fin = fopen(infname, "r"))) { 229 fatal_error("Cannot openin infname"); 230 } 231 if (!(fout = fopen(outfname, "w"))) { 232 fatal_error("Cannot openin outfname"); 233 } 234 for (fgets(incoming_ptr, MAX_STR_LEN, fin); 235 !feof(fin); fgets(incoming_ptr, MAX_STR_LEN, fin)) { 236 strip_spaces(incoming_ptr); 237 238 if (incoming[0] == '\0') { 239 continue; 240 } 241 242 sprintf(question_ptr, 243 "Should I restore the image of %s ?", incoming_ptr); 244 245 if (ask_me_yes_or_no(question_ptr)) { 246 fprintf(fout, "%s\n", incoming_ptr); 247 } 248 } 249 260 250 /*** free memory ***********/ 261 262 263 264 265 266 267 paranoid_fclose( fout);268 paranoid_fclose( fin);251 paranoid_free(incoming_ptr); 252 incoming_ptr = NULL; 253 paranoid_free(question_ptr); 254 question_ptr = NULL; 255 256 257 paranoid_fclose(fout); 258 paranoid_fclose(fin); 269 259 } 270 260 … … 289 279 * @ingroup restoreUtilityGroup 290 280 */ 291 int 292 extract_config_file_from_ramdisk( struct s_bkpinfo *bkpinfo, 293 char *ramdisk_fname, 294 char *output_cfg_file, 295 char *output_mountlist_file) 296 { 297 char *mountpt; 298 char *command; 299 char *orig_fname; 300 int retval=0; 301 302 assert(bkpinfo!=NULL); 303 malloc_string(mountpt); 304 malloc_string(command); 305 malloc_string(orig_fname); 306 assert_string_is_neither_NULL_nor_zerolength(ramdisk_fname); 307 assert_string_is_neither_NULL_nor_zerolength(output_cfg_file); 308 assert_string_is_neither_NULL_nor_zerolength(output_mountlist_file); 309 sprintf( mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir ); 310 sprintf( command, "mkdir -p %s", mountpt ); 311 run_program_and_log_output ( command, FALSE ); 312 sprintf( command, "gzip -dc %s > %s/mindi.rd 2> /dev/null", 313 ramdisk_fname, 314 bkpinfo->tmpdir ); 315 316 run_program_and_log_output( command, FALSE ); 317 sprintf( command, "umount %s", mountpt ); 318 319 run_program_and_log_output( command, FALSE ); 320 321 sprintf( command, "mount -o loop %s/mindi.rd -t ext2 %s", 322 bkpinfo->tmpdir, 323 mountpt ); 324 325 run_program_and_log_output( command, FALSE ); 326 327 sprintf( command, "mkdir -p %s/tmp", bkpinfo->tmpdir); 328 329 run_program_and_log_output( command, FALSE ); 330 331 sprintf( command, 332 "cp -f %s/%s %s", // %s/%s becomes {mountpt}/tmp/m*ndo-restore.cfg 333 mountpt, g_mondo_cfg_file, 334 output_cfg_file ); 335 run_program_and_log_output(command, FALSE); 336 337 sprintf( orig_fname, "%s/%s", mountpt, g_mountlist_fname ); 338 if (does_file_exist( orig_fname )) 339 { 340 sprintf( command, 341 "cp -f %s %s", 342 orig_fname, output_mountlist_file ); 343 run_program_and_log_output( command, FALSE ); 344 } 345 sprintf( command, "umount %s", mountpt ); 346 run_program_and_log_output( command, FALSE ); 347 if ( !does_file_exist(output_cfg_file) || (!does_file_exist(output_mountlist_file) && does_file_exist(orig_fname)) ) 348 { 349 log_msg(2, "Failed to extract %s and/or %s from ramdisk", 350 output_cfg_file, 351 output_mountlist_file ); 352 retval=1; 353 } 354 else 355 { 356 retval=0; 357 } 358 paranoid_free(mountpt); 359 paranoid_free(command); 360 paranoid_free(orig_fname); 361 return(retval); 281 int 282 extract_config_file_from_ramdisk(struct s_bkpinfo *bkpinfo, 283 char *ramdisk_fname, 284 char *output_cfg_file, 285 char *output_mountlist_file) 286 { 287 char *mountpt; 288 char *command; 289 char *orig_fname; 290 int retval = 0; 291 292 assert(bkpinfo != NULL); 293 malloc_string(mountpt); 294 malloc_string(command); 295 malloc_string(orig_fname); 296 assert_string_is_neither_NULL_nor_zerolength(ramdisk_fname); 297 assert_string_is_neither_NULL_nor_zerolength(output_cfg_file); 298 assert_string_is_neither_NULL_nor_zerolength(output_mountlist_file); 299 sprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir); 300 sprintf(command, "mkdir -p %s", mountpt); 301 run_program_and_log_output(command, FALSE); 302 sprintf(command, "gzip -dc %s > %s/mindi.rd 2> /dev/null", 303 ramdisk_fname, bkpinfo->tmpdir); 304 305 run_program_and_log_output(command, FALSE); 306 sprintf(command, "umount %s", mountpt); 307 308 run_program_and_log_output(command, FALSE); 309 310 sprintf(command, "mount -o loop %s/mindi.rd -t ext2 %s", 311 bkpinfo->tmpdir, mountpt); 312 313 run_program_and_log_output(command, FALSE); 314 315 sprintf(command, "mkdir -p %s/tmp", bkpinfo->tmpdir); 316 317 run_program_and_log_output(command, FALSE); 318 319 sprintf(command, "cp -f %s/%s %s", // %s/%s becomes {mountpt}/tmp/m*ndo-restore.cfg 320 mountpt, g_mondo_cfg_file, output_cfg_file); 321 run_program_and_log_output(command, FALSE); 322 323 sprintf(orig_fname, "%s/%s", mountpt, g_mountlist_fname); 324 if (does_file_exist(orig_fname)) { 325 sprintf(command, "cp -f %s %s", orig_fname, output_mountlist_file); 326 run_program_and_log_output(command, FALSE); 327 } 328 sprintf(command, "umount %s", mountpt); 329 run_program_and_log_output(command, FALSE); 330 if (!does_file_exist(output_cfg_file) 331 || (!does_file_exist(output_mountlist_file) 332 && does_file_exist(orig_fname))) { 333 log_msg(2, "Failed to extract %s and/or %s from ramdisk", 334 output_cfg_file, output_mountlist_file); 335 retval = 1; 336 } else { 337 retval = 0; 338 } 339 paranoid_free(mountpt); 340 paranoid_free(command); 341 paranoid_free(orig_fname); 342 return (retval); 362 343 363 344 } … … 372 353 void get_cfg_file_from_archive_or_bust(struct s_bkpinfo *bkpinfo) 373 354 { 374 while(get_cfg_file_from_archive(bkpinfo)) 375 { 376 if (!ask_me_yes_or_no("Failed to find config file/archives. Choose another source?")) 377 { fatal_error("Could not find config file/archives. Aborting."); } 378 interactively_obtain_media_parameters_from_user(bkpinfo, FALSE); 379 } 355 while (get_cfg_file_from_archive(bkpinfo)) { 356 if (!ask_me_yes_or_no 357 ("Failed to find config file/archives. Choose another source?")) 358 { 359 fatal_error("Could not find config file/archives. Aborting."); 360 } 361 interactively_obtain_media_parameters_from_user(bkpinfo, FALSE); 362 } 380 363 } 381 364 … … 388 371 * @return TRUE if it's in the list, FALSE if it's not. 389 372 */ 390 bool 391 is_file_in_list(char *f, char *list_fname, char *preamble) 373 bool is_file_in_list(char *f, char *list_fname, char *preamble) 392 374 { 393 375 394 376 /** needs malloc **/ 395 char *command; 396 char *file; 397 char *tmp; 398 int res; 399 400 malloc_string(command); 401 malloc_string(file); 402 malloc_string(tmp); 403 assert_string_is_neither_NULL_nor_zerolength(f); 404 assert_string_is_neither_NULL_nor_zerolength(list_fname); 405 assert(preamble!=NULL); 406 407 if ( strncmp( preamble, f, strlen(preamble ) ) == 0 ) 408 { 409 strcpy( file, f + strlen(preamble) ); 410 } 411 else 412 { 413 strcpy( file, f ); 414 } 415 if ( file[0] == '/' && file[1] == '/') 416 { 417 strcpy( tmp, file ); 418 strcpy( file,tmp + 1 ); 419 } 420 sprintf( tmp,"Checking to see if f=%s, file=%s, is in the list of biggiefiles", f, file); 421 log_msg(2, tmp ); 422 sprintf( command, "cat %s | grep -x \"%s\"", list_fname, file ); 423 res = run_program_and_log_output( command, FALSE); 424 paranoid_free(command); 425 paranoid_free(file); 426 paranoid_free(tmp); 427 if (res) 428 { 429 return(FALSE); 430 } 431 else 432 { 433 return(TRUE); 434 } 435 } 377 char *command; 378 char *file; 379 char *tmp; 380 int res; 381 382 malloc_string(command); 383 malloc_string(file); 384 malloc_string(tmp); 385 assert_string_is_neither_NULL_nor_zerolength(f); 386 assert_string_is_neither_NULL_nor_zerolength(list_fname); 387 assert(preamble != NULL); 388 389 if (strncmp(preamble, f, strlen(preamble)) == 0) { 390 strcpy(file, f + strlen(preamble)); 391 } else { 392 strcpy(file, f); 393 } 394 if (file[0] == '/' && file[1] == '/') { 395 strcpy(tmp, file); 396 strcpy(file, tmp + 1); 397 } 398 sprintf(tmp, 399 "Checking to see if f=%s, file=%s, is in the list of biggiefiles", 400 f, file); 401 log_msg(2, tmp); 402 sprintf(command, "cat %s | grep -x \"%s\"", list_fname, file); 403 res = run_program_and_log_output(command, FALSE); 404 paranoid_free(command); 405 paranoid_free(file); 406 paranoid_free(tmp); 407 if (res) { 408 return (FALSE); 409 } else { 410 return (TRUE); 411 } 412 } 413 436 414 /************************************************************************** 437 415 *END_IS_FILE_IN_LIST * … … 451 429 int iso_fiddly_bits(struct s_bkpinfo *bkpinfo, bool nuke_me_please) 452 430 { 453 char *mount_isodir_command, *tmp, 454 *command; 455 int retval=0, i; 456 bool already_mounted=FALSE; 457 458 assert(bkpinfo!=NULL); 459 malloc_string(mount_isodir_command); 460 malloc_string(tmp); 461 malloc_string(command); 462 g_ISO_restore_mode=TRUE; 463 read_cfg_var( g_mondo_cfg_file, "iso-dev", g_isodir_device); 464 if (bkpinfo->disaster_recovery) 465 { 431 char *mount_isodir_command, *tmp, *command; 432 int retval = 0, i; 433 bool already_mounted = FALSE; 434 435 assert(bkpinfo != NULL); 436 malloc_string(mount_isodir_command); 437 malloc_string(tmp); 438 malloc_string(command); 439 g_ISO_restore_mode = TRUE; 440 read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device); 441 if (bkpinfo->disaster_recovery) { 466 442 /* Patch Conor Daly 26-june-2004 467 443 * Don't let this clobber an existing bkpinfo->isodir */ 468 469 470 444 if (!bkpinfo->isodir[0]) { 445 strcpy(bkpinfo->isodir, "/tmp/isodir"); 446 } 471 447 /* End patch */ 472 sprintf(command, "mkdir -p %s", bkpinfo->isodir); 473 run_program_and_log_output(command, 5); 474 log_msg(2,"Setting isodir to %s", bkpinfo->isodir); 475 } 476 477 if (!get_isodir_info(g_isodir_device, g_isodir_format, bkpinfo->isodir, nuke_me_please)) {return(1);} 478 paranoid_system("umount "MNT_CDROM" 2> /dev/null"); /* just in case */ 479 480 if (is_this_device_mounted(g_isodir_device)) 481 { 482 log_to_screen("WARNING - isodir is already mounted"); 483 already_mounted=TRUE; 484 } 485 else 486 { 487 sprintf(mount_isodir_command,"mount %s", g_isodir_device); 488 if (strlen(g_isodir_format)>1) 489 { sprintf(mount_isodir_command+strlen(mount_isodir_command)," -t %s", g_isodir_format); } 490 strcat(mount_isodir_command," -o ro "); 491 strcat(mount_isodir_command, bkpinfo->isodir); 492 run_program_and_log_output("df -m", FALSE); 493 sprintf(tmp, "The 'mount' command is '%s'. PLEASE report this command to be if you have problems, ok?", mount_isodir_command); 494 log_msg(1,tmp); 495 if (run_program_and_log_output(mount_isodir_command, FALSE)) 496 { popup_and_OK("Cannot mount the device where the ISO files are stored."); return(1); } 497 log_to_screen("I have mounted the device where the ISO files are stored."); 498 } 499 if (!IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { mount_cdrom(bkpinfo); } 500 i=what_number_cd_is_this(bkpinfo); /* has the side-effect of calling mount_cdrom() */ 501 sprintf(tmp,"%s #%d has been mounted via loopback mount", media_descriptor_string(bkpinfo->backup_media_type), i); 502 log_msg(1,tmp); 503 if (i<0) 504 { popup_and_OK("Cannot find ISO images in the directory you specified."); retval=1; } 505 log_msg(2,"%ld: bkpinfo->isodir is now %s", __LINE__, bkpinfo->isodir); 506 paranoid_free(mount_isodir_command); 507 paranoid_free(tmp); 508 paranoid_free(command); 509 return(retval); 448 sprintf(command, "mkdir -p %s", bkpinfo->isodir); 449 run_program_and_log_output(command, 5); 450 log_msg(2, "Setting isodir to %s", bkpinfo->isodir); 451 } 452 453 if (!get_isodir_info 454 (g_isodir_device, g_isodir_format, bkpinfo->isodir, 455 nuke_me_please)) { 456 return (1); 457 } 458 paranoid_system("umount " MNT_CDROM " 2> /dev/null"); /* just in case */ 459 460 if (is_this_device_mounted(g_isodir_device)) { 461 log_to_screen("WARNING - isodir is already mounted"); 462 already_mounted = TRUE; 463 } else { 464 sprintf(mount_isodir_command, "mount %s", g_isodir_device); 465 if (strlen(g_isodir_format) > 1) { 466 sprintf(mount_isodir_command + strlen(mount_isodir_command), 467 " -t %s", g_isodir_format); 468 } 469 strcat(mount_isodir_command, " -o ro "); 470 strcat(mount_isodir_command, bkpinfo->isodir); 471 run_program_and_log_output("df -m", FALSE); 472 sprintf(tmp, 473 "The 'mount' command is '%s'. PLEASE report this command to be if you have problems, ok?", 474 mount_isodir_command); 475 log_msg(1, tmp); 476 if (run_program_and_log_output(mount_isodir_command, FALSE)) { 477 popup_and_OK 478 ("Cannot mount the device where the ISO files are stored."); 479 return (1); 480 } 481 log_to_screen 482 ("I have mounted the device where the ISO files are stored."); 483 } 484 if (!IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 485 mount_cdrom(bkpinfo); 486 } 487 i = what_number_cd_is_this(bkpinfo); /* has the side-effect of calling mount_cdrom() */ 488 sprintf(tmp, "%s #%d has been mounted via loopback mount", 489 media_descriptor_string(bkpinfo->backup_media_type), i); 490 log_msg(1, tmp); 491 if (i < 0) { 492 popup_and_OK 493 ("Cannot find ISO images in the directory you specified."); 494 retval = 1; 495 } 496 log_msg(2, "%ld: bkpinfo->isodir is now %s", __LINE__, 497 bkpinfo->isodir); 498 paranoid_free(mount_isodir_command); 499 paranoid_free(tmp); 500 paranoid_free(command); 501 return (retval); 510 502 } 511 503 … … 516 508 * Kill all Petris processes. 517 509 */ 518 void 519 kill_petris(void) 520 { 521 char *command; 522 malloc_string(command); 523 sprintf( command, "kill `ps wax 2> /dev/null | grep petris 2> /dev/null | grep -v grep | cut -d' ' -f2` 2> /dev/null"); 524 paranoid_system( command ); 525 paranoid_free(command); 526 } 510 void kill_petris(void) 511 { 512 char *command; 513 malloc_string(command); 514 sprintf(command, 515 "kill `ps wax 2> /dev/null | grep petris 2> /dev/null | grep -v grep | cut -d' ' -f2` 2> /dev/null"); 516 paranoid_system(command); 517 paranoid_free(command); 518 } 519 527 520 /************************************************************************** 528 521 *END_KILL_PETRIS * … … 537 530 * @return 0 for success, nonzero for failure. 538 531 */ 539 int 540 modify_rclocal_one_time( char *path ) 532 int modify_rclocal_one_time(char *path) 541 533 { 542 534 /** malloc **/ 543 544 545 546 547 548 549 550 551 552 sprintf( rclocal_fname, "%s/rc.local", path);535 char *rclocal_fname; 536 char *newfile_fname; 537 char *tmp; 538 539 malloc_string(rclocal_fname); 540 malloc_string(newfile_fname); 541 malloc_string(tmp); 542 assert_string_is_neither_NULL_nor_zerolength(path); 543 544 sprintf(rclocal_fname, "%s/rc.local", path); 553 545 554 546 // sprintf(tmp, "chmod 1777 %s/tmp", MNT_RESTORING); 555 547 // run_program_and_log_output( tmp, FALSE ); 556 return( 0 ); /* remove this line to open the floodgates... */ 557 558 if (! does_file_exist( rclocal_fname ) ) 559 { 560 sprintf( rclocal_fname, "%s/rc.d/rc.local", path ); 561 } 562 if (! does_file_exist( rclocal_fname ) ) 563 { 564 paranoid_free(rclocal_fname); 565 paranoid_free(newfile_fname); 566 paranoid_free(tmp); 567 return( 1 ); 568 } 569 sprintf( newfile_fname, "%s/rc.local.mondorescue", path ); 570 sprintf( tmp, "cat %s | grep mondorescue > /dev/null 2> /dev/null",rclocal_fname ); 571 if (system( tmp ) ) 572 { 573 sprintf( tmp,"echo \"[ -e %s ] && %s\n\" >> %s", 574 newfile_fname, 575 newfile_fname, 576 rclocal_fname); 577 578 paranoid_system( tmp ); 579 } 580 sprintf( tmp, "echo -en \"#!/bin/sh\ 548 return (0); /* remove this line to open the floodgates... */ 549 550 if (!does_file_exist(rclocal_fname)) { 551 sprintf(rclocal_fname, "%s/rc.d/rc.local", path); 552 } 553 if (!does_file_exist(rclocal_fname)) { 554 paranoid_free(rclocal_fname); 555 paranoid_free(newfile_fname); 556 paranoid_free(tmp); 557 return (1); 558 } 559 sprintf(newfile_fname, "%s/rc.local.mondorescue", path); 560 sprintf(tmp, "cat %s | grep mondorescue > /dev/null 2> /dev/null", 561 rclocal_fname); 562 if (system(tmp)) { 563 sprintf(tmp, "echo \"[ -e %s ] && %s\n\" >> %s", 564 newfile_fname, newfile_fname, rclocal_fname); 565 566 paranoid_system(tmp); 567 } 568 sprintf(tmp, "echo -en \"#!/bin/sh\ 581 569 \\n\ 582 570 \\n\ … … 587 575 service xfs start\\n\ 588 576 yes | rm -f %s\\n\ 589 \" > %s",rclocal_fname,rclocal_fname,newfile_fname,newfile_fname); 590 sprintf( tmp, "chmod +x \"%s\"", newfile_fname ); 591 run_program_and_log_output( tmp, FALSE ); 592 paranoid_free(rclocal_fname); 593 paranoid_free(newfile_fname); 594 paranoid_free(tmp); 595 return( 0 ); 596 } 577 \" > %s", rclocal_fname, rclocal_fname, newfile_fname, newfile_fname); 578 sprintf(tmp, "chmod +x \"%s\"", newfile_fname); 579 run_program_and_log_output(tmp, FALSE); 580 paranoid_free(rclocal_fname); 581 paranoid_free(newfile_fname); 582 paranoid_free(tmp); 583 return (0); 584 } 585 597 586 /************************************************************************** 598 587 *END_ MODIFY_RCLOCAL_ONE_TIME * … … 609 598 * @return The number of errors encountered (0 for success). 610 599 */ 611 int mount_all_devices(struct mountlist_itself *p_external_copy_of_mountlist, bool writeable) 612 { 613 int retval=0,lino,res; 614 char *tmp, *these_failed, *format; 615 struct mountlist_itself *mountlist; 616 617 malloc_string(tmp); 618 malloc_string(format); 619 malloc_string(these_failed); 620 assert(p_external_copy_of_mountlist!=NULL); 621 mountlist = malloc(sizeof(struct mountlist_itself)); 622 memcpy((void*)mountlist, (void*)p_external_copy_of_mountlist, sizeof(struct mountlist_itself)); 623 sort_mountlist_by_mountpoint(mountlist, 0); 600 int mount_all_devices(struct mountlist_itself 601 *p_external_copy_of_mountlist, bool writeable) 602 { 603 int retval = 0, lino, res; 604 char *tmp, *these_failed, *format; 605 struct mountlist_itself *mountlist; 606 607 malloc_string(tmp); 608 malloc_string(format); 609 malloc_string(these_failed); 610 assert(p_external_copy_of_mountlist != NULL); 611 mountlist = malloc(sizeof(struct mountlist_itself)); 612 memcpy((void *) mountlist, (void *) p_external_copy_of_mountlist, 613 sizeof(struct mountlist_itself)); 614 sort_mountlist_by_mountpoint(mountlist, 0); 624 615 625 616 /** menset **/ 626 these_failed[0] = '\0'; 627 628 mvaddstr_and_log_it( g_currentY, 0, "Mounting devices "); 629 open_progress_form("Mounting devices", 630 "I am now mounting all the drives.", 631 "This should not take long.", 632 "", 633 mountlist->entries); 634 635 for( lino = 0; lino < mountlist->entries; lino++ ) 636 { 637 if ( !strcmp( mountlist->el[lino].device, "/proc" ) ) 638 { 639 log_msg(1, "Again with the /proc - why is this in your mountlist?"); 640 } 641 else if ( is_this_device_mounted( mountlist->el[lino].device ) ) 642 { 643 sprintf( tmp, "%s is already mounted",mountlist->el[lino].device ); 644 log_to_screen( tmp ); 645 } 646 else if ( strcmp( mountlist->el[lino].mountpoint, "none" ) && strcmp( mountlist->el[lino].mountpoint, "lvm" ) && strcmp( mountlist->el[lino].mountpoint,"raid" ) && strcmp(mountlist->el[lino].mountpoint, "image" ) ) 647 { 648 sprintf( tmp, "Mounting %s",mountlist->el[lino].device ); 649 update_progress_form( tmp ); 650 strcpy(format, mountlist->el[lino].format); 651 if (!strcmp(format, "ext3")) { strcpy(format, "ext2"); } 652 res = mount_device( mountlist->el[lino].device, 653 mountlist->el[lino].mountpoint, 654 format, 655 writeable ); 656 retval += res; 657 if ( res ) 658 { 659 strcat( these_failed,mountlist->el[lino].device ); 660 strcat( these_failed, " " ); 661 } 662 } 663 g_current_progress++; 664 } 665 close_progress_form(); 666 run_program_and_log_output( "df -m", TRUE ); 667 if ( retval ) 668 { 669 if (g_partition_table_locked_up > 0) 670 { 671 log_to_screen( 672 "fdisk's ictol() call to refresh its copy of the partition table causes the kernel to"); 673 log_to_screen( 674 "lock up the partition table. You might have to reboot and use Interactive Mode to"); 675 log_to_screen( 676 "format and restore *without* partitioning first. Sorry for the inconvenience."); 677 } 678 sprintf( tmp, "Could not mount devices %s- shall I abort?", these_failed ); 679 if ( !ask_me_yes_or_no( tmp ) ) 680 { 681 retval = 0; 682 log_to_screen( "Continuing, although some devices failed to be mounted" ); 683 mvaddstr_and_log_it( g_currentY++, 74, "Done." ); 684 } 685 else 686 { 687 mvaddstr_and_log_it( g_currentY++, 74, "Failed." ); 688 log_to_screen( "Unable to mount some or all of your partitions." ); 689 } 690 } 691 else 692 { 693 log_to_screen("All partitions were mounted OK."); 694 mvaddstr_and_log_it(g_currentY++,74,"Done."); 695 } 696 run_program_and_log_output("df -m", 3); 697 paranoid_free(mountlist); 698 paranoid_free(tmp); 699 paranoid_free(format); 700 paranoid_free(these_failed); 701 return(retval); 702 } 617 these_failed[0] = '\0'; 618 619 mvaddstr_and_log_it(g_currentY, 0, "Mounting devices "); 620 open_progress_form("Mounting devices", 621 "I am now mounting all the drives.", 622 "This should not take long.", 623 "", mountlist->entries); 624 625 for (lino = 0; lino < mountlist->entries; lino++) { 626 if (!strcmp(mountlist->el[lino].device, "/proc")) { 627 log_msg(1, 628 "Again with the /proc - why is this in your mountlist?"); 629 } else if (is_this_device_mounted(mountlist->el[lino].device)) { 630 sprintf(tmp, "%s is already mounted", 631 mountlist->el[lino].device); 632 log_to_screen(tmp); 633 } else if (strcmp(mountlist->el[lino].mountpoint, "none") 634 && strcmp(mountlist->el[lino].mountpoint, "lvm") 635 && strcmp(mountlist->el[lino].mountpoint, "raid") 636 && strcmp(mountlist->el[lino].mountpoint, "image")) { 637 sprintf(tmp, "Mounting %s", mountlist->el[lino].device); 638 update_progress_form(tmp); 639 strcpy(format, mountlist->el[lino].format); 640 if (!strcmp(format, "ext3")) { 641 strcpy(format, "ext2"); 642 } 643 res = mount_device(mountlist->el[lino].device, 644 mountlist->el[lino].mountpoint, 645 format, writeable); 646 retval += res; 647 if (res) { 648 strcat(these_failed, mountlist->el[lino].device); 649 strcat(these_failed, " "); 650 } 651 } 652 g_current_progress++; 653 } 654 close_progress_form(); 655 run_program_and_log_output("df -m", TRUE); 656 if (retval) { 657 if (g_partition_table_locked_up > 0) { 658 log_to_screen 659 ("fdisk's ictol() call to refresh its copy of the partition table causes the kernel to"); 660 log_to_screen 661 ("lock up the partition table. You might have to reboot and use Interactive Mode to"); 662 log_to_screen 663 ("format and restore *without* partitioning first. Sorry for the inconvenience."); 664 } 665 sprintf(tmp, "Could not mount devices %s- shall I abort?", 666 these_failed); 667 if (!ask_me_yes_or_no(tmp)) { 668 retval = 0; 669 log_to_screen 670 ("Continuing, although some devices failed to be mounted"); 671 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 672 } else { 673 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 674 log_to_screen 675 ("Unable to mount some or all of your partitions."); 676 } 677 } else { 678 log_to_screen("All partitions were mounted OK."); 679 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 680 } 681 run_program_and_log_output("df -m", 3); 682 paranoid_free(mountlist); 683 paranoid_free(tmp); 684 paranoid_free(format); 685 paranoid_free(these_failed); 686 return (retval); 687 } 688 703 689 /************************************************************************** 704 690 *END_MOUNT_ALL_DEVICES * … … 717 703 int mount_cdrom(struct s_bkpinfo *bkpinfo) 718 704 { 719 720 int i,res;705 char *mount_cmd; 706 int i, res; 721 707 #ifdef __FreeBSD__ 722 723 708 char mdd[32]; 709 char *mddev = mdd; 724 710 #endif 725 711 726 malloc_string(mount_cmd); 727 assert(bkpinfo!=NULL); 728 729 if (bkpinfo->backup_media_type == tape || bkpinfo->backup_media_type == udev) 730 { 731 log_msg(8, "Tape/udev. Therefore, no need to mount CDROM."); 732 paranoid_free(mount_cmd); 733 return 0; 734 } 735 736 if (!run_program_and_log_output("mount | fgrep " MNT_CDROM, FALSE)) 737 { 738 log_msg(2,"mount_cdrom() - CD already mounted. Fair enough."); 739 paranoid_free(mount_cmd); 740 return(0); 741 } 742 743 if (bkpinfo->backup_media_type == nfs) 744 { 745 log_msg(2,"Mounting for NFS thingy"); 746 log_msg(2, "isodir = %s", bkpinfo->isodir); 747 if ((!bkpinfo->isodir[0] || !strcmp(bkpinfo->isodir, "/")) 748 && am_I_in_disaster_recovery_mode()) 749 { 750 strcpy(bkpinfo->isodir, "/tmp/isodir"); 751 log_msg(1, "isodir is being set to %s", bkpinfo->isodir); 752 } 753 712 malloc_string(mount_cmd); 713 assert(bkpinfo != NULL); 714 715 if (bkpinfo->backup_media_type == tape 716 || bkpinfo->backup_media_type == udev) { 717 log_msg(8, "Tape/udev. Therefore, no need to mount CDROM."); 718 paranoid_free(mount_cmd); 719 return 0; 720 } 721 722 if (!run_program_and_log_output("mount | fgrep " MNT_CDROM, FALSE)) { 723 log_msg(2, "mount_cdrom() - CD already mounted. Fair enough."); 724 paranoid_free(mount_cmd); 725 return (0); 726 } 727 728 if (bkpinfo->backup_media_type == nfs) { 729 log_msg(2, "Mounting for NFS thingy"); 730 log_msg(2, "isodir = %s", bkpinfo->isodir); 731 if ((!bkpinfo->isodir[0] || !strcmp(bkpinfo->isodir, "/")) 732 && am_I_in_disaster_recovery_mode()) { 733 strcpy(bkpinfo->isodir, "/tmp/isodir"); 734 log_msg(1, "isodir is being set to %s", bkpinfo->isodir); 735 } 754 736 #ifdef __FreeBSD__ 755 sprintf (mount_cmd, "/mnt/isodir/%s/%s/%d.iso", bkpinfo->isodir, bkpinfo->nfs_remote_dir, g_current_media_number); 756 mddev = make_vn (mount_cmd); 757 sprintf (mount_cmd, "mount_cd9660 -r %s "MNT_CDROM, mddev); 737 sprintf(mount_cmd, "/mnt/isodir/%s/%s/%d.iso", bkpinfo->isodir, 738 bkpinfo->nfs_remote_dir, g_current_media_number); 739 mddev = make_vn(mount_cmd); 740 sprintf(mount_cmd, "mount_cd9660 -r %s " MNT_CDROM, mddev); 758 741 #else 759 sprintf(mount_cmd, "mount %s/%s/%d.iso -t iso9660 -o loop,ro %s", bkpinfo->isodir, bkpinfo->nfs_remote_dir, g_current_media_number, MNT_CDROM); 742 sprintf(mount_cmd, "mount %s/%s/%d.iso -t iso9660 -o loop,ro %s", 743 bkpinfo->isodir, bkpinfo->nfs_remote_dir, 744 g_current_media_number, MNT_CDROM); 760 745 #endif 761 746 762 } 763 else 764 765 if (bkpinfo->backup_media_type == iso) 766 { 747 } else 748 if (bkpinfo->backup_media_type == iso) { 767 749 #ifdef __FreeBSD__ 768 sprintf (mount_cmd, "%s/%d.iso", bkpinfo->isodir, g_current_media_number); 769 mddev = make_vn (mount_cmd); 770 sprintf (mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM); 750 sprintf(mount_cmd, "%s/%d.iso", bkpinfo->isodir, 751 g_current_media_number); 752 mddev = make_vn(mount_cmd); 753 sprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM); 771 754 #else 772 sprintf(mount_cmd, "mount %s/%d.iso -t iso9660 -o loop,ro %s", bkpinfo->isodir, g_current_media_number, MNT_CDROM); 755 sprintf(mount_cmd, "mount %s/%d.iso -t iso9660 -o loop,ro %s", 756 bkpinfo->isodir, g_current_media_number, MNT_CDROM); 773 757 #endif 774 } 775 else if (strstr(bkpinfo->media_device, "/dev/")) 776 758 } else if (strstr(bkpinfo->media_device, "/dev/")) 777 759 #ifdef __FreeBSD__ 778 { sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, MNT_CDROM); } 760 { 761 sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, 762 MNT_CDROM); 763 } 779 764 #else 780 { sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", bkpinfo->media_device, MNT_CDROM); } 765 { 766 sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", 767 bkpinfo->media_device, MNT_CDROM); 768 } 781 769 #endif 782 770 783 else 784 { 785 if (bkpinfo->disaster_recovery && does_file_exist("/tmp/CDROM-LIVES-HERE")) 786 { strcpy(bkpinfo->media_device, last_line_of_file("/tmp/CDROM-LIVES-HERE")); } 787 else 788 { find_cdrom_device( bkpinfo->media_device, TRUE ); } 771 else { 772 if (bkpinfo->disaster_recovery 773 && does_file_exist("/tmp/CDROM-LIVES-HERE")) { 774 strcpy(bkpinfo->media_device, 775 last_line_of_file("/tmp/CDROM-LIVES-HERE")); 776 } else { 777 find_cdrom_device(bkpinfo->media_device, TRUE); 778 } 789 779 790 780 #ifdef __FreeBSD__ 791 sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, MNT_CDROM); 781 sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, 782 MNT_CDROM); 792 783 #else 793 sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", bkpinfo->media_device, MNT_CDROM); 784 sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", 785 bkpinfo->media_device, MNT_CDROM); 794 786 #endif 795 787 796 } 797 log_msg(2,"(mount_cdrom) --- command = %s", mount_cmd); 798 for(i=0;i<2;i++) 799 { 800 res=run_program_and_log_output(mount_cmd, FALSE); 801 if (!res) 802 { 803 break; 804 } 805 else 806 { 807 log_msg(2,"Failed to mount CD-ROM drive."); 808 sleep(5); 809 run_program_and_log_output( "sync", FALSE ); 810 } 811 } 812 if (res) { log_msg(2,"Failed, despite %d attempts", i); } 813 else { log_msg(2,"Mounted CD-ROM drive OK"); } 814 paranoid_free(mount_cmd); 815 return(res); 788 } 789 log_msg(2, "(mount_cdrom) --- command = %s", mount_cmd); 790 for (i = 0; i < 2; i++) { 791 res = run_program_and_log_output(mount_cmd, FALSE); 792 if (!res) { 793 break; 794 } else { 795 log_msg(2, "Failed to mount CD-ROM drive."); 796 sleep(5); 797 run_program_and_log_output("sync", FALSE); 798 } 799 } 800 if (res) { 801 log_msg(2, "Failed, despite %d attempts", i); 802 } else { 803 log_msg(2, "Mounted CD-ROM drive OK"); 804 } 805 paranoid_free(mount_cmd); 806 return (res); 816 807 } 817 808 … … 833 824 * @return 0 for success, nonzero for failure. 834 825 */ 835 int 836 mount_device( char *device, char *mpt, char *format, bool writeable) 837 { 838 int res = 0; 826 int mount_device(char *device, char *mpt, char *format, bool writeable) 827 { 828 int res = 0; 839 829 840 830 /** malloc **/ 841 char *tmp, *command, *mountdir, *mountpoint, *additional_parameters; 842 843 assert_string_is_neither_NULL_nor_zerolength(device); 844 assert_string_is_neither_NULL_nor_zerolength(mpt); 845 assert(format!=NULL); 846 malloc_string(tmp); 847 malloc_string(command); 848 malloc_string(mountdir); 849 malloc_string(mountpoint); 850 malloc_string(additional_parameters); 851 852 if (!strcmp (mpt, "/1")) 853 { 854 strcpy (mountpoint, "/"); 855 log_msg (3,"Mommm! SME is being a dildo!"); 856 } 857 else 858 { 859 strcpy (mountpoint, mpt); 860 } 861 862 if ( !strcmp(mountpoint,"lvm" ) ) 863 { 864 return( 0 ); 865 } 866 if ( !strcmp(mountpoint,"image" ) ) 867 { 868 return( 0 ); 869 } 870 sprintf( tmp, "Mounting device %s ", device ); 871 log_msg( 1, tmp ); 872 if ( writeable ) 873 { 874 strcpy( additional_parameters, "-o rw"); 875 } 876 else 877 { 878 strcpy( additional_parameters, "-o ro"); 879 } 880 if (find_home_of_exe("setfattr")) 881 { 882 strcat( additional_parameters, ",user_xattr"); 883 } 884 if (find_home_of_exe("setfacl")) 885 { 886 strcat( additional_parameters, ",acl"); 887 } 888 889 if ( !strcmp( mountpoint,"swap" ) ) 890 { 891 sprintf( command, "swapon %s", device ); 892 } 893 else 894 { 895 if ( !strcmp( mountpoint,"/" ) ) 896 { 897 strcpy( mountdir, MNT_RESTORING); 898 } 899 else 900 { 901 sprintf( mountdir, "%s%s", MNT_RESTORING, mountpoint); 902 } 903 sprintf( command, "mkdir -p %s", mountdir ); 904 run_program_and_log_output( command, FALSE ); 905 sprintf( command, "mount -t %s %s %s %s 2>> %s", format, device, additional_parameters, mountdir, MONDO_LOGFILE ); 906 log_msg(2, "command='%s'", command); 907 } 908 res = run_program_and_log_output( command, TRUE ); 909 if ( res && (strstr(command, "xattr") || strstr(command, "acl"))) 910 { 911 log_msg(1, "Re-trying without the fancy extra parameters"); 912 sprintf( command, "mount -t %s %s %s 2>> %s", format, device, mountdir, MONDO_LOGFILE ); 913 res = run_program_and_log_output( command, TRUE ); 914 } 915 if ( res ) 916 { 917 log_msg(1, "Unable to mount device %s (type %s) at %s", device, format, mountdir ); 918 log_msg(1, "command was '%s'", command); 919 if ( !strcmp( mountpoint, "swap" ) ) 920 { 921 log_to_screen( tmp ); 922 } 923 else 924 { 925 log_msg(2, "Retrying w/o the '-t' switch" ); 926 sprintf( command, "mount %s %s 2>> %s", device, mountdir, MONDO_LOGFILE); 927 log_msg(2, "2nd command = '%s'", command); 928 res = run_program_and_log_output( command, TRUE ); 929 if (res == 0 ) 930 { 931 log_msg(1, "That's OK. I called mount w/o a filesystem type and it worked fine in the end." ); 932 } 933 else 934 { 935 log_to_screen( tmp ); 936 } 937 } 938 } 939 if (res && !strcmp( mountpoint, "swap" )) 940 { 941 log_msg(2, "That's ok. It's just a swap partition."); 942 log_msg(2, "Non-fatal error. Returning 0."); 943 res=0; 944 } 945 946 paranoid_free(tmp); 947 paranoid_free(command); 948 paranoid_free(mountdir); 949 paranoid_free(mountpoint); 950 paranoid_free(additional_parameters); 951 952 return( res ); 953 } 831 char *tmp, *command, *mountdir, *mountpoint, *additional_parameters; 832 833 assert_string_is_neither_NULL_nor_zerolength(device); 834 assert_string_is_neither_NULL_nor_zerolength(mpt); 835 assert(format != NULL); 836 malloc_string(tmp); 837 malloc_string(command); 838 malloc_string(mountdir); 839 malloc_string(mountpoint); 840 malloc_string(additional_parameters); 841 842 if (!strcmp(mpt, "/1")) { 843 strcpy(mountpoint, "/"); 844 log_msg(3, "Mommm! SME is being a dildo!"); 845 } else { 846 strcpy(mountpoint, mpt); 847 } 848 849 if (!strcmp(mountpoint, "lvm")) { 850 return (0); 851 } 852 if (!strcmp(mountpoint, "image")) { 853 return (0); 854 } 855 sprintf(tmp, "Mounting device %s ", device); 856 log_msg(1, tmp); 857 if (writeable) { 858 strcpy(additional_parameters, "-o rw"); 859 } else { 860 strcpy(additional_parameters, "-o ro"); 861 } 862 if (find_home_of_exe("setfattr")) { 863 strcat(additional_parameters, ",user_xattr"); 864 } 865 if (find_home_of_exe("setfacl")) { 866 strcat(additional_parameters, ",acl"); 867 } 868 869 if (!strcmp(mountpoint, "swap")) { 870 sprintf(command, "swapon %s", device); 871 } else { 872 if (!strcmp(mountpoint, "/")) { 873 strcpy(mountdir, MNT_RESTORING); 874 } else { 875 sprintf(mountdir, "%s%s", MNT_RESTORING, mountpoint); 876 } 877 sprintf(command, "mkdir -p %s", mountdir); 878 run_program_and_log_output(command, FALSE); 879 sprintf(command, "mount -t %s %s %s %s 2>> %s", format, device, 880 additional_parameters, mountdir, MONDO_LOGFILE); 881 log_msg(2, "command='%s'", command); 882 } 883 res = run_program_and_log_output(command, TRUE); 884 if (res && (strstr(command, "xattr") || strstr(command, "acl"))) { 885 log_msg(1, "Re-trying without the fancy extra parameters"); 886 sprintf(command, "mount -t %s %s %s 2>> %s", format, device, 887 mountdir, MONDO_LOGFILE); 888 res = run_program_and_log_output(command, TRUE); 889 } 890 if (res) { 891 log_msg(1, "Unable to mount device %s (type %s) at %s", device, 892 format, mountdir); 893 log_msg(1, "command was '%s'", command); 894 if (!strcmp(mountpoint, "swap")) { 895 log_to_screen(tmp); 896 } else { 897 log_msg(2, "Retrying w/o the '-t' switch"); 898 sprintf(command, "mount %s %s 2>> %s", device, mountdir, 899 MONDO_LOGFILE); 900 log_msg(2, "2nd command = '%s'", command); 901 res = run_program_and_log_output(command, TRUE); 902 if (res == 0) { 903 log_msg(1, 904 "That's OK. I called mount w/o a filesystem type and it worked fine in the end."); 905 } else { 906 log_to_screen(tmp); 907 } 908 } 909 } 910 if (res && !strcmp(mountpoint, "swap")) { 911 log_msg(2, "That's ok. It's just a swap partition."); 912 log_msg(2, "Non-fatal error. Returning 0."); 913 res = 0; 914 } 915 916 paranoid_free(tmp); 917 paranoid_free(command); 918 paranoid_free(mountdir); 919 paranoid_free(mountpoint); 920 paranoid_free(additional_parameters); 921 922 return (res); 923 } 924 954 925 /************************************************************************** 955 926 *END_MOUNT_DEVICE * … … 962 933 * up correctly on the first boot. 963 934 */ 964 void 965 protect_against_braindead_sysadmins() 966 { 967 run_program_and_log_output( "touch " MNT_RESTORING "/var/log/pacct", FALSE ); 968 run_program_and_log_output( "touch " MNT_RESTORING "/var/account/pacct", FALSE ); 969 if (run_program_and_log_output( "ls " MNT_RESTORING" /tmp", FALSE ) ) 970 { 971 run_program_and_log_output( "chmod 1777 " MNT_RESTORING "/tmp", FALSE ); 972 } 973 run_program_and_log_output( "mkdir -p " MNT_RESTORING "/var/run/console", FALSE ); 974 run_program_and_log_output( "chmod 777 " MNT_RESTORING "/dev/null", FALSE ); 975 run_program_and_log_output( "cd " MNT_RESTORING "; for i in `ls home/`; do echo \"Moving $i's spurious files to $i/.disabled\"; mkdir $i/.disabled ; mv -f $i/.DCOP* $i/.MCOP* $i/.*authority $i/.kde/tmp* $i/.kde/socket* $i/.disabled/ ; done", TRUE); 976 run_program_and_log_output( "rm -f " MNT_RESTORING "/var/run/*.pid", TRUE); 977 run_program_and_log_output( "rm -f " MNT_RESTORING "/var/lock/subsys/*", TRUE); 978 } 935 void protect_against_braindead_sysadmins() 936 { 937 run_program_and_log_output("touch " MNT_RESTORING "/var/log/pacct", 938 FALSE); 939 run_program_and_log_output("touch " MNT_RESTORING "/var/account/pacct", 940 FALSE); 941 if (run_program_and_log_output("ls " MNT_RESTORING " /tmp", FALSE)) { 942 run_program_and_log_output("chmod 1777 " MNT_RESTORING "/tmp", 943 FALSE); 944 } 945 run_program_and_log_output("mkdir -p " MNT_RESTORING 946 "/var/run/console", FALSE); 947 run_program_and_log_output("chmod 777 " MNT_RESTORING "/dev/null", 948 FALSE); 949 run_program_and_log_output("cd " MNT_RESTORING 950 "; for i in `ls home/`; do echo \"Moving $i's spurious files to $i/.disabled\"; mkdir $i/.disabled ; mv -f $i/.DCOP* $i/.MCOP* $i/.*authority $i/.kde/tmp* $i/.kde/socket* $i/.disabled/ ; done", 951 TRUE); 952 run_program_and_log_output("rm -f " MNT_RESTORING "/var/run/*.pid", 953 TRUE); 954 run_program_and_log_output("rm -f " MNT_RESTORING "/var/lock/subsys/*", 955 TRUE); 956 } 957 979 958 /************************************************************************** 980 959 *END_PROTECT_AGAINST_BRAINDEAD_SYSADMINS * … … 991 970 * @return 0 for success, nonzero for failure. 992 971 */ 993 int 994 read_cfg_file_into_bkpinfo( char* cfgf, struct s_bkpinfo *bkpinfo) 972 int read_cfg_file_into_bkpinfo(char *cfgf, struct s_bkpinfo *bkpinfo) 995 973 { 996 974 /** add mallocs **/ 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 975 char *value; 976 char *tmp; 977 char *command; 978 char *iso_mnt; 979 char *iso_path; 980 char *old_isodir; 981 char cfg_file[100]; 982 t_bkptype media_specified_by_user; 983 984 malloc_string(command); 985 malloc_string(iso_mnt); 986 malloc_string(iso_path); 987 malloc_string(old_isodir); 988 malloc_string(value); 989 malloc_string(tmp); 1012 990 // assert_string_is_neither_NULL_nor_zerolength(cfg_file); 1013 assert(bkpinfo!=NULL); 1014 1015 if (!cfgf) 1016 { strcpy(cfg_file, g_mondo_cfg_file); } 1017 else 1018 { strcpy(cfg_file, cfgf); } 1019 1020 media_specified_by_user = bkpinfo->backup_media_type; // or 'none', if not specified 1021 1022 if (0 == read_cfg_var(cfg_file, "backup-media-type", value)) 1023 { 1024 if ( !strcmp(value, "cdstream" ) ) 1025 { 1026 bkpinfo->backup_media_type = cdstream; 1027 } 1028 else if (!strcmp(value, "cdr")) 1029 { 1030 bkpinfo->backup_media_type = cdr; 1031 } 1032 else if (!strcmp(value, "cdrw")) 1033 { 1034 bkpinfo->backup_media_type = cdrw; 1035 } 1036 else if (!strcmp(value, "dvd")) 1037 { 1038 bkpinfo->backup_media_type = dvd; 1039 } 1040 else if (!strcmp(value, "iso")) 1041 { 991 assert(bkpinfo != NULL); 992 993 if (!cfgf) { 994 strcpy(cfg_file, g_mondo_cfg_file); 995 } else { 996 strcpy(cfg_file, cfgf); 997 } 998 999 media_specified_by_user = bkpinfo->backup_media_type; // or 'none', if not specified 1000 1001 if (0 == read_cfg_var(cfg_file, "backup-media-type", value)) { 1002 if (!strcmp(value, "cdstream")) { 1003 bkpinfo->backup_media_type = cdstream; 1004 } else if (!strcmp(value, "cdr")) { 1005 bkpinfo->backup_media_type = cdr; 1006 } else if (!strcmp(value, "cdrw")) { 1007 bkpinfo->backup_media_type = cdrw; 1008 } else if (!strcmp(value, "dvd")) { 1009 bkpinfo->backup_media_type = dvd; 1010 } else if (!strcmp(value, "iso")) { 1042 1011 /* 1043 1012 if (am_I_in_disaster_recovery_mode() … … 1047 1016 1048 1017 // Patch by Conor Daly - 2004/07/12 1049 1050 if (am_I_in_disaster_recovery_mode()) 1051 {1052 /* Check to see if CD is already mounted before mounting it... */ 1053 if (!is_this_device_mounted("/dev/cdrom")) 1054 {1055 log_msg(2, "NB: CDROM device not mounted, mounting..."); 1056 run_program_and_log_output("mount /dev/cdrom "MNT_CDROM, 1);1057 1058 if( does_file_exist(MNT_CDROM"/archives/filelist.0"))1018 bkpinfo->backup_media_type = iso; 1019 if (am_I_in_disaster_recovery_mode()) { 1020 /* Check to see if CD is already mounted before mounting it... */ 1021 if (!is_this_device_mounted("/dev/cdrom")) { 1022 log_msg(2, 1023 "NB: CDROM device not mounted, mounting..."); 1024 run_program_and_log_output("mount /dev/cdrom " 1025 MNT_CDROM, 1); 1026 } 1027 if (does_file_exist(MNT_CDROM "/archives/filelist.0")) 1059 1028 // End patch 1060 { 1061 bkpinfo->backup_media_type = cdr; 1062 run_program_and_log_output("umount "MNT_CDROM, 1); 1063 log_it("Re-jigging configuration AGAIN. CD-R, not ISO."); 1064 } 1065 else 1066 { 1067 bkpinfo->backup_media_type = iso; 1068 } 1069 } 1070 } 1071 else if (!strcmp(value, "nfs")) 1072 { 1073 bkpinfo->backup_media_type = nfs; 1074 } 1075 else if (!strcmp(value, "tape")) 1076 { 1077 bkpinfo->backup_media_type = tape; 1078 } 1079 else if (!strcmp(value, "udev")) 1080 { 1081 bkpinfo->backup_media_type = udev; 1082 } 1083 else 1084 { 1085 fatal_error("UNKNOWN bkp-media-type"); 1086 } 1087 } 1088 else 1089 { 1090 fatal_error("backup-media-type not specified!"); 1091 } 1092 if (bkpinfo->disaster_recovery) 1093 { 1094 if (bkpinfo->backup_media_type == cdstream) 1095 { 1096 sprintf(bkpinfo->media_device, "/dev/cdrom"); 1029 { 1030 bkpinfo->backup_media_type = cdr; 1031 run_program_and_log_output("umount " MNT_CDROM, 1); 1032 log_it 1033 ("Re-jigging configuration AGAIN. CD-R, not ISO."); 1034 } else { 1035 bkpinfo->backup_media_type = iso; 1036 } 1037 } 1038 } else if (!strcmp(value, "nfs")) { 1039 bkpinfo->backup_media_type = nfs; 1040 } else if (!strcmp(value, "tape")) { 1041 bkpinfo->backup_media_type = tape; 1042 } else if (!strcmp(value, "udev")) { 1043 bkpinfo->backup_media_type = udev; 1044 } else { 1045 fatal_error("UNKNOWN bkp-media-type"); 1046 } 1047 } else { 1048 fatal_error("backup-media-type not specified!"); 1049 } 1050 if (bkpinfo->disaster_recovery) { 1051 if (bkpinfo->backup_media_type == cdstream) { 1052 sprintf(bkpinfo->media_device, "/dev/cdrom"); 1097 1053 // bkpinfo->media_size[0] = -1; 1098 bkpinfo->media_size[0] = 1999*1024; 1099 bkpinfo->media_size[1] = 650; /* good guess */ 1100 } 1101 else if (bkpinfo->backup_media_type == tape || bkpinfo->backup_media_type == udev) 1102 { 1103 if (read_cfg_var(cfg_file, "media-dev", value)) { fatal_error("Cannot get tape device name from cfg file"); } 1104 strcpy(bkpinfo->media_device, value); 1105 read_cfg_var(cfg_file, "media-size", value); 1106 bkpinfo->media_size[1] = atol(value); 1107 sprintf(tmp,"Backup medium is TAPE --- dev=%s",bkpinfo->media_device); 1108 log_msg(2, tmp); 1109 } 1110 else 1111 { 1112 strcpy(bkpinfo->media_device,"/dev/cdrom"); /* we don't really need this var */ 1113 bkpinfo->media_size[0]= 1999*1024; /* 650, probably, but we don't need this var anyway */ 1114 bkpinfo->media_size[1]=1999*1024; /* 650, probably, but we don't need this var anyway */ 1115 log_msg(2, "Backup medium is CD-R[W]"); 1116 } 1117 } 1118 else 1119 { 1120 log_msg(2, "Not in Disaster Recovery Mode. No need to derive device name from config file."); 1121 } 1122 1123 read_cfg_var(cfg_file, "use-star", value); 1124 if (strstr(value,"yes")) 1125 { 1126 bkpinfo->use_star = TRUE; 1127 log_msg(1, "Goody! ... bkpinfo->use_star is now true."); 1128 } 1129 1130 if (0 == read_cfg_var(cfg_file, "internal-tape-block-size", value)) 1131 { 1132 bkpinfo->internal_tape_block_size = atol(value); 1133 log_msg(1, "Internal tape block size has been custom-set to %ld", bkpinfo->internal_tape_block_size); 1134 } 1135 else 1136 { 1137 bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE; 1138 log_msg(1, "Internal tape block size = default (%ld)", DEFAULT_INTERNAL_TAPE_BLOCK_SIZE); 1139 } 1140 1141 read_cfg_var(cfg_file, "use-lzo", value); 1142 if (strstr(value,"yes")) 1143 { 1144 bkpinfo->use_lzo = TRUE; 1145 strcpy(bkpinfo->zip_exe, "lzop"); 1146 strcpy(bkpinfo->zip_suffix, "lzo"); 1147 } 1148 else 1149 { 1150 read_cfg_var(cfg_file, "use-comp", value); 1151 if (strstr(value,"yes")) 1152 { 1153 bkpinfo->use_lzo = FALSE; 1154 strcpy(bkpinfo->zip_exe, "bzip2"); 1155 strcpy(bkpinfo->zip_suffix, "bz2"); 1156 } 1157 else 1158 { 1159 bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0'; 1160 } 1161 } 1162 1163 value[0] = '\0'; 1164 read_cfg_var( cfg_file, "differential", value); 1165 if (!strcmp(value, "yes") || !strcmp(value, "1")) 1166 { 1167 bkpinfo->differential = TRUE; 1168 } 1169 log_msg(2, "differential var = '%s'", value); 1170 if (bkpinfo->differential) 1171 { 1172 log_msg(2, "THIS IS A DIFFERENTIAL BACKUP" ); 1173 } 1174 else 1175 { 1176 log_msg(2, "This is a regular (full) backup"); 1177 } 1178 1179 read_cfg_var( g_mondo_cfg_file, "please-dont-eject", tmp); 1180 if (tmp[0] || strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "donteject")) 1181 { bkpinfo->please_dont_eject = TRUE; log_msg(2, "Ok, I shan't eject when restoring! Groovy."); } 1182 1183 if (bkpinfo->backup_media_type == nfs) 1184 { 1185 if (!cfgf) 1186 { 1187 log_msg(2, "nfs_mount remains %s", bkpinfo->nfs_mount); 1188 log_msg(2, "nfs_remote_dir remains %s", bkpinfo->nfs_remote_dir); 1189 log_msg(2, "...cos it wouldn't make sense to abandon the values that GOT ME to this config file in the first place"); 1190 } 1191 else 1192 { 1193 read_cfg_var(g_mondo_cfg_file, "nfs-server-mount", bkpinfo->nfs_mount); 1194 read_cfg_var(g_mondo_cfg_file, "nfs-server-path", bkpinfo->nfs_remote_dir); 1195 log_msg(2, "nfs_mount is %s", bkpinfo->nfs_mount); 1196 log_msg(2, "nfs_remote_dir is %s", bkpinfo->nfs_remote_dir); 1197 } 1198 } 1199 else if (bkpinfo->backup_media_type == iso) 1200 { 1201 /* Patch by Conor Daly 23-june-2004 1202 * to correctly mount iso-dev and set a sensible 1203 * isodir in disaster recovery mode 1204 */ 1205 strcpy (old_isodir, bkpinfo->isodir); 1206 read_cfg_var(g_mondo_cfg_file, "iso-mnt", iso_mnt); 1207 read_cfg_var(g_mondo_cfg_file, "isodir", iso_path); 1208 sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path); 1209 if (!bkpinfo->isodir[0]) { 1210 strcpy (bkpinfo->isodir, old_isodir); 1211 } 1212 if (!bkpinfo->disaster_recovery) 1213 { 1214 if (strcmp(old_isodir, bkpinfo->isodir)) { 1215 log_it("user nominated isodir differs from archive, keeping user's choice: %s %s\n", old_isodir, bkpinfo->isodir); 1216 strcpy (bkpinfo->isodir, old_isodir); 1217 } 1218 } 1219 read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device); 1220 log_msg(2, "isodir=%s; iso-dev=%s", bkpinfo->isodir, g_isodir_device); 1221 if (bkpinfo->disaster_recovery) { 1222 if (is_this_device_mounted(g_isodir_device)) 1223 { log_msg(2, "NB: isodir is already mounted"); 1224 /* Find out where it's mounted */ 1225 sprintf(command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3", g_isodir_device); 1226 log_it("command = %s", command); 1227 log_it("res of it = %s", call_program_and_get_last_line_of_output(command)); 1228 sprintf(iso_mnt, "%s", call_program_and_get_last_line_of_output(command)); 1229 } 1230 else 1231 { 1232 sprintf(iso_mnt, "/tmp/isodir"); 1233 sprintf(tmp, "mkdir -p %s", iso_mnt); 1234 run_program_and_log_output(tmp, 5); 1235 sprintf(tmp, "mount %s %s", g_isodir_device, iso_mnt); 1236 if (run_program_and_log_output(tmp, 3)) 1237 { 1238 log_msg(1, "Unable to mount isodir. Perhaps this is really a CD backup?"); 1239 bkpinfo->backup_media_type = cdr; 1240 strcpy(bkpinfo->media_device,"/dev/cdrom"); /* superfluous */ 1241 bkpinfo->isodir[0] = iso_mnt[0] = iso_path[0] = '\0'; 1242 if ( mount_cdrom( bkpinfo ) ) 1243 { 1244 fatal_error( "Unable to mount isodir. Failed to mount CD-ROM as well."); 1245 } 1246 else 1247 { 1248 log_msg(1, "You backed up to disk, then burned some CDs. Naughty monkey!" ); 1249 } 1250 } 1251 } 1252 /* bkpinfo->isodir should now be the true path to 1.iso etc... */ 1253 if (bkpinfo->backup_media_type == iso) 1254 { 1255 sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path); 1256 } 1257 } 1258 } 1259 1260 if (media_specified_by_user != none) 1261 { 1262 if (g_restoring_live_from_cd) 1263 { 1264 if (bkpinfo->backup_media_type != media_specified_by_user) 1265 { 1266 log_msg(2, "bkpinfo->backup_media_type != media_specified_by_user, so I'd better ask :)"); 1267 interactively_obtain_media_parameters_from_user( bkpinfo, FALSE); 1268 media_specified_by_user = bkpinfo->backup_media_type; 1269 get_cfg_file_from_archive(bkpinfo); 1054 bkpinfo->media_size[0] = 1999 * 1024; 1055 bkpinfo->media_size[1] = 650; /* good guess */ 1056 } else if (bkpinfo->backup_media_type == tape 1057 || bkpinfo->backup_media_type == udev) { 1058 if (read_cfg_var(cfg_file, "media-dev", value)) { 1059 fatal_error("Cannot get tape device name from cfg file"); 1060 } 1061 strcpy(bkpinfo->media_device, value); 1062 read_cfg_var(cfg_file, "media-size", value); 1063 bkpinfo->media_size[1] = atol(value); 1064 sprintf(tmp, "Backup medium is TAPE --- dev=%s", 1065 bkpinfo->media_device); 1066 log_msg(2, tmp); 1067 } else { 1068 strcpy(bkpinfo->media_device, "/dev/cdrom"); /* we don't really need this var */ 1069 bkpinfo->media_size[0] = 1999 * 1024; /* 650, probably, but we don't need this var anyway */ 1070 bkpinfo->media_size[1] = 1999 * 1024; /* 650, probably, but we don't need this var anyway */ 1071 log_msg(2, "Backup medium is CD-R[W]"); 1072 } 1073 } else { 1074 log_msg(2, 1075 "Not in Disaster Recovery Mode. No need to derive device name from config file."); 1076 } 1077 1078 read_cfg_var(cfg_file, "use-star", value); 1079 if (strstr(value, "yes")) { 1080 bkpinfo->use_star = TRUE; 1081 log_msg(1, "Goody! ... bkpinfo->use_star is now true."); 1082 } 1083 1084 if (0 == read_cfg_var(cfg_file, "internal-tape-block-size", value)) { 1085 bkpinfo->internal_tape_block_size = atol(value); 1086 log_msg(1, "Internal tape block size has been custom-set to %ld", 1087 bkpinfo->internal_tape_block_size); 1088 } else { 1089 bkpinfo->internal_tape_block_size = 1090 DEFAULT_INTERNAL_TAPE_BLOCK_SIZE; 1091 log_msg(1, "Internal tape block size = default (%ld)", 1092 DEFAULT_INTERNAL_TAPE_BLOCK_SIZE); 1093 } 1094 1095 read_cfg_var(cfg_file, "use-lzo", value); 1096 if (strstr(value, "yes")) { 1097 bkpinfo->use_lzo = TRUE; 1098 strcpy(bkpinfo->zip_exe, "lzop"); 1099 strcpy(bkpinfo->zip_suffix, "lzo"); 1100 } else { 1101 read_cfg_var(cfg_file, "use-comp", value); 1102 if (strstr(value, "yes")) { 1103 bkpinfo->use_lzo = FALSE; 1104 strcpy(bkpinfo->zip_exe, "bzip2"); 1105 strcpy(bkpinfo->zip_suffix, "bz2"); 1106 } else { 1107 bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0'; 1108 } 1109 } 1110 1111 value[0] = '\0'; 1112 read_cfg_var(cfg_file, "differential", value); 1113 if (!strcmp(value, "yes") || !strcmp(value, "1")) { 1114 bkpinfo->differential = TRUE; 1115 } 1116 log_msg(2, "differential var = '%s'", value); 1117 if (bkpinfo->differential) { 1118 log_msg(2, "THIS IS A DIFFERENTIAL BACKUP"); 1119 } else { 1120 log_msg(2, "This is a regular (full) backup"); 1121 } 1122 1123 read_cfg_var(g_mondo_cfg_file, "please-dont-eject", tmp); 1124 if (tmp[0] 1125 || 1126 strstr(call_program_and_get_last_line_of_output 1127 ("cat /proc/cmdline"), "donteject")) { 1128 bkpinfo->please_dont_eject = TRUE; 1129 log_msg(2, "Ok, I shan't eject when restoring! Groovy."); 1130 } 1131 1132 if (bkpinfo->backup_media_type == nfs) { 1133 if (!cfgf) { 1134 log_msg(2, "nfs_mount remains %s", bkpinfo->nfs_mount); 1135 log_msg(2, "nfs_remote_dir remains %s", 1136 bkpinfo->nfs_remote_dir); 1137 log_msg(2, 1138 "...cos it wouldn't make sense to abandon the values that GOT ME to this config file in the first place"); 1139 } else { 1140 read_cfg_var(g_mondo_cfg_file, "nfs-server-mount", 1141 bkpinfo->nfs_mount); 1142 read_cfg_var(g_mondo_cfg_file, "nfs-server-path", 1143 bkpinfo->nfs_remote_dir); 1144 log_msg(2, "nfs_mount is %s", bkpinfo->nfs_mount); 1145 log_msg(2, "nfs_remote_dir is %s", bkpinfo->nfs_remote_dir); 1146 } 1147 } else if (bkpinfo->backup_media_type == iso) { 1148 /* Patch by Conor Daly 23-june-2004 1149 * to correctly mount iso-dev and set a sensible 1150 * isodir in disaster recovery mode 1151 */ 1152 strcpy(old_isodir, bkpinfo->isodir); 1153 read_cfg_var(g_mondo_cfg_file, "iso-mnt", iso_mnt); 1154 read_cfg_var(g_mondo_cfg_file, "isodir", iso_path); 1155 sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path); 1156 if (!bkpinfo->isodir[0]) { 1157 strcpy(bkpinfo->isodir, old_isodir); 1158 } 1159 if (!bkpinfo->disaster_recovery) { 1160 if (strcmp(old_isodir, bkpinfo->isodir)) { 1161 log_it 1162 ("user nominated isodir differs from archive, keeping user's choice: %s %s\n", 1163 old_isodir, bkpinfo->isodir); 1164 strcpy(bkpinfo->isodir, old_isodir); 1165 } 1166 } 1167 read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device); 1168 log_msg(2, "isodir=%s; iso-dev=%s", bkpinfo->isodir, 1169 g_isodir_device); 1170 if (bkpinfo->disaster_recovery) { 1171 if (is_this_device_mounted(g_isodir_device)) { 1172 log_msg(2, "NB: isodir is already mounted"); 1173 /* Find out where it's mounted */ 1174 sprintf(command, 1175 "mount | grep -w %s | tail -n1 | cut -d' ' -f3", 1176 g_isodir_device); 1177 log_it("command = %s", command); 1178 log_it("res of it = %s", 1179 call_program_and_get_last_line_of_output(command)); 1180 sprintf(iso_mnt, "%s", 1181 call_program_and_get_last_line_of_output(command)); 1182 } else { 1183 sprintf(iso_mnt, "/tmp/isodir"); 1184 sprintf(tmp, "mkdir -p %s", iso_mnt); 1185 run_program_and_log_output(tmp, 5); 1186 sprintf(tmp, "mount %s %s", g_isodir_device, iso_mnt); 1187 if (run_program_and_log_output(tmp, 3)) { 1188 log_msg(1, 1189 "Unable to mount isodir. Perhaps this is really a CD backup?"); 1190 bkpinfo->backup_media_type = cdr; 1191 strcpy(bkpinfo->media_device, "/dev/cdrom"); /* superfluous */ 1192 bkpinfo->isodir[0] = iso_mnt[0] = iso_path[0] = '\0'; 1193 if (mount_cdrom(bkpinfo)) { 1194 fatal_error 1195 ("Unable to mount isodir. Failed to mount CD-ROM as well."); 1196 } else { 1197 log_msg(1, 1198 "You backed up to disk, then burned some CDs. Naughty monkey!"); 1199 } 1200 } 1201 } 1202 /* bkpinfo->isodir should now be the true path to 1.iso etc... */ 1203 if (bkpinfo->backup_media_type == iso) { 1204 sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path); 1205 } 1206 } 1207 } 1208 1209 if (media_specified_by_user != none) { 1210 if (g_restoring_live_from_cd) { 1211 if (bkpinfo->backup_media_type != media_specified_by_user) { 1212 log_msg(2, 1213 "bkpinfo->backup_media_type != media_specified_by_user, so I'd better ask :)"); 1214 interactively_obtain_media_parameters_from_user(bkpinfo, 1215 FALSE); 1216 media_specified_by_user = bkpinfo->backup_media_type; 1217 get_cfg_file_from_archive(bkpinfo); 1270 1218 /* 1271 1219 if (media_specified_by_user != cdr && media_specified_by_user == cdrw) 1272 1220 { g_restoring_live_from_cd = FALSE; } 1273 1221 */ 1274 } 1275 } 1276 bkpinfo->backup_media_type = media_specified_by_user; 1277 } 1278 g_backup_media_type = bkpinfo->backup_media_type; 1279 paranoid_free(value); 1280 paranoid_free(tmp); 1281 paranoid_free(command); 1282 paranoid_free(iso_mnt); 1283 paranoid_free(iso_path); 1284 paranoid_free(old_isodir); 1285 return( 0 ); 1286 1287 } 1222 } 1223 } 1224 bkpinfo->backup_media_type = media_specified_by_user; 1225 } 1226 g_backup_media_type = bkpinfo->backup_media_type; 1227 paranoid_free(value); 1228 paranoid_free(tmp); 1229 paranoid_free(command); 1230 paranoid_free(iso_mnt); 1231 paranoid_free(iso_path); 1232 paranoid_free(old_isodir); 1233 return (0); 1234 1235 } 1236 1288 1237 /************************************************************************** 1289 1238 *END_READ_CFG_FILE_INTO_BKPINFO * … … 1291 1240 1292 1241 1293 1242 1294 1243 1295 1244 /** … … 1304 1253 */ 1305 1254 struct 1306 s_node *process_filelist_and_biggielist( struct s_bkpinfo *bkpinfo)1307 { 1308 1255 s_node *process_filelist_and_biggielist(struct s_bkpinfo *bkpinfo) 1256 { 1257 struct s_node *filelist; 1309 1258 1310 1259 /** add mallocs**/ 1311 char *command; 1312 char *tmp; 1313 int res=0; 1314 pid_t pid; 1315 1316 assert(bkpinfo!=NULL); 1317 malloc_string(command); 1318 malloc_string(tmp); 1319 1320 if ( does_file_exist( g_filelist_full ) && does_file_exist( g_biggielist_txt ) ) 1321 { 1322 log_msg(1, "%s exists", g_filelist_full); 1323 log_msg(1, "%s exists", g_biggielist_txt); 1324 log_msg(2, "Filelist and biggielist already recovered from media. Yay!" ); 1325 } 1326 else 1327 { 1328 getcwd( tmp, MAX_STR_LEN ); 1329 chdir( bkpinfo->tmpdir ); 1330 log_msg(1, "chdir(%s)", bkpinfo->tmpdir); 1331 log_to_screen( "Extracting filelist and biggielist from media..." ); 1332 unlink("/tmp/filelist.full"); 1333 unlink("/" FILELIST_FULL_STUB); 1334 unlink("/tmp/i-want-my-lvm"); 1335 if ( IS_THIS_A_STREAMING_BACKUP( bkpinfo->backup_media_type ) ) 1336 { 1337 sprintf( command, 1338 "tar -zxf %s %s %s %s %s %s", 1339 bkpinfo->media_device, 1340 MOUNTLIST_FNAME_STUB, 1341 BIGGIELIST_TXT_STUB, 1342 FILELIST_FULL_STUB, 1343 "tmp/i-want-my-lvm", 1344 MONDO_CFG_FILE_STUB); 1345 log_msg(1, "tarcommand = %s", command); 1346 run_program_and_log_output( command, 1 ); 1347 } 1348 else 1349 { 1350 log_msg(2,"Calling insist_on_this_cd_number; bkpinfo->isodir=%s", bkpinfo->isodir); 1351 insist_on_this_cd_number( bkpinfo, 1 ); 1352 log_msg(2, "Back from iotcn"); 1353 run_program_and_log_output("mount", 1); 1354 sprintf( command, 1355 "tar -zxf %s/images/all.tar.gz %s %s %s %s %s", 1356 MNT_CDROM, 1357 MOUNTLIST_FNAME_STUB, 1358 BIGGIELIST_TXT_STUB, 1359 FILELIST_FULL_STUB, 1360 "tmp/i-want-my-lvm", 1361 MONDO_CFG_FILE_STUB); 1362 1363 log_msg(1, "tarcommand = %s", command); 1364 run_program_and_log_output(command, 1); 1365 // popup_and_OK("Press ENTER to continue"); 1366 if ( !does_file_exist( BIGGIELIST_TXT_STUB ) ) 1367 { 1368 fatal_error( "all.tar.gz did not include tmp/biggielist.txt"); 1369 } 1370 if ( !does_file_exist( FILELIST_FULL_STUB ) ) 1371 { 1372 fatal_error( "all.tar.gz did not include tmp/filelist.full.gz"); 1373 } 1374 } 1375 sprintf( command, "cp -f %s %s", MONDO_CFG_FILE_STUB, g_mondo_cfg_file ); 1376 run_program_and_log_output( command, FALSE ); 1377 1378 sprintf(command, "cp -f %s/%s %s", bkpinfo->tmpdir, BIGGIELIST_TXT_STUB, g_biggielist_txt); 1379 log_msg(1, "command = %s", command); 1380 paranoid_system(command); 1381 sprintf(command, "ln -sf %s/%s %s", bkpinfo->tmpdir, FILELIST_FULL_STUB, g_filelist_full); 1382 log_msg(1, "command = %s", command); 1383 paranoid_system(command); 1384 } 1385 1386 if (am_I_in_disaster_recovery_mode() && ask_me_yes_or_no("Do you want to retrieve the mountlist as well?")) 1387 { 1260 char *command; 1261 char *tmp; 1262 int res = 0; 1263 pid_t pid; 1264 1265 assert(bkpinfo != NULL); 1266 malloc_string(command); 1267 malloc_string(tmp); 1268 1269 if (does_file_exist(g_filelist_full) 1270 && does_file_exist(g_biggielist_txt)) { 1271 log_msg(1, "%s exists", g_filelist_full); 1272 log_msg(1, "%s exists", g_biggielist_txt); 1273 log_msg(2, 1274 "Filelist and biggielist already recovered from media. Yay!"); 1275 } else { 1276 getcwd(tmp, MAX_STR_LEN); 1277 chdir(bkpinfo->tmpdir); 1278 log_msg(1, "chdir(%s)", bkpinfo->tmpdir); 1279 log_to_screen("Extracting filelist and biggielist from media..."); 1280 unlink("/tmp/filelist.full"); 1281 unlink("/" FILELIST_FULL_STUB); 1282 unlink("/tmp/i-want-my-lvm"); 1283 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 1284 sprintf(command, 1285 "tar -zxf %s %s %s %s %s %s", 1286 bkpinfo->media_device, 1287 MOUNTLIST_FNAME_STUB, 1288 BIGGIELIST_TXT_STUB, 1289 FILELIST_FULL_STUB, 1290 "tmp/i-want-my-lvm", MONDO_CFG_FILE_STUB); 1291 log_msg(1, "tarcommand = %s", command); 1292 run_program_and_log_output(command, 1); 1293 } else { 1294 log_msg(2, 1295 "Calling insist_on_this_cd_number; bkpinfo->isodir=%s", 1296 bkpinfo->isodir); 1297 insist_on_this_cd_number(bkpinfo, 1); 1298 log_msg(2, "Back from iotcn"); 1299 run_program_and_log_output("mount", 1); 1300 sprintf(command, 1301 "tar -zxf %s/images/all.tar.gz %s %s %s %s %s", 1302 MNT_CDROM, 1303 MOUNTLIST_FNAME_STUB, 1304 BIGGIELIST_TXT_STUB, 1305 FILELIST_FULL_STUB, 1306 "tmp/i-want-my-lvm", MONDO_CFG_FILE_STUB); 1307 1308 log_msg(1, "tarcommand = %s", command); 1309 run_program_and_log_output(command, 1); 1310 // popup_and_OK("Press ENTER to continue"); 1311 if (!does_file_exist(BIGGIELIST_TXT_STUB)) { 1312 fatal_error 1313 ("all.tar.gz did not include tmp/biggielist.txt"); 1314 } 1315 if (!does_file_exist(FILELIST_FULL_STUB)) { 1316 fatal_error 1317 ("all.tar.gz did not include tmp/filelist.full.gz"); 1318 } 1319 } 1320 sprintf(command, "cp -f %s %s", MONDO_CFG_FILE_STUB, 1321 g_mondo_cfg_file); 1322 run_program_and_log_output(command, FALSE); 1323 1324 sprintf(command, "cp -f %s/%s %s", bkpinfo->tmpdir, 1325 BIGGIELIST_TXT_STUB, g_biggielist_txt); 1326 log_msg(1, "command = %s", command); 1327 paranoid_system(command); 1328 sprintf(command, "ln -sf %s/%s %s", bkpinfo->tmpdir, 1329 FILELIST_FULL_STUB, g_filelist_full); 1330 log_msg(1, "command = %s", command); 1331 paranoid_system(command); 1332 } 1333 1334 if (am_I_in_disaster_recovery_mode() 1335 && 1336 ask_me_yes_or_no("Do you want to retrieve the mountlist as well?")) 1337 { 1388 1338 // sprintf(command, "cp -f tmp/mountlist.txt /tmp"); 1389 sprintf(command, "ln -sf %s/%s /tmp", MOUNTLIST_FNAME_STUB, bkpinfo->tmpdir); 1390 paranoid_system(command); 1391 } 1392 1393 chdir( tmp ); 1394 1395 if (!does_file_exist( g_biggielist_txt) ) 1396 { 1397 log_msg(1, "Warning - %s not found", g_biggielist_txt); 1398 } 1399 if (!does_file_exist(g_filelist_full) ) 1400 { 1401 log_msg(1, "Warning - %s does not exist", g_filelist_full); 1402 } 1403 1339 sprintf(command, "ln -sf %s/%s /tmp", MOUNTLIST_FNAME_STUB, 1340 bkpinfo->tmpdir); 1341 paranoid_system(command); 1342 } 1343 1344 chdir(tmp); 1345 1346 if (!does_file_exist(g_biggielist_txt)) { 1347 log_msg(1, "Warning - %s not found", g_biggielist_txt); 1348 } 1349 if (!does_file_exist(g_filelist_full)) { 1350 log_msg(1, "Warning - %s does not exist", g_filelist_full); 1351 } 1404 1352 // popup_and_OK("Wonderful."); 1405 1353 1406 log_msg(2, "Forking" ); 1407 pid = fork(); 1408 switch( pid ) 1409 { 1410 case -1: 1411 fatal_error("Forking error"); 1412 break; 1413 1414 case 0: 1415 log_to_screen("Pre-processing filelist"); 1416 if (!does_file_exist(g_biggielist_txt)) 1417 { 1418 sprintf(command,"> %s",g_biggielist_txt); 1419 paranoid_system(command); 1420 } 1421 sprintf(command,"cat %s | grep -x \"/dev/.*\" > %s", g_biggielist_txt, g_filelist_imagedevs); 1422 paranoid_system(command); 1423 exit( 0 ); 1424 break; 1425 1426 default: 1427 open_evalcall_form("Pre-processing filelist"); 1428 while( !waitpid( pid, (int*)0, WNOHANG ) ) 1429 { 1430 usleep( 100000 ); 1431 update_evalcall_form( 0 ); 1432 } 1433 } 1434 close_evalcall_form(); 1435 1436 log_msg(3, "loading filelist"); 1437 filelist = load_filelist( g_filelist_full ); 1438 log_msg(3, "deleting original filelist"); 1439 unlink(g_filelist_full); 1440 if (g_text_mode) 1441 { 1442 printf("Restore which directory? --> "); 1443 fgets(tmp, sizeof(tmp), stdin); 1444 toggle_path_selection (filelist, tmp, TRUE); 1445 if (strlen(tmp)==0) { res=1; } else { res=0; } 1446 } 1447 else 1448 { 1449 res = edit_filelist( filelist ); 1450 } 1451 if (res) 1452 { 1453 log_msg(2, "User hit 'cancel'. Freeing filelist and aborting."); 1454 free_filelist( filelist ); 1455 return( NULL ); 1456 } 1457 ask_about_these_imagedevs( g_filelist_imagedevs, g_imagedevs_restthese ); 1458 close_evalcall_form(); 1459 1460 // NB: It's not necessary to add g_biggielist_txt to the filelist.full 1461 // file. The filelist.full file already contains the filename of EVERY 1462 // file backed up - regular and biggie files. 1463 1464 // However, we do want to make sure the imagedevs selected by the user 1465 // are flagged for restoring. 1466 if ( length_of_file( g_imagedevs_restthese ) > 2 ) 1467 { add_list_of_files_to_filelist(filelist, g_imagedevs_restthese, TRUE); } 1468 1469 paranoid_free(command); 1470 paranoid_free(tmp); 1471 return( filelist ); 1472 } 1354 log_msg(2, "Forking"); 1355 pid = fork(); 1356 switch (pid) { 1357 case -1: 1358 fatal_error("Forking error"); 1359 break; 1360 1361 case 0: 1362 log_to_screen("Pre-processing filelist"); 1363 if (!does_file_exist(g_biggielist_txt)) { 1364 sprintf(command, "> %s", g_biggielist_txt); 1365 paranoid_system(command); 1366 } 1367 sprintf(command, "cat %s | grep -x \"/dev/.*\" > %s", 1368 g_biggielist_txt, g_filelist_imagedevs); 1369 paranoid_system(command); 1370 exit(0); 1371 break; 1372 1373 default: 1374 open_evalcall_form("Pre-processing filelist"); 1375 while (!waitpid(pid, (int *) 0, WNOHANG)) { 1376 usleep(100000); 1377 update_evalcall_form(0); 1378 } 1379 } 1380 close_evalcall_form(); 1381 1382 log_msg(3, "loading filelist"); 1383 filelist = load_filelist(g_filelist_full); 1384 log_msg(3, "deleting original filelist"); 1385 unlink(g_filelist_full); 1386 if (g_text_mode) { 1387 printf("Restore which directory? --> "); 1388 fgets(tmp, sizeof(tmp), stdin); 1389 toggle_path_selection(filelist, tmp, TRUE); 1390 if (strlen(tmp) == 0) { 1391 res = 1; 1392 } else { 1393 res = 0; 1394 } 1395 } else { 1396 res = edit_filelist(filelist); 1397 } 1398 if (res) { 1399 log_msg(2, "User hit 'cancel'. Freeing filelist and aborting."); 1400 free_filelist(filelist); 1401 return (NULL); 1402 } 1403 ask_about_these_imagedevs(g_filelist_imagedevs, g_imagedevs_restthese); 1404 close_evalcall_form(); 1405 1406 // NB: It's not necessary to add g_biggielist_txt to the filelist.full 1407 // file. The filelist.full file already contains the filename of EVERY 1408 // file backed up - regular and biggie files. 1409 1410 // However, we do want to make sure the imagedevs selected by the user 1411 // are flagged for restoring. 1412 if (length_of_file(g_imagedevs_restthese) > 2) { 1413 add_list_of_files_to_filelist(filelist, g_imagedevs_restthese, 1414 TRUE); 1415 } 1416 1417 paranoid_free(command); 1418 paranoid_free(tmp); 1419 return (filelist); 1420 } 1421 1473 1422 /************************************************************************** 1474 1423 *END_ PROCESS_FILELIST_AND_BIGGIELIST * … … 1485 1434 * @return 0 for success, nonzero for failure. 1486 1435 */ 1487 int backup_crucial_file(char *path_root, char *filename)1488 { 1489 1490 1491 1492 1493 1494 1495 assert(path_root!=NULL);1496 1497 1498 1499 1500 1501 1502 1503 1504 return(res);1436 int backup_crucial_file(char *path_root, char *filename) 1437 { 1438 char *tmp; 1439 char *command; 1440 int res; 1441 1442 malloc_string(tmp); 1443 malloc_string(command); 1444 assert(path_root != NULL); 1445 assert_string_is_neither_NULL_nor_zerolength(filename); 1446 1447 sprintf(tmp, "%s/%s", path_root, filename); 1448 sprintf(command, "cp -f %s %s.pristine", tmp, tmp); 1449 1450 res = run_program_and_log_output(command, 5); 1451 paranoid_free(tmp); 1452 paranoid_free(command); 1453 return (res); 1505 1454 } 1506 1455 … … 1512 1461 * @return 0 for success, nonzero for failure. 1513 1462 */ 1514 int 1515 run_boot_loader(bool offer_to_hack_scripts) 1516 { 1517 int res; 1518 int retval = 0; 1463 int run_boot_loader(bool offer_to_hack_scripts) 1464 { 1465 int res; 1466 int retval = 0; 1519 1467 1520 1468 /** malloc *******/ 1521 char *device; 1522 char *tmp; 1523 char *name; 1524 1525 malloc_string(device); 1526 malloc_string(tmp); 1527 malloc_string(name); 1528 backup_crucial_file( MNT_RESTORING, "/etc/fstab"); 1529 backup_crucial_file( MNT_RESTORING, "/etc/grub.conf"); 1530 backup_crucial_file( MNT_RESTORING, "/etc/lilo.conf"); 1531 backup_crucial_file( MNT_RESTORING, "/etc/elilo.conf"); 1532 read_cfg_var(g_mondo_cfg_file, "bootloader.device", device); 1533 read_cfg_var(g_mondo_cfg_file, "bootloader.name", name); 1534 sprintf(tmp,"run_boot_loader: device='%s', name='%s'",device,name); 1535 log_msg(2, tmp); 1536 system("sync"); 1537 if (!strcmp(name,"LILO")) 1538 { 1539 res = run_lilo(offer_to_hack_scripts); 1540 } 1541 else if (!strcmp(name,"ELILO")) 1542 { 1543 res = run_elilo(offer_to_hack_scripts); 1544 } 1545 else if (!strcmp(name,"GRUB")) 1546 { 1469 char *device; 1470 char *tmp; 1471 char *name; 1472 1473 malloc_string(device); 1474 malloc_string(tmp); 1475 malloc_string(name); 1476 backup_crucial_file(MNT_RESTORING, "/etc/fstab"); 1477 backup_crucial_file(MNT_RESTORING, "/etc/grub.conf"); 1478 backup_crucial_file(MNT_RESTORING, "/etc/lilo.conf"); 1479 backup_crucial_file(MNT_RESTORING, "/etc/elilo.conf"); 1480 read_cfg_var(g_mondo_cfg_file, "bootloader.device", device); 1481 read_cfg_var(g_mondo_cfg_file, "bootloader.name", name); 1482 sprintf(tmp, "run_boot_loader: device='%s', name='%s'", device, name); 1483 log_msg(2, tmp); 1484 system("sync"); 1485 if (!strcmp(name, "LILO")) { 1486 res = run_lilo(offer_to_hack_scripts); 1487 } else if (!strcmp(name, "ELILO")) { 1488 res = run_elilo(offer_to_hack_scripts); 1489 } else if (!strcmp(name, "GRUB")) { 1547 1490 // if ( does_file_exist(DO_MBR_PLEASE) || (offer_to_hack_scripts && ask_me_yes_or_no("Because of bugs in GRUB, you're much better off running mondorestore --mbr after this program terminates. Are you sure you want to install GRUB right now?"))) 1548 1491 // { 1549 1550 // 1551 // 1492 res = run_grub(offer_to_hack_scripts, device); 1493 // unlink(DO_MBR_PLEASE); 1494 // } 1552 1495 // else 1553 1496 // { 1554 // log_msg(1, "Not running run_grub(). Was a bad idea anyway."); 1555 // res = 1; 1556 // } 1557 } 1558 else if (!strcmp(name,"RAW")) 1559 { 1560 res = run_raw_mbr(offer_to_hack_scripts, device); 1561 } 1497 // log_msg(1, "Not running run_grub(). Was a bad idea anyway."); 1498 // res = 1; 1499 // } 1500 } else if (!strcmp(name, "RAW")) { 1501 res = run_raw_mbr(offer_to_hack_scripts, device); 1502 } 1562 1503 #ifdef __FreeBSD__ 1563 else if (!strcmp(name,"BOOT0")) 1564 { 1565 sprintf (tmp, "boot0cfg -B %s", device);1566 res = run_program_and_log_output (tmp, FALSE);1567 } else { 1568 sprintf (tmp, "ls /dev | grep -xq %ss[1-4].*", device);1569 if (!system (tmp)) {1570 sprintf (tmp, MNT_RESTORING "/sbin/fdisk -B %s", device);1571 res = run_program_and_log_output (tmp, 3);1572 } else {1573 log_msg (1,"I'm not running any boot loader. You have a DD boot drive. It's already loaded up.");1574 1575 1504 else if (!strcmp(name, "BOOT0")) { 1505 sprintf(tmp, "boot0cfg -B %s", device); 1506 res = run_program_and_log_output(tmp, FALSE); 1507 } else { 1508 sprintf(tmp, "ls /dev | grep -xq %ss[1-4].*", device); 1509 if (!system(tmp)) { 1510 sprintf(tmp, MNT_RESTORING "/sbin/fdisk -B %s", device); 1511 res = run_program_and_log_output(tmp, 3); 1512 } else { 1513 log_msg(1, 1514 "I'm not running any boot loader. You have a DD boot drive. It's already loaded up."); 1515 } 1516 } 1576 1517 #else 1577 else 1578 { 1579 log_to_screen("Unable to determine type of boot loader. Defaulting to LILO.");1580 res=run_lilo(offer_to_hack_scripts);1581 1518 else { 1519 log_to_screen 1520 ("Unable to determine type of boot loader. Defaulting to LILO."); 1521 res = run_lilo(offer_to_hack_scripts); 1522 } 1582 1523 #endif 1583 retval += res; 1584 if (res) 1585 { 1586 log_to_screen("Your boot loader returned an error"); 1587 } 1588 else 1589 { 1590 log_to_screen("Your boot loader ran OK"); 1591 } 1592 paranoid_free(device); 1593 paranoid_free(tmp); 1594 paranoid_free(name); 1595 return(retval); 1596 } 1524 retval += res; 1525 if (res) { 1526 log_to_screen("Your boot loader returned an error"); 1527 } else { 1528 log_to_screen("Your boot loader ran OK"); 1529 } 1530 paranoid_free(device); 1531 paranoid_free(tmp); 1532 paranoid_free(name); 1533 return (retval); 1534 } 1535 1597 1536 /************************************************************************** 1598 1537 *END_ RUN_BOOT_LOADER * … … 1608 1547 char *find_my_editor(void) 1609 1548 { 1610 static char output[MAX_STR_LEN]; 1611 if (find_home_of_exe("pico")) 1612 { strcpy(output, "pico"); } 1613 else if (find_home_of_exe("nano")) 1614 { strcpy(output, "nano"); } 1615 else if (find_home_of_exe ("e3em")) 1616 { 1617 strcpy (output, "e3em"); 1618 } 1619 else if (find_home_of_exe ("e3vi")) 1620 { 1621 strcpy (output, "e3vi"); 1622 } 1623 else 1624 { strcpy(output, "vi"); } 1625 if (!find_home_of_exe(output)) 1626 { log_msg(2, " (find_my_editor) --- warning - %s not found", output); } 1627 return(output); 1549 static char output[MAX_STR_LEN]; 1550 if (find_home_of_exe("pico")) { 1551 strcpy(output, "pico"); 1552 } else if (find_home_of_exe("nano")) { 1553 strcpy(output, "nano"); 1554 } else if (find_home_of_exe("e3em")) { 1555 strcpy(output, "e3em"); 1556 } else if (find_home_of_exe("e3vi")) { 1557 strcpy(output, "e3vi"); 1558 } else { 1559 strcpy(output, "vi"); 1560 } 1561 if (!find_home_of_exe(output)) { 1562 log_msg(2, " (find_my_editor) --- warning - %s not found", output); 1563 } 1564 return (output); 1628 1565 } 1629 1566 … … 1635 1572 * @return 0 for success, nonzero for failure. 1636 1573 */ 1637 int 1638 run_grub(bool offer_to_run_stabgrub, char*bd) 1574 int run_grub(bool offer_to_run_stabgrub, char *bd) 1639 1575 { 1640 1576 /** malloc **/ 1641 char *command; 1642 char *boot_device; 1643 char *rootdev; 1644 char *rootdrive; 1645 char *conffile; 1646 char *tmp; 1647 char *editor; 1648 1649 int res; 1650 int done; 1651 1652 malloc_string(command); 1653 malloc_string(boot_device); 1654 malloc_string(tmp); 1655 malloc_string(editor); 1656 malloc_string(rootdev); 1657 malloc_string(rootdrive); 1658 malloc_string(conffile); 1659 assert_string_is_neither_NULL_nor_zerolength(bd); 1660 strcpy( editor, "vi" ); // find_my_editor() ); 1661 strcpy( boot_device, bd); 1662 1663 if (!run_program_and_log_output("which grub-MR", FALSE)) 1664 { 1665 log_msg(1, "Yay! grub-MR found..."); 1666 sprintf(command, "grub-MR %s /tmp/mountlist.txt", boot_device); 1667 log_msg(1, "command = %s", command); 1668 } 1669 else 1670 { 1671 sprintf(command, "chroot " MNT_RESTORING " grub-install %s",boot_device); 1672 log_msg(1, "WARNING - grub-MR not found; using grub-install"); 1673 } 1674 if (offer_to_run_stabgrub && ask_me_yes_or_no("Did you change the mountlist?")) 1675 /* interactive mode */ 1676 { 1677 mvaddstr_and_log_it(g_currentY, 1678 0, 1679 "Modifying fstab and grub.conf, and running GRUB... "); 1680 for(done = FALSE; !done; ) 1577 char *command; 1578 char *boot_device; 1579 char *rootdev; 1580 char *rootdrive; 1581 char *conffile; 1582 char *tmp; 1583 char *editor; 1584 1585 int res; 1586 int done; 1587 1588 malloc_string(command); 1589 malloc_string(boot_device); 1590 malloc_string(tmp); 1591 malloc_string(editor); 1592 malloc_string(rootdev); 1593 malloc_string(rootdrive); 1594 malloc_string(conffile); 1595 assert_string_is_neither_NULL_nor_zerolength(bd); 1596 strcpy(editor, "vi"); // find_my_editor() ); 1597 strcpy(boot_device, bd); 1598 1599 if (!run_program_and_log_output("which grub-MR", FALSE)) { 1600 log_msg(1, "Yay! grub-MR found..."); 1601 sprintf(command, "grub-MR %s /tmp/mountlist.txt", boot_device); 1602 log_msg(1, "command = %s", command); 1603 } else { 1604 sprintf(command, "chroot " MNT_RESTORING " grub-install %s", 1605 boot_device); 1606 log_msg(1, "WARNING - grub-MR not found; using grub-install"); 1607 } 1608 if (offer_to_run_stabgrub 1609 && ask_me_yes_or_no("Did you change the mountlist?")) 1610 /* interactive mode */ 1681 1611 { 1682 popup_and_get_string("Boot device", 1683 "Please confirm/enter the boot device. If in doubt, try /dev/hda", 1684 boot_device, MAX_STR_LEN/4); 1685 sprintf(command, "stabgrub-me %s", boot_device); 1686 res = run_program_and_log_output(command, 1); 1687 if (res) 1688 { 1689 popup_and_OK("GRUB installation failed. Please install manually using 'grub-install' or similar command. You are now chroot()'ed to your restored system. Please type 'exit' when you are done."); 1690 newtSuspend(); 1691 system("chroot " MNT_RESTORING); 1692 newtResume(); 1693 popup_and_OK("Thank you."); 1694 } 1695 else 1696 { 1697 done = TRUE; 1698 } 1699 popup_and_OK("You will now edit fstab and grub.conf"); 1700 if (!g_text_mode) { newtSuspend(); } 1701 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1702 paranoid_system(tmp); 1703 sprintf(tmp, "%s " MNT_RESTORING "/etc/grub.conf", editor); 1704 paranoid_system(tmp); 1705 if (!g_text_mode) { newtResume(); } 1706 } 1707 } 1708 else 1709 1710 /* nuke mode */ 1711 { 1712 mvaddstr_and_log_it(g_currentY, 1713 0, 1714 "Running GRUB... "); 1715 iamhere(command); 1716 res = run_program_and_log_output(command, 1); 1717 if (res) 1612 mvaddstr_and_log_it(g_currentY, 1613 0, 1614 "Modifying fstab and grub.conf, and running GRUB... "); 1615 for (done = FALSE; !done;) { 1616 popup_and_get_string("Boot device", 1617 "Please confirm/enter the boot device. If in doubt, try /dev/hda", 1618 boot_device, MAX_STR_LEN / 4); 1619 sprintf(command, "stabgrub-me %s", boot_device); 1620 res = run_program_and_log_output(command, 1); 1621 if (res) { 1622 popup_and_OK 1623 ("GRUB installation failed. Please install manually using 'grub-install' or similar command. You are now chroot()'ed to your restored system. Please type 'exit' when you are done."); 1624 newtSuspend(); 1625 system("chroot " MNT_RESTORING); 1626 newtResume(); 1627 popup_and_OK("Thank you."); 1628 } else { 1629 done = TRUE; 1630 } 1631 popup_and_OK("You will now edit fstab and grub.conf"); 1632 if (!g_text_mode) { 1633 newtSuspend(); 1634 } 1635 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1636 paranoid_system(tmp); 1637 sprintf(tmp, "%s " MNT_RESTORING "/etc/grub.conf", editor); 1638 paranoid_system(tmp); 1639 if (!g_text_mode) { 1640 newtResume(); 1641 } 1642 } 1643 } else 1644 /* nuke mode */ 1718 1645 { 1719 popup_and_OK("Because of bugs in GRUB's own installer, GRUB was not installed properly. Please install the boot loader manually now, using this chroot()'ed shell prompt. Type 'exit' when you have finished."); 1720 newtSuspend(); 1721 system("chroot " MNT_RESTORING); 1722 newtResume(); 1723 popup_and_OK("Thank you."); 1724 } 1725 } 1726 if (res) 1727 { 1728 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 1729 log_to_screen("GRUB ran w/error(s). See /tmp/mondo-restore.log for more info."); 1730 log_msg(1,"Type:-"); 1731 log_msg(1," mount-me"); 1732 log_msg(1," chroot " MNT_RESTORING); 1733 log_msg(1," mount /boot"); 1734 log_msg(1," grub-install '(hd0)'"); 1735 log_msg(1," exit"); 1736 log_msg(1," unmount-me"); 1737 log_msg(1,"If you're really stuck, please e-mail the mailing list."); 1738 } 1739 else 1740 { 1741 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 1742 } 1743 paranoid_free(rootdev); 1744 paranoid_free(rootdrive); 1745 paranoid_free(conffile); 1746 paranoid_free(command); 1747 paranoid_free(boot_device); 1748 paranoid_free(tmp); 1749 paranoid_free(editor); 1750 1751 return( res ); 1752 } 1646 mvaddstr_and_log_it(g_currentY, 1647 0, 1648 "Running GRUB... "); 1649 iamhere(command); 1650 res = run_program_and_log_output(command, 1); 1651 if (res) { 1652 popup_and_OK 1653 ("Because of bugs in GRUB's own installer, GRUB was not installed properly. Please install the boot loader manually now, using this chroot()'ed shell prompt. Type 'exit' when you have finished."); 1654 newtSuspend(); 1655 system("chroot " MNT_RESTORING); 1656 newtResume(); 1657 popup_and_OK("Thank you."); 1658 } 1659 } 1660 if (res) { 1661 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 1662 log_to_screen 1663 ("GRUB ran w/error(s). See /tmp/mondo-restore.log for more info."); 1664 log_msg(1, "Type:-"); 1665 log_msg(1, " mount-me"); 1666 log_msg(1, " chroot " MNT_RESTORING); 1667 log_msg(1, " mount /boot"); 1668 log_msg(1, " grub-install '(hd0)'"); 1669 log_msg(1, " exit"); 1670 log_msg(1, " unmount-me"); 1671 log_msg(1, 1672 "If you're really stuck, please e-mail the mailing list."); 1673 } else { 1674 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 1675 } 1676 paranoid_free(rootdev); 1677 paranoid_free(rootdrive); 1678 paranoid_free(conffile); 1679 paranoid_free(command); 1680 paranoid_free(boot_device); 1681 paranoid_free(tmp); 1682 paranoid_free(editor); 1683 1684 return (res); 1685 } 1686 1753 1687 /************************************************************************** 1754 1688 *END_RUN_GRUB * … … 1761 1695 * @return 0 for success, nonzero for failure. 1762 1696 */ 1763 int 1764 run_elilo(bool offer_to_run_stabelilo) 1697 int run_elilo(bool offer_to_run_stabelilo) 1765 1698 { 1766 1699 /** malloc **/ 1767 char *command; 1768 char *tmp; 1769 char *editor; 1770 1771 int res; 1772 int done; 1773 1774 malloc_string(command); 1775 malloc_string(tmp); 1776 malloc_string(editor); 1777 strcpy(editor, find_my_editor()); 1778 if (offer_to_run_stabelilo && ask_me_yes_or_no("Did you change the mountlist?")) 1779 1780 /* interactive mode */ 1781 { 1782 mvaddstr_and_log_it(g_currentY, 1783 0, 1784 "Modifying fstab and elilo.conf... "); 1785 sprintf(command,"stabelilo-me"); 1786 res = run_program_and_log_output(command, 3); 1787 if (res) 1788 { 1789 popup_and_OK("You will now edit fstab and elilo.conf, to make sure they match your new mountlist."); 1790 for(done = FALSE; !done;) 1791 { 1792 if (!g_text_mode) { newtSuspend(); } 1793 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1794 paranoid_system(tmp); 1795 sprintf(tmp, "%s " MNT_RESTORING "/etc/elilo.conf", editor); 1796 paranoid_system(tmp); 1797 if (!g_text_mode) { newtResume(); } 1700 char *command; 1701 char *tmp; 1702 char *editor; 1703 1704 int res; 1705 int done; 1706 1707 malloc_string(command); 1708 malloc_string(tmp); 1709 malloc_string(editor); 1710 strcpy(editor, find_my_editor()); 1711 if (offer_to_run_stabelilo 1712 && ask_me_yes_or_no("Did you change the mountlist?")) 1713 1714 /* interactive mode */ 1715 { 1716 mvaddstr_and_log_it(g_currentY, 1717 0, 1718 "Modifying fstab and elilo.conf... "); 1719 sprintf(command, "stabelilo-me"); 1720 res = run_program_and_log_output(command, 3); 1721 if (res) { 1722 popup_and_OK 1723 ("You will now edit fstab and elilo.conf, to make sure they match your new mountlist."); 1724 for (done = FALSE; !done;) { 1725 if (!g_text_mode) { 1726 newtSuspend(); 1727 } 1728 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1729 paranoid_system(tmp); 1730 sprintf(tmp, "%s " MNT_RESTORING "/etc/elilo.conf", 1731 editor); 1732 paranoid_system(tmp); 1733 if (!g_text_mode) { 1734 newtResume(); 1735 } 1798 1736 // newtCls(); 1799 if (ask_me_yes_or_no("Edit them again?")) 1800 { 1801 continue; 1802 } 1803 done = TRUE; 1804 } 1805 } 1806 else 1737 if (ask_me_yes_or_no("Edit them again?")) { 1738 continue; 1739 } 1740 done = TRUE; 1741 } 1742 } else { 1743 log_to_screen("elilo.conf and fstab were modified OK"); 1744 } 1745 } else 1746 /* nuke mode */ 1807 1747 { 1808 log_to_screen("elilo.conf and fstab were modified OK"); 1809 } 1810 } 1811 else 1812 1813 /* nuke mode */ 1814 { 1815 res = TRUE; 1816 } 1817 paranoid_free(command); 1818 paranoid_free(tmp); 1819 paranoid_free(editor); 1820 return(res); 1821 } 1748 res = TRUE; 1749 } 1750 paranoid_free(command); 1751 paranoid_free(tmp); 1752 paranoid_free(editor); 1753 return (res); 1754 } 1755 1822 1756 /************************************************************************** 1823 1757 *END_RUN_ELILO * … … 1830 1764 * @return 0 for success, nonzero for failure. 1831 1765 */ 1832 int 1833 run_lilo(bool offer_to_run_stablilo) 1766 int run_lilo(bool offer_to_run_stablilo) 1834 1767 { 1835 1768 /** malloc **/ 1836 char *command; 1837 char *tmp; 1838 char *editor; 1839 1840 int res; 1841 int done; 1842 bool run_lilo_M = FALSE; 1843 malloc_string(command); 1844 malloc_string(tmp); 1845 malloc_string(editor); 1846 1847 if (!run_program_and_log_output("grep \"boot.*=.*/dev/md\" " MNT_RESTORING "/etc/lilo.conf", 1)) 1848 { run_lilo_M = TRUE; } 1849 1850 strcpy(editor, find_my_editor()); 1851 if (offer_to_run_stablilo && ask_me_yes_or_no("Did you change the mountlist?")) 1852 1853 /* interactive mode */ 1854 { 1855 mvaddstr_and_log_it(g_currentY, 1856 0, 1857 "Modifying fstab and lilo.conf, and running LILO... "); 1858 sprintf(command,"stablilo-me"); 1859 res = run_program_and_log_output(command, 3); 1860 if (res) 1861 { 1862 popup_and_OK("You will now edit fstab and lilo.conf, to make sure they match your new mountlist."); 1863 for(done = FALSE; !done;) 1864 { 1865 if (!g_text_mode) { newtSuspend(); } 1866 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1867 paranoid_system(tmp); 1868 sprintf(tmp, "%s " MNT_RESTORING "/etc/lilo.conf", editor); 1869 paranoid_system(tmp); 1870 if (!g_text_mode) { newtResume(); } 1769 char *command; 1770 char *tmp; 1771 char *editor; 1772 1773 int res; 1774 int done; 1775 bool run_lilo_M = FALSE; 1776 malloc_string(command); 1777 malloc_string(tmp); 1778 malloc_string(editor); 1779 1780 if (!run_program_and_log_output 1781 ("grep \"boot.*=.*/dev/md\" " MNT_RESTORING "/etc/lilo.conf", 1)) { 1782 run_lilo_M = TRUE; 1783 } 1784 1785 strcpy(editor, find_my_editor()); 1786 if (offer_to_run_stablilo 1787 && ask_me_yes_or_no("Did you change the mountlist?")) 1788 1789 /* interactive mode */ 1790 { 1791 mvaddstr_and_log_it(g_currentY, 1792 0, 1793 "Modifying fstab and lilo.conf, and running LILO... "); 1794 sprintf(command, "stablilo-me"); 1795 res = run_program_and_log_output(command, 3); 1796 if (res) { 1797 popup_and_OK 1798 ("You will now edit fstab and lilo.conf, to make sure they match your new mountlist."); 1799 for (done = FALSE; !done;) { 1800 if (!g_text_mode) { 1801 newtSuspend(); 1802 } 1803 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1804 paranoid_system(tmp); 1805 sprintf(tmp, "%s " MNT_RESTORING "/etc/lilo.conf", editor); 1806 paranoid_system(tmp); 1807 if (!g_text_mode) { 1808 newtResume(); 1809 } 1871 1810 // newtCls(); 1872 if (ask_me_yes_or_no("Edit them again?")) 1873 { 1874 continue; 1875 } 1876 res = run_program_and_log_output("chroot " MNT_RESTORING " lilo -L", 3); 1877 if (res) 1878 { 1879 res = run_program_and_log_output("chroot " MNT_RESTORING " lilo", 3); 1880 } 1881 if (res) 1882 { 1883 done = ask_me_yes_or_no("LILO failed. Re-edit system files?"); 1884 } 1885 else 1886 { 1887 done = TRUE; 1888 } 1889 } 1890 } 1891 else 1811 if (ask_me_yes_or_no("Edit them again?")) { 1812 continue; 1813 } 1814 res = 1815 run_program_and_log_output("chroot " MNT_RESTORING 1816 " lilo -L", 3); 1817 if (res) { 1818 res = 1819 run_program_and_log_output("chroot " MNT_RESTORING 1820 " lilo", 3); 1821 } 1822 if (res) { 1823 done = 1824 ask_me_yes_or_no 1825 ("LILO failed. Re-edit system files?"); 1826 } else { 1827 done = TRUE; 1828 } 1829 } 1830 } else { 1831 log_to_screen("lilo.conf and fstab were modified OK"); 1832 } 1833 } else 1834 /* nuke mode */ 1892 1835 { 1893 log_to_screen("lilo.conf and fstab were modified OK"); 1894 } 1895 } 1896 else 1897 1898 /* nuke mode */ 1899 { 1900 mvaddstr_and_log_it(g_currentY, 1901 0, 1902 "Running LILO... "); 1903 res = run_program_and_log_output("chroot " MNT_RESTORING " lilo -L", 3); 1904 if (res) 1905 { 1906 res = run_program_and_log_output("chroot " MNT_RESTORING " lilo", 3); 1907 } 1908 if (res) 1909 { 1910 mvaddstr_and_log_it(g_currentY++,74,"Failed."); 1911 log_to_screen("Failed to re-jig fstab and/or lilo. Edit/run manually, please."); 1912 } 1913 else 1914 { 1915 mvaddstr_and_log_it(g_currentY++,74,"Done."); 1916 } 1917 } 1918 if (run_lilo_M) 1919 { 1920 run_program_and_log_output("chroot " MNT_RESTORING " lilo -M /dev/hda", 3); 1921 run_program_and_log_output("chroot " MNT_RESTORING " lilo -M /dev/sda", 3); 1922 } 1923 paranoid_free(command); 1924 paranoid_free(tmp); 1925 paranoid_free(editor); 1926 return(res); 1927 } 1836 mvaddstr_and_log_it(g_currentY, 1837 0, 1838 "Running LILO... "); 1839 res = 1840 run_program_and_log_output("chroot " MNT_RESTORING " lilo -L", 1841 3); 1842 if (res) { 1843 res = 1844 run_program_and_log_output("chroot " MNT_RESTORING " lilo", 1845 3); 1846 } 1847 if (res) { 1848 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 1849 log_to_screen 1850 ("Failed to re-jig fstab and/or lilo. Edit/run manually, please."); 1851 } else { 1852 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 1853 } 1854 } 1855 if (run_lilo_M) { 1856 run_program_and_log_output("chroot " MNT_RESTORING 1857 " lilo -M /dev/hda", 3); 1858 run_program_and_log_output("chroot " MNT_RESTORING 1859 " lilo -M /dev/sda", 3); 1860 } 1861 paranoid_free(command); 1862 paranoid_free(tmp); 1863 paranoid_free(editor); 1864 return (res); 1865 } 1866 1928 1867 /************************************************************************** 1929 1868 *END_RUN_LILO * … … 1937 1876 * @return 0 for success, nonzero for failure. 1938 1877 */ 1939 int 1940 run_raw_mbr(bool offer_to_hack_scripts, char *bd) 1878 int run_raw_mbr(bool offer_to_hack_scripts, char *bd) 1941 1879 { 1942 1880 /** malloc **/ 1943 char *command; 1944 char *boot_device; 1945 char *tmp; 1946 char *editor; 1947 int res; 1948 int done; 1949 1950 malloc_string(command); 1951 malloc_string(boot_device); 1952 malloc_string(tmp); 1953 malloc_string(editor); 1954 assert_string_is_neither_NULL_nor_zerolength(bd); 1955 1956 strcpy( editor, find_my_editor() ); 1957 strcpy( boot_device, bd ); 1958 sprintf(command, "raw-MR %s /tmp/mountlist.txt", boot_device); 1959 log_msg(2, "run_raw_mbr() --- command='%s'", command); 1960 1961 if (offer_to_hack_scripts && ask_me_yes_or_no("Did you change the mountlist?")) 1962 /* interactive mode */ 1963 { 1964 mvaddstr_and_log_it(g_currentY,0,"Modifying fstab and restoring MBR... "); 1965 for(done=FALSE; !done; ) 1881 char *command; 1882 char *boot_device; 1883 char *tmp; 1884 char *editor; 1885 int res; 1886 int done; 1887 1888 malloc_string(command); 1889 malloc_string(boot_device); 1890 malloc_string(tmp); 1891 malloc_string(editor); 1892 assert_string_is_neither_NULL_nor_zerolength(bd); 1893 1894 strcpy(editor, find_my_editor()); 1895 strcpy(boot_device, bd); 1896 sprintf(command, "raw-MR %s /tmp/mountlist.txt", boot_device); 1897 log_msg(2, "run_raw_mbr() --- command='%s'", command); 1898 1899 if (offer_to_hack_scripts 1900 && ask_me_yes_or_no("Did you change the mountlist?")) 1901 /* interactive mode */ 1966 1902 { 1967 if (!run_program_and_log_output("which vi", FALSE)) 1968 { 1969 popup_and_OK("You will now edit fstab"); 1970 if (!g_text_mode) { newtSuspend(); } 1971 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1972 paranoid_system(tmp); 1973 if (!g_text_mode) { newtResume(); } 1903 mvaddstr_and_log_it(g_currentY, 0, 1904 "Modifying fstab and restoring MBR... "); 1905 for (done = FALSE; !done;) { 1906 if (!run_program_and_log_output("which vi", FALSE)) { 1907 popup_and_OK("You will now edit fstab"); 1908 if (!g_text_mode) { 1909 newtSuspend(); 1910 } 1911 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1912 paranoid_system(tmp); 1913 if (!g_text_mode) { 1914 newtResume(); 1915 } 1974 1916 // newtCls(); 1975 } 1976 popup_and_get_string("Boot device", "Please confirm/enter the boot device. If in doubt, try /dev/hda",boot_device, MAX_STR_LEN/4); 1977 sprintf(command, "stabraw-me %s", boot_device); 1978 res = run_program_and_log_output(command, 3); 1979 if (res) 1980 { 1981 done = ask_me_yes_or_no("Modifications failed. Re-try?"); 1982 } 1983 else 1984 { 1985 done = TRUE; 1986 } 1987 } 1988 } 1989 else 1990 1991 /* nuke mode */ 1992 { 1993 mvaddstr_and_log_it(g_currentY,0,"Restoring MBR... "); 1994 res = run_program_and_log_output(command, 3); 1995 } 1996 if (res) 1997 { 1998 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 1999 log_to_screen("MBR+fstab processed w/error(s). See /tmp/mondo-restore.log for more info."); 2000 } 2001 else 2002 { 2003 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 2004 } 2005 paranoid_free(command); 2006 paranoid_free(boot_device); 2007 paranoid_free(tmp); 2008 paranoid_free(editor); 2009 return(res); 2010 } 1917 } 1918 popup_and_get_string("Boot device", 1919 "Please confirm/enter the boot device. If in doubt, try /dev/hda", 1920 boot_device, MAX_STR_LEN / 4); 1921 sprintf(command, "stabraw-me %s", boot_device); 1922 res = run_program_and_log_output(command, 3); 1923 if (res) { 1924 done = ask_me_yes_or_no("Modifications failed. Re-try?"); 1925 } else { 1926 done = TRUE; 1927 } 1928 } 1929 } else 1930 /* nuke mode */ 1931 { 1932 mvaddstr_and_log_it(g_currentY, 0, 1933 "Restoring MBR... "); 1934 res = run_program_and_log_output(command, 3); 1935 } 1936 if (res) { 1937 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 1938 log_to_screen 1939 ("MBR+fstab processed w/error(s). See /tmp/mondo-restore.log for more info."); 1940 } else { 1941 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 1942 } 1943 paranoid_free(command); 1944 paranoid_free(boot_device); 1945 paranoid_free(tmp); 1946 paranoid_free(editor); 1947 return (res); 1948 } 1949 2011 1950 /************************************************************************** 2012 1951 *END_RUN_RAW_MBR * … … 2015 1954 2016 1955 2017 2018 1956 1957 2019 1958 /** 2020 1959 * Turn signal trapping on or off. … … 2022 1961 * print a message and exit immediately. 2023 1962 */ 2024 void 2025 set_signals( int on ) 2026 { 2027 int signals[]= { SIGKILL, SIGPIPE, SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT, SIGSTOP, 0 }; 2028 int i; 2029 for ( i = 0; signals[i]; i++) 2030 { 2031 if (on) 2032 { 2033 signal( signals[i], terminate_daemon); 2034 } 2035 else 2036 { 2037 signal(signals[i], termination_in_progress); 2038 } 2039 } 1963 void set_signals(int on) 1964 { 1965 int signals[] = 1966 { SIGKILL, SIGPIPE, SIGTERM, SIGHUP, SIGTRAP, SIGABRT, SIGINT, 1967 SIGSTOP, 0 }; 1968 int i; 1969 for (i = 0; signals[i]; i++) { 1970 if (on) { 1971 signal(signals[i], terminate_daemon); 1972 } else { 1973 signal(signals[i], termination_in_progress); 1974 } 1975 } 2040 1976 } 2041 1977 … … 2051 1987 * - @c bkpinfo->disaster_recovery 2052 1988 */ 2053 void 2054 setup_MR_global_filenames(struct s_bkpinfo *bkpinfo) 2055 { 2056 char *temppath; 2057 2058 assert(bkpinfo!=NULL); 2059 2060 malloc_string ( g_biggielist_txt ); 2061 malloc_string ( g_filelist_full ); 2062 malloc_string ( g_filelist_imagedevs ); 2063 malloc_string ( g_imagedevs_restthese ); 2064 malloc_string ( g_mondo_cfg_file ); 2065 malloc_string ( g_mountlist_fname ); 2066 malloc_string ( g_mondo_home ); 2067 malloc_string ( g_tmpfs_mountpt ); 2068 malloc_string ( g_isodir_device ); 2069 malloc_string ( g_isodir_format ); 2070 2071 temppath = bkpinfo->tmpdir; 2072 2073 sprintf(g_biggielist_txt, "%s/%s", temppath, BIGGIELIST_TXT_STUB); 2074 sprintf(g_filelist_full, "%s/%s", temppath, FILELIST_FULL_STUB); 2075 sprintf(g_filelist_imagedevs, "%s/tmp/filelist.imagedevs", temppath); 1989 void setup_MR_global_filenames(struct s_bkpinfo *bkpinfo) 1990 { 1991 char *temppath; 1992 1993 assert(bkpinfo != NULL); 1994 1995 malloc_string(g_biggielist_txt); 1996 malloc_string(g_filelist_full); 1997 malloc_string(g_filelist_imagedevs); 1998 malloc_string(g_imagedevs_restthese); 1999 malloc_string(g_mondo_cfg_file); 2000 malloc_string(g_mountlist_fname); 2001 malloc_string(g_mondo_home); 2002 malloc_string(g_tmpfs_mountpt); 2003 malloc_string(g_isodir_device); 2004 malloc_string(g_isodir_format); 2005 2006 temppath = bkpinfo->tmpdir; 2007 2008 sprintf(g_biggielist_txt, "%s/%s", temppath, BIGGIELIST_TXT_STUB); 2009 sprintf(g_filelist_full, "%s/%s", temppath, FILELIST_FULL_STUB); 2010 sprintf(g_filelist_imagedevs, "%s/tmp/filelist.imagedevs", temppath); 2076 2011 // sprintf(g_imagedevs_pot, "%s/tmp/imagedevs.pot", temppath); 2077 sprintf(g_imagedevs_restthese, "%s/tmp/imagedevs.restore-these", temppath); 2078 if (bkpinfo->disaster_recovery) 2079 2080 2081 2082 } 2083 else 2084 { 2085 sprintf(g_mondo_cfg_file, "%s/%s", temppath, MONDO_CFG_FILE_STUB);2086 sprintf(g_mountlist_fname, "%s/%s", temppath, MOUNTLIST_FNAME_STUB); 2087 2088 } 2012 sprintf(g_imagedevs_restthese, "%s/tmp/imagedevs.restore-these", 2013 temppath); 2014 if (bkpinfo->disaster_recovery) { 2015 sprintf(g_mondo_cfg_file, "/%s", MONDO_CFG_FILE_STUB); 2016 sprintf(g_mountlist_fname, "/%s", MOUNTLIST_FNAME_STUB); 2017 } else { 2018 sprintf(g_mondo_cfg_file, "%s/%s", temppath, MONDO_CFG_FILE_STUB); 2019 sprintf(g_mountlist_fname, "%s/%s", temppath, 2020 MOUNTLIST_FNAME_STUB); 2021 } 2022 } 2023 2089 2024 /************************************************************************** 2090 2025 *END_SET_GLOBAL_FILENAME * … … 2098 2033 * @param input_file The input file, a list of changed files created by a compare. 2099 2034 */ 2100 void 2101 streamline_changes_file(char *output_file, char *input_file) 2102 { 2103 FILE *fin; 2104 FILE *fout; 2035 void streamline_changes_file(char *output_file, char *input_file) 2036 { 2037 FILE *fin; 2038 FILE *fout; 2105 2039 /** malloc **/ 2106 char *incoming; 2107 2108 assert_string_is_neither_NULL_nor_zerolength(output_file); 2109 assert_string_is_neither_NULL_nor_zerolength(input_file); 2110 malloc_string(incoming); 2111 2112 if (!(fin=fopen(input_file,"r"))) 2113 { 2114 log_OS_error(input_file); 2115 return; 2116 } 2117 if (!(fout=fopen(output_file,"w"))) 2118 { 2119 fatal_error("cannot open output_file"); 2120 } 2121 for(fgets(incoming,MAX_STR_LEN-1,fin); !feof(fin); fgets(incoming,MAX_STR_LEN-1,fin)) 2122 { 2123 if(strncmp(incoming,"etc/adjtime",11) \ 2124 && strncmp(incoming,"etc/mtab",8) \ 2125 && strncmp(incoming,"tmp/",4) \ 2126 && strncmp(incoming,"boot/map",8) \ 2127 && !strstr(incoming,"incheckentry") \ 2128 && strncmp(incoming,"etc/mail/statistics",19) \ 2129 && strncmp(incoming,"var/",4)) 2130 fprintf(fout,"%s",incoming); /* don't need \n here, for some reason.. */ 2131 } 2132 paranoid_fclose(fout); 2133 paranoid_fclose(fin); 2134 paranoid_free(incoming); 2135 } 2040 char *incoming; 2041 2042 assert_string_is_neither_NULL_nor_zerolength(output_file); 2043 assert_string_is_neither_NULL_nor_zerolength(input_file); 2044 malloc_string(incoming); 2045 2046 if (!(fin = fopen(input_file, "r"))) { 2047 log_OS_error(input_file); 2048 return; 2049 } 2050 if (!(fout = fopen(output_file, "w"))) { 2051 fatal_error("cannot open output_file"); 2052 } 2053 for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin); 2054 fgets(incoming, MAX_STR_LEN - 1, fin)) { 2055 if (strncmp(incoming, "etc/adjtime", 11) 2056 && strncmp(incoming, "etc/mtab", 8) 2057 && strncmp(incoming, "tmp/", 4) 2058 && strncmp(incoming, "boot/map", 8) 2059 && !strstr(incoming, "incheckentry") 2060 && strncmp(incoming, "etc/mail/statistics", 19) 2061 && strncmp(incoming, "var/", 4)) 2062 fprintf(fout, "%s", incoming); /* don't need \n here, for some reason.. */ 2063 } 2064 paranoid_fclose(fout); 2065 paranoid_fclose(fin); 2066 paranoid_free(incoming); 2067 } 2068 2136 2069 /************************************************************************** 2137 2070 *END_STREAMLINE_CHANGES_FILE * … … 2146 2079 * Prompt the user to support the Mondo project. 2147 2080 */ 2148 void 2149 success_message(void) 2150 { 2151 int i; 2152 /* malloc and ptr */ 2153 char *tmp; 2154 2155 malloc_string(tmp); 2156 if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "restore") == NULL) { 2157 if (ask_me_yes_or_no("Have you contributed to the Mondo project financially or in some other way, yet?")) { 2158 log_to_screen("Thank you for supporting Mondo. It goes from strength to strength,"); 2159 log_to_screen("thanks to the support of users like you."); 2160 } 2161 else { 2162 if (ask_me_yes_or_no("Are you or your company willing to consider contributing to Mondo in some way?")) { 2163 popup_and_OK("To support the project which has just performed a valuable service for you, please visit http://www.mondorescue.com; click on 'Download' and then 'PayPal'."); 2164 } 2165 else { 2166 log_to_screen("Free Software, like freedom itself, must be supported or it will be lost."); 2167 log_msg(1, "To your credit, you were honest: you said no, you wouldn't be contributing"); 2168 log_msg(1, "to this project, ever. However, that makes you a freeloader. I bet you're"); 2169 log_msg(1, "the sort of person who likes to sneak into movie theatres..."); 2170 popup_and_OK("If you ever change your mind, you may support this product by going to http://www.mondrescue.com and clicking on 'Download', followed by 'PalPal'."); 2171 } 2172 } 2173 } 2174 2081 void success_message(void) 2082 { 2083 int i; 2084 /* malloc and ptr */ 2085 char *tmp; 2086 2087 malloc_string(tmp); 2088 if (strstr 2089 (call_program_and_get_last_line_of_output("cat /proc/cmdline"), 2090 "restore") == NULL) { 2091 if (ask_me_yes_or_no 2092 ("Have you contributed to the Mondo project financially or in some other way, yet?")) 2093 { 2094 log_to_screen 2095 ("Thank you for supporting Mondo. It goes from strength to strength,"); 2096 log_to_screen("thanks to the support of users like you."); 2097 } else { 2098 if (ask_me_yes_or_no 2099 ("Are you or your company willing to consider contributing to Mondo in some way?")) 2100 { 2101 popup_and_OK 2102 ("To support the project which has just performed a valuable service for you, please visit http://www.mondorescue.com; click on 'Download' and then 'PayPal'."); 2103 } else { 2104 log_to_screen 2105 ("Free Software, like freedom itself, must be supported or it will be lost."); 2106 log_msg(1, 2107 "To your credit, you were honest: you said no, you wouldn't be contributing"); 2108 log_msg(1, 2109 "to this project, ever. However, that makes you a freeloader. I bet you're"); 2110 log_msg(1, 2111 "the sort of person who likes to sneak into movie theatres..."); 2112 popup_and_OK 2113 ("If you ever change your mind, you may support this product by going to http://www.mondrescue.com and clicking on 'Download', followed by 'PalPal'."); 2114 } 2115 } 2116 } 2175 2117 #ifdef FREELOADER 2176 i = (int)(random())%32;2118 i = (int) (random()) % 32; 2177 2119 #else 2178 i=1;2120 i = 1; 2179 2121 #endif 2180 2122 2181 if (i!=25) 2182 { 2183 strcpy(tmp,"Mondo has restored your system. Please remove the backup media and reboot."); 2184 } 2185 else 2186 { 2187 strcpy(tmp,"M0nd0 h45 r3570r3d j00r 5y573m. P13453 r3m0v3 7h3 b4ckup m3d14 4nd r3b007."); 2188 } 2189 if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "restore") == NULL) { 2190 popup_and_OK(tmp); 2191 } 2192 log_to_screen(tmp); 2193 paranoid_free(tmp); 2194 } 2123 if (i != 25) { 2124 strcpy(tmp, 2125 "Mondo has restored your system. Please remove the backup media and reboot."); 2126 } else { 2127 strcpy(tmp, 2128 "M0nd0 h45 r3570r3d j00r 5y573m. P13453 r3m0v3 7h3 b4ckup m3d14 4nd r3b007."); 2129 } 2130 if (strstr 2131 (call_program_and_get_last_line_of_output("cat /proc/cmdline"), 2132 "restore") == NULL) { 2133 popup_and_OK(tmp); 2134 } 2135 log_to_screen(tmp); 2136 paranoid_free(tmp); 2137 } 2138 2195 2139 /************************************************************************** 2196 2140 *END_SUCCESS_MESSAGE * … … 2203 2147 * @param sig The signal we're exiting due to. 2204 2148 */ 2205 void 2206 terminate_daemon(int sig) 2207 { 2208 log_to_screen("Mondorestore is terminating in response to a signal from the OS"); 2209 paranoid_MR_finish(254); 2210 } 2149 void terminate_daemon(int sig) 2150 { 2151 log_to_screen 2152 ("Mondorestore is terminating in response to a signal from the OS"); 2153 paranoid_MR_finish(254); 2154 } 2155 2211 2156 /************************************************************************** 2212 2157 *END_TERMINATE_DAEMON * … … 2217 2162 * Give the user twenty seconds to press Ctrl-Alt-Del before we nuke their drives. 2218 2163 */ 2219 void 2220 twenty_seconds_til_yikes() 2221 { 2222 int i; 2223 /* MALLOC **/ 2224 char *tmp; 2225 2226 malloc_string(tmp); 2227 if (does_file_exist("/tmp/NOPAUSE")) { return; } 2228 open_progress_form("CAUTION", 2229 "Be advised: I am about to ERASE your hard disk(s)!",2230 "You may press Ctrl+Alt+Del to abort safely.",2231 "",2232 2233 for(i = 0; i < 20; i++) 2234 { 2235 g_current_progress = i;2236 sprintf(tmp,"You have %d seconds left to abort.", 20 - i);2237 update_progress_form( tmp);2238 sleep( 1 ); 2239 } 2240 close_progress_form();2241 paranoid_free(tmp); 2242 } 2164 void twenty_seconds_til_yikes() 2165 { 2166 int i; 2167 /* MALLOC * */ 2168 char *tmp; 2169 2170 malloc_string(tmp); 2171 if (does_file_exist("/tmp/NOPAUSE")) { 2172 return; 2173 } 2174 open_progress_form("CAUTION", 2175 "Be advised: I am about to ERASE your hard disk(s)!", 2176 "You may press Ctrl+Alt+Del to abort safely.", 2177 "", 20); 2178 for (i = 0; i < 20; i++) { 2179 g_current_progress = i; 2180 sprintf(tmp, "You have %d seconds left to abort.", 20 - i); 2181 update_progress_form(tmp); 2182 sleep(1); 2183 } 2184 close_progress_form(); 2185 paranoid_free(tmp); 2186 } 2187 2243 2188 /************************************************************************** 2244 2189 *END_TWENTY_SECONDS_TIL_YIKES * … … 2253 2198 * @param sig The signal we're exiting due to. 2254 2199 */ 2255 void 2256 termination_in_progress(int sig) 2257 { 2258 log_msg(1, "Termination in progress");2259 usleep(1000);2260 pthread_exit(0); 2261 } 2200 void termination_in_progress(int sig) 2201 { 2202 log_msg(1, "Termination in progress"); 2203 usleep(1000); 2204 pthread_exit(0); 2205 } 2206 2262 2207 /************************************************************************** 2263 2208 *END_TERMINATION_IN_PROGRESS * … … 2271 2216 * @return 0 for success, nonzero for failure. 2272 2217 */ 2273 int unmount_all_devices(struct mountlist_itself *p_external_copy_of_mountlist) 2274 { 2275 struct mountlist_itself *mountlist; 2276 int retval=0,lino,res=0,i; 2277 char *command; 2278 char *tmp; 2279 2280 malloc_string(command); 2281 malloc_string(tmp); 2282 assert(p_external_copy_of_mountlist!=NULL); 2283 2284 mountlist = malloc(sizeof(struct mountlist_itself)); 2285 memcpy((void*)mountlist, (void*)p_external_copy_of_mountlist, sizeof(struct mountlist_itself)); 2286 sort_mountlist_by_mountpoint(mountlist, 0); 2287 2288 run_program_and_log_output("df -m", 3); 2289 mvaddstr_and_log_it(g_currentY, 0, "Unmounting devices "); 2290 open_progress_form("Unmounting devices", 2291 "Unmounting all devices that were mounted," , 2292 "in preparation for the post-restoration reboot.", 2293 "", 2294 mountlist->entries); 2295 chdir( "/" ); 2296 for(i = 0; i < 10 && run_program_and_log_output("ps wax | grep buffer | grep -v \"grep buffer\"", TRUE) == 0; i++) 2297 { 2298 sleep( 1 ); 2299 log_msg(2, "Waiting for buffer() to finish"); 2300 } 2301 2302 paranoid_system("sync"); 2303 2304 if (run_program_and_log_output( "cp -f /tmp/mondo-restore.log " MNT_RESTORING "/tmp/", FALSE ) ) 2305 { 2306 log_msg(1, "Error. Failed to copy log to PC's /tmp dir. (Mounted read-only?)"); 2307 } 2308 if (run_program_and_log_output( "cp -f /tmp/mondo-restore.log " MNT_RESTORING "/root/", FALSE ) ) 2309 { 2310 log_msg(1, "Error. Failed to copy log to PC's /root dir. (Mounted read-only?)"); 2311 } 2312 if (does_file_exist("/tmp/DUMBASS-GENTOO")) 2313 { 2314 run_program_and_log_output("mkdir -p " MNT_RESTORING "/mnt/.boot.d", 5); 2315 } 2316 for( lino = mountlist->entries-1; lino >= 0; lino-- ) 2317 { 2318 if (!strcmp(mountlist->el[lino].mountpoint,"lvm")) 2319 { 2320 continue; 2321 } 2322 sprintf(tmp,"Unmounting device %s ",mountlist->el[lino].device); 2323 2324 update_progress_form(tmp); 2325 if (is_this_device_mounted(mountlist->el[lino].device)) 2326 { 2327 if (!strcmp(mountlist->el[lino].mountpoint,"swap")) 2328 { 2329 sprintf(command,"swapoff %s",mountlist->el[lino].device); 2330 } else { 2331 if (!strcmp (mountlist->el[lino].mountpoint, "/1")) 2332 { 2333 sprintf (command, "umount %s/", MNT_RESTORING); 2334 log_msg (3, "Well, I know a certain kitty-kitty who'll be sleeping with Mommy tonight..."); 2335 } 2336 else 2337 { 2338 sprintf(command,"umount " MNT_RESTORING "%s",mountlist->el[lino].mountpoint); 2339 } 2340 } 2341 log_msg(10, "The 'umount' command is '%s'", command); 2342 res = run_program_and_log_output(command, 3); 2343 } 2344 else 2345 { 2346 strcat(tmp,"...not mounted anyway :-) OK"); 2347 res = 0; 2348 } 2349 g_current_progress++; 2350 if (res) 2351 { 2352 strcat(tmp,"...Failed"); 2353 retval++; 2354 log_to_screen(tmp); 2355 } 2356 else 2357 { 2358 log_msg(2, tmp); 2359 } 2360 } 2361 close_progress_form(); 2362 if (retval) 2363 { 2364 mvaddstr_and_log_it(g_currentY++, 74, "Failed." ); 2365 } 2366 else 2367 { 2368 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 2369 } 2370 if (retval) 2371 { 2372 log_to_screen("Unable to unmount some of your partitions."); 2373 } 2374 else 2375 { 2376 log_to_screen("All partitions were unmounted OK."); 2377 } 2378 free(mountlist); 2379 paranoid_free(command); 2380 paranoid_free(tmp); 2381 return(retval); 2382 } 2218 int unmount_all_devices(struct mountlist_itself 2219 *p_external_copy_of_mountlist) 2220 { 2221 struct mountlist_itself *mountlist; 2222 int retval = 0, lino, res = 0, i; 2223 char *command; 2224 char *tmp; 2225 2226 malloc_string(command); 2227 malloc_string(tmp); 2228 assert(p_external_copy_of_mountlist != NULL); 2229 2230 mountlist = malloc(sizeof(struct mountlist_itself)); 2231 memcpy((void *) mountlist, (void *) p_external_copy_of_mountlist, 2232 sizeof(struct mountlist_itself)); 2233 sort_mountlist_by_mountpoint(mountlist, 0); 2234 2235 run_program_and_log_output("df -m", 3); 2236 mvaddstr_and_log_it(g_currentY, 0, "Unmounting devices "); 2237 open_progress_form("Unmounting devices", 2238 "Unmounting all devices that were mounted,", 2239 "in preparation for the post-restoration reboot.", 2240 "", mountlist->entries); 2241 chdir("/"); 2242 for (i = 0; 2243 i < 10 2244 && 2245 run_program_and_log_output 2246 ("ps wax | grep buffer | grep -v \"grep buffer\"", TRUE) == 0; 2247 i++) { 2248 sleep(1); 2249 log_msg(2, "Waiting for buffer() to finish"); 2250 } 2251 2252 paranoid_system("sync"); 2253 2254 if (run_program_and_log_output 2255 ("cp -f /tmp/mondo-restore.log " MNT_RESTORING "/tmp/", FALSE)) { 2256 log_msg(1, 2257 "Error. Failed to copy log to PC's /tmp dir. (Mounted read-only?)"); 2258 } 2259 if (run_program_and_log_output 2260 ("cp -f /tmp/mondo-restore.log " MNT_RESTORING "/root/", FALSE)) { 2261 log_msg(1, 2262 "Error. Failed to copy log to PC's /root dir. (Mounted read-only?)"); 2263 } 2264 if (does_file_exist("/tmp/DUMBASS-GENTOO")) { 2265 run_program_and_log_output("mkdir -p " MNT_RESTORING 2266 "/mnt/.boot.d", 5); 2267 } 2268 for (lino = mountlist->entries - 1; lino >= 0; lino--) { 2269 if (!strcmp(mountlist->el[lino].mountpoint, "lvm")) { 2270 continue; 2271 } 2272 sprintf(tmp, "Unmounting device %s ", mountlist->el[lino].device); 2273 2274 update_progress_form(tmp); 2275 if (is_this_device_mounted(mountlist->el[lino].device)) { 2276 if (!strcmp(mountlist->el[lino].mountpoint, "swap")) { 2277 sprintf(command, "swapoff %s", mountlist->el[lino].device); 2278 } else { 2279 if (!strcmp(mountlist->el[lino].mountpoint, "/1")) { 2280 sprintf(command, "umount %s/", MNT_RESTORING); 2281 log_msg(3, 2282 "Well, I know a certain kitty-kitty who'll be sleeping with Mommy tonight..."); 2283 } else { 2284 sprintf(command, "umount " MNT_RESTORING "%s", 2285 mountlist->el[lino].mountpoint); 2286 } 2287 } 2288 log_msg(10, "The 'umount' command is '%s'", command); 2289 res = run_program_and_log_output(command, 3); 2290 } else { 2291 strcat(tmp, "...not mounted anyway :-) OK"); 2292 res = 0; 2293 } 2294 g_current_progress++; 2295 if (res) { 2296 strcat(tmp, "...Failed"); 2297 retval++; 2298 log_to_screen(tmp); 2299 } else { 2300 log_msg(2, tmp); 2301 } 2302 } 2303 close_progress_form(); 2304 if (retval) { 2305 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 2306 } else { 2307 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 2308 } 2309 if (retval) { 2310 log_to_screen("Unable to unmount some of your partitions."); 2311 } else { 2312 log_to_screen("All partitions were unmounted OK."); 2313 } 2314 free(mountlist); 2315 paranoid_free(command); 2316 paranoid_free(tmp); 2317 return (retval); 2318 } 2319 2383 2320 /************************************************************************** 2384 2321 *END_UNMOUNT_ALL_DEVICES * … … 2393 2330 * @return 0 for success, nonzero for failure. 2394 2331 */ 2395 int extract_cfg_file_and_mountlist_from_tape_dev(char*dev) 2396 { 2397 char *command; 2398 int res=0; 2399 // BCO: below 32KB seems to block at least on RHAS 2.1 and MDK 10.0 2400 long tape_block_size=32768; 2401 2402 malloc_string(command); 2403 2404 // tar -zxvf- 2405 sprintf( command, 2406 "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx %s %s %s %s %s", 2407 dev, 2408 tape_block_size, 2409 1024L*1024*32/tape_block_size, 2410 MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, 2411 BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, 2412 "tmp/i-want-my-lvm" ); 2413 log_msg (2, "command = '%s'", command); 2414 res = run_program_and_log_output( command, -1 ); 2415 if (res!=0 && does_file_exist(MONDO_CFG_FILE_STUB)) { res=0; } 2416 paranoid_free(command); 2417 return(res); 2418 } 2419 2420 2421 2332 int extract_cfg_file_and_mountlist_from_tape_dev(char *dev) 2333 { 2334 char *command; 2335 int res = 0; 2336 // BCO: below 32KB seems to block at least on RHAS 2.1 and MDK 10.0 2337 long tape_block_size = 32768; 2338 2339 malloc_string(command); 2340 2341 // tar -zxvf- 2342 sprintf(command, 2343 "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx %s %s %s %s %s", 2344 dev, 2345 tape_block_size, 2346 1024L * 1024 * 32 / tape_block_size, 2347 MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, 2348 BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, "tmp/i-want-my-lvm"); 2349 log_msg(2, "command = '%s'", command); 2350 res = run_program_and_log_output(command, -1); 2351 if (res != 0 && does_file_exist(MONDO_CFG_FILE_STUB)) { 2352 res = 0; 2353 } 2354 paranoid_free(command); 2355 return (res); 2356 } 2357 2358 2359 2422 2360 /** 2423 2361 * Get the configuration file from the floppy, tape, or CD. … … 2428 2366 * @return 0 for success, nonzero for failure. 2429 2367 */ 2430 int 2431 get_cfg_file_from_archive( struct s_bkpinfo *bkpinfo ) 2432 { 2433 int retval = 0; 2434 2368 int get_cfg_file_from_archive(struct s_bkpinfo *bkpinfo) 2369 { 2370 int retval = 0; 2371 2435 2372 /** malloc *****/ 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 assert(bkpinfo!=NULL);2449 2450 2451 2452 2453 2454 2455 2456 2457 log_msg(2, "gcffa --- starting");2458 2459 sprintf( mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir);2460 2461 chdir( bkpinfo->tmpdir);2462 strcpy(cfg_file, MONDO_CFG_FILE_STUB);2463 unlink( cfg_file );// cfg_file[] is missing the '/' at the start, FYI, by intent2464 unlink( FILELIST_FULL_STUB);2465 unlink( BIGGIELIST_TXT_STUB);2466 unlink("tmp/i-want-my-lvm");2467 sprintf( command, "mkdir -p %s", mountpt);2468 run_program_and_log_output( command, FALSE);2469 2373 char *device; 2374 char *command; 2375 char *cfg_file; 2376 char *mounted_cfgf_path; 2377 char *tmp; 2378 char *mountpt; 2379 char *ramdisk_fname; 2380 char *mountlist_file; 2381 int res; 2382 2383 bool try_plan_B; 2384 2385 assert(bkpinfo != NULL); 2386 malloc_string(cfg_file); 2387 malloc_string(mounted_cfgf_path); 2388 malloc_string(mountpt); 2389 malloc_string(ramdisk_fname); 2390 malloc_string(mountlist_file); 2391 malloc_string(device); 2392 malloc_string(command); 2393 malloc_string(tmp); 2394 log_msg(2, "gcffa --- starting"); 2395 log_to_screen("I'm thinking..."); 2396 sprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir); 2397 device[0] = '\0'; 2398 chdir(bkpinfo->tmpdir); 2399 strcpy(cfg_file, MONDO_CFG_FILE_STUB); 2400 unlink(cfg_file); // cfg_file[] is missing the '/' at the start, FYI, by intent 2401 unlink(FILELIST_FULL_STUB); 2402 unlink(BIGGIELIST_TXT_STUB); 2403 unlink("tmp/i-want-my-lvm"); 2404 sprintf(command, "mkdir -p %s", mountpt); 2405 run_program_and_log_output(command, FALSE); 2406 2470 2407 // unlink( "tmp/mondo-restore.cfg" ); // superfluous, surely? 2471 2472 sprintf( cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB ); 2473 sprintf( mountlist_file, "%s/%s", bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB ); 2474 // make_hole_for_file( cfg_file ); 2475 // make_hole_for_file( mountlist_file); 2476 log_msg (2, "mountpt = %s; cfg_file=%s", mountpt, cfg_file ); 2477 2478 /* Floppy? */ 2479 sprintf( tmp, "mkdir -p %s", mountpt ); 2480 run_program_and_log_output( tmp, FALSE ); 2481 sprintf( tmp, "mkdir -p %s/tmp", bkpinfo->tmpdir); 2482 run_program_and_log_output( tmp, FALSE); 2483 2484 sprintf( command, "mount /dev/fd0u1722 %s", mountpt ); 2485 sprintf( tmp, "(sleep 15; kill `ps ax | grep \"%s\" | cut -d' ' -f1` 2> /dev/null) &", command); 2486 log_msg(1, "tmp = '%s'", tmp); 2487 system(tmp); 2488 res = run_program_and_log_output( command, FALSE ); 2489 if (res) { 2490 sprintf( command, "mount /dev/fd0H1440 %s", mountpt ); 2491 res = run_program_and_log_output( command, FALSE ); 2492 } 2493 if (res) { 2494 try_plan_B=TRUE; 2495 } else { 2496 try_plan_B=TRUE; 2497 log_msg(2, "Mounted floppy OK but I don't trust it because the archives might contain more up-to-date config file than the floppy does."); 2408 2409 sprintf(cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB); 2410 sprintf(mountlist_file, "%s/%s", bkpinfo->tmpdir, 2411 MOUNTLIST_FNAME_STUB); 2412 // make_hole_for_file( cfg_file ); 2413 // make_hole_for_file( mountlist_file); 2414 log_msg(2, "mountpt = %s; cfg_file=%s", mountpt, cfg_file); 2415 2416 /* Floppy? */ 2417 sprintf(tmp, "mkdir -p %s", mountpt); 2418 run_program_and_log_output(tmp, FALSE); 2419 sprintf(tmp, "mkdir -p %s/tmp", bkpinfo->tmpdir); 2420 run_program_and_log_output(tmp, FALSE); 2421 2422 sprintf(command, "mount /dev/fd0u1722 %s", mountpt); 2423 sprintf(tmp, 2424 "(sleep 15; kill `ps ax | grep \"%s\" | cut -d' ' -f1` 2> /dev/null) &", 2425 command); 2426 log_msg(1, "tmp = '%s'", tmp); 2427 system(tmp); 2428 res = run_program_and_log_output(command, FALSE); 2429 if (res) { 2430 sprintf(command, "mount /dev/fd0H1440 %s", mountpt); 2431 res = run_program_and_log_output(command, FALSE); 2432 } 2433 if (res) { 2434 try_plan_B = TRUE; 2435 } else { 2436 try_plan_B = TRUE; 2437 log_msg(2, 2438 "Mounted floppy OK but I don't trust it because the archives might contain more up-to-date config file than the floppy does."); 2498 2439 // NB: If busybox does not support 'mount -o loop' then Plan A WILL NOT WORK. 2499 log_msg(2, "Processing floppy (plan A?)" ); 2500 sprintf( ramdisk_fname, "%s/mindi.rdz", mountpt ); 2501 if ( !does_file_exist( ramdisk_fname ) ) 2502 { 2503 sprintf( ramdisk_fname, "%s/initrd.img", mountpt ); 2504 } 2505 if ( !does_file_exist( ramdisk_fname ) ) 2506 { 2507 log_msg(2, "Cannot find ramdisk file on mountpoint. Are you sure that's a boot disk in the drive?" ); 2508 } 2509 if ( extract_config_file_from_ramdisk( bkpinfo, ramdisk_fname, cfg_file, mountlist_file ) ) 2510 { 2511 log_msg(2, "Warning - failed to extract config file from ramdisk. I think this boot disk is mangled." ); 2512 } 2513 sprintf( command, "umount %s", mountpt ); 2514 run_program_and_log_output(command, 5); 2515 unlink(ramdisk_fname); 2516 } 2517 if ( !does_file_exist( cfg_file ) ) 2518 { 2519 log_msg(2, "gcffa --- we don't have cfg file yet." ); 2520 if ( IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type) ) 2521 { 2522 try_plan_B = TRUE; 2523 } 2524 else 2525 { 2526 log_msg(2, "gcffa --- calling mount_cdrom now :)" ); 2527 if ( !mount_cdrom( bkpinfo ) ) 2528 { 2529 log_msg(2, "gcffa --- managed to mount CD; so, no need for Plan B" ); 2530 try_plan_B = FALSE; 2531 } 2532 else 2533 { 2534 try_plan_B = TRUE; 2535 } 2536 if ( what_number_cd_is_this(bkpinfo) > 1 ) 2537 { 2538 insist_on_this_cd_number( bkpinfo, ( g_current_media_number = 1 ) ); 2539 } 2540 } 2541 if ( try_plan_B ) 2542 { 2543 log_msg(2, "gcffa --- OK, switching to Plan B" ); 2544 chdir( bkpinfo->tmpdir ); 2545 run_program_and_log_output ( "mkdir -p tmp", FALSE ); 2546 2547 if (strlen(bkpinfo->media_device) ==0 ) 2548 { 2549 strcpy(bkpinfo->media_device, "/dev/st0"); 2550 log_msg(2,"media_device is blank; assuming %s"); 2551 } 2552 strcpy(tmp, bkpinfo->media_device); 2553 if (extract_cfg_file_and_mountlist_from_tape_dev(bkpinfo->media_device)) 2554 { 2555 strcpy(bkpinfo->media_device, "/dev/st0"); 2556 if (extract_cfg_file_and_mountlist_from_tape_dev(bkpinfo->media_device)) 2557 { 2558 strcpy(bkpinfo->media_device, "/dev/osst0"); 2559 if (extract_cfg_file_and_mountlist_from_tape_dev(bkpinfo->media_device)) 2560 { 2561 strcpy(bkpinfo->media_device, "/dev/ht0"); 2562 if (extract_cfg_file_and_mountlist_from_tape_dev(bkpinfo->media_device)) 2563 { 2564 log_msg(3, "I tried lots of devices but none worked."); 2565 strcpy(bkpinfo->media_device, tmp); 2566 } 2567 } 2568 } 2569 } 2570 2571 if ( !does_file_exist( "tmp/mondo-restore.cfg") ) 2572 { 2573 log_to_screen ( "Cannot find config info on tape/CD/floppy"); 2574 return(1); 2575 } 2576 } 2577 else 2578 { 2579 log_msg(2, "gcffa --- looking at mounted CD for mindi-boot.2880.img" ); 2580 sprintf( command, "mount "MNT_CDROM"/images/mindi-boot.2880.img -o loop %s", mountpt ); 2581 sprintf( mounted_cfgf_path, "%s/%s", mountpt, cfg_file ); 2582 if (!does_file_exist(mounted_cfgf_path)) 2583 { 2584 log_msg(2,"gcffa --- Plan C, a.k.a. untarring some file from all.tar.gz" ); 2585 sprintf( command, 2586 "tar -zxvf "MNT_CDROM"/images/all.tar.gz %s %s %s %s %s", 2587 MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, "tmp/i-want-my-lvm" 2588 ); // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary 2589 run_program_and_log_output( command, TRUE ); 2590 if ( !does_file_exist( MONDO_CFG_FILE_STUB ) ) 2591 { 2592 fatal_error( "Please reinsert the disk/CD and try again." ); 2593 } 2594 } 2595 } 2596 } 2597 if ( does_file_exist( MONDO_CFG_FILE_STUB) ) 2598 { 2599 log_msg(1, "gcffa --- great! We've got the config file" ); 2600 sprintf(tmp, "%s/%s", call_program_and_get_last_line_of_output("pwd"), MONDO_CFG_FILE_STUB); 2601 sprintf( command, "cp -f %s %s", tmp, cfg_file); 2602 iamhere(command); 2603 if (strcmp(tmp, cfg_file) && run_program_and_log_output( command, 1 )) 2604 { log_msg(1,"... but an error occurred when I tried to move it to %s", cfg_file); } 2605 else 2606 { log_msg(1,"... and I moved it successfully to %s", cfg_file); } 2607 sprintf(command, "cp -f %s/%s %s", call_program_and_get_last_line_of_output("pwd"), MOUNTLIST_FNAME_STUB, mountlist_file); 2608 iamhere(command); 2609 if (strcmp(tmp, cfg_file) && run_program_and_log_output( command, 1 )) 2610 { log_msg(1,"Failed to get mountlist"); } 2611 else 2612 { 2613 log_msg(1,"Got mountlist too"); 2614 sprintf(command, "cp -f %s %s", mountlist_file, g_mountlist_fname); 2615 if (run_program_and_log_output(command, 1)) 2616 { log_msg(1, "Failed to copy mountlist to /tmp"); } 2617 else 2618 { 2619 log_msg(1, "Copied mountlist to /tmp as well OK"); 2620 sprintf(command, "cp -f tmp/i-want-my-lvm /tmp/"); 2621 run_program_and_log_output(command, 1); 2440 log_msg(2, "Processing floppy (plan A?)"); 2441 sprintf(ramdisk_fname, "%s/mindi.rdz", mountpt); 2442 if (!does_file_exist(ramdisk_fname)) { 2443 sprintf(ramdisk_fname, "%s/initrd.img", mountpt); 2444 } 2445 if (!does_file_exist(ramdisk_fname)) { 2446 log_msg(2, 2447 "Cannot find ramdisk file on mountpoint. Are you sure that's a boot disk in the drive?"); 2448 } 2449 if (extract_config_file_from_ramdisk 2450 (bkpinfo, ramdisk_fname, cfg_file, mountlist_file)) { 2451 log_msg(2, 2452 "Warning - failed to extract config file from ramdisk. I think this boot disk is mangled."); 2453 } 2454 sprintf(command, "umount %s", mountpt); 2455 run_program_and_log_output(command, 5); 2456 unlink(ramdisk_fname); 2457 } 2458 if (!does_file_exist(cfg_file)) { 2459 log_msg(2, "gcffa --- we don't have cfg file yet."); 2460 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 2461 try_plan_B = TRUE; 2462 } else { 2463 log_msg(2, "gcffa --- calling mount_cdrom now :)"); 2464 if (!mount_cdrom(bkpinfo)) { 2465 log_msg(2, 2466 "gcffa --- managed to mount CD; so, no need for Plan B"); 2467 try_plan_B = FALSE; 2468 } else { 2469 try_plan_B = TRUE; 2470 } 2471 if (what_number_cd_is_this(bkpinfo) > 1) { 2472 insist_on_this_cd_number(bkpinfo, 2473 (g_current_media_number = 1)); 2474 } 2475 } 2476 if (try_plan_B) { 2477 log_msg(2, "gcffa --- OK, switching to Plan B"); 2478 chdir(bkpinfo->tmpdir); 2479 run_program_and_log_output("mkdir -p tmp", FALSE); 2480 2481 if (strlen(bkpinfo->media_device) == 0) { 2482 strcpy(bkpinfo->media_device, "/dev/st0"); 2483 log_msg(2, "media_device is blank; assuming %s"); 2484 } 2485 strcpy(tmp, bkpinfo->media_device); 2486 if (extract_cfg_file_and_mountlist_from_tape_dev 2487 (bkpinfo->media_device)) { 2488 strcpy(bkpinfo->media_device, "/dev/st0"); 2489 if (extract_cfg_file_and_mountlist_from_tape_dev 2490 (bkpinfo->media_device)) { 2491 strcpy(bkpinfo->media_device, "/dev/osst0"); 2492 if (extract_cfg_file_and_mountlist_from_tape_dev 2493 (bkpinfo->media_device)) { 2494 strcpy(bkpinfo->media_device, "/dev/ht0"); 2495 if (extract_cfg_file_and_mountlist_from_tape_dev 2496 (bkpinfo->media_device)) { 2497 log_msg(3, 2498 "I tried lots of devices but none worked."); 2499 strcpy(bkpinfo->media_device, tmp); 2500 } 2501 } 2502 } 2503 } 2504 2505 if (!does_file_exist("tmp/mondo-restore.cfg")) { 2506 log_to_screen("Cannot find config info on tape/CD/floppy"); 2507 return (1); 2508 } 2509 } else { 2510 log_msg(2, 2511 "gcffa --- looking at mounted CD for mindi-boot.2880.img"); 2512 sprintf(command, 2513 "mount " MNT_CDROM 2514 "/images/mindi-boot.2880.img -o loop %s", mountpt); 2515 sprintf(mounted_cfgf_path, "%s/%s", mountpt, cfg_file); 2516 if (!does_file_exist(mounted_cfgf_path)) { 2517 log_msg(2, 2518 "gcffa --- Plan C, a.k.a. untarring some file from all.tar.gz"); 2519 sprintf(command, "tar -zxvf " MNT_CDROM "/images/all.tar.gz %s %s %s %s %s", MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, "tmp/i-want-my-lvm"); // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary 2520 run_program_and_log_output(command, TRUE); 2521 if (!does_file_exist(MONDO_CFG_FILE_STUB)) { 2522 fatal_error 2523 ("Please reinsert the disk/CD and try again."); 2524 } 2525 } 2526 } 2527 } 2528 if (does_file_exist(MONDO_CFG_FILE_STUB)) { 2529 log_msg(1, "gcffa --- great! We've got the config file"); 2530 sprintf(tmp, "%s/%s", 2531 call_program_and_get_last_line_of_output("pwd"), 2532 MONDO_CFG_FILE_STUB); 2533 sprintf(command, "cp -f %s %s", tmp, cfg_file); 2534 iamhere(command); 2535 if (strcmp(tmp, cfg_file) 2536 && run_program_and_log_output(command, 1)) { 2537 log_msg(1, 2538 "... but an error occurred when I tried to move it to %s", 2539 cfg_file); 2540 } else { 2541 log_msg(1, "... and I moved it successfully to %s", cfg_file); 2542 } 2543 sprintf(command, "cp -f %s/%s %s", 2544 call_program_and_get_last_line_of_output("pwd"), 2545 MOUNTLIST_FNAME_STUB, mountlist_file); 2546 iamhere(command); 2547 if (strcmp(tmp, cfg_file) 2548 && run_program_and_log_output(command, 1)) { 2549 log_msg(1, "Failed to get mountlist"); 2550 } else { 2551 log_msg(1, "Got mountlist too"); 2552 sprintf(command, "cp -f %s %s", mountlist_file, 2553 g_mountlist_fname); 2554 if (run_program_and_log_output(command, 1)) { 2555 log_msg(1, "Failed to copy mountlist to /tmp"); 2556 } else { 2557 log_msg(1, "Copied mountlist to /tmp as well OK"); 2558 sprintf(command, "cp -f tmp/i-want-my-lvm /tmp/"); 2559 run_program_and_log_output(command, 1); 2622 2560 /* sprintf(command, "grep \" lvm \" %s", g_mountlist_fname); 2623 2561 if (!run_program_and_log_output(command, 5) && !does_file_exist("/tmp/i-want-my-lvm")) … … 2639 2577 } 2640 2578 */ 2641 } 2642 } 2643 } 2644 run_program_and_log_output( "umount "MNT_CDROM, FALSE ); 2645 if ( !does_file_exist( cfg_file ) ) 2646 { 2647 iamhere(cfg_file); 2648 log_msg(1, "%s not found", cfg_file); 2649 log_to_screen("Oh dear. Unable to recover configuration file from boot disk"); 2650 return(1); 2651 } 2652 2653 log_to_screen( "Recovered mondo-restore.cfg" ); 2654 if (!does_file_exist( MOUNTLIST_FNAME_STUB )) 2655 { log_to_screen( "...but not mountlist.txt - a pity, really..."); } 2579 } 2580 } 2581 } 2582 run_program_and_log_output("umount " MNT_CDROM, FALSE); 2583 if (!does_file_exist(cfg_file)) { 2584 iamhere(cfg_file); 2585 log_msg(1, "%s not found", cfg_file); 2586 log_to_screen 2587 ("Oh dear. Unable to recover configuration file from boot disk"); 2588 return (1); 2589 } 2590 2591 log_to_screen("Recovered mondo-restore.cfg"); 2592 if (!does_file_exist(MOUNTLIST_FNAME_STUB)) { 2593 log_to_screen("...but not mountlist.txt - a pity, really..."); 2594 } 2656 2595 /* start SAH */ 2657 else 2658 { 2659 sprintf(command, "cp -f %s %s/%s", MOUNTLIST_FNAME_STUB,bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB);2660 run_program_and_log_output(command,FALSE);2661 2596 else { 2597 sprintf(command, "cp -f %s %s/%s", MOUNTLIST_FNAME_STUB, 2598 bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB); 2599 run_program_and_log_output(command, FALSE); 2600 } 2662 2601 /*--commented out by SAH 2663 2602 sprintf( command, "cp -f %s %s/%s", cfg_file, bkpinfo->tmpdir, MONDO_CFG_FILE_STUB ); … … 2668 2607 /* end SAH */ 2669 2608 2670 sprintf( command, "cp -f %s /%s", cfg_file, MONDO_CFG_FILE_STUB);2671 run_program_and_log_output( command, FALSE);2672 sprintf( command, "cp -f %s /%s", mountlist_file, MOUNTLIST_FNAME_STUB);2673 run_program_and_log_output( command, FALSE);2674 sprintf(command, "cp -f etc/raidtab /etc/");2675 run_program_and_log_output( command, FALSE);2676 sprintf(command, "cp -f tmp/i-want-my-lvm /tmp/");2677 run_program_and_log_output( command, FALSE);2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 return( retval);2609 sprintf(command, "cp -f %s /%s", cfg_file, MONDO_CFG_FILE_STUB); 2610 run_program_and_log_output(command, FALSE); 2611 sprintf(command, "cp -f %s /%s", mountlist_file, MOUNTLIST_FNAME_STUB); 2612 run_program_and_log_output(command, FALSE); 2613 sprintf(command, "cp -f etc/raidtab /etc/"); 2614 run_program_and_log_output(command, FALSE); 2615 sprintf(command, "cp -f tmp/i-want-my-lvm /tmp/"); 2616 run_program_and_log_output(command, FALSE); 2617 g_backup_media_type = bkpinfo->backup_media_type; 2618 paranoid_free(device); 2619 paranoid_free(command); 2620 paranoid_free(tmp); 2621 paranoid_free(cfg_file); 2622 paranoid_free(mounted_cfgf_path); 2623 paranoid_free(mountpt); 2624 paranoid_free(ramdisk_fname); 2625 paranoid_free(mountlist_file); 2626 return (retval); 2688 2627 } 2689 2628 … … 2706 2645 ***************************************************************************/ 2707 2646 2708 2709 2710 void wait_until_software_raids_are_prepped(char *mdstat_file, int wait_for_percentage)2711 { 2712 struct s_mdstat *mdstat; 2713 int unfinished_mdstat_devices=9999, i;2714 char *screen_message;2715 2716 malloc_string(screen_message); 2717 mdstat = malloc(sizeof(struct s_mdstat));2718 2719 assert(wait_for_percentage <= 100); 2720 iamhere("Help, my boat is sync'ing. (Get it? Urp! Urp!)");2721 while(unfinished_mdstat_devices > 0) 2722 2723 if (read_mdstat(mdstat, mdstat_file)) 2724 { log_to_screen("Sorry, cannot read %s", mdstat_file); return; } 2725 for(unfinished_mdstat_devices=i=0; i<mdstat->entries; i++) 2726 { 2727 if (mdstat->el[i].progress < wait_for_percentage) 2728 2729 2730 sprintf(screen_message, "Sync'ing /dev/md%d", mdstat->el[i].md);2731 open_evalcall_form(screen_message);2732 if (mdstat->el[i].progress == -1) // delayed while another partition inits2733 {2734 continue;2735 }2736 while(mdstat->el[i].progress < wait_for_percentage)2737 2738 2739 2740 if (read_mdstat(mdstat, mdstat_file)) {break;}2741 }2742 close_evalcall_form();2743 2744 } 2745 2746 paranoid_free(screen_message); 2747 paranoid_free(mdstat); 2748 } 2749 2750 2647 2648 2649 void wait_until_software_raids_are_prepped(char *mdstat_file, 2650 int wait_for_percentage) 2651 { 2652 struct s_mdstat *mdstat; 2653 int unfinished_mdstat_devices = 9999, i; 2654 char *screen_message; 2655 2656 malloc_string(screen_message); 2657 mdstat = malloc(sizeof(struct s_mdstat)); 2658 2659 assert(wait_for_percentage <= 100); 2660 iamhere("Help, my boat is sync'ing. (Get it? Urp! Urp!)"); 2661 while (unfinished_mdstat_devices > 0) { 2662 if (read_mdstat(mdstat, mdstat_file)) { 2663 log_to_screen("Sorry, cannot read %s", mdstat_file); 2664 return; 2665 } 2666 for (unfinished_mdstat_devices = i = 0; i < mdstat->entries; i++) { 2667 if (mdstat->el[i].progress < wait_for_percentage) { 2668 unfinished_mdstat_devices++; 2669 sprintf(screen_message, "Sync'ing /dev/md%d", 2670 mdstat->el[i].md); 2671 open_evalcall_form(screen_message); 2672 if (mdstat->el[i].progress == -1) // delayed while another partition inits 2673 { 2674 continue; 2675 } 2676 while (mdstat->el[i].progress < wait_for_percentage) { 2677 update_evalcall_form(mdstat->el[i].progress); 2678 sleep(2); 2679 if (read_mdstat(mdstat, mdstat_file)) { 2680 break; 2681 } 2682 } 2683 close_evalcall_form(); 2684 } 2685 } 2686 } 2687 paranoid_free(screen_message); 2688 paranoid_free(mdstat); 2689 } -
trunk/mondo/mondo/mondorestore/mondo-rstr-tools.h
r30 r59 4 4 5 5 void free_global_filenames(); 6 void get_cfg_file_from_archive_or_bust(struct s_bkpinfo *);7 bool is_file_in_list(char *, char*, char*);/* needle, haystack, preamble */6 void get_cfg_file_from_archive_or_bust(struct s_bkpinfo *); 7 bool is_file_in_list(char *, char *, char *); /* needle, haystack, preamble */ 8 8 int iso_fiddly_bits(struct s_bkpinfo *bkpinfo, bool nuke_me_please); 9 9 void kill_petris(void); 10 int modify_rclocal_one_time( char *path);10 int modify_rclocal_one_time(char *path); 11 11 int mount_cdrom(struct s_bkpinfo *bkpinfo); 12 int mount_device(char *,char*,char*,bool);13 int mount_all_devices(struct mountlist_itself *, bool);12 int mount_device(char *, char *, char *, bool); 13 int mount_all_devices(struct mountlist_itself *, bool); 14 14 void protect_against_braindead_sysadmins(void); 15 int read_cfg_file_into_bkpinfo( char*cfg_file, struct s_bkpinfo *bkpinfo);15 int read_cfg_file_into_bkpinfo(char *cfg_file, struct s_bkpinfo *bkpinfo); 16 16 struct s_node *process_filelist_and_biggielist(struct s_bkpinfo *); 17 int backup_crucial_file(char *path_root, char *filename);17 int backup_crucial_file(char *path_root, char *filename); 18 18 19 19 int run_boot_loader(bool); 20 int run_grub(bool, char *);20 int run_grub(bool, char *); 21 21 int run_lilo(bool); 22 22 int run_elilo(bool); 23 23 int run_raw_mbr(bool offer_to_hack_scripts, char *bd); 24 24 char *find_my_editor(void); 25 void streamline_changes_file(char *,char*);26 void set_signals( int on);25 void streamline_changes_file(char *, char *); 26 void set_signals(int on); 27 27 void setup_global_filenames(struct s_bkpinfo *bkpinfo); 28 28 //void setup_signals(int); 29 29 void success_message(void); 30 30 void twenty_seconds_til_yikes(void); 31 int run_raw_mbr(bool offer_to_hack_scripts, char *bd);31 int run_raw_mbr(bool offer_to_hack_scripts, char *bd); 32 32 void terminate_daemon(int); 33 33 void termination_in_progress(int); 34 int unmount_all_devices(struct mountlist_itself *);34 int unmount_all_devices(struct mountlist_itself *); 35 35 int get_cfg_file_from_archive(struct s_bkpinfo *bkpinfo); 36 void ask_about_these_imagedevs( char *infname, char *outfname ); 37 36 void ask_about_these_imagedevs(char *infname, char *outfname); -
trunk/mondo/mondo/mondorestore/mondoprep.h
r30 r59 5 5 copyright : (C) 2002 by Stan Benoit 6 6 email : troff@nakedsoul.org 7 cvsid : $Id : mondoprep.h,v 1.4 2004/06/16 10:38:29 hugo Exp$7 cvsid : $Id$ 8 8 ***************************************************************************/ 9 9 … … 23 23 extern int g_currentY, g_current_cd_number; 24 24 extern char *g_tape_device; 25 extern void finish 26 extern void setup_newt_stuff 27 extern char which_restore_mode 28 extern bool ask_me_yes_or_no 29 extern long get_phys_size_of_drive 25 extern void finish(int); 26 extern void setup_newt_stuff(void); 27 extern char which_restore_mode(void); 28 extern bool ask_me_yes_or_no(char *); 29 extern long get_phys_size_of_drive(char *); 30 30 //extern void log_to_screen (char *); 31 extern void update_progress_form 32 extern void open_progress_form 33 extern void close_progress_form 34 extern void popup_and_OK 35 extern bool popup_and_get_string 36 extern long get_time 37 extern bool is_this_device_mounted 38 extern int does_partition_exist 39 extern int strcmp_inc_numbers 40 extern long count_lines_in_file 41 extern long long length_of_file 42 extern long noof_lines_that_match_wildcard 31 extern void update_progress_form(char *); 32 extern void open_progress_form(char *, char *, char *, char *, long); 33 extern void close_progress_form(void); 34 extern void popup_and_OK(char *); 35 extern bool popup_and_get_string(char *, char *, char *, int); 36 extern long get_time(void); 37 extern bool is_this_device_mounted(char *); 38 extern int does_partition_exist(const char *device, int partno); 39 extern int strcmp_inc_numbers(char *, char *); 40 extern long count_lines_in_file(char *); 41 extern long long length_of_file(char *); 42 extern long noof_lines_that_match_wildcard(char *, char *); 43 43 //extern char *slice_fname (long, long, bool, char *); 44 extern char *last_line_of_file 45 extern void log_file_end_to_screen 46 extern int zero_out_a_device 47 extern void mvaddstr_and_log_it 48 extern bool does_file_exist 44 extern char *last_line_of_file(char *); 45 extern void log_file_end_to_screen(char *, char *); 46 extern int zero_out_a_device(char *); 47 extern void mvaddstr_and_log_it(int, int, char *); 48 extern bool does_file_exist(char *); 49 49 50 50 51 51 /** locals **********************************************************/ 52 int extrapolate_mountlist_to_include_raid_partitions (struct mountlist_itself 53 *, 54 struct mountlist_itself 55 *); 56 bool mountlist_contains_raid_devices (struct mountlist_itself *); 57 int start_raid_device (char *); 58 int stop_raid_device (char *); 59 int start_all_raid_devices (struct mountlist_itself *); 60 int stop_all_raid_devices (struct mountlist_itself *); 61 int format_everything (struct mountlist_itself *, bool); 62 int partition_device (FILE*,const char *, int, int, const char *, long long); 63 int partition_device_with_parted (FILE*,const char *, int, int, const char *, long long); 64 int partition_device_with_fdisk (FILE*,const char *, int, int, const char *, long long); 65 int format_device (char *, char *); 66 int partition_drive (struct mountlist_itself *, char *); 67 int partition_everything (struct mountlist_itself *); 68 int do_my_funky_lvm_stuff (bool, bool); 69 int which_format_command_do_i_need (char *, char *); 70 int make_dummy_partitions (FILE*, char *, int); 71 int make_list_of_drives (struct mountlist_itself *, 72 char drivelist[ARBITRARY_MAXIMUM][MAX_STR_LEN]); 73 int set_partition_type (FILE*,const char *, int, const char *, long long); 74 void resize_drive_proportionately_to_suit_new_drives (struct mountlist_itself 75 *mountlist, 76 char *drive_name); 77 void resize_mountlist_proportionately_to_suit_new_drives (struct 78 mountlist_itself 79 *mountlist); 52 int extrapolate_mountlist_to_include_raid_partitions(struct mountlist_itself 53 *, struct mountlist_itself 54 *); 55 bool mountlist_contains_raid_devices(struct mountlist_itself *); 56 int start_raid_device(char *); 57 int stop_raid_device(char *); 58 int start_all_raid_devices(struct mountlist_itself *); 59 int stop_all_raid_devices(struct mountlist_itself *); 60 int format_everything(struct mountlist_itself *, bool); 61 int partition_device(FILE *, const char *, int, int, const char *, 62 long long); 63 int partition_device_with_parted(FILE *, const char *, int, int, 64 const char *, long long); 65 int partition_device_with_fdisk(FILE *, const char *, int, int, 66 const char *, long long); 67 int format_device(char *, char *); 68 int partition_drive(struct mountlist_itself *, char *); 69 int partition_everything(struct mountlist_itself *); 70 int do_my_funky_lvm_stuff(bool, bool); 71 int which_format_command_do_i_need(char *, char *); 72 int make_dummy_partitions(FILE *, char *, int); 73 int make_list_of_drives(struct mountlist_itself *, 74 char drivelist[ARBITRARY_MAXIMUM][MAX_STR_LEN]); 75 int set_partition_type(FILE *, const char *, int, const char *, long long); 76 void resize_drive_proportionately_to_suit_new_drives(struct mountlist_itself 77 *mountlist, 78 char *drive_name); 79 void resize_mountlist_proportionately_to_suit_new_drives(struct 80 mountlist_itself 81 *mountlist); 80 82 81 83 82 char * 83 truncate_to_drive_name (char *partition); 84 void create_mountlist_for_drive(struct mountlist_itself *mountlist, char *drive_name, struct mountlist_reference *drivemntlist); 85 84 char *truncate_to_drive_name(char *partition); 85 void create_mountlist_for_drive(struct mountlist_itself *mountlist, 86 char *drive_name, 87 struct mountlist_reference *drivemntlist); -
trunk/mondo/mondo/mondorestore/mr-externs.h
r30 r59 1 1 /* 2 * $Id : mr-externs.h,v 1.3 2004/06/10 15:29:13 hugo Exp$2 * $Id$ 3 3 * 4 4 * mondo-restore.c's externs … … 6 6 */ 7 7 8 #define SIZE 730000 * 1024 8 #define SIZE 730000 * 1024 /* Size for ISO's stops -1 */ 9 9 #define BIGGIELIST MNT_CDROM"/archives/biggielist.txt" 10 10 #define ARCHIVES_PATH MNT_CDROM"/archives" … … 14 14 #endif 15 15 16 extern bool ask_me_yes_or_no(char *);17 extern char * calc_checksum_of_file(char*);18 extern int closein_tape(struct s_bkpinfo *);16 extern bool ask_me_yes_or_no(char *); 17 extern char *calc_checksum_of_file(char *); 18 extern int closein_tape(struct s_bkpinfo *); 19 19 extern void close_evalcall_form(void); 20 extern char *call_program_and_get_last_line_of_output(char *);20 extern char *call_program_and_get_last_line_of_output(char *); 21 21 extern void close_progress_form(void); 22 extern long count_lines_in_file(char *);23 extern bool does_file_exist(char *);24 extern int does_partition_exist(const char *device, int partno);22 extern long count_lines_in_file(char *); 23 extern bool does_file_exist(char *); 24 extern int does_partition_exist(const char *device, int partno); 25 25 extern int do_my_funky_lvm_stuff(bool, bool); 26 26 extern int edit_filelist(struct s_node *); 27 extern int edit_mountlist(char* mountlist_fname, struct mountlist_itself*, struct raidlist_itself*); 28 extern int format_everything(struct mountlist_itself*, bool); 29 extern int format_device(char*,char*); 27 extern int edit_mountlist(char *mountlist_fname, struct mountlist_itself *, 28 struct raidlist_itself *); 29 extern int format_everything(struct mountlist_itself *, bool); 30 extern int format_device(char *, char *); 30 31 extern void finish(int); 31 extern void free_filelist(struct s_node *);32 extern void free_filelist(struct s_node *); 32 33 extern long get_time(void); 33 extern bool get_isodir_info(char *,char*,char*,bool);34 extern void fatal_error(char *);35 extern void initialize_raid_record(struct raid_device_record *);36 extern bool is_this_device_mounted(char *);37 extern long long length_of_file(char *);38 extern char *last_line_of_file(char *);39 extern struct s_node *load_filelist(char *);34 extern bool get_isodir_info(char *, char *, char *, bool); 35 extern void fatal_error(char *); 36 extern void initialize_raid_record(struct raid_device_record *); 37 extern bool is_this_device_mounted(char *); 38 extern long long length_of_file(char *); 39 extern char *last_line_of_file(char *); 40 extern struct s_node *load_filelist(char *); 40 41 extern void log_tape_pos(void); 41 extern void initialize_raidrec(struct raid_device_record *);42 extern void log_file_end_to_screen(char *,char*);43 extern void log_to_screen 42 extern void initialize_raidrec(struct raid_device_record *); 43 extern void log_file_end_to_screen(char *, char *); 44 extern void log_to_screen(const char *fmt, ...); 44 45 extern void mvaddstr_and_log_it(int, int, char *); 45 extern int make_dummy_partitions(char*,int); 46 extern int make_hole_for_file(char*); 47 extern int make_list_of_drives(struct mountlist_itself*, struct list_of_disks*); 48 extern bool mountlist_contains_raid_devices(struct mountlist_itself*); 49 extern void open_evalcall_form(char*); 50 extern void open_progress_form(char*,char*,char*,char*,long); 46 extern int make_dummy_partitions(char *, int); 47 extern int make_hole_for_file(char *); 48 extern int make_list_of_drives(struct mountlist_itself *, 49 struct list_of_disks *); 50 extern bool mountlist_contains_raid_devices(struct mountlist_itself *); 51 extern void open_evalcall_form(char *); 52 extern void open_progress_form(char *, char *, char *, char *, long); 51 53 extern int openin_cdstream(struct s_bkpinfo *); 52 54 extern int openin_tape(struct s_bkpinfo *); 53 extern int partition_device(char *,int,int,char*,long);54 extern int partition_device_with_fdisk(char *,int,int,char*,long);55 extern int partition_device_with_parted(char *,int,int,char*,long);56 extern int partition_drive(struct mountlist_itself *, char*);57 extern int partition_everything(struct mountlist_itself *);58 extern void popup_and_OK(char *);59 extern bool popup_and_get_string(char *,char*,char*, int);55 extern int partition_device(char *, int, int, char *, long); 56 extern int partition_device_with_fdisk(char *, int, int, char *, long); 57 extern int partition_device_with_parted(char *, int, int, char *, long); 58 extern int partition_drive(struct mountlist_itself *, char *); 59 extern int partition_everything(struct mountlist_itself *); 60 extern void popup_and_OK(char *); 61 extern bool popup_and_get_string(char *, char *, char *, int); 60 62 extern void setup_newt_stuff(void); 61 extern void reset_bkpinfo(struct s_bkpinfo*); 62 extern int read_cfg_var(char*, char*, char*); 63 extern int read_file_from_stream_to_file(struct s_bkpinfo*, char*, long long); 64 extern int read_file_from_stream_to_stream(struct s_bkpinfo*, FILE*, long long); 65 extern int read_file_from_stream_FULL(struct s_bkpinfo*, char*, FILE*, long long); 66 extern int read_header_block_from_stream(long long *, char*, int *); 67 extern void save_filelist(struct s_node*, char*); 68 extern void strip_spaces(char*); 69 extern int strcmp_inc_numbers(char*,char*); 70 extern char *slice_fname(long,long,char*,char*); 71 extern int stop_raid_device(char*); 72 extern int stop_all_raid_devices(struct mountlist_itself*); 63 extern void reset_bkpinfo(struct s_bkpinfo *); 64 extern int read_cfg_var(char *, char *, char *); 65 extern int read_file_from_stream_to_file(struct s_bkpinfo *, char *, 66 long long); 67 extern int read_file_from_stream_to_stream(struct s_bkpinfo *, FILE *, 68 long long); 69 extern int read_file_from_stream_FULL(struct s_bkpinfo *, char *, FILE *, 70 long long); 71 extern int read_header_block_from_stream(long long *, char *, int *); 72 extern void save_filelist(struct s_node *, char *); 73 extern void strip_spaces(char *); 74 extern int strcmp_inc_numbers(char *, char *); 75 extern char *slice_fname(long, long, char *, char *); 76 extern int stop_raid_device(char *); 77 extern int stop_all_raid_devices(struct mountlist_itself *); 73 78 extern void update_evalcall_form(int); 74 extern void update_progress_form(char *);75 extern int verify_tape_backups(struct s_bkpinfo *);79 extern void update_progress_form(char *); 80 extern int verify_tape_backups(struct s_bkpinfo *); 76 81 extern char which_restore_mode(void); 77 extern int which_format_command_do_i_need(char*,char*); 78 extern int write_cfg_var(char*,char*,char*); 79 extern void wrong_marker(int,int); 80 extern void resize_drive_proportionately_to_suit_new_drives(struct mountlist_itself *mountlist, char*drive_name); 81 extern void resize_mountlist_proportionately_to_suit_new_drives(struct mountlist_itself *mountlist); 82 extern int get_cfg_file_from_archive(struct s_bkpinfo*); 82 extern int which_format_command_do_i_need(char *, char *); 83 extern int write_cfg_var(char *, char *, char *); 84 extern void wrong_marker(int, int); 85 extern void resize_drive_proportionately_to_suit_new_drives(struct 86 mountlist_itself 87 *mountlist, 88 char 89 *drive_name); 90 extern void resize_mountlist_proportionately_to_suit_new_drives(struct 91 mountlist_itself 92 *mountlist); 93 extern int get_cfg_file_from_archive(struct s_bkpinfo *); 83 94 84 95 … … 87 98 * Externals yummmy!!! * 88 99 **************************************************************************/ 89 extern long 90 extern long 91 extern long 92 extern int 93 extern int g_current_media_number; /* set to 1 in mondo-tools.c (tape)*/100 extern long g_maximum_progress; 101 extern long g_current_progress; 102 extern long g_start_time; 103 extern int g_currentY; 104 extern int g_current_media_number; /* set to 1 in mondo-tools.c (tape) */ 94 105 extern long long g_tape_posK; 95 106 extern FILE *g_tape_stream; … … 97 108 extern bool g_text_mode; 98 109 extern bool g_restoring_live_from_cd; 99 extern int fput_string_one_char_at_a_time(FILE *, char*);110 extern int fput_string_one_char_at_a_time(FILE *, char *); 100 111 101 112 … … 104 115 105 116 extern int 106 evaluate_mountlist 107 117 evaluate_mountlist(struct mountlist_itself *mountlist, char *flaws_str_A, 118 char *flaws_str_B, char *flaws_str_C); 108 119 109 120
Note:
See TracChangeset
for help on using the changeset viewer.