* Fix the integer types for non-windows platforms (assume they have stdint.h instead of assuming embedded).
* Fix file I/O, which was just barely working enough to pass the one test I did.

svn path=/trunk/; revision=69105
This commit is contained in:
David Quintana
2015-09-08 00:28:28 +00:00
parent 04cb0e03ef
commit 24fa75cda3
2 changed files with 28 additions and 17 deletions
+16 -7
View File
@@ -31,6 +31,10 @@ DSTATUS disk_initialize(
return 0;
driveHandle[0] = fopen(imageFileName, "r+b");
if(!driveHandle[0])
{
driveHandle[0] = fopen(imageFileName, "w+");
}
if (driveHandle[0] != NULL)
return 0;
@@ -80,10 +84,10 @@ DRESULT disk_read(
result = fread(buff, 512, count, driveHandle[pdrv]);
if (result == count)
return RES_OK;
if (result != count)
return RES_ERROR;
return RES_ERROR;
return RES_OK;
}
}
@@ -114,9 +118,8 @@ DRESULT disk_write(
return RES_ERROR;
result = fwrite(buff, 512, count, driveHandle[pdrv]);
return RES_ERROR;
if (result != (512 * count))
if (result != count)
return RES_ERROR;
return RES_OK;
@@ -155,9 +158,15 @@ DRESULT disk_ioctl(
*(DWORD*)buff = 512;
return RES_OK;
case GET_SECTOR_COUNT:
fseek(driveHandle[pdrv], 0, SEEK_END);
*(DWORD*)buff = ftell(driveHandle[pdrv]) / 512;
{
int temp = 0;
if(fseek(driveHandle[pdrv], 0, SEEK_END))
printf("fseek failed!\n");
else
temp = ftell(driveHandle[pdrv]);
*(DWORD*)buff = temp/512;
return RES_OK;
}
case SET_SECTOR_COUNT:
{
int count = *(DWORD*)buff;
+12 -10
View File
@@ -5,28 +5,30 @@
#ifndef _FF_INTEGER
#define _FF_INTEGER
#ifdef _WIN32 /* FatFs development platform */
#ifdef _WIN32 /* Windows */
#include <windows.h>
#include <tchar.h>
#else /* Embedded platform */
#else /* Unixes */
#include <stdint.h>
/* This type MUST be 8 bit */
typedef unsigned char BYTE;
typedef uint8_t BYTE;
/* These types MUST be 16 bit */
typedef short SHORT;
typedef unsigned short WORD;
typedef unsigned short WCHAR;
typedef int16_t SHORT;
typedef uint16_t WORD;
typedef uint16_t WCHAR;
/* These types MUST be 16 bit or 32 bit */
typedef int INT;
typedef unsigned int UINT;
typedef int_fast16_t INT;
typedef uint_fast16_t UINT;
/* These types MUST be 32 bit */
typedef long LONG;
typedef unsigned long DWORD;
typedef int32_t LONG;
typedef uint32_t DWORD;
#endif