ReactOS 0.4.15-dev-7991-ge77da17
ff_ioman.h
Go to the documentation of this file.
1/*****************************************************************************
2 * FullFAT - High Performance, Thread-Safe Embedded FAT File-System *
3 * Copyright (C) 2009 James Walmsley (james@worm.me.uk) *
4 * *
5 * This program is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17 * *
18 * IMPORTANT NOTICE: *
19 * ================= *
20 * Alternative Licensing is available directly from the Copyright holder, *
21 * (James Walmsley). For more information consult LICENSING.TXT to obtain *
22 * a Commercial license. *
23 * *
24 * See RESTRICTIONS.TXT for extra restrictions on the use of FullFAT. *
25 * *
26 * Removing the above notice is illegal and will invalidate this license. *
27 *****************************************************************************
28 * See http://worm.me.uk/fullfat for more information. *
29 * Or http://fullfat.googlecode.com/ for latest releases and the wiki. *
30 *****************************************************************************/
31
38#ifndef _FF_IOMAN_H_
39#define _FF_IOMAN_H_
40
41#include <stdlib.h> // Use of malloc()
42#include "ff_error.h"
43#include "ff_config.h"
44#include "ff_types.h"
45#include "ff_safety.h" // Provide thread-safety via semaphores.
46#include "ff_memory.h" // Memory access routines for ENDIAN independence.
47#include "ff_hash.h"
48
49//#define FF_MAX_PARTITION_NAME 5 ///< Partition name length.
50
51#define FF_T_FAT12 0x0A
52#define FF_T_FAT16 0x0B
53#define FF_T_FAT32 0x0C
54
55#define FF_MODE_READ 0x01
56#define FF_MODE_WRITE 0x02
57#define FF_MODE_APPEND 0x04
58#define FF_MODE_CREATE 0x08
59#define FF_MODE_TRUNCATE 0x10
60#define FF_MODE_DIR 0x80
61
62#define FF_BUF_MAX_HANDLES 0xFFFF
63
74typedef struct {
78
79typedef FF_T_SINT32 (*FF_WRITE_BLOCKS) (FF_T_UINT8 *pBuffer, FF_T_UINT32 SectorAddress, FF_T_UINT32 Count, void *pParam);
80typedef FF_T_SINT32 (*FF_READ_BLOCKS) (FF_T_UINT8 *pBuffer, FF_T_UINT32 SectorAddress, FF_T_UINT32 Count, void *pParam);
81
82#define FF_ERR_DRIVER_BUSY -10
83#define FF_ERR_DRIVER_FATAL_ERROR -11
84
89typedef struct {
93 void *pParam;
95
101typedef struct {
110} FF_BUFFER;
111
112typedef struct {
113#ifdef FF_UNICODE_SUPPORT
115#else
117#endif
120
121#ifdef FF_HASH_CACHE
122typedef struct {
123 FF_T_UINT32 ulDirCluster;
124 FF_HASH_TABLE pHashTable;
125 FF_T_UINT32 ulNumHandles;
126 FF_T_UINT32 ulMisses;
127} FF_HASHCACHE;
128#endif
129
135typedef struct {
136 //FF_T_UINT8 ID; ///< Partition Incremental ID number.
140 //FF_T_INT8 Name[FF_MAX_PARTITION_NAME]; ///< Partition Identifier e.g. c: sd0: etc.
141 FF_T_INT8 VolLabel[12];
159#ifdef FF_PATH_CACHE
162#endif
164
165
166
173#define FF_FAT_LOCK 0x01
174#define FF_DIR_LOCK 0x02
175//#define FF_PATHCACHE_LOCK 0x04
176
190typedef struct {
195#ifdef FF_BLKDEV_USES_SEM
197#endif
198 void *FirstFile;
206#ifdef FF_HASH_CACHE
207 FF_HASHCACHE HashCache[FF_HASH_CACHE_DEPTH];
208#endif
209} FF_IOMAN;
210
211// Bit-Masks for Memory Allocation testing.
212#define FF_IOMAN_ALLOC_BLKDEV 0x01
213#define FF_IOMAN_ALLOC_PART 0x02
214#define FF_IOMAN_ALLOC_BUFDESCR 0x04
215#define FF_IOMAN_ALLOC_BUFFERS 0x08
216#define FF_IOMAN_ALLOC_RESERVED 0xF0
217
218
219//---------- PROTOTYPES (in order of appearance)
220
221// PUBLIC (Interfaces):
224FF_ERROR FF_RegisterBlkDevice (FF_IOMAN *pIoman, FF_T_UINT16 BlkSize, FF_WRITE_BLOCKS fnWriteBlocks, FF_READ_BLOCKS fnReadBlocks, void *pParam);
230
231#ifdef FF_64_NUM_SUPPORT
233#else
235#endif
236
237// PUBLIC (To FullFAT Only):
238FF_T_SINT32 FF_BlockRead (FF_IOMAN *pIoman, FF_T_UINT32 ulSectorLBA, FF_T_UINT32 ulNumSectors, void *pBuffer);
239FF_T_SINT32 FF_BlockWrite (FF_IOMAN *pIoman, FF_T_UINT32 ulSectorLBA, FF_T_UINT32 ulNumSectors, void *pBuffer);
244
245// PRIVATE (For this module only!):
246
247
248#endif
249
250
PRTL_UNICODE_STRING_BUFFER Path
#define FF_MAX_PATH
Definition: ff_config.h:173
#define FF_PATH_CACHE_DEPTH
Definition: ff_config.h:106
#define FF_HASH_CACHE_DEPTH
Definition: ff_config.h:111
struct _FF_HASH_TABLE * FF_HASH_TABLE
Definition: ff_hash.h:47
FF_T_SINT32 FF_BlockRead(FF_IOMAN *pIoman, FF_T_UINT32 ulSectorLBA, FF_T_UINT32 ulNumSectors, void *pBuffer)
FF_ERROR FF_UnmountPartition(FF_IOMAN *pIoman)
FF_ERROR FF_DecreaseFreeClusters(FF_IOMAN *pIoman, FF_T_UINT32 Count)
FF_BUFFER * FF_GetBuffer(FF_IOMAN *pIoman, FF_T_UINT32 Sector, FF_T_UINT8 Mode)
FF_T_SINT32(* FF_WRITE_BLOCKS)(FF_T_UINT8 *pBuffer, FF_T_UINT32 SectorAddress, FF_T_UINT32 Count, void *pParam)
Definition: ff_ioman.h:79
FF_IOMAN * FF_CreateIOMAN(FF_T_UINT8 *pCacheMem, FF_T_UINT32 Size, FF_T_UINT16 BlkSize, FF_ERROR *pError)
FF_ERROR FF_UnregisterBlkDevice(FF_IOMAN *pIoman)
void FF_ReleaseBuffer(FF_IOMAN *pIoman, FF_BUFFER *pBuffer)
FF_T_SINT32 FF_BlockWrite(FF_IOMAN *pIoman, FF_T_UINT32 ulSectorLBA, FF_T_UINT32 ulNumSectors, void *pBuffer)
FF_T_SINT32(* FF_READ_BLOCKS)(FF_T_UINT8 *pBuffer, FF_T_UINT32 SectorAddress, FF_T_UINT32 Count, void *pParam)
Definition: ff_ioman.h:80
FF_T_SINT32 FF_GetPartitionBlockSize(FF_IOMAN *pIoman)
FF_ERROR FF_DestroyIOMAN(FF_IOMAN *pIoman)
FF_ERROR FF_IncreaseFreeClusters(FF_IOMAN *pIoman, FF_T_UINT32 Count)
FF_ERROR FF_RegisterBlkDevice(FF_IOMAN *pIoman, FF_T_UINT16 BlkSize, FF_WRITE_BLOCKS fnWriteBlocks, FF_READ_BLOCKS fnReadBlocks, void *pParam)
FF_ERROR FF_MountPartition(FF_IOMAN *pIoman, FF_T_UINT8 PartitionNumber)
FF_ERROR FF_FlushCache(FF_IOMAN *pIoman)
FF_T_UINT64 FF_GetVolumeSize(FF_IOMAN *pIoman)
unsigned char FF_T_UINT8
8 bit unsigned integer.
Definition: ff_types.h:51
signed long FF_T_SINT32
32 bit signed integer.
Definition: ff_types.h:62
unsigned long long FF_T_UINT64
Definition: ff_types.h:72
wchar_t FF_T_WCHAR
Unicode UTF-16 Charachter type, for FullFAT when UNICODE is enabled.
Definition: ff_types.h:80
unsigned short FF_T_UINT16
16 bit unsigned integer.
Definition: ff_types.h:56
char FF_T_BOOL
This can be a char if your compiler isn't C99.
Definition: ff_types.h:44
unsigned long FF_T_UINT32
32 bit unsigned integer.
Definition: ff_types.h:61
FF_T_SINT32 FF_ERROR
A special error code type to ease some inconsistencies in Error reporting.
Definition: ff_types.h:77
char FF_T_INT8
8 bit default integer.
Definition: ff_types.h:50
_In_ ULONG Mode
Definition: hubbusif.h:303
int Count
Definition: noreturn.cpp:7
PVOID pBuffer
Describes the block device driver interface to FullFAT.
Definition: ff_ioman.h:89
FF_WRITE_BLOCKS fnpWriteBlocks
Function Pointer, to write a block(s) from a block device.
Definition: ff_ioman.h:90
FF_READ_BLOCKS fnpReadBlocks
Function Pointer, to read a block(s) from a block device.
Definition: ff_ioman.h:91
void * pParam
Pointer to some parameters e.g. for a Low-Level Driver Handle.
Definition: ff_ioman.h:93
FF_T_UINT16 devBlkSize
Block size that the driver deals with.
Definition: ff_ioman.h:92
FullFAT handles memory with buffers, described as below.
Definition: ff_ioman.h:101
FF_T_UINT32 Sector
The LBA of the Cached sector.
Definition: ff_ioman.h:102
FF_T_UINT8 Mode
Read or Write mode.
Definition: ff_ioman.h:106
FF_T_BOOL Modified
If the sector was modified since read.
Definition: ff_ioman.h:107
FF_T_BOOL Valid
Initially FALSE.
Definition: ff_ioman.h:108
FF_T_UINT32 LRU
For the Least Recently Used algorithm.
Definition: ff_ioman.h:103
FF_T_UINT16 NumHandles
Number of objects using this buffer.
Definition: ff_ioman.h:104
FF_T_UINT8 * pBuffer
Pointer to the cache block.
Definition: ff_ioman.h:109
FF_T_UINT16 Persistance
For the persistance algorithm.
Definition: ff_ioman.h:105
FF_T_UINT32 TotalBlocks
Definition: ff_ioman.h:76
FF_T_UINT16 BlkSize
Definition: ff_ioman.h:75
FF_IOMAN Object. A developer should not touch these values.
Definition: ff_ioman.h:190
FF_T_UINT8 Locks
Lock Flag for FAT & DIR Locking etc (This must be accessed via a semaphore).
Definition: ff_ioman.h:205
FF_BLK_DEVICE * pBlkDevice
Pointer to a Block device description.
Definition: ff_ioman.h:191
void * pSemaphore
Pointer to a Semaphore object. (For buffer description modifications only!).
Definition: ff_ioman.h:194
FF_PARTITION * pPartition
Pointer to a partition description.
Definition: ff_ioman.h:192
void * FirstFile
Pointer to the first File object.
Definition: ff_ioman.h:198
FF_T_UINT16 BlkSize
The Block size that IOMAN is configured to.
Definition: ff_ioman.h:201
FF_T_UINT16 CacheSize
Size of the cache in number of Sectors.
Definition: ff_ioman.h:202
FF_T_UINT8 MemAllocation
Bit-Mask identifying allocated pointers.
Definition: ff_ioman.h:204
FF_BUFFER * pBuffers
Pointer to the first buffer description.
Definition: ff_ioman.h:193
FF_T_UINT8 * pCacheMem
Pointer to a block of memory for the cache.
Definition: ff_ioman.h:199
FF_T_UINT8 PreventFlush
Flushing to disk only allowed when 0.
Definition: ff_ioman.h:203
void * pBlkDevSemaphore
Semaphore to guarantee Atomic access to the underlying block device, if required.
Definition: ff_ioman.h:196
FF_T_UINT32 LastReplaced
Marks which sector was last replaced in the cache.
Definition: ff_ioman.h:200
FullFAT identifies a partition with the following data.
Definition: ff_ioman.h:135
FF_T_UINT32 TotalSectors
Definition: ff_ioman.h:148
FF_T_UINT32 BeginLBA
LBA start address of the partition.
Definition: ff_ioman.h:142
FF_T_UINT32 FirstDataSector
Definition: ff_ioman.h:151
FF_T_UINT32 ClusterBeginLBA
LBA of first cluster.
Definition: ff_ioman.h:153
FF_T_UINT16 BlkSize
Size of a Sector Block in bytes.
Definition: ff_ioman.h:138
FF_T_UINT32 SectorsPerFAT
Number of sectors per Fat.
Definition: ff_ioman.h:146
FF_T_UINT32 NumClusters
Number of clusters.
Definition: ff_ioman.h:154
FF_T_UINT32 DataSectors
Definition: ff_ioman.h:149
FF_T_UINT32 RootDirSectors
Definition: ff_ioman.h:150
FF_T_UINT32 FatBeginLBA
LBA of the FAT tables.
Definition: ff_ioman.h:144
FF_T_UINT8 BlkFactor
Scale Factor for blocksizes above 512!
Definition: ff_ioman.h:139
FF_T_UINT32 LastFreeCluster
Definition: ff_ioman.h:156
FF_T_UINT8 Type
Partition Type Identifier.
Definition: ff_ioman.h:137
FF_T_UINT32 RootDirCluster
Cluster number of the root directory entry.
Definition: ff_ioman.h:155
FF_T_UINT32 PCIndex
Definition: ff_ioman.h:161
FF_T_UINT32 PartSize
Size of Partition in number of sectors.
Definition: ff_ioman.h:143
FF_T_UINT8 SectorsPerCluster
Number of sectors per Cluster.
Definition: ff_ioman.h:147
FF_T_UINT32 FreeClusterCount
Records free space on mount.
Definition: ff_ioman.h:157
FF_T_BOOL PartitionMounted
FF_TRUE if the partition is mounted, otherwise FF_FALSE.
Definition: ff_ioman.h:158
FF_T_UINT16 ReservedSectors
Definition: ff_ioman.h:152
FF_T_UINT8 NumFATS
Number of FAT tables.
Definition: ff_ioman.h:145
FF_T_UINT32 DirCluster
Definition: ff_ioman.h:118
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_In_ ULONG _In_ ULONG PartitionNumber
Definition: iofuncs.h:2061