ReactOS  0.4.13-dev-464-g6b95727
fatfs.h
Go to the documentation of this file.
1 /*
2  * Copyright 2004 Martin Fuchs
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 
20  //
21  // Explorer clone
22  //
23  // fatfs.h
24  //
25  // Martin Fuchs, 01.02.2004
26  //
27 
28 
30 struct FATEntry : public Entry
31 {
32  FATEntry(Entry* parent, unsigned cluster) : Entry(parent, ET_FAT), _cluster(cluster) {}
33 
34 protected:
36 
37  virtual bool get_path(PTSTR path, size_t path_count) const;
38  virtual ShellPath create_absolute_pidl() const;
39 
41 };
42 
43 
44 struct FATDrive;
45 
47 struct FATDirectory : public FATEntry, public Directory
48 {
49  FATDirectory(FATDrive& drive, LPCTSTR root_path);
50  FATDirectory(FATDrive& drive, Entry* parent, LPCTSTR path, unsigned cluster);
51  ~FATDirectory();
52 
53  virtual void read_directory(int scan_flags=0);
54  virtual const void* get_next_path_component(const void*) const;
55  virtual Entry* find_entry(const void*);
56 
57 protected:
59 
60  struct dirsecz* _secarr;
61  int _cur_bufs;
62  int _ents;
63  struct dirent* _dir;
64  struct Kette* _alloc;
65 
66  bool read_dir();
67 };
68 
69 
70 #pragma pack(push, 1)
71 
72 struct BootSector {
73  BYTE jmp[3];
74  char OEM[8];
75  WORD BytesPerSector; // dpb.bsec
76  BYTE SectorsPerCluster; // dpb.sclus + 1
77  WORD ReservedSectors; // dpb.ffatsec
79  WORD RootEntries; // dpb.ndir
90  char Label[11];
91  char FileSystem[8];
92  BYTE BootCode[448];
94 };
95 
96 struct BootSector32 {
97  BYTE jmp[3];
98  char OEM[8];
103  WORD reserved1; // immer 0 für FAT32
106  WORD reserved2; // immer 0 für FAT32
113  DWORD RootSectors; // correct?
114  char unknown2[6];
115  char FileSystem[8];
118 };
119 
120 
121 struct filetime {
122  WORD sec2 : 5;
123  WORD min : 6;
124  WORD hour : 5;
125 };
126 
127 struct filedate {
128  WORD day : 5;
129  WORD month : 4;
130  WORD year : 7;
131 };
132 
133 typedef struct {
134  unsigned readonly : 1;
135  unsigned hidden : 1;
136  unsigned system : 1;
137  unsigned volume : 1;
138  unsigned directory : 1;
139  unsigned archived : 1;
140  unsigned deleted : 1;
141 } fattr;
142 
143 typedef union {
144  char b;
146 } FAT_attribute;
147 
148 struct DEntry_E {
149  char name[8];
150  char ext[3];
151  char attr;
152  char rsrvd[10];
153  struct filetime time;
154  struct filedate date;
157 };
158 
159 union DEntry {
161  BYTE B[8+3+1+10+sizeof(struct filetime)+sizeof(struct filedate)+sizeof(WORD)+sizeof(DWORD)];
162 };
163 
164 #pragma pack(pop)
165 
166 
167 #define BufLen 512
168 
169 struct Buffer {
171 };
172 
173 struct Cache {
175 };
176 
177 struct dskrwblk {
180  struct buffer far *buf;
181 };
182 
183 #define RONLY 0x01
184 #define HIDDEN 0x02
185 #define SYSTEM 0x04
186 #define VOLUME 0x08
187 #define DIRENT 0x10
188 #define ARCHIVE 0x20
189 
190 #define _A_DELETED 0x40
191 #define _A_ILLEGAL 0x80
192 #define IS_LNAME(a) ((a&0xFF)==0x0F) // "& 0xFF" correct?
193 
194 #define FAT_DEL_CHAR (char)0xe5
195 
196 #define AddP(p,s) {(int&)p += s;}
197 
198 struct dirent {
199  union DEntry ent[1];
200 };
201 
202 struct dirsecz {
203  DWORD s[32]; // 32 only as placeholder
204 };
205 
206 struct Kette {
207  struct Kette* Vorw;
208  struct Kette* Rueck;
209  union DEntry* Ent;
210 };
211 
212 
213 #define MK_P(ofs) ((void*) ((size_t)(ofs)))
214 #define MK_LONG(l,h) ((DWORD)WORD(l)|((DWORD)WORD(h)<<16))
215 
216 #define spoke(ofs,w) (*((BYTE*)MK_P(ofs)) = (BYTE)(w))
217 #define wpoke(ofs,w) (*((WORD*)MK_P(ofs)) = (WORD)(w))
218 #define dpoke(ofs,w) (*((DWORD*)MK_P(ofs)) = (DWORD)(w))
219 #define speek(ofs) (*((BYTE*)MK_P(ofs)))
220 #define wpeek(ofs) (*((WORD*)MK_P(ofs)))
221 #define dpeek(p) (*((DWORD*)MK_P(p)))
222 
223 
225 struct FATDrive : public FATDirectory
226 {
228 /*
229  FATDrive(Entry* parent, LPCTSTR path)
230  : FATEntry(parent)
231  {
232  _path = _tcsdup(path);
233  }
234 */
235  ~FATDrive();
236 
239  int _bufl;
240  int _bufents;
241  int _SClus;
242 
243 #define CACHE_SIZE_LOW 32
246  DWORD* _CacheSec; // numbers of buffered cache sectors
247  int* _CacheCnt; // counters for cache usage
248  bool* _CacheDty; // dirty flags for cache
249  int _Caches;
252 
253  bool read_sector(DWORD sec, Buffer* buf, int len);
254  DWORD read_FAT(DWORD Clus, bool& ok);
255 
256  void small_cache();
257  void reset_cache();
258  bool read_cache(DWORD sec, Buffer** bufptr);
259  int get_cache_buffer();
260 };
WORD Sectors16
Definition: fatfs.h:80
DWORD SerialNr
Definition: fatfs.h:89
WORD SectorsPerTrack
Definition: fatfs.h:83
WORD BytesPerSector
Definition: fatfs.h:75
struct buffer far * buf
Definition: fatfs.h:180
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
char Label[11]
Definition: fatfs.h:90
unsigned deleted
Definition: fatfs.h:140
int * _CacheCnt
Definition: fatfs.h:247
Definition: fatfs.h:159
BYTE MediaDescr
Definition: fatfs.h:81
BYTE SectorsPerCluster
Definition: fatfs.h:76
static unsigned int bufptr
Definition: tncon.cpp:77
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
BYTE dat[BufLen]
Definition: fatfs.h:170
BYTE NumberFATs
Definition: fatfs.h:78
BYTE SectorsPerCluster
Definition: fatfs.h:100
#define BufLen
Definition: fatfs.h:167
Definition: fatfs.h:173
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
WORD reserved1
Definition: fatfs.h:103
WORD month
Definition: fatfs.h:129
WORD ReservedSectors
Definition: fatfs.h:77
union DEntry ent[1]
Definition: fatfs.h:199
FAT file system file-entry.
Definition: fatfs.h:30
DWORD * _CacheSec
Definition: fatfs.h:246
BYTE DriveUnit
Definition: fatfs.h:87
bool read_sector(DWORD sec, Buffer *buf, int len)
char rsrvd[10]
Definition: fatfs.h:152
int _Caches
Definition: fatfs.h:249
int _bufl
Definition: fatfs.h:239
GLuint buffer
Definition: glext.h:5915
virtual void read_directory(int scan_flags=0)
int _cur_bufs
Definition: fatfs.h:61
unsigned readonly
Definition: fatfs.h:134
bool * _CacheDty
Definition: fatfs.h:248
virtual ShellPath create_absolute_pidl() const
char unknown2[6]
Definition: fatfs.h:114
virtual bool get_path(PTSTR path, size_t path_count) const
Definition: fatfs.h:198
int _bufents
Definition: fatfs.h:240
unsigned archived
Definition: fatfs.h:139
char OEM[8]
Definition: fatfs.h:98
#define far
Definition: windef.h:114
void reset_cache()
WORD sec2
Definition: fatfs.h:122
int get_cache_buffer()
Definition: fatfs.h:133
BYTE B[8+3+1+10+sizeof(struct filetime)+sizeof(struct filedate)+sizeof(WORD)+sizeof(DWORD)]
Definition: fatfs.h:161
union DEntry * Ent
Definition: fatfs.h:209
struct Kette * _alloc
Definition: fatfs.h:64
WORD ReservedSectors
Definition: fatfs.h:101
WORD anz
Definition: fatfs.h:179
WORD RootEntries
Definition: fatfs.h:79
char attr
Definition: fatfs.h:151
FATEntry(Entry *parent, unsigned cluster)
Definition: fatfs.h:32
DWORD read_FAT(DWORD Clus, bool &ok)
#define ok(value,...)
BootSector _boot_sector
Definition: fatfs.h:238
int _SClus
Definition: fatfs.h:241
WORD Heads
Definition: fatfs.h:84
char OEM[8]
Definition: fatfs.h:74
DWORD HiddenSectors
Definition: fatfs.h:85
struct filedate date
Definition: fatfs.h:154
WORD min
Definition: fatfs.h:123
Definition: bufpool.h:45
WORD BytesPerSector
Definition: fatfs.h:99
DEntry_E E
Definition: fatfs.h:160
char FileSystem[8]
Definition: fatfs.h:115
CHAR * PTSTR
Definition: xmlstorage.h:191
WORD day
Definition: fatfs.h:128
FAT drive root entry.
Definition: fatfs.h:225
unsigned directory
Definition: fatfs.h:138
unsigned hidden
Definition: fatfs.h:135
WORD hour
Definition: fatfs.h:124
HANDLE _hDrive
Definition: fatfs.h:237
DWORD RootSectors
Definition: fatfs.h:113
BYTE NumberFATs
Definition: fatfs.h:102
struct filetime time
Definition: fatfs.h:153
r parent
Definition: btrfs.c:2708
DWORD sec
Definition: fatfs.h:178
DWORD size
Definition: fatfs.h:156
struct Kette * Rueck
Definition: fatfs.h:208
unsigned short WORD
Definition: ntddk_ex.h:93
BYTE jmp[3]
Definition: fatfs.h:73
WORD Heads
Definition: fatfs.h:108
unsigned long DWORD
Definition: ntddk_ex.h:95
BYTE BootCode[448]
Definition: fatfs.h:92
void small_cache()
unsigned volume
Definition: fatfs.h:137
WORD Sectors16
Definition: fatfs.h:104
struct dirent * _dir
Definition: fatfs.h:63
virtual const void * get_next_path_component(const void *) const
BYTE dat[BufLen]
Definition: fatfs.h:174
fattr a
Definition: fatfs.h:145
int _read_ahead
Definition: fatfs.h:251
FAT file system directory-entry.
Definition: fatfs.h:47
WORD reserved2
Definition: fatfs.h:106
FATDrive(LPCTSTR path)
GLenum GLsizei len
Definition: glext.h:6722
unsigned char BYTE
Definition: mem.h:68
GLdouble s
Definition: gl.h:2039
struct dirsecz * _secarr
Definition: fatfs.h:60
Definition: fatfs.h:202
FATEntry()
Definition: fatfs.h:35
BYTE MediaDescr
Definition: fatfs.h:105
int _ents
Definition: fatfs.h:62
DWORD Sectors32
Definition: fatfs.h:110
bool read_dir()
WORD SectorsPerFAT
Definition: fatfs.h:82
bool _cache_empty
Definition: fatfs.h:250
char ext[3]
Definition: fatfs.h:150
BYTE jmp[3]
Definition: fatfs.h:97
FATDrive & _drive
Definition: fatfs.h:58
WORD year
Definition: fatfs.h:130
Definition: services.c:325
DWORD HiddenSectors
Definition: fatfs.h:109
FATDirectory(FATDrive &drive, LPCTSTR root_path)
WORD fclus
Definition: fatfs.h:155
Cache * _FATCache
Definition: fatfs.h:244
WORD SectorsPerTrack
Definition: fatfs.h:107
struct Kette * Vorw
Definition: fatfs.h:207
BYTE BootSignature[2]
Definition: fatfs.h:117
WORD ExtBootFlag
Definition: fatfs.h:88
Definition: name.c:36
BYTE BootSignature[2]
Definition: fatfs.h:93
virtual Entry * find_entry(const void *)
Definition: fatfs.h:206
DWORD Sectors32
Definition: fatfs.h:86
base for all directory entries
Definition: entries.h:138
Definition: entries.h:40
unsigned system
Definition: fatfs.h:136
int _CacheCount
Definition: fatfs.h:245
bool read_cache(DWORD sec, Buffer **bufptr)
BYTE BootCode[448]
Definition: fatfs.h:116
char FileSystem[8]
Definition: fatfs.h:91
wrapper class for item ID lists
Definition: shellclasses.h:651
DWORD unknown1
Definition: fatfs.h:112
base of all file and directory entries
Definition: entries.h:82
char b
Definition: fatfs.h:144
DWORD _cluster
Definition: fatfs.h:40
DWORD SectorsPerFAT32
Definition: fatfs.h:111