ReactOS 0.4.15-dev-7958-gcd0bb1a
diskio.c File Reference
#include "diskio.h"
#include <stdio.h>
Include dependency graph for diskio.c:

Go to the source code of this file.

Functions

DSTATUS disk_openimage (BYTE pdrv, const char *imageFileName)
 
VOID disk_cleanup (BYTE pdrv)
 
DSTATUS disk_initialize (BYTE pdrv)
 
DSTATUS disk_status (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)
 

Variables

UINT sectorCount [1] = { 0 }
 
FILEdriveHandle [1] = { NULL }
 
const int driveHandleCount = sizeof(driveHandle) / sizeof(FILE*)
 

Function Documentation

◆ disk_cleanup()

VOID disk_cleanup ( BYTE  pdrv)

Definition at line 48 of file diskio.c.

51{
52 if (pdrv < driveHandleCount)
53 {
54 if (driveHandle[pdrv] != NULL)
55 {
56 fclose(driveHandle[pdrv]);
57 driveHandle[pdrv] = NULL;
58 }
59 }
60}
const int driveHandleCount
Definition: diskio.c:18
FILE * driveHandle[1]
Definition: diskio.c:17
#define NULL
Definition: types.h:112
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)

Referenced by main().

◆ disk_initialize()

DSTATUS disk_initialize ( BYTE  pdrv)

Definition at line 66 of file diskio.c.

69{
70 if (pdrv == 0) /* only one drive (image file) supported atm. */
71 {
72 return 0;
73 }
74 return STA_NOINIT;
75}
#define STA_NOINIT
Definition: diskio.h:46

Referenced by f_mkfs(), and find_volume().

◆ disk_ioctl()

DRESULT disk_ioctl ( BYTE  pdrv,
BYTE  cmd,
void buff 
)

Definition at line 169 of file diskio.c.

174{
175 if (pdrv < driveHandleCount)
176 {
177 if (driveHandle[pdrv] != NULL)
178 {
179 switch (cmd)
180 {
181 case CTRL_SYNC:
182 fflush(driveHandle[pdrv]);
183 return RES_OK;
184 case GET_SECTOR_SIZE:
185 *(DWORD*)buff = 512;
186 return RES_OK;
187 case GET_BLOCK_SIZE:
188 *(DWORD*)buff = 512;
189 return RES_OK;
190 case GET_SECTOR_COUNT:
191 {
192 if (sectorCount[pdrv] <= 0)
193 {
194 if (fseek(driveHandle[pdrv], 0, SEEK_END))
195 printf("fseek failed!\n");
196 else
197 sectorCount[pdrv] = ftell(driveHandle[pdrv]) / 512;
198 }
199
200 *(DWORD*)buff = sectorCount[pdrv];
201 return RES_OK;
202 }
203 case SET_SECTOR_COUNT:
204 {
205 int count = *(DWORD*)buff;
206 long size;
207
208 sectorCount[pdrv] = count;
209
210 fseek(driveHandle[pdrv], 0, SEEK_END);
211 size = ftell(driveHandle[pdrv]) / 512;
212
213 if (size < count)
214 {
215 if (fseek(driveHandle[pdrv], count * 512 - 1, SEEK_SET))
216 return RES_ERROR;
217
218 fwrite(buff, 1, 1, driveHandle[pdrv]);
219
220 return RES_OK;
221 }
222 else
223 {
224 // SHRINKING NOT IMPLEMENTED
225 return RES_OK;
226 }
227 }
228 }
229 }
230 }
231
232 return RES_PARERR;
233}
#define SEEK_END
Definition: cabinet.c:29
UINT sectorCount[1]
Definition: diskio.c:16
#define CTRL_SYNC
Definition: diskio.h:54
#define GET_SECTOR_COUNT
Definition: diskio.h:55
@ RES_OK
Definition: diskio.h:23
@ RES_ERROR
Definition: diskio.h:24
@ RES_PARERR
Definition: diskio.h:27
#define SET_SECTOR_COUNT
Definition: diskio.h:61
#define GET_SECTOR_SIZE
Definition: diskio.h:56
#define GET_BLOCK_SIZE
Definition: diskio.h:57
static unsigned char buff[32768]
Definition: fatten.c:17
unsigned long DWORD
Definition: ntddk_ex.h:95
#define printf
Definition: freeldr.h:97
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLsizeiptr size
Definition: glext.h:5919
_Check_return_opt_ _CRTIMP int __cdecl fflush(_Inout_opt_ FILE *_File)
_Check_return_opt_ _CRTIMP int __cdecl fseek(_Inout_ FILE *_File, _In_ long _Offset, _In_ int _Origin)
_Check_return_ _CRTIMP long __cdecl ftell(_Inout_ FILE *_File)
_Check_return_opt_ _CRTIMP size_t __cdecl fwrite(_In_reads_bytes_(_Size *_Count) const void *_Str, _In_ size_t _Size, _In_ size_t _Count, _Inout_ FILE *_File)
#define SEEK_SET
Definition: jmemansi.c:26
Definition: ftp_var.h:139

