Changeset 1174 in MondoRescue
- Timestamp:
- Feb 16, 2007, 1:22:49 PM (18 years ago)
- Location:
- branches/stable/mondo/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mondo/src/common/libmondo-raid.c
r1172 r1174 1 /* libmondo-raid.c subroutines for handling RAID2 $Id$1 /* $Id$ 2 subroutines for handling RAID 3 3 */ 4 4 … … 10 10 11 11 #include "my-stuff.h" 12 #include "mr_str.h" 13 #include "mr_mem.h" 14 #include "mr_msg.h" 15 12 16 #include "mondostructures.h" 13 #include " libmondo-gui-EXT.h"17 #include "newt-specific-EXT.h" 14 18 #include "libmondo-files-EXT.h" 15 19 #include "libmondo-tools-EXT.h" 16 20 #include "libmondo-string-EXT.h" 17 21 #include "libmondo-raid.h" 18 #include "mr_str.h"19 #include "mr_mem.h"20 #include "mr_msg.h"21 22 22 23 #ifdef __FreeBSD__ … … 47 48 #else 48 49 /*@ buffer ********************************************************** */ 49 char *command; 50 int res; 51 52 command = mr_malloc(MAX_STR_LEN * 2); 53 strcpy(command, "grep \" /proc/mdstat"); 50 char *command = NULL; 51 int res = 0; 52 54 53 if (raidno == -1) { 55 strcat(command, "linear"); 54 mr_asprintf(&command, 55 "grep \"linear\" /proc/mdstat > /dev/null 2> /dev/null"); 56 56 } else { 57 sprintf(command + strlen(command), "raid%d", raidno); 58 } 59 strcat(command, "\" > /dev/null 2> /dev/null"); 57 mr_asprintf(&command, 58 "grep \"raid%d\" /proc/mdstat > /dev/null 2> /dev/null", 59 raidno); 60 } 60 61 log_it("Is raid %d registered? Command = '%s'", raidno, command); 61 62 res = system(command); … … 70 71 71 72 72 73 74 75 76 73 /** 77 74 * Search for @p device in @p disklist. … … 101 98 } 102 99 } 103 104 105 106 107 108 109 110 100 111 101 /** … … 192 182 { 193 183 /*@ buffers ***************************************************** */ 194 char *sz_value; 195 196 malloc_string(sz_value); 184 char *sz_value = NULL; 185 197 186 assert(raidrec != NULL); 198 187 assert(label != NULL); 199 188 200 sprintf(sz_value, "%d", value);189 mr_asprintf(&sz_value, "%d", value); 201 190 strcpy(raidrec->additional_vars.el[lino].label, label); 202 191 strcpy(raidrec->additional_vars.el[lino].value, sz_value); … … 204 193 } 205 194 #endif 206 207 208 209 210 211 212 213 195 214 196 #ifdef __FreeBSD__ … … 335 317 #ifdef __FreeBSD__ 336 318 int i, j; 319 char *org = NULL; 337 320 338 321 fprintf(fout, "\nvolume %s\n", raidrec->volname); 339 322 for (i = 0; i < raidrec->plexes; ++i) { 340 char org[24];341 323 switch (raidrec->plex[i].raidlevel) { 342 324 case -1: 343 strcpy(org, "concat");325 mr_asprintf(&org, "concat"); 344 326 break; 345 327 case 0: 346 strcpy(org, "striped");328 mr_asprintf(&org, "striped"); 347 329 break; 348 330 case 5: 349 strcpy(org, "raid5");331 mr_asprintf(&org, "raid5"); 350 332 break; 351 333 } 352 334 fprintf(fout, " plex org %s", org); 335 mr_free(org); 336 353 337 if (raidrec->plex[i].raidlevel != -1) { 354 338 fprintf(fout, " %ik", raidrec->plex[i].stripesize); … … 425 409 * @return 0 if the line was read and stored successfully, 1 if we're at end of file. 426 410 */ 427 int get_next_raidtab_line(FILE * 428 { 429 char *incoming ;430 char *p ;431 432 malloc_string(incoming); 411 int get_next_raidtab_line(FILE *fin, char *label, char *value) 412 { 413 char *incoming = NULL; 414 char *p = NULL; 415 size_t n = 0; 416 433 417 assert(fin != NULL); 434 418 assert(label != NULL); … … 437 421 label[0] = value[0] = '\0'; 438 422 if (feof(fin)) { 439 mr_free(incoming);440 423 return (1); 441 424 } 442 for ( fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);443 fgets(incoming, MAX_STR_LEN - 1, fin)) {425 for (mr_getline(&incoming, &n, fin); !feof(fin); 426 mr_getline(&incoming, &n, fin)) { 444 427 mr_strip_spaces(incoming); 445 428 p = strchr(incoming, ' '); … … 456 439 return (0); 457 440 } 441 mr_free(incoming); 458 442 return (1); 459 443 } 460 461 444 462 445 … … 471 454 char *fname) 472 455 { 473 FILE *fin; 474 char *tmp; 475 int items; 476 477 malloc_string(tmp); 456 FILE *fin = NULL; 457 int items = 0; 458 478 459 raidlist->spares.entries = 0; 479 460 raidlist->disks.entries = 0; … … 481 462 log_it("Raidtab is very small or non-existent. Ignoring it."); 482 463 raidlist->entries = 0; 483 mr_free(tmp);484 464 return (0); 485 465 } 486 466 if (!(fin = fopen(fname, "r"))) { 487 467 log_it("Cannot open raidtab"); 488 mr_free(tmp);489 468 return (1); 490 469 } … … 523 502 } 524 503 } else if (!strcmp(argv[0], "volume")) { 525 char *volname ;504 char *volname = NULL; 526 505 if (argc < 2) 527 506 continue; … … 532 511 } else if (!strcmp(argv[0], "plex")) { 533 512 int raidlevel, stripesize; 534 char *org = 0;535 char **tmp = 0;513 char *org = NULL; 514 char **tmp = NULL; 536 515 if (argc < 3) 537 516 continue; … … 570 549 } else if ((!strcmp(argv[0], "sd")) 571 550 || (!strcmp(argv[0], "subdisk"))) { 572 char *drive = 0;551 char *drive = NULL; 573 552 if (argc < 3) 574 553 continue; … … 589 568 fclose(fin); 590 569 log_it("Raidtab loaded successfully."); 591 sprintf(tmp, "%d RAID devices in raidtab", raidlist->entries); 592 log_it(tmp); 593 mr_free(tmp); 570 log_it("%d RAID devices in raidtab", raidlist->entries); 594 571 return (0); 595 572 } … … 601 578 char *fname) 602 579 { 603 FILE *fin; 604 char *tmp; 605 char *label; 606 char *value; 580 FILE *fin = NULL; 581 char *label = NULL; 582 char *value = NULL; 607 583 int items; 608 584 int v; 609 585 610 malloc_string(tmp);611 malloc_string(label);612 malloc_string(value);613 586 assert(raidlist != NULL); 614 587 assert_string_is_neither_NULL_nor_zerolength(fname); … … 617 590 log_it("Raidtab is very small or non-existent. Ignoring it."); 618 591 raidlist->entries = 0; 619 mr_free(tmp);620 mr_free(label);621 mr_free(value);622 592 return (0); 623 593 } 624 594 if (!(fin = fopen(fname, "r"))) { 625 595 log_it("Cannot open raidtab"); 626 mr_free(tmp);627 mr_free(label);628 mr_free(value);629 596 return (1); 630 597 } … … 642 609 v++; 643 610 get_next_raidtab_line(fin, label, value); 644 log_it(tmp);645 611 } 646 612 raidlist->el[items].additional_vars.entries = v; … … 662 628 mr_msg(1, "Raidtab loaded successfully."); 663 629 mr_msg(1, "%d RAID devices in raidtab", items); 664 mr_free(tmp);665 mr_free(label);666 mr_free(value);667 630 return (0); 668 631 } 669 632 #endif 670 671 672 673 674 675 676 633 677 634 … … 685 642 */ 686 643 void 687 process_raidtab_line(FILE * 644 process_raidtab_line(FILE *fin, 688 645 struct raid_device_record *raidrec, 689 646 char *label, char *value) … … 691 648 692 649 /*@ add mallocs * */ 693 char *tmp; 694 char *labelB; 695 char *valueB; 696 697 struct list_of_disks *disklist; 698 int v; 699 700 malloc_string(tmp); 650 char *labelB = NULL; 651 char *valueB = NULL; 652 653 struct list_of_disks *disklist = NULL; 654 int v = 0; 655 701 656 malloc_string(labelB); 702 657 malloc_string(valueB); … … 748 703 } 749 704 if (!disklist) { 750 sprintf(tmp, 751 "Ignoring '%s %s' pair of disk %s", labelB, valueB, 705 log_it("Ignoring '%s %s' pair of disk %s", labelB, valueB, 752 706 label); 753 log_it(tmp);754 707 } else { 755 708 add_disk_to_raid_device(disklist, value, atoi(valueB)); 756 709 } 710 mr_free(labelB); 711 mr_free(valueB); 757 712 } else { 758 713 v = raidrec->additional_vars.entries; … … 761 716 raidrec->additional_vars.entries = ++v; 762 717 } 763 mr_free(tmp);764 mr_free(labelB);765 mr_free(valueB);766 718 } 767 719 #endif … … 792 744 793 745 794 795 796 797 746 #ifdef __FreeBSD__ 798 747 /** … … 819 768 static char *argv[64]; 820 769 char **ap; 821 char *line = (char *) mr_malloc(MAX_STR_LEN); 822 (void) fgets(line, MAX_STR_LEN, f); 770 char *line = NULL; 771 size_t = 0; 772 int lastpos = 0; 773 774 mr_getline(&line, &n, f); 823 775 if (feof(f)) { 824 776 log_it("[GNVCL] Uh... I reached the EOF."); 825 return 0;777 return NULL; 826 778 } 827 779 … … 961 913 ("Oh my gosh. You actually think a YOTTABYTE will get you anywhere? What're you going to do with 1,208,925,819,614,629,174,706,176 bytes?!?!"); 962 914 popup_and_OK 963 ( "That sizespec is more than 1,208,925,819,614,629,174,706,176 bytes. You have a shocking amount of data. Please send a screenshot to the list :-)");915 (_("That sizespec is more than 1,208,925,819,614,629,174,706,176 bytes. You have a shocking amount of data. Please send a screenshot to the list :-)")); 964 916 return size * sign * 1024 * 1024 * 1024 * 1024 * 1024 * 965 917 1024 * 1024 * 1024; … … 979 931 const char delims[] = " "; 980 932 981 FILE *fin; 982 int row, i, index_min; 933 FILE *fin = NULL; 934 int row = 0; 935 int i = 0; 936 int index_min = 0; 983 937 int lastpos = 0; 984 938 size_t len = 0; 985 char *token;939 char *token = NULL; 986 940 char *string = NULL; 987 char *pos ;988 char type ;989 char *strtmp ;941 char *pos = NULL; 942 char type = NULL; 943 char *strtmp = NULL; 990 944 991 945 // open file … … 1005 959 // trim leading spaces 1006 960 pos = string; 1007 while (*pos == ' ') pos += 1;961 while (*pos == ' ') pos++; 1008 962 mr_asprintf(&strtmp, pos); 1009 strcpy(string,strtmp);963 mr_allocstr(string,strtmp); 1010 964 mr_free(strtmp); 1011 965 // if we have newline after only spaces, this is a blank line, update … … 1235 1189 1236 1190 1237 1238 1191 /* @} - end of raidGroup */ -
branches/stable/mondo/src/common/libmondo-stream.c
r1123 r1174 1 /* libmondo-stream.c 2 $Id$ 1 /* $Id$ 3 2 4 3 ...tools for talking to tapes, Monitas streams, etc. 5 6 4 */ 7 5 8 9 /**6 /* 7 * 10 8 * @file 11 9 * Functions for writing data to/reading data from streams (tape, CD stream, etc.) 12 10 */ 11 12 #include <unistd.h> 13 13 14 14 #include "my-stuff.h" 15 15 #include "mr_mem.h" 16 16 #include "mr_msg.h" 17 17 18 #include "mondostructures.h" 18 19 #include "libmondo-devices.h" … … 20 21 #include "libmondo-string-EXT.h" 21 22 #include "libmondo-files-EXT.h" 22 #include " libmondo-gui-EXT.h"23 #include "newt-specific-EXT.h" 23 24 #include "libmondo-fork-EXT.h" 24 25 #include "libmondo-tools-EXT.h" -
branches/stable/mondo/src/lib/mr_mem.c
r1156 r1174 86 86 void mr_allocstr_int(char *alloc, const char *orig, int line, const char *file) { 87 87 88 mr_free_int((void **)&alloc, line, file); 88 if (alloc != NULL) { 89 mr_free_int((void **)&alloc, line, file); 90 } 89 91 mr_asprintf_int(&alloc, line, file, orig); 90 92 }
Note:
See TracChangeset
for help on using the changeset viewer.