2 * Copyright 2004 Martin Fuchs
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.
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.
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
25 // Martin Fuchs, 01.02.2004
29 /// FAT file system file-entry
30 struct FATEntry
: public Entry
32 FATEntry(Entry
* parent
, unsigned cluster
) : Entry(parent
, ET_FAT
), _cluster(cluster
) {}
35 FATEntry() : Entry(ET_FAT
) {}
37 virtual bool get_path(PTSTR path
, size_t path_count
) const;
38 virtual ShellPath
create_absolute_pidl() const;
46 /// FAT file system directory-entry
47 struct FATDirectory
: public FATEntry
, public Directory
49 FATDirectory(FATDrive
& drive
, LPCTSTR root_path
);
50 FATDirectory(FATDrive
& drive
, Entry
* parent
, LPCTSTR path
, unsigned cluster
);
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*);
60 struct dirsecz
* _secarr
;
75 WORD BytesPerSector
; // dpb.bsec
76 BYTE SectorsPerCluster
; // dpb.sclus + 1
77 WORD ReservedSectors
; // dpb.ffatsec
79 WORD RootEntries
; // dpb.ndir
93 BYTE BootSignature
[2];
100 BYTE SectorsPerCluster
;
101 WORD ReservedSectors
;
103 WORD reserved1
; // immer 0 für FAT32
106 WORD reserved2
; // immer 0 für FAT32
107 WORD SectorsPerTrack
;
111 DWORD SectorsPerFAT32
;
113 DWORD RootSectors
; // correct?
117 BYTE BootSignature
[2];
134 unsigned readonly
: 1;
138 unsigned directory
: 1;
139 unsigned archived
: 1;
140 unsigned deleted
: 1;
153 struct filetime time
;
154 struct filedate date
;
161 BYTE B
[8+3+1+10+sizeof(struct filetime
)+sizeof(struct filedate
)+sizeof(WORD
)+sizeof(DWORD
)];
180 struct buffer far
*buf
;
190 #define _A_DELETED 0x40
191 #define _A_ILLEGAL 0x80
192 #define IS_LNAME(a) ((a&0xFF)==0x0F) // "& 0xFF" correct?
194 #define FAT_DEL_CHAR (char)0xe5
196 #define AddP(p,s) {(int&)p += s;}
203 DWORD s
[32]; // 32 only as placeholder
213 #define MK_P(ofs) ((void*) ((size_t)(ofs)))
214 #define MK_LONG(l,h) ((DWORD)WORD(l)|((DWORD)WORD(h)<<16))
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)))
224 /// FAT drive root entry
225 struct FATDrive
: public FATDirectory
227 FATDrive(LPCTSTR path
);
229 FATDrive(Entry* parent, LPCTSTR path)
232 _path = _tcsdup(path);
238 BootSector _boot_sector
;
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
253 bool read_sector(DWORD sec
, Buffer
* buf
, int len
);
254 DWORD
read_FAT(DWORD Clus
, bool& ok
);
258 bool read_cache(DWORD sec
, Buffer
** bufptr
);
259 int get_cache_buffer();