예제 #1
0
ulong skymedi_write_file(struct mmc * mmc, lbaint_t start, char *name,
			 u32 timeout_ms)
{
	unsigned char *buffer = (unsigned char *)Bulk_out_buf;	//???
	file_header_t *header =
	    get_file_header(buffer, BULK_OUT_BUF_SIZE, name);
	if (header == NULL) {
		printf("can't find file %s\n", name);
		return 0;
	}

	u32 size = header->size;
	void *src = buffer + header->offset;

	lbaint_t blkcnt = (size - 1) / 512 + 1;
	lbaint_t cur, blocks_todo = blkcnt;

	if (mmc_set_blocklen(mmc, mmc->write_bl_len))
		return 0;

	do {
		cur = (blocks_todo > mmc->b_max) ? mmc->b_max : blocks_todo;
		if (skymedi_write_blocks(mmc, start, cur, src, timeout_ms) !=
		    cur)
			return 0;
		blocks_todo -= cur;
		start += cur;
		src += cur * mmc->write_bl_len;
	} while (blocks_todo > 0);

	return blkcnt;
}
int report_data(void)
{
	char filename[91];
	FILE *fid;

	printf("Enter the file name for reporting statistics: ");
	gets(filename);
	printf("\n");

	int error = check_file_name(filename);
	if (!error)
	{
		fid = fopen(filename, "r");
		if (!fid)
		{
			// error in opening file
			printf(
					"Error in opening file %s: Check to make sure filename is correct and file exists.\n",
					filename);
			return FILE_ERROR; // a return here means we don't need an else clause
		}

		// Getting the data from the file.
		FileHeaderPtr fh_p = (FileHeaderPtr) malloc(sizeof(FileHeader));
		get_file_header(fh_p, fid);

		char buffer[256];
		printf("%s", to_string_file_header(fh_p, buffer));

		fclose(fid);

		printf("\nReporting Statistics for %s", filename);
		printf("\nThe mean is: %f", fh_p->mean);
		printf("\nThe median is: %f", fh_p->median);
		printf("\nThe variance is: %f", fh_p->variance);
		printf("\nThe standard deviation is: %f\n", fh_p->std_dev);
		printf("Reporting Statistics complete. Closing %s\n", filename);
		free(fh_p);
	}

	return error;
}