static bool process_file(char *filename)
{
  int i;
  wave_info *info;
  bool success;

  if (NULL == (info = new_wave_info(filename)))
    st_error("cannot continue due to error(s) shown above");

  input_is_cd_quality = (PROB_NOT_CD(info) ? FALSE : TRUE);

  get_extractable_tracks();

  if (repeated_split_point)
    read_split_points_repeated(info);
  else
    read_split_points_file(info);

  if (files[numfiles-2]->beginning_byte > info->data_size)
    st_error("split points go beyond input file's data size");

  if (files[numfiles-2]->beginning_byte == info->data_size) {
    st_free(files[numfiles-1]);
    numfiles--;
  }
  else {
    files[numfiles-1]->beginning_byte = info->data_size;
    files[numfiles-1]->data_size = info->data_size - files[numfiles-2]->beginning_byte;

    adjust_splitfile(numfiles-1);
  }

  success = split_file(info);

  for (i=0;i<numfiles;i++)
    st_free(files[i]);

  st_free(info);

  return success;
}
Exemplo n.º 2
0
int main ( int argc, char **argv )

/******************************************************************************/
/*
  Purpose:

    MAIN is the main program for F90SPLIT.

  Modified:

    05 December 2007
*/
{
  FILE *file_input;
  int i;

  for ( i = 1; i < argc ; ++i ) 
  {    
    printf ( "Splitting %s.\n", argv[i] );

    file_input = fopen ( argv[i], "r" );

    if ( file_input == NULL ) 
    {
      fprintf ( stderr, "\n" );
      fprintf ( stderr, "FSPLIT90: Error!\n" );
      fprintf ( stderr, "  Cannot open %s\n", argv[i] );
    }
    else
    {
      split_file ( file_input );
      ( void ) fclose ( file_input );
    }
  }

  return 0;
}
Exemplo n.º 3
0
int main (int argc, char **argv) {

	char			*filename,
				*usersize;
	int			ret;
	unsigned long int	size;
	size_t			len;


	if (argc < 3) {

		displayHelpOptions(argv[0]);
		exit (1);
	}

	if (!strcmp(argv[1], "-s")) {

		if (argc != 4)	{

			displayHelpOptions(argv[0]);
			exit (1);
		}

		if (argv[3][0] == '-') {
			printf("\n\tTransEase 1.0\n\n");
			printf("\t\tSplit size cannot be a negative number!\n\n");
			exit (1);
		}

		len = strlen(argv[3]);
		usersize = (char *)malloc((len + 1) * sizeof(char));
		strncpy(usersize, argv[3], len);
		
		if ((argv[3][len - 1] == 'M') || (argv[3][len - 1] == 'm')) {

			usersize[len - 1] = '\0';
			size = strtoul(usersize, NULL, 10);
			size *= 1024 * 1024;
		
		} else if ((argv[3][len - 1] == 'K') || (argv[3][len - 1] == 'k')) {

			usersize[len - 1] = '\0';
			size = strtoul(usersize, NULL, 10);
			size *= 1024;

		} else if ((argv[3][len - 1] == 'B' || argv[3][len - 1] == 'b')) {

			usersize[len - 1] = '\0';
			size = strtoul(usersize, NULL, 10);

		}else if (isdigit(argv[3][len - 1])) {

			size = strtoul(usersize, NULL, 10);

		} else {
			printf("\n\tTransEase 1.0\n\n");
			printf("\t\tPlease specify the size correctly!\n\n");
			displayHelpOptions(argv[0]);
			exit (1);
		}

		
		if (size == 0) {
			printf("\n\tTransEase 1.0\n\n");
			printf("\t\tInvalid split size (0) \n\n");
			exit (1);
		}

		if (size > MAX_SPLITSIZE) { /*MAX_SPLITSIZE is defined in configuration.h */
			printf("\n\tTransEase 1.0\n\n");
			printf("\t\tSplit size can be %lu bytes at maximum!\n\n", (uoff_t)MAX_SPLITSIZE);
			exit (1);
		}

		filename = strdup(argv[2]);

		ret = split_file(filename, size);

		exit (ret);
	
	} else if (!strcmp(argv[1], "-j")) {

		if (argc != 3) {
			displayHelpOptions(argv[0]);
			exit (1);
		}

		filename = strdup(argv[2]);
		ret = merge_files(filename);
		exit (ret);
	
	} else{
		printf("\n\tTransEase 1.0\n\n");
		printf("\t\tWhatch Wanna Do ?\n");
		displayHelpOptions(argv[0]);
		exit (1);

	}
	exit (0);
}
Exemplo n.º 4
0
int main(void)
{
    unsigned long bs;
    int i, status;
    FILE *fp[5] = {NULL, NULL, NULL, NULL, NULL};
    char *filename[] = {"test_raid5.dat",
                        "test_raid5.dev0.dat",
                        "test_raid5.dev1.dat",
                        "test_raid5.dev2.dat",
                        "test_raid5.out.dat",
                        "test_raid5.meta.dat",
                        "test_raid5.move.dat"
                       };

#if CHECKING == 1
    unsigned char *ascii = NULL;
    char *assumed[] = {"3b6f5cf4c8c3e8b6c6894da81c1fcea588db14d088c5970c1b98faed940b2ce4",
                       "",
                       "7d325d944a81a11c86b904ddd113d418bb1de188db55a14654cc489cb761f011",
                       "ea9a1b730b11572714cedc1cdf3d3dd31b37283b608587661edf6e781c05f5fe",
                       "3b6f5cf4c8c3e8b6c6894da81c1fcea588db14d088c5970c1b98faed940b2ce4",
                       "27a24e8b433337896e1559fd0359cc4e2df9c9c2a085668f0f336c1553d5ab7c",
                       "f7e1a1681fef523d4091b91d5d27ac56015698548ffc32a29ca521ba1926ea20"
                      };
#endif

#if BENCHMARK == 1
    struct timeval start, end;
    float elapsed_split, elapsed_merge;
#else
    printf("Running test for RAID5:\n\n");
#endif
    /* BENCHSIZE must be between 1 byte and MAXSIZE */
    if(BENCHSIZE < 0 || BENCHSIZE > MAXSIZE) {
        fprintf(stderr, "Aborting. BENCHSIZE out of range.\n");
        return 1;
    }

    /** Create test file **/
    fp[0] = fopen(filename[0], "wb");
    if(!fp[0]) {
        fprintf(stderr, "Cannot write test file!\n");
        return 1;
    }
    for(bs = 0; bs < BENCHSIZE; bs++) {
        /* Every device becomes the parity twice. dev2 three
           times but the third time only 512+256 Bytes
           (3/4 BLOCKSIZE).
           2 * BLOCKSIZE * 6 + 3/4 BLOCKSIZE = 13056 */
        fprintf(fp[0], "%c", (unsigned char)((bs * bs + bs) % 256));
    }
    fclose(fp[0]);

    /** Open test file for split **/
    fp[0] = fopen(filename[0], "rb");
    if(!fp[0]) {
        fprintf(stderr, "Cannot read test file!\n");
        return 1;
    }

    /** Create device and metadata files **/
    for(i = 1; i <= 3; i++) {
        fp[i] = fopen(filename[i], "wb");
        if(!fp[i]) {
            fprintf(stderr, "Cannot create device file %d!\n", i - 1);
            return 1;
        }
    }

    fp[4] = fopen(filename[5], "wb");
    if(!fp[4]) {
        fprintf(stderr, "Cannot create metadata file!\n");
        return 1;
    }

    /** perform the split **/
#if BENCHMARK == 1
    gettimeofday(&start, NULL);
    split_file(fp[0], &fp[1], fp[4], (char *) "password", 8);
    gettimeofday(&end, NULL);
    elapsed_split = ((end.tv_sec - start.tv_sec) * 1000000.0f + end.tv_usec - start.tv_usec) / 1000.0f;
#else
    printf("Start split ... ");
    fflush(stdout);
    status = split_file(fp[0], &fp[1], fp[4], (unsigned char *) "password", 8);
    if((status & SUCCESS_SPLIT) == 0) {
        fprintf(stderr, "Return code of split does not include the success flag(%d). Got %d.\n", SUCCESS_SPLIT, status);
    }
    printf("Done\n");
    fflush(stdout);
#endif

    /** Close the input file **/
    fclose(fp[0]);

    /** Close and reopen device and metadata files for merge **/
    for(i = 1; i <= 3; i++) {
        fclose(fp[i]);
        if(i == FILEID) {
            rename(filename[FILEID], filename[6]);
            fprintf(stderr, "renamed %s to %s\n", filename[FILEID], filename[6]);
        }
        fp[i] = fopen(filename[i], "rb");
#if BENCHMARK != 1
        if(!fp[i]) {
            fprintf(stderr, "Cannot open device file %d!", i - 1);
            if(i == FILEID) {
                fprintf(stderr, " [OK]\n");
            } else {
                fprintf(stderr, "\n");
            }
        }
#endif
    }

    fclose(fp[4]);
    fp[4] = fopen(filename[5], "rb");
    if(!fp[4]) {
        fprintf(stderr, "Cannot open metadata file!\n");
        return 1;
    }

    /** Open output file for merge **/
    fp[0] = fopen(filename[4], "wb");
    if(!fp[0]) {
        fprintf(stderr, "Cannot write output file!\n");
        return 1;
    }

    /** perform the merge **/
#if BENCHMARK == 1
    gettimeofday(&start, NULL);
    merge_file(fp[0], &fp[1], fp[4], (char *) "password", 8);
    gettimeofday(&end, NULL);
    elapsed_merge = ((end.tv_sec - start.tv_sec) * 1000000.0f + end.tv_usec - start.tv_usec) / 1000.0f;
#else
    printf("Start merge ... ");
    fflush(stdout);
    status = merge_file(fp[0], &fp[1], fp[4], (unsigned char *) "password", 8);
    if((status & SUCCESS_MERGE) == 0) {
        fprintf(stderr, "Return code of merge does not include the success flag(%d). Got %d.\n", SUCCESS_MERGE, status);
    }
    printf("Done\n");
    fflush(stdout);
#endif

    /** Close ALL files **/
    for(i = 0; i <= 4; i++) {
        if(fp[i]) {
            fclose(fp[i]);
        }
    }

    status = 0;
    for(i = 0; i <= 6; i++) {
        if(i == 1) {
            continue;
        }
#if CHECKING == 1
        printf("Checking file %s ... ", filename[i]);
        ascii = check_sha256_sum(filename[i], (unsigned char *) assumed[i]);

        if(ascii == NULL) {
            printf("CORRECT!\n");
        } else {
            if(memcmp(ascii, assumed[i], 64) == 0) {
                fprintf(stdout, "Memory Error!\n");
            } else {
                fprintf(stdout, "FALSE!\n");
                printf("%-12s%s\n%-12s%s\n", "Calculated:" , ascii, "Assumed:", assumed[i]);
                free(ascii);
            }
            status++;
        }
#endif
        /*remove ( filename[i] );*/
    }
#if BENCHMARK == 1
    printf("\"split\";\"%.3f\";\"merge\";\"%.3f\";\"bytes\";\"%d\"\n", elapsed_split, elapsed_merge , BENCHSIZE);
#endif
    return status;
}