Changeset 1173 in MondoRescue
- Timestamp:
- Feb 16, 2007, 12:25:24 PM (18 years ago)
- Location:
- branches/stable/mondo/src/common
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mondo/src/common/libmondo-files.c
r1158 r1173 83 83 return (output); 84 84 } 85 86 87 /**88 * Get a not-quite-unique representation of some of the file's @c stat properties.89 * The returned string has the form <tt>size-mtime-ctime</tt>.90 * @param curr_fname The file to generate the "checksum" for.91 * @return The "checksum".92 * @note The returned string points to static storage that will be overwritten with each call.93 */94 char *calc_file_ugly_minichecksum(char *curr_fname)95 {96 97 /*@ buffers ***************************************************** */98 static char curr_cksum[1000];99 100 /*@ pointers **************************************************** */101 102 /*@ structures ************************************************** */103 struct stat buf;104 105 /*@ initialize data *************************************************** */106 curr_cksum[0] = '\0';107 108 /*@************************************************************** */109 110 assert_string_is_neither_NULL_nor_zerolength(curr_fname);111 if (lstat(curr_fname, &buf)) {112 return (curr_cksum); // empty113 }114 115 sprintf(curr_cksum, "%ld-%ld-%ld", (long) (buf.st_size),116 (long) (buf.st_mtime), (long) (buf.st_ctime));117 return (curr_cksum);118 }119 120 85 121 86 … … 699 664 long file_len_K = 0L; 700 665 701 malloc_string(sz_res);702 666 mr_asprintf(&command, 703 667 "grep '%s ' %s/mountlist.txt | head -n1 | awk '{print $4;}'", 704 668 dev, tmpdir); 705 669 log_it(command); 706 strcpy(sz_res, call_program_and_get_last_line_of_output(command));670 mr_asprintf(&sz_res, call_program_and_get_last_line_of_output(command)); 707 671 file_len_K = atol(sz_res); 708 672 mr_msg(4, "%s --> %s --> %ld", command, sz_res, file_len_K); … … 982 946 /*@ Char buffers ** */ 983 947 char *command = NULL; 984 char tmp[MAX_STR_LEN];948 char *tmp = NULL; 985 949 char old_pwd[MAX_STR_LEN]; 986 950 … … 1008 972 mr_free(command); 1009 973 1010 sprintf(tmp, "%s/payload.tgz", g_mondo_home);974 mr_asprintf(&tmp, "%s/payload.tgz", g_mondo_home); 1011 975 if (does_file_exist(tmp)) { 1012 976 log_it("Untarring payload %s to scratchdir %s", tmp, … … 1021 985 chdir(old_pwd); 1022 986 } 987 mr_free(tmp); 1023 988 1024 989 mr_asprintf(&command, "cp -f %s/LAST-FILELIST-NUMBER %s", bkpinfo->tmpdir, 1025 990 bkpinfo->scratchdir); 1026 1027 991 if (run_program_and_log_output(command, FALSE)) { 1028 992 fatal_error("Failed to copy LAST-FILELIST-NUMBER to scratchdir"); … … 1030 994 mr_free(command); 1031 995 1032 strcpy(tmp,call_program_and_get_last_line_of_output("which mondorestore"));996 mr_asprintf(&tmp,call_program_and_get_last_line_of_output("which mondorestore")); 1033 997 if (!tmp) { 1034 998 fatal_error … … 1036 1000 } 1037 1001 mr_asprintf(&command, "cp -f %s %s", tmp, bkpinfo->tmpdir); 1002 mr_free(tmp); 1003 1038 1004 if (run_program_and_log_output(command, FALSE)) { 1039 1005 fatal_error("Failed to copy mondorestore to tmpdir"); … … 1267 1233 *(strchr(tmp, ' ')) = '\0'; 1268 1234 } 1269 if (!strcmp(strrchr(filename, '.'), tmp)) {1235 if (!strcmp(strrchr(filename, '.'), tmp)) { 1270 1236 mr_free(do_not_compress_these); 1271 1237 mr_free(tmp); -
branches/stable/mondo/src/common/libmondo-fork.c
r1168 r1173 46 46 47 47 assert_string_is_neither_NULL_nor_zerolength(call); 48 48 49 if ((fin = popen(call, "r"))) { 49 50 for (fgets(tmp, MAX_STR_LEN, fin); !feof(fin); … … 184 185 char *callstr = NULL; 185 186 char *incoming = NULL; 186 char *tmp = NULL;187 187 188 188 /*@ int ********************************************************* */ 189 189 int res = 0; 190 190 size_t n = 0; 191 int i;192 int len;193 191 bool log_if_failure = FALSE; 194 192 bool log_if_success = FALSE; … … 325 323 } 326 324 } 327 #ifdef _XWIN328 /* This only can update when newline goes into the file,329 but it's *much* prettier/faster on Qt. */330 while (does_file_exist(lockfile)) {331 while (!feof(fin)) {332 if (!fgets(tmp, 512, fin))333 break;334 log_to_screen(tmp);335 }336 usleep(500000);337 }338 #else339 325 /* This works on Newt, and it gives quicker updates. */ 340 326 for (; does_file_exist(lockfile); sleep(1)) { … … 342 328 update_evalcall_form(1); 343 329 } 344 #endif345 330 /* Evaluate the status returned by pclose to get the exit code of the called program. */ 346 331 errno = 0; … … 379 364 // if dir=='r' then copy from archived to orig 380 365 char *tmp = NULL; 366 char *tmp1 = NULL; 381 367 char *buf = NULL; 382 368 long int bytes_to_be_read, bytes_read_in, bytes_written_out = … … 396 382 fin = f_orig; 397 383 fout = f_archived; 398 sprintf(tmp, "%-64s", PIMP_START_SZ);399 if (fwrite(tmp , 1, 64, fout) != 64) {384 mr_asprintf(&tmp1, "%-64s", PIMP_START_SZ); 385 if (fwrite(tmp1, 1, 64, fout) != 64) { 400 386 fatal_error("Can't write the introductory block"); 401 387 } 388 mr_free(tmp1); 389 402 390 while (1) { 403 391 bytes_to_be_read = bytes_read_in = fread(buf, 1, bufcap, fin); … … 405 393 break; 406 394 } 407 sprintf(tmp, "%-64ld", bytes_read_in);408 if (fwrite(tmp , 1, 64, fout) != 64) {395 mr_asprintf(&tmp1, "%-64ld", bytes_read_in); 396 if (fwrite(tmp1, 1, 64, fout) != 64) { 409 397 fatal_error("Cannot write introductory block"); 410 398 } 399 mr_free(tmp1); 400 411 401 mr_msg(7, 412 402 "subslice #%ld --- I have read %ld of %ld bytes in from f_orig", 413 403 subsliceno, bytes_read_in, bytes_to_be_read); 414 404 bytes_written_out += fwrite(buf, 1, bytes_read_in, fout); 415 sprintf(tmp, "%-64ld", subsliceno);416 if (fwrite(tmp , 1, 64, fout) != 64) {405 mr_asprintf(&tmp1, "%-64ld", subsliceno); 406 if (fwrite(tmp1, 1, 64, fout) != 64) { 417 407 fatal_error("Cannot write post-thingy block"); 418 408 } 409 mr_free(tmp1); 410 419 411 mr_msg(7, "Subslice #%d written OK", subsliceno); 420 412 subsliceno++; … … 427 419 fin = f_archived; 428 420 fout = f_orig; 421 tmp = mr_malloc(64L); 429 422 if (fread(tmp, 1, 64L, fin) != 64L) { 430 423 fatal_error("Cannot read the introductory block"); … … 447 440 } 448 441 bytes_written_out += fwrite(buf, 1, bytes_read_in, fout); 449 if (fread(tmp, 1, 64 , fin) != 64) {442 if (fread(tmp, 1, 64L, fin) != 64L) { 450 443 fatal_error("Cannot read post-thingy block"); 451 444 } … … 456 449 mr_msg(7, "Subslice #%ld read OK", subsliceno); 457 450 subsliceno++; 458 if (fread(tmp, 1, 64 , fin) != 64) {451 if (fread(tmp, 1, 64L, fin) != 64L) { 459 452 fatal_error("Cannot read introductory block"); 460 453 } … … 466 459 467 460 if (direction == 'w') { 468 sprintf(tmp, "%-64s", PIMP_END_SZ);469 if (fwrite(tmp , 1, 64, fout) != 64) {461 mr_asprintf(&tmp1, "%-64s", PIMP_END_SZ); 462 if (fwrite(tmp1, 1, 64L, fout) != 64L) { 470 463 fatal_error("Can't write the final block"); 471 464 } 465 mr_free(tmp1); 472 466 } else { 473 467 mr_msg(1, "tmpA is %s", tmp); 474 468 if (!strstr(tmp, PIMP_END_SZ)) { 475 if (fread(tmp, 1, 64 , fin) != 64) {469 if (fread(tmp, 1, 64L, fin) != 64L) { 476 470 fatal_error("Can't read the final block"); 477 471 } … … 479 473 if (!strstr(tmp, PIMP_END_SZ)) { 480 474 ftmp = fopen("/tmp/out.leftover", "w"); 481 bytes_read_in = fread(tmp, 1, 64 , fin);475 bytes_read_in = fread(tmp, 1, 64L, fin); 482 476 mr_msg(1, "bytes_read_in = %ld", bytes_read_in); 483 477 // if (bytes_read_in!=128+64) { fatal_error("Can't read the terminating block"); } -
branches/stable/mondo/src/common/libmondo-mountlist.c
r1166 r1173 57 57 58 58 /*@ buffers ******************************************************** */ 59 char tmp[MAX_STR_LEN]; 60 char device[MAX_STR_LEN]; 61 char mountpoint[MAX_STR_LEN]; 59 char *tmp = NULL; 60 char *device = NULL; 61 char *ndevice = NULL; 62 // BERLIOS : useless ? char *mountpoint; 62 63 63 64 /*@ long *********************************************************** */ … … 66 67 67 68 /*@ pointers ******************************************************* */ 68 char *part_table_fmt ;69 char *part_table_fmt = NULL; 69 70 70 71 /*@ initialize ***************************************************** */ 71 72 flaws_str[0] = '\0'; 72 73 prev_part_no = 0; 73 tmp[0] = '\0';74 74 75 75 … … 77 77 78 78 if (physical_drive_size < 0) { 79 sprintf(tmp, " %s does not exist.", drive);79 mr_asprintf(&tmp, " %s does not exist.", drive); 80 80 strcat(flaws_str, tmp); 81 81 } else { 82 sprintf(tmp, "%s is %ld MB", drive, physical_drive_size);82 mr_asprintf(&tmp, "%s is %ld MB", drive, physical_drive_size); 83 83 } 84 84 log_it(tmp); 85 mr_free(tmp); 85 86 86 87 87 88 /* check DD */ 88 89 for (cur_sp_no = 'a'; cur_sp_no < 'z'; ++cur_sp_no) { 89 sprintf(device, "%s%c", drive, cur_sp_no);90 mr_asprintf(&device, "%s%c", drive, cur_sp_no); 90 91 if (find_device_in_mountlist(mountlist, device) >= 0) 91 92 foundsome = TRUE; 93 mr_free(device); 92 94 } 93 95 if (foundsome) { 94 96 for (cur_sp_no = 'a'; cur_sp_no < 'z'; ++cur_sp_no) { 95 sprintf(device, "%s%c", drive, cur_sp_no);97 mr_asprintf(&device, "%s%c", drive, cur_sp_no); 96 98 pos = find_device_in_mountlist(mountlist, device); 97 99 if (pos < 0) { 98 100 continue; 99 101 } 100 strcpy(mountpoint, mountlist->el[pos].mountpoint);102 // BERLIOS : useless ? mr_asprintf(&mountpoint, mountlist->el[pos].mountpoint); 101 103 /* is it too big? */ 102 104 if (curr_part_no > 'h') { 103 sprintf(tmp, " Can only have up to 'h' in disklabel.");105 mr_asprintf(&tmp, " Can only have up to 'h' in disklabel."); 104 106 log_it(tmp); 105 107 strcat(flaws_str, tmp); 108 mr_free(tmp); 106 109 res++; 107 110 } … … 114 117 } 115 118 if (device_copies > 1) { 116 sprintf(tmp, " %s %s's.", number_to_text(device_copies),117 device);119 mr_asprintf(&tmp, " %s %s's.", number_to_text(device_copies), 120 device); 118 121 if (!strstr(flaws_str, tmp)) { 119 122 log_it(tmp); … … 121 124 res++; 122 125 } 126 mr_free(tmp); 123 127 } 124 128 /* silly partition size? */ 125 129 if (mountlist->el[pos].size < 8192 126 130 && strcmp(mountlist->el[pos].mountpoint, "lvm")) { 127 sprintf(tmp, " %s is tiny!", device);131 mr_asprintf(&tmp, " %s is tiny!", device); 128 132 log_it(tmp); 129 133 strcat(flaws_str, tmp); 134 mr_free(tmp); 130 135 res++; 131 136 } … … 137 142 && strcmp(mountlist->el[pos].mountpoint, "none") 138 143 && mountlist->el[pos].mountpoint[0] != '/') { 139 sprintf(tmp, " %s has a weird mountpoint.", device);144 mr_asprintf(&tmp, " %s has a weird mountpoint.", device); 140 145 log_it(tmp); 141 146 strcat(flaws_str, tmp); 147 mr_free(tmp); 142 148 res++; 143 149 } 144 150 /* is format sensible? */ 145 151 if (!is_this_a_valid_disk_format(mountlist->el[pos].format)) { 146 sprintf(tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);152 mr_asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format); 147 153 log_it(tmp); 148 154 strcat(flaws_str, tmp); 155 mr_free(tmp); 149 156 res++; 150 157 } 151 158 amount_allocated += mountlist->el[pos].size / 1024; 152 159 prev_sp_no = cur_sp_no; 160 161 mr_free(device); 153 162 } 154 163 } … … 156 165 npos = pos = 0; 157 166 for (curr_part_no = 1; curr_part_no < 99; curr_part_no++) { 158 sprintf(device, "%ss%d", drive, curr_part_no);167 mr_asprintf(&device, "%ss%d", drive, curr_part_no); 159 168 pos = find_device_in_mountlist(mountlist, device); 160 169 npos = 0; 161 170 for (cur_sp_no = 'a'; cur_sp_no <= 'h'; cur_sp_no++) { 162 sprintf(device, "%ss%i%c", device, curr_part_no, cur_sp_no);163 if (find_device_in_mountlist(mountlist, device) >= 0)171 mr_asprintf(&ndevice, "%ss%d%c", device, curr_part_no, cur_sp_no); 172 if (find_device_in_mountlist(mountlist, ndevice) >= 0) 164 173 npos++; 165 } 174 mr_free(ndevice); 175 } 176 mr_free(device); 177 166 178 if (((pos >= 0) || npos) && foundsome) { 167 179 sprintf(flaws_str + strlen(flaws_str), … … 170 182 } 171 183 172 sprintf(device, "%ss%d", drive, curr_part_no);173 strcpy(mountpoint, mountlist->el[pos].mountpoint);184 mr_asprintf(&device, "%ss%d", drive, curr_part_no); 185 // BERLIOS : useless ? mr_asprintf(&mountpoint, mountlist->el[pos].mountpoint); 174 186 if (pos > 0 && !npos) { 175 187 /* gap in the partition list? */ 176 188 if (curr_part_no - prev_part_no > 1) { 177 189 if (prev_part_no == 0) { 178 sprintf(tmp, " Gap prior to %s.", device);190 mr_asprintf(&tmp, " Gap prior to %s.", device); 179 191 log_it(tmp); 180 192 strcat(flaws_str, tmp); 193 mr_free(tmp); 181 194 res++; 182 195 } else if (curr_part_no > 5 183 196 || (curr_part_no <= 4 && prev_part_no > 0)) { 184 sprintf(tmp, " Gap between %ss%d and %d.", drive,185 prev_part_no, curr_part_no);197 mr_asprintf(&tmp, " Gap between %ss%d and %d.", drive, 198 prev_part_no, curr_part_no); 186 199 log_it(tmp); 187 200 strcat(flaws_str, tmp); 201 mr_free(tmp); 188 202 res++; 189 203 } … … 194 208 if ((curr_part_no >= 5 && prev_part_no == 4) 195 209 && (strcmp(part_table_fmt, "MBR") == 0)) { 196 sprintf(tmp, " Partition %ss4 is occupied.", drive);210 mr_asprintf(&tmp, " Partition %ss4 is occupied.", drive); 197 211 log_it(tmp); 198 212 strcat(flaws_str, tmp); 213 mr_free(tmp); 199 214 res++; 200 215 } … … 207 222 } 208 223 if (device_copies > 1) { 209 sprintf(tmp, " %s %s's.", number_to_text(device_copies),210 device);224 mr_asprintf(&tmp, " %s %s's.", number_to_text(device_copies), 225 device); 211 226 if (!strstr(flaws_str, tmp)) { 212 227 log_it(tmp); … … 214 229 res++; 215 230 } 231 mr_free(tmp); 216 232 } 217 233 /* silly partition size? */ 218 234 if (mountlist->el[pos].size < 8192 219 235 && strcmp(mountlist->el[pos].mountpoint, "lvm")) { 220 sprintf(tmp, " %s is tiny!", device);236 mr_asprintf(&tmp, " %s is tiny!", device); 221 237 log_it(tmp); 222 238 strcat(flaws_str, tmp); 239 mr_free(tmp); 223 240 res++; 224 241 } … … 230 247 && strcmp(mountlist->el[pos].mountpoint, "none") 231 248 && mountlist->el[pos].mountpoint[0] != '/') { 232 sprintf(tmp, " %s has a weird mountpoint.", device);249 mr_asprintf(&tmp, " %s has a weird mountpoint.", device); 233 250 log_it(tmp); 234 251 strcat(flaws_str, tmp); 252 mr_free(tmp); 235 253 res++; 236 254 } 237 255 /* is format sensible? */ 238 256 if (!is_this_a_valid_disk_format(mountlist->el[pos].format)) { 239 sprintf(tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);257 mr_asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format); 240 258 log_it(tmp); 241 259 strcat(flaws_str, tmp); 260 mr_free(tmp); 242 261 res++; 243 262 } … … 245 264 /* Check subpartitions */ 246 265 for (cur_sp_no = 'a'; cur_sp_no < 'z'; ++cur_sp_no) { 247 sprintf(device, "%ss%d%c", drive, curr_part_no, cur_sp_no);266 mr_asprintf(&device, "%ss%d%c", drive, curr_part_no, cur_sp_no); 248 267 pos = find_device_in_mountlist(mountlist, device); 249 268 if (pos < 0) { 250 269 continue; 251 270 } 252 strcpy(mountpoint, mountlist->el[pos].mountpoint);271 // BERLIOS : useless ? mr_asprintf(&mountpoint, mountlist->el[pos].mountpoint); 253 272 /* is it too big? */ 254 273 if (curr_part_no > 'h') { 255 sprintf(tmp, " Can only have up to 'h' in disklabel."); 274 mr_asprintf(&tmp, 275 " Can only have up to 'h' in disklabel."); 256 276 log_it(tmp); 257 277 strcat(flaws_str, tmp); 278 mr_free(tmp); 258 279 res++; 259 280 } … … 266 287 } 267 288 if (device_copies > 1) { 268 sprintf(tmp, " %s %s's.",269 number_to_text(device_copies), device);289 mr_asprintf(&tmp, " %s %s's.", 290 number_to_text(device_copies), device); 270 291 if (!strstr(flaws_str, tmp)) { 271 292 log_it(tmp); … … 273 294 res++; 274 295 } 296 mr_free(tmp); 275 297 } 276 298 /* silly partition size? */ 277 299 if (mountlist->el[pos].size < 8192 278 300 && strcmp(mountlist->el[pos].mountpoint, "lvm")) { 279 sprintf(tmp, " %s is tiny!", device);301 mr_asprintf(&tmp, " %s is tiny!", device); 280 302 log_it(tmp); 281 303 strcat(flaws_str, tmp); 304 mr_free(tmp); 282 305 res++; 283 306 } … … 289 312 && strcmp(mountlist->el[pos].mountpoint, "none") 290 313 && mountlist->el[pos].mountpoint[0] != '/') { 291 sprintf(tmp, " %s has a weird mountpoint.", device);314 mr_asprintf(&tmp, " %s has a weird mountpoint.", device); 292 315 log_it(tmp); 293 316 strcat(flaws_str, tmp); 317 mr_free(tmp); 294 318 res++; 295 319 } … … 297 321 if (!is_this_a_valid_disk_format 298 322 (mountlist->el[pos].format)) { 299 sprintf(tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);323 mr_asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format); 300 324 log_it(tmp); 301 325 strcat(flaws_str, tmp); 326 mr_free(tmp); 302 327 res++; 303 328 } … … 306 331 } 307 332 } 333 mr_free(device); 308 334 309 335 /* OK, continue with main loop */ … … 315 341 if (amount_allocated > physical_drive_size) // Used to be +1, but what if you're 1 MB too high? 316 342 { 317 sprintf(tmp, " %ld MB over-allocated on %s.",318 amount_allocated - physical_drive_size, drive);343 mr_asprintf(&tmp, " %ld MB over-allocated on %s.", 344 amount_allocated - physical_drive_size, drive); 319 345 log_it(tmp); 320 346 strcat(flaws_str, tmp); 347 mr_free(tmp); 321 348 res++; 322 349 } else if (amount_allocated < physical_drive_size - 1) { /* NOT AN ERROR, JUST A WARNING :-) */ 323 sprintf(tmp, " %ld MB unallocated on %s.",324 physical_drive_size - amount_allocated, drive);350 mr_asprintf(&tmp, " %ld MB unallocated on %s.", 351 physical_drive_size - amount_allocated, drive); 325 352 log_it(tmp); 326 353 strcat(flaws_str, tmp); 354 mr_free(tmp); 327 355 /* BERLIOS: Flawed since rev 1 !! */ 328 356 res++; … … 349 377 350 378 /*@ buffers ******************************************************** */ 351 char *tmp ;352 char * device;353 char * mountpoint;379 char *tmp = NULL; 380 char *tmp1 = NULL; 381 char *device = NULL; 354 382 355 383 /*@ long *********************************************************** */ 356 long physical_drive_size = 0 ;357 long amount_allocated = 0 ;384 long physical_drive_size = 0L; 385 long amount_allocated = 0L; 358 386 359 387 /*@ pointers ******************************************************* */ 360 char *part_table_fmt ;388 char *part_table_fmt = NULL; 361 389 362 390 /*@ initialize ***************************************************** */ … … 365 393 assert(flaws_str != NULL); 366 394 367 malloc_string(tmp);368 malloc_string(device);369 malloc_string(mountpoint);370 395 flaws_str[0] = '\0'; 371 396 prev_part_no = 0; 372 tmp[0] = '\0';373 374 397 375 398 physical_drive_size = get_phys_size_of_drive(drive); 376 399 377 400 if (physical_drive_size < 0) { 378 sprintf(tmp, " %s does not exist.", drive);401 mr_asprintf(&tmp, " %s does not exist.", drive); 379 402 strcat(flaws_str, tmp); 380 403 res++; 381 404 mr_msg(1, tmp); 382 goto endoffunc; 405 mr_free(tmp); 406 return (FALSE); 383 407 } else { 384 sprintf(tmp, "%s is %ld MB", drive, physical_drive_size);408 mr_asprintf(&tmp, "%s is %ld MB", drive, physical_drive_size); 385 409 log_it(tmp); 410 mr_free(tmp); 386 411 } 387 412 388 413 for (curr_part_no = 1; curr_part_no < 99; curr_part_no++) { 389 sprintf(device, "%s%d", drive, curr_part_no);414 mr_asprintf(&device, "%s%d", drive, curr_part_no); 390 415 pos = find_device_in_mountlist(mountlist, device); 391 416 if (pos < 0) { … … 393 418 } 394 419 if (physical_drive_size < 0) { 395 sprintf(tmp, " %s refers to non-existent hardware.", device);420 mr_asprintf(&tmp, " %s refers to non-existent hardware.", device); 396 421 strcat(flaws_str, tmp); 397 422 res++; 423 mr_free(tmp); 398 424 continue; 399 425 } 400 strcpy(mountpoint, mountlist->el[pos].mountpoint);426 // BERLIOS : useless ? str-cpy(mountpoint, mountlist->el[pos].mountpoint); 401 427 /* gap in the partition list? */ 402 428 if (curr_part_no - prev_part_no > 1) { 403 429 if (prev_part_no == 0) { 404 sprintf(tmp, " Gap prior to %s.", device);430 mr_asprintf(&tmp, " Gap prior to %s.", device); 405 431 log_it(tmp); 406 432 strcat(flaws_str, tmp); 433 mr_free(tmp); 407 434 res++; 408 435 } else if (curr_part_no > 5 409 436 || (curr_part_no <= 4 && prev_part_no > 0)) { 410 sprintf(tmp, " Gap between %s%d and %d.", drive,437 mr_asprintf(&tmp, " Gap between %s%d and %d.", drive, 411 438 prev_part_no, curr_part_no); 412 439 log_it(tmp); 413 440 strcat(flaws_str, tmp); 441 mr_free(tmp); 414 442 res++; 415 443 } … … 420 448 if ((curr_part_no >= 5 && prev_part_no == 4) 421 449 && (strcmp(part_table_fmt, "MBR") == 0)) { 422 sprintf(tmp, " Partition %s4 is occupied.", drive);450 mr_asprintf(&tmp, " Partition %s4 is occupied.", drive); 423 451 log_it(tmp); 424 452 strcat(flaws_str, tmp); 453 mr_free(tmp); 425 454 res++; 426 455 } … … 433 462 } 434 463 if (device_copies > 1) { 435 sprintf(tmp, " %s %s's.", number_to_text(device_copies),436 device);464 mr_asprintf(&tmp, " %s %s's.", number_to_text(device_copies), 465 device); 437 466 if (!strstr(flaws_str, tmp)) { 438 467 log_it(tmp); … … 440 469 res++; 441 470 } 471 mr_free(tmp); 442 472 } 443 473 /* silly partition size? */ 444 474 if (mountlist->el[pos].size < 8192 445 475 && strcmp(mountlist->el[pos].mountpoint, "lvm")) { 446 sprintf(tmp, " %s is tiny!", device);476 mr_asprintf(&tmp, " %s is tiny!", device); 447 477 log_it(tmp); 448 478 strcat(flaws_str, tmp); 479 mr_free(tmp); 449 480 res++; 450 481 } … … 455 486 && strcmp(mountlist->el[pos].mountpoint, "image") 456 487 && mountlist->el[pos].mountpoint[0] != '/') { 457 sprintf(tmp, " %s has a weird mountpoint.", device);488 mr_asprintf(&tmp, " %s has a weird mountpoint.", device); 458 489 log_it(tmp); 459 490 strcat(flaws_str, tmp); 491 mr_free(tmp); 460 492 res++; 461 493 } 462 494 /* is format sensible? */ 463 495 if (!is_this_a_valid_disk_format(mountlist->el[pos].format)) { 464 sprintf(tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);496 mr_asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format); 465 497 log_it(tmp); 466 498 strcat(flaws_str, tmp); 499 mr_free(tmp); 467 500 res++; 468 501 } … … 470 503 amount_allocated += mountlist->el[pos].size / 1024; 471 504 prev_part_no = curr_part_no; 505 mr_free(device); 472 506 } 473 507 474 508 /* Over-allocated the disk? Unallocated space on disk? */ 475 509 if (amount_allocated > physical_drive_size + 1) { 476 sprintf(tmp, " %ld MB over-allocated on %s.",477 amount_allocated - physical_drive_size, drive);510 mr_asprintf(&tmp, " %ld MB over-allocated on %s.", 511 amount_allocated - physical_drive_size, drive); 478 512 log_it(tmp); 479 513 strcat(flaws_str, tmp); 514 mr_free(tmp); 480 515 res++; 481 516 } else if (amount_allocated < physical_drive_size - 1) { /* NOT AN ERROR, JUST A WARNING :-) */ 482 sprintf(tmp, " %ld MB unallocated on %s.",483 physical_drive_size - amount_allocated, drive);517 mr_asprintf(&tmp, " %ld MB unallocated on %s.", 518 physical_drive_size - amount_allocated, drive); 484 519 log_it(tmp); 485 520 strcat(flaws_str, tmp); 486 /* BERLIOS: Flawed since rev 1 !! */ 521 mr_free(tmp); 522 /* BERLIOS: Flawed since rev 1 !! - Is it sure ?? */ 487 523 res++; 488 524 } 489 490 endoffunc:491 mr_free(tmp);492 mr_free(device);493 mr_free(mountpoint);494 525 495 526 if (res) { … … 500 531 } 501 532 #endif 502 503 533 504 534 … … 519 549 520 550 /*@ buffer *********************************************************** */ 521 struct list_of_disks *drivelist; 522 char *tmp; 523 char *flaws_str; 551 struct list_of_disks *drivelist = NULL; 552 char *tmp = NULL; 553 char *tmp1 = NULL; 554 char *flaws_str = NULL; 524 555 525 556 /*@ int ************************************************************** */ … … 559 590 } 560 591 res += look_for_duplicate_mountpoints(mountlist, flaws_str); 561 /* res+=look_for_weird_formats(mountlist,flaws_str); .. not necessary, now that we can check to see562 which formarts are actually _supported_ by the kernel */563 /* log_it(flaws_str); */564 592 return (spread_flaws_across_three_lines 565 593 (flaws_str, flaws_str_A, flaws_str_B, flaws_str_C, res)); … … 580 608 /*@ int ************************************************************** */ 581 609 int i = 0; 582 char *tmp;583 char *flaws_str;584 585 malloc_string(tmp);586 malloc_string(flaws_str);587 610 588 611 assert(mountlist != NULL); … … 592 615 && strcmp(mountlist->el[i].device, device) != 0; i++); 593 616 594 mr_free(tmp);595 mr_free(flaws_str);596 597 617 if (i == mountlist->entries) { 598 618 return (-1); … … 601 621 } 602 622 } 603 604 605 606 623 607 624 … … 625 642 626 643 /*@ buffetr ********************************************************* */ 627 char *curr_mountpoint; 628 char *tmp; 629 630 malloc_string(curr_mountpoint); 631 malloc_string(tmp); 644 char *curr_mountpoint = NULL; 645 char *tmp = NULL; 646 char *tmp1 = NULL; 647 632 648 assert(mountlist != NULL); 633 649 assert(flaws_str != NULL); 650 634 651 for (currline = 0; currline < mountlist->entries; currline++) { 635 strcpy(curr_mountpoint, mountlist->el[currline].mountpoint);652 mr_asprintf(&curr_mountpoint, mountlist->el[currline].mountpoint); 636 653 for (i = 0, copies = 0, last_copy = -1; i < mountlist->entries; 637 654 i++) { … … 645 662 if (copies > 1 && last_copy == currline 646 663 && strcmp(curr_mountpoint, "raid")) { 647 sprintf(tmp, " %s %s's.", number_to_text(copies),664 mr_asprintf(&tmp, " %s %s's.", number_to_text(copies), 648 665 curr_mountpoint); 649 666 strcat(flaws_str, tmp); 650 667 log_it(tmp); 668 mr_free(tmp); 651 669 res++; 652 670 } 653 } 654 mr_free(curr_mountpoint); 655 mr_free(tmp); 671 mr_free(curr_mountpoint); 672 } 656 673 return (res); 657 674 } 658 659 /**660 * Look for strange formats. Does not respect /proc/filesystems.661 * @param mountlist The mountlist to check.662 * @param flaws_str The flaws string to append the results to.663 * @return The number of weird formats found, or 0 for success.664 * @bug Seems orphaned; please remove.665 */666 int667 look_for_weird_formats(struct mountlist_itself *mountlist, char *flaws_str)668 {669 670 /*@ int ************************************************************* */671 int i = 0;672 int res = 0;673 674 /*@ buffers ********************************************************* */675 char *tmp;676 char *format_sz;677 678 malloc_string(tmp);679 malloc_string(format_sz);680 681 assert(mountlist != NULL);682 assert(flaws_str != NULL);683 684 for (i = 0; i < mountlist->entries; i++) {685 sprintf(format_sz, " %s ", mountlist->el[i].format);686 if (!strstr(SANE_FORMATS, format_sz)687 && strcmp(mountlist->el[i].mountpoint, "image") != 0) {688 sprintf(tmp, " %s has unknown format.",689 mountlist->el[i].device);690 log_it(tmp);691 strcat(flaws_str, tmp);692 res++;693 } else if ((!strcmp(mountlist->el[i].format, "swap")694 && strcmp(mountlist->el[i].mountpoint, "swap")695 && strcmp(mountlist->el[i].mountpoint, "none"))696 || (strcmp(mountlist->el[i].format, "swap")697 && !strcmp(mountlist->el[i].mountpoint, "swap")698 && !strcmp(mountlist->el[i].mountpoint, "none"))) {699 sprintf(tmp, " %s is half-swap.", mountlist->el[i].device);700 log_it(tmp);701 strcat(flaws_str, tmp);702 res++;703 }704 }705 mr_free(tmp);706 mr_free(format_sz);707 return (res);708 }709 710 675 711 676 … … 727 692 728 693 /*@ buffers ********************************************************* */ 729 char *drive; 730 char *tmp; 694 char *drive = NULL; 731 695 732 696 long long size; 733 697 734 malloc_string(drive);735 malloc_string(tmp);736 698 assert(mountlist != NULL); 737 699 assert(drivelist != NULL); … … 739 701 for (lino = 0, noof_drives = 0; lino < mountlist->entries; lino++) { 740 702 741 strcpy(drive, mountlist->el[lino].device);703 mr_asprintf(&drive, mountlist->el[lino].device); 742 704 if (!strncmp(drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) { 743 sprintf(tmp, 744 "Not putting %s in list of drives: it's a virtual drive", 745 drive); 746 mr_msg(8, tmp); 705 mr_msg(8, "Not putting %s in list of drives: it's a virtual drive", drive); 747 706 continue; 748 707 } … … 750 709 size = mountlist->el[lino].size; 751 710 if (size == 0) { 752 sprintf(tmp, 753 "Not putting %s in list of drives: it has zero size (maybe an LVM volume)", 754 drive); 755 mr_msg(8, tmp); 711 mr_msg(8, "Not putting %s in list of drives: it has zero size (maybe an LVM volume)", drive); 756 712 continue; 757 713 } 758 714 759 /* 760 for (i = strlen (drive); isdigit (drive[i - 1]); i--); 761 drive[i] = '\0'; 762 if (get_phys_size_of_drive (drive) <= 0 && drive[i - 1] == 'p') 763 { 764 i--; 765 drive[i] = '\0'; 766 } 767 for (j = 0; j < noof_drives && strcmp (drivelist[j], drive) != 0; j++); 768 */ 769 770 sprintf(tmp, 771 "Putting %s with size %lli in list of drives", 772 drive, size); 773 mr_msg(8, tmp); 715 mr_msg(8, "Putting %s with size %lli in list of drives", drive, size); 774 716 775 717 (void) truncate_to_drive_name(drive); … … 781 723 strcpy(drivelist->el[noof_drives++].device, drive); 782 724 } 725 mr_free(drive); 726 783 727 } 784 728 drivelist->entries = noof_drives; 785 729 mr_msg(8, "Made list of drives"); 786 mr_free(drive);787 mr_free(tmp);788 730 789 731 return (noof_drives); 790 732 } 791 792 793 794 795 733 796 734 … … 816 754 817 755 /*@ buffers ********************************************************* */ 818 char *tmp; 819 820 malloc_string(tmp); 756 char *tmp = NULL; 757 821 758 assert(output_list != NULL); 822 759 assert(mountlist != NULL); … … 836 773 (void *) &mountlist->el[i], 837 774 sizeof(struct mountlist_line)); 838 sprintf(tmp, 839 "%s is available; user may choose to add it to raid device", 840 output_list->el[items - 1].device); 841 log_it(tmp); 775 mr_asprintf(&tmp, 776 "%s is available; user may choose to add it to raid device", 777 output_list->el[items - 1].device); 778 log_it(tmp); 779 mr_free(tmp); 842 780 } 843 781 } … … 845 783 output_list->entries = items; 846 784 log_it("MLUORP -- ending"); 847 mr_free(tmp); 848 } 849 850 851 785 } 852 786 853 787 … … 878 812 } 879 813 } 880 881 882 814 883 815 … … 894 826 int load_mountlist(struct mountlist_itself *mountlist, char *fname) 895 827 { 896 FILE *fin ;828 FILE *fin = NULL; 897 829 /* malloc ** */ 898 char *incoming; 899 char *siz; 900 char *tmp; 901 char *p; 902 903 int items; 904 int j; 830 char *incoming = NULL; 831 char *siz = NULL; 832 char *tmp = NULL; 833 char *p = NULL; 834 835 int items = 0; 836 int j = 0; 837 size_t n = 0; 905 838 906 839 assert(mountlist != NULL); 907 840 assert_string_is_neither_NULL_nor_zerolength(fname); 908 malloc_string(incoming); 909 malloc_string(siz); 910 malloc_string(tmp); 841 911 842 if (!(fin = fopen(fname, "r"))) { 912 843 log_it("Unable to open mountlist - '%s'", fname); 913 log_to_screen("Cannot open mountlist"); 914 mr_free(incoming); 915 mr_free(siz); 916 mr_free(tmp); 844 log_to_screen(_("Cannot open mountlist")); 917 845 return (1); 918 846 } 919 items = 0;920 (void) fgets(incoming, MAX_STR_LEN - 1, fin);847 malloc_string(siz); 848 mr_getline(&incoming, &n, fin); 921 849 log_it("Loading mountlist..."); 922 850 while (!feof(fin)) { … … 947 875 "Ignoring %s in mountlist - not loading that line :) ", 948 876 mountlist->el[items].device); 949 (void) fgets(incoming, MAX_STR_LEN - 1, fin);877 mr_getline(&incoming, &n, fin); 950 878 continue; 951 879 } … … 954 882 && mountlist->el[items].device[0] != '#') { 955 883 if (items >= ARBITRARY_MAXIMUM) { 956 log_to_screen( "Too many lines in mountlist.. ABORTING");884 log_to_screen(_("Too many lines in mountlist.. ABORTING")); 957 885 finish(1); 958 886 } … … 963 891 if (j < items) { 964 892 strcat(mountlist->el[items].device, "_dup"); 965 sprintf(tmp, 966 "Duplicate entry in mountlist - renaming to %s", 967 mountlist->el[items].device); 968 log_it(tmp); 969 } 970 strcpy(tmp, mountlist->el[items].device); 893 mr_asprintf(&tmp, 894 "Duplicate entry in mountlist - renaming to %s", 895 mountlist->el[items].device); 896 log_it(tmp); 897 mr_free(tmp); 898 } 899 mr_asprintf(&tmp, mountlist->el[items].device); 971 900 if (strstr(tmp, "/dev/md/")) { 972 901 log_it("format_device() --- Contracting %s", tmp); … … 981 910 strcpy(mountlist->el[items].device, tmp); 982 911 } 983 984 sprintf(tmp, 985 "%s %s %s %lld %s", 986 mountlist->el[items].device, 987 mountlist->el[items].mountpoint, 988 mountlist->el[items].format, 989 mountlist->el[items].size, mountlist->el[items].label); 990 991 log_it(tmp); 912 mr_free(tmp); 913 914 log_it("%s %s %s %lld %s", 915 mountlist->el[items].device, 916 mountlist->el[items].mountpoint, 917 mountlist->el[items].format, 918 mountlist->el[items].size, 919 mountlist->el[items].label); 992 920 items++; 993 921 } 994 (void) fgets(incoming, MAX_STR_LEN - 1, fin);922 mr_getline(&incoming, &n, fin); 995 923 } 996 924 paranoid_fclose(fin); 925 mr_free(incoming); 997 926 mountlist->entries = items; 998 927 999 928 log_it("Mountlist loaded successfully."); 1000 sprintf(tmp, "%d entries in mountlist", items); 1001 log_it(tmp); 1002 mr_free(incoming); 929 log_it("%d entries in mountlist", items); 930 1003 931 mr_free(siz); 1004 mr_free(tmp);1005 932 return (0); 1006 933 } 1007 1008 934 1009 935 … … 1038 964 return (0); 1039 965 } 1040 1041 966 1042 967 … … 1066 991 } 1067 992 993 1068 994 /** 1069 995 * Sort the mountlist alphabetically by mountpoint. … … 1105 1031 { 1106 1032 /*@ mallocs *** */ 1107 char device[64];1108 char mountpoint[256];1109 char format[64];1033 char *device = NULL; 1034 char *mountpoint = NULL; 1035 char *format = NULL; 1110 1036 1111 1037 long long size; … … 1115 1041 assert(b >= 0); 1116 1042 1117 strcpy(device, mountlist->el[a].device);1118 strcpy(mountpoint, mountlist->el[a].mountpoint);1119 strcpy(format, mountlist->el[a].format);1043 mr_asprintf(&device, mountlist->el[a].device); 1044 mr_asprintf(&mountpoint, mountlist->el[a].mountpoint); 1045 mr_asprintf(&format, mountlist->el[a].format); 1120 1046 1121 1047 size = mountlist->el[a].size; … … 1132 1058 1133 1059 mountlist->el[b].size = size; 1060 mr_free(device); 1061 mr_free(mountpoint); 1062 mr_free(format); 1134 1063 } 1135 1064
Note:
See TracChangeset
for help on using the changeset viewer.