Author: dquintana Date: Tue Sep 8 22:20:37 2015 New Revision: 69132
URL: http://svn.reactos.org/svn/reactos?rev=69132&view=rev Log: [FATTEN] * Fix the breakage I commited. Hopefully.
Modified: trunk/reactos/tools/fatten/fatfs/diskio.c trunk/reactos/tools/fatten/fatfs/diskio.h trunk/reactos/tools/fatten/fatten.c
Modified: trunk/reactos/tools/fatten/fatfs/diskio.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/fatten/fatfs/diskio.c... ============================================================================== --- trunk/reactos/tools/fatten/fatfs/diskio.c [iso-8859-1] (original) +++ trunk/reactos/tools/fatten/fatfs/diskio.c [iso-8859-1] Tue Sep 8 22:20:37 2015 @@ -9,15 +9,56 @@ #include "diskio.h" #include <stdio.h>
-extern char* g_imageFileName; - /*-----------------------------------------------------------------------*/ /* Correspondence between physical drive number and image file handles. */
+UINT sectorCount[1] = { 0 }; FILE* driveHandle[1] = { NULL }; const int driveHandleCount = sizeof(driveHandle) / sizeof(FILE*);
/*-----------------------------------------------------------------------*/ +/* Open an image file a Drive */ +/*-----------------------------------------------------------------------*/ + +DSTATUS disk_openimage(BYTE pdrv, const char* imageFileName) +{ + if (pdrv < driveHandleCount) + { + if (driveHandle[0] != NULL) + return 0; + + driveHandle[0] = fopen(imageFileName, "r+b"); + if (!driveHandle[0]) + { + driveHandle[0] = fopen(imageFileName, "w+"); + } + + if (driveHandle[0] != NULL) + return 0; + } + return STA_NOINIT; +} + + +/*-----------------------------------------------------------------------*/ +/* Cleanup a Drive */ +/*-----------------------------------------------------------------------*/ + +VOID disk_cleanup( + BYTE pdrv /* Physical drive nmuber (0..) */ + ) +{ + if (pdrv < driveHandleCount) + { + if (driveHandle[pdrv] != NULL) + { + fclose(driveHandle[pdrv]); + driveHandle[pdrv] = NULL; + } + } +} + +/*-----------------------------------------------------------------------*/ /* Inidialize a Drive */ /*-----------------------------------------------------------------------*/
@@ -27,17 +68,7 @@ { if (pdrv == 0) /* only one drive (image file) supported atm. */ { - if (driveHandle[0] != NULL) - return 0; - - driveHandle[0] = fopen(g_imageFileName, "r+b"); - if(!driveHandle[0]) - { - driveHandle[0] = fopen(g_imageFileName, "w+"); - } - - if (driveHandle[0] != NULL) - return 0; + return 0; } return STA_NOINIT; } @@ -58,26 +89,6 @@ return 0; } return STA_NOINIT; -} - - - -/*-----------------------------------------------------------------------*/ -/* Cleanup a Drive */ -/*-----------------------------------------------------------------------*/ - -VOID disk_cleanup( - BYTE pdrv /* Physical drive nmuber (0..) */ - ) -{ - if (pdrv < driveHandleCount) - { - if (driveHandle[pdrv] != NULL) - { - fclose(driveHandle[pdrv]); - driveHandle[pdrv] = NULL; - } - } }
/*-----------------------------------------------------------------------*/ @@ -177,18 +188,23 @@ return RES_OK; case GET_SECTOR_COUNT: { - int temp = 0; - if(fseek(driveHandle[pdrv], 0, SEEK_END)) - printf("fseek failed!\n"); - else - temp = ftell(driveHandle[pdrv]); - *(DWORD*)buff = temp/512; + if (sectorCount[pdrv] <= 0) + { + if (fseek(driveHandle[pdrv], 0, SEEK_END)) + printf("fseek failed!\n"); + else + sectorCount[pdrv] = ftell(driveHandle[pdrv]) / 512; + } + + *(DWORD*)buff = sectorCount[pdrv]; return RES_OK; } case SET_SECTOR_COUNT: { int count = *(DWORD*)buff; long size; + + sectorCount[pdrv] = count;
fseek(driveHandle[pdrv], 0, SEEK_END); size = ftell(driveHandle[pdrv]) / 512;
Modified: trunk/reactos/tools/fatten/fatfs/diskio.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/fatten/fatfs/diskio.h... ============================================================================== --- trunk/reactos/tools/fatten/fatfs/diskio.h [iso-8859-1] (original) +++ trunk/reactos/tools/fatten/fatfs/diskio.h [iso-8859-1] Tue Sep 8 22:20:37 2015 @@ -31,10 +31,11 @@ /*---------------------------------------*/ /* Prototypes for disk control functions */
+DSTATUS disk_openimage(BYTE pdrv, const char* imageFileName); +VOID disk_cleanup(BYTE pdrv);
DSTATUS disk_initialize (BYTE pdrv); DSTATUS disk_status (BYTE pdrv); -VOID disk_cleanup (BYTE pdrv); DRESULT disk_read (BYTE pdrv, BYTE* buff, DWORD sector, UINT count); DRESULT disk_write (BYTE pdrv, const BYTE* buff, DWORD sector, UINT count); DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff); @@ -57,7 +58,7 @@ #define CTRL_ERASE_SECTOR 4 /* Force erased a block of sectors (for only _USE_ERASE) */
/* Custom command for image file resizing */ -#define SET_SECTOR_COUNT 253 +#define SET_SECTOR_COUNT 126
#ifdef __cplusplus }
Modified: trunk/reactos/tools/fatten/fatten.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/tools/fatten/fatten.c?rev=6... ============================================================================== --- trunk/reactos/tools/fatten/fatten.c [iso-8859-1] (original) +++ trunk/reactos/tools/fatten/fatten.c [iso-8859-1] Tue Sep 8 22:20:37 2015 @@ -11,8 +11,6 @@ #include "fatfs/ff.h" #include "fatfs/diskio.h"
-char* g_imageFileName; - FATFS g_Filesystem;
static int isMounted = 0; @@ -89,7 +87,7 @@ #define NEED_MOUNT() \ do { ret = need_mount(); if(ret) \ {\ - printf("Error: could not mount image file '%s' (%d). \n", g_imageFileName, ret); \ + printf("Error: could not mount disk (%d). \n", ret); \ PRINT_HELP_AND_QUIT(); \ } } while(0)
@@ -136,7 +134,11 @@ PRINT_HELP_AND_QUIT(); }
- g_imageFileName = argv[0]; + if (disk_openimage(0, argv[0])) + { + printf("Error: could not open image file '%s'. \n", argv[0]); + PRINT_HELP_AND_QUIT(); + }
argc--; argv++; @@ -168,8 +170,6 @@
NEED_PARAMS(1, 1);
- NEED_MOUNT(); - // Arg 1: number of sectors sectors = atoi(argv[0]);
@@ -181,6 +181,8 @@ }
disk_ioctl(0, SET_SECTOR_COUNT, §ors); + + NEED_MOUNT();
ret = f_mkfs("0:", 1, sectors < 4096 ? 1 : 8); if (ret)