Referenced by f_mkfs(), find_volume(), main(), remove_chain(), and sync_fs().

◆ disk_openimage()

DSTATUS disk_openimage ( BYTE  pdrv,
const char imageFileName 
)

Definition at line 24 of file diskio.c.

25{
26 if (pdrv < driveHandleCount)
27 {
28 if (driveHandle[0] != NULL)
29 return 0;
30
31 driveHandle[0] = fopen(imageFileName, "r+b");
32 if (!driveHandle[0])
33 {
34 driveHandle[0] = fopen(imageFileName, "w+b");
35 }
36
37 if (driveHandle[0] != NULL)
38 return 0;
39 }
40 return STA_NOINIT;
41}
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)

Referenced by main().

◆ disk_read()

DRESULT disk_read ( BYTE  pdrv,
BYTE buff,
DWORD  sector,
UINT  count 
)

Definition at line 99 of file diskio.c.

105{
107
108 if (pdrv < driveHandleCount)
109 {
110 if (driveHandle[pdrv] != NULL)
111 {
112 if (fseek(driveHandle[pdrv], sector * 512, SEEK_SET))
113 return RES_ERROR;
114
115 result = fread(buff, 512, count, driveHandle[pdrv]);
116
117 if (result != count)
118 return RES_ERROR;
119
120 return RES_OK;
121 }
122 }
123
124 return RES_PARERR;
125}
GLuint64EXT * result
Definition: glext.h:11304
_Check_return_opt_ _CRTIMP size_t __cdecl fread(_Out_writes_bytes_(_ElementSize *_Count) void *_DstBuf, _In_ size_t _ElementSize, _In_ size_t _Count, _Inout_ FILE *_File)
uint32_t sector
Definition: isohybrid.c:61

◆ disk_status()

DSTATUS disk_status ( BYTE  pdrv)

Definition at line 83 of file diskio.c.

86{
87 if (pdrv < driveHandleCount)
88 {
89 if (driveHandle[pdrv] != NULL)
90 return 0;
91 }
92 return STA_NOINIT;
93}

Referenced by find_volume(), and validate().

◆ disk_write()

DRESULT disk_write ( BYTE  pdrv,
const BYTE buff,
DWORD  sector,
UINT  count 
)

Definition at line 134 of file diskio.c.

140{
142
143 if (pdrv < driveHandleCount)
144 {
145 if (driveHandle[pdrv] != NULL)
146 {
147 if (fseek(driveHandle[pdrv], sector * 512, SEEK_SET))
148 return RES_ERROR;
149
150 result = fwrite(buff, 512, count, driveHandle[pdrv]);
151
152 if (result != count)
153 return RES_ERROR;
154
155 return RES_OK;
156 }
157 }
158
159 return RES_PARERR;
160}

Variable Documentation

◆ driveHandle

FILE* driveHandle[1] = { NULL }

Definition at line 17 of file diskio.c.

Referenced by disk_cleanup(), disk_ioctl(), disk_openimage(), disk_read(), disk_status(), and disk_write().

◆ driveHandleCount

const int driveHandleCount = sizeof(driveHandle) / sizeof(FILE*)

Definition at line 18 of file diskio.c.

Referenced by disk_cleanup(), disk_ioctl(), disk_openimage(), disk_read(), disk_status(), and disk_write().

◆ sectorCount

UINT sectorCount[1] = { 0 }