From 24fa75cda33a7159b71de7ef92e729148f963fc1 Mon Sep 17 00:00:00 2001 From: David Quintana Date: Tue, 8 Sep 2015 00:28:28 +0000 Subject: [PATCH] [FATTEN] * 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 --- reactos/tools/fatten/fatfs/diskio.c | 23 ++++++++++++++++------- reactos/tools/fatten/fatfs/integer.h | 22 ++++++++++++---------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/reactos/tools/fatten/fatfs/diskio.c b/reactos/tools/fatten/fatfs/diskio.c index feaa3ec7023..f99ecb4346c 100644 --- a/reactos/tools/fatten/fatfs/diskio.c +++ b/reactos/tools/fatten/fatfs/diskio.c @@ -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; diff --git a/reactos/tools/fatten/fatfs/integer.h b/reactos/tools/fatten/fatfs/integer.h index f254b2a0280..6f61da0018b 100644 --- a/reactos/tools/fatten/fatfs/integer.h +++ b/reactos/tools/fatten/fatfs/integer.h @@ -5,28 +5,30 @@ #ifndef _FF_INTEGER #define _FF_INTEGER -#ifdef _WIN32 /* FatFs development platform */ +#ifdef _WIN32 /* Windows */ #include #include -#else /* Embedded platform */ +#else /* Unixes */ + +#include /* 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