ReactOS 0.4.15-dev-8231-g29a56f3
diskio.h File Reference
#include <typedefs.h>
Include dependency graph for diskio.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define _USE_WRITE   1 /* 1: Enable disk_write function */
 
#define _USE_IOCTL   1 /* 1: Enable disk_ioctl fucntion */
 
#define STA_NOINIT   0x01 /* Drive not initialized */
 
#define STA_NODISK   0x02 /* No medium in the drive */
 
#define STA_PROTECT   0x04 /* Write protected */
 
#define CTRL_SYNC   0 /* Complete pending write process (needed at _FS_READONLY == 0) */
 
#define GET_SECTOR_COUNT   1 /* Get media size (needed at _USE_MKFS == 1) */
 
#define GET_SECTOR_SIZE   2 /* Get sector size (needed at _MAX_SS != _MIN_SS) */
 
#define GET_BLOCK_SIZE   3 /* Get erase block size (needed at _USE_MKFS == 1) */
 
#define CTRL_TRIM   4 /* Inform device that the data on the block of sectors is no longer used (needed at _USE_TRIM == 1) */
 
#define SET_SECTOR_COUNT   126
 

Typedefs

typedef BYTE DSTATUS
 

Enumerations

enum  DRESULT {
  RES_OK = 0 , RES_ERROR , RES_WRPRT , RES_NOTRDY ,
  RES_PARERR
}
 

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)
 

Macro Definition Documentation

◆ _USE_IOCTL

#define _USE_IOCTL   1 /* 1: Enable disk_ioctl fucntion */

Definition at line 13 of file diskio.h.

◆ _USE_WRITE

#define _USE_WRITE   1 /* 1: Enable disk_write function */

Definition at line 12 of file diskio.h.

◆ CTRL_SYNC

#define CTRL_SYNC   0 /* Complete pending write process (needed at _FS_READONLY == 0) */

Definition at line 54 of file diskio.h.

◆ CTRL_TRIM

#define CTRL_TRIM   4 /* Inform device that the data on the block of sectors is no longer used (needed at _USE_TRIM == 1) */

Definition at line 58 of file diskio.h.

◆ GET_BLOCK_SIZE

#define GET_BLOCK_SIZE   3 /* Get erase block size (needed at _USE_MKFS == 1) */

Definition at line 57 of file diskio.h.

◆ GET_SECTOR_COUNT

#define GET_SECTOR_COUNT   1 /* Get media size (needed at _USE_MKFS == 1) */

Definition at line 55 of file diskio.h.

◆ GET_SECTOR_SIZE

#define GET_SECTOR_SIZE   2 /* Get sector size (needed at _MAX_SS != _MIN_SS) */

Definition at line 56 of file diskio.h.

◆ SET_SECTOR_COUNT

#define SET_SECTOR_COUNT   126

Definition at line 61 of file diskio.h.

◆ STA_NODISK

#define STA_NODISK   0x02 /* No medium in the drive */

Definition at line 47 of file diskio.h.

◆ STA_NOINIT

#define STA_NOINIT   0x01 /* Drive not initialized */

Definition at line 46 of file diskio.h.

◆ STA_PROTECT

#define STA_PROTECT   0x04 /* Write protected */

Definition at line 48 of file diskio.h.

Typedef Documentation

◆ DSTATUS

typedef BYTE DSTATUS

Definition at line 19 of file diskio.h.

Enumeration Type Documentation

◆ DRESULT

Enumerator
RES_OK 
RES_ERROR 
RES_WRPRT 
RES_NOTRDY 
RES_PARERR 

Definition at line 22 of file diskio.h.

22 {
23 RES_OK = 0, /* 0: Successful */
24 RES_ERROR, /* 1: R/W Error */
25 RES_WRPRT, /* 2: Write Protected */
26 RES_NOTRDY, /* 3: Not Ready */
27 RES_PARERR /* 4: Invalid Parameter */
28} DRESULT;
DRESULT
Definition: diskio.h:22
@ RES_OK
Definition: diskio.h:23
@ RES_WRPRT
Definition: diskio.h:25
@ RES_ERROR
Definition: diskio.h:24
@ RES_NOTRDY
Definition: diskio.h:26
@ RES_PARERR
Definition: diskio.h:27

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
#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}