Changeset 30237
- Timestamp:
- Jan 11, 2011, 6:12:09 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20101205/Ohana/src/tools/src/roc.c
r29938 r30237 4 4 # include <regex.h> 5 5 6 # define myAssert(LOGIC, MSG) { if (!(LOGIC)) { fprintf (stderr, "%s\n", MSG); abort(); } }6 # define myAssert(LOGIC,...) { if (!(LOGIC)) { fprintf (stderr, __VA_ARGS__); abort(); } } 7 7 8 8 # define ROC_HEADER_SIZE 0x1000 … … 14 14 int roc_insert (int argc, char **argv); 15 15 int roc_delete (int argc, char **argv); 16 int roc_validate (int argc, char **argv); 17 16 18 int usage (void); 17 19 int print_block (char *header, int *header_size, int *Noff, char *format,...); … … 28 30 if (!strcasecmp(argv[1], "-insert")) roc_insert (argc, argv); 29 31 if (!strcasecmp(argv[1], "-delete")) roc_delete (argc, argv); 32 if (!strcasecmp(argv[1], "-validate")) roc_validate (argc, argv); 30 33 31 34 usage(); … … 286 289 } 287 290 291 int roc_validate (int argc, char **argv) { 292 293 int i, j, n, Ninput, Nblocks, header_size, Nbytes, Nread; 294 off_t *sizes, *bytes_read; 295 char value; 296 char *header, *line, *ptr; 297 char **inputName, *targetName; 298 char **inputData; 299 char *targetData; 300 FILE **input, *target; 301 302 if (argc != 3) usage(); 303 304 305 /* find the md5 sum for each input file (ADD LATER) 306 * find the size of the input files 307 * define the output file size = MAX(sizes) 308 * create the target file header 309 */ 310 311 // the output file 312 targetName = argv[2]; 313 314 target = fopen(targetName, "r"); 315 myAssert (target, "failed to open roc datafile %s\n",targetName); 316 317 ALLOCATE (line, char, 1024); 318 319 scan_line (target, line); 320 myAssert (!strncmp(line, "ROC Version 0", strlen("ROC Verion 0")), "invalid ROC file or format"); 321 322 scan_line (target, line); 323 sscanf (line, "HEADER SIZE %x", &header_size); 324 325 ALLOCATE (header, char, header_size); 326 327 // read the full header 328 fseeko (target, 0, SEEK_SET); 329 fread (header, 1, header_size, target); 330 331 ptr = header; 332 ptr = strchr (ptr, '\n'); ptr ++; // ROC Version 333 ptr = strchr (ptr, '\n'); ptr ++; // HEADER SIZE 334 335 sscanf (ptr, "N_FILES %d", &Ninput); ptr = strchr (ptr, '\n'); ptr ++; 336 sscanf (ptr, "N_BLOCKS %d", &Nblocks); ptr = strchr (ptr, '\n'); ptr ++; 337 338 // the input files 339 ALLOCATE (inputName, char *, Ninput); 340 ALLOCATE (sizes, off_t, Ninput); 341 ALLOCATE (bytes_read, off_t, Ninput); 342 for (i = 0; i < Ninput; i++) { 343 ALLOCATE (inputName[i], char, 1024); 344 sscanf (ptr, "%*s : %s", inputName[i]); ptr = strchr (ptr, '\n'); ptr ++; 345 ptr = strchr (ptr, '\n'); ptr ++; // BASE 346 sscanf (ptr, "%*s : "OFF_T_FMT, &sizes[i]); ptr = strchr (ptr, '\n'); ptr ++; 347 ptr = strchr (ptr, '\n'); ptr ++; // MD5 348 bytes_read[i] = 0; 349 } 350 351 ALLOCATE (input, FILE *, Ninput); 352 for (i = 0; i < Ninput; i++) { 353 input[i] = fopen(inputName[i], "r"); 354 myAssert (input[i], "failed to open file %s\n",inputName[i]); 355 } 356 357 ALLOCATE (inputData, char *, Ninput); 358 ALLOCATE (targetData, char, ROC_BLOCKSIZE); 359 for (i = 0; i < Ninput; i++) { 360 ALLOCATE (inputData[i], char, ROC_BLOCKSIZE); 361 } 362 363 for (n = 0; n < Nblocks; n++) { 364 for (i = 0; i < Ninput; i++) { 365 Nread = MIN (ROC_BLOCKSIZE, sizes[i] - bytes_read[i]); 366 Nbytes = fread (inputData[i], 1, Nread, input[i]); 367 myAssert (Nbytes == Nread, "failed to read data file: %s read: %d expect: %d prev_read: %d block: %d\n",inputName[i],Nbytes,Nread,(int) bytes_read[i],n); 368 if (Nread < ROC_BLOCKSIZE) { 369 // if we have reached the end of the file, fill in the rest with NULLs 370 memset (&inputData[i][Nread], 0, ROC_BLOCKSIZE - Nread); 371 } 372 bytes_read[i] += Nread; 373 } 374 fread (targetData, 1, ROC_BLOCKSIZE, target); 375 376 for (j = 0; j < ROC_BLOCKSIZE; j++) { 377 value = targetData[j]; 378 for (i = 0; i < Ninput; i++) { 379 value = value ^ inputData[i][j]; 380 } 381 myAssert(value == 0, "validation failed on block %d and byte %d\n",n,j); 382 } 383 384 } 385 386 for (i = 0; i < Ninput; i++) { 387 fclose(input[i]); 388 } 389 390 fclose (target); 391 392 fprintf (stderr, "validation: %s appears correct.\n",targetName); 393 exit (0); 394 } 395 288 396 int roc_insert (int argc, char **argv) { 289 397 … … 318 426 fprintf (stderr, " -create (target) (input) (input) (input) ... [options]\n"); 319 427 fprintf (stderr, " -repair (target) (file #) (output\n"); 428 fprintf (stderr, " -validate (target)\n"); 320 429 fprintf (stderr, " -insert (target) (input)\n"); 321 430 fprintf (stderr, " -delete (target) (file)\n"); 431 322 432 exit (2); 323 433 }
Note:
See TracChangeset
for help on using the changeset viewer.
