Changeset 2764 in MondoRescue
- Timestamp:
- Apr 20, 2011, 12:18:46 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mondo/src/mondorestore/mondo-prep.c
r2480 r2764 2464 2464 2465 2465 /** float ***********************************************************/ 2466 float factor; 2467 float new_size; 2468 // float newcylinderno; 2466 long long factor; 2467 long long new_size; 2469 2468 2470 2469 /** long *************************************************************/ 2471 long newsizL = 0L; 2472 long current_size_of_drive = 0L; 2473 long original_size_of_drive = 0L; 2474 long final_size = 0L; /* all in Megabytes */ 2470 long long newsizL = 0LL; 2471 long long totalsizL = 0LL; 2472 long long current_size_of_drive = 0LL; /* use KB interally for precision */ 2473 long long original_size_of_drive = 0LL; /* use KB interally for precision */ 2474 long long final_size = 0LL; /* all in Megabytes */ 2475 2475 struct mountlist_reference *drivemntlist; 2476 2476 … … 2479 2479 /** end **************************************************************/ 2480 2480 2481 malloc_string(tmp);2482 2481 assert(mountlist != NULL); 2483 2482 assert_string_is_neither_NULL_nor_zerolength(drive_name); … … 2486 2485 if (strncmp(drive_name, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB)) 2487 2486 == 0) { 2488 paranoid_free(tmp);2489 2487 return; 2490 2488 } 2491 2489 } 2492 2490 2493 current_size_of_drive = get_phys_size_of_drive(drive_name);2494 2495 if (current_size_of_drive <= 0 ) {2491 current_size_of_drive = (long long) get_phys_size_of_drive(drive_name) * 1024LL; 2492 2493 if (current_size_of_drive <= 0LL) { 2496 2494 log_it("Not resizing to match %s - can't find drive", drive_name); 2497 paranoid_free(tmp);2498 2495 return; 2499 2496 } 2500 sprintf(tmp, "Expanding entries to suit drive %s (%ld MB)", drive_name, 2501 current_size_of_drive); 2497 mr_asprintf(&tmp, "Expanding entries to suit drive %s (%lld MB)", drive_name, current_size_of_drive / 1024); 2502 2498 log_to_screen(tmp); 2499 mr_free(tmp); 2503 2500 2504 2501 drivemntlist = malloc(sizeof(struct mountlist_reference)); … … 2512 2509 2513 2510 for (partno = 0; partno < drivemntlist->entries; partno++) { 2514 if (drivemntlist->el[partno]->size > 0) { 2515 original_size_of_drive += (drivemntlist->el[partno]->size / 1024L); 2511 if (drivemntlist->el[partno]->size > 0LL) { 2512 /* Keep KB here */ 2513 original_size_of_drive += drivemntlist->el[partno]->size; 2516 2514 } 2517 2515 } 2518 2516 2519 2517 if (original_size_of_drive <= 0) { 2520 sprintf(tmp, "Cannot resize %s's entries. Drive not found.", 2521 drive_name); 2518 mr_asprintf(&tmp, "Cannot resize %s's entries. Drive not found.", drive_name); 2522 2519 log_to_screen(tmp); 2523 paranoid_free(tmp);2520 mr_free(tmp); 2524 2521 return; 2525 2522 } 2526 factor = 2527 (float) (current_size_of_drive) / (float) (original_size_of_drive); 2528 sprintf(tmp, "Disk %s was %ld MB; is now %ld MB; factor = %f", 2529 drive_name, original_size_of_drive, current_size_of_drive, 2530 factor); 2523 factor = (current_size_of_drive) / (original_size_of_drive); 2524 mr_asprintf(&tmp, "Disk %s was %lld MB; is now %lld MB; Proportionally resizing partitions (factor ~= %lld)", 2525 drive_name, original_size_of_drive/1024, current_size_of_drive/1024, factor); 2531 2526 log_to_screen(tmp); 2527 mr_free(tmp); 2532 2528 2533 2529 lastpart = drivemntlist->entries - 1; … … 2535 2531 /* the 'atoi' thing is to make sure we don't try to resize _images_, whose formats will be numeric */ 2536 2532 if (!atoi(drivemntlist->el[partno]->format)) { 2537 new_size = ( float) (drivemntlist->el[partno]->size) * factor;2533 new_size = (drivemntlist->el[partno]->size) * factor; 2538 2534 } else { 2539 2535 new_size = drivemntlist->el[partno]->size; … … 2544 2540 drivemntlist->el[partno]->device, 2545 2541 drivemntlist->el[partno]->mountpoint); 2546 newsizL = (long) new_size; // It looks wrong but it's not 2547 } else { 2548 newsizL = (long) new_size; 2549 } 2542 } 2543 newsizL = new_size; 2550 2544 2551 2545 /* Do not apply the factor if partition was of negative size */ 2552 if (newsizL < 0 ) {2546 if (newsizL < 0LL) { 2553 2547 newsizL = drivemntlist->el[partno]->size; 2554 2548 } 2555 2556 sprintf(tmp, "Changing %s from %lld KB to %ld KB", 2557 drivemntlist->el[partno]->device, 2558 drivemntlist->el[partno]->size, newsizL); 2549 totalsizL += newsizL; 2550 2551 mr_asprintf(&tmp, "Changing %s from %lld KB to %lld KB", drivemntlist->el[partno]->device, drivemntlist->el[partno]->size, newsizL); 2559 2552 log_to_screen(tmp); 2553 mr_free(tmp); 2560 2554 drivemntlist->el[partno]->size = newsizL; 2561 2555 } 2562 final_size = get_phys_size_of_drive(drive_name); 2563 sprintf(tmp, "final_size = %ld MB", final_size); 2556 // Ensures over-allocation alert and prompt for interactive mode does not happen 2557 if (totalsizL > current_size_of_drive) { 2558 mr_asprintf(&tmp, "Last partition size calculated would be over-allocated, reducing %s from %lld KB to %lld KB.", drivemntlist->el[lastpart]->device, drivemntlist->el[lastpart]->size, drivemntlist->el[lastpart]->size - (totalsizL - current_size_of_drive)); 2559 drivemntlist->el[drivemntlist->entries-1]->size -= (totalsizL - current_size_of_drive); 2560 } else if (totalsizL < current_size_of_drive) { 2561 mr_asprintf(&tmp, "Last partition size calculated would be under-allocated, increasing %s from %lld KB to %lld KB.",drivemntlist->el[lastpart]->device, drivemntlist->el[lastpart]->size, drivemntlist->el[lastpart]->size + (current_size_of_drive - totalsizL)); 2562 drivemntlist->el[drivemntlist->entries-1]->size += (current_size_of_drive - totalsizL); 2563 } 2564 2564 log_to_screen(tmp); 2565 paranoid_free(tmp); 2565 mr_free(tmp); 2566 mr_asprintf(&tmp, "final_size = %lld MB", current_size_of_drive / 1024); 2567 log_to_screen(tmp); 2568 mr_free(tmp); 2566 2569 } 2567 2570
Note:
See TracChangeset
for help on using the changeset viewer.