Changeset 2316 in MondoRescue for branches/2.2.10/mondo/src/mondorestore/mondo-rstr-newt.c
- Timestamp:
- Aug 18, 2009, 2:34:29 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.10/mondo/src/mondorestore/mondo-rstr-newt.c
r2314 r2316 12 12 #include "mondo-rstr-newt.h" 13 13 #include "mr_mem.h" 14 #include "mr_str.h" 14 15 15 16 //static char cvsid[] = "$Id$"; … … 255 256 { 256 257 257 /** buffers ***********************************************************/258 char sz_out[MAX_STR_LEN];259 260 258 /** int ****************************************************************/ 261 259 int items = 0; 262 260 int i = 0; 263 261 262 char *p = NULL; 263 264 264 assert(raidrec != NULL); 265 265 266 sz_out[0] = '\0'; 267 if (popup_and_get_string 268 ("Add variable", "Enter the name of the variable to add", sz_out, 269 MAX_STR_LEN)) { 270 strip_spaces(sz_out); 266 p = popup_and_get_string("Add variable", "Enter the name of the variable to add", ""); 267 if (p != NULL) { 268 mr_strip_spaces(p); 271 269 items = raidrec->additional_vars.entries; 272 270 for (i = 0; 273 271 i < items 274 && strcmp(raidrec->additional_vars.el[i].label, sz_out); i++);272 && strcmp(raidrec->additional_vars.el[i].label, p); i++); 275 273 if (i < items) { 276 274 popup_and_OK 277 275 ("No need to add that variable. It is already listed here."); 278 276 } else { 279 strcpy(raidrec->additional_vars.el[items].label, sz_out);277 strcpy(raidrec->additional_vars.el[items].label, p); 280 278 edit_varslist_entry(raidrec, items); 281 279 raidrec->additional_vars.entries = ++items; 282 280 } 283 281 } 282 mr_free(p); 284 283 } 285 284 #endif … … 464 463 465 464 /** int ***************************************************************/ 466 int res = 0;467 465 int out = 0; 466 int i = 0; 468 467 469 468 /** buffers ***********************************************************/ 470 char tmp[MAX_STR_LEN]; 469 char *tmp = NULL; 470 char *p = NULL; 471 char *q = NULL; 471 472 char *prompt = NULL; 472 char *sz = NULL;473 473 474 474 mr_asprintf(&prompt, "Please enter the RAID level you want. (concat, striped, raid5)"); 475 475 if (raidrec->raidlevel == -1) { 476 strcpy(tmp, "concat");476 mr_asprintf(&tmp, "concat"); 477 477 } else if (raidrec->raidlevel == 0) { 478 strcpy(tmp, "striped");478 mr_asprintf(&tmp, "striped"); 479 479 } else { 480 sprintf(tmp, "raid%i", raidrec->raidlevel);480 mr_asprintf(&tmp, "raid%i", raidrec->raidlevel); 481 481 } 482 482 for (out = 999; out == 999;) { 483 res = popup_and_get_string("Specify RAID level", prompt, tmp, 10); 484 if (!res) { 483 p = popup_and_get_string("Specify RAID level", prompt, tmp); 484 if (p == NULL) { 485 mr_free(tmp); 486 mr_free(prompt); 485 487 mr_free(prompt); 486 488 return; 487 489 } 488 strip_spaces(tmp); 489 if (tmp[0] == '[' && tmp[strlen(tmp) - 1] == ']') { 490 mr_asprintf(&sz, "%s", tmp); 491 strncpy(tmp, sz + 1, strlen(sz) - 2); 492 tmp[strlen(sz) - 2] = '\0'; 490 mr_strip_spaces(p); 491 /* Suppress brakets at each hend */ 492 if (p[0] == '[' && p[strlen(p) - 1] == ']') { 493 q = p+1; 494 i = 0; 495 while (*q != ']') { 496 p[i] = *q; 497 i++; 498 q++; 499 } 500 p[i] = '\0'; 493 501 mr_free(sz); 494 502 } 495 if (!strcmp( tmp, "concat")) {503 if (!strcmp(p, "concat")) { 496 504 out = -1; 497 } else if (!strcmp( tmp, "striped")) {505 } else if (!strcmp(p, "striped")) { 498 506 out = 0; 499 } else if (!strcmp( tmp, "raid5")) {507 } else if (!strcmp(p, "raid5")) { 500 508 out = 5; 501 509 } 502 log_it(tmp); 510 log_it("Raid level : %s",p); 511 mr_free(p); 512 503 513 if (is_this_raid_personality_registered(out)) { 504 log_it 505 ("Groovy. You've picked a RAID personality which is registered."); 514 log_it("Groovy. You've picked a RAID personality which is registered."); 506 515 } else { 507 if (ask_me_yes_or_no 508 ("You have chosen a RAID personality which is not registered with the kernel. Make another selection?")) 516 if (ask_me_yes_or_no("You have chosen a RAID personality which is not registered with the kernel. Make another selection?")) 509 517 { 510 518 out = 999; … … 512 520 } 513 521 } 522 mr_free(tmp); 514 523 mr_free(prompt); 524 515 525 raidrec->raidlevel = out; 516 526 #else 517 527 /** buffers ***********************************************************/ 518 char tmp[MAX_STR_LEN];528 char *tmp = NULL; 519 529 char *personalities = NULL; 520 530 char *prompt = NULL; 521 char *sz = NULL; 522 int out = 0, res = 0; 531 char *p = NULL; 532 char *q = NULL; 533 int out = 0; 534 int i = 0; 523 535 524 536 525 537 assert(raidrec != NULL); 526 system 527 538 539 system("grep Pers /proc/mdstat > /tmp/raid-personalities.txt 2> /dev/null"); 528 540 mr_asprintf(&personalities, "%s", last_line_of_file("/tmp/raid-personalities.txt")); 529 541 mr_asprintf(&prompt, "Please enter the RAID level you want. %s", personalities); … … 531 543 532 544 if (raidrec->raid_level == -1) { 533 strcpy(tmp, "linear");545 mr_asprintf(&tmp, "linear"); 534 546 } else { 535 sprintf(tmp, "%d", raidrec->raid_level);547 mr_asprintf(&tmp, "%d", raidrec->raid_level); 536 548 } 537 549 for (out = 999; 538 550 out != -1 && out != 0 && out != 1 && out != 4 && out != 5 539 551 && out != 10;) { 540 res = popup_and_get_string("Specify RAID level", prompt, tmp, 10); 541 if (!res) { 552 p = popup_and_get_string("Specify RAID level", prompt, tmp); 553 554 if (p == NULL) { 555 mr_free(tmp); 556 mr_free(prompt); 542 557 mr_free(prompt); 543 558 return; 544 559 } 545 strip_spaces(tmp); 546 if (tmp[0] == '[' && tmp[strlen(tmp) - 1] == ']') { 547 mr_asprintf(&sz, "%s", tmp); 548 strncpy(tmp, sz + 1, strlen(sz) - 2); 549 tmp[strlen(sz) - 2] = '\0'; 560 mr_strip_spaces(p); 561 if (p[0] == '[' && p[strlen(p) - 1] == ']') { 562 q = p+1; 563 i = 0; 564 while (*q != ']') { 565 p[i] = *q; 566 i++; 567 q++; 568 } 569 p[i] = '\0'; 550 570 mr_free(sz); 551 571 } 552 if (!strcmp( tmp, "linear")) {572 if (!strcmp(p, "linear")) { 553 573 out = -1; 554 } else if (!strncmp( tmp, "raid", 4)) {555 out = atoi( tmp + 4);574 } else if (!strncmp(p, "raid", 4)) { 575 out = atoi(p + 4); 556 576 } else { 557 out = atoi( tmp);558 } 559 log_it( tmp);577 out = atoi(p); 578 } 579 log_it("Raid level : %s",p); 560 580 if (is_this_raid_personality_registered(out)) { 561 log_it 562 ("Groovy. You've picked a RAID personality which is registered."); 581 log_it("Groovy. You've picked a RAID personality which is registered."); 563 582 } else { 564 if (ask_me_yes_or_no 565 ("You have chosen a RAID personality which is not registered with the kernel. Make another selection?")) 566 { 583 if (ask_me_yes_or_no("You have chosen a RAID personality which is not registered with the kernel. Make another selection?")) { 567 584 out = 999; 568 585 } 569 586 } 570 587 } 588 mr_free(tmp); 571 589 mr_free(prompt); 572 590 raidrec->raid_level = out; … … 1696 1714 int currline_a, currline_u; 1697 1715 1716 char *p = NULL; 1717 1698 1718 struct mountlist_itself *unallocparts; 1699 1719 … … 1828 1848 choose_raid_level(raidrec); 1829 1849 } else if (b_res == bStripeSize) { 1830 char tmp[64]; 1831 sprintf(tmp, "%i", raidrec->stripesize); 1832 if (popup_and_get_string 1833 ("Stripe size", 1834 "Please enter the stripe size in kilobytes.", tmp, 20)) { 1835 raidrec->stripesize = atoi(tmp); 1850 char *tmp = NULL; 1851 1852 mr_asprintf(&tmp, "%i", raidrec->stripesize); 1853 p = popup_and_get_string("Stripe size", "Please enter the stripe size in kilobytes.", tmp); 1854 mr_free(tmp); 1855 1856 if (p != NULL) { 1857 raidrec->stripesize = atoi(p); 1836 1858 } 1859 mr_free(p); 1837 1860 } else if ((b_res == bAlloc) || (b_res == unallocListbox)) { 1838 1861 if (currline_u <= unallocparts->entries) … … 1868 1891 1869 1892 /** buffers ***********************************************************/ 1870 char header[MAX_STR_LEN]; 1871 char comment[MAX_STR_LEN]; 1872 char sz_out[MAX_STR_LEN]; 1893 char *header = NULL; 1894 char *comment = NULL; 1895 char *sz_out = NULL; 1896 char *p = NULL; 1873 1897 1874 1898 assert(raidrec != 0); 1875 1899 assert(lino >= 0); 1876 1900 1877 strcpy(sz_out, raidrec->additional_vars.el[lino].value); 1878 sprintf(header, "Edit %s", raidrec->additional_vars.el[lino].label); 1879 sprintf(comment, "Please set %s's value (currently '%s')", 1880 raidrec->additional_vars.el[lino].label, sz_out); 1881 if (popup_and_get_string(header, comment, sz_out, MAX_STR_LEN)) { 1882 strip_spaces(sz_out); 1883 strcpy(raidrec->additional_vars.el[lino].value, sz_out); 1884 } 1901 mr_asprintf(&sz_out, "%s", raidrec->additional_vars.el[lino].value); 1902 mr_asprintf(&header, "Edit %s", raidrec->additional_vars.el[lino].label); 1903 mr_asprintf(&comment, "Please set %s's value (currently '%s')", raidrec->additional_vars.el[lino].label, sz_out); 1904 p = popup_and_get_string(header, comment, sz_out); 1905 if (p != NULL) { 1906 mr_strip_spaces(p); 1907 strcpy(raidrec->additional_vars.el[lino].value, p); 1908 } 1909 mr_free(p); 1885 1910 } 1886 1911 … … 2242 2267 * @return TRUE if OK was pressed, FALSE otherwise. 2243 2268 */ 2244 bool 2245 get_isodir_info(char *isodir_device, char *isodir_format, 2246 char *isodir_path, bool nuke_me_please) 2247 { 2269 bool get_isodir_info(char *isodir_device, char *isodir_format, char *isodir_path, bool nuke_me_please) 2270 { 2271 2272 char *p = NULL; 2273 char *q = NULL; 2274 char *r = NULL; 2275 char *idev = NULL; 2276 bool ret = FALSE; /* Should be false by default, and modfiy if conditions respected */ 2248 2277 2249 2278 /** initialize ********************************************************/ 2250 2279 2251 2280 assert(isodir_device != NULL); 2252 assert(isodir_format != NULL);2253 2281 assert(isodir_path != NULL); 2254 2282 2255 2283 log_it("isodir_path = %s", isodir_path); 2256 isodir_format[0] = '\0';2257 2284 if (isodir_device[0] == '\0') { 2258 strcpy(isodir_device, "/dev/"); 2259 } 2285 mr_asprintf(&idev, "/dev/"); 2286 } else { 2287 mr_asprintf(&idev, "%s", isodir_device); 2288 } 2289 2260 2290 if (isodir_path[0] == '\0') { 2261 2291 strcpy(isodir_path, "/"); 2262 2292 } 2263 2293 if (does_file_exist("/tmp/NFS-SERVER-PATH")) { 2264 strcpy(isodir_device, last_line_of_file("/tmp/NFS-SERVER-MOUNT")); 2265 strcpy(isodir_format, "nfs"); 2294 mr_free(idev); 2295 mr_asprintf(&idev, "%s", last_line_of_file("/tmp/NFS-SERVER-MOUNT")); 2296 mr_asprintf(&isodir_format, "nfs"); 2266 2297 strcpy(isodir_path, last_line_of_file("/tmp/NFS-SERVER-PATH")); 2267 2298 } 2299 2300 /* modify for the caller */ 2301 strcpy(isodir_device, idev); 2268 2302 if (nuke_me_please) { 2269 return (TRUE); 2270 } 2271 2272 if (popup_and_get_string 2273 ("ISO Mode - device", "On what device do the ISO files live?", 2274 isodir_device, MAX_STR_LEN / 4)) { 2275 if (popup_and_get_string 2276 ("ISO Mode - format", 2277 "What is the disk format of the device? (Hit ENTER if you don't know.)", 2278 isodir_format, 16)) { 2279 if (popup_and_get_string 2280 ("ISO Mode - path", 2281 "At what path on this device can the ISO files be found?", 2282 isodir_path, MAX_STR_LEN / 4)) { 2283 strip_spaces(isodir_device); 2284 strip_spaces(isodir_format); 2285 strip_spaces(isodir_path); 2286 log_it("isodir_device = %s - isodir_format = %s - isodir_path = %s", isodir_device, isodir_format, isodir_path); 2287 return (TRUE); 2303 ret = TRUE; 2304 } else { 2305 p = popup_and_get_string("ISO Mode - device", "On what device do the ISO files live?", idev); 2306 if (p != NULL) { 2307 q = popup_and_get_string("ISO Mode - format", "What is the disk format of the device? (Hit ENTER if you don't know.)", isodir_format); 2308 mr_free(isodir_format); 2309 2310 if (q != NULL) { 2311 r = popup_and_get_string("ISO Mode - path", "At what path on this device can the ISO files be found?", isodir_path); 2312 if (r != NULL) { 2313 mr_strip_spaces(p); 2314 mr_strip_spaces(q); 2315 mr_strip_spaces(r); 2316 2317 isodir_format = q; 2318 2319 /* modify for the caller */ 2320 strcpy(isodir_device, p); 2321 strcpy(isodir_path, r); 2322 log_it("isodir_device = %s - isodir_format = %s - isodir_path = %s", isodir_device, isodir_format, isodir_path); 2323 mr_free(r); 2324 2325 ret = TRUE; 2326 } 2288 2327 } 2289 2328 } 2290 } 2291 return (FALSE); 2329 mr_free(p); 2330 } 2331 mr_free(idev); 2332 mr_free(isodir_format); 2333 return(ret); 2292 2334 } 2293 2335 … … 2700 2742 /** buffers **********************************************************/ 2701 2743 void *keylist[ARBITRARY_MAXIMUM]; 2702 char *tmp; 2703 char *help_text; 2704 char *title_of_window; 2705 char *sz_res; 2706 char *header_text; 2744 char *tmp = NULL; 2745 char *help_text = NULL; 2746 char *title_of_window = NULL; 2747 char *sz_res = NULL; 2748 char *header_text = NULL; 2749 char *p = NULL; 2707 2750 2708 2751 /** int **************************************************************/ … … 2717 2760 2718 2761 log_it("malloc'ing"); 2719 malloc_string(tmp); 2720 malloc_string(help_text); 2721 malloc_string(title_of_window); 2722 malloc_string(sz_res); 2723 malloc_string(header_text); 2724 if (!(bkp_raidrec = malloc(sizeof(struct raid_device_record)))) { 2725 fatal_error("Cannot malloc space for raidrec"); 2726 } 2727 if (!(bkp_disklist = malloc(sizeof(struct list_of_disks)))) { 2728 fatal_error("Cannot malloc space for disklist"); 2729 } 2730 if (!(bkp_raidlist = malloc(sizeof(struct raidlist_itself)))) { 2731 fatal_error("Cannot malloc space for raidlist"); 2732 } 2733 if (! 2734 (unallocated_raid_partitions = 2735 malloc(sizeof(struct mountlist_itself)))) { 2736 fatal_error("Cannot malloc space for unallocated_raid_partitions"); 2737 } 2738 2739 memcpy((void *) bkp_raidlist, (void *) raidlist, 2740 sizeof(struct raidlist_itself)); 2741 memcpy((void *) bkp_raidrec, (void *) raidrec, 2742 sizeof(struct raid_device_record)); 2743 memcpy((void *) bkp_disklist, (void *) disklist, 2744 sizeof(struct list_of_disks)); 2762 bkp_raidrec = mr_malloc(sizeof(struct raid_device_record)); 2763 bkp_disklist = mr_malloc(sizeof(struct list_of_disks)); 2764 bkp_raidlist = mr_malloc(sizeof(struct raidlist_itself)); 2765 unallocated_raid_partitions = mr_malloc(sizeof(struct mountlist_itself)); 2766 2767 memcpy((void *) bkp_raidlist, (void *) raidlist, sizeof(struct raidlist_itself)); 2768 memcpy((void *) bkp_raidrec, (void *) raidrec, sizeof(struct raid_device_record)); 2769 memcpy((void *) bkp_disklist, (void *) disklist, sizeof(struct list_of_disks)); 2745 2770 2746 2771 log_it("Post-malloc"); 2747 strcpy(help_text, 2748 " Edit this RAID device's list of partitions. Choose OK or Cancel when done."); 2749 sprintf(header_text, "%-24s %s", "Device", "Index"); 2750 sprintf(title_of_window, "%s contains...", raidrec->raid_device); 2772 mr_asprintf(&help_text, " Edit this RAID device's list of partitions. Choose OK or Cancel when done."); 2773 mr_asprintf(&header_text, "%-24s %s", "Device", "Index"); 2774 mr_asprintf(&title_of_window, "%s contains...", raidrec->raid_device); 2751 2775 newtPushHelpLine(help_text); 2752 2776 for (b_res = (newtComponent) 12345; b_res != bOK && b_res != bCancel;) { … … 2803 2827 redraw_disklist(disklist, keylist, partitionsListbox); 2804 2828 } else { 2805 sprintf(tmp, "%s's index is %d. What should it be?",2806 raidrec->raid_device,2807 disklist->el[currline].index);2808 sprintf(sz_res, "%d", disklist->el[currline].index);2809 if (p opup_and_get_string("Set index", tmp, sz_res, 10)) {2829 mr_asprintf(&tmp, "%s's index is %d. What should it be?", raidrec->raid_device, disklist->el[currline].index); 2830 mr_asprintf(&sz_res, "%d", disklist->el[currline].index); 2831 p = popup_and_get_string("Set index", tmp, sz_res); 2832 mr_free(tmp); 2833 if (p != NULL) { 2810 2834 disklist->el[currline].index = atoi(sz_res); 2811 2835 } 2812 2836 redraw_disklist(disklist, keylist, partitionsListbox); 2837 mr_free(sz_res); 2813 2838 } 2814 2839 } … … 2818 2843 } 2819 2844 newtPopHelpLine(); 2845 mr_free(help_text); 2846 mr_free(header_text); 2847 mr_free(title_of_window); 2848 2820 2849 if (b_res == bCancel) { 2821 memcpy((void *) raidlist, (void *) bkp_raidlist, 2822 sizeof(struct raidlist_itself)); 2823 memcpy((void *) raidrec, (void *) bkp_raidrec, 2824 sizeof(struct raid_device_record)); 2825 memcpy((void *) disklist, (void *) bkp_disklist, 2826 sizeof(struct list_of_disks)); 2827 } 2828 paranoid_free(tmp); 2829 paranoid_free(help_text); 2830 paranoid_free(title_of_window); 2831 paranoid_free(sz_res); 2832 paranoid_free(header_text); 2833 paranoid_free(bkp_raidrec); 2834 paranoid_free(bkp_disklist); 2835 paranoid_free(bkp_raidlist); 2836 paranoid_free(unallocated_raid_partitions); 2850 memcpy((void *) raidlist, (void *) bkp_raidlist, sizeof(struct raidlist_itself)); 2851 memcpy((void *) raidrec, (void *) bkp_raidrec, sizeof(struct raid_device_record)); 2852 memcpy((void *) disklist, (void *) bkp_disklist, sizeof(struct list_of_disks)); 2853 } 2854 mr_free(bkp_raidrec); 2855 mr_free(bkp_disklist); 2856 mr_free(bkp_raidlist); 2857 mr_free(unallocated_raid_partitions); 2837 2858 } 2838 2859 #endif
Note:
See TracChangeset
for help on using the changeset viewer.