mirror of
https://github.com/reactos/reactos.git
synced 2025-06-04 08:50:27 +00:00
[FATTEN]
* Fix the breakage I commited. Hopefully. svn path=/trunk/; revision=69132
This commit is contained in:
parent
9a82c8549f
commit
51731534a2
3 changed files with 66 additions and 47 deletions
|
@ -9,14 +9,55 @@
|
|||
#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 @@ DSTATUS disk_initialize(
|
|||
{
|
||||
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;
|
||||
}
|
||||
|
@ -60,26 +91,6 @@ DSTATUS disk_status(
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Read Sector(s) */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
@ -177,12 +188,15 @@ DRESULT disk_ioctl(
|
|||
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:
|
||||
|
@ -190,6 +204,8 @@ DRESULT disk_ioctl(
|
|||
int count = *(DWORD*)buff;
|
||||
long size;
|
||||
|
||||
sectorCount[pdrv] = count;
|
||||
|
||||
fseek(driveHandle[pdrv], 0, SEEK_END);
|
||||
size = ftell(driveHandle[pdrv]) / 512;
|
||||
|
||||
|
|
|
@ -31,10 +31,11 @@ typedef enum {
|
|||
/*---------------------------------------*/
|
||||
/* 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 @@ DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
|
|||
#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
|
||||
}
|
||||
|
|
|
@ -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 @@ int need_mount()
|
|||
#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 @@ int main(int oargc, char* oargv[])
|
|||
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 @@ int main(int oargc, char* oargv[])
|
|||
|
||||
NEED_PARAMS(1, 1);
|
||||
|
||||
NEED_MOUNT();
|
||||
|
||||
// Arg 1: number of sectors
|
||||
sectors = atoi(argv[0]);
|
||||
|
||||
|
@ -182,6 +182,8 @@ int main(int oargc, char* oargv[])
|
|||
|
||||
disk_ioctl(0, SET_SECTOR_COUNT, §ors);
|
||||
|
||||
NEED_MOUNT();
|
||||
|
||||
ret = f_mkfs("0:", 1, sectors < 4096 ? 1 : 8);
|
||||
if (ret)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue